ApiCartMapper.xml 12 KB

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