Browse Source

商品一键上架

郑杰 2 years ago
parent
commit
3c98b58759

+ 19 - 0
framework/src/main/java/cn/lili/modules/goods/service/GoodsService.java

@@ -9,6 +9,7 @@ import cn.lili.modules.goods.entity.vos.GoodsVO;
9 9
 import cn.lili.modules.store.entity.dos.Store;
10 10
 import com.baomidou.mybatisplus.core.metadata.IPage;
11 11
 import com.baomidou.mybatisplus.extension.service.IService;
12
+import org.springframework.web.multipart.MultipartFile;
12 13
 
13 14
 import java.util.List;
14 15
 
@@ -173,4 +174,22 @@ public interface GoodsService extends IService<Goods> {
173 174
      */
174 175
     long countStoreGoodsNum(String storeId);
175 176
 
177
+    /**
178
+     * 根据报关材料批量创建订单
179
+     */
180
+    List<Goods> batchCreate(MultipartFile files);
181
+
182
+    /**
183
+     * 未提交的导入订单
184
+     */
185
+    List<Goods> unSubmitOrder();
186
+
187
+    /**
188
+     * 是否有未提交的导入订单
189
+     */
190
+    boolean hasUnSubmitOrder();
191
+
192
+    void saveImportGoods(List<Goods> goods);
193
+
194
+    void submitImportGoods(List<Goods> goods);
176 195
 }

+ 98 - 0
framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java

@@ -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索引的信息

+ 35 - 0
seller-api/src/main/java/cn/lili/controller/goods/GoodsStoreController.java

@@ -1,5 +1,6 @@
1 1
 package cn.lili.controller.goods;
2 2
 
3
+import cn.lili.common.enums.ResultCode;
3 4
 import cn.lili.common.enums.ResultUtil;
4 5
 import cn.lili.common.security.OperationalJudgment;
5 6
 import cn.lili.common.security.context.UserContext;
@@ -24,7 +25,9 @@ import io.swagger.annotations.ApiImplicitParam;
24 25
 import io.swagger.annotations.ApiImplicitParams;
25 26
 import io.swagger.annotations.ApiOperation;
26 27
 import org.springframework.beans.factory.annotation.Autowired;
28
+import org.springframework.http.MediaType;
27 29
 import org.springframework.web.bind.annotation.*;
30
+import org.springframework.web.multipart.MultipartFile;
28 31
 
29 32
 import javax.validation.Valid;
30 33
 import java.util.List;
@@ -58,6 +61,38 @@ public class GoodsStoreController {
58 61
     @Autowired
59 62
     private StoreDetailService storeDetailService;
60 63
 
64
+    @ApiOperation(value = "上传文件批量上架商品")
65
+    @PostMapping(value = "/batchCreate", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
66
+    public ResultMessage<List<Goods>> batchDeliver(@RequestPart("files") MultipartFile files) {
67
+        return ResultUtil.data(goodsService.batchCreate(files));
68
+    }
69
+
70
+    @ApiOperation(value = "是否有未提交的导入")
71
+    @GetMapping(value = "/hasUnSubmitOrder")
72
+    public ResultMessage<Boolean> hasUnSubmitOrder() {
73
+        return ResultUtil.data(goodsService.hasUnSubmitOrder());
74
+    }
75
+
76
+    @ApiOperation(value = "获取未提交的导入")
77
+    @GetMapping(value = "/UnSubmitOrder")
78
+    public ResultMessage<List<Goods>> unSubmitOrder() {
79
+        return ResultUtil.data(goodsService.unSubmitOrder());
80
+    }
81
+
82
+    @ApiOperation(value = "保存导入的商品")
83
+    @PostMapping(value = "/saveImportGoods")
84
+    public ResultMessage<Boolean> saveImportGoods(@RequestBody List<Goods> goods) {
85
+        goodsService.saveImportGoods(goods);
86
+        return ResultUtil.success();
87
+    }
88
+
89
+    @ApiOperation(value = "一件上架导入的商品")
90
+    @PostMapping(value = "/submitImportGoods")
91
+    public ResultMessage<Boolean> submitImportGoods(@RequestBody List<Goods> goods) {
92
+        goodsService.submitImportGoods(goods);
93
+        return ResultUtil.success();
94
+    }
95
+
61 96
     @ApiOperation(value = "分页获取商品列表")
62 97
     @GetMapping(value = "/list")
63 98
     public ResultMessage<IPage<Goods>> getByPage(GoodsSearchParams goodsSearchParams) {