MsgAlarmMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.ozs.mapper.MsgAlarmMapper">
  4. <resultMap id="AlarmStatisticDtoResult" type="com.ozs.entity.vo.AlarmStatisticDto">
  5. <id column="id" property="id"/>
  6. <result column="alarm_id" property="alarmId"/>
  7. <result column="railway_name" property="railwayName"/>
  8. <result column="alarm_time" property="alarmTime"/>
  9. <result column="line_dir" property="lineDir"/>
  10. <result column="alarm_mile" property="alarmMile"/>
  11. <result column="content" property="content"/>
  12. <result column="alarm_level" property="alarmLevel"/>
  13. <result column="alarm_confidence" property="alarmConfidence"/>
  14. <result column="alarm_type" property="alarmType"/>
  15. <result column="alarm_attr" property="alarmAttr"/>
  16. <result column="is_release" property="isRelease"/>
  17. <result column="released_by" property="releasedBy"/>
  18. <result column="released_time" property="releasedTime"/>
  19. <result column="release_content" property="releaseContent"/>
  20. <result column="remark" property="remark"/>
  21. </resultMap>
  22. <select id="list" resultMap="AlarmStatisticDtoResult">
  23. SELECT
  24. a.alarm_id ,
  25. b.railway_name,
  26. a.alarm_time ,
  27. a.line_dir,
  28. a.alarm_mile,
  29. a.alarm_level,
  30. a.content ,
  31. a.alarm_confidence ,
  32. a.alarm_type,
  33. a.alarm_attr,
  34. a.is_release,
  35. a.released_by ,
  36. a.released_time,
  37. a.release_content,
  38. a.remark
  39. FROM
  40. msg_alarm AS a inner join
  41. base_railway_management AS b on a.railway_code=b.railway_code
  42. <where>
  43. <if test="railwayCode != null and railwayCode != ''">
  44. and UPPER(a.railway_code) like UPPER(CONCAT('%',#{railwayCode},'%'))
  45. </if>
  46. <if test="currentYear != null and currentYear != 0">
  47. and YEAR(a.alarm_time) like UPPER(CONCAT('%',#{currentYear},'%'))
  48. </if>
  49. <if test="currentYear == null or currentYear == ''">
  50. and YEAR(a.alarm_time) = YEAR(SYSDATE())
  51. </if>
  52. <if test="currentMonth != null and currentMonth != 0">
  53. and MONTH(a.alarm_time) =#{currentMonth}
  54. </if>
  55. </where>
  56. group by a.alarm_id order by a.alarm_time desc
  57. </select>
  58. <resultMap id="AlarmStatisticMonthDtoResult" type="com.ozs.entity.vo.AlarmStatisticMonthDto">
  59. <id column="id" property="id"/>
  60. <result column="monthsta" property="monthsta"/>
  61. <result column="alarmType" property="alarmType"/>
  62. <result column="monthstaString" property="monthstaString"/>
  63. <result column="frequency" property="frequency"/>
  64. </resultMap>
  65. <select id="alarmTypeCount" resultMap="AlarmStatisticMonthDtoResult">
  66. SELECT sum(p.fre) as frequency,p.alarmType as alarmType
  67. from
  68. (SELECT
  69. a.alarm_type as alarmType,
  70. count(DISTINCT a.alarm_id) as fre
  71. FROM
  72. msg_alarm AS a
  73. <where>
  74. <if test="railwayCode != null and railwayCode != ''">
  75. and UPPER(a.railway_code) like UPPER(CONCAT('%',#{railwayCode},'%'))
  76. </if>
  77. <if test="currentYear != null and currentYear != 0">
  78. and YEAR(a.alarm_time) like UPPER(CONCAT('%',#{currentYear},'%'))
  79. </if>
  80. <if test="currentYear == null or currentYear == ''">
  81. and YEAR(a.alarm_time) = YEAR(SYSDATE())
  82. </if>
  83. <if test="currentMonth != null and currentMonth != 0">
  84. and MONTH(a.alarm_time) =#{currentMonth}
  85. </if>
  86. </where>
  87. group by a.alarm_id) AS p group by p.alarmType
  88. </select>
  89. <select id="listDtoMonth" resultMap="AlarmStatisticMonthDtoResult">
  90. SELECT p.monthsta as monthsta,sum(p.fre) as frequency,p.monthstaString as monthstaString
  91. from
  92. (SELECT
  93. DATE_FORMAT(a.alarm_time,'%Y年%m月') as monthstaString,
  94. MONTH(a.alarm_time) as monthsta,
  95. count(DISTINCT a.alarm_id) as fre
  96. FROM
  97. msg_alarm AS a
  98. <where>
  99. <if test="railwayCode != null and railwayCode != ''">
  100. and UPPER(a.railway_code) like UPPER(CONCAT('%',#{railwayCode},'%'))
  101. </if>
  102. <if test="currentYear != null and currentYear != 0">
  103. and YEAR(a.alarm_time) like UPPER(CONCAT('%',#{currentYear},'%'))
  104. </if>
  105. <if test="currentYear == null or currentYear == ''">
  106. and YEAR(a.alarm_time) = YEAR(SYSDATE())
  107. </if>
  108. <if test="currentMonth != null and currentMonth != 0">
  109. and MONTH(a.alarm_time) =#{currentMonth}
  110. </if>
  111. </where>
  112. group by a.alarm_id) AS p group by p.monthsta order by p.monthsta
  113. </select>
  114. <select id="listDtoDay" resultMap="AlarmStatisticMonthDtoResult">
  115. SELECT p.daysta as monthsta,sum(p.fre) as frequency,p.daystaString as monthstaString
  116. from
  117. (SELECT
  118. DATE_FORMAT(a.alarm_time,'%Y年%m月%d日') as daystaString,
  119. DAY(a.alarm_time) as daysta,
  120. count(DISTINCT a.alarm_id) as fre
  121. FROM
  122. msg_alarm AS a
  123. <where>
  124. <if test="railwayCode != null and railwayCode != ''">
  125. and UPPER(a.railway_code) like UPPER(CONCAT('%',#{railwayCode},'%'))
  126. </if>
  127. <if test="currentYear != null and currentYear != 0">
  128. and YEAR(a.alarm_time) like UPPER(CONCAT('%',#{currentYear},'%'))
  129. </if>
  130. <if test="currentYear == null or currentYear == ''">
  131. and YEAR(a.alarm_time) = YEAR(SYSDATE())
  132. </if>
  133. <if test="currentMonth != null and currentMonth != 0">
  134. and MONTH(a.alarm_time) =#{currentMonth}
  135. </if>
  136. </where>
  137. group by a.alarm_id) AS p group by p.daysta order by p.daysta
  138. </select>
  139. <resultMap id="AlarmTypeStatisticResult" type="com.ozs.entity.vo.AlarmFreqArea">
  140. <id column="id" property="id"/>
  141. <result column="railwayName" property="railwayName"/>
  142. <result column="railwayCode" property="railwayCode"/>
  143. <result column="alarmMile" property="alarmMile"/>
  144. <result column="frequency" property="frequency"/>
  145. </resultMap>
  146. <select id="alarmTypeAreaCount" resultMap="AlarmTypeStatisticResult">
  147. SELECT railwayCode,railwayName,alarmMile,SUM(p.pre) as frequency
  148. from
  149. (SELECT
  150. a.railway_code as railwayCode,
  151. b.railway_name as railwayName,
  152. a.alarm_mile as alarmMile,
  153. count(a.railway_code) as pre
  154. FROM
  155. msg_alarm AS a inner join
  156. base_railway_management b on a.railway_code=b.railway_code
  157. <where>
  158. <if test="railwayCode != null and railwayCode != ''">
  159. and UPPER(a.railway_code) like UPPER(CONCAT('%',#{railwayCode},'%'))
  160. </if>
  161. <if test="currentYear != null and currentYear != 0">
  162. and YEAR(a.alarm_time) like UPPER(CONCAT('%',#{currentYear},'%'))
  163. </if>
  164. <if test="currentYear == null or currentYear == ''">
  165. and YEAR(a.alarm_time) = YEAR(SYSDATE())
  166. </if>
  167. <if test="currentMonth != null and currentMonth != 0">
  168. and MONTH(a.alarm_time) =#{currentMonth}
  169. </if>
  170. </where>
  171. group by a.alarm_id) AS p group by p.railwayCode order by frequency desc
  172. </select>
  173. <select id="getAlarmNum" resultType="java.lang.Long">
  174. select count(DISTINCT alarm_id) as alarmNum
  175. from
  176. msg_alarm
  177. </select>
  178. <select id="selectCameraCode" parameterType="java.lang.String" resultType="java.lang.Integer">
  179. select is_lock from msg_alarm where camera_code = #{cameraCode} ORDER BY alarm_time DESC LIMIT 1
  180. </select>
  181. <select id="selectByCameraCode" parameterType="java.lang.String" resultType="com.ozs.entity.MsgAlarm">
  182. select * from msg_alarm where camera_code = #{cameraCode} order by alarm_time desc limit 1
  183. </select>
  184. <select id="selectMsgAlarmList" resultType="com.ozs.entity.MsgAlarm" parameterType="com.ozs.entity.vo.MsgAlarmVo">
  185. SELECT * FROM msg_alarm
  186. <where>
  187. <if test="railwayCode != null and railwayCode != ''">
  188. and railway_code = #{railwayCode}
  189. </if>
  190. <if test="alarmType != null and alarmType != 0">
  191. and alarm_type = #{alarmType}
  192. </if>
  193. <if test="alarmMile != null and alarmMile != 0">
  194. and alarm_mile = #{alarmMile}
  195. </if>
  196. <if test="isRelease != null and isRelease != 0">
  197. and is_release = #{isRelease}
  198. </if>
  199. <if test="lineDir != null and lineDir != 0">
  200. and line_dir = #{lineDir}
  201. </if>
  202. <if test="beginAlarmTime != null and beginAlarmTime != ''">
  203. and date_format(alarm_time,'%Y-%m-%d %H:%i:%S') &gt;= date_format(#{beginAlarmTime},'%Y-%m-%d %H:%i:%S')
  204. </if>
  205. <if test="endAlarmTime != null and endAlarmTime != ''">
  206. AND date_format(alarm_time,'%Y-%m-%d %H:%i:%S') &lt;= date_format(#{endAlarmTime},'%Y-%m-%d %H:%i:%S')
  207. </if>
  208. </where>
  209. order by alarm_time desc
  210. </select>
  211. <select id="getByAlarmId" resultType="com.ozs.entity.MsgAlarm" parameterType="java.lang.String">
  212. select * from msg_alarm where alarm_id = #{alarmId}
  213. </select>
  214. <select id="countMsg" parameterType="com.ozs.entity.vo.MsgAlarmVo" resultType="java.lang.Integer">
  215. select count(1) from msg_alarm
  216. </select>
  217. <select id="countJC" parameterType="com.ozs.entity.vo.MsgAlarmVo" resultType="java.lang.Integer">
  218. select count(1) from msg_alarm AS a join base_camera_management AS b on a.railway_code=b.railway_code
  219. <where>
  220. a.is_release = 1
  221. <if test="!dsFlay">
  222. and
  223. <trim prefix="(" prefixOverrides="or" suffix=")">
  224. <if test="dsUserId != null and dsUserId != ''">
  225. or a.create_by = #{dsUserId}
  226. </if>
  227. <if test="dsDeptId != null and dsDeptId != 0">
  228. or b.dept_id = #{dsDeptId}
  229. </if>
  230. <if test="dsDeptIds != null">
  231. or b.dept_id in
  232. <foreach item="item" collection="dsDeptIds" separator="," open="(" close=")" index="">
  233. #{item}
  234. </foreach>
  235. </if>
  236. </trim>
  237. </if>
  238. </where>
  239. </select>
  240. <select id="countWJC" parameterType="com.ozs.entity.vo.MsgAlarmVo" resultType="java.lang.Integer">
  241. select count(1) from msg_alarm AS a join base_camera_management AS b on a.camera_code=b.camera_code
  242. <where>
  243. a.is_release = 2
  244. <if test="!dsFlay">
  245. and
  246. <trim prefix="(" prefixOverrides="or" suffix=")">
  247. <if test="dsUserId != null and dsUserId != ''">
  248. or a.create_by = #{dsUserId}
  249. </if>
  250. <if test="dsDeptId != null and dsDeptId != 0">
  251. or b.dept_id = #{dsDeptId}
  252. </if>
  253. <if test="dsDeptIds != null">
  254. or b.dept_id in
  255. <foreach item="item" collection="dsDeptIds" separator="," open="(" close=")" index="">
  256. #{item}
  257. </foreach>
  258. </if>
  259. </trim>
  260. </if>
  261. </where>
  262. </select>
  263. </mapper>