WaterMeterReplaceLogMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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.WaterMeterReplaceLogMapper">
  4. <!--auto generated Code-->
  5. <resultMap id="BaseResultMap" type="com.bz.smart_city.entity.WaterMeterReplaceLog">
  6. <!--@mbg.generated-->
  7. <!--@Table sc_water_meter_replace_log-->
  8. <id column="id" property="id" />
  9. <result column="site_id" property="siteId" />
  10. <result column="main_log_id" property="mainLogId" />
  11. <result column="device_id" property="deviceId" />
  12. <result column="replace_method" property="replaceMethod" />
  13. <result column="new_device_type_id" property="newDeviceTypeId" />
  14. <result column="old_device_type_id" property="oldDeviceTypeId" />
  15. <result column="new_water_no" property="newWaterNo" />
  16. <result column="old_water_no" property="oldWaterNo" />
  17. <result column="new_begin_wsv" property="newBeginWsv" />
  18. <result column="old_end_wsv" property="oldEndWsv" />
  19. <result column="new_device_no" property="newDeviceNo" />
  20. <result column="old_device_no" property="oldDeviceNo" />
  21. <result column="new_sim_no" property="newSimNo" />
  22. <result column="old_sim_no" property="oldSimNo" />
  23. <result column="new_device_flag_no" property="newDeviceFlagNo" />
  24. <result column="old_device_flag_no" property="oldDeviceFlagNo" />
  25. <result column="remark" property="remark" />
  26. <result column="status" property="status" />
  27. <result column="replace_username" property="replaceUsername" />
  28. <result column="replace_user_phone" property="replaceUserPhone" />
  29. <result column="date_create" property="dateCreate" />
  30. <result column="date_update" property="dateUpdate" />
  31. <result column="create_by" property="createBy" />
  32. <result column="update_by" property="updateBy" />
  33. </resultMap>
  34. <sql id="Base_Column_List">
  35. <!--@mbg.generated-->
  36. id, site_id, main_log_id, device_id, replace_method, new_device_type_id, old_device_type_id,
  37. new_water_no, old_water_no, new_begin_wsv, old_end_wsv, new_device_no, old_device_no,
  38. new_sim_no, old_sim_no, new_device_flag_no, old_device_flag_no, remark, `status`,
  39. replace_username, replace_user_phone, date_create, date_update, create_by, update_by
  40. </sql>
  41. <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.bz.smart_city.entity.WaterMeterReplaceLog" useGeneratedKeys="true">
  42. <!--@mbg.generated-->
  43. insert into sc_water_meter_replace_log
  44. <trim prefix="(" suffix=")" suffixOverrides=",">
  45. <if test="siteId != null">
  46. site_id,
  47. </if>
  48. <if test="mainLogId != null">
  49. main_log_id,
  50. </if>
  51. <if test="deviceId != null">
  52. device_id,
  53. </if>
  54. <if test="replaceMethod != null">
  55. replace_method,
  56. </if>
  57. <if test="newDeviceTypeId != null">
  58. new_device_type_id,
  59. </if>
  60. <if test="oldDeviceTypeId != null">
  61. old_device_type_id,
  62. </if>
  63. <if test="newWaterNo != null">
  64. new_water_no,
  65. </if>
  66. <if test="oldWaterNo != null">
  67. old_water_no,
  68. </if>
  69. <if test="newBeginWsv != null">
  70. new_begin_wsv,
  71. </if>
  72. <if test="oldEndWsv != null">
  73. old_end_wsv,
  74. </if>
  75. <if test="newDeviceNo != null">
  76. new_device_no,
  77. </if>
  78. <if test="oldDeviceNo != null">
  79. old_device_no,
  80. </if>
  81. <if test="newSimNo != null">
  82. new_sim_no,
  83. </if>
  84. <if test="oldSimNo != null">
  85. old_sim_no,
  86. </if>
  87. <if test="newDeviceFlagNo != null">
  88. new_device_flag_no,
  89. </if>
  90. <if test="oldDeviceFlagNo != null">
  91. old_device_flag_no,
  92. </if>
  93. <if test="remark != null">
  94. remark,
  95. </if>
  96. <if test="status != null">
  97. `status`,
  98. </if>
  99. <if test="replaceUsername != null">
  100. replace_username,
  101. </if>
  102. <if test="replaceUserPhone != null">
  103. replace_user_phone,
  104. </if>
  105. <if test="dateCreate != null">
  106. date_create,
  107. </if>
  108. <if test="dateUpdate != null">
  109. date_update,
  110. </if>
  111. <if test="createBy != null">
  112. create_by,
  113. </if>
  114. <if test="updateBy != null">
  115. update_by,
  116. </if>
  117. </trim>
  118. <trim prefix="values (" suffix=")" suffixOverrides=",">
  119. <if test="siteId != null">
  120. #{siteId},
  121. </if>
  122. <if test="mainLogId != null">
  123. #{mainLogId},
  124. </if>
  125. <if test="deviceId != null">
  126. #{deviceId},
  127. </if>
  128. <if test="replaceMethod != null">
  129. #{replaceMethod},
  130. </if>
  131. <if test="newDeviceTypeId != null">
  132. #{newDeviceTypeId},
  133. </if>
  134. <if test="oldDeviceTypeId != null">
  135. #{oldDeviceTypeId},
  136. </if>
  137. <if test="newWaterNo != null">
  138. #{newWaterNo},
  139. </if>
  140. <if test="oldWaterNo != null">
  141. #{oldWaterNo},
  142. </if>
  143. <if test="newBeginWsv != null">
  144. #{newBeginWsv},
  145. </if>
  146. <if test="oldEndWsv != null">
  147. #{oldEndWsv},
  148. </if>
  149. <if test="newDeviceNo != null">
  150. #{newDeviceNo},
  151. </if>
  152. <if test="oldDeviceNo != null">
  153. #{oldDeviceNo},
  154. </if>
  155. <if test="newSimNo != null">
  156. #{newSimNo},
  157. </if>
  158. <if test="oldSimNo != null">
  159. #{oldSimNo},
  160. </if>
  161. <if test="newDeviceFlagNo != null">
  162. #{newDeviceFlagNo},
  163. </if>
  164. <if test="oldDeviceFlagNo != null">
  165. #{oldDeviceFlagNo},
  166. </if>
  167. <if test="remark != null">
  168. #{remark},
  169. </if>
  170. <if test="status != null">
  171. #{status},
  172. </if>
  173. <if test="replaceUsername != null">
  174. #{replaceUsername},
  175. </if>
  176. <if test="replaceUserPhone != null">
  177. #{replaceUserPhone},
  178. </if>
  179. <if test="dateCreate != null">
  180. #{dateCreate},
  181. </if>
  182. <if test="dateUpdate != null">
  183. #{dateUpdate},
  184. </if>
  185. <if test="createBy != null">
  186. #{createBy},
  187. </if>
  188. <if test="updateBy != null">
  189. #{updateBy},
  190. </if>
  191. </trim>
  192. </insert>
  193. <update id="updateByPrimaryKeySelective" parameterType="com.bz.smart_city.entity.WaterMeterReplaceLog">
  194. <!--@mbg.generated-->
  195. update sc_water_meter_replace_log
  196. <set>
  197. <if test="siteId != null">
  198. site_id = #{siteId},
  199. </if>
  200. <if test="mainLogId != null">
  201. main_log_id = #{mainLogId},
  202. </if>
  203. <if test="deviceId != null">
  204. device_id = #{deviceId},
  205. </if>
  206. <if test="replaceMethod != null">
  207. replace_method = #{replaceMethod},
  208. </if>
  209. <if test="newDeviceTypeId != null">
  210. new_device_type_id = #{newDeviceTypeId},
  211. </if>
  212. <if test="oldDeviceTypeId != null">
  213. old_device_type_id = #{oldDeviceTypeId},
  214. </if>
  215. <if test="newWaterNo != null">
  216. new_water_no = #{newWaterNo},
  217. </if>
  218. <if test="oldWaterNo != null">
  219. old_water_no = #{oldWaterNo},
  220. </if>
  221. <if test="newBeginWsv != null">
  222. new_begin_wsv = #{newBeginWsv},
  223. </if>
  224. <if test="oldEndWsv != null">
  225. old_end_wsv = #{oldEndWsv},
  226. </if>
  227. <if test="newDeviceNo != null">
  228. new_device_no = #{newDeviceNo},
  229. </if>
  230. <if test="oldDeviceNo != null">
  231. old_device_no = #{oldDeviceNo},
  232. </if>
  233. <if test="newSimNo != null">
  234. new_sim_no = #{newSimNo},
  235. </if>
  236. <if test="oldSimNo != null">
  237. old_sim_no = #{oldSimNo},
  238. </if>
  239. <if test="newDeviceFlagNo != null">
  240. new_device_flag_no = #{newDeviceFlagNo},
  241. </if>
  242. <if test="oldDeviceFlagNo != null">
  243. old_device_flag_no = #{oldDeviceFlagNo},
  244. </if>
  245. <if test="remark != null">
  246. remark = #{remark},
  247. </if>
  248. <if test="status != null">
  249. `status` = #{status},
  250. </if>
  251. <if test="replaceUsername != null">
  252. replace_username = #{replaceUsername},
  253. </if>
  254. <if test="replaceUserPhone != null">
  255. replace_user_phone = #{replaceUserPhone},
  256. </if>
  257. <if test="dateCreate != null">
  258. date_create = #{dateCreate},
  259. </if>
  260. <if test="dateUpdate != null">
  261. date_update = #{dateUpdate},
  262. </if>
  263. <if test="createBy != null">
  264. create_by = #{createBy},
  265. </if>
  266. <if test="updateBy != null">
  267. update_by = #{updateBy},
  268. </if>
  269. </set>
  270. where id = #{id}
  271. </update>
  272. <insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
  273. <!--@mbg.generated-->
  274. insert into sc_water_meter_replace_log
  275. (site_id, main_log_id, device_id, replace_method, new_device_type_id, old_device_type_id,
  276. new_water_no, old_water_no, new_begin_wsv, old_end_wsv, new_device_no, old_device_no,
  277. new_sim_no, old_sim_no, new_device_flag_no, old_device_flag_no, remark, `status`,
  278. replace_username, replace_user_phone, date_create, date_update, create_by, update_by
  279. )
  280. values
  281. <foreach collection="list" item="item" separator=",">
  282. (#{item.siteId}, #{item.mainLogId}, #{item.deviceId}, #{item.replaceMethod}, #{item.newDeviceTypeId},
  283. #{item.oldDeviceTypeId}, #{item.newWaterNo}, #{item.oldWaterNo}, #{item.newBeginWsv},
  284. #{item.oldEndWsv}, #{item.newDeviceNo}, #{item.oldDeviceNo}, #{item.newSimNo},
  285. #{item.oldSimNo}, #{item.newDeviceFlagNo}, #{item.oldDeviceFlagNo}, #{item.remark},
  286. #{item.status}, #{item.replaceUsername}, #{item.replaceUserPhone}, #{item.dateCreate},
  287. #{item.dateUpdate}, #{item.createBy}, #{item.updateBy})
  288. </foreach>
  289. </insert>
  290. <select id="findByMainLogId" resultMap="BaseResultMap">
  291. select <include refid="Base_Column_List"/> from sc_water_meter_replace_log where status = 1 and main_log_id = #{mainLogId}
  292. </select>
  293. <select id="findList" resultType="com.bz.smart_city.dto.WaterMeterReplaceLogDto">
  294. select
  295. rl.*,
  296. d.water_meter_file_no,
  297. d.loc_desc,
  298. sc.customer_name,
  299. sb.name as building_name,
  300. sil.is_accepted,
  301. sdt1.equipment_type as new_equipment_type,
  302. sdt1.model as new_model,
  303. sdm1.name as new_manufacturer_name,
  304. sdt2.equipment_type as old_equipment_type,
  305. sdt2.model as old_model,
  306. sdm2.name as old_manufacturer_name
  307. from sc_water_meter_replace_log rl
  308. left join sc_device d on(d.id = rl.device_id)
  309. left join sc_customer sc on(sc.id = d.customer_id)
  310. left join sc_building sb on(sb.id = d.building_id)
  311. left join sc_install_list sil on(sil.device_id = rl.device_id)
  312. left join sc_device_type sdt1 on(sdt1.id = rl.new_device_type_id)
  313. left join sc_device_manufacturer sdm1 on(sdm1.id = sdt1.manufacturer_id)
  314. left join sc_device_type sdt2 on(sdt2.id = rl.old_device_type_id)
  315. left join sc_device_manufacturer sdm2 on(sdm2.id = sdt2.manufacturer_id)
  316. <if test="programItems != null and programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = d.id and sdd.status = 1)</if>
  317. where rl.status = 1 and d.status = 1
  318. <if test="siteId != null"> and d.site_id = #{siteId}</if>
  319. <if test="deviceId != null"> and rl.device_id = #{deviceId}</if>
  320. <if test="deviceNo != null and deviceNo != ''"> and (
  321. rl.new_device_no LIKE concat('%',#{deviceNo},'%') or rl.old_device_no LIKE concat('%',#{deviceNo},'%') or
  322. rl.new_water_no LIKE concat('%',#{deviceNo},'%') or rl.old_water_no LIKE concat('%',#{deviceNo},'%') or
  323. d.water_meter_file_no LIKE concat('%',#{deviceNo},'%')
  324. )</if>
  325. <if test="replaceMethod != null"> and rl.replace_method = #{replaceMethod}</if>
  326. <if test="customerId != null"> and d.customer_id = #{customerId}</if>
  327. <if test="replaceUsername != null and replaceUsername != ''"> and rl.replace_username LIKE concat('%',#{replaceUsername},'%')</if>
  328. <if test="isAccepted != null and isAccepted == 1"> and sil.is_accepted = #{isAccepted}</if>
  329. <if test="isAccepted != null and isAccepted == 0"> and (sil.is_accepted = #{isAccepted} or sil.is_accepted is null)</if>
  330. <if test="provinceId != null"> and sb.province = #{provinceId}</if>
  331. <if test="cityId != null"> and sb.city = #{cityId}</if>
  332. <if test="regionId != null"> and sb.region = #{regionId}</if>
  333. <if test="communityId != null"> and sb.community = #{communityId}</if>
  334. <if test="buildingId != null"> and d.building_id = #{buildingId}</if>
  335. <if test="startDate != null"> and rl.date_create <![CDATA[ >= ]]> #{startDate}</if>
  336. <if test="endDate != null"> and rl.date_create <![CDATA[ <= ]]> #{endDate}</if>
  337. <if test="programItems != null and programItems.size() != 0"> and
  338. <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  339. sdd.${item.dimensionCode} = #{item.dimensionValue}
  340. </foreach>
  341. </if>
  342. order by rl.date_create desc
  343. </select>
  344. <select id="findList_COUNT" resultType="Long">
  345. select
  346. count(1)
  347. from sc_water_meter_replace_log rl
  348. left join sc_device d on(d.id = rl.device_id)
  349. left join sc_building sb on(sb.id = d.building_id)
  350. <if test="isAccepted != null">left join sc_install_list sil on(sil.device_id = rl.device_id)</if>
  351. <if test="programItems != null and programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = d.id and sdd.status = 1)</if>
  352. where rl.status = 1 and d.status = 1
  353. <if test="siteId != null"> and d.site_id = #{siteId}</if>
  354. <if test="deviceId != null"> and rl.device_id = #{deviceId}</if>
  355. <if test="deviceNo != null and deviceNo != ''"> and (
  356. rl.new_device_no LIKE concat('%',#{deviceNo},'%') or rl.old_device_no LIKE concat('%',#{deviceNo},'%') or
  357. rl.new_water_no LIKE concat('%',#{deviceNo},'%') or rl.old_water_no LIKE concat('%',#{deviceNo},'%') or
  358. d.water_meter_file_no LIKE concat('%',#{deviceNo},'%')
  359. )</if>
  360. <if test="replaceMethod != null"> and rl.replace_method = #{replaceMethod}</if>
  361. <if test="customerId != null"> and d.customer_id = #{customerId}</if>
  362. <if test="replaceUsername != null and replaceUsername != ''"> and rl.replace_username LIKE concat('%',#{replaceUsername},'%')</if>
  363. <if test="isAccepted != null and isAccepted == 1"> and sil.is_accepted = #{isAccepted}</if>
  364. <if test="isAccepted != null and isAccepted == 0"> and (sil.is_accepted = #{isAccepted} or sil.is_accepted is null)</if>
  365. <if test="provinceId != null"> and sb.province = #{provinceId}</if>
  366. <if test="cityId != null"> and sb.city = #{cityId}</if>
  367. <if test="regionId != null"> and sb.region = #{regionId}</if>
  368. <if test="communityId != null"> and sb.community = #{communityId}</if>
  369. <if test="buildingId != null"> and d.building_id = #{buildingId}</if>
  370. <if test="startDate != null"> and rl.date_create <![CDATA[ >= ]]> #{startDate}</if>
  371. <if test="endDate != null"> and rl.date_create <![CDATA[ <= ]]> #{endDate}</if>
  372. <if test="programItems != null and programItems.size() != 0"> and
  373. <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  374. sdd.${item.dimensionCode} = #{item.dimensionValue}
  375. </foreach>
  376. </if>
  377. </select>
  378. <select id="getAreaList" resultType="com.bz.smart_city.dto.BuildingSelectInfoDto">
  379. select
  380. b.id,
  381. b.name,
  382. b.province,
  383. b.city,
  384. b.region,
  385. b.community,
  386. b.longitude,
  387. b.latitude,
  388. t1.device_count
  389. from sc_building b
  390. right join (
  391. select sd.building_id,count(1) as device_count
  392. from sc_water_meter_replace_log rl
  393. left join sc_device sd on(sd.id = rl.device_id)
  394. <if test="isAccepted != null">left join sc_install_list sil on(sil.device_id = rl.device_id)</if>
  395. <if test="programItems != null and programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = d.id and sdd.status = 1)</if>
  396. where rl.status = 1 and sd.status = 1
  397. <if test="siteId != null"> and sd.site_id = #{siteId}</if>
  398. <if test="deviceId != null"> and rl.device_id = #{deviceId}</if>
  399. <if test="deviceNo != null and deviceNo != ''"> and (
  400. rl.new_device_no LIKE concat('%',#{deviceNo},'%') or rl.old_device_no LIKE concat('%',#{deviceNo},'%') or
  401. rl.new_water_no LIKE concat('%',#{deviceNo},'%') or rl.old_water_no LIKE concat('%',#{deviceNo},'%') or
  402. sd.water_meter_file_no LIKE concat('%',#{deviceNo},'%')
  403. )</if>
  404. <if test="replaceMethod != null"> and rl.replace_method = #{replaceMethod}</if>
  405. <if test="customerId != null"> and sd.customer_id = #{customerId}</if>
  406. <if test="replaceUsername != null and replaceUsername != ''"> and rl.replace_username LIKE concat('%',#{replaceUsername},'%')</if>
  407. <if test="isAccepted != null and isAccepted == 1"> and sil.is_accepted = #{isAccepted}</if>
  408. <if test="isAccepted != null and isAccepted == 0"> and (sil.is_accepted = #{isAccepted} or sil.is_accepted is null)</if>
  409. <if test="startDate != null"> and rl.date_create <![CDATA[ >= ]]> #{startDate}</if>
  410. <if test="endDate != null"> and rl.date_create <![CDATA[ <= ]]> #{endDate}</if>
  411. <if test="programItems != null and programItems.size() != 0"> and
  412. <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  413. sdd.${item.dimensionCode} = #{item.dimensionValue}
  414. </foreach>
  415. </if>
  416. GROUP BY sd.building_id
  417. ) t1 on (t1.building_id = b.id)
  418. where b.status = 1
  419. </select>
  420. </mapper>