AlarmsInfoMapper.xml 17 KB
Newer Older
葛齐林's avatar
葛齐林 committed
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 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 322 323 324 325 326 327 328 329
<?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.devplatform.alarm.modules.alarms.dao.AlarmsInfoDao">
  <!-- Result Map -->
  <resultMap id="BaseResultMap" type="com.devplatform.alarm.modules.alarms.bean.AlarmsInfo">
    <result column="id" property="id"/>
    <result column="system_id" property="systemId"/>
    <result column="event_number" property="eventNumber"/>
    <result column="event_name" property="eventName"/>
    <result column="event_type" property="eventType"/>
    <result column="event_level" property="eventLevel"/>
    <result column="resource_id" property="resourceId"/>
    <result column="resource_name" property="resourceName"/>
    <result column="occurrence_time" property="occurrenceTime"/>
    <result column="occurrence_site" property="occurrenceSite"/>
    <result column="status" property="status"/>
    <result column="alarms_status" property="alarmsStatus"/>
    <result column="type" property="type"/>
    <result column="plan_id" property="planId"/>
    <result column="create_time" property="createTime"/>
    <result column="create_user_id" property="createUserId"/>
    <result column="update_time" property="updateTime"/>
    <result column="update_user_id" property="updateUserId"/>
    <result column="deleted" property="deleted"/>
    <result column="byx1" property="byx1"/>
    <result column="byx2" property="byx2"/>
    <result column="byx3" property="byx3"/>
    <result column="sys_sign" property="sysSign"/>
    <result column="station_id" property="stationId"/>
    <association column="{id=id,stationId=station_id}" property="fj" select="getFj"/>
    <association column="{id=id,stationId=station_id}" property="hmdfj" select="getHmdfj"/>
  </resultMap>

  <!-- alarms_info table all fields -->
  <sql id="Base_Column_List">
		id,system_id,event_number,event_name,event_type,event_level,resource_id,resource_name,occurrence_time,occurrence_site,status,alarms_status,`type`,plan_id,create_time,create_user_id,update_time,update_user_id,deleted,byx1,byx2,byx3,sys_sign,station_id
	</sql>

  <!-- 公共查询条件 -->
  <sql id="Example_Where_Clause">
    where deleted=0
    <if test="id!=null and id!=''">and id = #{id}</if>
    <if test="systemId!=null and systemId!=''">and system_id = #{systemId}</if>
    <if test="eventNumber!=null and eventNumber!=''">and event_number = #{eventNumber}</if>
    <if test="eventName!=null and eventName!=''">and event_name = #{eventName}</if>
    <if test="eventType!=null and eventType!=''">and event_type = #{eventType}</if>
    <if test="eventLevel!=null ">and event_level = #{eventLevel}</if>
    <if test="resourceId!=null and resourceId!=''">and resource_id = #{resourceId}</if>
    <if test="resourceName!=null and resourceName!=''">and resource_name = #{resourceName}</if>
    <if test="occurrenceTime!=null ">and occurrence_time = #{occurrenceTime}</if>
    <if test="occurrenceSite!=null and occurrenceSite!=''">and occurrence_site = #{occurrenceSite}</if>
    <if test="status!=null ">and status = #{status}</if>
    <if test="createTime!=null ">and create_time = #{createTime}</if>
    <if test="createUserId!=null and createUserId!=''">and create_user_id = #{createUserId}</if>
    <if test="updateTime!=null ">and update_time = #{updateTime}</if>
    <if test="updateUserId!=null and updateUserId!=''">and update_user_id = #{updateUserId}</if>
    <if test="deleted!=null ">and deleted = #{deleted}</if>
    <if test="byx1!=null and byx1!=''">and byx1 = #{byx1}</if>
    <if test="byx2!=null and byx2!=''">and byx2 = #{byx2}</if>
    <if test="byx3!=null and byx3!=''">and byx3 = #{byx3}</if>
    <if test="sysSign!=null and sysSign!=''">and sys_sign = #{sysSign}</if>
    <if test="stationId!=null and stationId!=''">and station_id = #{stationId}</if>
  </sql>

  <!-- 分页查询条件 -->
  <sql id="queryPageByListClause">
    where ai.deleted=0
    <if test="eventType != null and eventType !='' ">
      and ai.event_type = #{eventType}
    </if>
    <if test="stationId != null and stationId != '' and params !=null and params != '' ">
      and (INSTR(ai.event_number, #{params})
      or INSTR(ai.event_name, #{params})
      or INSTR(ai.resource_name, #{params}))
    </if>
    <if test="(stationId == null or stationId == '') and params !=null and params != '' ">
      and (INSTR(ai.event_number, #{params})
      or INSTR(ai.event_name, #{params})
      or INSTR(ai.resource_name, #{params})
      or INSTR(ls.station_name, #{params}))
    </if>
    <!--查询未处理的-->
    <if test="status == null">
      and ai.status IN (1,2)
    </if>
    <if test="status != null">
      and ai.status = #{status}
    </if>
    <if test="levelList != null">
      <if test="levelList.size() > 0">
        and ai.event_level in
        <foreach close=")" collection="levelList" index="index" item="level" open="(" separator=",">
          #{level}
        </foreach>
      </if>
    </if>
    <if test='systemId != null and systemId != "" and systemId != "0"'>
      and ai.system_id = #{systemId}
    </if>
    <if test='stationId != null and stationId != ""'>
      and ai.station_id = #{stationId}
    </if>
    <if test="startTime !=null and startTime !=''">
      and ai.occurrence_time &gt;= #{startTime}
    </if>
    <if test="endTime !=null and endTime !=''">
      and ai.occurrence_time &lt;= #{endTime}
    </if>
  </sql>

  <select id="getFj" resultType="com.devplatform.alarm.modules.link.log.bean.LinkAttachment">
    SELECT fj.*
    FROM link_attachment fj
    left join link_logs_action lla on lla.id = fj.link_logs_action_id and lla.station_id = fj.station_id
    left join link_logs ll on ll.id = lla.logs_id and ll.station_id = fj.station_id
    left join alarms_info ai on ai.id = ll.alarms_info_id and ai.station_id = fj.station_id
    WHERE fj.deleted = 0 and lower(fj.file_type) = 'jpg' and ai.id = #{id}
    <if test='stationId != null and stationId != ""'>
      and fj.station_id = #{stationId}
    </if>
    order by fj.create_time limit 1
  </select>

  <select id="getHmdfj" resultType="com.devplatform.alarm.modules.alarms.bean.AlarmsAttachment">
    SELECT fj.*
    FROM alarms_attachment fj
    WHERE fj.deleted = 0 and fj.obj_id = #{id}
    <if test='stationId != null and stationId != ""'>
      and fj.station_id = #{stationId}
    </if>
    order by fj.create_time,fj.status desc limit 1
  </select>

  <!--根据id查询报警信息-->
  <select id="queryById" parameterType="java.lang.String" resultMap="BaseResultMap">
    select ai.*,ls.station_name stationName,lsm.name tierName,lr.code as resourceCode,le.event_name as eventTypeName from alarms_info ai
    left join li_resource lr on lr.id = ai.resource_id and lr.station_id = ai.station_id
    left join li_station ls on lr.station_id = ai.id
    left join li_station_map lsm on lsm.id = lr.tier_id and lsm.station_id = ai.station_id
    left join link_event le on le.id = ai.event_type
    where ai.deleted=0 and ai.id = #{id}
    <if test='stationId != null and stationId != ""'>
      and ai.station_id = #{stationId}
    </if>
  </select>

  <!--分页页数统计-->
  <select id="queryPageByCount" parameterType="java.lang.Object" resultType="java.lang.Integer">
    SELECT COUNT(1) FROM alarms_info ai
    left join li_resource lr on lr.id = ai.resource_id and lr.station_id = ai.station_id
    left join li_station ls on ls.id = ai.station_id
    left join link_event le on le.id = ai.event_type
    <include refid="queryPageByListClause"></include>
  </select>

  <!--分页查询-->
  <select id="queryPageByList" parameterType="java.lang.Object" resultMap="BaseResultMap">
    select ai.*,lr.type as resourceType,ls.station_name as stationName,le.event_name as eventTypeName
    from alarms_info ai
    left join li_resource lr on lr.id = ai.resource_id and lr.station_id = ai.station_id
    left join li_station ls on ls.id = ai.station_id
    left join link_event le on le.id = ai.event_type
    <include refid="queryPageByListClause"></include>
    <if test="pager.orderCondition != null and pager.orderCondition != ''">
      ${pager.orderCondition}
    </if>
    <if test="pager.mysqlQueryCondition != null and pager.mysqlQueryCondition != ''">
      ${pager.mysqlQueryCondition}
    </if>
  </select>

  <select id="queryAll" parameterType="java.lang.Object" resultMap="BaseResultMap">
    select ai.*,ls.station_name as stationName,lsm.name as tierName,le.event_name as eventTypeName from alarms_info ai
    left join li_resource lr on lr.id = ai.resource_id and lr.station_id = ai.station_id
    left join li_station ls on lr.station_id = ls.id and ls.station_id = ai.station_id
    left join li_station_map lsm on lsm.id = lr.tier_id and lsm.station_id = ai.station_id
    left join link_event le on le.id = ai.event_type
    where ai.deleted=0
    <if test="params.status!=null ">and ai.status = #{params.status}</if>
    <if test="params.stationId!=null and params.stationId !=''">and lr.station_id = #{params.stationId} and ai.station_id = #{params.stationId}</if>
    order by ai.occurrence_time desc
  </select>

  <!--统计未处理报警信息-->
  <select id="queryGroupUntreated" parameterType="java.lang.Object" resultType="com.devplatform.alarm.modules.alarms.bean.AlarmsInfo">
    SELECT
    *
    FROM
    (
    SELECT
    '视频监控系统' AS systemName,
    count( CASE WHEN event_level = 1 AND `status` IN (1,2) AND system_id = '438c30d3d7f241b573f22a1a36c60485' THEN 0 END ) AS oneCount,
    count( CASE WHEN event_level = 2 AND `status` IN (1,2) AND system_id = '438c30d3d7f241b573f22a1a36c60485' THEN 0 END ) AS twoCount,
    count( CASE WHEN event_level = 3 AND `status` IN (1,2) AND system_id = '438c30d3d7f241b573f22a1a36c60485' THEN 0 END ) AS threeCount
    FROM
    alarms_info where deleted = 0
    <if test="stationId!=null and stationId!=''">and station_id=#{stationId}</if>
    UNION
    SELECT
    '入侵报警系统' AS systemName,
    count( CASE WHEN event_level = 1 AND `status` IN (1,2) AND system_id = '75c7c11716713edfd2ce3581f5e7c193' THEN 0 END ) AS oneCount,
    count( CASE WHEN event_level = 2 AND `status` IN (1,2) AND system_id = '75c7c11716713edfd2ce3581f5e7c193' THEN 0 END ) AS twoCount,
    count( CASE WHEN event_level = 3 AND `status` IN (1,2) AND system_id = '75c7c11716713edfd2ce3581f5e7c193' THEN 0 END ) AS threeCount
    FROM
    alarms_info where deleted = 0
    <if test="stationId!=null and stationId!=''">and station_id=#{stationId}</if>
    UNION
    SELECT
    '安全检查及探测系统' AS systemName,
    count( CASE WHEN event_level = 1 AND `status` IN (1,2) AND system_id = '3a64b86b1a5dead8ff9d2ad913744e50' THEN 0 END ) AS oneCount,
    count( CASE WHEN event_level = 2 AND `status` IN (1,2) AND system_id = '3a64b86b1a5dead8ff9d2ad913744e50' THEN 0 END ) AS twoCount,
    count( CASE WHEN event_level = 3 AND `status` IN (1,2) AND system_id = '3a64b86b1a5dead8ff9d2ad913744e50' THEN 0 END ) AS threeCount
    FROM
    alarms_info where deleted = 0
    <if test="stationId!=null and stationId!=''">and station_id=#{stationId}</if>
    UNION
    SELECT
    '出入口控制系统' AS systemName,
    count( CASE WHEN event_level = 1 AND `status` IN (1,2) AND system_id = 'ed401f7d9291b508d411d8192b016c6e' THEN 0 END ) AS oneCount,
    count( CASE WHEN event_level = 2 AND `status` IN (1,2) AND system_id = 'ed401f7d9291b508d411d8192b016c6e' THEN 0 END ) AS twoCount,
    count( CASE WHEN event_level = 3 AND `status` IN (1,2) AND system_id = 'ed401f7d9291b508d411d8192b016c6e' THEN 0 END ) AS threeCount
    FROM
    alarms_info where deleted = 0
    <if test="stationId!=null and stationId!=''">and station_id=#{stationId}</if>
    ) a

  </select>

  <!--统计已处理报警信息-->
  <select id="queryGroupProcessed" parameterType="java.lang.Object" resultType="com.devplatform.alarm.modules.alarms.bean.AlarmsInfo">
    SELECT
    *
    FROM
    (
    SELECT
    '视频监控系统' AS systemName,
    count( CASE WHEN event_level = 1 AND `status` = 3 AND system_id = '438c30d3d7f241b573f22a1a36c60485' THEN 0 END ) AS oneCount,
    count( CASE WHEN event_level = 2 AND `status` = 3 AND system_id = '438c30d3d7f241b573f22a1a36c60485' THEN 0 END ) AS twoCount,
    count( CASE WHEN event_level = 3 AND `status` = 3 AND system_id = '438c30d3d7f241b573f22a1a36c60485' THEN 0 END ) AS threeCount
    FROM
    alarms_info where deleted = 0
    <if test="stationId!=null and stationId!=''">and station_id=#{stationId}</if>
    UNION
    SELECT
    '入侵报警系统' AS systemName,
    count( CASE WHEN event_level = 1 AND `status` = 3 AND system_id = '75c7c11716713edfd2ce3581f5e7c193' THEN 0 END ) AS oneCount,
    count( CASE WHEN event_level = 2 AND `status` = 3 AND system_id = '75c7c11716713edfd2ce3581f5e7c193' THEN 0 END ) AS twoCount,
    count( CASE WHEN event_level = 3 AND `status` = 3 AND system_id = '75c7c11716713edfd2ce3581f5e7c193' THEN 0 END ) AS threeCount
    FROM
    alarms_info where deleted = 0
    <if test="stationId!=null and stationId!=''">and station_id=#{stationId}</if>
    UNION
    SELECT
    '安全检查及探测系统' AS systemName,
    count( CASE WHEN event_level = 1 AND `status` = 3 AND system_id = '3a64b86b1a5dead8ff9d2ad913744e50' THEN 0 END ) AS oneCount,
    count( CASE WHEN event_level = 2 AND `status` = 3 AND system_id = '3a64b86b1a5dead8ff9d2ad913744e50' THEN 0 END ) AS twoCount,
    count( CASE WHEN event_level = 3 AND `status` = 3 AND system_id = '3a64b86b1a5dead8ff9d2ad913744e50' THEN 0 END ) AS threeCount
    FROM
    alarms_info where deleted = 0
    <if test="stationId!=null and stationId!=''">and station_id=#{stationId}</if>
    UNION
    SELECT
    '出入口控制系统' AS systemName,
    count( CASE WHEN event_level = 1 AND `status` = 3 AND system_id = 'ed401f7d9291b508d411d8192b016c6e' THEN 0 END ) AS oneCount,
    count( CASE WHEN event_level = 2 AND `status` = 3 AND system_id = 'ed401f7d9291b508d411d8192b016c6e' THEN 0 END ) AS twoCount,
    count( CASE WHEN event_level = 3 AND `status` = 3 AND system_id = 'ed401f7d9291b508d411d8192b016c6e' THEN 0 END ) AS threeCount
    FROM
    alarms_info where deleted = 0
    <if test="stationId!=null and stationId!=''">and station_id=#{stationId}</if>
    ) a
  </select>
  <select id="countNum" parameterType="java.lang.Object" resultType="java.lang.Integer">
    select
    count(1)
    from alarms_info ai
    left join li_resource lr on lr.id = ai.resource_id and lr.station_id = ai.station_id
    where ai.deleted=0
    <if test="params.status!=null ">and ai.status = #{params.status}</if>
    <if test="params.stationId!=null and params.stationId !=''">and lr.station_id = #{params.stationId} and ai.station_id = #{params.stationId}</if>
  </select>

  <select id="getHistoryVideInfo" resultType="java.util.HashMap">
    SELECT la.*
    FROM alarms_info ai
    LEFT JOIN link_logs ll ON ai.id = ll.alarms_info_id and ll.station_id = ai.station_id
    LEFT JOIN link_logs_action lla ON lla.logs_id = ll.id and lla.station_id = ai.station_id
    RIGHT JOIN link_attachment la ON la.link_logs_action_id = lla.id and la.station_id = ai.station_id
    WHERE la.file_type = 'mp4'
    AND ai.id = #{id}
    <if test="stationId!=null and stationId!=''">where ai.station_id=#{stationId}</if>
  </select>

  <select id="queryRoutesGroupUntreated" parameterType="java.lang.Object" resultType="com.devplatform.alarm.modules.alarms.bean.AlarmsInfo">
    SELECT
    count( CASE WHEN ai.event_level = 1 AND ai.`status` IN (1,2) THEN 0 END ) AS oneCount,
    count( CASE WHEN ai.event_level = 2 AND ai.`status` IN (1,2) THEN 0 END ) AS twoCount,
    count( CASE WHEN ai.event_level = 3 AND ai.`status` IN (1,2) THEN 0 END ) AS threeCount
    FROM alarms_info ai
    left join li_resource lr on lr.id = ai.resource_id and lr.station_id = ai.station_id
    where ai.deleted=0
    <if test="params.stationId!=null and params.stationId !=''">and lr.station_id = #{params.stationId} and ai.station_id = #{params.stationId}</if>
    <if test="params.lineId!=null and params.lineId !=''">and lr.line_id = #{params.lineId}</if>
  </select>

  <select id="queryRoutesAll" parameterType="java.lang.Object" resultType="com.devplatform.alarm.modules.alarms.bean.AlarmsInfo">
    select ai.id,ai.occurrence_time,ai.event_name,ai.create_time,ai.station_id stationId,lr.line_name lineName,lr.station_name stationName,lsm.name tierName
    from alarms_info ai
    left join li_resource lr on lr.id = ai.resource_id and lr.station_id = ai.station_id
    left join li_station_map lsm on lsm.id = lr.tier_id and lsm.station_id = ai.station_id
    where ai.deleted=0 and ai.`status` in (1,2)
    <if test="params.stationId!=null and params.stationId !=''">and ai.station_id = #{params.stationId}</if>
    <if test="params.lineId!=null and params.lineId !=''">and lr.line_id = #{params.lineId}</if>
    ORDER BY ai.occurrence_time desc
    LIMIT 0,${params.limit}
  </select>

  <select id="queryStationIds" resultType="java.lang.String">
    select ai.station_id
    from alarms_info ai
    left join li_resource lr on lr.id = ai.resource_id and lr.station_id = ai.station_id
    where ai.deleted=0 and ai.`status` in (1,2)
    <if test="params.lineId!=null and params.lineId !=''">and lr.line_id = #{params.lineId}</if>
    group by ai.station_id
  </select>


</mapper>