IotAlarmDataMapper.xml 9.4 KB

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