DayReportMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.huaxu.dao.DayReportMapper">
  6. <resultMap type="DayReportEntity" id="DayReportResult">
  7. <result property="id" column="id"/>
  8. <result property="tenantId" column="tenant_id"/>
  9. <result property="year" column="year"/>
  10. <result property="month" column="month"/>
  11. <result property="day" column="day"/>
  12. <result property="hour" column="hour"/>
  13. <result property="parentSceneId" column="parent_scene_id"/>
  14. <result property="parentSceneName" column="parent_scene_name"/>
  15. <result property="sceneId" column="scene_id"/>
  16. <result property="sceneName" column="scene_name"/>
  17. <result property="deviceId" column="device_id"/>
  18. <result property="deviceName" column="device_name"/>
  19. <result property="deviceCode" column="device_code"/>
  20. <result property="attributeId" column="attribute_id"/>
  21. <result property="attributeName" column="attribute_name"/>
  22. <result property="minValue" column="min_value"/>
  23. <result property="maxValue" column="max_value"/>
  24. <result property="avgValue" column="avg_value"/>
  25. <result property="sumValue" column="sum_value"/>
  26. <result property="latestValue" column="latest_value"/>
  27. <result property="collectDate" column="collect_date"/>
  28. <result property="dateCreate" column="date_create"/>
  29. <result property="createBy" column="create_by"/>
  30. <result property="dateUpdate" column="date_update"/>
  31. <result property="updateBy" column="update_by"/>
  32. </resultMap>
  33. <!-- 实体栏位 -->
  34. <sql id="dayReportColumns">
  35. a.id as "id" ,
  36. a.tenant_id as "tenantId" ,
  37. a.year as "year" ,
  38. a.month as "month" ,
  39. a.day as "day" ,
  40. a.hour as "hour" ,
  41. a.parent_scene_id as "parentSceneId" ,
  42. a.parent_scene_name as "parentSceneName" ,
  43. a.scene_id as "sceneId" ,
  44. a.scene_name as "sceneName" ,
  45. a.device_id as "deviceId" ,
  46. a.device_name as "deviceName" ,
  47. a.device_code as "deviceCode" ,
  48. a.attribute_id as "attributeId" ,
  49. a.attribute_name as "attributeName" ,
  50. a.min_value as "minValue" ,
  51. a.max_value as "maxValue" ,
  52. a.avg_value as "avgValue" ,
  53. a.sum_value as "sumValue" ,
  54. a.latest_value as "latestValue" ,
  55. a.collect_date as "collectDate" ,
  56. a.date_create as "dateCreate" ,
  57. a.create_by as "createBy" ,
  58. a.date_update as "dateUpdate" ,
  59. a.update_by as "updateBy"
  60. </sql>
  61. <!-- 根据主键获取实体 -->
  62. <select id="findDayReportById" resultType="com.huaxu.entity.DayReportEntity">
  63. SELECT
  64. <include refid="dayReportColumns"/>
  65. FROM sms_day_report a
  66. WHERE a.id = #{id}
  67. </select>
  68. <!-- 根据获取实体List -->
  69. <select id="findList" resultType="com.huaxu.entity.DayReportEntity">
  70. SELECT
  71. <include refid="dayReportColumns"/>
  72. FROM sms_day_report a
  73. <where>
  74. <if test="tenantId != null and tenantId != ''">and a.tenant_id = #{tenantId}</if>
  75. <if test="year != null ">and a.year = #{year}</if>
  76. <if test="month != null ">and a.month = #{month}</if>
  77. <if test="day != null ">and a.day = #{day}</if>
  78. <if test="hour != null ">and a.hour = #{hour}</if>
  79. <if test="parentSceneId != null ">and a.parent_scene_id = #{parentSceneId}</if>
  80. <if test="sceneId != null ">and a.scene_id = #{sceneId}</if>
  81. <if test="deviceId != null ">and a.device_id = #{deviceId}</if>
  82. <if test="deviceCode != null and deviceCode != ''">and a.device_code = #{deviceCode}</if>
  83. <if test="attributeId != null ">and a.attribute_id = #{attributeId}</if>
  84. <if test="collectDate != null ">and a.collect_date = #{collectDate}</if>
  85. </where>
  86. </select>
  87. <!-- 根据获取实体 page -->
  88. <select id="findPage" resultType="com.huaxu.dto.ReportDto">
  89. SELECT
  90. distinct
  91. a.tenant_id as "tenantId" ,
  92. a.year as "year" ,
  93. a.month as "month" ,
  94. a.day as "day" ,
  95. a.hour as "hour" ,
  96. a.DEVICE_NAME as "deviceName",
  97. b.parent_scene_id as "parentSceneId",
  98. c.SCENE_NAME as "parentSceneName"
  99. FROM sms_day_report a
  100. inner join sms_device_parm b on a.DEVICE_ID = b.DEVICE_ID and a.ATTRIBUTE_ID=b.ATTRIBUTE_ID
  101. <if test="dayReport.typeIds != null">
  102. and b.PARM_TYPE in
  103. <foreach collection="dayReport.typeIds" item="typeId" open="(" close=")" separator=",">
  104. #{typeId}
  105. </foreach>
  106. </if>
  107. and b.`STATUS`=1
  108. inner join sms_scene c on b.PARENT_SCENE_ID=c.id
  109. <where>
  110. b.IS_REPORT=1
  111. <if test="dayReport.tenantId != null and dayReport.tenantId != ''">and a.tenant_id =
  112. #{dayReport.tenantId}
  113. </if>
  114. <if test="dayReport.deviceIds != null and dayReport.deviceIds.size() > 0">
  115. and b.DEVICE_ID in
  116. <foreach collection="dayReport.deviceIds" item="dramaId" open="(" close=")" separator=",">
  117. #{dramaId.id}
  118. </foreach>
  119. </if>
  120. <if test="dayReport.year != null ">and a.year = #{dayReport.year}</if>
  121. <if test="dayReport.month != null ">and a.month = #{dayReport.month}</if>
  122. <if test="dayReport.day != null ">and a.day = #{dayReport.day}</if>
  123. <if test="dayReport.parentSceneIds != null and dayReport.parentSceneIds.length > 0">
  124. and b.parent_scene_id in
  125. <foreach collection="dayReport.parentSceneIds" item="dramaId" open="(" close=")" separator=",">
  126. #{dramaId}
  127. </foreach>
  128. </if>
  129. </where>
  130. order by b.parent_scene_id,a.year,a.month,a.day,a.hour
  131. </select>
  132. <!-- 根据获取实体 page -->
  133. <select id="findPageReprot" resultType="com.huaxu.dto.ReportDto">
  134. SELECT
  135. distinct
  136. a.tenant_id as "tenantId" ,
  137. a.year as "year" ,
  138. a.month as "month" ,
  139. a.day as "day" ,
  140. a.hour as "hour" ,
  141. a.DEVICE_NAME as "deviceName",
  142. b.parent_scene_id as "parentSceneId",
  143. c.SCENE_NAME as "parentSceneName",
  144. a.COLLECT_DATE as "collectDate",
  145. t.SCENE_TYPE_NAME as "sceneTypeName"
  146. FROM sms_day_report a
  147. inner join sms_device_parm b on a.DEVICE_ID = b.DEVICE_ID and a.ATTRIBUTE_ID=b.ATTRIBUTE_ID
  148. <if test="dayReport.typeIds != null">
  149. and b.PARM_TYPE in
  150. <foreach collection="dayReport.typeIds" item="typeId" open="(" close=")" separator=",">
  151. #{typeId}
  152. </foreach>
  153. </if>
  154. and b.`STATUS`=1
  155. inner join sms_scene c on b.PARENT_SCENE_ID=c.id
  156. inner join sms_scene_type t on c.SCENE_TYPE_ID = t.id
  157. <where>
  158. b.IS_REPORT=1
  159. <if test="dayReport.tenantId != null and dayReport.tenantId != ''">and a.tenant_id =
  160. #{dayReport.tenantId}
  161. </if>
  162. <if test="dayReport.deviceIds != null and dayReport.deviceIds.size() > 0">
  163. and b.DEVICE_ID in
  164. <foreach collection="dayReport.deviceIds" item="dramaId" open="(" close=")" separator=",">
  165. #{dramaId.id}
  166. </foreach>
  167. </if>
  168. <if test="dayReport.year != null ">and a.year = #{dayReport.year}</if>
  169. <if test="dayReport.month != null ">and a.month = #{dayReport.month}</if>
  170. <if test="dayReport.day != null ">and a.day = #{dayReport.day}</if>
  171. <if test="dayReport.parentSceneIds != null and dayReport.parentSceneIds.length > 0">
  172. and b.parent_scene_id in
  173. <foreach collection="dayReport.parentSceneIds" item="dramaId" open="(" close=")" separator=",">
  174. #{dramaId}
  175. </foreach>
  176. </if>
  177. </where>
  178. order by b.parent_scene_id,a.year,a.month,a.day,a.hour
  179. </select>
  180. <select id="findAttributeList" resultType="com.huaxu.dto.ReportAttributeDto">
  181. SELECT tab.attributeName,tab.ATTRIBUTE_TYPE,min(tab.minValue) as "minValue",
  182. max(tab.maxValue) as "maxValue",AVG(tab.avgValue)as "avgValue",
  183. AVG(tab.sumValue)as "sumValue",AVG(tab.latestValue) as "latestValue"
  184. from
  185. (SELECT IFNULL(a.REMARK,b.`NAME`) AS "attributeName",
  186. c.min_value as "minValue" ,c.max_value as "maxValue" ,c.avg_value as "avgValue" ,
  187. c.sum_value as "sumValue" ,c.latest_value as "latestValue",
  188. a.PARM_TYPE as ATTRIBUTE_TYPE
  189. FROM sms_device_parm a
  190. INNER JOIN sms_device_attribute b on a.ATTRIBUTE_ID=b.ID
  191. INNER JOIN sms_day_report c on a.ATTRIBUTE_ID=c.ATTRIBUTE_ID and a.DEVICE_ID=c.DEVICE_ID
  192. where
  193. a.IS_REPORT=1 and a.`STATUS`=1
  194. <if test="report.deviceIds != null and report.deviceIds.size() > 0">
  195. and a.DEVICE_ID in
  196. <foreach collection="report.deviceIds" item="dramaId" open="(" close=")" separator=",">
  197. #{dramaId.id}
  198. </foreach>
  199. </if>
  200. <if test="report.year != null ">and c.`YEAR`=#{report.year}</if>
  201. <if test="report.month != null ">and c.`MONTH`=#{report.month}</if>
  202. <if test="report.day != null ">and c.`DAY`=#{report.day}</if>
  203. <if test="report.hour != null ">and c.`HOUR`=#{report.hour}</if>
  204. <if test="report.parentSceneId != null ">and a.PARENT_SCENE_ID=#{report.parentSceneId}</if>
  205. ORDER BY a.SEQ
  206. ) as tab
  207. group by tab.attributeName,tab.ATTRIBUTE_TYPE
  208. </select>
  209. <select id="findReport" resultType="com.huaxu.dto.ReportDto">
  210. select
  211. tab.year,tab.month,tab.day,tab.hour,
  212. sum(ifnull(intakeWaterUsage,0))as "intakeWaterUsage",
  213. sum(ifnull(yieldWaterUsage,0))as "yieldWaterUsage",
  214. sum(ifnull(powerUsage,0))as "powerUsage",
  215. sum(ifnull(drugUsage,0))as "drugUsage"
  216. from
  217. (SELECT
  218. c.year,c.month,c.day,c.hour,
  219. case when a.PARM_TYPE=4 then
  220. c.SUM_VALUE end as "intakeWaterUsage",
  221. case when a.PARM_TYPE=3 then
  222. c.SUM_VALUE end as "yieldWaterUsage",
  223. case when a.PARM_TYPE=5 then
  224. c.SUM_VALUE end as "powerUsage",
  225. case when a.PARM_TYPE=6 then
  226. c.SUM_VALUE end as "drugUsage"
  227. FROM sms_device_parm a
  228. INNER JOIN sms_device_attribute b on a.ATTRIBUTE_ID=b.ID
  229. INNER JOIN sms_day_report c on a.ATTRIBUTE_ID=c.ATTRIBUTE_ID and a.DEVICE_ID=c.DEVICE_ID
  230. where
  231. <if test="report.deviceIds != null and report.deviceIds.size() > 0">
  232. a.DEVICE_ID in
  233. <foreach collection="report.deviceIds" item="dramaId" open="(" close=")" separator=",">
  234. #{dramaId.id}
  235. </foreach>
  236. </if>
  237. <if test="report.parentSceneIds != null and report.parentSceneIds.length > 0" >
  238. and a.PARENT_SCENE_ID in
  239. <foreach collection="report.parentSceneIds" item="dramaId" open="(" close=")" separator=",">
  240. #{dramaId}
  241. </foreach>
  242. </if>
  243. <if test="report.year != null ">and c.`YEAR`=#{report.year}</if>
  244. <if test="report.month != null ">and c.`MONTH`=#{report.month}</if>
  245. <if test="report.day != null ">and c.`DAY`=#{report.day}</if>
  246. <if test="report.parentSceneId != null ">and a.PARENT_SCENE_ID=#{report.parentSceneId}</if>
  247. <if test="report.parmType != null ">and a.PARM_TYPE in
  248. <foreach collection="report.parmType" item="ptype" open="(" close=")" separator=",">
  249. #{ptype}
  250. </foreach>
  251. and a.`STATUS`=1) tab
  252. </if>
  253. <if test="report.parmType == null ">
  254. and (a.PARM_TYPE =3 or a.PARM_TYPE =4 or a.PARM_TYPE =5 or a.PARM_TYPE =6) and a.`STATUS`=1) tab
  255. </if>
  256. group by tab.year,tab.month,tab.day,tab.HOUR
  257. order by tab.year desc,tab.month desc,tab.day desc,tab.hour desc
  258. </select>
  259. <!-- 根据获取实体 page -->
  260. <select id="findDevicePressPage" resultType="com.huaxu.dto.DevicePressReportAttributeDto">
  261. SELECT
  262. a.DEVICE_CODE as "deviceCode",
  263. a.DEVICE_NAME as "deviceName",
  264. a.min_value as "minValue" ,a.max_value as "maxValue" ,a.avg_value as "avgValue" ,
  265. a.sum_value as "sumValue" ,a.latest_value as "latestValue",
  266. a.COLLECT_DATE as "collectDate"
  267. FROM sms_day_report a
  268. inner join sms_device d on d.id = a.DEVICE_ID
  269. inner join sms_device_parm b on a.DEVICE_ID = b.DEVICE_ID and a.ATTRIBUTE_ID=b.ATTRIBUTE_ID and b.`STATUS`=1
  270. <if test="dayReport.type == 1">
  271. and b.PARM_TYPE = 13
  272. </if>
  273. <if test="dayReport.type == 2">
  274. and b.PARM_TYPE = 14
  275. </if>
  276. <where>
  277. <if test="dayReport.tenantId != null and dayReport.tenantId != ''">and a.tenant_id =
  278. #{dayReport.tenantId}
  279. </if>
  280. <if test="dayReport.year != null ">and a.year = #{dayReport.year}</if>
  281. <if test="dayReport.month != null ">and a.month = #{dayReport.month}</if>
  282. <if test="dayReport.day != null ">and a.day = #{dayReport.day}</if>
  283. and a.DEVICE_ID in
  284. <foreach collection="dayReport.deviceIds" item="dramaId" open="(" close=")" separator=",">
  285. #{dramaId.id}
  286. </foreach>
  287. </where>
  288. order by a.DEVICE_ID,a.year,a.month,a.day,a.hour
  289. </select>
  290. <!-- 根据获取实体 page -->
  291. <select id="findDeviceWaterPage" resultType="com.huaxu.dto.DeviceWaterReportAttributeDto">
  292. select tab.deviceCode,tab.deviceName,tab.collectDate,
  293. sum(tab.minPHValue) as minPHValue,sum(tab.maxPHValue) as maxPHValue,sum(tab.avgPHValue) as avgPHValue,sum(tab.sumPHValue) as sumPHValue,sum(tab.latestPHValue) as latestPHValue,
  294. sum(tab.minQuValue) as minQuValue,sum(tab.maxQuValue) as maxQuValue,sum(tab.avgQuValue) as avgQuValue,sum(tab.sumQuValue) as sumQuValue,sum(tab.latestQuValue) as latestQuValue,
  295. sum(tab.minCLValue) as minCLValue,sum(tab.maxCLValue) as maxCLValue,sum(tab.avgCLValue) as avgCLValue,sum(tab.sumCLValue) as sumCLValue,sum(tab.latestCLValue) as latestCLValue
  296. from (
  297. SELECT a.DEVICE_ID,a.id,a.DEVICE_CODE as "deviceCode", a.DEVICE_NAME as "deviceName",
  298. case when b.PARM_TYPE=7 then a.min_value end as "minPHValue" ,
  299. case when b.PARM_TYPE=7 then a.max_value end as "maxPHValue" ,
  300. case when b.PARM_TYPE=7 then a.avg_value end as "avgPHValue" ,
  301. case when b.PARM_TYPE=7 then a.sum_value end as "sumPHValue" ,
  302. case when b.PARM_TYPE=7 then a.latest_value end as "latestPHValue",
  303. case when b.PARM_TYPE=9 then a.min_value end as "minQuValue" ,
  304. case when b.PARM_TYPE=9 then a.max_value end as "maxQuValue" ,
  305. case when b.PARM_TYPE=9 then a.avg_value end as "avgQuValue" ,
  306. case when b.PARM_TYPE=9 then a.sum_value end as "sumQuValue" ,
  307. case when b.PARM_TYPE=9 then a.latest_value end as "latestQuValue",
  308. case when b.PARM_TYPE=11 then a.min_value end as "minCLValue" ,
  309. case when b.PARM_TYPE=11 then a.max_value end as "maxCLValue" ,
  310. case when b.PARM_TYPE=11 then a.avg_value end as "avgCLValue" ,
  311. case when b.PARM_TYPE=11 then a.sum_value end as "sumCLValue" ,
  312. case when b.PARM_TYPE=11 then a.latest_value end as "latestCLValue",
  313. a.COLLECT_DATE as "collectDate" ,
  314. a.year,a.month,a.day,a.hour,b.deviceParmId
  315. FROM sms_day_report a
  316. inner join sms_device d on d.id = a.DEVICE_ID
  317. inner join sms_device_parm b on a.DEVICE_ID = b.DEVICE_ID and a.ATTRIBUTE_ID=b.ATTRIBUTE_ID and b.`STATUS`=1
  318. and (b.PARM_TYPE = 7 or b.PARM_TYPE = 9 or b.PARM_TYPE = 11)
  319. <where>
  320. <if test="dayReport.tenantId != null and dayReport.tenantId != ''">and a.tenant_id =
  321. #{dayReport.tenantId}
  322. </if>
  323. <if test="dayReport.year != null ">and a.year = #{dayReport.year}</if>
  324. <if test="dayReport.month != null ">and a.month = #{dayReport.month}</if>
  325. <if test="dayReport.day != null ">and a.day = #{dayReport.day}</if>
  326. and a.DEVICE_ID in
  327. <foreach collection="dayReport.deviceIds" item="dramaId" open="(" close=")" separator=",">
  328. #{dramaId.id}
  329. </foreach>
  330. </where>) as tab
  331. group by tab.DEVICE_ID,tab.year,tab.month,tab.day,tab.hour,tab.deviceCode,tab.deviceName,tab.collectDate
  332. order by tab.DEVICE_ID,tab.year,tab.month,tab.day,tab.hour
  333. </select>
  334. <select id="findDeviceLastDayValue" resultType="com.huaxu.entity.DayReportEntity">
  335. select a.LATEST_VALUE as "latestValue"
  336. from sms_day_report a
  337. where a.ATTRIBUTE_ID= #{dayReport.attributeId} and a.DEVICE_ID=#{dayReport.deviceId}
  338. <if test="dayReport.year != null ">and a.year = #{dayReport.year}</if>
  339. <if test="dayReport.month != null ">and a.month = #{dayReport.month}</if>
  340. <if test="dayReport.day != null ">and a.day = #{dayReport.day}</if>
  341. order by a.COLLECT_DATE DESC
  342. limit 1
  343. </select>
  344. </mapper>