<?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.background.mapper.ITodayTaskMapper">

    <!--获取当日任务列表-->
    <select id="getToDayTaskLists" resultType="com.securitycontrol.entity.background.vo.TodayTaskVo">
        SELECT tcm.class_id AS classId,
               tcm.bid_code AS bidCode,
               tcm.pro_code AS proCode,
               tcm.risk_level AS riskLevel,
                CASE tcm.sg_status WHEN '1' THEN '开工'
                WHEN '2' THEN '暂停' WHEN '3' THEN '完工' END AS sgStatus,
               tcm.bid_name AS bidName,
               tcm.sgdw,
               tcm.jldw,
               tcm.work_content AS workContent,
               tcm.work_manager AS workManager,
               tcm.puid AS puid,
               tcm.ticket_no AS ticketNo,
               sb.city_name AS org,
               tcm.bid_code AS bidCode,
               tcm.sign_code AS signCode,
               tcmc.user_id AS checkUserId
        FROM t_class_metting tcm
        LEFT JOIN t_class_metting_check tcmc ON tcm.class_id = tcmc.class_id AND tcmc.create_day BETWEEN #{startTime} AND #{endTime}
        LEFT JOIN sys_build sb ON tcm.org = sb.org_id
        WHERE tcm.work_day BETWEEN #{startTime} AND #{endTime} AND tcm.del_flag = '0'
        <if test="keyWord !=null and keyWord !=''">
            AND (
                INSTR(tcm.bid_name,#{keyWord}) > 0 OR
                INSTR(tcm.ticket_no,#{keyWord}) > 0 OR
                INSTR(tcm.sgdw,#{keyWord}) > 0 OR
                INSTR(tcm.jldw,#{keyWord}) > 0 OR
                INSTR(tcm.work_manager,#{keyWord}) > 0
            )
        </if>
        <if test="orgCode!=null and orgCode!=''">
            AND sb.org_id IN (
            <foreach collection="orgCodeList" item="item" separator=",">
                #{item}
            </foreach>
            )
        </if>
        <if test="riskLevel!=null and riskLevel!=''">
            AND tcm.risk_level IN (
            <foreach collection="riskLevelList" item="item" separator=",">
                #{item}
            </foreach>
            )
        </if>
    </select>
    <!--查询督查人-->
    <select id="getCheckUser" resultType="java.lang.String">
        SELECT login_name FROM sys_user where user_id = #{checkUserId}
    </select>
    <!--站班会详情-->
    <select id="getClassDetail" resultType="java.util.Map">
        SELECT tcm.class_id AS classId,
               tcm.ticket_id AS ticketId,
               tcm.ticket_no AS ticketNo,
               CASE tcm.sg_status WHEN '1' THEN '开工'
                                  WHEN '2' THEN '暂停' WHEN '3' THEN '完工' END AS sgStatus,
               tcm.bid_name AS bidName,
               tcm.sgdw,
               tcm.jldw,
               tcm.work_day AS workDay,
               tcm.start_time AS startTime,
               tcm.work_content AS workContent,
               tcm.work_manager AS workManager,
               tcm.safety_manager AS safetyManager,
               tcm.work_manager_phone AS workManagerPhone,
               tcm.controll,
               tcm.changes,
               tcm.current_control AS currentControl
        FROM t_class_metting tcm
        WHERE tcm.class_id = #{classId}
    </select>
    <!--施工人员-->
    <select id="getWorkPeopleLists" resultType="java.util.Map">
        SELECT id,tcmp.user_name AS userName
        FROM t_class_metting_people tcmp
        WHERE tcmp.class_id = #{classId}
    </select>
    <!--球机在线时长-->
    <select id="getBallTimeList" resultType="com.securitycontrol.entity.background.vo.DeviceUpDownVo">
        select tdu.puid,
               tdu.up_time AS upTime,
               tdu.down_time downTime
        FROM t_device_updown tdu
        left join t_class_metting tcm on tdu.puid=tcm.puid AND tcm.del_flag = '0'
        <where>
            <if test="classId!=null and classId!=''">
                AND tcm.class_id=#{classId}
            </if>
            <if test="workDay!=null and workDay!=''">
                AND tdu.up_time BETWEEN CONCAT(#{workDay},' 00:00:00') AND CONCAT(#{workDay},' 23:59:59')
            </if>
        </where>
    </select>

</mapper>