OnlineMonitorMapper.xml 43 KB

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