TDetectorReportDataMapper.xml 13.7 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 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 261 262 263 264 265 266 267 268
<?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.TDetectorReportDataMapper">
    
    <resultMap type="TDetectorReportData" id="TDetectorReportDataResult">
        <result property="id"    column="id"    />
        <result property="sourceId"    column="source_id"    />
        <result property="detectorCode"    column="detector_code"    />
        <result property="detectorStatusId"    column="detector_status_id"    />
        <result property="statusName"    column="status_name"    />
        <result property="reportValue"    column="report_value"    />
        <result property="zhHostStatusId"    column="zh_host_status_id"    />
        <result property="netPoint"    column="net_point"    />
        <result property="signalStrength"    column="signal_strength"    />
        <result property="ipAddress"    column="ip_address"    />
        <result property="createTime"    column="create_time"    />
        <result property="isCancelAlarm"    column="is_cancel_alarm"    />
        <result property="cancelTime"    column="cancel_time"    />
    </resultMap>

    <sql id="selectTDetectorReportDataVo">
        select id, source_id, detector_code, detector_status_id, status_name, report_value, zh_host_status_id, net_point, signal_strength, ip_address, create_time, is_cancel_alarm, cancel_time from t_detector_report_data
    </sql>

    <select id="selectTDetectorReportDataList" parameterType="TDetectorReportDataForm" resultType="TDetectorAlarmInfoVO">
    select * from(
        select rd.id,
               rd.cancel_time cancelTime,
               rd.detector_code detectorCode,
               CONCAT_WS("#",IFNULL(u.nick_name,IFNULL(di.linkman,di.detector_addr)),di.linkman) unitName,
               di.detector_type detectorType,
               rd.status_name statusName,
               rd.create_time alarmTime,
               rd.is_cancel_alarm handledStatus
        FROM t_detector_report_data rd
        LEFT JOIN t_detector_info di ON rd.detector_code = di.detector_code
        LEFT JOIN t_detector_user u ON u.user_id = di.user_id
        <where> u.is_del = '0' and di.is_del = '0'
            <if test="detectorCode != null  and detectorCode != ''"> and rd.detector_code = #{detectorCode}</if>
            <if test="statusName != null  and statusName != ''"> and rd.status_name = #{statusName}</if>
            <if test="createTimeStart != null "> and rd.create_time &gt;= #{createTimeStart}</if>
            <if test="createTimeEnd != null "> and rd.create_time &lt;= #{createTimeEnd}</if>
            <if test="isCancelAlarm != null  and isCancelAlarm != ''"> and is_cancel_alarm = #{isCancelAlarm}</if>
            <if test="cancelTimeStart != null "> and rd.cancel_time &gt;= #{cancelTimeStart}</if>
            <if test="cancelTimeEnd != null "> and rd.cancel_time &lt;= #{cancelTimeEnd}</if>
        </where>
        union
        SELECT rd.id,
               rd.cancel_time cancelTime,
               rd.detector_code detectorCode,
               CONCAT_WS("#",ti.device_name,ti.linkman) unitName,
               di.detector_type detectorType,
               rd.status_name statusName,
               rd.create_time alarmTime,
               rd.is_cancel_alarm handledStatus
        FROM t_detector_report_data rd
        LEFT JOIN t_detector_info di ON rd.detector_code = di.detector_code
        LEFT JOIN t_relation_device_detail_info ri ON rd.detector_code = ri.iot_no
        LEFT JOIN t_device_info ti ON ri.relation_device_id = ti.device_id
        <where> ri.relation_device_type = '1' and ri.is_del = '0' and ti.is_del = '0'
            <if test="detectorCode != null  and detectorCode != ''"> and rd.detector_code = #{detectorCode}</if>
            <if test="statusName != null  and statusName != ''"> and rd.status_name = #{statusName}</if>
            <if test="createTimeStart != null "> and rd.create_time &gt;= #{createTimeStart}</if>
            <if test="createTimeEnd != null "> and rd.create_time &lt;= #{createTimeEnd}</if>
            <if test="isCancelAlarm != null  and isCancelAlarm != ''"> and is_cancel_alarm = #{isCancelAlarm}</if>
            <if test="cancelTimeStart != null "> and rd.cancel_time &gt;= #{cancelTimeStart}</if>
            <if test="cancelTimeEnd != null "> and rd.cancel_time &lt;= #{cancelTimeEnd}</if>
        </where>
        union
        SELECT rd.id,
               rd.cancel_time cancelTime,
               rd.detector_code detectorCode,
               CONCAT_WS("#",si.site_station_name,si.build_unit) unitName,
               di.detector_type detectorType,
               rd.status_name statusName,
               rd.create_time alarmTime,
               rd.is_cancel_alarm handledStatus
        FROM t_detector_report_data rd
        LEFT JOIN t_detector_info di ON rd.detector_code = di.detector_code
        LEFT JOIN t_relation_device_detail_info ti ON rd.detector_code = ti.iot_no
        LEFT JOIN t_site_station_info si ON ti.relation_device_id = si.site_station_id
        <where> ti.relation_device_type = '2' and ti.is_del = '0' and si.is_del = '0'
            <if test="detectorCode != null  and detectorCode != ''"> and rd.detector_code = #{detectorCode}</if>
            <if test="statusName != null  and statusName != ''"> and rd.status_name = #{statusName}</if>
            <if test="createTimeStart != null "> and rd.create_time &gt;= #{createTimeStart}</if>
            <if test="createTimeEnd != null "> and rd.create_time &lt;= #{createTimeEnd}</if>
            <if test="isCancelAlarm != null  and isCancelAlarm != ''"> and is_cancel_alarm = #{isCancelAlarm}</if>
            <if test="cancelTimeStart != null "> and rd.cancel_time &gt;= #{cancelTimeStart}</if>
            <if test="cancelTimeEnd != null "> and rd.cancel_time &lt;= #{cancelTimeEnd}</if>
        </where>
        )t
        ORDER BY t.alarmTime DESC
    </select>
    
    <select id="selectTDetectorReportDataById" parameterType="Long" resultMap="TDetectorReportDataResult">
        <include refid="selectTDetectorReportDataVo"/>
        where id = #{id}
    </select>

    <select id="selectTDetectorReportDataByCode" parameterType="String" resultMap="TDetectorReportDataResult">
        <include refid="selectTDetectorReportDataVo"/>
        where detector_code = #{detectorCode}
        and is_cancel_alarm = '0'
        ORDER BY create_time DESC
    </select>

    <select id="selectTDetectorAlarm" resultType="TDetectorAlarmInfoVO">
    select * from(
        SELECT
            rd.detector_code detectorCode,
            CONCAT_WS("#",IFNULL(u.nick_name,IFNULL(di.linkman,di.detector_addr)),di.linkman) unitName,
            di.detector_type detectorType,
            rd.status_name statusName,
            rd.create_time alarmTime,
            IF (
                rd.is_cancel_alarm = 0,
                '未消除',
                '已消除'
            ) handledStatus
        FROM t_detector_report_data rd
        LEFT JOIN t_detector_info di ON rd.detector_code = di.detector_code
        LEFT JOIN t_detector_user u ON u.user_id = di.user_id
        WHERE u.is_del = '0' and di.is_del = '0' and rd.is_cancel_alarm = '0'
        union
		SELECT
            rd.detector_code detectorCode,
            CONCAT_WS("#",ti.device_name,ti.linkman) unitName,
            di.detector_type detectorType,
            rd.status_name statusName,
            rd.create_time alarmTime,
            IF (
                rd.is_cancel_alarm = 0,
                '未消除',
                '已消除'
            ) handledStatus
        FROM t_detector_report_data rd
        LEFT JOIN t_detector_info di ON rd.detector_code = di.detector_code
        LEFT JOIN t_relation_device_detail_info ri ON rd.detector_code = ri.iot_no
				LEFT JOIN t_device_info ti ON ri.relation_device_id = ti.device_id
        WHERE ri.relation_device_type = '1' and ri.is_del = '0' and ti.is_del = '0' and rd.is_cancel_alarm = '0'
        union
		SELECT
            rd.detector_code detectorCode,
            CONCAT_WS("#",si.site_station_name,si.build_unit) unitName,
            di.detector_type detectorType,
            rd.status_name statusName,
            rd.create_time alarmTime,
            IF (
                rd.is_cancel_alarm = 0,
                '未消除',
                '已消除'
            ) handledStatus
        FROM t_detector_report_data rd
        LEFT JOIN t_detector_info di ON rd.detector_code = di.detector_code
        LEFT JOIN t_relation_device_detail_info ti ON rd.detector_code = ti.iot_no
				LEFT JOIN t_site_station_info si ON ti.relation_device_id = si.site_station_id
        WHERE ti.relation_device_type = '2' and ti.is_del = '0' and si.is_del = '0' and rd.is_cancel_alarm = '0'
	)t
    ORDER BY t.alarmTime DESC LIMIT 50
    </select>


    <select id="selectRealtimeDataList" resultMap="TDetectorReportDataResult">
        SELECT * FROM
        (
            SELECT
            t.source_id,
            t.detector_code,
            t.detector_status_id,
            t.status_name,
            t.report_value,
            t.zh_host_status_id,
            t.net_point,
            t.signal_strength,
            t.ip_address,
            t.create_time,
            t.is_cancel_alarm,
            t.cancel_time,
            d.detector_id,
            d.detector_name,
            d.detector_type
            FROM
            t_detector_report_data t
            LEFT JOIN t_detector_info d ON t.detector_code = d.detector_code
            WHERE
            t.detector_status_id != '1'
            ORDER BY t.create_time DESC
        )data
        GROUP BY data.detector_id LIMIT 50
    </select>

    <select id="countDetectorByUserId" parameterType="TDetectorInfo" resultMap="TDetectorReportDataResult" >
        select r.id, r.source_id, r.detector_code, r.detector_status_id, r.is_cancel_alarm, r.cancel_time
        from t_detector_report_data r
        left join t_detector_info d on r.detector_code = d.detector_code
        where r.detector_status_id != '1' and d.user_id = #{userId} and d.is_del = #{isDel}
    </select>
        
    <insert id="insertTDetectorReportData" parameterType="TDetectorReportData" useGeneratedKeys="true" keyProperty="id">
        insert into t_detector_report_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sourceId != null">source_id,</if>
            <if test="detectorCode != null and detectorCode != ''">detector_code,</if>
            <if test="detectorStatusId != null">detector_status_id,</if>
            <if test="statusName != null">status_name,</if>
            <if test="reportValue != null">report_value,</if>
            <if test="zhHostStatusId != null">zh_host_status_id,</if>
            <if test="netPoint != null">net_point,</if>
            <if test="signalStrength != null">signal_strength,</if>
            <if test="ipAddress != null">ip_address,</if>
            <if test="createTime != null">create_time,</if>
            <if test="isCancelAlarm != null">is_cancel_alarm,</if>
            <if test="cancelTime != null">cancel_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sourceId != null">#{sourceId},</if>
            <if test="detectorCode != null and detectorCode != ''">#{detectorCode},</if>
            <if test="detectorStatusId != null">#{detectorStatusId},</if>
            <if test="statusName != null">#{statusName},</if>
            <if test="reportValue != null">#{reportValue},</if>
            <if test="zhHostStatusId != null">#{zhHostStatusId},</if>
            <if test="netPoint != null">#{netPoint},</if>
            <if test="signalStrength != null">#{signalStrength},</if>
            <if test="ipAddress != null">#{ipAddress},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="isCancelAlarm != null">#{isCancelAlarm},</if>
            <if test="cancelTime != null">#{cancelTime},</if>
         </trim>
    </insert>

    <update id="updateTDetectorReportData" parameterType="TDetectorReportData">
        update t_detector_report_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="sourceId != null">source_id = #{sourceId},</if>
            <if test="detectorCode != null and detectorCode != ''">detector_code = #{detectorCode},</if>
            <if test="detectorStatusId != null">detector_status_id = #{detectorStatusId},</if>
            <if test="statusName != null">status_name = #{statusName},</if>
            <if test="reportValue != null">report_value = #{reportValue},</if>
            <if test="zhHostStatusId != null">zh_host_status_id = #{zhHostStatusId},</if>
            <if test="netPoint != null">net_point = #{netPoint},</if>
            <if test="signalStrength != null">signal_strength = #{signalStrength},</if>
            <if test="ipAddress != null">ip_address = #{ipAddress},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="isCancelAlarm != null">is_cancel_alarm = #{isCancelAlarm},</if>
            <if test="cancelTime != null">cancel_time = #{cancelTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTDetectorReportDataById" parameterType="Long">
        delete from t_detector_report_data where id = #{id}
    </delete>

    <delete id="deleteTDetectorReportDataByIds" parameterType="String">
        delete from t_detector_report_data where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <select id="selectAlarm" parameterType="integer" resultType="TDetectorAlarmInfoVO">
      SELECT d.*,u.nick_name as unitName  t_detector_report_data d
      LEFT JOIN t_detector_info i on i.detector_code = d.detector_code
      LEFT JOIN t_detector_user u on u.user_id = i.user_id
      WHERE d.id = #{id}
    </select>
</mapper>