futian.liu
2023-12-01 b3dc06734af35528496c192368586d5d8a61b42a
consum-base/src/main/java/com/consum/base/service/LWhFormOutputCoreService.java
@@ -1,9 +1,11 @@
package com.consum.base.service;
import cn.hutool.core.convert.Convert;
import com.consum.base.core.CodeGeneratorEnum;
import com.consum.base.core.CodeGeneratorService;
import com.consum.base.core.WhBusinessEnum;
import com.consum.base.core.param.BaseWarehouseParam1;
import com.consum.base.core.service.LWhWarningCoreServiceImpl;
import com.consum.base.core.utils.LockManage;
import com.consum.model.po.*;
import com.iplatform.model.po.S_user_core;
@@ -12,9 +14,11 @@
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;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -26,7 +30,7 @@
 **/
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public class LWhFormOutputCoreService {
    private BaseGoodsTemplateServiceImpl baseGoodsTemplateService;
@@ -34,6 +38,7 @@
    private CodeGeneratorService codeGeneratorService;
    private LWhProcureModelService lWhProcureModelService;
    private LWhFormOutputService lWhFormOutputService;
    private LWhWarningCoreServiceImpl lWhWarningCoreService;
    private LWarehouseFlowService lWarehouseFlowService;
    private LWhGoodsRecordDetailsService lWhGoodsRecordDetailsService;
    private LWhGoodsRecordService lWhGoodsRecordService;
@@ -46,7 +51,8 @@
                                    LWhFormOutputService lWhFormOutputService,
                                    LWarehouseFlowService lWarehouseFlowService,
                                    LWhGoodsRecordDetailsService lWhGoodsRecordDetailsService,
                                    LWhGoodsRecordService lWhGoodsRecordService) {
                                    LWhGoodsRecordService lWhGoodsRecordService,
                                    LWhWarningCoreServiceImpl lWhWarningCoreService) {
        this.baseGoodsTemplateService = baseGoodsTemplateService;
        this.lWhGoodsService = lWhGoodsService;
        this.codeGeneratorService = codeGeneratorService;
@@ -55,6 +61,7 @@
        this.lWarehouseFlowService = lWarehouseFlowService;
        this.lWhGoodsRecordDetailsService = lWhGoodsRecordDetailsService;
        this.lWhGoodsRecordService = lWhGoodsRecordService;
        this.lWhWarningCoreService = lWhWarningCoreService;
    }
