OnlineMonitorMapper.xml 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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. <result property="attributeType" column="attribute_type" jdbcType="VARCHAR"/>
  40. <result property="latestValue" column="latest_value" jdbcType="VARCHAR"/>
  41. </collection>
  42. </resultMap>
  43. <!-- 管网图层设备结果集 -->
  44. <resultMap type="com.huaxu.dto.PipeNetLayerDto" id="layerMap">
  45. <result property="sceneId" column="scene_id" jdbcType="INTEGER"/>
  46. <result property="sceneName" column="scene_name" jdbcType="VARCHAR"/>
  47. <collection property="deviceDataList" ofType="com.huaxu.dto.MonitorDataCollectDto" javaType="list">
  48. <result property="deviceId" column="device_id" jdbcType="INTEGER"/>
  49. <result property="deviceCode" column="device_code" jdbcType="VARCHAR"/>
  50. <result property="deviceName" column="device_name" jdbcType="VARCHAR"/>
  51. <result property="pointX" column="point_x" jdbcType="VARCHAR"/>
  52. <result property="pointY" column="point_y" jdbcType="VARCHAR"/>
  53. <result property="address" column="address" jdbcType="VARCHAR"/>
  54. <result property="deviceState" column="device_state" jdbcType="INTEGER"/>
  55. </collection>
  56. </resultMap>
  57. <sql id="Base_Column_List">
  58. t1.id scene_Id,
  59. t1.scene_name ,
  60. t1.point_x ,
  61. t1.point_y,
  62. t1.address ,
  63. t5.device_id,
  64. t5.attribute_id ,
  65. ifnull(t5.remark, t9.`name`) attribute_name,
  66. t9.unit ,
  67. case when t5.attribute_id is null then null when t6.id is null then 0 else 1 end is_alarm,
  68. t5.parm_type attribute_type,
  69. if (t5.device_id is null, null, t4.device_code) device_code
  70. </sql>
  71. <sql id="sceneDeviceJoins">
  72. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  73. left join sms_device_scene t2 on t2.parent_scene_id=t1.id and t2. status = 1
  74. left join sms_device t4 on t2.device_id=t4.id and t4. status = 1 and t4. enable_state = 1
  75. left join sms_device_parm t5 on t5.scene_id = t2.scene_id and t5.device_id=t2.device_id and t5. status = 1
  76. <if test="type == 3 ">
  77. and t5.is_suspension = 1
  78. </if>
  79. <if test="type == 4 ">
  80. and t5.is_map = 1
  81. </if>
  82. left join sms_device_attribute t9 on t5.attribute_id=t9.id and t9.status = 1
  83. left join sms_alarm_details t6 on t6.scene_id=t2.scene_id and t6.device_id=t2.device_id
  84. and t6.attribute_id=t5.attribute_id and t6.status = 1 and t6.state=1
  85. </sql>
  86. <sql id="sceneAlarmJoins">
  87. left join (
  88. select parent_scene_id,count(1) alarm_count
  89. from sms_alarm_details a1
  90. where a1.`status` = 1 and a1.state = 1
  91. <if test="sceneIds != null and sceneIds.size() > 0">
  92. and a1.scene_id in
  93. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  94. #{item}
  95. </foreach>
  96. </if>
  97. group by parent_scene_id
  98. )t7 on t7.parent_scene_id=t1.id
  99. </sql>
  100. <sql id="deviceInnerJoins">
  101. inner join sms_scene_type t3 on t1.scene_type_id=t3.id
  102. inner join sms_device_scene t2 on t2.parent_scene_id=t1.id and t2. status = 1
  103. inner join sms_device t6 on t2.device_id=t6.id and t6. status = 1
  104. inner join sms_scene t4 on t2.scene_id=t4.id
  105. inner join sms_scene_type t5 on t4.scene_type_id=t5.id and t5. status = 1
  106. </sql>
  107. <sql id="deviceLeftJoins">
  108. inner join sms_scene_type t3 on t1.scene_type_id=t3.id and t3. status = 1
  109. left join sms_device_scene t2 on t2.parent_scene_id=t1.id and t2. status = 1
  110. left join sms_device t6 on t2.device_id=t6.id and t6. status = 1
  111. left join sms_scene t4 on t2.scene_id=t4.id and t4. status = 1
  112. left join sms_scene_type t5 on t4.scene_type_id=t5.id and t5. status = 1 and t5.scene_type_name = #{sceneTypeName}
  113. </sql>
  114. <!--查询实时报警信息-->
  115. <select id="selectAlarmDetails" resultType="com.huaxu.dto.AlarmDetailsDto">
  116. select
  117. t1.scene_name as "sceneName",
  118. t6.alarm_content as "alarmContent",
  119. t6.alarm_start_time as "alarmStartTime"
  120. from sms_scene t1
  121. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  122. inner join sms_alarm_details t6 on t1.id=t6.parent_scene_id and t6.`status`=1
  123. 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
  124. <if test="sceneIds != null and sceneIds.size() > 0">
  125. and t1.id in
  126. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  127. #{item}
  128. </foreach>
  129. </if>
  130. <if test="sceneIds == null or sceneIds.size() == 0">
  131. and t1.id is null
  132. </if>
  133. <if test="sceneName != null and sceneName != ''">
  134. and t1.scene_name like concat('%',#{sceneName},'%')
  135. </if>
  136. <if test="tenantId != null and tenantId != ''">
  137. and t1.tenant_id = #{tenantId}
  138. </if>
  139. order by t6.alarm_start_time desc
  140. </select>
  141. <!--查询实时报警数量-->
  142. <select id="selectAlarmCount" resultType="java.util.Map">
  143. select
  144. t1.scene_name as "sceneName",
  145. count(1) as "alalmCount"
  146. from sms_scene t1
  147. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  148. inner join sms_alarm_details t6 on t1.id=t6.parent_scene_id and t6.`status`=1
  149. 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
  150. <if test="sceneIds != null and sceneIds.size() > 0">
  151. and t1.id in
  152. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  153. #{item}
  154. </foreach>
  155. </if>
  156. <if test="sceneIds == null or sceneIds.size() == 0">
  157. and t1.id is null
  158. </if>
  159. <if test="sceneName != null and sceneName != ''">
  160. and t1.scene_name like concat('%',#{sceneName},'%')
  161. </if>
  162. <if test="tenantId != null and tenantId != ''">
  163. and t1.tenant_id = #{tenantId}
  164. </if>
  165. group by t1.scene_name
  166. order by alalmCount desc
  167. </select>
  168. <!--查询地图悬浮数据-->
  169. <select id="selectMapSuspension" resultMap="monitorDataMap">
  170. select
  171. <include refid="Base_Column_List"/>,if (t7.alarm_count>0, 1, 0) scene_state
  172. from sms_scene t1
  173. <include refid="sceneDeviceJoins"/>
  174. <include refid="sceneAlarmJoins"/>
  175. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = #{sceneTypeName}
  176. <if test="sceneIds != null and sceneIds.size() > 0">
  177. and t1.id in
  178. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  179. #{item}
  180. </foreach>
  181. </if>
  182. <if test="sceneIds == null or sceneIds.size() == 0">
  183. and t1.id is null
  184. </if>
  185. <if test="tenantId != null and tenantId != ''">
  186. and t1.tenant_id = #{tenantId}
  187. </if>
  188. order by t1.scene_name,t5.seq
  189. </select>
  190. <!--查询地图参数数据-->
  191. <select id="selectMapParam" resultMap="monitorDataMap">
  192. select
  193. <include refid="Base_Column_List"/>
  194. from sms_scene t1
  195. <include refid="sceneDeviceJoins"/>
  196. <include refid="sceneAlarmJoins"/>
  197. where t1.parent_scene_id = 0 and t1. status = 1 and t1.id = #{sceneId}
  198. <if test="sceneIds != null and sceneIds.size() > 0">
  199. and t1.id in
  200. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  201. #{item}
  202. </foreach>
  203. </if>
  204. order by t1.scene_name,t5.seq
  205. </select>
  206. <!--查询实时数据列表-->
  207. <select id="selectPage" resultType="com.huaxu.dto.OnlineDataDto">
  208. select t1.id scene_id,t1.scene_name,t1.address
  209. from sms_scene t1
  210. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  211. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = #{onlineDataDto.sceneTypeName}
  212. <if test="onlineDataDto.sceneIds != null and onlineDataDto.sceneIds.size() > 0">
  213. and t1.id in
  214. <foreach collection="onlineDataDto.sceneIds" item="item" open="(" close=")" separator=",">
  215. #{item}
  216. </foreach>
  217. </if>
  218. <if test="onlineDataDto.sceneIds == null or onlineDataDto.sceneIds.size() == 0">
  219. and t1.id is null
  220. </if>
  221. <if test="onlineDataDto.sceneName != null and onlineDataDto.sceneName != ''">
  222. and t1.scene_name like concat('%',#{onlineDataDto.sceneName},'%')
  223. </if>
  224. <if test="onlineDataDto.tenantId != null and onlineDataDto.tenantId != ''">
  225. and t1.tenant_id = #{onlineDataDto.tenantId}
  226. </if>
  227. order by t1.date_create
  228. </select>
  229. <!--查询设备报警分析-->
  230. <select id="selectAlarmStats" resultType="java.util.Map">
  231. select
  232. t4.id,
  233. t4.device_name as "deviceName",
  234. count(1) as "alarmCount",
  235. sum(timestampdiff(minute,t6.alarm_start_time,ifnull(t6.alarm_end_time,now()))) as "alarmDuration"
  236. from sms_scene t1
  237. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  238. inner join sms_alarm_details t6 on t1.id=t6.parent_scene_id and t6.`status`=1
  239. inner join sms_device t4 on t4.id=t6.device_id and t4.`status`=1 and t4. enable_state = 1
  240. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t1.id = #{id}
  241. <if test="sceneIds != null and sceneIds.size() > 0">
  242. and t1.id in
  243. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  244. #{item}
  245. </foreach>
  246. </if>
  247. <if test="days != null">
  248. and t6.alarm_start_time>DATE(NOW() + INTERVAL-#{days}+1 DAY)
  249. </if>
  250. group by t4.id,t4.device_name
  251. </select>
  252. <!--查询场景对应参数数据-->
  253. <select id="selectSceneParam" resultMap="monitorDataMap">
  254. select
  255. <include refid="Base_Column_List"/>,t8.latest_value
  256. from sms_scene t1
  257. <include refid="sceneDeviceJoins"/>
  258. left join (
  259. select c1.device_id,c1.attribute_id,c1.latest_value
  260. from sms_day_report c1
  261. inner join (
  262. select b1.device_id,b1.attribute_id,max(b1.collect_date) collect_date
  263. from sms_day_report b1
  264. where b1.year = year(now() + interval-1 day) and b1.month = month(now() + interval-1 day) and b1.day = day(now() + interval-1 day)
  265. group by b1.device_id,b1.attribute_id )c2 on c1.device_id=c2.device_id and c1.attribute_id=c2.attribute_id and c1.collect_date=c2.collect_date
  266. )t8 on t8.device_id=t2.device_id and t8.attribute_id =t5.attribute_id
  267. where t1.parent_scene_id = 0 and t1. status = 1
  268. <if test="type == 1 ">
  269. and t5.parm_type in(3,4,5,6)
  270. </if>
  271. <if test="type == 2 ">
  272. and t5.parm_type in(2,3,4,5,6,7,8,9,10,11,12,13,14)
  273. </if>
  274. <if test="sceneTypeName != null and sceneTypeName != '' ">
  275. and t3.scene_type_name = #{sceneTypeName}
  276. </if>
  277. <if test="sceneId != null and sceneId != '' ">
  278. and t1.id = #{sceneId}
  279. </if>
  280. <if test="sceneIds != null and sceneIds.size() > 0">
  281. and t1.id in
  282. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  283. #{item}
  284. </foreach>
  285. </if>
  286. <if test="tenantId != null and tenantId != ''">
  287. and t1.tenant_id = #{tenantId}
  288. </if>
  289. order by t1.scene_name,t5.seq
  290. </select>
  291. <!--按管网名称分类查询设备数量-->
  292. <select id="selectDeviceCount" resultType="java.util.Map">
  293. select t1.id sceneId,t1.scene_name sceneName,sum(if(t5.id is null,0,1)) deviceCount
  294. from sms_scene t1
  295. <include refid="deviceLeftJoins"/>
  296. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = '管网'
  297. <if test="sceneIds != null and sceneIds.size() > 0">
  298. and t1.id in
  299. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  300. #{item}
  301. </foreach>
  302. </if>
  303. <if test="sceneIds == null or sceneIds.size() == 0">
  304. and t1.id is null
  305. </if>
  306. <if test="sceneId != null">
  307. and t1.id = #{sceneId}
  308. </if>
  309. <if test="deviceName != null and deviceName != ''">
  310. and t6.device_name like concat('%', #{deviceName},'%')
  311. </if>
  312. group by t1.id,t1.scene_name
  313. </select>
  314. <!--查询设备地图参数数据-->
  315. <select id="selectDeviceMapParam" resultMap="deviceDataMap">
  316. 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,
  317. 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
  318. from sms_device t1
  319. left join sms_device_parm t2 on t2.device_id=t1.id and t2.is_map=1
  320. left join sms_device_attribute t3 on t2.attribute_id=t3.id
  321. left join (
  322. 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
  323. )t4 on t4.device_id=t1.id
  324. 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
  325. where t1. status = 1 and t1. enable_state = 1 and t1.id= #{deviceId}
  326. </select>
  327. <!--统计设备合格数据-->
  328. <select id="statsDeviceQualified" resultType="com.huaxu.dto.DeviceCountStatsDto">
  329. select count(1) totalCount,sum(if(t7.device_id is null,0,1)) alarmCount,count(1)-sum(if(t7.device_id is null,0,1)) normalCount
  330. from sms_scene t1
  331. <include refid="deviceInnerJoins"/>
  332. left join(
  333. select a1.scene_id, a1.device_id from sms_alarm_details a1 where a1.`status` = 1 and a1.state = 1 group by a1.scene_id, a1.device_id
  334. )t7 on t7.scene_id=t2.scene_id and t7.device_id=t2.device_id
  335. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = '管网' and t5.scene_type_name = #{sceneTypeName}
  336. <if test="sceneIds != null and sceneIds.size() > 0">
  337. and t1.id in
  338. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  339. #{item}
  340. </foreach>
  341. </if>
  342. <if test="sceneIds == null or sceneIds.size() == 0">
  343. and t1.id is null
  344. </if>
  345. <if test="sceneId != null">
  346. and t1.id = #{sceneId}
  347. </if>
  348. <if test="deviceName != null and deviceName != ''">
  349. and t6.device_name like concat('%', #{deviceName},'%')
  350. </if>
  351. </select>
  352. <!--统计设备属性合格数据-->
  353. <select id="statsParmQualified" resultType="com.huaxu.dto.DeviceCountStatsDto">
  354. select case t7.parm_type when '13' then '压力' when '7' then 'PH' when '9' then '浊度' when '11' then '余氯' end type,
  355. count(t8.device_id) alarmCount
  356. from sms_scene t1
  357. <include refid="deviceInnerJoins"/>
  358. inner join sms_device_parm t7 on t7.scene_id=t2.scene_id and t7.device_id=t2.device_id
  359. <if test="sceneTypeName == '压力'">
  360. and t7.parm_type in(13)
  361. </if>
  362. <if test="sceneTypeName == '水质'">
  363. and t7.parm_type in(7,9,11)
  364. </if>
  365. inner join sms_alarm_details t8 on t8.attribute_id=t7.attribute_id and t8.device_id=t7.device_id and t8.scene_id=t7.scene_id and t8.`status` = 1 and t8.state = 1
  366. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = '管网' and t5.scene_type_name = #{sceneTypeName}
  367. <if test="sceneIds != null and sceneIds.size() > 0">
  368. and t1.id in
  369. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  370. #{item}
  371. </foreach>
  372. </if>
  373. <if test="sceneIds == null or sceneIds.size() == 0">
  374. and t1.id is null
  375. </if>
  376. <if test="sceneId != null">
  377. and t1.id = #{sceneId}
  378. </if>
  379. <if test="deviceName != null and deviceName != ''">
  380. and t6.device_name like concat('%', #{deviceName},'%')
  381. </if>
  382. group by t7.parm_type
  383. </select>
  384. <!-- 查询设备参数-->
  385. <select id="statsDeviceParm" resultMap="deviceDataMap">
  386. SELECT t6.id device_id,t6.device_code,t6.device_name,t7.attribute_id,t7.parm_type attribute_type,
  387. case when t7.attribute_id is null then null when t8.id is null then 0 else 1 end is_alarm
  388. <if test="type == 4 ">,t9.latest_value</if>
  389. from sms_scene t1
  390. <include refid="deviceInnerJoins"/>
  391. left join sms_device_parm t7 on t7.scene_id=t2.scene_id and t7.device_id=t2.device_id
  392. <if test="type == 1 ">
  393. and t7.parm_type in(13)
  394. </if>
  395. <if test="type == 2 ">
  396. and t7.parm_type in(14,16)
  397. </if>
  398. <if test="type == 3">
  399. and t7.parm_type in(7,9,11,18)
  400. </if>
  401. <if test="type == 4 ">
  402. and t7.parm_type in(16)
  403. left join (
  404. select c1.device_id,c1.attribute_id,c1.latest_value
  405. from sms_day_report c1
  406. inner join (
  407. select b1.device_id,b1.attribute_id,max(b1.collect_date) collect_date
  408. from sms_day_report b1
  409. where b1.year = year(now() + interval-1 day) and b1.month = month(now() + interval-1 day) and b1.day = day(now() + interval-1 day)
  410. group by b1.device_id,b1.attribute_id )c2 on c1.device_id=c2.device_id and c1.attribute_id=c2.attribute_id and c1.collect_date=c2.collect_date
  411. )t9 on t9.device_id=t2.device_id and t9.attribute_id =t7.attribute_id
  412. </if>
  413. <if test="type == 5 ">
  414. and t7.parm_type in(14)
  415. </if>
  416. left join sms_alarm_details t8 on t8.attribute_id=t7.attribute_id and t8.device_id=t7.device_id and t8.scene_id=t7.scene_id and t8.`status` = 1 and t8.state = 1
  417. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = '管网' and t5.scene_type_name = #{sceneTypeName}
  418. <if test="sceneIds != null and sceneIds.size() > 0">
  419. and t1.id in
  420. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  421. #{item}
  422. </foreach>
  423. </if>
  424. <if test="sceneIds == null or sceneIds.size() == 0">
  425. and t1.id is null
  426. </if>
  427. <if test="sceneId != null">
  428. and t1.id = #{sceneId}
  429. </if>
  430. <if test="deviceIds != null and deviceIds.size() > 0">
  431. and t6.id in
  432. <foreach collection="deviceIds" item="item" open="(" close=")" separator=",">
  433. #{item}
  434. </foreach>
  435. </if>
  436. <if test="deviceName != null and deviceName != ''">
  437. and t6.device_name like concat('%', #{deviceName},'%')
  438. </if>
  439. </select>
  440. <!--查询管网实时数据列表-->
  441. <select id="selectPipeNetPage" resultType="com.huaxu.dto.OnlineDataDto">
  442. select t1.id scene_id,t1.scene_name,t6.id device_id,t6.device_code,t6.device_name,t6.address,if (t7.alarm_count>0, 1, 0) deviceState
  443. from sms_scene t1
  444. <include refid="deviceInnerJoins"/>
  445. left join(
  446. select a1.scene_id, a1.device_id ,count(1) alarm_count from sms_alarm_details a1 where a1.`status` = 1 and a1.state = 1 group by a1.scene_id, a1.device_id
  447. )t7 on t7.scene_id=t2.scene_id and t7.device_id=t2.device_id
  448. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = '管网' and t5.scene_type_name = #{onlineDataDto.sceneTypeName}
  449. <if test="onlineDataDto.sceneIds != null and onlineDataDto.sceneIds.size() > 0">
  450. and t1.id in
  451. <foreach collection="onlineDataDto.sceneIds" item="item" open="(" close=")" separator=",">
  452. #{item}
  453. </foreach>
  454. </if>
  455. <if test="onlineDataDto.sceneIds == null or onlineDataDto.sceneIds.size() == 0">
  456. and t1.id is null
  457. </if>
  458. <if test="onlineDataDto.sceneId != null">
  459. and t1.id = #{onlineDataDto.sceneId}
  460. </if>
  461. <if test="onlineDataDto.deviceName != null and onlineDataDto.deviceName != ''">
  462. and t6.device_name like concat('%', #{onlineDataDto.deviceName},'%')
  463. </if>
  464. order by t6.date_create
  465. </select>
  466. <!--查询管网地图图层-->
  467. <select id="selectPipeNetLayer" resultMap="layerMap">
  468. select t4.id scene_id,t4.scene_name,t6.id device_id,t6.device_code,t6.device_name,t6.point_x,t6.point_y,t6.address,if (t7.alarm_count>0, 1, 0) device_state
  469. from sms_scene t1
  470. <include refid="deviceInnerJoins"/>
  471. left join(
  472. select a1.scene_id, a1.device_id ,count(1) alarm_count from sms_alarm_details a1 where a1.`status` = 1 and a1.state = 1 group by a1.scene_id, a1.device_id
  473. )t7 on t7.scene_id=t2.scene_id and t7.device_id=t2.device_id
  474. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = '管网'
  475. and t5.scene_type_name in('压力','流量','水质')
  476. <if test="sceneIds != null and sceneIds.size() > 0">
  477. and t1.id in
  478. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  479. #{item}
  480. </foreach>
  481. </if>
  482. <if test="sceneIds == null or sceneIds.size() == 0">
  483. and t1.id is null
  484. </if>
  485. order by t4.scene_name,t6.date_create
  486. </select>
  487. </mapper>