<?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.securitycontrol.screen.mapper.PersonnelControlMapper">

    <!--人员管控-穿戴装备-->
    <select id="getWearEquipmentList" resultType="com.securitycontrol.entity.screen.vo.PersonnelControlVo">
        SELECT
            tbd.device_type AS deviceType,
            su.user_name AS userName,
            tbd.device_name AS deviceName,
            trd.status AS status
            FROM t_team_people ttp
                JOIN sys_user su ON ttp.user_id = su.user_id
                JOIN tb_work_team twt ON ttp.team_id = twt.team_id
                JOIN tb_user_bind_cap tuc ON ttp.user_id = tuc.people_id
                JOIN tb_device tbd ON tuc.device_id = tbd.device_id
                JOIN tb_rel_device trd ON tbd.device_id = trd.device_id
        WHERE twt.bid_code = #{bidCode}
    </select>
    <!--人员管控-人员列表-->
    <select id="getPersonnelList" resultType="com.securitycontrol.entity.screen.vo.PersonnelControlVo">
        SELECT
        twt.team_id AS id,
        twt.bid_code AS parentId,
        twt.team_name AS title
        FROM
        tb_work_team twt
        WHERE
        twt.bid_code = #{bidCode}

        UNION ALL

        SELECT
        ttp.user_id AS id,
        ttp.team_id AS parentId,
        CONCAT(ttp.user_name, ' (', ttp.phone, ')') AS title
        FROM
        t_team_people ttp
        JOIN tb_work_team twt ON ttp.team_id = twt.team_id
        WHERE
        twt.bid_code = #{bidCode}
        <if test="keyWord != null and keyWord != ''">
            AND CONCAT(ttp.user_name, ' (', ttp.phone, ')') LIKE CONCAT('%', #{keyWord}, '%')
        </if>
    </select>
    <!--人员管控-人员运动趋预警-->
    <select id="getPersonnelMovementList" resultType="com.securitycontrol.entity.screen.vo.PersonnelControlVo">
        SELECT
            tw.warn_time AS warningTime,
            tw.warn_content AS warningContent
        FROM
            tb_warn tw
        WHERE
            tw.warn_type = 1806
            AND tw.bid_code = #{bidCode}
            AND DATE(tw.warn_time) = CURDATE();
    </select>
</mapper>