WaterMeterMapper.xml 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. </mapper>