<?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.njcn.gather.device.types.mapper.CsDevTypeMapper">

    <resultMap id="DeviceTypeVOResultMap"
               type="com.njcn.gather.device.types.pojo.vo.DeviceTypeVO">
        <id column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="icdId" property="icdId"/>
        <result column="icdName" property="icdName"/>
        <result column="icdPath" property="icdPath"/>
        <result column="icdResult" property="icdResult"/>
        <result column="icdMsg" property="icdMsg"
                typeHandler="com.njcn.gather.device.types.typehandler.JsonNodeTypeHandler"/>
        <result column="power" property="power"/>
        <result column="devVolt" property="devVolt"/>
        <result column="devCurr" property="devCurr"/>
        <result column="devChns" property="devChns"/>
        <result column="waveCmd" property="waveCmd"/>
        <result column="reportName" property="reportName"/>
        <result column="canCheckIcd" property="canCheckIcd"/>
        <result column="canCheckPqdif" property="canCheckPqdif"/>
    </resultMap>

    <select id="selectDeviceTypeCheckList"
            resultMap="DeviceTypeVOResultMap">
        SELECT
            d.id AS id,
            d.name AS name,
            d.icd AS icdId,
            p.Name AS icdName,
            NULL AS icdPath,
            p.Result AS icdResult,
            p.Msg AS icdMsg,
            d.power AS power,
            d.Dev_Volt AS devVolt,
            d.Dev_Curr AS devCurr,
            d.Dev_Chns AS devChns,
            d.Wave_Cmd AS waveCmd,
            d.report_name AS reportName,
            1 AS canCheckIcd,
            0 AS canCheckPqdif
        FROM cs_dev_type d
        LEFT JOIN cs_icd_path p ON d.icd = p.ID
        WHERE d.State = 1
        <if test="keyword != null and keyword != ''">
            AND (d.name LIKE CONCAT('%', #{keyword}, '%')
            OR p.Name LIKE CONCAT('%', #{keyword}, '%'))
        </if>
        ORDER BY d.Update_Time DESC, d.Create_Time DESC
    </select>

</mapper>
