TDetectorInfoMapper.xml 15.6 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
<?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.TDetectorInfoMapper">
    
    <resultMap type="TDetectorInfo" id="TDetectorInfoResult">
        <result property="detectorId"    column="detector_id"    />
        <result property="enterpriseId"    column="enterprise_id"    />
        <result property="userId"    column="user_id"    />
        <result property="detectorName"    column="detector_name"    />
        <result property="detectorCode"    column="detector_code"    />
        <result property="detectorAddr"    column="detector_addr"    />
        <result property="detectorType"    column="detector_type"    />
        <result property="medium"    column="medium"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="iotNo"    column="iot_no"    />
        <result property="linkman"    column="linkman"    />
        <result property="phone"    column="phone"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="alarmTime"    column="alarm_time"    />
        <result property="detectorStatus"    column="detector_status"    />
        <result property="isDel"    column="is_del"    />
        <result property="remarks"    column="remarks"    />
27 28
        <result property="beyondDevicename"    column="beyondDevicename"    />
        <result property="enterpriseName"    column="enterprise_name"    />
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
    </resultMap>

    <sql id="selectTDetectorInfoVo">
        select detector_id, enterprise_id, user_id, detector_name, detector_code, detector_addr, detector_type, medium, longitude, latitude, iot_no, linkman, phone, create_time, update_time, alarm_time, detector_status, is_del, remarks from t_detector_info
    </sql>

    <select id="selectTDetectorInfoList" parameterType="TDetectorInfo" resultMap="TDetectorInfoResult">
        <include refid="selectTDetectorInfoVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="enterpriseId != null and enterpriseId != 0 "> and enterprise_id = #{enterpriseId}</if>
            <if test="detectorName != null  and detectorName != ''"> and detector_name like concat('%', #{detectorName}, '%')</if>
            <if test="detectorCode != null  and detectorCode != ''"> and detector_code = #{detectorCode}</if>
            <if test="detectorAddr != null  and detectorAddr != ''"> and detector_addr = #{detectorAddr}</if>
            <if test="detectorType != null  and detectorType != ''"> and detector_type = #{detectorType}</if>
            <if test="medium != null  and medium != ''"> and medium = #{medium}</if>
            <if test="longitude != null "> and longitude = #{longitude}</if>
            <if test="latitude != null "> and latitude = #{latitude}</if>
            <if test="iotNo != null  and iotNo != ''"> and iot_no = #{iotNo}</if>
            <if test="linkman != null  and linkman != ''"> and linkman = #{linkman}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="createTime != null "> and create_time = #{createTime}</if>
            <if test="updateTime != null "> and update_time = #{updateTime}</if>
            <if test="alarmTime != null "> and alarm_time = #{alarmTime}</if>
            <if test="detectorStatus != null  and detectorStatus != ''"> and detector_status = #{detectorStatus}</if>
            <if test="isDel != null  and isDel != ''"> and is_del = #{isDel}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        </where>
57
        order by detector_status desc, alarm_time desc
58 59 60 61 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 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
    </select>
    
    <select id="selectTDetectorInfoById" parameterType="Long" resultMap="TDetectorInfoResult">
        <include refid="selectTDetectorInfoVo"/>
        where detector_id = #{detectorId}
    </select>

    <select id="selectTDetectorInfoByCode" parameterType="String" resultMap="TDetectorInfoResult">
        <include refid="selectTDetectorInfoVo"/>
        where detector_code = #{detectorCode}
        and is_del = '0'
    </select>
        
    <insert id="insertTDetectorInfo" parameterType="TDetectorInfo" useGeneratedKeys="true" keyProperty="detectorId">
        insert into t_detector_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="enterpriseId != null and enterpriseId != 0">enterprise_id,</if>
            <if test="detectorName != null">detector_name,</if>
            <if test="detectorCode != null">detector_code,</if>
            <if test="detectorAddr != null">detector_addr,</if>
            <if test="detectorType != null">detector_type,</if>
            <if test="medium != null">medium,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="iotNo != null">iot_no,</if>
            <if test="linkman != null">linkman,</if>
            <if test="phone != null">phone,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="alarmTime != null">alarm_time,</if>
            <if test="detectorStatus != null">detector_status,</if>
            <if test="isDel != null">is_del,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="enterpriseId != null and enterpriseId != 0">#{enterpriseId},</if>
            <if test="detectorName != null">#{detectorName},</if>
            <if test="detectorCode != null">#{detectorCode},</if>
            <if test="detectorAddr != null">#{detectorAddr},</if>
            <if test="detectorType != null">#{detectorType},</if>
            <if test="medium != null">#{medium},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="iotNo != null">#{iotNo},</if>
            <if test="linkman != null">#{linkman},</if>
            <if test="phone != null">#{phone},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="alarmTime != null">#{alarmTime},</if>
            <if test="detectorStatus != null">#{detectorStatus},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>
    <insert id="insertBatch" parameterType="java.util.List" >
        insert into t_detector_info (
        user_id, detector_name, detector_code, detector_addr, detector_type, medium, longitude, latitude, linkman, phone, create_time
        )
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.userId,jdbcType=INTEGER}, #{item.detectorName,jdbcType=VARCHAR}, #{item.detectorCode,jdbcType=VARCHAR},
            #{item.detectorAddr,jdbcType=VARCHAR}, #{item.detectorType,jdbcType=VARCHAR}, #{item.medium,jdbcType=VARCHAR},
            #{item.longitude,jdbcType=DECIMAL}, #{item.latitude,jdbcType=DECIMAL}, #{item.linkman,jdbcType=VARCHAR},
            #{item.phone,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP}
            )
        </foreach>
    </insert>

    <update id="updateBatch" parameterType="java.util.List">
        update t_detector_info d
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="user_id=case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                    <if test="item.userId != null">
                        when detector_code=#{item.detectorCode} then #{item.userId}
                    </if>
                </foreach>
            </trim>
            <trim prefix="detector_name=case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                    <if test="item.detectorName != null &amp;&amp; item.detectorName != ''">
                        when detector_code=#{item.detectorCode} then #{item.detectorName}
                    </if>
                </foreach>
            </trim>
            <trim prefix="detector_addr=case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                    <if test="item.detectorAddr != null &amp;&amp; item.detectorAddr != ''">
                        when detector_code=#{item.detectorCode} then #{item.detectorAddr}
                    </if>
                </foreach>
            </trim>
            <trim prefix="detector_type=case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                    <if test="item.detectorType != null &amp;&amp; item.detectorType != ''">
                        when detector_code=#{item.detectorCode} then #{item.detectorType}
                    </if>
                </foreach>
            </trim>
            <trim prefix="medium=case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                    <if test="item.medium != null &amp;&amp; item.medium != ''">
                        when detector_code=#{item.detectorCode} then #{item.medium}
                    </if>
                </foreach>
            </trim>
            <trim prefix="longitude=case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                    <if test="item.longitude != null &amp;&amp; item.longitude != ''">
                        when detector_code=#{item.detectorCode} then #{item.longitude}
                    </if>
                </foreach>
            </trim>
            <trim prefix="latitude=case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                    <if test="item.latitude != null &amp;&amp; item.latitude != ''">
                        when detector_code=#{item.detectorCode} then #{item.latitude}
                    </if>
                </foreach>
            </trim>
            <trim prefix="linkman=case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                    <if test="item.linkman != null &amp;&amp; item.linkman != ''">
                        when detector_code=#{item.detectorCode} then #{item.linkman}
                    </if>
                </foreach>
            </trim>
            <trim prefix="phone=case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                    <if test="item.phone != null &amp;&amp; item.phone != ''">
                        when detector_code=#{item.detectorCode} then #{item.phone}
                    </if>
                </foreach>
            </trim>
            <trim prefix="is_del=case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                    <if test="item.isDel != null &amp;&amp; item.isDel != ''">
                        when detector_code=#{item.detectorCode} then #{item.isDel}
                    </if>
                </foreach>
            </trim>
            <trim prefix="detector_status=case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                    <if test="item.detectorStatus != null &amp;&amp; item.detectorStatus != ''">
                        when detector_code=#{item.detectorCode} then #{item.detectorStatus}
                    </if>
                </foreach>
            </trim>
            <trim prefix="update_time=case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                    <if test="item.updateTime != null">
                        when detector_code=#{item.detectorCode} then #{item.updateTime}
                    </if>
                </foreach>
            </trim>
            <trim prefix="alarm_time=case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                    when detector_code=#{item.detectorCode} then #{item.alarmTime}
                </foreach>
            </trim>
        </trim>
        where
        <foreach collection="list" separator="or" item="item" index="index">
            detector_code=#{item.detectorCode}
        </foreach>
    </update>

    <update id="updateTDetectorInfo" parameterType="TDetectorInfo">
        update t_detector_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="detectorName != null">detector_name = #{detectorName},</if>
            <if test="detectorCode != null">detector_code = #{detectorCode},</if>
            <if test="detectorAddr != null">detector_addr = #{detectorAddr},</if>
            <if test="detectorType != null">detector_type = #{detectorType},</if>
            <if test="medium != null">medium = #{medium},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="iotNo != null">iot_no = #{iotNo},</if>
            <if test="linkman != null">linkman = #{linkman},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            alarm_time = #{alarmTime},
            <if test="detectorStatus != null">detector_status = #{detectorStatus},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where detector_id = #{detectorId}
    </update>

    <delete id="deleteTDetectorInfoById" parameterType="Long">
        delete from t_detector_info where detector_id = #{detectorId}
    </delete>

    <delete id="deleteTDetectorInfoByIds" parameterType="String">
        delete from t_detector_info where detector_id in 
        <foreach item="detectorId" collection="array" open="(" separator="," close=")">
            #{detectorId}
        </foreach>
    </delete>
