MonitorDataReportMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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. <collection property="monitorDataChartReportValue" resultMap="MonitorDataChartReportValue"/>
  13. </resultMap>
  14. <resultMap id="MonitorDataChartReportValue" type="com.huaxu.dto.MonitorDataChartReportValueDto">
  15. <result property="dateLabel" column="dateLabel" />
  16. <result property="monitorData" column="monitorData" />
  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. <select id="MonitorDataChartReport" resultMap="MonitorDataChartReportMap">
  26. select
  27. <if test="type != null and type ==1">
  28. r.`MONTH` as "dateLabel",
  29. </if>
  30. <if test="type != null and type ==2">
  31. r.`DAY` as "dateLabel",
  32. </if>
  33. <if test="type != null and type ==3">
  34. r.`HOUR` as "dateLabel",
  35. </if>
  36. cast(ifnull(r.AVG_VALUE,'') as char)+ifnull(da.UNIT,'') as "monitorData"
  37. ,r.AVG_VALUE as "data"
  38. ,r.COLLECT_DATE as "date"
  39. ,d.DEVICE_CODE as "devoceCode"
  40. ,d.DEVICE_NAME as "deviceName"
  41. ,r.ATTRIBUTE_NAME as "attributeName"
  42. from ${tableName} r
  43. <include refid="MonitorDataReportJoins"/>
  44. where dp.IS_CHART = 1 and r.PARENT_SCENE_ID=#{sceneId}
  45. <if test="year != null">
  46. and r.year=#{year}
  47. </if>
  48. <if test="month != null">
  49. and r.month=#{month}
  50. </if>
  51. <if test="day != null">
  52. and r.day=#{day}
  53. </if>
  54. <if test="tenantId != null and tenantId != '' ">
  55. and d.tenant_id = #{tenantId}
  56. </if>
  57. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  58. <if test="permissonType == 5 or permissonType == 2">
  59. and ( d.DEPT_ORG_ID in
  60. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  61. #{item.orgId}
  62. </foreach>
  63. or
  64. d.COMPANY_ORG_ID in
  65. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  66. #{item.orgId}
  67. </foreach>
  68. )
  69. </if>
  70. <if test="permissonType == 4 or permissonType == 3">
  71. and d.DEPT_ORG_ID in
  72. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  73. #{item.orgId}
  74. </foreach>
  75. </if>
  76. <if test="permissonType == 1">
  77. and d.COMPANY_ORG_ID in
  78. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  79. #{item.orgId}
  80. </foreach>
  81. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  82. </if>
  83. </if>
  84. <if test="type != null and type ==1">
  85. order by d.DEVICE_CODE,r.ATTRIBUTE_NAME,r.`MONTH` asc
  86. </if>
  87. <if test="type != null and type ==2">
  88. order by d.DEVICE_CODE,r.ATTRIBUTE_NAME,r.`DAY` asc
  89. </if>
  90. <if test="type != null and type ==3">
  91. order by d.DEVICE_CODE,r.ATTRIBUTE_NAME,r.`HOUR` asc
  92. </if>
  93. </select>
  94. <select id="MonitorDataEnergyReport" resultMap="MonitorDataChartReportMap">
  95. select
  96. <if test="type != null and type ==1">
  97. r.`MONTH` as "dateLabel",
  98. </if>
  99. <if test="type != null and type ==2">
  100. r.`DAY` as "dateLabel",
  101. </if>
  102. <if test="type != null and type ==3">
  103. r.`HOUR` as "dateLabel",
  104. </if>
  105. cast(ifnull(r.SUM_VALUE,0) as char)+ifnull(da.UNIT,'') as "monitorData"
  106. ,ifnull(r.SUM_VALUE ,0) as "data"
  107. ,r.COLLECT_DATE as "date"
  108. ,d.DEVICE_CODE as "devoceCode"
  109. ,d.DEVICE_NAME as "deviceName"
  110. ,da.ATTRIBUTE_TYPE as "attributeType"
  111. ,if(da.ATTRIBUTE_TYPE=3,'用水量','耗电量') as "attributeName"
  112. <if test="type != null and type ==1">
  113. from sms_year_report r
  114. </if>
  115. <if test="type != null and type ==2">
  116. from sms_month_report r
  117. </if>
  118. <if test="type != null and type ==3">
  119. from sms_day_report r
  120. </if>
  121. <include refid="MonitorDataReportJoins"/>
  122. where (da.ATTRIBUTE_TYPE=3 or da.ATTRIBUTE_TYPE=5)
  123. <if test="sceneIds != null and sceneIds.size()>0">
  124. and r.PARENT_SCENE_ID in
  125. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  126. #{item}
  127. </foreach>
  128. </if>
  129. <if test="tenantId != null and tenantId != '' ">
  130. and d.tenant_id = #{tenantId}
  131. </if>
  132. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  133. <if test="permissonType == 5 or permissonType == 2">
  134. and ( d.DEPT_ORG_ID in
  135. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  136. #{item.orgId}
  137. </foreach>
  138. or
  139. d.COMPANY_ORG_ID in
  140. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  141. #{item.orgId}
  142. </foreach>
  143. )
  144. </if>
  145. <if test="permissonType == 4 or permissonType == 3">
  146. and d.DEPT_ORG_ID in
  147. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  148. #{item.orgId}
  149. </foreach>
  150. </if>
  151. <if test="permissonType == 1">
  152. and d.COMPANY_ORG_ID in
  153. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  154. #{item.orgId}
  155. </foreach>
  156. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  157. </if>
  158. </if>
  159. <if test="type != null and type ==1">
  160. and r.year=#{year}
  161. order by d.DEVICE_CODE,da.ATTRIBUTE_TYPE asc,r.`MONTH` asc
  162. </if>
  163. <if test="type != null and type ==2">
  164. and r.year=#{year} and r.month=#{month}
  165. order by d.DEVICE_CODE,da.ATTRIBUTE_TYPE asc,r.`day` asc
  166. </if>
  167. <if test="type != null and type ==3">
  168. and r.year=#{year} and r.month=#{month} and r.day=#{day}
  169. order by d.DEVICE_CODE,da.ATTRIBUTE_TYPE asc,r.`hour` asc
  170. </if>
  171. </select>
  172. <select id="MonitorDataQualityReport" resultMap="MonitorDataChartReportMap">
  173. select
  174. <if test="type != null and type ==1">
  175. r.`MONTH` as "dateLabel",
  176. </if>
  177. <if test="type != null and type ==2">
  178. r.`DAY` as "dateLabel",
  179. </if>
  180. <if test="type != null and type ==3">
  181. r.`HOUR` as "dateLabel",
  182. </if>
  183. cast(ifnull(r.AVG_VALUE,'') as char)+ifnull(da.UNIT,'') as "monitorData"
  184. ,r.AVG_VALUE as "data"
  185. ,r.COLLECT_DATE as "date"
  186. ,d.DEVICE_CODE as "devoceCode"
  187. ,d.DEVICE_NAME as "deviceName"
  188. ,da.ATTRIBUTE_TYPE as "attributeType"
  189. ,if(da.ATTRIBUTE_TYPE=8,'PH',if(da.ATTRIBUTE_TYPE=11,'余氯','浊度')) as "attributeName"
  190. <if test="type != null and type ==1">
  191. from sms_year_report r
  192. </if>
  193. <if test="type != null and type ==2">
  194. from sms_month_report r
  195. </if>
  196. <if test="type != null and type ==3">
  197. from sms_day_report r
  198. </if>
  199. <include refid="MonitorDataReportJoins"/>
  200. where (da.ATTRIBUTE_TYPE=8 or da.ATTRIBUTE_TYPE=11 or da.ATTRIBUTE_TYPE=10)
  201. <if test="sceneIds != null and sceneIds.size()>0">
  202. and r.PARENT_SCENE_ID in
  203. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  204. #{item}
  205. </foreach>
  206. </if>
  207. <if test="tenantId != null and tenantId != '' ">
  208. and d.tenant_id = #{tenantId}
  209. </if>
  210. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  211. <if test="permissonType == 5 or permissonType == 2">
  212. and ( d.DEPT_ORG_ID in
  213. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  214. #{item.orgId}
  215. </foreach>
  216. or
  217. d.COMPANY_ORG_ID in
  218. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  219. #{item.orgId}
  220. </foreach>
  221. )
  222. </if>
  223. <if test="permissonType == 4 or permissonType == 3">
  224. and d.DEPT_ORG_ID in
  225. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  226. #{item.orgId}
  227. </foreach>
  228. </if>
  229. <if test="permissonType == 1">
  230. and d.COMPANY_ORG_ID in
  231. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  232. #{item.orgId}
  233. </foreach>
  234. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  235. </if>
  236. </if>
  237. <if test="type != null and type ==1">
  238. and r.year=#{year}
  239. order by d.DEVICE_CODE,da.ATTRIBUTE_TYPE asc,r.`MONTH` asc
  240. </if>
  241. <if test="type != null and type ==2">
  242. and r.year=#{year} and r.month=#{month}
  243. order by d.DEVICE_CODE,da.ATTRIBUTE_TYPE asc,r.`day` asc
  244. </if>
  245. <if test="type != null and type ==3">
  246. and r.year=#{year} and r.month=#{month} and r.day=#{day}
  247. order by d.DEVICE_CODE,da.ATTRIBUTE_TYPE asc,r.`hour` asc
  248. </if>
  249. </select>
  250. <select id="DeviceAlarmReport" resultMap="MonitorDataChartReportMap">
  251. select
  252. a.*,DATE_ADD(#{beginDate},INTERVAL a.dateLabel ${dateType}) as "date"
  253. from (
  254. select
  255. ${dateType}(ad.ALARM_START_TIME) as "dateLabel"
  256. ,count(1) as "monitorData"
  257. ,count(1) as "data"
  258. ,d.DEVICE_CODE as "devoceCode"
  259. ,d.DEVICE_NAME as "deviceName"
  260. ,'报警次数' as "attributeName"
  261. from sms_alarm_details ad
  262. left join sms_device d on ad.DEVICE_ID=d.ID
  263. left join sms_scene s on s.id = d.SCENE_ID and s.`STATUS` = 1
  264. left join sms_scene ps on s.PARENT_SCENE_IDS LIKE concat('%,', ps.id ,',%') and ps.PARENT_SCENE_ID ='0' and ps.`STATUS` = 1
  265. where ad.ALARM_START_TIME &lt; #{endDate} and ad.ALARM_START_TIME >= #{beginDate}
  266. <if test="sceneIds != null and sceneIds.size()>0">
  267. and ps.id in
  268. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  269. #{item}
  270. </foreach>
  271. </if>
  272. <if test="tenantId != null and tenantId != '' ">
  273. and d.tenant_id = #{tenantId}
  274. </if>
  275. <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
  276. <if test="permissonType == 5 or permissonType == 2">
  277. and ( d.DEPT_ORG_ID in
  278. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  279. #{item.orgId}
  280. </foreach>
  281. or
  282. d.COMPANY_ORG_ID in
  283. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  284. #{item.orgId}
  285. </foreach>
  286. )
  287. </if>
  288. <if test="permissonType == 4 or permissonType == 3">
  289. and d.DEPT_ORG_ID in
  290. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  291. #{item.orgId}
  292. </foreach>
  293. </if>
  294. <if test="permissonType == 1">
  295. and d.COMPANY_ORG_ID in
  296. <foreach collection="programItems" item="item" open="(" close=")" separator=",">
  297. #{item.orgId}
  298. </foreach>
  299. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  300. </if>
  301. </if>
  302. group by d.DEVICE_CODE,d.DEVICE_NAME,${dateType}(ad.ALARM_START_TIME)
  303. )a
  304. order by devoceCode,deviceName,dateLabel
  305. </select>
  306. </mapper>