OnlineMonitorMapper.xml 15 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.huaxu.dao.OnlineMonitorMapper">
  4. <!-- 结果集 -->
  5. <resultMap type="com.huaxu.dto.MonitorDataCollectDto" id="monitorDataMap">
  6. <result property="sceneId" column="scene_id" jdbcType="INTEGER"/>
  7. <result property="sceneName" column="scene_name" jdbcType="VARCHAR"/>
  8. <result property="pointX" column="point_x" jdbcType="VARCHAR"/>
  9. <result property="pointY" column="point_y" jdbcType="VARCHAR"/>
  10. <result property="address" column="address" jdbcType="VARCHAR"/>
  11. <result property="sceneState" column="scene_state" jdbcType="INTEGER"/>
  12. <collection property="MonitorDataEntities" ofType="com.huaxu.dto.MonitorDataDto" javaType="list">
  13. <result property="deviceId" column="device_id" jdbcType="INTEGER"/>
  14. <result property="attributeId" column="attribute_id" jdbcType="INTEGER"/>
  15. <result property="attributeName" column="attribute_name" jdbcType="VARCHAR"/>
  16. <result property="unit" column="unit" jdbcType="VARCHAR"/>
  17. <result property="isAlarm" column="is_Alarm" jdbcType="VARCHAR"/>
  18. <result property="attributeType" column="attribute_type" jdbcType="VARCHAR"/>
  19. <result property="deviceCode" column="device_code" jdbcType="VARCHAR"/>
  20. <result property="latestValue" column="latest_value" jdbcType="VARCHAR"/>
  21. </collection>
  22. </resultMap>
  23. <!-- 设备结果集 -->
  24. <resultMap type="com.huaxu.dto.MonitorDataCollectDto" id="deviceDataMap">
  25. <result property="sceneId" column="scene_id" jdbcType="INTEGER"/>
  26. <result property="sceneName" column="scene_name" jdbcType="VARCHAR"/>
  27. <result property="deviceId" column="device_id" jdbcType="INTEGER"/>
  28. <result property="deviceCode" column="device_code" jdbcType="VARCHAR"/>
  29. <result property="deviceName" column="device_name" jdbcType="VARCHAR"/>
  30. <result property="pointX" column="point_x" jdbcType="VARCHAR"/>
  31. <result property="pointY" column="point_y" jdbcType="VARCHAR"/>
  32. <result property="address" column="address" jdbcType="VARCHAR"/>
  33. <result property="sceneState" column="scene_state" jdbcType="INTEGER"/>
  34. <collection property="MonitorDataEntities" ofType="com.huaxu.dto.MonitorDataDto" javaType="list">
  35. <result property="attributeId" column="attribute_id" jdbcType="INTEGER"/>
  36. <result property="attributeName" column="attribute_name" jdbcType="VARCHAR"/>
  37. <result property="unit" column="unit" jdbcType="VARCHAR"/>
  38. <result property="isAlarm" column="is_Alarm" jdbcType="VARCHAR"/>
  39. </collection>
  40. </resultMap>
  41. <sql id="Base_Column_List">
  42. t1.id scene_Id,
  43. t1.scene_name ,
  44. t1.point_x ,
  45. t1.point_y,
  46. t1.address ,
  47. t5.device_id,
  48. t5.attribute_id ,
  49. ifnull(t5.remark, t9.`name`) attribute_name,
  50. t9.unit ,
  51. case when t5.attribute_id is null then null when t6.id is null then 0 else 1 end is_alarm,
  52. t5.parm_type attribute_type,
  53. if (t5.device_id is null, null, t4.device_code) device_code
  54. </sql>
  55. <sql id="sceneDeviceJoins">
  56. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  57. left join sms_device_scene t2 on t2.parent_scene_id=t1.id and t2. status = 1
  58. left join sms_device t4 on t2.device_id=t4.id and t4. status = 1 and t4. enable_state = 1
  59. left join sms_device_parm t5 on t5.scene_id = t2.scene_id and t5.device_id=t2.device_id and t5. status = 1
  60. <if test="type == 3 ">
  61. and t5.is_suspension = 1
  62. </if>
  63. <if test="type == 4 ">
  64. and t5.is_map = 1
  65. </if>
  66. left join sms_device_attribute t9 on t5.attribute_id=t9.id and t9.status = 1
  67. left join sms_alarm_details t6 on t6.scene_id=t2.scene_id and t6.device_id=t2.device_id
  68. and t6.attribute_id=t5.attribute_id and t6.status = 1 and t6.state=1
  69. </sql>
  70. <sql id="sceneAlarmJoins">
  71. left join (
  72. select parent_scene_id,count(1) alarm_count
  73. from sms_alarm_details a1
  74. where a1.`status` = 1 and a1.state = 1
  75. <if test="sceneIds != null and sceneIds.size() > 0">
  76. and a1.scene_id in
  77. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  78. #{item}
  79. </foreach>
  80. </if>
  81. group by parent_scene_id
  82. )t7 on t7.parent_scene_id=t1.id
  83. </sql>
  84. <!--查询实时报警信息-->
  85. <select id="selectAlarmDetails" resultType="com.huaxu.dto.AlarmDetailsDto">
  86. select
  87. t1.scene_name as "sceneName",
  88. t6.alarm_content as "alarmContent",
  89. t6.alarm_start_time as "alarmStartTime"
  90. from sms_scene t1
  91. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  92. inner join sms_alarm_details t6 on t1.id=t6.parent_scene_id and t6.`status`=1
  93. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = #{sceneTypeName} and t6.state=1
  94. <if test="sceneIds != null and sceneIds.size() > 0">
  95. and t1.id in
  96. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  97. #{item}
  98. </foreach>
  99. </if>
  100. <if test="sceneIds == null or sceneIds.size() == 0">
  101. and t1.id is null
  102. </if>
  103. <if test="sceneName != null and sceneName != ''">
  104. and t1.scene_name like concat('%',#{sceneName},'%')
  105. </if>
  106. <if test="tenantId != null and tenantId != ''">
  107. and t1.tenant_id = #{tenantId}
  108. </if>
  109. order by t6.alarm_start_time desc
  110. </select>
  111. <!--查询实时报警数量-->
  112. <select id="selectAlarmCount" resultType="java.util.Map">
  113. select
  114. t1.scene_name as "sceneName",
  115. count(1) as "alalmCount"
  116. from sms_scene t1
  117. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  118. inner join sms_alarm_details t6 on t1.id=t6.parent_scene_id and t6.`status`=1
  119. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = #{sceneTypeName} and t6.state=1
  120. <if test="sceneIds != null and sceneIds.size() > 0">
  121. and t1.id in
  122. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  123. #{item}
  124. </foreach>
  125. </if>
  126. <if test="sceneIds == null or sceneIds.size() == 0">
  127. and t1.id is null
  128. </if>
  129. <if test="sceneName != null and sceneName != ''">
  130. and t1.scene_name like concat('%',#{sceneName},'%')
  131. </if>
  132. <if test="tenantId != null and tenantId != ''">
  133. and t1.tenant_id = #{tenantId}
  134. </if>
  135. group by t1.scene_name
  136. order by alalmCount desc
  137. </select>
  138. <!--查询地图悬浮数据-->
  139. <select id="selectMapSuspension" resultMap="monitorDataMap">
  140. select
  141. <include refid="Base_Column_List"/>,if (t7.alarm_count>0, 1, 0) scene_state
  142. from sms_scene t1
  143. <include refid="sceneDeviceJoins"/>
  144. <include refid="sceneAlarmJoins"/>
  145. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = #{sceneTypeName}
  146. <if test="sceneIds != null and sceneIds.size() > 0">
  147. and t1.id in
  148. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  149. #{item}
  150. </foreach>
  151. </if>
  152. <if test="sceneIds == null or sceneIds.size() == 0">
  153. and t1.id is null
  154. </if>
  155. <if test="tenantId != null and tenantId != ''">
  156. and t1.tenant_id = #{tenantId}
  157. </if>
  158. order by t1.scene_name,t5.seq
  159. </select>
  160. <!--查询地图参数数据-->
  161. <select id="selectMapParam" resultMap="monitorDataMap">
  162. select
  163. <include refid="Base_Column_List"/>
  164. from sms_scene t1
  165. <include refid="sceneDeviceJoins"/>
  166. <include refid="sceneAlarmJoins"/>
  167. where t1.parent_scene_id = 0 and t1. status = 1 and t1.id = #{sceneId}
  168. <if test="sceneIds != null and sceneIds.size() > 0">
  169. and t1.id in
  170. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  171. #{item}
  172. </foreach>
  173. </if>
  174. order by t1.scene_name,t5.seq
  175. </select>
  176. <!--查询实时数据列表-->
  177. <select id="selectPage" resultType="com.huaxu.dto.OnlineDataDto">
  178. select t1.id scene_id,t1.scene_name,t1.address
  179. from sms_scene t1
  180. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  181. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = #{onlineDataDto.sceneTypeName}
  182. <if test="onlineDataDto.sceneIds != null and onlineDataDto.sceneIds.size() > 0">
  183. and t1.id in
  184. <foreach collection="onlineDataDto.sceneIds" item="item" open="(" close=")" separator=",">
  185. #{item}
  186. </foreach>
  187. </if>
  188. <if test="onlineDataDto.sceneIds == null or onlineDataDto.sceneIds.size() == 0">
  189. and t1.id is null
  190. </if>
  191. <if test="onlineDataDto.sceneName != null and onlineDataDto.sceneName != ''">
  192. and t1.scene_name like concat('%',#{onlineDataDto.sceneName},'%')
  193. </if>
  194. <if test="onlineDataDto.tenantId != null and onlineDataDto.tenantId != ''">
  195. and t1.tenant_id = #{onlineDataDto.tenantId}
  196. </if>
  197. order by t1.date_create
  198. </select>
  199. <!--查询设备报警分析-->
  200. <select id="selectAlarmStats" resultType="java.util.Map">
  201. select
  202. t4.id,
  203. t4.device_name as "deviceName",
  204. count(1) as "alarmCount",
  205. sum(timestampdiff(minute,t6.alarm_start_time,ifnull(t6.alarm_end_time,now()))) as "alarmDuration"
  206. from sms_scene t1
  207. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  208. inner join sms_alarm_details t6 on t1.id=t6.parent_scene_id and t6.`status`=1
  209. inner join sms_device t4 on t4.id=t6.device_id and t4.`status`=1 and t4. enable_state = 1
  210. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t1.id = #{id}
  211. <if test="sceneIds != null and sceneIds.size() > 0">
  212. and t1.id in
  213. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  214. #{item}
  215. </foreach>
  216. </if>
  217. <if test="days != null">
  218. and t6.alarm_start_time>DATE(NOW() + INTERVAL-#{days}+1 DAY)
  219. </if>
  220. group by t4.id,t4.device_name
  221. </select>
  222. <!--查询场景对应参数数据-->
  223. <select id="selectSceneParam" resultMap="monitorDataMap">
  224. select
  225. <include refid="Base_Column_List"/>,t8.latest_value
  226. from sms_scene t1
  227. <include refid="sceneDeviceJoins"/>
  228. left join (
  229. select b1.device_id,b1.attribute_id,max(latest_value) latest_value
  230. from sms_day_report b1
  231. where b1.year = year(now() + interval-1 day) and b1.month = month(now() + interval-1 day) and b1.day = day(now() + interval-1 day)
  232. group by b1.device_id,b1.attribute_id
  233. )t8 on t8.device_id=t2.device_id and t8.attribute_id =t5.attribute_id
  234. where t1.parent_scene_id = 0 and t1. status = 1
  235. <if test="type == 1 ">
  236. and t5.parm_type in(3,4,5,6)
  237. </if>
  238. <if test="type == 2 ">
  239. and t5.parm_type in(2,3,4,5,6,7,8,9,10,11,12,13,14)
  240. </if>
  241. <if test="sceneTypeName != null and sceneTypeName != '' ">
  242. and t3.scene_type_name = #{sceneTypeName}
  243. </if>
  244. <if test="sceneId != null and sceneId != '' ">
  245. and t1.id = #{sceneId}
  246. </if>
  247. <if test="sceneIds != null and sceneIds.size() > 0">
  248. and t1.id in
  249. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  250. #{item}
  251. </foreach>
  252. </if>
  253. <if test="tenantId != null and tenantId != ''">
  254. and t1.tenant_id = #{tenantId}
  255. </if>
  256. order by t1.scene_name,t5.seq
  257. </select>
  258. <!--按管网名称分类查询设备数量-->
  259. <select id="selectDeviceCount" resultType="java.util.Map">
  260. select t1.id,t1.scene_name sceneName,sum(if(t5.id is null,0,1)) deviceCount
  261. from sms_scene t1
  262. inner join sms_scene_type t3 on t1.scene_type_id=t3.id and t3. status = 1
  263. left join sms_device_scene t2 on t2.parent_scene_id=t1.id and t2. status = 1
  264. left join sms_device t6 on t2.device_id=t6.id and t6. status = 1
  265. left join sms_scene t4 on t2.scene_id=t4.id and t4. status = 1
  266. left join sms_scene_type t5 on t4.scene_type_id=t5.id and t5. status = 1 and t5.scene_type_name = #{sceneTypeName}
  267. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = '管网'
  268. <if test="sceneIds != null and sceneIds.size() > 0">
  269. and t1.id in
  270. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  271. #{item}
  272. </foreach>
  273. </if>
  274. <if test="sceneIds == null or sceneIds.size() == 0">
  275. and t1.id is null
  276. </if>
  277. <if test="sceneId != null">
  278. and t1.id = #{sceneId}
  279. </if>
  280. <if test="deviceName != null and deviceName != ''">
  281. and t6.device_name like concat('%', #{deviceName},'%')
  282. </if>
  283. group by t1.id,t1.scene_name
  284. </select>
  285. <!--查询设备地图参数数据-->
  286. <select id="selectDeviceMapParam" resultMap="deviceDataMap">
  287. select distinct t1.id device_id,t1.device_code,t1.device_name,t1.point_x,point_y,t1.address,t2.attribute_id, ifnull(t2.remark, t3.`name`) attribute_name,t3.unit,
  288. case when t2.attribute_id is null then null when t6.id is null then 0 else 1 end is_alarm, if (t4.alarm_count>0, 1, 0) scene_state
  289. from sms_device t1
  290. left join sms_device_parm t2 on t2.device_id=t1.id and t2.is_map=1
  291. left join sms_device_attribute t3 on t2.attribute_id=t3.id
  292. left join (
  293. select a1.device_id,count(1) alarm_count from sms_alarm_details a1 where a1.device_id= #{deviceId} and a1.`status` = 1 and a1.state = 1
  294. )t4 on t4.device_id=t1.id
  295. left join sms_alarm_details t6 on t6.device_id=t1.id and t6.attribute_id=t2.attribute_id and t6.status = 1 and t6.state=1
  296. where t1. status = 1 and t1. enable_state = 1 and t1.id= #{deviceId}
  297. </select>
  298. </mapper>