IotAlarmDataMapper.xml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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="param.deviceType != null and param.deviceType != ''">
  27. and a.source_type = #{param.deviceType}
  28. </if>
  29. <if test="param.params.alarmStartTime != null">
  30. and a.time &gt;= #{param.params.alarmStartTime}
  31. </if>
  32. <if test="param.params.alarmEndTime != null">
  33. and a.time &lt;= #{param.params.alarmEndTime}
  34. </if>
  35. <if test="param.params.endAlarmStartTime != null">
  36. and a.end_time &gt;= #{param.params.endAlarmStartTime}
  37. </if>
  38. <if test="param.params.endAlarmEndTime != null">
  39. and a.end_time &lt;= #{param.params.endAlarmEndTime}
  40. </if>
  41. <if test="param.params.dealAlarmStartTime != null">
  42. and a.do_time &gt;= #{param.params.dealAlarmStartTime}
  43. </if>
  44. <if test="param.params.dealAlarmEndTime != null">
  45. and a.do_time &lt;= #{param.params.dealAlarmEndTime}
  46. </if>
  47. <if test="param.isDo != null and param.isDo != ''">
  48. and a.is_do = #{param.isDo}
  49. </if>
  50. <if test="param.isDo == 0">
  51. and a.is_do is null
  52. </if>
  53. order by a.end_time ,a.time desc
  54. </select>
  55. <select id="selectAppPageList" resultType="com.xunmei.iot.vo.alarmData.AppAlarmDataPageVo">
  56. SELECT
  57. a.id,
  58. a.device_name,
  59. a.source_type,
  60. a.source_type_des,
  61. a.time as start_time,
  62. a.end_time,
  63. a.do_time,
  64. a.do_type,
  65. a.do_by_user,
  66. a.do_content,
  67. b.short_name AS org_name
  68. FROM
  69. iot_alarm_data a
  70. LEFT JOIN sys_org b ON a.org_id = b.id
  71. where 1=1
  72. <if test="param.deviceName != null and param.deviceName != ''">
  73. and a.device_name like concat('%',#{param.deviceName},'%')
  74. </if>
  75. <if test="param.orgId != null and param.orgId != ''">
  76. and a.org_id = #{param.orgId}
  77. </if>
  78. <if test="param.orgPath != null and param.orgPath != ''">
  79. and b.path like concat(#{param.orgPath},'%')
  80. </if>
  81. <if test="param.alarmType != null and param.alarmType != ''">
  82. and a.source_type = #{param.alarmType}
  83. </if>
  84. <if test="param.state==0">
  85. and a.end_time is not null
  86. </if>
  87. <if test="param.state==1">
  88. and a.end_time is null
  89. </if>
  90. <if test="param.params != null and param.params.alarmStartTime != null">
  91. and a.time &gt;= #{param.params.alarmStartTime}
  92. </if>
  93. <if test="param.params != null and param.params.alarmEndTime != null">
  94. and a.time &lt;= #{param.params.alarmEndTime}
  95. </if>
  96. <if test="param.isDo != null and param.isDo != ''">
  97. and a.is_do = #{param.isDo}
  98. </if>
  99. <if test="param.isDo == 0">
  100. and a.is_do is null
  101. </if>
  102. order by a.end_time ,a.time desc
  103. </select>
  104. <select id="detail" resultType="com.xunmei.iot.vo.alarm.IotAlarmDataVo">
  105. SELECT a.*,
  106. b.affiliated_area AS city,
  107. b.affiliated_bank AS bank,
  108. b.short_name AS org_name
  109. FROM iot_alarm_data a
  110. LEFT JOIN sys_org b ON a.org_id = b.id
  111. where a.id = #{id}
  112. </select>
  113. <select id="appBadge" resultType="java.lang.Integer">
  114. SELECT count(0)
  115. FROM iot_alarm_data a
  116. where a.org_id = #{orgId} and a.end_time is null
  117. </select>
  118. <select id="selectAlarmDataListByOrgPath" resultType="com.xunmei.common.core.domain.mediator.domain.IotAlarmData">
  119. select d.* from iot_alarm_data d inner join sys_org o on d.org_id = o.id where o.path like concat(#{orgPath},'%') and o.deleted = 0
  120. <if test="dataType != null">
  121. and d.data_type = #{dataType}
  122. </if>
  123. </select>
  124. <select id="selectDeviceTypeCount" resultType="com.xunmei.iot.vo.alarmData.DeviceTypeCountVo">
  125. SELECT
  126. s.device_type AS deviceType,
  127. count(*) AS deviceTypeCount,
  128. (
  129. SELECT
  130. count(*)
  131. FROM
  132. iot_sensor a
  133. WHERE
  134. a.device_type = s.device_type
  135. AND a.state = 1
  136. <if test=" query.checkSub != null and query.checkSub == true">
  137. and a.org_path like concat(concat('%',#{query.orgPath}),'%')
  138. </if>
  139. <if test=" query.checkSub != null and query.checkSub == false">
  140. and a.org_id = #{query.orgId}
  141. </if>
  142. ) AS deviceTypeAlarmCount
  143. FROM
  144. iot_sensor s
  145. WHERE
  146. s.deleted = 0
  147. <if test=" query.checkSub != null and query.checkSub == true">
  148. and s.org_path like concat(concat('%',#{query.orgPath}),'%')
  149. </if>
  150. <if test=" query.checkSub != null and query.checkSub == false">
  151. and s.org_id = #{query.orgId}
  152. </if>
  153. GROUP BY
  154. s.device_type
  155. </select>
  156. <select id="selectSensorAlarmPageList" resultType="com.xunmei.iot.vo.alarm.IotAlarmDataVo">
  157. SELECT
  158. a.*,
  159. b.affiliated_area AS city,
  160. b.affiliated_bank AS bank,
  161. b.short_name AS org_name
  162. FROM
  163. iot_alarm_data a
  164. LEFT JOIN iot_sensor s ON a.device_id = s.device_code AND a.org_id = s.org_id
  165. LEFT JOIN sys_org b ON a.org_id = b.id
  166. WHERE
  167. 1=1
  168. <if test="param.sensorId != null">
  169. and s.id = #{param.sensorId}
  170. </if>
  171. <if test="param.deviceName != null and param.deviceName != ''">
  172. and s.device_name like concat('%',#{param.deviceName},'%')
  173. </if>
  174. ORDER BY
  175. a.`time` DESC,
  176. a.end_time DESC
  177. </select>
  178. <select id="selectAlarmCount" resultType="java.util.Map">
  179. select CAST(d.source_type as CHAR) deviceType, CAST(SUM(1) AS CHAR) as nums
  180. from iot_alarm_data d
  181. inner join sys_org o on o.id = d.org_id
  182. where o.deleted = 0 and data_type=0
  183. and (
  184. (
  185. #{beginTime} <![CDATA[<=]]> d.time
  186. and now() <![CDATA[>=]]> d.time
  187. )
  188. or
  189. (
  190. #{beginTime} <![CDATA[<=]]> d.end_time
  191. and now() <![CDATA[>=]]> d.end_time
  192. )
  193. or (
  194. #{beginTime} <![CDATA[>=]]> d.time
  195. and now() <![CDATA[<=]]> d.end_time
  196. )
  197. )
  198. and o.path like concat(#{orgPath}, '%') and d.source_type is not null
  199. group by d.source_type
  200. </select>
  201. </mapper>