CollectorMapper.xml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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.CollectorMapper">
  4. <resultMap id="BaseResultMap" type="com.bz.smart_city.entity.Collector">
  5. <!--@mbg.generated-->
  6. <!--@Table sc_collector-->
  7. <id column="id" property="id" />
  8. <result column="site_id" property="siteId" />
  9. <result column="customer_id" property="customerId" />
  10. <result column="building_id" property="buildingId" />
  11. <result column="collector_no" property="collectorNo" />
  12. <result column="concentrator_id" property="concentratorId" />
  13. <result column="device_type" property="deviceType" />
  14. <result column="address" property="address" />
  15. <result column="status" property="status" />
  16. <result column="remark" property="remark" />
  17. <result column="date_create" property="dateCreate" />
  18. <result column="date_update" property="dateUpdate" />
  19. <result column="create_by" property="createBy" />
  20. <result column="update_by" property="updateBy" />
  21. </resultMap>
  22. <sql id="Base_Column_List">
  23. <!--@mbg.generated-->
  24. id, site_id, customer_id, building_id, collector_no, concentrator_id, device_type,
  25. address, `status`, remark, date_create, date_update, create_by, update_by
  26. </sql>
  27. <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.bz.smart_city.entity.Collector" useGeneratedKeys="true">
  28. <!--@mbg.generated-->
  29. insert into sc_collector
  30. <trim prefix="(" suffix=")" suffixOverrides=",">
  31. <if test="siteId != null">
  32. site_id,
  33. </if>
  34. <if test="customerId != null">
  35. customer_id,
  36. </if>
  37. <if test="buildingId != null">
  38. building_id,
  39. </if>
  40. <if test="collectorNo != null">
  41. collector_no,
  42. </if>
  43. <if test="concentratorId != null">
  44. concentrator_id,
  45. </if>
  46. <if test="deviceType != null">
  47. device_type,
  48. </if>
  49. <if test="address != null">
  50. address,
  51. </if>
  52. <if test="status != null">
  53. `status`,
  54. </if>
  55. <if test="remark != null">
  56. remark,
  57. </if>
  58. <if test="dateCreate != null">
  59. date_create,
  60. </if>
  61. <if test="dateUpdate != null">
  62. date_update,
  63. </if>
  64. <if test="createBy != null">
  65. create_by,
  66. </if>
  67. <if test="updateBy != null">
  68. update_by,
  69. </if>
  70. </trim>
  71. <trim prefix="values (" suffix=")" suffixOverrides=",">
  72. <if test="siteId != null">
  73. #{siteId},
  74. </if>
  75. <if test="customerId != null">
  76. #{customerId},
  77. </if>
  78. <if test="buildingId != null">
  79. #{buildingId},
  80. </if>
  81. <if test="collectorNo != null">
  82. #{collectorNo},
  83. </if>
  84. <if test="concentratorId != null">
  85. #{concentratorId},
  86. </if>
  87. <if test="deviceType != null">
  88. #{deviceType},
  89. </if>
  90. <if test="address != null">
  91. #{address},
  92. </if>
  93. <if test="status != null">
  94. #{status},
  95. </if>
  96. <if test="remark != null">
  97. #{remark},
  98. </if>
  99. <if test="dateCreate != null">
  100. #{dateCreate},
  101. </if>
  102. <if test="dateUpdate != null">
  103. #{dateUpdate},
  104. </if>
  105. <if test="createBy != null">
  106. #{createBy},
  107. </if>
  108. <if test="updateBy != null">
  109. #{updateBy},
  110. </if>
  111. </trim>
  112. </insert>
  113. <update id="updateByPrimaryKeySelective" parameterType="com.bz.smart_city.entity.Collector">
  114. <!--@mbg.generated-->
  115. update sc_collector
  116. <set>
  117. <if test="siteId != null">
  118. site_id = #{siteId},
  119. </if>
  120. <if test="customerId != null">
  121. customer_id = #{customerId},
  122. </if>
  123. <if test="buildingId != null">
  124. building_id = #{buildingId},
  125. </if>
  126. <if test="collectorNo != null">
  127. collector_no = #{collectorNo},
  128. </if>
  129. <if test="concentratorId != null">
  130. concentrator_id = #{concentratorId},
  131. </if>
  132. <if test="deviceType != null">
  133. device_type = #{deviceType},
  134. </if>
  135. <if test="address != null">
  136. address = #{address},
  137. </if>
  138. <if test="status != null">
  139. `status` = #{status},
  140. </if>
  141. <if test="remark != null">
  142. remark = #{remark},
  143. </if>
  144. <if test="dateCreate != null">
  145. date_create = #{dateCreate},
  146. </if>
  147. <if test="dateUpdate != null">
  148. date_update = #{dateUpdate},
  149. </if>
  150. <if test="createBy != null">
  151. create_by = #{createBy},
  152. </if>
  153. <if test="updateBy != null">
  154. update_by = #{updateBy},
  155. </if>
  156. </set>
  157. where id = #{id}
  158. </update>
  159. <insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
  160. <!--@mbg.generated-->
  161. insert into sc_collector
  162. (site_id, customer_id, building_id, collector_no, concentrator_id, device_type, address,
  163. `status`, remark, date_create, date_update, create_by, update_by)
  164. values
  165. <foreach collection="list" item="item" separator=",">
  166. (#{item.siteId}, #{item.customerId}, #{item.buildingId}, #{item.collectorNo}, #{item.concentratorId},
  167. #{item.deviceType}, #{item.address}, #{item.status}, #{item.remark}, #{item.dateCreate},
  168. #{item.dateUpdate}, #{item.createBy}, #{item.updateBy})
  169. </foreach>
  170. </insert>
  171. <select id="getList" resultType="com.bz.smart_city.dto.CollectorDto">
  172. select
  173. soll.*,
  174. scon.serial_number,
  175. sb.name building_name,
  176. scu.customer_name,
  177. sb.province,
  178. sb.city,
  179. sb.region,
  180. sb.community
  181. from sc_collector soll
  182. left join sc_concentrator scon on(scon.id = soll.concentrator_id)
  183. left join sc_building sb on(sb.id = soll.building_id)
  184. left join sc_customer scu on(scu.id = soll.customer_id)
  185. where soll.status = 1
  186. <if test="siteId != null"> and soll.site_id = #{siteId}</if>
  187. <if test="concentratorId != null"> and soll.concentrator_id = #{concentratorId}</if>
  188. <if test="collectorNo != null and collectorNo != ''"> and soll.collector_no LIKE concat('%',#{collectorNo},'%')</if>
  189. <if test="serialNumber != null and serialNumber != ''"> and scon.serial_number LIKE concat('%',#{serialNumber},'%')</if>
  190. <if test="address != null and address != ''"> and soll.address LIKE concat('%',#{address},'%')</if>
  191. <if test="provinceId != null"> and sb.province = #{provinceId}</if>
  192. <if test="cityId != null"> and sb.city = #{cityId}</if>
  193. <if test="regionId != null"> and sb.region = #{regionId}</if>
  194. <if test="communityId != null"> and sb.community = #{communityId}</if>
  195. <if test="buildingId != null"> and sb.id = #{buildingId}</if>
  196. <if test="customerIds != null and customerIds.size() != 0">
  197. and soll.customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  198. </if>
  199. order by soll.date_create desc
  200. </select>
  201. <select id="findList" resultType="com.bz.smart_city.entity.Collector">
  202. select id,collector_no from sc_collector where status = 1 and concentrator_id = #{concentratorId}
  203. </select>
  204. <select id="getAreaList" resultType="com.bz.smart_city.dto.BuildingSelectInfoDto">
  205. select
  206. b.id,
  207. b.name,
  208. b.province,
  209. b.city,
  210. b.region,
  211. b.community,
  212. b.longitude,
  213. b.latitude,
  214. t1.device_count
  215. from sc_building b
  216. right join (
  217. select soll.building_id,count(1) as device_count
  218. from sc_collector soll
  219. left join sc_concentrator scon on(scon.id = soll.concentrator_id)
  220. where soll.status = 1
  221. <if test="siteId != null"> and soll.site_id = #{siteId}</if>
  222. <if test="collectorNo != null and collectorNo != ''"> and soll.collector_no LIKE concat('%',#{collectorNo},'%')</if>
  223. <if test="serialNumber != null and serialNumber != ''"> and scon.serial_number LIKE concat('%',#{serialNumber},'%')</if>
  224. <if test="address != null and address != ''"> and soll.address LIKE concat('%',#{address},'%')</if>
  225. <if test="customerIds != null and customerIds.size() != 0">
  226. and soll.customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  227. </if>
  228. GROUP BY soll.building_id
  229. ) t1 on (t1.building_id = b.id)
  230. where b.status = 1
  231. </select>
  232. <select id="countByConcentratorId" resultType="java.lang.Integer">
  233. select count(1) from sc_collector where status = 1 and concentrator_id = #{concentratorId}
  234. </select>
  235. <select id="findByCollectorNoUnique" resultType="int">
  236. select count(1) from sc_collector where status = 1 and concentrator_id = #{concentratorId} and collector_no = #{collectorNo}
  237. <if test="id != null"> and id != #{id}</if>
  238. </select>
  239. <select id="findName" resultMap="BaseResultMap">
  240. select id,collector_no from sc_collector where status = 1 and concentrator_id = #{concentratorId} and collector_no = #{collectorNo}
  241. </select>
  242. </mapper>