SiteMapper.xml 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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.SiteMapper">
  4. <!--auto generated Code-->
  5. <resultMap id="BaseResultMap" type="com.bz.smart_city.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. </resultMap>
  18. <!--auto generated Code-->
  19. <sql id="Base_Column_List">
  20. create_date,
  21. create_by,
  22. update_date,
  23. update_by,
  24. id,
  25. name,
  26. website,
  27. logo_url,
  28. status,
  29. type,
  30. customer_id
  31. </sql>
  32. <!--auto generated Code-->
  33. <insert id="insert" useGeneratedKeys="true" keyProperty="site.id">
  34. INSERT INTO sc_site (
  35. create_date,
  36. create_by,
  37. update_date,
  38. update_by,
  39. id,
  40. name,
  41. website,
  42. logo_url,
  43. status,
  44. type,
  45. customer_id
  46. ) VALUES (
  47. #{site.createDate,jdbcType=TIMESTAMP},
  48. #{site.createBy,jdbcType=VARCHAR},
  49. #{site.updateDate,jdbcType=TIMESTAMP},
  50. #{site.updateBy,jdbcType=VARCHAR},
  51. #{site.id,jdbcType=INTEGER},
  52. #{site.name,jdbcType=VARCHAR},
  53. #{site.website,jdbcType=VARCHAR},
  54. #{site.logoUrl,jdbcType=VARCHAR},
  55. #{site.status,jdbcType=INTEGER},
  56. #{site.type,jdbcType=INTEGER},
  57. #{site.customerId,jdbcType=INTEGER}
  58. )
  59. </insert>
  60. <!--auto generated Code-->
  61. <insert id="insertSelective" useGeneratedKeys="true" keyProperty="site.id">
  62. INSERT INTO sc_site
  63. <trim prefix="(" suffix=")" suffixOverrides=",">
  64. <if test="site.createDate!=null"> create_date,</if>
  65. <if test="site.createBy!=null"> create_by,</if>
  66. <if test="site.updateDate!=null"> update_date,</if>
  67. <if test="site.updateBy!=null"> update_by,</if>
  68. <if test="site.id!=null"> id,</if>
  69. <if test="site.name!=null"> name,</if>
  70. <if test="site.website!=null"> website,</if>
  71. <if test="site.logoUrl!=null"> logo_url,</if>
  72. <if test="site.status!=null"> status,</if>
  73. <if test="site.type!=null"> type,</if>
  74. <if test="site.customerId!=null"> customer_id,</if>
  75. </trim>
  76. VALUES
  77. <trim prefix="(" suffix=")" suffixOverrides=",">
  78. <if test="site.createDate!=null">#{site.createDate,jdbcType=TIMESTAMP},
  79. </if>
  80. <if test="site.createBy!=null">#{site.createBy,jdbcType=VARCHAR},
  81. </if>
  82. <if test="site.updateDate!=null">#{site.updateDate,jdbcType=TIMESTAMP},
  83. </if>
  84. <if test="site.updateBy!=null">#{site.updateBy,jdbcType=VARCHAR},
  85. </if>
  86. <if test="site.id!=null">#{site.id,jdbcType=INTEGER},
  87. </if>
  88. <if test="site.name!=null">#{site.name,jdbcType=VARCHAR},
  89. </if>
  90. <if test="site.website!=null">#{site.website,jdbcType=VARCHAR},
  91. </if>
  92. <if test="site.logoUrl!=null">#{site.logoUrl,jdbcType=VARCHAR},
  93. </if>
  94. <if test="site.status!=null">#{site.status,jdbcType=INTEGER},
  95. </if>
  96. <if test="site.type!=null">#{site.type,jdbcType=INTEGER},
  97. </if>
  98. <if test="site.customerId!=null">#{site.customerId,jdbcType=INTEGER},
  99. </if>
  100. </trim>
  101. </insert>
  102. <!--auto generated Code-->
  103. <insert id="insertList">
  104. INSERT INTO sc_site (
  105. create_date,
  106. create_by,
  107. update_date,
  108. update_by,
  109. id,
  110. name,
  111. website,
  112. logo_url,
  113. status,
  114. type,
  115. customer_id
  116. )VALUES
  117. <foreach collection="sites" item="site" index="index" separator=",">
  118. (
  119. #{site.createDate,jdbcType=TIMESTAMP},
  120. #{site.createBy,jdbcType=VARCHAR},
  121. #{site.updateDate,jdbcType=TIMESTAMP},
  122. #{site.updateBy,jdbcType=VARCHAR},
  123. #{site.id,jdbcType=INTEGER},
  124. #{site.name,jdbcType=VARCHAR},
  125. #{site.website,jdbcType=VARCHAR},
  126. #{site.logoUrl,jdbcType=VARCHAR},
  127. #{site.status,jdbcType=INTEGER},
  128. #{site.type,jdbcType=INTEGER},
  129. #{site.customerId,jdbcType=INTEGER}
  130. )
  131. </foreach>
  132. </insert>
  133. <!--auto generated Code-->
  134. <update id="updateByPrimaryKeySelective">
  135. UPDATE sc_site
  136. <set>
  137. <if test="site.createDate != null"> create_date= #{site.createDate,jdbcType=TIMESTAMP},</if>
  138. <if test="site.createBy != null"> create_by= #{site.createBy,jdbcType=VARCHAR},</if>
  139. <if test="site.updateDate != null"> update_date= #{site.updateDate,jdbcType=TIMESTAMP},</if>
  140. <if test="site.updateBy != null"> update_by= #{site.updateBy,jdbcType=VARCHAR},</if>
  141. <if test="site.name != null"> name= #{site.name,jdbcType=VARCHAR},</if>
  142. <if test="site.website != null"> website= #{site.website,jdbcType=VARCHAR},</if>
  143. <if test="site.logoUrl != null"> logo_url= #{site.logoUrl,jdbcType=VARCHAR},</if>
  144. <if test="site.status != null"> status= #{site.status,jdbcType=INTEGER},</if>
  145. <if test="site.type != null"> type= #{site.type,jdbcType=INTEGER},</if>
  146. <if test="site.customerId != null"> customer_id= #{site.customerId,jdbcType=INTEGER}</if>
  147. </set>
  148. WHERE id = #{site.id,jdbcType=INTEGER}
  149. </update>
  150. <select id="getList" resultMap="lazyLoadChannelIds">
  151. select
  152. ss.*,
  153. (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,
  154. (select count(1) from sc_building sb where sb.status = 1 and sb.site_id = ss.id) as building_count,
  155. (select count(1) from sc_device sd where sd.status = 1 and sd.site_id = ss.id) as device_count
  156. from sc_site ss
  157. where ss.status = 1
  158. <if test="siteIds != null and siteIds.size()>0">
  159. and ss.id in <foreach collection="siteIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  160. </if>
  161. <if test="name != null and name != ''"> AND ss.name LIKE concat('%',#{name},'%')</if>
  162. order by ss.create_date desc
  163. </select>
  164. <resultMap id="lazyLoadChannelIds" type="com.bz.smart_city.dto.SiteDto" extends="BaseResultMap">
  165. <collection property="channelIds" ofType="java.lang.Integer" select="com.bz.smart_city.dao.ChannelMapper.getChannelBySiteId"
  166. column="id"></collection>
  167. </resultMap>
  168. <update id="delete">
  169. update sc_site set status = 0,update_date=NOW(),update_by=#{updateBy} where id = #{id}
  170. </update>
  171. <select id="findByNameUnique" resultType="int">
  172. select count(1) from sc_site where status = 1 and name = #{name}
  173. <if test="id != null"> and id != #{id}</if>
  174. </select>
  175. <select id="findById" resultMap="BaseResultMap">
  176. select ss.*,sc.customer_name
  177. from sc_site as ss
  178. left join sc_customer as sc on (sc.id = ss.customer_id)
  179. where ss.status = 1 and ss.id = #{siteId}
  180. </select>
  181. <select id="findByCustomerIdUnique" resultType="int">
  182. select count(1) from sc_site where status = 1 and customer_id = #{customerId}
  183. <if test="id != null"> and id != #{id}</if>
  184. </select>
  185. <select id="getSiteAndCustomerByCustomerNo" resultType="com.bz.smart_city.dto.pay.SiteinfoDto">
  186. select
  187. s.id,
  188. s.name as "siteName",
  189. s.customer_id,
  190. c.customer_no,
  191. c.customer_name as "customerName"
  192. from sc_site s
  193. left join sc_customer c on s.customer_id=c.id
  194. where c.customer_no=#{customerNo}
  195. </select>
  196. </mapper>