StatMeterReadRateByBuildingMapper.xml 60 KB

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