StatMeterReadRateByConcentratorMapper.xml 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  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.StatMeterReadRateByConcentratorMapper">
  4. <!--auto generated Code-->
  5. <resultMap id="BaseResultMap" type="com.bz.smart_city.entity.StatMeterReadRateByConcentrator">
  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="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. concentrator_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="statMeterReadRateByConcentrator.statDay">
  36. INSERT INTO sc_stat_meter_read_rate_by_concentrator (
  37. stat_day,
  38. site_id,
  39. channel_id,
  40. customer_id,
  41. concentrator_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. #{statMeterReadRateByConcentrator.statDay,jdbcType=INTEGER},
  51. #{statMeterReadRateByConcentrator.siteId,jdbcType=INTEGER},
  52. #{statMeterReadRateByConcentrator.channelId,jdbcType=INTEGER},
  53. #{statMeterReadRateByConcentrator.customerId,jdbcType=INTEGER},
  54. #{statMeterReadRateByConcentrator.concentratorId,jdbcType=INTEGER},
  55. #{statMeterReadRateByConcentrator.deviceCount,jdbcType=INTEGER},
  56. #{statMeterReadRateByConcentrator.readTimes,jdbcType=INTEGER},
  57. #{statMeterReadRateByConcentrator.realReadTimes,jdbcType=INTEGER},
  58. #{statMeterReadRateByConcentrator.unReadTimes,jdbcType=INTEGER},
  59. #{statMeterReadRateByConcentrator.readRate,jdbcType=DECIMAL},
  60. #{statMeterReadRateByConcentrator.dateCreate,jdbcType=TIMESTAMP},
  61. #{statMeterReadRateByConcentrator.dateUpdate,jdbcType=TIMESTAMP}
  62. )
  63. </insert>
  64. <!--auto generated Code-->
  65. <insert id="insertSelective" useGeneratedKeys="true" keyProperty="statMeterReadRateByConcentrator.statDay">
  66. INSERT INTO sc_stat_meter_read_rate_by_concentrator
  67. <trim prefix="(" suffix=")" suffixOverrides=",">
  68. <if test="statMeterReadRateByConcentrator.statDay!=null"> stat_day,</if>
  69. <if test="statMeterReadRateByConcentrator.siteId!=null"> site_id,</if>
  70. <if test="statMeterReadRateByConcentrator.channelId!=null"> channel_id,</if>
  71. <if test="statMeterReadRateByConcentrator.customerId!=null"> customer_id,</if>
  72. <if test="statMeterReadRateByConcentrator.concentratorId!=null"> concentrator_id,</if>
  73. <if test="statMeterReadRateByConcentrator.deviceCount!=null"> device_count,</if>
  74. <if test="statMeterReadRateByConcentrator.readTimes!=null"> read_times,</if>
  75. <if test="statMeterReadRateByConcentrator.realReadTimes!=null"> real_read_times,</if>
  76. <if test="statMeterReadRateByConcentrator.unReadTimes!=null"> un_read_times,</if>
  77. <if test="statMeterReadRateByConcentrator.readRate!=null"> read_rate,</if>
  78. <if test="statMeterReadRateByConcentrator.dateCreate!=null"> date_create,</if>
  79. <if test="statMeterReadRateByConcentrator.dateUpdate!=null"> date_update,</if>
  80. </trim>
  81. VALUES
  82. <trim prefix="(" suffix=")" suffixOverrides=",">
  83. <if test="statMeterReadRateByConcentrator.statDay!=null">#{statMeterReadRateByConcentrator.statDay,jdbcType=INTEGER},
  84. </if>
  85. <if test="statMeterReadRateByConcentrator.siteId!=null">#{statMeterReadRateByConcentrator.siteId,jdbcType=INTEGER},
  86. </if>
  87. <if test="statMeterReadRateByConcentrator.channelId!=null">#{statMeterReadRateByConcentrator.channelId,jdbcType=INTEGER},
  88. </if>
  89. <if test="statMeterReadRateByConcentrator.customerId!=null">#{statMeterReadRateByConcentrator.customerId,jdbcType=INTEGER},
  90. </if>
  91. <if test="statMeterReadRateByConcentrator.concentratorId!=null">#{statMeterReadRateByConcentrator.concentratorId,jdbcType=INTEGER},
  92. </if>
  93. <if test="statMeterReadRateByConcentrator.deviceCount!=null">#{statMeterReadRateByConcentrator.deviceCount,jdbcType=INTEGER},
  94. </if>
  95. <if test="statMeterReadRateByConcentrator.readTimes!=null">#{statMeterReadRateByConcentrator.readTimes,jdbcType=INTEGER},
  96. </if>
  97. <if test="statMeterReadRateByConcentrator.realReadTimes!=null">#{statMeterReadRateByConcentrator.realReadTimes,jdbcType=INTEGER},
  98. </if>
  99. <if test="statMeterReadRateByConcentrator.unReadTimes!=null">#{statMeterReadRateByConcentrator.unReadTimes,jdbcType=INTEGER},
  100. </if>
  101. <if test="statMeterReadRateByConcentrator.readRate!=null">#{statMeterReadRateByConcentrator.readRate,jdbcType=DECIMAL},
  102. </if>
  103. <if test="statMeterReadRateByConcentrator.dateCreate!=null">#{statMeterReadRateByConcentrator.dateCreate,jdbcType=TIMESTAMP},
  104. </if>
  105. <if test="statMeterReadRateByConcentrator.dateUpdate!=null">#{statMeterReadRateByConcentrator.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_concentrator (
  112. stat_day,
  113. site_id,
  114. channel_id,
  115. customer_id,
  116. concentrator_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="statMeterReadRateByConcentrators" item="statMeterReadRateByConcentrator" index="index" separator=",">
  126. (
  127. #{statMeterReadRateByConcentrator.statDay,jdbcType=INTEGER},
  128. #{statMeterReadRateByConcentrator.siteId,jdbcType=INTEGER},
  129. #{statMeterReadRateByConcentrator.channelId,jdbcType=INTEGER},
  130. #{statMeterReadRateByConcentrator.customerId,jdbcType=INTEGER},
  131. #{statMeterReadRateByConcentrator.concentratorId,jdbcType=INTEGER},
  132. #{statMeterReadRateByConcentrator.deviceCount,jdbcType=INTEGER},
  133. #{statMeterReadRateByConcentrator.readTimes,jdbcType=INTEGER},
  134. #{statMeterReadRateByConcentrator.realReadTimes,jdbcType=INTEGER},
  135. #{statMeterReadRateByConcentrator.unReadTimes,jdbcType=INTEGER},
  136. #{statMeterReadRateByConcentrator.readRate,jdbcType=DECIMAL},
  137. #{statMeterReadRateByConcentrator.dateCreate,jdbcType=TIMESTAMP},
  138. #{statMeterReadRateByConcentrator.dateUpdate,jdbcType=TIMESTAMP}
  139. )
  140. </foreach>
  141. </insert>
  142. <!--auto generated Code-->
  143. <update id="updateByPrimaryKeySelective">
  144. UPDATE sc_stat_meter_read_rate_by_concentrator
  145. <set>
  146. <if test="statMeterReadRateByConcentrator.siteId != null"> site_id= #{statMeterReadRateByConcentrator.siteId,jdbcType=INTEGER},</if>
  147. <if test="statMeterReadRateByConcentrator.channelId != null"> channel_id= #{statMeterReadRateByConcentrator.channelId,jdbcType=INTEGER},</if>
  148. <if test="statMeterReadRateByConcentrator.customerId != null"> customer_id= #{statMeterReadRateByConcentrator.customerId,jdbcType=INTEGER},</if>
  149. <if test="statMeterReadRateByConcentrator.concentratorId != null"> concentrator_id= #{statMeterReadRateByConcentrator.concentratorId,jdbcType=INTEGER},</if>
  150. <if test="statMeterReadRateByConcentrator.deviceCount != null"> device_count= #{statMeterReadRateByConcentrator.deviceCount,jdbcType=INTEGER},</if>
  151. <if test="statMeterReadRateByConcentrator.readTimes != null"> read_times= #{statMeterReadRateByConcentrator.readTimes,jdbcType=INTEGER},</if>
  152. <if test="statMeterReadRateByConcentrator.realReadTimes != null"> real_read_times= #{statMeterReadRateByConcentrator.realReadTimes,jdbcType=INTEGER},</if>
  153. <if test="statMeterReadRateByConcentrator.unReadTimes != null"> un_read_times= #{statMeterReadRateByConcentrator.unReadTimes,jdbcType=INTEGER},</if>
  154. <if test="statMeterReadRateByConcentrator.readRate != null"> read_rate= #{statMeterReadRateByConcentrator.readRate,jdbcType=DECIMAL},</if>
  155. <if test="statMeterReadRateByConcentrator.dateCreate != null"> date_create= #{statMeterReadRateByConcentrator.dateCreate,jdbcType=TIMESTAMP},</if>
  156. <if test="statMeterReadRateByConcentrator.dateUpdate != null"> date_update= #{statMeterReadRateByConcentrator.dateUpdate,jdbcType=TIMESTAMP}</if>
  157. </set>
  158. WHERE stat_day = #{statMeterReadRateByConcentrator.statDay,jdbcType=INTEGER}
  159. </update>
  160. <!--查询抄表率明细-->
  161. <select id="getList" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  162. SELECT
  163. d.customer_name,
  164. a.*,
  165. c.serial_number
  166. FROM
  167. sc_stat_meter_read_rate_by_concentrator a
  168. LEFT JOIN sc_customer d ON d.id = a.customer_id
  169. LEFT JOIN sc_concentrator c ON c.id = a.concentrator_id
  170. WHERE 1=1
  171. <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
  172. AND DATE(a.stat_day) BETWEEN CONCAT(#{beginTime},' 00:00:00') AND CONCAT(#{endTime}, '23:59:59')
  173. </if>
  174. <if test="beginRate !=null">
  175. AND a.read_rate >= #{beginRate}
  176. </if>
  177. <if test="endRate !=null">
  178. AND #{endRate} >= a.read_rate
  179. </if>
  180. <if test="customerId !=null">
  181. AND a.customer_id = #{customerId}
  182. </if>
  183. <if test="serialNumber !=null and serialNumber !=''">
  184. AND c.serial_number LIKE CONCAT('%',#{serialNumber},'%')
  185. </if>
  186. </select>
  187. <!--查询客户最近7天抄表率-->
  188. <select id="getLast7DayReadRate" resultType="String">
  189. SELECT SUM(read_rate)/COUNT(1)
  190. FROM sc_stat_meter_read_rate_by_concentrator
  191. WHERE customer_id = #{customerId}
  192. AND DATE(stat_day) BETWEEN CONCAT(#{beginTime},' 00:00:00') AND CONCAT(#{endTime}, '23:59:59')
  193. </select>
  194. <!-- 查询抄表率,含近7天统计 -->
  195. <select id="getListWith7Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  196. SELECT
  197. rc.stat_day as stat_day,
  198. cust.customer_name as customer_name,
  199. con.serial_number as serial_number,
  200. rc.device_count as device_count,
  201. rc.read_times as read_times,
  202. rc.real_read_times as real_read_times,
  203. rc.un_read_times as un_read_times,
  204. rc.read_rate as read_rate,
  205. rcd.read_rate as last_seven_day_read_rate
  206. FROM
  207. sc_stat_meter_read_rate_by_concentrator rc
  208. LEFT JOIN sc_stat_meter_read_rate_by_concentrator_7day rcd ON (
  209. rc.site_id = rcd.site_id
  210. AND rc.channel_id = rcd.channel_id
  211. AND rc.customer_id = rcd.customer_id
  212. AND rc.concentrator_id = rcd.concentrator_id
  213. and rc.meter_type_id = rcd.meter_type_id
  214. AND rc.stat_day = rcd.stat_day
  215. )
  216. LEFT JOIN sc_customer cust ON ( rc.customer_id = cust.id )
  217. LEFT JOIN sc_concentrator con ON ( rc.concentrator_id = con.id )
  218. where 1 = 1
  219. <!-- 表类型 -->
  220. <if test="param.deviceTypeId != null ">
  221. and rc.meter_type_id = #{param.deviceTypeId}
  222. </if>
  223. <!-- 数据权限 -->
  224. <if test="param.siteId != null and param.siteId != 0 "> and rc.site_id = #{param.siteId} </if>
  225. <!--
  226. <if test="param.isAdmin != null and param.isAdmin == 1">
  227. and rc.site_id = 0
  228. </if>
  229. <if test="param.sites != null and param.sites.size() != 0">
  230. and rc.site_id in
  231. <foreach collection="param.sites" item="site" open="(" separator="," close=")">
  232. #{site.id}
  233. </foreach>
  234. </if>
  235. -->
  236. <if test='param.programItems != null and param.programItems.size() != 0' >
  237. and rc.concentrator_id IN (
  238. SELECT DISTINCT
  239. rd.concentrator_id
  240. FROM
  241. sc_water_related_device rd
  242. WHERE
  243. rd.device_id IN (
  244. SELECT
  245. ud.device_id
  246. FROM
  247. (
  248. SELECT
  249. DISTINCT df.device_id
  250. FROM sc_device_dim_info df
  251. WHERE 1 = 1
  252. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  253. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  254. </foreach> ) ud
  255. )
  256. )
  257. </if>
  258. <if test = "param.startDate != null and param.startDate != 0"> and rc.stat_day >= #{param.startDate}</if>
  259. <if test = "param.endDate != null and param.endDate != 0"> and rc.stat_day <![CDATA[ <= ]]> #{param.endDate}</if>
  260. <if test = "param.beginRate != null "> and rc.read_rate >= #{param.beginRate}</if>
  261. <if test = "param.endRate != null "> and rc.read_rate <![CDATA[ <= ]]> #{param.endRate}</if>
  262. <if test = "param.custormerId != null"> and rc.customer_id = #{param.custormerId}</if>
  263. <if test = "param.concentratorCode != null and param.concentratorCode != '' "> and con.serial_number like #{param.concentratorCode}</if>
  264. ORDER BY read_rate DESC
  265. </select>
  266. <sql id="base_query">
  267. SELECT
  268. cust.customer_name as customer_name,
  269. con.serial_number as serial_number,
  270. tmp.device_count as device_count,
  271. tmp.read_times as read_times,
  272. tmp.real_read_times as real_read_times,
  273. tmp.un_read_times as un_read_times,
  274. tmp.read_rate as read_rate
  275. FROM
  276. (
  277. SELECT
  278. customer_id,
  279. concentrator_id,
  280. sum( device_count) AS device_count,
  281. sum( read_times ) AS read_times,
  282. sum( real_read_times ) AS real_read_times,
  283. sum( un_read_times ) AS un_read_times ,
  284. FORMAT( sum( real_read_times ) / sum( read_times ) * 100, 2 ) AS read_rate
  285. FROM
  286. sc_stat_meter_read_rate_by_concentrator
  287. WHERE 1 = 1
  288. <!-- 表类型 -->
  289. <if test="param.deviceTypeId != null ">
  290. and meter_type_id = #{param.deviceTypeId}
  291. </if>
  292. <!-- 数据权限 -->
  293. <if test="param.siteId != null and param.siteId != 0 "> and site_id = #{param.siteId} </if>
  294. <!--
  295. <if test="param.isAdmin != null and param.isAdmin == 1">
  296. and site_id = 0
  297. </if>
  298. <if test="param.sites != null and param.sites.size() != 0">
  299. and site_id in
  300. <foreach collection="param.sites" item="site" open="(" separator="," close=")">
  301. #{site.id}
  302. </foreach>
  303. </if>
  304. -->
  305. <if test='param.programItems != null and param.programItems.size() != 0' >
  306. and concentrator_id IN (
  307. SELECT DISTINCT
  308. rd.concentrator_id
  309. FROM
  310. sc_water_related_device rd
  311. WHERE
  312. rd.device_id IN (
  313. SELECT
  314. ud.device_id
  315. FROM
  316. (
  317. SELECT
  318. DISTINCT df.device_id
  319. FROM sc_device_dim_info df
  320. WHERE 1 = 1
  321. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  322. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  323. </foreach> ) ud
  324. )
  325. )
  326. </if>
  327. <if test = "param.startDate != null and param.startDate != 0"> and stat_day >= #{param.startDate}</if>
  328. <if test = "param.endDate != null and param.endDate != 0"> and stat_day <![CDATA[ <= ]]> #{param.endDate}</if>
  329. GROUP BY
  330. customer_id,
  331. concentrator_id
  332. ) tmp
  333. LEFT JOIN sc_customer cust ON ( tmp.customer_id = cust.id )
  334. LEFT JOIN sc_concentrator con ON ( tmp.concentrator_id = con.id )
  335. </sql>
  336. <sql id="where_clause">
  337. where 1 = 1
  338. <if test = "param.beginRate != null "> and tmp.read_rate >= #{param.beginRate}</if>
  339. <if test = "param.endRate != null "> and tmp.read_rate <![CDATA[ <= ]]> #{param.endRate}</if>
  340. <if test = "param.custormerId != null"> and tmp.customer_id = #{param.custormerId}</if>
  341. <if test = "param.concentratorId != null">and tmp.concentrator_id = #{param.concentratorId}</if>
  342. <if test = "param.deviceTypeId != null" >and tmp.device_type_id = #{param.deviceTypeId}</if>
  343. <if test = "param.concentratorCode != null and param.concentratorCode != '' "> and con.serial_number like #{param.concentratorCode}</if>
  344. </sql>
  345. <!-- 查询抄表率,不含近7天统计 -->
  346. <select id="getListWithOut7Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  347. <include refid="base_query" />
  348. <include refid="where_clause"/>
  349. ORDER BY read_rate DESC
  350. </select>
  351. <select id="summaryList" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  352. select
  353. ifnull(SUM(tmp.device_count),0) as device_count,
  354. ifnull(SUM(tmp.read_times),0) as read_times,
  355. ifnull(SUM(tmp.real_read_times),0) as real_read_times,
  356. ifnull(SUM(tmp.un_read_times),0) as un_read_times,
  357. ifnull(FORMAT(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
  358. from (
  359. <include refid="base_query" />
  360. <include refid="where_clause"/>
  361. ) tmp
  362. ORDER BY read_rate DESC
  363. </select>
  364. <sql id="base_query_getListByDay">
  365. SELECT
  366. cust.customer_name as customer_name,
  367. con.serial_number as serial_number,
  368. concat_ws('/',m.name,dt.equipment_type,dt.model) as device_type_name,
  369. tmp.device_count as device_count,
  370. tmp.read_times as read_times,
  371. tmp.real_read_times as real_read_times,
  372. tmp.un_read_times as un_read_times,
  373. tmp.read_rate as read_rate
  374. FROM
  375. (
  376. SELECT
  377. customer_id,
  378. concentrator_id,
  379. meter_type_id as device_type_id,
  380. sum( device_count) AS device_count,
  381. sum( read_times ) AS read_times,
  382. sum( real_read_times ) AS real_read_times,
  383. sum( un_read_times ) AS un_read_times ,
  384. FORMAT( sum( real_read_times ) / sum( read_times ) * 100, 2 ) AS read_rate
  385. FROM
  386. sc_stat_meter_read_rate_by_concentrator
  387. WHERE 1 = 1
  388. <!-- 表类型 -->
  389. <if test="param.deviceTypeId != null ">
  390. and meter_type_id = #{param.deviceTypeId}
  391. </if>
  392. <!-- 数据权限 -->
  393. <if test="param.siteId != null and param.siteId != 0 "> and site_id = #{param.siteId} </if>
  394. <if test="param.customerIds != null and param.customerIds.size() != 0">
  395. and customer_id in <foreach collection="param.customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  396. </if>
  397. <!--
  398. <if test='param.programItems != null and param.programItems.size() != 0' >
  399. and concentrator_id IN (
  400. SELECT DISTINCT
  401. rd.concentrator_id
  402. FROM
  403. sc_water_related_device rd
  404. WHERE
  405. rd.device_id IN (
  406. SELECT
  407. ud.device_id
  408. FROM
  409. (
  410. SELECT
  411. DISTINCT df.device_id
  412. FROM sc_device_dim_info df
  413. WHERE 1 = 1
  414. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  415. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  416. </foreach> ) ud
  417. )
  418. )
  419. </if>
  420. -->
  421. <if test = "param.statDay != null and param.statDay != 0"> and stat_day = #{param.statDay}</if>
  422. GROUP BY
  423. customer_id,
  424. concentrator_id,
  425. device_type_id
  426. ) tmp
  427. LEFT JOIN sc_customer cust ON ( tmp.customer_id = cust.id )
  428. LEFT JOIN sc_concentrator con ON ( tmp.concentrator_id = con.id )
  429. left join sc_device_type dt on (tmp.device_type_id = dt.id)
  430. left join sc_device_manufacturer m on (dt.manufacturer_id = m.id)
  431. </sql>
  432. <select id="getListByDay" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  433. <include refid="base_query_getListByDay" />
  434. <include refid="where_clause" />
  435. <if test="param.sortColumn != null and param.sortColumn != ''">
  436. <if test="param.sortOrder != null and param.sortOrder != ''">
  437. order by ${param.sortColumn} ${param.sortOrder}
  438. </if>
  439. </if>
  440. </select>
  441. <select id="summaryListByDay" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  442. select
  443. ifnull(SUM(tmp.device_count),0) as device_count,
  444. ifnull(SUM(tmp.read_times),0) as read_times,
  445. ifnull(SUM(tmp.real_read_times),0) as real_read_times,
  446. ifnull(SUM(tmp.un_read_times),0) as un_read_times,
  447. ifnull(FORMAT(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
  448. from (
  449. <include refid="base_query_getListByDay" />
  450. <include refid="where_clause"/>
  451. ) tmp
  452. ORDER BY read_rate DESC
  453. </select>
  454. <sql id="base_query_getListBy7Day">
  455. SELECT
  456. cust.customer_name as customer_name,
  457. con.serial_number as serial_number,
  458. concat_ws('/',m.name,dt.equipment_type,dt.model) as device_type_name,
  459. tmp.device_count as device_count,
  460. tmp.read_times as read_times,
  461. tmp.real_read_times as real_read_times,
  462. tmp.un_read_times as un_read_times,
  463. tmp.read_rate as read_rate
  464. FROM
  465. (
  466. SELECT
  467. customer_id,
  468. concentrator_id,
  469. meter_type_id as device_type_id,
  470. sum( device_count) AS device_count,
  471. sum( read_times ) AS read_times,
  472. sum( real_read_times ) AS real_read_times,
  473. sum( un_read_times ) AS un_read_times ,
  474. FORMAT( sum( real_read_times ) / sum( read_times ) * 100, 2 ) AS read_rate
  475. FROM
  476. sc_stat_meter_read_rate_by_concentrator_7day
  477. WHERE 1 = 1
  478. <!-- 表类型 -->
  479. <if test="param.deviceTypeId != null ">
  480. and meter_type_id = #{param.deviceTypeId}
  481. </if>
  482. <!-- 数据权限 -->
  483. <if test="param.siteId != null and param.siteId != 0 "> and site_id = #{param.siteId} </if>
  484. <if test="param.customerIds != null and param.customerIds.size() != 0">
  485. and customer_id in <foreach collection="param.customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  486. </if>
  487. <!--
  488. <if test='param.programItems != null and param.programItems.size() != 0' >
  489. and concentrator_id IN (
  490. SELECT DISTINCT
  491. rd.concentrator_id
  492. FROM
  493. sc_water_related_device rd
  494. WHERE
  495. rd.device_id IN (
  496. SELECT
  497. ud.device_id
  498. FROM
  499. (
  500. SELECT
  501. DISTINCT df.device_id
  502. FROM sc_device_dim_info df
  503. WHERE 1 = 1
  504. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  505. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  506. </foreach> ) ud
  507. )
  508. )
  509. </if>
  510. -->
  511. <if test = "param.statDay != null and param.statDay != 0"> and stat_day = #{param.statDay}</if>
  512. GROUP BY
  513. customer_id,
  514. concentrator_id,
  515. device_type_id
  516. ) tmp
  517. LEFT JOIN sc_customer cust ON ( tmp.customer_id = cust.id )
  518. LEFT JOIN sc_concentrator con ON ( tmp.concentrator_id = con.id )
  519. left join sc_device_type dt on (tmp.device_type_id = dt.id)
  520. left join sc_device_manufacturer m on (dt.manufacturer_id = m.id)
  521. </sql>
  522. <select id="getListBy7Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  523. <include refid="base_query_getListBy7Day" />
  524. <include refid="where_clause" />
  525. <if test="param.sortColumn != null and param.sortColumn != ''">
  526. <if test="param.sortOrder != null and param.sortOrder != ''">
  527. order by ${param.sortColumn} ${param.sortOrder}
  528. </if>
  529. </if>
  530. </select>
  531. <select id="summaryListBy7Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  532. select
  533. ifnull(SUM(tmp.device_count),0) as device_count,
  534. ifnull(SUM(tmp.read_times),0) as read_times,
  535. ifnull(SUM(tmp.real_read_times),0) as real_read_times,
  536. ifnull(SUM(tmp.un_read_times),0) as un_read_times,
  537. ifnull(FORMAT(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
  538. from (
  539. <include refid="base_query_getListBy7Day" />
  540. <include refid="where_clause"/>
  541. ) tmp
  542. ORDER BY read_rate DESC
  543. </select>
  544. <sql id="base_query_getListBy15Day">
  545. SELECT
  546. cust.customer_name as customer_name,
  547. con.serial_number as serial_number,
  548. concat_ws('/',m.name,dt.equipment_type,dt.model) as device_type_name,
  549. tmp.device_count as device_count,
  550. tmp.read_times as read_times,
  551. tmp.real_read_times as real_read_times,
  552. tmp.un_read_times as un_read_times,
  553. tmp.read_rate as read_rate
  554. FROM
  555. (
  556. SELECT
  557. customer_id,
  558. concentrator_id,
  559. meter_type_id as device_type_id,
  560. sum( device_count) AS device_count,
  561. sum( read_times ) AS read_times,
  562. sum( real_read_times ) AS real_read_times,
  563. sum( un_read_times ) AS un_read_times ,
  564. FORMAT( sum( real_read_times ) / sum( read_times ) * 100, 2 ) AS read_rate
  565. FROM
  566. sc_stat_meter_read_rate_by_concentrator_15day
  567. WHERE 1 = 1
  568. <!-- 表类型 -->
  569. <if test="param.deviceTypeId != null ">
  570. and meter_type_id = #{param.deviceTypeId}
  571. </if>
  572. <!-- 数据权限 -->
  573. <if test="param.siteId != null and param.siteId != 0 "> and site_id = #{param.siteId} </if>
  574. <if test="param.customerIds != null and param.customerIds.size() != 0">
  575. and customer_id in <foreach collection="param.customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  576. </if>
  577. <!--
  578. <if test='param.programItems != null and param.programItems.size() != 0' >
  579. and concentrator_id IN (
  580. SELECT DISTINCT
  581. rd.concentrator_id
  582. FROM
  583. sc_water_related_device rd
  584. WHERE
  585. rd.device_id IN (
  586. SELECT
  587. ud.device_id
  588. FROM
  589. (
  590. SELECT
  591. DISTINCT df.device_id
  592. FROM sc_device_dim_info df
  593. WHERE 1 = 1
  594. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  595. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  596. </foreach> ) ud
  597. )
  598. )
  599. </if>
  600. -->
  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. device_type_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_device_type dt on (tmp.device_type_id = dt.id)
  610. left join sc_device_manufacturer m on (dt.manufacturer_id = m.id)
  611. </sql>
  612. <select id="getListBy15Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  613. <include refid="base_query_getListBy15Day" />
  614. <include refid="where_clause" />
  615. <if test="param.sortColumn != null and param.sortColumn != ''">
  616. <if test="param.sortOrder != null and param.sortOrder != ''">
  617. order by ${param.sortColumn} ${param.sortOrder}
  618. </if>
  619. </if>
  620. </select>
  621. <select id="summaryListBy15Day" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  622. select
  623. ifnull(SUM(tmp.device_count),0) as device_count,
  624. ifnull(SUM(tmp.read_times),0) as read_times,
  625. ifnull(SUM(tmp.real_read_times),0) as real_read_times,
  626. ifnull(SUM(tmp.un_read_times),0) as un_read_times,
  627. ifnull(FORMAT(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
  628. from (
  629. <include refid="base_query_getListBy7Day" />
  630. <include refid="where_clause"/>
  631. ) tmp
  632. ORDER BY read_rate DESC
  633. </select>
  634. <!-- 今日抄表率 -->
  635. <sql id="base_query_getListByToday">
  636. SELECT
  637. cust.customer_name as customer_name,
  638. con.serial_number as serial_number,
  639. concat_ws('/',m.name,dt.equipment_type,dt.model) as device_type_name,
  640. tmp.device_count as device_count,
  641. tmp.read_times as read_times,
  642. tmp.real_read_times as real_read_times,
  643. tmp.un_read_times as un_read_times,
  644. tmp.read_rate as read_rate
  645. FROM
  646. (
  647. SELECT
  648. customer_id,
  649. concentrator_id,
  650. device_type_id,
  651. count(1) as device_count,
  652. count(1) AS read_times,
  653. SUM(IF(read_status = 2, 1, 0)) as real_read_times,
  654. SUM(IF(read_status = 1, 1, 0)) as un_read_times ,
  655. convert( SUM(IF(read_status = 2, 1, 0)) / count(1) * 100, decimal(5,2) ) AS read_rate
  656. FROM
  657. sc_meter_read_record
  658. WHERE 1 = 1
  659. and device_type_id IN ( SELECT device_type_id FROM sc_w_meter_type WHERE parent_id = 1 )
  660. <!-- 表类型 -->
  661. <if test="param.deviceTypeId != null ">
  662. and device_type_id = #{param.deviceTypeId}
  663. </if>
  664. <!-- 数据权限 -->
  665. <if test="param.siteId != null and param.siteId != 0 "> and site_id = #{param.siteId} </if>
  666. <if test="param.customerIds != null and param.customerIds.size() != 0">
  667. and customer_id in <foreach collection="param.customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  668. </if>
  669. <!--
  670. <if test='param.programItems != null and param.programItems.size() != 0' >
  671. and concentrator_id IN (
  672. SELECT DISTINCT
  673. rd.concentrator_id
  674. FROM
  675. sc_water_related_device rd
  676. WHERE
  677. rd.device_id IN (
  678. SELECT
  679. ud.device_id
  680. FROM
  681. (
  682. SELECT
  683. DISTINCT df.device_id
  684. FROM sc_device_dim_info df
  685. WHERE 1 = 1
  686. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  687. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  688. </foreach> ) ud
  689. )
  690. )
  691. </if>
  692. -->
  693. <if test = "param.statDay != null and param.statDay != 0"> and read_date = #{param.statDay}</if>
  694. GROUP BY
  695. customer_id,
  696. concentrator_id,
  697. device_type_id
  698. ) tmp
  699. LEFT JOIN sc_customer cust ON ( tmp.customer_id = cust.id )
  700. LEFT JOIN sc_concentrator con ON ( tmp.concentrator_id = con.id )
  701. left join sc_device_type dt on (tmp.device_type_id = dt.id)
  702. left join sc_device_manufacturer m on (dt.manufacturer_id = m.id)
  703. </sql>
  704. <select id="getListByToday_COUNT" resultType="Long">
  705. SELECT
  706. count(1)
  707. FROM
  708. (
  709. SELECT
  710. customer_id,
  711. concentrator_id,
  712. device_type_id,
  713. count(1) as device_count,
  714. count(1) AS read_times,
  715. SUM(IF(read_status = 2, 1, 0)) as real_read_times,
  716. SUM(IF(read_status = 1, 1, 0)) as un_read_times ,
  717. convert( SUM(IF(read_status = 2, 1, 0)) / count(1) * 100, decimal(5,2) ) AS read_rate
  718. FROM
  719. sc_meter_read_record
  720. WHERE 1 = 1
  721. and device_type_id IN ( SELECT device_type_id FROM sc_w_meter_type WHERE parent_id = 1 )
  722. <!-- 表类型 -->
  723. <if test="param.deviceTypeId != null ">
  724. and device_type_id = #{param.deviceTypeId}
  725. </if>
  726. <!-- 数据权限 -->
  727. <if test="param.siteId != null and param.siteId != 0 "> and site_id = #{param.siteId} </if>
  728. <if test="param.customerIds != null and param.customerIds.size() != 0">
  729. and customer_id in <foreach collection="param.customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  730. </if>
  731. <!--
  732. <if test='param.programItems != null and param.programItems.size() != 0' >
  733. and concentrator_id IN (
  734. SELECT DISTINCT
  735. rd.concentrator_id
  736. FROM
  737. sc_water_related_device rd
  738. WHERE
  739. rd.device_id IN (
  740. SELECT
  741. ud.device_id
  742. FROM
  743. (
  744. SELECT
  745. DISTINCT df.device_id
  746. FROM sc_device_dim_info df
  747. WHERE 1 = 1
  748. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  749. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  750. </foreach> ) ud
  751. )
  752. )
  753. </if>
  754. -->
  755. <if test = "param.statDay != null and param.statDay != 0"> and read_date = #{param.statDay}</if>
  756. GROUP BY
  757. customer_id,
  758. concentrator_id,
  759. device_type_id
  760. ) tmp
  761. where 1 = 1
  762. <if test = "param.beginRate != null "> and tmp.read_rate >= #{param.beginRate}</if>
  763. <if test = "param.endRate != null "> and tmp.read_rate <![CDATA[ <= ]]> #{param.endRate}</if>
  764. <if test = "param.custormerId != null"> and tmp.customer_id = #{param.custormerId}</if>
  765. <if test = "param.concentratorId != null">and tmp.concentrator_id = #{param.concentratorId}</if>
  766. <if test = "param.deviceTypeId != null" >and tmp.device_type_id = #{param.deviceTypeId}</if>
  767. </select>
  768. <select id="getListByToday" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  769. <include refid="base_query_getListByToday" />
  770. <include refid="where_clause" />
  771. <if test="param.sortColumn != null and param.sortColumn != ''">
  772. <if test="param.sortOrder != null and param.sortOrder != ''">
  773. order by ${param.sortColumn} ${param.sortOrder}
  774. </if>
  775. </if>
  776. </select>
  777. <select id="summaryListByToday" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  778. select
  779. ifnull(SUM(tmp.device_count),0) as device_count,
  780. ifnull(SUM(tmp.read_times),0) as read_times,
  781. ifnull(SUM(tmp.real_read_times),0) as real_read_times,
  782. ifnull(SUM(tmp.un_read_times),0) as un_read_times,
  783. ifnull(FORMAT(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
  784. from (
  785. <include refid="base_query_getListByToday" />
  786. <include refid="where_clause"/>
  787. ) tmp
  788. ORDER BY read_rate DESC
  789. </select>
  790. <!-- 按月查询抄表率 -->
  791. <sql id="base_query_getListByMonth">
  792. SELECT
  793. cust.customer_name as customer_name,
  794. con.serial_number as serial_number,
  795. concat_ws('/',m.name,dt.equipment_type,dt.model) as device_type_name,
  796. tmp.device_count as device_count,
  797. tmp.read_times as read_times,
  798. tmp.real_read_times as real_read_times,
  799. tmp.un_read_times as un_read_times,
  800. tmp.read_rate as read_rate
  801. FROM
  802. (
  803. SELECT
  804. customer_id,
  805. concentrator_id,
  806. meter_type_id as device_type_id,
  807. sum( device_count) AS device_count,
  808. sum( read_times ) AS read_times,
  809. sum( real_read_times ) AS real_read_times,
  810. sum( un_read_times ) AS un_read_times ,
  811. FORMAT( sum( real_read_times ) / sum( read_times ) * 100, 2 ) AS read_rate
  812. FROM
  813. sc_stat_meter_read_rate_by_concentrator_month
  814. WHERE 1 = 1
  815. <!-- 表类型 -->
  816. <if test="param.deviceTypeId != null ">
  817. and meter_type_id = #{param.deviceTypeId}
  818. </if>
  819. <!-- 数据权限 -->
  820. <if test="param.siteId != null and param.siteId != 0 "> and site_id = #{param.siteId} </if>
  821. <if test="param.customerIds != null and param.customerIds.size() != 0">
  822. and customer_id in <foreach collection="param.customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  823. </if>
  824. <!--
  825. <if test='param.programItems != null and param.programItems.size() != 0' >
  826. and concentrator_id IN (
  827. SELECT DISTINCT
  828. rd.concentrator_id
  829. FROM
  830. sc_water_related_device rd
  831. WHERE
  832. rd.device_id IN (
  833. SELECT
  834. ud.device_id
  835. FROM
  836. (
  837. SELECT
  838. DISTINCT df.device_id
  839. FROM sc_device_dim_info df
  840. WHERE 1 = 1
  841. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  842. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  843. </foreach> ) ud
  844. )
  845. )
  846. </if>
  847. -->
  848. <if test = "param.statDay != null and param.statDay != 0"> and stat_month = #{param.statDay}</if>
  849. GROUP BY
  850. customer_id,
  851. concentrator_id,
  852. device_type_id
  853. ) tmp
  854. LEFT JOIN sc_customer cust ON ( tmp.customer_id = cust.id )
  855. LEFT JOIN sc_concentrator con ON ( tmp.concentrator_id = con.id )
  856. left join sc_device_type dt on (tmp.device_type_id = dt.id)
  857. left join sc_device_manufacturer m on (dt.manufacturer_id = m.id)
  858. </sql>
  859. <select id="getListByMonth" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  860. <include refid="base_query_getListByMonth" />
  861. <include refid="where_clause" />
  862. <if test="param.sortColumn != null and param.sortColumn != ''">
  863. <if test="param.sortOrder != null and param.sortOrder != ''">
  864. order by ${param.sortColumn} ${param.sortOrder}
  865. </if>
  866. </if>
  867. </select>
  868. <select id="summaryListByMonth" resultType="com.bz.smart_city.dto.StatMeterReadRateDto">
  869. select
  870. ifnull(SUM(tmp.device_count),0) as device_count,
  871. ifnull(SUM(tmp.read_times),0) as read_times,
  872. ifnull(SUM(tmp.real_read_times),0) as real_read_times,
  873. ifnull(SUM(tmp.un_read_times),0) as un_read_times,
  874. ifnull(FORMAT(SUM(tmp.real_read_times)/SUM(tmp.read_times)*100,2),0) as read_rate
  875. from (
  876. <include refid="base_query_getListByMonth" />
  877. <include refid="where_clause"/>
  878. ) tmp
  879. ORDER BY read_rate DESC
  880. </select>
  881. </mapper>