浏览代码

师傅辅材配件库存初始化

FengChaoYu 9 月之前
父节点
当前提交
c08f3caabe

+ 9 - 17
mall-server-api/src/main/java/com/gree/mall/manager/bean/material/stock/WorkerStockDTO.java

@@ -105,12 +105,9 @@ public class WorkerStockDTO {
     @ApiModelProperty("业务对象")
     private String obj;
 
-    @ApiModelProperty("状态 ING=在途 TAKE=已提货 USED=已使用 REFUND=退货 INIT=初始化 REFUND_NEW=返新件 REFUND_OLD=返旧件")
+    @ApiModelProperty("状态 USED=已使用 REFUND=退货 INIT=初始化 REFUND_NEW=返新件 REFUND_OLD=返旧件")
     private String flag;
 
-    @ApiModelProperty("销售方式 OWM=自有 OUT=外购")
-    private String settlementType;
-
     @ApiModelProperty("工单号")
     private String workerOrderNo;
 
@@ -126,15 +123,12 @@ public class WorkerStockDTO {
         WorkerStock workerStock = new WorkerStock();
         BeanUtils.copyProperties(this, workerStock);
         workerStock.setId(null)
-//                .setWebsitId(this.websitId)
-//                .setWebsitName(this.websitName)
-                .setWayQty(BigDecimal.ZERO)
+                .setWebsitId(this.websitId)
+                .setWebsitName(this.websitName)
                 .setQty(BigDecimal.ZERO)
                 .setOldQty(BigDecimal.ZERO)
-                .setCreateBy(this.operateBy)
-                .setCreateTime(this.operateTime)
-                .setUpdateBy(this.operateBy)
-                .setUpdateTime(this.operateTime);
+                .setOperBy(this.operateBy)
+                .setOperTime(this.operateTime);
         return workerStock;
     }
 
@@ -159,17 +153,15 @@ public class WorkerStockDTO {
         BeanUtils.copyProperties(this, workerStockAcc);
         workerStockAcc.setQty(qty)
                 .setCloseQty(closeQty)
-                .setCreateBy(this.operateBy)
-                .setCreateTime(this.operateTime);
+                .setOperBy(this.operateBy)
+                .setOperTime(this.operateTime);
         // 注入库存
         if (this.partsAttr.equals(PartsAttrEnum.NEW.getKey())) {
             workerStock.setQty(closeQty);
         } else if (this.partsAttr.equals(PartsAttrEnum.OLD.getKey())) {
             workerStock.setOldQty(closeQty);
-        } else {
-            workerStock.setWayQty(closeQty);
         }
-        workerStock.setUpdateBy(this.operateBy)
-                .setUpdateTime(this.operateTime);
+        workerStock.setOperBy(this.operateBy)
+                .setOperTime(this.operateTime);
     }
 }

+ 1 - 0
mall-server-api/src/main/java/com/gree/mall/manager/constant/Constant.java

