StatMeterReadRateByBuildingMapper.xml 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168
  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.bz.smart_city.dao.StatMeterReadRateByBuildingMapper">
  4. <!--auto generated Code-->
  5. <resultMap id="BaseResultMap" type="com.bz.smart_city.entity.StatMeterReadRateByBuilding">
  6. <result column="stat_day" property="statDay" jdbcType="INTEGER"/>
  7. <result column="site_id" property="siteId" jdbcType="INTEGER"/>
  8. <result column="channel_id" property="channelId" jdbcType="INTEGER"/>
  9. <result column="customer_id" property="customerId" jdbcType="INTEGER"/>
  10. <result column="building_id" property="buildingId" jdbcType="INTEGER"/>
  11. <result column="device_count" property="deviceCount" jdbcType="INTEGER"/>
  12. <result column="read_times" property="readTimes" jdbcType="INTEGER"/>
  13. <result column="real_read_times" property="realReadTimes" jdbcType="INTEGER"/>
  14. <result column="un_read_times" property="unReadTimes" jdbcType="INTEGER"/>
  15. <result column="read_rate" property="readRate" jdbcType="DECIMAL"/>
  16. <result column="date_create" property="dateCreate" jdbcType="TIMESTAMP"/>
  17. <result column="date_update" property="dateUpdate" jdbcType="TIMESTAMP"/>
  18. </resultMap>
  19. <!--auto generated Code-->
  20. <sql id="Base_Column_List">
  21. stat_day,
  22. site_id,
  23. channel_id,
  24. customer_id,
  25. building_id,
  26. device_count,
  27. read_times,
  28. real_read_times,
  29. un_read_times,
  30. read_rate,
  31. date_create,
  32. date_update
  33. </sql>
  34. <!--auto generated Code-->
  35. <insert id="insert" useGeneratedKeys="true" keyProperty="statMeterReadRateByBuilding.statDay">
  36. INSERT INTO sc_stat_meter_read_rate_by_building (
  37. stat_day,
  38. site_id,
  39. channel_id,
  40. customer_id,
  41. building_id,
  42. device_count,
  43. read_times,
  44. real_read_times,
  45. un_read_times,
  46. read_rate,
  47. date_create,
  48. date_update
  49. ) VALUES (
  50. #{statMeterReadRateByBuilding.statDay,jdbcType=INTEGER},
  51. #{statMeterReadRateByBuilding.siteId,jdbcType=INTEGER},
  52. #{statMeterReadRateByBuilding.channelId,jdbcType=INTEGER},
  53. #{statMeterReadRateByBuilding.customerId,jdbcType=INTEGER},
  54. #{statMeterReadRateByBuilding.buildingId,jdbcType=INTEGER},
  55. #{statMeterReadRateByBuilding.deviceCount,jdbcType=INTEGER},
  56. #{statMeterReadRateByBuilding.readTimes,jdbcType=INTEGER},
  57. #{statMeterReadRateByBuilding.realReadTimes,jdbcType=INTEGER},
  58. #{statMeterReadRateByBuilding.unReadTimes,jdbcType=INTEGER},
  59. #{statMeterReadRateByBuilding.readRate,jdbcType=DECIMAL},
  60. #{statMeterReadRateByBuilding.dateCreate,jdbcType=TIMESTAMP},
  61. #{statMeterReadRateByBuilding.dateUpdate,jdbcType=TIMESTAMP}
  62. )
  63. </insert>
  64. <!--auto generated Code-->
  65. <insert id="insertSelective" useGeneratedKeys="true" keyProperty="statMeterReadRateByBuilding.statDay">
  66. INSERT INTO sc_stat_meter_read_rate_by_building
  67. <trim prefix="(" suffix=")" suffixOverrides=",">
  68. <if test="statMeterReadRateByBuilding.statDay!=null"> stat_day,</if>
  69. <if test="statMeterReadRateByBuilding.siteId!=null"> site_id,</if>
  70. <if test="statMeterReadRateByBuilding.channelId!=null"> channel_id,</if>
  71. <if test="statMeterReadRateByBuilding.customerId!=null"> customer_id,</if>
  72. <if test="statMeterReadRateByBuilding.buildingId!=null"> building_id,</if>
  73. <if test="statMeterReadRateByBuilding.deviceCount!=null"> device_count,</if>
  74. <if test="statMeterReadRateByBuilding.readTimes!=null"> read_times,</if>
  75. <if test="statMeterReadRateByBuilding.realReadTimes!=null"> real_read_times,</if>
  76. <if test="statMeterReadRateByBuilding.unReadTimes!=null"> un_read_times,</if>
  77. <if test="statMeterReadRateByBuilding.readRate!=null"> read_rate,</if>
  78. <if test="statMeterReadRateByBuilding.dateCreate!=null"> date_create,</if>
  79. <if test="statMeterReadRateByBuilding.dateUpdate!=null"> date_update,</if>
  80. </trim>
  81. VALUES
  82. <trim prefix="(" suffix=")" suffixOverrides=",">
  83. <if test="statMeterReadRateByBuilding.statDay!=null">#{statMeterReadRateByBuilding.statDay,jdbcType=INTEGER},
  84. </if>
  85. <if test="statMeterReadRateByBuilding.siteId!=null">#{statMeterReadRateByBuilding.siteId,jdbcType=INTEGER},
  86. </if>
  87. <if test="statMeterReadRateByBuilding.channelId!=null">#{statMeterReadRateByBuilding.channelId,jdbcType=INTEGER},
  88. </if>
  89. <if test="statMeterReadRateByBuilding.customerId!=null">#{statMeterReadRateByBuilding.customerId,jdbcType=INTEGER},
  90. </if>
  91. <if test="statMeterReadRateByBuilding.buildingId!=null">#{statMeterReadRateByBuilding.buildingId,jdbcType=INTEGER},
  92. </if>
  93. <if test="statMeterReadRateByBuilding.deviceCount!=null">#{statMeterReadRateByBuilding.deviceCount,jdbcType=INTEGER},
  94. </if>
  95. <if test="statMeterReadRateByBuilding.readTimes!=null">#{statMeterReadRateByBuilding.readTimes,jdbcType=INTEGER},
  96. </if>
  97. <if test="statMeterReadRateByBuilding.realReadTimes!=null">#{statMeterReadRateByBuilding.realReadTimes,jdbcType=INTEGER},
  98. </if>
  99. <if test="statMeterReadRateByBuilding.unReadTimes!=null">#{statMeterReadRateByBuilding.unReadTimes,jdbcType=INTEGER},
  100. </if>
  101. <if test="statMeterReadRateByBuilding.readRate!=null">#{statMeterReadRateByBuilding.readRate,jdbcType=DECIMAL},
  102. </if>
  103. <if test="statMeterReadRateByBuilding.dateCreate!=null">#{statMeterReadRateByBuilding.dateCreate,jdbcType=TIMESTAMP},
  104. </if>
  105. <if test="statMeterReadRateByBuilding.dateUpdate!=null">#{statMeterReadRateByBuilding.dateUpdate,jdbcType=TIMESTAMP},
  106. </if>
  107. </trim>
  108. </insert>
  109. <!--auto generated Code-->
  110. <insert id="insertList">
  111. INSERT INTO sc_stat_meter_read_rate_by_building (
  112. stat_day,
  113. site_id,
  114. channel_id,
  115. customer_id,
  116. building_id,
  117. device_count,
  118. read_times,
  119. real_read_times,
  120. un_read_times,
  121. read_rate,
  122. date_create,
  123. date_update
  124. )VALUES
  125. <foreach collection="statMeterReadRateByBuildings" item="statMeterReadRateByBuilding" index="index" separator=",">
  126. (
  127. #{statMeterReadRateByBuilding.statDay,jdbcType=INTEGER},
  128. #{statMeterReadRateByBuilding.siteId,jdbcType=INTEGER},
  129. #{statMeterReadRateByBuilding.channelId,jdbcType=INTEGER},
  130. #{statMeterReadRateByBuilding.customerId,jdbcType=INTEGER},
  131. #{statMeterReadRateByBuilding.buildingId,jdbcType=INTEGER},
  132. #{statMeterReadRateByBuilding.deviceCount,jdbcType=INTEGER},
  133. #{statMeterReadRateByBuilding.readTimes,jdbcType=INTEGER},
  134. #{statMeterReadRateByBuilding.realReadTimes,jdbcType=INTEGER},
  135. #{statMeterReadRateByBuilding.unReadTimes,jdbcType=INTEGER},
  136. #{statMeterReadRateByBuilding.readRate,jdbcType=DECIMAL},
  137. #{statMeterReadRateByBuilding.dateCreate,jdbcType=TIMESTAMP},
  138. #{statMeterReadRateByBuilding.dateUpdate,jdbcType=TIMESTAMP}
  139. )
  140. </foreach>
  141. </insert>
  142. <!--auto generated Code-->
  143. <update id="updateByPrimaryKeySelective">
  144. UPDATE sc_stat_meter_read_rate_by_building
  145. <set>
  146. <if test="statMeterReadRateByBuilding.siteId != null"> site_id= #{statMeterReadRateByBuilding.siteId,jdbcType=INTEGER},</if>
  147. <if test="statMeterReadRateByBuilding.channelId != null"> channel_id= #{statMeterReadRateByBuilding.channelId,jdbcType=INTEGER},</if>
  148. <if test="statMeterReadRateByBuilding.customerId != null"> customer_id= #{statMeterReadRateByBuilding.customerId,jdbcType=INTEGER},</if>
  149. <if test="statMeterReadRateByBuilding.buildingId != null"> building_id= #{statMeterReadRateByBuilding.buildingId,jdbcType=INTEGER},</if>
  150. <if test="statMeterReadRateByBuilding.deviceCount != null"> device_count= #{statMeterReadRateByBuilding.deviceCount,jdbcType=INTEGER},</if>
  151. <if test="statMeterReadRateByBuilding.readTimes != null"> read_times= #{statMeterReadRateByBuilding.readTimes,jdbcType=INTEGER},</if>
  152. <if test="statMeterReadRateByBuilding.realReadTimes != null"> real_read_times= #{statMeterReadRateByBuilding.realReadTimes,jdbcType=INTEGER},</if>
  153. <if test="statMeterReadRateByBuilding.unReadTimes != null"> un_read_times= #{statMeterReadRateByBuilding.unReadTimes,jdbcType=INTEGER},</if>
  154. <if test="statMeterReadRateByBuilding.readRate != null"> read_rate= #{statMeterReadRateByBuilding.readRate,jdbcType=DECIMAL},</if>
  155. <if test="statMeterReadRateByBuilding.dateCreate != null"> date_create= #{statMeterReadRateByBuilding.dateCreate,jdbcType=TIMESTAMP},</if>
  156. <if test="statMeterReadRateByBuilding.dateUpdate != null"> date_update= #{statMeterReadRateByBuilding.dateUpdate,jdbcType=TIMESTAMP}</if>
  157. </set>
  158. WHERE stat_day = #{statMeterReadRateByBuilding.statDay,jdbcType=INTEGER}
  159. </update>
  160. <sql id="where_clause">
  161. WHERE 1 = 1
  162. <!-- 表类型 -->
  163. <if test="param.channelId != null and param.channelId != 0">
  164. and rb.channel_id = #{param.channelId}
  165. </if>
  166. <!-- 数据权限 -->
  167. <if test="param.siteId != null and param.siteId != 0 "> and rb.site_id = #{param.siteId} </if>
  168. <!--
  169. <if test="param.sites != null and param.sites.size() != 0">
  170. and rb.site_id in
  171. <foreach collection="param.sites" item="site" open="(" separator="," close=")">
  172. #{site.id}
  173. </foreach>
  174. </if>
  175. <if test='param.programItems != null and param.programItems.size() != 0' >
  176. and rb.building_id in (
  177. select c.id
  178. from
  179. sc_building c
  180. where 1 = 1
  181. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  182. <if test = 'item.dimensionCode == "PROVINCE" '>
  183. c.province = #{item.dimensionValue}
  184. </if>
  185. <if test = 'item.dimensionCode == "CITY" '>
  186. c.city = #{item.dimensionValue}
  187. </if>
  188. <if test = 'item.dimensionCode == "REGION" '>
  189. c.region = #{item.dimensionValue}
  190. </if>
  191. <if test = 'item.dimensionCode == "COMMUNITY" '>
  192. c.community = #{item.dimensionValue}
  193. </if>
  194. <if test = 'item.dimensionCode == "BUILDING" '>
  195. c.id = #{item.dimensionValue}
  196. </if>
  197. </foreach>
  198. )
  199. </if>
  200. -->
  201. <if test='param.programItems != null and param.programItems.size() != 0' >
  202. and
  203. <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  204. <if test = 'item.dimensionCode == "PROVINCE" or item.dimensionCode == "CITY" or item.dimensionCode == "REGION" or item.dimensionCode == "COMMUNITY" '>
  205. b.${item.dimensionCode} = #{item.dimensionValue}
  206. </if>
  207. <if test='item.dimensionCode == "BUILDING" '>
  208. b.id = #{item.dimensionValue}
  209. </if>
  210. <if test='item.dimensionCode == "CUSTOMER" '>
  211. c.id = #{item.dimensionValue}
  212. </if>
  213. </foreach>
  214. </if>
  215. <if test = "param.statDay != null and param.statDay != 0">and rb.stat_day = #{param.statDay}</if>
  216. <if test = "param.startDate != null and param.startDate != 0"> and rb.stat_day >= #{param.startDate}</if>
  217. <if test = "param.endDate != null and param.endDate != 0"> and rb.stat_day <![CDATA[ <= ]]> #{param.endDate}</if>
  218. <if test = "param.beginRate != null "> and rb.read_rate >= #{param.beginRate}</if>
  219. <if test = "param.endRate != null "> and rb.read_rate <![CDATA[ <= ]]> #{param.endRate}</if>
  220. <if test = "param.custormerId != null"> and rb.customer_id = #{param.custormerId}</if>
  221. <if test = "param.communityId != null "> and b.community = #{param.communityId}</if>
  222. <if test = "param.buildingId != null and param.buildingId != 0 "> and rb.building_id = #{param.buildingId}</if>
  223. </sql>
  224. <sql id="base_query">
  225. SELECT
  226. rb.stat_day as stat_day,
  227. rb.building_id as building_id,
  228. b.`name` AS building_name,
  229. rb.device_count AS device_count,
  230. rb.read_times AS read_times,
  231. rb.real_read_times AS real_read_times,
  232. rb.un_read_times AS un_read_times,
  233. rb.read_rate AS read_rate,
  234. de.alarm_device_num AS alarm_device_num ,
  235. c.customer_name as customer_name
  236. FROM
  237. sc_stat_meter_read_rate_by_building rb
  238. LEFT JOIN sc_stat_device_error_day de ON (
  239. rb.stat_day = de.stat_day
  240. AND rb.site_id = de.site_id
  241. AND rb.channel_id = de.sys_id
  242. AND rb.building_id = de.building_id
  243. AND de.alarm_category = '0'
  244. AND de.alarm_type = 0
  245. AND de.handle_status = '0'
  246. )
  247. LEFT JOIN sc_building b ON ( rb.building_id = b.id )
  248. LEFT JOIN sc_customer c on (rb.customer_id = c.id)
  249. </sql>
  250. <select id="summaryRateListByBuilding" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  251. select
  252. ifnull(SUM(tmp.device_count),0) as device_count,
  253. ifnull(SUM(tmp.read_times),0) as read_times,
  254. ifnull(SUM(tmp.real_read_times),0) as real_read_times,
  255. ifnull(SUM(tmp.un_read_times),0) as un_read_times,
  256. ifnull(SUM(tmp.alarm_device_num),0) as alarm_device_num,
  257. ifnull(ROUND(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
  258. from (
  259. <include refid="base_query"></include>
  260. <include refid="where_clause"></include>
  261. ) tmp
  262. </select>
  263. <select id="analysisMeterReadRate" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  264. select
  265. tmp.stat_day as stat_day,
  266. ifnull(SUM(tmp.device_count),0) as device_count,
  267. ifnull(SUM(tmp.read_times),0) as read_times,
  268. ifnull(SUM(tmp.real_read_times),0) as real_read_times,
  269. ifnull(SUM(tmp.un_read_times),0) as un_read_times,
  270. ifnull(SUM(tmp.alarm_device_num),0) as alarm_device_num,
  271. ifnull(ROUND(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
  272. from (
  273. <include refid="base_query"></include>
  274. <include refid="where_clause"></include>
  275. ) tmp
  276. group by tmp.stat_day
  277. </select>
  278. <select id="getRateListByBuilding" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  279. <include refid="base_query"></include>
  280. <include refid="where_clause"></include>
  281. order by rb.stat_day desc
  282. </select>
  283. <!--按表类型查询时间范围内的抄表率数据统计-->
  284. <select id="getRateCountByTime" resultType="com.bz.smart_city.dto.WaterReadRateCountDto">
  285. SELECT
  286. (select SUM(device_count) from sc_stat_meter_read_rate_by_building where 1 = 1 <if test="siteId != null"> and site_id = #{siteId} </if>
  287. <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  288. GROUP BY stat_day desc limit 1) as device_count,
  289. SUM(read_times) as read_times,
  290. SUM(real_read_times) as real_read_times,
  291. SUM(un_read_times) as un_read_times,
  292. ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
  293. FROM sc_stat_meter_read_rate_by_building a
  294. LEFT JOIN sc_w_meter_type b ON b.channel_id = a.channel_id
  295. WHERE a.stat_day = #{startDate}
  296. AND b.`status` = 1
  297. <if test="siteId != null"> and a.site_id = #{siteId} </if>
  298. <if test="buildingIds != null and buildingIds.size() != 0"> and a.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  299. </select>
  300. <!--按表类型查询7天内的抄表率数据统计-->
  301. <select id="getRateCount7DayByTime" resultType="com.bz.smart_city.dto.WaterReadRateCountDto">
  302. SELECT
  303. (select SUM(device_count) from sc_stat_meter_read_rate_by_building_7day where 1 = 1 <if test="siteId != null"> and site_id = #{siteId} </if>
  304. <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  305. GROUP BY stat_day desc limit 1) as device_count,
  306. SUM(read_times) as read_times,
  307. SUM(real_read_times) as real_read_times,
  308. SUM(un_read_times) as un_read_times,
  309. ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
  310. FROM sc_stat_meter_read_rate_by_building_7day a
  311. LEFT JOIN sc_w_meter_type b ON b.channel_id = a.channel_id
  312. WHERE a.stat_day = #{startDate}
  313. AND b.`status` = 1
  314. <if test="siteId != null"> and a.site_id = #{siteId} </if>
  315. <if test="buildingIds != null and buildingIds.size() != 0"> and a.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  316. </select>
  317. <!--按表类型查询15天内的抄表率数据统计-->
  318. <select id="getRateCount15DayByTime" resultType="com.bz.smart_city.dto.WaterReadRateCountDto">
  319. SELECT
  320. (select SUM(device_count) from sc_stat_meter_read_rate_by_building_15day where 1 = 1 <if test="siteId != null"> and site_id = #{siteId} </if>
  321. <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  322. GROUP BY stat_day desc limit 1) as device_count,
  323. SUM(read_times) as read_times,
  324. SUM(real_read_times) as real_read_times,
  325. SUM(un_read_times) as un_read_times,
  326. ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
  327. FROM sc_stat_meter_read_rate_by_building_15day a
  328. LEFT JOIN sc_w_meter_type b ON b.channel_id = a.channel_id
  329. WHERE a.stat_day = #{startDate}
  330. AND b.`status` = 1
  331. <if test="siteId != null"> and a.site_id = #{siteId} </if>
  332. <if test="buildingIds != null and buildingIds.size() != 0"> and a.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  333. </select>
  334. <!--查询时间范围内根据表类型的抄表率数据统计-->
  335. <select id="getRateListByType" resultType="com.bz.smart_city.dto.WaterReadRateListDto">
  336. SELECT
  337. swmt.channel_id,
  338. sdt.equipment_type as device_type_name,
  339. (select SUM(device_count) from sc_stat_meter_read_rate_by_building where channel_id = swmt.channel_id <if test="siteId != null"> and site_id = #{siteId} </if>
  340. <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  341. GROUP BY stat_day desc limit 1) as device_count,
  342. SUM(ssmrrbb.read_times) as read_times,
  343. SUM(ssmrrbb.real_read_times) as real_read_times,
  344. SUM(ssmrrbb.un_read_times) as un_read_times,
  345. ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
  346. FROM sc_w_meter_type swmt
  347. LEFT JOIN sc_stat_meter_read_rate_by_building ssmrrbb on (
  348. ssmrrbb.channel_id = swmt.channel_id <if test="siteId != null"> and ssmrrbb.site_id = #{siteId} </if>
  349. and ssmrrbb.stat_day = #{startDate}
  350. <if test="buildingIds != null and buildingIds.size() != 0"> and ssmrrbb.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  351. )
  352. left join sc_device_type sdt on (sdt.id = swmt.device_type_id)
  353. WHERE swmt.`level` = 2
  354. GROUP BY swmt.channel_id,sdt.equipment_type
  355. <if test="sortColumn != null and sortColumn != ''">
  356. <if test="sortOrder != null and sortOrder != ''">
  357. order by ${sortColumn} ${sortOrder}
  358. </if>
  359. </if>
  360. </select>
  361. <!--查询7天内根据表类型的抄表率数据统计-->
  362. <select id="getRateList7DayByType" resultType="com.bz.smart_city.dto.WaterReadRateListDto">
  363. SELECT
  364. swmt.channel_id,
  365. sdt.equipment_type as device_type_name,
  366. (select SUM(device_count) from sc_stat_meter_read_rate_by_building_7day where channel_id = swmt.channel_id <if test="siteId != null"> and site_id = #{siteId} </if>
  367. <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  368. GROUP BY stat_day desc limit 1) as device_count,
  369. SUM(ssmrrbb.read_times) as read_times,
  370. SUM(ssmrrbb.real_read_times) as real_read_times,
  371. SUM(ssmrrbb.un_read_times) as un_read_times,
  372. ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
  373. FROM sc_w_meter_type swmt
  374. LEFT JOIN sc_stat_meter_read_rate_by_building_7day ssmrrbb on (
  375. ssmrrbb.channel_id = swmt.channel_id <if test="siteId != null"> and ssmrrbb.site_id = #{siteId} </if>
  376. and ssmrrbb.stat_day = #{startDate}
  377. <if test="buildingIds != null and buildingIds.size() != 0"> and ssmrrbb.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  378. )
  379. left join sc_device_type sdt on (sdt.id = swmt.device_type_id)
  380. WHERE swmt.`level` = 2
  381. GROUP BY swmt.channel_id,sdt.equipment_type
  382. <if test="sortColumn != null and sortColumn != ''">
  383. <if test="sortOrder != null and sortOrder != ''">
  384. order by ${sortColumn} ${sortOrder}
  385. </if>
  386. </if>
  387. </select>
  388. <!--查询15天内根据表类型的抄表率数据统计-->
  389. <select id="getRateList15DayByType" resultType="com.bz.smart_city.dto.WaterReadRateListDto">
  390. SELECT
  391. swmt.channel_id,
  392. sdt.equipment_type as device_type_name,
  393. (select SUM(device_count) from sc_stat_meter_read_rate_by_building_15day where channel_id = swmt.channel_id <if test="siteId != null"> and site_id = #{siteId} </if>
  394. <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  395. GROUP BY stat_day desc limit 1) as device_count,
  396. SUM(ssmrrbb.read_times) as read_times,
  397. SUM(ssmrrbb.real_read_times) as real_read_times,
  398. SUM(ssmrrbb.un_read_times) as un_read_times,
  399. ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
  400. FROM sc_w_meter_type swmt
  401. LEFT JOIN sc_stat_meter_read_rate_by_building_15day ssmrrbb on (
  402. ssmrrbb.channel_id = swmt.channel_id <if test="siteId != null"> and ssmrrbb.site_id = #{siteId} </if>
  403. and ssmrrbb.stat_day = #{startDate}
  404. <if test="buildingIds != null and buildingIds.size() != 0"> and ssmrrbb.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  405. )
  406. left join sc_device_type sdt on (sdt.id = swmt.device_type_id)
  407. WHERE swmt.`level` = 2
  408. GROUP BY swmt.channel_id,sdt.equipment_type
  409. <if test="sortColumn != null and sortColumn != ''">
  410. <if test="sortOrder != null and sortOrder != ''">
  411. order by ${sortColumn} ${sortOrder}
  412. </if>
  413. </if>
  414. </select>
  415. <!--查询最近7天抄表率-->
  416. <select id="getLast7DaysReadRate" resultType="java.lang.Double">
  417. SELECT
  418. ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0)
  419. FROM
  420. sc_stat_meter_read_rate_by_building ssmrrbb
  421. WHERE
  422. stat_day between #{beginTime} AND #{endTime}
  423. <if test="programItems != null and programItems.size() != 0">
  424. and EXISTS(
  425. select 1 from
  426. (select sd.building_id FROM sc_device_dim_info df
  427. LEFT JOIN sc_device sd ON sd.id = df.device_id
  428. WHERE 1 = 1
  429. and
  430. <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  431. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  432. </foreach>
  433. GROUP BY sd.building_id) ud
  434. WHERE ud.building_id = ssmrrbb.building_id
  435. )
  436. </if>
  437. <if test="siteId != null">
  438. AND site_id = #{siteId}
  439. </if>
  440. <if test="channelId != null">
  441. AND channel_id = #{channelId}
  442. </if>
  443. <if test="customerId != null">
  444. AND customer_id = #{customerId}
  445. </if>
  446. </select>
  447. <!--按客户查询时间范围内的抄表率数数据统计-->
  448. <select id="getRateListByCustomer" resultType="com.bz.smart_city.dto.WaterReadRateListDto">
  449. SELECT
  450. sc.id as customer_id,
  451. sc.customer_name,
  452. (select SUM(device_count) from sc_stat_meter_read_rate_by_building where customer_id = ssmrrbb.customer_id <if test="siteId != null"> and site_id = #{siteId} </if>
  453. <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  454. GROUP BY stat_day desc limit 1) as device_count,
  455. SUM(ssmrrbb.read_times) as read_times,
  456. SUM(ssmrrbb.real_read_times) as real_read_times,
  457. SUM(ssmrrbb.un_read_times) as un_read_times,
  458. ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
  459. FROM sc_customer sc
  460. LEFT JOIN sc_stat_meter_read_rate_by_building ssmrrbb on(
  461. ssmrrbb.customer_id = sc.id
  462. <if test="siteId != null"> and ssmrrbb.site_id = #{siteId} </if>
  463. and ssmrrbb.stat_day = #{startDate}
  464. <if test="buildingIds != null and buildingIds.size() != 0"> and ssmrrbb.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  465. )
  466. WHERE sc.status = 1
  467. <if test="customerList != null and customerList.size() != 0">
  468. and sc.id in
  469. <foreach collection="customerList" item="item" open="(" separator="," close=")">#{item.id}</foreach>
  470. </if>
  471. GROUP BY sc.id,ssmrrbb.customer_id,sc.customer_name
  472. <if test="sortColumn != null and sortColumn != ''">
  473. <if test="sortOrder != null and sortOrder != ''">
  474. order by ${sortColumn} ${sortOrder}
  475. </if>
  476. </if>
  477. </select>
  478. <select id="getRateListByCustomerV2" resultType="com.bz.smart_city.dto.CustomerRateDto">
  479. SELECT sc.id as customer_id,sc.parent_id,sc.customer_name,sc.children_num FROM sc_customer sc
  480. LEFT JOIN(
  481. SELECT
  482. ssmrrbb.customer_id,
  483. SUM(device_count) as device_count
  484. FROM
  485. ${tableName} ssmrrbb
  486. WHERE
  487. ssmrrbb.site_id = #{siteId}
  488. <if test="channelId != null"> and ssmrrbb.channel_id = #{channelId} </if>
  489. AND ssmrrbb.stat_day = #{startDate}
  490. AND ssmrrbb.channel_id <![CDATA[ <> ]]> - 99
  491. <if test="buildingIds != null and buildingIds.size() != 0"> and ssmrrbb.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  492. <if test="customerIds != null and customerIds.size() != 0"> and ssmrrbb.customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  493. GROUP BY
  494. ssmrrbb.customer_id
  495. )t1 on(t1.customer_id = sc.id)
  496. WHERE sc.`status` = 1 and sc.site_id = #{siteId}
  497. <if test="customerIds != null and customerIds.size() != 0"> and sc.id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  498. ORDER BY device_count desc
  499. </select>
  500. <select id="getRateListByCustomerV2AndDeviceType" resultType="com.bz.smart_city.dto.WaterReadRateListDto">
  501. SELECT
  502. ssmrrbb.customer_id,
  503. ssmrrbb.channel_id,
  504. sc.channel_name,
  505. SUM(device_count) as device_count,
  506. SUM(ssmrrbb.read_times) as read_times,
  507. SUM(ssmrrbb.real_read_times) as real_read_times,
  508. SUM(ssmrrbb.un_read_times) as un_read_times,
  509. ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
  510. FROM sc_stat_meter_read_rate_by_building ssmrrbb
  511. left join sc_channel sc on(sc.id = ssmrrbb.channel_id)
  512. WHERE
  513. ssmrrbb.site_id = #{siteId}
  514. and ssmrrbb.stat_day = #{startDate}
  515. AND ssmrrbb.channel_id <![CDATA[ <> ]]> - 99
  516. <if test="customerId != null"> and ssmrrbb.customer_id = #{customerId} </if>
  517. <if test="channelId != null"> and ssmrrbb.channel_id = #{channelId} </if>
  518. GROUP BY ssmrrbb.customer_id,ssmrrbb.channel_id,sc.channel_name
  519. order by read_rate desc
  520. </select>
  521. <!--按客户查询7天内的抄表率数数据统计-->
  522. <select id="getRateList7DayByCustomer" resultType="com.bz.smart_city.dto.WaterReadRateListDto">
  523. SELECT
  524. sc.id as customer_id,
  525. sc.customer_name,
  526. (select SUM(device_count) from sc_stat_meter_read_rate_by_building_7day where customer_id = ssmrrbb.customer_id <if test="siteId != null"> and site_id = #{siteId} </if>
  527. <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  528. GROUP BY stat_day desc limit 1) as device_count,
  529. SUM(ssmrrbb.read_times) as read_times,
  530. SUM(ssmrrbb.real_read_times) as real_read_times,
  531. SUM(ssmrrbb.un_read_times) as un_read_times,
  532. ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
  533. FROM sc_customer sc
  534. LEFT JOIN sc_stat_meter_read_rate_by_building_7day ssmrrbb on(
  535. ssmrrbb.customer_id = sc.id
  536. <if test="siteId != null"> and ssmrrbb.site_id = #{siteId} </if>
  537. and ssmrrbb.stat_day = #{startDate}
  538. <if test="buildingIds != null and buildingIds.size() != 0"> and ssmrrbb.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  539. )
  540. WHERE sc.status = 1
  541. <if test="customerList != null and customerList.size() != 0">
  542. and sc.id in
  543. <foreach collection="customerList" item="item" open="(" separator="," close=")">#{item.id}</foreach>
  544. </if>
  545. GROUP BY sc.id,ssmrrbb.customer_id,sc.customer_name
  546. <if test="sortColumn != null and sortColumn != ''">
  547. <if test="sortOrder != null and sortOrder != ''">
  548. order by ${sortColumn} ${sortOrder}
  549. </if>
  550. </if>
  551. </select>
  552. <!--按客户查询15天内的抄表率数数据统计-->
  553. <select id="getRateList15DayByCustomer" resultType="com.bz.smart_city.dto.WaterReadRateListDto">
  554. SELECT
  555. sc.id as customer_id,
  556. sc.customer_name,
  557. (select SUM(device_count) from sc_stat_meter_read_rate_by_building_15day where customer_id = ssmrrbb.customer_id <if test="siteId != null"> and site_id = #{siteId} </if>
  558. <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  559. GROUP BY stat_day desc limit 1) as device_count,
  560. SUM(ssmrrbb.read_times) as read_times,
  561. SUM(ssmrrbb.real_read_times) as real_read_times,
  562. SUM(ssmrrbb.un_read_times) as un_read_times,
  563. ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
  564. FROM sc_customer sc
  565. LEFT JOIN sc_stat_meter_read_rate_by_building_15day ssmrrbb on(
  566. ssmrrbb.customer_id = sc.id
  567. <if test="siteId != null"> and ssmrrbb.site_id = #{siteId} </if>
  568. and ssmrrbb.stat_day = #{startDate}
  569. <if test="buildingIds != null and buildingIds.size() != 0"> and ssmrrbb.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  570. )
  571. WHERE sc.status = 1
  572. <if test="customerList != null and customerList.size() != 0">
  573. and sc.id in
  574. <foreach collection="customerList" item="item" open="(" separator="," close=")">#{item.id}</foreach>
  575. </if>
  576. GROUP BY sc.id,ssmrrbb.customer_id,sc.customer_name
  577. <if test="sortColumn != null and sortColumn != ''">
  578. <if test="sortOrder != null and sortOrder != ''">
  579. order by ${sortColumn} ${sortOrder}
  580. </if>
  581. </if>
  582. </select>
  583. <!--按客户查询时间范围内的抄表率数据统计-->
  584. <select id="getCountByCustomer" resultType="com.bz.smart_city.dto.WaterReadRateCountDto">
  585. SELECT
  586. (select SUM(device_count) from sc_stat_meter_read_rate_by_building where 1 = 1 <if test="siteId != null"> and site_id = #{siteId} </if>
  587. <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  588. GROUP BY stat_day desc limit 1) as device_count,
  589. SUM(read_times) as read_times,
  590. SUM(real_read_times) as real_read_times,
  591. SUM(un_read_times) as un_read_times,
  592. ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
  593. FROM sc_stat_meter_read_rate_by_building a
  594. LEFT JOIN sc_w_meter_type b ON b.channel_id = a.channel_id
  595. WHERE a.stat_day = #{startDate}
  596. AND b.`status` = 1
  597. <if test="siteId != null"> and a.site_id = #{siteId} </if>
  598. <if test="buildingIds != null and buildingIds.size() != 0"> and a.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  599. <if test="customerList != null and customerList.size() != 0">
  600. and a.customer_id in
  601. <foreach collection="customerList" item="item" open="(" separator="," close=")">#{item.id}</foreach>
  602. </if>
  603. </select>
  604. <select id="getCountByCustomerV2" resultType="com.bz.smart_city.dto.WaterReadRateCountDto">
  605. SELECT
  606. SUM(device_count) as device_count,
  607. SUM(read_times) as read_times,
  608. SUM(real_read_times) as real_read_times,
  609. SUM(un_read_times) as un_read_times,
  610. ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
  611. FROM ${tableName} scmrrbb
  612. WHERE stat_day = #{startDate}
  613. and channel_id <![CDATA[ <> ]]> - 99
  614. <if test="siteId != null"> and site_id = #{siteId} </if>
  615. <if test="channelId != null"> and channel_id = #{channelId} </if>
  616. <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  617. <if test="customerIds != null and customerIds.size() != 0"> and customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  618. </select>
  619. <!--按客户查询时间范围内的抄表率数据统计-->
  620. <select id="getCount7DayByCustomer" resultType="com.bz.smart_city.dto.WaterReadRateCountDto">
  621. SELECT
  622. (select SUM(device_count) from sc_stat_meter_read_rate_by_building_7day where 1 = 1 <if test="siteId != null"> and site_id = #{siteId} </if>
  623. <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  624. GROUP BY stat_day desc limit 1) as device_count,
  625. SUM(read_times) as read_times,
  626. SUM(real_read_times) as real_read_times,
  627. SUM(un_read_times) as un_read_times,
  628. ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
  629. FROM sc_stat_meter_read_rate_by_building_7day a
  630. LEFT JOIN sc_w_meter_type b ON b.channel_id = a.channel_id
  631. WHERE a.stat_day = #{startDate}
  632. AND b.`status` = 1
  633. <if test="siteId != null"> and a.site_id = #{siteId} </if>
  634. <if test="buildingIds != null and buildingIds.size() != 0"> and a.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  635. <if test="customerList != null and customerList.size() != 0">
  636. and a.customer_id in
  637. <foreach collection="customerList" item="item" open="(" separator="," close=")">#{item.id}</foreach>
  638. </if>
  639. </select>
  640. <!--按客户查询时间范围内的抄表率数据统计-->
  641. <select id="getCount15DayByCustomer" resultType="com.bz.smart_city.dto.WaterReadRateCountDto">
  642. SELECT
  643. (select SUM(device_count) from sc_stat_meter_read_rate_by_building_15day where 1 = 1 <if test="siteId != null"> and site_id = #{siteId} </if>
  644. <if test="buildingIds != null and buildingIds.size() != 0"> and building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  645. GROUP BY stat_day desc limit 1) as device_count,
  646. SUM(read_times) as read_times,
  647. SUM(real_read_times) as real_read_times,
  648. SUM(un_read_times) as un_read_times,
  649. ifnull(ROUND(sum(real_read_times)/sum(device_count)*100,2),0) as read_rate
  650. FROM sc_stat_meter_read_rate_by_building_15day a
  651. LEFT JOIN sc_w_meter_type b ON b.channel_id = a.channel_id
  652. WHERE a.stat_day = #{startDate}
  653. AND b.`status` = 1
  654. <if test="siteId != null"> and a.site_id = #{siteId} </if>
  655. <if test="buildingIds != null and buildingIds.size() != 0"> and a.building_id in <foreach collection="buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  656. <if test="customerList != null and customerList.size() != 0">
  657. and a.customer_id in
  658. <foreach collection="customerList" item="item" open="(" separator="," close=")">#{item.id}</foreach>
  659. </if>
  660. </select>
  661. <!-- 按建筑统计天表 -->
  662. <sql id="base_GetRateListByBuildingForDay">
  663. select
  664. rb.stat_day as stat_day,
  665. rb.building_id as building_id,
  666. b.`name` AS building_name,
  667. rb.device_count AS device_count,
  668. rb.read_times AS read_times,
  669. rb.real_read_times AS real_read_times,
  670. rb.un_read_times AS un_read_times,
  671. rb.read_rate AS read_rate,
  672. rb.customer_id as customer_id,
  673. c.customer_name as customer_name
  674. from
  675. sc_stat_meter_read_rate_by_building rb
  676. LEFT JOIN sc_building b ON ( rb.building_id = b.id )
  677. LEFT JOIN sc_customer c on (rb.customer_id = c.id)
  678. </sql>
  679. <select id="getRateListByBuildingForDay" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  680. <include refid="base_GetRateListByBuildingForDay"></include>
  681. <include refid="where_clause"></include>
  682. <if test="param.sortColumn != null and param.sortColumn != ''">
  683. <if test="param.sortOrder != null and param.sortOrder != ''">
  684. order by ${param.sortColumn} ${param.sortOrder}
  685. </if>
  686. </if>
  687. </select>
  688. <select id="getRateAreaListByBuildingForDay" resultType="com.bz.smart_city.dto.BuildingSelectInfoDto">
  689. select
  690. b.id,
  691. b.name,
  692. b.province,
  693. b.city,
  694. b.region,
  695. b.community,
  696. b.longitude,
  697. b.latitude,
  698. 0
  699. from
  700. sc_stat_meter_read_rate_by_building rb
  701. LEFT JOIN sc_building b ON ( rb.building_id = b.id )
  702. LEFT JOIN sc_customer c on (rb.customer_id = c.id)
  703. <include refid="where_clause"></include>
  704. </select>
  705. <select id="summaryRateListByBuildingForDay" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  706. select
  707. ifnull(SUM(tmp.device_count),0) as device_count,
  708. ifnull(SUM(tmp.read_times),0) as read_times,
  709. ifnull(SUM(tmp.real_read_times),0) as real_read_times,
  710. ifnull(SUM(tmp.un_read_times),0) as un_read_times,
  711. ifnull(ROUND(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
  712. from (
  713. <include refid="base_GetRateListByBuildingForDay"></include>
  714. <include refid="where_clause"></include>
  715. ) tmp
  716. <if test="param.sortColumn != null and param.sortColumn != ''">
  717. <if test="param.sortOrder != null and param.sortOrder != ''">
  718. order by read_rate ${param.sortOrder}
  719. </if>
  720. </if>
  721. </select>
  722. <!-- 按建筑统计天表 新装水表场景适用 -->
  723. <sql id="base_GetRateListByBuildingForDayWithNew">
  724. select
  725. rb.stat_day as stat_day,
  726. rb.building_id as building_id,
  727. b.`name` AS building_name,
  728. rb.device_count AS device_count,
  729. rb.read_times AS read_times,
  730. rb.real_read_times AS real_read_times,
  731. rb.un_read_times AS un_read_times,
  732. rb.customer_id as customer_id,
  733. c.customer_name as customer_name,
  734. (
  735. SELECT
  736. count( 1 )
  737. FROM
  738. sc_install_list l
  739. WHERE
  740. l.`status` = 1
  741. AND l.is_installed = 1
  742. AND l.is_accepted = 0
  743. AND l.building_id = rb.building_id
  744. ) AS installed_device_count,
  745. (
  746. SELECT
  747. SUM( IF ( d.device_status = 5, 1, 0 ) )
  748. FROM
  749. sc_device d
  750. WHERE
  751. d.building_id = rb.building_id
  752. AND d.`status` = 1
  753. AND d.sys_id = - 99
  754. ) AS unenable_device_count ,
  755. FORMAT(rb.real_read_times/ (
  756. SELECT
  757. count( 1 )
  758. FROM
  759. sc_install_list l
  760. WHERE
  761. l.`status` = 1
  762. AND l.is_installed = 1
  763. AND l.is_accepted = 0
  764. AND l.building_id = rb.building_id
  765. ) *100, 2) as read_rate
  766. from
  767. sc_stat_meter_read_rate_by_building rb
  768. LEFT JOIN sc_building b ON ( rb.building_id = b.id )
  769. LEFT JOIN sc_customer c on (rb.customer_id = c.id)
  770. </sql>
  771. <select id="getRateListByBuildingForDayWithNew" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  772. <include refid="base_GetRateListByBuildingForDayWithNew"></include>
  773. <include refid="where_clause"></include>
  774. <if test="param.sortColumn != null and param.sortColumn != ''">
  775. <if test="param.sortOrder != null and param.sortOrder != ''">
  776. order by ${param.sortColumn} ${param.sortOrder}
  777. </if>
  778. </if>
  779. </select>
  780. <select id="summaryRateListByBuildingForDayWithNew" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  781. select
  782. ifnull(SUM(tmp.installed_device_count),0) as device_count,
  783. ifnull(SUM(tmp.read_times),0) as read_times,
  784. ifnull(SUM(tmp.real_read_times),0) as real_read_times,
  785. ifnull(SUM(tmp.un_read_times),0) as un_read_times,
  786. ifnull(ROUND(SUM(tmp.real_read_times)/SUM(tmp.installed_device_count)*100,2),0) as read_rate
  787. from (
  788. <include refid="base_GetRateListByBuildingForDayWithNew"></include>
  789. <include refid="where_clause"></include>
  790. ) tmp
  791. <if test="param.sortColumn != null and param.sortColumn != ''">
  792. <if test="param.sortOrder != null and param.sortOrder != ''">
  793. order by read_rate ${param.sortOrder}
  794. </if>
  795. </if>
  796. </select>
  797. <!-- 按建筑统计7天表 -->
  798. <sql id="base_GetRateListByBuildingFor7Day">
  799. select
  800. rb.stat_day as stat_day,
  801. rb.building_id as building_id,
  802. b.`name` AS building_name,
  803. rb.device_count AS device_count,
  804. rb.read_times AS read_times,
  805. rb.real_read_times AS real_read_times,
  806. rb.un_read_times AS un_read_times,
  807. rb.read_rate AS read_rate,
  808. rb.customer_id as customer_id,
  809. c.customer_name as customer_name
  810. from
  811. sc_stat_meter_read_rate_by_building_7day rb
  812. LEFT JOIN sc_building b ON ( rb.building_id = b.id )
  813. LEFT JOIN sc_customer c on (rb.customer_id = c.id)
  814. </sql>
  815. <select id="getRateAreaListByBuildingFor7Day" resultType="com.bz.smart_city.dto.BuildingSelectInfoDto">
  816. select
  817. b.id,
  818. b.name,
  819. b.province,
  820. b.city,
  821. b.region,
  822. b.community,
  823. b.longitude,
  824. b.latitude,
  825. 0
  826. from
  827. sc_stat_meter_read_rate_by_building_7day rb
  828. LEFT JOIN sc_building b ON ( rb.building_id = b.id )
  829. LEFT JOIN sc_customer c on (rb.customer_id = c.id)
  830. <include refid="where_clause"></include>
  831. </select>
  832. <select id="getRateListByBuildingFor7Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  833. <include refid="base_GetRateListByBuildingFor7Day"></include>
  834. <include refid="where_clause"></include>
  835. <if test="param.sortColumn != null and param.sortColumn != ''">
  836. <if test="param.sortOrder != null and param.sortOrder != ''">
  837. order by ${param.sortColumn} ${param.sortOrder}
  838. </if>
  839. </if>
  840. </select>
  841. <select id="summaryRateListByBuildingFor7Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  842. select
  843. ifnull(SUM(tmp.device_count),0) as device_count,
  844. ifnull(SUM(tmp.read_times),0) as read_times,
  845. ifnull(SUM(tmp.real_read_times),0) as real_read_times,
  846. ifnull(SUM(tmp.un_read_times),0) as un_read_times,
  847. ifnull(ROUND(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
  848. from (
  849. <include refid="base_GetRateListByBuildingFor7Day"></include>
  850. <include refid="where_clause"></include>
  851. ) tmp
  852. <if test="param.sortColumn != null and param.sortColumn != ''">
  853. <if test="param.sortOrder != null and param.sortOrder != ''">
  854. order by read_rate ${param.sortOrder}
  855. </if>
  856. </if>
  857. </select>
  858. <!-- 按建筑统计7天表 新装水表场景适用 -->
  859. <sql id="base_GetRateListByBuildingFor7DayWithNew">
  860. select
  861. rb.stat_day as stat_day,
  862. rb.building_id as building_id,
  863. b.`name` AS building_name,
  864. rb.device_count AS device_count,
  865. rb.read_times AS read_times,
  866. rb.real_read_times AS real_read_times,
  867. rb.un_read_times AS un_read_times,
  868. rb.customer_id as customer_id,
  869. c.customer_name as customer_name,
  870. (
  871. SELECT
  872. count( 1 )
  873. FROM
  874. sc_install_list l
  875. WHERE
  876. l.`status` = 1
  877. AND l.is_installed = 1
  878. AND l.is_accepted = 0
  879. AND l.building_id = rb.building_id
  880. ) AS installed_device_count,
  881. (
  882. SELECT
  883. SUM( IF ( d.device_status = 5, 1, 0 ) )
  884. FROM
  885. sc_device d
  886. WHERE
  887. d.building_id = rb.building_id
  888. AND d.`status` = 1
  889. AND d.sys_id = - 99
  890. ) AS unenable_device_count ,
  891. FORMAT(rb.real_read_times/ (
  892. SELECT
  893. count( 1 )
  894. FROM
  895. sc_install_list l
  896. WHERE
  897. l.`status` = 1
  898. AND l.is_installed = 1
  899. AND l.is_accepted = 0
  900. AND l.building_id = rb.building_id
  901. ) *100, 2) as read_rate
  902. from
  903. sc_stat_meter_read_rate_by_building_7day rb
  904. LEFT JOIN sc_building b ON ( rb.building_id = b.id )
  905. LEFT JOIN sc_customer c on (rb.customer_id = c.id)
  906. </sql>
  907. <select id="getRateListByBuildingFor7DayWithNew" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  908. <include refid="base_GetRateListByBuildingFor7DayWithNew"></include>
  909. <include refid="where_clause"></include>
  910. <if test="param.sortColumn != null and param.sortColumn != ''">
  911. <if test="param.sortOrder != null and param.sortOrder != ''">
  912. order by ${param.sortColumn} ${param.sortOrder}
  913. </if>
  914. </if>
  915. </select>
  916. <select id="summaryRateListByBuildingFor7DayWithNew" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  917. select
  918. ifnull(SUM(tmp.installed_device_count),0) as device_count,
  919. ifnull(SUM(tmp.read_times),0) as read_times,
  920. ifnull(SUM(tmp.real_read_times),0) as real_read_times,
  921. ifnull(SUM(tmp.un_read_times),0) as un_read_times,
  922. ifnull(ROUND(SUM(tmp.real_read_times)/SUM(tmp.installed_device_count)*100,2),0) as read_rate
  923. from (
  924. <include refid="base_GetRateListByBuildingFor7DayWithNew"></include>
  925. <include refid="where_clause"></include>
  926. ) tmp
  927. <if test="param.sortColumn != null and param.sortColumn != ''">
  928. <if test="param.sortOrder != null and param.sortOrder != ''">
  929. order by read_rate ${param.sortOrder}
  930. </if>
  931. </if>
  932. </select>
  933. <!-- 按建筑统计15天表 -->
  934. <sql id="base_GetRateListByBuildingFor15Day">
  935. select
  936. rb.stat_day as stat_day,
  937. rb.building_id as building_id,
  938. b.`name` AS building_name,
  939. rb.device_count AS device_count,
  940. rb.read_times AS read_times,
  941. rb.real_read_times AS real_read_times,
  942. rb.un_read_times AS un_read_times,
  943. rb.read_rate AS read_rate,
  944. rb.customer_id as customer_id,
  945. c.customer_name as customer_name
  946. from
  947. sc_stat_meter_read_rate_by_building_15day rb
  948. LEFT JOIN sc_building b ON ( rb.building_id = b.id )
  949. LEFT JOIN sc_customer c on (rb.customer_id = c.id)
  950. </sql>
  951. <!-- 按建筑统计月表 -->
  952. <sql id="base_GetRateListByBuildingForMonth">
  953. select
  954. rb.stat_day as stat_day,
  955. rb.building_id as building_id,
  956. b.`name` AS building_name,
  957. rb.device_count AS device_count,
  958. rb.read_times AS read_times,
  959. rb.real_read_times AS real_read_times,
  960. rb.un_read_times AS un_read_times,
  961. rb.read_rate AS read_rate,
  962. rb.customer_id as customer_id,
  963. c.customer_name as customer_name
  964. from
  965. sc_stat_meter_read_rate_by_building_month rb
  966. LEFT JOIN sc_building b ON ( rb.building_id = b.id )
  967. LEFT JOIN sc_customer c on (rb.customer_id = c.id)
  968. </sql>
  969. <select id="getRateListByBuildingFor15Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  970. <include refid="base_GetRateListByBuildingFor15Day"></include>
  971. <include refid="where_clause"></include>
  972. <if test="param.sortColumn != null and param.sortColumn != ''">
  973. <if test="param.sortOrder != null and param.sortOrder != ''">
  974. order by ${param.sortColumn} ${param.sortOrder}
  975. </if>
  976. </if>
  977. </select>
  978. <select id="getRateListByBuildingForMonth" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  979. <include refid="base_GetRateListByBuildingForMonth"></include>
  980. <include refid="where_clause"></include>
  981. <if test="param.sortColumn != null and param.sortColumn != ''">
  982. <if test="param.sortOrder != null and param.sortOrder != ''">
  983. order by ${param.sortColumn} ${param.sortOrder}
  984. </if>
  985. </if>
  986. </select>
  987. <select id="getRateAreaListByBuildingFor15Day" resultType="com.bz.smart_city.dto.BuildingSelectInfoDto">
  988. select
  989. b.id,
  990. b.name,
  991. b.province,
  992. b.city,
  993. b.region,
  994. b.community,
  995. b.longitude,
  996. b.latitude,
  997. 0
  998. from
  999. sc_stat_meter_read_rate_by_building_15day rb
  1000. LEFT JOIN sc_building b ON ( rb.building_id = b.id )
  1001. LEFT JOIN sc_customer c on (rb.customer_id = c.id)
  1002. <include refid="where_clause"></include>
  1003. </select>
  1004. <select id="getRateAreaListByBuildingForMonth" resultType="com.bz.smart_city.dto.BuildingSelectInfoDto">
  1005. select
  1006. b.id,
  1007. b.name,
  1008. b.province,
  1009. b.city,
  1010. b.region,
  1011. b.community,
  1012. b.longitude,
  1013. b.latitude,
  1014. 0
  1015. from
  1016. sc_stat_meter_read_rate_by_building_month rb
  1017. LEFT JOIN sc_building b ON ( rb.building_id = b.id )
  1018. LEFT JOIN sc_customer c on (rb.customer_id = c.id)
  1019. <include refid="where_clause"></include>
  1020. </select>
  1021. <select id="summaryRateListByBuildingFor15Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  1022. select
  1023. ifnull(SUM(tmp.device_count),0) as device_count,
  1024. ifnull(SUM(tmp.read_times),0) as read_times,
  1025. ifnull(SUM(tmp.real_read_times),0) as real_read_times,
  1026. ifnull(SUM(tmp.un_read_times),0) as un_read_times,
  1027. ifnull(ROUND(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
  1028. from (
  1029. <include refid="base_GetRateListByBuildingFor15Day"></include>
  1030. <include refid="where_clause"></include>
  1031. ) tmp
  1032. <if test="param.sortColumn != null and param.sortColumn != ''">
  1033. <if test="param.sortOrder != null and param.sortOrder != ''">
  1034. order by read_rate ${param.sortOrder}
  1035. </if>
  1036. </if>
  1037. </select>
  1038. <select id="summaryRateListByBuildingForMonth" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  1039. select
  1040. ifnull(SUM(tmp.device_count),0) as device_count,
  1041. ifnull(SUM(tmp.read_times),0) as read_times,
  1042. ifnull(SUM(tmp.real_read_times),0) as real_read_times,
  1043. ifnull(SUM(tmp.un_read_times),0) as un_read_times,
  1044. ifnull(ROUND(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
  1045. from (
  1046. <include refid="base_GetRateListByBuildingForMonth"></include>
  1047. <include refid="where_clause"></include>
  1048. ) tmp
  1049. <if test="param.sortColumn != null and param.sortColumn != ''">
  1050. <if test="param.sortOrder != null and param.sortOrder != ''">
  1051. order by read_rate ${param.sortOrder}
  1052. </if>
  1053. </if>
  1054. </select>
  1055. <!-- 按建筑统计15天表 新装水表场景适用-->
  1056. <sql id="base_GetRateListByBuildingFor15DayWithNew">
  1057. select
  1058. rb.stat_day as stat_day,
  1059. rb.building_id as building_id,
  1060. b.`name` AS building_name,
  1061. rb.device_count AS device_count,
  1062. rb.read_times AS read_times,
  1063. rb.real_read_times AS real_read_times,
  1064. rb.un_read_times AS un_read_times,
  1065. rb.customer_id as customer_id,
  1066. c.customer_name as customer_name,
  1067. (
  1068. SELECT
  1069. count( 1 )
  1070. FROM
  1071. sc_install_list l
  1072. WHERE
  1073. l.`status` = 1
  1074. AND l.is_installed = 1
  1075. AND l.is_accepted = 0
  1076. AND l.building_id = rb.building_id
  1077. ) AS installed_device_count,
  1078. (
  1079. SELECT
  1080. SUM( IF ( d.device_status = 5, 1, 0 ) )
  1081. FROM
  1082. sc_device d
  1083. WHERE
  1084. d.building_id = rb.building_id
  1085. AND d.`status` = 1
  1086. AND d.sys_id = - 99
  1087. ) AS unenable_device_count ,
  1088. FORMAT(rb.real_read_times/ (
  1089. SELECT
  1090. count( 1 )
  1091. FROM
  1092. sc_install_list l
  1093. WHERE
  1094. l.`status` = 1
  1095. AND l.is_installed = 1
  1096. AND l.is_accepted = 0
  1097. AND l.building_id = rb.building_id
  1098. ) *100, 2) as read_rate
  1099. from
  1100. sc_stat_meter_read_rate_by_building_15day rb
  1101. LEFT JOIN sc_building b ON ( rb.building_id = b.id )
  1102. LEFT JOIN sc_customer c on (rb.customer_id = c.id)
  1103. </sql>
  1104. <select id="getRateListByBuildingFor15DayWithNew" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  1105. <include refid="base_GetRateListByBuildingFor15DayWithNew"></include>
  1106. <include refid="where_clause"></include>
  1107. <if test="param.sortColumn != null and param.sortColumn != ''">
  1108. <if test="param.sortOrder != null and param.sortOrder != ''">
  1109. order by ${param.sortColumn} ${param.sortOrder}
  1110. </if>
  1111. </if>
  1112. </select>
  1113. <select id="summaryRateListByBuildingFor15DayWithNew" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  1114. select
  1115. ifnull(SUM(tmp.installed_device_count),0) as device_count,
  1116. ifnull(SUM(tmp.read_times),0) as read_times,
  1117. ifnull(SUM(tmp.real_read_times),0) as real_read_times,
  1118. ifnull(SUM(tmp.un_read_times),0) as un_read_times,
  1119. ifnull(ROUND(SUM(tmp.real_read_times)/SUM(tmp.installed_device_count)*100,2),0) as read_rate
  1120. from (
  1121. <include refid="base_GetRateListByBuildingFor15DayWithNew"></include>
  1122. <include refid="where_clause"></include>
  1123. ) tmp
  1124. <if test="param.sortColumn != null and param.sortColumn != ''">
  1125. <if test="param.sortOrder != null and param.sortOrder != ''">
  1126. order by read_rate ${param.sortOrder}
  1127. </if>
  1128. </if>
  1129. </select>
  1130. </mapper>