| 5432 |
amar.kumar |
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
2 |
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
3 |
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
|
4 |
|
|
|
5 |
<mapper namespace="in.shop2020.user.persistence.CartMapper">
|
|
|
6 |
|
|
|
7 |
<resultMap type="cartWithLine" id="cartWithLineResult">
|
|
|
8 |
<id property="id" column="id"/>
|
|
|
9 |
<collection property="lines" javaType="ArrayList" column="id" ofType="line" select="getLineByCartId"/>
|
|
|
10 |
</resultMap>
|
|
|
11 |
<resultMap type="cart" id="cartResult">
|
|
|
12 |
<id property="id" column="id"/>
|
|
|
13 |
</resultMap>
|
|
|
14 |
<resultMap type="line" id="lineResult">
|
|
|
15 |
<collection property="discounts" javaType="ArrayList" column="cart_id=cart_id, item_id=item_id" ofType="discount" select="getDiscounts"/>
|
|
|
16 |
</resultMap>
|
|
|
17 |
<resultMap type="discount" id="discountResult">
|
|
|
18 |
</resultMap>
|
|
|
19 |
|
|
|
20 |
<insert id="createCart" parameterType="cart" useGeneratedKeys="true" keyProperty="id">
|
|
|
21 |
INSERT INTO cart
|
|
|
22 |
(cart_status, checked_out_on, created_on, updated_on,
|
|
|
23 |
total_price, discounted_price, coupon_code )
|
|
|
24 |
VALUES
|
|
|
25 |
(#{cart_status}, #{checked_out_on}, #{created_on}, #{updated_on},
|
|
|
26 |
#{total_price}, #{discounted_price}, #{coupon_code})
|
|
|
27 |
</insert>
|
|
|
28 |
|
|
|
29 |
<insert id="insertDiscount" parameterType="discount" useGeneratedKeys="true" keyProperty="id">
|
|
|
30 |
INSERT INTO discount
|
|
|
31 |
(line_cart_id, line_item_id, discount, quantity)
|
|
|
32 |
VALUES
|
|
|
33 |
(#{line_cart_id}, #{line_item_id}, #{discount}, #{quantity})
|
|
|
34 |
</insert>
|
|
|
35 |
|
|
|
36 |
<select id="getDiscounts" parameterType="map" resultType="discount">
|
|
|
37 |
SELECT *
|
|
|
38 |
FROM discount
|
|
|
39 |
<where>
|
|
|
40 |
line_cart_id = #{cart_id}
|
|
|
41 |
AND line_item_id = #{item_id}
|
|
|
42 |
</where>
|
|
|
43 |
</select>
|
|
|
44 |
|
|
|
45 |
<insert id="insertLine" parameterType="line">
|
|
|
46 |
INSERT INTO line
|
|
|
47 |
(cart_id, item_id, quantity, line_status, estimate, created_on, updated_on,
|
|
|
48 |
actual_price)
|
|
|
49 |
VALUES
|
|
|
50 |
(#{cart_id}, #{item_id}, #{quantity}, #{line_status}, #{estimate}, #{created_on},
|
|
|
51 |
#{updated_on}, #{actual_price})
|
|
|
52 |
</insert>
|
|
|
53 |
|
|
|
54 |
<update id="updateLineQuantity" parameterType="map">
|
|
|
55 |
UPDATE line
|
|
|
56 |
SET quantity = #{quantity},
|
|
|
57 |
updated_on = #{date}
|
|
|
58 |
<where>
|
|
|
59 |
cart_id = #{cartId}
|
|
|
60 |
AND item_id = #{itemId}
|
|
|
61 |
</where>
|
|
|
62 |
</update>
|
|
|
63 |
|
|
|
64 |
<delete id="deleteDiscountForLine" parameterType="map">
|
|
|
65 |
DELETE from discount
|
|
|
66 |
<where>
|
|
|
67 |
line_cart_id = #{cartId}
|
|
|
68 |
AND line_item_id = #{itemId}
|
|
|
69 |
</where>
|
|
|
70 |
</delete>
|
|
|
71 |
|
|
|
72 |
<delete id="deleteLine" parameterType="map">
|
|
|
73 |
DELETE from line
|
|
|
74 |
<where>
|
|
|
75 |
cart_id = #{cartId}
|
|
|
76 |
AND item_id = #{itemId}
|
|
|
77 |
</where>
|
|
|
78 |
</delete>
|
|
|
79 |
|
|
|
80 |
<update id="changeCartStatus" parameterType="map">
|
|
|
81 |
UPDATE cart
|
|
|
82 |
SET cart_status = #{status}
|
|
|
83 |
<where>
|
|
|
84 |
id = #{cartId}
|
|
|
85 |
</where>
|
|
|
86 |
</update>
|
|
|
87 |
|
|
|
88 |
<select id="getCart" parameterType="long" resultMap="cartWithLineResult">
|
|
|
89 |
SELECT *
|
|
|
90 |
FROM cart
|
|
|
91 |
<where>
|
|
|
92 |
id = #{id}
|
|
|
93 |
</where>
|
|
|
94 |
</select>
|
|
|
95 |
|
|
|
96 |
<select id="getCartsByStatus" parameterType="int" resultMap="cartWithLineResult">
|
|
|
97 |
SELECT *
|
|
|
98 |
FROM cart
|
|
|
99 |
<where>
|
|
|
100 |
cart_status = #{status}
|
|
|
101 |
</where>
|
|
|
102 |
</select>
|
|
|
103 |
|
|
|
104 |
<select id="getCartsByTime" parameterType="map" resultMap="cartWithLineResult">
|
|
|
105 |
SELECT *
|
|
|
106 |
FROM cart
|
|
|
107 |
<where>
|
|
|
108 |
cart_status = #{status}
|
|
|
109 |
AND created_on >= #{from_time}
|
|
|
110 |
AND created_on <= #{to_time}
|
|
|
111 |
</where>
|
|
|
112 |
</select>
|
|
|
113 |
|
|
|
114 |
<select id="getCartsWithCouponCount" parameterType="String" resultType="long">
|
|
|
115 |
SELECT id
|
|
|
116 |
FROM cart
|
|
|
117 |
<where>
|
|
|
118 |
coupon_code = #{couponCode}
|
|
|
119 |
</where>
|
|
|
120 |
</select>
|
|
|
121 |
|
|
|
122 |
<select id="getLine" parameterType="map" resultType="line">
|
|
|
123 |
SELECT *
|
|
|
124 |
FROM line
|
|
|
125 |
<where>
|
|
|
126 |
item_id = #{itemId}
|
|
|
127 |
AND cart_id = #{cartId}
|
|
|
128 |
<if test="status != -1">
|
|
|
129 |
AND line_status = #{status}
|
|
|
130 |
</if>
|
|
|
131 |
</where>
|
|
|
132 |
LIMIT 1
|
|
|
133 |
</select>
|
|
|
134 |
|
|
|
135 |
<select id="getLineByCartId" parameterType="int" resultMap="lineResult">
|
|
|
136 |
SELECT *
|
|
|
137 |
FROM line
|
|
|
138 |
<where>
|
|
|
139 |
cart_id = #{id}
|
|
|
140 |
</where>
|
|
|
141 |
</select>
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
<update id="updateLine" parameterType="line">
|
|
|
145 |
UPDATE line
|
|
|
146 |
SET line_status = #{line_status},
|
|
|
147 |
updated_on = #{updated_on},
|
|
|
148 |
quantity = #{quantity},
|
|
|
149 |
discounted_price = #{discounted_price},
|
|
|
150 |
actual_price = #{actual_price},
|
|
|
151 |
estimate = #{estimate}
|
|
|
152 |
<where>
|
|
|
153 |
cart_id = #{cart_id}
|
|
|
154 |
AND item_id = #{item_id}
|
|
|
155 |
</where>
|
|
|
156 |
</update>
|
|
|
157 |
|
|
|
158 |
<update id="changeCartIdForLine" parameterType="map">
|
|
|
159 |
UPDATE line
|
|
|
160 |
SET cart_id = #{toCartId}
|
|
|
161 |
<where>
|
|
|
162 |
cart_id = #{fromCartId}
|
|
|
163 |
AND item_id = #{itemId}
|
|
|
164 |
</where>
|
|
|
165 |
</update>
|
|
|
166 |
|
|
|
167 |
<update id="updateCartUpdatedTime" parameterType="map">
|
|
|
168 |
UPDATE cart
|
|
|
169 |
SET updated_on = #{date}
|
|
|
170 |
<where>
|
|
|
171 |
id = #{cartId}
|
|
|
172 |
</where>
|
|
|
173 |
</update>
|
|
|
174 |
|
|
|
175 |
<update id="removeLineDiscount" parameterType="map">
|
|
|
176 |
UPDATE line
|
|
|
177 |
SET discounted_price = NULL
|
|
|
178 |
<where>
|
|
|
179 |
cart_id = #{cartId}
|
|
|
180 |
AND item_id = #{itemId}
|
|
|
181 |
</where>
|
|
|
182 |
</update>
|
|
|
183 |
|
|
|
184 |
<update id="addAddressToCart" parameterType="map">
|
|
|
185 |
UPDATE cart
|
|
|
186 |
SET address_id = #{addressId}
|
|
|
187 |
<where>
|
|
|
188 |
id = #{cartId}
|
|
|
189 |
</where>
|
|
|
190 |
</update>
|
|
|
191 |
|
|
|
192 |
<update id="updateCart" parameterType="cart">
|
|
|
193 |
UPDATE cart
|
|
|
194 |
SET total_price = #{total_price},
|
|
|
195 |
discounted_price = #{discounted_price},
|
|
|
196 |
coupon_code = #{coupon_code},
|
|
|
197 |
updated_on = #{updated_on},
|
|
|
198 |
checked_out_on = #{checked_out_on},
|
|
|
199 |
total_price = #{total_price},
|
|
|
200 |
discounted_price = #{discounted_price},
|
|
|
201 |
coupon_code = #{coupon_code}
|
|
|
202 |
<where>
|
|
|
203 |
id = #{id}
|
|
|
204 |
</where>
|
|
|
205 |
</update>
|
|
|
206 |
|
|
|
207 |
<update id="deActivateCart" parameterType="long">
|
|
|
208 |
UPDATE cart
|
|
|
209 |
SET cart_status = 1
|
|
|
210 |
<where>
|
|
|
211 |
id = #{id}
|
|
|
212 |
</where>
|
|
|
213 |
</update>
|
|
|
214 |
|
|
|
215 |
</mapper>
|