WaterMeterMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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.huaxu.zoniot.dao.WaterMeterMapper">
  4. <resultMap id="BaseResultMap" type="com.huaxu.zoniot.entity.WaterMeter">
  5. <id column="device_id" jdbcType="BIGINT" property="deviceId" />
  6. <result column="water_meter_type" jdbcType="INTEGER" property="waterMeterType" />
  7. <result column="site_id" jdbcType="INTEGER" property="siteId" />
  8. <result column="sys_id" jdbcType="INTEGER" property="sysId" />
  9. <result column="province" jdbcType="INTEGER" property="province" />
  10. <result column="city" jdbcType="INTEGER" property="city" />
  11. <result column="region" jdbcType="INTEGER" property="region" />
  12. <result column="community" jdbcType="INTEGER" property="community" />
  13. <result column="customer_id" jdbcType="INTEGER" property="customerId" />
  14. <result column="concentrator_id" jdbcType="INTEGER" property="concentratorId" />
  15. <result column="collector_id" jdbcType="INTEGER" property="collectorId" />
  16. <result column="building_id" jdbcType="INTEGER" property="buildingId" />
  17. <result column="location" jdbcType="VARCHAR" property="location" />
  18. <result column="device_type_id" jdbcType="INTEGER" property="deviceTypeId" />
  19. <result column="device_id" jdbcType="BIGINT" property="deviceId" />
  20. <result column="device_no" jdbcType="VARCHAR" property="deviceNo" />
  21. <result column="meter_no" jdbcType="VARCHAR" property="meterNo" />
  22. <result column="meter_file_no" jdbcType="VARCHAR" property="meterFileNo" />
  23. <result column="reading_measuring_code" jdbcType="VARCHAR" property="readingMeasuringCode" />
  24. <result column="valve_measuring_code" jdbcType="VARCHAR" property="valveMeasuringCode" />
  25. <result column="status" jdbcType="INTEGER" property="status" />
  26. <result column="date_create" jdbcType="TIMESTAMP" property="dateCreate" />
  27. <result column="date_update" jdbcType="TIMESTAMP" property="dateUpdate" />
  28. <result column="create_by" jdbcType="VARCHAR" property="createBy" />
  29. <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
  30. <result column="community_name" jdbcType="VARCHAR" property="communityName" />
  31. <result column="building_name" jdbcType="VARCHAR" property="buildingName" />
  32. <result column="customer_name" jdbcType="VARCHAR" property="customerName" />
  33. <result column="province_name" jdbcType="VARCHAR" property="provinceName" />
  34. <result column="city_name" jdbcType="VARCHAR" property="cityName"/>
  35. <result column="region_name" jdbcType="VARCHAR" property="regionName" />
  36. <result column="concentrator_no" jdbcType="VARCHAR" property="concentratorNo" />
  37. <result column="collector_no" jdbcType="VARCHAR" property="collectorNo" />
  38. <result column="device_type_name" jdbcType="VARCHAR" property="deviceTypeName"/>
  39. <result column="manufacturer_id" jdbcType="INTEGER" property="manufacturerId" />
  40. <result column="manufacturer_name" jdbcType="VARCHAR" property="manufacturerName" />
  41. <result column="is_valve" jdbcType="INTEGER" property="isValve" />
  42. </resultMap>
  43. <insert id="insert" keyProperty="waterMeter.id">
  44. INSERT INTO sc_device (
  45. id,
  46. device_no,
  47. device_type,
  48. sys_id,
  49. site_id,
  50. building_id,
  51. loc_desc,
  52. manufacturer_id,
  53. device_status,
  54. `status`,
  55. create_by,
  56. update_by,
  57. date_create,
  58. date_update,
  59. water_meter_no,
  60. water_meter_file_no,
  61. customer_id,
  62. register_status
  63. ) VALUES (
  64. #{waterMeter.deviceId,jdbcType=BIGINT},
  65. #{waterMeter.deviceNo,jdbcType=VARCHAR},
  66. #{waterMeter.deviceTypeId,jdbcType=BIGINT},
  67. #{waterMeter.sysId,jdbcType=BIGINT},
  68. #{waterMeter.siteId,jdbcType=BIGINT},
  69. #{waterMeter.buildingId,jdbcType=BIGINT},
  70. #{waterMeter.location,jdbcType=VARCHAR},
  71. #{waterMeter.manufacturerId,jdbcType=BIGINT},
  72. #{waterMeter.deviceStatus,jdbcType=INTEGER},
  73. #{waterMeter.status,jdbcType=INTEGER},
  74. #{waterMeter.createBy,jdbcType=VARCHAR},
  75. #{waterMeter.updateBy,jdbcType=VARCHAR},
  76. #{waterMeter.dateCreate,jdbcType=TIMESTAMP},
  77. #{waterMeter.dateUpdate,jdbcType=TIMESTAMP},
  78. #{waterMeter.meterNo,jdbcType=VARCHAR},
  79. #{waterMeter.meterFileNo,jdbcType=VARCHAR},
  80. #{waterMeter.customerId,jdbcType=INTEGER},
  81. #{waterMeter.registerStatus,jdbcType=INTEGER}
  82. )
  83. </insert>
  84. <sql id="Base_Column_List">
  85. <!--@mbg.generated-->
  86. device_id ,water_meter_type,device_no, site_id, sys_id, building_id,
  87. province, city, region, community, customer_id, meter_no, meter_file_no,
  88. device_type_id, concentrator_id,collector_id, `location`,valve_measuring_code,
  89. reading_measuring_code,date_create
  90. </sql>
  91. <sql id="Base_Meter_Query_Column">
  92. d.id as device_id ,
  93. wmt.parent_id as water_meter_type ,
  94. d.device_no as device_no ,
  95. d.site_id as site_id ,
  96. d.sys_id as sys_id ,
  97. d.building_id as building_id ,
  98. b.province as province ,
  99. b.city as city ,
  100. b.region as region,
  101. b.community as community ,
  102. d.customer_id as customer_id ,
  103. d.water_meter_no as meter_no ,
  104. d.water_meter_file_no as meter_file_no,
  105. d.device_type as device_type_id ,
  106. wrd.concentrator_id as concentrator_id ,
  107. wrd.collector_id as collector_id ,
  108. d.loc_desc as location,
  109. wmt.valve_measuring_code as valve_measuring_code ,
  110. wmt.reading_measuring_code as reading_measuring_code,
  111. d.date_create as date_create,
  112. b.`name` as building_name,
  113. c.`name` as community_name ,
  114. p.name as province_name,
  115. cc.name as city_name,
  116. r.`name` as region_name,
  117. con.serial_number as concentrator_no,
  118. col.collector_no as collector_no,
  119. concat_ws('/',m.name,dt.equipment_type,dt.model) as device_type_name,
  120. d.manufacturer_id as manufacturer_id ,
  121. m.`name` as manufacturer_name,
  122. cu.customer_name as customer_name,
  123. cn.channel_name as channel_name ,
  124. wrd.channel_number_id as channel_number_id,
  125. dt.is_valve as is_valve
  126. </sql>
  127. <sql id="Base_Meter_Query_Where">
  128. d.`status` = 1
  129. and wmt.`status` = 1
  130. and wmt.valve_measuring_code is not null
  131. and wmt.reading_measuring_code is not null
  132. and wmt.parent_id in (1,2)
  133. </sql>
  134. <sql id = "Base_Meter_Query">
  135. SELECT
  136. <include refid="Base_Meter_Query_Column" />
  137. FROM
  138. <include refid="Base_Meter_Query_Table"></include>
  139. WHERE
  140. <include refid="Base_Meter_Query_Where" />
  141. </sql>
  142. <sql id="Base_Meter_Query_Table">
  143. sc_w_meter_type wmt
  144. left join sc_device d on (d.`status` = 1 and wmt.device_type_id = d.device_type)
  145. left join sc_water_related_device wrd on (wrd.device_id =d.id)
  146. left join sc_building b on (d.building_id = b.id)
  147. LEFT JOIN sc_community c on (b.community = c.id )
  148. LEFT JOIN sc_area p on (c.province = p.id)
  149. LEFT JOIN sc_area cc on (c.city = cc.id)
  150. LEFT JOIN sc_area r on (c.region =r.id)
  151. LEFT JOIN sc_concentrator con on (con.id = wrd.concentrator_id)
  152. LEFT JOIN sc_collector col on (col.id = wrd.collector_id)
  153. left join sc_device_type dt on (d.device_type = dt.id)
  154. left join sc_device_manufacturer m on (d.manufacturer_id = m.id)
  155. left join sc_customer cu on (cu.id = d.customer_id)
  156. left join sc_channel_number cn on(cn.id = wrd.channel_number_id)
  157. </sql>
  158. <select id="findAllWaterMeterList" resultMap="BaseResultMap">
  159. <include refid="Base_Meter_Query" />
  160. </select>
  161. <select id="findWaterMeterListWithPage" resultMap="BaseResultMap">
  162. <include refid="Base_Meter_Query" />
  163. order by d.id asc
  164. limit #{start,jdbcType=INTEGER},#{offset,jdbcType=INTEGER}
  165. </select>
  166. <select id="findWaterMeterById" resultMap="BaseResultMap">
  167. <include refid="Base_Meter_Query" />
  168. and d.id = #{deviceId,jdbcType=BIGINT}
  169. </select>
  170. <select id="findWaterMeterByDeviceNo" resultMap="BaseResultMap">
  171. <include refid="Base_Meter_Query" />
  172. and d.device_no = #{deviceNo,jdbcType=VARCHAR}
  173. limit 1
  174. </select>
  175. <select id="countWaterMeter" resultType="java.lang.Long">
  176. select
  177. count(1)
  178. from
  179. <include refid="Base_Meter_Query_Table"></include>
  180. WHERE
  181. <include refid="Base_Meter_Query_Where" />
  182. </select>
  183. <select id="countWaterMeterByShard" resultType="java.lang.Long">
  184. select
  185. count(1)
  186. from (
  187. <include refid="Base_Meter_Query" />
  188. limit #{shardBegin,jdbcType=INTEGER},#{shardSize,jdbcType=INTEGER}
  189. ) tmp
  190. </select>
  191. <select id="findShardWaterMeterListWithPage" resultMap="BaseResultMap">
  192. select
  193. <include refid="Base_Column_List" />
  194. from (
  195. <include refid="Base_Meter_Query" />
  196. order by d.id asc
  197. limit #{shardBegin,jdbcType=INTEGER},#{shardSize,jdbcType=INTEGER}
  198. ) tmp
  199. limit #{start,jdbcType=INTEGER},#{offset,jdbcType=INTEGER}
  200. </select>
  201. <select id="findWaterMeterByDeviceNoAndCustomerId" resultMap="BaseResultMap">
  202. <include refid="Base_Meter_Query" />
  203. and d.device_no = #{deviceNo,jdbcType=VARCHAR}
  204. and d.customer_id = #{customerId,jdbcType=INTEGER}
  205. limit 1
  206. </select>
  207. <select id="findWaterMeterByMeterNoAndCustomerId" resultMap="BaseResultMap">
  208. <include refid="Base_Meter_Query" />
  209. and d.water_meter_no = #{meterNo,jdbcType=VARCHAR}
  210. and d.customer_id = #{customerId,jdbcType=INTEGER}
  211. limit 1
  212. </select>
  213. <select id="findWaterMeterByDeviceNoList" resultMap="BaseResultMap">
  214. <include refid="Base_Meter_Query" />
  215. and d.customer_id = #{customerId,jdbcType=INTEGER}
  216. and d.device_no in <foreach collection="deviceNoList" item="deviceNo" open="(" close=")" separator=",">#{deviceNo}</foreach>
  217. </select>
  218. <select id="findWaterMeterByDeviceNoAndChildrenCustomer" resultMap="BaseResultMap">
  219. <include refid="Base_Meter_Query" />
  220. and d.device_no in <foreach collection="deviceNoList" item="deviceNo" open="(" close=")" separator=",">#{deviceNo}</foreach>
  221. and d.customer_id in
  222. <foreach collection="customerList" item="customerId" open="(" close=")" separator=",">
  223. #{customerId}
  224. </foreach>
  225. </select>
  226. <select id="findWaterMeterByMeterNoAndChildrenCustomer" resultMap="BaseResultMap">
  227. <include refid="Base_Meter_Query" />
  228. and d.water_meter_no in <foreach collection="meterNoList" item="meterNo" open="(" close=")" separator=",">#{meterNo}</foreach>
  229. and d.customer_id in
  230. <foreach collection="customerList" item="customerId" open="(" close=")" separator=",">
  231. #{customerId}
  232. </foreach>
  233. </select>
  234. <select id="findWaterMeterByDeviceNoAndCustomerList" resultMap="BaseResultMap">
  235. <include refid="Base_Meter_Query" />
  236. and d.device_no = #{deviceNo,jdbcType=INTEGER}
  237. and d.customer_id in
  238. <foreach collection="customerList" item="customerId" open="(" close=")" separator=",">
  239. #{customerId}
  240. </foreach>
  241. </select>
  242. <select id="findWaterMeterByMeterNoAndCustomerList" resultMap="BaseResultMap">
  243. <include refid="Base_Meter_Query" />
  244. and d.water_meter_no = #{meterNo,jdbcType=INTEGER}
  245. and d.customer_id in
  246. <foreach collection="customerList" item="customerId" open="(" close=")" separator=",">
  247. #{customerId}
  248. </foreach>
  249. </select>
  250. <select id="getMeterListByRange" resultMap="BaseResultMap">
  251. <include refid="Base_Meter_Query" />
  252. AND d.sys_id != - 99
  253. <if test="customers != null and customers != '' ">
  254. AND FIND_IN_SET( d.customer_id, #{customers} )
  255. </if>
  256. <if test="communitys != null and communitys != '' ">
  257. AND FIND_IN_SET( c.id, #{communitys} )
  258. </if>
  259. <if test="buildings != null and buildings != '' ">
  260. AND FIND_IN_SET( d.building_id, #{buildings} )
  261. </if>
  262. <if test="channels != null and channels != '' ">
  263. AND FIND_IN_SET( d.sys_id, #{channels} )
  264. </if>
  265. <if test="deviceTypes != null and deviceTypes != '' ">
  266. AND FIND_IN_SET( d.device_type, #{deviceTypes} )
  267. </if>
  268. </select>
  269. <insert id="batchInsert" keyProperty="waterMeter.id" parameterType="map">
  270. INSERT INTO sc_device (
  271. id,
  272. device_no,
  273. device_type,
  274. sys_id,
  275. site_id,
  276. building_id,
  277. loc_desc,
  278. manufacturer_id,
  279. device_status,
  280. `status`,
  281. create_by,
  282. update_by,
  283. date_create,
  284. date_update,
  285. water_meter_no,
  286. water_meter_file_no,
  287. customer_id,
  288. register_status
  289. ) VALUES
  290. <foreach collection="list" item="item" separator=",">(
  291. #{item.deviceId,jdbcType=BIGINT},
  292. #{item.deviceNo,jdbcType=VARCHAR},
  293. #{item.deviceTypeId,jdbcType=BIGINT},
  294. #{item.sysId,jdbcType=BIGINT},
  295. #{item.siteId,jdbcType=BIGINT},
  296. #{item.buildingId,jdbcType=BIGINT},
  297. #{item.location,jdbcType=VARCHAR},
  298. #{item.manufacturerId,jdbcType=BIGINT},
  299. #{item.deviceStatus,jdbcType=INTEGER},
  300. #{item.status,jdbcType=INTEGER},
  301. #{item.createBy,jdbcType=VARCHAR},
  302. #{item.updateBy,jdbcType=VARCHAR},
  303. #{item.dateCreate,jdbcType=TIMESTAMP},
  304. #{item.dateUpdate,jdbcType=TIMESTAMP},
  305. #{item.meterNo,jdbcType=VARCHAR},
  306. #{item.meterFileNo,jdbcType=VARCHAR},
  307. #{item.customerId,jdbcType=INTEGER},
  308. #{item.registerStatus,jdbcType=INTEGER}
  309. )
  310. </foreach>
  311. </insert>
  312. <select id="getPushMeterList" resultType="java.util.HashMap">
  313. SELECT
  314. d.id AS deviceId,
  315. d.device_no AS deviceNo,
  316. cast(d.status as SIGNED ) AS status,
  317. dt.equipment_type AS deviceType,
  318. DATE_FORMAT( d.date_create, '%Y-%m-%d' ) AS dateCreate,
  319. ifnull(m.factory,f.`name`) as factory,
  320. m.user_name AS userName,
  321. if(LENGTH(trim(ifnull(ll.new_meter_start,'0')))>0 ,ifnull(ll.new_meter_start,'0'),'0') AS beginWSV,
  322. ifnull(m.area_name,c.`name`) AS areaName,
  323. d.loc_desc AS location,
  324. d.water_meter_no AS meterNumber,
  325. ifnull(m.meter_no,d.water_meter_no) as meter_no,
  326. ifnull(m.user_address,b.`name`) AS userAddress,
  327. m.user_no AS userNumber,
  328. m.user_phone AS userPhone,
  329. DATE_FORMAT(m.archive_time,'%Y-%m-%d') AS archiveTime,
  330. m.caliber
  331. FROM
  332. sc_device d
  333. Left JOIN sc_install_list ll on (d.id = ll.device_id and ll.status =1 )
  334. LEFT JOIN sc_meter_info m ON ( CONCAT('91000',d.water_meter_no) = m.meter_no )
  335. LEFT JOIN sc_device_type dt ON ( d.device_type = dt.id )
  336. LEFT JOIN sc_building b on (d.building_id =b.id)
  337. LEFT JOIN sc_community c on (b.community = c.id)
  338. left join sc_device_manufacturer f on (dt.manufacturer_id = f.id)
  339. where d.sys_id != -99
  340. <if test="customers != null and customers != '' ">
  341. AND FIND_IN_SET( d.customer_id, #{customers} )
  342. </if>
  343. <if test="communitys != null and communitys != '' ">
  344. AND FIND_IN_SET( c.id, #{communitys} )
  345. </if>
  346. <if test="buildings != null and buildings != '' ">
  347. AND FIND_IN_SET( d.building_id, #{buildings} )
  348. </if>
  349. <if test="channels != null and channels != '' ">
  350. AND FIND_IN_SET( d.sys_id, #{channels} )
  351. </if>
  352. <if test="deviceTypes != null and deviceTypes != '' ">
  353. AND FIND_IN_SET( d.device_type, #{deviceTypes} )
  354. </if>
  355. <if test="status != null">
  356. AND d.status = #{status}
  357. </if>
  358. and d.date_update > #{beginDate ,jdbcType=TIMESTAMP }
  359. and d.date_update <![CDATA[ <= ]]> #{endDate ,jdbcType=TIMESTAMP }
  360. </select>
  361. <select id="getPushMeterListV2" resultType="com.huaxu.zoniot.model.DeviceData">
  362. select
  363. sd.id,
  364. sd.device_no,
  365. sd.water_meter_no as meter_no,
  366. sd.water_meter_file_no as file_no,
  367. sd.seal_no,
  368. sd.sys_id,
  369. sd.customer_id,
  370. sd.device_type as device_type_id,
  371. sd.manufacturer_id,
  372. sd.building_id,
  373. sb.community as community_id,
  374. sd.loc_desc,
  375. swmed.meter_reading,
  376. swmed.valve_status,
  377. sd.device_status,
  378. sd.last_receive_time,
  379. sd.status,
  380. sd.date_create,
  381. sd.date_update
  382. from sc_device sd
  383. LEFT JOIN sc_building sb on (sd.building_id =sb.id)
  384. LEFT JOIN sc_water_meter_error_days swmed on (swmed.device_id =sd.id)
  385. where sd.sys_id != -99
  386. <if test="customers != null and customers != '' ">
  387. AND FIND_IN_SET( sd.customer_id, #{customers} )
  388. </if>
  389. <if test="channels != null and channels != '' ">
  390. AND FIND_IN_SET( sd.sys_id, #{channels} )
  391. </if>
  392. <if test="status != null">
  393. AND sd.status = #{status}
  394. </if>
  395. and sd.date_update > #{beginDate ,jdbcType=TIMESTAMP }
  396. and sd.date_update <![CDATA[ <= ]]> #{endDate ,jdbcType=TIMESTAMP }
  397. </select>
  398. </mapper>