ApiCartMapper.xml 16 KB

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