ApiCartMapper.xml 14 KB

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