ApiCartMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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.kmall.api.dao.ApiCartMapper">
  4. <!-- 可根据自己的需求,是否要使用 -->
  5. <resultMap type="com.kmall.api.entity.CartVo" id="cartMap">
  6. <result property="id" column="id"/>
  7. <result property="user_id" column="user_id"/>
  8. <result property="store_id" column="store_id"/>
  9. <result property="goods_id" column="goods_id"/>
  10. <result property="goods_sn" column="goods_sn"/>
  11. <result property="product_id" column="product_id"/>
  12. <result property="goods_name" column="goods_name"/>
  13. <result property="market_price" column="market_price"/>
  14. <result property="retail_price" column="retail_price"/>
  15. <result property="number" column="number"/>
  16. <result property="goods_specification_name_value" column="goods_specification_name_value"/>
  17. <result property="goods_specification_ids" column="goods_specification_ids"/>
  18. <result property="checked" column="checked"/>
  19. <result property="list_pic_url" column="list_pic_url"/>
  20. <result column="sku" property="sku" jdbcType="VARCHAR" />
  21. <result column="goods_biz_type" property="goodsBizType" jdbcType="CHAR" />
  22. <result column="creater_sn" property="createrSn" jdbcType="VARCHAR" />
  23. <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
  24. <result column="moder_sn" property="moderSn" jdbcType="VARCHAR" />
  25. <result column="mod_time" property="modTime" jdbcType="TIMESTAMP" />
  26. <result column="tstm" property="tstm" jdbcType="TIMESTAMP" />
  27. </resultMap>
  28. <sql id="Base_Column_List" >
  29. id, user_id, goods_id, sku, goods_sn, product_id, goods_name, market_price, retail_price,
  30. number, goods_specification_ids, checked, list_pic_url, store_id, goods_biz_type,
  31. creater_sn, create_time, moder_sn, mod_time, tstm,goods_specification_name_value
  32. </sql>
  33. <select id="queryObject" resultMap="cartMap">
  34. select
  35. <include refid="Base_Column_List" /> from mall_cart where id = #{value}
  36. </select>
  37. <select id="queryCartByGoodsBizType" resultMap="cartMap">
  38. select
  39. <include refid="Base_Column_List" /> from mall_cart where goods_biz_type = #{goodsBizType}
  40. </select>
  41. <select id="queryList" resultMap="cartMap">
  42. select a.*,
  43. b.list_pic_url as list_pic_url,
  44. psr.retail_price as retail_product_price
  45. from mall_cart a
  46. left join mall_goods b on a.goods_id = b.id
  47. left join mall_product c on c.goods_id = a.goods_id and c.id = a.product_id
  48. left join mall_product_store_rela psr on psr.product_id = c.id and psr.store_id = #{store_id}
  49. where 1 = 1
  50. <if test="user_id != null">
  51. AND a.user_id = #{user_id}
  52. </if>
  53. <if test="goods_id != null">
  54. AND a.goods_id = #{goods_id}
  55. </if>
  56. <if test="product_id != null">
  57. AND a.product_id = #{product_id}
  58. </if>
  59. <if test="store_id != null">
  60. AND psr.store_id = #{store_id}
  61. </if>
  62. <if test="checked != null">
  63. AND a.checked = #{checked}
  64. </if>
  65. <choose>
  66. <when test="sidx != null and sidx.trim() != ''">
  67. order by ${sidx} ${order}
  68. </when>
  69. <otherwise>
  70. order by a.id desc
  71. </otherwise>
  72. </choose>
  73. <if test="offset != null and limit != null">
  74. limit #{offset}, #{limit}
  75. </if>
  76. </select>
  77. <select id="queryTotal" resultType="int">
  78. select count(*) from mall_cart a
  79. where 1 = 1
  80. <if test="user_id != null">
  81. AND a.user_id = #{user_id}
  82. </if>
  83. <if test="goods_id != null">
  84. AND a.goods_id = #{goods_id}
  85. </if>
  86. <if test="product_id != product_id">
  87. AND a.product_id = #{product_id}
  88. </if>
  89. <if test="checked != null">
  90. AND a.checked = #{checked}
  91. </if>
  92. </select>
  93. <insert id="save" parameterType="com.kmall.api.entity.CartVo" useGeneratedKeys="true" keyProperty="id">
  94. INSERT INTO mall_cart
  95. <trim prefix="(" suffix=")" suffixOverrides="," >
  96. <if test="user_id != null" >
  97. user_id,
  98. </if>
  99. <if test="goods_id != null" >
  100. goods_id,
  101. </if>
  102. <if test="sku != null" >
  103. sku,
  104. </if>
  105. <if test="goods_sn != null" >
  106. goods_sn,
  107. </if>
  108. <if test="product_id != null" >
  109. product_id,
  110. </if>
  111. <if test="goods_name != null" >
  112. goods_name,
  113. </if>
  114. <if test="market_price != null" >
  115. market_price,
  116. </if>
  117. <if test="retail_price != null" >
  118. retail_price,
  119. </if>
  120. <if test="number != null" >
  121. number,
  122. </if>
  123. <if test="goods_specification_ids != null" >
  124. goods_specification_ids,
  125. </if>
  126. <if test="checked != null" >
  127. checked,
  128. </if>
  129. <if test="list_pic_url != null" >
  130. list_pic_url,
  131. </if>
  132. <if test="store_id != null" >
  133. store_id,
  134. </if>
  135. <if test="goodsBizType != null" >
  136. goods_biz_type,
  137. </if>
  138. <if test="createrSn != null" >
  139. creater_sn,
  140. </if>
  141. <if test="createTime != null" >
  142. create_time,
  143. </if>
  144. <if test="moderSn != null" >
  145. moder_sn,
  146. </if>
  147. <if test="modTime != null" >
  148. mod_time,
  149. </if>
  150. <if test="tstm != null" >
  151. tstm,
  152. </if>
  153. <if test="goods_specification_name_value != null" >
  154. goods_specification_name_value,
  155. </if>
  156. </trim>
  157. <trim prefix="values (" suffix=")" suffixOverrides="," >
  158. <if test="user_id != null" >
  159. #{user_id},
  160. </if>
  161. <if test="goods_id != null" >
  162. #{goods_id,jdbcType=INTEGER},
  163. </if>
  164. <if test="sku != null" >
  165. #{sku,jdbcType=VARCHAR},
  166. </if>
  167. <if test="goods_sn != null" >
  168. #{goods_sn,jdbcType=VARCHAR},
  169. </if>
  170. <if test="product_id != null" >
  171. #{product_id,jdbcType=INTEGER},
  172. </if>
  173. <if test="goods_name != null" >
  174. #{goods_name,jdbcType=VARCHAR},
  175. </if>
  176. <if test="market_price != null" >
  177. #{market_price,jdbcType=DECIMAL},
  178. </if>
  179. <if test="retail_price != null" >
  180. #{retail_price,jdbcType=DECIMAL},
  181. </if>
  182. <if test="number != null" >
  183. #{number,jdbcType=SMALLINT},
  184. </if>
  185. <if test="goods_specification_ids != null" >
  186. #{goods_specification_ids,jdbcType=VARCHAR},
  187. </if>
  188. <if test="checked != null" >
  189. #{checked,jdbcType=BIT},
  190. </if>
  191. <if test="list_pic_url != null" >
  192. #{list_pic_url,jdbcType=VARCHAR},
  193. </if>
  194. <if test="store_id != null" >
  195. #{store_id,jdbcType=INTEGER},
  196. </if>
  197. <if test="goodsBizType != null" >
  198. #{goodsBizType,jdbcType=CHAR},
  199. </if>
  200. <if test="createrSn != null" >
  201. #{createrSn,jdbcType=VARCHAR},
  202. </if>
  203. <if test="createTime != null" >
  204. #{createTime,jdbcType=TIMESTAMP},
  205. </if>
  206. <if test="moderSn != null" >
  207. #{moderSn,jdbcType=VARCHAR},
  208. </if>
  209. <if test="modTime != null" >
  210. #{modTime,jdbcType=TIMESTAMP},
  211. </if>
  212. <if test="tstm != null" >
  213. #{tstm,jdbcType=TIMESTAMP},
  214. </if>
  215. <if test="goods_specification_name_value != null" >
  216. #{goods_specification_name_value,jdbcType=LONGVARCHAR},
  217. </if>
  218. </trim>
  219. </insert>
  220. <update id="update" parameterType="com.kmall.api.entity.CartVo">
  221. update mall_cart
  222. <set >
  223. <if test="user_id != null" >
  224. user_id = #{user_id},
  225. </if>
  226. <if test="goods_id != null" >
  227. goods_id = #{goods_id,jdbcType=INTEGER},
  228. </if>
  229. <if test="sku != null" >
  230. sku = #{sku,jdbcType=VARCHAR},
  231. </if>
  232. <if test="goods_sn != null" >
  233. goods_sn = #{goods_sn,jdbcType=VARCHAR},
  234. </if>
  235. <if test="product_id != null" >
  236. product_id = #{product_id,jdbcType=INTEGER},
  237. </if>
  238. <if test="goods_name != null" >
  239. goods_name = #{goods_name,jdbcType=VARCHAR},
  240. </if>
  241. <if test="market_price != null" >
  242. market_price = #{market_price,jdbcType=DECIMAL},
  243. </if>
  244. <if test="retail_price != null" >
  245. retail_price = #{retail_price,jdbcType=DECIMAL},
  246. </if>
  247. <if test="number != null" >
  248. number = #{number,jdbcType=SMALLINT},
  249. </if>
  250. <if test="goods_specification_ids != null" >
  251. goods_specification_ids = #{goods_specification_ids,jdbcType=VARCHAR},
  252. </if>
  253. <if test="checked != null" >
  254. checked = #{checked,jdbcType=BIT},
  255. </if>
  256. <if test="list_pic_url != null" >
  257. list_pic_url = #{list_pic_url,jdbcType=VARCHAR},
  258. </if>
  259. <if test="store_id != null" >
  260. store_id = #{store_id,jdbcType=INTEGER},
  261. </if>
  262. <if test="goodsBizType != null" >
  263. goods_biz_type = #{goodsBizType,jdbcType=CHAR},
  264. </if>
  265. <if test="createrSn != null" >
  266. creater_sn = #{createrSn,jdbcType=VARCHAR},
  267. </if>
  268. <if test="createTime != null" >
  269. create_time = #{createTime,jdbcType=TIMESTAMP},
  270. </if>
  271. <if test="moderSn != null" >
  272. moder_sn = #{moderSn,jdbcType=VARCHAR},
  273. </if>
  274. <if test="modTime != null" >
  275. mod_time = #{modTime,jdbcType=TIMESTAMP},
  276. </if>
  277. <if test="tstm != null" >
  278. tstm = #{tstm,jdbcType=TIMESTAMP},
  279. </if>
  280. <if test="goods_specification_name_value != null" >
  281. goods_specification_name_value = #{goods_specification_name_value,jdbcType=LONGVARCHAR},
  282. </if>
  283. </set>
  284. where id = #{id}
  285. </update>
  286. <update id="updateCheck">
  287. update mall_cart
  288. set `checked` = #{isChecked}
  289. where product_id in
  290. <foreach item="product_id" collection="productIds" open="(" separator="," close=")">
  291. #{product_id}
  292. </foreach>
  293. and user_id = #{user_id} and store_id = #{store_id}
  294. </update>
  295. <delete id="delete">
  296. delete from mall_cart where id = #{value}
  297. </delete>
  298. <delete id="deleteBatch">
  299. delete from mall_cart where id in
  300. <foreach item="id" collection="array" open="(" separator="," close=")">
  301. #{id}
  302. </foreach>
  303. </delete>
  304. <delete id="deleteByProductIds">
  305. delete from mall_cart where product_id in
  306. <foreach item="id" collection="productIds" open="(" separator="," close=")">
  307. #{id}
  308. </foreach>
  309. and store_id = #{store_id}
  310. </delete>
  311. <delete id="deleteByCart">
  312. delete from mall_cart
  313. where user_id = #{user_id} and store_id = #{store_id} and checked = #{checked}
  314. </delete>
  315. </mapper>