<?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.yx.face.dao.UserControlEarlyWarningListLogDao">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.yx.face.model.entity.UserControlEarlyWarningListLog">
        <id column="id" property="id" />
        <result column="update_time" property="updateTime" />
        <result column="create_time" property="createTime" />
        <result column="admin_id" property="adminId" />
        <result column="status" property="status" />
        <result column="face_log_id" property="faceLogId" />
        <result column="control_early_warning_id" property="controlEarlyWarningId" />
    </resultMap>
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, update_time, create_time, admin_id, status, face_log_id, control_early_warning_id
    </sql>
    <update id="updateEarlyWarningConfirm">
        UPDATE user_control_early_warning_list_log SET  status = #{status}  WHERE
        id = #{id}
    </update>

    <select id="getListLog" resultType="com.yx.face.model.vo.UserEarlyWarningLogVO">
        SELECT
            a.id,
            b.face_time AS faceTime,
            c.`name` AS snName,
            b.`name` AS `name`,
            b.cardid AS idNumber,
            b.photo,
            a.control_unit AS controlUnit,
            a.control_phone AS controlPhone,
            a.control_name AS controlName
        FROM
            user_control_early_warning_list_log AS a
                LEFT JOIN face_log AS b ON a.face_log_id = b.id
                LEFT JOIN face_device AS c ON b.device_sn = c.sn
                LEFT JOIN admin e on e.id =a.admin_id
        <where>
            and a.`status` = 1
            <if test="type == 2">
                and e.province_id = #{provinceId}
                and e.type =5
            </if>
            <if test="type == 3">
                and e.province_id = #{provinceId}
                and e.type =5
                and e.tag_id = #{tagId}
            </if>
            <if test="type == 4">
                and e.city_id = #{cityId}
                and e.type = 5
                and e.tag_id = #{tagId}
            </if>
            <if test="type == 5">
                and e.id =#{id}
            </if>
        </where>
        ORDER BY a.id DESC

    </select>
    <select id="getListLogPageInfo" resultType="com.yx.face.model.vo.UserEarlyWarningLogVO">
        SELECT
        a.id,
        b.face_time AS faceTime,
        c.`name` AS snName,
        b.`name` AS `name`,
        b.cardid AS idNumber,
        b.photo,
        a.control_unit AS controlUnit,
        a.control_phone AS controlPhone,
        a.control_name AS controlName,
        a.status
        FROM
        user_control_early_warning_list_log AS a
        LEFT JOIN face_log AS b ON a.face_log_id = b.id
        LEFT JOIN face_device AS c ON b.device_sn = c.sn
        LEFT JOIN admin e on e.id =a.admin_id
        <where>
            <if test="adminVo.type == 2">
                and e.province_id = #{adminVo.provinceId}
                and e.type =5
            </if>
            <if test="adminVo.type == 3">
                and e.province_id = #{adminVo.provinceId}
                and e.type =5
                and e.tag_id = #{adminVo.tagId}
            </if>
            <if test="adminVo.type == 4">
                and e.city_id = #{adminVo.cityId}
                and e.type = 5
                and e.tag_id = #{adminVo.tagId}
            </if>
            <if test="adminVo.type == 5">
                and e.id =#{adminVo.id}
            </if>
            <if test="qu.status != 0 ">
                and a.status =#{qu.status}
            </if>
            <if test="qu.name != '' and qu.name != null ">
                and b.name  like concat('%',#{qu.name},'%')
            </if>
            <if test="qu.idNumber != '' and qu.idNumber != null ">
                and b.cardid =#{qu.idNumber}
            </if>

            <if test="qu.controlUnit != null and qu.controlUnit != '' ">
                and a.control_unit like concat('%',#{qu.controlUnit},'%')
            </if>
            <if test="qu.controlPhone != null and qu.controlPhone != '' ">
                and a.control_phone =#{qu.controlPhone}
            </if>
            <if test="qu.controlName != null and qu.controlName != '' ">
                and a.control_name  like concat('%',#{qu.controlName},'%')
            </if>
            <if test="qu.startTime != null and qu.startTime != '' and qu.endTime != null and qu.endTime != '' ">
                AND  <![CDATA[ b.face_time >= #{qu.startTime}]]>
                AND  <![CDATA[ b.face_time < #{qu.endTime}]]>
            </if>
            <if test="qu.startTime == '' and qu.endTime != null and qu.endTime != '' ">
                AND  <![CDATA[ b.face_time <= #{qu.endTime}]]>
            </if>
        </where>
        ORDER BY a.id DESC
    </select>
    <select id="getUserEarlyWarningLogExcel" resultType="com.yx.face.model.excel.UserEarlyWarningLogExcel">
        SELECT
        a.id,
        b.face_time AS faceTime,
        c.`name` AS snName,
        b.`name` AS `name`,
        b.cardid AS idNumber,
        b.photo,
        a.control_unit AS controlUnit,
        a.control_phone AS controlPhone,
        a.control_name AS controlName,
        a.status
        FROM
        user_control_early_warning_list_log AS a
        LEFT JOIN face_log AS b ON a.face_log_id = b.id
        LEFT JOIN face_device AS c ON b.device_sn = c.sn
        LEFT JOIN admin e on e.id =a.admin_id
        <where>
            <if test="adminVo.type == 2">
                and e.province_id = #{adminVo.provinceId}
                and e.type =5
            </if>
            <if test="adminVo.type == 3">
                and e.province_id = #{adminVo.provinceId}
                and e.type =5
                and e.tag_id = #{adminVo.tagId}
            </if>
            <if test="adminVo.type == 4">
                and e.city_id = #{adminVo.cityId}
                and e.type = 5
                and e.tag_id = #{adminVo.tagId}
            </if>
            <if test="adminVo.type == 5">
                and e.id =#{adminVo.id}
            </if>
            <if test="qu.status != 0 ">
                and a.status =#{qu.status}
            </if>
            <if test="qu.name != '' and qu.name != null ">
                and b.name =#{qu.name}
            </if>
            <if test="qu.idNumber != '' and qu.idNumber != null ">
                and b.cardid =#{qu.idNumber}
            </if>

            <if test="qu.controlUnit != null and qu.controlUnit != '' ">
                and a.control_unit like concat('%',#{qu.controlUnit},'%')
            </if>
            <if test="qu.controlPhone != null and qu.controlPhone != '' ">
                and a.control_phone =#{qu.controlPhone}
            </if>
            <if test="qu.controlName != null and qu.controlName != '' ">
                and a.control_name =#{qu.controlName}
            </if>
            <if test="qu.startTime != null and qu.startTime != '' and qu.endTime != null and qu.endTime != '' ">
                AND  <![CDATA[ b.face_time >= #{qu.startTime}]]>
                AND  <![CDATA[ b.face_time < #{qu.endTime}]]>
            </if>
            <if test="qu.startTime == '' and qu.endTime != null and qu.endTime != '' ">
                AND  <![CDATA[ b.face_time <= #{qu.endTime}]]>
            </if>
        </where>
        ORDER BY a.id DESC
    </select>

</mapper>
