MonitorDataReportMapper.xml 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  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 test="sceneType != null and sceneType == 1">
  184. IF( p.parm_type = 5, '耗电量','取水量' ) AS "attributeName",
  185. </if>
  186. <if test="sceneType == null or sceneType == 0">
  187. IF( p.parm_type = 5, '耗电量','用水量' ) AS "attributeName",
  188. </if>
  189. s.SCENE_NAME AS "deviceName",
  190. p.parm_type AS "attributeType",
  191. da.unit AS "unit",
  192. ifnull( ROUND( sum( r.SUM_VALUE ), 2 ), 0 ) AS "data",
  193. max( r.COLLECT_DATE ) AS "date"
  194. FROM sms_device_parm p
  195. LEFT JOIN sms_day_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  196. left join sms_scene s on s.id=p.parent_scene_id
  197. left join sms_device_attribute da ON da.id = p.ATTRIBUTE_ID
  198. LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
  199. WHERE p.`STATUS`= 1
  200. <if test="sceneType != null and sceneType == 1">
  201. and p.parm_type in (4,5)
  202. </if>
  203. <if test="sceneType == null or sceneType == 0">
  204. and p.parm_type in (3,5)
  205. </if>
  206. and d.ENABLE_STATE = 1 and d.`STATUS`= 1
  207. AND r.YEAR = #{year} and r.month=#{month} and r.day=#{day}
  208. <if test="sceneIds != null and sceneIds.size()>0">
  209. and p.PARENT_SCENE_ID in
  210. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  211. #{item}
  212. </foreach>
  213. </if>
  214. <if test="tenantId != null and tenantId != '' ">
  215. and d.tenant_id = #{tenantId}
  216. </if>
  217. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  218. <if test="permissonType == 5 or permissonType == 2">
  219. and ( d.DEPT_ORG_ID in
  220. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  221. #{item.orgId}
  222. </foreach>
  223. or
  224. d.COMPANY_ORG_ID in
  225. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  226. #{item.orgId}
  227. </foreach>
  228. )
  229. </if>
  230. <if test="permissonType == 4 or permissonType == 3">
  231. and d.DEPT_ORG_ID in
  232. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  233. #{item.orgId}
  234. </foreach>
  235. </if>
  236. <if test="permissonType == 1">
  237. and d.COMPANY_ORG_ID in
  238. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  239. #{item.orgId}
  240. </foreach>
  241. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  242. </if>
  243. </if>
  244. GROUP BY s.SCENE_NAME,p.parm_type,da.unit,r.HOUR
  245. order by r.`hour` asc
  246. </select>
  247. <select id="MonitorDataEnergyReportByMonth" resultMap="MonitorDataChartReportMap">
  248. SELECT
  249. r.`day` AS "dateLabel",
  250. <if test="sceneType != null and sceneType == 1">
  251. IF( p.parm_type = 5, '耗电量','取水量' ) AS "attributeName",
  252. </if>
  253. <if test="sceneType == null or sceneType == 0">
  254. IF( p.parm_type = 5, '耗电量','用水量' ) AS "attributeName",
  255. </if>
  256. s.SCENE_NAME AS "deviceName",
  257. p.parm_type AS "attributeType",
  258. da.unit AS "unit",
  259. ifnull( ROUND( sum( r.SUM_VALUE ), 2 ), 0 ) AS "data",
  260. max( r.COLLECT_DATE ) AS "date"
  261. FROM sms_device_parm p
  262. LEFT JOIN sms_month_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  263. left join sms_scene s on s.id=p.parent_scene_id
  264. left join sms_device_attribute da ON da.id = p.ATTRIBUTE_ID
  265. LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
  266. WHERE p.`STATUS`= 1
  267. <if test="sceneType != null and sceneType == 1">
  268. and p.parm_type in (4,5)
  269. </if>
  270. <if test="sceneType == null or sceneType == 0">
  271. and p.parm_type in (3,5)
  272. </if>
  273. and d.ENABLE_STATE = 1 and d.`STATUS`= 1
  274. AND r.YEAR = #{year} and r.month=#{month}
  275. <if test="sceneIds != null and sceneIds.size()>0">
  276. and p.PARENT_SCENE_ID in
  277. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  278. #{item}
  279. </foreach>
  280. </if>
  281. <if test="tenantId != null and tenantId != '' ">
  282. and d.tenant_id = #{tenantId}
  283. </if>
  284. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  285. <if test="permissonType == 5 or permissonType == 2">
  286. and ( d.DEPT_ORG_ID in
  287. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  288. #{item.orgId}
  289. </foreach>
  290. or
  291. d.COMPANY_ORG_ID in
  292. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  293. #{item.orgId}
  294. </foreach>
  295. )
  296. </if>
  297. <if test="permissonType == 4 or permissonType == 3">
  298. and d.DEPT_ORG_ID in
  299. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  300. #{item.orgId}
  301. </foreach>
  302. </if>
  303. <if test="permissonType == 1">
  304. and d.COMPANY_ORG_ID in
  305. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  306. #{item.orgId}
  307. </foreach>
  308. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  309. </if>
  310. </if>
  311. GROUP BY s.SCENE_NAME,p.parm_type,da.unit,r.day
  312. order by r.`day` asc
  313. </select>
  314. <select id="MonitorDataEnergyReportByYear" resultMap="MonitorDataChartReportMap">
  315. SELECT
  316. r.`month` AS "dateLabel",
  317. <if test="sceneType != null and sceneType == 1">
  318. IF( p.parm_type = 5, '耗电量','取水量' ) AS "attributeName",
  319. </if>
  320. <if test="sceneType == null or sceneType == 0">
  321. IF( p.parm_type = 5, '耗电量','用水量' ) AS "attributeName",
  322. </if>
  323. s.SCENE_NAME AS "deviceName",
  324. p.parm_type AS "attributeType",
  325. da.unit AS "unit",
  326. ifnull( ROUND( sum( r.SUM_VALUE ), 2 ), 0 ) AS "data",
  327. max( r.COLLECT_DATE ) AS "date"
  328. FROM sms_device_parm p
  329. LEFT JOIN sms_year_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  330. left join sms_scene s on s.id=p.parent_scene_id
  331. left join sms_device_attribute da ON da.id = p.ATTRIBUTE_ID
  332. LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
  333. WHERE p.`STATUS`= 1
  334. <if test="sceneType != null and sceneType == 1">
  335. and p.parm_type in (4,5)
  336. </if>
  337. <if test="sceneType == null or sceneType == 0">
  338. and p.parm_type in (3,5)
  339. </if>
  340. and d.ENABLE_STATE = 1 and d.`STATUS`= 1
  341. AND r.YEAR = #{year}
  342. <if test="sceneIds != null and sceneIds.size()>0">
  343. and p.PARENT_SCENE_ID in
  344. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  345. #{item}
  346. </foreach>
  347. </if>
  348. <if test="tenantId != null and tenantId != '' ">
  349. and d.tenant_id = #{tenantId}
  350. </if>
  351. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  352. <if test="permissonType == 5 or permissonType == 2">
  353. and ( d.DEPT_ORG_ID in
  354. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  355. #{item.orgId}
  356. </foreach>
  357. or
  358. d.COMPANY_ORG_ID in
  359. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  360. #{item.orgId}
  361. </foreach>
  362. )
  363. </if>
  364. <if test="permissonType == 4 or permissonType == 3">
  365. and d.DEPT_ORG_ID in
  366. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  367. #{item.orgId}
  368. </foreach>
  369. </if>
  370. <if test="permissonType == 1">
  371. and d.COMPANY_ORG_ID in
  372. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  373. #{item.orgId}
  374. </foreach>
  375. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  376. </if>
  377. </if>
  378. GROUP BY s.SCENE_NAME,p.parm_type,da.unit,r.month
  379. order by r.`month` asc
  380. </select>
  381. <!-- 对比————PH、余氯、浊度 -->
  382. <select id="MonitorDataQualityReportByDay" resultMap="MonitorDataChartReportMap">
  383. SELECT
  384. r.`HOUR` AS "dateLabel",
  385. if(p.parm_type=7,'PH',if(p.parm_type=11,'余氯','浊度')) as "attributeName",
  386. s.SCENE_NAME AS "deviceName",
  387. p.parm_type AS "attributeType",
  388. da.unit AS "unit",
  389. ifnull( ROUND( sum( r.SUM_VALUE ), 2 ), 0 ) AS "data",
  390. max( r.COLLECT_DATE ) AS "date"
  391. FROM sms_device_parm p
  392. LEFT JOIN sms_day_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  393. left join sms_scene s on s.id=p.parent_scene_id
  394. left join sms_device_attribute da ON da.id = p.ATTRIBUTE_ID
  395. LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
  396. WHERE p.`STATUS`= 1 and p.parm_type in (7,11,9) and d.ENABLE_STATE = 1 and d.`STATUS`= 1
  397. AND r.YEAR = #{year} and r.month=#{month} and r.day=#{day}
  398. <if test="sceneIds != null and sceneIds.size()>0">
  399. and p.PARENT_SCENE_ID in
  400. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  401. #{item}
  402. </foreach>
  403. </if>
  404. <if test="tenantId != null and tenantId != '' ">
  405. and d.tenant_id = #{tenantId}
  406. </if>
  407. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  408. <if test="permissonType == 5 or permissonType == 2">
  409. and ( d.DEPT_ORG_ID in
  410. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  411. #{item.orgId}
  412. </foreach>
  413. or
  414. d.COMPANY_ORG_ID in
  415. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  416. #{item.orgId}
  417. </foreach>
  418. )
  419. </if>
  420. <if test="permissonType == 4 or permissonType == 3">
  421. and d.DEPT_ORG_ID in
  422. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  423. #{item.orgId}
  424. </foreach>
  425. </if>
  426. <if test="permissonType == 1">
  427. and d.COMPANY_ORG_ID in
  428. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  429. #{item.orgId}
  430. </foreach>
  431. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  432. </if>
  433. </if>
  434. GROUP BY s.SCENE_NAME,p.parm_type,da.unit,r.HOUR
  435. order by r.`hour` asc
  436. </select>
  437. <select id="MonitorDataQualityReportByMonth" resultMap="MonitorDataChartReportMap">
  438. SELECT
  439. r.`day` AS "dateLabel",
  440. if(p.parm_type=7,'PH',if(p.parm_type=11,'余氯','浊度')) as "attributeName",
  441. s.SCENE_NAME AS "deviceName",
  442. p.parm_type AS "attributeType",
  443. da.unit AS "unit",
  444. ifnull( ROUND( sum( r.SUM_VALUE ), 2 ), 0 ) AS "data",
  445. max( r.COLLECT_DATE ) AS "date"
  446. FROM sms_device_parm p
  447. LEFT JOIN sms_month_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  448. left join sms_scene s on s.id=p.parent_scene_id
  449. left join sms_device_attribute da ON da.id = p.ATTRIBUTE_ID
  450. LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
  451. WHERE p.`STATUS`= 1 and p.parm_type in (7,11,9) and d.ENABLE_STATE = 1 and d.`STATUS`= 1
  452. AND r.YEAR = #{year} and r.month=#{month}
  453. <if test="sceneIds != null and sceneIds.size()>0">
  454. and p.PARENT_SCENE_ID in
  455. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  456. #{item}
  457. </foreach>
  458. </if>
  459. <if test="tenantId != null and tenantId != '' ">
  460. and d.tenant_id = #{tenantId}
  461. </if>
  462. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  463. <if test="permissonType == 5 or permissonType == 2">
  464. and ( d.DEPT_ORG_ID in
  465. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  466. #{item.orgId}
  467. </foreach>
  468. or
  469. d.COMPANY_ORG_ID in
  470. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  471. #{item.orgId}
  472. </foreach>
  473. )
  474. </if>
  475. <if test="permissonType == 4 or permissonType == 3">
  476. and d.DEPT_ORG_ID in
  477. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  478. #{item.orgId}
  479. </foreach>
  480. </if>
  481. <if test="permissonType == 1">
  482. and d.COMPANY_ORG_ID in
  483. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  484. #{item.orgId}
  485. </foreach>
  486. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  487. </if>
  488. </if>
  489. GROUP BY s.SCENE_NAME,p.parm_type,da.unit,r.day
  490. order by r.`day` asc
  491. </select>
  492. <select id="MonitorDataQualityReportByYear" resultMap="MonitorDataChartReportMap">
  493. SELECT
  494. r.`month` AS "dateLabel",
  495. if(p.parm_type=7,'PH',if(p.parm_type=11,'余氯','浊度')) as "attributeName",
  496. s.SCENE_NAME AS "deviceName",
  497. p.parm_type AS "attributeType",
  498. da.unit AS "unit",
  499. ifnull( ROUND( sum( r.SUM_VALUE ), 2 ), 0 ) AS "data",
  500. max( r.COLLECT_DATE ) AS "date"
  501. FROM sms_device_parm p
  502. LEFT JOIN sms_year_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  503. left join sms_scene s on s.id=p.parent_scene_id
  504. left join sms_device_attribute da ON da.id = p.ATTRIBUTE_ID
  505. LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
  506. WHERE p.`STATUS`= 1 and p.parm_type in (7,11,9)
  507. AND r.YEAR = #{year} and d.ENABLE_STATE = 1 and d.`STATUS`= 1
  508. <if test="sceneIds != null and sceneIds.size()>0">
  509. and p.PARENT_SCENE_ID in
  510. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  511. #{item}
  512. </foreach>
  513. </if>
  514. <if test="tenantId != null and tenantId != '' ">
  515. and d.tenant_id = #{tenantId}
  516. </if>
  517. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  518. <if test="permissonType == 5 or permissonType == 2">
  519. and ( d.DEPT_ORG_ID in
  520. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  521. #{item.orgId}
  522. </foreach>
  523. or
  524. d.COMPANY_ORG_ID in
  525. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  526. #{item.orgId}
  527. </foreach>
  528. )
  529. </if>
  530. <if test="permissonType == 4 or permissonType == 3">
  531. and d.DEPT_ORG_ID in
  532. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  533. #{item.orgId}
  534. </foreach>
  535. </if>
  536. <if test="permissonType == 1">
  537. and d.COMPANY_ORG_ID in
  538. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  539. #{item.orgId}
  540. </foreach>
  541. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  542. </if>
  543. </if>
  544. GROUP BY s.SCENE_NAME,p.parm_type,da.unit,r.month
  545. order by r.`month` asc
  546. </select>
  547. <!-- 对比————报警 -->
  548. <select id="DeviceAlarmReport" resultMap="MonitorDataChartReportMap">
  549. select
  550. a.*,DATE_ADD(#{beginDate},INTERVAL a.dateLabel-1 ${dateType}) as "date"
  551. from (
  552. select
  553. ${dateType}(ad.ALARM_START_TIME) as "dateLabel"
  554. <if test="dateType != null and dateType == 'month'">
  555. ,DATE_FORMAT(max(ad.ALARM_START_TIME),'%Y-%m') as "dateStringLabel"
  556. </if>
  557. <if test="dateType != null and dateType == 'day'">
  558. ,DATE_FORMAT(max(ad.ALARM_START_TIME),'%Y-%m-%d') as "dateStringLabel"
  559. </if>
  560. <if test="dateType != null and dateType == 'hour'">
  561. ,DATE_FORMAT(max(ad.ALARM_START_TIME),'%Y-%m-%d %H:00') as "dateStringLabel"
  562. </if>
  563. ,ad.PARENT_SCENE_NAME as "deviceName"
  564. ,'报警次数' as "attributeName"
  565. ,count(1) as "monitorData"
  566. ,count(1) as "data"
  567. from sms_alarm_details ad
  568. left join sms_device d on ad.DEVICE_ID=d.ID
  569. where ad.ALARM_START_TIME &lt; #{endDate} and ad.ALARM_START_TIME >= #{beginDate} and d.ENABLE_STATE = 1 and d.`STATUS`= 1
  570. <if test="sceneIds != null and sceneIds.size()>0">
  571. and ad.parent_scene_id in
  572. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  573. #{item}
  574. </foreach>
  575. </if>
  576. <if test="tenantId != null and tenantId != '' ">
  577. and d.tenant_id = #{tenantId}
  578. </if>
  579. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  580. <if test="permissonType == 5 or permissonType == 2">
  581. and ( d.DEPT_ORG_ID in
  582. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  583. #{item.orgId}
  584. </foreach>
  585. or
  586. d.COMPANY_ORG_ID in
  587. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  588. #{item.orgId}
  589. </foreach>
  590. )
  591. </if>
  592. <if test="permissonType == 4 or permissonType == 3">
  593. and d.DEPT_ORG_ID in
  594. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  595. #{item.orgId}
  596. </foreach>
  597. </if>
  598. <if test="permissonType == 1">
  599. and d.COMPANY_ORG_ID in
  600. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  601. #{item.orgId}
  602. </foreach>
  603. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  604. </if>
  605. </if>
  606. group by ad.PARENT_SCENE_NAME,${dateType}(ad.ALARM_START_TIME)
  607. )a
  608. order by deviceName,dateLabel
  609. </select>
  610. <!-- 根据场景类型查询设备-->
  611. <select id="getDeviceBySceneTypeName" resultType="com.huaxu.entity.DeviceEntity">
  612. select
  613. distinct d.DEVICE_NAME as "deviceName",d.id
  614. from sms_scene_type st
  615. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  616. left join sms_device_scene ds on ds.SCENE_ID=s.ID
  617. left join sms_device d on d.id=ds.DEVICE_ID
  618. where st.SCENE_TYPE_NAME=#{sceneTypeName} and d.`STATUS`= 1 and d.ENABLE_STATE = 1
  619. <if test="tenantId != null and tenantId != '' ">
  620. and d.tenant_id = #{tenantId}
  621. </if>
  622. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  623. <if test="permissonType == 5 or permissonType == 2">
  624. and ( d.DEPT_ORG_ID in
  625. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  626. #{item.orgId}
  627. </foreach>
  628. or
  629. d.COMPANY_ORG_ID in
  630. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  631. #{item.orgId}
  632. </foreach>
  633. )
  634. </if>
  635. <if test="permissonType == 4 or permissonType == 3">
  636. and d.DEPT_ORG_ID in
  637. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  638. #{item.orgId}
  639. </foreach>
  640. </if>
  641. <if test="permissonType == 1">
  642. and d.COMPANY_ORG_ID in
  643. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  644. #{item.orgId}
  645. </foreach>
  646. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  647. </if>
  648. </if>
  649. </select>
  650. <!-- 设备报表 -->
  651. <select id="MonitorDataDeviceReportByDay" resultMap="MonitorDataChartReportMap">
  652. SELECT
  653. d.DEVICE_NAME AS "deviceName",
  654. p.parm_type AS "attributeType",
  655. IF( p.parm_type = 13, '压力',
  656. IF( p.parm_type = 14, '瞬时流量',
  657. IF( p.parm_type = 16, '流速',
  658. IF( p.parm_type = 7, 'PH',
  659. IF( p.parm_type = 15, 'COD',
  660. IF( p.parm_type = 9, '浊度',
  661. IF( p.parm_type = 11, '余氯', '' )))))))
  662. AS "attributeName",
  663. da.unit AS "unit",
  664. r.`HOUR` AS "dateLabel",
  665. ifnull( ROUND( sum( r.AVG_VALUE ), 2 ), 0 ) AS "data",
  666. max( r.COLLECT_DATE ) AS "date"
  667. FROM sms_device_parm p
  668. LEFT JOIN sms_day_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  669. left join sms_device_attribute da ON da.id = p.ATTRIBUTE_ID
  670. LEFT JOIN sms_device d ON d.id = p.DEVICE_ID
  671. WHERE p.`STATUS`= 1 and d.ENABLE_STATE = 1 and d.`STATUS`= 1
  672. AND r.YEAR = #{year} and r.month=#{month} and r.day=#{day}
  673. <if test="searchType != null and searchType == 1">
  674. and p.parm_type = 13
  675. </if>
  676. <if test="searchType != null and searchType == 2">
  677. and p.parm_type in (14,16)
  678. </if>
  679. <if test="searchType != null and searchType == 3">
  680. and p.parm_type in (7,9,11,15)
  681. </if>
  682. <if test="deviceIds != null and deviceIds.size()>0">
  683. and d.id in
  684. <foreach collection="deviceIds" item="item" open="(" close=")" separator=",">
  685. #{item}
  686. </foreach>
  687. </if>
  688. <if test="tenantId != null and tenantId != '' ">
  689. and d.tenant_id = #{tenantId}
  690. </if>
  691. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  692. <if test="permissonType == 5 or permissonType == 2">
  693. and ( d.DEPT_ORG_ID in
  694. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  695. #{item.orgId}
  696. </foreach>
  697. or
  698. d.COMPANY_ORG_ID in
  699. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  700. #{item.orgId}
  701. </foreach>
  702. )
  703. </if>
  704. <if test="permissonType == 4 or permissonType == 3">
  705. and d.DEPT_ORG_ID in
  706. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  707. #{item.orgId}
  708. </foreach>
  709. </if>
  710. <if test="permissonType == 1">
  711. and d.COMPANY_ORG_ID in
  712. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  713. #{item.orgId}
  714. </foreach>
  715. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  716. </if>
  717. </if>
  718. GROUP BY d.DEVICE_NAME, p.parm_type,da.unit,r.HOUR
  719. order by r.`hour` asc
  720. </select>
  721. <select id="MonitorDataDeviceReportByMonth" resultMap="MonitorDataChartReportMap">
  722. SELECT
  723. d.DEVICE_NAME AS "deviceName",
  724. p.parm_type AS "attributeType",
  725. IF( p.parm_type = 13, '压力',
  726. IF( p.parm_type = 14, '瞬时流量',
  727. IF( p.parm_type = 16, '流速',
  728. IF( p.parm_type = 7, 'PH',
  729. IF( p.parm_type = 15, 'COD',
  730. IF( p.parm_type = 9, '浊度',
  731. IF( p.parm_type = 11, '余氯', '' )))))))
  732. AS "attributeName",
  733. da.unit AS "unit",
  734. r.`day` AS "dateLabel",
  735. ifnull( ROUND( sum( r.AVG_VALUE ), 2 ), 0 ) AS "data",
  736. max( r.COLLECT_DATE ) AS "date"
  737. FROM sms_device_parm p
  738. LEFT JOIN sms_month_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  739. left join sms_device_attribute da ON da.id = p.ATTRIBUTE_ID
  740. LEFT JOIN sms_device d ON d.id = p.DEVICE_ID
  741. WHERE p.`STATUS`= 1 and d.ENABLE_STATE = 1
  742. AND r.YEAR = #{year} and r.month=#{month}
  743. <if test="searchType != null and searchType == 1">
  744. and p.parm_type = 13
  745. </if>
  746. <if test="searchType != null and searchType == 2">
  747. and p.parm_type in (14,16)
  748. </if>
  749. <if test="searchType != null and searchType == 3">
  750. and p.parm_type in (7,9,11,15)
  751. </if>
  752. <if test="deviceIds != null and deviceIds.size()>0">
  753. and d.id in
  754. <foreach collection="deviceIds" item="item" open="(" close=")" separator=",">
  755. #{item}
  756. </foreach>
  757. </if>
  758. <if test="tenantId != null and tenantId != '' ">
  759. and d.tenant_id = #{tenantId}
  760. </if>
  761. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  762. <if test="permissonType == 5 or permissonType == 2">
  763. and ( d.DEPT_ORG_ID in
  764. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  765. #{item.orgId}
  766. </foreach>
  767. or
  768. d.COMPANY_ORG_ID in
  769. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  770. #{item.orgId}
  771. </foreach>
  772. )
  773. </if>
  774. <if test="permissonType == 4 or permissonType == 3">
  775. and d.DEPT_ORG_ID in
  776. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  777. #{item.orgId}
  778. </foreach>
  779. </if>
  780. <if test="permissonType == 1">
  781. and d.COMPANY_ORG_ID in
  782. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  783. #{item.orgId}
  784. </foreach>
  785. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  786. </if>
  787. </if>
  788. GROUP BY d.DEVICE_NAME, p.parm_type,da.unit,r.day
  789. order by r.day asc
  790. </select>
  791. <select id="MonitorDataDeviceReportByYear" resultMap="MonitorDataChartReportMap">
  792. SELECT
  793. d.DEVICE_NAME AS "deviceName",
  794. p.parm_type AS "attributeType",
  795. IF( p.parm_type = 13, '压力',
  796. IF( p.parm_type = 14, '瞬时流量',
  797. IF( p.parm_type = 16, '流速',
  798. IF( p.parm_type = 7, 'PH',
  799. IF( p.parm_type = 15, 'COD',
  800. IF( p.parm_type = 9, '浊度',
  801. IF( p.parm_type = 11, '余氯', '' )))))))
  802. AS "attributeName",
  803. da.unit AS "unit",
  804. r.month AS "dateLabel",
  805. ifnull( ROUND( sum( r.AVG_VALUE ), 2 ), 0 ) AS "data",
  806. max( r.COLLECT_DATE ) AS "date"
  807. FROM sms_device_parm p
  808. LEFT JOIN sms_year_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
  809. left join sms_device_attribute da ON da.id = p.ATTRIBUTE_ID
  810. LEFT JOIN sms_device d ON d.id = p.DEVICE_ID
  811. WHERE p.`STATUS`= 1 and d.ENABLE_STATE = 1
  812. AND r.YEAR = #{year}
  813. <if test="searchType != null and searchType == 1">
  814. and p.parm_type = 13
  815. </if>
  816. <if test="searchType != null and searchType == 2">
  817. and p.parm_type in (14,16)
  818. </if>
  819. <if test="searchType != null and searchType == 3">
  820. and p.parm_type in (7,9,11,15)
  821. </if>
  822. <if test="deviceIds != null and deviceIds.size()>0">
  823. and d.id in
  824. <foreach collection="deviceIds" item="item" open="(" close=")" separator=",">
  825. #{item}
  826. </foreach>
  827. </if>
  828. <if test="tenantId != null and tenantId != '' ">
  829. and d.tenant_id = #{tenantId}
  830. </if>
  831. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  832. <if test="permissonType == 5 or permissonType == 2">
  833. and ( d.DEPT_ORG_ID in
  834. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  835. #{item.orgId}
  836. </foreach>
  837. or
  838. d.COMPANY_ORG_ID in
  839. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  840. #{item.orgId}
  841. </foreach>
  842. )
  843. </if>
  844. <if test="permissonType == 4 or permissonType == 3">
  845. and d.DEPT_ORG_ID in
  846. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  847. #{item.orgId}
  848. </foreach>
  849. </if>
  850. <if test="permissonType == 1">
  851. and d.COMPANY_ORG_ID in
  852. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  853. #{item.orgId}
  854. </foreach>
  855. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  856. </if>
  857. </if>
  858. GROUP BY d.DEVICE_NAME, p.parm_type,da.unit,r.month
  859. order by r.`month` asc
  860. </select>
  861. <!-- 概览页 -->
  862. <select id="selectDeviceCode" resultType="java.lang.String">
  863. select DEVICE_CODE from sms_device
  864. where STATUS =1 and ENABLE_STATE =1 and TENANT_ID=#{tenantId}
  865. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  866. <if test="permissonType == 5 or permissonType == 2">
  867. and ( d.DEPT_ORG_ID in
  868. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  869. #{item.orgId}
  870. </foreach>
  871. or
  872. d.COMPANY_ORG_ID in
  873. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  874. #{item.orgId}
  875. </foreach>
  876. )
  877. </if>
  878. <if test="permissonType == 4 or permissonType == 3">
  879. and d.DEPT_ORG_ID in
  880. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  881. #{item.orgId}
  882. </foreach>
  883. </if>
  884. <if test="permissonType == 1">
  885. and d.COMPANY_ORG_ID in
  886. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  887. #{item.orgId}
  888. </foreach>
  889. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  890. </if>
  891. </if>
  892. </select>
  893. <select id="getDeviceWaterFor30Day" resultType="com.huaxu.dto.generalView.DeviceWaterSupply">
  894. select
  895. r.year,r.month,r.day,
  896. sum(r.SUM_VALUE) as "amount"
  897. from sms_scene_type st
  898. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  899. left join sms_device_parm dp on s.id=dp.SCENE_ID
  900. left join sms_month_report r on r.DEVICE_ID= dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID
  901. where dp.`STATUS`=1 and st.SCENE_TYPE_NAME = '水厂'
  902. and dp.PARM_TYPE = 3 and dp.TENANT_ID=#{tenantId}
  903. and r.COLLECT_DATE >= DATE_SUB(CURDATE(),INTERVAL 30 day)
  904. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  905. <if test="permissonType == 5 or permissonType == 2">
  906. and ( s.DEPT_ORG_ID in
  907. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  908. #{item.orgId}
  909. </foreach>
  910. or
  911. s.COMPANY_ORG_ID in
  912. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  913. #{item.orgId}
  914. </foreach>
  915. )
  916. </if>
  917. <if test="permissonType == 4 or permissonType == 3">
  918. and s.DEPT_ORG_ID in
  919. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  920. #{item.orgId}
  921. </foreach>
  922. </if>
  923. <if test="permissonType == 1">
  924. and s.COMPANY_ORG_ID in
  925. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  926. #{item.orgId}
  927. </foreach>
  928. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  929. </if>
  930. </if>
  931. group by r.year,r.month,r.day
  932. order by r.year desc,r.month desc,r.day desc
  933. </select>
  934. <select id="getDeviceWaterDetailForNow" resultType="com.huaxu.dto.generalView.DeviceWaterDetail">
  935. select
  936. s.SCENE_NAME as "sceneName"
  937. ,dp.DEVICE_ID as "deviceId"
  938. ,dp.ATTRIBUTE_ID as "attributeId"
  939. ,dp.PARM_TYPE as "parmType"
  940. from sms_scene_type st
  941. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  942. left join sms_device_parm dp on s.id=dp.SCENE_ID
  943. where dp.`STATUS`=1 and st.SCENE_TYPE_NAME = #{sceneTypeName}
  944. and dp.PARM_TYPE =#{parmType} and dp.TENANT_ID=#{tenantId}
  945. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  946. <if test="permissonType == 5 or permissonType == 2">
  947. and ( s.DEPT_ORG_ID in
  948. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  949. #{item.orgId}
  950. </foreach>
  951. or
  952. s.COMPANY_ORG_ID in
  953. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  954. #{item.orgId}
  955. </foreach>
  956. )
  957. </if>
  958. <if test="permissonType == 4 or permissonType == 3">
  959. and s.DEPT_ORG_ID in
  960. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  961. #{item.orgId}
  962. </foreach>
  963. </if>
  964. <if test="permissonType == 1">
  965. and s.COMPANY_ORG_ID in
  966. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  967. #{item.orgId}
  968. </foreach>
  969. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  970. </if>
  971. </if>
  972. </select>
  973. <select id="getDeviceWaterDetailForDay" resultType="com.huaxu.dto.generalView.DeviceWaterDetail">
  974. select
  975. s.SCENE_NAME as "sceneName"
  976. ,dp.DEVICE_ID as "deviceId"
  977. ,dp.ATTRIBUTE_ID as "attributeId"
  978. ,dp.PARM_TYPE as "parmType"
  979. ,max(ifnull(r.LATEST_VALUE,0)) as "latestValue"
  980. ,sum(ifnull(r.SUM_VALUE,0)) as "amount"
  981. from sms_scene_type st
  982. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  983. left join sms_device_parm dp on s.id=dp.PARENT_SCENE_ID
  984. left join sms_day_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}
  985. where dp.`STATUS`=1 and st.SCENE_TYPE_NAME = #{sceneTypeName}
  986. and dp.PARM_TYPE =#{parmType} and dp.TENANT_ID=#{tenantId}
  987. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  988. <if test="permissonType == 5 or permissonType == 2">
  989. and ( s.DEPT_ORG_ID in
  990. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  991. #{item.orgId}
  992. </foreach>
  993. or
  994. s.COMPANY_ORG_ID in
  995. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  996. #{item.orgId}
  997. </foreach>
  998. )
  999. </if>
  1000. <if test="permissonType == 4 or permissonType == 3">
  1001. and s.DEPT_ORG_ID in
  1002. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1003. #{item.orgId}
  1004. </foreach>
  1005. </if>
  1006. <if test="permissonType == 1">
  1007. and s.COMPANY_ORG_ID in
  1008. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1009. #{item.orgId}
  1010. </foreach>
  1011. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  1012. </if>
  1013. </if>
  1014. group by s.SCENE_NAME,dp.DEVICE_ID ,dp.ATTRIBUTE_ID,dp.PARM_TYPE
  1015. </select>
  1016. <select id="getDeviceWaterDetailForMonth" resultType="java.math.BigDecimal">
  1017. select
  1018. sum(ifnull(r.SUM_VALUE,0)) as "amount"
  1019. from sms_scene_type st
  1020. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  1021. left join sms_device_parm dp on s.id=dp.SCENE_ID
  1022. 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}
  1023. where dp.`STATUS`=1 and st.SCENE_TYPE_NAME = #{sceneTypeName}
  1024. and dp.PARM_TYPE =#{parmType} and dp.TENANT_ID=#{tenantId}
  1025. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  1026. <if test="permissonType == 5 or permissonType == 2">
  1027. and ( s.DEPT_ORG_ID in
  1028. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1029. #{item.orgId}
  1030. </foreach>
  1031. or
  1032. s.COMPANY_ORG_ID in
  1033. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1034. #{item.orgId}
  1035. </foreach>
  1036. )
  1037. </if>
  1038. <if test="permissonType == 4 or permissonType == 3">
  1039. and s.DEPT_ORG_ID in
  1040. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1041. #{item.orgId}
  1042. </foreach>
  1043. </if>
  1044. <if test="permissonType == 1">
  1045. and s.COMPANY_ORG_ID in
  1046. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1047. #{item.orgId}
  1048. </foreach>
  1049. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  1050. </if>
  1051. </if>
  1052. group by dp.DEVICE_ID ,dp.ATTRIBUTE_ID,dp.PARM_TYPE
  1053. </select>
  1054. <select id="getDeviceWaterDetailForYear" resultType="java.math.BigDecimal">
  1055. select
  1056. sum(ifnull(r.SUM_VALUE,0)) as "amount"
  1057. from sms_scene_type st
  1058. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  1059. left join sms_device_parm dp on s.id=dp.SCENE_ID
  1060. left join sms_year_report r on r.DEVICE_ID= dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID and r.year = #{year}
  1061. where dp.`STATUS`=1 and st.SCENE_TYPE_NAME = #{sceneTypeName}
  1062. and dp.PARM_TYPE =#{parmType} and dp.TENANT_ID=#{tenantId}
  1063. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  1064. <if test="permissonType == 5 or permissonType == 2">
  1065. and ( s.DEPT_ORG_ID in
  1066. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1067. #{item.orgId}
  1068. </foreach>
  1069. or
  1070. s.COMPANY_ORG_ID in
  1071. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1072. #{item.orgId}
  1073. </foreach>
  1074. )
  1075. </if>
  1076. <if test="permissonType == 4 or permissonType == 3">
  1077. and s.DEPT_ORG_ID in
  1078. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1079. #{item.orgId}
  1080. </foreach>
  1081. </if>
  1082. <if test="permissonType == 1">
  1083. and s.COMPANY_ORG_ID in
  1084. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1085. #{item.orgId}
  1086. </foreach>
  1087. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  1088. </if>
  1089. </if>
  1090. group by dp.DEVICE_ID ,dp.ATTRIBUTE_ID,dp.PARM_TYPE
  1091. </select>
  1092. <select id="getAlarmInfoForScene" resultType="com.huaxu.dto.generalView.SceneAlarm">
  1093. select
  1094. s.SCENE_NAME as "sceneName",count(ad.id) as "alarmNumber"
  1095. from sms_scene_type st
  1096. left join sms_scene s on s.SCENE_TYPE_ID =st.id and s.PARENT_SCENE_ID = 0
  1097. left join sms_alarm_details ad on ad.STATE = 1 and ad.PARENT_SCENE_ID=s.id
  1098. where s.`STATUS` = 1 and (st.SCENE_TYPE_NAME = '水厂' or st.SCENE_TYPE_NAME ='水源') and s.TENANT_ID=#{tenantId}
  1099. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  1100. <if test="permissonType == 5 or permissonType == 2">
  1101. and ( s.DEPT_ORG_ID in
  1102. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1103. #{item.orgId}
  1104. </foreach>
  1105. or
  1106. s.COMPANY_ORG_ID in
  1107. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1108. #{item.orgId}
  1109. </foreach>
  1110. )
  1111. </if>
  1112. <if test="permissonType == 4 or permissonType == 3">
  1113. and s.DEPT_ORG_ID in
  1114. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1115. #{item.orgId}
  1116. </foreach>
  1117. </if>
  1118. <if test="permissonType == 1">
  1119. and s.COMPANY_ORG_ID in
  1120. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1121. #{item.orgId}
  1122. </foreach>
  1123. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  1124. </if>
  1125. </if>
  1126. group by s.SCENE_NAME
  1127. having count(ad.id) >0
  1128. </select>
  1129. <select id="getQualificationForScene" resultType="com.huaxu.dto.generalView.SceneNormalRate">
  1130. select
  1131. sum(if(alarmNumber > 0 ,1,0)) as "abnormal",
  1132. sum(if(alarmNumber > 0 ,0,1)) as "normal",
  1133. ROUND(sum(if(alarmNumber > 0 ,0,1))/if(count(1) != 0, count(1),1) * 100,2) as "normalRate"
  1134. from (
  1135. select
  1136. s.SCENE_NAME as "sceneName",count(ad.id) as "alarmNumber"
  1137. from sms_scene_type st
  1138. left join sms_scene s on s.SCENE_TYPE_ID =st.id and PARENT_SCENE_ID ='0'
  1139. left join sms_device_parm dp on dp.PARENT_SCENE_ID =s.ID
  1140. left join sms_alarm_details ad on ad.STATE = 1 and ad.SCENE_ID=dp.SCENE_ID and ad.DEVICE_ID =dp.DEVICE_ID and ad.ATTRIBUTE_ID =dp.ATTRIBUTE_ID
  1141. where s.`STATUS`=1 and st.SCENE_TYPE_NAME = '水厂' and s.TENANT_ID =#{tenantId}
  1142. <if test="parmType != null and parmType == -1">
  1143. and dp.PARM_TYPE in (15,7,9,11,18,19)
  1144. </if>
  1145. <if test="parmType != null and parmType != -1">
  1146. and dp.PARM_TYPE = #{parmType}
  1147. </if>
  1148. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  1149. <if test="permissonType == 5 or permissonType == 2">
  1150. and ( s.DEPT_ORG_ID in
  1151. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1152. #{item.orgId}
  1153. </foreach>
  1154. or
  1155. s.COMPANY_ORG_ID in
  1156. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1157. #{item.orgId}
  1158. </foreach>
  1159. )
  1160. </if>
  1161. <if test="permissonType == 4 or permissonType == 3">
  1162. and s.DEPT_ORG_ID in
  1163. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1164. #{item.orgId}
  1165. </foreach>
  1166. </if>
  1167. <if test="permissonType == 1">
  1168. and s.COMPANY_ORG_ID in
  1169. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1170. #{item.orgId}
  1171. </foreach>
  1172. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  1173. </if>
  1174. </if>
  1175. group by s.SCENE_NAME
  1176. ) a
  1177. </select>
  1178. <select id="getWaterSupplyData" resultType="com.huaxu.dto.generalView.WaterSupplyData">
  1179. select
  1180. r.year
  1181. ,r.month
  1182. ,r.day
  1183. ,dp.PARM_TYPE as "parmType"
  1184. ,sum(r.SUM_VALUE) as "amount"
  1185. ,da.UNIT as "unit"
  1186. from sms_scene_type st
  1187. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  1188. left join sms_device_parm dp on s.id=dp.SCENE_ID
  1189. left join sms_device_attribute da on dp.ATTRIBUTE_ID =da.ID
  1190. left join sms_month_report r on r.DEVICE_ID =dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID
  1191. where dp.`STATUS`=1 and st.SCENE_TYPE_NAME = #{sceneTypeName}
  1192. and r.COLLECT_DATE >= DATE_SUB(CURDATE(),INTERVAL 7 day)
  1193. and dp.PARM_TYPE in (3,5,6) and dp.TENANT_ID=#{tenantId}
  1194. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  1195. <if test="permissonType == 5 or permissonType == 2">
  1196. and ( s.DEPT_ORG_ID in
  1197. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1198. #{item.orgId}
  1199. </foreach>
  1200. or
  1201. s.COMPANY_ORG_ID in
  1202. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1203. #{item.orgId}
  1204. </foreach>
  1205. )
  1206. </if>
  1207. <if test="permissonType == 4 or permissonType == 3">
  1208. and s.DEPT_ORG_ID in
  1209. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1210. #{item.orgId}
  1211. </foreach>
  1212. </if>
  1213. <if test="permissonType == 1">
  1214. and s.COMPANY_ORG_ID in
  1215. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1216. #{item.orgId}
  1217. </foreach>
  1218. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  1219. </if>
  1220. </if>
  1221. group by r.year,r.month,r.day,dp.PARM_TYPE,da.UNIT
  1222. </select>
  1223. </mapper>