@@ -65,7 +72,7 @@
     * @return 出库单Id
     */
    @Transactional(rollbackFor = Exception.class)
    public Long createOutFormByTransId(Long whFormTransferId, S_user_core currentUser, Long dealTime) {
    public Long createOutFormByTransId(Long whFormTransferId, WhBusinessEnum businessEnum, S_user_core currentUser, Long dealTime) {
        if (whFormTransferId == null) {
            return null;
        }
@@ -82,10 +89,11 @@
        }
        //申请调拨的物品
        List<LWhProcureModel> goodsModelNumList = lWhProcureModelService.getModelByForm(WhBusinessEnum.DIAOBO, whFormTransferId);
        List<LWhProcureModel> goodsModelNumList = lWhProcureModelService.getModelByForm(businessEnum, whFormTransferId);
        if (CollectionUtils.isEmpty(goodsModelNumList)) {
            log.error("没有要入库的物品");
            return null;
            throw new RuntimeException("没有要入库的物品");
//            return null;
        }
        Long outWarehouseId = lWhFormTransfer.getOutWarehouseId();
        String outWarehouseName = lWhFormTransfer.getOutWarehouseName();
@@ -121,6 +129,7 @@
        whFormOutput.setOutputName("调拨出库");
        whFormOutput.setWarehouseId(outWarehouseId);
        whFormOutput.setWarehouseName(outWarehouseName);
        // 这样就查询不到该条记录
        whFormOutput.setAgencyId(null);
        whFormOutput.setAgencyName(null);
        whFormOutput.setOperatorId(currentUser.getId());
@@ -145,7 +154,7 @@
     * @return 流水记录总表ID
     */
    @Transactional(rollbackFor = Exception.class)
    public Long outFormByTransId(Long outWarehouseFormId, S_user_core currentUser, Long dealTime) {
    public Long outFormByTransId(Long outWarehouseFormId, WhBusinessEnum businessType, S_user_core currentUser, Long dealTime) {
        if (outWarehouseFormId == null) {
            return null;
        }
@@ -178,33 +187,41 @@
        long lWarehouseFlowBusinessId = outWarehouseFormId;
        // 物品状态(0=在途调拨;1=入库未分发;2=已下发;3=报废)
        short queryModelStatusT = 1;
        Integer queryModelStatusT = 1;
        //采购方式(1:集采;2=自采)
        Short buyTypeT = null;
        Integer buyTypeT = null;
        Integer modGoodsTransferingStatusT = null;
        String outputCode = lWhFormOutput.getOutputCode();
        if ((BaseWarehouseParam1.In_OutPutTypeEnum.Transfer_Output.getValue() + "").equals(outputCode)) {
        short businessTypeValue = businessType.getValue();
        if (BaseWarehouseParam1.In_OutPutTypeEnum.Transfer_Output.getValue() == businessTypeValue) {
            //调拨出库
            queryModelStatusT = 1;
            buyTypeT = 1;
            lWarehouseFlowBusinessId = lWhFormOutput.getTransBusinessId();
            modGoodsTransferingStatusT = 0;
        } else if ((BaseWarehouseParam1.In_OutPutTypeEnum.Dept_Lending_Out.getValue() + "").equals(outputCode)) {
        } else if (BaseWarehouseParam1.In_OutPutTypeEnum.Dept_Lending_Out.getValue() == businessTypeValue) {
            //  部门仓库 分发出库
//            queryModelStatusT = 2;
        } else if ((BaseWarehouseParam1.In_OutPutTypeEnum.Fragmentary_Output.getValue() + "").equals(outputCode)) {
            lWarehouseFlowBusinessId = lWhFormOutput.getTransBusinessId();
        } else if (BaseWarehouseParam1.In_OutPutTypeEnum.Fragmentary_Output.getValue() == businessTypeValue) {
            //  零星出库
            queryModelStatusT = 1;
            buyTypeT = null;
            modGoodsTransferingStatusT = 4;
        } else if (BaseWarehouseParam1.In_OutPutTypeEnum.Inventory_Output.getValue() == businessTypeValue) {
            //  盘点出库
            queryModelStatusT = 1;
            buyTypeT = null;
            modGoodsTransferingStatusT = 4;
        }
        short queryModelStatus = queryModelStatusT;
        Short buyType = buyTypeT;
        Integer queryModelStatus = queryModelStatusT;
        Integer buyType = buyTypeT;
        Integer modGoodsTransferingStatus = modGoodsTransferingStatusT;
        ArrayList<Long> allChangModelList = new ArrayList<>();
        goodsModelNumList.forEach(itemModelInfo -> {
            // 需要调拨的物品的某个型号
            Long baseGoodsModelsId = itemModelInfo.getBaseGoodsModelsId();
            allChangModelList.add(baseGoodsModelsId);
            // 需要调拨的物品某个型号的数量
            Integer counts = itemModelInfo.getCounts();
@@ -258,10 +275,11 @@
                lWhGoodsService.modGoodsTransfering(outGoodsId, inWarehouseType, inWarehouseId, inWarehouseName, modGoodsTransferingStatus);
                // 批量插入 进出库流水明细[L_WH_GOODS_RECORD_DETAILS]
                lWhGoodsRecordDetailsService.sameGoodsInsertMore(outGoodsId, whGoodsRecordId, (short) 0);
                lWhGoodsRecordService.insert(whGoodsRecord);
            }
            long totalAmount = lWhGoodsService.queryGoodsPriceById(outGoodsId);
            LWhProcureModel lWhProcureModel = new LWhProcureModel(itemModelInfo.getId());
            whGoodsRecord.setTotalPrice(totalAmount);
            lWhGoodsRecordService.insert(whGoodsRecord);
            lWhProcureModel.setTotalAmount(totalAmount);
            lWhProcureModelService.update(lWhProcureModel);
        });
@@ -270,7 +288,7 @@
        warehouseFlow.setWarehouseId(outWarehouseId);
        warehouseFlow.setWarehouseName(warehouseName);
        warehouseFlow.setThisType(2);
        warehouseFlow.setBusinessType(WhBusinessEnum.DIAOBO.getValue() + 0);
        warehouseFlow.setBusinessType(businessType.getValue() + 0);
        warehouseFlow.setBusinessFormId(lWarehouseFlowBusinessId);
        warehouseFlow.setOperatorId(userId);
@@ -287,6 +305,10 @@
        lWhFormOutput.setWarehouseFlowId(lWarehouseFlowId);
        lWhFormOutputService.update(lWhFormOutput);
        //当库存变动时调用该方法
        if (outWarehouseType == 0){
            lWhWarningCoreService.updateKuCun(Convert.toShort(outWarehouseType, (short) 0), outWarehouseId, allChangModelList, null, dealTime);
        }
        return lWarehouseFlowId;
    }