MeterReadRecordMapper.xml 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804
  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.MeterReadRecordMapper">
  4. <!--auto generated Code-->
  5. <resultMap id="BaseResultMap" type="com.bz.smart_city.entity.MeterReadRecord">
  6. <result column="id" property="id" jdbcType="BIGINT"/>
  7. <result column="read_date" property="readDate" jdbcType="INTEGER"/>
  8. <result column="site_id" property="siteId" jdbcType="INTEGER"/>
  9. <result column="sys_id" property="sysId" jdbcType="INTEGER"/>
  10. <result column="province" property="province" jdbcType="INTEGER"/>
  11. <result column="city" property="city" jdbcType="INTEGER"/>
  12. <result column="region" property="region" jdbcType="INTEGER"/>
  13. <result column="community" property="communityId" jdbcType="VARCHAR"/>
  14. <result column="building_id" property="buildingId" jdbcType="INTEGER"/>
  15. <result column="location" property="location" jdbcType="VARCHAR"/>
  16. <result column="device_type_id" property="deviceTypeId" jdbcType="INTEGER"/>
  17. <result column="device_id" property="deviceId" jdbcType="BIGINT"/>
  18. <result column="device_no" property="deviceNo" jdbcType="VARCHAR"/>
  19. <result column="meter_no" property="meterNo" jdbcType="VARCHAR"/>
  20. <result column="meter_file_no" property="meterFileNo" jdbcType="VARCHAR"/>
  21. <result column="read_time" property="readTime" jdbcType="TIMESTAMP"/>
  22. <result column="read_status" property="readStatus" jdbcType="VARCHAR"/>
  23. <result column="read_data" property="readData" jdbcType="VARCHAR"/>
  24. <result column="last_valid" property="lastValid" jdbcType="VARCHAR"/>
  25. <result column="last_cost" property="lastCost" jdbcType="DECIMAL"/>
  26. <result column="status" property="status" jdbcType="INTEGER"/>
  27. <result column="date_create" property="dateCreate" jdbcType="TIMESTAMP"/>
  28. <result column="date_update" property="dateUpdate" jdbcType="TIMESTAMP"/>
  29. <result column="create_by" property="createBy" jdbcType="VARCHAR"/>
  30. <result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
  31. </resultMap>
  32. <!--auto generated Code-->
  33. <sql id="Base_Column_List">
  34. id,
  35. read_date,
  36. site_id,
  37. sys_id,
  38. province,
  39. city,
  40. region,
  41. community,
  42. building_id,
  43. location,
  44. device_type_id,
  45. device_id,
  46. device_no,
  47. meter_no,
  48. meter_file_no,
  49. read_time,
  50. read_status,
  51. read_data,
  52. last_valid,
  53. last_cost,
  54. status,
  55. date_create,
  56. date_update,
  57. create_by,
  58. update_by
  59. </sql>
  60. <!--auto generated Code-->
  61. <insert id="insert" useGeneratedKeys="true" keyProperty="meterReadRecord.id">
  62. INSERT INTO sc_meter_read_record (
  63. id,
  64. read_date,
  65. site_id,
  66. sys_id,
  67. province,
  68. city,
  69. region,
  70. community,
  71. building_id,
  72. location,
  73. device_type_id,
  74. device_id,
  75. device_no,
  76. meter_no,
  77. meter_file_no,
  78. read_time,
  79. read_status,
  80. read_data,
  81. last_valid,
  82. last_cost,
  83. status,
  84. date_create,
  85. date_update,
  86. create_by,
  87. update_by
  88. ) VALUES (
  89. #{meterReadRecord.id,jdbcType=BIGINT},
  90. #{meterReadRecord.readDate,jdbcType=INTEGER},
  91. #{meterReadRecord.siteId,jdbcType=INTEGER},
  92. #{meterReadRecord.sysId,jdbcType=INTEGER},
  93. #{meterReadRecord.province,jdbcType=INTEGER},
  94. #{meterReadRecord.city,jdbcType=INTEGER},
  95. #{meterReadRecord.region,jdbcType=INTEGER},
  96. #{meterReadRecord.communityId,jdbcType=VARCHAR},
  97. #{meterReadRecord.buildingId,jdbcType=INTEGER},
  98. #{meterReadRecord.location,jdbcType=VARCHAR},
  99. #{meterReadRecord.deviceTypeId,jdbcType=INTEGER},
  100. #{meterReadRecord.deviceId,jdbcType=BIGINT},
  101. #{meterReadRecord.deviceNo,jdbcType=VARCHAR},
  102. #{meterReadRecord.meterNo,jdbcType=VARCHAR},
  103. #{meterReadRecord.meterFileNo,jdbcType=VARCHAR},
  104. #{meterReadRecord.readTime,jdbcType=TIMESTAMP},
  105. #{meterReadRecord.readStatus,jdbcType=VARCHAR},
  106. #{meterReadRecord.readData,jdbcType=VARCHAR},
  107. #{meterReadRecord.lastValid,jdbcType=VARCHAR},
  108. #{meterReadRecord.lastCost,jdbcType=DECIMAL},
  109. #{meterReadRecord.status,jdbcType=INTEGER},
  110. #{meterReadRecord.dateCreate,jdbcType=TIMESTAMP},
  111. #{meterReadRecord.dateUpdate,jdbcType=TIMESTAMP},
  112. #{meterReadRecord.createBy,jdbcType=VARCHAR},
  113. #{meterReadRecord.updateBy,jdbcType=VARCHAR}
  114. )
  115. </insert>
  116. <!--auto generated Code-->
  117. <insert id="insertSelective" useGeneratedKeys="true" keyProperty="meterReadRecord.id">
  118. INSERT INTO sc_meter_read_record
  119. <trim prefix="(" suffix=")" suffixOverrides=",">
  120. <if test="meterReadRecord.id!=null"> id,</if>
  121. <if test="meterReadRecord.readDate!=null"> read_date,</if>
  122. <if test="meterReadRecord.siteId!=null"> site_id,</if>
  123. <if test="meterReadRecord.sysId!=null"> sys_id,</if>
  124. <if test="meterReadRecord.province!=null"> province,</if>
  125. <if test="meterReadRecord.city!=null"> city,</if>
  126. <if test="meterReadRecord.region!=null"> region,</if>
  127. <if test="meterReadRecord.communityId!=null"> community,</if>
  128. <if test="meterReadRecord.buildingId!=null"> building_id,</if>
  129. <if test="meterReadRecord.location!=null"> location,</if>
  130. <if test="meterReadRecord.deviceTypeId!=null"> device_type_id,</if>
  131. <if test="meterReadRecord.deviceId!=null"> device_id,</if>
  132. <if test="meterReadRecord.deviceNo!=null"> device_no,</if>
  133. <if test="meterReadRecord.meterNo!=null"> meter_no,</if>
  134. <if test="meterReadRecord.meterFileNo!=null"> meter_file_no,</if>
  135. <if test="meterReadRecord.readTime!=null"> read_time,</if>
  136. <if test="meterReadRecord.readStatus!=null"> read_status,</if>
  137. <if test="meterReadRecord.readData!=null"> read_data,</if>
  138. <if test="meterReadRecord.lastValid!=null"> last_valid,</if>
  139. <if test="meterReadRecord.lastCost!=null"> last_cost,</if>
  140. <if test="meterReadRecord.status!=null"> status,</if>
  141. <if test="meterReadRecord.dateCreate!=null"> date_create,</if>
  142. <if test="meterReadRecord.dateUpdate!=null"> date_update,</if>
  143. <if test="meterReadRecord.createBy!=null"> create_by,</if>
  144. <if test="meterReadRecord.updateBy!=null"> update_by,</if>
  145. </trim>
  146. VALUES
  147. <trim prefix="(" suffix=")" suffixOverrides=",">
  148. <if test="meterReadRecord.id!=null">#{meterReadRecord.id,jdbcType=BIGINT},
  149. </if>
  150. <if test="meterReadRecord.readDate!=null">#{meterReadRecord.readDate,jdbcType=INTEGER},
  151. </if>
  152. <if test="meterReadRecord.siteId!=null">#{meterReadRecord.siteId,jdbcType=INTEGER},
  153. </if>
  154. <if test="meterReadRecord.sysId!=null">#{meterReadRecord.sysId,jdbcType=INTEGER},
  155. </if>
  156. <if test="meterReadRecord.province!=null">#{meterReadRecord.province,jdbcType=INTEGER},
  157. </if>
  158. <if test="meterReadRecord.city!=null">#{meterReadRecord.city,jdbcType=INTEGER},
  159. </if>
  160. <if test="meterReadRecord.region!=null">#{meterReadRecord.region,jdbcType=INTEGER},
  161. </if>
  162. <if test="meterReadRecord.communityId!=null">#{meterReadRecord.communityId,jdbcType=VARCHAR},
  163. </if>
  164. <if test="meterReadRecord.buildingId!=null">#{meterReadRecord.buildingId,jdbcType=INTEGER},
  165. </if>
  166. <if test="meterReadRecord.location!=null">#{meterReadRecord.location,jdbcType=VARCHAR},
  167. </if>
  168. <if test="meterReadRecord.deviceTypeId!=null">#{meterReadRecord.deviceTypeId,jdbcType=INTEGER},
  169. </if>
  170. <if test="meterReadRecord.deviceId!=null">#{meterReadRecord.deviceId,jdbcType=BIGINT},
  171. </if>
  172. <if test="meterReadRecord.deviceNo!=null">#{meterReadRecord.deviceNo,jdbcType=VARCHAR},
  173. </if>
  174. <if test="meterReadRecord.meterNo!=null">#{meterReadRecord.meterNo,jdbcType=VARCHAR},
  175. </if>
  176. <if test="meterReadRecord.meterFileNo!=null">#{meterReadRecord.meterFileNo,jdbcType=VARCHAR},
  177. </if>
  178. <if test="meterReadRecord.readTime!=null">#{meterReadRecord.readTime,jdbcType=TIMESTAMP},
  179. </if>
  180. <if test="meterReadRecord.readStatus!=null">#{meterReadRecord.readStatus,jdbcType=VARCHAR},
  181. </if>
  182. <if test="meterReadRecord.readData!=null">#{meterReadRecord.readData,jdbcType=VARCHAR},
  183. </if>
  184. <if test="meterReadRecord.lastValid!=null">#{meterReadRecord.lastValid,jdbcType=VARCHAR},
  185. </if>
  186. <if test="meterReadRecord.lastCost!=null">#{meterReadRecord.lastCost,jdbcType=DECIMAL},
  187. </if>
  188. <if test="meterReadRecord.status!=null">#{meterReadRecord.status,jdbcType=INTEGER},
  189. </if>
  190. <if test="meterReadRecord.dateCreate!=null">#{meterReadRecord.dateCreate,jdbcType=TIMESTAMP},
  191. </if>
  192. <if test="meterReadRecord.dateUpdate!=null">#{meterReadRecord.dateUpdate,jdbcType=TIMESTAMP},
  193. </if>
  194. <if test="meterReadRecord.createBy!=null">#{meterReadRecord.createBy,jdbcType=VARCHAR},
  195. </if>
  196. <if test="meterReadRecord.updateBy!=null">#{meterReadRecord.updateBy,jdbcType=VARCHAR},
  197. </if>
  198. </trim>
  199. </insert>
  200. <!--auto generated Code-->
  201. <insert id="insertList">
  202. replace INTO sc_meter_read_record (
  203. id,
  204. read_date,
  205. site_id,
  206. sys_id,
  207. province,
  208. city,
  209. region,
  210. community,
  211. customer_id,
  212. building_id,
  213. location,
  214. device_type_id,
  215. device_id,
  216. device_no,
  217. meter_no,
  218. meter_file_no,
  219. read_time,
  220. read_status,
  221. read_data,
  222. last_valid,
  223. last_cost,
  224. status,
  225. date_create,
  226. date_update,
  227. create_by,
  228. update_by
  229. )VALUES
  230. <foreach collection="meterReadRecords" item="meterReadRecord" index="index" separator=",">
  231. (
  232. #{meterReadRecord.id,jdbcType=BIGINT},
  233. #{meterReadRecord.readDate,jdbcType=INTEGER},
  234. #{meterReadRecord.siteId,jdbcType=INTEGER},
  235. #{meterReadRecord.sysId,jdbcType=INTEGER},
  236. #{meterReadRecord.province,jdbcType=INTEGER},
  237. #{meterReadRecord.city,jdbcType=INTEGER},
  238. #{meterReadRecord.region,jdbcType=INTEGER},
  239. #{meterReadRecord.communityId,jdbcType=INTEGER},
  240. #{meterReadRecord.customerId,jdbcType=INTEGER},
  241. #{meterReadRecord.buildingId,jdbcType=INTEGER},
  242. #{meterReadRecord.location,jdbcType=VARCHAR},
  243. #{meterReadRecord.deviceTypeId,jdbcType=INTEGER},
  244. #{meterReadRecord.deviceId,jdbcType=BIGINT},
  245. #{meterReadRecord.deviceNo,jdbcType=VARCHAR},
  246. #{meterReadRecord.meterNo,jdbcType=VARCHAR},
  247. #{meterReadRecord.meterFileNo,jdbcType=VARCHAR},
  248. #{meterReadRecord.readTime,jdbcType=TIMESTAMP},
  249. #{meterReadRecord.readStatus,jdbcType=VARCHAR},
  250. #{meterReadRecord.readData,jdbcType=VARCHAR},
  251. #{meterReadRecord.lastValid, jdbcType=VARCHAR},
  252. #{meterReadRecord.lastCost,jdbcType=DECIMAL},
  253. #{meterReadRecord.status,jdbcType=INTEGER},
  254. #{meterReadRecord.dateCreate,jdbcType=TIMESTAMP},
  255. #{meterReadRecord.dateUpdate,jdbcType=TIMESTAMP},
  256. #{meterReadRecord.createBy,jdbcType=VARCHAR},
  257. #{meterReadRecord.updateBy,jdbcType=VARCHAR}
  258. )
  259. </foreach>
  260. </insert>
  261. <!--auto generated Code-->
  262. <update id="updateByPrimaryKeySelective">
  263. UPDATE sc_meter_read_record
  264. <set>
  265. <if test="meterReadRecord.readDate != null"> read_date= #{meterReadRecord.readDate,jdbcType=INTEGER},</if>
  266. <if test="meterReadRecord.siteId != null"> site_id= #{meterReadRecord.siteId,jdbcType=INTEGER},</if>
  267. <if test="meterReadRecord.sysId != null"> sys_id= #{meterReadRecord.sysId,jdbcType=INTEGER},</if>
  268. <if test="meterReadRecord.province != null"> province= #{meterReadRecord.province,jdbcType=INTEGER},</if>
  269. <if test="meterReadRecord.city != null"> city= #{meterReadRecord.city,jdbcType=INTEGER},</if>
  270. <if test="meterReadRecord.region != null"> region= #{meterReadRecord.region,jdbcType=INTEGER},</if>
  271. <if test="meterReadRecord.communityId != null"> community= #{meterReadRecord.communityId,jdbcType=VARCHAR},</if>
  272. <if test="meterReadRecord.buildingId != null"> building_id= #{meterReadRecord.buildingId,jdbcType=INTEGER},</if>
  273. <if test="meterReadRecord.location != null"> location= #{meterReadRecord.location,jdbcType=VARCHAR},</if>
  274. <if test="meterReadRecord.deviceTypeId != null"> device_type_id= #{meterReadRecord.deviceTypeId,jdbcType=INTEGER},</if>
  275. <if test="meterReadRecord.deviceId != null"> device_id= #{meterReadRecord.deviceId,jdbcType=BIGINT},</if>
  276. <if test="meterReadRecord.deviceNo != null"> device_no= #{meterReadRecord.deviceNo,jdbcType=VARCHAR},</if>
  277. <if test="meterReadRecord.meterNo != null"> meter_no= #{meterReadRecord.meterNo,jdbcType=VARCHAR},</if>
  278. <if test="meterReadRecord.meterFileNo != null"> meter_file_no= #{meterReadRecord.meterFileNo,jdbcType=VARCHAR},</if>
  279. <if test="meterReadRecord.readTime != null"> read_time= #{meterReadRecord.readTime,jdbcType=TIMESTAMP},</if>
  280. <if test="meterReadRecord.readStatus != null"> read_status= #{meterReadRecord.readStatus,jdbcType=VARCHAR},</if>
  281. <if test="meterReadRecord.readData != null"> read_data= #{meterReadRecord.readData,jdbcType=VARCHAR},</if>
  282. <if test="meterReadRecord.lastValid!=null"> last_valid = #{meterReadRecord.lastValid,jdbcType=VARCHAR},</if>
  283. <if test="meterReadRecord.lastCost!=null"> last_cost = #{meterReadRecord.lastCost,jdbcType=DECIMAL},</if>
  284. <if test="meterReadRecord.status != null"> status= #{meterReadRecord.status,jdbcType=INTEGER},</if>
  285. <if test="meterReadRecord.dateCreate != null"> date_create= #{meterReadRecord.dateCreate,jdbcType=TIMESTAMP},</if>
  286. <if test="meterReadRecord.dateUpdate != null"> date_update= #{meterReadRecord.dateUpdate,jdbcType=TIMESTAMP},</if>
  287. <if test="meterReadRecord.createBy != null"> create_by= #{meterReadRecord.createBy,jdbcType=VARCHAR},</if>
  288. <if test="meterReadRecord.updateBy != null"> update_by= #{meterReadRecord.updateBy,jdbcType=VARCHAR}</if>
  289. </set>
  290. WHERE id = #{meterReadRecord.id,jdbcType=BIGINT}
  291. </update>
  292. <select id="queryMeterReadRecord" resultType="com.bz.smart_city.entity.MeterReadRecord">
  293. select
  294. m.id as id,
  295. read_date,
  296. m.site_id as site_id,
  297. m.sys_id as sys_id,
  298. m.province as province,
  299. m.city as city,
  300. m.region as region,
  301. m.community as community,
  302. m.building_id as building_id,
  303. b.name as building_name,
  304. m.location as location,
  305. device_type_id,
  306. device_id,
  307. device_no,
  308. meter_no,
  309. meter_file_no,
  310. read_time,
  311. read_status,
  312. read_data,
  313. m.status as status
  314. from
  315. sc_meter_read_record m
  316. left join sc_building b on ( building_id = b.id)
  317. where 1=1
  318. <if test="param.siteId != null and param.siteId != 0"> and m.site_id = #{param.siteId}</if>
  319. <if test="param.buildingId != null and param.buildingId != 0"> and building_id = #{param.buildingId}</if>
  320. <if test = "param.deviceNo != null and param.deviceNo != ''"> and device_no like #{param.deviceNo}</if>
  321. <if test = 'param.readStatus != null and param.readStatus != "0"'> and read_status = #{param.readStatus,jdbcType=VARCHAR}</if>
  322. <if test = "param.location != null and param.location != ''"> and location like #{param.location}</if>
  323. <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
  324. <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
  325. and m.status = 1
  326. order by read_time desc
  327. </select>
  328. <!--
  329. <select id="statisticReadRecordsByProvince" resultType="com.bz.smart_city.entity.MeterRecordStat">
  330. SELECT
  331. '省' as level,
  332. a.province as item_id,
  333. a.NAME as item_name,
  334. CASE WHEN b.total IS NULL THEN 0 ELSE b.total END AS total
  335. FROM
  336. (
  337. SELECT
  338. DISTINCT
  339. province,
  340. a.NAME
  341. FROM
  342. sc_building
  343. LEFT JOIN sc_area a ON (province = a.id )
  344. WHERE
  345. 1 = 1
  346. and STATUS = 1
  347. <if test = "param.siteId != null and param.siteId != 0"> and site_id = #{param.siteId}</if>
  348. <if test='param.programItems != null and param.programItems.size() != 0' >
  349. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  350. <if test = 'item.dimensionCode == "PROVINCE" '>
  351. province = #{item.dimensionValue}
  352. </if>
  353. <if test = 'item.dimensionCode == "CITY" '>
  354. city = #{item.dimensionValue}
  355. </if>
  356. <if test = 'item.dimensionCode == "REGION" '>
  357. region = #{item.dimensionValue}
  358. </if>
  359. <if test = 'item.dimensionCode == "COMMUNITY" '>
  360. community = #{item.dimensionValue}
  361. </if>
  362. <if test = 'item.dimensionCode == "BUILDING" '>
  363. id = #{item.dimensionValue}
  364. </if>
  365. </foreach>
  366. </if>
  367. ) a
  368. LEFT JOIN (
  369. SELECT
  370. province,
  371. count( 1 ) AS total
  372. FROM
  373. sc_meter_read_record
  374. WHERE
  375. 1 = 1
  376. AND STATUS = 1
  377. <if test="param.channelId != null and param.channelId != 0 "> and sys_id = #{param.channelId}</if>
  378. <if test = "param.siteId !=null and param.siteId != 0"> and site_id = #{param.siteId}</if>
  379. <if test='param.programItems != null and param.programItems.size() != 0' >
  380. and EXISTS (
  381. select 1 from
  382. (select
  383. distinct df.device_id
  384. FROM sc_device_dim_info df
  385. WHERE 1 = 1
  386. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  387. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  388. </foreach> ) ud WHERE ud.device_id = device_id)
  389. </if>
  390. <if test = "param.deviceNo != null and param.deviceNo != ''"> and device_no like #{param.deviceNo}</if>
  391. <if test = 'param.readStatus != null and param.readStatus != "0"'> and read_status = #{param.readStatus,jdbcType=VARCHAR}</if>
  392. <if test = "param.location != null and param.location != ''"> and location like #{param.location}</if>
  393. <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
  394. <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
  395. GROUP BY
  396. province
  397. ) b ON ( a.province = b.province )
  398. order by total desc
  399. </select>
  400. <select id="statisticReadRecordsByCity" resultType="com.bz.smart_city.entity.MeterRecordStat">
  401. SELECT
  402. '市' as level,
  403. a.city as item_id,
  404. a.NAME as item_name,
  405. CASE WHEN b.total IS NULL THEN 0 ELSE b.total END AS total
  406. FROM
  407. (
  408. SELECT
  409. DISTINCT
  410. city,
  411. a.NAME
  412. FROM
  413. sc_building
  414. LEFT JOIN sc_area a ON (city = a.id )
  415. WHERE
  416. 1 = 1
  417. and STATUS = 1
  418. <if test = "param.siteId != null and param.siteId != 0"> and site_id = #{param.siteId}</if>
  419. <if test = "param.province != null and param.province != ''"> and province = #{param.province}</if>
  420. <if test='param.programItems != null and param.programItems.size() != 0' >
  421. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  422. <if test = 'item.dimensionCode == "PROVINCE" '>
  423. province = #{item.dimensionValue}
  424. </if>
  425. <if test = 'item.dimensionCode == "CITY" '>
  426. city = #{item.dimensionValue}
  427. </if>
  428. <if test = 'item.dimensionCode == "REGION" '>
  429. region = #{item.dimensionValue}
  430. </if>
  431. <if test = 'item.dimensionCode == "COMMUNITY" '>
  432. community = #{item.dimensionValue}
  433. </if>
  434. <if test = 'item.dimensionCode == "BUILDING" '>
  435. id = #{item.dimensionValue}
  436. </if>
  437. </foreach>
  438. </if>
  439. ) a
  440. LEFT JOIN (
  441. SELECT
  442. city,
  443. count( 1 ) AS total
  444. FROM
  445. sc_meter_read_record
  446. WHERE
  447. 1 = 1
  448. AND STATUS = 1
  449. <if test="param.channelId != null and param.channelId != 0 "> and sys_id = #{param.channelId}</if>
  450. <if test = "param.siteId !=null and param.siteId != 0"> and site_id = #{param.siteId}</if>
  451. <if test='param.programItems != null and param.programItems.size() != 0' >
  452. and EXISTS (
  453. select 1 from
  454. (select
  455. distinct df.device_id
  456. FROM sc_device_dim_info df
  457. WHERE 1 = 1
  458. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  459. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  460. </foreach> ) ud WHERE ud.device_id = device_id)
  461. </if>
  462. <if test = "param.province != null and param.province != ''"> and province = #{param.province}</if>
  463. <if test = "param.deviceNo != null and param.deviceNo != ''"> and device_no like #{param.deviceNo}</if>
  464. <if test = 'param.readStatus != null and param.readStatus != "0"'> and read_status = #{param.readStatus,jdbcType=VARCHAR}</if>
  465. <if test = "param.location != null and param.location != ''"> and location like #{param.location}</if>
  466. <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
  467. <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
  468. GROUP BY
  469. city
  470. ) b ON ( a.city = b.city )
  471. order by total desc
  472. </select>
  473. -->
  474. <!-- 按照小区进行汇总
  475. <select id="statisticReadRecordsByCommunity" resultType="com.bz.smart_city.entity.MeterRecordStat">
  476. SELECT
  477. '小区' as level,
  478. a.community as item_id,
  479. a.NAME as item_name,
  480. CASE WHEN b.total IS NULL THEN 0 ELSE b.total END AS total
  481. FROM
  482. (
  483. SELECT
  484. DISTINCT
  485. community,
  486. a.NAME
  487. FROM
  488. sc_building b
  489. left join sc_community a on (community = a.id)
  490. WHERE
  491. 1 = 1
  492. and a.STATUS = 1
  493. <if test = "param.siteId != null and param.siteId != 0"> and b.site_id = #{param.siteId}</if>
  494. <if test = "param.city != null and param.city != ''"> and b.city = #{param.city}</if>
  495. <if test='param.programItems != null and param.programItems.size() != 0' >
  496. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  497. <if test = 'item.dimensionCode == "PROVINCE" '>
  498. b.province = #{item.dimensionValue}
  499. </if>
  500. <if test = 'item.dimensionCode == "CITY" '>
  501. b.city = #{item.dimensionValue}
  502. </if>
  503. <if test = 'item.dimensionCode == "REGION" '>
  504. b.region = #{item.dimensionValue}
  505. </if>
  506. <if test = 'item.dimensionCode == "COMMUNITY" '>
  507. b.community = #{item.dimensionValue}
  508. </if>
  509. <if test = 'item.dimensionCode == "BUILDING" '>
  510. b.id = #{item.dimensionValue}
  511. </if>
  512. </foreach>
  513. </if>
  514. ) a
  515. LEFT JOIN (
  516. SELECT
  517. community,
  518. count( 1 ) AS total
  519. FROM
  520. sc_meter_read_record
  521. WHERE
  522. 1 = 1
  523. AND STATUS = 1
  524. <if test="param.channelId != null and param.channelId != 0 "> and sys_id = #{param.channelId}</if>
  525. <if test = "param.siteId !=null and param.siteId != 0"> and site_id = #{param.siteId}</if>
  526. <if test='param.programItems != null and param.programItems.size() != 0' >
  527. and EXISTS (
  528. select 1 from
  529. (select
  530. distinct df.device_id
  531. FROM sc_device_dim_info df
  532. WHERE 1 = 1
  533. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  534. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  535. </foreach> ) ud WHERE ud.device_id = device_id)
  536. </if>
  537. <if test = "param.city != null and param.city != ''"> and city = #{param.city}</if>
  538. <if test = "param.deviceNo != null and param.deviceNo != ''"> and device_no like #{param.deviceNo}</if>
  539. <if test = 'param.readStatus != null and param.readStatus != "0"'> and read_status = #{param.readStatus,jdbcType=VARCHAR}</if>
  540. <if test = "param.location != null and param.location != ''"> and location like #{param.location}</if>
  541. <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
  542. <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
  543. GROUP BY
  544. community
  545. ) b ON ( a.community = b.community )
  546. order by total desc
  547. </select>
  548. -->
  549. <update id = "createTmpTable">
  550. create TEMPORARY table ${tableName} as
  551. select
  552. province,
  553. city,
  554. community,
  555. building_id,
  556. id
  557. from
  558. sc_meter_read_record
  559. where status = 1
  560. <if test="param.channelId != null and param.channelId != 0 "> and sys_id = #{param.channelId}</if>
  561. <if test = "param.siteId !=null and param.siteId != 0"> and site_id = #{param.siteId}</if>
  562. <if test='param.programItems != null and param.programItems.size() != 0' >
  563. and device_id in (
  564. select
  565. df.device_id
  566. FROM sc_device_dim_info df
  567. WHERE 1 = 1
  568. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  569. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  570. </foreach>
  571. )
  572. </if>
  573. <if test = "param.province != null and param.province != ''"> and province = #{param.province}</if>
  574. <if test = "param.region != null and param.region != ''"> and region = #{param.region}</if>
  575. <if test = "param.city != null and param.city != ''"> and city = #{param.city}</if>
  576. <if test = "param.communityId != null and param.communityId != '' ">and community = #{param.communityId} </if>
  577. <if test = "param.deviceNo != null and param.deviceNo != ''"> and device_no like #{param.deviceNo}</if>
  578. <if test = 'param.readStatus != null and param.readStatus != "0"'> and read_status = #{param.readStatus,jdbcType=VARCHAR}</if>
  579. <if test = "param.location != null and param.location != ''"> and location like #{param.location}</if>
  580. <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
  581. <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
  582. </update>
  583. <update id="dropTmpTable" >
  584. drop TEMPORARY table if exists ${tableName}
  585. </update>
  586. <select id= "statisticReadRecordsByProvince" resultType="com.bz.smart_city.entity.MeterRecordStat">
  587. select
  588. 1 as level,
  589. a.parent_id as parent_id,
  590. province as item_id,
  591. a.name as item_name,
  592. count(1) as total
  593. from
  594. ${tableName}
  595. left join sc_area a on (province = a.id)
  596. group by province,a.name,a.parent_id
  597. </select>
  598. <select id= "statisticReadRecordsByCity" resultType="com.bz.smart_city.entity.MeterRecordStat">
  599. select
  600. 2 as level,
  601. a.parent_id as parent_id,
  602. city as item_id,
  603. a.name as item_name,
  604. count(1) as total
  605. from
  606. ${tableName}
  607. left join sc_area a on (city = a.id)
  608. group by city,a.name,a.parent_id
  609. </select>
  610. <select id= "statisticReadRecordsByCommuinty" resultType="com.bz.smart_city.entity.MeterRecordStat">
  611. select
  612. 3 as level,
  613. a.city as parent_id,
  614. community as item_id,
  615. a.name as item_name,
  616. count(1) as total
  617. from
  618. ${tableName}
  619. left join sc_community a on (community = a.id)
  620. group by community,a.name,a.city
  621. </select>
  622. <select id= "statisticReadRecordsByBuilding" resultType="com.bz.smart_city.entity.MeterRecordStat">
  623. select
  624. 4 as level,
  625. a.community as parent_id,
  626. building_id as item_id,
  627. a.name as item_name,
  628. count(1) as total
  629. from
  630. ${tableName}
  631. left join sc_building a on (building_id = a.id)
  632. group by building_id,a.name,a.community
  633. </select>
  634. <!--
  635. <select id="statisticReadRecordsByRegion" resultType="com.bz.smart_city.entity.MeterRecordStat">
  636. SELECT
  637. '区' as level,
  638. a.region as item_id,
  639. a.NAME as item_name,
  640. CASE WHEN b.total IS NULL THEN 0 ELSE b.total END AS total
  641. FROM
  642. (
  643. SELECT DISTINCT
  644. region,
  645. NAME
  646. FROM
  647. sc_meter_read_record
  648. LEFT JOIN sc_area a ON ( region = a.id )
  649. WHERE
  650. 1 = 1
  651. AND a.STATUS = 1
  652. <if test="param.channelId != null and param.channelId != 0 "> and sys_id = #{param.channelId}</if>
  653. <if test = "param.siteId !=null and param.siteId != 0"> and site_id = #{param.siteId}</if>
  654. <if test = "param.city != null and param.city != ''"> and city = #{param.city}</if>
  655. ) a
  656. LEFT JOIN (
  657. SELECT
  658. region,
  659. count( 1 ) AS total
  660. FROM
  661. sc_meter_read_record
  662. WHERE
  663. 1 = 1
  664. AND STATUS = 1
  665. <if test="param.channelId != null and param.channelId != 0 "> and sys_id = #{param.channelId}</if>
  666. <if test = "param.siteId !=null and param.siteId != 0"> and site_id = #{param.siteId}</if>
  667. <if test = "param.province != null and param.province != ''"> and province = #{param.province}</if>
  668. <if test = "param.region != null and param.region != ''"> and region = #{param.region}</if>
  669. <if test = "param.city != null and param.city != ''"> and city = #{param.city}</if>
  670. <if test = "param.communityId != null and param.communityId != '' ">and community = #{param.communityId} </if>
  671. <if test = "param.deviceNo != null and param.deviceNo != ''"> and device_no like #{param.deviceNo}</if>
  672. <if test = 'param.readStatus != null and param.readStatus != "0"'> and read_status = #{param.readStatus,jdbcType=VARCHAR}</if>
  673. <if test = "param.location != null and param.location != ''"> and location like #{param.location}</if>
  674. <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
  675. <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
  676. GROUP BY
  677. region
  678. ) b ON ( a.region = b.region )
  679. order by total desc
  680. </select>
  681. <select id="statisticReadRecordsByBuilding" resultType="com.bz.smart_city.entity.MeterRecordStat">
  682. SELECT
  683. '建筑' as level,
  684. a.id as item_id,
  685. a.name as item_name,
  686. case when b.total is null then 0 else b.total end as total
  687. FROM
  688. (
  689. SELECT
  690. DISTINCT
  691. id,
  692. NAME
  693. FROM
  694. sc_building
  695. WHERE
  696. 1 = 1
  697. and STATUS = 1
  698. <if test = "param.siteId != null and param.siteId != 0"> and site_id = #{param.siteId}</if>
  699. <if test = "param.province != null and param.province != ''"> and province = #{param.province}</if>
  700. <if test = "param.region != null and param.region != ''"> and region = #{param.region}</if>
  701. <if test = "param.city != null and param.city != ''"> and city = #{param.city}</if>
  702. <if test=" param.communityId != null and param.communityId != '' ">and community = #{param.communityId} </if>
  703. <if test='param.programItems != null and param.programItems.size() != 0' >
  704. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  705. <if test = 'item.dimensionCode == "PROVINCE" '>
  706. province = #{item.dimensionValue}
  707. </if>
  708. <if test = 'item.dimensionCode == "CITY" '>
  709. city = #{item.dimensionValue}
  710. </if>
  711. <if test = 'item.dimensionCode == "REGION" '>
  712. region = #{item.dimensionValue}
  713. </if>
  714. <if test = 'item.dimensionCode == "COMMUNITY" '>
  715. community = #{item.dimensionValue}
  716. </if>
  717. <if test = 'item.dimensionCode == "BUILDING" '>
  718. id = #{item.dimensionValue}
  719. </if>
  720. </foreach>
  721. </if>
  722. ) a
  723. LEFT JOIN (
  724. SELECT
  725. building_id,
  726. count( 1 ) AS total
  727. FROM
  728. sc_meter_read_record
  729. WHERE
  730. 1 = 1
  731. AND STATUS = 1
  732. <if test = "param.channelId != null and param.channelId != 0 "> and sys_id = #{param.channelId}</if>
  733. <if test = "param.siteId !=null and param.siteId != 0"> and site_id = #{param.siteId}</if>
  734. <if test = "param.city != null and param.city != ''"> and city = #{param.city}</if>
  735. <if test = "param.region != null and param.region != ''"> and region = #{param.region}</if>
  736. <if test=" param.communityId != null and param.communityId != '' ">and community = #{param.communityId} </if>
  737. <if test='param.programItems != null and param.programItems.size() != 0' >
  738. and EXISTS (
  739. select 1 from
  740. (select
  741. distinct df.device_id
  742. FROM sc_device_dim_info df
  743. WHERE 1 = 1
  744. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  745. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  746. </foreach> ) ud WHERE ud.device_id = device_id)
  747. </if>
  748. <if test = "param.deviceNo != null and param.deviceNo != ''"> and device_no like #{param.deviceNo}</if>
  749. <if test = 'param.readStatus != null and param.readStatus != "0"'> and read_status = #{param.readStatus,jdbcType=VARCHAR}</if>
  750. <if test = "param.location != null and param.location != ''"> and location like #{param.location}</if>
  751. <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
  752. <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
  753. GROUP BY
  754. building_id
  755. ) b ON ( a.id = b.building_id )
  756. order by b.total desc
  757. </select>
  758. -->
  759. <select id="queryMeterReadRecordWithCondtion" resultType="com.bz.smart_city.entity.MeterReadRecord">
  760. SELECT
  761. m.id AS id,
  762. m.read_date as read_date,
  763. m.site_id AS site_id,
  764. m.sys_id AS sys_id,
  765. m.province AS province,
  766. m.city AS city,
  767. m.community AS community_id,
  768. com.`name` as community_name,
  769. m.building_id AS building_id,
  770. b.NAME AS building_name,
  771. m.location AS location,
  772. device_type_id ,
  773. m.device_id,
  774. device_no,
  775. meter_no,
  776. meter_file_no,
  777. read_time,
  778. read_status,
  779. read_data,
  780. m.concentrator_id as concentrator_id,
  781. con.serial_number as concentrator_no,
  782. m.collector_id as collector_id ,
  783. col.collector_no as collector_no,
  784. m.customer_id as customer_id,
  785. cust.customer_name as customer_name,
  786. dt.manufacturer_id as factory_id,
  787. dt.equipment_type,
  788. dt.model,
  789. dm.`name` as factory_name,
  790. scn.channel_name as channel_number_name
  791. FROM
  792. sc_meter_read_record m
  793. LEFT JOIN sc_building b ON ( m.building_id = b.id )
  794. left join sc_community com on (com.id = m.community)
  795. left join sc_customer cust on (cust.id = m.customer_id)
  796. left join sc_concentrator con on (con.id = m.concentrator_id)
  797. left join sc_collector col on (col.id = m.collector_id)
  798. left join sc_device_type dt on (dt.id = m.device_type_id)
  799. left join sc_device_manufacturer dm on (dm.id = dt.manufacturer_id)
  800. left join sc_water_related_device wrd on (wrd.device_id = m.device_id)
  801. left join sc_channel_number scn on (scn.id = wrd.channel_number_id)
  802. WHERE m.STATUS = 1
  803. <!-- 数据权限 -->
  804. <if test="param.siteId != null and param.siteId != 0">
  805. and m.site_id = #{param.siteId}
  806. </if>
  807. <if test="param.sites != null and param.sites.size() != 0">
  808. and m.site_id in
  809. <foreach collection="param.sites" item="site" open="(" separator="," close=")">
  810. #{site.id}
  811. </foreach>
  812. </if>
  813. <if test="param.buildingIds != null and param.buildingIds.size() != 0">
  814. and m.building_id in <foreach collection="param.buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  815. </if>
  816. <if test="param.customerIds != null and param.customerIds.size() != 0">
  817. and m.customer_id in <foreach collection="param.customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  818. </if>
  819. <if test = "param.concentratorCode != null and param.concentratorCode != '' "> and con.serial_number like #{param.concentratorCode}</if>
  820. <if test = "param.concentratorId != null"> and m.concentrator_id = #{param.concentratorId}</if>
  821. <if test = "param.channelNumberId != null"> and wrd.channel_number_id = #{param.channelNumberId}</if>
  822. <if test = "param.collectorCode != null and param.collectorCode != '' "> and col.collector_no like #{param.collectorCode}</if>
  823. <if test = "param.deviceNo != null and param.deviceNo != '' ">
  824. and m.meter_no like #{param.deviceElectricNo}
  825. </if>
  826. <if test = "param.custormerId !=null and param.custormerId != 0"> and m.customer_id = #{param.custormerId}</if>
  827. <if test = "param.communityId != null and param.communityId != 0"> and m.community = #{param.communityId}</if>
  828. <if test = "param.buildingId != null and param.buildingId != 0"> and m.building_id = #{param.buildingId}</if>
  829. <if test = 'param.readStatus != null and param.readStatus != ""'> and read_status = #{param.readStatus}</if>
  830. <if test = "param.channelId != null and param.channelId != 0"> and m.sys_id = #{param.channelId}</if>
  831. <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
  832. <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
  833. order by read_time desc
  834. </select>
  835. <select id="queryMeterReadRecordWithCondtion_COUNT" resultType="Long">
  836. SELECT
  837. count(1)
  838. FROM
  839. sc_meter_read_record m
  840. <if test = "param.concentratorCode != null and param.concentratorCode != '' ">left join sc_concentrator con on (con.id = m.concentrator_id)</if>
  841. <if test = "param.collectorCode != null and param.collectorCode != '' ">left join sc_collector col on (col.id = m.collector_id)</if>
  842. <if test = "param.channelNumberId != null">left join sc_water_related_device wrd on (wrd.device_id = m.device_id)</if>
  843. WHERE m.STATUS = 1
  844. <!-- 数据权限 -->
  845. <if test="param.siteId != null and param.siteId != 0">
  846. and m.site_id = #{param.siteId}
  847. </if>
  848. <if test="param.sites != null and param.sites.size() != 0">
  849. and m.site_id in
  850. <foreach collection="param.sites" item="site" open="(" separator="," close=")">
  851. #{site.id}
  852. </foreach>
  853. </if>
  854. <if test="param.buildingIds != null and param.buildingIds.size() != 0">
  855. and m.building_id in <foreach collection="param.buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  856. </if>
  857. <if test="param.customerIds != null and param.customerIds.size() != 0">
  858. and m.customer_id in <foreach collection="param.customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  859. </if>
  860. <if test = "param.concentratorCode != null and param.concentratorCode != '' "> and con.serial_number like #{param.concentratorCode}</if>
  861. <if test = "param.concentratorId != null"> and m.concentrator_id = #{param.concentratorId}</if>
  862. <if test = "param.channelNumberId != null"> and wrd.channel_number_id = #{param.channelNumberId}</if>
  863. <if test = "param.collectorCode != null and param.collectorCode != '' "> and col.collector_no like #{param.collectorCode}</if>
  864. <if test = "param.deviceNo != null and param.deviceNo != '' ">
  865. and m.meter_no like #{param.deviceElectricNo}
  866. </if>
  867. <if test = "param.custormerId !=null and param.custormerId != 0"> and m.customer_id = #{param.custormerId}</if>
  868. <if test = "param.communityId != null and param.communityId != 0"> and m.community = #{param.communityId}</if>
  869. <if test = "param.buildingId != null and param.buildingId != 0"> and m.building_id = #{param.buildingId}</if>
  870. <if test = 'param.readStatus != null and param.readStatus != ""'> and read_status = #{param.readStatus}</if>
  871. <if test = "param.channelId != null and param.channelId != 0"> and m.sys_id = #{param.channelId}</if>
  872. <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
  873. <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
  874. order by read_time desc
  875. </select>
  876. <select id="queryUnReadDeviceListWithNew" resultType="com.bz.smart_city.dto.DeviceDto">
  877. SELECT
  878. d.site_id as siteId,
  879. d.customer_id as customerId,
  880. d.sys_id as sysId,
  881. d.id as id,
  882. d.device_type as deviceType,
  883. d.building_id as buildingId,
  884. co.id as community,
  885. p.id as province,
  886. c.id as city,
  887. r.id as region,
  888. cu.customer_name as customerName,
  889. b.`name`as buildingName,
  890. co.`name`as communityName,
  891. col.collector_no as collectorName,
  892. con.serial_number as concentratorName,
  893. d.water_meter_no as waterMeterNo,
  894. d.water_meter_file_no as waterMeterFileNo,
  895. d.device_no as deviceNo,
  896. d.device_status as deviceStatus,
  897. d.floor as floor,
  898. d.loc_desc as locDesc,
  899. d.last_receive_time as lastReceiveTime
  900. FROM
  901. sc_device d
  902. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  903. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  904. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  905. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  906. LEFT JOIN sc_area p ON ( b.province = p.id )
  907. LEFT JOIN sc_area c ON ( b.city = c.id )
  908. LEFT JOIN sc_area r ON ( b.region = r.id )
  909. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  910. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  911. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  912. where d.status = 1
  913. <if test = "param.buildingId != null and param.buildingId != 0">
  914. and d.building_id = #{param.buildingId}
  915. </if>
  916. <if test="param.siteId != null and param.siteId != 0">
  917. and d.site_id = #{param.siteId}
  918. </if>
  919. <if test = "param.channelId != null and param.channelId != 0">
  920. and d.sys_id = #{param.channelId}
  921. </if>
  922. <if test="param.custormerId != null and param.custormerId != 0">
  923. and d.customer_id = #{param.custormerId}
  924. </if>
  925. and ( d.id IN (
  926. SELECT
  927. tmp.device_id
  928. FROM
  929. (
  930. SELECT
  931. site_id,
  932. sys_id,
  933. building_id,
  934. device_id
  935. FROM
  936. sc_meter_read_record
  937. WHERE
  938. <if test = "param.statDay != null and param.statDay != 0">
  939. read_date = #{param.statDay}
  940. </if>
  941. <if test = "param.buildingId != null and param.buildingId != 0">
  942. AND building_id = #{param.buildingId}
  943. </if>
  944. AND read_status = 1
  945. ) tmp
  946. ) or d.device_status = 5)
  947. </select>
  948. <select id="queryUnReadDeviceList" resultType="com.bz.smart_city.dto.DeviceDto">
  949. SELECT
  950. d.site_id as siteId,
  951. d.customer_id as customerId,
  952. d.sys_id as sysId,
  953. d.id as id,
  954. d.device_type as deviceType,
  955. d.building_id as buildingId,
  956. co.id as community,
  957. p.id as province,
  958. c.id as city,
  959. r.id as region,
  960. cu.customer_name as customerName,
  961. b.`name`as buildingName,
  962. co.`name`as communityName,
  963. col.collector_no as collectorName,
  964. con.serial_number as concentratorName,
  965. d.water_meter_no as waterMeterNo,
  966. d.water_meter_file_no as waterMeterFileNo,
  967. d.device_no as deviceNo,
  968. d.device_status as deviceStatus,
  969. d.floor as floor,
  970. d.loc_desc as locDesc,
  971. d.last_receive_time as lastReceiveTime
  972. FROM
  973. sc_device d
  974. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  975. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  976. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  977. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  978. LEFT JOIN sc_area p ON ( b.province = p.id )
  979. LEFT JOIN sc_area c ON ( b.city = c.id )
  980. LEFT JOIN sc_area r ON ( b.region = r.id )
  981. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  982. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  983. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  984. where d.status = 1
  985. <if test = "param.buildingId != null and param.buildingId != 0">
  986. and d.building_id = #{param.buildingId}
  987. </if>
  988. <if test="param.siteId != null and param.siteId != 0">
  989. and d.site_id = #{param.siteId}
  990. </if>
  991. <if test = "param.channelId != null and param.channelId != 0">
  992. and d.sys_id = #{param.channelId}
  993. </if>
  994. <if test="param.custormerId != null and param.custormerId != 0">
  995. and d.customer_id = #{param.custormerId}
  996. </if>
  997. and d.id IN (
  998. SELECT
  999. tmp.device_id
  1000. FROM
  1001. (
  1002. SELECT
  1003. site_id,
  1004. channel_id,
  1005. building_id,
  1006. device_id
  1007. FROM
  1008. sc_stat_meter_unread_device_by_building
  1009. WHERE
  1010. <if test = "param.statDay != null and param.statDay != 0">
  1011. stat_day = #{param.statDay}
  1012. </if>
  1013. <if test = "param.buildingId != null and param.buildingId != 0">
  1014. AND building_id = #{param.buildingId}
  1015. </if>
  1016. ) tmp
  1017. )
  1018. </select>
  1019. <select id="queryUnReadDeviceListV2" resultType="com.bz.smart_city.dto.DeviceDto">
  1020. SELECT
  1021. d.site_id as siteId,
  1022. d.customer_id as customerId,
  1023. d.sys_id as sysId,
  1024. d.id as id,
  1025. d.device_type as deviceType,
  1026. d.building_id as buildingId,
  1027. co.id as community,
  1028. cu.customer_name as customerName,
  1029. b.`name`as buildingName,
  1030. co.`name`as communityName,
  1031. col.collector_no as collectorName,
  1032. con.serial_number as concentratorName,
  1033. d.water_meter_no as waterMeterNo,
  1034. d.water_meter_file_no as waterMeterFileNo,
  1035. d.device_no as deviceNo,
  1036. d.device_status as deviceStatus,
  1037. d.floor as floor,
  1038. d.loc_desc as locDesc,
  1039. d.last_receive_time as lastReceiveTime
  1040. FROM ${tableName} as t1
  1041. LEFT JOIN sc_device d on(t1.device_id = d.id)
  1042. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1043. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1044. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1045. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1046. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1047. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1048. where d.status = 1
  1049. <if test = "param.buildingId != null and param.buildingId != 0">
  1050. and d.building_id = #{param.buildingId}
  1051. </if>
  1052. <if test="param.siteId != null and param.siteId != 0">
  1053. and d.site_id = #{param.siteId}
  1054. </if>
  1055. <if test = "param.channelId != null and param.channelId != 0">
  1056. and d.sys_id = #{param.channelId}
  1057. </if>
  1058. <if test="param.custormerId != null and param.custormerId != 0">
  1059. and d.customer_id = #{param.custormerId}
  1060. </if>
  1061. <if test = "param.statDay != null and param.statDay != 0">
  1062. and t1.stat_day = #{param.statDay}
  1063. </if>
  1064. <if test = "param.buildingId != null and param.buildingId != 0">
  1065. AND t1.building_id = #{param.buildingId}
  1066. </if>
  1067. </select>
  1068. <select id="queryUnReadDeviceListForToday_COUNT" resultType="Long">
  1069. SELECT
  1070. count(device_id)
  1071. FROM sc_meter_read_record
  1072. WHERE read_status = 1
  1073. <if test = "param.buildingId != null">
  1074. and building_id = #{param.buildingId}
  1075. </if>
  1076. <if test="param.channelId != null">
  1077. and sys_id = #{param.channelId}
  1078. </if>
  1079. <if test="param.custormerId != null ">
  1080. and customer_id = #{param.custormerId}
  1081. </if>
  1082. AND read_date = DATE_FORMAT( now( ), '%Y%m%d' )
  1083. </select>
  1084. <select id="queryUnReadDeviceListForToday" resultType="com.bz.smart_city.dto.DeviceDto">
  1085. SELECT
  1086. d.site_id as siteId,
  1087. d.customer_id as customerId,
  1088. d.sys_id as sysId,
  1089. d.id as id,
  1090. d.device_type as deviceType,
  1091. d.building_id as buildingId,
  1092. col.collector_no as collectorName,
  1093. con.serial_number as concentratorName,
  1094. d.water_meter_no as waterMeterNo,
  1095. d.water_meter_file_no as waterMeterFileNo,
  1096. d.device_no as deviceNo,
  1097. d.device_status as deviceStatus,
  1098. d.floor as floor,
  1099. d.loc_desc as locDesc,
  1100. d.last_receive_time as lastReceiveTime
  1101. FROM (
  1102. SELECT
  1103. device_id
  1104. FROM sc_meter_read_record
  1105. WHERE read_status = 1
  1106. <if test = "param.buildingId != null">
  1107. and building_id = #{param.buildingId}
  1108. </if>
  1109. <if test="param.channelId != null">
  1110. and sys_id = #{param.channelId}
  1111. </if>
  1112. <if test="param.custormerId != null ">
  1113. and customer_id = #{param.custormerId}
  1114. </if>
  1115. AND read_date = DATE_FORMAT( now( ), '%Y%m%d' )
  1116. ) t1
  1117. LEFT JOIN sc_device d on (t1.device_id = d.id)
  1118. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1119. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1120. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1121. where d.status = 1
  1122. </select>
  1123. <select id="queryUnReadDeviceListFor7Day" resultType="com.bz.smart_city.dto.DeviceDto">
  1124. SELECT
  1125. d.site_id as siteId,
  1126. d.customer_id as customerId,
  1127. d.sys_id as sysId,
  1128. d.id as id,
  1129. d.device_type as deviceType,
  1130. d.building_id as buildingId,
  1131. co.id as community,
  1132. p.id as province,
  1133. c.id as city,
  1134. r.id as region,
  1135. cu.customer_name as customerName,
  1136. b.`name`as buildingName,
  1137. co.`name`as communityName,
  1138. col.collector_no as collectorName,
  1139. con.serial_number as concentratorName,
  1140. d.water_meter_no as waterMeterNo,
  1141. d.water_meter_file_no as waterMeterFileNo,
  1142. d.device_no as deviceNo,
  1143. d.device_status as deviceStatus,
  1144. d.floor as floor,
  1145. d.loc_desc as locDesc,
  1146. d.last_receive_time as lastReceiveTime
  1147. FROM
  1148. sc_device d
  1149. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  1150. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1151. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1152. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1153. LEFT JOIN sc_area p ON ( b.province = p.id )
  1154. LEFT JOIN sc_area c ON ( b.city = c.id )
  1155. LEFT JOIN sc_area r ON ( b.region = r.id )
  1156. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1157. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1158. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1159. where d.status = 1
  1160. <if test = "param.buildingId != null and param.buildingId != 0">
  1161. and d.building_id = #{param.buildingId}
  1162. </if>
  1163. <if test="param.siteId != null and param.siteId != 0">
  1164. and d.site_id = #{param.siteId}
  1165. </if>
  1166. <if test = "param.channelId != null and param.channelId != 0">
  1167. and d.sys_id = #{param.channelId}
  1168. </if>
  1169. <if test="param.custormerId != null and param.custormerId != 0">
  1170. and d.customer_id = #{param.custormerId}
  1171. </if>
  1172. and d.id IN (
  1173. SELECT
  1174. tmp.device_id
  1175. FROM
  1176. (
  1177. SELECT
  1178. site_id,
  1179. channel_id,
  1180. building_id,
  1181. device_id
  1182. FROM
  1183. sc_stat_meter_unread_device_by_building_7day
  1184. WHERE
  1185. <if test = "param.statDay != null and param.statDay != 0">
  1186. stat_day = #{param.statDay}
  1187. </if>
  1188. <if test = "param.buildingId != null and param.buildingId != 0">
  1189. AND building_id = #{param.buildingId}
  1190. </if>
  1191. ) tmp
  1192. )
  1193. </select>
  1194. <select id="queryUnReadDeviceListFor7DayWithNew" resultType="com.bz.smart_city.dto.DeviceDto">
  1195. SELECT
  1196. d.site_id as siteId,
  1197. d.customer_id as customerId,
  1198. d.sys_id as sysId,
  1199. d.id as id,
  1200. d.device_type as deviceType,
  1201. d.building_id as buildingId,
  1202. co.id as community,
  1203. p.id as province,
  1204. c.id as city,
  1205. r.id as region,
  1206. cu.customer_name as customerName,
  1207. b.`name`as buildingName,
  1208. co.`name`as communityName,
  1209. col.collector_no as collectorName,
  1210. con.serial_number as concentratorName,
  1211. d.water_meter_no as waterMeterNo,
  1212. d.water_meter_file_no as waterMeterFileNo,
  1213. d.device_no as deviceNo,
  1214. d.device_status as deviceStatus,
  1215. d.floor as floor,
  1216. d.loc_desc as locDesc,
  1217. d.last_receive_time as lastReceiveTime
  1218. FROM
  1219. sc_device d
  1220. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  1221. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1222. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1223. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1224. LEFT JOIN sc_area p ON ( b.province = p.id )
  1225. LEFT JOIN sc_area c ON ( b.city = c.id )
  1226. LEFT JOIN sc_area r ON ( b.region = r.id )
  1227. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1228. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1229. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1230. where d.status = 1
  1231. <if test = "param.buildingId != null and param.buildingId != 0">
  1232. and d.building_id = #{param.buildingId}
  1233. </if>
  1234. <if test="param.siteId != null and param.siteId != 0">
  1235. and d.site_id = #{param.siteId}
  1236. </if>
  1237. <if test = "param.channelId != null and param.channelId != 0">
  1238. and d.sys_id = #{param.channelId}
  1239. </if>
  1240. <if test="param.custormerId != null and param.custormerId != 0">
  1241. and d.customer_id = #{param.custormerId}
  1242. </if>
  1243. and ( d.id IN (
  1244. SELECT
  1245. tmp.device_id
  1246. FROM
  1247. (
  1248. SELECT
  1249. site_id,
  1250. channel_id,
  1251. building_id,
  1252. device_id
  1253. FROM
  1254. sc_stat_meter_unread_device_by_building_7day
  1255. WHERE
  1256. <if test = "param.statDay != null and param.statDay != 0">
  1257. stat_day = #{param.statDay}
  1258. </if>
  1259. <if test = "param.buildingId != null and param.buildingId != 0">
  1260. AND building_id = #{param.buildingId}
  1261. </if>
  1262. ) tmp
  1263. ) or d.device_status = 5 )
  1264. </select>
  1265. <select id="queryUnReadDeviceListFor15Day" resultType="com.bz.smart_city.dto.DeviceDto">
  1266. SELECT
  1267. d.site_id as siteId,
  1268. d.customer_id as customerId,
  1269. d.sys_id as sysId,
  1270. d.id as id,
  1271. d.device_type as deviceType,
  1272. d.building_id as buildingId,
  1273. co.id as community,
  1274. p.id as province,
  1275. c.id as city,
  1276. r.id as region,
  1277. cu.customer_name as customerName,
  1278. b.`name`as buildingName,
  1279. co.`name`as communityName,
  1280. col.collector_no as collectorName,
  1281. con.serial_number as concentratorName,
  1282. d.water_meter_no as waterMeterNo,
  1283. d.water_meter_file_no as waterMeterFileNo,
  1284. d.device_no as deviceNo,
  1285. d.device_status as deviceStatus,
  1286. d.floor as floor,
  1287. d.loc_desc as locDesc,
  1288. d.last_receive_time as lastReceiveTime
  1289. FROM
  1290. sc_device d
  1291. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  1292. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1293. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1294. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1295. LEFT JOIN sc_area p ON ( b.province = p.id )
  1296. LEFT JOIN sc_area c ON ( b.city = c.id )
  1297. LEFT JOIN sc_area r ON ( b.region = r.id )
  1298. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1299. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1300. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1301. where d.status = 1
  1302. <if test = "param.buildingId != null and param.buildingId != 0">
  1303. and d.building_id = #{param.buildingId}
  1304. </if>
  1305. <if test="param.siteId != null and param.siteId != 0">
  1306. and d.site_id = #{param.siteId}
  1307. </if>
  1308. <if test = "param.channelId != null and param.channelId != 0">
  1309. and d.sys_id = #{param.channelId}
  1310. </if>
  1311. <if test="param.custormerId != null and param.custormerId != 0">
  1312. and d.customer_id = #{param.custormerId}
  1313. </if>
  1314. and d.id IN (
  1315. SELECT
  1316. tmp.device_id
  1317. FROM
  1318. (
  1319. SELECT
  1320. site_id,
  1321. channel_id,
  1322. building_id,
  1323. device_id
  1324. FROM
  1325. sc_stat_meter_unread_device_by_building_15day
  1326. WHERE
  1327. <if test = "param.statDay != null and param.statDay != 0">
  1328. stat_day = #{param.statDay}
  1329. </if>
  1330. <if test = "param.buildingId != null and param.buildingId != 0">
  1331. AND building_id = #{param.buildingId}
  1332. </if>
  1333. ) tmp
  1334. )
  1335. </select>
  1336. <select id="queryUnReadDeviceListForMonth" resultType="com.bz.smart_city.dto.DeviceDto">
  1337. SELECT
  1338. d.site_id as siteId,
  1339. d.customer_id as customerId,
  1340. d.sys_id as sysId,
  1341. d.id as id,
  1342. d.device_type as deviceType,
  1343. d.building_id as buildingId,
  1344. co.id as community,
  1345. p.id as province,
  1346. c.id as city,
  1347. r.id as region,
  1348. cu.customer_name as customerName,
  1349. b.`name`as buildingName,
  1350. co.`name`as communityName,
  1351. col.collector_no as collectorName,
  1352. con.serial_number as concentratorName,
  1353. d.water_meter_no as waterMeterNo,
  1354. d.water_meter_file_no as waterMeterFileNo,
  1355. d.device_no as deviceNo,
  1356. d.device_status as deviceStatus,
  1357. d.floor as floor,
  1358. d.loc_desc as locDesc,
  1359. d.last_receive_time as lastReceiveTime
  1360. FROM
  1361. sc_device d
  1362. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  1363. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1364. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1365. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1366. LEFT JOIN sc_area p ON ( b.province = p.id )
  1367. LEFT JOIN sc_area c ON ( b.city = c.id )
  1368. LEFT JOIN sc_area r ON ( b.region = r.id )
  1369. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1370. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1371. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1372. where d.status = 1
  1373. <if test = "param.buildingId != null and param.buildingId != 0">
  1374. and d.building_id = #{param.buildingId}
  1375. </if>
  1376. <if test="param.siteId != null and param.siteId != 0">
  1377. and d.site_id = #{param.siteId}
  1378. </if>
  1379. <if test = "param.channelId != null and param.channelId != 0">
  1380. and d.sys_id = #{param.channelId}
  1381. </if>
  1382. <if test="param.custormerId != null and param.custormerId != 0">
  1383. and d.customer_id = #{param.custormerId}
  1384. </if>
  1385. and d.id IN (
  1386. SELECT
  1387. tmp.device_id
  1388. FROM
  1389. (
  1390. SELECT
  1391. site_id,
  1392. channel_id,
  1393. building_id,
  1394. device_id
  1395. FROM
  1396. sc_stat_meter_unread_device_by_building_month
  1397. WHERE
  1398. <if test = "param.statDay != null and param.statDay != 0">
  1399. stat_day = #{param.statDay}
  1400. </if>
  1401. <if test = "param.buildingId != null and param.buildingId != 0">
  1402. AND building_id = #{param.buildingId}
  1403. </if>
  1404. ) tmp
  1405. )
  1406. </select>
  1407. <select id="queryUnReadDeviceListFor15DayWithNew" resultType="com.bz.smart_city.dto.DeviceDto">
  1408. SELECT
  1409. d.site_id as siteId,
  1410. d.customer_id as customerId,
  1411. d.sys_id as sysId,
  1412. d.id as id,
  1413. d.device_type as deviceType,
  1414. d.building_id as buildingId,
  1415. co.id as community,
  1416. p.id as province,
  1417. c.id as city,
  1418. r.id as region,
  1419. cu.customer_name as customerName,
  1420. b.`name`as buildingName,
  1421. co.`name`as communityName,
  1422. col.collector_no as collectorName,
  1423. con.serial_number as concentratorName,
  1424. d.water_meter_no as waterMeterNo,
  1425. d.water_meter_file_no as waterMeterFileNo,
  1426. d.device_no as deviceNo,
  1427. d.device_status as deviceStatus,
  1428. d.floor as floor,
  1429. d.loc_desc as locDesc,
  1430. d.last_receive_time as lastReceiveTime
  1431. FROM
  1432. sc_device d
  1433. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  1434. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1435. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1436. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1437. LEFT JOIN sc_area p ON ( b.province = p.id )
  1438. LEFT JOIN sc_area c ON ( b.city = c.id )
  1439. LEFT JOIN sc_area r ON ( b.region = r.id )
  1440. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1441. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1442. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1443. where d.status = 1
  1444. <if test = "param.buildingId != null and param.buildingId != 0">
  1445. and d.building_id = #{param.buildingId}
  1446. </if>
  1447. <if test="param.siteId != null and param.siteId != 0">
  1448. and d.site_id = #{param.siteId}
  1449. </if>
  1450. <if test = "param.channelId != null and param.channelId != 0">
  1451. and d.sys_id = #{param.channelId}
  1452. </if>
  1453. <if test="param.custormerId != null and param.custormerId != 0">
  1454. and d.customer_id = #{param.custormerId}
  1455. </if>
  1456. and (d.id IN (
  1457. SELECT
  1458. tmp.device_id
  1459. FROM
  1460. (
  1461. SELECT
  1462. site_id,
  1463. channel_id,
  1464. building_id,
  1465. device_id
  1466. FROM
  1467. sc_stat_meter_unread_device_by_building_15day
  1468. WHERE
  1469. <if test = "param.statDay != null and param.statDay != 0">
  1470. stat_day = #{param.statDay}
  1471. </if>
  1472. <if test = "param.buildingId != null and param.buildingId != 0">
  1473. AND building_id = #{param.buildingId}
  1474. </if>
  1475. ) tmp
  1476. ) or d.device_status = 5)
  1477. </select>
  1478. <select id="queryDeviceMeterReadRecordWithCondtion" resultType="com.bz.smart_city.entity.MeterReadRecord">
  1479. select
  1480. <include refid="Base_Column_List" />
  1481. from
  1482. sc_meter_read_record
  1483. where read_status = 2
  1484. and device_id = #{param.deviceId}
  1485. <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
  1486. <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
  1487. order by read_date desc
  1488. </select>
  1489. <select id="getSummary" resultType="com.bz.smart_city.dto.WaterConsumptionSummaryDto">
  1490. select
  1491. ifnull(sum(result.water_consumption), 0) as total_water_consumption,
  1492. count(result.device_id) as total_device_count
  1493. from (
  1494. select
  1495. smrr.device_id as device_id,
  1496. smrr.building_id as building_id,
  1497. ifnull(sum(smrr.last_cost), 0) as water_consumption
  1498. from
  1499. sc_meter_read_record smrr
  1500. where smrr.status = 1
  1501. <if test="param.siteId != null"> and smrr.site_id = #{param.siteId}</if>
  1502. <if test="param.custormerId != null"> and smrr.customer_id = #{param.custormerId} </if>
  1503. <if test="param.buildingIds != null and param.buildingIds.size() != 0">
  1504. and smrr.building_id in <foreach collection="param.buildingIds" item="item" open="(" separator="," close=")"> #{item}</foreach>
  1505. </if>
  1506. <if test="param.startDate != null"> and smrr.read_date <![CDATA[ >= ]]> #{param.startDate} </if>
  1507. <if test="param.endDate != null"> and smrr.read_date <![CDATA[ <= ]]> #{param.endDate} </if>
  1508. <if test="param.customerIds != null and param.customerIds.size() != 0"> and smrr.customer_id in <foreach collection="param.customerIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  1509. group by
  1510. smrr.device_id, smrr.building_id
  1511. ) result
  1512. left join sc_building sb on (result.building_id = sb.id and sb.status = 1)
  1513. <if test="param.programItems != null and param.programItems.size() != 0"> left join sc_device_dimension sdd on (sdd.device_id = result.device_id and sdd.status = 1) </if>
  1514. where 1 = 1
  1515. <if test="param.programItems != null and param.programItems.size() != 0"> and
  1516. <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  1517. sdd.${item.dimensionCode} = #{item.dimensionValue}
  1518. </foreach>
  1519. </if>
  1520. <if test="param.provinces != null and param.provinces.size() != 0">
  1521. and sb.province in <foreach collection="param.provinces" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1522. </if>
  1523. <if test="param.cities != null and param.cities.size() != 0">
  1524. and sb.city in <foreach collection="param.cities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1525. </if>
  1526. <if test="param.regions != null and param.regions.size() != 0">
  1527. and sb.region in <foreach collection="param.regions" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1528. </if>
  1529. <if test="param.communities != null and param.communities.size() != 0">
  1530. and sb.community in <foreach collection="param.communities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1531. </if>
  1532. <if test="param.beginRate != null"> and result.water_consumption <![CDATA[ >= ]]> #{param.beginRate} </if>
  1533. <if test="param.endRate != null"> and result.water_consumption <![CDATA[ <= ]]> #{param.endRate} </if>
  1534. </select>
  1535. <select id="getList" resultType="com.bz.smart_city.dto.WaterConsumptionDto">
  1536. select
  1537. list.meter_no as meter_no,
  1538. list.device_type as device_type,
  1539. list.customer as customer,
  1540. list.district as district,
  1541. list.community as community,
  1542. list.building as building,
  1543. list.location as location,
  1544. list.water_consumption as water_consumption
  1545. from (
  1546. select
  1547. smrr.meter_no as meter_no,
  1548. sdt.equipment_type as device_type,
  1549. scu.customer_name as customer,
  1550. replace(replace(sa.manger_name, "中国", ""), ",", "") as district,
  1551. sco.name as community,
  1552. sb.name as building,
  1553. smrr.location as location,
  1554. ifnull(sum(smrr.last_cost), 0) as water_consumption
  1555. from
  1556. sc_meter_read_record smrr
  1557. left join sc_device_type sdt on (smrr.device_type_id = sdt.id and sdt.status = 1)
  1558. left join sc_customer scu on (smrr.customer_id = scu.id and scu.status = 1)
  1559. left join sc_building sb on (smrr.building_id = sb.id and sb.status = 1)
  1560. left join sc_area sa on (sa.id = sb.region)
  1561. left join sc_community sco on (sb.community = sco.id and sco.id)
  1562. <if test="param.programItems != null and param.programItems.size() != 0"> left join sc_device_dimension sdd on (sdd.device_id = smrr.device_id and sdd.status = 1) </if>
  1563. where
  1564. smrr.status = 1
  1565. <if test="param.siteId != null"> and smrr.site_id = #{param.siteId} </if>
  1566. <if test="param.programItems != null and param.programItems.size() != 0"> and
  1567. <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  1568. sdd.${item.dimensionCode} = #{item.dimensionValue}
  1569. </foreach>
  1570. </if>
  1571. <if test="param.custormerId != null"> and smrr.customer_id = #{param.custormerId} </if>
  1572. <if test="param.provinces != null and param.provinces.size() != 0">
  1573. and sb.province in <foreach collection="param.provinces" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1574. </if>
  1575. <if test="param.cities != null and param.cities.size() != 0">
  1576. and sb.city in <foreach collection="param.cities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1577. </if>
  1578. <if test="param.regions != null and param.regions.size() != 0">
  1579. and sb.region in <foreach collection="param.regions" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1580. </if>
  1581. <if test="param.communities != null and param.communities.size() != 0">
  1582. and sb.community in <foreach collection="param.communities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1583. </if>
  1584. <if test="param.buildingIds != null and param.buildingIds.size() != 0">
  1585. and smrr.building_id in <foreach collection="param.buildingIds" item="item" open="(" separator="," close=")"> #{item}</foreach>
  1586. </if>
  1587. <if test="param.startDate != null"> and smrr.read_date <![CDATA[ >= ]]> #{param.startDate} </if>
  1588. <if test="param.endDate != null"> and smrr.read_date <![CDATA[ <= ]]> #{param.endDate} </if>
  1589. <if test="param.customerIds != null and param.customerIds.size() != 0"> and smrr.customer_id in <foreach collection="param.customerIds" item="item" open="(" separator="," close=")">#{item}</foreach> </if>
  1590. group by
  1591. smrr.meter_no, sdt.equipment_type, scu.customer_name, district, sco.name, sb.name, smrr.location
  1592. ) list
  1593. where 1 = 1
  1594. <if test="param.beginRate != null"> and list.water_consumption <![CDATA[ >= ]]> #{param.beginRate} </if>
  1595. <if test="param.endRate != null"> and list.water_consumption <![CDATA[ <= ]]> #{param.endRate} </if>
  1596. <if test="param.sortOrder != null"> order by list.water_consumption ${param.sortOrder} </if>
  1597. </select>
  1598. <select id="getList_COUNT" resultType="Long">
  1599. select
  1600. count(result.device_id)
  1601. from (
  1602. select
  1603. smrr.device_id as device_id,
  1604. smrr.building_id as building_id,
  1605. ifnull(sum(smrr.last_cost), 0) as water_consumption
  1606. from
  1607. sc_meter_read_record smrr
  1608. where smrr.status = 1
  1609. <if test="param.siteId != null"> and smrr.site_id = #{param.siteId}</if>
  1610. <if test="param.custormerId != null"> and smrr.customer_id = #{param.custormerId} </if>
  1611. <if test="param.buildingIds != null and param.buildingIds.size() != 0">
  1612. and smrr.building_id in <foreach collection="param.buildingIds" item="item" open="(" separator="," close=")"> #{item}</foreach>
  1613. </if>
  1614. <if test="param.startDate != null"> and smrr.read_date <![CDATA[ >= ]]> #{param.startDate} </if>
  1615. <if test="param.endDate != null"> and smrr.read_date <![CDATA[ <= ]]> #{param.endDate} </if>
  1616. group by
  1617. smrr.device_id, smrr.building_id
  1618. ) result
  1619. left join sc_building sb on (result.building_id = sb.id and sb.status = 1)
  1620. <if test="param.programItems != null and param.programItems.size() != 0"> left join sc_device_dimension sdd on (sdd.device_id = result.device_id and sdd.status = 1) </if>
  1621. where 1 = 1
  1622. <if test="param.programItems != null and param.programItems.size() != 0"> and
  1623. <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  1624. sdd.${item.dimensionCode} = #{item.dimensionValue}
  1625. </foreach>
  1626. </if>
  1627. <if test="param.provinces != null and param.provinces.size() != 0">
  1628. and sb.province in <foreach collection="param.provinces" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1629. </if>
  1630. <if test="param.cities != null and param.cities.size() != 0">
  1631. and sb.city in <foreach collection="param.cities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1632. </if>
  1633. <if test="param.regions != null and param.regions.size() != 0">
  1634. and sb.region in <foreach collection="param.regions" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1635. </if>
  1636. <if test="param.communities != null and param.communities.size() != 0">
  1637. and sb.community in <foreach collection="param.communities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1638. </if>
  1639. <if test="param.beginRate != null"> and result.water_consumption <![CDATA[ >= ]]> #{param.beginRate} </if>
  1640. <if test="param.endRate != null"> and result.water_consumption <![CDATA[ <= ]]> #{param.endRate} </if>
  1641. </select>
  1642. <select id="getLastDayData" resultMap="BaseResultMap">
  1643. select
  1644. <include refid="Base_Column_List" />
  1645. from
  1646. sc_meter_read_record
  1647. where
  1648. status = 1 and device_id = #{deviceId} and read_date = #{lastDate}
  1649. </select>
  1650. <select id="getLastDayDataV2" resultMap="BaseResultMap">
  1651. select
  1652. <include refid="Base_Column_List" />
  1653. from
  1654. sc_meter_read_record
  1655. where
  1656. status = 1 and device_id = #{deviceId} and read_date <![CDATA[ < ]]> #{lastDate} order by read_date desc limit 1
  1657. </select>
  1658. <select id="getAllDeviceId" resultType="Long">
  1659. select distinct device_id
  1660. from sc_meter_read_record
  1661. where status = 1 and sys_id = -99
  1662. <if test="startDate != null"> and read_date <![CDATA[ >= ]]> #{startDate} </if>
  1663. order by device_id asc
  1664. </select>
  1665. <select id="getMeterReadRecordByDeviceId" resultMap="BaseResultMap">
  1666. select
  1667. <include refid="Base_Column_List" />
  1668. from sc_meter_read_record
  1669. where status = 1
  1670. <if test="deviceId != null"> and device_id = #{deviceId} </if>
  1671. <if test="startDate != null"> and read_date <![CDATA[ >= ]]> #{startDate} </if>
  1672. order by read_date asc
  1673. </select>
  1674. <update id="batchUpdate" parameterType="list">
  1675. UPDATE sc_meter_read_record
  1676. <trim prefix="set" suffixOverrides=",">
  1677. <trim prefix="last_valid =case" suffix="end,">
  1678. <foreach collection="list" item="item">
  1679. <if test="item.lastValid!=null">
  1680. when id=#{item.id} then #{item.lastValid}
  1681. </if>
  1682. </foreach>
  1683. </trim>
  1684. <trim prefix="last_cost =case" suffix="end,">
  1685. <foreach collection="list" item="item">
  1686. <if test="item.lastCost!=null">
  1687. when id=#{item.id} then #{item.lastCost}
  1688. </if>
  1689. </foreach>
  1690. </trim>
  1691. </trim>
  1692. <where>
  1693. id in <foreach collection="list" item="item" open="(" separator="," close=")">#{item.id}</foreach>
  1694. </where>
  1695. </update>
  1696. <select id="getDeviceIdOnDate" resultType="Long">
  1697. select
  1698. device_id
  1699. from sc_meter_read_record
  1700. where status = 1 and read_date = #{date}
  1701. limit #{limit}
  1702. </select>
  1703. <select id="queryMeterReadData" resultType="com.bz.smart_city.dto.MeterReadDataDTO">
  1704. SELECT
  1705. read_date as meter_read_date,
  1706. device_no,
  1707. meter_no as electronic_no,
  1708. read_data as meter_read_data,
  1709. read_time as meter_read_time
  1710. FROM
  1711. sc_meter_read_record
  1712. WHERE
  1713. read_status = 2
  1714. AND read_date = #{meterReadDate}
  1715. <if test="deviceNo != null and deviceNo != ''">
  1716. and device_no = #{deviceNo}
  1717. </if>
  1718. <if test="electronicNo != null and electronicNo != ''">
  1719. and meter_no = #{electronicNo}
  1720. </if>
  1721. <if test="custId != null">
  1722. and customer_id = #{custId}
  1723. </if>
  1724. </select>
  1725. <update id="updateHitoryData">
  1726. UPDATE sc_meter_read_record
  1727. <set>
  1728. <if test="meterReadRecord.sysId != null"> sys_id= #{meterReadRecord.sysId,jdbcType=INTEGER},</if>
  1729. </set>
  1730. where device_id= #{meterReadRecord.deviceId,jdbcType=BIGINT}
  1731. </update>
  1732. <select id="findSyncMeterRecord" resultMap="BaseResultMap">
  1733. select device_id,meter_file_no,read_data,read_time from sc_meter_read_record
  1734. where read_date=#{readTime} and read_data is not null
  1735. and device_id in
  1736. <foreach collection="deviceIds" item="item" separator="," open="(" close=")">
  1737. #{item}
  1738. </foreach>
  1739. </select>
  1740. <select id="findMeterLastReadRecord" resultMap="BaseResultMap">
  1741. select
  1742. <include refid="Base_Column_List"></include>
  1743. from
  1744. sc_meter_read_record
  1745. where device_id = #{deviceId,jdbcType=BIGINT}
  1746. and read_status = 2
  1747. and status = 1
  1748. and read_date = ( SELECT max( read_date ) FROM sc_meter_read_record WHERE device_id = #{deviceId,jdbcType=BIGINT} and read_status = 2)
  1749. limit 1
  1750. </select>
  1751. <select id="getReadingMeter" resultType="com.bz.smart_city.dto.RequestMaterInfo">
  1752. select
  1753. meter_file_no as ciid,
  1754. meter_no as miid,
  1755. read_data as mrecode,
  1756. read_time as mrrdate,
  1757. now() as mrinputdate,
  1758. '' as mrinputper,
  1759. if(read_status = 2,'Y','N') as mrreadok,
  1760. 1 as mrface
  1761. from sc_meter_read_record r
  1762. where status = 1
  1763. and customer_id = #{customerId} and read_date = #{date}
  1764. <if test ="meterNo != null">
  1765. and meter_no = #{meterNo}
  1766. </if>
  1767. </select>
  1768. <select id="findById" resultMap="BaseResultMap">
  1769. select id,device_id,concentrator_id,collector_id,building_id,read_status from sc_meter_read_record
  1770. where status = 1
  1771. and id in <foreach collection="ids" item="item" open="(" separator="," close=")">#{item}</foreach>
  1772. </select>
  1773. </mapper>