@@ -56,6 +56,7 @@ public class Constant {
         public final static String MATERIAL_SALES = "jsm:sxb:lock:material:sales:";
         public final static String GOODS_MATERIAL_PURCHASE = "jsm:sxb:lock:goods:material:purchase:";
         public final static String GOODS_MATERIAL_PURCHASE_RET = "jsm:sxb:lock:goods:material:purchase:ret:";
+        public final static String MATERIAL_WORKER_INCR = "jsm:sxb:lock:material:worker:incr";
         //订单号每日流水
         public final static String ORDER_NUM = "jsm:sxb:orderNo:";
 

+ 18 - 1
mall-server-api/src/main/java/com/gree/mall/manager/controller/material/base/WorkerGoodsController.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.gree.mall.manager.annotation.ZfireList;
 import com.gree.mall.manager.bean.material.base.WorkerGoodsBean;
 import com.gree.mall.manager.bean.material.base.WorkerGoodsVO;
+import com.gree.mall.manager.constant.Constant;
 import com.gree.mall.manager.exception.RemoteServiceException;
 import com.gree.mall.manager.helper.ResponseHelper;
 import com.gree.mall.manager.logic.material.base.WorkerGoodsLogic;
@@ -14,11 +15,14 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.integration.redis.util.RedisLockRegistry;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
 
 @Slf4j
 @RestController
@@ -28,6 +32,8 @@ public class WorkerGoodsController {
 
     @Resource
     WorkerGoodsLogic workerGoodsLogic;
+    @Resource
+    RedisLockRegistry redisLockRegistry;
 
     @ZfireList
     @PostMapping("/list")
@@ -65,7 +71,18 @@ public class WorkerGoodsController {
     public ResponseHelper add(
             @RequestBody WorkerGoodsBean bean
     ) throws Exception {
-        workerGoodsLogic.add(bean);
+        Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.MATERIAL_WORKER_INCR);
+        try {
+            if (obtain.tryLock(5, TimeUnit.SECONDS)) {
+                workerGoodsLogic.add(bean);
+            }
+        } catch(Exception e) {
+            log.error("【师傅辅材添加】失败", e);
+            throw e;
+        } finally {
+            obtain.unlock();
+        }
+
         return ResponseHelper.success();
     }
 

+ 10 - 4
mall-server-api/src/main/java/com/gree/mall/manager/controller/material/stock/WorkerStockController.java

@@ -3,7 +3,10 @@ package com.gree.mall.manager.controller.material.stock;
 import cn.hutool.core.lang.TypeReference;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.gree.mall.manager.annotation.ZfireList;
-import com.gree.mall.manager.bean.listvo.material.*;
+import com.gree.mall.manager.bean.listvo.material.WorkerStockAccPVO;
+import com.gree.mall.manager.bean.listvo.material.WorkerStockAccVO;
+import com.gree.mall.manager.bean.listvo.material.WorkerStockPVO;
+import com.gree.mall.manager.bean.listvo.material.WorkerStockVO;
 import com.gree.mall.manager.enums.material.WebsitGoodsTypeEnum;
 import com.gree.mall.manager.helper.ResponseHelper;
 import com.gree.mall.manager.logic.material.stock.WorkerStockLogic;
@@ -14,6 +17,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.integration.redis.util.RedisLockRegistry;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -21,9 +25,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
 import java.util.List;
 
 @Slf4j
@@ -35,6 +39,8 @@ public class WorkerStockController {
 
     @Autowired
     WorkerStockLogic workerStockLogic;
+    @Resource
+    RedisLockRegistry redisLockRegistry;
 
     @ZfireList
     @PostMapping("list")
@@ -87,7 +93,7 @@ public class WorkerStockController {
 
     @PostMapping("importM")
     @ApiOperation("辅材师傅库存-导入(模板名称:辅材师傅库存.xlsx)")
-    public ResponseHelper importData(MultipartFile file) throws IOException {
+    public ResponseHelper importData(MultipartFile file) throws Exception {
         List<Object> objects = ExcelUtils.importExcel(file);
         workerStockLogic.importData(objects, WebsitGoodsTypeEnum.M);
         return ResponseHelper.success();
@@ -96,7 +102,7 @@ public class WorkerStockController {
 
     @PostMapping("importP")
     @ApiOperation("配件师傅库存-导入(模板名称:配件师傅库存.xlsx)")
-    public ResponseHelper importDataP(MultipartFile file) throws IOException {
+    public ResponseHelper importDataP(MultipartFile file) throws Exception {
         List<Object> objects = ExcelUtils.importExcel(file);
         workerStockLogic.importData(objects, WebsitGoodsTypeEnum.P);
         return ResponseHelper.success();

+ 11 - 1
mall-server-api/src/main/java/com/gree/mall/manager/logic/material/base/WorkerGoodsLogic.java

@@ -9,8 +9,10 @@ import com.gree.mall.manager.bean.material.base.WorkerGoodsVO;
 import com.gree.mall.manager.commonmapper.MaterialMapper;
 import com.gree.mall.manager.exception.RemoteServiceException;
 import com.gree.mall.manager.logic.common.CommonLogic;
+import com.gree.mall.manager.plus.entity.MaterialConfig;
 import com.gree.mall.manager.plus.entity.WorkerGoods;
 import com.gree.mall.manager.plus.entity.WorkerGoodsRela;
+import com.gree.mall.manager.plus.service.MaterialConfigService;
 import com.gree.mall.manager.plus.service.WorkerGoodsRelaService;
 import com.gree.mall.manager.plus.service.WorkerGoodsService;
 import com.gree.mall.manager.zfire.bean.ZfireParamBean;
@@ -32,6 +34,7 @@ public class WorkerGoodsLogic {
     private final MaterialMapper materialMapper;
     private final WorkerGoodsService workerGoodsService;
     private final WorkerGoodsRelaService workerGoodsRelaService;
+    private final MaterialConfigService materialConfigService;
 
     public IPage<WorkerGoodsVO> page(ZfireParamBean zfireParamBean) {
         AdminUserCom adminUser = commonLogic.getAdminUser();
@@ -54,14 +57,21 @@ public class WorkerGoodsLogic {
     @Transactional(rollbackFor = Exception.class)
     public void add(WorkerGoodsBean bean) {
         AdminUserCom adminUser = commonLogic.getAdminUser();
+        MaterialConfig config = materialConfigService.lambdaQuery()
+                .eq(MaterialConfig::getCompanyWechatId, adminUser.getAdminCompanyWechat().getCompanyWechatId())
+                .one();
+        Integer incrId = config.getWorkerGoodsIncrId();
         bean.setGoodsId(null);
         bean.setCompanyWechatId(adminUser.getCompanyWechatId());
 
         WorkerGoods workerGoods = new WorkerGoods();
         BeanUtils.copyProperties(bean, workerGoods);
-
+        workerGoods.setGoodsId("W" + incrId);
         workerGoods.insert();
 
+        config.setWorkerGoodsIncrId(incrId + 1)
+                .updateById();
+
         if (CollectionUtil.isNotEmpty(bean.getItems())) {
             // 检查是否已有绑定关系
             for (WorkerGoodsRela item : bean.getItems()) {

+ 3 - 3
mall-server-api/src/main/java/com/gree/mall/manager/logic/material/stock/WebsitGoodsStockLogic.java

@@ -143,10 +143,10 @@ public class WebsitGoodsStockLogic {
         Map<String, WorkerStock> existWorkerStockMap = this.createNotExistWorkerStock(stockList, existWorkerStockList);
         // 计算商品库存
         List<WorkerStockAcc> workerStockAccList = new ArrayList<>();
-        this.computeWorkerStock(stockList, existWorkerStockMap, null, workerStockAccList);
+        this.computeWorkerStock(stockList, existWorkerStockMap, workerStockAccList);
 
         if (CollectionUtil.isEmpty(workerStockAccList)) {
-            throw new RemoteServiceException("师傅配件库存处理失败");
+            throw new RemoteServiceException("师傅库存处理失败");
         }
 
         workerStockService.saveOrUpdateBatch(existWorkerStockMap.values());
@@ -154,7 +154,7 @@ public class WebsitGoodsStockLogic {
     }
 
     private void computeWorkerStock(List<WorkerStockDTO> stockList, Map<String, WorkerStock> existWorkerStockMap,
-                                    List<WorkerStock> workerStockList, List<WorkerStockAcc> workerStockAccList) throws Exception {
+                                    List<WorkerStockAcc> workerStockAccList) throws Exception {
         for (WorkerStockDTO workerStockDTO : stockList) {
             WorkerStock workerStock = existWorkerStockMap.get(workerStockDTO.getGoodsId());
             WorkerStockAcc workerStockAcc = new WorkerStockAcc();

+ 173 - 97
mall-server-api/src/main/java/com/gree/mall/manager/logic/material/stock/WorkerStockLogic.java

@@ -1,21 +1,27 @@
 package com.gree.mall.manager.logic.material.stock;
 
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.gree.mall.manager.bean.admin.AdminUserCom;
 import com.gree.mall.manager.bean.listvo.material.WorkerStockAccPVO;
 import com.gree.mall.manager.bean.listvo.material.WorkerStockAccVO;
 import com.gree.mall.manager.bean.listvo.material.WorkerStockPVO;
 import com.gree.mall.manager.bean.listvo.material.WorkerStockVO;
+import com.gree.mall.manager.bean.material.stock.WorkerStockDTO;
 import com.gree.mall.manager.commonmapper.CommonMapper;
 import com.gree.mall.manager.enums.material.DirectFlagEnum;
+import com.gree.mall.manager.enums.material.PartsAttrEnum;
 import com.gree.mall.manager.enums.material.WebsitGoodsTypeEnum;
+import com.gree.mall.manager.enums.material.WorkerStockFlagEnum;
 import com.gree.mall.manager.exception.RemoteServiceException;
 import com.gree.mall.manager.logic.common.CommonLogic;
 import com.gree.mall.manager.plus.entity.User;
 import com.gree.mall.manager.plus.entity.WebsitGoods;
+import com.gree.mall.manager.plus.entity.WorkerGoods;
 import com.gree.mall.manager.plus.entity.WorkerStock;
-import com.gree.mall.manager.plus.entity.WorkerStockAcc;
 import com.gree.mall.manager.plus.service.*;
 import com.gree.mall.manager.utils.CommonUtils;
 import com.gree.mall.manager.zfire.bean.ZfireParamBean;
@@ -27,7 +33,6 @@ import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 
 @Slf4j
@@ -37,17 +42,21 @@ public class WorkerStockLogic {
 
     private final CommonLogic commonLogic;
     private final CommonMapper commonMapper;
-    private final WebsitGoodsService websitGoodsService;
+    private final WorkerGoodsService workerGoodsService;
     private final WorkerStockService workerStockService;
     private final WorkerStockAccService workerStockAccService;
     private final AdminWebsitService adminWebsitService;
     private final UserService userService;
+    private final WebsitGoodsStockLogic websitGoodsStockLogic;
+    private final WebsitGoodsService websitGoodsService;
+
     /**
      * 师傅辅材库存列表
+     *
      * @param zfireParamBean
      * @return
      */
-    public IPage<WorkerStockVO> workerStockList(ZfireParamBean zfireParamBean){
+    public IPage<WorkerStockVO> workerStockList(ZfireParamBean zfireParamBean) {
         final AdminUserCom adminUser = commonLogic.getAdminUser();
         FieldUtils.materialParam(zfireParamBean, WorkerStockVO.class, adminUser);
 
@@ -57,12 +66,13 @@ public class WorkerStockLogic {
 
     /**
      * 师傅辅材库存明细
+     *
      * @param zfireParamBean
      * @return
      */
-    public IPage<WorkerStockAccVO> workerStockAccList(ZfireParamBean zfireParamBean){
+    public IPage<WorkerStockAccVO> workerStockAccList(ZfireParamBean zfireParamBean) {
         zfireParamBean.setCompanyWechatId(commonLogic.getAdminUser().getCompanyWechatId());
-        FieldUtils.supplyParam(zfireParamBean,WorkerStockAccVO.class);
+        FieldUtils.supplyParam(zfireParamBean, WorkerStockAccVO.class);
         IPage<WorkerStockAccVO> page = commonMapper.workerStockAccList(new Page(zfireParamBean.getPageNum(), zfireParamBean.getPageSize()), zfireParamBean);
         return page;
     }
@@ -70,24 +80,26 @@ public class WorkerStockLogic {
 
     /**
      * 师傅配件库存列表
+     *
      * @param zfireParamBean
      * @return
      */
-    public IPage<WorkerStockPVO> workerStockPList(ZfireParamBean zfireParamBean){
+    public IPage<WorkerStockPVO> workerStockPList(ZfireParamBean zfireParamBean) {
         zfireParamBean.setCompanyWechatId(commonLogic.getAdminUser().getCompanyWechatId());
-        FieldUtils.supplyParam(zfireParamBean,WorkerStockPVO.class);
+        FieldUtils.supplyParam(zfireParamBean, WorkerStockPVO.class);
         IPage<WorkerStockPVO> page = commonMapper.workerStockPList(new Page(zfireParamBean.getPageNum(), zfireParamBean.getPageSize()), zfireParamBean);
         return page;
     }
 
     /**
      * 师傅配件库存明细
+     *
      * @param zfireParamBean
      * @return
      */
-    public IPage<WorkerStockAccPVO> workerStockAccPList(ZfireParamBean zfireParamBean){
+    public IPage<WorkerStockAccPVO> workerStockAccPList(ZfireParamBean zfireParamBean) {
         zfireParamBean.setCompanyWechatId(commonLogic.getAdminUser().getCompanyWechatId());
-        FieldUtils.supplyParam(zfireParamBean,WorkerStockAccPVO.class);
+        FieldUtils.supplyParam(zfireParamBean, WorkerStockAccPVO.class);
         IPage<WorkerStockAccPVO> page = commonMapper.workerStockAccPList(new Page(zfireParamBean.getPageNum(), zfireParamBean.getPageSize()), zfireParamBean);
         return page;
     }
@@ -95,99 +107,163 @@ public class WorkerStockLogic {
 
     /**
      * 导入师傅库存(各个商品只能导第一次)
+     *
      * @param datas
      */
-    public void importData(List<Object> datas, WebsitGoodsTypeEnum websitGoodsTypeEnum){
+    public void importData(List<Object> datas, WebsitGoodsTypeEnum websitGoodsTypeEnum) throws Exception {
         AdminUserCom adminUser = commonLogic.getAdminUser();
-        List<WorkerStock> workerStocks = new ArrayList<>();
-        List<WorkerStockAcc> workerStockAccs = new ArrayList<>();
-        for(int i= 0 ;i<datas.size() ; i++){
-            List<String> row = (List<String>)datas.get(i);
-            CommonUtils.initList(row,10);
-            String goodsId = row.get(0);
-            String stock = row.get(1);
-            String wayQty = row.get(2);
-            String oldQty = row.get(3);
-            //String websitName = row.get(4);
-            String workerMobile = row.get(4);
-            if(StringUtils.isAnyBlank(goodsId,stock,wayQty,oldQty,workerMobile)){
-                throw new RemoteServiceException("第"+(i+1)+"行请补充完整内容");
-            }
-            WebsitGoods websitGoods = websitGoodsService.lambdaQuery()
-                    .eq(WebsitGoods::getCompanyWechatId,adminUser.getCompanyWechatId())
-                    .eq(WebsitGoods::getGoodsType,websitGoodsTypeEnum.getKey())
-                    .eq(WebsitGoods::getGoodsId,goodsId).one();
-            if(websitGoods == null){
-                throw new RemoteServiceException("商品编号【"+goodsId+"】不存在");
-            }
-//            AdminWebsit adminWebsit = adminWebsitService.lambdaQuery()
-//                    .eq(AdminWebsit::getName, websitName)
-//                    .eq(StringUtils.isNotBlank(adminUser.getCompanyWechatId()),AdminWebsit::getCompanyWechatId, adminUser.getCompanyWechatId()).one();
-//            if(adminWebsit == null){
-//                throw new RemoteServiceException("网点名字【"+websitName+"】不存在");
-//            }
-            //判断师傅信息
-            User user = userService.lambdaQuery()
-                    .eq(User::getMobile, workerMobile)
-                    .eq(User::getCompanyWechatId, adminUser.getCompanyWechatId())
-                    .last("limit 1").one();
-            if(user == null){
-                throw new RemoteServiceException("师傅手机号【"+workerMobile+"】不存在");
-            }
-            Integer count = workerStockService.lambdaQuery()
-                    .eq(WorkerStock::getCompanyWechatId, adminUser.getCompanyWechatId())
-                    .eq(WorkerStock::getWorkerId,user.getUserId())
-                    .eq(WorkerStock::getGoodsId, goodsId).count();
-            if(count > 0){
-                throw new RemoteServiceException("商品编号【"+goodsId+"】的库存记录已存在于系统,导入失败");
-            }
 
-            WorkerStock bean = new WorkerStock();
-            bean.setCompanyWechatId(adminUser.getCompanyWechatId());
-            bean.setCompanyWechatName(adminUser.getCompanyName());
-//            bean.setWebsitId(adminWebsit.getWebsitId());
-//            bean.setWebsitName(adminWebsit.getName());
-            bean.setGoodsType(websitGoodsTypeEnum.getKey());
-            bean.setGoodsId(goodsId);
-            bean.setGoodsName(websitGoods.getGoodsName());
-            bean.setGoodsType(websitGoods.getGoodsType());
-            bean.setQty(new BigDecimal(stock));
-            bean.setWayQty(new BigDecimal(wayQty));
-            bean.setOldQty(new BigDecimal(oldQty));
-            bean.setWorkerId(user.getUserId());
-            bean.setIdentity(user.getIdCard());
-            bean.setCreateBy(adminUser.getNickName());
-            bean.setUpdateBy(adminUser.getNickName());
-            workerStocks.add(bean);
-
-            //网点库存三级帐
-            WorkerStockAcc workerStockAcc = new WorkerStockAcc();
-            workerStockAcc.setCompanyWechatId(bean.getCompanyWechatId());
-            workerStockAcc.setCompanyWechatName(bean.getCompanyWechatName());
-//            workerStockAcc.setWebsitId(bean.getWebsitId());
-//            workerStockAcc.setWebsitName(bean.getWebsitName());
-            workerStockAcc.setGoodsType(bean.getGoodsType());
-            workerStockAcc.setWorkerId(bean.getWorkerId());
-//            workerStockAcc.setWorkerWebsitName(bean.getWebsitName());
-//            workerStockAcc.setWorkerWebsitId(bean.getWebsitId());
-            //workerStockAcc.setPartsAttr(PartsAttrEnum.NEW.getKey());
-            workerStockAcc.setGoodsId(bean.getGoodsId());
-            workerStockAcc.setGoodsName(bean.getGoodsName());
-            workerStockAcc.setSdate(new Date());
-            workerStockAcc.setDirectFlag(DirectFlagEnum.ADD.getKey());
-            workerStockAcc.setChangeQty(bean.getQty());
-            workerStockAcc.setCloseQty(bean.getQty());
-            workerStockAcc.setRef("system");
-            workerStockAcc.setObj("system");
-            workerStockAcc.setCreateBy(adminUser.getNickName());
-            workerStockAcc.setCreateTime(new Date());
-            workerStockAcc.setFlag("INIT");
-            workerStockAcc.setRemark("期初导入");
-            workerStockAccs.add(workerStockAcc);
+        if (adminUser.getType() == 2) {
+            throw new RemoteServiceException("平台账号禁止操作");
+        }
+
+        List<WorkerStockDTO> workerStockDTOS = new ArrayList<>();
+        final DateTime curDate = DateUtil.date();
+        final String idStr = IdWorker.getIdStr();
+
+        for (int i = 0; i < datas.size(); i++) {
+            List<String> row = (List<String>) datas.get(i);
+            CommonUtils.initList(row, 10);
+            if (websitGoodsTypeEnum.getKey().equals(WebsitGoodsTypeEnum.M.getKey())) {
+                String goodsId = row.get(0);
+                String workerNumber = row.get(1);
+                String qty = row.get(2);
+                String price = row.get(3);
+                if (StringUtils.isAnyBlank(goodsId, workerNumber, qty, price)) {
+                    throw new RemoteServiceException("第" + (i + 1) + "行请补充完整内容");
+                }
+                WorkerGoods workerGoods = workerGoodsService.lambdaQuery()
+                        .eq(WorkerGoods::getCompanyWechatId, adminUser.getCompanyWechatId())
+                        .eq(WorkerGoods::getGoodsId, goodsId)
+                        .one();
+                if (workerGoods == null) {
+                    throw new RemoteServiceException("商品编号【" + goodsId + "】不存在");
+                }
 
+                //判断师傅信息
+                User user = userService.lambdaQuery()
+                        .eq(User::getWorkerNumber, workerNumber)
+                        .eq(User::getCompanyWechatId, adminUser.getCompanyWechatId())
+                        .last("limit 1")
+                        .one();
+                if (user == null) {
+                    throw new RemoteServiceException("师傅编号【" + workerNumber + "】不存在");
+                }
+                Integer count = workerStockService.lambdaQuery()
+                        .eq(WorkerStock::getCompanyWechatId, adminUser.getCompanyWechatId())
+                        .eq(WorkerStock::getWorkerId, user.getUserId())
+                        .eq(WorkerStock::getGoodsId, goodsId).count();
+                if (count > 0) {
+                    throw new RemoteServiceException("商品编号【" + goodsId + "】的库存记录已存在于系统,导入失败");
+                }
+
+                WorkerStockDTO workerStockDTO = new WorkerStockDTO();
+                workerStockDTO.setCompanyWechatId(adminUser.getCompanyWechatId());
+                workerStockDTO.setCompanyWechatName(adminUser.getCompanyName());
+                workerStockDTO.setIdentity(user.getIdCard());
+                workerStockDTO.setWorkerId(user.getWorkerNumber());
+                workerStockDTO.setWorkerName(user.getNickName());
+                workerStockDTO.setSdate(curDate);
+                workerStockDTO.setGoodsId(goodsId);
+                workerStockDTO.setGoodsName(workerGoods.getGoodsName());
+                workerStockDTO.setGoodsType(WebsitGoodsTypeEnum.M.getKey());
+                workerStockDTO.setPrice(new BigDecimal(price));
+                workerStockDTO.setUnitName(workerGoods.getSalesUnit());
+                workerStockDTO.setRef(idStr);
+                workerStockDTO.setRefType("库存导入");
+                workerStockDTO.setPartsAttr(PartsAttrEnum.NEW.getKey());
+                workerStockDTO.setChangeQty(new BigDecimal(qty));
+                workerStockDTO.setDirectFlag(DirectFlagEnum.ADD.getKey());
+                workerStockDTO.setFlag(WorkerStockFlagEnum.INIT.getKey());
+                workerStockDTO.setObj("师傅");
+                workerStockDTO.setWorkerOrderNo("");
+                workerStockDTO.setOperateBy(adminUser.getJoinNickName());
+                workerStockDTO.setOperateTime(curDate);
+                workerStockDTOS.add(workerStockDTO);
+            } else {
+                String goodsId = row.get(0);
+                String stock = row.get(1);
+                String oldQty = row.get(2);
+                //String websitName = row.get(4);
+                String workerId = row.get(4);
+                if (StringUtils.isAnyBlank(goodsId, stock, oldQty, workerId)) {
+                    throw new RemoteServiceException("第" + (i + 1) + "行请补充完整内容");
+                }
+                WebsitGoods websitGoods = websitGoodsService.lambdaQuery()
+                        .eq(WebsitGoods::getCompanyWechatId, adminUser.getCompanyWechatId())
+                        .eq(WebsitGoods::getGoodsType, websitGoodsTypeEnum.getKey())
+                        .eq(WebsitGoods::getGoodsId, goodsId)
+                        .one();
+                if (websitGoods == null) {
+                    throw new RemoteServiceException("商品编号【" + goodsId + "】不存在");
+                }
+
+                //判断师傅信息
+                User user = userService.lambdaQuery()
+                        .eq(User::getWorkerNumber, workerId)
+                        .eq(User::getCompanyWechatId, adminUser.getCompanyWechatId())
+                        .last("limit 1")
+                        .one();
+                if (user == null) {
+                    throw new RemoteServiceException("师傅编号【" + workerId + "】不存在");
+                }
+                Integer count = workerStockService.lambdaQuery()
+                        .eq(WorkerStock::getCompanyWechatId, adminUser.getCompanyWechatId())
+                        .eq(WorkerStock::getWorkerId, user.getWorkerNumber())
+                        .eq(WorkerStock::getGoodsId, goodsId)
+                        .count();
+                if (count > 0) {
+                    throw new RemoteServiceException("商品编号【" + goodsId + "】的库存记录已存在于系统,导入失败");
+                }
+                WorkerStockDTO workerStockDTO = new WorkerStockDTO();
+                workerStockDTO.setCompanyWechatId(adminUser.getCompanyWechatId());
+                workerStockDTO.setCompanyWechatName(adminUser.getCompanyName());
+                workerStockDTO.setIdentity(user.getIdCard());
+                workerStockDTO.setWorkerId(user.getWorkerNumber());
+                workerStockDTO.setWorkerName(user.getNickName());
+                workerStockDTO.setSdate(curDate);
+                workerStockDTO.setGoodsId(goodsId);
+                workerStockDTO.setGoodsName(websitGoods.getGoodsName());
+                workerStockDTO.setGoodsType(WebsitGoodsTypeEnum.M.getKey());
+                workerStockDTO.setUnitName(websitGoods.getGoodsSalesUnit());
+                workerStockDTO.setRef(idStr);
+                workerStockDTO.setRefType("库存导入");
+                workerStockDTO.setPartsAttr(PartsAttrEnum.OLD.getKey());
+                workerStockDTO.setChangeQty(new BigDecimal(stock));
+                workerStockDTO.setDirectFlag(DirectFlagEnum.ADD.getKey());
+                workerStockDTO.setFlag(WorkerStockFlagEnum.INIT.getKey());
+                workerStockDTO.setObj("师傅");
+                workerStockDTO.setWorkerOrderNo("");
+                workerStockDTO.setOperateBy(adminUser.getJoinNickName());
+                workerStockDTO.setOperateTime(curDate);
+                if (new BigDecimal(oldQty).compareTo(BigDecimal.ZERO) > 0) {
+                    WorkerStockDTO workerStockDTO2 = new WorkerStockDTO();
+                    workerStockDTO2.setCompanyWechatId(adminUser.getCompanyWechatId());
+                    workerStockDTO2.setCompanyWechatName(adminUser.getCompanyName());
+                    workerStockDTO2.setIdentity(user.getIdCard());
+                    workerStockDTO2.setWorkerId(user.getWorkerNumber());
+                    workerStockDTO2.setWorkerName(user.getNickName());
+                    workerStockDTO2.setSdate(curDate);
+                    workerStockDTO2.setGoodsId(goodsId);
+                    workerStockDTO2.setGoodsName(websitGoods.getGoodsName());
+                    workerStockDTO2.setGoodsType(WebsitGoodsTypeEnum.M.getKey());
+                    workerStockDTO2.setUnitName(websitGoods.getGoodsSalesUnit());
+                    workerStockDTO2.setRef(idStr);
+                    workerStockDTO2.setRefType("库存导入");
+                    workerStockDTO2.setPartsAttr(PartsAttrEnum.NEW.getKey());
+                    workerStockDTO2.setChangeQty(new BigDecimal(oldQty));
+                    workerStockDTO2.setDirectFlag(DirectFlagEnum.ADD.getKey());
+                    workerStockDTO2.setFlag(WorkerStockFlagEnum.INIT.getKey());
+                    workerStockDTO2.setObj("师傅");
+                    workerStockDTO2.setWorkerOrderNo("");
+                    workerStockDTO2.setOperateBy(adminUser.getJoinNickName());
+                    workerStockDTO2.setOperateTime(curDate);
+                }
+                workerStockDTOS.add(workerStockDTO);
+            }
         }
-        workerStockService.saveBatch(workerStocks);
-        workerStockAccService.saveBatch(workerStockAccs);
+        // 开始处理库存
+        websitGoodsStockLogic.handleWorkerStock(workerStockDTOS);
     }
 
 }

+ 6 - 6
mall-server-api/src/main/resources/mapper/CommonMapper.xml

@@ -211,10 +211,10 @@
           ${ex.selected},
           d.category_name 'categoryName2'
         from worker_stock a
-        join websit_goods b on a.goods_id = b.goods_id
+        join worker_goods b on a.goods_id = b.goods_id
         left join websit_goods_category c on b.parent_category_id = c.category_id
         left join websit_goods_category d on b.goods_category_id = d.category_id
-        join user e on e.user_id = a.worker_id
+        join user e on e.worker_number = a.worker_id
           ${ex.query}
           and a.goods_type='M'
         order by a.id desc
@@ -225,10 +225,10 @@
           ${ex.selected},
           d.category_name 'categoryName2'
         from worker_stock_acc a
-        join websit_goods b on a.goods_id = b.goods_id
+        join worker_goods b on a.goods_id = b.goods_id
         left join websit_goods_category c on b.parent_category_id = c.category_id
         left join websit_goods_category d on b.goods_category_id = d.category_id
-        join user e on e.user_id = a.worker_id
+        join user e on e.worker_number = a.worker_id
           ${ex.query}
           and a.goods_type='M'
         order by a.id desc
@@ -239,7 +239,7 @@
           ${ex.selected}
         from worker_stock a
         join websit_goods b on a.goods_id = b.goods_id
-        join user e on e.user_id = a.worker_id
+        join user e on e.worker_number = a.worker_id
           ${ex.query}
         and a.goods_type='P'
         order by a.id desc
@@ -250,7 +250,7 @@
           ${ex.selected}
         from worker_stock_acc a
         join websit_goods b on a.goods_id = b.goods_id
-        join user e on e.user_id = a.worker_id
+        join user e on e.worker_number = a.worker_id
           ${ex.query}
           and a.goods_type='P'
         order by a.id desc

二进制
mall-server-api/src/main/resources/template/辅材师傅库存.xlsx


二进制
mall-server-api/src/main/resources/template/配件师傅库存.xlsx