SiteMapper.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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.zoniot.ccrc.dao.SiteMapper">
  4. <!--auto generated Code-->
  5. <resultMap id="BaseResultMap" type="com.zoniot.ccrc.entity.Site">
  6. <result column="create_date" property="createDate" jdbcType="TIMESTAMP"/>
  7. <result column="create_by" property="createBy" jdbcType="VARCHAR"/>
  8. <result column="update_date" property="updateDate" jdbcType="TIMESTAMP"/>
  9. <result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
  10. <result column="id" property="id" jdbcType="INTEGER"/>
  11. <result column="name" property="name" jdbcType="VARCHAR"/>
  12. <result column="website" property="website" jdbcType="VARCHAR"/>
  13. <result column="logo_url" property="logoUrl" jdbcType="VARCHAR"/>
  14. <result column="status" property="status" jdbcType="INTEGER"/>
  15. <result column="type" property="type" jdbcType="INTEGER"/>
  16. <result column="customer_id" property="customerId" jdbcType="INTEGER"/>
  17. <result column="account" property="account" jdbcType="VARCHAR"/>
  18. </resultMap>
  19. <!--auto generated Code-->
  20. <sql id="Base_Column_List">
  21. create_date,
  22. create_by,
  23. update_date,
  24. update_by,
  25. id,
  26. name,
  27. website,
  28. logo_url,
  29. status,
  30. type,
  31. customer_id,
  32. account
  33. </sql>
  34. <!--auto generated Code-->
  35. <insert id="insert" useGeneratedKeys="true" keyProperty="site.id">
  36. INSERT INTO sc_site (
  37. create_date,
  38. create_by,
  39. update_date,
  40. update_by,
  41. id,
  42. name,
  43. website,
  44. logo_url,
  45. status,
  46. type,
  47. customer_id,
  48. account
  49. ) VALUES (
  50. #{site.createDate,jdbcType=TIMESTAMP},
  51. #{site.createBy,jdbcType=VARCHAR},
  52. #{site.updateDate,jdbcType=TIMESTAMP},
  53. #{site.updateBy,jdbcType=VARCHAR},
  54. #{site.id,jdbcType=INTEGER},
  55. #{site.name,jdbcType=VARCHAR},
  56. #{site.website,jdbcType=VARCHAR},
  57. #{site.logoUrl,jdbcType=VARCHAR},
  58. #{site.status,jdbcType=INTEGER},
  59. #{site.type,jdbcType=INTEGER},
  60. #{site.customerId,jdbcType=INTEGER},
  61. #{site.account,jdbcType=VARCHAR}
  62. )
  63. </insert>
  64. <!--auto generated Code-->
  65. <insert id="insertSelective" useGeneratedKeys="true" keyProperty="site.id">
  66. INSERT INTO sc_site
  67. <trim prefix="(" suffix=")" suffixOverrides=",">
  68. <if test="site.createDate!=null"> create_date,</if>
  69. <if test="site.createBy!=null"> create_by,</if>
  70. <if test="site.updateDate!=null"> update_date,</if>
  71. <if test="site.updateBy!=null"> update_by,</if>
  72. <if test="site.id!=null"> id,</if>
  73. <if test="site.name!=null"> name,</if>
  74. <if test="site.website!=null"> website,</if>
  75. <if test="site.logoUrl!=null"> logo_url,</if>
  76. <if test="site.status!=null"> status,</if>
  77. <if test="site.type!=null"> type,</if>
  78. <if test="site.customerId!=null"> customer_id,</if>
  79. <if test="site.account!=null"> account,</if>
  80. </trim>
  81. VALUES
  82. <trim prefix="(" suffix=")" suffixOverrides=",">
  83. <if test="site.createDate!=null">#{site.createDate,jdbcType=TIMESTAMP},
  84. </if>
  85. <if test="site.createBy!=null">#{site.createBy,jdbcType=VARCHAR},
  86. </if>
  87. <if test="site.updateDate!=null">#{site.updateDate,jdbcType=TIMESTAMP},
  88. </if>
  89. <if test="site.updateBy!=null">#{site.updateBy,jdbcType=VARCHAR},
  90. </if>
  91. <if test="site.id!=null">#{site.id,jdbcType=INTEGER},
  92. </if>
  93. <if test="site.name!=null">#{site.name,jdbcType=VARCHAR},
  94. </if>
  95. <if test="site.website!=null">#{site.website,jdbcType=VARCHAR},
  96. </if>
  97. <if test="site.logoUrl!=null">#{site.logoUrl,jdbcType=VARCHAR},
  98. </if>
  99. <if test="site.status!=null">#{site.status,jdbcType=INTEGER},
  100. </if>
  101. <if test="site.type!=null">#{site.type,jdbcType=INTEGER},
  102. </if>
  103. <if test="site.customerId!=null">#{site.customerId,jdbcType=INTEGER},
  104. </if>
  105. <if test="site.account!=null">#{site.account,jdbcType=VARCHAR},
  106. </if>
  107. </trim>
  108. </insert>
  109. <!--auto generated Code-->
  110. <insert id="insertList">
  111. INSERT INTO sc_site (
  112. create_date,
  113. create_by,
  114. update_date,
  115. update_by,
  116. id,
  117. name,
  118. website,
  119. logo_url,
  120. status,
  121. type,
  122. customer_id,
  123. account
  124. )VALUES
  125. <foreach collection="sites" item="site" index="index" separator=",">
  126. (
  127. #{site.createDate,jdbcType=TIMESTAMP},
  128. #{site.createBy,jdbcType=VARCHAR},
  129. #{site.updateDate,jdbcType=TIMESTAMP},
  130. #{site.updateBy,jdbcType=VARCHAR},
  131. #{site.id,jdbcType=INTEGER},
  132. #{site.name,jdbcType=VARCHAR},
  133. #{site.website,jdbcType=VARCHAR},
  134. #{site.logoUrl,jdbcType=VARCHAR},
  135. #{site.status,jdbcType=INTEGER},
  136. #{site.type,jdbcType=INTEGER},
  137. #{site.customerId,jdbcType=INTEGER}
  138. )
  139. </foreach>
  140. </insert>
  141. <!--auto generated Code-->
  142. <update id="updateByPrimaryKeySelective">
  143. UPDATE sc_site
  144. <set>
  145. <if test="site.createDate != null"> create_date= #{site.createDate,jdbcType=TIMESTAMP},</if>
  146. <if test="site.createBy != null"> create_by= #{site.createBy,jdbcType=VARCHAR},</if>
  147. <if test="site.updateDate != null"> update_date= #{site.updateDate,jdbcType=TIMESTAMP},</if>
  148. <if test="site.updateBy != null"> update_by= #{site.updateBy,jdbcType=VARCHAR},</if>
  149. <if test="site.name != null"> name= #{site.name,jdbcType=VARCHAR},</if>
  150. <if test="site.website != null"> website= #{site.website,jdbcType=VARCHAR},</if>
  151. <if test="site.logoUrl != null"> logo_url= #{site.logoUrl,jdbcType=VARCHAR},</if>
  152. <if test="site.status != null"> status= #{site.status,jdbcType=INTEGER},</if>
  153. <if test="site.type != null"> type= #{site.type,jdbcType=INTEGER},</if>
  154. <if test="site.customerId != null"> customer_id= #{site.customerId,jdbcType=INTEGER},</if>
  155. <if test="site.account != null"> account= #{site.account,jdbcType=VARCHAR}</if>
  156. </set>
  157. WHERE id = #{site.id,jdbcType=INTEGER}
  158. </update>
  159. <select id="getList" resultType="com.zoniot.ccrc.dto.SiteDto">
  160. select
  161. ss.*,ifnull(a.buildingCount,0)buildingCount,ifnull(b.deviceCount,0)deviceCount,
  162. (SELECT GROUP_CONCAT(su.username SEPARATOR '、') FROM sc_site_user ssu LEFT JOIN sc_user su on(su.id = ssu.user_id and su.`status`= 1) WHERE ssu.site_id = ss.id and ssu.`status` =1 and ssu.is_admin= 1) as username
  163. from sc_site ss
  164. left join (select count(*)buildingCount,site_id from sc_building group by site_id) a on ss.id=a.site_id
  165. left join (select count(*)deviceCount,site_id from sc_device group by site_id) b on ss.id=b.site_id
  166. where ss.status = 1
  167. <if test="siteIds != null and siteIds.size()>0">
  168. and ss.id in <foreach collection="siteIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  169. </if>
  170. <if test="name != null and name != ''"> AND ss.name LIKE concat('%',#{name},'%')</if>
  171. order by ss.create_date desc
  172. </select>
  173. <update id="delete">
  174. update sc_site set status = 0,update_date=NOW(),update_by=#{updateBy} where id = #{id}
  175. </update>
  176. <update id="deleteCustomerRelations">
  177. update sc_customer set site_id=null where site_id=#{id}
  178. </update>
  179. <update id="updateCustomerSiteId">
  180. update sc_customer set site_id=#{id}
  181. where id in (
  182. <foreach collection="customerIds" item="cid" index="index" open="" close="" separator=",">
  183. #{cid}
  184. </foreach>
  185. )
  186. </update>
  187. <update id="updateOrgId">
  188. update sc_site_user set organ_id=#{orgId} where user_id=#{userId}
  189. </update>
  190. <select id="findByNameUnique" resultType="int">
  191. select count(1) from sc_site where status = 1 and name = #{name}
  192. <if test="id != null"> and id != #{id}</if>
  193. </select>
  194. <select id="findById" resultMap="BaseResultMap">
  195. select ss.*,sc.customer_name
  196. from sc_site as ss
  197. left join sc_customer as sc on (sc.id = ss.customer_id)
  198. where ss.status = 1 and ss.id = #{siteId}
  199. </select>
  200. <select id="findByCustomerIdUnique" resultType="int">
  201. select count(1) from sc_site where status = 1 and customer_id = #{customerId}
  202. <if test="id != null"> and id != #{id}</if>
  203. </select>
  204. <select id="getSiteCustomerIds" resultType="java.lang.Integer">
  205. select customer_id from sc_site where status = 1
  206. </select>
  207. <select id="getCustomerList" resultType="com.zoniot.ccrc.entity.Customer">
  208. select * from sc_customer where parent_id=0 and status=1
  209. </select>
  210. <select id="getAllCustomerIds" resultType="java.lang.Integer">
  211. SELECT DATA.id FROM(
  212. SELECT
  213. @ids as _ids,
  214. ( SELECT @ids := GROUP_CONCAT(id)
  215. FROM sc_customer
  216. WHERE FIND_IN_SET(parent_id, @ids)
  217. ) as cids,
  218. @l := @l+1 as level
  219. FROM sc_customer,
  220. (SELECT @ids :=#{customerId}, @l := 0 ) b
  221. WHERE @ids IS NOT NULL
  222. ) id, sc_customer DATA
  223. WHERE FIND_IN_SET(DATA.id, ID._ids)
  224. </select>
  225. </mapper>