<?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.amos.fas.business.dao.mapper.EquipmentSpecificIndexMapper">


    <select id="findByDetailIdInAndNameKey"
            resultType="com.yeejoin.amos.fas.business.vo.EquipmentSpecificIndexVo">
        SELECT
            wsi.`value`,
            wei.unit AS equipmentIndexUnitName
        FROM
            `wl_equipment_index` wei
            RIGHT JOIN wl_equipment_specific_index wsi ON wei.id = wsi.equipment_index_id
            LEFT JOIN wl_equipment_specific wes ON wsi.equipment_specific_id = wes.id
        WHERE
            wsi.`value` != ''
            <if test="nameKey != null and nameKey !=''">
                AND wei.name_key = #{nameKey}
            </if>
            <if test="list != null and list.size() > 0">
                AND wes.equipment_detail_id IN
                <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        GROUP BY
            wsi.id
        ORDER BY
            wsi.update_date DESC
    </select>

    <select id="queryInitAlarm" resultType="com.yeejoin.amos.fas.business.vo.EquipmentSpecificIndexVo">
        SELECT
            concat(wes.id) as id,
        	concat(wes.id) as equipmentSpecificId,
            wed.`name`,
            wes.`code`,
            wei.name_key,
            wei.`name` AS equipmentIndexName,
            wsi.`value`
        FROM
            `wl_equipment_specific_index` wsi
            LEFT JOIN wl_equipment_index wei ON wsi.equipment_index_id = wei.id
            LEFT JOIN wl_equipment_specific wes ON wsi.equipment_specific_id = wes.id
            LEFT JOIN wl_equipment_detail wed ON wed.id = wes.equipment_detail_id
        <where>
            <if test="value != null and value != ''">
                AND wsi.`value` = #{value}
            </if>
            <if test="list != null and list.length > 0">
                AND
                <foreach collection="list" item="item" index="index" open="(" close=")" separator="OR">
                    wei.name_key = #{item}
                </foreach>
            </if>
        </where>
        GROUP BY
            wsi.equipment_specific_id
        ORDER BY
            wsi.update_date DESC
    </select>
    <select id="getInitAlarm" resultType="com.yeejoin.amos.fas.business.vo.EquipmentSpecificIndexVo">
        SELECT
        concat(wes.id) as id,
        concat(wes.id) as equipmentSpecificId,
        wed.`name`,
        wes.`code`,
        wei.name_key,
        wei.`name` AS equipmentIndexName,
        wsi.`value`,
        'equip' AS type
        FROM
        `wl_equipment_specific_index` wsi
        LEFT JOIN wl_equipment_index wei ON wsi.equipment_index_id = wei.id
        LEFT JOIN wl_equipment_specific wes ON wsi.equipment_specific_id = wes.id
        LEFT JOIN wl_equipment_detail wed ON wed.id = wes.equipment_detail_id
        where
       	wei.is_iot  = 1 
           <if test="value != null and value != ''">
               AND wsi.`value` = #{value}
           </if>
           <if test="list != null and list.length > 0">
               AND
               <foreach collection="list" item="item" index="index" open="(" close=")" separator="OR">
                   wei.name_key = #{item}
               </foreach>
           </if>
        GROUP BY
        wsi.equipment_specific_id
        ORDER BY
        wsi.update_date DESC
    </select>
</mapper>