MeterReadRecordMapper.xml 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689
  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. p.id as province,
  993. c.id as city,
  994. r.id as region,
  995. cu.customer_name as customerName,
  996. b.`name`as buildingName,
  997. co.`name`as communityName,
  998. col.collector_no as collectorName,
  999. con.serial_number as concentratorName,
  1000. d.water_meter_no as waterMeterNo,
  1001. d.water_meter_file_no as waterMeterFileNo,
  1002. d.device_no as deviceNo,
  1003. d.device_status as deviceStatus,
  1004. d.floor as floor,
  1005. d.loc_desc as locDesc,
  1006. d.last_receive_time as lastReceiveTime
  1007. FROM ${tableName} as t1
  1008. LEFT JOIN sc_device d on(t1.device_id = d.id)
  1009. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  1010. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1011. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1012. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1013. LEFT JOIN sc_area p ON ( b.province = p.id )
  1014. LEFT JOIN sc_area c ON ( b.city = c.id )
  1015. LEFT JOIN sc_area r ON ( b.region = r.id )
  1016. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1017. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1018. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1019. where d.status = 1
  1020. <if test = "param.buildingId != null and param.buildingId != 0">
  1021. and d.building_id = #{param.buildingId}
  1022. </if>
  1023. <if test="param.siteId != null and param.siteId != 0">
  1024. and d.site_id = #{param.siteId}
  1025. </if>
  1026. <if test = "param.channelId != null and param.channelId != 0">
  1027. and d.sys_id = #{param.channelId}
  1028. </if>
  1029. <if test="param.custormerId != null and param.custormerId != 0">
  1030. and d.customer_id = #{param.custormerId}
  1031. </if>
  1032. <if test = "param.statDay != null and param.statDay != 0">
  1033. and t1.stat_day = #{param.statDay}
  1034. </if>
  1035. <if test = "param.buildingId != null and param.buildingId != 0">
  1036. AND t1.building_id = #{param.buildingId}
  1037. </if>
  1038. </select>
  1039. <select id="queryUnReadDeviceListFor7Day" resultType="com.bz.smart_city.dto.DeviceDto">
  1040. SELECT
  1041. d.site_id as siteId,
  1042. d.customer_id as customerId,
  1043. d.sys_id as sysId,
  1044. d.id as id,
  1045. d.device_type as deviceType,
  1046. d.building_id as buildingId,
  1047. co.id as community,
  1048. p.id as province,
  1049. c.id as city,
  1050. r.id as region,
  1051. cu.customer_name as customerName,
  1052. b.`name`as buildingName,
  1053. co.`name`as communityName,
  1054. col.collector_no as collectorName,
  1055. con.serial_number as concentratorName,
  1056. d.water_meter_no as waterMeterNo,
  1057. d.water_meter_file_no as waterMeterFileNo,
  1058. d.device_no as deviceNo,
  1059. d.device_status as deviceStatus,
  1060. d.floor as floor,
  1061. d.loc_desc as locDesc,
  1062. d.last_receive_time as lastReceiveTime
  1063. FROM
  1064. sc_device d
  1065. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  1066. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1067. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1068. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1069. LEFT JOIN sc_area p ON ( b.province = p.id )
  1070. LEFT JOIN sc_area c ON ( b.city = c.id )
  1071. LEFT JOIN sc_area r ON ( b.region = r.id )
  1072. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1073. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1074. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1075. where d.status = 1
  1076. <if test = "param.buildingId != null and param.buildingId != 0">
  1077. and d.building_id = #{param.buildingId}
  1078. </if>
  1079. <if test="param.siteId != null and param.siteId != 0">
  1080. and d.site_id = #{param.siteId}
  1081. </if>
  1082. <if test = "param.channelId != null and param.channelId != 0">
  1083. and d.sys_id = #{param.channelId}
  1084. </if>
  1085. <if test="param.custormerId != null and param.custormerId != 0">
  1086. and d.customer_id = #{param.custormerId}
  1087. </if>
  1088. and d.id IN (
  1089. SELECT
  1090. tmp.device_id
  1091. FROM
  1092. (
  1093. SELECT
  1094. site_id,
  1095. channel_id,
  1096. building_id,
  1097. device_id
  1098. FROM
  1099. sc_stat_meter_unread_device_by_building_7day
  1100. WHERE
  1101. <if test = "param.statDay != null and param.statDay != 0">
  1102. stat_day = #{param.statDay}
  1103. </if>
  1104. <if test = "param.buildingId != null and param.buildingId != 0">
  1105. AND building_id = #{param.buildingId}
  1106. </if>
  1107. ) tmp
  1108. )
  1109. </select>
  1110. <select id="queryUnReadDeviceListFor7DayWithNew" resultType="com.bz.smart_city.dto.DeviceDto">
  1111. SELECT
  1112. d.site_id as siteId,
  1113. d.customer_id as customerId,
  1114. d.sys_id as sysId,
  1115. d.id as id,
  1116. d.device_type as deviceType,
  1117. d.building_id as buildingId,
  1118. co.id as community,
  1119. p.id as province,
  1120. c.id as city,
  1121. r.id as region,
  1122. cu.customer_name as customerName,
  1123. b.`name`as buildingName,
  1124. co.`name`as communityName,
  1125. col.collector_no as collectorName,
  1126. con.serial_number as concentratorName,
  1127. d.water_meter_no as waterMeterNo,
  1128. d.water_meter_file_no as waterMeterFileNo,
  1129. d.device_no as deviceNo,
  1130. d.device_status as deviceStatus,
  1131. d.floor as floor,
  1132. d.loc_desc as locDesc,
  1133. d.last_receive_time as lastReceiveTime
  1134. FROM
  1135. sc_device d
  1136. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  1137. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1138. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1139. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1140. LEFT JOIN sc_area p ON ( b.province = p.id )
  1141. LEFT JOIN sc_area c ON ( b.city = c.id )
  1142. LEFT JOIN sc_area r ON ( b.region = r.id )
  1143. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1144. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1145. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1146. where d.status = 1
  1147. <if test = "param.buildingId != null and param.buildingId != 0">
  1148. and d.building_id = #{param.buildingId}
  1149. </if>
  1150. <if test="param.siteId != null and param.siteId != 0">
  1151. and d.site_id = #{param.siteId}
  1152. </if>
  1153. <if test = "param.channelId != null and param.channelId != 0">
  1154. and d.sys_id = #{param.channelId}
  1155. </if>
  1156. <if test="param.custormerId != null and param.custormerId != 0">
  1157. and d.customer_id = #{param.custormerId}
  1158. </if>
  1159. and ( d.id IN (
  1160. SELECT
  1161. tmp.device_id
  1162. FROM
  1163. (
  1164. SELECT
  1165. site_id,
  1166. channel_id,
  1167. building_id,
  1168. device_id
  1169. FROM
  1170. sc_stat_meter_unread_device_by_building_7day
  1171. WHERE
  1172. <if test = "param.statDay != null and param.statDay != 0">
  1173. stat_day = #{param.statDay}
  1174. </if>
  1175. <if test = "param.buildingId != null and param.buildingId != 0">
  1176. AND building_id = #{param.buildingId}
  1177. </if>
  1178. ) tmp
  1179. ) or d.device_status = 5 )
  1180. </select>
  1181. <select id="queryUnReadDeviceListFor15Day" resultType="com.bz.smart_city.dto.DeviceDto">
  1182. SELECT
  1183. d.site_id as siteId,
  1184. d.customer_id as customerId,
  1185. d.sys_id as sysId,
  1186. d.id as id,
  1187. d.device_type as deviceType,
  1188. d.building_id as buildingId,
  1189. co.id as community,
  1190. p.id as province,
  1191. c.id as city,
  1192. r.id as region,
  1193. cu.customer_name as customerName,
  1194. b.`name`as buildingName,
  1195. co.`name`as communityName,
  1196. col.collector_no as collectorName,
  1197. con.serial_number as concentratorName,
  1198. d.water_meter_no as waterMeterNo,
  1199. d.water_meter_file_no as waterMeterFileNo,
  1200. d.device_no as deviceNo,
  1201. d.device_status as deviceStatus,
  1202. d.floor as floor,
  1203. d.loc_desc as locDesc,
  1204. d.last_receive_time as lastReceiveTime
  1205. FROM
  1206. sc_device d
  1207. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  1208. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1209. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1210. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1211. LEFT JOIN sc_area p ON ( b.province = p.id )
  1212. LEFT JOIN sc_area c ON ( b.city = c.id )
  1213. LEFT JOIN sc_area r ON ( b.region = r.id )
  1214. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1215. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1216. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1217. where d.status = 1
  1218. <if test = "param.buildingId != null and param.buildingId != 0">
  1219. and d.building_id = #{param.buildingId}
  1220. </if>
  1221. <if test="param.siteId != null and param.siteId != 0">
  1222. and d.site_id = #{param.siteId}
  1223. </if>
  1224. <if test = "param.channelId != null and param.channelId != 0">
  1225. and d.sys_id = #{param.channelId}
  1226. </if>
  1227. <if test="param.custormerId != null and param.custormerId != 0">
  1228. and d.customer_id = #{param.custormerId}
  1229. </if>
  1230. and d.id IN (
  1231. SELECT
  1232. tmp.device_id
  1233. FROM
  1234. (
  1235. SELECT
  1236. site_id,
  1237. channel_id,
  1238. building_id,
  1239. device_id
  1240. FROM
  1241. sc_stat_meter_unread_device_by_building_15day
  1242. WHERE
  1243. <if test = "param.statDay != null and param.statDay != 0">
  1244. stat_day = #{param.statDay}
  1245. </if>
  1246. <if test = "param.buildingId != null and param.buildingId != 0">
  1247. AND building_id = #{param.buildingId}
  1248. </if>
  1249. ) tmp
  1250. )
  1251. </select>
  1252. <select id="queryUnReadDeviceListForMonth" resultType="com.bz.smart_city.dto.DeviceDto">
  1253. SELECT
  1254. d.site_id as siteId,
  1255. d.customer_id as customerId,
  1256. d.sys_id as sysId,
  1257. d.id as id,
  1258. d.device_type as deviceType,
  1259. d.building_id as buildingId,
  1260. co.id as community,
  1261. p.id as province,
  1262. c.id as city,
  1263. r.id as region,
  1264. cu.customer_name as customerName,
  1265. b.`name`as buildingName,
  1266. co.`name`as communityName,
  1267. col.collector_no as collectorName,
  1268. con.serial_number as concentratorName,
  1269. d.water_meter_no as waterMeterNo,
  1270. d.water_meter_file_no as waterMeterFileNo,
  1271. d.device_no as deviceNo,
  1272. d.device_status as deviceStatus,
  1273. d.floor as floor,
  1274. d.loc_desc as locDesc,
  1275. d.last_receive_time as lastReceiveTime
  1276. FROM
  1277. sc_device d
  1278. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  1279. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1280. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1281. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1282. LEFT JOIN sc_area p ON ( b.province = p.id )
  1283. LEFT JOIN sc_area c ON ( b.city = c.id )
  1284. LEFT JOIN sc_area r ON ( b.region = r.id )
  1285. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1286. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1287. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1288. where d.status = 1
  1289. <if test = "param.buildingId != null and param.buildingId != 0">
  1290. and d.building_id = #{param.buildingId}
  1291. </if>
  1292. <if test="param.siteId != null and param.siteId != 0">
  1293. and d.site_id = #{param.siteId}
  1294. </if>
  1295. <if test = "param.channelId != null and param.channelId != 0">
  1296. and d.sys_id = #{param.channelId}
  1297. </if>
  1298. <if test="param.custormerId != null and param.custormerId != 0">
  1299. and d.customer_id = #{param.custormerId}
  1300. </if>
  1301. and d.id IN (
  1302. SELECT
  1303. tmp.device_id
  1304. FROM
  1305. (
  1306. SELECT
  1307. site_id,
  1308. channel_id,
  1309. building_id,
  1310. device_id
  1311. FROM
  1312. sc_stat_meter_unread_device_by_building_month
  1313. WHERE
  1314. <if test = "param.statDay != null and param.statDay != 0">
  1315. stat_day = #{param.statDay}
  1316. </if>
  1317. <if test = "param.buildingId != null and param.buildingId != 0">
  1318. AND building_id = #{param.buildingId}
  1319. </if>
  1320. ) tmp
  1321. )
  1322. </select>
  1323. <select id="queryUnReadDeviceListFor15DayWithNew" resultType="com.bz.smart_city.dto.DeviceDto">
  1324. SELECT
  1325. d.site_id as siteId,
  1326. d.customer_id as customerId,
  1327. d.sys_id as sysId,
  1328. d.id as id,
  1329. d.device_type as deviceType,
  1330. d.building_id as buildingId,
  1331. co.id as community,
  1332. p.id as province,
  1333. c.id as city,
  1334. r.id as region,
  1335. cu.customer_name as customerName,
  1336. b.`name`as buildingName,
  1337. co.`name`as communityName,
  1338. col.collector_no as collectorName,
  1339. con.serial_number as concentratorName,
  1340. d.water_meter_no as waterMeterNo,
  1341. d.water_meter_file_no as waterMeterFileNo,
  1342. d.device_no as deviceNo,
  1343. d.device_status as deviceStatus,
  1344. d.floor as floor,
  1345. d.loc_desc as locDesc,
  1346. d.last_receive_time as lastReceiveTime
  1347. FROM
  1348. sc_device d
  1349. LEFT JOIN sc_w_meter_type wmt ON ( d.device_type = wmt.device_type_id AND wmt.`status` = 1 )
  1350. LEFT JOIN sc_customer cu ON ( d.customer_id = cu.id AND cu.`status` = 1 )
  1351. LEFT JOIN sc_building b ON ( d.building_id = b.id AND b.`status` = 1 )
  1352. LEFT JOIN sc_community co ON ( b.community = co.id AND co.`status` = 1 )
  1353. LEFT JOIN sc_area p ON ( b.province = p.id )
  1354. LEFT JOIN sc_area c ON ( b.city = c.id )
  1355. LEFT JOIN sc_area r ON ( b.region = r.id )
  1356. LEFT JOIN sc_water_related_device rd ON ( rd.device_id = d.id AND rd.`status` = 1 )
  1357. LEFT JOIN sc_collector col ON ( col.id = rd.collector_id AND col.`status` = 1 )
  1358. LEFT JOIN sc_concentrator con ON ( con.id = rd.concentrator_id AND con.`status` = 1 )
  1359. where d.status = 1
  1360. <if test = "param.buildingId != null and param.buildingId != 0">
  1361. and d.building_id = #{param.buildingId}
  1362. </if>
  1363. <if test="param.siteId != null and param.siteId != 0">
  1364. and d.site_id = #{param.siteId}
  1365. </if>
  1366. <if test = "param.channelId != null and param.channelId != 0">
  1367. and d.sys_id = #{param.channelId}
  1368. </if>
  1369. <if test="param.custormerId != null and param.custormerId != 0">
  1370. and d.customer_id = #{param.custormerId}
  1371. </if>
  1372. and (d.id IN (
  1373. SELECT
  1374. tmp.device_id
  1375. FROM
  1376. (
  1377. SELECT
  1378. site_id,
  1379. channel_id,
  1380. building_id,
  1381. device_id
  1382. FROM
  1383. sc_stat_meter_unread_device_by_building_15day
  1384. WHERE
  1385. <if test = "param.statDay != null and param.statDay != 0">
  1386. stat_day = #{param.statDay}
  1387. </if>
  1388. <if test = "param.buildingId != null and param.buildingId != 0">
  1389. AND building_id = #{param.buildingId}
  1390. </if>
  1391. ) tmp
  1392. ) or d.device_status = 5)
  1393. </select>
  1394. <select id="queryDeviceMeterReadRecordWithCondtion" resultType="com.bz.smart_city.entity.MeterReadRecord">
  1395. select
  1396. <include refid="Base_Column_List" />
  1397. from
  1398. sc_meter_read_record
  1399. where read_status = 2
  1400. and device_id = #{param.deviceId}
  1401. <if test = "param.startDate != null and param.startDate != 0"> and read_date >= #{param.startDate}</if>
  1402. <if test = "param.endDate != null and param.endDate != 0"> and read_date <![CDATA[ <= ]]> #{param.endDate}</if>
  1403. order by read_date desc
  1404. </select>
  1405. <select id="getSummary" resultType="com.bz.smart_city.dto.WaterConsumptionSummaryDto">
  1406. select
  1407. ifnull(sum(result.water_consumption), 0) as total_water_consumption,
  1408. count(result.device_id) as total_device_count
  1409. from (
  1410. select
  1411. smrr.device_id as device_id,
  1412. smrr.building_id as building_id,
  1413. ifnull(sum(smrr.last_cost), 0) as water_consumption
  1414. from
  1415. sc_meter_read_record smrr
  1416. where smrr.status = 1
  1417. <if test="param.siteId != null"> and smrr.site_id = #{param.siteId}</if>
  1418. <if test="param.custormerId != null"> and smrr.customer_id = #{param.custormerId} </if>
  1419. <if test="param.buildingIds != null and param.buildingIds.size() != 0">
  1420. and smrr.building_id in <foreach collection="param.buildingIds" item="item" open="(" separator="," close=")"> #{item}</foreach>
  1421. </if>
  1422. <if test="param.startDate != null"> and smrr.read_date <![CDATA[ >= ]]> #{param.startDate} </if>
  1423. <if test="param.endDate != null"> and smrr.read_date <![CDATA[ <= ]]> #{param.endDate} </if>
  1424. group by
  1425. smrr.device_id, smrr.building_id
  1426. ) result
  1427. left join sc_building sb on (result.building_id = sb.id and sb.status = 1)
  1428. <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>
  1429. where 1 = 1
  1430. <if test="param.programItems != null and param.programItems.size() != 0"> and
  1431. <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  1432. sdd.${item.dimensionCode} = #{item.dimensionValue}
  1433. </foreach>
  1434. </if>
  1435. <if test="param.provinces != null and param.provinces.size() != 0">
  1436. and sb.province in <foreach collection="param.provinces" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1437. </if>
  1438. <if test="param.cities != null and param.cities.size() != 0">
  1439. and sb.city in <foreach collection="param.cities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1440. </if>
  1441. <if test="param.regions != null and param.regions.size() != 0">
  1442. and sb.region in <foreach collection="param.regions" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1443. </if>
  1444. <if test="param.communities != null and param.communities.size() != 0">
  1445. and sb.community in <foreach collection="param.communities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1446. </if>
  1447. <if test="param.beginRate != null"> and result.water_consumption <![CDATA[ >= ]]> #{param.beginRate} </if>
  1448. <if test="param.endRate != null"> and result.water_consumption <![CDATA[ <= ]]> #{param.endRate} </if>
  1449. </select>
  1450. <select id="getList" resultType="com.bz.smart_city.dto.WaterConsumptionDto">
  1451. select
  1452. list.meter_no as meter_no,
  1453. list.device_type as device_type,
  1454. list.customer as customer,
  1455. list.district as district,
  1456. list.community as community,
  1457. list.building as building,
  1458. list.location as location,
  1459. list.water_consumption as water_consumption
  1460. from (
  1461. select
  1462. smrr.meter_no as meter_no,
  1463. sdt.equipment_type as device_type,
  1464. scu.customer_name as customer,
  1465. replace(replace(sa.manger_name, "中国", ""), ",", "") as district,
  1466. sco.name as community,
  1467. sb.name as building,
  1468. smrr.location as location,
  1469. ifnull(sum(smrr.last_cost), 0) as water_consumption
  1470. from
  1471. sc_meter_read_record smrr
  1472. left join sc_device_type sdt on (smrr.device_type_id = sdt.id and sdt.status = 1)
  1473. left join sc_customer scu on (smrr.customer_id = scu.id and scu.status = 1)
  1474. left join sc_building sb on (smrr.building_id = sb.id and sb.status = 1)
  1475. left join sc_area sa on (sa.id = sb.region)
  1476. left join sc_community sco on (sb.community = sco.id and sco.id)
  1477. <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>
  1478. where
  1479. smrr.status = 1
  1480. <if test="param.siteId != null"> and smrr.site_id = #{param.siteId} </if>
  1481. <if test="param.programItems != null and param.programItems.size() != 0"> and
  1482. <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  1483. sdd.${item.dimensionCode} = #{item.dimensionValue}
  1484. </foreach>
  1485. </if>
  1486. <if test="param.custormerId != null"> and smrr.customer_id = #{param.custormerId} </if>
  1487. <if test="param.provinces != null and param.provinces.size() != 0">
  1488. and sb.province in <foreach collection="param.provinces" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1489. </if>
  1490. <if test="param.cities != null and param.cities.size() != 0">
  1491. and sb.city in <foreach collection="param.cities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1492. </if>
  1493. <if test="param.regions != null and param.regions.size() != 0">
  1494. and sb.region in <foreach collection="param.regions" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1495. </if>
  1496. <if test="param.communities != null and param.communities.size() != 0">
  1497. and sb.community in <foreach collection="param.communities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1498. </if>
  1499. <if test="param.buildingIds != null and param.buildingIds.size() != 0">
  1500. and smrr.building_id in <foreach collection="param.buildingIds" item="item" open="(" separator="," close=")"> #{item}</foreach>
  1501. </if>
  1502. <if test="param.startDate != null"> and smrr.read_date <![CDATA[ >= ]]> #{param.startDate} </if>
  1503. <if test="param.endDate != null"> and smrr.read_date <![CDATA[ <= ]]> #{param.endDate} </if>
  1504. group by
  1505. smrr.meter_no, sdt.equipment_type, scu.customer_name, district, sco.name, sb.name, smrr.location
  1506. ) list
  1507. where 1 = 1
  1508. <if test="param.beginRate != null"> and list.water_consumption <![CDATA[ >= ]]> #{param.beginRate} </if>
  1509. <if test="param.endRate != null"> and list.water_consumption <![CDATA[ <= ]]> #{param.endRate} </if>
  1510. <if test="param.sortOrder != null"> order by list.water_consumption ${param.sortOrder} </if>
  1511. </select>
  1512. <select id="getList_COUNT" resultType="Long">
  1513. select
  1514. count(result.device_id)
  1515. from (
  1516. select
  1517. smrr.device_id as device_id,
  1518. smrr.building_id as building_id,
  1519. ifnull(sum(smrr.last_cost), 0) as water_consumption
  1520. from
  1521. sc_meter_read_record smrr
  1522. where smrr.status = 1
  1523. <if test="param.siteId != null"> and smrr.site_id = #{param.siteId}</if>
  1524. <if test="param.custormerId != null"> and smrr.customer_id = #{param.custormerId} </if>
  1525. <if test="param.buildingIds != null and param.buildingIds.size() != 0">
  1526. and smrr.building_id in <foreach collection="param.buildingIds" item="item" open="(" separator="," close=")"> #{item}</foreach>
  1527. </if>
  1528. <if test="param.startDate != null"> and smrr.read_date <![CDATA[ >= ]]> #{param.startDate} </if>
  1529. <if test="param.endDate != null"> and smrr.read_date <![CDATA[ <= ]]> #{param.endDate} </if>
  1530. group by
  1531. smrr.device_id, smrr.building_id
  1532. ) result
  1533. left join sc_building sb on (result.building_id = sb.id and sb.status = 1)
  1534. <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>
  1535. where 1 = 1
  1536. <if test="param.programItems != null and param.programItems.size() != 0"> and
  1537. <foreach collection="param.programItems" item="item" open="(" separator=" or " close=")">
  1538. sdd.${item.dimensionCode} = #{item.dimensionValue}
  1539. </foreach>
  1540. </if>
  1541. <if test="param.provinces != null and param.provinces.size() != 0">
  1542. and sb.province in <foreach collection="param.provinces" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1543. </if>
  1544. <if test="param.cities != null and param.cities.size() != 0">
  1545. and sb.city in <foreach collection="param.cities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1546. </if>
  1547. <if test="param.regions != null and param.regions.size() != 0">
  1548. and sb.region in <foreach collection="param.regions" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1549. </if>
  1550. <if test="param.communities != null and param.communities.size() != 0">
  1551. and sb.community in <foreach collection="param.communities" item="item" open="(" separator="," close=")"> #{item} </foreach>
  1552. </if>
  1553. <if test="param.beginRate != null"> and result.water_consumption <![CDATA[ >= ]]> #{param.beginRate} </if>
  1554. <if test="param.endRate != null"> and result.water_consumption <![CDATA[ <= ]]> #{param.endRate} </if>
  1555. </select>
  1556. <select id="getLastDayData" resultMap="BaseResultMap">
  1557. select
  1558. <include refid="Base_Column_List" />
  1559. from
  1560. sc_meter_read_record
  1561. where
  1562. status = 1 and device_id = #{deviceId} and read_date = #{lastDate}
  1563. </select>
  1564. <select id="getLastDayDataV2" resultMap="BaseResultMap">
  1565. select
  1566. <include refid="Base_Column_List" />
  1567. from
  1568. sc_meter_read_record
  1569. where
  1570. status = 1 and device_id = #{deviceId} and read_date <![CDATA[ < ]]> #{lastDate} order by read_date desc limit 1
  1571. </select>
  1572. <select id="getAllDeviceId" resultType="Long">
  1573. select distinct device_id
  1574. from sc_meter_read_record
  1575. where status = 1 and sys_id = -99
  1576. <if test="startDate != null"> and read_date <![CDATA[ >= ]]> #{startDate} </if>
  1577. order by device_id asc
  1578. </select>
  1579. <select id="getMeterReadRecordByDeviceId" resultMap="BaseResultMap">
  1580. select
  1581. <include refid="Base_Column_List" />
  1582. from sc_meter_read_record
  1583. where status = 1
  1584. <if test="deviceId != null"> and device_id = #{deviceId} </if>
  1585. <if test="startDate != null"> and read_date <![CDATA[ >= ]]> #{startDate} </if>
  1586. order by read_date asc
  1587. </select>
  1588. <update id="batchUpdate" parameterType="list">
  1589. UPDATE sc_meter_read_record
  1590. <trim prefix="set" suffixOverrides=",">
  1591. <trim prefix="last_valid =case" suffix="end,">
  1592. <foreach collection="list" item="item">
  1593. <if test="item.lastValid!=null">
  1594. when id=#{item.id} then #{item.lastValid}
  1595. </if>
  1596. </foreach>
  1597. </trim>
  1598. <trim prefix="last_cost =case" suffix="end,">
  1599. <foreach collection="list" item="item">
  1600. <if test="item.lastCost!=null">
  1601. when id=#{item.id} then #{item.lastCost}
  1602. </if>
  1603. </foreach>
  1604. </trim>
  1605. </trim>
  1606. <where>
  1607. id in <foreach collection="list" item="item" open="(" separator="," close=")">#{item.id}</foreach>
  1608. </where>
  1609. </update>
  1610. <select id="getDeviceIdOnDate" resultType="Long">
  1611. select
  1612. device_id
  1613. from sc_meter_read_record
  1614. where status = 1 and read_date = #{date}
  1615. limit #{limit}
  1616. </select>
  1617. <select id="queryMeterReadData" resultType="com.bz.smart_city.dto.MeterReadDataDTO">
  1618. SELECT
  1619. read_date as meter_read_date,
  1620. device_no,
  1621. meter_no as electronic_no,
  1622. read_data as meter_read_data,
  1623. read_time as meter_read_time
  1624. FROM
  1625. sc_meter_read_record
  1626. WHERE
  1627. read_status = 2
  1628. AND read_date = #{meterReadDate}
  1629. <if test="deviceNo != null and deviceNo != ''">
  1630. and device_no = #{deviceNo}
  1631. </if>
  1632. <if test="electronicNo != null and electronicNo != ''">
  1633. and meter_no = #{electronicNo}
  1634. </if>
  1635. <if test="custId != null">
  1636. and customer_id = #{custId}
  1637. </if>
  1638. </select>
  1639. <update id="updateHitoryData">
  1640. UPDATE sc_meter_read_record
  1641. <set>
  1642. <if test="meterReadRecord.sysId != null"> sys_id= #{meterReadRecord.sysId,jdbcType=INTEGER},</if>
  1643. </set>
  1644. where device_id= #{meterReadRecord.deviceId,jdbcType=BIGINT}
  1645. </update>
  1646. <select id="findSyncMeterRecord" resultMap="BaseResultMap">
  1647. select device_id,meter_file_no,read_data from sc_meter_read_record
  1648. where read_date=#{readTime}
  1649. and device_id in
  1650. <foreach collection="deviceIds" item="item" separator="," open="(" close=")">
  1651. #{item}
  1652. </foreach>
  1653. </select>
  1654. <select id="findMeterLastReadRecord" resultMap="BaseResultMap">
  1655. select
  1656. <include refid="Base_Column_List"></include>
  1657. from
  1658. sc_meter_read_record
  1659. where device_id = #{deviceId,jdbcType=BIGINT}
  1660. and read_status = 2
  1661. and status = 1
  1662. and read_date = ( SELECT max( read_date ) FROM sc_meter_read_record WHERE device_id = #{deviceId,jdbcType=BIGINT} and read_status = 2)
  1663. limit 1
  1664. </select>
  1665. </mapper>