OnlineMonitorMapper.xml 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  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
  92. <if test="flag == null or flag ==0">
  93. ,count(1) alarm_count
  94. </if>
  95. <if test="flag == 1">
  96. ,sum(case when alarm_type='参数报警' then 1 else 0 end) alarm_count
  97. ,sum(case when alarm_type='状态报警' then 1 else 0 end) offline_alarm_count
  98. </if>
  99. from sms_alarm_details a1
  100. where a1.`status` = 1 and a1.state = 1
  101. <if test="sceneIds != null and sceneIds.size() > 0">
  102. and a1.scene_id in
  103. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  104. #{item}
  105. </foreach>
  106. </if>
  107. group by parent_scene_id
  108. )t7 on t7.parent_scene_id=t1.id
  109. <if test="flag == 1">
  110. left join (
  111. select parent_scene_id,count(distinct device_id) setting_device_count
  112. from sms_alarm_setting
  113. where alarm_type='状态报警' and status=1
  114. group by parent_scene_id
  115. )t10 on t7.parent_scene_id=t10.parent_scene_id
  116. </if>
  117. </sql>
  118. <sql id="deviceInnerJoins">
  119. inner join sms_scene_type t3 on t1.scene_type_id=t3.id
  120. inner join sms_device_scene t2 on t2.parent_scene_id=t1.id and t2. status = 1
  121. inner join sms_device t6 on t2.device_id=t6.id and t6. status = 1 and t6.enable_state = 1
  122. inner join sms_scene t4 on t2.scene_id=t4.id
  123. inner join sms_scene_type t5 on t4.scene_type_id=t5.id and t5. status = 1
  124. </sql>
  125. <sql id="deviceLeftJoins">
  126. inner join sms_scene_type t3 on t1.scene_type_id=t3.id and t3. status = 1
  127. left join sms_device_scene t2 on t2.parent_scene_id=t1.id and t2. status = 1
  128. left join sms_device t6 on t2.device_id=t6.id and t6. status = 1 and t6.enable_state = 1
  129. left join sms_scene t4 on t2.scene_id=t4.id and t4. status = 1
  130. left join sms_scene_type t5 on t4.scene_type_id=t5.id and t5. status = 1 and t5.scene_type_name = #{sceneTypeName}
  131. </sql>
  132. <!--查询实时报警信息-->
  133. <select id="selectAlarmDetails" resultType="com.huaxu.dto.AlarmDetailsDto">
  134. select
  135. t1.scene_name as "sceneName",
  136. t6.alarm_content as "alarmContent",
  137. t6.alarm_start_time as "alarmStartTime"
  138. from sms_scene t1
  139. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  140. inner join sms_alarm_details t6 on t1.id=t6.parent_scene_id and t6.`status`=1
  141. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t6.state=1
  142. <if test="sceneTypeName != null and sceneTypeName != ''">
  143. and t3.scene_type_name = #{sceneTypeName}
  144. </if>
  145. <if test="companyOrgId != null and companyOrgId !=''">
  146. and t6.company_org_id=#{companyOrgId}
  147. </if>
  148. <if test="sceneIds != null and sceneIds.size() > 0">
  149. and t1.id in
  150. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  151. #{item}
  152. </foreach>
  153. </if>
  154. <if test="sceneIds == null or sceneIds.size() == 0">
  155. and t1.id is null
  156. </if>
  157. <if test="sceneName != null and sceneName != ''">
  158. and t1.scene_name like concat('%',#{sceneName},'%')
  159. </if>
  160. <if test="tenantId != null and tenantId != ''">
  161. and t1.tenant_id = #{tenantId}
  162. </if>
  163. order by t6.alarm_start_time desc
  164. </select>
  165. <!--查询实时报警数量-->
  166. <select id="selectAlarmCount" resultType="java.util.Map">
  167. select
  168. t1.scene_name as "sceneName",
  169. count(1) as "alalmCount"
  170. from sms_scene t1
  171. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  172. inner join sms_alarm_details t6 on t1.id=t6.parent_scene_id and t6.`status`=1
  173. 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
  174. <if test="sceneIds != null and sceneIds.size() > 0">
  175. and t1.id in
  176. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  177. #{item}
  178. </foreach>
  179. </if>
  180. <if test="sceneIds == null or sceneIds.size() == 0">
  181. and t1.id is null
  182. </if>
  183. <if test="sceneName != null and sceneName != ''">
  184. and t1.scene_name like concat('%',#{sceneName},'%')
  185. </if>
  186. <if test="tenantId != null and tenantId != ''">
  187. and t1.tenant_id = #{tenantId}
  188. </if>
  189. group by t1.scene_name
  190. order by alalmCount desc
  191. </select>
  192. <!--查询地图悬浮数据-->
  193. <select id="selectMapSuspension" resultMap="monitorDataMap">
  194. select
  195. <include refid="Base_Column_List"/>
  196. <if test="flag == null or flag ==0">
  197. ,if (t7.alarm_count>0, 1, 0) scene_state,
  198. </if>
  199. <if test="flag == 1">
  200. ,case when t7.offline_alarm_count=t10.setting_device_count then 2
  201. when t7.alarm_count>0 or t7.offline_alarm_count>0 then 1 else 0 end scene_state,
  202. </if>
  203. t1.company_org_id as "companyOrgId"
  204. from sms_scene t1
  205. <include refid="sceneDeviceJoins"/>
  206. <include refid="sceneAlarmJoins"/>
  207. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1
  208. <choose>
  209. <when test="sceneTypeName != null and sceneTypeName !=''">
  210. and t3.scene_type_name = #{sceneTypeName}
  211. </when>
  212. <otherwise>
  213. and t3.scene_type_name in('水源','水厂','泵站')
  214. </otherwise>
  215. </choose>
  216. <if test="sceneIds != null and sceneIds.size() > 0">
  217. and t1.id in
  218. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  219. #{item}
  220. </foreach>
  221. </if>
  222. <if test="sceneIds == null or sceneIds.size() == 0">
  223. and t1.id is null
  224. </if>
  225. <if test="tenantId != null and tenantId != ''">
  226. and t1.tenant_id = #{tenantId}
  227. </if>
  228. order by t3.scene_type_name,t1.scene_name,t5.seq
  229. </select>
  230. <!--查询地图参数数据-->
  231. <select id="selectMapParam" resultMap="monitorDataMap">
  232. select
  233. <include refid="Base_Column_List"/>
  234. <if test="flag == null or flag == 0">
  235. ,if (t7.alarm_count>0, 1, 0) scene_state
  236. </if>
  237. <if test="flag == 1">
  238. ,case when t7.offline_alarm_count=t10.setting_device_count then 2
  239. when t7.alarm_count>0 or t7.offline_alarm_count>0 then 1 else 0 end scene_state
  240. </if>
  241. from sms_scene t1
  242. <include refid="sceneDeviceJoins"/>
  243. <include refid="sceneAlarmJoins"/>
  244. where t1.parent_scene_id = 0 and t1. status = 1 and t1.id = #{sceneId}
  245. <if test="sceneIds != null and sceneIds.size() > 0">
  246. and t1.id in
  247. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  248. #{item}
  249. </foreach>
  250. </if>
  251. order by t1.scene_name,t5.seq
  252. </select>
  253. <!--查询实时数据列表-->
  254. <select id="selectPage" resultType="com.huaxu.dto.OnlineDataDto">
  255. select t1.id scene_id,t1.scene_name,t1.address
  256. from sms_scene t1
  257. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  258. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = #{onlineDataDto.sceneTypeName}
  259. <if test="onlineDataDto.sceneIds != null and onlineDataDto.sceneIds.size() > 0">
  260. and t1.id in
  261. <foreach collection="onlineDataDto.sceneIds" item="item" open="(" close=")" separator=",">
  262. #{item}
  263. </foreach>
  264. </if>
  265. <if test="onlineDataDto.sceneIds == null or onlineDataDto.sceneIds.size() == 0">
  266. and t1.id is null
  267. </if>
  268. <if test="onlineDataDto.sceneName != null and onlineDataDto.sceneName != ''">
  269. and t1.scene_name like concat('%',#{onlineDataDto.sceneName},'%')
  270. </if>
  271. <if test="onlineDataDto.tenantId != null and onlineDataDto.tenantId != ''">
  272. and t1.tenant_id = #{onlineDataDto.tenantId}
  273. </if>
  274. order by t1.date_create
  275. </select>
  276. <!--查询设备报警分析-->
  277. <select id="selectAlarmStats" resultType="java.util.Map">
  278. select
  279. t4.id,
  280. t4.device_name as "deviceName",
  281. count(1) as "alarmCount",
  282. sum(timestampdiff(minute,t6.alarm_start_time,ifnull(t6.alarm_end_time,now()))) as "alarmDuration"
  283. from sms_scene t1
  284. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  285. inner join sms_alarm_details t6 on t1.id=t6.parent_scene_id and t6.`status`=1
  286. inner join sms_device t4 on t4.id=t6.device_id and t4.`status`=1 and t4. enable_state = 1
  287. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t1.id = #{id}
  288. <if test="sceneIds != null and sceneIds.size() > 0">
  289. and t1.id in
  290. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  291. #{item}
  292. </foreach>
  293. </if>
  294. <if test="days != null">
  295. and t6.alarm_start_time>DATE(NOW() + INTERVAL-#{days}+1 DAY)
  296. </if>
  297. group by t4.id,t4.device_name
  298. </select>
  299. <!--查询场景对应参数数据-->
  300. <select id="selectSceneParam" resultMap="monitorDataMap">
  301. select
  302. <include refid="Base_Column_List"/>,t8.latest_value
  303. from sms_scene t1
  304. <include refid="sceneDeviceJoins"/>
  305. left join (
  306. select c1.device_id,c1.attribute_id,c1.latest_value
  307. from sms_month_report c1
  308. inner join (
  309. select b1.device_id,b1.attribute_id,max(b1.collect_date) collect_date
  310. from sms_month_report b1
  311. where b1.year = year(now() + interval-1 day) and b1.month = month(now() + interval-1 day) and b1.day = day(now() + interval-1 day)
  312. 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
  313. )t8 on t8.device_id=t2.device_id and t8.attribute_id =t5.attribute_id
  314. where t1.parent_scene_id = 0 and t1. status = 1
  315. <if test="type == 1 ">
  316. and t5.parm_type in(3,4,5,6)
  317. </if>
  318. <if test="type == 2 ">
  319. and t5.parm_type in(2,3,4,5,6,7,8,9,10,11,12,13,14)
  320. </if>
  321. <if test="sceneTypeName != null and sceneTypeName != '' ">
  322. and t3.scene_type_name = #{sceneTypeName}
  323. </if>
  324. <if test="sceneId != null and sceneId != '' ">
  325. and t1.id = #{sceneId}
  326. </if>
  327. <if test="sceneIds != null and sceneIds.size() > 0">
  328. and t1.id in
  329. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  330. #{item}
  331. </foreach>
  332. </if>
  333. <if test="tenantId != null and tenantId != ''">
  334. and t1.tenant_id = #{tenantId}
  335. </if>
  336. order by t1.scene_name,t5.seq
  337. </select>
  338. <!--按管网名称分类查询设备数量-->
  339. <select id="selectDeviceCount" resultType="java.util.Map">
  340. 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
  341. from sms_scene t1
  342. <include refid="deviceInnerJoins"/>
  343. left join(
  344. 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
  345. )t7 on t7.scene_id=t2.scene_id and t7.device_id=t2.device_id
  346. 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}
  347. <if test="sceneIds != null and sceneIds.size() > 0">
  348. and t1.id in
  349. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  350. #{item}
  351. </foreach>
  352. </if>
  353. <if test="sceneIds == null or sceneIds.size() == 0">
  354. and t1.id is null
  355. </if>
  356. <if test="sceneId != null">
  357. and t1.id = #{sceneId}
  358. </if>
  359. <if test="deviceName != null and deviceName != ''">
  360. and t6.device_name like concat('%', #{deviceName},'%')
  361. </if>
  362. group by t1.id,t1.scene_name
  363. </select>
  364. <!--查询设备地图参数数据-->
  365. <select id="selectDeviceMapParam" resultMap="deviceDataMap">
  366. 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,
  367. t2.seq,case when t2.attribute_id is null then null when t6.id is null then 0 else 1 end is_alarm
  368. <if test="flag == null or flag ==0">
  369. ,if (t4.alarm_count>0, 1, 0) device_state
  370. </if>
  371. <if test="flag == 1">
  372. ,case when t4.offline_alarm_count>0 then 2 when t4.alarm_count>0 then 1 else 0 end device_state
  373. </if>
  374. from sms_device t1
  375. left join sms_device_parm t2 on t2.device_id=t1.id and t2.is_map=1 and t2.status=1
  376. left join sms_device_attribute t3 on t2.attribute_id=t3.id and t3.status=1
  377. left join (
  378. select a1.device_id
  379. <if test="flag == null or flag ==0">
  380. ,count(1) alarm_count
  381. </if>
  382. <if test="flag == 1">
  383. ,sum(case when alarm_type='参数报警' then 1 else 0 end) alarm_count
  384. ,sum(case when alarm_type='状态报警' then 1 else 0 end) offline_alarm_count
  385. </if>
  386. from sms_alarm_details a1 where a1.device_id= #{deviceId} and a1.`status` = 1 and a1.state = 1
  387. )t4 on t4.device_id=t1.id
  388. 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
  389. where t1. status = 1 and t1. enable_state = 1 and t1.id= #{deviceId}
  390. order by t2.seq
  391. </select>
  392. <!--统计设备合格数据-->
  393. <select id="statsDeviceQualified" resultType="com.huaxu.dto.DeviceCountStatsDto">
  394. 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
  395. from sms_scene t1
  396. <include refid="deviceInnerJoins"/>
  397. left join(
  398. select a1.scene_id, a1.device_id from sms_alarm_details a1 where a1.`status` = 1 and a1.state = 1 and a1.alarm_type = '参数报警'
  399. group by a1.scene_id, a1.device_id
  400. )t7 on t7.scene_id=t2.scene_id and t7.device_id=t2.device_id
  401. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = '管网'
  402. <choose>
  403. <when test="sceneTypeName != null and sceneTypeName !=''">
  404. and t5.scene_type_name = #{sceneTypeName}
  405. </when>
  406. <otherwise>
  407. and t5.scene_type_name in('压力','流量','水质')
  408. </otherwise>
  409. </choose>
  410. <if test="sceneIds != null and sceneIds.size() > 0">
  411. and t1.id in
  412. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  413. #{item}
  414. </foreach>
  415. </if>
  416. <if test="sceneIds == null or sceneIds.size() == 0">
  417. and t1.id is null
  418. </if>
  419. <if test="sceneId != null">
  420. and t1.id = #{sceneId}
  421. </if>
  422. <if test="deviceName != null and deviceName != ''">
  423. and t6.device_name like concat('%', #{deviceName},'%')
  424. </if>
  425. group by t5.scene_type_name
  426. </select>
  427. <!--统计设备属性合格数据-->
  428. <select id="statsParmQualified" resultType="com.huaxu.dto.DeviceCountStatsDto">
  429. select case t7.parm_type when '13' then '压力' when '7' then 'PH' when '9' then '浊度' when '11' then '余氯' end type,
  430. count(t8.device_id) alarmCount
  431. from sms_scene t1
  432. <include refid="deviceInnerJoins"/>
  433. inner join sms_device_parm t7 on t7.scene_id=t2.scene_id and t7.device_id=t2.device_id and t7.status=1
  434. <if test="sceneTypeName == '压力'">
  435. and t7.parm_type in(13)
  436. </if>
  437. <if test="sceneTypeName == '水质'">
  438. and t7.parm_type in(7,9,11)
  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="deviceName != null and deviceName != ''">
  455. and t6.device_name like concat('%', #{deviceName},'%')
  456. </if>
  457. group by t7.parm_type
  458. </select>
  459. <!-- 查询设备参数-->
  460. <select id="statsDeviceParm" resultMap="deviceDataMap">
  461. SELECT t6.id device_id,t6.device_code,t6.device_name,t7.attribute_id,t7.parm_type attribute_type,
  462. case when t7.attribute_id is null then null when t8.id is null then 0 else 1 end is_alarm
  463. <if test="type == 4 ">,t9.latest_value</if>
  464. from sms_scene t1
  465. <include refid="deviceInnerJoins"/>
  466. left join sms_device_parm t7 on t7.scene_id=t2.scene_id and t7.device_id=t2.device_id and t7.status=1
  467. <if test="type == 1 ">
  468. and t7.parm_type in(13)
  469. </if>
  470. <if test="type == 2 ">
  471. and t7.parm_type in(14,16)
  472. </if>
  473. <if test="type == 3">
  474. and t7.parm_type in(7,9,11,18)
  475. </if>
  476. <if test="type == 4 ">
  477. and t7.parm_type in(16)
  478. left join (
  479. select c1.device_id,c1.attribute_id,c1.latest_value
  480. from sms_month_report c1
  481. inner join (
  482. select b1.device_id,b1.attribute_id,max(b1.collect_date) collect_date
  483. from sms_month_report b1
  484. where b1.year = year(now() + interval-1 day) and b1.month = month(now() + interval-1 day) and b1.day = day(now() + interval-1 day)
  485. 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
  486. )t9 on t9.device_id=t2.device_id and t9.attribute_id =t7.attribute_id
  487. </if>
  488. <if test="type == 5 ">
  489. and t7.parm_type in(14)
  490. </if>
  491. 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
  492. 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}
  493. <if test="sceneIds != null and sceneIds.size() > 0">
  494. and t1.id in
  495. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  496. #{item}
  497. </foreach>
  498. </if>
  499. <if test="sceneIds == null or sceneIds.size() == 0">
  500. and t1.id is null
  501. </if>
  502. <if test="sceneId != null">
  503. and t1.id = #{sceneId}
  504. </if>
  505. <if test="deviceIds != null and deviceIds.size() > 0">
  506. and t6.id in
  507. <foreach collection="deviceIds" item="item" open="(" close=")" separator=",">
  508. #{item}
  509. </foreach>
  510. </if>
  511. <if test="deviceName != null and deviceName != ''">
  512. and t6.device_name like concat('%', #{deviceName},'%')
  513. </if>
  514. </select>
  515. <!--查询管网实时数据列表-->
  516. <select id="selectPipeNetPage" resultType="com.huaxu.dto.OnlineDataDto">
  517. 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
  518. from sms_scene t1
  519. <include refid="deviceInnerJoins"/>
  520. left join(
  521. 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
  522. )t7 on t7.scene_id=t2.scene_id and t7.device_id=t2.device_id
  523. 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}
  524. <if test="onlineDataDto.sceneIds != null and onlineDataDto.sceneIds.size() > 0">
  525. and t1.id in
  526. <foreach collection="onlineDataDto.sceneIds" item="item" open="(" close=")" separator=",">
  527. #{item}
  528. </foreach>
  529. </if>
  530. <if test="onlineDataDto.sceneIds == null or onlineDataDto.sceneIds.size() == 0">
  531. and t1.id is null
  532. </if>
  533. <if test="onlineDataDto.sceneId != null">
  534. and t1.id = #{onlineDataDto.sceneId}
  535. </if>
  536. <if test="onlineDataDto.deviceName != null and onlineDataDto.deviceName != ''">
  537. and t6.device_name like concat('%', #{onlineDataDto.deviceName},'%')
  538. </if>
  539. order by t6.last_update_time desc
  540. </select>
  541. <!--查询管网地图图层及设备-->
  542. <select id="selectPipeNetLayer" resultMap="layerMap">
  543. 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
  544. <if test="flag == null or flag ==0">
  545. ,if (t7.alarm_count>0, 1, 0) device_state
  546. </if>
  547. <if test="flag == 1">
  548. ,case when t7.offline_alarm_count>0 then 2 when t7.alarm_count>0 then 1 else 0 end device_state
  549. </if>
  550. from sms_scene t1
  551. <include refid="deviceInnerJoins"/>
  552. left join(
  553. select a1.scene_id, a1.device_id
  554. <if test="flag == null or flag ==0">
  555. ,count(1) alarm_count
  556. </if>
  557. <if test="flag == 1">
  558. ,sum(case when alarm_type='参数报警' then 1 else 0 end) alarm_count
  559. ,sum(case when alarm_type='状态报警' then 1 else 0 end) offline_alarm_count
  560. </if>
  561. from sms_alarm_details a1 where a1.`status` = 1 and a1.state = 1 group by a1.scene_id, a1.device_id
  562. )t7 on t7.scene_id=t2.scene_id and t7.device_id=t2.device_id
  563. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = '管网'
  564. <choose>
  565. <when test="sceneTypeName != null and sceneTypeName !=''">
  566. and t5.scene_type_name = #{sceneTypeName}
  567. </when>
  568. <otherwise>
  569. and t5.scene_type_name in('压力','流量','水质')
  570. </otherwise>
  571. </choose>
  572. <if test="sceneIds != null and sceneIds.size() > 0">
  573. and t1.id in
  574. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  575. #{item}
  576. </foreach>
  577. </if>
  578. <if test="sceneIds == null or sceneIds.size() == 0">
  579. and t1.id is null
  580. </if>
  581. order by t4.scene_name,t6.date_create
  582. </select>
  583. <!--查询昨日水厂制水总量-->
  584. <select id="selectTotalYieldWater" resultType="java.lang.Double">
  585. select sum(sum_value) yieldWater
  586. from sms_scene t1
  587. <include refid="sceneDeviceJoins"/>
  588. inner join sms_month_report t8 on t8.device_id=t2.device_id and t8.attribute_id =t5.attribute_id
  589. and t8.year = year(now() + interval-1 day) and t8.month = month(now() + interval-1 day) and t8.day = day(now() + interval-1 day)
  590. where t1.parent_scene_id = 0 and t1. status = 1 and t5.parm_type in(3) and t3.scene_type_name = '水厂'
  591. <if test="sceneIds != null and sceneIds.size() > 0">
  592. and t1.id in
  593. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  594. #{item}
  595. </foreach>
  596. </if>
  597. <if test="tenantId != null and tenantId != ''">
  598. and t1.tenant_id = #{tenantId}
  599. </if>
  600. </select>
  601. </mapper>