BrandSupplierMapper.xml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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.caimei.modules.brand.dao.BrandSupplierDao">
  4. <sql id="brandSupplierColumns">
  5. a.id AS "id",
  6. a.shopid AS "shopID",
  7. a.logo AS "LOGO",
  8. a.name AS "name",
  9. a.business_license AS "businessLicense",
  10. a.business_address AS "businessAddress",
  11. a.business_phone AS "businessPhone",
  12. a.legal_representaive AS "legalRepresentaive",
  13. a.registered_capital AS "registeredCapital",
  14. a.enterprise_type AS "enterpriseType",
  15. a.business_scope AS "businessScope",
  16. a.enabled_status AS "enabledStatus",
  17. a.create_by AS "createBy.id",
  18. a.create_date AS "createDate",
  19. a.update_by AS "updateBy.id",
  20. a.update_date AS "updateDate"
  21. </sql>
  22. <sql id="brandSupplierColumnsWithProductCount">
  23. a.id AS "id",
  24. a.shopid AS "shopID",
  25. a.logo AS "LOGO",
  26. a.name AS "name",
  27. a.business_license AS "businessLicense",
  28. a.business_address AS "businessAddress",
  29. a.business_phone AS "businessPhone",
  30. a.legal_representaive AS "legalRepresentaive",
  31. a.registered_capital AS "registeredCapital",
  32. a.enterprise_type AS "enterpriseType",
  33. a.business_scope AS "businessScope",
  34. a.enabled_status AS "enabledStatus",
  35. a.create_by AS "createBy.id",
  36. a.create_date AS "createDate",
  37. a.update_by AS "updateBy.id",
  38. a.update_date AS "updateDate",
  39. COUNT(b.id) AS "productTotalCount",
  40. COUNT(DISTINCT c.productID) AS "productTypeCount"
  41. </sql>
  42. <sql id="brandSupplierJoins">
  43. </sql>
  44. <sql id="brandSupplierJoinsWithProductCount">
  45. LEFT JOIN brand_product b ON a.id = b.supplier_id
  46. LEFT JOIN product c ON b.productID = c.productID
  47. </sql>
  48. <select id="get" resultType="BrandSupplier">
  49. SELECT
  50. <include refid="brandSupplierColumns"/>, b.name AS shopName
  51. FROM brand_supplier a LEFT JOIN shop b ON a.shopID = b.shopID
  52. <include refid="brandSupplierJoins"/>
  53. WHERE a.id = #{id}
  54. </select>
  55. <select id="findList" resultType="BrandSupplier">
  56. SELECT
  57. <include refid="brandSupplierColumnsWithProductCount"/>
  58. FROM brand_supplier a
  59. <include refid="brandSupplierJoinsWithProductCount"/>
  60. <where>
  61. <if test="shopID != null and shopID != ''">
  62. AND a.shopid = #{shopID}
  63. </if>
  64. <if test="name != null and name != ''">
  65. AND a.name LIKE
  66. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  67. <if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
  68. <if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
  69. </if>
  70. <if test="enabledStatus != null and enabledStatus != ''">
  71. AND a.enabled_status = #{enabledStatus}
  72. </if>
  73. and c.productCategory = 1
  74. </where>
  75. GROUP BY a.id
  76. <choose>
  77. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  78. ORDER BY ${page.orderBy}
  79. </when>
  80. <otherwise>
  81. ORDER BY a.enabled_status DESC,a.update_date DESC
  82. </otherwise>
  83. </choose>
  84. </select>
  85. <select id="findAllList" resultType="BrandSupplier">
  86. SELECT
  87. <include refid="brandSupplierColumns"/>
  88. FROM brand_supplier a
  89. <include refid="brandSupplierJoins"/>
  90. <where>
  91. </where>
  92. <choose>
  93. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  94. ORDER BY ${page.orderBy}
  95. </when>
  96. <otherwise>
  97. ORDER BY a.update_date DESC
  98. </otherwise>
  99. </choose>
  100. </select>
  101. <insert id="insert" parameterType="BrandSupplier" keyProperty="id" useGeneratedKeys="true">
  102. INSERT INTO brand_supplier(
  103. shopid,
  104. logo,
  105. name,
  106. business_license,
  107. business_address,
  108. business_phone,
  109. legal_representaive,
  110. registered_capital,
  111. enterprise_type,
  112. business_scope,
  113. enabled_status,
  114. create_by,
  115. create_date,
  116. update_by,
  117. update_date
  118. ) VALUES (
  119. #{shopID},
  120. #{LOGO},
  121. #{name},
  122. #{businessLicense},
  123. #{businessAddress},
  124. #{businessPhone},
  125. #{legalRepresentaive},
  126. #{registeredCapital},
  127. #{enterpriseType},
  128. #{businessScope},
  129. #{enabledStatus},
  130. #{createBy.id},
  131. #{createDate},
  132. #{updateBy.id},
  133. #{updateDate}
  134. )
  135. </insert>
  136. <update id="update">
  137. UPDATE brand_supplier SET
  138. shopid = #{shopID},
  139. logo = #{LOGO},
  140. name = #{name},
  141. business_license = #{businessLicense},
  142. business_address = #{businessAddress},
  143. business_phone = #{businessPhone},
  144. legal_representaive = #{legalRepresentaive},
  145. registered_capital = #{registeredCapital},
  146. enterprise_type = #{enterpriseType},
  147. business_scope = #{businessScope},
  148. enabled_status = #{enabledStatus},
  149. update_by = #{updateBy.id},
  150. update_date = #{updateDate}
  151. WHERE id = #{id}
  152. </update>
  153. <delete id="delete">
  154. DELETE FROM brand_supplier
  155. WHERE id = #{id}
  156. </delete>
  157. <update id="changeStatus" parameterType="Map">
  158. UPDATE brand_supplier SET enabled_status = #{enabledStatus}
  159. WHERE id = #{id}
  160. </update>
  161. <update id="updateEnabledStatusByIds" parameterType="Map">
  162. UPDATE brand_supplier a SET a.enabled_status = #{param1}
  163. WHERE a.id IN
  164. <foreach collection="param2" item="id" index="index" open="(" separator="," close=")" >
  165. #{id}
  166. </foreach>
  167. </update>
  168. </mapper>