|
@@ -2,7 +2,10 @@ package cn.lili.modules.goods.serviceimpl;
|
2
|
2
|
|
3
|
3
|
import cn.hutool.core.text.CharSequenceUtil;
|
4
|
4
|
import cn.hutool.core.util.NumberUtil;
|
|
5
|
+import cn.hutool.core.util.StrUtil;
|
5
|
6
|
import cn.hutool.json.JSONUtil;
|
|
7
|
+import cn.hutool.poi.excel.ExcelReader;
|
|
8
|
+import cn.hutool.poi.excel.ExcelUtil;
|
6
|
9
|
import cn.lili.cache.Cache;
|
7
|
10
|
import cn.lili.cache.CachePrefix;
|
8
|
11
|
import cn.lili.common.enums.ResultCode;
|
|
@@ -29,6 +32,7 @@ import cn.lili.modules.goods.service.GoodsSkuService;
|
29
|
32
|
import cn.lili.modules.member.entity.dos.MemberEvaluation;
|
30
|
33
|
import cn.lili.modules.member.entity.enums.EvaluationGradeEnum;
|
31
|
34
|
import cn.lili.modules.member.service.MemberEvaluationService;
|
|
35
|
+import cn.lili.modules.order.order.entity.dto.OrderBatchDeliverDTO;
|
32
|
36
|
import cn.lili.modules.store.entity.dos.FreightTemplate;
|
33
|
37
|
import cn.lili.modules.store.entity.dos.Store;
|
34
|
38
|
import cn.lili.modules.store.entity.vos.StoreVO;
|
|
@@ -41,6 +45,8 @@ import cn.lili.modules.system.service.SettingService;
|
41
|
45
|
import cn.lili.mybatis.util.PageUtil;
|
42
|
46
|
import cn.lili.rocketmq.RocketmqSendCallbackBuilder;
|
43
|
47
|
import cn.lili.rocketmq.tags.GoodsTagsEnum;
|
|
48
|
+import com.alibaba.fastjson.JSON;
|
|
49
|
+import com.alibaba.fastjson.TypeReference;
|
44
|
50
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
45
|
51
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
46
|
52
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
@@ -53,7 +59,10 @@ import org.springframework.beans.BeanUtils;
|
53
|
59
|
import org.springframework.beans.factory.annotation.Autowired;
|
54
|
60
|
import org.springframework.stereotype.Service;
|
55
|
61
|
import org.springframework.transaction.annotation.Transactional;
|
|
62
|
+import org.springframework.util.Assert;
|
|
63
|
+import org.springframework.web.multipart.MultipartFile;
|
56
|
64
|
|
|
65
|
+import java.io.InputStream;
|
57
|
66
|
import java.util.*;
|
58
|
67
|
|
59
|
68
|
/**
|
|
@@ -113,6 +122,9 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
113
|
122
|
@Autowired
|
114
|
123
|
private Cache<GoodsVO> cache;
|
115
|
124
|
|
|
125
|
+ @Autowired
|
|
126
|
+ private Cache<String> otherCache;
|
|
127
|
+
|
116
|
128
|
@Override
|
117
|
129
|
public List<Goods> getByBrandIds(List<String> brandIds) {
|
118
|
130
|
LambdaQueryWrapper<Goods> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
@@ -452,6 +464,92 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
452
|
464
|
.eq(Goods::getMarketEnable, GoodsStatusEnum.UPPER.name()));
|
453
|
465
|
}
|
454
|
466
|
|
|
467
|
+ private final static String INTRO_TEMP = "<p>%s</p>";
|
|
468
|
+ private final static String GOODS_IMPORT_KEY_PREFIX = "GOODS::IMPORT::";
|
|
469
|
+
|
|
470
|
+ @Override
|
|
471
|
+ public List<Goods> batchCreate(MultipartFile files) {
|
|
472
|
+ InputStream inputStream;
|
|
473
|
+ AuthUser authUser = UserContext.getCurrentUser();
|
|
474
|
+ Assert.notNull(authUser, "登录信息已失效,请重新登录");
|
|
475
|
+ try {
|
|
476
|
+ inputStream = files.getInputStream();
|
|
477
|
+ //2.应用HUtool ExcelUtil获取ExcelReader指定输入流和sheet
|
|
478
|
+ ExcelReader excelReader = ExcelUtil.getReader(inputStream);
|
|
479
|
+ //可以加上表头验证
|
|
480
|
+ //3.读取第二行到最后一行数据
|
|
481
|
+ List<List<Object>> read = excelReader.read(19, excelReader.getRowCount());
|
|
482
|
+ List<Goods> goodsList = new ArrayList<>(read.size());
|
|
483
|
+ Goods goods = null;
|
|
484
|
+ String itemNo = null;
|
|
485
|
+ for (int i = 0; i < read.size(); i++) {
|
|
486
|
+ List<Object> props = read.get(i);
|
|
487
|
+ if (i%2 == 1){
|
|
488
|
+ // 商品规格明细
|
|
489
|
+ String[] strs = String.valueOf(props.get(3)).split("\\|");
|
|
490
|
+ itemNo = strs[strs.length - 1];
|
|
491
|
+ goods.setGoodsName(goods.getGoodsName() + itemNo + " ");
|
|
492
|
+ goods.setIntro(String.format(INTRO_TEMP, String.valueOf(props.get(3)).replace("|" + itemNo, "")));
|
|
493
|
+ goods.setMobileIntro(goods.getIntro());
|
|
494
|
+ goods.setSellingPoint(strs[strs.length - 3]);
|
|
495
|
+ goodsList.add(goods);
|
|
496
|
+ }else {
|
|
497
|
+ if (StrUtil.isBlank(String.valueOf(props.get(0)))) break;
|
|
498
|
+ goods = new Goods();
|
|
499
|
+ // 商品基本信息
|
|
500
|
+ goods.setGoodsName(String.valueOf(props.get(2)));
|
|
501
|
+ goods.setQuantity(99999);
|
|
502
|
+ goods.setGoodsUnit(String.valueOf(props.get(4)));
|
|
503
|
+ goods.setPrice(Double.parseDouble(String.valueOf(props.get(5))));
|
|
504
|
+
|
|
505
|
+ goods.setStoreId(authUser.getStoreId());
|
|
506
|
+ goods.setStoreName(authUser.getStoreName());
|
|
507
|
+ // 固定属性
|
|
508
|
+ goods.setParams("[]");
|
|
509
|
+ goods.setSalesModel("RETAIL");
|
|
510
|
+ goods.setRecommend(true);
|
|
511
|
+ goods.setSelfOperated(false);
|
|
512
|
+ goods.setBuyCount(0);
|
|
513
|
+ goods.setCommentNum(0);
|
|
514
|
+ goods.setGrade(100D);
|
|
515
|
+ goods.setAuthFlag("PASS");
|
|
516
|
+ goods.setMarketEnable("UPPER");
|
|
517
|
+ goods.setGoodsType("PHYSICAL_GOODS");
|
|
518
|
+ }
|
|
519
|
+ }
|
|
520
|
+ otherCache.put(importKey(), JSON.toJSONString(goodsList), 3600 * 24L);
|
|
521
|
+ return goodsList;
|
|
522
|
+ } catch (Exception e) {
|
|
523
|
+ throw new ServiceException(ResultCode.ORDER_BATCH_DELIVER_ERROR);
|
|
524
|
+ }
|
|
525
|
+ }
|
|
526
|
+
|
|
527
|
+ @Override
|
|
528
|
+ public List<Goods> unSubmitOrder() {
|
|
529
|
+ return JSON.parseArray(otherCache.get(importKey()), Goods.class);
|
|
530
|
+ }
|
|
531
|
+
|
|
532
|
+ @Override
|
|
533
|
+ public boolean hasUnSubmitOrder() {
|
|
534
|
+ return otherCache.hasKey(importKey());
|
|
535
|
+ }
|
|
536
|
+
|
|
537
|
+ @Override
|
|
538
|
+ public void saveImportGoods(List<Goods> goods) {
|
|
539
|
+ otherCache.put(importKey(), JSON.toJSONString(goods), 3600 * 24L);
|
|
540
|
+ }
|
|
541
|
+
|
|
542
|
+ @Override
|
|
543
|
+ public void submitImportGoods(List<Goods> goods) {
|
|
544
|
+ otherCache.remove(importKey());
|
|
545
|
+ }
|
|
546
|
+
|
|
547
|
+ private String importKey(){
|
|
548
|
+ AuthUser authUser = UserContext.getCurrentUser();
|
|
549
|
+ Assert.notNull(authUser, "登录信息已失效,请重新登录");
|
|
550
|
+ return GOODS_IMPORT_KEY_PREFIX + authUser.getId();
|
|
551
|
+ }
|
|
552
|
+
|
455
|
553
|
|
456
|
554
|
/**
|
457
|
555
|
* 发送删除es索引的信息
|