futian.liu
2023-12-09 b16483ae0dff952639e4b7e152f72dc32e662154
consum-base/src/main/java/com/consum/base/service/impl/LWhFormTransferCoreService.java
@@ -1,28 +1,46 @@
package com.consum.base.service.impl;
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.base.service.*;
import com.consum.model.po.*;
import com.iplatform.model.po.S_user_core;
import com.walker.infrastructure.utils.CollectionUtils;
import com.walker.infrastructure.utils.DateUtils;
import com.walker.infrastructure.utils.NumberGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
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.base.service.BaseGoodsTemplateService;
import com.consum.base.service.GoodsBaseServiceImpl;
import com.consum.base.service.LGoodsUserRecordServiceImpl;
import com.consum.base.service.LGoodsWhRecordServiceImpl;
import com.consum.base.service.LWarehouseFlowService;
import com.consum.base.service.LWhFormTransferService;
import com.consum.base.service.LWhGoodsRecordService;
import com.consum.base.service.LWhGoodsService;
import com.consum.base.service.LWhProcureModelService;
import com.consum.model.po.LGoodsUserRecord;
import com.consum.model.po.LWarehouseFlow;
import com.consum.model.po.LWhFormTransfer;
import com.consum.model.po.LWhGoodsRecord;
import com.consum.model.po.LWhGoodsRecordDetails;
import com.consum.model.po.LWhProcureModel;
import com.consum.model.po.LWhProcureModelUser;
import com.iplatform.model.po.S_user_core;
import com.walker.infrastructure.utils.CollectionUtils;
import com.walker.infrastructure.utils.DateUtils;
import com.walker.infrastructure.utils.NumberGenerator;
import com.walker.infrastructure.utils.StringUtils;
import cn.hutool.core.convert.Convert;
import lombok.extern.slf4j.Slf4j;
/**
 * @ClassName LWhFormTransferCoreService
@@ -41,7 +59,6 @@
    private LWhProcureModelService lWhProcureModelService;
    @Resource
    private BaseGoodsTemplateService baseGoodsTemplateService;
    @Resource
    private LWhFormOutputCoreService lWhFormOutputCoreService;
@@ -138,13 +155,13 @@
        String nickName = currentUser.getNick_name();
        long dealTime = DateUtils.getDateTimeNumber(System.currentTimeMillis());
        //申请调拨的物品
        List<LWhProcureModel> goodsModelNumList = lWhProcureModelService.getModelByForm(WhBusinessEnum.DIAOBO, whFormTransferId);
        List<LWhProcureModel> goodsModelNumList =
            lWhProcureModelService.getModelByForm(WhBusinessEnum.DIAOBO, whFormTransferId);
        if (CollectionUtils.isEmpty(goodsModelNumList)) {
            log.error("没有要出库的物品");
            return null;
        }
        List<LWhProcureModel> goodsModelNumUpdList = new ArrayList<>(goodsModelNumList.size());
        // 要出物品的仓库id
        Integer outWarehouseType = lWhFormTransfer.getOutWarehouseType();
@@ -168,7 +185,6 @@
        queryModelStatusT = 1;
        buyTypeT = 1;
        modGoodsTransferingStatusT = 0;
        Integer queryModelStatus = queryModelStatusT;
        Integer buyType = buyTypeT;
@@ -211,7 +227,8 @@
            List<Long> outGoodsId = null;
            synchronized (warehouseModelLockObj) {
                // 获得锁后查询该型号的期初数量
                int goodsModelNum = lWhGoodsService.queryGoodsModelNum(outWarehouseType, outWarehouseId, baseGoodsModelsId, queryModelStatus, buyType);
                int goodsModelNum = lWhGoodsService.queryGoodsModelNum(outWarehouseType, outWarehouseId,
                    baseGoodsModelsId, queryModelStatus, buyType);
                if (goodsModelNum < counts) {
                    log.error("出库失败!型号{} 的数量不足,需要调拨{}个,仓库中现存{}个", baseGoodsModelsId, counts, goodsModelNum);
                    // 手动回滚
@@ -222,9 +239,10 @@
                whGoodsRecord.setEndCount(goodsModelNum - counts);
                //出库时候,按 先入库的先出库,同时入库的,按价格高的先出库
                outGoodsId = lWhGoodsService.queryOutGoodsId(outWarehouseType, outWarehouseId, baseGoodsModelsId, queryModelStatus, buyType,
                        counts);
                lWhGoodsService.modGoodsTransfering(outGoodsId, inWarehouseType, inWarehouseId, inWarehouseName, modGoodsTransferingStatus);
                outGoodsId = lWhGoodsService.queryOutGoodsId(outWarehouseType, outWarehouseId, baseGoodsModelsId,
                    queryModelStatus, buyType, counts);
                lWhGoodsService.modGoodsTransfering(outGoodsId, inWarehouseType, inWarehouseId, inWarehouseName,
                    modGoodsTransferingStatus);
                // 批量插入 进出库流水明细[L_WH_GOODS_RECORD_DETAILS]
                lWhGoodsRecordDetailsService.sameGoodsInsertMore(outGoodsId, whGoodsRecordId, (short) 0);
            }
@@ -259,7 +277,8 @@
        //当库存变动时调用该方法
        if (outWarehouseType == 0) {
            lWhWarningCoreService.updateKuCun(Convert.toShort(outWarehouseType, (short) 0), outWarehouseId, allChangModelList, null, dealTime);
            lWhWarningCoreService.updateKuCun(Convert.toShort(outWarehouseType, (short)0), outWarehouseId,
                allChangModelList, null, dealTime);
        }
        // 更新调拨单
@@ -284,7 +303,7 @@
     * @param whFormTransferId
     * @param currentUser
     */
    public void doTransferInPut(Long whFormTransferId, S_user_core currentUser) {
    public void doTransferInPut(Long whFormTransferId, S_user_core currentUser, String inOperatorName) {
        LWhFormTransfer lWhFormTransfer = new LWhFormTransfer(whFormTransferId);
        lWhFormTransfer = lWhFormTransferService.get(lWhFormTransfer);
        if (lWhFormTransfer == null || lWhFormTransfer.getStates() != 1) {
@@ -361,17 +380,18 @@
                    throw new RuntimeException("入库单失败,未查询到物品!");
                }
                // 获得锁后查询该型号的期初数量
                int goodsModelNum = lWhGoodsService.queryGoodsModelNum(inWarehouseType, inWarehouseId, baseGoodsModelsId, 1, null);
                int goodsModelNum =
                    lWhGoodsService.queryGoodsModelNum(inWarehouseType, inWarehouseId, baseGoodsModelsId, 1, null);
                // 库存物品详情(L_WH_GOODS)中 状态设置为1
                lWhGoodsService.modGoodsTransfering(outGoodsIds, inWarehouseType, inWarehouseId, inWarehouseName, goodsStatus);
                lWhGoodsService.modGoodsTransfering(outGoodsIds, inWarehouseType, inWarehouseId, inWarehouseName,
                    goodsStatus);
                // 通过物品id查询所有商品的总金额
//                long amount = lWhGoodsService.queryGoodsPriceById(outGoodsIds);
//                LWhProcureModel lWhFormScrappedGoods = new LWhProcureModel(formScrappedGood.getId());
//                lWhFormScrappedGoods.setTotalAmount(amount);
//                lWhFormTransferService.update(lWhFormScrappedGoods);
                whGoodsRecord.setInitialCount(goodsModelNum);
                whGoodsRecord.setEndCount(goodsModelNum + whGoodsRecord.getThisCount());
@@ -453,8 +473,13 @@
        lWhFormTransfer.setInWarehouseFlowId(inWarehouseFlowId);
        lWhFormTransfer.setInWarehouseFormId(null);
        lWhFormTransfer.setStates(2);
        if (StringUtils.isEmpty(inOperatorName)) {
        lWhFormTransfer.setInOperatorId(userId);
        lWhFormTransfer.setInOperatorName(nickName);
        } else {
            lWhFormTransfer.setInOperatorName(inOperatorName);
        }
        lWhFormTransfer.setInTime(dealTime);
        lWhFormTransferService.update(lWhFormTransfer);