SceneMapper.xml 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.huaxu.dao.SceneMapper">
  6. <resultMap type="SceneEntity" id="SceneResult">
  7. <result property="id" column="id"/>
  8. <result property="tenantId" column="tenant_id"/>
  9. <result property="parentSceneId" column="parent_scene_id"/>
  10. <result property="parentSceneIds" column="parent_scene_ids"/>
  11. <result property="sceneName" column="scene_name"/>
  12. <result property="companyOrgId" column="company_org_id"/>
  13. <result property="deptOrgId" column="dept_org_id"/>
  14. <result property="sceneTypeId" column="scene_type_id"/>
  15. <result property="enableState" column="enable_state"/>
  16. <result property="runTime" column="run_time"/>
  17. <result property="address" column="address"/>
  18. <result property="pointX" column="point_x"/>
  19. <result property="pointY" column="point_y"/>
  20. <result property="remark" column="remark"/>
  21. <result property="status" column="status"/>
  22. <result property="dateCreate" column="date_create"/>
  23. <result property="createBy" column="create_by"/>
  24. <result property="dateUpdate" column="date_update"/>
  25. <result property="updateBy" column="update_by"/>
  26. </resultMap>
  27. <!-- 实体栏位 -->
  28. <sql id="sceneColumns">
  29. a.id as "id" ,
  30. a.tenant_id as "tenantId" ,
  31. a.parent_scene_id as "parentSceneId" ,
  32. a.parent_scene_ids as "parentSceneIds" ,
  33. a.scene_name as "sceneName" ,
  34. a.company_org_id as "companyOrgId" ,
  35. a.dept_org_id as "deptOrgId" ,
  36. a.scene_type_id as "sceneTypeId" ,
  37. a.enable_state as "enableState" ,
  38. a.run_time as "runTime" ,
  39. a.address as "address" ,
  40. a.point_x as "pointX" ,
  41. a.point_y as "pointY" ,
  42. a.remark as "remark" ,
  43. a.status as "status" ,
  44. a.date_create as "dateCreate" ,
  45. a.create_by as "createBy" ,
  46. a.date_update as "dateUpdate" ,
  47. a.update_by as "updateBy",
  48. s.scene_type_name as "sceneTypeName"
  49. </sql>
  50. <sql id="deviceJoins">
  51. left join sms_scene_type s on s.id =a.scene_type_id and s.status=1
  52. </sql>
  53. <!-- 根据主键获取实体 -->
  54. <select id="findSceneById" resultType="com.huaxu.entity.SceneEntity">
  55. SELECT
  56. <include refid="sceneColumns"/>
  57. FROM sms_scene a
  58. <include refid="deviceJoins"/>
  59. WHERE a.id = #{id} and a.status=1
  60. </select>
  61. <!-- 根据获取实体List -->
  62. <select id="findList" resultType="com.huaxu.entity.SceneEntity">
  63. SELECT
  64. <include refid="sceneColumns"/>
  65. FROM sms_scene a
  66. <include refid="deviceJoins"/>
  67. <where>
  68. a.status=1
  69. <if test="scene.companyOrgId!=null and scene.deptOrgId!=null">
  70. and a.DEPT_ORG_ID = #{scene.deptOrgId} and a.COMPANY_ORG_ID = #{scene.companyOrgId}
  71. </if>
  72. <if test="scene.companyOrgId!=null and scene.deptOrgId == null">
  73. and a.DEPT_ORG_ID is null and a.COMPANY_ORG_ID = #{scene.companyOrgId}
  74. </if>
  75. <if test="scene.tenantId != null and scene.tenantId != ''">and a.tenant_id = #{scene.tenantId}</if>
  76. <if test="scene.parentSceneId != null ">and a.parent_scene_id = #{scene.parentSceneId}</if>
  77. <if test="scene.sceneName != null and scene.sceneName != ''">
  78. and a.scene_name LIKE concat('%',#{scene.sceneName},'%')
  79. </if>
  80. <if test="scene.sceneTypeId != null ">and a.scene_type_id = #{scene.sceneTypeId}</if>
  81. <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
  82. <if test="scene.permissonType == 5 or scene.permissonType == 2">
  83. and ( a.DEPT_ORG_ID in
  84. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  85. #{item.orgId}
  86. </foreach>
  87. or
  88. a.COMPANY_ORG_ID in
  89. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  90. #{item.orgId}
  91. </foreach>
  92. )
  93. </if>
  94. <if test="scene.permissonType == 4 or scene.permissonType == 3">
  95. and a.DEPT_ORG_ID in
  96. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  97. #{item.orgId}
  98. </foreach>
  99. </if>
  100. <if test="scene.permissonType == 1">
  101. and a.COMPANY_ORG_ID in
  102. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  103. #{item.orgId}
  104. </foreach>
  105. and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
  106. </if>
  107. </if>
  108. </where>
  109. order by a.date_create
  110. </select>
  111. <!-- 根据主键获取租户菜单 -->
  112. <select id="findBySceneTypeIds" resultType="com.huaxu.entity.SceneEntity">
  113. select a.id
  114. FROM sms_scene a
  115. <include refid="deviceJoins"/>
  116. WHERE a.scene_type_id in
  117. <foreach collection = "Ids" item = "dramaId" open = "(" close = ")" separator = "," >
  118. #{dramaId}
  119. </foreach>
  120. </select>
  121. <!-- 根据主键获取租户菜单 -->
  122. <select id="findByParentSceneIds" resultType="com.huaxu.entity.SceneEntity">
  123. select a.id
  124. FROM sms_scene a
  125. <include refid="deviceJoins"/>
  126. WHERE a.status=1 and a.parent_scene_id in
  127. <foreach collection = "Ids" item = "dramaId" open = "(" close = ")" separator = "," >
  128. #{dramaId}
  129. </foreach>
  130. </select>
  131. <select id="findByParentIdsLike" resultType="com.huaxu.entity.SceneEntity">
  132. SELECT
  133. <include refid="sceneColumns"/>
  134. FROM sms_scene a
  135. <include refid="deviceJoins"/>
  136. <where>
  137. a.status=1
  138. <if test="scene.companyOrgId != null ">and a.COMPANY_ORG_ID=#{scene.companyOrgId}</if>
  139. <if test="scene.tenantId != null and scene.tenantId != ''">and a.tenant_id = #{scene.tenantId}</if>
  140. <if test="scene.parentSceneIds != null ">and a.parent_scene_ids LIKE #{scene.parentSceneIds}</if>
  141. <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
  142. <if test="scene.permissonType == 5 or scene.permissonType == 2">
  143. and ( a.DEPT_ORG_ID in
  144. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  145. #{item.orgId}
  146. </foreach>
  147. or
  148. a.COMPANY_ORG_ID in
  149. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  150. #{item.orgId}
  151. </foreach>
  152. )
  153. </if>
  154. <if test="scene.permissonType == 4 or scene.permissonType == 3">
  155. and a.DEPT_ORG_ID in
  156. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  157. #{item.orgId}
  158. </foreach>
  159. </if>
  160. <if test="scene.permissonType == 1">
  161. and a.COMPANY_ORG_ID in
  162. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  163. #{item.orgId}
  164. </foreach>
  165. and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
  166. </if>
  167. </if>
  168. </where>
  169. </select>
  170. <!-- 根据获取实体 page -->
  171. <select id="findPage" resultType="com.huaxu.entity.SceneEntity">
  172. SELECT
  173. <include refid="sceneColumns"/>
  174. FROM sms_scene a
  175. <include refid="deviceJoins"/>
  176. <where>
  177. a.status=1 and a.parent_scene_id=0
  178. <if test="scene.companyOrgId!=null">
  179. and a.COMPANY_ORG_ID = #{scene.companyOrgId}
  180. </if>
  181. <if test="scene.deptOrgId != null">
  182. and a.DEPT_ORG_ID = #{scene.deptOrgId}
  183. </if>
  184. <if test="scene.tenantId != null and scene.tenantId != ''">and a.tenant_id = #{scene.tenantId}</if>
  185. <if test="scene.parentSceneId != null ">and a.parent_scene_id = #{scene.parentSceneId}</if>
  186. <if test="scene.sceneName != null and scene.sceneName != ''">
  187. and a.scene_name LIKE concat('%',#{scene.sceneName},'%')
  188. </if>
  189. <if test="scene.sceneTypeId != null ">and a.scene_type_id = #{scene.sceneTypeId}</if>
  190. <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
  191. <if test="scene.permissonType == 5 or scene.permissonType == 2">
  192. and ( a.DEPT_ORG_ID in
  193. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  194. #{item.orgId}
  195. </foreach>
  196. or
  197. a.COMPANY_ORG_ID in
  198. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  199. #{item.orgId}
  200. </foreach>
  201. )
  202. </if>
  203. <if test="scene.permissonType == 4 or scene.permissonType == 3">
  204. and a.DEPT_ORG_ID in
  205. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  206. #{item.orgId}
  207. </foreach>
  208. </if>
  209. <if test="scene.permissonType == 1">
  210. and a.COMPANY_ORG_ID in
  211. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  212. #{item.orgId}
  213. </foreach>
  214. and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
  215. </if>
  216. </if>
  217. </where>
  218. order by a.date_create desc
  219. </select>
  220. <!--一级场景查询-->
  221. <select id="selectByTypeName" resultType="com.huaxu.entity.SceneEntity">
  222. SELECT
  223. <include refid="sceneColumns"/>
  224. FROM sms_scene a
  225. <include refid="deviceJoins"/>
  226. <where>
  227. a.parent_scene_id=0 and a.status=1 and a.enable_state=1
  228. <if test="scene.sceneTypeName == null ">
  229. and (s.scene_type_name='水源' or s.scene_type_name='水厂')
  230. </if>
  231. <if test="scene.sceneTypeName != null ">
  232. and s.scene_type_name=#{scene.sceneTypeName}
  233. </if>
  234. <if test="scene.companyOrgId != null ">and a.COMPANY_ORG_ID=#{scene.companyOrgId}</if>
  235. <if test="scene.tenantId != null and scene.tenantId != ''">and a.tenant_id = #{scene.tenantId}</if>
  236. <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
  237. <if test="scene.permissonType == 5 or scene.permissonType == 2">
  238. and ( a.DEPT_ORG_ID in
  239. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  240. #{item.orgId}
  241. </foreach>
  242. or
  243. a.COMPANY_ORG_ID in
  244. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  245. #{item.orgId}
  246. </foreach>
  247. )
  248. </if>
  249. <if test="scene.permissonType == 4 or scene.permissonType == 3">
  250. and a.DEPT_ORG_ID in
  251. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  252. #{item.orgId}
  253. </foreach>
  254. </if>
  255. <if test="scene.permissonType == 1">
  256. and a.COMPANY_ORG_ID in
  257. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  258. #{item.orgId}
  259. </foreach>
  260. and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
  261. </if>
  262. </if>
  263. </where>
  264. order by a.date_create
  265. </select>
  266. <!--根据一级场景查询所有场景信息-->
  267. <select id="findByParentId" resultType="com.huaxu.entity.SceneEntity">
  268. SELECT
  269. <include refid="sceneColumns"/>
  270. FROM sms_scene a
  271. <include refid="deviceJoins"/>
  272. <where>
  273. a.status=1
  274. <if test="scene.parentSceneIds != null ">and a.parent_scene_ids LIKE #{scene.parentSceneIds}</if>
  275. <if test="scene.tenantId != null and scene.tenantId != ''">and a.tenant_id = #{scene.tenantId}</if>
  276. <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
  277. <if test="scene.permissonType == 5 or scene.permissonType == 2">
  278. and ( a.DEPT_ORG_ID in
  279. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  280. #{item.orgId}
  281. </foreach>
  282. or
  283. a.COMPANY_ORG_ID in
  284. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  285. #{item.orgId}
  286. </foreach>
  287. )
  288. </if>
  289. <if test="scene.permissonType == 4 or scene.permissonType == 3">
  290. and a.DEPT_ORG_ID in
  291. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  292. #{item.orgId}
  293. </foreach>
  294. </if>
  295. <if test="scene.permissonType == 1">
  296. and a.COMPANY_ORG_ID in
  297. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  298. #{item.orgId}
  299. </foreach>
  300. and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
  301. </if>
  302. </if>
  303. </where>
  304. order by a.date_create
  305. </select>
  306. <!--根据场景id查询一级场景信息-->
  307. <select id="findParentSceneById" resultType="com.huaxu.entity.SceneEntity">
  308. select t1.scene_name as "sceneName",t2.id as "parentSceneId",t2.scene_name as "parentSceneName"
  309. from sms_scene t1
  310. left join sms_scene t2 on substring_index(substring_index(t1.parent_scene_ids, ',', 2), ',', -1)=t2.id
  311. where t1.id=#{id}
  312. </select>
  313. <!--根据用户权限统计一级场景个数-->
  314. <select id="findSceneAmount" resultType="map">
  315. select a.sceneTypeName,amount,newAmount from
  316. (
  317. select count(a.ID) amount,b.SCENE_TYPE_NAME sceneTypeName
  318. from sms_scene a INNER JOIN sms_scene_type b on a.SCENE_TYPE_ID=b.ID
  319. <where>
  320. a.PARENT_SCENE_ID=0
  321. and a.STATUS=1
  322. <if test="scene.tenantId != null and scene.tenantId != ''">
  323. and a.tenant_id = #{scene.tenantId}
  324. </if>
  325. <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
  326. <if test="scene.permissonType == 5 or scene.permissonType == 2">
  327. and ( a.DEPT_ORG_ID in
  328. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  329. #{item.orgId}
  330. </foreach>
  331. or
  332. a.COMPANY_ORG_ID in
  333. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  334. #{item.orgId}
  335. </foreach>
  336. )
  337. </if>
  338. <if test="scene.permissonType == 4 or scene.permissonType == 3">
  339. and a.DEPT_ORG_ID in
  340. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  341. #{item.orgId}
  342. </foreach>
  343. </if>
  344. <if test="scene.permissonType == 1">
  345. and a.COMPANY_ORG_ID in
  346. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  347. #{item.orgId}
  348. </foreach>
  349. and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
  350. </if>
  351. </if>
  352. and SCENE_TYPE_NAME in('水源','水厂','泵站')
  353. </where>
  354. group by b.SCENE_TYPE_NAME
  355. ) a left join
  356. (
  357. select count(a.ID) newAmount,b.SCENE_TYPE_NAME sceneTypeName
  358. from sms_scene a INNER JOIN sms_scene_type b on a.SCENE_TYPE_ID=b.ID
  359. <where>
  360. a.PARENT_SCENE_ID=0
  361. and a.STATUS=1
  362. <if test="months != null">
  363. and a.run_time>=date_sub(date_format(curdate(), '%y-%m-1' ), interval #{months}-1 month)
  364. </if>
  365. <if test="scene.tenantId != null and scene.tenantId != ''">
  366. and a.tenant_id = #{scene.tenantId}
  367. </if>
  368. <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
  369. <if test="scene.permissonType == 5 or scene.permissonType == 2">
  370. and ( a.DEPT_ORG_ID in
  371. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  372. #{item.orgId}
  373. </foreach>
  374. or
  375. a.COMPANY_ORG_ID in
  376. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  377. #{item.orgId}
  378. </foreach>
  379. )
  380. </if>
  381. <if test="scene.permissonType == 4 or scene.permissonType == 3">
  382. and a.DEPT_ORG_ID in
  383. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  384. #{item.orgId}
  385. </foreach>
  386. </if>
  387. <if test="scene.permissonType == 1">
  388. and a.COMPANY_ORG_ID in
  389. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  390. #{item.orgId}
  391. </foreach>
  392. and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
  393. </if>
  394. </if>
  395. and SCENE_TYPE_NAME in('水源','水厂','泵站')
  396. </where>
  397. group by b.SCENE_TYPE_NAME
  398. ) b
  399. on a.sceneTypeName = b.sceneTypeName
  400. union all
  401. select '户表' , ifnull(sum(user_meter_count),0) amount,sum(user_meter_add_count) newAmount
  402. from sms_month_revenue a
  403. <where>
  404. <if test="months != null">
  405. and a.collect_date>=date_sub(date_format(curdate(), '%y-%m-1' ), interval #{months}-1 month)
  406. </if>
  407. <if test="scene.tenantId != null and scene.tenantId != ''">
  408. and a.tenant_id = #{scene.tenantId}
  409. </if>
  410. <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
  411. <if test="scene.permissonType == 5 or scene.permissonType == 2">
  412. and a.COMPANY_ORG_ID in
  413. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  414. #{item.orgId}
  415. </foreach>
  416. </if>
  417. <if test="scene.permissonType == 1">
  418. and a.COMPANY_ORG_ID in
  419. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  420. #{item.orgId}
  421. </foreach>
  422. </if>
  423. </if>
  424. </where>
  425. </select>
  426. <!--报警场景及报警设备查询-->
  427. <select id="selectAlarmSceneAndDevice" resultType="map">
  428. select amount, id, scene_id, name, sort from(
  429. select count(1) amount, a.id,a.id scene_id, a.SCENE_NAME name,2 sort
  430. from sms_scene a INNER JOIN sms_scene_type b on a.SCENE_TYPE_ID=b.ID
  431. INNER JOIN sms_alarm_details c on c.PARENT_SCENE_ID=a.ID
  432. <where>
  433. a.PARENT_SCENE_ID=0 and a.STATUS=1
  434. <if test="scene.tenantId != null and scene.tenantId != ''">
  435. and a.tenant_id = #{scene.tenantId}
  436. </if>
  437. <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
  438. <if test="scene.permissonType == 5 or scene.permissonType == 2">
  439. and ( a.DEPT_ORG_ID in
  440. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  441. #{item.orgId}
  442. </foreach>
  443. or
  444. a.COMPANY_ORG_ID in
  445. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  446. #{item.orgId}
  447. </foreach>
  448. )
  449. </if>
  450. <if test="scene.permissonType == 4 or scene.permissonType == 3">
  451. and a.DEPT_ORG_ID in
  452. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  453. #{item.orgId}
  454. </foreach>
  455. </if>
  456. <if test="scene.permissonType == 1">
  457. and a.COMPANY_ORG_ID in
  458. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  459. #{item.orgId}
  460. </foreach>
  461. and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
  462. </if>
  463. </if>
  464. and c.alarm_start_time &gt;= date_format(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d')
  465. and c.alarm_start_time &lt; date_format(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d')
  466. and SCENE_TYPE_NAME in('水源','水厂','泵站')
  467. </where>
  468. group by a.scene_name, a.id, sort
  469. union all
  470. select count(*) amount, id, GROUP_CONCAT(DISTINCT scene_id SEPARATOR ',') scene_id, name,1 sort from
  471. (
  472. select d.id,c.PARENT_SCENE_ID scene_id, d.device_name name
  473. from sms_alarm_details c
  474. INNER JOIN sms_device d on c.DEVICE_ID=d.ID
  475. INNER JOIN sms_scene a on c.PARENT_SCENE_ID=a.ID
  476. INNER JOIN sms_scene_type b on a.SCENE_TYPE_ID=b.ID
  477. <where>
  478. a.PARENT_SCENE_ID=0 and a.STATUS=1
  479. <if test="scene.tenantId != null and scene.tenantId != ''">
  480. and a.tenant_id = #{scene.tenantId}
  481. </if>
  482. <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
  483. <if test="scene.permissonType == 5 or scene.permissonType == 2">
  484. and ( a.DEPT_ORG_ID in
  485. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  486. #{item.orgId}
  487. </foreach>
  488. or
  489. a.COMPANY_ORG_ID in
  490. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  491. #{item.orgId}
  492. </foreach>
  493. )
  494. </if>
  495. <if test="scene.permissonType == 4 or scene.permissonType == 3">
  496. and a.DEPT_ORG_ID in
  497. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  498. #{item.orgId}
  499. </foreach>
  500. </if>
  501. <if test="scene.permissonType == 1">
  502. and a.COMPANY_ORG_ID in
  503. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  504. #{item.orgId}
  505. </foreach>
  506. and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
  507. </if>
  508. </if>
  509. and c.alarm_start_time &gt;= date_format(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d')
  510. and c.alarm_start_time &lt; date_format(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d')
  511. and SCENE_TYPE_NAME='管网'
  512. </where>
  513. ) t1
  514. group by name, id, scene_id, sort ) t
  515. order by amount desc
  516. </select>
  517. <select id="selectMonthAlarmTimes" resultType="map">
  518. select count(1) 数量, DATE_FORMAT(c.DATE_CREATE,'%Y-%m-%d') 日期
  519. <if test="sort == 2">
  520. from sms_scene a INNER JOIN sms_scene_type b on a.SCENE_TYPE_ID=b.ID
  521. INNER JOIN sms_alarm_details c on c.PARENT_SCENE_ID=a.ID
  522. where a.ID = #{scene.id}
  523. </if>
  524. <if test="sort == 1">
  525. from sms_scene a inner join sms_scene_type b on a.SCENE_TYPE_ID=b.ID
  526. INNER JOIN sms_alarm_details c on c.PARENT_SCENE_ID=a.ID
  527. where a.PARENT_SCENE_ID=0 and a.STATUS=1
  528. and c.device_id = #{scene.id}
  529. and b.SCENE_TYPE_NAME='管网'
  530. <if test="scene.tenantId != null and scene.tenantId != ''">
  531. and a.tenant_id = #{scene.tenantId}
  532. </if>
  533. <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
  534. <if test="scene.permissonType == 5 or scene.permissonType == 2">
  535. and ( a.DEPT_ORG_ID in
  536. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  537. #{item.orgId}
  538. </foreach>
  539. or
  540. a.COMPANY_ORG_ID in
  541. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  542. #{item.orgId}
  543. </foreach>
  544. )
  545. </if>
  546. <if test="scene.permissonType == 4 or scene.permissonType == 3">
  547. and a.DEPT_ORG_ID in
  548. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  549. #{item.orgId}
  550. </foreach>
  551. </if>
  552. <if test="scene.permissonType == 1">
  553. and a.COMPANY_ORG_ID in
  554. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  555. #{item.orgId}
  556. </foreach>
  557. and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
  558. </if>
  559. </if>
  560. </if>
  561. and c.alarm_start_time &gt;= date_format(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d')
  562. and c.alarm_start_time &lt; date_format(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d')
  563. group by DATE_FORMAT(c.DATE_CREATE,'%Y-%m-%d')
  564. </select>
  565. <select id="selectYearAlarmTimes" resultType="map">
  566. select count(1) 数量, DATE_FORMAT(c.DATE_CREATE,'%Y-%m') 日期
  567. <if test="sort == 2">
  568. from sms_scene a INNER JOIN sms_scene_type b on a.SCENE_TYPE_ID=b.ID
  569. INNER JOIN sms_alarm_details c on c.PARENT_SCENE_ID=a.ID
  570. where a.ID = #{scene.id}
  571. </if>
  572. <if test="sort == 1">
  573. from sms_scene a inner join sms_scene_type b on a.SCENE_TYPE_ID=b.ID
  574. INNER JOIN sms_alarm_details c on c.PARENT_SCENE_ID=a.ID
  575. where a.PARENT_SCENE_ID=0 and a.STATUS=1
  576. and c.device_id = #{scene.id}
  577. and b.SCENE_TYPE_NAME='管网'
  578. <if test="scene.tenantId != null and scene.tenantId != ''">
  579. and a.tenant_id = #{scene.tenantId}
  580. </if>
  581. <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
  582. <if test="scene.permissonType == 5 or scene.permissonType == 2">
  583. and ( a.DEPT_ORG_ID in
  584. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  585. #{item.orgId}
  586. </foreach>
  587. or
  588. a.COMPANY_ORG_ID in
  589. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  590. #{item.orgId}
  591. </foreach>
  592. )
  593. </if>
  594. <if test="scene.permissonType == 4 or scene.permissonType == 3">
  595. and a.DEPT_ORG_ID in
  596. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  597. #{item.orgId}
  598. </foreach>
  599. </if>
  600. <if test="scene.permissonType == 1">
  601. and a.COMPANY_ORG_ID in
  602. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  603. #{item.orgId}
  604. </foreach>
  605. and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
  606. </if>
  607. </if>
  608. </if>
  609. and c.date_create &gt;= date_format(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d')
  610. and c.date_create &lt; date_format(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d')
  611. group by DATE_FORMAT(c.DATE_CREATE,'%Y-%m')
  612. </select>
  613. <select id="selectAlarmLable" resultType="map">
  614. select amount 数量, label 标签 from
  615. (
  616. select count(1) amount, concat(label,op) label from
  617. (
  618. select if(d.REMARK is null,e.NAME,d.REMARK) label,CASE WHEN ALARM_CONDITION='&gt;' OR ALARM_CONDITION='&gt;=' then '高'
  619. WHEN ALARM_CONDITION='&lt;' OR ALARM_CONDITION='&lt;=' then '低'
  620. ELSE '' END op
  621. <if test="sort == 2">
  622. from sms_scene a INNER JOIN sms_scene_type b on a.SCENE_TYPE_ID=b.ID
  623. INNER JOIN sms_alarm_details c on c.PARENT_SCENE_ID=a.ID
  624. INNER JOIN sms_device_attribute e on e.ID = c.ATTRIBUTE_ID and e.STATUS=1
  625. LEFT JOIN sms_device_parm d on d.ATTRIBUTE_ID = c.ATTRIBUTE_ID and d.DEVICE_ID=c.DEVICE_ID and d.TENANT_ID=c.TENANT_ID and d.PARENT_SCENE_ID=c.PARENT_SCENE_ID and d.STATUS=1
  626. INNER JOIN sms_alarm_setting f on f.device_id = c.device_id and f.SCENE_ID=c.SCENE_ID and f.ATTRIBUTE_ID=c.ATTRIBUTE_ID and f.STATUS=1
  627. where a.ID = #{scene.id}
  628. </if>
  629. <if test="sort == 1">
  630. from sms_alarm_details c
  631. INNER JOIN sms_device_attribute e on e.ID = c.ATTRIBUTE_ID and e.STATUS=1
  632. LEFT JOIN sms_device_parm d on d.ATTRIBUTE_ID = c.ATTRIBUTE_ID and d.DEVICE_ID=c.DEVICE_ID and d.TENANT_ID=c.TENANT_ID and d.PARENT_SCENE_ID=c.PARENT_SCENE_ID and d.STATUS=1
  633. INNER JOIN sms_alarm_setting f on f.device_id = c.device_id and f.SCENE_ID=c.SCENE_ID and f.ATTRIBUTE_ID=c.ATTRIBUTE_ID and f.STATUS=1
  634. where c.device_id = #{scene.id}
  635. </if>
  636. and c.date_create &gt;= date_format(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d')
  637. and c.date_create &lt; date_format(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d')
  638. ) t1
  639. group by concat(label,op)
  640. union all
  641. select count(1) amount, label from
  642. (
  643. select '离线' label
  644. <if test="sort == 2">
  645. from sms_scene a INNER JOIN sms_scene_type b on a.SCENE_TYPE_ID=b.ID
  646. INNER JOIN sms_alarm_details c on c.PARENT_SCENE_ID=a.ID
  647. where a.ID = #{scene.id} and alarm_type='状态报警'
  648. </if>
  649. <if test="sort == 1">
  650. from sms_alarm_details c
  651. where c.device_id = #{scene.id} and alarm_type='状态报警'
  652. </if>
  653. and c.alarm_start_time &gt;= date_format(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d')
  654. and c.alarm_start_time &lt; date_format(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d')
  655. ) t1
  656. group by label
  657. ) t2
  658. order by amount desc
  659. </select>
  660. <select id="selectAlarmDeviceIdBySenceId" resultType="map">
  661. select DISTINCT c.device_id from sms_scene a INNER JOIN sms_scene_type b on a.SCENE_TYPE_ID=b.ID
  662. INNER JOIN sms_alarm_details c on c.PARENT_SCENE_ID=a.ID
  663. where a.ID = #{id}
  664. </select>
  665. </mapper>