StatMeterReadRateByCollectorMapper.xml 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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.StatMeterReadRateByCollectorMapper">
  4. <!--auto generated Code-->
  5. <resultMap id="BaseResultMap" type="com.bz.smart_city.entity.StatMeterReadRateByCollector">
  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="concentrator_id" property="concentratorId" jdbcType="INTEGER"/>
  11. <result column="collector_id" property="collectorId" jdbcType="INTEGER"/>
  12. <result column="device_count" property="deviceCount" jdbcType="INTEGER"/>
  13. <result column="read_times" property="readTimes" jdbcType="INTEGER"/>
  14. <result column="real_read_times" property="realReadTimes" jdbcType="INTEGER"/>
  15. <result column="un_read_times" property="unReadTimes" jdbcType="INTEGER"/>
  16. <result column="read_rate" property="readRate" jdbcType="DECIMAL"/>
  17. <result column="date_create" property="dateCreate" jdbcType="TIMESTAMP"/>
  18. <result column="date_update" property="dateUpdate" jdbcType="TIMESTAMP"/>
  19. </resultMap>
  20. <!--auto generated Code-->
  21. <sql id="Base_Column_List">
  22. stat_day,
  23. site_id,
  24. channel_id,
  25. customer_id,
  26. concentrator_id,
  27. collector_id,
  28. device_count,
  29. read_times,
  30. real_read_times,
  31. un_read_times,
  32. read_rate,
  33. date_create,
  34. date_update
  35. </sql>
  36. <!--auto generated Code-->
  37. <insert id="insert" useGeneratedKeys="true" keyProperty="statMeterReadRateByCollector.statDay">
  38. INSERT INTO sc_stat_meter_read_rate_by_collector (
  39. stat_day,
  40. site_id,
  41. channel_id,
  42. customer_id,
  43. concentrator_id,
  44. collector_id,
  45. device_count,
  46. read_times,
  47. real_read_times,
  48. un_read_times,
  49. read_rate,
  50. date_create,
  51. date_update
  52. ) VALUES (
  53. #{statMeterReadRateByCollector.statDay,jdbcType=INTEGER},
  54. #{statMeterReadRateByCollector.siteId,jdbcType=INTEGER},
  55. #{statMeterReadRateByCollector.channelId,jdbcType=INTEGER},
  56. #{statMeterReadRateByCollector.customerId,jdbcType=INTEGER},
  57. #{statMeterReadRateByCollector.concentratorId,jdbcType=INTEGER},
  58. #{statMeterReadRateByCollector.collectorId,jdbcType=INTEGER},
  59. #{statMeterReadRateByCollector.deviceCount,jdbcType=INTEGER},
  60. #{statMeterReadRateByCollector.readTimes,jdbcType=INTEGER},
  61. #{statMeterReadRateByCollector.realReadTimes,jdbcType=INTEGER},
  62. #{statMeterReadRateByCollector.unReadTimes,jdbcType=INTEGER},
  63. #{statMeterReadRateByCollector.readRate,jdbcType=DECIMAL},
  64. #{statMeterReadRateByCollector.dateCreate,jdbcType=TIMESTAMP},
  65. #{statMeterReadRateByCollector.dateUpdate,jdbcType=TIMESTAMP}
  66. )
  67. </insert>
  68. <!--auto generated Code-->
  69. <insert id="insertSelective" useGeneratedKeys="true" keyProperty="statMeterReadRateByCollector.statDay">
  70. INSERT INTO sc_stat_meter_read_rate_by_collector
  71. <trim prefix="(" suffix=")" suffixOverrides=",">
  72. <if test="statMeterReadRateByCollector.statDay!=null"> stat_day,</if>
  73. <if test="statMeterReadRateByCollector.siteId!=null"> site_id,</if>
  74. <if test="statMeterReadRateByCollector.channelId!=null"> channel_id,</if>
  75. <if test="statMeterReadRateByCollector.customerId!=null"> customer_id,</if>
  76. <if test="statMeterReadRateByCollector.concentratorId!=null"> concentrator_id,</if>
  77. <if test="statMeterReadRateByCollector.collectorId!=null"> collector_id,</if>
  78. <if test="statMeterReadRateByCollector.deviceCount!=null"> device_count,</if>
  79. <if test="statMeterReadRateByCollector.readTimes!=null"> read_times,</if>
  80. <if test="statMeterReadRateByCollector.realReadTimes!=null"> real_read_times,</if>
  81. <if test="statMeterReadRateByCollector.unReadTimes!=null"> un_read_times,</if>
  82. <if test="statMeterReadRateByCollector.readRate!=null"> read_rate,</if>
  83. <if test="statMeterReadRateByCollector.dateCreate!=null"> date_create,</if>
  84. <if test="statMeterReadRateByCollector.dateUpdate!=null"> date_update,</if>
  85. </trim>
  86. VALUES
  87. <trim prefix="(" suffix=")" suffixOverrides=",">
  88. <if test="statMeterReadRateByCollector.statDay!=null">#{statMeterReadRateByCollector.statDay,jdbcType=INTEGER},
  89. </if>
  90. <if test="statMeterReadRateByCollector.siteId!=null">#{statMeterReadRateByCollector.siteId,jdbcType=INTEGER},
  91. </if>
  92. <if test="statMeterReadRateByCollector.channelId!=null">#{statMeterReadRateByCollector.channelId,jdbcType=INTEGER},
  93. </if>
  94. <if test="statMeterReadRateByCollector.customerId!=null">#{statMeterReadRateByCollector.customerId,jdbcType=INTEGER},
  95. </if>
  96. <if test="statMeterReadRateByCollector.concentratorId!=null">#{statMeterReadRateByCollector.concentratorId,jdbcType=INTEGER},
  97. </if>
  98. <if test="statMeterReadRateByCollector.collectorId!=null">#{statMeterReadRateByCollector.collectorId,jdbcType=INTEGER},
  99. </if>
  100. <if test="statMeterReadRateByCollector.deviceCount!=null">#{statMeterReadRateByCollector.deviceCount,jdbcType=INTEGER},
  101. </if>
  102. <if test="statMeterReadRateByCollector.readTimes!=null">#{statMeterReadRateByCollector.readTimes,jdbcType=INTEGER},
  103. </if>
  104. <if test="statMeterReadRateByCollector.realReadTimes!=null">#{statMeterReadRateByCollector.realReadTimes,jdbcType=INTEGER},
  105. </if>
  106. <if test="statMeterReadRateByCollector.unReadTimes!=null">#{statMeterReadRateByCollector.unReadTimes,jdbcType=INTEGER},
  107. </if>
  108. <if test="statMeterReadRateByCollector.readRate!=null">#{statMeterReadRateByCollector.readRate,jdbcType=DECIMAL},
  109. </if>
  110. <if test="statMeterReadRateByCollector.dateCreate!=null">#{statMeterReadRateByCollector.dateCreate,jdbcType=TIMESTAMP},
  111. </if>
  112. <if test="statMeterReadRateByCollector.dateUpdate!=null">#{statMeterReadRateByCollector.dateUpdate,jdbcType=TIMESTAMP},
  113. </if>
  114. </trim>
  115. </insert>
  116. <!--auto generated Code-->
  117. <insert id="insertList">
  118. INSERT INTO sc_stat_meter_read_rate_by_collector (
  119. stat_day,
  120. site_id,
  121. channel_id,
  122. customer_id,
  123. concentrator_id,
  124. collector_id,
  125. device_count,
  126. read_times,
  127. real_read_times,
  128. un_read_times,
  129. read_rate,
  130. date_create,
  131. date_update
  132. )VALUES
  133. <foreach collection="statMeterReadRateByCollectors" item="statMeterReadRateByCollector" index="index" separator=",">
  134. (
  135. #{statMeterReadRateByCollector.statDay,jdbcType=INTEGER},
  136. #{statMeterReadRateByCollector.siteId,jdbcType=INTEGER},
  137. #{statMeterReadRateByCollector.channelId,jdbcType=INTEGER},
  138. #{statMeterReadRateByCollector.customerId,jdbcType=INTEGER},
  139. #{statMeterReadRateByCollector.concentratorId,jdbcType=INTEGER},
  140. #{statMeterReadRateByCollector.collectorId,jdbcType=INTEGER},
  141. #{statMeterReadRateByCollector.deviceCount,jdbcType=INTEGER},
  142. #{statMeterReadRateByCollector.readTimes,jdbcType=INTEGER},
  143. #{statMeterReadRateByCollector.realReadTimes,jdbcType=INTEGER},
  144. #{statMeterReadRateByCollector.unReadTimes,jdbcType=INTEGER},
  145. #{statMeterReadRateByCollector.readRate,jdbcType=DECIMAL},
  146. #{statMeterReadRateByCollector.dateCreate,jdbcType=TIMESTAMP},
  147. #{statMeterReadRateByCollector.dateUpdate,jdbcType=TIMESTAMP}
  148. )
  149. </foreach>
  150. </insert>
  151. <!--auto generated Code-->
  152. <update id="updateByPrimaryKeySelective">
  153. UPDATE sc_stat_meter_read_rate_by_collector
  154. <set>
  155. <if test="statMeterReadRateByCollector.siteId != null"> site_id= #{statMeterReadRateByCollector.siteId,jdbcType=INTEGER},</if>
  156. <if test="statMeterReadRateByCollector.channelId != null"> channel_id= #{statMeterReadRateByCollector.channelId,jdbcType=INTEGER},</if>
  157. <if test="statMeterReadRateByCollector.customerId != null"> customer_id= #{statMeterReadRateByCollector.customerId,jdbcType=INTEGER},</if>
  158. <if test="statMeterReadRateByCollector.concentratorId != null"> concentrator_id= #{statMeterReadRateByCollector.concentratorId,jdbcType=INTEGER},</if>
  159. <if test="statMeterReadRateByCollector.collectorId != null"> collector_id= #{statMeterReadRateByCollector.collectorId,jdbcType=INTEGER},</if>
  160. <if test="statMeterReadRateByCollector.deviceCount != null"> device_count= #{statMeterReadRateByCollector.deviceCount,jdbcType=INTEGER},</if>
  161. <if test="statMeterReadRateByCollector.readTimes != null"> read_times= #{statMeterReadRateByCollector.readTimes,jdbcType=INTEGER},</if>
  162. <if test="statMeterReadRateByCollector.realReadTimes != null"> real_read_times= #{statMeterReadRateByCollector.realReadTimes,jdbcType=INTEGER},</if>
  163. <if test="statMeterReadRateByCollector.unReadTimes != null"> un_read_times= #{statMeterReadRateByCollector.unReadTimes,jdbcType=INTEGER},</if>
  164. <if test="statMeterReadRateByCollector.readRate != null"> read_rate= #{statMeterReadRateByCollector.readRate,jdbcType=DECIMAL},</if>
  165. <if test="statMeterReadRateByCollector.dateCreate != null"> date_create= #{statMeterReadRateByCollector.dateCreate,jdbcType=TIMESTAMP},</if>
  166. <if test="statMeterReadRateByCollector.dateUpdate != null"> date_update= #{statMeterReadRateByCollector.dateUpdate,jdbcType=TIMESTAMP}</if>
  167. </set>
  168. WHERE stat_day = #{statMeterReadRateByCollector.statDay,jdbcType=INTEGER}
  169. </update>
  170. <sql id="base_query">
  171. SELECT
  172. cust.customer_name as customer_name,
  173. con.serial_number as serial_number,
  174. col.collector_no as collector_no,
  175. tmp.device_count as device_count,
  176. tmp.read_times as read_times,
  177. tmp.real_read_times as real_read_times,
  178. tmp.un_read_times as un_read_times,
  179. tmp.read_rate as read_rate
  180. FROM
  181. (
  182. SELECT
  183. customer_id,
  184. concentrator_id,
  185. collector_id,
  186. sum( device_count) AS device_count,
  187. sum( read_times ) AS read_times,
  188. sum( real_read_times ) AS real_read_times,
  189. sum( un_read_times ) AS un_read_times ,
  190. FORMAT( sum( real_read_times ) / sum( read_times ) * 100, 2 ) AS read_rate
  191. FROM
  192. sc_stat_meter_read_rate_by_collector
  193. WHERE 1 = 1
  194. <!-- 表类型 -->
  195. <if test="param.deviceTypeId != null ">
  196. and meter_type_id = #{param.deviceTypeId}
  197. </if>
  198. <!-- 数据权限 -->
  199. <if test="param.siteId != null and param.siteId != 0 "> and site_id = #{param.siteId} </if>
  200. <!--
  201. <if test="param.isAdmin != null and param.isAdmin == 1">
  202. and site_id = 0
  203. </if>
  204. <if test="param.sites != null and param.sites.size() != 0">
  205. and site_id in
  206. <foreach collection="param.sites" item="site" open="(" separator="," close=")">
  207. #{site.id}
  208. </foreach>
  209. </if>
  210. -->
  211. <if test='param.programItems != null and param.programItems.size() != 0' >
  212. and collector_id IN (
  213. SELECT DISTINCT
  214. rd.collector_id
  215. FROM
  216. sc_water_related_device rd
  217. WHERE
  218. rd.device_id IN (
  219. SELECT
  220. ud.device_id
  221. FROM
  222. (
  223. SELECT
  224. DISTINCT df.device_id
  225. FROM sc_device_dim_info df
  226. WHERE 1 = 1
  227. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  228. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  229. </foreach> ) ud
  230. )
  231. )
  232. </if>
  233. <if test = "param.startDate != null and param.startDate != 0"> and stat_day >= #{param.startDate}</if>
  234. <if test = "param.endDate != null and param.endDate != 0"> and stat_day <![CDATA[ <= ]]> #{param.endDate}</if>
  235. GROUP BY
  236. customer_id,
  237. concentrator_id,
  238. collector_id
  239. ) tmp
  240. LEFT JOIN sc_customer cust ON ( tmp.customer_id = cust.id )
  241. LEFT JOIN sc_concentrator con ON ( tmp.concentrator_id = con.id )
  242. LEFT JOIN sc_collector col ON ( tmp.collector_id = col.id )
  243. </sql>
  244. <sql id="where_clause">
  245. where 1 = 1
  246. <if test = "param.beginRate != null "> and tmp.read_rate >= #{param.beginRate}</if>
  247. <if test = "param.endRate != null "> and tmp.read_rate <![CDATA[ <= ]]> #{param.endRate}</if>
  248. <if test = "param.custormerId != null"> and tmp.customer_id = #{param.custormerId}</if>
  249. <if test = "param.collectorCode != null and param.collectorCode != '' "> and col.collector_no like #{param.collectorCode}</if>
  250. <if test = "param.concentratorCode != null and param.concentratorCode != '' "> and con.serial_number like #{param.concentratorCode}</if>
  251. </sql>
  252. <select id="summaryList" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  253. select
  254. ifnull(SUM(tmp.device_count),0) as device_count,
  255. ifnull(SUM(tmp.read_times),0) as read_times,
  256. ifnull(SUM(tmp.real_read_times),0) as real_read_times,
  257. ifnull(SUM(tmp.un_read_times),0) as un_read_times,
  258. ifnull(FORMAT(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
  259. from (
  260. <include refid="base_query" />
  261. <include refid="where_clause"/>
  262. ) tmp
  263. </select>
  264. <!-- 查询抄表率,不含近7天统计 -->
  265. <select id="getListWithOut7Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  266. <include refid="base_query" />
  267. <include refid="where_clause" />
  268. </select>
  269. <!-- 查询抄表率,含近7天统计 -->
  270. <select id="getListWith7Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  271. SELECT
  272. rc.stat_day as stat_day,
  273. cust.customer_name as customer_name,
  274. con.serial_number as serial_number,
  275. col.collector_no as collector_no,
  276. rc.device_count as device_count,
  277. rc.read_times as read_times,
  278. rc.real_read_times as real_read_times,
  279. rc.un_read_times as un_read_times,
  280. rc.read_rate as read_rate,
  281. rcd.read_rate as last_seven_day_read_rate
  282. FROM
  283. sc_stat_meter_read_rate_by_collector rc
  284. LEFT JOIN sc_stat_meter_read_rate_by_collector_7day rcd ON (
  285. rc.site_id = rcd.site_id
  286. AND rc.channel_id = rcd.channel_id
  287. AND rc.customer_id = rcd.customer_id
  288. and rc.meter_type_id = rcd.meter_type_id
  289. AND rc.concentrator_id = rcd.concentrator_id
  290. AND rc.collector_id = rcd.collector_id
  291. AND rc.stat_day = rcd.stat_day
  292. )
  293. LEFT JOIN sc_customer cust ON ( rc.customer_id = cust.id )
  294. LEFT JOIN sc_concentrator con ON ( rc.concentrator_id = con.id )
  295. LEFT JOIN sc_collector col ON ( rc.collector_id = col.id )
  296. where 1 = 1
  297. <!-- 表类型 -->
  298. <if test="param.deviceTypeId != null ">
  299. and rc.meter_type_id = #{param.deviceTypeId}
  300. </if>
  301. <!-- 数据权限 -->
  302. <if test="param.siteId != null and param.siteId != 0 "> and rc.site_id = #{param.siteId} </if>
  303. <!--
  304. <if test="param.isAdmin != null and param.isAdmin == 1">
  305. and rc.site_id = 0
  306. </if>
  307. <if test="param.sites != null and param.sites.size() != 0">
  308. and rc.site_id in
  309. <foreach collection="param.sites" item="site" open="(" separator="," close=")">
  310. #{site.id}
  311. </foreach>
  312. </if>
  313. -->
  314. <if test='param.programItems != null and param.programItems.size() != 0' >
  315. and rc.collector_id IN (
  316. SELECT DISTINCT
  317. rd.collector_id
  318. FROM
  319. sc_water_related_device rd
  320. WHERE
  321. rd.device_id IN (
  322. SELECT
  323. ud.device_id
  324. FROM
  325. (
  326. SELECT
  327. DISTINCT df.device_id
  328. FROM sc_device_dim_info df
  329. WHERE 1 = 1
  330. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  331. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  332. </foreach> ) ud
  333. )
  334. )
  335. </if>
  336. <if test = "param.startDate != null and param.startDate != 0"> and rc.stat_day >= #{param.startDate}</if>
  337. <if test = "param.endDate != null and param.endDate != 0"> and rc.stat_day <![CDATA[ <= ]]> #{param.endDate}</if>
  338. <if test = "param.beginRate != null "> and rc.read_rate >= #{param.beginRate}</if>
  339. <if test = "param.endRate != null "> and rc.read_rate <![CDATA[ <= ]]> #{param.endRate}</if>
  340. <if test = "param.custormerId != null"> and rc.customer_id = #{param.custormerId}</if>
  341. <if test = "param.collectorCode != null and param.collectorCode != '' "> and col.collector_no like #{param.collectorCode}</if>
  342. <if test = "param.concentratorCode != null and param.concentratorCode != '' "> and con.serial_number like #{param.concentratorCode}</if>
  343. </select>
  344. <!--查询抄表率明细-->
  345. <select id="getList" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  346. SELECT
  347. d.customer_name,
  348. a.*,
  349. b.collector_no,
  350. c.serial_number
  351. FROM
  352. sc_stat_meter_read_rate_by_collector a
  353. LEFT JOIN sc_customer d ON d.id = a.customer_id
  354. LEFT JOIN sc_collector b ON b.id = a.collector_id
  355. LEFT JOIN sc_concentrator c ON c.id = a.concentrator_id
  356. WHERE 1=1
  357. <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
  358. AND DATE(a.stat_day) BETWEEN CONCAT(#{beginTime},' 00:00:00') AND CONCAT(#{endTime}, '23:59:59')
  359. </if>
  360. <if test="beginRate !=null">
  361. AND a.read_rate >= #{beginRate}
  362. </if>
  363. <if test="endRate !=null">
  364. AND #{endRate} >= a.read_rate
  365. </if>
  366. <if test="customerId !=null">
  367. AND a.customer_id = #{customerId}
  368. </if>
  369. <if test="serialNumber !=null and serialNumber !=''">
  370. AND c.serial_number LIKE CONCAT('%',#{serialNumber},'%')
  371. </if>
  372. <if test="collectorNo !=null and collectorNo !=''">
  373. AND b.collector_no LIKE CONCAT('%',#{collectorNo},'%')
  374. </if>
  375. </select>
  376. <!--查询客户最近7天抄表率-->
  377. <select id="getLast7DayReadRate" resultType="String">
  378. SELECT SUM(read_rate)/COUNT(1)
  379. FROM sc_stat_meter_read_rate_by_collector
  380. WHERE customer_id = #{customerId}
  381. AND DATE(stat_day) BETWEEN CONCAT(#{beginTime},' 00:00:00') AND CONCAT(#{endTime}, '23:59:59')
  382. </select>
  383. <sql id= "base_query_getListByDay">
  384. SELECT
  385. cust.customer_name as customer_name,
  386. con.serial_number as serial_number,
  387. col.collector_no as collector_no,
  388. tmp.device_count as device_count,
  389. tmp.read_times as read_times,
  390. tmp.real_read_times as real_read_times,
  391. tmp.un_read_times as un_read_times,
  392. tmp.read_rate as read_rate
  393. FROM
  394. (
  395. SELECT
  396. customer_id,
  397. concentrator_id,
  398. collector_id,
  399. sum( device_count) AS device_count,
  400. sum( read_times ) AS read_times,
  401. sum( real_read_times ) AS real_read_times,
  402. sum( un_read_times ) AS un_read_times ,
  403. FORMAT( sum( real_read_times ) / sum( read_times ) * 100, 2 ) AS read_rate
  404. FROM
  405. sc_stat_meter_read_rate_by_collector
  406. WHERE 1 = 1
  407. <!-- 表类型 -->
  408. <if test="param.deviceTypeId != null ">
  409. and meter_type_id = #{param.deviceTypeId}
  410. </if>
  411. <!-- 数据权限 -->
  412. <if test="param.siteId != null and param.siteId != 0 "> and site_id = #{param.siteId} </if>
  413. <if test='param.programItems != null and param.programItems.size() != 0' >
  414. and collector_id IN (
  415. SELECT DISTINCT
  416. rd.collector_id
  417. FROM
  418. sc_water_related_device rd
  419. WHERE
  420. rd.device_id IN (
  421. SELECT
  422. ud.device_id
  423. FROM
  424. (
  425. SELECT
  426. DISTINCT df.device_id
  427. FROM sc_device_dim_info df
  428. WHERE 1 = 1
  429. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  430. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  431. </foreach> ) ud
  432. )
  433. )
  434. </if>
  435. <if test = "param.statDay != null and param.statDay != 0"> and stat_day = #{param.statDay}</if>
  436. GROUP BY
  437. customer_id,
  438. concentrator_id,
  439. collector_id
  440. ) tmp
  441. LEFT JOIN sc_customer cust ON ( tmp.customer_id = cust.id )
  442. LEFT JOIN sc_concentrator con ON ( tmp.concentrator_id = con.id )
  443. LEFT JOIN sc_collector col ON ( tmp.collector_id = col.id )
  444. </sql>
  445. <select id="getListByDay" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  446. <include refid="base_query_getListByDay" />
  447. <include refid="where_clause" />
  448. <if test="param.sortColumn != null and param.sortColumn != ''">
  449. <if test="param.sortOrder != null and param.sortOrder != ''">
  450. order by ${param.sortColumn} ${param.sortOrder}
  451. </if>
  452. </if>
  453. </select>
  454. <select id="summaryListByDay" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  455. select
  456. ifnull(SUM(tmp.device_count),0) as device_count,
  457. ifnull(SUM(tmp.read_times),0) as read_times,
  458. ifnull(SUM(tmp.real_read_times),0) as real_read_times,
  459. ifnull(SUM(tmp.un_read_times),0) as un_read_times,
  460. ifnull(FORMAT(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
  461. from (
  462. <include refid="base_query_getListByDay" />
  463. <include refid="where_clause"/>
  464. ) tmp
  465. </select>
  466. <sql id= "base_query_getListBy7Day">
  467. SELECT
  468. cust.customer_name as customer_name,
  469. con.serial_number as serial_number,
  470. col.collector_no as collector_no,
  471. tmp.device_count as device_count,
  472. tmp.read_times as read_times,
  473. tmp.real_read_times as real_read_times,
  474. tmp.un_read_times as un_read_times,
  475. tmp.read_rate as read_rate
  476. FROM
  477. (
  478. SELECT
  479. customer_id,
  480. concentrator_id,
  481. collector_id,
  482. sum( device_count) AS device_count,
  483. sum( read_times ) AS read_times,
  484. sum( real_read_times ) AS real_read_times,
  485. sum( un_read_times ) AS un_read_times ,
  486. FORMAT( sum( real_read_times ) / sum( read_times ) * 100, 2 ) AS read_rate
  487. FROM
  488. sc_stat_meter_read_rate_by_collector_7day
  489. WHERE 1 = 1
  490. <!-- 表类型 -->
  491. <if test="param.deviceTypeId != null ">
  492. and meter_type_id = #{param.deviceTypeId}
  493. </if>
  494. <!-- 数据权限 -->
  495. <if test="param.siteId != null and param.siteId != 0 "> and site_id = #{param.siteId} </if>
  496. <if test='param.programItems != null and param.programItems.size() != 0' >
  497. and collector_id IN (
  498. SELECT DISTINCT
  499. rd.collector_id
  500. FROM
  501. sc_water_related_device rd
  502. WHERE
  503. rd.device_id IN (
  504. SELECT
  505. ud.device_id
  506. FROM
  507. (
  508. SELECT
  509. DISTINCT df.device_id
  510. FROM sc_device_dim_info df
  511. WHERE 1 = 1
  512. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  513. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  514. </foreach> ) ud
  515. )
  516. )
  517. </if>
  518. <if test = "param.statDay != null and param.statDay != 0"> and stat_day = #{param.statDay}</if>
  519. GROUP BY
  520. customer_id,
  521. concentrator_id,
  522. collector_id
  523. ) tmp
  524. LEFT JOIN sc_customer cust ON ( tmp.customer_id = cust.id )
  525. LEFT JOIN sc_concentrator con ON ( tmp.concentrator_id = con.id )
  526. LEFT JOIN sc_collector col ON ( tmp.collector_id = col.id )
  527. </sql>
  528. <select id="getListBy7Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  529. <include refid="base_query_getListBy7Day" />
  530. <include refid="where_clause" />
  531. <if test="param.sortColumn != null and param.sortColumn != ''">
  532. <if test="param.sortOrder != null and param.sortOrder != ''">
  533. order by ${param.sortColumn} ${param.sortOrder}
  534. </if>
  535. </if>
  536. </select>
  537. <select id="summaryListBy7Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  538. select
  539. ifnull(SUM(tmp.device_count),0) as device_count,
  540. ifnull(SUM(tmp.read_times),0) as read_times,
  541. ifnull(SUM(tmp.real_read_times),0) as real_read_times,
  542. ifnull(SUM(tmp.un_read_times),0) as un_read_times,
  543. ifnull(FORMAT(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
  544. from (
  545. <include refid="base_query_getListBy7Day" />
  546. <include refid="where_clause"/>
  547. ) tmp
  548. </select>
  549. <sql id= "base_query_getListBy15Day">
  550. SELECT
  551. cust.customer_name as customer_name,
  552. con.serial_number as serial_number,
  553. col.collector_no as collector_no,
  554. tmp.device_count as device_count,
  555. tmp.read_times as read_times,
  556. tmp.real_read_times as real_read_times,
  557. tmp.un_read_times as un_read_times,
  558. tmp.read_rate as read_rate
  559. FROM
  560. (
  561. SELECT
  562. customer_id,
  563. concentrator_id,
  564. collector_id,
  565. sum( device_count) AS device_count,
  566. sum( read_times ) AS read_times,
  567. sum( real_read_times ) AS real_read_times,
  568. sum( un_read_times ) AS un_read_times ,
  569. FORMAT( sum( real_read_times ) / sum( read_times ) * 100, 2 ) AS read_rate
  570. FROM
  571. sc_stat_meter_read_rate_by_collector_15day
  572. WHERE 1 = 1
  573. <!-- 表类型 -->
  574. <if test="param.deviceTypeId != null ">
  575. and meter_type_id = #{param.deviceTypeId}
  576. </if>
  577. <!-- 数据权限 -->
  578. <if test="param.siteId != null and param.siteId != 0 "> and site_id = #{param.siteId} </if>
  579. <if test='param.programItems != null and param.programItems.size() != 0' >
  580. and collector_id IN (
  581. SELECT DISTINCT
  582. rd.collector_id
  583. FROM
  584. sc_water_related_device rd
  585. WHERE
  586. rd.device_id IN (
  587. SELECT
  588. ud.device_id
  589. FROM
  590. (
  591. SELECT
  592. DISTINCT df.device_id
  593. FROM sc_device_dim_info df
  594. WHERE 1 = 1
  595. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  596. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  597. </foreach> ) ud
  598. )
  599. )
  600. </if>
  601. <if test = "param.statDay != null and param.statDay != 0"> and stat_day = #{param.statDay}</if>
  602. GROUP BY
  603. customer_id,
  604. concentrator_id,
  605. collector_id
  606. ) tmp
  607. LEFT JOIN sc_customer cust ON ( tmp.customer_id = cust.id )
  608. LEFT JOIN sc_concentrator con ON ( tmp.concentrator_id = con.id )
  609. LEFT JOIN sc_collector col ON ( tmp.collector_id = col.id )
  610. </sql>
  611. <select id="getListBy15Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  612. <include refid="base_query_getListBy15Day" />
  613. <include refid="where_clause" />
  614. <if test="param.sortColumn != null and param.sortColumn != ''">
  615. <if test="param.sortOrder != null and param.sortOrder != ''">
  616. order by ${param.sortColumn} ${param.sortOrder}
  617. </if>
  618. </if>
  619. </select>
  620. <select id="summaryListBy15Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  621. select
  622. ifnull(SUM(tmp.device_count),0) as device_count,
  623. ifnull(SUM(tmp.read_times),0) as read_times,
  624. ifnull(SUM(tmp.real_read_times),0) as real_read_times,
  625. ifnull(SUM(tmp.un_read_times),0) as un_read_times,
  626. ifnull(FORMAT(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
  627. from (
  628. <include refid="base_query_getListBy15Day" />
  629. <include refid="where_clause"/>
  630. ) tmp
  631. </select>
  632. </mapper>