<?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.system.base.mapper.ISelectMapper">

    <!--组织机构树-->
    <select id="getOrgTree" resultType="com.securitycontrol.entity.system.vo.TreeNode">
        SELECT org_id AS id,
        p_id AS parentId,
        org_name AS label
        FROM sys_org
        WHERE del_flag = 0
    </select>
    <!--角色下拉选-->
    <select id="getRoleLists" resultType="com.securitycontrol.entity.system.vo.SelectVo">
        SELECT role_id AS id,
        role_name AS name
        FROM sys_role
        WHERE del_flag = 0
        ORDER BY role_sort
    </select>
    <!--菜单树-->
    <select id="getMenuTree" resultType="com.securitycontrol.entity.system.vo.TreeNode">
        SELECT menu_id AS id,
        p_id AS parentId,
        menu_name AS label,
        menu_type AS level
        FROM sys_menu
        WHERE del_flag = 0
    </select>
    <!--字典下拉选-->
    <select id="getDictList" resultType="com.securitycontrol.entity.system.vo.TreeNode">
        select dict_code as id, dict_name label, p_code AS parentId
        from sys_dict
        WHERE del_flag = 0
        <if test="code!=null and code!=''">
            and p_code=#{code}
        </if>
        ORDER BY dict_sort desc
    </select>
    <!--建管单位下拉选-->
    <select id="getBuildLists" resultType="com.securitycontrol.entity.system.vo.SelectVo">
        SELECT city_name AS name,
        org_id AS orgId
        FROM sys_build
    </select>
    <!--字典表下拉选-->
    <select id="getDictLists" resultType="com.securitycontrol.entity.system.vo.SelectVo">
        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 = #{param} AND sd.del_flag = 0
        ORDER BY sd2.dict_sort
    </select>
    <!--杆塔下拉选-->
    <select id="getTowerLists" resultType="com.securitycontrol.entity.system.vo.SelectVo">
        <if test="proType == 1">
            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 = #{param} AND sd.del_flag = 0
            ORDER BY sd2.dict_sort
        </if>
        <if test="proType == 2">
            SELECT gt_id AS id,
            gt_name AS name
            FROM t_pro_gt WHERE bid_code = #{param} AND del_flag = 0
        </if>

    </select>
    <!--班组下拉选-->
    <select id="getTeamLists" resultType="com.securitycontrol.entity.system.vo.SelectVo">
        SELECT team_id AS id,
               team_name AS name,
               team_leader AS teamLeader,
               team_leader_phone AS teamLeaderPhone
        FROM tb_work_team
        <where>
            <if test="param!=null and param!=''">
               AND bid_code = #{param}
            </if>
        </where>

    </select>
    <!--工程下拉选-->
    <select id="getProLists" resultType="com.securitycontrol.entity.system.vo.SelectVo">
        SELECT bid_code AS id,
               pro_name AS name,
               pro_type AS proType
        FROM tb_project
        WHERE del_flag = 0
    </select>
    <!--区域列表下拉选-->
    <select id="getAreaLists" resultType="com.securitycontrol.entity.system.vo.SelectVo">
        SELECT area_id AS id,
               area_name AS name
        FROM tb_area
        <where>
            bid_code = #{bidCode} AND del_flag = 0
            <if test="gtId !=null and gtId!=''">
                AND gt_id = #{gtId}
            </if>
        </where>
    </select>
    <!--边带下拉选-->
    <select id="getBdLists" resultType="com.securitycontrol.entity.system.vo.SelectVo">
        SELECT id,bd_name AS name,bid_code AS bidCode,gt_id AS gtId
        FROM tb_pro_bd
        <where>
            del_flag = 0
            <if test="bidCode!=null and bidCode !=''">
                AND bid_code = #{bidCode}
            </if>
        </where>
    </select>
    <!--工程下拉选-->
    <select id="getProList" resultType="com.securitycontrol.entity.system.vo.SelectVo">
        select  pro.bid_code bidCode,pro.pro_name name
                from  tb_project pro
                LEFT JOIN sys_build sb on sb.org_id=pro.org
                where  pro.del_flag =0
                <if test="proType!=null and proType!=''">
                    and  pro.pro_type=#{proType}
                </if>
                <if test="orgId!=null and orgId!=''">
                    and  pro.org=#{orgId}
                </if>
                <if test="cityName!=null and cityName!=''">
                    and  sb.city_name=#{cityName}
                </if>
    </select>
    <select id="getSelectLists" resultType="com.securitycontrol.entity.system.vo.SelectVo">
        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 = '999' AND sd.del_flag = 0
        ORDER BY sd2.dict_sort
    </select>

    <select id="getGtLists" resultType="com.securitycontrol.entity.system.vo.SelectVo">
        SELECT gt_id AS gtId,gt_name AS name FROM t_pro_gt tpg
        WHERE tpg.bid_code = #{bidCode}
    </select>
</mapper>