CommunityMapper.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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.CommunityMapper">
  4. <!--auto generated Code-->
  5. <resultMap id="BaseResultMap" type="com.bz.smart_city.entity.Community">
  6. <result column="id" property="id" jdbcType="INTEGER"/>
  7. <result column="site_id" property="siteId" jdbcType="INTEGER"/>
  8. <result column="name" property="name" jdbcType="VARCHAR"/>
  9. <result column="code" property="code" jdbcType="VARCHAR"/>
  10. <result column="customer_id" property="customerId" jdbcType="INTEGER"/>
  11. <result column="province" property="province" jdbcType="INTEGER"/>
  12. <result column="city" property="city" jdbcType="INTEGER"/>
  13. <result column="region" property="region" jdbcType="INTEGER"/>
  14. <result column="longitude" property="longitude" jdbcType="VARCHAR"/>
  15. <result column="latitude" property="latitude" jdbcType="VARCHAR"/>
  16. <result column="district_id" property="districtId" jdbcType="INTEGER"/>
  17. <result column="address" property="address" jdbcType="VARCHAR"/>
  18. <result column="remark" property="remark" jdbcType="VARCHAR"/>
  19. <result column="status" property="status" jdbcType="INTEGER"/>
  20. <result column="date_create" property="dateCreate" jdbcType="TIMESTAMP"/>
  21. <result column="date_update" property="dateUpdate" jdbcType="TIMESTAMP"/>
  22. <result column="create_by" property="createBy" jdbcType="VARCHAR"/>
  23. <result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
  24. </resultMap>
  25. <!--auto generated Code-->
  26. <sql id="Base_Column_List">
  27. id,
  28. site_id,
  29. code,
  30. `name`,
  31. customer_id,
  32. province,
  33. city,
  34. region,
  35. longitude,
  36. latitude,
  37. district_id,
  38. address,
  39. remark,
  40. `status`,
  41. date_create,
  42. date_update,
  43. create_by,
  44. update_by
  45. </sql>
  46. <sql id="General_Column_List">
  47. sc.id,
  48. sc.site_id,
  49. sc.`name`,
  50. sc.code,
  51. sc.customer_id,
  52. sc.province,
  53. sc.city,
  54. sc.region,
  55. sc.longitude,
  56. sc.latitude,
  57. sc.district_id,
  58. sc.address,
  59. sc.remark,
  60. sc.`status`,
  61. sc.date_create,
  62. sc.date_update,
  63. sc.create_by,
  64. sc.update_by
  65. </sql>
  66. <!--auto generated Code-->
  67. <insert id="insert" useGeneratedKeys="true" keyProperty="community.id">
  68. INSERT INTO sc_community (
  69. id,
  70. site_id,
  71. `name`,
  72. code,
  73. customer_id,
  74. org_id,
  75. province,
  76. city,
  77. region,
  78. longitude,
  79. latitude,
  80. district_id,
  81. address,
  82. remark,
  83. `status`,
  84. date_create,
  85. date_update,
  86. create_by,
  87. update_by
  88. ) VALUES (
  89. #{community.id,jdbcType=INTEGER},
  90. #{community.siteId,jdbcType=INTEGER},
  91. #{community.name,jdbcType=VARCHAR},
  92. #{community.code,jdbcType=VARCHAR},
  93. #{community.customerId,jdbcType=INTEGER},
  94. #{community.orgId,jdbcType=INTEGER},
  95. #{community.province,jdbcType=INTEGER},
  96. #{community.city,jdbcType=INTEGER},
  97. #{community.region,jdbcType=INTEGER},
  98. #{community.longitude,jdbcType=VARCHAR},
  99. #{community.latitude,jdbcType=VARCHAR},
  100. #{community.districtId,jdbcType=INTEGER},
  101. #{community.address,jdbcType=VARCHAR},
  102. #{community.remark,jdbcType=VARCHAR},
  103. #{community.status,jdbcType=INTEGER},
  104. #{community.dateCreate,jdbcType=TIMESTAMP},
  105. #{community.dateUpdate,jdbcType=TIMESTAMP},
  106. #{community.createBy,jdbcType=VARCHAR},
  107. #{community.updateBy,jdbcType=VARCHAR}
  108. )
  109. </insert>
  110. <!--auto generated Code-->
  111. <insert id="insertSelective" useGeneratedKeys="true" keyProperty="community.id">
  112. INSERT INTO sc_community
  113. <trim prefix="(" suffix=")" suffixOverrides=",">
  114. <if test="community.id!=null"> id,</if>
  115. <if test="community.siteId!=null"> site_id,</if>
  116. <if test="community.name!=null"> `name`,</if>
  117. <if test="community.code!=null"> code,</if>
  118. <if test="community.customerId!=null"> customer_id,</if>
  119. <if test="community.province!=null"> province,</if>
  120. <if test="community.city!=null"> city,</if>
  121. <if test="community.region!=null"> region,</if>
  122. <if test="community.longitude!=null"> longitude,</if>
  123. <if test="community.latitude!=null"> latitude,</if>
  124. <if test="community.districtId!=null"> district_id,</if>
  125. <if test="community.address!=null"> address,</if>
  126. <if test="community.remark!=null"> remark,</if>
  127. <if test="community.status!=null"> `status`,</if>
  128. <if test="community.dateCreate!=null"> date_create,</if>
  129. <if test="community.dateUpdate!=null"> date_update,</if>
  130. <if test="community.createBy!=null"> create_by,</if>
  131. <if test="community.updateBy!=null"> update_by,</if>
  132. </trim>
  133. VALUES
  134. <trim prefix="(" suffix=")" suffixOverrides=",">
  135. <if test="community.id!=null">#{community.id,jdbcType=INTEGER},
  136. </if>
  137. <if test="community.siteId!=null">#{community.siteId,jdbcType=INTEGER},
  138. </if>
  139. <if test="community.name!=null">#{community.name,jdbcType=VARCHAR},
  140. </if>
  141. <if test="community.code!=null">#{community.code,jdbcType=VARCHAR},
  142. </if>
  143. <if test="community.customerId!=null">#{community.customerId,jdbcType=INTEGER},
  144. </if>
  145. <if test="community.province!=null">#{community.province,jdbcType=INTEGER},
  146. </if>
  147. <if test="community.city!=null">#{community.city,jdbcType=INTEGER},
  148. </if>
  149. <if test="community.region!=null">#{community.region,jdbcType=INTEGER},
  150. </if>
  151. <if test="community.longitude!=null"> #{community.longitude,jdbcType=VARCHAR},</if>
  152. <if test="community.latitude!=null"> #{community.latitude,jdbcType=VARCHAR},</if>
  153. <if test="community.districtId!=null">#{community.districtId,jdbcType=INTEGER},
  154. </if>
  155. <if test="community.address!=null">#{community.address,jdbcType=VARCHAR},
  156. </if>
  157. <if test="community.remark!=null">#{community.remark,jdbcType=VARCHAR},
  158. </if>
  159. <if test="community.status!=null">#{community.status,jdbcType=INTEGER},
  160. </if>
  161. <if test="community.dateCreate!=null">#{community.dateCreate,jdbcType=TIMESTAMP},
  162. </if>
  163. <if test="community.dateUpdate!=null">#{community.dateUpdate,jdbcType=TIMESTAMP},
  164. </if>
  165. <if test="community.createBy!=null">#{community.createBy,jdbcType=VARCHAR},
  166. </if>
  167. <if test="community.updateBy!=null">#{community.updateBy,jdbcType=VARCHAR},
  168. </if>
  169. </trim>
  170. </insert>
  171. <!--auto generated Code-->
  172. <insert id="insertList">
  173. INSERT INTO sc_community (
  174. id,
  175. site_id,
  176. `name`,
  177. code,
  178. customer_id,
  179. province,
  180. city,
  181. region,
  182. longitude,
  183. latitude,
  184. district_id,
  185. address,
  186. remark,
  187. `status`,
  188. date_create,
  189. date_update,
  190. create_by,
  191. update_by
  192. )VALUES
  193. <foreach collection="communitys" item="community" index="index" separator=",">
  194. (
  195. #{community.id,jdbcType=INTEGER},
  196. #{community.siteId,jdbcType=INTEGER},
  197. #{community.name,jdbcType=VARCHAR},
  198. #{community.code,jdbcType=VARCHAR},
  199. #{community.customerId,jdbcType=INTEGER},
  200. #{community.province,jdbcType=INTEGER},
  201. #{community.city,jdbcType=INTEGER},
  202. #{community.region,jdbcType=INTEGER},
  203. #{community.longitude,jdbcType=VARCHAR},
  204. #{community.latitude,jdbcType=VARCHAR},
  205. #{community.districtId,jdbcType=INTEGER},
  206. #{community.address,jdbcType=VARCHAR},
  207. #{community.remark,jdbcType=VARCHAR},
  208. #{community.status,jdbcType=INTEGER},
  209. #{community.dateCreate,jdbcType=TIMESTAMP},
  210. #{community.dateUpdate,jdbcType=TIMESTAMP},
  211. #{community.createBy,jdbcType=VARCHAR},
  212. #{community.updateBy,jdbcType=VARCHAR}
  213. )
  214. </foreach>
  215. </insert>
  216. <!--auto generated Code-->
  217. <update id="updateByPrimaryKeySelective">
  218. UPDATE sc_community
  219. <set>
  220. <if test="community.siteId != null"> site_id= #{community.siteId,jdbcType=INTEGER},</if>
  221. <if test="community.name != null"> `name`= #{community.name,jdbcType=VARCHAR},</if>
  222. <if test="community.customerId != null"> customer_id= #{community.customerId,jdbcType=INTEGER},</if>
  223. <if test="community.orgId != null"> org_id= #{community.orgId,jdbcType=INTEGER},</if>
  224. <if test="community.province != null"> province= #{community.province,jdbcType=INTEGER},</if>
  225. <if test="community.city != null"> city= #{community.city,jdbcType=INTEGER},</if>
  226. <if test="community.region != null"> region= #{community.region,jdbcType=INTEGER},</if>
  227. <if test="community.longitude != null"> longitude = #{community.longitude,jdbcType=VARCHAR},</if>
  228. <if test="community.latitude != null"> latitude = #{community.latitude,jdbcType=VARCHAR},</if>
  229. <if test="community.districtId != null"> district_id= #{community.districtId,jdbcType=INTEGER},</if>
  230. <if test="community.address != null"> address= #{community.address,jdbcType=VARCHAR},</if>
  231. <if test="community.remark != null"> remark= #{community.remark,jdbcType=VARCHAR},</if>
  232. <if test="community.status != null"> `status`= #{community.status,jdbcType=INTEGER},</if>
  233. <if test="community.dateCreate != null"> date_create= #{community.dateCreate,jdbcType=TIMESTAMP},</if>
  234. <if test="community.dateUpdate != null"> date_update= #{community.dateUpdate,jdbcType=TIMESTAMP},</if>
  235. <if test="community.createBy != null"> create_by= #{community.createBy,jdbcType=VARCHAR},</if>
  236. <if test="community.updateBy != null"> update_by= #{community.updateBy,jdbcType=VARCHAR}</if>
  237. </set>
  238. WHERE id = #{community.id,jdbcType=INTEGER}
  239. </update>
  240. <select id="findBySiteId" resultType="com.bz.smart_city.dto.CommunityDto">
  241. select
  242. sc.*,
  243. sa1.name as province_name,
  244. sa2.name as city_name,
  245. sa3.name as region_name
  246. from sc_community sc
  247. left join sc_area sa1 on sc.province =sa1.id
  248. left join sc_area sa2 on sc.city=sa2.id
  249. left join sc_area sa3 on sc.region=sa3.id
  250. where sc.status = 1
  251. <if test="siteId != null"> and sc.site_id = #{siteId} </if>
  252. <if test="customerIds != null and customerIds.size() != 0">
  253. and customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  254. </if>
  255. </select>
  256. <select id="findByCustomerId" resultType="com.bz.smart_city.dto.CommunityDto">
  257. select
  258. sc.*,
  259. sa1.name as province_name,
  260. sa2.name as city_name,
  261. sa3.name as region_name
  262. from sc_community sc
  263. left join sc_area sa1 on sc.province =sa1.id
  264. left join sc_area sa2 on sc.city=sa2.id
  265. left join sc_area sa3 on sc.region=sa3.id
  266. where sc.status = 1
  267. <if test="customerId != null"> and sc.customer_id = #{customerId} </if>
  268. </select>
  269. <select id="findByIds" resultMap="BaseResultMap">
  270. select id,name,province,city,region from sc_community where status = 1
  271. and id in <foreach collection="ids" item="item" open="(" separator="," close=")">#{item}</foreach>
  272. order by name asc
  273. </select>
  274. <select id="queryList" resultType="com.bz.smart_city.dto.CommunityDto">
  275. select
  276. sc.id as id,
  277. sc.name as name ,
  278. sc.code as code,
  279. sc.province as province,
  280. sc.city as city,
  281. sc.region as region,
  282. sc.longitude as longitude,
  283. sc.latitude as latitude,
  284. sc.address as address,
  285. sa1.name as province_name,
  286. sa2.name as city_name,
  287. sa3.name as region_name
  288. from sc_community sc
  289. left join sc_area sa1 on sc.province =sa1.id
  290. left join sc_area sa2 on sc.city=sa2.id
  291. left join sc_area sa3 on sc.region=sa3.id
  292. where sc.status = 1
  293. <if test="param.siteId "> and sc.site_id = #{param.siteId} </if>
  294. <if test="param.customerId != null and param.customerId != 0 "> and sc.customer_id = #{param.customerId} </if>
  295. <if test="param.province != null"> and sc.province = #{param.province} </if>
  296. <if test="param.city != null"> and sc.city = #{param.city} </if>
  297. <if test="param.region != null"> and sc.region = #{param.region} </if>
  298. <if test="param.id != null"> and sc.id = #{param.id}</if>
  299. <if test="param.name != null and param.name != '' "> and sc.name like #{param.name}</if>
  300. </select>
  301. <select id="queryCommunity" resultType="com.bz.smart_city.dto.CommunityDto">
  302. select
  303. sc.id as id,
  304. sc.name as name ,
  305. sc.code as code,
  306. sc.province as province,
  307. sc.city as city,
  308. sc.region as region,
  309. sc.longitude as longitude,
  310. sc.latitude as latitude,
  311. sc.address as address,
  312. sa1.name as province_name,
  313. sa2.name as city_name,
  314. sa3.name as region_name
  315. from sc_community sc
  316. left join sc_area sa1 on sc.province =sa1.id
  317. left join sc_area sa2 on sc.city=sa2.id
  318. left join sc_area sa3 on sc.region=sa3.id
  319. where sc.status = 1
  320. <if test="param.siteId != null"> and sc.site_id = #{param.siteId} </if>
  321. <if test="param.customerId != null and param.customerId != 0 "> and sc.customer_id = #{param.customerId} </if>
  322. <if test="param.province != null"> and sc.province = #{param.province} </if>
  323. <if test="param.city != null"> and sc.city = #{param.city} </if>
  324. <if test="param.region != null"> and sc.region = #{param.region} </if>
  325. <if test="param.id != null"> and sc.id = #{param.id}</if>
  326. <if test="param.name != null and param.name != '' "> and sc.name like #{param.name}</if>
  327. <if test="customerIds != null and customerIds.size() != 0">
  328. and sc.customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  329. </if>
  330. </select>
  331. <select id="getList" resultType="com.bz.smart_city.dto.CommunityDto">
  332. select
  333. sc.*,
  334. sa1.name as province_name,
  335. sa2.name as city_name,
  336. sa3.name as region_name,
  337. so.name as org_name
  338. from sc_community sc
  339. left join sc_area sa1 on sa1.id = sc.province
  340. left join sc_area sa2 on sa2.id = sc.city
  341. left join sc_area sa3 on sa3.id = sc.region
  342. left join sc_organization so on so.id=sc.org_id
  343. where sc.status = 1
  344. <if test="siteId != null"> and sc.site_id = #{siteId} </if>
  345. <if test="customerId != null"> and sc.customer_id = #{customerId} </if>
  346. <if test="communityName != null and communityName != ''"> and sc.name like concat('%',#{communityName} ,'%')</if>
  347. <if test="province != null"> and sc.province = #{province}</if>
  348. <if test="city != null"> and sc.city = #{city}</if>
  349. <if test="region != null"> and sc.region = #{region}</if>
  350. order by sc.date_create desc
  351. </select>
  352. <select id="findByNameUnique" resultType="java.lang.Integer">
  353. select count(1) from sc_community where status = 1 and province = #{province} and city = #{city} and region = #{region} and name = #{name}
  354. <if test="siteId != null"> and site_id = #{siteId} </if>
  355. <if test="id != null"> and id != #{id}</if>
  356. </select>
  357. <select id="findByName" resultMap="BaseResultMap">
  358. SELECT <include refid="Base_Column_List"></include> from sc_community where status = 1 and site_id = #{siteId} and name = #{communityName}
  359. </select>
  360. <select id="findByNameV2" resultMap="BaseResultMap">
  361. SELECT <include refid="Base_Column_List"></include> from sc_community where status = 1 and site_id = #{siteId}
  362. and province = #{province} and city = #{city} and region = #{region} and name = #{communityName}
  363. </select>
  364. <select id="findById" resultMap="BaseResultMap">
  365. select
  366. <include refid="Base_Column_List"/>
  367. from sc_community
  368. where status = 1 and id=#{id}
  369. </select>
  370. <select id="getBySiteId" resultMap="BaseResultMap">
  371. select <include refid="Base_Column_List"></include> from sc_community where status = 1 and site_id = #{siteId}
  372. </select>
  373. <select id="findCommunityContainBuilding" resultType="com.bz.smart_city.dto.CommunityDto">
  374. select
  375. <include refid="Base_Column_List" />
  376. from sc_community
  377. where status = 1
  378. and site_id = #{siteId}
  379. and id in (select distinct b.community from sc_building b where b.site_id = #{siteId})
  380. <if test="name != null and name !='' ">
  381. and name like concat('%',#{name} ,'%')
  382. </if>
  383. </select>
  384. <select id="getMaxCodeBySiteId" resultMap="BaseResultMap">
  385. select MAX(ifnull(code,0))+1 code
  386. from sc_community
  387. where status = 1 and site_id = #{siteId}
  388. </select>
  389. <select id="getListByCustomerIds" resultType="com.bz.smart_city.dto.CommunityDto">
  390. select
  391. sc.*,
  392. sa1.name as province_name,
  393. sa2.name as city_name,
  394. sa3.name as region_name,
  395. sc.name as org_name
  396. from sc_community sc
  397. left join sc_area sa1 on sa1.id = sc.province
  398. left join sc_area sa2 on sa2.id = sc.city
  399. left join sc_area sa3 on sa3.id = sc.region
  400. left join sc_organization so on so.id = sc.org_id
  401. where sc.status = 1
  402. <if test="siteId != null"> and sc.site_id = #{siteId} </if>
  403. <if test="customerIds != null">
  404. and sc.customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  405. </if>
  406. <if test="communityName != null and communityName != ''"> and sc.name like concat('%',#{communityName} ,'%')</if>
  407. <if test="province != null"> and sc.province = #{province}</if>
  408. <if test="city != null"> and sc.city = #{city}</if>
  409. <if test="region != null"> and sc.region = #{region}</if>
  410. order by sc.date_create desc
  411. </select>
  412. <select id="findCommunityByArea" parameterType="com.bz.smart_city.dto.syncdata.AreaRequstData" resultType="com.bz.smart_city.dto.syncdata.AreaResponseData">
  413. select a.address,b.manger_name,a.`name`, a.city,a.customer_id,a.latitude,
  414. a.longitude,a.province,a.region,a.remark,b.`name` regionName
  415. from sc_community a join sc_area b on a.region=b.id
  416. <where>
  417. <if test="name != null"> and a.name = #{name} </if>
  418. <if test="province != null"> and a.province = #{province} </if>
  419. <if test="city != null"> and a.city = #{city} </if>
  420. <if test="region != null"> and a.region = #{region} </if>
  421. <if test="communityId != null"> and a.id = #{communityId} </if>
  422. </where>
  423. limit 1
  424. </select>
  425. </mapper>