CommunityMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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. province,
  75. city,
  76. region,
  77. longitude,
  78. latitude,
  79. district_id,
  80. address,
  81. remark,
  82. `status`,
  83. date_create,
  84. date_update,
  85. create_by,
  86. update_by
  87. ) VALUES (
  88. #{community.id,jdbcType=INTEGER},
  89. #{community.siteId,jdbcType=INTEGER},
  90. #{community.name,jdbcType=VARCHAR},
  91. #{community.code,jdbcType=VARCHAR},
  92. #{community.customerId,jdbcType=INTEGER},
  93. #{community.province,jdbcType=INTEGER},
  94. #{community.city,jdbcType=INTEGER},
  95. #{community.region,jdbcType=INTEGER},
  96. #{community.longitude,jdbcType=VARCHAR},
  97. #{community.latitude,jdbcType=VARCHAR},
  98. #{community.districtId,jdbcType=INTEGER},
  99. #{community.address,jdbcType=VARCHAR},
  100. #{community.remark,jdbcType=VARCHAR},
  101. #{community.status,jdbcType=INTEGER},
  102. #{community.dateCreate,jdbcType=TIMESTAMP},
  103. #{community.dateUpdate,jdbcType=TIMESTAMP},
  104. #{community.createBy,jdbcType=VARCHAR},
  105. #{community.updateBy,jdbcType=VARCHAR}
  106. )
  107. </insert>
  108. <!--auto generated Code-->
  109. <insert id="insertSelective" useGeneratedKeys="true" keyProperty="community.id">
  110. INSERT INTO sc_community
  111. <trim prefix="(" suffix=")" suffixOverrides=",">
  112. <if test="community.id!=null"> id,</if>
  113. <if test="community.siteId!=null"> site_id,</if>
  114. <if test="community.name!=null"> `name`,</if>
  115. <if test="community.code!=null"> code,</if>
  116. <if test="community.customerId!=null"> customer_id,</if>
  117. <if test="community.province!=null"> province,</if>
  118. <if test="community.city!=null"> city,</if>
  119. <if test="community.region!=null"> region,</if>
  120. <if test="community.longitude!=null"> longitude,</if>
  121. <if test="community.latitude!=null"> latitude,</if>
  122. <if test="community.districtId!=null"> district_id,</if>
  123. <if test="community.address!=null"> address,</if>
  124. <if test="community.remark!=null"> remark,</if>
  125. <if test="community.status!=null"> `status`,</if>
  126. <if test="community.dateCreate!=null"> date_create,</if>
  127. <if test="community.dateUpdate!=null"> date_update,</if>
  128. <if test="community.createBy!=null"> create_by,</if>
  129. <if test="community.updateBy!=null"> update_by,</if>
  130. </trim>
  131. VALUES
  132. <trim prefix="(" suffix=")" suffixOverrides=",">
  133. <if test="community.id!=null">#{community.id,jdbcType=INTEGER},
  134. </if>
  135. <if test="community.siteId!=null">#{community.siteId,jdbcType=INTEGER},
  136. </if>
  137. <if test="community.name!=null">#{community.name,jdbcType=VARCHAR},
  138. </if>
  139. <if test="community.code!=null">#{community.code,jdbcType=VARCHAR},
  140. </if>
  141. <if test="community.customerId!=null">#{community.customerId,jdbcType=INTEGER},
  142. </if>
  143. <if test="community.province!=null">#{community.province,jdbcType=INTEGER},
  144. </if>
  145. <if test="community.city!=null">#{community.city,jdbcType=INTEGER},
  146. </if>
  147. <if test="community.region!=null">#{community.region,jdbcType=INTEGER},
  148. </if>
  149. <if test="community.longitude!=null"> #{community.longitude,jdbcType=VARCHAR},</if>
  150. <if test="community.latitude!=null"> #{community.latitude,jdbcType=VARCHAR},</if>
  151. <if test="community.districtId!=null">#{community.districtId,jdbcType=INTEGER},
  152. </if>
  153. <if test="community.address!=null">#{community.address,jdbcType=VARCHAR},
  154. </if>
  155. <if test="community.remark!=null">#{community.remark,jdbcType=VARCHAR},
  156. </if>
  157. <if test="community.status!=null">#{community.status,jdbcType=INTEGER},
  158. </if>
  159. <if test="community.dateCreate!=null">#{community.dateCreate,jdbcType=TIMESTAMP},
  160. </if>
  161. <if test="community.dateUpdate!=null">#{community.dateUpdate,jdbcType=TIMESTAMP},
  162. </if>
  163. <if test="community.createBy!=null">#{community.createBy,jdbcType=VARCHAR},
  164. </if>
  165. <if test="community.updateBy!=null">#{community.updateBy,jdbcType=VARCHAR},
  166. </if>
  167. </trim>
  168. </insert>
  169. <!--auto generated Code-->
  170. <insert id="insertList">
  171. INSERT INTO sc_community (
  172. id,
  173. site_id,
  174. `name`,
  175. code,
  176. customer_id,
  177. province,
  178. city,
  179. region,
  180. longitude,
  181. latitude,
  182. district_id,
  183. address,
  184. remark,
  185. `status`,
  186. date_create,
  187. date_update,
  188. create_by,
  189. update_by
  190. )VALUES
  191. <foreach collection="communitys" item="community" index="index" separator=",">
  192. (
  193. #{community.id,jdbcType=INTEGER},
  194. #{community.siteId,jdbcType=INTEGER},
  195. #{community.name,jdbcType=VARCHAR},
  196. #{community.code,jdbcType=VARCHAR},
  197. #{community.customerId,jdbcType=INTEGER},
  198. #{community.province,jdbcType=INTEGER},
  199. #{community.city,jdbcType=INTEGER},
  200. #{community.region,jdbcType=INTEGER},
  201. #{community.longitude,jdbcType=VARCHAR},
  202. #{community.latitude,jdbcType=VARCHAR},
  203. #{community.districtId,jdbcType=INTEGER},
  204. #{community.address,jdbcType=VARCHAR},
  205. #{community.remark,jdbcType=VARCHAR},
  206. #{community.status,jdbcType=INTEGER},
  207. #{community.dateCreate,jdbcType=TIMESTAMP},
  208. #{community.dateUpdate,jdbcType=TIMESTAMP},
  209. #{community.createBy,jdbcType=VARCHAR},
  210. #{community.updateBy,jdbcType=VARCHAR}
  211. )
  212. </foreach>
  213. </insert>
  214. <!--auto generated Code-->
  215. <update id="updateByPrimaryKeySelective">
  216. UPDATE sc_community
  217. <set>
  218. <if test="community.siteId != null"> site_id= #{community.siteId,jdbcType=INTEGER},</if>
  219. <if test="community.name != null"> `name`= #{community.name,jdbcType=VARCHAR},</if>
  220. <if test="community.customerId != null"> customer_id= #{community.customerId,jdbcType=INTEGER},</if>
  221. <if test="community.province != null"> province= #{community.province,jdbcType=INTEGER},</if>
  222. <if test="community.city != null"> city= #{community.city,jdbcType=INTEGER},</if>
  223. <if test="community.region != null"> region= #{community.region,jdbcType=INTEGER},</if>
  224. <if test="community.longitude != null"> longitude = #{community.longitude,jdbcType=VARCHAR},</if>
  225. <if test="community.latitude != null"> latitude = #{community.latitude,jdbcType=VARCHAR},</if>
  226. <if test="community.districtId != null"> district_id= #{community.districtId,jdbcType=INTEGER},</if>
  227. <if test="community.address != null"> address= #{community.address,jdbcType=VARCHAR},</if>
  228. <if test="community.remark != null"> remark= #{community.remark,jdbcType=VARCHAR},</if>
  229. <if test="community.status != null"> `status`= #{community.status,jdbcType=INTEGER},</if>
  230. <if test="community.dateCreate != null"> date_create= #{community.dateCreate,jdbcType=TIMESTAMP},</if>
  231. <if test="community.dateUpdate != null"> date_update= #{community.dateUpdate,jdbcType=TIMESTAMP},</if>
  232. <if test="community.createBy != null"> create_by= #{community.createBy,jdbcType=VARCHAR},</if>
  233. <if test="community.updateBy != null"> update_by= #{community.updateBy,jdbcType=VARCHAR}</if>
  234. </set>
  235. WHERE id = #{community.id,jdbcType=INTEGER}
  236. </update>
  237. <select id="findBySiteId" resultType="com.bz.smart_city.dto.CommunityDto">
  238. select
  239. sc.*,
  240. sa1.name as province_name,
  241. sa2.name as city_name,
  242. sa3.name as region_name
  243. from sc_community sc
  244. left join sc_area sa1 on sc.province =sa1.id
  245. left join sc_area sa2 on sc.city=sa2.id
  246. left join sc_area sa3 on sc.region=sa3.id
  247. where sc.status = 1
  248. <if test="siteId != null"> and sc.site_id = #{siteId} </if>
  249. </select>
  250. <select id="findByCustomerId" resultType="com.bz.smart_city.dto.CommunityDto">
  251. select
  252. sc.*,
  253. sa1.name as province_name,
  254. sa2.name as city_name,
  255. sa3.name as region_name
  256. from sc_community sc
  257. left join sc_area sa1 on sc.province =sa1.id
  258. left join sc_area sa2 on sc.city=sa2.id
  259. left join sc_area sa3 on sc.region=sa3.id
  260. where sc.status = 1
  261. <if test="customerId != null"> and sc.customer_id = #{customerId} </if>
  262. </select>
  263. <select id="queryList" resultType="com.bz.smart_city.dto.CommunityDto">
  264. select
  265. sc.id as id,
  266. sc.name as name ,
  267. sc.code as code,
  268. sc.province as province,
  269. sc.city as city,
  270. sc.region as region,
  271. sc.longitude as longitude,
  272. sc.latitude as latitude,
  273. sc.address as address,
  274. sa1.name as province_name,
  275. sa2.name as city_name,
  276. sa3.name as region_name
  277. from sc_community sc
  278. left join sc_area sa1 on sc.province =sa1.id
  279. left join sc_area sa2 on sc.city=sa2.id
  280. left join sc_area sa3 on sc.region=sa3.id
  281. where sc.status = 1
  282. <if test="param.customerId != null and param.customerId != 0 "> and sc.customer_id = #{param.customerId} </if>
  283. <if test="param.province != null"> and sc.province = #{param.province} </if>
  284. <if test="param.city != null"> and sc.city = #{param.city} </if>
  285. <if test="param.region != null"> and sc.region = #{param.region} </if>
  286. <if test="param.id != null"> and sc.id = #{param.id}</if>
  287. <if test="param.name != null and param.name != '' "> and sc.name like #{param.name}</if>
  288. </select>
  289. <select id="getList" resultType="com.bz.smart_city.dto.CommunityDto">
  290. select <include refid="General_Column_List"></include>,
  291. sa1.name as province_name,
  292. sa2.name as city_name,
  293. sa3.name as region_name
  294. from sc_community sc
  295. left join sc_area sa1 on sa1.id = sc.province
  296. left join sc_area sa2 on sa2.id = sc.city
  297. left join sc_area sa3 on sa3.id = sc.region
  298. where sc.status = 1
  299. <if test="siteId != null"> and site_id = #{siteId} </if>
  300. <if test="customerId != null"> and customer_id = #{customerId} </if>
  301. <if test="communityName != null and communityName != ''"> and sc.name like concat('%',#{communityName} ,'%')</if>
  302. <if test="province != null"> and sc.province = #{province}</if>
  303. <if test="city != null"> and sc.city = #{city}</if>
  304. <if test="region != null"> and sc.region = #{region}</if>
  305. order by sc.date_create desc
  306. </select>
  307. <select id="findByNameUnique" resultType="java.lang.Integer">
  308. select count(1) from sc_community where status = 1 and province = #{province} and city = #{city} and region = #{region} and name = #{name}
  309. <if test="siteId != null"> and site_id = #{siteId} </if>
  310. <if test="id != null"> and id != #{id}</if>
  311. </select>
  312. <select id="findById" resultMap="BaseResultMap">
  313. select
  314. <include refid="Base_Column_List"/>
  315. from sc_community
  316. where status = 1 and id=#{id}
  317. </select>
  318. <select id="getBySiteId" resultMap="BaseResultMap">
  319. select <include refid="Base_Column_List"></include> from sc_community where status = 1
  320. and site_id = #{siteId}
  321. </select>
  322. <select id="getByCustomerId" resultMap="BaseResultMap">
  323. select <include refid="Base_Column_List"></include> from sc_community where status = 1
  324. and customer_id = #{customerId}
  325. </select>
  326. <select id="getMaxCodeBySiteId" resultMap="BaseResultMap">
  327. select MAX(ifnull(code,0))+1 code
  328. from sc_community
  329. where status = 1 and site_id = #{siteId}
  330. </select>
  331. <select id="getListByCustomerIds" resultType="com.bz.smart_city.dto.CommunityDto">
  332. select <include refid="General_Column_List"></include>,
  333. sa1.name as province_name,
  334. sa2.name as city_name,
  335. sa3.name as region_name
  336. from sc_community sc
  337. left join sc_area sa1 on sa1.id = sc.province
  338. left join sc_area sa2 on sa2.id = sc.city
  339. left join sc_area sa3 on sa3.id = sc.region
  340. where sc.status = 1
  341. <if test="siteId != null"> and site_id = #{siteId} </if>
  342. <if test="customerIds != null">
  343. and customer_id in <foreach collection="customerIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  344. </if>
  345. <if test="communityName != null and communityName != ''"> and sc.name like concat('%',#{communityName} ,'%')</if>
  346. <if test="province != null"> and sc.province = #{province}</if>
  347. <if test="city != null"> and sc.city = #{city}</if>
  348. <if test="region != null"> and sc.region = #{region}</if>
  349. order by sc.date_create desc
  350. </select>
  351. <select id="findByNameV2" resultMap="BaseResultMap">
  352. SELECT <include refid="Base_Column_List"></include> from sc_community where status = 1 and site_id = #{siteId}
  353. and province = #{province} and city = #{city} and region = #{region} and name = #{communityName}
  354. </select>
  355. <select id="findByName" resultMap="BaseResultMap">
  356. SELECT <include refid="Base_Column_List"></include>
  357. from sc_community
  358. where status = 1 and name = #{communityName}
  359. <if test="siteId != null"> and site_id = #{siteId} </if>
  360. </select>
  361. </mapper>