<?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.bracelet.mapper.WarnHistoryMapper">
    <!--设备领用列表-->
    <select id="getWarnLists" resultType="com.bonus.common.entity.bracelet.vo.WarnInfoVo">
        select * from(
        select sdd.dict_label as devTypeName,tb.dev_name as devName,tw.warn_time as warnTime,tw.warn_content as warnContent
        from tb_warn tw
        left join tb_device tb on tw.dev_id = tb.id and tb.del_flag = 0
        left join sys_dict_data  sdd on sdd.dict_value = tb.dev_type and sdd.dict_type = 'sys_device_type'
        where  tw.dev_type = 1 and tw.del_flag = 0
        <if test="devTypeName!=null and devTypeName!='' and devTypeName != 'shx'">
            AND tb.dev_type = #{devTypeName}
        </if>
        <if test="devTypeName!=null and devTypeName!='' and devTypeName == 'shx'">
            AND tb.id = -1
        </if>
        union all
        select '手环箱' as warnType,tbb.sh_code as deviceName,tw.warn_time as warnTime,tw.warn_content as warnContent
        from tb_warn tw
        left join tb_bracelet tbb on tw.dev_id = tbb.id and tbb.del_flag = 0
        where tw.dev_type = 0 and tw.del_flag = 0
        <if test="devTypeName!=null and devTypeName!='' and devTypeName != 'shx'">
            AND tbb.id = -1
        </if>
        ) a
        <where>
            <if test="devName!=null and devName!=''">
                AND INSTR(a.devName,#{devName}) > 0
            </if>
            <if test="warnContent!=null and warnContent!=''">
                AND INSTR(a.warnContent,#{warnContent}) > 0
            </if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                and date_format(a.warnTime,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                and date_format(a.warnTime,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
        </where>
    </select>
</mapper>