MeterReadRecordMapper.xml 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686
  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. 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. dm.`name` as factory_name
  788. FROM
  789. sc_meter_read_record m
  790. LEFT JOIN sc_building b ON ( m.building_id = b.id )
  791. left join sc_community com on (com.id = m.community)
  792. left join sc_customer cust on (cust.id = m.customer_id)
  793. left join sc_concentrator con on (con.id = m.concentrator_id)
  794. left join sc_collector col on (col.id = m.collector_id)
  795. left join sc_device_type dt on (dt.id = m.device_type_id)
  796. left join sc_device_manufacturer dm on (dm.id = dt.manufacturer_id)
  797. WHERE m.STATUS = 1
  798. <!-- 数据权限 -->
  799. <if test="param.siteId != null and param.siteId != 0">
  800. and m.site_id = #{param.siteId}
  801. </if>
  802. <if test="param.sites != null and param.sites.size() != 0">
  803. and m.site_id in
  804. <foreach collection="param.sites" item="site" open="(" separator="," close=")">
  805. #{site.id}
  806. </foreach>
  807. </if>
  808. <if test="param.buildingIds != null and param.buildingIds.size() != 0">
  809. and m.building_id in <foreach collection="param.buildingIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  810. </if>
  811. <!--
  812. <if test='param.programItems != null and param.programItems.size() != 0' >
  813. and EXISTS (
  814. select 1 from
  815. (select
  816. distinct df.device_id
  817. FROM sc_device_dim_info df
  818. WHERE 1 = 1
  819. and <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  820. (df.dimension_code = #{item.dimensionCode} and df.dimension_value = #{item.dimensionValue})
  821. </foreach> ) ud WHERE ud.device_id = m.device_id)
  822. </if>
  823. -->
  824. <if test = "param.concentratorCode != null and param.concentratorCode != '' "> and con.serial_number like #{param.concentratorCode}</if>
  825. <if test = "param.collectorCode != null and param.collectorCode != '' "> and col.collector like #{param.collectorCode}</if>
  826. <if test = "param.deviceNo != null and param.deviceNo != '' ">
  827. and ( m.device_no like #{param.deviceNo}
  828. or m.meter_no like #{param.deviceElectricNo}
  829. or m.meter_file_no like #{param.devicefileNo})
  830. </if>
  831. <if test = "param.custormerId !=null and param.custormerId != 0"> and m.customer_id = #{param.custormerId}</if>
  832. <if test = "param.communityId != null and param.communityId != 0"> and m.community = #{param.communityId}</if>
  833. <if test = "param.buildingId != null and param.buildingId != 0"> and m.building_id = #{param.buildingId}</if>
  834. <if test = 'param.readStatus != null and param.readStatus != ""'> and read_status = #{param.readStatus}</if>
  835. <if test = "param.channelId != null and param.channelId != 0"> and m.sys_id = #{param.channelId}</if>
  836. <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
  837. <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
  838. order by read_time desc
  839. </select>
  840. <select id="queryUnReadDeviceListWithNew" resultType="com.bz.smart_city.dto.DeviceDto">
  841. SELECT
  842. d.site_id as siteId,
  843. d.customer_id as customerId,
  844. d.sys_id as sysId,
  845. d.id as id,
  846. d.device_type as deviceType,
  847. d.building_id as buildingId,
  848. co.id as community,
  849. p.id as province,
  850. c.id as city,
  851. r.id as region,
  852. cu.customer_name as customerName,
  853. b.`name`as buildingName,
  854. co.`name`as communityName,
  855. col.collector_no as collectorName,
  856. con.serial_number as concentratorName,
  857. d.water_meter_no as waterMeterNo,
  858. d.water_meter_file_no as waterMeterFileNo,
  859. d.device_no as deviceNo,
  860. d.device_status as deviceStatus,
  861. d.floor as floor,
  862. d.loc_desc as locDesc,
  863. d.last_receive_time as lastReceiveTime
  864. FROM
  865. sc_device d
  866. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  867. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  868. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  869. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  870. LEFT JOIN sc_area p ON ( b.province = p.id )
  871. LEFT JOIN sc_area c ON ( b.city = c.id )
  872. LEFT JOIN sc_area r ON ( b.region = r.id )
  873. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  874. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  875. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  876. where d.status = 1
  877. <if test = "param.buildingId != null and param.buildingId != 0">
  878. and d.building_id = #{param.buildingId}
  879. </if>
  880. <if test="param.siteId != null and param.siteId != 0">
  881. and d.site_id = #{param.siteId}
  882. </if>
  883. <if test = "param.channelId != null and param.channelId != 0">
  884. and d.sys_id = #{param.channelId}
  885. </if>
  886. <if test="param.custormerId != null and param.custormerId != 0">
  887. and d.customer_id = #{param.custormerId}
  888. </if>
  889. and ( d.id IN (
  890. SELECT
  891. tmp.device_id
  892. FROM
  893. (
  894. SELECT
  895. site_id,
  896. sys_id,
  897. building_id,
  898. device_id
  899. FROM
  900. sc_meter_read_record
  901. WHERE
  902. <if test = "param.statDay != null and param.statDay != 0">
  903. read_date = #{param.statDay}
  904. </if>
  905. <if test = "param.buildingId != null and param.buildingId != 0">
  906. AND building_id = #{param.buildingId}
  907. </if>
  908. AND read_status = 1
  909. ) tmp
  910. ) or d.device_status = 5)
  911. </select>
  912. <select id="queryUnReadDeviceList" resultType="com.bz.smart_city.dto.DeviceDto">
  913. SELECT
  914. d.site_id as siteId,
  915. d.customer_id as customerId,
  916. d.sys_id as sysId,
  917. d.id as id,
  918. d.device_type as deviceType,
  919. d.building_id as buildingId,
  920. co.id as community,
  921. p.id as province,
  922. c.id as city,
  923. r.id as region,
  924. cu.customer_name as customerName,
  925. b.`name`as buildingName,
  926. co.`name`as communityName,
  927. col.collector_no as collectorName,
  928. con.serial_number as concentratorName,
  929. d.water_meter_no as waterMeterNo,
  930. d.water_meter_file_no as waterMeterFileNo,
  931. d.device_no as deviceNo,
  932. d.device_status as deviceStatus,
  933. d.floor as floor,
  934. d.loc_desc as locDesc,
  935. d.last_receive_time as lastReceiveTime
  936. FROM
  937. sc_device d
  938. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  939. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  940. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  941. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  942. LEFT JOIN sc_area p ON ( b.province = p.id )
  943. LEFT JOIN sc_area c ON ( b.city = c.id )
  944. LEFT JOIN sc_area r ON ( b.region = r.id )
  945. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  946. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  947. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  948. where d.status = 1
  949. <if test = "param.buildingId != null and param.buildingId != 0">
  950. and d.building_id = #{param.buildingId}
  951. </if>
  952. <if test="param.siteId != null and param.siteId != 0">
  953. and d.site_id = #{param.siteId}
  954. </if>
  955. <if test = "param.channelId != null and param.channelId != 0">
  956. and d.sys_id = #{param.channelId}
  957. </if>
  958. <if test="param.custormerId != null and param.custormerId != 0">
  959. and d.customer_id = #{param.custormerId}
  960. </if>
  961. and d.id IN (
  962. SELECT
  963. tmp.device_id
  964. FROM
  965. (
  966. SELECT
  967. site_id,
  968. channel_id,
  969. building_id,
  970. device_id
  971. FROM
  972. sc_stat_meter_unread_device_by_building
  973. WHERE
  974. <if test = "param.statDay != null and param.statDay != 0">
  975. stat_day = #{param.statDay}
  976. </if>
  977. <if test = "param.buildingId != null and param.buildingId != 0">
  978. AND building_id = #{param.buildingId}
  979. </if>
  980. ) tmp
  981. )
  982. </select>
  983. <select id="queryUnReadDeviceListV2" resultType="com.bz.smart_city.dto.DeviceDto">
  984. SELECT
  985. d.site_id as siteId,
  986. d.customer_id as customerId,
  987. d.sys_id as sysId,
  988. d.id as id,
  989. d.device_type as deviceType,
  990. d.building_id as buildingId,
  991. co.id as community,
  992. cu.customer_name as customerName,
  993. b.`name`as buildingName,
  994. co.`name`as communityName,
  995. col.collector_no as collectorName,
  996. con.serial_number as concentratorName,
  997. d.water_meter_no as waterMeterNo,
  998. d.water_meter_file_no as waterMeterFileNo,
  999. d.device_no as deviceNo,
  1000. d.device_status as deviceStatus,
  1001. d.floor as floor,
  1002. d.loc_desc as locDesc,
  1003. d.last_receive_time as lastReceiveTime
  1004. FROM ${tableName} as t1
  1005. LEFT JOIN sc_device d on(t1.device_id = d.id)
  1006. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1007. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1008. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1009. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1010. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1011. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1012. where d.status = 1
  1013. <if test = "param.buildingId != null and param.buildingId != 0">
  1014. and d.building_id = #{param.buildingId}
  1015. </if>
  1016. <if test="param.siteId != null and param.siteId != 0">
  1017. and d.site_id = #{param.siteId}
  1018. </if>
  1019. <if test = "param.channelId != null and param.channelId != 0">
  1020. and d.sys_id = #{param.channelId}
  1021. </if>
  1022. <if test="param.custormerId != null and param.custormerId != 0">
  1023. and d.customer_id = #{param.custormerId}
  1024. </if>
  1025. <if test = "param.statDay != null and param.statDay != 0">
  1026. and t1.stat_day = #{param.statDay}
  1027. </if>
  1028. <if test = "param.buildingId != null and param.buildingId != 0">
  1029. AND t1.building_id = #{param.buildingId}
  1030. </if>
  1031. </select>
  1032. <select id="queryUnReadDeviceListFor7Day" resultType="com.bz.smart_city.dto.DeviceDto">
  1033. SELECT
  1034. d.site_id as siteId,
  1035. d.customer_id as customerId,
  1036. d.sys_id as sysId,
  1037. d.id as id,
  1038. d.device_type as deviceType,
  1039. d.building_id as buildingId,
  1040. co.id as community,
  1041. p.id as province,
  1042. c.id as city,
  1043. r.id as region,
  1044. cu.customer_name as customerName,
  1045. b.`name`as buildingName,
  1046. co.`name`as communityName,
  1047. col.collector_no as collectorName,
  1048. con.serial_number as concentratorName,
  1049. d.water_meter_no as waterMeterNo,
  1050. d.water_meter_file_no as waterMeterFileNo,
  1051. d.device_no as deviceNo,
  1052. d.device_status as deviceStatus,
  1053. d.floor as floor,
  1054. d.loc_desc as locDesc,
  1055. d.last_receive_time as lastReceiveTime
  1056. FROM
  1057. sc_device d
  1058. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  1059. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1060. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1061. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1062. LEFT JOIN sc_area p ON ( b.province = p.id )
  1063. LEFT JOIN sc_area c ON ( b.city = c.id )
  1064. LEFT JOIN sc_area r ON ( b.region = r.id )
  1065. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1066. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1067. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1068. where d.status = 1
  1069. <if test = "param.buildingId != null and param.buildingId != 0">
  1070. and d.building_id = #{param.buildingId}
  1071. </if>
  1072. <if test="param.siteId != null and param.siteId != 0">
  1073. and d.site_id = #{param.siteId}
  1074. </if>
  1075. <if test = "param.channelId != null and param.channelId != 0">
  1076. and d.sys_id = #{param.channelId}
  1077. </if>
  1078. <if test="param.custormerId != null and param.custormerId != 0">
  1079. and d.customer_id = #{param.custormerId}
  1080. </if>
  1081. and d.id IN (
  1082. SELECT
  1083. tmp.device_id
  1084. FROM
  1085. (
  1086. SELECT
  1087. site_id,
  1088. channel_id,
  1089. building_id,
  1090. device_id
  1091. FROM
  1092. sc_stat_meter_unread_device_by_building_7day
  1093. WHERE
  1094. <if test = "param.statDay != null and param.statDay != 0">
  1095. stat_day = #{param.statDay}
  1096. </if>
  1097. <if test = "param.buildingId != null and param.buildingId != 0">
  1098. AND building_id = #{param.buildingId}
  1099. </if>
  1100. ) tmp
  1101. )
  1102. </select>
  1103. <select id="queryUnReadDeviceListFor7DayWithNew" resultType="com.bz.smart_city.dto.DeviceDto">
  1104. SELECT
  1105. d.site_id as siteId,
  1106. d.customer_id as customerId,
  1107. d.sys_id as sysId,
  1108. d.id as id,
  1109. d.device_type as deviceType,
  1110. d.building_id as buildingId,
  1111. co.id as community,
  1112. p.id as province,
  1113. c.id as city,
  1114. r.id as region,
  1115. cu.customer_name as customerName,
  1116. b.`name`as buildingName,
  1117. co.`name`as communityName,
  1118. col.collector_no as collectorName,
  1119. con.serial_number as concentratorName,
  1120. d.water_meter_no as waterMeterNo,
  1121. d.water_meter_file_no as waterMeterFileNo,
  1122. d.device_no as deviceNo,
  1123. d.device_status as deviceStatus,
  1124. d.floor as floor,
  1125. d.loc_desc as locDesc,
  1126. d.last_receive_time as lastReceiveTime
  1127. FROM
  1128. sc_device d
  1129. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  1130. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1131. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1132. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1133. LEFT JOIN sc_area p ON ( b.province = p.id )
  1134. LEFT JOIN sc_area c ON ( b.city = c.id )
  1135. LEFT JOIN sc_area r ON ( b.region = r.id )
  1136. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1137. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1138. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1139. where d.status = 1
  1140. <if test = "param.buildingId != null and param.buildingId != 0">
  1141. and d.building_id = #{param.buildingId}
  1142. </if>
  1143. <if test="param.siteId != null and param.siteId != 0">
  1144. and d.site_id = #{param.siteId}
  1145. </if>
  1146. <if test = "param.channelId != null and param.channelId != 0">
  1147. and d.sys_id = #{param.channelId}
  1148. </if>
  1149. <if test="param.custormerId != null and param.custormerId != 0">
  1150. and d.customer_id = #{param.custormerId}
  1151. </if>
  1152. and ( d.id IN (
  1153. SELECT
  1154. tmp.device_id
  1155. FROM
  1156. (
  1157. SELECT
  1158. site_id,
  1159. channel_id,
  1160. building_id,
  1161. device_id
  1162. FROM
  1163. sc_stat_meter_unread_device_by_building_7day
  1164. WHERE
  1165. <if test = "param.statDay != null and param.statDay != 0">
  1166. stat_day = #{param.statDay}
  1167. </if>
  1168. <if test = "param.buildingId != null and param.buildingId != 0">
  1169. AND building_id = #{param.buildingId}
  1170. </if>
  1171. ) tmp
  1172. ) or d.device_status = 5 )
  1173. </select>
  1174. <select id="queryUnReadDeviceListFor15Day" resultType="com.bz.smart_city.dto.DeviceDto">
  1175. SELECT
  1176. d.site_id as siteId,
  1177. d.customer_id as customerId,
  1178. d.sys_id as sysId,
  1179. d.id as id,
  1180. d.device_type as deviceType,
  1181. d.building_id as buildingId,
  1182. co.id as community,
  1183. p.id as province,
  1184. c.id as city,
  1185. r.id as region,
  1186. cu.customer_name as customerName,
  1187. b.`name`as buildingName,
  1188. co.`name`as communityName,
  1189. col.collector_no as collectorName,
  1190. con.serial_number as concentratorName,
  1191. d.water_meter_no as waterMeterNo,
  1192. d.water_meter_file_no as waterMeterFileNo,
  1193. d.device_no as deviceNo,
  1194. d.device_status as deviceStatus,
  1195. d.floor as floor,
  1196. d.loc_desc as locDesc,
  1197. d.last_receive_time as lastReceiveTime
  1198. FROM
  1199. sc_device d
  1200. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  1201. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1202. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1203. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1204. LEFT JOIN sc_area p ON ( b.province = p.id )
  1205. LEFT JOIN sc_area c ON ( b.city = c.id )
  1206. LEFT JOIN sc_area r ON ( b.region = r.id )
  1207. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1208. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1209. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1210. where d.status = 1
  1211. <if test = "param.buildingId != null and param.buildingId != 0">
  1212. and d.building_id = #{param.buildingId}
  1213. </if>
  1214. <if test="param.siteId != null and param.siteId != 0">
  1215. and d.site_id = #{param.siteId}
  1216. </if>
  1217. <if test = "param.channelId != null and param.channelId != 0">
  1218. and d.sys_id = #{param.channelId}
  1219. </if>
  1220. <if test="param.custormerId != null and param.custormerId != 0">
  1221. and d.customer_id = #{param.custormerId}
  1222. </if>
  1223. and d.id IN (
  1224. SELECT
  1225. tmp.device_id
  1226. FROM
  1227. (
  1228. SELECT
  1229. site_id,
  1230. channel_id,
  1231. building_id,
  1232. device_id
  1233. FROM
  1234. sc_stat_meter_unread_device_by_building_15day
  1235. WHERE
  1236. <if test = "param.statDay != null and param.statDay != 0">
  1237. stat_day = #{param.statDay}
  1238. </if>
  1239. <if test = "param.buildingId != null and param.buildingId != 0">
  1240. AND building_id = #{param.buildingId}
  1241. </if>
  1242. ) tmp
  1243. )
  1244. </select>
  1245. <select id="queryUnReadDeviceListForMonth" resultType="com.bz.smart_city.dto.DeviceDto">
  1246. SELECT
  1247. d.site_id as siteId,
  1248. d.customer_id as customerId,
  1249. d.sys_id as sysId,
  1250. d.id as id,
  1251. d.device_type as deviceType,
  1252. d.building_id as buildingId,
  1253. co.id as community,
  1254. p.id as province,
  1255. c.id as city,
  1256. r.id as region,
  1257. cu.customer_name as customerName,
  1258. b.`name`as buildingName,
  1259. co.`name`as communityName,
  1260. col.collector_no as collectorName,
  1261. con.serial_number as concentratorName,
  1262. d.water_meter_no as waterMeterNo,
  1263. d.water_meter_file_no as waterMeterFileNo,
  1264. d.device_no as deviceNo,
  1265. d.device_status as deviceStatus,
  1266. d.floor as floor,
  1267. d.loc_desc as locDesc,
  1268. d.last_receive_time as lastReceiveTime
  1269. FROM
  1270. sc_device d
  1271. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  1272. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1273. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1274. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1275. LEFT JOIN sc_area p ON ( b.province = p.id )
  1276. LEFT JOIN sc_area c ON ( b.city = c.id )
  1277. LEFT JOIN sc_area r ON ( b.region = r.id )
  1278. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1279. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1280. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1281. where d.status = 1
  1282. <if test = "param.buildingId != null and param.buildingId != 0">
  1283. and d.building_id = #{param.buildingId}
  1284. </if>
  1285. <if test="param.siteId != null and param.siteId != 0">
  1286. and d.site_id = #{param.siteId}
  1287. </if>
  1288. <if test = "param.channelId != null and param.channelId != 0">
  1289. and d.sys_id = #{param.channelId}
  1290. </if>
  1291. <if test="param.custormerId != null and param.custormerId != 0">
  1292. and d.customer_id = #{param.custormerId}
  1293. </if>
  1294. and d.id IN (
  1295. SELECT
  1296. tmp.device_id
  1297. FROM
  1298. (
  1299. SELECT
  1300. site_id,
  1301. channel_id,
  1302. building_id,
  1303. device_id
  1304. FROM
  1305. sc_stat_meter_unread_device_by_building_month
  1306. WHERE
  1307. <if test = "param.statDay != null and param.statDay != 0">
  1308. stat_day = #{param.statDay}
  1309. </if>
  1310. <if test = "param.buildingId != null and param.buildingId != 0">
  1311. AND building_id = #{param.buildingId}
  1312. </if>
  1313. ) tmp
  1314. )
  1315. </select>
  1316. <select id="queryUnReadDeviceListFor15DayWithNew" resultType="com.bz.smart_city.dto.DeviceDto">
  1317. SELECT
  1318. d.site_id as siteId,
  1319. d.customer_id as customerId,
  1320. d.sys_id as sysId,
  1321. d.id as id,
  1322. d.device_type as deviceType,
  1323. d.building_id as buildingId,
  1324. co.id as community,
  1325. p.id as province,
  1326. c.id as city,
  1327. r.id as region,
  1328. cu.customer_name as customerName,
  1329. b.`name`as buildingName,
  1330. co.`name`as communityName,
  1331. col.collector_no as collectorName,
  1332. con.serial_number as concentratorName,
  1333. d.water_meter_no as waterMeterNo,
  1334. d.water_meter_file_no as waterMeterFileNo,
  1335. d.device_no as deviceNo,
  1336. d.device_status as deviceStatus,
  1337. d.floor as floor,
  1338. d.loc_desc as locDesc,
  1339. d.last_receive_time as lastReceiveTime
  1340. FROM
  1341. sc_device d
  1342. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  1343. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1344. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1345. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1346. LEFT JOIN sc_area p ON ( b.province = p.id )
  1347. LEFT JOIN sc_area c ON ( b.city = c.id )
  1348. LEFT JOIN sc_area r ON ( b.region = r.id )
  1349. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1350. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1351. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1352. where d.status = 1
  1353. <if test = "param.buildingId != null and param.buildingId != 0">
  1354. and d.building_id = #{param.buildingId}
  1355. </if>
  1356. <if test="param.siteId != null and param.siteId != 0">
  1357. and d.site_id = #{param.siteId}
  1358. </if>
  1359. <if test = "param.channelId != null and param.channelId != 0">
  1360. and d.sys_id = #{param.channelId}
  1361. </if>
  1362. <if test="param.custormerId != null and param.custormerId != 0">
  1363. and d.customer_id = #{param.custormerId}
  1364. </if>
  1365. and (d.id IN (
  1366. SELECT
  1367. tmp.device_id
  1368. FROM
  1369. (
  1370. SELECT
  1371. site_id,
  1372. channel_id,
  1373. building_id,
  1374. device_id
  1375. FROM
  1376. sc_stat_meter_unread_device_by_building_15day
  1377. WHERE
  1378. <if test = "param.statDay != null and param.statDay != 0">
  1379. stat_day = #{param.statDay}
  1380. </if>
  1381. <if test = "param.buildingId != null and param.buildingId != 0">
  1382. AND building_id = #{param.buildingId}
  1383. </if>
  1384. ) tmp
  1385. ) or d.device_status = 5)
  1386. </select>
  1387. <select id="queryDeviceMeterReadRecordWithCondtion" resultType="com.bz.smart_city.entity.MeterReadRecord">
  1388. select
  1389. <include refid="Base_Column_List" />
  1390. from
  1391. sc_meter_read_record
  1392. where read_status = 2
  1393. and device_id = #{param.deviceId}
  1394. <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
  1395. <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
  1396. order by read_date desc
  1397. </select>
  1398. <select id="getSummary" resultType="com.bz.smart_city.dto.WaterConsumptionSummaryDto">
  1399. select
  1400. ifnull(sum(result.water_consumption), 0) as total_water_consumption,
  1401. count(result.device_id) as total_device_count
  1402. from (
  1403. select
  1404. smrr.device_id as device_id,
  1405. smrr.building_id as building_id,
  1406. ifnull(sum(smrr.last_cost), 0) as water_consumption
  1407. from
  1408. sc_meter_read_record smrr
  1409. where smrr.status = 1
  1410. <if test="param.siteId != null"> and smrr.site_id = #{param.siteId}</if>
  1411. <if test="param.custormerId != null"> and smrr.customer_id = #{param.custormerId} </if>
  1412. <if test="param.buildingIds != null and param.buildingIds.size() != 0">
  1413. and smrr.building_id in <foreach collection="param.buildingIds" item="item" open="(" separator="," close=")"> #{item}</foreach>
  1414. </if>
  1415. <if test="param.startDate != null"> and smrr.read_date <![CDATA[ >= ]]> #{param.startDate} </if>
  1416. <if test="param.endDate != null"> and smrr.read_date <![CDATA[ <= ]]> #{param.endDate} </if>
  1417. <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>
  1418. group by
  1419. smrr.device_id, smrr.building_id
  1420. ) result
  1421. left join sc_building sb on (result.building_id = sb.id and sb.status = 1)
  1422. <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>
  1423. where 1 = 1
  1424. <if test="param.programItems != null and param.programItems.size() != 0"> and
  1425. <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  1426. sdd.${item.dimensionCode} = #{item.dimensionValue}
  1427. </foreach>
  1428. </if>
  1429. <if test="param.provinces != null and param.provinces.size() != 0">
  1430. and sb.province in <foreach collection="param.provinces" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1431. </if>
  1432. <if test="param.cities != null and param.cities.size() != 0">
  1433. and sb.city in <foreach collection="param.cities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1434. </if>
  1435. <if test="param.regions != null and param.regions.size() != 0">
  1436. and sb.region in <foreach collection="param.regions" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1437. </if>
  1438. <if test="param.communities != null and param.communities.size() != 0">
  1439. and sb.community in <foreach collection="param.communities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1440. </if>
  1441. <if test="param.beginRate != null"> and result.water_consumption <![CDATA[ >= ]]> #{param.beginRate} </if>
  1442. <if test="param.endRate != null"> and result.water_consumption <![CDATA[ <= ]]> #{param.endRate} </if>
  1443. </select>
  1444. <select id="getList" resultType="com.bz.smart_city.dto.WaterConsumptionDto">
  1445. select
  1446. list.meter_no as meter_no,
  1447. list.device_type as device_type,
  1448. list.customer as customer,
  1449. list.district as district,
  1450. list.community as community,
  1451. list.building as building,
  1452. list.location as location,
  1453. list.water_consumption as water_consumption
  1454. from (
  1455. select
  1456. smrr.meter_no as meter_no,
  1457. sdt.equipment_type as device_type,
  1458. scu.customer_name as customer,
  1459. replace(replace(sa.manger_name, "中国", ""), ",", "") as district,
  1460. sco.name as community,
  1461. sb.name as building,
  1462. smrr.location as location,
  1463. ifnull(sum(smrr.last_cost), 0) as water_consumption
  1464. from
  1465. sc_meter_read_record smrr
  1466. left join sc_device_type sdt on (smrr.device_type_id = sdt.id and sdt.status = 1)
  1467. left join sc_customer scu on (smrr.customer_id = scu.id and scu.status = 1)
  1468. left join sc_building sb on (smrr.building_id = sb.id and sb.status = 1)
  1469. left join sc_area sa on (sa.id = sb.region)
  1470. left join sc_community sco on (sb.community = sco.id and sco.id)
  1471. <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>
  1472. where
  1473. smrr.status = 1
  1474. <if test="param.siteId != null"> and smrr.site_id = #{param.siteId} </if>
  1475. <if test="param.programItems != null and param.programItems.size() != 0"> and
  1476. <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  1477. sdd.${item.dimensionCode} = #{item.dimensionValue}
  1478. </foreach>
  1479. </if>
  1480. <if test="param.custormerId != null"> and smrr.customer_id = #{param.custormerId} </if>
  1481. <if test="param.provinces != null and param.provinces.size() != 0">
  1482. and sb.province in <foreach collection="param.provinces" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1483. </if>
  1484. <if test="param.cities != null and param.cities.size() != 0">
  1485. and sb.city in <foreach collection="param.cities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1486. </if>
  1487. <if test="param.regions != null and param.regions.size() != 0">
  1488. and sb.region in <foreach collection="param.regions" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1489. </if>
  1490. <if test="param.communities != null and param.communities.size() != 0">
  1491. and sb.community in <foreach collection="param.communities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1492. </if>
  1493. <if test="param.buildingIds != null and param.buildingIds.size() != 0">
  1494. and smrr.building_id in <foreach collection="param.buildingIds" item="item" open="(" separator="," close=")"> #{item}</foreach>
  1495. </if>
  1496. <if test="param.startDate != null"> and smrr.read_date <![CDATA[ >= ]]> #{param.startDate} </if>
  1497. <if test="param.endDate != null"> and smrr.read_date <![CDATA[ <= ]]> #{param.endDate} </if>
  1498. <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>
  1499. group by
  1500. smrr.meter_no, sdt.equipment_type, scu.customer_name, district, sco.name, sb.name, smrr.location
  1501. ) list
  1502. where 1 = 1
  1503. <if test="param.beginRate != null"> and list.water_consumption <![CDATA[ >= ]]> #{param.beginRate} </if>
  1504. <if test="param.endRate != null"> and list.water_consumption <![CDATA[ <= ]]> #{param.endRate} </if>
  1505. <if test="param.sortOrder != null"> order by list.water_consumption ${param.sortOrder} </if>
  1506. </select>
  1507. <select id="getList_COUNT" resultType="Long">
  1508. select
  1509. count(result.device_id)
  1510. from (
  1511. select
  1512. smrr.device_id as device_id,
  1513. smrr.building_id as building_id,
  1514. ifnull(sum(smrr.last_cost), 0) as water_consumption
  1515. from
  1516. sc_meter_read_record smrr
  1517. where smrr.status = 1
  1518. <if test="param.siteId != null"> and smrr.site_id = #{param.siteId}</if>
  1519. <if test="param.custormerId != null"> and smrr.customer_id = #{param.custormerId} </if>
  1520. <if test="param.buildingIds != null and param.buildingIds.size() != 0">
  1521. and smrr.building_id in <foreach collection="param.buildingIds" item="item" open="(" separator="," close=")"> #{item}</foreach>
  1522. </if>
  1523. <if test="param.startDate != null"> and smrr.read_date <![CDATA[ >= ]]> #{param.startDate} </if>
  1524. <if test="param.endDate != null"> and smrr.read_date <![CDATA[ <= ]]> #{param.endDate} </if>
  1525. group by
  1526. smrr.device_id, smrr.building_id
  1527. ) result
  1528. left join sc_building sb on (result.building_id = sb.id and sb.status = 1)
  1529. <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>
  1530. where 1 = 1
  1531. <if test="param.programItems != null and param.programItems.size() != 0"> and
  1532. <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  1533. sdd.${item.dimensionCode} = #{item.dimensionValue}
  1534. </foreach>
  1535. </if>
  1536. <if test="param.provinces != null and param.provinces.size() != 0">
  1537. and sb.province in <foreach collection="param.provinces" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1538. </if>
  1539. <if test="param.cities != null and param.cities.size() != 0">
  1540. and sb.city in <foreach collection="param.cities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1541. </if>
  1542. <if test="param.regions != null and param.regions.size() != 0">
  1543. and sb.region in <foreach collection="param.regions" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1544. </if>
  1545. <if test="param.communities != null and param.communities.size() != 0">
  1546. and sb.community in <foreach collection="param.communities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1547. </if>
  1548. <if test="param.beginRate != null"> and result.water_consumption <![CDATA[ >= ]]> #{param.beginRate} </if>
  1549. <if test="param.endRate != null"> and result.water_consumption <![CDATA[ <= ]]> #{param.endRate} </if>
  1550. </select>
  1551. <select id="getLastDayData" resultMap="BaseResultMap">
  1552. select
  1553. <include refid="Base_Column_List" />
  1554. from
  1555. sc_meter_read_record
  1556. where
  1557. status = 1 and device_id = #{deviceId} and read_date = #{lastDate}
  1558. </select>
  1559. <select id="getLastDayDataV2" resultMap="BaseResultMap">
  1560. select
  1561. <include refid="Base_Column_List" />
  1562. from
  1563. sc_meter_read_record
  1564. where
  1565. status = 1 and device_id = #{deviceId} and read_date <![CDATA[ < ]]> #{lastDate} order by read_date desc limit 1
  1566. </select>
  1567. <select id="getAllDeviceId" resultType="Long">
  1568. select distinct device_id
  1569. from sc_meter_read_record
  1570. where status = 1 and sys_id = -99
  1571. <if test="startDate != null"> and read_date <![CDATA[ >= ]]> #{startDate} </if>
  1572. order by device_id asc
  1573. </select>
  1574. <select id="getMeterReadRecordByDeviceId" resultMap="BaseResultMap">
  1575. select
  1576. <include refid="Base_Column_List" />
  1577. from sc_meter_read_record
  1578. where status = 1
  1579. <if test="deviceId != null"> and device_id = #{deviceId} </if>
  1580. <if test="startDate != null"> and read_date <![CDATA[ >= ]]> #{startDate} </if>
  1581. order by read_date asc
  1582. </select>
  1583. <update id="batchUpdate" parameterType="list">
  1584. UPDATE sc_meter_read_record
  1585. <trim prefix="set" suffixOverrides=",">
  1586. <trim prefix="last_valid =case" suffix="end,">
  1587. <foreach collection="list" item="item">
  1588. <if test="item.lastValid!=null">
  1589. when id=#{item.id} then #{item.lastValid}
  1590. </if>
  1591. </foreach>
  1592. </trim>
  1593. <trim prefix="last_cost =case" suffix="end,">
  1594. <foreach collection="list" item="item">
  1595. <if test="item.lastCost!=null">
  1596. when id=#{item.id} then #{item.lastCost}
  1597. </if>
  1598. </foreach>
  1599. </trim>
  1600. </trim>
  1601. <where>
  1602. id in <foreach collection="list" item="item" open="(" separator="," close=")">#{item.id}</foreach>
  1603. </where>
  1604. </update>
  1605. <select id="getDeviceIdOnDate" resultType="Long">
  1606. select
  1607. device_id
  1608. from sc_meter_read_record
  1609. where status = 1 and read_date = #{date}
  1610. limit #{limit}
  1611. </select>
  1612. <select id="queryMeterReadData" resultType="com.bz.smart_city.dto.MeterReadDataDTO">
  1613. SELECT
  1614. read_date as meter_read_date,
  1615. device_no,
  1616. meter_no as electronic_no,
  1617. read_data as meter_read_data,
  1618. read_time as meter_read_time
  1619. FROM
  1620. sc_meter_read_record
  1621. WHERE
  1622. read_status = 2
  1623. AND read_date = #{meterReadDate}
  1624. <if test="deviceNo != null and deviceNo != ''">
  1625. and device_no = #{deviceNo}
  1626. </if>
  1627. <if test="electronicNo != null and electronicNo != ''">
  1628. and meter_no = #{electronicNo}
  1629. </if>
  1630. <if test="custId != null">
  1631. and customer_id = #{custId}
  1632. </if>
  1633. </select>
  1634. <update id="updateHitoryData">
  1635. UPDATE sc_meter_read_record
  1636. <set>
  1637. <if test="meterReadRecord.sysId != null"> sys_id= #{meterReadRecord.sysId,jdbcType=INTEGER},</if>
  1638. </set>
  1639. where device_id= #{meterReadRecord.deviceId,jdbcType=BIGINT}
  1640. </update>
  1641. <select id="findSyncMeterRecord" resultMap="BaseResultMap">
  1642. select device_id,meter_file_no,read_data,read_time from sc_meter_read_record
  1643. where read_date=#{readTime} and read_data is not null
  1644. and device_id in
  1645. <foreach collection="deviceIds" item="item" separator="," open="(" close=")">
  1646. #{item}
  1647. </foreach>
  1648. </select>
  1649. <select id="findMeterLastReadRecord" resultMap="BaseResultMap">
  1650. select
  1651. <include refid="Base_Column_List"></include>
  1652. from
  1653. sc_meter_read_record
  1654. where device_id = #{deviceId,jdbcType=BIGINT}
  1655. and read_status = 2
  1656. and status = 1
  1657. and read_date = ( SELECT max( read_date ) FROM sc_meter_read_record WHERE device_id = #{deviceId,jdbcType=BIGINT} and read_status = 2)
  1658. limit 1
  1659. </select>
  1660. </mapper>