HomePageReportMapper.xml 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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.HomePageReportMapper">
  4. <select id="getDeviceWaterForSixMonth" resultType="com.huaxu.dto.generalView.DeviceWaterSupply">
  5. select
  6. r.year,r.month,
  7. sum(r.SUM_VALUE)/10000 as "amount"
  8. from sms_scene_type st
  9. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  10. left join sms_device_parm dp on s.id=dp.PARENT_SCENE_ID
  11. left join sms_year_report r on r.DEVICE_ID= dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID
  12. where dp.`STATUS`=1 and s.ENABLE_STATE = 1 and dp.TENANT_ID=#{tenantId}
  13. <if test="companyOrgId != null">
  14. and s.COMPANY_ORG_ID = #{companyOrgId}
  15. </if>
  16. and dp.PARM_TYPE = #{parmType} and st.SCENE_TYPE_NAME = #{sceneType}
  17. and r.year*12 + r.month >= year(CURDATE())*12 + month(CURDATE()) - 5
  18. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  19. <if test="permissonType == 5 or permissonType == 2">
  20. and ( s.DEPT_ORG_ID in
  21. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  22. #{item.orgId}
  23. </foreach>
  24. or
  25. s.COMPANY_ORG_ID in
  26. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  27. #{item.orgId}
  28. </foreach>
  29. )
  30. </if>
  31. <if test="permissonType == 4 or permissonType == 3">
  32. and s.DEPT_ORG_ID in
  33. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  34. #{item.orgId}
  35. </foreach>
  36. </if>
  37. <if test="permissonType == 1">
  38. and s.COMPANY_ORG_ID in
  39. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  40. #{item.orgId}
  41. </foreach>
  42. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  43. </if>
  44. </if>
  45. group by r.year,r.month
  46. order by r.year desc,r.month desc
  47. </select>
  48. <select id="countSceneByType" resultType="com.huaxu.dto.homePage.CompanyCount">
  49. select
  50. sum(if(SCENE_TYPE_NAME = "水源",1,0)) as "waterSource"
  51. ,sum(if(SCENE_TYPE_NAME = "水厂",1,0)) as "waterFactory"
  52. ,sum(if(SCENE_TYPE_NAME = "管网",1,0)) as "pipeNetwork"
  53. ,sum(if(SCENE_TYPE_NAME = "泵站",1,0)) as "pumpingStation"
  54. ,0 as "waterMeter"
  55. from sms_scene s
  56. left join sms_scene_type st on s.SCENE_TYPE_ID =st.ID
  57. where s.PARENT_SCENE_ID= 0 and s.`STATUS` = 1 and st.`STATUS` = 1
  58. and st.SCENE_TYPE_NAME in ('水源','水厂','管网','泵站')
  59. <if test="companyOrgId != null">
  60. and s.COMPANY_ORG_ID = #{companyOrgId}
  61. </if>
  62. and s.TENANT_ID=#{tenantId}
  63. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  64. <if test="permissonType == 5 or permissonType == 2">
  65. and ( s.DEPT_ORG_ID in
  66. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  67. #{item.orgId}
  68. </foreach>
  69. or
  70. s.COMPANY_ORG_ID in
  71. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  72. #{item.orgId}
  73. </foreach>
  74. )
  75. </if>
  76. <if test="permissonType == 4 or permissonType == 3">
  77. and s.DEPT_ORG_ID in
  78. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  79. #{item.orgId}
  80. </foreach>
  81. </if>
  82. <if test="permissonType == 1">
  83. and s.COMPANY_ORG_ID in
  84. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  85. #{item.orgId}
  86. </foreach>
  87. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  88. </if>
  89. </if>
  90. </select>
  91. <select id="getWaterSalesDetails" resultType="com.huaxu.dto.homePage.CompanyProduce">
  92. select
  93. sum(RECEIVABLE_TOTAL_AMOUNT) AS "receivableAmount",
  94. sum(RECEIVED_TOTAL_AMOUNT) AS "receivedAmount",
  95. sum(METER_READING_USAGE) AS "waterSale"
  96. from sms_month_revenue r
  97. where r.TENANT_ID = #{tenantId}
  98. <if test="companyOrgId != null">
  99. and r.COMPANY_ORG_ID = #{companyOrgId}
  100. </if>
  101. and year(r.COLLECT_DATE) =year(CURDATE()) and month(r.COLLECT_DATE) = month(CURDATE())
  102. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  103. and r.COMPANY_ORG_ID in
  104. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  105. #{item.orgId}
  106. </foreach>
  107. </if>
  108. </select>
  109. <select id="getPipeNetworkQualification" resultType="com.huaxu.dto.homePage.WaterQualityRate">
  110. select
  111. sum(alarmNumber ) as "abnormal",
  112. ROUND(sum(if(alarmNumber > 0 ,0,1))/if(count(1) != 0, count(1),1) * 100,2) as "averageQuality"
  113. from
  114. (
  115. select
  116. s.id as "sceneId"
  117. ,dp.DEVICE_ID as "deviceId"
  118. ,count(ad.id) as "alarmNumber"
  119. from sms_scene_type pst
  120. left join sms_scene ps on ps.SCENE_TYPE_ID =pst.ID
  121. left join sms_scene s on s.PARENT_SCENE_ID =ps.ID
  122. left join sms_scene_type st on s.SCENE_TYPE_ID =st.ID
  123. left join sms_device_parm dp on dp.PARENT_SCENE_ID =ps.ID and dp.SCENE_ID =s.ID
  124. left join sms_alarm_details ad on dp.SCENE_ID =ad.SCENE_ID and dp.DEVICE_ID =ad.DEVICE_ID and dp.attribute_id = ad.attribute_id
  125. and ad.STATE = 1 and ad.`STATUS` =1 and ad.ALARM_TYPE = '参数报警'
  126. where pst.`STATUS` = 1 and st.`STATUS` = 1 and ps.`STATUS` = 1 and s.`STATUS` = 1 and dp.`STATUS` = 1
  127. and pst.SCENE_TYPE_NAME ='管网' and st.SCENE_TYPE_NAME ='水质'
  128. <if test="companyOrgId != null">
  129. and ps.COMPANY_ORG_ID = #{companyOrgId}
  130. </if>
  131. and ps.TENANT_ID=#{tenantId}
  132. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  133. <if test="permissonType == 5 or permissonType == 2">
  134. and ( s.DEPT_ORG_ID in
  135. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  136. #{item.orgId}
  137. </foreach>
  138. or
  139. s.COMPANY_ORG_ID in
  140. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  141. #{item.orgId}
  142. </foreach>
  143. )
  144. </if>
  145. <if test="permissonType == 4 or permissonType == 3">
  146. and s.DEPT_ORG_ID in
  147. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  148. #{item.orgId}
  149. </foreach>
  150. </if>
  151. <if test="permissonType == 1">
  152. and s.COMPANY_ORG_ID in
  153. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  154. #{item.orgId}
  155. </foreach>
  156. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  157. </if>
  158. </if>
  159. group by s.id,dp.DEVICE_ID
  160. ) a
  161. </select>
  162. <select id="getWaterQualification" resultType="com.huaxu.dto.homePage.WaterQualityRate">
  163. select
  164. sum(alarmNumber ) as "abnormal",
  165. ROUND(sum(if(alarmNumber > 0 ,0,1))/if(count(1) != 0, count(1),1) * 100,2) as "averageQuality"
  166. from (
  167. select
  168. s.id as "sceneId"
  169. ,sum( if(dp.PARM_TYPE IN
  170. <foreach collection="parmTypes" item="item" open="(" close=")" separator=",">
  171. #{item}
  172. </foreach>
  173. and ad.id is not null,1,0) ) AS "alarmNumber"
  174. from sms_scene_type st
  175. left join sms_scene s on s.SCENE_TYPE_ID =st.id and PARENT_SCENE_ID ='0'
  176. left join sms_device_parm dp on dp.PARENT_SCENE_ID =s.ID
  177. left join sms_alarm_details ad on ad.STATE = 1 and ad.PARENT_SCENE_ID=dp.PARENT_SCENE_ID and ad.DEVICE_ID =dp.DEVICE_ID and ad.ATTRIBUTE_ID =dp.ATTRIBUTE_ID
  178. where s.`STATUS`=1 and s.ENABLE_STATE = 1 and dp.`STATUS` = 1 and st.SCENE_TYPE_NAME = #{sceneType}
  179. <if test="companyOrgId != null">
  180. and s.COMPANY_ORG_ID = #{companyOrgId}
  181. </if>
  182. and s.TENANT_ID =#{tenantId}
  183. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  184. <if test="permissonType == 5 or permissonType == 2">
  185. and ( s.DEPT_ORG_ID in
  186. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  187. #{item.orgId}
  188. </foreach>
  189. or
  190. s.COMPANY_ORG_ID in
  191. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  192. #{item.orgId}
  193. </foreach>
  194. )
  195. </if>
  196. <if test="permissonType == 4 or permissonType == 3">
  197. and s.DEPT_ORG_ID in
  198. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  199. #{item.orgId}
  200. </foreach>
  201. </if>
  202. <if test="permissonType == 1">
  203. and s.COMPANY_ORG_ID in
  204. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  205. #{item.orgId}
  206. </foreach>
  207. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  208. </if>
  209. </if>
  210. group by s.id
  211. ) a
  212. </select>
  213. <select id="getMonitorDataFifteenDays" resultType="com.huaxu.dto.generalView.DeviceWaterSupply">
  214. select
  215. r.year,r.month,r.day,
  216. sum(r.SUM_VALUE) as "amount"
  217. from sms_scene_type st
  218. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  219. left join sms_device_parm dp on s.id=dp.PARENT_SCENE_ID
  220. left join sms_month_report r on r.DEVICE_ID= dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID
  221. where st.`STATUS`=1 and dp.`STATUS`=1 and s.ENABLE_STATE = 1
  222. and s.id = #{sceneId}
  223. and st.SCENE_TYPE_NAME = #{sceneType}
  224. and dp.PARM_TYPE = #{parmType}
  225. and dp.TENANT_ID=#{tenantId}
  226. and r.COLLECT_DATE >= DATE_SUB(CURDATE(),INTERVAL 14 day)
  227. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  228. <if test="permissonType == 5 or permissonType == 2">
  229. and ( s.DEPT_ORG_ID in
  230. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  231. #{item.orgId}
  232. </foreach>
  233. or
  234. s.COMPANY_ORG_ID in
  235. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  236. #{item.orgId}
  237. </foreach>
  238. )
  239. </if>
  240. <if test="permissonType == 4 or permissonType == 3">
  241. and s.DEPT_ORG_ID in
  242. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  243. #{item.orgId}
  244. </foreach>
  245. </if>
  246. <if test="permissonType == 1">
  247. and s.COMPANY_ORG_ID in
  248. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  249. #{item.orgId}
  250. </foreach>
  251. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  252. </if>
  253. </if>
  254. group by r.year,r.month,r.day
  255. order by r.year desc,r.month desc,r.day desc
  256. </select>
  257. <select id="getWaterQualificationForScene" resultType="java.math.BigDecimal">
  258. select
  259. ROUND(sum(if(alarmNumber > 0 ,0,1))/if(count(1) != 0, count(1),1) * 100,2)
  260. from
  261. (
  262. select
  263. s.id as "sceneId"
  264. ,d.id as "deviceId"
  265. ,count(ad.id) as "alarmNumber"
  266. from sms_scene_type st
  267. left join sms_scene s on s.SCENE_TYPE_ID =st.ID
  268. left join sms_device_scene ds on ds.PARENT_SCENE_ID = s.ID
  269. left join sms_device d on d.id=ds.DEVICE_ID
  270. left join sms_device_parm dp on dp.SCENE_ID =ds.SCENE_ID and dp.DEVICE_ID =ds.DEVICE_ID and dp.PARM_TYPE =#{parmType}
  271. left join sms_alarm_details ad on dp.SCENE_ID =ad.SCENE_ID and dp.DEVICE_ID =ad.DEVICE_ID and dp.ATTRIBUTE_ID =ad.ATTRIBUTE_ID
  272. and ad.STATE = 1 and ad.`STATUS` =1
  273. where st.`STATUS` = 1 and s.`STATUS` = 1 and ds.`STATUS` = 1 and d.`STATUS` = 1 and dp.`STATUS` = 1
  274. and s.id= #{sceneId}
  275. and st.SCENE_TYPE_NAME = #{sceneType}
  276. and s.TENANT_ID=#{tenantId}
  277. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  278. <if test="permissonType == 5 or permissonType == 2">
  279. and ( s.DEPT_ORG_ID in
  280. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  281. #{item.orgId}
  282. </foreach>
  283. or
  284. s.COMPANY_ORG_ID in
  285. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  286. #{item.orgId}
  287. </foreach>
  288. )
  289. </if>
  290. <if test="permissonType == 4 or permissonType == 3">
  291. and s.DEPT_ORG_ID in
  292. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  293. #{item.orgId}
  294. </foreach>
  295. </if>
  296. <if test="permissonType == 1">
  297. and s.COMPANY_ORG_ID in
  298. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  299. #{item.orgId}
  300. </foreach>
  301. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  302. </if>
  303. </if>
  304. group by s.id,d.id
  305. ) a
  306. </select>
  307. <select id="getWaterQualificationByMonth" resultType="java.math.BigDecimal">
  308. select
  309. ROUND(if(count(1) >0 ,1-((sum(alarmNumber) /count(1))/timestampdiff(MINUTE,#{monthDate},now())),1)* 100,2)
  310. from
  311. (
  312. select
  313. ifnull(sum(
  314. if(ad.state = 1,
  315. timestampdiff(MINUTE,if(ad.ALARM_START_TIME > #{monthDate},ad.ALARM_START_TIME ,#{monthDate}),now())
  316. ,if(ad.ALARM_START_TIME > #{monthDate} ,timestampdiff(MINUTE,ad.ALARM_START_TIME,ad.alarm_end_time), timestampdiff(MINUTE,#{monthDate},ad.alarm_end_time))
  317. )),0) alarmNumber
  318. from sms_scene_type st
  319. left join sms_scene s on s.SCENE_TYPE_ID =st.ID
  320. left join sms_device_scene ds on ds.PARENT_SCENE_ID = s.ID
  321. left join sms_device d on d.id=ds.DEVICE_ID
  322. left join sms_device_parm dp on dp.SCENE_ID =ds.SCENE_ID and dp.DEVICE_ID =ds.DEVICE_ID and dp.PARM_TYPE =#{parmType}
  323. left join sms_alarm_details ad on dp.SCENE_ID =ad.SCENE_ID and dp.DEVICE_ID =ad.DEVICE_ID and dp.ATTRIBUTE_ID =ad.ATTRIBUTE_ID
  324. and ad.`STATUS` =1 and (ad.alarm_end_time > #{monthDate} or ad.state = 1)
  325. where st.`STATUS` = 1 and s.`STATUS` = 1 and ds.`STATUS` = 1 and d.`STATUS` = 1 and dp.`STATUS` = 1
  326. and s.id= #{sceneId}
  327. and st.SCENE_TYPE_NAME = #{sceneType}
  328. and s.TENANT_ID=#{tenantId}
  329. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  330. <if test="permissonType == 5 or permissonType == 2">
  331. and ( s.DEPT_ORG_ID in
  332. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  333. #{item.orgId}
  334. </foreach>
  335. or
  336. s.COMPANY_ORG_ID in
  337. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  338. #{item.orgId}
  339. </foreach>
  340. )
  341. </if>
  342. <if test="permissonType == 4 or permissonType == 3">
  343. and s.DEPT_ORG_ID in
  344. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  345. #{item.orgId}
  346. </foreach>
  347. </if>
  348. <if test="permissonType == 1">
  349. and s.COMPANY_ORG_ID in
  350. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  351. #{item.orgId}
  352. </foreach>
  353. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  354. </if>
  355. </if>
  356. group by s.id,d.id,dp.ATTRIBUTE_ID
  357. ) a
  358. </select>
  359. <select id="getWaterSupplyData" resultType="com.huaxu.dto.generalView.WaterSupplyData">
  360. select
  361. r.year
  362. ,r.month
  363. ,r.day
  364. ,dp.PARM_TYPE as "parmType"
  365. ,sum(r.SUM_VALUE) as "amount"
  366. ,da.UNIT as "unit"
  367. from sms_scene_type st
  368. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  369. left join sms_device_parm dp on s.id=dp.PARENT_SCENE_ID
  370. left join sms_device_attribute da on dp.ATTRIBUTE_ID =da.ID
  371. left join sms_month_report r on r.DEVICE_ID =dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID
  372. where dp.`STATUS`=1 and st.`STATUS`=1 and s.`STATUS`=1 and s.ENABLE_STATE = 1
  373. and r.COLLECT_DATE >= date_add(curdate(), interval - day(curdate()) + 1 day)
  374. and dp.PARM_TYPE in (3,5,6)
  375. and s.id= #{sceneId}
  376. and st.SCENE_TYPE_NAME = #{sceneType}
  377. and dp.TENANT_ID=#{tenantId}
  378. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  379. <if test="permissonType == 5 or permissonType == 2">
  380. and ( s.DEPT_ORG_ID in
  381. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  382. #{item.orgId}
  383. </foreach>
  384. or
  385. s.COMPANY_ORG_ID in
  386. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  387. #{item.orgId}
  388. </foreach>
  389. )
  390. </if>
  391. <if test="permissonType == 4 or permissonType == 3">
  392. and s.DEPT_ORG_ID in
  393. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  394. #{item.orgId}
  395. </foreach>
  396. </if>
  397. <if test="permissonType == 1">
  398. and s.COMPANY_ORG_ID in
  399. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  400. #{item.orgId}
  401. </foreach>
  402. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  403. </if>
  404. </if>
  405. group by r.year,r.month,r.day,dp.PARM_TYPE,da.UNIT
  406. </select>
  407. <!--查询前N个月的取水量供水量-->
  408. <select id="getDeviceWaterForMonth" resultType="com.huaxu.dto.generalView.DeviceWaterSupply">
  409. select
  410. r.year,r.month,
  411. sum(r.SUM_VALUE)/10000 as "amount"
  412. from sms_scene_type st
  413. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  414. left join sms_device_parm dp on s.id=dp.PARENT_SCENE_ID
  415. left join sms_year_report r on r.DEVICE_ID= dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID
  416. where dp.`STATUS`=1 and s.ENABLE_STATE = 1 and dp.TENANT_ID=#{tenantId}
  417. <if test="companyOrgId != null">
  418. and s.COMPANY_ORG_ID = #{companyOrgId}
  419. </if>
  420. and dp.PARM_TYPE = #{parmType} and st.SCENE_TYPE_NAME = #{sceneType}
  421. and r.year*12 + r.month >= year(CURDATE())*12 + month(CURDATE()) + 1 - #{month}
  422. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  423. <if test="permissonType == 5 or permissonType == 2">
  424. and ( s.DEPT_ORG_ID in
  425. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  426. #{item.orgId}
  427. </foreach>
  428. or
  429. s.COMPANY_ORG_ID in
  430. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  431. #{item.orgId}
  432. </foreach>
  433. )
  434. </if>
  435. <if test="permissonType == 4 or permissonType == 3">
  436. and s.DEPT_ORG_ID in
  437. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  438. #{item.orgId}
  439. </foreach>
  440. </if>
  441. <if test="permissonType == 1">
  442. and s.COMPANY_ORG_ID in
  443. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  444. #{item.orgId}
  445. </foreach>
  446. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  447. </if>
  448. </if>
  449. group by r.year,r.month
  450. order by r.year desc,r.month desc
  451. </select>
  452. <!--查询时间段内的取水量供水量(精确到天)-->
  453. <select id="getDeviceWaterForDay" resultType="com.huaxu.dto.generalView.DeviceWaterSupply">
  454. select
  455. r.year,r.month,r.day,
  456. sum(r.SUM_VALUE)/10000 as "amount"
  457. from sms_scene_type st
  458. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  459. left join sms_device_parm dp on s.id=dp.PARENT_SCENE_ID
  460. left join sms_month_report r on r.DEVICE_ID= dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID
  461. where dp.`STATUS`=1 and s.ENABLE_STATE = 1 and dp.TENANT_ID=#{tenantId}
  462. <if test="companyOrgId != null">
  463. and s.COMPANY_ORG_ID = #{companyOrgId}
  464. </if>
  465. and dp.PARM_TYPE = #{parmType} and st.SCENE_TYPE_NAME = #{sceneType}
  466. and r.year*365 + r.month*30 +r.day >= #{startYear}*365 + #{startMonth} *30 + #{startDay}
  467. and r.year*365 + r.month*30 +r.day &lt;= #{endYear}*365 + #{endMonth} *30 + #{endDay}
  468. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  469. <if test="permissonType == 5 or permissonType == 2">
  470. and ( s.DEPT_ORG_ID in
  471. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  472. #{item.orgId}
  473. </foreach>
  474. or
  475. s.COMPANY_ORG_ID in
  476. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  477. #{item.orgId}
  478. </foreach>
  479. )
  480. </if>
  481. <if test="permissonType == 4 or permissonType == 3">
  482. and s.DEPT_ORG_ID in
  483. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  484. #{item.orgId}
  485. </foreach>
  486. </if>
  487. <if test="permissonType == 1">
  488. and s.COMPANY_ORG_ID in
  489. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  490. #{item.orgId}
  491. </foreach>
  492. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  493. </if>
  494. </if>
  495. group by r.year,r.month,r.day
  496. order by r.year desc,r.month desc,r.day desc
  497. </select>
  498. </mapper>