IotAlarmDataMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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.xunmei.iot.mapper.IotAlarmDataMapper">
  4. <select id="selectPageList" resultType="com.xunmei.iot.vo.alarm.IotAlarmDataVo">
  5. SELECT
  6. a.*,
  7. b.affiliated_area AS city,
  8. b.affiliated_bank AS bank,
  9. b.short_name AS org_name
  10. FROM
  11. iot_alarm_data a
  12. LEFT JOIN sys_org b ON a.org_id = b.id
  13. LEFT JOIN iot_device_info d ON a.device_id = d.id
  14. where 1=1 and d.deleted = 0
  15. <if test="param.deviceName != null and param.deviceName != ''">
  16. and a.device_name like concat('%',#{param.deviceName},'%')
  17. </if>
  18. <if test="param.orgId != null and param.orgId != ''">
  19. and a.org_id = #{param.orgId}
  20. </if>
  21. <if test="param.orgPath != null and param.orgPath != ''">
  22. and b.path like concat(#{param.orgPath},'%')
  23. </if>
  24. <if test="param.dataType != null">
  25. and a.data_type = #{param.dataType}
  26. </if>
  27. <if test=" deviceTypeList!= null and deviceTypeList.size() > 0">
  28. and a.source_type in
  29. <foreach collection="deviceTypeList" index="index" item="item" open="(" separator="," close=")">
  30. #{item}
  31. </foreach>
  32. </if>
  33. <if test="param.params.alarmStartTime != null">
  34. and a.time &gt;= #{param.params.alarmStartTime}
  35. </if>
  36. <if test="param.params.alarmEndTime != null">
  37. and a.time &lt;= #{param.params.alarmEndTime}
  38. </if>
  39. <if test="param.params.endAlarmStartTime != null">
  40. and a.end_time &gt;= #{param.params.endAlarmStartTime}
  41. </if>
  42. <if test="param.params.endAlarmEndTime != null">
  43. and a.end_time &lt;= #{param.params.endAlarmEndTime}
  44. </if>
  45. <if test="param.params.dealAlarmStartTime != null">
  46. and a.do_time &gt;= #{param.params.dealAlarmStartTime}
  47. </if>
  48. <if test="param.params.dealAlarmEndTime != null">
  49. and a.do_time &lt;= #{param.params.dealAlarmEndTime}
  50. </if>
  51. <if test="param.isDo != null and param.isDo != ''">
  52. and a.is_do = #{param.isDo}
  53. </if>
  54. <if test="param.isDo == 0">
  55. and a.is_do is null
  56. </if>
  57. order by a.end_time ,a.time desc
  58. </select>
  59. <select id="selectAppPageList" resultType="com.xunmei.iot.vo.alarmData.AppAlarmDataPageVo">
  60. SELECT
  61. a.id,
  62. a.device_name,
  63. a.source_type,
  64. a.source_type_des,
  65. a.time as start_time,
  66. a.end_time,
  67. a.do_time,
  68. a.do_type,
  69. a.do_by_user,
  70. a.do_content,
  71. b.short_name AS org_name
  72. FROM
  73. iot_alarm_data a
  74. LEFT JOIN sys_org b ON a.org_id = b.id
  75. LEFT JOIN iot_device_info d ON a.device_id = d.id
  76. where 1=1 and d.deleted = 0
  77. <if test="param.deviceName != null and param.deviceName != ''">
  78. and a.device_name like concat('%',#{param.deviceName},'%')
  79. </if>
  80. <if test="param.orgId != null and param.orgId != ''">
  81. and a.org_id = #{param.orgId}
  82. </if>
  83. <if test="param.orgPath != null and param.orgPath != ''">
  84. and b.path like concat(#{param.orgPath},'%')
  85. </if>
  86. <if test="param.alarmType != null and param.alarmType != ''">
  87. and a.source_type = #{param.alarmType}
  88. </if>
  89. <if test="param.state==0">
  90. and a.end_time is not null
  91. </if>
  92. <if test="param.state==1">
  93. and a.end_time is null
  94. </if>
  95. <if test="param.params != null and param.params.alarmStartTime != null">
  96. and a.time &gt;= #{param.params.alarmStartTime}
  97. </if>
  98. <if test="param.params != null and param.params.alarmEndTime != null">
  99. and a.time &lt;= #{param.params.alarmEndTime}
  100. </if>
  101. <if test="param.isDo != null and param.isDo != ''">
  102. and a.is_do = #{param.isDo}
  103. </if>
  104. <if test="param.isDo == 0">
  105. and a.is_do is null
  106. </if>
  107. order by a.end_time ,a.time desc
  108. </select>
  109. <select id="detail" resultType="com.xunmei.iot.vo.alarm.IotAlarmDataVo">
  110. SELECT a.*,
  111. b.affiliated_area AS city,
  112. b.affiliated_bank AS bank,
  113. b.short_name AS org_name
  114. FROM iot_alarm_data a
  115. LEFT JOIN sys_org b ON a.org_id = b.id
  116. where a.id = #{id}
  117. </select>
  118. <select id="appBadge" resultType="java.lang.Integer">
  119. SELECT count(0)
  120. FROM iot_alarm_data a
  121. where a.org_id = #{orgId}
  122. and a.end_time is null
  123. </select>
  124. <select id="selectAlarmDataListByOrgPath" resultType="com.xunmei.common.core.domain.mediator.domain.IotAlarmData">
  125. SELECT
  126. d.*
  127. FROM
  128. iot_alarm_data d
  129. INNER JOIN sys_org o ON d.org_id = o.id
  130. LEFT JOIN iot_device_info i ON d.device_id = i.id
  131. where
  132. o.path like concat(#{orgPath},'%')
  133. and o.deleted = 0
  134. and i.deleted = 0
  135. <if test="dataType != null">
  136. and d.data_type = #{dataType}
  137. </if>
  138. </select>
  139. <select id="selectDeviceTypeCount" resultType="com.xunmei.iot.vo.alarmData.DeviceTypeCountVo">
  140. SELECT a.id,
  141. a.device_type as deviceType,
  142. count(1) as deviceTypeCount,
  143. t.alarmNums as deviceTypeAlarmCount
  144. FROM iot_device_info a
  145. left JOIN (
  146. SELECT s.device_id as deviceId,
  147. COUNT(1) as alarmNums
  148. from iot_device_info i
  149. INNER join iot_device_status s on i.id = s.device_id and i.iot_token = s.iot_token and i.deleted = 0
  150. WHERE s.state=1
  151. group by s.device_id
  152. ) t on t.deviceId= a.id
  153. WHERE a.deleted = 0
  154. <if test=" query.checkSub != null and query.checkSub == true">
  155. and a.org_path like concat(concat('%',#{query.orgPath}),'%')
  156. </if>
  157. <if test=" query.checkSub != null and query.checkSub == false">
  158. and a.org_id = #{query.orgId}
  159. </if>
  160. GROUP BY a.id
  161. union all
  162. SELECT a.id,
  163. a.sensor_type as deviceType,
  164. count(1) as deviceTypeCount,
  165. t.alarmNums as deviceTypeAlarmCount
  166. FROM iot_alarm_defence_area a
  167. left JOIN (
  168. SELECT a.id as deviceId,
  169. sum(IF(a.state='alarm',1,0)) as alarmNums FROM iot_alarm_defence_area a where a.deleted=0 GROUP BY a.id
  170. ) t on a.id=t.deviceId WHERE a.deleted = 0
  171. <if test=" query.checkSub != null and query.checkSub == true">
  172. and a.org_path like concat(concat('%',#{query.orgPath}),'%')
  173. </if>
  174. <if test=" query.checkSub != null and query.checkSub == false">
  175. and a.org_id = #{query.orgId}
  176. </if>
  177. GROUP BY a.id;
  178. </select>
  179. <select id="selectSensorAlarmPageList" resultType="com.xunmei.iot.vo.alarm.IotAlarmDataVo">
  180. SELECT
  181. a.*,
  182. b.affiliated_area AS city,
  183. b.affiliated_bank AS bank,
  184. b.short_name AS org_name
  185. FROM
  186. iot_alarm_data a
  187. LEFT JOIN iot_sensor s ON a.device_id = s.device_code AND a.org_id = s.org_id
  188. LEFT JOIN sys_org b ON a.org_id = b.id
  189. WHERE
  190. 1=1
  191. <if test="param.sensorId != null">
  192. and s.id = #{param.sensorId}
  193. </if>
  194. <if test="param.deviceName != null and param.deviceName != ''">
  195. and s.device_name like concat('%',#{param.deviceName},'%')
  196. </if>
  197. ORDER BY
  198. a.`time` DESC,
  199. a.end_time DESC
  200. </select>
  201. <select id="selectAlarmCount" resultType="java.util.Map">
  202. select CAST(d.source_type as CHAR) deviceType, CAST(SUM(1) AS CHAR) as nums
  203. from iot_alarm_data d
  204. inner join sys_org o on o.id = d.org_id
  205. where o.deleted = 0
  206. and data_type = 0
  207. and (
  208. (
  209. #{beginTime} <![CDATA[<=]]> d.time
  210. and now() <![CDATA[>=]]> d.time
  211. )
  212. or
  213. (
  214. #{beginTime} <![CDATA[<=]]> d.end_time
  215. and now() <![CDATA[>=]]> d.end_time
  216. )
  217. or (
  218. #{beginTime} <![CDATA[>=]]> d.time
  219. and now() <![CDATA[<=]]> d.end_time
  220. )
  221. )
  222. and o.path like concat(#{orgPath}, '%')
  223. and d.source_type is not null
  224. group by d.source_type
  225. </select>
  226. <select id="selectAlarmTypeList" resultType="com.xunmei.iot.vo.alarmData.AlarmTypeSelectedVO">
  227. select product_type as value,
  228. replace(product_name,'传感器','') as label
  229. from iot_alarm_system_field
  230. where product_type not in
  231. <foreach item="name" collection="excludeTypes" separator="," open="(" close=")">
  232. #{name}
  233. </foreach>
  234. <choose>
  235. <when test=" category == null or category =='' ">
  236. and (product_type like 'FSU_%' or product_type like 'AlarmHostInput_%')
  237. </when>
  238. <when test=" category == '0' ">
  239. and product_type like 'FSU_%'
  240. </when>
  241. <when test=" category == '2'">
  242. and (product_type like 'AlarmHostInput_%' or product_type in
  243. <foreach item="name" collection="mixTypes" separator="," open="(" close=")">
  244. #{name}
  245. </foreach>
  246. )
  247. </when>
  248. <otherwise>
  249. </otherwise>
  250. </choose>
  251. group by product_type
  252. </select>
  253. <select id="selectUpsAlarmCount" resultType="java.lang.Integer">
  254. select CAST(SUM(1) AS CHAR) as nums
  255. from iot_alarm_data d
  256. inner join sys_org o on o.id = d.org_id
  257. where o.deleted = 0
  258. and data_type = 0
  259. and (
  260. (
  261. #{beginTime} <![CDATA[<=]]> d.time
  262. and now() <![CDATA[>=]]> d.time
  263. )
  264. or
  265. (
  266. #{beginTime} <![CDATA[<=]]> d.end_time
  267. and now() <![CDATA[>=]]> d.end_time
  268. )
  269. or (
  270. #{beginTime} <![CDATA[>=]]> d.time
  271. and now() <![CDATA[<=]]> d.end_time
  272. )
  273. )
  274. and o.path like concat(#{orgPath}, '%')
  275. and d.source_type = 'FSU_Ups'
  276. </select>
  277. <select id="getByProductTypesAndOrgId"
  278. resultType="com.xunmei.common.core.domain.mediator.domain.IotAlarmData">
  279. SELECT
  280. d.*
  281. FROM
  282. iot_alarm_data d
  283. INNER JOIN sys_org o ON d.org_id = o.id
  284. WHERE
  285. o.id = #{orgId}
  286. AND o.deleted = 0
  287. <if test="dataType != null">
  288. and d.data_type = #{dataType}
  289. </if>
  290. <if test="productTypes !=null and productTypes.size()>0">
  291. and d.source_type in
  292. <foreach collection="productTypes" item="item" open="(" separator="," close=")">
  293. #{item}
  294. </foreach>
  295. </if>
  296. </select>
  297. </mapper>