SkuMapper.xml
13.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.sibu.orderHelper.integral.web.dao.IMSkuDao">
<resultMap id="skuResponse" type="com.sibu.orderHelper.integral.reponse.SkuResponse">
<result property="skuId" column="sku_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="imProductId" column="im_product_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="erpCode" column="erp_code" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="stockNum" column="stock_num" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="exchangeIntegral" column="exchange_integral" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="memberPrice" column="member_price" />
<result property="retailPrice" column="retail_price" />
<result property="marketPrice" column="market_price" />
<result property="isShow" column="is_show" javaType="java.lang.Boolean" jdbcType="VARCHAR"/>
<collection property="values" ofType="com.sibu.orderHelper.integral.reponse.SkuValueResponse" column="sku_Id">
<result property="attrValueId" column="attr_value_id" javaType="java.lang.Long" jdbcType="BIGINT"/>
<result property="attrId" column="attr_id" javaType="java.lang.Long" jdbcType="BIGINT"/>
<result property="attrName" column="attr_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
</collection>
</resultMap>
<!-- API返回类 -->
<resultMap id="skuApiResponse" type="com.sibu.orderHelper.integral.reponse.SkuApiResponse">
<result property="skuId" column="sku_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="erpCode" column="erp_code" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="stockNum" column="stock_num" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="exchangeIntegral" column="exchange_integral" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="retailPrice" column="retail_price"/>
<result property="marketPrice" column="market_price"/>
<result property="memberPrice" column="member_price"/>
<collection property="values" ofType="com.sibu.orderHelper.integral.reponse.SkuValueResponse" column="sku_Id">
<result property="attrValueId" column="attr_value_id" javaType="java.lang.Long" jdbcType="BIGINT"/>
<result property="attrId" column="attr_id" javaType="java.lang.Long" jdbcType="BIGINT"/>
<result property="attrName" column="attr_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="valueName" column="attr_value" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="sortIndex" column="sort_index" javaType="java.lang.Integer" jdbcType="TINYINT"/>
</collection>
</resultMap>
<resultMap type="com.sibu.orderHelper.integral.model.SkuBean" id="skuBean">
<result property="skuId" column="sku_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="imProductId" column="im_product_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="erpCode" column="erp_code" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="stockNum" column="stock_num" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="exchangeIntegral" column="exchange_integral" javaType="java.lang.Integer" jdbcType="INTEGER"/>
<result property="retailPrice" column="retail_price" />
<result property="marketPrice" column="market_price" />
<result property="isShow" column="is_show" javaType="java.lang.Boolean" jdbcType="VARCHAR"/>
</resultMap>
<!-- 查询product sku返回 -->
<select id="selectSkuByProductId" parameterType="java.lang.String" resultMap="skuResponse">
SELECT s.sku_id,s.im_product_id,s.erp_code,s.stock_num,s.exchange_integral,
s.member_price,s.retail_price,s.market_price,
s.is_show,ref.attr_value_id,n.attr_id,n.attr_name FROM sku s
INNER JOIN attr_ref ref ON s.sku_id =ref.sku_id
INNER JOIN attr_value v ON v.value_id =ref.attr_value_id
INNER JOIN attr_name n ON n.attr_id =v.attr_id
where s.im_product_id =#{productId}
</select>
<!-- 查询sku bean -->
<select id="listSkuBeanByProductId" parameterType="java.lang.String" resultMap="skuBean">
select sku_id,im_product_id,erp_code,stock_num,exchange_integral,retail_price,market_price,is_show from sku where im_product_id=#{productId}
</select>
<!-- 查询product sku返回 -->
<select id="selectApiSkuByProductId" parameterType="java.lang.String" resultMap="skuApiResponse">
SELECT s.sku_id,s.erp_code,s.stock_num,s.exchange_integral,s.retail_price,s.market_price,s.member_price,
s.is_show,ref.attr_value_id,n.attr_id,n.attr_name,v.attr_value ,n.sort_index FROM sku s
INNER JOIN attr_ref ref ON s.sku_id =ref.sku_id
INNER JOIN attr_value v ON v.value_id =ref.attr_value_id
INNER JOIN attr_name n ON n.attr_id =v.attr_id
WHERE s.im_product_id =#{productId}
ORDER BY n.sort_index
</select>
<!-- 保存实体 -->
<insert id="save" parameterType="com.sibu.orderHelper.integral.request.ProductSpecRequest">
INSERT INTO sku (
sku_id,im_product_id,erp_code,stock_num,exchange_integral,member_price,retail_price,market_price,create_date,update_date,is_show
) VALUES (
#{skuId},#{productId},#{erpCode},#{stockNum},#{integral},
#{memberPrice},#{price},#{marketPrice},now(),now(),#{isShow}
)
</insert>
<!-- 批量保存 -->
<insert id="batchSave" parameterType="java.util.List">
INSERT INTO sku (
sku_id,im_product_id,erp_code,stock_num,exchange_integral,member_price,retail_price,market_price,create_date,update_date,is_show
) VALUES
<foreach collection="list" item="sku" separator=",">
(#{sku.skuId},#{sku.productId},#{sku.erpCode},#{sku.stockNum},#{sku.integral},
#{sku.memberPrice},#{sku.price},#{sku.marktPrice},now(),now(),#{sku.isShow})
</foreach>
</insert>
<!-- 批量保存 -->
<insert id="batchSaveSkuValue" parameterType="java.util.List">
insert into attr_ref (sku_id,attr_value_id) values
<foreach collection="list" item="item" separator=",">
(#{item.skuId},#{item.attrValueId})
</foreach>
</insert>
<update id="updateSku" parameterType="com.sibu.orderHelper.integral.request.ProductSpecRequest">
UPDATE sku
<trim prefix="SET" suffixOverrides=",">
<if test="null != erpCode">
erp_code=#{erpCode},
</if>
<if test="null != stockNum">
stock_num=#{stockNum},
</if>
<if test="null != integral">
exchange_integral=#{integral},
</if>
<if test="null != memberPrice">
member_price=#{memberPrice},
</if>
<if test="null != price">
retail_price=#{price},
</if>
<if test="null != marktPrice">
market_price=#{marktPrice},
</if>
<if test="null != isShow">
is_show=#{isShow},
</if>
update_date=now()
</trim>
WHERE sku_id = #{skuId}
</update>
<!-- 同步sku库存和价格 -->
<update id="syncSkuStockAndPrice" parameterType="com.sibu.orderHelper.integral.model.SkuBean">
update sku
<trim prefix="SET" suffixOverrides=",">
<if test="null != stockNum">
stock_num=#{stockNum},
</if>
<if test="null != exchangeIntegral">
exchange_integral=#{exchangeIntegral},
</if>
<if test="null != memberPrice">
member_price=#{memberPrice},
</if>
<if test="null != retailPrice">
retail_price=#{retailPrice},
</if>
<if test="null != marketPrice">
market_price=#{marketPrice},
</if>
update_date=now()
</trim>
WHERE erp_code=#{erpCode}
</update>
<!-- 删除sku实体 -->
<delete id="delete" parameterType="java.lang.String">
DELETE FROM sku WHERE sku_id = #{skuId}
</delete>
<!-- 批量删除SKU实体 -->
<delete id="batchDelete" parameterType="java.util.List">
DELETE FROM sku WHERE sku_id in
<foreach collection="list" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</delete>
<!-- 批量删除 -->
<delete id="batchDeleteSkuValue" parameterType="java.util.List">
delete from attr_ref where sku_id in
<foreach collection="list" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</delete>
<!-- 通过skuId批量删除对象 -->
<delete id="batchDeleteSkuValueBySkuId" parameterType="java.util.List">
delete from attr_ref where sku_id in
<foreach collection="list" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</delete>
<!-- 查出所有的产品SKU主键 -->
<select id="selectSkuIds" parameterType="java.util.Map" resultType="java.lang.String">
select sku_id from sku where im_product_id=#{productId}
</select>
<resultMap type="com.sibu.orderHelper.integral.model.AttrNameBean" id="attrNameBeanList">
<result property="attrId" column="attr_id" javaType="java.lang.Long" jdbcType="BIGINT"/>
<result property="categoryId" column="category_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="attrName" column="attr_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
</resultMap>
<resultMap type="com.sibu.orderHelper.integral.model.AttrValueBean" id="attrValueBeanList">
<result property="valueId" column="value_id" javaType="java.lang.Long" jdbcType="BIGINT"/>
<result property="attrValue" column="attr_value" javaType="java.lang.String" jdbcType="VARCHAR"/>
<result property="attrId" column="attr_id" javaType="java.lang.Long" jdbcType="BIGINT"/>
</resultMap>
<!-- 查出所有的产品规格属性值 -->
<select id="selectFirstAttrValue" parameterType="java.util.Map" resultMap="attrValueBeanList">
SELECT value_id,attr_value,attr_id
FROM attr_value WHERE attr_value=rtrim(ltrim(#{attrValue})) AND attr_id=rtrim(ltrim(#{attrNameId}))
Limit 0,1
</select>
<!-- 查出所有的产品规格属性名称-->
<select id="selectFirstAttrName" parameterType="java.util.Map" resultMap="attrNameBeanList">
SELECT attr_id,category_id ,attr_name
FROM attr_name WHERE attr_name=rtrim(ltrim(#{attrName})) AND category_id=rtrim(ltrim(#{categoryId}))
Limit 0,1
</select>
<!-- 判断该规格是否已经存在 -->
<select id="selectSkuByErpCodeAndProductId" parameterType="java.util.Map" resultMap="skuBean">
SELECT s.sku_id,s.im_product_id,s.erp_code,s.stock_num,s.exchange_integral,s.retail_price,s.market_price,
s.is_show FROM sku s
WHERE s.im_product_id =#{productId} AND s.erp_code=#{erpCode}
Limit 0,1
</select>
<!-- 判断属性联合键是否已经存在 -->
<select id="selectSkuListProductId" parameterType="java.util.Map" resultType="com.sibu.orderHelper.integral.vo.ImportSkuExist">
SELECT t0.sku_id AS skuId,t0.erp_code AS erpCode,t0.is_show AS isShow,
GROUP_CONCAT(t2.attr_value ORDER BY t2.attr_value DESC) AS attrValue,
t0.stock_num AS stockNum,t0.exchange_integral AS exchangeIntegral,t0.retail_price AS retailPrice
FROM sku t0
INNER JOIN attr_ref t1 ON t1.sku_id=t0.sku_id
INNER JOIN attr_value t2 ON t2.value_id=t1.attr_value_id
INNER JOIN attr_name t3 ON t3.attr_id=t2.attr_id
WHERE t0.im_product_id=#{productId}
GROUP BY t0.sku_id,t0.erp_code,t0.stock_num,t0.exchange_integral,t0.retail_price,t0.is_show
ORDER BY t0.sku_id ASC,t2.attr_value ASC,t0.erp_code ASC,t3.attr_name ASC
</select>
<!-- 单个保存 -->
<insert id="saveSku" parameterType="com.sibu.orderHelper.integral.request.ProductSpecRequest2">
INSERT INTO sku (
sku_id,im_product_id,erp_code,stock_num,exchange_integral,member_price,retail_price,market_price,create_date,update_date,is_show
) VALUES
(#{skuId},#{productId},#{erpCode},#{stockNum},#{integral},#{memberPrice},#{price}
,#{marktPrice},now(),now(),#{isShow})
</insert>
<!-- 单个保存 -->
<insert id="saveSkuValue" parameterType="com.sibu.orderHelper.integral.model.AttrRefBean">
insert into attr_ref (sku_id,attr_value_id) values
(#{skuId},#{attrValueId})
</insert>
<!-- 批量保存 -->
<insert id="batchSave2" parameterType="java.util.List">
INSERT INTO sku (
sku_id,im_product_id,erp_code,stock_num,exchange_integral,member_price,retail_price,market_price,create_date,update_date,is_show
) VALUES
<foreach collection="list" item="sku" separator=",">
(#{sku.skuId},#{sku.productId},#{sku.erpCode},#{sku.stockNum},#{sku.integral},#{sku.memberPrice},#{sku.price},#{sku.marktPrice},now(),now(),#{sku.isShow})
</foreach>
</insert>
<!-- 同步修改相同产品的库存 -->
<select id="selectSkuProductIdAndErpCode" parameterType="java.util.Map" resultMap="skuBean">
SELECT s.sku_id,s.im_product_id,s.erp_code,s.stock_num,s.exchange_integral,s.retail_price,s.market_price,s.is_show
FROM sku s WHERE s.`erp_code`=#{erpCode} AND s.`im_product_id` IN (
SELECT p.`im_product_id` FROM im_product p WHERE p.`im_product_id` != #{productId}
AND p.`erp_code`= (SELECT p.`erp_code` FROM im_product p WHERE p.`im_product_id`=#{productId})
)
</select>
<!-- 同步不同分类的相同产品SKU的库存 -->
<update id="syncSkuStock" parameterType="com.sibu.orderHelper.integral.model.SkuBean">
update sku
<trim prefix="SET" suffixOverrides=",">
<if test="null != erpCode">
erp_code=#{erpCode},
</if>
<if test="null != exchangeIntegral">
exchange_integral=#{exchangeIntegral},
</if>
<if test="null != memberPrice">
member_price=#{memberPrice},
</if>
<if test="null != retailPrice">
retail_price=#{retailPrice},
</if>
<if test="null != memberPrice">
market_price=#{memberPrice},
</if>
<if test="null != stockNum">
stock_num=#{stockNum},
</if>
update_date=now()
</trim>
WHERE erp_code=#{erpCode} AND im_product_id=#{imProductId}
</update>
<!-- 同步修改相同产品的库存 -->
<select id="getSkuById" parameterType="java.lang.String" resultMap="skuBean">
SELECT s.sku_id,s.im_product_id,s.erp_code,s.stock_num,s.exchange_integral,s.retail_price,s.market_price,s.is_show
FROM sku s WHERE s.sku_id=#{skuId}
</select>
<update id="updateSkuByStock" parameterType="com.sibu.orderHelper.integral.model.SkuBean">
UPDATE sku
<trim prefix="SET" suffixOverrides=",">
<if test="null != stockNum">
stock_num=#{stockNum},
</if>
<if test="null != isShow">
is_show=#{isShow},
</if>
update_date=now()
</trim>
WHERE sku_id = #{skuId}
</update>
</mapper>