<?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.boot.module.tzs.api.mapper.ElevatorMapper">
    <select id="queryElevatorList" resultType="com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorWlInfoDto">
        select
        te.sequence_nbr sequenceNbr,
        concat(te.province,te.city,te.district) area,
        te.device_category category,
        te.register_code registerCode,
        te.rescue_code rescueCode,
        te.address ,
        te.start_date happenTime,
        te.type ,
        case te.deal_status
        when '0' then '处置完成'
        when '1' then '故障发生'
        when '2' then '发出通知'
        when '3' then '处置响应'
        when '4' then '处置到场'
        when '5' then '误报'
        ELSE '' END dealStatus,
        '电梯' categoryName,
        '立信远大科技有限公司' IotServiceProvider
        from  tz_elevator_alarm te
        where 1=1
        <if test="address != null and address != ''">
            and te.address like  CONCAT(CONCAT('%',#{address}),'%')
        </if>
        <if test="registerCode != null and registerCode != ''">
            and te.register_code like  CONCAT(CONCAT('%',#{registerCode}),'%')
        </if>
        <if test="rescueCode != null and rescueCode != ''">
            and te.rescue_code like  CONCAT(CONCAT('%',#{rescueCode}),'%')
        </if>
        <if test="type != null and type != ''">
            and te.type = #{type}
        </if>
        <if test="dealStatus != null and dealStatus != ''">
            and te.deal_status = #{dealStatus}
        </if>
        <if test="sequenceNbr != null and sequenceNbr != ''">
            and te.sequence_nbr = #{sequenceNbr}
        </if>
        group by register_code
        order by start_date DESC limit #{current},#{size}
    </select>

    <select id="queryElevatorListDetails" resultType="com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorWlInfoDto">
        select
        te.sequence_nbr sequenceNbr,
        concat(te.province,te.city,te.district) area,
        te.device_category category,
        te.register_code registerCode,
        te.rescue_code rescueCode,
        te.address ,
        te.start_date happenTime,
        te.type ,
        case te.deal_status
        when '0' then '处置完成'
        when '1' then '故障发生'
        when '2' then '发出通知'
        when '3' then '处置响应'
        when '4' then '处置到场'
        when '5' then '误报'
        ELSE '' END dealStatus,
        '电梯' categoryName,
        '立信远大科技有限公司' IotServiceProvider
        from  tz_elevator_alarm te
        where 1=1
        <if test="sequenceNbr != null and sequenceNbr != ''">
            and te.sequence_nbr = #{sequenceNbr}
        </if>
    </select>

    <select id="queryElevatorListCount" resultType="int">
        select count(1) from (
        select
        te.sequence_nbr
        from  tz_elevator_alarm te
        where 1=1
        group by register_code  order by start_date desc
        ) te
    </select>

</mapper>
