BrandPurchaserMapper.xml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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.BrandPurchaserDao">
  4. <sql id="brandPurchaserColumns">
  5. a.id AS "id",
  6. a.name AS "name",
  7. a.purchase_date AS "purchaseDate",
  8. a.intro AS "intro",
  9. a.publicty_material_images AS "publictyMaterialImages",
  10. a.large_Images AS "largeImages",
  11. a.enabled_status AS "enabledStatus",
  12. a.create_by AS "createBy.id",
  13. a.create_date AS "createDate",
  14. a.update_by AS "updateBy.id",
  15. a.update_date AS "updateDate"
  16. </sql>
  17. <sql id="brandPurchaserColumnsWithProductCount">
  18. a.id AS "id",
  19. a.name AS "name",
  20. a.purchase_date AS "purchaseDate",
  21. a.intro AS "intro",
  22. a.publicty_material_images AS "publictyMaterialImages",
  23. a.large_Images AS "largeImages",
  24. a.enabled_status AS "enabledStatus",
  25. a.create_by AS "createBy.id",
  26. a.create_date AS "createDate",
  27. a.update_by AS "updateBy.id",
  28. a.update_date AS "updateDate",
  29. COUNT(b.id) AS "productTotalCount",
  30. COUNT(DISTINCT c.productID) AS "productTypeCount"
  31. </sql>
  32. <sql id="brandPurchaserJoins">
  33. </sql>
  34. <sql id="brandPurchaserJoinsWithProductCount">
  35. LEFT JOIN brand_product b ON a.id = b.purchaser_id
  36. LEFT JOIN product c ON b.productID = c.productID
  37. </sql>
  38. <select id="get" resultType="BrandPurchaser">
  39. SELECT
  40. <include refid="brandPurchaserColumns"/>
  41. FROM brand_purchaser a
  42. <include refid="brandPurchaserJoins"/>
  43. WHERE a.id = #{id}
  44. </select>
  45. <select id="findList" resultType="BrandPurchaser">
  46. SELECT
  47. <include refid="brandPurchaserColumnsWithProductCount"/>
  48. FROM brand_purchaser a
  49. <include refid="brandPurchaserJoinsWithProductCount"/>
  50. <where>
  51. <if test="id != null and id != ''">
  52. AND a.id = #{id}
  53. </if>
  54. <if test="name != null and name != ''">
  55. AND a.name LIKE concat('%',#{name},'%')
  56. </if>
  57. <if test="enabledStatus != null and enabledStatus != ''">
  58. AND a.enabled_status = #{enabledStatus}
  59. </if>
  60. and c.productCategory = 1
  61. </where>
  62. GROUP BY a.id
  63. <choose>
  64. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  65. ORDER BY ${page.orderBy}
  66. </when>
  67. <otherwise>
  68. ORDER BY a.enabled_status DESC,a.update_date DESC
  69. </otherwise>
  70. </choose>
  71. </select>
  72. <select id="findAllList" resultType="BrandPurchaser">
  73. SELECT
  74. <include refid="brandPurchaserColumns"/>
  75. FROM brand_purchaser a
  76. <include refid="brandPurchaserJoins"/>
  77. <where>
  78. </where>
  79. <choose>
  80. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  81. ORDER BY ${page.orderBy}
  82. </when>
  83. <otherwise>
  84. ORDER BY a.update_date DESC
  85. </otherwise>
  86. </choose>
  87. </select>
  88. <insert id="insert" parameterType="BrandPurchaser" keyProperty="id" useGeneratedKeys="true">
  89. INSERT INTO brand_purchaser(
  90. name,
  91. purchase_date,
  92. intro,
  93. publicty_material_images,
  94. large_Images,
  95. enabled_status,
  96. create_by,
  97. create_date,
  98. update_by,
  99. update_date
  100. ) VALUES (
  101. #{name},
  102. #{purchaseDate},
  103. #{intro},
  104. #{publictyMaterialImages},
  105. #{largeImages},
  106. #{enabledStatus},
  107. #{createBy.id},
  108. #{createDate},
  109. #{updateBy.id},
  110. #{updateDate}
  111. )
  112. </insert>
  113. <update id="update">
  114. UPDATE brand_purchaser SET
  115. name = #{name},
  116. purchase_date = #{purchaseDate},
  117. intro = #{intro},
  118. publicty_material_images = #{publictyMaterialImages},
  119. large_Images = #{largeImages},
  120. enabled_status = #{enabledStatus},
  121. update_by = #{updateBy.id},
  122. update_date = #{updateDate}
  123. WHERE id = #{id}
  124. </update>
  125. <delete id="delete">
  126. DELETE FROM brand_purchaser
  127. WHERE id = #{id}
  128. </delete>
  129. <update id="changeStatus" parameterType="Map">
  130. UPDATE brand_purchaser SET
  131. enabled_status = #{enabledStatus}
  132. WHERE id = #{id}
  133. </update>
  134. </mapper>