261 262
    <select id="selectDetectorNum" resultType="java.util.HashMap">
        SELECT IFNULL(SUM(IF(detector_status=0,1,0)),0) AS changNum,IFNULL(SUM(detector_status=1),0) AS liNum,
263
        IFNULL(SUM(IF(detector_status=2,1,0)),0) AS baoNum 
264 265
        FROM t_detector_info WHERE is_del = 0
    </select>
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287

    <select id="selectDetectorMointor" parameterType="TDetectorInfo" resultMap="TDetectorInfoResult">
        SELECT
          device.device_name AS beyondDevicename,
          detector.detector_name,
          detector.detector_code,
          enterprise.enterprise_name,
          detector.medium,
          detector.detector_status,
          detector.update_time AS reportTime
        FROM
          t_relation_device_detail_info relation
        INNER JOIN t_detector_info detector ON detector.detector_code = relation.iot_no
        INNER JOIN t_device_info device ON device.device_id = relation.relation_device_id
        INNER JOIN t_enterprise_info enterprise ON enterprise.enterprise_id = device.beyond_enterprise_id
        <where>
            relation.device_type = '3' AND relation.is_del = '0'
            <if test="enterpriseId != null  and enterpriseId != ''"> and enterprise.enterprise_id = #{enterpriseId}</if>
            <if test="detectorName != null  and detectorName != ''"> and detector.detector_name like concat('%', #{detectorName}, '%')</if>
            <if test="detectorCode != null  and detectorCode != ''"> and detector.detector_code like concat('%', #{detectorCode}, '%')</if>
        </where>
    </select>
288
</mapper>