<?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.bracelet.mapper.ConsControlMapper">
    <!--添加验证时间配置项-->
    <insert id="addConfig" keyProperty="configId" useGeneratedKeys="true">
        INSERT INTO tb_config(config_type,config_id) VALUES (
            #{configType},null
        )
    </insert>
    <!--添加验证时间配置内容项-->
    <insert id="addConfigItems">
        INSERT INTO tb_config_items
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="val != null and val != ''">config_time,</if>
            id,
            <if test="params.configId != null">config_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="val != null and val != ''">#{val},</if>
            null,
            <if test="params.configId != null">#{params.configId},</if>
        </trim>
    </insert>
    <!--添加近电感应设备配置属性-->
    <insert id="addJdConfigData">
        INSERT INTO tb_jd_config(id,dev_id,config_type,voltage_level,distance) VALUES
        <foreach collection="configItems" separator="," item="item">
            (
            null,#{devId},#{item.configType},#{item.voltageLevel},#{item.distance}
            )
        </foreach>
    </insert>
    <!--删除验证时间配置项-->
    <delete id="delConfig">
        DELETE FROM tb_config
    </delete>
    <!--删除验证时间配置内容项-->
    <delete id="delConfigItems">
        DELETE FROM tb_config_items
    </delete>
    <!--删除近电配置项-->
    <delete id="delJdConfig">
        DELETE FROM tb_jd_config WHERE dev_id = #{devId}
    </delete>

    <!--获取球机设备列表 项目部权限-->
    <select id="getBallDeviceLists" resultType="com.bonus.common.entity.bracelet.vo.BallTreeVo">
    SELECT * FROM (
          SELECT tp.id,
                 tp.pro_name AS label,
                 '0' AS devCode,
                 '0' AS devIndex,
                  0 AS parentId,
                  tp.depart_id AS departId,
                  0 AS devStatus,
                  tp.create_time AS orderTime
          FROM tb_project tp
          WHERE tp.del_flag = 0
    UNION ALL
          SELECT
              td.id,
              CONCAT(tpe.name,'-',tpe.phone) AS label,
              td.dev_code AS devCode,
              IFNULL(td.dev_index,0) AS devIndex,
              tdl.pro_id AS parentId,
              tp.depart_id AS departId,
              IFNULL(td.dev_status,0) AS devStatus,
              tdl.ly_time AS orderTime
          FROM tb_device td
          LEFT JOIN tb_dev_ly tdl ON td.id = tdl.dev_id
          LEFT JOIN tb_people tpe ON tpe.id = tdl.ly_user AND tpe.del_flag = 0
          LEFT JOIN tb_project tp ON tdl.pro_id = tp.id AND tp.del_flag = 0
          WHERE td.dev_type = 'ball' AND td.del_flag = 0 AND tdl.ly_user IS NOT NULL
    ) a
    <where>
        <if test="roleCode!='administrators' and roleCode!='depart'">
            a.id = -1
        </if>
        <if test="roleCode=='depart'">
           AND a.departId = #{departId}
        </if>
        AND a.departId IS NOT NULL
    </where>
    ORDER BY a.orderTime DESC
    </select>
    <!--获取球机违章识别内容-->
    <select id="getBallWarnLists" resultType="com.bonus.common.entity.bracelet.vo.WarnInfoVo">
        SELECT tw.warn_content AS warnContent,
        tw.warn_time AS warnTime,
        td.dev_name AS devName,
        sfs.file_path AS base64Url
        FROM tb_warn tw
        LEFT JOIN tb_device td ON tw.dev_id = td.id AND td.del_flag = 0 AND td.dev_type = #{devType}
        LEFT JOIN sys_file_source sfs ON tw.id = sfs.source_id AND sfs.source_type = 8 AND sfs.del_flag = 0
        LEFT JOIN tb_project tp ON tp.id = tw.pro_id AND tp.del_flag = 0
        WHERE tw.dev_type = 1 AND tw.warn_type = 2
            <if test="roleCode!='administrators' and roleCode!='depart'">
                AND tp.depart_id = -1
            </if>
            <if test="roleCode=='depart'">
                AND tp.depart_id = #{departId}
            </if>
            AND tp.depart_id IS NOT NULL
        ORDER BY tw.create_time DESC
    </select>
    <!--预警信息-->
    <select id="getWarnLists" resultType="com.bonus.common.entity.bracelet.vo.WarnInfoVo">
        SELECT tw.warn_content AS warnContent,
               tw.warn_time AS warnTime,
               td.dev_name AS devName,
               sdd.dict_label AS devTypeName,
               tp.depart_id AS departId
        FROM tb_warn tw
        LEFT JOIN tb_project tp ON tp.id = tw.pro_id AND tp.del_flag = 0
        LEFT JOIN tb_device td ON tw.dev_id = td.id AND td.del_flag = 0
        LEFT JOIN sys_dict_data sdd ON td.dev_type = sdd.dict_value AND sdd.dict_type = 'sys_device_type'
        WHERE tw.dev_type = 1 AND tw.warn_type = 2
        <if test="roleCode!='administrators' and roleCode!='depart'">
            AND tp.depart_id = -1
        </if>
        <if test="roleCode=='depart'">
            AND tp.depart_id = #{departId}
        </if>
        AND tp.depart_id IS NOT NULL
        ORDER BY tw.warn_time
    </select>
    <!--人员管控-人员树-->
    <select id="getPersonsTree" resultType="com.bonus.common.entity.bracelet.vo.PersonTreeVo">
        SELECT * FROM (
          SELECT DISTINCT tp.id,
                 tp.pro_name AS label,
                 tp.depart_id AS departId,
                 0 AS parentId,
                 1 AS level,
                 0 AS isTeamLeader,
                 0 AS isWarn,
                 0 AS type,
                 0 AS devId,
                 0 AS gtId,
                 0 AS proId,
                 0 AS teamId
          FROM tb_project tp
          LEFT JOIN tb_sh_box tsb ON tp.id = tsb.pro_id AND tsb.del_flag = 0
          LEFT JOIN tb_bracelet tb ON tsb.id = tb.box_id AND tb.del_flag = 0
          WHERE tp.del_flag = 0 AND tb.bid_id IS NOT NULL
        UNION ALL
          SELECT DISTINCT CONCAT('tower','-',tpp.id),
                 tpp.power_name AS label,
                 tp.depart_id AS departId,
                 tpp.pro_id AS parentId,
                 2 AS level,
                 0 AS isTeamLeader,
                 0 AS isWarn,
                 0 AS type,
                 0 AS devId,
                 0 AS gtId,
                 0 AS proId,
                 0 AS teamId
          FROM tb_project_power tpp
          LEFT JOIN tb_project tp ON tpp.pro_id = tp.id AND tp.del_flag = 0
          LEFT JOIN tb_sh_box tsb ON tpp.id = tsb.gt_id AND tsb.del_flag = 0
          LEFT JOIN tb_bracelet tb ON tsb.id = tb.box_id AND tb.del_flag = 0
          WHERE tpp.del_flag = 0 AND tb.bid_id IS NOT NULL
        UNION ALL
          SELECT DISTINCT CONCAT('team','-',twt.team_id) AS id,
                 twt.team_name AS label,
                 tp.depart_id AS departId,
                 CONCAT('tower','-',tsb.gt_id) AS parentId,
                 3 AS level,
                 0 AS isTeamLeader,
                 0 AS isWarn,
                 0 AS type,
                 0 AS devId,
                 0 AS gtId,
                 0 AS proId,
                 0 AS teamId
          FROM tb_sh_box tsb
          LEFT JOIN tb_bracelet tb ON tsb.id = tb.box_id AND tb.del_flag = 0
          LEFT JOIN t_work_team twt ON tsb.team_id = twt.team_id AND twt.del_flag = 0
          LEFT JOIN tb_project tp ON twt.pro_id = tp.id AND tp.del_flag = 0
          WHERE tsb.del_flag = 0 AND tsb.team_id IS NOT NULL AND tb.bid_id IS NOT NULL
        UNION ALL
          SELECT tpe.id,
                 CONCAT(tpe.name,'-',tpe.phone) AS label,
                 tp.depart_id AS departId,
                 CONCAT('team','-',tpe.team_id) AS parentId,
                 4 AS level,
                 IF(twt.team_leader_id = tpe.id,1,0) AS isTeamLeader,
                 0 AS isWarn,
                 0 AS type,
                 tb.id AS devId,
                 tsb.gt_id AS gtId,
                 tsb.pro_id AS proId,
                 tpe.team_id AS teamId
          FROM tb_bracelet tb
          LEFT JOIN tb_sh_box tsb ON tb.box_id = tsb.id AND tsb.del_flag = 0
          LEFT JOIN tb_people tpe ON tb.bid_id = tpe.id AND tpe.del_flag = 0
          LEFT JOIN t_work_team twt ON tpe.team_id = twt.team_id AND twt.del_flag = 0
          LEFT JOIN tb_project tp ON twt.pro_id = tp.id AND tp.del_flag = 0
          WHERE tb.peopel_type = 0  AND tb.del_flag = 0 AND tb.bid_id IS NOT NULL
        UNION ALL
            SELECT tlu.id,
            CONCAT(tlu.name,'-',tlu.phone) AS label,
            tp.depart_id AS departId,
            CONCAT('team','-',tlu.team_id) AS parentId,
            4 AS level,
            0 AS isTeamLeader,
            0 AS isWarn,
            1 AS type,
            tb.id AS devId,
            tsb.gt_id AS gtId,
            tsb.pro_id AS proId,
            tlu.team_id AS teamId
        FROM tb_bracelet tb
        LEFT JOIN tb_sh_box tsb ON tb.box_id = tsb.id AND tsb.del_flag = 0
        LEFT JOIN tb_ls_user tlu ON tb.bid_id = tlu.id
        LEFT JOIN t_work_team twt ON tlu.team_id = twt.team_id AND twt.del_flag = 0
        LEFT JOIN tb_project tp ON twt.pro_id = tp.id AND tp.del_flag = 0
        WHERE tb.peopel_type = 1 AND tb.del_flag = 0 AND tb.bid_id IS NOT NULL
    ) a
    <where>
        <if test="roleCode!='administrators' and roleCode!='depart'">
            a.departId = -1
        </if>
        <if test="roleCode=='depart'">
            AND a.departId = #{departId}
        </if>
        AND a.departId IS NOT NULL
        ORDER BY a.isTeamLeader DESC
    </where>
    </select>
    <!--获取今日施工班组/班组施工人数-->
    <select id="getWorkNum" resultType="java.lang.Integer">
        SELECT COUNT(DISTINCT tb.box_id)
        FROM tb_bracelet tb
        LEFT JOIN tb_sh_box tsb ON tb.box_id = tsb.id AND tsb.del_flag = 0
        LEFT JOIN tb_project tp ON tsb.pro_id = tp.id AND tp.del_flag = 0
        WHERE tb.bid_id IS NOT NULL AND tb.del_flag = 0 AND tsb.gt_id = #{id}
        <if test="roleCode!='administrators' and roleCode!='depart'">
            AND tp.depart_id = -1
        </if>
        <if test="roleCode=='depart'">
            AND tp.depart_id = #{departId}
        </if>
        AND tp.depart_id IS NOT NULL
    UNION ALL
        SELECT COUNT(*)
        FROM tb_bracelet tb
        LEFT JOIN tb_sh_box tsb ON tb.box_id = tsb.id AND tsb.del_flag = 0
        LEFT JOIN tb_project tp ON tsb.pro_id = tp.id AND tp.del_flag = 0
        WHERE tb.bid_id IS NOT NULL AND tb.del_flag = 0 AND tsb.gt_id = #{id}
        <if test="roleCode!='administrators' and roleCode!='depart'">
            AND tp.depart_id = -1
        </if>
        <if test="roleCode=='depart'">
            AND tp.depart_id = #{departId}
        </if>
        AND tp.depart_id IS NOT NULL
    </select>
    <!--安全帽绑定信息-->
    <select id="getSafetyHatInfo" resultType="java.util.Map">
        SELECT td.id,
               tpe.name,
               tpe.phone,
               td.dev_name AS devName,
               td.dev_code AS devCode,
               td.dev_index AS devIndex,
               td.dev_status AS devStatus
        FROM tb_device td
        LEFT JOIN tb_dev_ly tdl ON td.id = tdl.dev_id
        LEFT JOIN tb_project tp ON tdl.pro_id = tp.id AND tp.del_flag = 0
        LEFT JOIN tb_people tpe ON tdl.ly_user = tpe.id AND tpe.del_flag = 0
        WHERE td.dev_type = 'aqm' AND tdl.ly_user IS NOT NULL
        <if test="roleCode!='administrators' and roleCode!='depart'">
            AND tp.depart_id = -1
        </if>
        <if test="roleCode=='depart'">
            AND tp.depart_id = #{departId}
        </if>
        AND tp.depart_id IS NOT NULL
    </select>
    <!--获取杆塔坐标-->
    <select id="getTowerInfo" resultType="com.bonus.common.entity.bracelet.vo.PersonControlVo$TowerInfo">
        SELECT id,
               power_name AS powerName,
               lon,
               lat
        FROM tb_project_power
        WHERE id = #{id}
    </select>
    <!--获取施工距离-->
    <select id="getDistance" resultType="java.lang.String">
        SELECT dict_value
        FROM sys_dict_data
        WHERE dict_type = 'sys_sg_distance'
        LIMIT 1
    </select>
    <!--获取绑定手环的施工班组人员、临时人员信息-->
    <select id="getWorkPersonInfo" resultType="com.bonus.common.entity.bracelet.vo.PersonControlVo$WorkPersonInfo">
        SELECT tpe.id,tpe.name,tpe.phone,tb.id AS devId,0 AS type
        FROM tb_bracelet tb
        LEFT JOIN tb_people tpe ON tb.bid_id = tpe.id AND tpe.del_flag = 0
        WHERE tb.peopel_type = 0 AND tpe.team_id = #{teamId}
    UNION ALL
        SELECT tls.id,tls.name,tls.phone,tb.id AS devId,1 AS type
        FROM tb_bracelet tb
        LEFT JOIN tb_ls_user tls ON tb.bid_id = tls.id
        WHERE tb.peopel_type = 1 AND tls.team_id = #{teamId}
    </select>
    <!--获取已绑手环的信息-->
    <select id="getShDeviceInfo" resultType="com.bonus.common.entity.bracelet.vo.PersonControlVo$BraceletInfo">
        SELECT id ,
               data_name AS dataName,
               data_val AS dataVal,
               data_unit AS dataUnit,
               data_code AS dataCode,
               data_time AS dataTime
        FROM tb_dev_details
        WHERE dev_id=#{devId} AND dev_type = 0 AND del_flag = 0
    </select>
    <!--根据杆塔获取班组人员-已绑定手环-->
    <select id="getTeamPersonByTower" resultType="com.bonus.common.entity.bracelet.vo.TeamPeopleTreeVo">
        SELECT 0 AS id,
               '在施班组及人员' AS label,
               -1 AS parentId,
               null AS shCode,
               null AS devCode,
               null AS userType
    UNION ALL
        SELECT twt.team_id AS id,
               twt.team_name AS label,
               0 AS parentId,
               null AS shCode,
               null AS devCode,
               null AS userType
        FROM tb_sh_box sbx
        INNER JOIN t_work_team twt on twt.team_id=sbx.team_id AND twt.del_flag = 0
        WHERE sbx.gt_id = #{id} AND sbx.del_flag = 0
    UNION ALL
        SELECT tpe.id,
               CONCAT(tpe.name,'-',tpe.phone) AS label,
               tpe.team_id AS parentId,
               tb.sh_code AS shCode,
               IFNULL(tb.dev_code,'') AS devCode,
               0 AS userType
        FROM tb_bracelet tb
        LEFT JOIN tb_sh_box sbx ON tb.box_id=sbx.id AND sbx.del_flag = 0
        LEFT JOIN tb_people tpe ON tpe.id= tb.bid_id AND tpe.del_flag = 0
        WHERE sbx.gt_id = #{id} AND tb.peopel_type = 0 AND tb.bid_id IS NOT NULL AND sbx.del_flag = 0
    UNION ALL
        SELECT tlu.id,
               CONCAT(tlu.name,'-',tlu.phone) AS label,
               tlu.team_id AS parentId,
               tb.sh_code AS shCode,
               IFNULL(tb.dev_code,'') AS devCode,
               1 AS userType
        FROM tb_bracelet tb
        LEFT JOIN tb_sh_box sbx ON tb.box_id=sbx.id AND sbx.del_flag = 0
        LEFT JOIN tb_ls_user tlu ON tlu.id= tb.bid_id
        WHERE sbx.gt_id = #{id} AND tb.peopel_type = 1 AND sbx.del_flag = 0
    </select>
    <!--获取自动验证配置-->
    <select id="getCheckConfig" resultType="com.bonus.common.entity.bracelet.vo.CheckConfigVo">
        SELECT tc.config_type AS configType,
               tc.config_id AS configId,
               tci.config_time AS time
        FROM tb_config tc
        LEFT JOIN tb_config_items tci on tc.config_id = tci.config_id
        ORDER BY config_time
    </select>
    <!--获取人员详情数据-->
    <select id="getPersonInfoData" resultType="com.bonus.common.entity.bracelet.vo.PersonDetailVo">
        <if test="type == 0">
            SELECT tp.id,
                   tp.name,
                   tp.phone,
                   twt.team_name AS teamName,
                   tp.id_card AS idCard,
                   tb.face_status AS faceStatus,
                   tb.id AS braceletId,
                   sbx.gt_id AS towerId,
                   tb.sh_code AS shCode,
                   IFNULL(tp.mj_code,'--') AS mjCode
            FROM tb_people tp
            LEFT JOIN tb_bracelet tb ON tp.id = tb.bid_id AND tb.peopel_type = 0
            LEFT JOIN tb_sh_box sbx ON tb.box_id=sbx.id AND sbx.del_flag = 0
            LEFT JOIN t_work_team twt ON tp.team_id = twt.team_id
            WHERE tp.id = #{id}
        </if>
        <if test="type == 1">
            SELECT tlu.id,
                tlu.name,
                tlu.phone,
                twt.team_name AS teamName,
                tlu.id_card AS idCard,
                tb.face_status AS faceStatus,
                tb.id AS braceletId,
                sbx.gt_id AS towerId,
                tb.sh_code AS shCode,
                '--' AS mjCode
            FROM tb_ls_user tlu
            LEFT JOIN tb_bracelet tb ON tlu.id = tb.bid_id AND tb.peopel_type = 1
            LEFT JOIN tb_sh_box sbx ON tb.box_id=sbx.id AND sbx.del_flag = 0
            LEFT JOIN t_work_team twt ON tlu.team_id = twt.team_id
            WHERE tlu.id = #{id}
        </if>
    </select>
    <!--获取人员绑定安全帽信息-->
    <select id="getSafetyHat" resultType="com.bonus.common.entity.bracelet.vo.PersonDetailVo$SafetyHat">
        SELECT td.id AS devId,
               td.dev_code AS devCode,
               td.dev_index AS devIndex,
               td.dev_status AS devStatus,
               td.dev_name AS name
        FROM tb_device td
        LEFT JOIN tb_dev_ly tdl ON td.id = tdl.dev_id
        WHERE td.dev_type = 'aqm' AND tdl.ly_user = #{id} AND td.del_flag = 0
    </select>
    <!--获取手环的预警信息-->
    <select id="getWarnInfo" resultType="com.bonus.common.entity.bracelet.vo.PersonDetailVo$WarnInfo">
        SELECT tw.warn_content AS warnContent,
               tw.warn_time AS warnTime
        FROM tb_warn tw
        WHERE dev_id = #{id} AND dev_type = 0
        <if test="startTime!=null and startTime!='' and endTime!=null and endTime!=''">
            AND DATE_FORMAT(tw.warn_time, '%Y-%m-%d') BETWEEN #{startTime} AND #{endTime}
        </if>
    </select>
    <!--人员历史轨迹-->
    <select id="getHistoryGj" resultType="java.util.Map">
        SELECT GROUP_CONCAT(data_value) AS value
        FROM tb_dev_his tdh
        WHERE tdh.dev_id = #{id} AND tdh.dev_type = 0 AND tdh.data_name IN
        <foreach collection="dataName" separator="," open="(" close=")" item="item">
            #{item}
        </foreach>
        <if test="startTime!=null and startTime!=''">
            AND DATE_FORMAT(tdh.data_time, '%Y-%m-%d') BETWEEN #{startTime} AND #{startTime}
        </if>
        GROUP BY tdh.data_type
    </select>
    <!--吊装预警设备列表-->
    <select id="getDzWarnList" resultType="com.bonus.common.entity.app.vo.DevInfoVo">
        SELECT twt.team_leader AS teamLeader,
               twt.leader_phone AS leaderPhone,
               td.dev_code AS devCode,
               td.id AS devId,
               td.dev_index AS devIndex,
               td.dev_name AS devName,
               twt.team_name AS teamName,
               tp.pro_name AS proName
        FROM tb_device td
        LEFT JOIN tb_dev_ly tdl ON td.id = tdl.dev_id
        LEFT JOIN tb_project tp ON tp.id = tdl.pro_id AND tp.del_flag = 0
        LEFT JOIN t_work_team twt ON tdl.team_id = twt.team_id AND twt.del_flag = 0
        WHERE td.dev_type = #{devType}
        <if test="keyWord!=null and keyWord!=''">
            AND (
                INSTR(td.dev_name,#{keyWord}) > 0 OR
                INSTR(tp.pro_name,#{keyWord}) > 0 OR
                INSTR(twt.team_leader,#{keyWord}) > 0
            )
        </if>
        <if test="roleCode!='administrators' and roleCode!='depart'">
            AND tp.depart_id = -1
        </if>
        <if test="roleCode=='depart'">
            AND tp.depart_id = #{departId}
        </if>
        AND tp.depart_id IS NOT NULL
        AND td.del_flag = 0
        ORDER BY tdl.ly_time DESC
    </select>
    <!--近电感应设备预警信息-->
    <select id="getJdWarnList" resultType="com.bonus.common.entity.app.vo.DevWarnVo">
        SELECT td.dev_name AS devName,
        tw.warn_time AS warnTime,
        tw.warn_content AS warnContent
        FROM tb_warn tw
        LEFT JOIN tb_device td ON tw.dev_id = td.id
        LEFT JOIN tb_dev_ly tdl ON td.id = tdl.dev_id
        LEFT JOIN tb_project tp ON tp.id = tdl.pro_id AND tp.del_flag = 0
        WHERE td.dev_type = #{devType}
        <if test="startTime!=null and startTime!='' and endTime!=null and endTime!=''">
            AND DATE_FORMAT(tw.warn_time, '%Y-%m-%d') BETWEEN #{startTime} AND #{endTime}
        </if>
        <if test="roleCode!='administrators' and roleCode!='depart'">
            AND tp.depart_id = -1
        </if>
        <if test="roleCode=='depart'">
            AND tp.depart_id = #{departId}
        </if>
        AND tp.depart_id IS NOT NULL
        AND tw.dev_type = 1 AND tw.del_flag = 0
        ORDER BY tw.warn_time DESC
    </select>
    <!--查询近电感应设备-->
    <select id="getJdList" resultType="com.bonus.common.entity.app.vo.DevInfoVo">
        SELECT td.dev_code AS devCode,
               td.id AS devId,
               td.dev_index AS devIndex,
               td.dev_name AS devName
        FROM tb_device td
        LEFT JOIN tb_dev_ly tdl ON td.id = tdl.dev_id
        LEFT JOIN tb_project tp ON tp.id = tdl.pro_id AND tp.del_flag = 0
        WHERE td.dev_type = #{devType}
        <if test="roleCode!='administrators' and roleCode!='depart'">
            AND tp.depart_id = -1
        </if>
        <if test="roleCode=='depart'">
            AND tp.depart_id = #{departId}
        </if>
        AND tp.depart_id IS NOT NULL
        AND td.del_flag = 0
    </select>
    <!--查询近电感应设备的电量-->
    <select id="getElectricQuantity" resultType="java.lang.String">
        SELECT data_val FROM tb_dev_details WHERE dev_id = #{devId} AND data_code = #{dataCode} AND dev_type = 1 LIMIT 1
    </select>
    <!--查询近电感应设备配置-->
    <select id="getConfigJdDevice" resultType="com.bonus.common.entity.app.vo.JdConfigVo$ConfigItems">
        SELECT * FROM (
          SELECT tdc.id,
                 tdc.config_type AS configType,
                 sdt.dict_name AS configTypeName,
                 tdc.distance AS distance,
                 tdc.voltage_level AS voltageLevel,
                 sdd.dict_label AS voltageLevelName
          FROM tb_jd_config tdc
          LEFT JOIN sys_dict_type sdt ON tdc.config_type = sdt.dict_type AND sdt.status = '0'
          LEFT JOIN sys_dict_data sdd ON tdc.voltage_level = sdd.dict_value AND sdd.status = '0' AND sdd.dict_type = 'communication'
          WHERE tdc.dev_id = #{devId} AND tdc.config_type = 'communication'
          UNION ALL
          SELECT tdc.id,
                 tdc.config_type AS configType,
                 sdt.dict_name AS configTypeName,
                 tdc.distance AS distance,
                 tdc.voltage_level AS voltageLevel,
                 sdd.dict_label AS voltageLevelName
          FROM tb_jd_config tdc
          LEFT JOIN sys_dict_type sdt ON tdc.config_type = sdt.dict_type AND sdt.status = '0'
          LEFT JOIN sys_dict_data sdd ON tdc.voltage_level = sdd.dict_value AND sdd.status = '0' AND sdd.dict_type = 'direct_current'
          WHERE tdc.dev_id = #{devId} AND  tdc.config_type = 'direct_current'
    ) a
    ORDER BY a.id
    </select>

</mapper>