MonitorDataReportMapper.xml 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452
  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.MonitorDataReportMapper">
  4. <resultMap id="MonitorDataChartReportMap" type="com.huaxu.dto.MonitorDataChartReportDeviceDto">
  5. <result property="devoceCode" column="devoceCode" jdbcType="INTEGER"/>
  6. <result property="deviceName" column="deviceName" jdbcType="INTEGER"/>
  7. <collection property="attributeData" resultMap="AttributeData"/>
  8. </resultMap>
  9. <resultMap id="AttributeData" type="com.huaxu.dto.MonitorDataChartReportAttributeDto">
  10. <result property="attributeType" column="attributeType"/>
  11. <result property="attributeName" column="attributeName"/>
  12. <result property="unit" column="unit"/>
  13. <collection property="monitorDataChartReportValue" resultMap="MonitorDataChartReportValue"/>
  14. </resultMap>
  15. <resultMap id="MonitorDataChartReportValue" type="com.huaxu.dto.MonitorDataChartReportValueDto">
  16. <result property="dateLabel" column="dateLabel" />
  17. <result property="data" column="data"/>
  18. <result property="date" column="date"/>
  19. </resultMap>
  20. <sql id="MonitorDataReportJoins">
  21. left join sms_device_parm dp on dp.DEVICE_ID=r.DEVICE_ID and dp.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  22. left join sms_device_attribute da on da.id=r.ATTRIBUTE_ID
  23. left join sms_device d on d.id=r.DEVICE_ID
  24. </sql>
  25. <!-- 图表 -->
  26. <select id="MonitorDataChartReportByDay" resultMap="MonitorDataChartReportMap">
  27. SELECT
  28. r.`HOUR` AS "dateLabel",
  29. CONCAT( s.SCENE_NAME, r.DEVICE_NAME ) AS "deviceName",
  30. r.DEVICE_CODE AS "devoceCode",
  31. r.ATTRIBUTE_NAME AS "attributeName",
  32. da.unit AS "unit",
  33. ROUND( sum(r.AVG_VALUE), 2 ) AS "data",
  34. max(r.COLLECT_DATE) AS "date"
  35. FROM sms_device_parm p
  36. LEFT JOIN sms_day_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  37. LEFT JOIN sms_device_attribute da ON da.id = r.ATTRIBUTE_ID
  38. LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
  39. left join sms_scene s on s.id=p.PARENT_SCENE_ID
  40. where p.IS_CHART = 1 and p.`STATUS`= 1 and d.ENABLE_STATE = 1 and d.`STATUS`= 1
  41. and p.PARENT_SCENE_ID=#{sceneId}
  42. and r.year=#{year}
  43. and r.month=#{month}
  44. and r.day=#{day}
  45. <if test="tenantId != null and tenantId != '' ">
  46. and d.tenant_id = #{tenantId}
  47. </if>
  48. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  49. <if test="permissonType == 5 or permissonType == 2">
  50. and ( d.DEPT_ORG_ID in
  51. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  52. #{item.orgId}
  53. </foreach>
  54. or
  55. d.COMPANY_ORG_ID in
  56. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  57. #{item.orgId}
  58. </foreach>
  59. )
  60. </if>
  61. <if test="permissonType == 4 or permissonType == 3">
  62. and d.DEPT_ORG_ID in
  63. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  64. #{item.orgId}
  65. </foreach>
  66. </if>
  67. <if test="permissonType == 1">
  68. and d.COMPANY_ORG_ID in
  69. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  70. #{item.orgId}
  71. </foreach>
  72. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  73. </if>
  74. </if>
  75. group by r.hour ,s.SCENE_NAME,r.DEVICE_NAME,r.DEVICE_CODE,r.ATTRIBUTE_NAME,da.unit
  76. ORDER BY r.`HOUR` ASC
  77. </select>
  78. <select id="MonitorDataChartReportByMonth" resultMap="MonitorDataChartReportMap">
  79. SELECT
  80. r.`day` AS "dateLabel",
  81. CONCAT( s.SCENE_NAME, r.DEVICE_NAME ) AS "deviceName",
  82. r.DEVICE_CODE AS "devoceCode",
  83. r.ATTRIBUTE_NAME AS "attributeName",
  84. da.unit AS "unit",
  85. ROUND( sum(r.AVG_VALUE), 2 ) AS "data",
  86. max(r.COLLECT_DATE) AS "date"
  87. FROM sms_device_parm p
  88. LEFT JOIN sms_month_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  89. LEFT JOIN sms_device_attribute da ON da.id = r.ATTRIBUTE_ID
  90. LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
  91. left join sms_scene s on s.id=p.PARENT_SCENE_ID
  92. where p.IS_CHART = 1 and p.`STATUS`= 1 and d.ENABLE_STATE = 1 and d.`STATUS`= 1
  93. and p.PARENT_SCENE_ID=#{sceneId}
  94. and r.year=#{year}
  95. and r.month=#{month}
  96. <if test="tenantId != null and tenantId != '' ">
  97. and d.tenant_id = #{tenantId}
  98. </if>
  99. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  100. <if test="permissonType == 5 or permissonType == 2">
  101. and ( d.DEPT_ORG_ID in
  102. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  103. #{item.orgId}
  104. </foreach>
  105. or
  106. d.COMPANY_ORG_ID in
  107. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  108. #{item.orgId}
  109. </foreach>
  110. )
  111. </if>
  112. <if test="permissonType == 4 or permissonType == 3">
  113. and d.DEPT_ORG_ID in
  114. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  115. #{item.orgId}
  116. </foreach>
  117. </if>
  118. <if test="permissonType == 1">
  119. and d.COMPANY_ORG_ID in
  120. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  121. #{item.orgId}
  122. </foreach>
  123. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  124. </if>
  125. </if>
  126. group by r.day ,s.SCENE_NAME,r.DEVICE_NAME,r.DEVICE_CODE,r.ATTRIBUTE_NAME,da.unit
  127. ORDER BY r.`day` ASC
  128. </select>
  129. <select id="MonitorDataChartReportByYear" resultMap="MonitorDataChartReportMap">
  130. SELECT
  131. r.`month` AS "dateLabel",
  132. CONCAT( s.SCENE_NAME, r.DEVICE_NAME ) AS "deviceName",
  133. r.DEVICE_CODE AS "devoceCode",
  134. r.ATTRIBUTE_NAME AS "attributeName",
  135. da.unit AS "unit",
  136. ROUND( sum(r.AVG_VALUE), 2 ) AS "data",
  137. max(r.COLLECT_DATE) AS "date"
  138. FROM sms_device_parm p
  139. LEFT JOIN sms_year_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  140. LEFT JOIN sms_device_attribute da ON da.id = r.ATTRIBUTE_ID
  141. LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
  142. left join sms_scene s on s.id=p.PARENT_SCENE_ID
  143. where p.IS_CHART = 1 and p.`STATUS`= 1 and d.ENABLE_STATE = 1 and d.`STATUS`= 1
  144. and p.PARENT_SCENE_ID=#{sceneId}
  145. and r.year=#{year}
  146. <if test="tenantId != null and tenantId != '' ">
  147. and d.tenant_id = #{tenantId}
  148. </if>
  149. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  150. <if test="permissonType == 5 or permissonType == 2">
  151. and ( d.DEPT_ORG_ID in
  152. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  153. #{item.orgId}
  154. </foreach>
  155. or
  156. d.COMPANY_ORG_ID in
  157. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  158. #{item.orgId}
  159. </foreach>
  160. )
  161. </if>
  162. <if test="permissonType == 4 or permissonType == 3">
  163. and d.DEPT_ORG_ID in
  164. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  165. #{item.orgId}
  166. </foreach>
  167. </if>
  168. <if test="permissonType == 1">
  169. and d.COMPANY_ORG_ID in
  170. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  171. #{item.orgId}
  172. </foreach>
  173. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  174. </if>
  175. </if>
  176. group by r.month ,s.SCENE_NAME,r.DEVICE_NAME,r.DEVICE_CODE,r.ATTRIBUTE_NAME,da.unit
  177. ORDER BY r.`month` ASC
  178. </select>
  179. <!-- 对比————用水量、耗电量 -->
  180. <select id="MonitorDataEnergyReportByDay" resultMap="MonitorDataChartReportMap">
  181. SELECT
  182. r.`HOUR` AS "dateLabel",
  183. IF( p.parm_type = 5, '耗电量', IF( p.parm_type = 4, '取水量', '用水量' ) ) AS "attributeName",
  184. s.SCENE_NAME AS "deviceName",
  185. p.parm_type AS "attributeType",
  186. da.unit AS "unit",
  187. ifnull( ROUND( sum( r.SUM_VALUE ), 2 ), 0 ) AS "data",
  188. max( r.COLLECT_DATE ) AS "date"
  189. FROM sms_device_parm p
  190. LEFT JOIN sms_day_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  191. left join sms_scene s on s.id=p.parent_scene_id
  192. left join sms_device_attribute da ON da.id = p.ATTRIBUTE_ID
  193. LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
  194. WHERE p.`STATUS`= 1
  195. <if test="sceneType != null and sceneType == 1">
  196. and p.parm_type in (4,5)
  197. </if>
  198. <if test="sceneType == null or sceneType == 0">
  199. and p.parm_type in (3,5)
  200. </if>
  201. and d.ENABLE_STATE = 1 and d.`STATUS`= 1
  202. AND r.YEAR = #{year} and r.month=#{month} and r.day=#{day}
  203. <if test="sceneIds != null and sceneIds.size()>0">
  204. and p.PARENT_SCENE_ID in
  205. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  206. #{item}
  207. </foreach>
  208. </if>
  209. <if test="tenantId != null and tenantId != '' ">
  210. and d.tenant_id = #{tenantId}
  211. </if>
  212. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  213. <if test="permissonType == 5 or permissonType == 2">
  214. and ( d.DEPT_ORG_ID in
  215. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  216. #{item.orgId}
  217. </foreach>
  218. or
  219. d.COMPANY_ORG_ID in
  220. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  221. #{item.orgId}
  222. </foreach>
  223. )
  224. </if>
  225. <if test="permissonType == 4 or permissonType == 3">
  226. and d.DEPT_ORG_ID in
  227. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  228. #{item.orgId}
  229. </foreach>
  230. </if>
  231. <if test="permissonType == 1">
  232. and d.COMPANY_ORG_ID in
  233. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  234. #{item.orgId}
  235. </foreach>
  236. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  237. </if>
  238. </if>
  239. GROUP BY s.SCENE_NAME,p.parm_type,da.unit,r.HOUR
  240. order by r.`hour` asc
  241. </select>
  242. <select id="MonitorDataEnergyReportByMonth" resultMap="MonitorDataChartReportMap">
  243. SELECT
  244. r.`day` AS "dateLabel",
  245. <if test="sceneType != null and sceneType == 1">
  246. IF( p.parm_type = 5, '耗电量','取水量' ) AS "attributeName",
  247. </if>
  248. <if test="sceneType == null or sceneType == 0">
  249. IF( p.parm_type = 5, '耗电量','用水量' ) AS "attributeName",
  250. </if>
  251. s.SCENE_NAME AS "deviceName",
  252. p.parm_type AS "attributeType",
  253. da.unit AS "unit",
  254. ifnull( ROUND( sum( r.SUM_VALUE ), 2 ), 0 ) AS "data",
  255. max( r.COLLECT_DATE ) AS "date"
  256. FROM sms_device_parm p
  257. LEFT JOIN sms_month_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  258. left join sms_scene s on s.id=p.parent_scene_id
  259. left join sms_device_attribute da ON da.id = p.ATTRIBUTE_ID
  260. LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
  261. WHERE p.`STATUS`= 1
  262. <if test="sceneType != null and sceneType == 1">
  263. and p.parm_type in (4,5)
  264. </if>
  265. <if test="sceneType == null or sceneType == 0">
  266. and p.parm_type in (3,5)
  267. </if>
  268. and d.ENABLE_STATE = 1 and d.`STATUS`= 1
  269. AND r.YEAR = #{year} and r.month=#{month}
  270. <if test="sceneIds != null and sceneIds.size()>0">
  271. and p.PARENT_SCENE_ID in
  272. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  273. #{item}
  274. </foreach>
  275. </if>
  276. <if test="tenantId != null and tenantId != '' ">
  277. and d.tenant_id = #{tenantId}
  278. </if>
  279. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  280. <if test="permissonType == 5 or permissonType == 2">
  281. and ( d.DEPT_ORG_ID in
  282. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  283. #{item.orgId}
  284. </foreach>
  285. or
  286. d.COMPANY_ORG_ID in
  287. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  288. #{item.orgId}
  289. </foreach>
  290. )
  291. </if>
  292. <if test="permissonType == 4 or permissonType == 3">
  293. and d.DEPT_ORG_ID in
  294. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  295. #{item.orgId}
  296. </foreach>
  297. </if>
  298. <if test="permissonType == 1">
  299. and d.COMPANY_ORG_ID in
  300. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  301. #{item.orgId}
  302. </foreach>
  303. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  304. </if>
  305. </if>
  306. GROUP BY s.SCENE_NAME,p.parm_type,da.unit,r.day
  307. order by r.`day` asc
  308. </select>
  309. <select id="MonitorDataEnergyReportByYear" resultMap="MonitorDataChartReportMap">
  310. SELECT
  311. r.`month` AS "dateLabel",
  312. <if test="sceneType != null and sceneType == 1">
  313. IF( p.parm_type = 5, '耗电量','取水量' ) AS "attributeName",
  314. </if>
  315. <if test="sceneType == null or sceneType == 0">
  316. IF( p.parm_type = 5, '耗电量','用水量' ) AS "attributeName",
  317. </if>
  318. s.SCENE_NAME AS "deviceName",
  319. p.parm_type AS "attributeType",
  320. da.unit AS "unit",
  321. ifnull( ROUND( sum( r.SUM_VALUE ), 2 ), 0 ) AS "data",
  322. max( r.COLLECT_DATE ) AS "date"
  323. FROM sms_device_parm p
  324. LEFT JOIN sms_year_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  325. left join sms_scene s on s.id=p.parent_scene_id
  326. left join sms_device_attribute da ON da.id = p.ATTRIBUTE_ID
  327. LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
  328. WHERE p.`STATUS`= 1
  329. <if test="sceneType != null and sceneType == 1">
  330. and p.parm_type in (4,5)
  331. </if>
  332. <if test="sceneType == null or sceneType == 0">
  333. and p.parm_type in (3,5)
  334. </if>
  335. and d.ENABLE_STATE = 1 and d.`STATUS`= 1
  336. AND r.YEAR = #{year}
  337. <if test="sceneIds != null and sceneIds.size()>0">
  338. and p.PARENT_SCENE_ID in
  339. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  340. #{item}
  341. </foreach>
  342. </if>
  343. <if test="tenantId != null and tenantId != '' ">
  344. and d.tenant_id = #{tenantId}
  345. </if>
  346. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  347. <if test="permissonType == 5 or permissonType == 2">
  348. and ( d.DEPT_ORG_ID in
  349. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  350. #{item.orgId}
  351. </foreach>
  352. or
  353. d.COMPANY_ORG_ID in
  354. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  355. #{item.orgId}
  356. </foreach>
  357. )
  358. </if>
  359. <if test="permissonType == 4 or permissonType == 3">
  360. and d.DEPT_ORG_ID in
  361. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  362. #{item.orgId}
  363. </foreach>
  364. </if>
  365. <if test="permissonType == 1">
  366. and d.COMPANY_ORG_ID in
  367. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  368. #{item.orgId}
  369. </foreach>
  370. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  371. </if>
  372. </if>
  373. GROUP BY s.SCENE_NAME,p.parm_type,da.unit,r.month
  374. order by r.`month` asc
  375. </select>
  376. <!-- 对比————PH、余氯、浊度 -->
  377. <select id="MonitorDataQualityReportByDay" resultMap="MonitorDataChartReportMap">
  378. SELECT
  379. r.`HOUR` AS "dateLabel",
  380. if(p.parm_type=7,'PH',if(p.parm_type=11,'余氯','浊度')) as "attributeName",
  381. s.SCENE_NAME AS "deviceName",
  382. p.parm_type AS "attributeType",
  383. da.unit AS "unit",
  384. ifnull( ROUND( sum( r.SUM_VALUE ), 2 ), 0 ) AS "data",
  385. max( r.COLLECT_DATE ) AS "date"
  386. FROM sms_device_parm p
  387. LEFT JOIN sms_day_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  388. left join sms_scene s on s.id=p.parent_scene_id
  389. left join sms_device_attribute da ON da.id = p.ATTRIBUTE_ID
  390. LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
  391. WHERE p.`STATUS`= 1 and p.parm_type in (7,11,9) and d.ENABLE_STATE = 1 and d.`STATUS`= 1
  392. AND r.YEAR = #{year} and r.month=#{month} and r.day=#{day}
  393. <if test="sceneIds != null and sceneIds.size()>0">
  394. and p.PARENT_SCENE_ID in
  395. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  396. #{item}
  397. </foreach>
  398. </if>
  399. <if test="tenantId != null and tenantId != '' ">
  400. and d.tenant_id = #{tenantId}
  401. </if>
  402. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  403. <if test="permissonType == 5 or permissonType == 2">
  404. and ( d.DEPT_ORG_ID in
  405. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  406. #{item.orgId}
  407. </foreach>
  408. or
  409. d.COMPANY_ORG_ID in
  410. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  411. #{item.orgId}
  412. </foreach>
  413. )
  414. </if>
  415. <if test="permissonType == 4 or permissonType == 3">
  416. and d.DEPT_ORG_ID in
  417. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  418. #{item.orgId}
  419. </foreach>
  420. </if>
  421. <if test="permissonType == 1">
  422. and d.COMPANY_ORG_ID in
  423. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  424. #{item.orgId}
  425. </foreach>
  426. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  427. </if>
  428. </if>
  429. GROUP BY s.SCENE_NAME,p.parm_type,da.unit,r.HOUR
  430. order by r.`hour` asc
  431. </select>
  432. <select id="MonitorDataQualityReportByMonth" resultMap="MonitorDataChartReportMap">
  433. SELECT
  434. r.`day` AS "dateLabel",
  435. if(p.parm_type=7,'PH',if(p.parm_type=11,'余氯','浊度')) as "attributeName",
  436. s.SCENE_NAME AS "deviceName",
  437. p.parm_type AS "attributeType",
  438. da.unit AS "unit",
  439. ifnull( ROUND( sum( r.SUM_VALUE ), 2 ), 0 ) AS "data",
  440. max( r.COLLECT_DATE ) AS "date"
  441. FROM sms_device_parm p
  442. LEFT JOIN sms_month_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  443. left join sms_scene s on s.id=p.parent_scene_id
  444. left join sms_device_attribute da ON da.id = p.ATTRIBUTE_ID
  445. LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
  446. WHERE p.`STATUS`= 1 and p.parm_type in (7,11,9) and d.ENABLE_STATE = 1 and d.`STATUS`= 1
  447. AND r.YEAR = #{year} and r.month=#{month}
  448. <if test="sceneIds != null and sceneIds.size()>0">
  449. and p.PARENT_SCENE_ID in
  450. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  451. #{item}
  452. </foreach>
  453. </if>
  454. <if test="tenantId != null and tenantId != '' ">
  455. and d.tenant_id = #{tenantId}
  456. </if>
  457. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  458. <if test="permissonType == 5 or permissonType == 2">
  459. and ( d.DEPT_ORG_ID in
  460. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  461. #{item.orgId}
  462. </foreach>
  463. or
  464. d.COMPANY_ORG_ID in
  465. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  466. #{item.orgId}
  467. </foreach>
  468. )
  469. </if>
  470. <if test="permissonType == 4 or permissonType == 3">
  471. and d.DEPT_ORG_ID in
  472. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  473. #{item.orgId}
  474. </foreach>
  475. </if>
  476. <if test="permissonType == 1">
  477. and d.COMPANY_ORG_ID in
  478. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  479. #{item.orgId}
  480. </foreach>
  481. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  482. </if>
  483. </if>
  484. GROUP BY s.SCENE_NAME,p.parm_type,da.unit,r.day
  485. order by r.`day` asc
  486. </select>
  487. <select id="MonitorDataQualityReportByYear" resultMap="MonitorDataChartReportMap">
  488. SELECT
  489. r.`month` AS "dateLabel",
  490. if(p.parm_type=7,'PH',if(p.parm_type=11,'余氯','浊度')) as "attributeName",
  491. s.SCENE_NAME AS "deviceName",
  492. p.parm_type AS "attributeType",
  493. da.unit AS "unit",
  494. ifnull( ROUND( sum( r.SUM_VALUE ), 2 ), 0 ) AS "data",
  495. max( r.COLLECT_DATE ) AS "date"
  496. FROM sms_device_parm p
  497. LEFT JOIN sms_year_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  498. left join sms_scene s on s.id=p.parent_scene_id
  499. left join sms_device_attribute da ON da.id = p.ATTRIBUTE_ID
  500. LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
  501. WHERE p.`STATUS`= 1 and p.parm_type in (7,11,9)
  502. AND r.YEAR = #{year} and d.ENABLE_STATE = 1 and d.`STATUS`= 1
  503. <if test="sceneIds != null and sceneIds.size()>0">
  504. and p.PARENT_SCENE_ID in
  505. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  506. #{item}
  507. </foreach>
  508. </if>
  509. <if test="tenantId != null and tenantId != '' ">
  510. and d.tenant_id = #{tenantId}
  511. </if>
  512. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  513. <if test="permissonType == 5 or permissonType == 2">
  514. and ( d.DEPT_ORG_ID in
  515. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  516. #{item.orgId}
  517. </foreach>
  518. or
  519. d.COMPANY_ORG_ID in
  520. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  521. #{item.orgId}
  522. </foreach>
  523. )
  524. </if>
  525. <if test="permissonType == 4 or permissonType == 3">
  526. and d.DEPT_ORG_ID in
  527. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  528. #{item.orgId}
  529. </foreach>
  530. </if>
  531. <if test="permissonType == 1">
  532. and d.COMPANY_ORG_ID in
  533. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  534. #{item.orgId}
  535. </foreach>
  536. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  537. </if>
  538. </if>
  539. GROUP BY s.SCENE_NAME,p.parm_type,da.unit,r.month
  540. order by r.`month` asc
  541. </select>
  542. <!-- 对比————报警 -->
  543. <select id="DeviceAlarmReport" resultMap="MonitorDataChartReportMap">
  544. select
  545. a.*,DATE_ADD(#{beginDate},INTERVAL a.dateLabel-1 ${dateType}) as "date"
  546. from (
  547. select
  548. ${dateType}(ad.ALARM_START_TIME) as "dateLabel"
  549. <if test="dateType != null and dateType == 'month'">
  550. ,DATE_FORMAT(max(ad.ALARM_START_TIME),'%Y-%m') as "dateStringLabel"
  551. </if>
  552. <if test="dateType != null and dateType == 'day'">
  553. ,DATE_FORMAT(max(ad.ALARM_START_TIME),'%Y-%m-%d') as "dateStringLabel"
  554. </if>
  555. <if test="dateType != null and dateType == 'hour'">
  556. ,DATE_FORMAT(max(ad.ALARM_START_TIME),'%Y-%m-%d %H:00') as "dateStringLabel"
  557. </if>
  558. ,ad.PARENT_SCENE_NAME as "deviceName"
  559. ,'报警次数' as "attributeName"
  560. ,count(1) as "monitorData"
  561. ,count(1) as "data"
  562. from sms_alarm_details ad
  563. left join sms_device d on ad.DEVICE_ID=d.ID
  564. where ad.ALARM_START_TIME &lt; #{endDate} and ad.ALARM_START_TIME >= #{beginDate} and d.ENABLE_STATE = 1 and d.`STATUS`= 1
  565. <if test="sceneIds != null and sceneIds.size()>0">
  566. and ad.parent_scene_id in
  567. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  568. #{item}
  569. </foreach>
  570. </if>
  571. <if test="tenantId != null and tenantId != '' ">
  572. and d.tenant_id = #{tenantId}
  573. </if>
  574. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  575. <if test="permissonType == 5 or permissonType == 2">
  576. and ( d.DEPT_ORG_ID in
  577. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  578. #{item.orgId}
  579. </foreach>
  580. or
  581. d.COMPANY_ORG_ID in
  582. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  583. #{item.orgId}
  584. </foreach>
  585. )
  586. </if>
  587. <if test="permissonType == 4 or permissonType == 3">
  588. and d.DEPT_ORG_ID in
  589. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  590. #{item.orgId}
  591. </foreach>
  592. </if>
  593. <if test="permissonType == 1">
  594. and d.COMPANY_ORG_ID in
  595. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  596. #{item.orgId}
  597. </foreach>
  598. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  599. </if>
  600. </if>
  601. group by ad.PARENT_SCENE_NAME,${dateType}(ad.ALARM_START_TIME)
  602. )a
  603. order by deviceName,dateLabel
  604. </select>
  605. <!-- 根据场景类型查询设备-->
  606. <select id="getDeviceBySceneTypeName" resultType="com.huaxu.entity.DeviceEntity">
  607. select
  608. distinct d.DEVICE_NAME as "deviceName",d.id
  609. from sms_scene_type st
  610. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  611. left join sms_device_scene ds on ds.SCENE_ID=s.ID
  612. left join sms_device d on d.id=ds.DEVICE_ID
  613. where st.SCENE_TYPE_NAME=#{sceneTypeName} and d.`STATUS`= 1 and d.ENABLE_STATE = 1 and s.ENABLE_STATE = 1 and ds.status=1
  614. <if test="tenantId != null and tenantId != '' ">
  615. and d.tenant_id = #{tenantId}
  616. </if>
  617. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  618. <if test="permissonType == 5 or permissonType == 2">
  619. and ( d.DEPT_ORG_ID in
  620. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  621. #{item.orgId}
  622. </foreach>
  623. or
  624. d.COMPANY_ORG_ID in
  625. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  626. #{item.orgId}
  627. </foreach>
  628. )
  629. </if>
  630. <if test="permissonType == 4 or permissonType == 3">
  631. and d.DEPT_ORG_ID in
  632. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  633. #{item.orgId}
  634. </foreach>
  635. </if>
  636. <if test="permissonType == 1">
  637. and d.COMPANY_ORG_ID in
  638. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  639. #{item.orgId}
  640. </foreach>
  641. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  642. </if>
  643. </if>
  644. </select>
  645. <!-- 设备报表 -->
  646. <select id="MonitorDataDeviceReportByDay" resultMap="MonitorDataChartReportMap">
  647. SELECT
  648. d.DEVICE_NAME AS "deviceName",
  649. p.parm_type AS "attributeType",
  650. IF( p.parm_type = 13, '压力',
  651. IF( p.parm_type = 14, '瞬时流量',
  652. IF( p.parm_type = 16, '流速',
  653. IF( p.parm_type = 7, 'PH',
  654. IF( p.parm_type = 15, 'COD',
  655. IF( p.parm_type = 9, '浊度',
  656. IF( p.parm_type = 11, '余氯', '' )))))))
  657. AS "attributeName",
  658. da.unit AS "unit",
  659. r.`HOUR` AS "dateLabel",
  660. ifnull( ROUND( sum( r.AVG_VALUE ), 2 ), 0 ) AS "data",
  661. max( r.COLLECT_DATE ) AS "date"
  662. FROM sms_device_parm p
  663. LEFT JOIN sms_day_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  664. left join sms_device_attribute da ON da.id = p.ATTRIBUTE_ID
  665. LEFT JOIN sms_device d ON d.id = p.DEVICE_ID
  666. WHERE p.`STATUS`= 1 and d.ENABLE_STATE = 1 and d.`STATUS`= 1
  667. AND r.YEAR = #{year} and r.month=#{month} and r.day=#{day}
  668. <if test="searchType != null and searchType == 1">
  669. and p.parm_type = 13
  670. </if>
  671. <if test="searchType != null and searchType == 2">
  672. and p.parm_type in (14,16)
  673. </if>
  674. <if test="searchType != null and searchType == 3">
  675. and p.parm_type in (7,9,11,15)
  676. </if>
  677. <if test="deviceIds != null and deviceIds.size()>0">
  678. and d.id in
  679. <foreach collection="deviceIds" item="item" open="(" close=")" separator=",">
  680. #{item}
  681. </foreach>
  682. </if>
  683. <if test="tenantId != null and tenantId != '' ">
  684. and d.tenant_id = #{tenantId}
  685. </if>
  686. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  687. <if test="permissonType == 5 or permissonType == 2">
  688. and ( d.DEPT_ORG_ID in
  689. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  690. #{item.orgId}
  691. </foreach>
  692. or
  693. d.COMPANY_ORG_ID in
  694. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  695. #{item.orgId}
  696. </foreach>
  697. )
  698. </if>
  699. <if test="permissonType == 4 or permissonType == 3">
  700. and d.DEPT_ORG_ID in
  701. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  702. #{item.orgId}
  703. </foreach>
  704. </if>
  705. <if test="permissonType == 1">
  706. and d.COMPANY_ORG_ID in
  707. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  708. #{item.orgId}
  709. </foreach>
  710. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  711. </if>
  712. </if>
  713. GROUP BY d.DEVICE_NAME, p.parm_type,da.unit,r.HOUR
  714. order by r.`hour` asc
  715. </select>
  716. <select id="MonitorDataDeviceReportByMonth" resultMap="MonitorDataChartReportMap">
  717. SELECT
  718. d.DEVICE_NAME AS "deviceName",
  719. p.parm_type AS "attributeType",
  720. IF( p.parm_type = 13, '压力',
  721. IF( p.parm_type = 14, '瞬时流量',
  722. IF( p.parm_type = 16, '流速',
  723. IF( p.parm_type = 7, 'PH',
  724. IF( p.parm_type = 15, 'COD',
  725. IF( p.parm_type = 9, '浊度',
  726. IF( p.parm_type = 11, '余氯', '' )))))))
  727. AS "attributeName",
  728. da.unit AS "unit",
  729. r.`day` AS "dateLabel",
  730. ifnull( ROUND( sum( r.AVG_VALUE ), 2 ), 0 ) AS "data",
  731. max( r.COLLECT_DATE ) AS "date"
  732. FROM sms_device_parm p
  733. LEFT JOIN sms_month_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  734. left join sms_device_attribute da ON da.id = p.ATTRIBUTE_ID
  735. LEFT JOIN sms_device d ON d.id = p.DEVICE_ID
  736. WHERE p.`STATUS`= 1 and d.ENABLE_STATE = 1
  737. AND r.YEAR = #{year} and r.month=#{month}
  738. <if test="searchType != null and searchType == 1">
  739. and p.parm_type = 13
  740. </if>
  741. <if test="searchType != null and searchType == 2">
  742. and p.parm_type in (14,16)
  743. </if>
  744. <if test="searchType != null and searchType == 3">
  745. and p.parm_type in (7,9,11,15)
  746. </if>
  747. <if test="deviceIds != null and deviceIds.size()>0">
  748. and d.id in
  749. <foreach collection="deviceIds" item="item" open="(" close=")" separator=",">
  750. #{item}
  751. </foreach>
  752. </if>
  753. <if test="tenantId != null and tenantId != '' ">
  754. and d.tenant_id = #{tenantId}
  755. </if>
  756. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  757. <if test="permissonType == 5 or permissonType == 2">
  758. and ( d.DEPT_ORG_ID in
  759. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  760. #{item.orgId}
  761. </foreach>
  762. or
  763. d.COMPANY_ORG_ID in
  764. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  765. #{item.orgId}
  766. </foreach>
  767. )
  768. </if>
  769. <if test="permissonType == 4 or permissonType == 3">
  770. and d.DEPT_ORG_ID in
  771. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  772. #{item.orgId}
  773. </foreach>
  774. </if>
  775. <if test="permissonType == 1">
  776. and d.COMPANY_ORG_ID in
  777. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  778. #{item.orgId}
  779. </foreach>
  780. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  781. </if>
  782. </if>
  783. GROUP BY d.DEVICE_NAME, p.parm_type,da.unit,r.day
  784. order by r.day asc
  785. </select>
  786. <select id="MonitorDataDeviceReportByYear" resultMap="MonitorDataChartReportMap">
  787. SELECT
  788. d.DEVICE_NAME AS "deviceName",
  789. p.parm_type AS "attributeType",
  790. IF( p.parm_type = 13, '压力',
  791. IF( p.parm_type = 14, '瞬时流量',
  792. IF( p.parm_type = 16, '流速',
  793. IF( p.parm_type = 7, 'PH',
  794. IF( p.parm_type = 15, 'COD',
  795. IF( p.parm_type = 9, '浊度',
  796. IF( p.parm_type = 11, '余氯', '' )))))))
  797. AS "attributeName",
  798. da.unit AS "unit",
  799. r.month AS "dateLabel",
  800. ifnull( ROUND( sum( r.AVG_VALUE ), 2 ), 0 ) AS "data",
  801. max( r.COLLECT_DATE ) AS "date"
  802. FROM sms_device_parm p
  803. LEFT JOIN sms_year_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  804. left join sms_device_attribute da ON da.id = p.ATTRIBUTE_ID
  805. LEFT JOIN sms_device d ON d.id = p.DEVICE_ID
  806. WHERE p.`STATUS`= 1 and d.ENABLE_STATE = 1
  807. AND r.YEAR = #{year}
  808. <if test="searchType != null and searchType == 1">
  809. and p.parm_type = 13
  810. </if>
  811. <if test="searchType != null and searchType == 2">
  812. and p.parm_type in (14,16)
  813. </if>
  814. <if test="searchType != null and searchType == 3">
  815. and p.parm_type in (7,9,11,15)
  816. </if>
  817. <if test="deviceIds != null and deviceIds.size()>0">
  818. and d.id in
  819. <foreach collection="deviceIds" item="item" open="(" close=")" separator=",">
  820. #{item}
  821. </foreach>
  822. </if>
  823. <if test="tenantId != null and tenantId != '' ">
  824. and d.tenant_id = #{tenantId}
  825. </if>
  826. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  827. <if test="permissonType == 5 or permissonType == 2">
  828. and ( d.DEPT_ORG_ID in
  829. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  830. #{item.orgId}
  831. </foreach>
  832. or
  833. d.COMPANY_ORG_ID in
  834. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  835. #{item.orgId}
  836. </foreach>
  837. )
  838. </if>
  839. <if test="permissonType == 4 or permissonType == 3">
  840. and d.DEPT_ORG_ID in
  841. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  842. #{item.orgId}
  843. </foreach>
  844. </if>
  845. <if test="permissonType == 1">
  846. and d.COMPANY_ORG_ID in
  847. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  848. #{item.orgId}
  849. </foreach>
  850. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  851. </if>
  852. </if>
  853. GROUP BY d.DEVICE_NAME, p.parm_type,da.unit,r.month
  854. order by r.`month` asc
  855. </select>
  856. <!-- 概览页 -->
  857. <select id="selectDeviceCode" resultType="java.lang.String">
  858. select DEVICE_CODE from sms_device d
  859. where STATUS =1 and ENABLE_STATE =1 and TENANT_ID=#{tenantId}
  860. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  861. <if test="permissonType == 5 or permissonType == 2">
  862. and ( d.DEPT_ORG_ID in
  863. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  864. #{item.orgId}
  865. </foreach>
  866. or
  867. d.COMPANY_ORG_ID in
  868. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  869. #{item.orgId}
  870. </foreach>
  871. )
  872. </if>
  873. <if test="permissonType == 4 or permissonType == 3">
  874. and d.DEPT_ORG_ID in
  875. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  876. #{item.orgId}
  877. </foreach>
  878. </if>
  879. <if test="permissonType == 1">
  880. and d.COMPANY_ORG_ID in
  881. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  882. #{item.orgId}
  883. </foreach>
  884. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  885. </if>
  886. </if>
  887. </select>
  888. <select id="selectDeviceCodeByConditions" resultType="java.lang.String">
  889. select distinct d.DEVICE_CODE
  890. FROM sms_scene_type st
  891. LEFT JOIN sms_scene s ON s.SCENE_TYPE_ID = st.ID
  892. LEFT JOIN sms_device_scene ds ON ds.PARENT_SCENE_ID = s.ID
  893. LEFT JOIN sms_device d ON d.id = ds.DEVICE_ID
  894. WHERE st.`STATUS` = 1 AND s.`STATUS` = 1 AND ds.`STATUS` = 1 AND d.`STATUS` = 1
  895. <if test="companyOrgId != null">
  896. and d.COMPANY_ORG_ID =#{companyOrgId}
  897. </if>
  898. <if test="sceneId != null">
  899. and s.id =#{sceneId}
  900. </if>
  901. <if test="sceneTypeName != null and sceneTypeName != ''">
  902. AND st.SCENE_TYPE_NAME = #{sceneTypeName}
  903. </if>
  904. and s.TENANT_ID=#{tenantId}
  905. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  906. <if test="permissonType == 5 or permissonType == 2">
  907. and ( d.DEPT_ORG_ID in
  908. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  909. #{item.orgId}
  910. </foreach>
  911. or
  912. d.COMPANY_ORG_ID in
  913. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  914. #{item.orgId}
  915. </foreach>
  916. )
  917. </if>
  918. <if test="permissonType == 4 or permissonType == 3">
  919. and d.DEPT_ORG_ID in
  920. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  921. #{item.orgId}
  922. </foreach>
  923. </if>
  924. <if test="permissonType == 1">
  925. and d.COMPANY_ORG_ID in
  926. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  927. #{item.orgId}
  928. </foreach>
  929. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  930. </if>
  931. </if>
  932. </select>
  933. <select id="getDeviceWaterFor30Day" resultType="com.huaxu.dto.generalView.DeviceWaterSupply">
  934. select
  935. r.year,r.month,r.day,
  936. sum(r.SUM_VALUE) as "amount"
  937. from sms_scene_type st
  938. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  939. left join sms_device_parm dp on s.id=dp.PARENT_SCENE_ID
  940. left join sms_month_report r on r.DEVICE_ID= dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID
  941. where dp.`STATUS`=1 and st.SCENE_TYPE_NAME = '水厂' and s.ENABLE_STATE = 1
  942. and dp.PARM_TYPE = 3 and dp.TENANT_ID=#{tenantId}
  943. and r.COLLECT_DATE >= DATE_SUB(CURDATE(),INTERVAL 29 day)
  944. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  945. <if test="permissonType == 5 or permissonType == 2">
  946. and ( s.DEPT_ORG_ID in
  947. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  948. #{item.orgId}
  949. </foreach>
  950. or
  951. s.COMPANY_ORG_ID in
  952. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  953. #{item.orgId}
  954. </foreach>
  955. )
  956. </if>
  957. <if test="permissonType == 4 or permissonType == 3">
  958. and s.DEPT_ORG_ID in
  959. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  960. #{item.orgId}
  961. </foreach>
  962. </if>
  963. <if test="permissonType == 1">
  964. and s.COMPANY_ORG_ID in
  965. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  966. #{item.orgId}
  967. </foreach>
  968. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  969. </if>
  970. </if>
  971. group by r.year,r.month,r.day
  972. order by r.year desc,r.month desc,r.day desc
  973. </select>
  974. <select id="getDeviceWaterDetailForNow" resultType="com.huaxu.dto.generalView.DeviceWaterDetail">
  975. select
  976. s.SCENE_NAME as "sceneName"
  977. ,dp.DEVICE_ID as "deviceId"
  978. ,dp.ATTRIBUTE_ID as "attributeId"
  979. ,dp.PARM_TYPE as "parmType"
  980. from sms_scene_type st
  981. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  982. left join sms_device_parm dp on s.id=dp.PARENT_SCENE_ID
  983. where dp.`STATUS`=1 and st.SCENE_TYPE_NAME = #{sceneTypeName} and s.ENABLE_STATE = 1 and s.PARENT_SCENE_ID = 0
  984. and dp.PARM_TYPE =#{parmType} and dp.TENANT_ID=#{tenantId}
  985. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  986. <if test="permissonType == 5 or permissonType == 2">
  987. and ( s.DEPT_ORG_ID in
  988. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  989. #{item.orgId}
  990. </foreach>
  991. or
  992. s.COMPANY_ORG_ID in
  993. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  994. #{item.orgId}
  995. </foreach>
  996. )
  997. </if>
  998. <if test="permissonType == 4 or permissonType == 3">
  999. and s.DEPT_ORG_ID in
  1000. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1001. #{item.orgId}
  1002. </foreach>
  1003. </if>
  1004. <if test="permissonType == 1">
  1005. and s.COMPANY_ORG_ID in
  1006. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1007. #{item.orgId}
  1008. </foreach>
  1009. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  1010. </if>
  1011. </if>
  1012. </select>
  1013. <select id="getDeviceWaterDetailForDay" resultType="com.huaxu.dto.generalView.DeviceWaterDetail">
  1014. select
  1015. s.SCENE_NAME as "sceneName"
  1016. ,dp.DEVICE_ID as "deviceId"
  1017. ,dp.ATTRIBUTE_ID as "attributeId"
  1018. ,dp.PARM_TYPE as "parmType"
  1019. ,r.LATEST_VALUE as "latestValue"
  1020. from sms_scene_type st
  1021. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  1022. left join sms_device_parm dp on s.id=dp.PARENT_SCENE_ID
  1023. left join sms_month_report r on r.DEVICE_ID= dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID and r.year = #{year} and r.month= #{month} and r.day = #{day}
  1024. where dp.`STATUS`=1 and st.SCENE_TYPE_NAME = #{sceneTypeName} and s.ENABLE_STATE = 1
  1025. <if test="companyOrgId != null">
  1026. and s.COMPANY_ORG_ID = #{companyOrgId}
  1027. </if>
  1028. <if test="sceneId != null">
  1029. and s.id = #{sceneId}
  1030. </if>
  1031. and dp.PARM_TYPE =#{parmType} and dp.TENANT_ID=#{tenantId}
  1032. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  1033. <if test="permissonType == 5 or permissonType == 2">
  1034. and ( s.DEPT_ORG_ID in
  1035. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1036. #{item.orgId}
  1037. </foreach>
  1038. or
  1039. s.COMPANY_ORG_ID in
  1040. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1041. #{item.orgId}
  1042. </foreach>
  1043. )
  1044. </if>
  1045. <if test="permissonType == 4 or permissonType == 3">
  1046. and s.DEPT_ORG_ID in
  1047. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1048. #{item.orgId}
  1049. </foreach>
  1050. </if>
  1051. <if test="permissonType == 1">
  1052. and s.COMPANY_ORG_ID in
  1053. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1054. #{item.orgId}
  1055. </foreach>
  1056. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  1057. </if>
  1058. </if>
  1059. </select>
  1060. <select id="getDeviceWaterDetailForMonth" resultType="java.math.BigDecimal">
  1061. select
  1062. sum(ifnull(r.SUM_VALUE,0)) as "amount"
  1063. from sms_scene_type st
  1064. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  1065. left join sms_device_parm dp on s.id=dp.PARENT_SCENE_ID
  1066. left join sms_month_report r on r.DEVICE_ID= dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID and r.year = #{year} and r.month= #{month}
  1067. where dp.`STATUS`=1 and st.SCENE_TYPE_NAME = #{sceneTypeName} and s.ENABLE_STATE = 1
  1068. <if test="companyOrgId != null">
  1069. and s.COMPANY_ORG_ID = #{companyOrgId}
  1070. </if>
  1071. <if test="sceneId != null">
  1072. and s.id = #{sceneId}
  1073. </if>
  1074. and dp.PARM_TYPE =#{parmType} and dp.TENANT_ID=#{tenantId}
  1075. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  1076. <if test="permissonType == 5 or permissonType == 2">
  1077. and ( s.DEPT_ORG_ID in
  1078. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1079. #{item.orgId}
  1080. </foreach>
  1081. or
  1082. s.COMPANY_ORG_ID in
  1083. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1084. #{item.orgId}
  1085. </foreach>
  1086. )
  1087. </if>
  1088. <if test="permissonType == 4 or permissonType == 3">
  1089. and s.DEPT_ORG_ID in
  1090. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1091. #{item.orgId}
  1092. </foreach>
  1093. </if>
  1094. <if test="permissonType == 1">
  1095. and s.COMPANY_ORG_ID in
  1096. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1097. #{item.orgId}
  1098. </foreach>
  1099. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  1100. </if>
  1101. </if>
  1102. </select>
  1103. <select id="getDeviceWaterDetailForYear" resultType="java.math.BigDecimal">
  1104. select
  1105. sum(ifnull(r.SUM_VALUE,0)) as "amount"
  1106. from sms_scene_type st
  1107. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  1108. left join sms_device_parm dp on s.id=dp.PARENT_SCENE_ID
  1109. left join sms_year_report r on r.DEVICE_ID= dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID and r.year = #{year}
  1110. where dp.`STATUS`=1 and st.SCENE_TYPE_NAME = #{sceneTypeName} and s.ENABLE_STATE = 1
  1111. <if test="companyOrgId != null">
  1112. and s.COMPANY_ORG_ID = #{companyOrgId}
  1113. </if>
  1114. <if test="sceneId != null">
  1115. and s.id = #{sceneId}
  1116. </if>
  1117. and dp.PARM_TYPE =#{parmType} and dp.TENANT_ID=#{tenantId}
  1118. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  1119. <if test="permissonType == 5 or permissonType == 2">
  1120. and ( s.DEPT_ORG_ID in
  1121. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1122. #{item.orgId}
  1123. </foreach>
  1124. or
  1125. s.COMPANY_ORG_ID in
  1126. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1127. #{item.orgId}
  1128. </foreach>
  1129. )
  1130. </if>
  1131. <if test="permissonType == 4 or permissonType == 3">
  1132. and s.DEPT_ORG_ID in
  1133. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1134. #{item.orgId}
  1135. </foreach>
  1136. </if>
  1137. <if test="permissonType == 1">
  1138. and s.COMPANY_ORG_ID in
  1139. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1140. #{item.orgId}
  1141. </foreach>
  1142. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  1143. </if>
  1144. </if>
  1145. </select>
  1146. <select id="getAlarmInfoForScene" resultType="com.huaxu.dto.generalView.SceneAlarm">
  1147. select
  1148. s.SCENE_NAME as "sceneName",count(ad.id) as "alarmNumber"
  1149. from sms_scene_type st
  1150. left join sms_scene s on s.SCENE_TYPE_ID =st.id and s.PARENT_SCENE_ID = 0
  1151. left join sms_alarm_details ad on ad.STATE = 1 and ad.PARENT_SCENE_ID=s.id
  1152. where s.`STATUS` = 1 and s.ENABLE_STATE = 1 and (st.SCENE_TYPE_NAME = '水厂' or st.SCENE_TYPE_NAME ='水源') and s.TENANT_ID=#{tenantId}
  1153. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  1154. <if test="permissonType == 5 or permissonType == 2">
  1155. and ( s.DEPT_ORG_ID in
  1156. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1157. #{item.orgId}
  1158. </foreach>
  1159. or
  1160. s.COMPANY_ORG_ID in
  1161. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1162. #{item.orgId}
  1163. </foreach>
  1164. )
  1165. </if>
  1166. <if test="permissonType == 4 or permissonType == 3">
  1167. and s.DEPT_ORG_ID in
  1168. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1169. #{item.orgId}
  1170. </foreach>
  1171. </if>
  1172. <if test="permissonType == 1">
  1173. and s.COMPANY_ORG_ID in
  1174. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1175. #{item.orgId}
  1176. </foreach>
  1177. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  1178. </if>
  1179. </if>
  1180. group by s.SCENE_NAME
  1181. having count(ad.id) >0
  1182. </select>
  1183. <select id="getQualificationForScene" resultType="com.huaxu.dto.generalView.SceneNormalRate">
  1184. select
  1185. sum(if(alarmNumber > 0 ,1,0)) as "abnormal",
  1186. sum(if(alarmNumber > 0 ,0,1)) as "normal",
  1187. ROUND(sum(if(alarmNumber > 0 ,0,1))/if(count(1) != 0, count(1),1) * 100,2) as "normalRate"
  1188. from (
  1189. select
  1190. s.SCENE_NAME as "sceneName"
  1191. <if test="parmType != null and parmType == -1">
  1192. ,sum( if(dp.PARM_TYPE IN ( 15, 8, 10, 11, 18, 19 ) and ad.id is not null,1,0) ) AS "alarmNumber"
  1193. </if>
  1194. <if test="parmType != null and parmType != -1">
  1195. ,sum( if(dp.PARM_TYPE = #{parmType} and ad.id is not null,1,0) ) AS "alarmNumber"
  1196. </if>
  1197. from sms_scene_type st
  1198. left join sms_scene s on s.SCENE_TYPE_ID =st.id and PARENT_SCENE_ID ='0'
  1199. left join sms_device_parm dp on dp.PARENT_SCENE_ID =s.ID
  1200. 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
  1201. where s.`STATUS`=1 and s.ENABLE_STATE = 1 and st.SCENE_TYPE_NAME = '水厂' and s.TENANT_ID =#{tenantId} and dp.`STATUS` = 1
  1202. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  1203. <if test="permissonType == 5 or permissonType == 2">
  1204. and ( s.DEPT_ORG_ID in
  1205. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1206. #{item.orgId}
  1207. </foreach>
  1208. or
  1209. s.COMPANY_ORG_ID in
  1210. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1211. #{item.orgId}
  1212. </foreach>
  1213. )
  1214. </if>
  1215. <if test="permissonType == 4 or permissonType == 3">
  1216. and s.DEPT_ORG_ID in
  1217. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1218. #{item.orgId}
  1219. </foreach>
  1220. </if>
  1221. <if test="permissonType == 1">
  1222. and s.COMPANY_ORG_ID in
  1223. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1224. #{item.orgId}
  1225. </foreach>
  1226. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  1227. </if>
  1228. </if>
  1229. group by s.SCENE_NAME
  1230. ) a
  1231. </select>
  1232. <select id="getWaterSupplyData" resultType="com.huaxu.dto.generalView.WaterSupplyData">
  1233. select
  1234. r.year
  1235. ,r.month
  1236. ,r.day
  1237. ,dp.PARM_TYPE as "parmType"
  1238. ,sum(r.SUM_VALUE) as "amount"
  1239. ,da.UNIT as "unit"
  1240. from sms_scene_type st
  1241. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  1242. left join sms_device_parm dp on s.id=dp.PARENT_SCENE_ID
  1243. left join sms_device_attribute da on dp.ATTRIBUTE_ID =da.ID
  1244. left join sms_month_report r on r.DEVICE_ID =dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID
  1245. where dp.`STATUS`=1 and st.SCENE_TYPE_NAME = #{sceneTypeName} and s.ENABLE_STATE = 1
  1246. and r.COLLECT_DATE >= DATE_SUB(CURDATE(),INTERVAL 7 day)
  1247. and dp.PARM_TYPE in (3,5,6) and dp.TENANT_ID=#{tenantId}
  1248. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  1249. <if test="permissonType == 5 or permissonType == 2">
  1250. and ( s.DEPT_ORG_ID in
  1251. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1252. #{item.orgId}
  1253. </foreach>
  1254. or
  1255. s.COMPANY_ORG_ID in
  1256. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1257. #{item.orgId}
  1258. </foreach>
  1259. )
  1260. </if>
  1261. <if test="permissonType == 4 or permissonType == 3">
  1262. and s.DEPT_ORG_ID in
  1263. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1264. #{item.orgId}
  1265. </foreach>
  1266. </if>
  1267. <if test="permissonType == 1">
  1268. and s.COMPANY_ORG_ID in
  1269. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1270. #{item.orgId}
  1271. </foreach>
  1272. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  1273. </if>
  1274. </if>
  1275. group by r.year,r.month,r.day,dp.PARM_TYPE,da.UNIT
  1276. </select>
  1277. <select id="getWaterSupplyDataByMonth" resultType="com.huaxu.dto.generalView.WaterSupplyData">
  1278. select
  1279. r.year
  1280. ,r.month
  1281. ,dp.PARM_TYPE as "parmType"
  1282. ,sum(r.SUM_VALUE) as "amount"
  1283. from sms_scene_type st
  1284. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  1285. left join sms_device_parm dp on s.id=dp.PARENT_SCENE_ID
  1286. left join sms_device_attribute da on dp.ATTRIBUTE_ID =da.ID
  1287. left join sms_year_report r on r.DEVICE_ID =dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID
  1288. where dp.`STATUS`=1 and st.SCENE_TYPE_NAME = #{sceneTypeName} and s.ENABLE_STATE = 1 and st.`STATUS`=1 and s.`STATUS`=1
  1289. and r.COLLECT_DATE >= DATE_SUB(CURDATE(),INTERVAL 6 month)
  1290. and dp.PARM_TYPE in (3,5) and dp.TENANT_ID=#{tenantId}
  1291. <if test="companyOrgId != null ">and s.COMPANY_ORG_ID=#{companyOrgId}</if>
  1292. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  1293. <if test="permissonType == 5 or permissonType == 2">
  1294. and ( s.DEPT_ORG_ID in
  1295. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1296. #{item.orgId}
  1297. </foreach>
  1298. or
  1299. s.COMPANY_ORG_ID in
  1300. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1301. #{item.orgId}
  1302. </foreach>
  1303. )
  1304. </if>
  1305. <if test="permissonType == 4 or permissonType == 3">
  1306. and s.DEPT_ORG_ID in
  1307. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1308. #{item.orgId}
  1309. </foreach>
  1310. </if>
  1311. <if test="permissonType == 1">
  1312. and s.COMPANY_ORG_ID in
  1313. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1314. #{item.orgId}
  1315. </foreach>
  1316. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  1317. </if>
  1318. </if>
  1319. group by r.year,r.month,dp.PARM_TYPE
  1320. </select>
  1321. <select id="getWaterSupplyDataByMonthForCurrentMonth" resultType="com.huaxu.dto.generalView.WaterSupplyData">
  1322. select
  1323. r.year
  1324. ,r.month
  1325. ,dp.PARM_TYPE as "parmType"
  1326. ,sum(r.SUM_VALUE) as "amount"
  1327. from sms_scene_type st
  1328. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  1329. left join sms_device_parm dp on s.id=dp.PARENT_SCENE_ID
  1330. left join sms_device_attribute da on dp.ATTRIBUTE_ID =da.ID
  1331. left join sms_month_report r on r.DEVICE_ID =dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID
  1332. where dp.`STATUS`=1
  1333. <if test="sceneTypeName != null ">
  1334. and st.SCENE_TYPE_NAME = #{sceneTypeName}
  1335. </if>
  1336. <if test="sceneTypeName == null ">
  1337. and st.SCENE_TYPE_NAME in ('水源','水厂','泵站')
  1338. </if>
  1339. and s.ENABLE_STATE = 1 and st.`STATUS`=1 and s.`STATUS`=1
  1340. and DATE_FORMAT(r.COLLECT_DATE,'%Y%m' ) = DATE_FORMAT(CURDATE( ) , '%Y%m' )
  1341. and dp.PARM_TYPE in (3,4,5) and dp.TENANT_ID=#{tenantId}
  1342. <if test="companyOrgId != null ">and s.COMPANY_ORG_ID=#{companyOrgId}</if>
  1343. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  1344. <if test="permissonType == 5 or permissonType == 2">
  1345. and ( s.DEPT_ORG_ID in
  1346. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1347. #{item.orgId}
  1348. </foreach>
  1349. or
  1350. s.COMPANY_ORG_ID in
  1351. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1352. #{item.orgId}
  1353. </foreach>
  1354. )
  1355. </if>
  1356. <if test="permissonType == 4 or permissonType == 3">
  1357. and s.DEPT_ORG_ID in
  1358. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1359. #{item.orgId}
  1360. </foreach>
  1361. </if>
  1362. <if test="permissonType == 1">
  1363. and s.COMPANY_ORG_ID in
  1364. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1365. #{item.orgId}
  1366. </foreach>
  1367. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  1368. </if>
  1369. </if>
  1370. group by r.year,r.month,dp.PARM_TYPE
  1371. </select>
  1372. <select id="getUseAmount" resultType="java.math.BigDecimal">
  1373. select sum(ifnull(a.WATER_USAGE,0)) as "amount"
  1374. from sms_month_sellwater a
  1375. <if test="companyOrgId != null">
  1376. and a.COMPANY_ORG_ID = #{companyOrgId}
  1377. </if>
  1378. and a.TENANT_ID=#{tenantId}
  1379. <if test="searchType ==1">
  1380. date_format(a.COLLECT_DATE, '%Y-%m') = DATE_FORMAT(now(), '%Y-%m')
  1381. </if>
  1382. <if test="searchType ==2">
  1383. date_format(a.COLLECT_DATE, '%Y') = DATE_FORMAT(now(), '%Y')
  1384. </if>
  1385. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  1386. <if test="permissonType == 5 or permissonType == 2">
  1387. and a.COMPANY_ORG_ID in
  1388. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1389. #{item.orgId}
  1390. </foreach>
  1391. </if>
  1392. <if test="permissonType == 4 or permissonType == 3">
  1393. and a.COMPANY_ORG_ID in
  1394. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1395. #{item.orgId}
  1396. </foreach>
  1397. </if>
  1398. <if test="permissonType == 1">
  1399. and a.COMPANY_ORG_ID in
  1400. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1401. #{item.orgId}
  1402. </foreach>
  1403. </if>
  1404. </if>
  1405. </select>
  1406. </mapper>