ConcentratorMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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.ConcentratorMapper">
  4. <resultMap id="BaseResultMap" type="com.bz.smart_city.entity.Concentrator">
  5. <!--@mbg.generated-->
  6. <!--@Table sc_concentrator-->
  7. <id column="id" property="id" />
  8. <result column="site_id" property="siteId" />
  9. <result column="customer_id" property="customerId" />
  10. <result column="serial_number" property="serialNumber" />
  11. <result column="name" property="name" />
  12. <result column="type" property="type" />
  13. <result column="province" property="province" />
  14. <result column="city" property="city" />
  15. <result column="region" property="region" />
  16. <result column="building_id" property="buildingId" />
  17. <result column="address" property="address" />
  18. <result column="device_status" property="deviceStatus" />
  19. <result column="device_type" property="deviceType" />
  20. <result column="baud_rate" property="baudRate" />
  21. <result column="ip" property="ip" />
  22. <result column="port" property="port" />
  23. <result column="sim_no" property="simNo" />
  24. <result column="date_create" property="dateCreate" />
  25. <result column="date_update" property="dateUpdate" />
  26. <result column="create_by" property="createBy" />
  27. <result column="update_by" property="updateBy" />
  28. <result column="status" property="status" />
  29. </resultMap>
  30. <sql id="Base_Column_List">
  31. <!--@mbg.generated-->
  32. id, site_id, customer_id, serial_number, `name`, `type`, province, city, region,
  33. building_id, address, device_status, device_type, baud_rate, ip, port, sim_no, date_create,
  34. date_update, create_by, update_by, `status`
  35. </sql>
  36. <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.bz.smart_city.entity.Concentrator" useGeneratedKeys="true">
  37. <!--@mbg.generated-->
  38. insert into sc_concentrator
  39. <trim prefix="(" suffix=")" suffixOverrides=",">
  40. <if test="siteId != null">
  41. site_id,
  42. </if>
  43. <if test="customerId != null">
  44. customer_id,
  45. </if>
  46. <if test="serialNumber != null">
  47. serial_number,
  48. </if>
  49. <if test="name != null">
  50. `name`,
  51. </if>
  52. <if test="type != null">
  53. `type`,
  54. </if>
  55. <if test="province != null">
  56. province,
  57. </if>
  58. <if test="city != null">
  59. city,
  60. </if>
  61. <if test="region != null">
  62. region,
  63. </if>
  64. <if test="buildingId != null">
  65. building_id,
  66. </if>
  67. <if test="address != null">
  68. address,
  69. </if>
  70. <if test="deviceStatus != null">
  71. device_status,
  72. </if>
  73. <if test="deviceType != null">
  74. device_type,
  75. </if>
  76. <if test="baudRate != null">
  77. baud_rate,
  78. </if>
  79. <if test="ip != null">
  80. ip,
  81. </if>
  82. <if test="port != null">
  83. port,
  84. </if>
  85. <if test="simNo != null">
  86. sim_no,
  87. </if>
  88. <if test="dateCreate != null">
  89. date_create,
  90. </if>
  91. <if test="dateUpdate != null">
  92. date_update,
  93. </if>
  94. <if test="createBy != null">
  95. create_by,
  96. </if>
  97. <if test="updateBy != null">
  98. update_by,
  99. </if>
  100. <if test="status != null">
  101. `status`,
  102. </if>
  103. </trim>
  104. <trim prefix="values (" suffix=")" suffixOverrides=",">
  105. <if test="siteId != null">
  106. #{siteId},
  107. </if>
  108. <if test="customerId != null">
  109. #{customerId},
  110. </if>
  111. <if test="serialNumber != null">
  112. #{serialNumber},
  113. </if>
  114. <if test="name != null">
  115. #{name},
  116. </if>
  117. <if test="type != null">
  118. #{type},
  119. </if>
  120. <if test="province != null">
  121. #{province},
  122. </if>
  123. <if test="city != null">
  124. #{city},
  125. </if>
  126. <if test="region != null">
  127. #{region},
  128. </if>
  129. <if test="buildingId != null">
  130. #{buildingId},
  131. </if>
  132. <if test="address != null">
  133. #{address},
  134. </if>
  135. <if test="deviceStatus != null">
  136. #{deviceStatus},
  137. </if>
  138. <if test="deviceType != null">
  139. #{deviceType},
  140. </if>
  141. <if test="baudRate != null">
  142. #{baudRate},
  143. </if>
  144. <if test="ip != null">
  145. #{ip},
  146. </if>
  147. <if test="port != null">
  148. #{port},
  149. </if>
  150. <if test="simNo != null">
  151. #{simNo},
  152. </if>
  153. <if test="dateCreate != null">
  154. #{dateCreate},
  155. </if>
  156. <if test="dateUpdate != null">
  157. #{dateUpdate},
  158. </if>
  159. <if test="createBy != null">
  160. #{createBy},
  161. </if>
  162. <if test="updateBy != null">
  163. #{updateBy},
  164. </if>
  165. <if test="status != null">
  166. #{status},
  167. </if>
  168. </trim>
  169. </insert>
  170. <update id="updateByPrimaryKeySelective" parameterType="com.bz.smart_city.entity.Concentrator">
  171. <!--@mbg.generated-->
  172. update sc_concentrator
  173. <set>
  174. <if test="siteId != null">
  175. site_id = #{siteId},
  176. </if>
  177. <if test="customerId != null">
  178. customer_id = #{customerId},
  179. </if>
  180. <if test="serialNumber != null">
  181. serial_number = #{serialNumber},
  182. </if>
  183. <if test="name != null">
  184. `name` = #{name},
  185. </if>
  186. <if test="type != null">
  187. `type` = #{type},
  188. </if>
  189. <if test="province != null">
  190. province = #{province},
  191. </if>
  192. <if test="city != null">
  193. city = #{city},
  194. </if>
  195. <if test="region != null">
  196. region = #{region},
  197. </if>
  198. <if test="buildingId != null">
  199. building_id = #{buildingId},
  200. </if>
  201. <if test="address != null">
  202. address = #{address},
  203. </if>
  204. <if test="deviceStatus != null">
  205. device_status = #{deviceStatus},
  206. </if>
  207. <if test="deviceType != null">
  208. device_type = #{deviceType},
  209. </if>
  210. <if test="baudRate != null">
  211. baud_rate = #{baudRate},
  212. </if>
  213. <if test="ip != null">
  214. ip = #{ip},
  215. </if>
  216. <if test="port != null">
  217. port = #{port},
  218. </if>
  219. <if test="simNo != null">
  220. sim_no = #{simNo},
  221. </if>
  222. <if test="dateCreate != null">
  223. date_create = #{dateCreate},
  224. </if>
  225. <if test="dateUpdate != null">
  226. date_update = #{dateUpdate},
  227. </if>
  228. <if test="createBy != null">
  229. create_by = #{createBy},
  230. </if>
  231. <if test="updateBy != null">
  232. update_by = #{updateBy},
  233. </if>
  234. <if test="status != null">
  235. `status` = #{status},
  236. </if>
  237. </set>
  238. where id = #{id}
  239. </update>
  240. <insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
  241. <!--@mbg.generated-->
  242. insert into sc_concentrator
  243. (site_id, customer_id, serial_number, `name`, `type`, province, city, region, building_id,
  244. address, device_status, device_type, baud_rate, ip, port, sim_no, date_create,
  245. date_update, create_by, update_by, `status`)
  246. values
  247. <foreach collection="list" item="item" separator=",">
  248. (#{item.siteId}, #{item.customerId}, #{item.serialNumber}, #{item.name}, #{item.type},
  249. #{item.province}, #{item.city}, #{item.region}, #{item.buildingId}, #{item.address},
  250. #{item.deviceStatus}, #{item.deviceType}, #{item.baudRate}, #{item.ip}, #{item.port},
  251. #{item.simNo}, #{item.dateCreate}, #{item.dateUpdate}, #{item.createBy}, #{item.updateBy},
  252. #{item.status})
  253. </foreach>
  254. </insert>
  255. <select id="getList" resultType="com.bz.smart_city.dto.ConcentratorDto">
  256. select
  257. scon.*,
  258. (select count(1) from sc_channel_number where status = 1 and concentrator_id = scon.id) as channel_num,
  259. (select count(1) from sc_collector where status = 1 and concentrator_id = scon.id) as collector_num,
  260. (select count(1) from sc_water_related_device where status = 1 and concentrator_id = scon.id) as device_num,
  261. sc.customer_name,
  262. sdt.equipment_type,
  263. sdt.model,
  264. sdm.name manufacturer_name,
  265. sb.name as building_name,
  266. sb.community
  267. from sc_concentrator scon
  268. left join sc_customer sc on(sc.id = scon.customer_id)
  269. left join sc_device_type sdt on (sdt.id = scon.device_type)
  270. left join sc_device_manufacturer sdm on (sdm.id = sdt.manufacturer_id )
  271. left join sc_building sb on (sb.id = scon.building_id)
  272. where scon.status = 1
  273. <if test="siteId != null"> and scon.site_id = #{siteId}</if>
  274. <if test="serialNumber != null and serialNumber != ''"> and scon.serial_number LIKE concat('%',#{serialNumber},'%')</if>
  275. <if test="deviceStatus != null"> and scon.device_status = #{deviceStatus}</if>
  276. <if test="customerId != null"> and scon.customer_id = #{customerId}</if>
  277. <if test="address != null and address != ''"> and scon.address LIKE concat('%',#{address},'%')</if>
  278. <if test="provinceId != null"> and sb.province = #{provinceId}</if>
  279. <if test="cityId != null"> and sb.city = #{cityId}</if>
  280. <if test="regionId != null"> and sb.region = #{regionId}</if>
  281. <if test="communityId != null"> and sb.community = #{communityId}</if>
  282. <if test="buildingId != null"> and sb.id = #{buildingId}</if>
  283. <if test="customerIds != null and customerIds.size() != 0">
  284. and customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  285. </if>
  286. order by scon.date_create desc
  287. </select>
  288. <select id="findList" resultType="com.bz.smart_city.dto.ConcentratorDto">
  289. select
  290. scon.*
  291. from sc_concentrator scon
  292. where scon.status = 1
  293. <if test="siteId != null"> and scon.site_id = #{siteId}</if>
  294. <if test="serialNumber != null and serialNumber != ''"> and scon.serial_number LIKE concat('%',#{serialNumber},'%')</if>
  295. <if test="customerIds != null and customerIds.size() != 0">
  296. and scon.customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  297. </if>
  298. </select>
  299. <select id="getAreaList" resultType="com.bz.smart_city.dto.BuildingSelectInfoDto">
  300. select
  301. b.id,
  302. b.name,
  303. b.province,
  304. b.city,
  305. b.region,
  306. b.community,
  307. b.longitude,
  308. b.latitude,
  309. t1.device_count
  310. from sc_building b
  311. right join (
  312. select scon.building_id,count(1) as device_count
  313. from sc_concentrator scon
  314. where scon.status = 1
  315. <if test="siteId != null"> and scon.site_id = #{siteId}</if>
  316. <if test="serialNumber != null and serialNumber != ''"> and scon.serial_number LIKE concat('%',#{serialNumber},'%')</if>
  317. <if test="deviceStatus != null"> and scon.device_status = #{deviceStatus}</if>
  318. <if test="customerId != null"> and scon.customer_id = #{customerId}</if>
  319. <if test="address != null and address != ''"> and scon.address LIKE concat('%',#{address},'%')</if>
  320. <if test="customerIds != null and customerIds.size() != 0">
  321. and scon.customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  322. </if>
  323. GROUP BY scon.building_id
  324. ) t1 on (t1.building_id = b.id)
  325. where b.status = 1
  326. </select>
  327. <select id="findBySerialNumberUnique" resultType="int">
  328. select count(1) from sc_concentrator where status = 1 and serial_number = #{serialNumber}
  329. <if test="id != null"> and id != #{id}</if>
  330. </select>
  331. <resultMap id="lazyLoadConcentrator" type="com.bz.smart_city.dto.ConcentratorDto" extends="BaseResultMap">
  332. <result column="id" property="id" jdbcType="INTEGER"/>
  333. <result column="serial_number" property="serialNumber" jdbcType="VARCHAR"/>
  334. <collection property="channelNumberList" ofType="com.bz.smart_city.entity.ChannelNumber" select="com.bz.smart_city.dao.ChannelNumberMapper.getList"
  335. column="id"></collection>
  336. <collection property="collectorList" ofType="com.bz.smart_city.entity.Collector" select="com.bz.smart_city.dao.CollectorMapper.findList"
  337. column="id"></collection>
  338. </resultMap>
  339. <select id="getLazyList" resultMap="lazyLoadConcentrator">
  340. select
  341. id,
  342. serial_number
  343. from sc_concentrator where status = 1 and site_id = #{siteId}
  344. <if test="customerIds != null and customerIds.size() != 0">
  345. and customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  346. </if>
  347. </select>
  348. <select id="findName" resultMap="BaseResultMap">
  349. select id,serial_number from sc_concentrator where status = 1 and site_id = #{siteId} and serial_number = #{serialNumber}
  350. </select>
  351. <select id="findById" resultMap="BaseResultMap">
  352. select * from sc_concentrator where status = 1 and id = #{concentratorId}
  353. </select>
  354. </mapper>