MsgAlarmMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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 /*+ GROUP_OPT_FLAG(1)*/
  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 /*+ GROUP_OPT_FLAG(1)*/ sum(p.fre) as frequency,p.alarmType as alarmType
  67. from
  68. (SELECT /*+ GROUP_OPT_FLAG(1)*/
  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 /*+ GROUP_OPT_FLAG(1)*/ p.monthsta as monthsta,sum(p.fre) as frequency,p.monthstaString as monthstaString
  91. from
  92. (SELECT /*+ GROUP_OPT_FLAG(1)*/
  93. translate(to_char(a.alarm_time, 'yyyy-mm#'),'-#','年月')
  94. /*DATE_FORMAT(a.alarm_time,'%Y年%m月')*/ as monthstaString,
  95. MONTH(a.alarm_time) as monthsta,
  96. count(DISTINCT a.alarm_id) as fre
  97. FROM
  98. msg_alarm AS a
  99. <where>
  100. <if test="railwayCode != null and railwayCode != ''">
  101. and UPPER(a.railway_code) like UPPER(CONCAT('%',#{railwayCode},'%'))
  102. </if>
  103. <if test="currentYear != null and currentYear != 0">
  104. and YEAR(a.alarm_time) like UPPER(CONCAT('%',#{currentYear},'%'))
  105. </if>
  106. <if test="currentYear == null or currentYear == ''">
  107. and YEAR(a.alarm_time) = YEAR(SYSDATE())
  108. </if>
  109. <if test="currentMonth != null and currentMonth != 0">
  110. and MONTH(a.alarm_time) =#{currentMonth}
  111. </if>
  112. </where>
  113. group by a.alarm_id) AS p group by p.monthsta order by p.monthsta
  114. </select>
  115. <select id="listDtoDay" resultMap="AlarmStatisticMonthDtoResult">
  116. SELECT /*+ GROUP_OPT_FLAG(1)*/ p.daysta as monthsta,sum(p.fre) as frequency,p.daystaString as monthstaString
  117. from
  118. (SELECT /*+ GROUP_OPT_FLAG(1)*/
  119. translate(to_char(a.alarm_time, 'yyyy-mm-dd#'),'-#','年月日')
  120. /*DATE_FORMAT(a.alarm_time,'%Y年%m月%d日')*/ as daystaString,
  121. DAY(a.alarm_time) as daysta,
  122. count(DISTINCT a.alarm_id) as fre
  123. FROM
  124. msg_alarm AS a
  125. <where>
  126. <if test="railwayCode != null and railwayCode != ''">
  127. and UPPER(a.railway_code) like UPPER(CONCAT('%',#{railwayCode},'%'))
  128. </if>
  129. <if test="currentYear != null and currentYear != 0">
  130. and YEAR(a.alarm_time) like UPPER(CONCAT('%',#{currentYear},'%'))
  131. </if>
  132. <if test="currentYear == null or currentYear == ''">
  133. and YEAR(a.alarm_time) = YEAR(SYSDATE())
  134. </if>
  135. <if test="currentMonth != null and currentMonth != 0">
  136. and MONTH(a.alarm_time) =#{currentMonth}
  137. </if>
  138. </where>
  139. group by a.alarm_id) AS p group by p.daysta order by p.daysta
  140. </select>
  141. <resultMap id="AlarmTypeStatisticResult" type="com.ozs.entity.vo.AlarmFreqArea">
  142. <id column="id" property="id"/>
  143. <result column="railwayName" property="railwayName"/>
  144. <result column="railwayCode" property="railwayCode"/>
  145. <result column="alarmMile" property="alarmMile"/>
  146. <result column="frequency" property="frequency"/>
  147. </resultMap>
  148. <select id="alarmTypeAreaCount" resultMap="AlarmTypeStatisticResult">
  149. SELECT /*+ GROUP_OPT_FLAG(1)*/ railwayCode,railwayName,alarmMile,SUM(p.pre) as frequency,
  150. p.line_dir AS lineDir
  151. from
  152. (SELECT /*+ GROUP_OPT_FLAG(1)*/
  153. a.railway_code as railwayCode,
  154. b.railway_name as railwayName,
  155. a.alarm_mile as alarmMile,
  156. count(a.railway_code) as pre,
  157. a.line_dir
  158. FROM
  159. msg_alarm AS a inner join
  160. base_railway_management b on a.railway_code=b.railway_code
  161. <where>
  162. <if test="railwayCode != null and railwayCode != ''">
  163. and UPPER(a.railway_code) like UPPER(CONCAT('%',#{railwayCode},'%'))
  164. </if>
  165. <if test="currentYear != null and currentYear != 0">
  166. and YEAR(a.alarm_time) like UPPER(CONCAT('%',#{currentYear},'%'))
  167. </if>
  168. <if test="currentYear == null or currentYear == ''">
  169. and YEAR(a.alarm_time) = YEAR(SYSDATE())
  170. </if>
  171. <if test="currentMonth != null and currentMonth != 0">
  172. and MONTH(a.alarm_time) =#{currentMonth}
  173. </if>
  174. </where>
  175. group by a.alarm_id) AS p group by p.railwayCode order by frequency desc
  176. </select>
  177. <select id="getAlarmNum" resultType="java.lang.Long">
  178. select count(DISTINCT alarm_id) as alarmNum
  179. from msg_alarm
  180. </select>
  181. <select id="selectCameraCode" parameterType="java.lang.String" resultType="java.lang.Integer">
  182. select is_lock
  183. from msg_alarm
  184. where camera_code = #{cameraCode}
  185. ORDER BY alarm_time DESC
  186. LIMIT 1
  187. </select>
  188. <select id="selectByCameraCode" parameterType="java.lang.String" resultType="com.ozs.entity.MsgAlarm">
  189. select *
  190. from msg_alarm
  191. where camera_code = #{cameraCode}
  192. order by alarm_time desc
  193. limit 1
  194. </select>
  195. <!-- and date_format(alarm_time,'%Y-%m-%d %H:%i:%S') &gt;= date_format(#{beginAlarmTime},'%Y-%m-%d
  196. %H:%i:%S') -->
  197. <!-- AND date_format(alarm_time,'%Y-%m-%d %H:%i:%S') &lt;= date_format(#{endAlarmTime},'%Y-%m-%d
  198. %H:%i:%S')-->
  199. <select id="selectMsgAlarmList" resultType="com.ozs.entity.MsgAlarm" parameterType="com.ozs.entity.vo.MsgAlarmVo">
  200. SELECT * FROM msg_alarm
  201. <where>
  202. <if test="railwayCode != null and railwayCode != ''">
  203. and railway_code = #{railwayCode}
  204. </if>
  205. <if test="alarmType != null and alarmType != 0">
  206. and alarm_type = #{alarmType}
  207. </if>
  208. <if test="alarmMile != null and alarmMile != 0">
  209. and alarm_mile = #{alarmMile}
  210. </if>
  211. <if test="beginMile != null and beginMile != 0">
  212. and alarm_mile &gt;= #{beginMile}
  213. </if>
  214. <if test="endMile != null and endMile != 0">
  215. and alarm_mile &lt;= #{endMile}
  216. </if>
  217. <if test="isRelease != null and isRelease != 0">
  218. and is_release = #{isRelease}
  219. </if>
  220. <if test="lineDir != null and lineDir != 0">
  221. and line_dir = #{lineDir}
  222. </if>
  223. <if test="beginAlarmTime != null and beginAlarmTime != ''">
  224. and TO_CHAR(alarm_time, 'YYYY-MM-DD HH24:MI:SS') &gt;= TO_CHAR(#{beginAlarmTime}, 'YYYY-MM-DD
  225. HH24:MI:SS')
  226. </if>
  227. <if test="endAlarmTime != null and endAlarmTime != ''">
  228. and TO_CHAR(alarm_time, 'YYYY-MM-DD HH24:MI:SS') &lt;= TO_CHAR(#{endAlarmTime}, 'YYYY-MM-DD HH24:MI:SS')
  229. </if>
  230. <if test="source != null and source != ''">
  231. and source = #{source}
  232. </if>
  233. </where>
  234. order by alarm_time desc
  235. </select>
  236. <select id="getByAlarmId" resultType="com.ozs.entity.MsgAlarm" parameterType="java.lang.String">
  237. select * from msg_alarm where alarm_id = #{alarmId}
  238. </select>
  239. <select id="countMsg" parameterType="com.ozs.entity.vo.MsgAlarmVo" resultType="java.lang.Integer">
  240. select count(1) from msg_alarm
  241. </select>
  242. <select id="countJC" parameterType="com.ozs.entity.vo.MsgAlarmVo" resultType="java.lang.Integer">
  243. select count(1) from msg_alarm AS a join base_camera_management AS b on a.railway_code=b.railway_code
  244. <where>
  245. a.is_release = 1
  246. <if test="!dsFlay">
  247. and
  248. <trim prefix="(" prefixOverrides="or" suffix=")">
  249. <if test="dsUserId != null and dsUserId != ''">
  250. or a.create_by = #{dsUserId}
  251. </if>
  252. <if test="dsDeptId != null and dsDeptId != 0">
  253. or b.dept_id = #{dsDeptId}
  254. </if>
  255. <if test="dsDeptIds != null">
  256. or b.dept_id in
  257. <foreach item="item" collection="dsDeptIds" separator="," open="(" close=")" index="">
  258. #{item}
  259. </foreach>
  260. </if>
  261. </trim>
  262. </if>
  263. </where>
  264. </select>
  265. <select id="countWJC" parameterType="com.ozs.entity.vo.MsgAlarmVo" resultType="java.lang.Integer">
  266. select count(1) from msg_alarm AS a join base_camera_management AS b on a.railway_code=b.railway_code
  267. <where>
  268. a.is_release = 2
  269. <if test="!dsFlay">
  270. and
  271. <trim prefix="(" prefixOverrides="or" suffix=")">
  272. <if test="dsUserId != null and dsUserId != ''">
  273. or a.create_by = #{dsUserId}
  274. </if>
  275. <if test="dsDeptId != null and dsDeptId != 0">
  276. or b.dept_id = #{dsDeptId}
  277. </if>
  278. <if test="dsDeptIds != null">
  279. or b.dept_id in
  280. <foreach item="item" collection="dsDeptIds" separator="," open="(" close=")" index="">
  281. #{item}
  282. </foreach>
  283. </if>
  284. </trim>
  285. </if>
  286. </where>
  287. </select>
  288. </mapper>