<?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.IScIndexMapper">

    <!--工程统计-->
    <select id="proStatusStatistics" resultType="java.util.Map">
        SELECT sd.dict_code AS id,
               sd.dict_name AS name,
               IFNULL(a.num,0) AS num
        FROM sys_dict sd
        LEFT JOIN (
                SELECT tp.status,
                COUNT(tp.status) AS num
                FROM tb_project tp
                LEFT JOIN sys_dict sd ON tp.status = sd.dict_code AND sd.dict_code = 0
                GROUP BY sd.dict_code
        ) a ON a.status = sd.dict_code
        WHERE sd.p_code = 1200 AND sd.del_flag = 0
    </select>
    <!--地图风险点-->
    <select id="riskStatistics" resultType="com.securitycontrol.entity.screen.vo.MapRiskVo">
        SELECT tcm.class_id AS classId,
               tcm.lon,
               tcm.lat,
               tcm.bid_name AS bidName,
               tcm.team_name AS teamName,
               tcm.risk_level AS riskLevel,
               tcm.work_content AS workContent,
               tcm.bid_code AS bidCode,
               tcm.work_manager AS workManager
        FROM t_class_metting tcm
        WHERE tcm.work_day = CURRENT_DATE AND tcm.del_flag = 0
    </select>
    <!--施工质量-->
    <select id="constrQuality" resultType="com.securitycontrol.entity.screen.vo.ConstrQuality">
        SELECT tte.team_id AS teamId,
               tp.pro_name AS bidName,
               tp.bid_code AS bidCode,
               twt.team_name AS teamName,
               twt.team_leader AS teamLeader,
               tte.score AS constrQuality
        FROM tb_team_eval tte
        LEFT JOIN tb_work_team twt on tte.team_id = twt.team_id
        LEFT JOIN tb_project tp ON tp.bid_code = twt.bid_code AND tp.del_flag = 0
        WHERE tte.del_falge = 0
    </select>
    <!--告警提醒-->
    <select id="alarmReminder" resultType="java.util.Map">
        SELECT tw.warn_content AS warningContent,
               tp.pro_name AS proName,
               tw.warn_id AS warningId
        FROM tb_warn tw
        LEFT JOIN tb_project tp ON tw.bid_code = tp.bid_code AND tp.del_flag = 0
        WHERE tw.warn_time BETWEEN CONCAT(CURRENT_DATE, ' 00:00:00') AND CONCAT(CURRENT_DATE, ' 23:59:59')
        ORDER BY tw.warn_time DESC
    </select>
    <!--环境监测分析-->
    <select id="environmentDetection" resultType="java.util.Map">
        SELECT COUNT(IF(tdd.mode_name = '空气质量' and tdv.is_warn = 0,1,NULL)) AS aqiNormalNum,
               COUNT(IF(tdd.mode_name = '空气质量' and tdv.is_warn = 1,1,NULL)) AS aqiErrorNum,
               COUNT(IF(tdd.mode_name = '噪声水平' and tdv.is_warn = 0,1,NULL)) AS dbNormalNum,
               COUNT(IF(tdd.mode_name = '噪声水平' and tdv.is_warn = 1,1,NULL)) AS dbErrorNum,
               COUNT(IF(tdd.mode_name = '灰尘浓度' and tdv.is_warn = 0,1,NULL)) AS hcNormalNum,
               COUNT(IF(tdd.mode_name = '灰尘浓度' and tdv.is_warn = 1,1,NULL)) AS hcErrorNum
        FROM tb_bd_device tbd
        INNER JOIN sys_dict sd ON tbd.devic_type = sd.dict_code AND sd.del_flag = 0 AND sd.dict_code = '1804'
        INNER JOIN tb_area ta ON tbd.area_id = ta.area_id AND ta.del_flag = 0 AND ta.area_type = '0'
        LEFT JOIN tb_device_detail tdd ON tbd.device_id = tdd.device_id AND tdd.del_flag = 0
        LEFT JOIN tb_device_value tdv ON tdd.id = tdv.attribute_id
        WHERE tbd.del_flage = 0
    </select>
    <!--设备状态 目前只查询边带设备-->
    <select id="deviceStatus" resultType="java.util.Map">
        SELECT tp.bid_code AS bidCode,
               tp.pro_name AS proName,
               IF(tbd.status = '801', '1', '0') AS status
        FROM tb_bd_device tbd
        INNER JOIN tb_pro_bd tpb ON tpb.id = tbd.bd_id AND tpb.del_flag = 0
        INNER JOIN tb_project tp on tpb.bid_code = tp.bid_code AND tp.del_flag = 0
        WHERE tbd.del_flage = 0
    </select>
    <!--工程安全隐患分析-->
    <select id="potentialSafetyHazard" resultType="java.util.Map">
        SELECT sb.org_id AS orgId,
               sb.city_name AS orgName,
               IFNULL(a.num,0) AS planNum,
               0 AS dangerNum
        FROM sys_build sb
        LEFT JOIN (
            SELECT build_no,COUNT(build_no) AS num
            FROM jj_week_plan
            WHERE start_date BETWEEN #{startTime} AND #{endTime} AND end_date BETWEEN #{startTime} AND #{endTime}
            GROUP BY build_no
        )a ON sb.org_id = a.build_no
    </select>
    <!--取班组人员/获取站班会人员-->
    <select id="getPersonnel" resultType="java.lang.Integer">
        SELECT COUNT(*)
        FROM t_class_metting_people
        WHERE create_day = CURRENT_DATE
    UNION ALL
        SELECT COUNT(*)
        FROM t_team_people
        WHERE del_falge = '0'
    </select>
    <!--设备 在线/不在线 数量 边带子设备/设备-->
    <select id="allDeviceStatus" resultType="java.util.Map">
        SELECT tbd.device_id AS id, IF(tbd.status = '801', '1', '0') AS status
        FROM tb_bd_device tbd
        WHERE tbd.del_flage = 0
    UNION ALL
        SELECT td.device_id AS id,
               IF(on_line = '1', '1', '0') AS status
        FROM tb_device td
        WHERE td.del_flag = 0
    </select>
    <!--效率分析（工程进度分析）-->
    <select id="efficiencyAnalysis" resultType="java.util.Map">
        SELECT tp.bid_code AS bidCode,
               tp.pro_name AS proName,
               tgp.plan_id AS planId,
               tgp.gx_weight AS gxWeight,
               IFNULL(tgp.plan_progress,'0') AS planProgress
        FROM tb_project tp
        LEFT JOIN tb_gx_plan tgp ON tp.bid_code = tgp.bid_code AND tgp.del_flag = 0
        WHERE tp.del_flag = 0
    </select>
    <!--获取地市隐患数-->
    <select id="getDangerNum" resultType="java.util.Map">
        SELECT jwp.bid_no AS bidCode,
               IFNULL(a.num,0) AS num
        FROM jj_week_plan jwp
        LEFT JOIN (
            SELECT tw.bid_code,COUNT(tw.bid_code) AS num
            FROM tb_warn tw
            WHERE tw.warn_time BETWEEN #{params.startTime} AND #{params.endTime}
            GROUP BY tw.bid_code
        ) a ON jwp.bid_no = a.bid_code
        WHERE jwp.start_date BETWEEN #{params.startTime} AND #{params.endTime} AND jwp.end_date BETWEEN #{params.startTime} AND #{params.endTime}
          AND jwp.build_no = #{orgId}
    </select>
</mapper>