TDeviceInfoMapper.xml 16.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
<?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.zehong.system.mapper.TDeviceInfoMapper">

    <resultMap type="TDeviceInfo" id="TDeviceInfoResult">
        <result property="deviceId"    column="device_id"    />
        <result property="deviceName"    column="device_name"    />
        <result property="deviceCode"    column="device_code"    />
        <result property="deviceAddr"    column="device_addr"    />
        <result property="deviceModel"    column="device_model"    />
        <result property="deviceType"    column="device_type"    />
        <result property="beyondEnterpriseId"    column="beyond_enterprise_id"    />
        <result property="beyondEnterpriseName"    column="beyond_enterprise_name"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="iconUrl"    column="icon_url"    />
        <result property="linkman"    column="linkman"    />
        <result property="phone"    column="phone"    />
        <result property="installationTime"    column="installation_time"    />
        <result property="inspectionTime"    column="inspection_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

<!--关联设备map-->
    <resultMap type="TDeviceInfoS" id="TDeviceInfoResultS">
        <result property="relationDeviceDetailId"    column="relation_device_detail_id"    />
        <result property="relationDeviceId"    column="relation_device_id"    />
        <result property="deviceName"    column="device_name"    />
        <result property="deviceModel"    column="device_model"    />
        <result property="deviceType"    column="device_type"    />
        <result property="iotNo"    column="iot_no"    />
        <result property="detectionMedium"    column="detection_medium"    />
        <result property="remarksn"    column="remarks"    />
    </resultMap>

    <sql id="selectTDeviceInfoVo">
        select a.device_id, a.device_name, a.device_code, a.device_addr, a.device_model,
        (CASE  a.device_type WHEN '1' THEN '阀井' WHEN '2' THEN '调压箱'WHEN '3' THEN '巡检员' WHEN '4' THEN '视频' end) as  device_type ,
        a.beyond_enterprise_id, a.longitude, a.latitude, a.icon_url, a.linkman, a.phone, a.installation_time, a.inspection_time, a.create_by, a.create_time, a.update_by, a.update_time, a.is_del, a.remarks
        ,b.enterprise_name as beyond_enterprise_name
        from t_device_info a left join t_enterprise_info b on a.beyond_enterprise_id=b.enterprise_id
    </sql>

    <select id="selectTDeviceInfoList" parameterType="TDeviceInfo" resultMap="TDeviceInfoResult">
        <include refid="selectTDeviceInfoVo"/>
        <where>
            a.is_del='0'
            <if test="beyondEnterpriseId != null  and beyondEnterpriseId != -2"> and beyond_enterprise_id = #{beyondEnterpriseId}</if>
            <if test="deviceName != null  and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if>
            <if test="deviceCode != null  and deviceCode != ''"> and device_code = #{deviceCode}</if>
            <if test="deviceAddr != null  and deviceAddr != ''"> and device_addr = #{deviceAddr}</if>
        </where>
60
        order by a.device_id desc
