HomePageReportMapper.xml 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  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) as amount
  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. <if test="item.orgId != null">
  334. #{item.orgId}
  335. </if>
  336. </foreach>
  337. or
  338. s.COMPANY_ORG_ID in
  339. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  340. <if test="item.orgId != null">
  341. #{item.orgId}
  342. </if>
  343. </foreach>
  344. )
  345. </if>
  346. <if test="permissonType == 4 or permissonType == 3">
  347. and s.DEPT_ORG_ID in
  348. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  349. <if test="item.orgId != null">
  350. #{item.orgId}
  351. </if>
  352. </foreach>
  353. </if>
  354. <if test="permissonType == 1">
  355. and s.COMPANY_ORG_ID in
  356. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  357. <if test="item.orgId != null">
  358. #{item.orgId}
  359. </if>
  360. </foreach>
  361. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  362. </if>
  363. </if>
  364. group by s.id,d.id,dp.ATTRIBUTE_ID
  365. ) a
  366. </select>
  367. <select id="getWaterSupplyData" resultType="com.huaxu.dto.generalView.WaterSupplyData">
  368. select
  369. r.year
  370. ,r.month
  371. ,r.day
  372. ,dp.PARM_TYPE as "parmType"
  373. ,sum(r.SUM_VALUE) as "amount"
  374. ,da.UNIT as "unit"
  375. from sms_scene_type st
  376. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  377. left join sms_device_parm dp on s.id=dp.PARENT_SCENE_ID
  378. left join sms_device_attribute da on dp.ATTRIBUTE_ID =da.ID
  379. left join sms_month_report r on r.DEVICE_ID =dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID
  380. where dp.`STATUS`=1 and st.`STATUS`=1 and s.`STATUS`=1 and s.ENABLE_STATE = 1
  381. and r.COLLECT_DATE >= date_add(curdate(), interval - day(curdate()) + 1 day)
  382. and dp.PARM_TYPE in (3,4,5,6,12)
  383. and s.id= #{sceneId}
  384. and st.SCENE_TYPE_NAME = #{sceneType}
  385. and dp.TENANT_ID=#{tenantId}
  386. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  387. <if test="permissonType == 5 or permissonType == 2">
  388. and ( s.DEPT_ORG_ID in
  389. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  390. #{item.orgId}
  391. </foreach>
  392. or
  393. s.COMPANY_ORG_ID in
  394. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  395. #{item.orgId}
  396. </foreach>
  397. )
  398. </if>
  399. <if test="permissonType == 4 or permissonType == 3">
  400. and s.DEPT_ORG_ID in
  401. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  402. #{item.orgId}
  403. </foreach>
  404. </if>
  405. <if test="permissonType == 1">
  406. and s.COMPANY_ORG_ID in
  407. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  408. #{item.orgId}
  409. </foreach>
  410. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  411. </if>
  412. </if>
  413. group by r.year,r.month,r.day,dp.PARM_TYPE,da.UNIT
  414. </select>
  415. <!--查询前N个月的取水量供水量-->
  416. <select id="getDeviceWaterForMonth" resultType="com.huaxu.dto.generalView.DeviceWaterSupply">
  417. select
  418. r.year,r.month,
  419. sum(r.SUM_VALUE)/10000 as "amount"
  420. from sms_scene_type st
  421. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  422. left join sms_device_parm dp on s.id=dp.PARENT_SCENE_ID
  423. left join sms_year_report r on r.DEVICE_ID= dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID
  424. where dp.`STATUS`=1 and s.ENABLE_STATE = 1 and dp.TENANT_ID=#{tenantId}
  425. <if test="companyOrgId != null">
  426. and s.COMPANY_ORG_ID = #{companyOrgId}
  427. </if>
  428. and dp.PARM_TYPE = #{parmType} and st.SCENE_TYPE_NAME = #{sceneType}
  429. and r.year*12 + r.month >= year(CURDATE())*12 + month(CURDATE()) + 1 - #{month}
  430. and r.year*12 + r.month &lt; year(CURDATE())*12 + month(CURDATE()) + 1
  431. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  432. <if test="permissonType == 5 or permissonType == 2">
  433. and ( s.DEPT_ORG_ID in
  434. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  435. #{item.orgId}
  436. </foreach>
  437. or
  438. s.COMPANY_ORG_ID in
  439. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  440. #{item.orgId}
  441. </foreach>
  442. )
  443. </if>
  444. <if test="permissonType == 4 or permissonType == 3">
  445. and s.DEPT_ORG_ID in
  446. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  447. #{item.orgId}
  448. </foreach>
  449. </if>
  450. <if test="permissonType == 1">
  451. and s.COMPANY_ORG_ID in
  452. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  453. #{item.orgId}
  454. </foreach>
  455. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  456. </if>
  457. </if>
  458. group by r.year,r.month
  459. order by r.year desc,r.month desc
  460. </select>
  461. <!--查询时间段内的取水量供水量-->
  462. <select id="getDeviceWaterForMonth" resultType="com.huaxu.dto.generalView.DeviceWaterSupply">
  463. select
  464. r.year,r.month,r.day,
  465. sum(r.SUM_VALUE)/10000 as "amount"
  466. from sms_scene_type st
  467. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  468. left join sms_device_parm dp on s.id=dp.PARENT_SCENE_ID
  469. left join sms_year_report r on r.DEVICE_ID= dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID
  470. where dp.`STATUS`=1 and s.ENABLE_STATE = 1 and dp.TENANT_ID=#{tenantId}
  471. <if test="companyOrgId != null">
  472. and s.COMPANY_ORG_ID = #{companyOrgId}
  473. </if>
  474. and dp.PARM_TYPE = #{parmType} and st.SCENE_TYPE_NAME = #{sceneType}
  475. and r.year*12 + r.month >= #{startYear}*12 + #{startMonth}
  476. and r.year*12 + r.month &lt;= #{endYear}*12 + #{endMonth}
  477. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  478. <if test="permissonType == 5 or permissonType == 2">
  479. and ( s.DEPT_ORG_ID in
  480. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  481. #{item.orgId}
  482. </foreach>
  483. or
  484. s.COMPANY_ORG_ID in
  485. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  486. #{item.orgId}
  487. </foreach>
  488. )
  489. </if>
  490. <if test="permissonType == 4 or permissonType == 3">
  491. and s.DEPT_ORG_ID in
  492. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  493. #{item.orgId}
  494. </foreach>
  495. </if>
  496. <if test="permissonType == 1">
  497. and s.COMPANY_ORG_ID in
  498. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  499. #{item.orgId}
  500. </foreach>
  501. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  502. </if>
  503. </if>
  504. group by r.year,r.month,r.day
  505. order by r.year desc,r.month desc,r.day desc
  506. </select>
  507. </mapper>