<?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.bonus.system.mapper.SelectMapper">

    <!--获取班组下拉选-->
    <select id="getTeamList" resultType="com.bonus.system.domain.vo.SysSelectVo">
        SELECT team_id AS id,
               CONCAT(team_name,'(',team_name,')') AS name
        FROM t_work_team WHERE del_flag = 0 AND team_status = 0
    </select>
    <!--工程下拉选-->
    <select id="getProList" resultType="com.bonus.system.domain.vo.SysSelectVo">
        SELECT tp.id,tp.pro_name AS name
        FROM tb_project tp WHERE tp.del_flag = 0
        <if test="roleCode!='administrators' and roleCode!='depart'">
            AND tp.depart_id = -1
        </if>
        <if test="roleCode=='depart'">
            AND tp.depart_id = #{departId}
        </if>
    </select>

    <!--所属项目部下拉选-->
    <select id="getEngineeringList" resultType="com.bonus.system.domain.vo.SysSelectVo">
        SELECT tpd.id,tpd.depart_name AS name
        FROM tb_project_depart tpd WHERE tpd.del_flag = 0
    </select>

    <!--班组下拉选-->
    <select id="getTeamLists" resultType="java.util.Map">
        SELECT twt.team_id AS teamId,
               twt.team_name AS teamName,
               twt.team_leader AS teamLeader,
               tp.pro_name AS proName,
               twt.pro_id AS proId
        FROM t_work_team twt
        LEFT JOIN tb_project tp on twt.pro_id = tp.id AND tp.del_flag = 0
        WHERE twt.del_flag = 0 AND twt.team_status = 0
        <if test="roleCode!='administrators' and roleCode!='depart'">
            AND tp.depart_id = -1
        </if>
        <if test="roleCode=='depart'">
            AND tp.depart_id = #{departId}
        </if>
    </select>
    <!--根据工程获取杆塔下拉选-->
    <select id="getPowerLists" resultType="com.bonus.system.domain.vo.SysSelectVo">
        SELECT id,power_name AS name
        FROM tb_project_power
        <where>
            <if test="proId!=null">
                pro_id = #{proId}
            </if>
            AND del_flag = 0
        </where>
    </select>
    <!--根据班组id获取班组所属人员-->
    <select id="getTeamPeople" resultType="com.bonus.system.domain.vo.SysSelectVo">
        SELECT id,CONCAT(name,'-',phone) AS name FROM tb_people WHERE team_id = #{teamId}
    </select>

    <!--根据杆塔ID获取领用吊装预警设备的班组-->
    <select id="getTeamListsByDzDevice" resultType="com.bonus.system.domain.vo.SysSelectVo">
        SELECT DISTINCT twt.team_id AS id,
               twt.team_name AS name
        FROM tb_device td
        LEFT JOIN tb_dev_ly tdl ON td.id = tdl.dev_id
        LEFT JOIN t_work_team twt ON tdl.team_id = twt.team_id AND twt.del_flag = 0
        WHERE tdl.gt_id = #{towerId} AND td.dev_type IN('lift_warn','elec_induction') AND td.del_flag = 0
    </select>
    <!--获取线路属性-->
    <select id="getLineStats" resultType="com.bonus.system.domain.vo.SysSelectVo">
        SELECT dict_name AS name,
               dict_type AS id
        FROM sys_dict_type WHERE dict_type IN('communication','direct_current') AND status = '0'
    </select>
    <!--获取线路属性所属的电压等级-->
    <select id="getVoltageLevelByLineStats" resultType="com.bonus.system.domain.vo.SysSelectVo">
        SELECT dict_label AS name,
               dict_value AS id
        FROM sys_dict_data WHERE dict_type = #{id}
    </select>
    <!--根据字典编码获取下拉选-->
    <select id="getDicts" resultType="com.bonus.system.domain.vo.SysSelectVo">
        SELECT dict_label AS name,
               dict_value AS id
        FROM sys_dict_data WHERE dict_type = #{id}
    </select>
</mapper>