61
    </select>
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
    <select id="queryBasicInforByNameForBigWindows" resultType="map">
        SELECT
            device_id AS id,
            device_name AS NAME,
            CONCAT( '[[', longitude, ', ', latitude, ']]' ) AS coordinates,
            device_type AS type
        FROM
            t_device_info
        WHERE
          <if test="name != null  and name != ''"> device_name like concat('%', #{name}, '%') AND</if>
          longitude IS NOT NULL
          AND latitude IS NOT NULL UNION
        SELECT
            site_station_id AS id,
            site_station_name AS NAME,
            CONCAT( '[[', longitude, ', ', latitude, ']]' ) AS coordinates,
            '3' AS type
        FROM
            t_site_station_info
        WHERE
          <if test="name != null  and name != ''"> site_station_name like concat('%', #{name}, '%') AND</if>
          longitude IS NOT NULL
          AND latitude IS NOT NULL UNION
        SELECT
            user_id AS id,
            nick_name AS NAME,
            CONCAT( '[[', longitude, ', ', latitude, ']]' ) AS coordinates,
            CASE
                user_type
                WHEN '1' THEN
                    '4'
                WHEN '2' THEN
                    '5'
                WHEN '3' THEN
                    '6'
                END AS type
        FROM
            t_detector_user
        WHERE
          <if test="name != null  and name != ''"> nick_name like concat('%', #{name}, '%') AND</if>
          longitude IS NOT NULL
          AND latitude IS NOT NULL UNION
        SELECT
            video_manager_id AS id,
            video_name AS NAME,
            CONCAT( '[[', longitude, ', ', latitude, ']]' ) AS coordinates,
            '7' AS type
        FROM
            t_video_manager
        WHERE
          <if test="name != null  and name != ''"> video_name like concat('%', #{name}, '%') AND</if>
          longitude IS NOT NULL
          AND latitude IS NOT NULL UNION
        SELECT
            user_id AS id,
            nick_name AS NAME,
            CONCAT( '[[', longitude, ', ', latitude, ']]' ) AS coordinates,
            '8' AS type
        FROM
            t_yehuaqi_user
        WHERE
          <if test="name != null  and name != ''"> nick_name like concat('%', #{name}, '%') AND</if>
          longitude IS NOT NULL
          AND latitude IS NOT NULL UNION
        SELECT
            pipe_id AS id,
            pipe_addr AS NAME,
            coordinates,
            '9' AS type
        FROM
            t_pipe_info
        WHERE
          <if test="name != null  and name != ''"> pipe_addr like concat('%', #{name}, '%') AND</if>
          coordinates IS NOT NULL
    </select>
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
    <select id="selectDeviceList" parameterType="TDeviceInfo" resultMap="TDeviceInfoResult">
        SELECT * FROM t_device_info WHERE device_name like concat('%', #{deviceName}, '%')
    </select>


    <select id="selectTDeviceInfoById" parameterType="Long" resultMap="TDeviceInfoResult">
    select device_id, device_name, device_code, device_addr, device_model,device_type,
        beyond_enterprise_id, beyond_enterprise_name, longitude, latitude, icon_url, linkman, phone, installation_time, inspection_time, create_by, create_time, update_by, update_time, is_del, remarks from t_device_info
        where device_id = #{deviceId} and is_del='0'
    </select>

    <select id="getDeviceInfoAlarmList" resultType="Map">
        select a3.device_id as deviceId,
               a3.device_type as deviceType
        from t_relation_device_detail_info a1
        left join t_detector_info a2 on a1.iot_no = a2.detector_code
        right join t_device_info a3 on a1.relation_device_id = a3.device_id
        where a1.is_del = '0' and a2.is_del = '0' and a3.is_del = '0' and a2.detector_status = '2'
    </select>

    <insert id="insertTDeviceInfo" parameterType="TDeviceInfo" useGeneratedKeys="true" keyProperty="deviceId">
        insert into t_device_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceName != null">device_name,</if>
            <if test="deviceCode != null">device_code,</if>
            <if test="deviceAddr != null">device_addr,</if>
            <if test="deviceModel != null">device_model,</if>
            <if test="deviceType != null">device_type,</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id,</if>
            <if test="beyondEnterpriseName != null">beyond_enterprise_name,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="iconUrl != null">icon_url,</if>
            <if test="linkman != null">linkman,</if>
            <if test="phone != null">phone,</if>
            <if test="installationTime != null">installation_time,</if>
            <if test="inspectionTime != null">inspection_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceName != null">#{deviceName},</if>
            <if test="deviceCode != null">#{deviceCode},</if>
            <if test="deviceAddr != null">#{deviceAddr},</if>
            <if test="deviceModel != null">#{deviceModel},</if>
            <if test="deviceType != null">#{deviceType},</if>
            <if test="beyondEnterpriseId != null">#{beyondEnterpriseId},</if>
            <if test="beyondEnterpriseName != null">#{beyondEnterpriseName},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="iconUrl != null">#{iconUrl},</if>
            <if test="linkman != null">#{linkman},</if>
            <if test="phone != null">#{phone},</if>
            <if test="installationTime != null">#{installationTime},</if>
            <if test="inspectionTime != null">#{inspectionTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTDeviceInfo" parameterType="TDeviceInfo">
        update t_device_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceName != null">device_name = #{deviceName},</if>
            <if test="deviceCode != null">device_code = #{deviceCode},</if>
            <if test="deviceAddr != null">device_addr = #{deviceAddr},</if>
            <if test="deviceModel != null">device_model = #{deviceModel},</if>
            <if test="deviceType != null">device_type = #{deviceType},</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id = #{beyondEnterpriseId},</if>
            <if test="beyondEnterpriseName != null">beyond_enterprise_name = #{beyondEnterpriseName},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="iconUrl != null">icon_url = #{iconUrl},</if>
            <if test="linkman != null">linkman = #{linkman},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="installationTime != null">installation_time = #{installationTime},</if>
            <if test="inspectionTime != null">inspection_time = #{inspectionTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where device_id = #{deviceId}
    </update>

    <update id="deleteTDeviceInfoById" parameterType="Long">
        update t_device_info set is_del='1' where device_id = #{deviceId}
    </update>

    <update id="deleteTDeviceInfoByIds" parameterType="String">
        update  t_device_info set is_del='1' where device_id in
        <foreach item="deviceId" collection="array" open="(" separator="," close=")">
            #{deviceId}
        </foreach>
    </update>


    <insert id="insertDeviceDetailInfo">
        INSERT INTO t_relation_device_detail_info (relation_device_id,detection_medium,device_name,device_model,device_type,iot_no,remarks)
        VALUES
            (#{relationDeviceId},#{detectionMedium},#{deviceName},#{deviceModel},#{deviceType},#{iotNo},#{remarksn})
    </insert>

    <!--获取设备详细信息列表-->
    <select id="getdeviceDetailInfo" resultMap="TDeviceInfoResultS">
        select relation_device_detail_id,relation_device_id,device_name,device_model,device_type,iot_no,remarks,detection_medium
        from t_relation_device_detail_info  where relation_device_id =#{deviceId}
    </select>

    <!--查询无绑定的 关联设备信息-->
    <select id="selectDetailInfo" resultMap="TDeviceInfoResultS">
        select relation_device_detail_id,detection_medium,relation_device_id,device_name,device_model,iot_no,remarks, (CASE  device_type WHEN '1' THEN '压力表' WHEN '2' THEN '流量计' WHEN '3' THEN '探测器' end) as  device_type
        from t_relation_device_detail_info  where is_del='0' and relation_device_id is  null
        <if test="deviceName != null  and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if>
        <if test="deviceModel != null  and deviceModel != ''"> and device_model like concat('%', #{deviceModel}, '%')</if>
        <if test="iotNo != null  and iotNo != ''"> and iot_no like concat('%', #{iotNo}, '%')</if>
263 264
        group by relation_device_detail_id
        order by relation_device_detail_id desc
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
    </select>

    <!--查询设备已经关联的关联设备-->
    <select id="selectDetailInfoList" resultMap="TDeviceInfoResultS">
        select relation_device_detail_id,detection_medium,relation_device_id,device_name,device_model,iot_no,remarks, (CASE  device_type WHEN '1' THEN '压力表' WHEN '2' THEN '流量计' WHEN '3' THEN '探测器' end) as  device_type
        from t_relation_device_detail_info  where relation_device_id=#{id} and relation_device_type=#{relationDeviceType}
    </select>

    <!--关联设备数据删除接口-->
    <update id="deleteDetailInfo">
        update  t_relation_device_detail_info set is_del='1' where relation_device_detail_id in
        <foreach item="deviceId" collection="array" open="(" separator="," close=")">
            #{deviceId}
        </foreach>
    </update>

    <!--关联设备数据删除接口 单条删除-->
    <update id="deleteDetailinfOS">
        update t_relation_device_detail_info set is_del='1' where relation_device_detail_id = #{deviceId}
    </update>


    <!--将关联设备信息与设备进行绑定-->
    <update id="updatetRelationDeviceDetailInfo" parameterType="java.util.List">
        update t_relation_device_detail_info set relation_device_id = #{id} ,relation_device_type =#{relationDevicetype}
        where
        relation_device_detail_id in
        <foreach collection="gettDeviceInfoS" item="items" index="key" open="(" separator="," close=")">
           #{items.relationDeviceDetailId}
        </foreach>
    </update>

    <!--解绑 设备与关联设备关系-->
    <update id="deleteDeviceDetailInfo">
        update t_relation_device_detail_info set relation_device_id=NULL where relation_device_detail_id=#{deviceId}
    </update>
    <select id="selectDeviceNum" resultType="java.util.HashMap">
        SELECT SUM(IF(device_type=1,1,0)) AS fajing, SUM(IF(device_type=2,1,0)) AS tiaoya ,
        (SELECT COUNT(video_manager_id) FROM t_video_manager WHERE is_del = 0
            and beyond_enterprise_id IN
            <foreach item="enterpriseId" collection="enterpriseIds" open="(" separator="," close=")">
                #{enterpriseId}
            </foreach>
        ) AS videoNum,
        (SELECT COUNT(site_station_id) FROM t_site_station_info WHERE is_del = 0
            and beyond_enterprise_id IN
            <foreach item="enterpriseId" collection="enterpriseIds" open="(" separator="," close=")">
                #{enterpriseId}
            </foreach>
        ) AS stationNum
        FROM t_device_info
        WHERE is_del = 0 and beyond_enterprise_id IN
        <foreach item="enterpriseId" collection="enterpriseIds" open="(" separator="," close=")">
            #{enterpriseId}
        </foreach>
    </select>
</mapper>