KwsAlarmMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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.sckw.slope.detection.dao.mysql.KwsAlarmMapper">
  4. <resultMap id="BaseResultMap" type="com.sckw.slope.detection.model.dos.mysql.KwsAlarm">
  5. <!--@mbg.generated-->
  6. <!--@Table kws_alarm-->
  7. <id column="id" jdbcType="BIGINT" property="id"/>
  8. <result column="title" jdbcType="VARCHAR" property="title"/>
  9. <result column="company_id" jdbcType="VARCHAR" property="companyId"/>
  10. <result column="mountain_id" jdbcType="VARCHAR" property="mountainId"/>
  11. <result column="project_id" jdbcType="VARCHAR" property="projectId"/>
  12. <result column="device_id" jdbcType="VARCHAR" property="deviceId"/>
  13. <result column="level" jdbcType="INTEGER" property="level"/>
  14. <result column="trigger_times" jdbcType="INTEGER" property="triggerTimes"/>
  15. <result column="type" jdbcType="INTEGER" property="type"/>
  16. <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
  17. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
  18. <result column="status" jdbcType="TINYINT" property="status"/>
  19. <result column="is_history" jdbcType="TINYINT" property="isHistory"/>
  20. <result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
  21. </resultMap>
  22. <sql id="Base_Column_List">
  23. <!--@mbg.generated-->
  24. id,
  25. title,
  26. `level`,
  27. `type`,
  28. create_time,
  29. `status`,
  30. company_id,
  31. mountain_id,
  32. project_id,
  33. update_time,
  34. device_id,
  35. trigger_times,
  36. is_history,
  37. del_flag
  38. </sql>
  39. <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
  40. <!--@mbg.generated-->
  41. select
  42. <include refid="Base_Column_List"/>
  43. from kws_alarm
  44. where id = #{id,jdbcType=BIGINT}
  45. </select>
  46. <select id="selectByDevicesId" parameterType="java.lang.String" resultType="java.util.Map">
  47. <!--@mbg.generated-->
  48. select count(d.id) as count,a.device_id,type
  49. from kws_alarm as a inner join kws_alarm_detail as d
  50. on a.id=d.alarm_id
  51. where a.type = 1
  52. and a.del_flag = 0
  53. <if test="devicesId != null and devicesId.size() > 0">
  54. AND device_id IN
  55. <foreach collection="devicesId" open="(" close=")" item="item" separator=",">
  56. #{item}
  57. </foreach>
  58. AND d.pid IN
  59. <foreach collection="devicesId" open="(" close=")" item="item" separator=",">
  60. #{item}
  61. </foreach>
  62. </if>
  63. group by device_id, type
  64. </select>
  65. <select id="selectDataByDevicesId" parameterType="java.lang.String" resultType="java.util.Map">
  66. <!--@mbg.generated-->
  67. select sum(trigger_times) as count,a.device_id,type
  68. from kws_alarm as a
  69. where a.del_flag = 0
  70. <if test="devicesId != null and devicesId.size() > 0">
  71. AND device_id IN
  72. <foreach collection="devicesId" open="(" close=")" item="item" separator=",">
  73. #{item}
  74. </foreach>
  75. </if>
  76. group by device_id
  77. </select>
  78. <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
  79. <!--@mbg.generated-->
  80. delete
  81. from kws_alarm
  82. where id = #{id,jdbcType=BIGINT}
  83. </delete>
  84. <insert id="insertSelective" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsAlarm">
  85. <!--@mbg.generated-->
  86. insert into kws_alarm
  87. <trim prefix="(" suffix=")" suffixOverrides=",">
  88. <if test="id != null">
  89. id,
  90. </if>
  91. <if test="pid != null">
  92. pid,
  93. </if>
  94. <if test="title != null">
  95. title,
  96. </if>
  97. <if test="val != null">
  98. val,
  99. </if>
  100. <if test="content != null">
  101. content,
  102. </if>
  103. <if test="level != null">
  104. `level`,
  105. </if>
  106. <if test="type != null">
  107. `type`,
  108. </if>
  109. <if test="lat != null">
  110. lat,
  111. </if>
  112. <if test="lng != null">
  113. lng,
  114. </if>
  115. <if test="alt != null">
  116. alt,
  117. </if>
  118. <if test="createTime != null">
  119. create_time,
  120. </if>
  121. <if test="triggerTimes != null">
  122. trigger_times,
  123. </if>
  124. <if test="status != null">
  125. `status`,
  126. </if>
  127. </trim>
  128. <trim prefix="values (" suffix=")" suffixOverrides=",">
  129. <if test="id != null">
  130. #{id,jdbcType=BIGINT},
  131. </if>
  132. <if test="pid != null">
  133. #{pid,jdbcType=BIGINT},
  134. </if>
  135. <if test="title != null">
  136. #{title,jdbcType=VARCHAR},
  137. </if>
  138. <if test="val != null">
  139. #{val,jdbcType=VARCHAR},
  140. </if>
  141. <if test="content != null">
  142. #{content,jdbcType=VARCHAR},
  143. </if>
  144. <if test="level != null">
  145. #{level,jdbcType=INTEGER},
  146. </if>
  147. <if test="type != null">
  148. #{type,jdbcType=INTEGER},
  149. </if>
  150. <if test="lat != null">
  151. #{lat,jdbcType=VARCHAR},
  152. </if>
  153. <if test="lng != null">
  154. #{lng,jdbcType=VARCHAR},
  155. </if>
  156. <if test="alt != null">
  157. #{alt,jdbcType=VARCHAR},
  158. </if>
  159. <if test="createTime != null">
  160. #{createTime,jdbcType=TIMESTAMP},
  161. </if>
  162. <if test="triggerTimes != null">
  163. #{triggerTimes,jdbcType=INTEGER},
  164. </if>
  165. <if test="status != null">
  166. #{status,jdbcType=TINYINT},
  167. </if>
  168. </trim>
  169. </insert>
  170. <update id="updateByPrimaryKeySelective" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsAlarm">
  171. <!--@mbg.generated-->
  172. update kws_alarm
  173. <set>
  174. <if test="pid != null">
  175. pid = #{pid,jdbcType=BIGINT},
  176. </if>
  177. <if test="title != null">
  178. title = #{title,jdbcType=VARCHAR},
  179. </if>
  180. <if test="val != null">
  181. val = #{val,jdbcType=VARCHAR},
  182. </if>
  183. <if test="content != null">
  184. content = #{content,jdbcType=VARCHAR},
  185. </if>
  186. <if test="level != null">
  187. `level` = #{level,jdbcType=INTEGER},
  188. </if>
  189. <if test="type != null">
  190. `type` = #{type,jdbcType=INTEGER},
  191. </if>
  192. <if test="lat != null">
  193. lat = #{lat,jdbcType=VARCHAR},
  194. </if>
  195. <if test="lng != null">
  196. lng = #{lng,jdbcType=VARCHAR},
  197. </if>
  198. <if test="alt != null">
  199. alt = #{alt,jdbcType=VARCHAR},
  200. </if>
  201. <if test="createTime != null">
  202. create_time = #{createTime,jdbcType=TIMESTAMP},
  203. </if>
  204. <if test="triggerTimes != null">
  205. trigger_times = #{triggerTimes,jdbcType=INTEGER},
  206. </if>
  207. <if test="status != null">
  208. `status` = #{status,jdbcType=TINYINT},
  209. </if>
  210. </set>
  211. where id = #{id,jdbcType=BIGINT}
  212. </update>
  213. <update id="updateByPrimaryKey" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsAlarm">
  214. <!--@mbg.generated-->
  215. update kws_alarm
  216. set pid = #{pid,jdbcType=BIGINT},
  217. title = #{title,jdbcType=VARCHAR},
  218. val = #{val,jdbcType=VARCHAR},
  219. content = #{content,jdbcType=VARCHAR},
  220. `level` = #{level,jdbcType=INTEGER},
  221. `type` = #{type,jdbcType=INTEGER},
  222. lat = #{lat,jdbcType=VARCHAR},
  223. lng = #{lng,jdbcType=VARCHAR},
  224. alt = #{alt,jdbcType=VARCHAR},
  225. create_time = #{createTime,jdbcType=TIMESTAMP},
  226. trigger_times = #{triggerTimes,jdbcType=INTEGER},
  227. `status` = #{status,jdbcType=TINYINT}
  228. where id = #{id,jdbcType=BIGINT}
  229. </update>
  230. <select id="getDataAlarmToDay" resultType="java.util.Map">
  231. SELECT DATE_FORMAT(h.h, '%Y-%m-%d %H:00:00') AS dateTime, COUNT(t.id) AS number
  232. FROM (SELECT #{startTime} + INTERVAL n HOUR AS h
  233. FROM (
  234. SELECT 0 AS n
  235. UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5
  236. UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL SELECT 10
  237. UNION ALL SELECT 11 UNION ALL SELECT 12 UNION ALL SELECT 13 UNION ALL SELECT 14 UNION ALL SELECT 15
  238. UNION ALL SELECT 16 UNION ALL SELECT 17 UNION ALL SELECT 18 UNION ALL SELECT 19 UNION ALL SELECT 20
  239. UNION ALL SELECT 21 UNION ALL SELECT 22 UNION ALL SELECT 23
  240. ) hours) h
  241. LEFT JOIN
  242. (SELECT a.id,
  243. a.create_time,
  244. b.project_id as projectId,
  245. b.company_id as companyId,
  246. b.mountain_id as mountainId
  247. FROM kws_alarm_detail a
  248. LEFT JOIN kws_alarm b ON a.alarm_id = b.id and a.del_flag = 0
  249. <where>
  250. <if test="type != null and type != ''">
  251. and b.type = #{type}
  252. </if>
  253. <if test="mountainId != null and mountainId != ''">
  254. and b.mountain_id = #{mountainId}
  255. </if>
  256. <if test="level != null and level != ''">
  257. and b.level = #{level}
  258. </if>
  259. </where>
  260. ) t
  261. ON DATE_FORMAT(t.create_time, '%Y-%m-%d %H') = DATE_FORMAT(h.h, '%Y-%m-%d %H')
  262. WHERE h.h BETWEEN #{startTime}
  263. AND #{endTime}
  264. GROUP BY dateTime
  265. ORDER BY dateTime ASC;
  266. </select>
  267. <select id="getDataAlarmToWeek" resultType="java.util.Map">
  268. SELECT a.date as dateTime, COALESCE(b.number, 0) as number
  269. from (select date_add(#{dateTimeFormat}, interval row1 DAY) date
  270. from
  271. (
  272. SELECT @row := @row + 1 as row1 FROM
  273. (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union
  274. all select 6 union all select 7 union all select 8 union all select 9) t, (select 0 union all select 1 union all
  275. select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union
  276. all select 8 union all select 9) t2, (select 0 union all select 1 union all select 2 union all select 3 union
  277. all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t3, (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union
  278. all select 6 union all select 7 union all select 8 union all select 9) t4, (SELECT @row := -1) r
  279. ) se
  280. where date_add(#{startTime}
  281. , interval row1 DAY) &lt;= #{endTime}) a
  282. LEFT JOIN
  283. (SELECT count(b.id) as number,
  284. DATE_FORMAT(b.create_time, '%Y-%m-%d') date_time,
  285. a.project_id as projectId,
  286. a.company_id as companyId,
  287. a.mountain_id as mountainId
  288. FROM kws_alarm a
  289. LEFT JOIN
  290. kws_alarm_detail b on a.id = b.alarm_id and b.del_flag = 0
  291. <where>
  292. <if test="type != null and type != ''">
  293. and a.type = #{type}
  294. </if>
  295. <if test="mountainId != null and mountainId != ''">
  296. and a.mountain_id = #{mountainId}
  297. </if>
  298. <if test="projectId != null and projectId != ''">
  299. and a.project_id = #{projectId}
  300. </if>
  301. <if test="level != null and level != ''">
  302. and a.level = #{level}
  303. </if>
  304. </where>
  305. GROUP BY DATE_FORMAT(b.create_time, '%Y-%m-%d')) b ON a.date = b.date_time
  306. </select>
  307. <select id="getDataAlarmToYear" resultType="java.util.Map">
  308. SELECT a.dateTime AS dateTime,
  309. COALESCE(b.number, 0) AS number
  310. FROM (SELECT DATE_FORMAT(DATE_ADD(#{startTime}, INTERVAL ROW1 MONTH ), '%Y-%m') dateTime
  311. FROM (SELECT @ROW := @ROW + 1 AS row1
  312. FROM
  313. (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t, (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t2, (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t3, (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t4, ( SELECT @ROW := - 1 ) r) se
  314. WHERE date_add(#{startTime}, INTERVAL row1 MONTH ) &lt;= #{endTime}) a
  315. LEFT JOIN (SELECT count(b.id) AS number,
  316. DATE_FORMAT(b.create_time, '%Y-%m') dateTime
  317. FROM kws_alarm a
  318. LEFT JOIN kws_alarm_detail b ON a.id = b.alarm_id and b.del_flag = 0
  319. <where>
  320. <if test="type != null and type != ''">
  321. and a.type = #{type}
  322. </if>
  323. <if test="mountainId != null and mountainId != ''">
  324. and a.mountain_id = #{mountainId}
  325. </if>
  326. <if test="projectId != null and projectId != ''">
  327. and a.project_id = #{projectId}
  328. </if>
  329. <if test="level != null and level != ''">
  330. and a.level = #{level}
  331. </if>
  332. </where>
  333. GROUP BY DATE_FORMAT(b.create_time, '%Y-%m')) b ON a.dateTime = b.dateTime
  334. </select>
  335. <select id="getProjectAlarmList" resultType="java.util.Map">
  336. SELECT project_id as projectId,
  337. COUNT(DISTINCT b.id) as alarmTotal
  338. FROM kws_alarm a
  339. LEFT JOIN kws_alarm_detail b ON a.id = b.alarm_id and b.del_flag = 0
  340. <where>
  341. <if test="type != null and type != ''">
  342. and a.type = #{type}
  343. </if>
  344. <if test="startTime != null and startTime != ''">
  345. and b.create_time &gt; #{startTime}
  346. </if>
  347. <if test="endTime != null and endTime != ''">
  348. and b.create_time &lt; #{endTime}
  349. </if>
  350. <if test="level != null and level != ''">
  351. and a.level = #{level}
  352. </if>
  353. </where>
  354. GROUP BY a.project_id
  355. </select>
  356. <select id="selectDetailList" resultType="com.sckw.slope.detection.model.vo.AlarmLogThresholdVO">
  357. SELECT a.id AS id,
  358. b.project_id AS projectId,
  359. b.mountain_id AS mountainId,
  360. b.title AS title,
  361. a.val AS val,
  362. b.`level` AS LEVEL,
  363. a.create_time AS createTime
  364. FROM kws_alarm_detail a
  365. LEFT JOIN kws_alarm b ON a.alarm_id = b.id
  366. WHERE a.mountain_id = b.mountain_id
  367. and b.`status` = 0
  368. ORDER BY a.create_time DESC
  369. <!-- <if test="page != null and pageSize !=null ">-->
  370. <!-- limit #{page} , #{pageSize}-->
  371. <!-- </if>-->
  372. </select>
  373. <select id="selectDetailCount" resultType="int">
  374. </select>
  375. <select id="selectListByQuery" resultMap="BaseResultMap">
  376. select
  377. <include refid="Base_Column_List">
  378. </include>
  379. from kws_alarm
  380. <where>
  381. del_flag = 0
  382. and trigger_times > 0
  383. <if test="mountainId != null and mountainId != ''">
  384. and mountain_id = #{mountainId}
  385. </if>
  386. <if test="query.projectId != null and query.projectId != ''">
  387. and project_id = #{query.projectId}
  388. </if>
  389. <if test="query.alarmInfo != null and query.alarmInfo != ''">
  390. and title = #{query.alarmInfo}
  391. </if>
  392. <if test="query.status != null">
  393. and status = #{query.status}
  394. </if>
  395. <!-- <if test="query.status != null and query.status != ''">-->
  396. <!-- and is_history = #{query.status}-->
  397. <!-- </if>-->
  398. <if test="query.alarmLevel != null and query.alarmLevel != ''">
  399. and level = #{query.alarmLevel}
  400. </if>
  401. <if test="query.deviceName != null and query.deviceName != ''">
  402. and device_id in
  403. (SELECT id FROM kws_device WHERE del_flag = 0 and name like concat('%', #{query.deviceName}, '%'))
  404. </if>
  405. </where>
  406. </select>
  407. <select id="selectExportListByQuery" resultMap="BaseResultMap">
  408. select
  409. <include refid="Base_Column_List">
  410. </include>
  411. from kws_alarm
  412. <where>
  413. del_flag = 0 and trigger_times > 0
  414. <if test="idsList != null and idsList.size() > 0">
  415. and id in
  416. <foreach collection="idsList" item="item" open="(" close=")" separator=",">
  417. #{item}
  418. </foreach>
  419. </if>
  420. <if test="mountainId != null and mountainId != ''">
  421. and mountain_id = #{mountainId}
  422. </if>
  423. <if test="query.projectId != null and query.projectId != ''">
  424. and project_id = #{query.projectId}
  425. </if>
  426. <if test="query.alarmInfo != null and query.alarmInfo != ''">
  427. and title = #{query.alarmInfo}
  428. </if>
  429. <if test="query.status != null and query.status != ''">
  430. and status = #{query.status}
  431. </if>
  432. <!-- <if test="query.status != null and query.status != ''">-->
  433. <!-- and is_history = #{query.status}-->
  434. <!-- </if>-->
  435. <if test="query.alarmLevel != null and query.alarmLevel != ''">
  436. and level = #{query.alarmLevel}
  437. </if>
  438. <if test="query.deviceName != null and query.deviceName != ''">
  439. and device_id in
  440. (SELECT id
  441. FROM kws_device
  442. WHERE del_flag = 0
  443. and name like concat('%'
  444. , #{query.deviceName}
  445. , '%'))
  446. </if>
  447. </where>
  448. </select>
  449. </mapper>