| | |
| | | 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.util.LockManage; |
| | | import com.consum.model.po.*; |
| | | 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.LWhFormOutput; |
| | | import com.consum.model.po.LWhFormTransfer; |
| | | import com.consum.model.po.LWhGoodsRecord; |
| | | import com.consum.model.po.LWhProcureModel; |
| | | 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 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.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @ClassName WhFormOutputCoreService |
| | | * @Author cy |
| | | * @Date 2023/10/26 |
| | | * @Description |
| | | * @Version 1.0 |
| | | **/ |
| | | @Slf4j |
| | | @Service |
| | | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) |
| | | public class LWhFormOutputCoreService { |
| | | |
| | | private BaseGoodsTemplateServiceImpl baseGoodsTemplateService; |
| | | private BaseGoodsTemplateService baseGoodsTemplateService; |
| | | private LWhGoodsService lWhGoodsService; |
| | | private CodeGeneratorService codeGeneratorService; |
| | | private LWhProcureModelService lWhProcureModelService; |
| | | private LWhFormTransferService lWhFormTransferService; |
| | | private LWhFormOutputService lWhFormOutputService; |
| | | private LWhWarningCoreServiceImpl lWhWarningCoreService; |
| | | private LWarehouseFlowService lWarehouseFlowService; |
| | | private LWhGoodsRecordDetailsService lWhGoodsRecordDetailsService; |
| | | private LWhGoodsRecordService lWhGoodsRecordService; |
| | | |
| | | @Autowired |
| | | public LWhFormOutputCoreService(BaseGoodsTemplateServiceImpl baseGoodsTemplateService, |
| | | public LWhFormOutputCoreService(BaseGoodsTemplateService baseGoodsTemplateService, |
| | | LWhGoodsService lWhGoodsService, |
| | | CodeGeneratorService codeGeneratorService, |
| | | LWhProcureModelService lWhProcureModelService, |
| | | LWhFormTransferService lWhFormTransferService, |
| | | LWhFormOutputService lWhFormOutputService, |
| | | LWarehouseFlowService lWarehouseFlowService, |
| | | LWhGoodsRecordDetailsService lWhGoodsRecordDetailsService, |
| | | LWhGoodsRecordService lWhGoodsRecordService) { |
| | | LWhGoodsRecordService lWhGoodsRecordService, |
| | | LWhWarningCoreServiceImpl lWhWarningCoreService) { |
| | | this.baseGoodsTemplateService = baseGoodsTemplateService; |
| | | this.lWhGoodsService = lWhGoodsService; |
| | | this.codeGeneratorService = codeGeneratorService; |
| | | this.lWhProcureModelService = lWhProcureModelService; |
| | | this.lWhFormTransferService = lWhFormTransferService; |
| | | this.lWhFormOutputService = lWhFormOutputService; |
| | | this.lWarehouseFlowService = lWarehouseFlowService; |
| | | this.lWhGoodsRecordDetailsService = lWhGoodsRecordDetailsService; |
| | | this.lWhGoodsRecordService = lWhGoodsRecordService; |
| | | this.lWhWarningCoreService = lWhWarningCoreService; |
| | | } |
| | | |
| | | |
| | |
| | | * @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; |
| | | } |
| | | LWhFormTransfer lWhFormTransfer = new LWhFormTransfer(whFormTransferId); |
| | | lWhFormTransfer = lWhFormTransferService.get(lWhFormTransfer); |
| | | lWhFormTransfer = lWhFormOutputService.get(lWhFormTransfer); |
| | | if (lWhFormTransfer == null || lWhFormTransfer.getStates() != 0) { |
| | | log.error("调拨失败!请检查调拨单状态"); |
| | | return null; |
| | |
| | | } |
| | | |
| | | //申请调拨的物品 |
| | | 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(); |
| | |
| | | // 调拨单物品 已经按型号分好了 |
| | | goodsModelNumList.forEach(itemModelInfo -> { |
| | | // 复用对象 |
| | | itemModelInfo.setId(NumberGenerator.getLongSequenceNumber()); |
| | | itemModelInfo.setId(IdUtil.generateId()); |
| | | itemModelInfo.setFromProcureGoodsId(null); |
| | | itemModelInfo.setBusinessType(3); |
| | | itemModelInfo.setBusinessId(outWarehouseFormId); |
| | |
| | | whFormOutput.setId(outWarehouseFormId); |
| | | // 此时并没有出库 |
| | | whFormOutput.setWarehouseFlowId(null); |
| | | whFormOutput.setBusinessFormCode(codeGeneratorService.createCodeByPrefix(CodeGeneratorEnum.OutPut_Warehouse.getValue(), 4)); |
| | | whFormOutput.setBusinessFormCode(codeGeneratorService.createBusinessFormCode(CodeGeneratorEnum.OutPut_Warehouse)); |
| | | //进出库流水总表 入库单ID |
| | | whFormOutput.setInWarehouseFlowId(null); |
| | | // 调拨单ID(调拨时需要) |
| | |
| | | whFormOutput.setOutputName("调拨出库"); |
| | | whFormOutput.setWarehouseId(outWarehouseId); |
| | | whFormOutput.setWarehouseName(outWarehouseName); |
| | | // 这样就查询不到该条记录 |
| | | whFormOutput.setAgencyId(null); |
| | | whFormOutput.setAgencyName(null); |
| | | whFormOutput.setOperatorId(currentUser.getId()); |
| | |
| | | * @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, Long whFormTransferId) { |
| | | if (outWarehouseFormId == null) { |
| | | return null; |
| | | } |
| | |
| | | Integer outWarehouseType = lWhFormOutput.getOutWarehouseType(); |
| | | Long outWarehouseId = lWhFormOutput.getWarehouseId(); |
| | | String warehouseName = lWhFormOutput.getWarehouseName(); |
| | | Integer inWarehouseType = lWhFormOutput.getInWarehouseType(); |
| | | Long inWarehouseId = lWhFormOutput.getInWarehouseId(); |
| | | String inWarehouseName = lWhFormOutput.getInWarehouseName(); |
| | | |
| | | Long userId = currentUser.getId(); |
| | | String nickName = currentUser.getNick_name(); |
| | |
| | | long lWarehouseFlowBusinessId = outWarehouseFormId; |
| | | |
| | | // 物品状态(0=在途调拨;1=入库未分发;2=已下发;3=报废) |
| | | short queryModelStatusT = 1; |
| | | Integer queryModelStatusT = 1; |
| | | //采购方式(1:集采;2=自采) |
| | | Short buyTypeT = null; |
| | | Short modGoodsTransferingStatusT = null; |
| | | String outputCode = lWhFormOutput.getOutputCode(); |
| | | if ((BaseWarehouseParam1.In_OutPutTypeEnum.Transfer_Output.getValue() + "").equals(outputCode)) { |
| | | Integer buyTypeT = null; |
| | | Integer modGoodsTransferingStatusT = null; |
| | | 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; |
| | | Short modGoodsTransferingStatus = modGoodsTransferingStatusT; |
| | | Integer queryModelStatus = queryModelStatusT; |
| | | Integer buyType = buyTypeT; |
| | | Integer modGoodsTransferingStatus = modGoodsTransferingStatusT; |
| | | |
| | | // 接收方仓库信息 |
| | | Long inWarehouseId = lWhFormOutput.getInWarehouseId(); |
| | | String inWarehouseName = lWhFormOutput.getInWarehouseName(); |
| | | |
| | | ArrayList<Long> allChangModelList = new ArrayList<>(); |
| | | goodsModelNumList.forEach(itemModelInfo -> { |
| | | // 需要调拨的物品的某个型号 |
| | | Long baseGoodsModelsId = itemModelInfo.getBaseGoodsModelsId(); |
| | | |
| | | //TODO 为空时不加入更新列表 |
| | | if (baseGoodsModelsId != null) { |
| | | allChangModelList.add(baseGoodsModelsId); |
| | | } |
| | | // 需要调拨的物品某个型号的数量 |
| | | Integer counts = itemModelInfo.getCounts(); |
| | | |
| | |
| | | |
| | | //通过LockManage获得锁 |
| | | Object warehouseModelLockObj = LockManage.acquireLock(outWarehouseType, outWarehouseId, baseGoodsModelsId); |
| | | List<Long> outGoodsId = null; |
| | | synchronized (warehouseModelLockObj) { |
| | | // 获得锁后查询该型号的期初数量 |
| | | int goodsModelNum = lWhGoodsService.queryGoodsModelNum(outWarehouseType, outWarehouseId, baseGoodsModelsId, queryModelStatus, buyType); |
| | |
| | | whGoodsRecord.setEndCount(goodsModelNum - counts); |
| | | |
| | | //出库时候,按 先入库的先出库,同时入库的,按价格高的先出库 |
| | | List<Long> outGoodsId = lWhGoodsService.queryOutGoodsId(outWarehouseType, outWarehouseId, baseGoodsModelsId, queryModelStatus, buyType, goodsModelNum); |
| | | lWhGoodsService.modGoodsTransfering(outGoodsId, outWarehouseType, 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); |
| | | 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); |
| | | }); |
| | | LWarehouseFlow warehouseFlow = new LWarehouseFlow(); |
| | | warehouseFlow.setId(lWarehouseFlowId); |
| | | warehouseFlow.setWarehouseId(outWarehouseId); |
| | | warehouseFlow.setWarehouseName(warehouseName); |
| | | warehouseFlow.setThisType(2); |
| | | warehouseFlow.setBusinessType(WhBusinessEnum.DIAOBO.getValue() + 0); |
| | | warehouseFlow.setBusinessType(businessType.getValue() + 0); |
| | | |
| | | warehouseFlow.setBusinessFormId(lWarehouseFlowBusinessId); |
| | | warehouseFlow.setBusinessFormId(whFormTransferId == null ? lWarehouseFlowBusinessId : whFormTransferId); |
| | | warehouseFlow.setOperatorId(userId); |
| | | warehouseFlow.setOperatorName(nickName); |
| | | warehouseFlow.setDealTime(dealTime); |
| | |
| | | if (flowInsertFlag == 0) { |
| | | return null; |
| | | } |
| | | // 向出库单 插入 进出库流水总表ID |
| | | lWhFormOutput = new LWhFormOutput(outWarehouseFormId); |
| | | lWhFormOutput.setStates(2); |
| | | lWhFormOutput.setWarehouseFlowId(lWarehouseFlowId); |
| | | lWhFormOutputService.update(lWhFormOutput); |
| | | |
| | | //当库存变动时调用该方法 |
| | | if (outWarehouseType == 0) { |
| | | lWhWarningCoreService.updateKuCun(Convert.toShort(outWarehouseType, (short) 0), outWarehouseId, allChangModelList, null, dealTime); |
| | | } |
| | | return lWarehouseFlowId; |
| | | } |
| | | |