<?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.MarqueeDataMapper">

<select id="selectAll" resultType="java.util.Map">
    SELECT
    wlesal.id,
    wlesal.org_code,
    wlesal.equipment_specific_id AS fireEquipmentId,
    wles.equipment_detail_id AS equipDetailId,
    wles.CODE AS fireEquipmentCode,
    wles.system_id AS systemId,
    IF
    (
    wles.CODE IS NULL,
    wlesal.equipment_specific_name,
    concat( wlesal.equipment_specific_name, '(', wles.CODE, ')' )) AS fireEquipmentName,
    concat( wlesal.equipment_specific_name, wlesal.equipment_specific_index_name ) AS alamContent,
    IF
    ( wlesal.confirm_type IS NULL, '未处理', '已处理' ) handleStatus,
    IF
    ( wlesal.clean_time IS NOT NULL, '已消除', '未消除' ) cleanStatus,
    confirm_type AS handleType,
    wlesal.equipment_index_id AS fireEquipmentIndexId,
    wlesal.equipment_specific_index_key AS fireEquipmentSpecificIndexKey,
    wlesal.equipment_specific_index_name AS fireEquipmentSpecificIndexName,
    wles.warehouse_structure_id AS buildId,
    we.img AS imgUrl,
    CASE
    wlesal.equipment_specific_index_value
    WHEN 'true' THEN
    '是'
    WHEN 'false' THEN
    '否' ELSE wlesal.equipment_specific_index_value
    END AS fireEquipmentPointValue,
    wlesal.type AS typeCode,
    ( SELECT type_name FROM wl_signal_classify sc WHERE sc.type_code = wlesal.type LIMIT 1 ) AS type,
    date_format( wlesal.create_date, '%Y-%m-%d %H:%i:%s' ) createDate,
    CONCAT_WS( ' ', wles.position, wled.area ) AS warehouseStructureName,
    /*告警列表拼接详细地址*/
    (
    SELECT
    group_concat( fet.`name` )
    FROM
    f_equipment_fire_equipment AS fefe
    LEFT JOIN f_equipment AS fet ON fet.id = fefe.equipment_id
    WHERE
    fefe.fire_equipment_id = wlesal.equipment_specific_id
    ) AS equipmentName,
    wlesal.equipment_specific_name AS equipmentSpecificName,
    wles.position,
    null messageId,
    null messageType,
    null isRead
    FROM wl_equipment_specific_alarm_log wlesal
    LEFT JOIN wl_equipment_specific wles ON wlesal.equipment_specific_id = wles.id
    LEFT JOIN wl_equipment_detail wled ON wles.equipment_detail_id = wled.id
    LEFT JOIN wl_equipment we ON wled.equipment_id = we.id
    <where>
        <if test="param.cleanStatus != null and param.cleanStatus != '' and param.cleanStatus == 2">
            wlesal.clean_time IS NULL
        </if>
        <if test="param.bizOrgCode != null and param.bizOrgCode != ''">AND
            wles.biz_org_code like concat (#{param.bizOrgCode},'%')
        </if>
    </where>
--     UNION ALL
--     SELECT
--     equipment_specific_id id,
--     NULL org_code,
--     null fireEquipmentId,
--     NULL equipDetailId,
--     NULL fireEquipmentCode,
--     null systemId,
--     NULL fireEquipmentName,
--     NULL alamContent,
--     NULL handleStatus,
--     NULL cleanStatus,
--     NULL handleType,
--     NULL fireEquipmentIndexId,
--     NULL fireEquipmentSpecificIndexKey,
--     type fireEquipmentSpecificIndexName,
--     NULL buildId,
--     NULL imgUrl,
--     NULL fireEquipmentPointValue,
--     NULL typeCode,
--     NULL type,
--     date_format( create_date, '%Y-%m-%d %H:%i:%s' ) createDate,
--     NULL warehouseStructureName,
--     NULL equipmentName,
--     NAME equipmentSpecificName,
--     position,
--     id messageId,
--     message_type messageType,
--     is_read isRead
--     FROM
--     wl_marquee_data
--     WHERE
--     is_read = '0'
    ORDER BY createDate DESC
    </select>
</mapper>
