IotAlarmDataMapper.xml 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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.device_type as deviceType ,count(1) as deviceTypeCount,t.alarmNums as deviceTypeAlarmCount
  131. FROM iot_device_info a INNER JOIN (
  132. SELECT s.device_id as deviceId,COUNT(1) as alarmNums from iot_device_info i INNER join iot_device_status s on
  133. i.id = s.device_id and i.iot_token = s.iot_token
  134. WHERE s.state=1
  135. ) t on t.deviceId= a.id
  136. <where>
  137. <if test=" query.checkSub != null and query.checkSub == true">
  138. and a.org_path like concat(concat('%',#{query.orgPath}),'%')
  139. </if>
  140. <if test=" query.checkSub != null and query.checkSub == false">
  141. and a.org_id = #{query.orgId}
  142. </if>
  143. </where>
  144. GROUP BY a.device_type;
  145. </select>
  146. <select id="selectSensorAlarmPageList" resultType="com.xunmei.iot.vo.alarm.IotAlarmDataVo">
  147. SELECT
  148. a.*,
  149. b.affiliated_area AS city,
  150. b.affiliated_bank AS bank,
  151. b.short_name AS org_name
  152. FROM
  153. iot_alarm_data a
  154. LEFT JOIN iot_sensor s ON a.device_id = s.device_code AND a.org_id = s.org_id
  155. LEFT JOIN sys_org b ON a.org_id = b.id
  156. WHERE
  157. 1=1
  158. <if test="param.sensorId != null">
  159. and s.id = #{param.sensorId}
  160. </if>
  161. <if test="param.deviceName != null and param.deviceName != ''">
  162. and s.device_name like concat('%',#{param.deviceName},'%')
  163. </if>
  164. ORDER BY
  165. a.`time` DESC,
  166. a.end_time DESC
  167. </select>
  168. <select id="selectAlarmCount" resultType="java.util.Map">
  169. select CAST(d.source_type as CHAR) deviceType, CAST(SUM(1) AS CHAR) as nums
  170. from iot_alarm_data d
  171. inner join sys_org o on o.id = d.org_id
  172. where o.deleted = 0
  173. and data_type = 0
  174. and (
  175. (
  176. #{beginTime} <![CDATA[<=]]> d.time
  177. and now() <![CDATA[>=]]> d.time
  178. )
  179. or
  180. (
  181. #{beginTime} <![CDATA[<=]]> d.end_time
  182. and now() <![CDATA[>=]]> d.end_time
  183. )
  184. or (
  185. #{beginTime} <![CDATA[>=]]> d.time
  186. and now() <![CDATA[<=]]> d.end_time
  187. )
  188. )
  189. and o.path like concat(#{orgPath}, '%')
  190. and d.source_type is not null
  191. group by d.source_type
  192. </select>
  193. <select id="selectAlarmTypeList" resultType="com.xunmei.iot.vo.alarmData.AlarmTypeSelectedVO">
  194. select product_type as value,
  195. replace(product_name,'传感器','') as label
  196. from iot_alarm_system_field
  197. where product_type not in
  198. <foreach item="name" collection="excludeTypes" separator="," open="(" close=")">
  199. #{name}
  200. </foreach>
  201. <choose>
  202. <when test=" category == null or category =='' ">
  203. and (product_type like 'FSU_%' or product_type like 'AlarmHostInput_%')
  204. </when>
  205. <when test=" category == '0' ">
  206. and product_type like 'FSU_%'
  207. </when>
  208. <when test=" category == '2'">
  209. and (product_type like 'AlarmHostInput_%' or product_type in
  210. <foreach item="name" collection="mixTypes" separator="," open="(" close=")">
  211. #{name}
  212. </foreach>
  213. )
  214. </when>
  215. <otherwise>
  216. </otherwise>
  217. </choose>
  218. group by product_type
  219. </select>
  220. </mapper>