OnlineMonitorMapper.xml 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  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. <resultMap type="com.huaxu.dto.MonitorDataCollectDto" id="monitorDataMap2">
  25. <result property="sceneId" column="scene_id" jdbcType="INTEGER"/>
  26. <result property="sceneName" column="scene_name" jdbcType="VARCHAR"/>
  27. <result property="sceneTypeName" column="scene_type_name" jdbcType="VARCHAR"/>
  28. <result property="pointX" column="point_x" jdbcType="VARCHAR"/>
  29. <result property="pointY" column="point_y" jdbcType="VARCHAR"/>
  30. <result property="address" column="address" jdbcType="VARCHAR"/>
  31. <result property="sceneState" column="scene_state" jdbcType="INTEGER"/>
  32. <result property="companyOrgId" column="companyOrgId" jdbcType="INTEGER"/>
  33. <collection property="MonitorDataEntities" ofType="com.huaxu.dto.MonitorDataDto" javaType="list">
  34. <result property="deviceId" column="device_id" jdbcType="INTEGER"/>
  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="deviceCode" column="device_code" jdbcType="VARCHAR"/>
  41. <result property="latestValue" column="latest_value" jdbcType="VARCHAR"/>
  42. </collection>
  43. </resultMap>
  44. <!-- 设备结果集 -->
  45. <resultMap type="com.huaxu.dto.MonitorDataCollectDto" id="deviceDataMap">
  46. <result property="sceneId" column="scene_id" jdbcType="INTEGER"/>
  47. <result property="sceneName" column="scene_name" jdbcType="VARCHAR"/>
  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. <result property="sceneTypeName" column="scene_type_name" jdbcType="VARCHAR"/>
  56. <collection property="MonitorDataEntities" ofType="com.huaxu.dto.MonitorDataDto" javaType="list">
  57. <result property="attributeId" column="attribute_id" jdbcType="INTEGER"/>
  58. <result property="attributeName" column="attribute_name" jdbcType="VARCHAR"/>
  59. <result property="unit" column="unit" jdbcType="VARCHAR"/>
  60. <result property="isAlarm" column="is_Alarm" jdbcType="VARCHAR"/>
  61. <result property="attributeType" column="attribute_type" jdbcType="VARCHAR"/>
  62. <result property="latestValue" column="latest_value" jdbcType="VARCHAR"/>
  63. </collection>
  64. </resultMap>
  65. <!-- 管网图层设备结果集 -->
  66. <resultMap type="com.huaxu.dto.PipeNetLayerDto" id="layerMap">
  67. <result property="sceneId" column="scene_id" jdbcType="INTEGER"/>
  68. <result property="sceneName" column="scene_name" jdbcType="VARCHAR"/>
  69. <result property="sceneTypeName" column="scene_type_name" jdbcType="VARCHAR"/>
  70. <collection property="deviceDataList" ofType="com.huaxu.dto.MonitorDataCollectDto" javaType="list">
  71. <result property="deviceId" column="device_id" jdbcType="INTEGER"/>
  72. <result property="deviceCode" column="device_code" jdbcType="VARCHAR"/>
  73. <result property="deviceName" column="device_name" jdbcType="VARCHAR"/>
  74. <result property="pointX" column="point_x" jdbcType="VARCHAR"/>
  75. <result property="pointY" column="point_y" jdbcType="VARCHAR"/>
  76. <result property="address" column="address" jdbcType="VARCHAR"/>
  77. <result property="deviceState" column="device_state" jdbcType="INTEGER"/>
  78. </collection>
  79. </resultMap>
  80. <sql id="Base_Column_List">
  81. t1.id scene_Id,
  82. t1.scene_name ,
  83. t3.scene_type_name,
  84. t1.point_x ,
  85. t1.point_y,
  86. t1.address ,
  87. t5.device_id,
  88. t5.attribute_id ,
  89. ifnull(t5.remark, t9.`name`) attribute_name,
  90. t9.unit ,
  91. case when t5.attribute_id is null then null when t6.id is null then 0 else 1 end is_alarm,
  92. t5.parm_type attribute_type,
  93. if (t5.device_id is null, null, t4.device_code) device_code
  94. </sql>
  95. <sql id="sceneDeviceJoins">
  96. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  97. left join sms_device_scene t2 on t2.parent_scene_id=t1.id and t2. status = 1
  98. left join sms_device t4 on t2.device_id=t4.id and t4. status = 1 and t4. enable_state = 1
  99. left join sms_device_parm t5 on t5.scene_id = t2.scene_id and t5.device_id=t2.device_id and t5. status = 1
  100. <if test="type == 3 ">
  101. and t5.is_suspension = 1
  102. </if>
  103. <if test="type == 4 ">
  104. and t5.is_map = 1
  105. </if>
  106. left join sms_device_attribute t9 on t5.attribute_id=t9.id and t9.status = 1
  107. left join sms_alarm_details t6 on t6.scene_id=t2.scene_id and t6.device_id=t2.device_id
  108. and t6.attribute_id=t5.attribute_id and t6.status = 1 and t6.state=1
  109. </sql>
  110. <sql id="sceneAlarmJoins">
  111. left join (
  112. select parent_scene_id
  113. <if test="flag == null or flag ==0">
  114. ,count(1) alarm_count
  115. </if>
  116. <if test="flag == 1">
  117. ,sum(case when alarm_type='参数报警' then 1 else 0 end) alarm_count
  118. ,sum(case when alarm_type='状态报警' then 1 else 0 end) offline_alarm_count
  119. </if>
  120. from sms_alarm_details a1
  121. where a1.`status` = 1 and a1.state = 1
  122. <if test="sceneIds != null and sceneIds.size() > 0">
  123. and a1.scene_id in
  124. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  125. #{item}
  126. </foreach>
  127. </if>
  128. group by parent_scene_id
  129. )t7 on t7.parent_scene_id=t1.id
  130. <if test="flag == 1">
  131. left join (
  132. select parent_scene_id,count(distinct device_id) setting_device_count
  133. from sms_alarm_setting
  134. where alarm_type='状态报警' and status=1
  135. group by parent_scene_id
  136. )t10 on t7.parent_scene_id=t10.parent_scene_id
  137. </if>
  138. </sql>
  139. <sql id="deviceInnerJoins">
  140. inner join sms_scene_type t3 on t1.scene_type_id=t3.id
  141. inner join sms_device_scene t2 on t2.parent_scene_id=t1.id and t2. status = 1
  142. inner join sms_device t6 on t2.device_id=t6.id and t6. status = 1 and t6.enable_state = 1
  143. inner join sms_scene t4 on t2.scene_id=t4.id
  144. inner join sms_scene_type t5 on t4.scene_type_id=t5.id and t5. status = 1
  145. </sql>
  146. <sql id="deviceLeftJoins">
  147. inner join sms_scene_type t3 on t1.scene_type_id=t3.id and t3. status = 1
  148. left join sms_device_scene t2 on t2.parent_scene_id=t1.id and t2. status = 1
  149. left join sms_device t6 on t2.device_id=t6.id and t6. status = 1 and t6.enable_state = 1
  150. left join sms_scene t4 on t2.scene_id=t4.id and t4. status = 1
  151. left join sms_scene_type t5 on t4.scene_type_id=t5.id and t5. status = 1 and t5.scene_type_name = #{sceneTypeName}
  152. </sql>
  153. <!--查询实时报警信息-->
  154. <select id="selectAlarmDetails" resultType="com.huaxu.dto.AlarmDetailsDto">
  155. select
  156. t1.scene_name as "sceneName",
  157. t6.alarm_content as "alarmContent",
  158. t6.alarm_start_time as "alarmStartTime"
  159. from sms_scene t1
  160. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  161. inner join sms_alarm_details t6 on t1.id=t6.parent_scene_id and t6.`status`=1
  162. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t6.state=1
  163. <if test="sceneTypeName != null and sceneTypeName != ''">
  164. and t3.scene_type_name = #{sceneTypeName}
  165. </if>
  166. <if test="companyOrgId != null and companyOrgId !=''">
  167. and t6.company_org_id=#{companyOrgId}
  168. </if>
  169. <if test="sceneIds != null and sceneIds.size() > 0">
  170. and t1.id in
  171. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  172. #{item}
  173. </foreach>
  174. </if>
  175. <if test="sceneIds == null or sceneIds.size() == 0">
  176. and t1.id is null
  177. </if>
  178. <if test="sceneName != null and sceneName != ''">
  179. and t1.scene_name like concat('%',#{sceneName},'%')
  180. </if>
  181. <if test="tenantId != null and tenantId != ''">
  182. and t1.tenant_id = #{tenantId}
  183. </if>
  184. order by t6.alarm_start_time desc
  185. </select>
  186. <!--查询实时报警数量-->
  187. <select id="selectAlarmCount" resultType="java.util.Map">
  188. select
  189. t1.scene_name as "sceneName",
  190. count(1) as "alalmCount"
  191. from sms_scene t1
  192. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  193. inner join sms_alarm_details t6 on t1.id=t6.parent_scene_id and t6.`status`=1
  194. 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
  195. <if test="sceneIds != null and sceneIds.size() > 0">
  196. and t1.id in
  197. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  198. #{item}
  199. </foreach>
  200. </if>
  201. <if test="sceneIds == null or sceneIds.size() == 0">
  202. and t1.id is null
  203. </if>
  204. <if test="sceneName != null and sceneName != ''">
  205. and t1.scene_name like concat('%',#{sceneName},'%')
  206. </if>
  207. <if test="tenantId != null and tenantId != ''">
  208. and t1.tenant_id = #{tenantId}
  209. </if>
  210. group by t1.scene_name
  211. order by alalmCount desc
  212. </select>
  213. <!--查询地图悬浮数据-->
  214. <select id="selectMapSuspension" resultMap="monitorDataMap2">
  215. select
  216. <include refid="Base_Column_List"/>
  217. <if test="flag == null or flag ==0">
  218. ,if (t7.alarm_count>0, 1, 0) scene_state,
  219. </if>
  220. <if test="flag == 1">
  221. ,case when t7.offline_alarm_count=t10.setting_device_count then 2
  222. when t7.alarm_count>0 or t7.offline_alarm_count>0 then 1 else 0 end scene_state,
  223. </if>
  224. t1.company_org_id as "companyOrgId"
  225. from sms_scene t1
  226. <include refid="sceneDeviceJoins"/>
  227. <include refid="sceneAlarmJoins"/>
  228. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1
  229. <choose>
  230. <when test="sceneTypeName != null and sceneTypeName !=''">
  231. and t3.scene_type_name = #{sceneTypeName}
  232. </when>
  233. <otherwise>
  234. and t3.scene_type_name in('水源','水厂','泵站')
  235. </otherwise>
  236. </choose>
  237. <if test="sceneIds != null and sceneIds.size() > 0">
  238. and t1.id in
  239. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  240. #{item}
  241. </foreach>
  242. </if>
  243. <if test="sceneIds == null or sceneIds.size() == 0">
  244. and t1.id is null
  245. </if>
  246. <if test="tenantId != null and tenantId != ''">
  247. and t1.tenant_id = #{tenantId}
  248. </if>
  249. order by t3.scene_type_name,t1.scene_name,t5.seq
  250. </select>
  251. <!--查询地图参数数据-->
  252. <select id="selectMapParam" resultMap="monitorDataMap">
  253. select
  254. <include refid="Base_Column_List"/>
  255. <if test="flag == null or flag == 0">
  256. ,if (t7.alarm_count>0, 1, 0) scene_state
  257. </if>
  258. <if test="flag == 1">
  259. ,case when t7.offline_alarm_count=t10.setting_device_count then 2
  260. when t7.alarm_count>0 or t7.offline_alarm_count>0 then 1 else 0 end scene_state
  261. </if>
  262. from sms_scene t1
  263. <include refid="sceneDeviceJoins"/>
  264. <include refid="sceneAlarmJoins"/>
  265. where t1.parent_scene_id = 0 and t1. status = 1 and t1.id = #{sceneId}
  266. <if test="sceneIds != null and sceneIds.size() > 0">
  267. and t1.id in
  268. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  269. #{item}
  270. </foreach>
  271. </if>
  272. order by t1.scene_name,t5.seq
  273. </select>
  274. <!--分页查询实时数据列表-->
  275. <select id="selectPage" resultType="com.huaxu.dto.OnlineDataDto">
  276. select t1.id scene_id,t1.scene_name,t1.address
  277. from sms_scene t1
  278. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  279. left join(
  280. select parent_scene_id,max(last_update_time) last_update_time
  281. from sms_device_scene a1
  282. left join sms_device a2 on a2.id=a1.device_id
  283. where
  284. <if test="onlineDataDto.sceneIds != null and onlineDataDto.sceneIds.size() > 0">
  285. a1.scene_id in
  286. <foreach collection="onlineDataDto.sceneIds" item="item" open="(" close=")" separator=",">
  287. #{item}
  288. </foreach>
  289. </if>
  290. <if test="onlineDataDto.sceneIds == null or onlineDataDto.sceneIds.size() == 0">
  291. a1.scene_id is null
  292. </if>
  293. group by parent_scene_id
  294. )t4 on t1.id=t4.parent_scene_id
  295. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = #{onlineDataDto.sceneTypeName}
  296. <if test="onlineDataDto.sceneIds != null and onlineDataDto.sceneIds.size() > 0">
  297. and t1.id in
  298. <foreach collection="onlineDataDto.sceneIds" item="item" open="(" close=")" separator=",">
  299. #{item}
  300. </foreach>
  301. </if>
  302. <if test="onlineDataDto.sceneIds == null or onlineDataDto.sceneIds.size() == 0">
  303. and t1.id is null
  304. </if>
  305. <if test="onlineDataDto.sceneName != null and onlineDataDto.sceneName != ''">
  306. and t1.scene_name like concat('%',#{onlineDataDto.sceneName},'%')
  307. </if>
  308. <if test="onlineDataDto.tenantId != null and onlineDataDto.tenantId != ''">
  309. and t1.tenant_id = #{onlineDataDto.tenantId}
  310. </if>
  311. order by t4.last_update_time desc
  312. </select>
  313. <!--查询设备报警分析-->
  314. <select id="selectAlarmStats" resultType="java.util.Map">
  315. select
  316. t4.id,
  317. t4.device_name as "deviceName",
  318. count(1) as "alarmCount",
  319. sum(timestampdiff(minute,t6.alarm_start_time,ifnull(t6.alarm_end_time,now()))) as "alarmDuration"
  320. from sms_scene t1
  321. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  322. inner join sms_alarm_details t6 on t1.id=t6.parent_scene_id and t6.`status`=1
  323. inner join sms_device t4 on t4.id=t6.device_id and t4.`status`=1 and t4. enable_state = 1
  324. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t1.id = #{id}
  325. <if test="sceneIds != null and sceneIds.size() > 0">
  326. and t1.id in
  327. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  328. #{item}
  329. </foreach>
  330. </if>
  331. <if test="days != null">
  332. and t6.alarm_start_time>DATE(NOW() + INTERVAL-#{days}+1 DAY)
  333. </if>
  334. group by t4.id,t4.device_name
  335. </select>
  336. <!--查询场景对应参数数据-->
  337. <select id="selectSceneParam" resultMap="monitorDataMap">
  338. select
  339. <include refid="Base_Column_List"/>,t8.latest_value
  340. from sms_scene t1
  341. <include refid="sceneDeviceJoins"/>
  342. left join (
  343. select c1.device_id,c1.attribute_id,c1.latest_value
  344. from sms_month_report c1
  345. inner join (
  346. select b1.device_id,b1.attribute_id,max(b1.collect_date) collect_date
  347. from sms_month_report b1
  348. where b1.year = year(now() + interval-1 day) and b1.month = month(now() + interval-1 day) and b1.day = day(now() + interval-1 day)
  349. 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
  350. )t8 on t8.device_id=t2.device_id and t8.attribute_id =t5.attribute_id
  351. where t1.parent_scene_id = 0 and t1. status = 1
  352. <if test="type == 1 ">
  353. and t5.parm_type in(3,4,5,6)
  354. </if>
  355. <if test="type == 2 ">
  356. and t5.parm_type in(2,3,4,5,6,7,8,9,10,11,12,13,14)
  357. </if>
  358. <if test="type == 5 ">
  359. and t5.parm_type in(3,4,13,14)
  360. </if>
  361. <if test="sceneTypeName != null and sceneTypeName != '' ">
  362. and t3.scene_type_name = #{sceneTypeName}
  363. </if>
  364. <if test="sceneId != null and sceneId != '' ">
  365. and t1.id = #{sceneId}
  366. </if>
  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="tenantId != null and tenantId != ''">
  374. and t1.tenant_id = #{tenantId}
  375. </if>
  376. order by t1.scene_name,t5.seq
  377. </select>
  378. <!--查询场景对应参数数据-->
  379. <select id="selectSceneParamForLastMonth" resultMap="monitorDataMap">
  380. select
  381. <include refid="Base_Column_List"/>,t8.latest_value
  382. from sms_scene t1
  383. <include refid="sceneDeviceJoins"/>
  384. left join (
  385. select c1.device_id,c1.attribute_id,c1.latest_value
  386. from sms_month_report c1
  387. inner join (
  388. select b1.device_id,b1.attribute_id,max(b1.collect_date) collect_date
  389. from sms_month_report b1
  390. where PERIOD_DIFF( date_format( now( ) , '%Y%m' ) , date_format( b1.COLLECT_DATE, '%Y%m' ) ) =1
  391. 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
  392. )t8 on t8.device_id=t2.device_id and t8.attribute_id =t5.attribute_id
  393. where t1.parent_scene_id = 0 and t1. status = 1
  394. <if test="type == 1 ">
  395. and t5.parm_type in(3,4,5,6)
  396. </if>
  397. <if test="type == 2 ">
  398. and t5.parm_type in(2,3,4,5,6,7,8,9,10,11,12,13,14)
  399. </if>
  400. <if test="sceneTypeName != null and sceneTypeName != '' ">
  401. and t3.scene_type_name = #{sceneTypeName}
  402. </if>
  403. <if test="sceneId != null and sceneId != '' ">
  404. and t1.id = #{sceneId}
  405. </if>
  406. <if test="sceneIds != null and sceneIds.size() > 0">
  407. and t1.id in
  408. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  409. #{item}
  410. </foreach>
  411. </if>
  412. <if test="tenantId != null and tenantId != ''">
  413. and t1.tenant_id = #{tenantId}
  414. </if>
  415. order by t1.scene_name,t5.seq
  416. </select>
  417. <!--按管网名称分类查询设备数量-->
  418. <select id="selectDeviceCount" resultType="java.util.Map">
  419. 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
  420. from sms_scene t1
  421. <include refid="deviceInnerJoins"/>
  422. left join(
  423. 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
  424. )t7 on t7.scene_id=t2.scene_id and t7.device_id=t2.device_id
  425. 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}
  426. <if test="sceneIds != null and sceneIds.size() > 0">
  427. and t1.id in
  428. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  429. #{item}
  430. </foreach>
  431. </if>
  432. <if test="sceneIds == null or sceneIds.size() == 0">
  433. and t1.id is null
  434. </if>
  435. <if test="sceneId != null">
  436. and t1.id = #{sceneId}
  437. </if>
  438. <if test="deviceName != null and deviceName != ''">
  439. and t6.device_name like concat('%', #{deviceName},'%')
  440. </if>
  441. group by t1.id,t1.scene_name
  442. </select>
  443. <!--查询设备地图参数数据-->
  444. <select id="selectDeviceMapParam" resultMap="deviceDataMap">
  445. 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,
  446. t2.seq,case when t2.attribute_id is null then null when t6.id is null then 0 else 1 end is_alarm
  447. <if test="flag == null or flag ==0">
  448. ,if (t4.alarm_count>0, 1, 0) device_state
  449. </if>
  450. <if test="flag == 1">
  451. ,case when t4.offline_alarm_count>0 then 2 when t4.alarm_count>0 then 1 else 0 end device_state
  452. </if>
  453. from sms_device t1
  454. left join sms_device_parm t2 on t2.device_id=t1.id and t2.is_map=1 and t2.status=1
  455. left join sms_device_attribute t3 on t2.attribute_id=t3.id and t3.status=1
  456. left join (
  457. select a1.device_id
  458. <if test="flag == null or flag ==0">
  459. ,count(1) alarm_count
  460. </if>
  461. <if test="flag == 1">
  462. ,sum(case when alarm_type='参数报警' then 1 else 0 end) alarm_count
  463. ,sum(case when alarm_type='状态报警' then 1 else 0 end) offline_alarm_count
  464. </if>
  465. from sms_alarm_details a1 where a1.device_id= #{deviceId} and a1.`status` = 1 and a1.state = 1
  466. )t4 on t4.device_id=t1.id
  467. 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
  468. where t1. status = 1 and t1. enable_state = 1 and t1.id= #{deviceId}
  469. order by t2.seq
  470. </select>
  471. <!--统计设备合格数据-->
  472. <select id="statsDeviceQualified" resultType="com.huaxu.dto.DeviceCountStatsDto">
  473. select t5.scene_type_name type,count(1) totalCount,sum(if(t7.device_id is null,0,1)) alarmCount
  474. <if test="flag == null or flag ==0">
  475. ,count(1)-sum(if(t7.device_id is null,0,1)) normalCount
  476. </if>
  477. <if test="flag == 1">
  478. ,sum(if(t8.device_id is null,0,1)) offlineCount
  479. ,count(1)-sum(if(t7.device_id is null,0,1))-sum(if(t8.device_id is null,0,1)) normalCount
  480. </if>
  481. from sms_scene t1
  482. <include refid="deviceInnerJoins"/>
  483. left join(
  484. select a1.scene_id, a1.device_id from sms_alarm_details a1 where a1.`status` = 1 and a1.state = 1
  485. <if test="sceneTypeName != null and sceneTypeName !=''">
  486. and a1.alarm_type = '参数报警'
  487. </if>
  488. group by a1.scene_id, a1.device_id
  489. )t7 on t7.scene_id=t2.scene_id and t7.device_id=t2.device_id
  490. <if test="flag == 1">
  491. left join(
  492. select a1.scene_id, a1.device_id from sms_alarm_details a1 where a1.`status` = 1 and a1.state = 1 and a1.alarm_type = '状态报警'
  493. group by a1.scene_id, a1.device_id
  494. )t8 on t8.scene_id=t2.scene_id and t8.device_id=t2.device_id
  495. </if>
  496. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = '管网'
  497. <choose>
  498. <when test="sceneTypeName != null and sceneTypeName !=''">
  499. and t5.scene_type_name = #{sceneTypeName}
  500. </when>
  501. <otherwise>
  502. and t5.scene_type_name in('压力','流量','水质')
  503. </otherwise>
  504. </choose>
  505. <if test="sceneIds != null and sceneIds.size() > 0">
  506. and t1.id in
  507. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  508. #{item}
  509. </foreach>
  510. </if>
  511. <if test="sceneIds == null or sceneIds.size() == 0">
  512. and t1.id is null
  513. </if>
  514. <if test="sceneId != null">
  515. and t1.id = #{sceneId}
  516. </if>
  517. <if test="deviceName != null and deviceName != ''">
  518. and t6.device_name like concat('%', #{deviceName},'%')
  519. </if>
  520. group by t5.scene_type_name
  521. </select>
  522. <!--统计设备属性合格数据-->
  523. <select id="statsParmQualified" resultType="com.huaxu.dto.DeviceCountStatsDto">
  524. select case t7.parm_type when '13' then '压力' when '7' then 'PH' when '9' then '浊度' when '11' then '余氯' end type,
  525. count(t8.device_id) alarmCount
  526. from sms_scene t1
  527. <include refid="deviceInnerJoins"/>
  528. inner join sms_device_parm t7 on t7.scene_id=t2.scene_id and t7.device_id=t2.device_id and t7.status=1
  529. <if test="sceneTypeName == '压力'">
  530. and t7.parm_type in(13)
  531. </if>
  532. <if test="sceneTypeName == '水质'">
  533. and t7.parm_type in(7,9,11)
  534. </if>
  535. 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
  536. 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}
  537. <if test="sceneIds != null and sceneIds.size() > 0">
  538. and t1.id in
  539. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  540. #{item}
  541. </foreach>
  542. </if>
  543. <if test="sceneIds == null or sceneIds.size() == 0">
  544. and t1.id is null
  545. </if>
  546. <if test="sceneId != null">
  547. and t1.id = #{sceneId}
  548. </if>
  549. <if test="deviceName != null and deviceName != ''">
  550. and t6.device_name like concat('%', #{deviceName},'%')
  551. </if>
  552. group by t7.parm_type
  553. </select>
  554. <!-- 查询设备参数-->
  555. <select id="statsDeviceParm" resultMap="deviceDataMap">
  556. SELECT t6.id device_id,t6.device_code,t6.device_name,t7.attribute_id,t7.parm_type attribute_type,t3.scene_type_name,
  557. case when t7.attribute_id is null then null when t8.id is null then 0 else 1 end is_alarm
  558. <if test="type == 4 ">,t9.latest_value</if>
  559. from sms_scene t1
  560. <include refid="deviceInnerJoins"/>
  561. left join sms_device_parm t7 on t7.scene_id=t2.scene_id and t7.device_id=t2.device_id and t7.status=1
  562. <if test="type == 1 ">
  563. and t7.parm_type in(13)
  564. </if>
  565. <if test="type == 2 ">
  566. and t7.parm_type in(14,16)
  567. </if>
  568. <if test="type == 3">
  569. and t7.parm_type in(7,9,11,18)
  570. </if>
  571. <if test="type == 4 ">
  572. and t7.parm_type in(16)
  573. left join (
  574. select c1.device_id,c1.attribute_id,c1.latest_value
  575. from sms_month_report c1
  576. inner join (
  577. select b1.device_id,b1.attribute_id,max(b1.collect_date) collect_date
  578. from sms_month_report b1
  579. where b1.year = year(now() + interval-1 day) and b1.month = month(now() + interval-1 day) and b1.day = day(now() + interval-1 day)
  580. 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
  581. )t9 on t9.device_id=t2.device_id and t9.attribute_id =t7.attribute_id
  582. </if>
  583. <if test="type == 5 ">
  584. and t7.parm_type in(14)
  585. </if>
  586. 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
  587. 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}
  588. <if test="sceneIds != null and sceneIds.size() > 0">
  589. and t1.id in
  590. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  591. #{item}
  592. </foreach>
  593. </if>
  594. <if test="sceneIds == null or sceneIds.size() == 0">
  595. and t1.id is null
  596. </if>
  597. <if test="sceneId != null">
  598. and t1.id = #{sceneId}
  599. </if>
  600. <if test="deviceIds != null and deviceIds.size() > 0">
  601. and t6.id in
  602. <foreach collection="deviceIds" item="item" open="(" close=")" separator=",">
  603. #{item}
  604. </foreach>
  605. </if>
  606. <if test="deviceName != null and deviceName != ''">
  607. and t6.device_name like concat('%', #{deviceName},'%')
  608. </if>
  609. </select>
  610. <!--分页查询管网实时数据列表-->
  611. <select id="selectPipeNetPage" resultType="com.huaxu.dto.OnlineDataDto">
  612. 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
  613. from sms_scene t1
  614. <include refid="deviceInnerJoins"/>
  615. left join(
  616. 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
  617. )t7 on t7.scene_id=t2.scene_id and t7.device_id=t2.device_id
  618. 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}
  619. <if test="onlineDataDto.sceneIds != null and onlineDataDto.sceneIds.size() > 0">
  620. and t1.id in
  621. <foreach collection="onlineDataDto.sceneIds" item="item" open="(" close=")" separator=",">
  622. #{item}
  623. </foreach>
  624. </if>
  625. <if test="onlineDataDto.sceneIds == null or onlineDataDto.sceneIds.size() == 0">
  626. and t1.id is null
  627. </if>
  628. <if test="onlineDataDto.sceneId != null">
  629. and t1.id = #{onlineDataDto.sceneId}
  630. </if>
  631. <if test="onlineDataDto.deviceName != null and onlineDataDto.deviceName != ''">
  632. and t6.device_name like concat('%', #{onlineDataDto.deviceName},'%')
  633. </if>
  634. order by t6.last_update_time desc
  635. </select>
  636. <!--查询管网地图图层及设备-->
  637. <select id="selectPipeNetLayer" resultMap="layerMap">
  638. 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
  639. <if test="flag == null or flag ==0">
  640. ,if (t7.alarm_count>0, 1, 0) device_state
  641. </if>
  642. <if test="flag == 1">
  643. ,case when t7.offline_alarm_count>0 then 2 when t7.alarm_count>0 then 1 else 0 end device_state
  644. </if>
  645. from sms_scene t1
  646. <include refid="deviceInnerJoins"/>
  647. left join(
  648. select a1.scene_id, a1.device_id
  649. <if test="flag == null or flag ==0">
  650. ,count(1) alarm_count
  651. </if>
  652. <if test="flag == 1">
  653. ,sum(case when alarm_type='参数报警' then 1 else 0 end) alarm_count
  654. ,sum(case when alarm_type='状态报警' then 1 else 0 end) offline_alarm_count
  655. </if>
  656. from sms_alarm_details a1 where a1.`status` = 1 and a1.state = 1 group by a1.scene_id, a1.device_id
  657. )t7 on t7.scene_id=t2.scene_id and t7.device_id=t2.device_id
  658. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = '管网'
  659. <choose>
  660. <when test="sceneTypeName != null and sceneTypeName !=''">
  661. and t5.scene_type_name = #{sceneTypeName}
  662. </when>
  663. <otherwise>
  664. and t5.scene_type_name in('压力','流量','水质')
  665. </otherwise>
  666. </choose>
  667. <if test="sceneIds != null and sceneIds.size() > 0">
  668. and t1.id in
  669. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  670. #{item}
  671. </foreach>
  672. </if>
  673. <if test="sceneIds == null or sceneIds.size() == 0">
  674. and t1.id is null
  675. </if>
  676. order by t4.scene_name,t6.date_create
  677. </select>
  678. <!--查询昨日水厂制水总量-->
  679. <select id="selectTotalYieldWater" resultType="java.lang.Double">
  680. select sum(sum_value)/10000 yieldWater
  681. from sms_scene t1
  682. <include refid="sceneDeviceJoins"/>
  683. inner join sms_month_report t8 on t8.device_id=t2.device_id and t8.attribute_id =t5.attribute_id
  684. and t8.year = year(now() + interval-1 day) and t8.month = month(now() + interval-1 day) and t8.day = day(now() + interval-1 day)
  685. where t1.parent_scene_id = 0 and t1. status = 1 and t5.parm_type in(3) and t3.scene_type_name = '水厂'
  686. <if test="sceneIds != null and sceneIds.size() > 0">
  687. and t1.id in
  688. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  689. #{item}
  690. </foreach>
  691. </if>
  692. <if test="tenantId != null and tenantId != ''">
  693. and t1.tenant_id = #{tenantId}
  694. </if>
  695. </select>
  696. <!--查询实时数据列表-->
  697. <select id="selectList" resultType="com.huaxu.dto.OnlineDataDto">
  698. select t1.id scene_id,t1.scene_name,t1.address
  699. ,case when t7.offline_alarm_count=t10.setting_device_count then 2
  700. when t7.alarm_count>0 or t7.offline_alarm_count>0 then 1 else 0 end scene_state
  701. from sms_scene t1
  702. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  703. left join(
  704. select parent_scene_id,max(last_update_time) last_update_time
  705. from sms_device_scene a1
  706. left join sms_device a2 on a2.id=a1.device_id
  707. where
  708. <if test="sceneIds != null and sceneIds.size() > 0">
  709. a1.scene_id in
  710. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  711. #{item}
  712. </foreach>
  713. </if>
  714. <if test="sceneIds == null or sceneIds.size() == 0">
  715. a1.scene_id is null
  716. </if>
  717. group by parent_scene_id
  718. )t4 on t1.id=t4.parent_scene_id
  719. left join (
  720. select parent_scene_id
  721. ,sum(case when alarm_type='参数报警' then 1 else 0 end) alarm_count
  722. ,sum(case when alarm_type='状态报警' then 1 else 0 end) offline_alarm_count
  723. from sms_alarm_details a1
  724. where a1.`status` = 1 and a1.state = 1
  725. <if test="sceneIds != null and sceneIds.size() > 0">
  726. and a1.scene_id in
  727. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  728. #{item}
  729. </foreach>
  730. </if>
  731. group by parent_scene_id
  732. )t7 on t7.parent_scene_id=t1.id
  733. left join (
  734. select parent_scene_id,count(distinct device_id) setting_device_count
  735. from sms_alarm_setting
  736. where alarm_type='状态报警' and status=1
  737. group by parent_scene_id
  738. )t10 on t7.parent_scene_id=t10.parent_scene_id
  739. where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = #{sceneTypeName}
  740. <if test="sceneIds != null and sceneIds.size() > 0">
  741. and t1.id in
  742. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  743. #{item}
  744. </foreach>
  745. </if>
  746. <if test="sceneIds == null or sceneIds.size() == 0">
  747. and t1.id is null
  748. </if>
  749. <if test="tenantId != null and tenantId != ''">
  750. and t1.tenant_id = #{tenantId}
  751. </if>
  752. <if test="sceneId != null and sceneId != ''">
  753. and t1.id = #{sceneId}
  754. </if>
  755. <if test="companyOrgId != null and companyOrgId != ''">
  756. and t1.company_org_id = #{companyOrgId}
  757. </if>
  758. order by field(scene_state,1,0,2),t4.last_update_time desc
  759. </select>
  760. <!--查询管网实时数据列表-->
  761. <select id="selectPipeNetList" resultType="com.huaxu.dto.OnlineDataDto">
  762. select t1.id scene_id,t1.scene_name,t6.id device_id,t6.device_code,t6.device_name,t6.address
  763. ,case when t7.offline_alarm_count>0 then 2 when t7.alarm_count>0 then 1 else 0 end device_state
  764. from sms_scene t1
  765. <include refid="deviceInnerJoins"/>
  766. left join(
  767. select a1.scene_id, a1.device_id
  768. ,sum(case when alarm_type='参数报警' then 1 else 0 end) alarm_count
  769. ,sum(case when alarm_type='状态报警' then 1 else 0 end) offline_alarm_count
  770. from sms_alarm_details a1 where a1.`status` = 1 and a1.state = 1 group by a1.scene_id, a1.device_id
  771. )t7 on t7.scene_id=t2.scene_id and t7.device_id=t2.device_id
  772. 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}
  773. <if test="sceneIds != null and sceneIds.size() > 0">
  774. and t1.id in
  775. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  776. #{item}
  777. </foreach>
  778. </if>
  779. <if test="sceneIds == null or sceneIds.size() == 0">
  780. and t1.id is null
  781. </if>
  782. <if test="deviceId != null and deviceId != ''">
  783. and t6.id = #{deviceId}
  784. </if>
  785. <if test="companyOrgId != null and companyOrgId != ''">
  786. and t1.company_org_id = #{companyOrgId}
  787. </if>
  788. order by field(device_state,1,0,2),t6.last_update_time desc
  789. </select>
  790. </mapper>