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

    <!--项目简介-->
    <select id="getProBrief" resultType="com.securitycontrol.entity.system.base.vo.ProVo">
        SELECT tp.pro_id AS proId,
               tp.sign_code AS signCode,
               tp.bid_code AS bidCode,
               tp.pro_code AS proCode,
               tp.pro_name AS proName,
               sb.city_name AS org,
               tp.plan_start_time AS planStartTime,
               tp.plan_end_time AS planEndTime,
               tp.jl_unit AS jlUnit,
               tp.sg_unit AS sgUnit,
               tp.pro_brief AS proBrief,
               tp.pro_type AS proType
        FROM tb_project tp
        LEFT JOIN sys_build sb ON tp.org = sb.org_id
        WHERE tp.bid_code = #{bidCode} AND del_flag = 0
    </select>
    <!-- 获取工程图片/平面图 -->
    <select id="getFiles" resultType="com.securitycontrol.entity.system.vo.ResourceFileVo">
        SELECT id AS resourceId,
               file_id AS fileId
        FROM tb_resource_file
        WHERE source_id = #{proId} AND source_type = '工程图片'
    </select>
    <!--当前登录人绑定的工程-->
    <select id="getProsByUser" resultType="java.util.Map">
        SELECT tp.pro_name AS proName,
                tp.bid_code AS bidCode
        FROM tb_project tp
        <if test="id!=null and id!='' and roleCode == 'roleCode'">
            INNER JOIN tb_user_pro tup ON tp.bid_code = tup.bid_cod AND tup.del_flag = '0' AND tup.user_id = #{id}
        </if>
        WHERE tp.del_flag = 0
        <if test="orgId != '' and orgId!=null and roleCode == 'city'">
            AND tp.org = #{orgId}
        </if>
    </select>
    <!--人员管理-->
    <select id="getPersonnelList" resultType="com.securitycontrol.entity.background.vo.HumanManageVo">
        SELECT ttp.user_name AS userName,
               ttp.phone,
               ttp.id_number AS idNumber,
               IF(ttp.status = '1','在场','离场') AS status
        FROM t_team_people ttp
        LEFT JOIN tb_work_team twt on twt.team_id = ttp.team_id
        WHERE twt.bid_code = #{bidCode} AND ttp.del_falge = '0'
        ORDER BY cratet_time
    </select>
    <!--车辆管理-->
    <select id="getCarList" resultType="com.securitycontrol.entity.background.vo.VehicleVo">
        SELECT car_num AS carNum,
               tc.phone,
               tc.user_name AS userName
        FROM tb_car tc
        WHERE tc.bid_code = #{bidCode} AND del_flag = 0
    </select>
    <!--项目进度-->
    <select id="getProBasicInfo" resultType="java.util.Map">
        SELECT tp.bid_code AS bidCode,
               tp.pro_name AS proName,
               tp.plan_start_time AS planStartTime,
               tp.plan_end_time AS planEndTime,
               tgp.plan_id AS planId,
               tgp.gx_weight AS gxWeight,
               a.gxProgress
        FROM tb_project tp
        LEFT JOIN tb_gx_plan tgp ON tp.bid_code = tgp.bid_code AND tgp.del_flag = 0
        LEFT JOIN (
            SELECT tpp.plan_id AS planId,
                   tpp.gx_progress AS gxProgress
            FROM tb_project_progress tpp
            INNER JOIN (SELECT MAX( create_time ) AS create_time FROM tb_project_progress GROUP BY plan_id) tpp2 ON tpp.create_time = tpp2.create_time
        )a ON tgp.plan_id = a.planId
        WHERE tp.del_flag = 0 AND tp.bid_code = #{bidCode}
    </select>
    <!--告警-->
    <select id="alarmLists" resultType="java.util.Map">
        SELECT tw.warn_id AS id,
               DATE_FORMAT(tw.warn_time, '%Y-%m-%d %H:%i:%s') AS warnTime,
               tw.warn_content AS warnContent,
               IF(status = '1','已处理','未处理') AS status
        FROM tb_warn tw
        WHERE tw.bid_code = #{bidCode} AND tw.warn_time BETWEEN CONCAT(CURRENT_DATE,' 00:00:00') AND CONCAT(CURRENT_DATE,' 23:59:59')
        ORDER BY warn_time DESC,status ASC
    </select>
    <!--工程工序计划-->
    <select id="getProGxPlan" resultType="java.util.Map">
        SELECT tp.bid_code AS bidCode,
               tgp.gx_weight AS gxWeight,
               a.gxProgress,
               tp.pro_type AS proType,
               tgp.gx_id AS gxId,
               tgp.plan_start_time AS planStartTime,
               tgp.plan_end_time AS planEndTime,
               tgp.start_time AS startTime,
               tgp.end_time AS endTime
        FROM tb_gx_plan tgp
        LEFT JOIN tb_project tp ON tp.bid_code = tgp.bid_code AND tp.del_flag = 0
        LEFT JOIN (
            SELECT tpp.plan_id AS planId,
                   tpp.gx_progress AS gxProgress
            FROM tb_project_progress tpp
            INNER JOIN (SELECT MAX( create_time ) AS create_time FROM tb_project_progress GROUP BY plan_id) tpp2 ON tpp.create_time = tpp2.create_time
        )a ON tgp.plan_id = a.planId
        WHERE tp.bid_code = #{bidCode} AND tgp.del_flag = 0
    </select>
    <!--获取工序或杆塔名称-->
    <select id="getGtOrGxName" resultType="java.lang.String">
        <if test="proType=='线路'">
            SELECT gt_name FROM t_pro_gt tpg WHERE bid_code =#{bidCode} AND gt_id = #{gxId}
        </if>
        <if test="proType=='变电'">
            SELECT sd2.dict_code AS id,
                   sd2.dict_name AS name
            FROM sys_dict sd
            LEFT JOIN sys_dict sd2 ON sd.dict_code = sd2.p_code AND sd2.del_flag = 0
            WHERE sd.dict_code = '400' AND sd2.dict_code = #{gxId} AND sd.del_flag = 0
        </if>
    </select>
</mapper>