IMProductMapper.xml
22.5 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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
<?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.dao.IMProductDao">
<select id="listImProductById" resultMap="listIMProduct" parameterType="map">
SELECT
<include refid="Base_Product_Column"/>
FROM
im_product imp
WHERE
imp.delete_flag = 1 AND imp.is_show = 1 AND imp.product_type = ${type} and imp.audit_flag = 100
<if test="iMCategoryId != null and iMCategoryId != ''">
AND imp.im_category_id = #{iMCategoryId}
</if>
<if test="iMCategoryId == null or iMCategoryId == ''">
AND imp.is_hot = 1
</if>
ORDER BY
<if test="type == 0">
imp.xws_exchange_integral ASC
</if>
<if test="type == 1">
imp.retail_price ASC
</if>
LIMIT ${pageNow}, ${pageSize}
</select>
<select id="totalImProductById" resultType="int" parameterType="map">
select count(1)
FROM im_product imp
WHERE
imp.delete_flag = 1 AND imp.is_show = 1 AND product_type = ${type} and imp.audit_flag = 100
<if test="iMCategoryId != null and iMCategoryId != ''">
AND imp.im_category_id = #{iMCategoryId}
</if>
<if test="iMCategoryId == null or iMCategoryId == ''">
AND imp.is_hot = 1
</if>
</select>
<!-- 搜索产品 -->
<select id="searchImProduct" resultMap="listIMProduct" parameterType="map">
SELECT
<include refid="Base_Product_Column"/>
FROM
im_product imp
WHERE
imp.delete_flag = 1 AND imp.is_show = 1 AND imp.product_type = ${type} and imp.audit_flag = 100
AND imp.name like concat('%',#{keyword},'%')
ORDER BY
<if test="type == 1">
<if test="sortType == 'descPrice'">
imp.retail_price desc
</if>
<if test="sortType == 'ascPrice'">
imp.retail_price asc
</if>
</if>
<if test="type == 0">
<if test="sortType == 'descPrice'">
imp.xws_exchange_integral desc
</if>
<if test="sortType == 'ascPrice'">
imp.xws_exchange_integral asc
</if>
</if>
<if test="sortType == 'cost'">
imp.cost desc
</if>
LIMIT ${pageNow}, ${pageSize}
</select>
<!--添加用户搜索记录-->
<insert id="addProductSearch" parameterType="com.sibu.orderHelper.integral.request.ProductSearchAddRequest">
INSERT INTO t_product_search (
phone,wechat,level_name,search_content,member_id,nick_name,true_name
) VALUES (
#{phone},#{wechat},#{levelName},#{searchContent},#{memberId},#{nickName},#{trueName}
)
</insert>
<!-- 统计搜索的产品数量 -->
<select id="totalSearchImProduct" resultType="int" parameterType="map">
select count(1)
FROM im_product imp
WHERE
imp.delete_flag = 1 AND imp.is_show = 1 AND imp.product_type = ${type}
AND imp.name like concat('%',#{keyword},'%')
</select>
<!-- 查询首页热销推荐的10哥产品 -->
<select id="listShowIndexProduct" resultMap="listIMProduct" parameterType="java.lang.Integer" useCache="true"
statementType="PREPARED">
SELECT
<include refid="Base_Product_Column" />
FROM
im_product imp
WHERE
imp.delete_flag = 1 AND imp.is_show = 1 AND imp.is_hot = 1 AND imp.product_type = ${_parameter}
ORDER BY
imp.sort_index asc
LIMIT 0,10
</select>
<!-- 新款上架查询 -->
<select id="listNewProductIndex" resultMap="listIMProduct" parameterType="java.util.Map" useCache="true"
statementType="PREPARED">
<if test="sortType == 'cost'">
SELECT
imp.im_product_id,
imp.name,
imp.short_name,
imp.stock_num,
imp.exchange_integral,
imp.xws_exchange_integral,
imp.sibukg_exchange_integral,
imp.onther1_exchange_integral,
imp.onther2_exchange_integral,
imp.onther3_exchange_integral,
imp.limit_exchange_number,
imp.thumb_img,
imp.is_new,
imp.is_hot,
imp.is_reco,
ipi.cost,
imp.attention,
imp.is_show,
imp.product_type,
imp.retail_price,
imp.market_price,
imp.member_price,
imp.is_open_spec,
imp.spec,
imp.mini_purchase_number,
imp.format_str
FROM im_product_inventory ipi left join im_product imp on imp.im_product_id = ipi.im_product_id
WHERE
imp.delete_flag = 1 AND imp.is_show = 1 AND imp.is_new = 1 AND imp.product_type = ${type}
ORDER BY
ipi.cost desc
LIMIT ${pageNow}, ${pageSize}
</if>
<if test="sortType == 'descPrice'">
SELECT
<include refid="Base_Product_Column"/>
FROM
im_product imp
WHERE
imp.delete_flag = 1 AND imp.is_show = 1 AND imp.is_new = 1 AND imp.product_type = ${type}
ORDER BY imp.retail_price desc ,imp.im_product_id desc
LIMIT ${pageNow}, ${pageSize}
</if>
<if test="sortType == 'ascPrice'">
SELECT
<include refid="Base_Product_Column"/>
FROM
im_product imp
WHERE
imp.delete_flag = 1 AND imp.is_show = 1 AND imp.is_new = 1 AND imp.product_type = ${type}
ORDER BY imp.retail_price asc,imp.im_product_id asc
LIMIT ${pageNow}, ${pageSize}
</if>
<if test="sortType == 'ascDiscount'">
select
<include refid="Base_Product_Column"/>
from (
SELECT
impr.retail_price / impr.market_price discou,
impr.im_product_id
FROM
im_product impr
WHERE
impr.market_price != 0
AND impr.market_price IS NOT NULL
AND impr.delete_flag = 1 AND impr.is_show = 1 AND impr.is_new = 1 AND impr.product_type = ${type}
ORDER BY
discou asc,im_product_id asc
LIMIT ${pageNow}, ${pageSize} ) impr1 LEFT JOIN im_product imp on imp.im_product_id = impr1.im_product_id
</if>
<if test="sortType == 'descDiscount'">
select
<include refid="Base_Product_Column"/>
from (
SELECT
impr.retail_price / impr.market_price discou,
impr.im_product_id
FROM
im_product impr
WHERE
impr.market_price != 0
AND impr.market_price IS NOT NULL
AND impr.delete_flag = 1 AND impr.is_show = 1 AND impr.is_new = 1 AND impr.product_type = ${type}
ORDER BY
discou desc,im_product_id desc
LIMIT ${pageNow}, ${pageSize} ) impr1 LEFT JOIN im_product imp on imp.im_product_id = impr1.im_product_id
</if>
<if test="sortType == '' or sortType == null">
SELECT
<include refid="Base_Product_Column"/>
FROM
im_product imp
WHERE
imp.delete_flag = 1 AND imp.is_show = 1 AND imp.is_new = 1 AND imp.product_type = ${type}
ORDER BY imp.sort_index asc
LIMIT ${pageNow}, ${pageSize}
</if>
</select>
<select id="totalNewImProductById" resultType="int" parameterType="map">
select count(1)
FROM im_product imp
WHERE
imp.delete_flag = 1 AND imp.is_show = 1 AND imp.is_new = 1 AND product_type = ${type}
</select>
<!--获取可以分享的商品列表-->
<select id="listCanShareProduct" parameterType="java.util.Map" resultMap="APIProductBean">
<if test="sortType == 'cost'">
SELECT
imp.im_product_id,imp.name,imp.short_name,imp.stock_num,imp.exchange_integral,imp.xws_exchange_integral,imp.sibukg_exchange_integral,imp.onther1_exchange_integral,
imp.onther2_exchange_integral,imp.onther3_exchange_integral,imp.limit_exchange_number,imp.thumb_img,imp.is_new,imp.is_hot,imp.is_reco,ipi.cost,imp.attention,
imp.is_show,imp.product_type,imp.retail_price,imp.market_price,imp.member_price,imp.is_open_spec,imp.spec,imp.mini_purchase_number,imp.format_str,imp.share_status,
imp.share_percentage
FROM im_product imp LEFT JOIN
im_product_inventory ipi ON imp.im_product_id = ipi.im_product_id
where imp.share_status = 1 and imp.delete_flag = 1 AND imp.is_show = 1 and imp.product_type = 1
ORDER BY
ipi.cost desc
LIMIT ${pageNow}, ${pageSize}
</if>
<if test="sortType == 'descPrice'">
SELECT
<include refid="Base_Product_Column"/>
FROM im_product imp
where imp.share_status = 1 and imp.delete_flag = 1 AND imp.is_show = 1 and imp.product_type = 1
ORDER BY imp.retail_price desc
LIMIT ${pageNow}, ${pageSize}
</if>
<if test="sortType == 'ascPrice'">
SELECT
<include refid="Base_Product_Column"/>
FROM im_product imp
where imp.share_status = 1 and imp.delete_flag = 1 AND imp.is_show = 1 and imp.product_type = 1
ORDER BY imp.retail_price asc
LIMIT ${pageNow}, ${pageSize}
</if>
<if test="sortType == 'descCommission'">
SELECT
<include refid="Base_Product_Column"/>
FROM im_product imp
where imp.share_status = 1 and imp.delete_flag = 1 AND imp.is_show = 1 and imp.product_type = 1
ORDER BY imp.share_percentage desc
LIMIT ${pageNow}, ${pageSize}
</if>
<if test="sortType == 'ascCommission'">
SELECT
<include refid="Base_Product_Column"/>
FROM im_product imp
where imp.share_status = 1 and imp.delete_flag = 1 AND imp.is_show = 1 and imp.product_type = 1
ORDER BY imp.share_percentage asc
LIMIT ${pageNow}, ${pageSize}
</if>
<if test="sortType == '' or sortType == null">
SELECT
<include refid="Base_Product_Column"/>
FROM
im_product imp
where imp.share_status = 1 and imp.delete_flag = 1 AND imp.is_show = 1 and imp.product_type = 1
ORDER BY imp.sort_index asc
LIMIT ${pageNow}, ${pageSize}
</if>
</select>
<select id="totalCanShareProduct" resultType="int" parameterType="java.util.Map">
select count(1) from im_product imp where imp.share_status=1 and imp.delete_flag = 1 AND imp.is_show = 1 and imp.product_type = 1
</select>
<!-- 专场产品查询 -->
<select id="listCampaginProduct" resultMap="listIMProduct" parameterType="java.util.Map" useCache="true"
statementType="PREPARED">
select
<include refid="Base_Product_Column2"/>
from campaign_product cp
left join im_product imp on cp.product_id=imp.im_product_id
left join im_product_inventory imi on cp.product_id=imi.im_product_id
where cp.campaign_id =#{campaginId} and cp.is_show = 1 and cp.product_type = #{productType} and imp.is_show =1 and imp.delete_flag = 1 and imp.audit_flag = 100
<if test="supplierId != '' and supplierId != null">
and imp.im_product_id in (select product_id from im_product_supplier where supplier_id=#{supplierId})
</if>
<choose>
<when test="sortType == 'cost'">
ORDER BY imi.cost desc,imi.im_product_id desc
</when>
<when test="sortType == 'ascPrice'">
ORDER BY imp.retail_price asc,imp.im_product_id asc
</when>
<when test="sortType == 'descPrice'">
ORDER BY imp.retail_price desc, imp.im_product_id desc
</when>
<when test="sortType == 'comprehensiveRetailPrice'">
ORDER BY cp.campaign_sort_index,imp.retail_price,imi.cost desc
</when>
<otherwise>
ORDER BY cp.campaign_sort_index,imp.member_price,imi.cost desc
</otherwise>
</choose>
LIMIT ${pageNow}, ${pageSize}
</select>
<select id="totalCampaginProduct" resultType="int" parameterType="map">
select
count(*)
from campaign_product cp
left join im_product imp on cp.product_id=imp.im_product_id
left join im_product_inventory imi on cp.product_id=imi.im_product_id
where cp.campaign_id =#{campaginId} and cp.is_show = 1 and cp.product_type = #{productType} and imp.is_show =1 and imp.delete_flag = 1
<if test="supplierId != '' and supplierId != null">
and imp.im_product_id in (select product_id from im_product_supplier where supplier_id=#{supplierId})
</if>
</select>
<!-- 刷新购物车中的商品价格 -->
<select id="refreshPriceByIds" resultMap="listIMProduct" parameterType="java.util.List" useCache="true"
statementType="PREPARED">
SELECT
<include refid="Base_Product_Column2"/>
FROM
im_product imp left join im_product_inventory imi on imp.im_product_id = imi.im_product_id
WHERE
imp.im_product_id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="getProductDetailById" resultMap="APIProductBean" parameterType="String" useCache="true"
statementType="PREPARED">
select imp.im_product_id,
imp.name,
imp.short_name,
imp.stock_num,
imp.details,
imp.exchange_integral,
imp.xws_exchange_integral,
imp.sibukg_exchange_integral,
imp.onther1_exchange_integral,
imp.onther2_exchange_integral,
imp.onther3_exchange_integral,
imp.limit_exchange_number,
imp.thumb_img,
imp.bannel_img1,
imp.bannel_img2,
imp.bannel_img3,
imp.bannel_img4,
imp.bannel_img5,
imp.is_new,
imp.is_hot,
imp.is_reco,
imp.is_show,
imp.product_type,
imp.member_price,
imp.retail_price,
imp.market_price,
imp.is_open_spec,
imp.spec,
imp.mini_purchase_number,
imp.format_str,
imp.is_group,
imp.share_status,
imp.share_percentage,
imp.delete_flag,
ipi.attention,
ipi.total_comment_score,
ipi.total_comment_number,
ipi.cost
FROM im_product imp left join im_product_inventory ipi on imp.im_product_id = ipi.im_product_id
WHERE
imp.im_product_id = #{productId}
AND imp.delete_flag = 1
</select>
<!-- 更新积分产品的评论人数和分数 -->
<update id="updateProductComment" parameterType="IMProductCommentBean">
UPDATE im_product_inventory SET total_comment_score=total_comment_score+${grade}, total_comment_number=total_comment_number+1
WHERE im_product_id=#{imProductId}
</update>
<!-- 更新产品销量 -->
<update id="updataProductCost" parameterType="map">
UPDATE im_product_inventory SET cost = cost + ${amount}, stock_num = stock_num - ${amount}
WHERE im_product_id=#{imProductId}
</update>
<sql id="Base_Product_Column">
imp.im_product_id,
imp.name,
imp.short_name,
imp.stock_num,
imp.exchange_integral,
imp.xws_exchange_integral,
imp.sibukg_exchange_integral,
imp.onther1_exchange_integral,
imp.onther2_exchange_integral,
imp.onther3_exchange_integral,
imp.limit_exchange_number,
imp.thumb_img,
imp.is_new,
imp.is_hot,
imp.is_reco,
imp.cost,
imp.attention,
imp.is_show,
imp.product_type,
imp.member_price,
imp.retail_price,
imp.market_price,
imp.is_open_spec,
imp.spec,
imp.mini_purchase_number,
imp.format_str,
imp.share_status,
imp.share_percentage
</sql>
<sql id="Base_Product_Column2">
imp.im_product_id,
imp.name,
imp.short_name,
ifnull(imi.stock_num,0) as stock_num,
imp.exchange_integral,
imp.xws_exchange_integral,
imp.sibukg_exchange_integral,
imp.onther1_exchange_integral,
imp.onther2_exchange_integral,
imp.onther3_exchange_integral,
imp.limit_exchange_number,
imp.thumb_img,
imp.is_new,
imp.is_hot,
imp.is_reco,
imp.cost,
imp.attention,
imp.is_show,
imp.product_type,
imp.member_price,
imp.retail_price,
imp.market_price,
imp.is_open_spec,
imp.spec,
imp.mini_purchase_number,
imp.format_str,
imp.share_status,
imp.share_percentage
</sql>
<resultMap type="IMProductBean" id="listIMProduct">
<result column="im_product_id" property="imProductId"/>
<result column="name" property="name"/>
<result column="short_name" property="shortName"/>
<result column="stock_num" property="stockNum"/>
<result column="details" property="details"/>
<result column="exchange_integral" property="exchangeIntegral"/>
<result column="xws_exchange_integral" property="xwsExchangeIntegral"/>
<result column="sibukg_exchange_integral" property="sibukgExchangeIntegral"/>
<result column="onther1_exchange_integral" property="onther1ExchangeIntegral"/>
<result column="onther2_exchange_integral" property="onther2ExchangeIntegral"/>
<result column="onther3_exchange_integral" property="onther3ExchangeIntegral"/>
<result column="thumb_img" property="thumbImg"/>
<result column="bannel_img1" property="bannelImg1"/>
<result column="bannel_img2" property="bannelImg2"/>
<result column="bannel_img3" property="bannelImg3"/>
<result column="bannel_img4" property="bannelImg4"/>
<result column="bannel_img5" property="bannelImg5"/>
<result column="limit_exchange_number" property="limitExchangeNumber"/>
<result column="is_new" property="isNew"/>
<result column="is_hot" property="isHot"/>
<result column="is_reco" property="isReco"/>
<result column="cost" property="cost"/>
<result column="attention" property="attention"/>
<result column="total_comment_score" property="totalCommentScore"/>
<result column="total_comment_number" property="totalCommentNumber"/>
<result column="member_price" property="memberPrice"/>
<result column="retail_price" property="retailPrice"/>
<result column="market_price" property="marketPrice"/>
<result column="product_type" property="productType"/>
<result column="is_show" property="isShow"/>
<result column="is_open_spec" property="isOpenSpec"/>
<result column="spec" property="spec"/>
<result column="mini_purchase_number" property="miniPurchaseNumber"/>
<result column="format_str" property="formatStr"/>
<result column="is_group" property="isGroup"/>
</resultMap>
<resultMap type="IMProductBean" id="APIProductBean">
<result column="im_product_id" property="imProductId"/>
<result column="name" property="name"/>
<result column="short_name" property="shortName"/>
<result column="stock_num" property="stockNum"/>
<result column="details" property="details"/>
<result column="exchange_integral" property="exchangeIntegral"/>
<result column="xws_exchange_integral" property="xwsExchangeIntegral"/>
<result column="sibukg_exchange_integral" property="sibukgExchangeIntegral"/>
<result column="onther1_exchange_integral" property="onther1ExchangeIntegral"/>
<result column="onther2_exchange_integral" property="onther2ExchangeIntegral"/>
<result column="onther3_exchange_integral" property="onther3ExchangeIntegral"/>
<result column="thumb_img" property="thumbImg"/>
<result column="bannel_img1" property="bannelImg1"/>
<result column="bannel_img2" property="bannelImg2"/>
<result column="bannel_img3" property="bannelImg3"/>
<result column="bannel_img4" property="bannelImg4"/>
<result column="bannel_img5" property="bannelImg5"/>
<result column="limit_exchange_number" property="limitExchangeNumber"/>
<result column="is_new" property="isNew"/>
<result column="is_hot" property="isHot"/>
<result column="is_reco" property="isReco"/>
<result column="cost" property="cost"/>
<result column="attention" property="attention"/>
<result column="total_comment_score" property="totalCommentScore"/>
<result column="total_comment_number" property="totalCommentNumber"/>
<result column="member_price" property="memberPrice"/>
<result column="retail_price" property="retailPrice"/>
<result column="market_price" property="marketPrice"/>
<result column="product_type" property="productType"/>
<result column="is_show" property="isShow"/>
<result column="is_open_spec" property="isOpenSpec"/>
<result column="spec" property="spec"/>
<result column="mini_purchase_number" property="miniPurchaseNumber"/>
<result column="format_str" property="formatStr"/>
<result column="is_group" property="isGroup"/>
<result column="share_status" property="shareStatus"/>
<result column="share_percentage" property="sharePercentage"/>
<result column="delete_flag" property="deleteFlag"/>
</resultMap>
<select id="getProductSku" parameterType="map" 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 FROM sku s
where s.im_product_id =#{productId} and s.sku_id = #{skuId} limit 1
</select>
<resultMap id="skuResponse" type="com.sibu.orderHelper.integral.model.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="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"/>
</resultMap>
</mapper>