<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeejoin.equipmanage.mapper.CarPropertyMapper">
    <select id="getCarPropListByIotCode" resultType="com.yeejoin.equipmanage.common.entity.CarProperty">
        SELECT
        wcp.id AS id,
        wcp.car_id AS carId,
        wcp.value AS value,
        wcp.remark AS remark,
        wcp.equipment_index_id AS equipmentIndexId,
        wei.name_key AS nameKey
        FROM
        wl_car_property wcp
        LEFT JOIN wl_car AS wc ON wc.id = wcp.car_id
        LEFT JOIN wl_equipment_index AS wei ON wei.id = wcp.equipment_index_id
        WHERE
        wc.iot_code = #{iotCode}
        AND
        TRIM(wei.name_key) != '' AND wei.name_key IS NOT NULL
    </select>
    <select id="getCarPropertyList" resultType="com.yeejoin.equipmanage.common.entity.vo.CarPropertyVo">
        SELECT
        cp.id,
        cp.car_id,
        IFNULL(ei.`name`,'') AS `name`,
        ei.name_key AS nameKey,
        cp.`value`,
        ei.unit,
        ei.is_iot AS isIot,
        ei.sort_num AS sort,
        cp.create_date ,
        IFNULL(c.qr_code,'') AS mRid
        FROM
        wl_car_property cp
        LEFT JOIN wl_equipment_index ei ON ei.id = cp.equipment_index_id
        LEFT JOIN wl_car c ON c.id = cp.car_id
        <where>
            <if test="id != null">
                cp.car_id = #{id}
            </if>
        </where>
    </select>
    <select id="getCarPropertyListByCarIds" resultType="com.yeejoin.equipmanage.common.entity.vo.CarPropertyVo">
        SELECT
        cp.id,
        cp.car_id,
        ei.`name`,
        ei.name_key AS nameKey,
        cp.`value`,
        ei.unit,
        ei.is_iot AS isIot,
        ei.sort_num AS sort,
        cp.create_date
        FROM
        wl_car_property cp
        LEFT JOIN wl_equipment_index ei ON ei.id = cp.equipment_index_id
        <where>
            <if test="list != null and list.size > 0">
                cp.car_id IN
                <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>
</mapper>
