<?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.bonus.app.mapper.WarnReminderMapper">
    <!--查询预警提醒列表违章识别信息-->
    <select id="getViolationInfoList" resultType="com.bonus.app.entity.ViolationInfoEntity" >
        select
        tp.pro_name proName,td.id devId,td.dev_name devName,tw.warn_time warnTime,tw.warn_content warnContent,
        case
        WHEN  tw.people_type=0 then tpe.name
        WHEN  tw.people_type=1 then tlu.name
        ELSE ''
        END AS userName,
        sfs.file_path AS filePath,
        sfs.id AS fileId
        from tb_warn tw
        left join tb_device td on tw.dev_id = td.id and td.dev_type = 'ball' and td.del_flag = 0
        left join tb_people tpe on tw.user_id=tpe.id and tw.people_type=0 and tpe.name is not null and tpe.name!=''
        left join tb_ls_user tlu on tw.user_id=tlu.id and tw.people_type=1 and tlu.name is not null and tlu.name!=''
        left join tb_project tp on tw.pro_id = tp.id and tp.del_flag = 0
        left join sys_file_source sfs ON tw.dev_id = sfs.source_id AND sfs.source_type = 8 AND sfs.del_flag = 0
        <where>
            tw.dev_type = 1 and tw.warn_type = 2
            <if test="proId!=null and proId!=''">
                and tw.pro_id = #{proId}
            </if>
        </where>
        order by tw.warn_time  desc
    </select>

    <!--查询预警提醒列表设备预警信息-->
    <select id="getDeviceInfoList" resultType="com.bonus.app.entity.DeviceWarnEntity" >
        select
        case
        WHEN  tw.dev_type=1 then tdd.dict_label
        WHEN  tw.dev_type=0 then '手环'
        ELSE ''
        END AS deviceTypeName,
        tw.warn_time warnTime,tw.warn_content warnContent,
        case
        WHEN  tw.dev_type=1 then td.dev_name
        WHEN  tw.dev_type=0 then tb.sh_code
        ELSE ''
        END AS devName
        from tb_warn tw
        left join tb_device td on tw.dev_id = td.id and tw.dev_type = 1 and td.dev_type !='ball' and td.del_flag = 0
        left join tb_bracelet tb on tw.dev_id = tb.id and tw.dev_type = 0 and tb.del_flag = 0
        left join sys_dict_data tdd on tdd.dict_value=td.dev_type AND tdd.dict_type='sys_device_type'
        <where>
                tw.warn_type = 1
            <if test="proId!=null and proId!=''">
                and tw.pro_id = #{proId}
            </if>
        </where>
        order by  tw.warn_time DESC
    </select>

</mapper>