AlarmsInfoMapper.xml 14.7 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
<?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.equipment.modules.alarms.dao.AlarmsInfoDao">
  <!-- Result Map -->
  <resultMap id="BaseResultMap" type="com.devplatform.equipment.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="station_id" property="stationId"/>
    <result column="sys_sign" property="sysSign"/>
  </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 deleted=0
    <if test="eventType != null and eventType !='' ">
      and event_type = #{eventType}
    </if>
    <if test="params !=null and params != '' ">
      and (INSTR(event_number, #{params})
      or INSTR(event_name, #{params})
      or INSTR(resource_name, #{params}))
    </if>
    <!--查询未处理的-->
    <if test="status != null and status == 0">
      and status IN (1,2)
    </if>
    <if test="status != null and status !=0">
      and status = #{status}
    </if>
    <if test="levelList != null">
      <if test="levelList.size() > 0">
        and 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 system_id = #{systemId}
    </if>
    <if test="startTime !=null and startTime !=''">
      and occurrence_time &gt;= #{startTime}
    </if>
    <if test="endTime !=null and endTime !=''">
      and occurrence_time &lt;= #{endTime}
    </if>
    <if test="stationId!=null and stationId!=''">and station_id = #{stationId}</if>
  </sql>

co_dengxiongwen's avatar
co_dengxiongwen committed
101

葛齐林's avatar
葛齐林 committed
102 103 104

  <!--根据id查询报警信息-->
  <select id="queryById" parameterType="java.lang.String" resultMap="BaseResultMap">
co_dengxiongwen's avatar
co_dengxiongwen committed
105
    select ai.*,ls.station_name stationName,lsm.name tierName,lr.code as resourceCode from alarms_info ai
葛齐林's avatar
葛齐林 committed
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
    left join li_resource lr on lr.id = ai.resource_id and ai.station_id = lr.station_id
    left join li_station ls on lr.station_id = ls.id and ai.station_id = ls.station_id
    left join li_station_map lsm on lsm.id = lr.tier_id and ai.station_id = lsm.station_id
    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
    <include refid="queryPageByListClause"></include>
  </select>

  <!--分页查询-->
  <select id="queryPageByList" parameterType="java.lang.Object" resultMap="BaseResultMap">
    select * from alarms_info
    <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 stationName,lsm.name tierName from alarms_info ai
    left join li_resource lr on lr.id = ai.resource_id and ai.station_id = lr.station_id
    left join li_station ls on lr.station_id = ls.id and ai.station_id = ls.station_id
    left join li_station_map lsm on lsm.id = lr.tier_id and ai.station_id = lsm.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}</if>
    order by ai.occurrence_time desc
  </select>

  <!--统计未处理报警信息-->
  <select id="queryGroupUntreated" parameterType="java.lang.Integer" resultMap="BaseResultMap">
		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 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 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 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
				) a

	</select>

  <!--统计已处理报警信息-->
  <select id="queryGroupProcessed" parameterType="java.lang.Integer" resultMap="BaseResultMap">
		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 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 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 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
				) a
	</select>

  <select id="queryByCameraList" parameterType="java.lang.Object" resultType="java.util.Map">
    select a.*
    from alarms_info a
    where a.id IN (
    select ai.id
    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 fj.file_type = 'mp4' and ai.deleted = 0
    <if test="params.systemId !=null and params.systemId != ''">and ai.system_id = #{params.systemId}</if>
    <if test="params.level !=null and params.level != ''">and ai.event_level = #{params.level}</if>
    <if test="params.name !=null and params.name !=''">and INSTR(ai.event_name, #{params.name})</if>
    <if test="params.staTime !=null and params.staTime != ''">and ai.occurrence_time &gt;= #{params.staTime}</if>
    <if test="params.endTime !=null and params.endTime != ''">and ai.occurrence_time &lt;= #{params.endTime}</if>
    <if test="params.stationId!=null and params.stationId!=''">and ai.station_id = #{params.stationId}</if>
    GROUP BY ai.id)
    order by a.occurrence_time desc
  </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}</if>
  </select>

  <select id="cNum" 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.startTime !=null and params.startTime !=''">
      and ai.occurrence_time &gt;= #{params.startTime}
    </if>
    <if test="params.endTime !=null and params.endTime !=''">
      and ai.occurrence_time &lt;= #{params.endTime}
    </if>
    <if test="params.stationId!=null and params.stationId !=''">and lr.station_id = #{params.stationId}</if>
    <if test="params.resourceId!=null and params.resourceId !=''">and ai.resource_id = #{params.resourceId}</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 = la.id and lla.station_id = ai.station_id
    WHERE la.file_type = 'mp4'
    AND ai.id = #{id}
    <if test="stationId!=null and stationId!=''">and ai.station_id = #{stationId}</if>
  </select>

  <select id="queryByCameraVideoList" resultType="java.util.Map">
    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 fj.file_type = 'mp4' AND ai.id = #{alarmsId}
    <if test="stationId!=null and stationId!=''">and ai.station_id = #{stationId}</if>
  </select>

  <select id="queryBsZt" parameterType="java.lang.Object" resultMap="BaseResultMap">
    select * from alarms_info
    <include refid="queryPageByListClause"></include>
    order by occurrence_time desc limit 1
  </select>
</mapper>