OnlineMonitorMapper.xml 27 KB

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