MeterReadRecordMapper.xml 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869
  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. </select>
  875. <select id="queryUnReadDeviceListWithNew" resultType="com.bz.smart_city.dto.DeviceDto">
  876. SELECT
  877. d.site_id as siteId,
  878. d.customer_id as customerId,
  879. d.sys_id as sysId,
  880. d.id as id,
  881. d.device_type as deviceType,
  882. d.building_id as buildingId,
  883. co.id as community,
  884. p.id as province,
  885. c.id as city,
  886. r.id as region,
  887. cu.customer_name as customerName,
  888. b.`name`as buildingName,
  889. co.`name`as communityName,
  890. col.collector_no as collectorName,
  891. con.serial_number as concentratorName,
  892. d.water_meter_no as waterMeterNo,
  893. d.water_meter_file_no as waterMeterFileNo,
  894. d.device_no as deviceNo,
  895. d.device_status as deviceStatus,
  896. d.floor as floor,
  897. d.loc_desc as locDesc,
  898. d.last_receive_time as lastReceiveTime
  899. FROM
  900. sc_device d
  901. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  902. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  903. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  904. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  905. LEFT JOIN sc_area p ON ( b.province = p.id )
  906. LEFT JOIN sc_area c ON ( b.city = c.id )
  907. LEFT JOIN sc_area r ON ( b.region = r.id )
  908. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  909. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  910. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  911. where d.status = 1
  912. <if test = "param.buildingId != null and param.buildingId != 0">
  913. and d.building_id = #{param.buildingId}
  914. </if>
  915. <if test="param.siteId != null and param.siteId != 0">
  916. and d.site_id = #{param.siteId}
  917. </if>
  918. <if test = "param.channelId != null and param.channelId != 0">
  919. and d.sys_id = #{param.channelId}
  920. </if>
  921. <if test="param.custormerId != null and param.custormerId != 0">
  922. and d.customer_id = #{param.custormerId}
  923. </if>
  924. and ( d.id IN (
  925. SELECT
  926. tmp.device_id
  927. FROM
  928. (
  929. SELECT
  930. site_id,
  931. sys_id,
  932. building_id,
  933. device_id
  934. FROM
  935. sc_meter_read_record
  936. WHERE
  937. <if test = "param.statDay != null and param.statDay != 0">
  938. read_date = #{param.statDay}
  939. </if>
  940. <if test = "param.buildingId != null and param.buildingId != 0">
  941. AND building_id = #{param.buildingId}
  942. </if>
  943. AND read_status = 1
  944. ) tmp
  945. ) or d.device_status = 5)
  946. </select>
  947. <select id="queryUnReadDeviceList" resultType="com.bz.smart_city.dto.DeviceDto">
  948. SELECT
  949. d.site_id as siteId,
  950. d.customer_id as customerId,
  951. d.sys_id as sysId,
  952. d.id as id,
  953. d.device_type as deviceType,
  954. d.building_id as buildingId,
  955. co.id as community,
  956. p.id as province,
  957. c.id as city,
  958. r.id as region,
  959. cu.customer_name as customerName,
  960. b.`name`as buildingName,
  961. co.`name`as communityName,
  962. col.collector_no as collectorName,
  963. con.serial_number as concentratorName,
  964. d.water_meter_no as waterMeterNo,
  965. d.water_meter_file_no as waterMeterFileNo,
  966. d.device_no as deviceNo,
  967. d.device_status as deviceStatus,
  968. d.floor as floor,
  969. d.loc_desc as locDesc,
  970. d.last_receive_time as lastReceiveTime
  971. FROM
  972. sc_device d
  973. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  974. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  975. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  976. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  977. LEFT JOIN sc_area p ON ( b.province = p.id )
  978. LEFT JOIN sc_area c ON ( b.city = c.id )
  979. LEFT JOIN sc_area r ON ( b.region = r.id )
  980. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  981. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  982. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  983. where d.status = 1
  984. <if test = "param.buildingId != null and param.buildingId != 0">
  985. and d.building_id = #{param.buildingId}
  986. </if>
  987. <if test="param.siteId != null and param.siteId != 0">
  988. and d.site_id = #{param.siteId}
  989. </if>
  990. <if test = "param.channelId != null and param.channelId != 0">
  991. and d.sys_id = #{param.channelId}
  992. </if>
  993. <if test="param.custormerId != null and param.custormerId != 0">
  994. and d.customer_id = #{param.custormerId}
  995. </if>
  996. and d.id IN (
  997. SELECT
  998. tmp.device_id
  999. FROM
  1000. (
  1001. SELECT
  1002. site_id,
  1003. channel_id,
  1004. building_id,
  1005. device_id
  1006. FROM
  1007. sc_stat_meter_unread_device_by_building
  1008. WHERE
  1009. <if test = "param.statDay != null and param.statDay != 0">
  1010. stat_day = #{param.statDay}
  1011. </if>
  1012. <if test = "param.buildingId != null and param.buildingId != 0">
  1013. AND building_id = #{param.buildingId}
  1014. </if>
  1015. ) tmp
  1016. )
  1017. </select>
  1018. <select id="queryUnReadDeviceListV2" resultType="Long">
  1019. select
  1020. device_id
  1021. from
  1022. ${tableName}
  1023. where 1=1
  1024. <if test="param.custormerId != null and param.custormerId != 0">
  1025. and customer_id = #{param.custormerId}
  1026. </if>
  1027. <if test = "param.channelId != null and param.channelId != 0">
  1028. and channel_id = #{param.channelId}
  1029. </if>
  1030. <if test = "param.statDay != null and param.statDay != 0">
  1031. and stat_day = #{param.statDay}
  1032. </if>
  1033. <if test = "param.buildingId != null and param.buildingId != 0">
  1034. AND building_id = #{param.buildingId}
  1035. </if>
  1036. </select>
  1037. <!--
  1038. <select id="queryUnReadDeviceListV2" resultType="com.bz.smart_city.dto.DeviceDto">
  1039. SELECT
  1040. d.site_id as siteId,
  1041. d.customer_id as customerId,
  1042. d.sys_id as sysId,
  1043. d.id as id,
  1044. d.device_type as deviceType,
  1045. d.building_id as buildingId,
  1046. co.id as community,
  1047. cu.customer_name as customerName,
  1048. b.`name`as buildingName,
  1049. co.`name`as communityName,
  1050. col.collector_no as collectorName,
  1051. con.serial_number as concentratorName,
  1052. d.water_meter_no as waterMeterNo,
  1053. d.water_meter_file_no as waterMeterFileNo,
  1054. d.device_no as deviceNo,
  1055. d.device_status as deviceStatus,
  1056. d.floor as floor,
  1057. d.loc_desc as locDesc,
  1058. d.last_receive_time as lastReceiveTime
  1059. FROM ${tableName} as t1
  1060. LEFT JOIN sc_device d on(t1.device_id = d.id)
  1061. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1062. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1063. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1064. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1065. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1066. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1067. where d.status = 1
  1068. <if test = "param.buildingId != null and param.buildingId != 0">
  1069. and d.building_id = #{param.buildingId}
  1070. </if>
  1071. <if test="param.siteId != null and param.siteId != 0">
  1072. and d.site_id = #{param.siteId}
  1073. </if>
  1074. <if test = "param.channelId != null and param.channelId != 0">
  1075. and d.sys_id = #{param.channelId}
  1076. </if>
  1077. <if test="param.custormerId != null and param.custormerId != 0">
  1078. and d.customer_id = #{param.custormerId}
  1079. </if>
  1080. <if test = "param.statDay != null and param.statDay != 0">
  1081. and t1.stat_day = #{param.statDay}
  1082. </if>
  1083. <if test = "param.buildingId != null and param.buildingId != 0">
  1084. AND t1.building_id = #{param.buildingId}
  1085. </if>
  1086. </select>
  1087. -->
  1088. <select id="queryUnReadDeviceListForToday_COUNT" resultType="Long">
  1089. SELECT
  1090. count(device_id)
  1091. FROM sc_meter_read_record
  1092. WHERE read_status = 1
  1093. <if test = "param.buildingId != null">
  1094. and building_id = #{param.buildingId}
  1095. </if>
  1096. <if test="param.channelId != null">
  1097. and sys_id = #{param.channelId}
  1098. </if>
  1099. <if test="param.custormerId != null ">
  1100. and customer_id = #{param.custormerId}
  1101. </if>
  1102. AND read_date = DATE_FORMAT( now( ), '%Y%m%d' )
  1103. </select>
  1104. <select id="queryUnReadDeviceListForToday" resultType="Long">
  1105. SELECT
  1106. device_id
  1107. FROM sc_meter_read_record
  1108. WHERE read_status = 1
  1109. <if test = "param.buildingId != null">
  1110. and building_id = #{param.buildingId}
  1111. </if>
  1112. <if test="param.channelId != null">
  1113. and sys_id = #{param.channelId}
  1114. </if>
  1115. <if test="param.custormerId != null ">
  1116. and customer_id = #{param.custormerId}
  1117. </if>
  1118. AND read_date = DATE_FORMAT( now( ), '%Y%m%d' )
  1119. </select>
  1120. <select id="queryUnReadDeviceListByIds" resultType="com.bz.smart_city.dto.DeviceDto">
  1121. SELECT
  1122. d.site_id as siteId,
  1123. d.customer_id as customerId,
  1124. d.sys_id as sysId,
  1125. d.id as id,
  1126. d.device_type as deviceType,
  1127. d.building_id as buildingId,
  1128. col.collector_no as collectorName,
  1129. con.serial_number as concentratorName,
  1130. d.water_meter_no as waterMeterNo,
  1131. d.water_meter_file_no as waterMeterFileNo,
  1132. d.device_no as deviceNo,
  1133. d.device_status as deviceStatus,
  1134. d.floor as floor,
  1135. d.loc_desc as locDesc,
  1136. d.last_receive_time as lastReceiveTime
  1137. from
  1138. sc_device d
  1139. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1140. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1141. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1142. where d.status = 1
  1143. <if test="param != null">
  1144. and d.id in <foreach collection="param" item="deviceId" open="(" separator="," close=")"> #{deviceId}</foreach>
  1145. </if>
  1146. </select>
  1147. <!--
  1148. <select id="queryUnReadDeviceListForToday" resultType="com.bz.smart_city.dto.DeviceDto">
  1149. SELECT
  1150. d.site_id as siteId,
  1151. d.customer_id as customerId,
  1152. d.sys_id as sysId,
  1153. d.id as id,
  1154. d.device_type as deviceType,
  1155. d.building_id as buildingId,
  1156. col.collector_no as collectorName,
  1157. con.serial_number as concentratorName,
  1158. d.water_meter_no as waterMeterNo,
  1159. d.water_meter_file_no as waterMeterFileNo,
  1160. d.device_no as deviceNo,
  1161. d.device_status as deviceStatus,
  1162. d.floor as floor,
  1163. d.loc_desc as locDesc,
  1164. d.last_receive_time as lastReceiveTime
  1165. FROM (
  1166. SELECT
  1167. device_id
  1168. FROM sc_meter_read_record
  1169. WHERE read_status = 1
  1170. <if test = "param.buildingId != null">
  1171. and building_id = #{param.buildingId}
  1172. </if>
  1173. <if test="param.channelId != null">
  1174. and sys_id = #{param.channelId}
  1175. </if>
  1176. <if test="param.custormerId != null ">
  1177. and customer_id = #{param.custormerId}
  1178. </if>
  1179. AND read_date = DATE_FORMAT( now( ), '%Y%m%d' )
  1180. ) t1
  1181. LEFT JOIN sc_device d on (t1.device_id = d.id)
  1182. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1183. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1184. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1185. where d.status = 1
  1186. </select>
  1187. -->
  1188. <select id="queryUnReadDeviceListFor7Day" resultType="com.bz.smart_city.dto.DeviceDto">
  1189. SELECT
  1190. d.site_id as siteId,
  1191. d.customer_id as customerId,
  1192. d.sys_id as sysId,
  1193. d.id as id,
  1194. d.device_type as deviceType,
  1195. d.building_id as buildingId,
  1196. co.id as community,
  1197. p.id as province,
  1198. c.id as city,
  1199. r.id as region,
  1200. cu.customer_name as customerName,
  1201. b.`name`as buildingName,
  1202. co.`name`as communityName,
  1203. col.collector_no as collectorName,
  1204. con.serial_number as concentratorName,
  1205. d.water_meter_no as waterMeterNo,
  1206. d.water_meter_file_no as waterMeterFileNo,
  1207. d.device_no as deviceNo,
  1208. d.device_status as deviceStatus,
  1209. d.floor as floor,
  1210. d.loc_desc as locDesc,
  1211. d.last_receive_time as lastReceiveTime
  1212. FROM
  1213. sc_device d
  1214. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  1215. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1216. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1217. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1218. LEFT JOIN sc_area p ON ( b.province = p.id )
  1219. LEFT JOIN sc_area c ON ( b.city = c.id )
  1220. LEFT JOIN sc_area r ON ( b.region = r.id )
  1221. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1222. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1223. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1224. where d.status = 1
  1225. <if test = "param.buildingId != null and param.buildingId != 0">
  1226. and d.building_id = #{param.buildingId}
  1227. </if>
  1228. <if test="param.siteId != null and param.siteId != 0">
  1229. and d.site_id = #{param.siteId}
  1230. </if>
  1231. <if test = "param.channelId != null and param.channelId != 0">
  1232. and d.sys_id = #{param.channelId}
  1233. </if>
  1234. <if test="param.custormerId != null and param.custormerId != 0">
  1235. and d.customer_id = #{param.custormerId}
  1236. </if>
  1237. and d.id IN (
  1238. SELECT
  1239. tmp.device_id
  1240. FROM
  1241. (
  1242. SELECT
  1243. site_id,
  1244. channel_id,
  1245. building_id,
  1246. device_id
  1247. FROM
  1248. sc_stat_meter_unread_device_by_building_7day
  1249. WHERE
  1250. <if test = "param.statDay != null and param.statDay != 0">
  1251. stat_day = #{param.statDay}
  1252. </if>
  1253. <if test = "param.buildingId != null and param.buildingId != 0">
  1254. AND building_id = #{param.buildingId}
  1255. </if>
  1256. ) tmp
  1257. )
  1258. </select>
  1259. <select id="queryUnReadDeviceListFor7DayWithNew" resultType="com.bz.smart_city.dto.DeviceDto">
  1260. SELECT
  1261. d.site_id as siteId,
  1262. d.customer_id as customerId,
  1263. d.sys_id as sysId,
  1264. d.id as id,
  1265. d.device_type as deviceType,
  1266. d.building_id as buildingId,
  1267. co.id as community,
  1268. p.id as province,
  1269. c.id as city,
  1270. r.id as region,
  1271. cu.customer_name as customerName,
  1272. b.`name`as buildingName,
  1273. co.`name`as communityName,
  1274. col.collector_no as collectorName,
  1275. con.serial_number as concentratorName,
  1276. d.water_meter_no as waterMeterNo,
  1277. d.water_meter_file_no as waterMeterFileNo,
  1278. d.device_no as deviceNo,
  1279. d.device_status as deviceStatus,
  1280. d.floor as floor,
  1281. d.loc_desc as locDesc,
  1282. d.last_receive_time as lastReceiveTime
  1283. FROM
  1284. sc_device d
  1285. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  1286. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1287. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1288. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1289. LEFT JOIN sc_area p ON ( b.province = p.id )
  1290. LEFT JOIN sc_area c ON ( b.city = c.id )
  1291. LEFT JOIN sc_area r ON ( b.region = r.id )
  1292. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1293. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1294. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1295. where d.status = 1
  1296. <if test = "param.buildingId != null and param.buildingId != 0">
  1297. and d.building_id = #{param.buildingId}
  1298. </if>
  1299. <if test="param.siteId != null and param.siteId != 0">
  1300. and d.site_id = #{param.siteId}
  1301. </if>
  1302. <if test = "param.channelId != null and param.channelId != 0">
  1303. and d.sys_id = #{param.channelId}
  1304. </if>
  1305. <if test="param.custormerId != null and param.custormerId != 0">
  1306. and d.customer_id = #{param.custormerId}
  1307. </if>
  1308. and ( d.id IN (
  1309. SELECT
  1310. tmp.device_id
  1311. FROM
  1312. (
  1313. SELECT
  1314. site_id,
  1315. channel_id,
  1316. building_id,
  1317. device_id
  1318. FROM
  1319. sc_stat_meter_unread_device_by_building_7day
  1320. WHERE
  1321. <if test = "param.statDay != null and param.statDay != 0">
  1322. stat_day = #{param.statDay}
  1323. </if>
  1324. <if test = "param.buildingId != null and param.buildingId != 0">
  1325. AND building_id = #{param.buildingId}
  1326. </if>
  1327. ) tmp
  1328. ) or d.device_status = 5 )
  1329. </select>
  1330. <select id="queryUnReadDeviceListFor15Day" resultType="com.bz.smart_city.dto.DeviceDto">
  1331. SELECT
  1332. d.site_id as siteId,
  1333. d.customer_id as customerId,
  1334. d.sys_id as sysId,
  1335. d.id as id,
  1336. d.device_type as deviceType,
  1337. d.building_id as buildingId,
  1338. co.id as community,
  1339. p.id as province,
  1340. c.id as city,
  1341. r.id as region,
  1342. cu.customer_name as customerName,
  1343. b.`name`as buildingName,
  1344. co.`name`as communityName,
  1345. col.collector_no as collectorName,
  1346. con.serial_number as concentratorName,
  1347. d.water_meter_no as waterMeterNo,
  1348. d.water_meter_file_no as waterMeterFileNo,
  1349. d.device_no as deviceNo,
  1350. d.device_status as deviceStatus,
  1351. d.floor as floor,
  1352. d.loc_desc as locDesc,
  1353. d.last_receive_time as lastReceiveTime
  1354. FROM
  1355. sc_device d
  1356. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  1357. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1358. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1359. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1360. LEFT JOIN sc_area p ON ( b.province = p.id )
  1361. LEFT JOIN sc_area c ON ( b.city = c.id )
  1362. LEFT JOIN sc_area r ON ( b.region = r.id )
  1363. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1364. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1365. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1366. where d.status = 1
  1367. <if test = "param.buildingId != null and param.buildingId != 0">
  1368. and d.building_id = #{param.buildingId}
  1369. </if>
  1370. <if test="param.siteId != null and param.siteId != 0">
  1371. and d.site_id = #{param.siteId}
  1372. </if>
  1373. <if test = "param.channelId != null and param.channelId != 0">
  1374. and d.sys_id = #{param.channelId}
  1375. </if>
  1376. <if test="param.custormerId != null and param.custormerId != 0">
  1377. and d.customer_id = #{param.custormerId}
  1378. </if>
  1379. and d.id IN (
  1380. SELECT
  1381. tmp.device_id
  1382. FROM
  1383. (
  1384. SELECT
  1385. site_id,
  1386. channel_id,
  1387. building_id,
  1388. device_id
  1389. FROM
  1390. sc_stat_meter_unread_device_by_building_15day
  1391. WHERE
  1392. <if test = "param.statDay != null and param.statDay != 0">
  1393. stat_day = #{param.statDay}
  1394. </if>
  1395. <if test = "param.buildingId != null and param.buildingId != 0">
  1396. AND building_id = #{param.buildingId}
  1397. </if>
  1398. ) tmp
  1399. )
  1400. </select>
  1401. <select id="queryUnReadDeviceListForMonth" resultType="com.bz.smart_city.dto.DeviceDto">
  1402. SELECT
  1403. d.site_id as siteId,
  1404. d.customer_id as customerId,
  1405. d.sys_id as sysId,
  1406. d.id as id,
  1407. d.device_type as deviceType,
  1408. d.building_id as buildingId,
  1409. co.id as community,
  1410. p.id as province,
  1411. c.id as city,
  1412. r.id as region,
  1413. cu.customer_name as customerName,
  1414. b.`name`as buildingName,
  1415. co.`name`as communityName,
  1416. col.collector_no as collectorName,
  1417. con.serial_number as concentratorName,
  1418. d.water_meter_no as waterMeterNo,
  1419. d.water_meter_file_no as waterMeterFileNo,
  1420. d.device_no as deviceNo,
  1421. d.device_status as deviceStatus,
  1422. d.floor as floor,
  1423. d.loc_desc as locDesc,
  1424. d.last_receive_time as lastReceiveTime
  1425. FROM
  1426. sc_device d
  1427. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  1428. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1429. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1430. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1431. LEFT JOIN sc_area p ON ( b.province = p.id )
  1432. LEFT JOIN sc_area c ON ( b.city = c.id )
  1433. LEFT JOIN sc_area r ON ( b.region = r.id )
  1434. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1435. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1436. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1437. where d.status = 1
  1438. <if test = "param.buildingId != null and param.buildingId != 0">
  1439. and d.building_id = #{param.buildingId}
  1440. </if>
  1441. <if test="param.siteId != null and param.siteId != 0">
  1442. and d.site_id = #{param.siteId}
  1443. </if>
  1444. <if test = "param.channelId != null and param.channelId != 0">
  1445. and d.sys_id = #{param.channelId}
  1446. </if>
  1447. <if test="param.custormerId != null and param.custormerId != 0">
  1448. and d.customer_id = #{param.custormerId}
  1449. </if>
  1450. and d.id IN (
  1451. SELECT
  1452. tmp.device_id
  1453. FROM
  1454. (
  1455. SELECT
  1456. site_id,
  1457. channel_id,
  1458. building_id,
  1459. device_id
  1460. FROM
  1461. sc_stat_meter_unread_device_by_building_month
  1462. WHERE
  1463. <if test = "param.statDay != null and param.statDay != 0">
  1464. stat_day = #{param.statDay}
  1465. </if>
  1466. <if test = "param.buildingId != null and param.buildingId != 0">
  1467. AND building_id = #{param.buildingId}
  1468. </if>
  1469. ) tmp
  1470. )
  1471. </select>
  1472. <select id="queryUnReadDeviceListFor15DayWithNew" resultType="com.bz.smart_city.dto.DeviceDto">
  1473. SELECT
  1474. d.site_id as siteId,
  1475. d.customer_id as customerId,
  1476. d.sys_id as sysId,
  1477. d.id as id,
  1478. d.device_type as deviceType,
  1479. d.building_id as buildingId,
  1480. co.id as community,
  1481. p.id as province,
  1482. c.id as city,
  1483. r.id as region,
  1484. cu.customer_name as customerName,
  1485. b.`name`as buildingName,
  1486. co.`name`as communityName,
  1487. col.collector_no as collectorName,
  1488. con.serial_number as concentratorName,
  1489. d.water_meter_no as waterMeterNo,
  1490. d.water_meter_file_no as waterMeterFileNo,
  1491. d.device_no as deviceNo,
  1492. d.device_status as deviceStatus,
  1493. d.floor as floor,
  1494. d.loc_desc as locDesc,
  1495. d.last_receive_time as lastReceiveTime
  1496. FROM
  1497. sc_device d
  1498. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  1499. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1500. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1501. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1502. LEFT JOIN sc_area p ON ( b.province = p.id )
  1503. LEFT JOIN sc_area c ON ( b.city = c.id )
  1504. LEFT JOIN sc_area r ON ( b.region = r.id )
  1505. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1506. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1507. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1508. where d.status = 1
  1509. <if test = "param.buildingId != null and param.buildingId != 0">
  1510. and d.building_id = #{param.buildingId}
  1511. </if>
  1512. <if test="param.siteId != null and param.siteId != 0">
  1513. and d.site_id = #{param.siteId}
  1514. </if>
  1515. <if test = "param.channelId != null and param.channelId != 0">
  1516. and d.sys_id = #{param.channelId}
  1517. </if>
  1518. <if test="param.custormerId != null and param.custormerId != 0">
  1519. and d.customer_id = #{param.custormerId}
  1520. </if>
  1521. and (d.id IN (
  1522. SELECT
  1523. tmp.device_id
  1524. FROM
  1525. (
  1526. SELECT
  1527. site_id,
  1528. channel_id,
  1529. building_id,
  1530. device_id
  1531. FROM
  1532. sc_stat_meter_unread_device_by_building_15day
  1533. WHERE
  1534. <if test = "param.statDay != null and param.statDay != 0">
  1535. stat_day = #{param.statDay}
  1536. </if>
  1537. <if test = "param.buildingId != null and param.buildingId != 0">
  1538. AND building_id = #{param.buildingId}
  1539. </if>
  1540. ) tmp
  1541. ) or d.device_status = 5)
  1542. </select>
  1543. <select id="queryDeviceMeterReadRecordWithCondtion" resultType="com.bz.smart_city.entity.MeterReadRecord">
  1544. select
  1545. <include refid="Base_Column_List" />
  1546. from
  1547. sc_meter_read_record
  1548. where read_status = 2
  1549. and device_id = #{param.deviceId}
  1550. <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
  1551. <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
  1552. order by read_date desc
  1553. </select>
  1554. <select id="getSummary" resultType="com.bz.smart_city.dto.WaterConsumptionSummaryDto">
  1555. select
  1556. ifnull(sum(result.water_consumption), 0) as total_water_consumption,
  1557. count(result.device_id) as total_device_count
  1558. from (
  1559. select
  1560. smrr.device_id as device_id,
  1561. smrr.building_id as building_id,
  1562. ifnull(sum(smrr.last_cost), 0) as water_consumption
  1563. from
  1564. sc_meter_read_record smrr
  1565. where smrr.status = 1
  1566. <if test="param.siteId != null"> and smrr.site_id = #{param.siteId}</if>
  1567. <if test="param.custormerId != null"> and smrr.customer_id = #{param.custormerId} </if>
  1568. <if test="param.buildingIds != null and param.buildingIds.size() != 0">
  1569. and smrr.building_id in <foreach collection="param.buildingIds" item="item" open="(" separator="," close=")"> #{item}</foreach>
  1570. </if>
  1571. <if test="param.startDate != null"> and smrr.read_date <![CDATA[ >= ]]> #{param.startDate} </if>
  1572. <if test="param.endDate != null"> and smrr.read_date <![CDATA[ <= ]]> #{param.endDate} </if>
  1573. <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>
  1574. group by
  1575. smrr.device_id, smrr.building_id
  1576. ) result
  1577. left join sc_building sb on (result.building_id = sb.id and sb.status = 1)
  1578. <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>
  1579. where 1 = 1
  1580. <if test="param.programItems != null and param.programItems.size() != 0"> and
  1581. <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  1582. sdd.${item.dimensionCode} = #{item.dimensionValue}
  1583. </foreach>
  1584. </if>
  1585. <if test="param.provinces != null and param.provinces.size() != 0">
  1586. and sb.province in <foreach collection="param.provinces" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1587. </if>
  1588. <if test="param.cities != null and param.cities.size() != 0">
  1589. and sb.city in <foreach collection="param.cities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1590. </if>
  1591. <if test="param.regions != null and param.regions.size() != 0">
  1592. and sb.region in <foreach collection="param.regions" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1593. </if>
  1594. <if test="param.communities != null and param.communities.size() != 0">
  1595. and sb.community in <foreach collection="param.communities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1596. </if>
  1597. <if test="param.beginRate != null"> and result.water_consumption <![CDATA[ >= ]]> #{param.beginRate} </if>
  1598. <if test="param.endRate != null"> and result.water_consumption <![CDATA[ <= ]]> #{param.endRate} </if>
  1599. </select>
  1600. <select id="getList" resultType="com.bz.smart_city.dto.WaterConsumptionDto">
  1601. select
  1602. list.meter_no as meter_no,
  1603. list.device_type as device_type,
  1604. list.customer as customer,
  1605. list.district as district,
  1606. list.community as community,
  1607. list.building as building,
  1608. list.location as location,
  1609. list.water_consumption as water_consumption
  1610. from (
  1611. select
  1612. smrr.meter_no as meter_no,
  1613. sdt.equipment_type as device_type,
  1614. scu.customer_name as customer,
  1615. replace(replace(sa.manger_name, "中国", ""), ",", "") as district,
  1616. sco.name as community,
  1617. sb.name as building,
  1618. smrr.location as location,
  1619. ifnull(sum(smrr.last_cost), 0) as water_consumption
  1620. from
  1621. sc_meter_read_record smrr
  1622. left join sc_device_type sdt on (smrr.device_type_id = sdt.id and sdt.status = 1)
  1623. left join sc_customer scu on (smrr.customer_id = scu.id and scu.status = 1)
  1624. left join sc_building sb on (smrr.building_id = sb.id and sb.status = 1)
  1625. left join sc_area sa on (sa.id = sb.region)
  1626. left join sc_community sco on (sb.community = sco.id and sco.id)
  1627. <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>
  1628. where
  1629. smrr.status = 1
  1630. <if test="param.siteId != null"> and smrr.site_id = #{param.siteId} </if>
  1631. <if test="param.programItems != null and param.programItems.size() != 0"> and
  1632. <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  1633. sdd.${item.dimensionCode} = #{item.dimensionValue}
  1634. </foreach>
  1635. </if>
  1636. <if test="param.custormerId != null"> and smrr.customer_id = #{param.custormerId} </if>
  1637. <if test="param.provinces != null and param.provinces.size() != 0">
  1638. and sb.province in <foreach collection="param.provinces" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1639. </if>
  1640. <if test="param.cities != null and param.cities.size() != 0">
  1641. and sb.city in <foreach collection="param.cities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1642. </if>
  1643. <if test="param.regions != null and param.regions.size() != 0">
  1644. and sb.region in <foreach collection="param.regions" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1645. </if>
  1646. <if test="param.communities != null and param.communities.size() != 0">
  1647. and sb.community in <foreach collection="param.communities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1648. </if>
  1649. <if test="param.buildingIds != null and param.buildingIds.size() != 0">
  1650. and smrr.building_id in <foreach collection="param.buildingIds" item="item" open="(" separator="," close=")"> #{item}</foreach>
  1651. </if>
  1652. <if test="param.startDate != null"> and smrr.read_date <![CDATA[ >= ]]> #{param.startDate} </if>
  1653. <if test="param.endDate != null"> and smrr.read_date <![CDATA[ <= ]]> #{param.endDate} </if>
  1654. <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>
  1655. group by
  1656. smrr.meter_no, sdt.equipment_type, scu.customer_name, district, sco.name, sb.name, smrr.location
  1657. ) list
  1658. where 1 = 1
  1659. <if test="param.beginRate != null"> and list.water_consumption <![CDATA[ >= ]]> #{param.beginRate} </if>
  1660. <if test="param.endRate != null"> and list.water_consumption <![CDATA[ <= ]]> #{param.endRate} </if>
  1661. <if test="param.sortOrder != null"> order by list.water_consumption ${param.sortOrder} </if>
  1662. </select>
  1663. <select id="getList_COUNT" resultType="Long">
  1664. select
  1665. count(result.device_id)
  1666. from (
  1667. select
  1668. smrr.device_id as device_id,
  1669. smrr.building_id as building_id,
  1670. ifnull(sum(smrr.last_cost), 0) as water_consumption
  1671. from
  1672. sc_meter_read_record smrr
  1673. where smrr.status = 1
  1674. <if test="param.siteId != null"> and smrr.site_id = #{param.siteId}</if>
  1675. <if test="param.custormerId != null"> and smrr.customer_id = #{param.custormerId} </if>
  1676. <if test="param.buildingIds != null and param.buildingIds.size() != 0">
  1677. and smrr.building_id in <foreach collection="param.buildingIds" item="item" open="(" separator="," close=")"> #{item}</foreach>
  1678. </if>
  1679. <if test="param.startDate != null"> and smrr.read_date <![CDATA[ >= ]]> #{param.startDate} </if>
  1680. <if test="param.endDate != null"> and smrr.read_date <![CDATA[ <= ]]> #{param.endDate} </if>
  1681. group by
  1682. smrr.device_id, smrr.building_id
  1683. ) result
  1684. left join sc_building sb on (result.building_id = sb.id and sb.status = 1)
  1685. <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>
  1686. where 1 = 1
  1687. <if test="param.programItems != null and param.programItems.size() != 0"> and
  1688. <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  1689. sdd.${item.dimensionCode} = #{item.dimensionValue}
  1690. </foreach>
  1691. </if>
  1692. <if test="param.provinces != null and param.provinces.size() != 0">
  1693. and sb.province in <foreach collection="param.provinces" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1694. </if>
  1695. <if test="param.cities != null and param.cities.size() != 0">
  1696. and sb.city in <foreach collection="param.cities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1697. </if>
  1698. <if test="param.regions != null and param.regions.size() != 0">
  1699. and sb.region in <foreach collection="param.regions" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1700. </if>
  1701. <if test="param.communities != null and param.communities.size() != 0">
  1702. and sb.community in <foreach collection="param.communities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1703. </if>
  1704. <if test="param.beginRate != null"> and result.water_consumption <![CDATA[ >= ]]> #{param.beginRate} </if>
  1705. <if test="param.endRate != null"> and result.water_consumption <![CDATA[ <= ]]> #{param.endRate} </if>
  1706. </select>
  1707. <select id="getLastDayData" resultMap="BaseResultMap">
  1708. select
  1709. <include refid="Base_Column_List" />
  1710. from
  1711. sc_meter_read_record
  1712. where
  1713. status = 1 and device_id = #{deviceId} and read_date = #{lastDate}
  1714. </select>
  1715. <select id="getLastDayDataV2" resultMap="BaseResultMap">
  1716. select
  1717. <include refid="Base_Column_List" />
  1718. from
  1719. sc_meter_read_record
  1720. where
  1721. status = 1 and device_id = #{deviceId} and read_date <![CDATA[ < ]]> #{lastDate} order by read_date desc limit 1
  1722. </select>
  1723. <select id="getAllDeviceId" resultType="Long">
  1724. select distinct device_id
  1725. from sc_meter_read_record
  1726. where status = 1 and sys_id = -99
  1727. <if test="startDate != null"> and read_date <![CDATA[ >= ]]> #{startDate} </if>
  1728. order by device_id asc
  1729. </select>
  1730. <select id="getMeterReadRecordByDeviceId" resultMap="BaseResultMap">
  1731. select
  1732. <include refid="Base_Column_List" />
  1733. from sc_meter_read_record
  1734. where status = 1
  1735. <if test="deviceId != null"> and device_id = #{deviceId} </if>
  1736. <if test="startDate != null"> and read_date <![CDATA[ >= ]]> #{startDate} </if>
  1737. order by read_date asc
  1738. </select>
  1739. <update id="batchUpdate" parameterType="list">
  1740. UPDATE sc_meter_read_record
  1741. <trim prefix="set" suffixOverrides=",">
  1742. <trim prefix="last_valid =case" suffix="end,">
  1743. <foreach collection="list" item="item">
  1744. <if test="item.lastValid!=null">
  1745. when id=#{item.id} then #{item.lastValid}
  1746. </if>
  1747. </foreach>
  1748. </trim>
  1749. <trim prefix="last_cost =case" suffix="end,">
  1750. <foreach collection="list" item="item">
  1751. <if test="item.lastCost!=null">
  1752. when id=#{item.id} then #{item.lastCost}
  1753. </if>
  1754. </foreach>
  1755. </trim>
  1756. </trim>
  1757. <where>
  1758. id in <foreach collection="list" item="item" open="(" separator="," close=")">#{item.id}</foreach>
  1759. </where>
  1760. </update>
  1761. <select id="getDeviceIdOnDate" resultType="Long">
  1762. select
  1763. device_id
  1764. from sc_meter_read_record
  1765. where status = 1 and read_date = #{date}
  1766. limit #{limit}
  1767. </select>
  1768. <select id="queryMeterReadData" resultType="com.bz.smart_city.dto.MeterReadDataDTO">
  1769. SELECT
  1770. read_date as meter_read_date,
  1771. device_no,
  1772. meter_no as electronic_no,
  1773. read_data as meter_read_data,
  1774. read_time as meter_read_time
  1775. FROM
  1776. sc_meter_read_record
  1777. WHERE
  1778. read_status = 2
  1779. AND read_date = #{meterReadDate}
  1780. <if test="deviceNo != null and deviceNo != ''">
  1781. and device_no = #{deviceNo}
  1782. </if>
  1783. <if test="electronicNo != null and electronicNo != ''">
  1784. and meter_no = #{electronicNo}
  1785. </if>
  1786. <if test="custId != null">
  1787. and customer_id = #{custId}
  1788. </if>
  1789. </select>
  1790. <update id="updateHitoryData">
  1791. UPDATE sc_meter_read_record
  1792. <set>
  1793. <if test="meterReadRecord.sysId != null"> sys_id= #{meterReadRecord.sysId,jdbcType=INTEGER},</if>
  1794. </set>
  1795. where device_id= #{meterReadRecord.deviceId,jdbcType=BIGINT}
  1796. </update>
  1797. <select id="findSyncMeterRecord" resultMap="BaseResultMap">
  1798. select device_id,meter_file_no,read_data,read_time from sc_meter_read_record
  1799. where read_date=#{readTime} and read_data is not null
  1800. and device_id in
  1801. <foreach collection="deviceIds" item="item" separator="," open="(" close=")">
  1802. #{item}
  1803. </foreach>
  1804. </select>
  1805. <select id="findMeterLastReadRecord" resultMap="BaseResultMap">
  1806. select
  1807. <include refid="Base_Column_List"></include>
  1808. from
  1809. sc_meter_read_record
  1810. where device_id = #{deviceId,jdbcType=BIGINT}
  1811. and read_status = 2
  1812. and status = 1
  1813. and read_date = ( SELECT max( read_date ) FROM sc_meter_read_record WHERE device_id = #{deviceId,jdbcType=BIGINT} and read_status = 2)
  1814. limit 1
  1815. </select>
  1816. <select id="getReadingMeter" resultType="com.bz.smart_city.dto.RequestMaterInfo">
  1817. select
  1818. meter_file_no as ciid,
  1819. meter_no as miid,
  1820. read_data as mrecode,
  1821. read_time as mrrdate,
  1822. now() as mrinputdate,
  1823. '' as mrinputper,
  1824. if(read_status = 2,'Y','N') as mrreadok,
  1825. 0 as mrface
  1826. from sc_meter_read_record r
  1827. where status = 1
  1828. and customer_id = #{customerId} and read_date = #{date}
  1829. <if test ="meterNo != null">
  1830. and meter_no = #{meterNo}
  1831. </if>
  1832. </select>
  1833. <select id="findById" resultMap="BaseResultMap">
  1834. select id,device_id,concentrator_id,collector_id,building_id,read_status from sc_meter_read_record
  1835. where status = 1
  1836. and id in <foreach collection="ids" item="item" open="(" separator="," close=")">#{item}</foreach>
  1837. </select>
  1838. </mapper>