MonitorDataReportMapper.xml 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259
  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 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="getDeviceWaterFor30Day" resultType="com.huaxu.dto.generalView.DeviceWaterSupply">
  889. select
  890. r.year,r.month,r.day,
  891. sum(r.SUM_VALUE) as "amount"
  892. from sms_scene_type st
  893. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  894. left join sms_device_parm dp on s.id=dp.SCENE_ID
  895. left join sms_month_report r on r.DEVICE_ID= dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID
  896. where dp.`STATUS`=1 and st.SCENE_TYPE_NAME = '水厂'
  897. and dp.PARM_TYPE = 3 and dp.TENANT_ID=#{tenantId}
  898. and r.COLLECT_DATE >= DATE_SUB(CURDATE(),INTERVAL 30 day)
  899. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  900. <if test="permissonType == 5 or permissonType == 2">
  901. and ( s.DEPT_ORG_ID in
  902. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  903. #{item.orgId}
  904. </foreach>
  905. or
  906. s.COMPANY_ORG_ID in
  907. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  908. #{item.orgId}
  909. </foreach>
  910. )
  911. </if>
  912. <if test="permissonType == 4 or permissonType == 3">
  913. and s.DEPT_ORG_ID in
  914. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  915. #{item.orgId}
  916. </foreach>
  917. </if>
  918. <if test="permissonType == 1">
  919. and s.COMPANY_ORG_ID in
  920. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  921. #{item.orgId}
  922. </foreach>
  923. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  924. </if>
  925. </if>
  926. group by r.year,r.month,r.day
  927. order by r.year desc,r.month desc,r.day desc
  928. </select>
  929. <select id="getDeviceWaterDetailForNow" resultType="com.huaxu.dto.generalView.DeviceWaterDetail">
  930. select
  931. s.SCENE_NAME as "sceneName"
  932. ,dp.DEVICE_ID as "deviceId"
  933. ,dp.ATTRIBUTE_ID as "attributeId"
  934. ,dp.PARM_TYPE as "parmType"
  935. from sms_scene_type st
  936. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  937. left join sms_device_parm dp on s.id=dp.SCENE_ID
  938. where dp.`STATUS`=1 and st.SCENE_TYPE_NAME = #{sceneTypeName}
  939. and dp.PARM_TYPE =#{parmType} and dp.TENANT_ID=#{tenantId}
  940. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  941. <if test="permissonType == 5 or permissonType == 2">
  942. and ( s.DEPT_ORG_ID in
  943. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  944. #{item.orgId}
  945. </foreach>
  946. or
  947. s.COMPANY_ORG_ID in
  948. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  949. #{item.orgId}
  950. </foreach>
  951. )
  952. </if>
  953. <if test="permissonType == 4 or permissonType == 3">
  954. and s.DEPT_ORG_ID in
  955. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  956. #{item.orgId}
  957. </foreach>
  958. </if>
  959. <if test="permissonType == 1">
  960. and s.COMPANY_ORG_ID in
  961. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  962. #{item.orgId}
  963. </foreach>
  964. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  965. </if>
  966. </if>
  967. </select>
  968. <select id="getDeviceWaterDetailForDay" resultType="com.huaxu.dto.generalView.DeviceWaterDetail">
  969. select
  970. s.SCENE_NAME as "sceneName"
  971. ,dp.DEVICE_ID as "deviceId"
  972. ,dp.ATTRIBUTE_ID as "attributeId"
  973. ,dp.PARM_TYPE as "parmType"
  974. ,ifnull(r.LATEST_VALUE,0) as "latestValue"
  975. from sms_scene_type st
  976. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  977. left join sms_device_parm dp on s.id=dp.PARENT_SCENE_ID
  978. 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}
  979. where dp.`STATUS`=1 and st.SCENE_TYPE_NAME = #{sceneTypeName}
  980. and dp.PARM_TYPE =#{parmType} and dp.TENANT_ID=#{tenantId}
  981. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  982. <if test="permissonType == 5 or permissonType == 2">
  983. and ( s.DEPT_ORG_ID in
  984. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  985. #{item.orgId}
  986. </foreach>
  987. or
  988. s.COMPANY_ORG_ID in
  989. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  990. #{item.orgId}
  991. </foreach>
  992. )
  993. </if>
  994. <if test="permissonType == 4 or permissonType == 3">
  995. and s.DEPT_ORG_ID in
  996. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  997. #{item.orgId}
  998. </foreach>
  999. </if>
  1000. <if test="permissonType == 1">
  1001. and s.COMPANY_ORG_ID in
  1002. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1003. #{item.orgId}
  1004. </foreach>
  1005. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  1006. </if>
  1007. </if>
  1008. </select>
  1009. <select id="getDeviceWaterDetailForMonth" resultType="java.math.BigDecimal">
  1010. select
  1011. sum(ifnull(r.SUM_VALUE,0)) as "amount"
  1012. from sms_scene_type st
  1013. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  1014. left join sms_device_parm dp on s.id=dp.SCENE_ID
  1015. 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}
  1016. where dp.`STATUS`=1 and st.SCENE_TYPE_NAME = #{sceneTypeName}
  1017. and dp.PARM_TYPE =#{parmType} and dp.TENANT_ID=#{tenantId}
  1018. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  1019. <if test="permissonType == 5 or permissonType == 2">
  1020. and ( s.DEPT_ORG_ID in
  1021. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1022. #{item.orgId}
  1023. </foreach>
  1024. or
  1025. s.COMPANY_ORG_ID in
  1026. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1027. #{item.orgId}
  1028. </foreach>
  1029. )
  1030. </if>
  1031. <if test="permissonType == 4 or permissonType == 3">
  1032. and s.DEPT_ORG_ID in
  1033. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1034. #{item.orgId}
  1035. </foreach>
  1036. </if>
  1037. <if test="permissonType == 1">
  1038. and s.COMPANY_ORG_ID in
  1039. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1040. #{item.orgId}
  1041. </foreach>
  1042. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  1043. </if>
  1044. </if>
  1045. </select>
  1046. <select id="getDeviceWaterDetailForYear" resultType="java.math.BigDecimal">
  1047. select
  1048. sum(ifnull(r.SUM_VALUE,0)) as "amount"
  1049. from sms_scene_type st
  1050. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  1051. left join sms_device_parm dp on s.id=dp.SCENE_ID
  1052. left join sms_year_report r on r.DEVICE_ID= dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID and r.year = #{year}
  1053. where dp.`STATUS`=1 and st.SCENE_TYPE_NAME = #{sceneTypeName}
  1054. and dp.PARM_TYPE =#{parmType} and dp.TENANT_ID=#{tenantId}
  1055. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  1056. <if test="permissonType == 5 or permissonType == 2">
  1057. and ( s.DEPT_ORG_ID in
  1058. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1059. #{item.orgId}
  1060. </foreach>
  1061. or
  1062. s.COMPANY_ORG_ID in
  1063. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1064. #{item.orgId}
  1065. </foreach>
  1066. )
  1067. </if>
  1068. <if test="permissonType == 4 or permissonType == 3">
  1069. and s.DEPT_ORG_ID in
  1070. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1071. #{item.orgId}
  1072. </foreach>
  1073. </if>
  1074. <if test="permissonType == 1">
  1075. and s.COMPANY_ORG_ID in
  1076. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1077. #{item.orgId}
  1078. </foreach>
  1079. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  1080. </if>
  1081. </if>
  1082. </select>
  1083. <select id="getAlarmInfoForScene" resultType="com.huaxu.dto.generalView.SceneAlarm">
  1084. select
  1085. s.SCENE_NAME as "sceneName",count(ad.id) as "alarmNumber"
  1086. from sms_scene_type st
  1087. left join sms_scene s on s.SCENE_TYPE_ID =st.id and s.PARENT_SCENE_ID = 0
  1088. left join sms_alarm_details ad on ad.STATE = 1 and ad.PARENT_SCENE_ID=s.id
  1089. where s.`STATUS` = 1 and (st.SCENE_TYPE_NAME = '水厂' or st.SCENE_TYPE_NAME ='水源') and s.TENANT_ID=#{tenantId}
  1090. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  1091. <if test="permissonType == 5 or permissonType == 2">
  1092. and ( s.DEPT_ORG_ID in
  1093. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1094. #{item.orgId}
  1095. </foreach>
  1096. or
  1097. s.COMPANY_ORG_ID in
  1098. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1099. #{item.orgId}
  1100. </foreach>
  1101. )
  1102. </if>
  1103. <if test="permissonType == 4 or permissonType == 3">
  1104. and s.DEPT_ORG_ID in
  1105. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1106. #{item.orgId}
  1107. </foreach>
  1108. </if>
  1109. <if test="permissonType == 1">
  1110. and s.COMPANY_ORG_ID in
  1111. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1112. #{item.orgId}
  1113. </foreach>
  1114. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  1115. </if>
  1116. </if>
  1117. group by s.SCENE_NAME
  1118. having count(ad.id) >0
  1119. </select>
  1120. <select id="getQualificationForScene" resultType="com.huaxu.dto.generalView.SceneNormalRate">
  1121. select
  1122. sum(if(alarmNumber > 0 ,1,0)) as "abnormal",
  1123. sum(if(alarmNumber > 0 ,0,1)) as "normal",
  1124. ROUND(sum(if(alarmNumber > 0 ,0,1))/if(count(1) != 0, count(1),1) * 100,2) as "normalRate"
  1125. from (
  1126. select
  1127. s.SCENE_NAME as "sceneName",count(ad.id) as "alarmNumber"
  1128. from sms_scene_type st
  1129. left join sms_scene s on s.SCENE_TYPE_ID =st.id and PARENT_SCENE_ID ='0'
  1130. left join sms_device_parm dp on dp.PARENT_SCENE_ID =s.ID
  1131. 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
  1132. where s.`STATUS`=1 and st.SCENE_TYPE_NAME = '水厂' and s.TENANT_ID =#{tenantId}
  1133. <if test="parmType != null and parmType == -1">
  1134. and dp.PARM_TYPE in (15,8,10,11,18,19)
  1135. </if>
  1136. <if test="parmType != null and parmType != -1">
  1137. and dp.PARM_TYPE = #{parmType}
  1138. </if>
  1139. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  1140. <if test="permissonType == 5 or permissonType == 2">
  1141. and ( s.DEPT_ORG_ID in
  1142. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1143. #{item.orgId}
  1144. </foreach>
  1145. or
  1146. s.COMPANY_ORG_ID in
  1147. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1148. #{item.orgId}
  1149. </foreach>
  1150. )
  1151. </if>
  1152. <if test="permissonType == 4 or permissonType == 3">
  1153. and s.DEPT_ORG_ID in
  1154. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1155. #{item.orgId}
  1156. </foreach>
  1157. </if>
  1158. <if test="permissonType == 1">
  1159. and s.COMPANY_ORG_ID in
  1160. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1161. #{item.orgId}
  1162. </foreach>
  1163. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  1164. </if>
  1165. </if>
  1166. group by s.SCENE_NAME
  1167. ) a
  1168. </select>
  1169. <select id="getWaterSupplyData" resultType="com.huaxu.dto.generalView.WaterSupplyData">
  1170. select
  1171. r.year
  1172. ,r.month
  1173. ,r.day
  1174. ,dp.PARM_TYPE as "parmType"
  1175. ,sum(r.SUM_VALUE) as "amount"
  1176. ,da.UNIT as "unit"
  1177. from sms_scene_type st
  1178. left join sms_scene s on s.SCENE_TYPE_ID =st.id
  1179. left join sms_device_parm dp on s.id=dp.SCENE_ID
  1180. left join sms_device_attribute da on dp.ATTRIBUTE_ID =da.ID
  1181. left join sms_month_report r on r.DEVICE_ID =dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID
  1182. where dp.`STATUS`=1 and st.SCENE_TYPE_NAME = #{sceneTypeName}
  1183. and r.COLLECT_DATE >= DATE_SUB(CURDATE(),INTERVAL 7 day)
  1184. and dp.PARM_TYPE in (3,5,6) and dp.TENANT_ID=#{tenantId}
  1185. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  1186. <if test="permissonType == 5 or permissonType == 2">
  1187. and ( s.DEPT_ORG_ID in
  1188. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1189. #{item.orgId}
  1190. </foreach>
  1191. or
  1192. s.COMPANY_ORG_ID in
  1193. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1194. #{item.orgId}
  1195. </foreach>
  1196. )
  1197. </if>
  1198. <if test="permissonType == 4 or permissonType == 3">
  1199. and s.DEPT_ORG_ID in
  1200. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1201. #{item.orgId}
  1202. </foreach>
  1203. </if>
  1204. <if test="permissonType == 1">
  1205. and s.COMPANY_ORG_ID in
  1206. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  1207. #{item.orgId}
  1208. </foreach>
  1209. and (s.DEPT_ORG_ID is null or s.DEPT_ORG_ID =0)
  1210. </if>
  1211. </if>
  1212. group by r.year,r.month,r.day,dp.PARM_TYPE,da.UNIT
  1213. </select>
  1214. </mapper>