CmProductCombinationMapper.xml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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.product.dao.CmProductCombinationDao">
  4. <sql id="cmProductCombinationColumns">
  5. a.id AS "id",
  6. a.name AS "name",
  7. a.addTime AS "addTime",
  8. a.updateTime AS "updateTime",
  9. a.delFlag AS "delFlag"
  10. </sql>
  11. <sql id="cmProductCombinationJoins">
  12. </sql>
  13. <select id="get" resultType="CmProductCombination">
  14. SELECT
  15. <include refid="cmProductCombinationColumns"/>
  16. FROM cm_product_combination a
  17. <include refid="cmProductCombinationJoins"/>
  18. WHERE a.id = #{id}
  19. </select>
  20. <select id="findList" resultType="CmProductCombination">
  21. SELECT
  22. <include refid="cmProductCombinationColumns"/>
  23. FROM cm_product_combination a
  24. <include refid="cmProductCombinationJoins"/>
  25. <where>
  26. <if test="id != null and id != ''">
  27. AND a.id = #{id}
  28. </if>
  29. <if test="name != null and name != ''">
  30. AND a.name LIKE
  31. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  32. <if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
  33. <if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
  34. </if>
  35. and a.delFlag = 0
  36. </where>
  37. <choose>
  38. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  39. ORDER BY ${page.orderBy}
  40. </when>
  41. <otherwise>
  42. order by a.addTime desc
  43. </otherwise>
  44. </choose>
  45. </select>
  46. <select id="findCombinationProductList" resultType="com.caimei.modules.product.entity.Product">
  47. SELECT a.*,s.name as "shopName"
  48. FROM product a
  49. left join shop s on a.shopId = s.shopID
  50. where
  51. combinationID = #{id}
  52. and a.productCategory = 1
  53. group by a.productID
  54. ORDER BY combinationSort!= 0 desc,combinationSort asc
  55. </select>
  56. <select id="findProductCombinationList" resultType="com.caimei.modules.product.entity.CmProductCombination">
  57. select * From cm_product_combination where delFlag = 0
  58. </select>
  59. <select id="findAllList" resultType="CmProductCombination">
  60. SELECT
  61. <include refid="cmProductCombinationColumns"/>
  62. FROM cm_product_combination a
  63. <include refid="cmProductCombinationJoins"/>
  64. <where>
  65. a.delFlag = 0
  66. </where>
  67. <choose>
  68. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  69. ORDER BY ${page.orderBy}
  70. </when>
  71. <otherwise>
  72. order by a.addTime desc
  73. </otherwise>
  74. </choose>
  75. </select>
  76. <insert id="insert" parameterType="CmProductCombination" keyProperty="id" useGeneratedKeys="true">
  77. INSERT INTO cm_product_combination(
  78. name,
  79. addTime,
  80. updateTime,
  81. delFlag
  82. ) VALUES (
  83. #{name},
  84. #{addTime},
  85. #{updateTime},
  86. #{delFlag}
  87. )
  88. </insert>
  89. <update id="update">
  90. UPDATE cm_product_combination SET
  91. name = #{name},
  92. addTime = #{addTime},
  93. updateTime = #{updateTime},
  94. delFlag = #{delFlag}
  95. WHERE id = #{id}
  96. </update>
  97. <update id="saveSort">
  98. UPDATE product SET combinationSort = #{sort} WHERE productID = #{id}
  99. </update>
  100. <update id="untieProduct">
  101. UPDATE product SET combinationID = NULL,combinationSort = NULL where combinationID = #{combinationId};
  102. </update>
  103. <update id="addProductCombination">
  104. UPDATE product SET combinationID = #{id},combinationSort = 0 where productID in
  105. <foreach collection="productIds" item="item" index="index" open="(" separator="," close=")">
  106. #{item}
  107. </foreach>
  108. </update>
  109. <!--获取商品列表,排除已经绑定组合的商品-->
  110. <select id="findProductList" resultType="com.caimei.modules.product.entity.Product">
  111. SELECT a.*,s.name as "shopName"
  112. FROM product a
  113. left join cm_organize_product_info copi on copi.productId = a.productID
  114. left join shop s on a.shopId = s.shopID
  115. <where>
  116. copi.validFlag in (2,3,9)
  117. <if test="productID !=null and productID !=''">
  118. AND a.productID=#{productID}
  119. </if>
  120. <if test="name != null and name != ''">
  121. AND a.name LIKE
  122. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  123. <if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
  124. <if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
  125. </if>
  126. <if test="shopName != null and shopName != ''">
  127. AND s.name LIKE
  128. <if test="dbName == 'oracle'">'%'||#{shopName}||'%'</if>
  129. <if test="dbName == 'mssql'">'%'+#{shopName}+'%'</if>
  130. <if test="dbName == 'mysql'">concat('%',#{shopName},'%')</if>
  131. </if>
  132. and a.combinationID is null
  133. and a.productCategory = 1
  134. </where>
  135. group by a.productID
  136. <choose>
  137. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  138. ORDER BY ${page.orderBy}
  139. </when>
  140. <otherwise>
  141. order by a.productID desc
  142. </otherwise>
  143. </choose>
  144. </select>
  145. <update id="untieProductByProductId">
  146. UPDATE product SET combinationID = NULL,combinationSort = NULL where productID = #{productId};
  147. </update>
  148. <delete id="delete">
  149. DELETE FROM cm_product_combination
  150. WHERE id = #{id}
  151. </delete>
  152. </mapper>