WaterMeterMapper.xml 15 KB

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