futian.liu
2023-12-02 8e41786892a4bd7cff2d63bde8cb0636cdb0650c
consum-base/src/main/java/com/consum/base/service/LWhFormScrappedCoreService.java
@@ -1,6 +1,9 @@
package com.consum.base.service;
import cn.hutool.core.convert.Convert;
import com.consum.base.core.WhBusinessEnum;
import com.consum.base.core.service.LWhWarningCoreServiceImpl;
import com.consum.base.core.utils.IdUtil;
import com.consum.base.core.utils.LockManage;
import com.consum.model.po.LWarehouseFlow;
import com.consum.model.po.LWhFormScrapped;
@@ -8,13 +11,14 @@
import com.consum.model.po.LWhGoodsRecord;
import com.iplatform.model.po.S_user_core;
import com.walker.infrastructure.utils.CollectionUtils;
import com.walker.infrastructure.utils.NumberGenerator;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
@@ -26,24 +30,27 @@
 **/
@Service
@Slf4j
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public class LWhFormScrappedCoreService {
    private GoodsBaseServiceImpl goodsBaseService;
    private LWhFormScrappedGoodsService lWhFormScrappedGoodsService;
    private BaseGoodsTemplateServiceImpl baseGoodsTemplateService;
    private BaseGoodsTemplateService baseGoodsTemplateService;
    private LWhGoodsService lWhGoodsService;
    private LWhGoodsRecordDetailsService lWhGoodsRecordDetailsService;
    private LWhGoodsRecordService lWhGoodsRecordService;
    private LWarehouseFlowService lWarehouseFlowService;
    private LWhWarningCoreServiceImpl lWhWarningCoreService;
    @Autowired
    public LWhFormScrappedCoreService(GoodsBaseServiceImpl goodsBaseService,
        LWhFormScrappedGoodsService lWhFormScrappedGoodsService,
        BaseGoodsTemplateServiceImpl baseGoodsTemplateService,
        LWhGoodsService lWhGoodsService,
        LWhGoodsRecordDetailsService lWhGoodsRecordDetailsService,
        LWhGoodsRecordService lWhGoodsRecordService,
        LWarehouseFlowService lWarehouseFlowService) {
                                      LWhFormScrappedGoodsService lWhFormScrappedGoodsService,
                                      BaseGoodsTemplateService baseGoodsTemplateService,
                                      LWhGoodsService lWhGoodsService,
                                      LWhGoodsRecordDetailsService lWhGoodsRecordDetailsService,
                                      LWhGoodsRecordService lWhGoodsRecordService,
                                      LWarehouseFlowService lWarehouseFlowService,
                                      LWhWarningCoreServiceImpl lWhWarningCoreService) {
//        this.lWhFormScrappedService = lWhFormScrappedService;
        this.lWhFormScrappedGoodsService = lWhFormScrappedGoodsService;
        this.baseGoodsTemplateService = baseGoodsTemplateService;
@@ -52,6 +59,7 @@
        this.lWhGoodsRecordService = lWhGoodsRecordService;
        this.lWarehouseFlowService = lWarehouseFlowService;
        this.goodsBaseService = goodsBaseService;
        this.lWhWarningCoreService = lWhWarningCoreService;
    }
@@ -80,7 +88,7 @@
        Long warehouseId = lWhFormScrapped.getWarehouseId();
        String warehouseName = lWhFormScrapped.getWarehouseName();
        // 流水记录总表ID
        long lWarehouseFlowId = NumberGenerator.getLongSequenceNumberNano();
        long lWarehouseFlowId = IdUtil.generateId();
        //要报废的物品
        LWhFormScrappedGoods goods = new LWhFormScrappedGoods();
@@ -92,11 +100,14 @@
        }
        // 按型号分组
        ArrayList<Long> allChangModelList = new ArrayList<>();
        Map<Long, List<LWhFormScrappedGoods>> modelGroup = formScrappedGoods.stream()
            .collect(Collectors.groupingBy(LWhFormScrappedGoods::getBaseGoodsModelsId));
                .collect(Collectors.groupingBy(LWhFormScrappedGoods::getBaseGoodsModelsId));
        for (Map.Entry<Long, List<LWhFormScrappedGoods>> entry : modelGroup.entrySet()) {
            //规格型号编号
            Long baseGoodsModelsId = entry.getKey();
            allChangModelList.add(baseGoodsModelsId);
            //对每组中要报废的数量求和
            List<LWhFormScrappedGoods> modelGoodsList = entry.getValue();
            //查询型号信息
@@ -107,7 +118,7 @@
            String goodsName = (String) tempGoodsInfo.get("goodsname");
            String modelName = (String) tempGoodsInfo.get("modelname");
            // 插入 各规格物品的进出库记录 L_WH_GOODS_RECORD
            long whGoodsRecordId = NumberGenerator.getLongSequenceNumberNano();
            long whGoodsRecordId = IdUtil.generateId();
            LWhGoodsRecord whGoodsRecord = new LWhGoodsRecord();
            whGoodsRecord.setId(whGoodsRecordId);
            whGoodsRecord.setWarehouseType(warehouseType);
@@ -140,7 +151,7 @@
                        String userName = formScrappedGood.getUserName();
                        // 根据分发单、规格型号编号、使用人员名称,进行报废
                        srappedGoodsIds = lWhGoodsService.queryScrappedGoodsIds(warehouseType, warehouseId, transBusinessId, userName, baseGoodsModelsId,
                            (short) 2, counts);
                                (short) 2, counts);
                    }
                    if (CollectionUtils.isEmpty(srappedGoodsIds) || srappedGoodsIds.size() < counts) {
                        log.error("要报废的物品数量不足!");
@@ -180,17 +191,15 @@
        }
        // 更新报废单
        lWhFormScrapped = new LWhFormScrapped(formScrappedId);
        lWhFormScrapped = goodsBaseService.get(lWhFormScrapped);
        if (lWhFormScrapped != null && lWhFormScrapped.getStates() != 0) {
            log.error("报废失败!请检查报废单状态");
            return null;
        }
        lWhFormScrapped.setLWarehouseFlowId(lWarehouseFlowId);
        lWhFormScrapped.setStates(1);
        lWhFormScrapped.setOperatorId(userId);
        lWhFormScrapped.setOperatorName(nickName);
        lWhFormScrapped.setDealTime(dealTime);
        goodsBaseService.update(lWhFormScrapped);
        //当库存变动时调用该方法
        lWhWarningCoreService.updateKuCun(Convert.toShort(warehouseType,(short) 0), warehouseId, allChangModelList, null, dealTime);
        return lWarehouseFlowId;
    }