RepeatPurchasePriceMapper.xml 5.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.caimei.modules.product.dao.RepeatPurchasePriceDao">
  4. <sql id="repeatPurchasePriceColumns">
  5. a.id AS "id",
  6. a.userId AS "userId",
  7. a.productId AS "productId",
  8. a.shopId AS "shopId",
  9. a.shopName AS "shopName",
  10. a.taxRate AS "taxRate",
  11. a.currentPrice AS "currentPrice",
  12. a.createTime AS "createTime"
  13. </sql>
  14. <sql id="repeatPurchasePriceJoins">
  15. left join product as b on a.productId = b.productID
  16. left join user as c on a.userId = c.userId
  17. </sql>
  18. <sql id="repeatPurchasePriceHistoryJoins">
  19. INNER JOIN repeat_purchase_price AS b ON a.`userId` = b.`userId` AND a.`productId` = b.`productId`
  20. </sql>
  21. <select id="get" resultType="RepeatPurchasePrice">
  22. SELECT
  23. <include refid="repeatPurchasePriceColumns"/>
  24. FROM repeat_purchase_price a
  25. <include refid="repeatPurchasePriceJoins"/>
  26. where a.id = #{id}
  27. AND a.delFlag = 0
  28. </select>
  29. <select id="getRepeatPurchasePrice" resultType="RepeatPurchasePrice">
  30. SELECT
  31. <include refid="repeatPurchasePriceColumns"/>,
  32. c.userName AS "userName",
  33. c.mobile As "mobile",
  34. c.registerUserTypeID As "type",
  35. b.name AS "productName"
  36. FROM repeat_purchase_price a
  37. <include refid="repeatPurchasePriceJoins"/>
  38. <where>
  39. <if test="repeatPurchasePriceId != null and repeatPurchasePriceId != ''" >
  40. AND a.id = #{repeatPurchasePriceId}
  41. </if>
  42. AND a.delFlag = 0
  43. and b.productCategory = 1
  44. </where>
  45. </select>
  46. <select id="findList" resultType="RepeatPurchasePrice">
  47. SELECT
  48. <include refid="repeatPurchasePriceColumns"/>,
  49. c.name AS "userName",
  50. c.mobile As "mobile",
  51. c.bindMobile AS "bindMobile",
  52. c.registerUserTypeID As "type",
  53. b.name AS "productName",
  54. CASE b.costCheckFlag
  55. WHEN 1 THEN b.`costPrice`
  56. WHEN 2 THEN b.`costProportional` * b.`price1` / 100
  57. END AS "costPrice"
  58. FROM repeat_purchase_price a
  59. <include refid="repeatPurchasePriceJoins"/>
  60. <where>
  61. <if test="productId != null and productId != ''" >
  62. AND a.productId = #{productId}
  63. </if>
  64. <if test="productName != null and productName != ''" >
  65. AND b.name LIKE
  66. <if test="dbName == 'oracle'">'%'||#{productName}||'%'</if>
  67. <if test="dbName == 'mssql'">'%'+#{productName}+'%'</if>
  68. <if test="dbName == 'mysql'">concat('%',#{productName},'%')</if>
  69. </if>
  70. <if test="userName != null and userName != ''" >
  71. AND c.name LIKE
  72. <if test="dbName == 'oracle'">'%'||#{userName}||'%'</if>
  73. <if test="dbName == 'mssql'">'%'+#{userName}+'%'</if>
  74. <if test="dbName == 'mysql'">concat('%',#{userName},'%')</if>
  75. </if>
  76. <if test="mobile != null and mobile != ''" >
  77. AND (c.mobile = #{mobile} or c.bindMobile = #{mobile})
  78. </if>
  79. <if test="shopName != null and shopName != ''" >
  80. AND a.shopName LIKE
  81. <if test="dbName == 'oracle'">'%'||#{shopName}||'%'</if>
  82. <if test="dbName == 'mssql'">'%'+#{shopName}+'%'</if>
  83. <if test="dbName == 'mysql'">concat('%',#{shopName},'%')</if>
  84. </if>
  85. AND a.delFlag = 0
  86. and b.productCategory = 1
  87. </where>
  88. <choose>
  89. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  90. ORDER BY ${page.orderBy} desc
  91. </when>
  92. <otherwise>
  93. </otherwise>
  94. </choose>
  95. </select>
  96. <select id="findHistoryPriceList" resultType="RepeatPurchasePriceHistory">
  97. SELECT
  98. a.*
  99. FROM repeat_purchase_price_history a
  100. <include refid="repeatPurchasePriceHistoryJoins"/>
  101. <where>
  102. <if test="repeatPurchasePriceId != null and repeatPurchasePriceId != ''" >
  103. AND b.id = #{repeatPurchasePriceId}
  104. </if>
  105. AND a.cmCartId is null
  106. AND a.delFlag = 0
  107. </where>
  108. <choose>
  109. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  110. ORDER BY ${page.orderBy} desc
  111. </when>
  112. <otherwise>
  113. </otherwise>
  114. </choose>
  115. </select>
  116. <select id="findPriceProductList" resultType="String">
  117. select GROUP_CONCAT(productId) From repeat_purchase_price WHERE userId = #{userId} and delFlag = 0;
  118. </select>
  119. <select id="findAllList" resultType="RepeatPurchasePrice">
  120. SELECT
  121. <include refid="repeatPurchasePriceColumns"/>
  122. FROM repeat_purchase_price a
  123. <include refid="repeatPurchasePriceJoins"/>
  124. <where>
  125. a.delFlag = 0
  126. and b.productCategory = 1
  127. </where>
  128. <choose>
  129. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  130. ORDER BY ${page.orderBy}
  131. </when>
  132. <otherwise>
  133. </otherwise>
  134. </choose>
  135. </select>
  136. <insert id="insert" parameterType="RepeatPurchasePrice" keyProperty="id" useGeneratedKeys="true">
  137. INSERT INTO repeat_purchase_price(
  138. id,
  139. userId,
  140. productId,
  141. shopId,
  142. shopName,
  143. taxRate,
  144. currentPrice,
  145. createTime,
  146. orderId,
  147. clubId
  148. ) VALUES (
  149. #{id},
  150. #{userId},
  151. #{productId},
  152. #{shopId},
  153. #{shopName},
  154. #{taxRate},
  155. #{currentPrice},
  156. #{createTime},
  157. #{orderId},
  158. #{clubId}
  159. )
  160. </insert>
  161. <update id="update">
  162. UPDATE repeat_purchase_price SET
  163. userId = #{userId},
  164. productId = #{productId},
  165. shopId = #{shopId},
  166. shopName = #{shopName},
  167. taxRate = #{taxRate},
  168. currentPrice = #{currentPrice},
  169. createTime = #{createTime}
  170. WHERE id = #{id}
  171. </update>
  172. <update id="delete">
  173. UPDATE repeat_purchase_price SET
  174. delFlag = #{delFlag}
  175. WHERE id = #{id}
  176. </update>
  177. <select id="getLastBuyPrice" resultType="RepeatPurchasePrice">
  178. select <include refid="repeatPurchasePriceColumns"/>
  179. from repeat_purchase_price a
  180. <where>
  181. <if test="userId != null and userId != ''">
  182. and a.userId = #{userId}
  183. </if>
  184. <if test="clubId != null and clubId != ''">
  185. and a.clubId = #{clubId}
  186. </if>
  187. <if test="productId != null and productId != ''">
  188. and a.productId = #{productId}
  189. </if>
  190. AND a.delFlag = 0
  191. </where>
  192. limit 0, 1
  193. </select>
  194. </mapper>