New file |
| | |
| | | package com.consum.base.service; |
| | | |
| | | 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.util.IdUtil; |
| | | import com.consum.model.po.*; |
| | | import com.iplatform.model.po.S_user_core; |
| | | import com.walker.infrastructure.utils.NumberGenerator; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @ClassName LWhFormInventoryCoreService |
| | | * @Author cy |
| | | * @Date 2023/11/1 |
| | | * @Description |
| | | * @Version 1.0 |
| | | **/ |
| | | @Slf4j |
| | | @Service |
| | | public class LWhFormInventoryCoreService { |
| | | private LWhFormInventoryGoodsServiceImpl lWhFormInventoryGoods; |
| | | private LWhFormOutputCoreService lWhFormOutputCoreService; |
| | | private CodeGeneratorService codeGeneratorService; |
| | | private LWhFormProcureService lWhFormProcureService; |
| | | private BaseWarehouseServiceImpl baseWarehouseService; |
| | | private LWhFormProcureGoodsService lWhFormProcureGoodsService; |
| | | private LWhProcureModelService lWhProcureModelService; |
| | | private BaseGoodsTemplateServiceImpl baseGoodsTemplateService; |
| | | private LWhGoodsService lWhGoodsService; |
| | | private LWhFormInventoryServiceImpl lWhFormInventoryService; |
| | | private LWhFormProcureCoreService lWhFormProcureCoreService; |
| | | private LWhFormOutputServiceImpl lWhFormOutputService; |
| | | |
| | | @Autowired |
| | | public LWhFormInventoryCoreService(LWhFormInventoryGoodsServiceImpl lWhFormInventoryGoods, |
| | | LWhFormOutputCoreService lWhFormOutputCoreService, |
| | | CodeGeneratorService codeGeneratorService, |
| | | LWhFormProcureService lWhFormProcureService, |
| | | BaseWarehouseServiceImpl baseWarehouseService, |
| | | LWhFormProcureGoodsService lWhFormProcureGoodsService, |
| | | LWhProcureModelService lWhProcureModelService, |
| | | BaseGoodsTemplateServiceImpl baseGoodsTemplateService, |
| | | LWhGoodsService lWhGoodsService, |
| | | LWhFormInventoryServiceImpl lWhFormInventoryService, |
| | | LWhFormProcureCoreService lWhFormProcureCoreService, |
| | | LWhFormOutputServiceImpl lWhFormOutputService |
| | | |
| | | ) { |
| | | this.lWhFormInventoryGoods = lWhFormInventoryGoods; |
| | | this.lWhFormOutputCoreService = lWhFormOutputCoreService; |
| | | this.codeGeneratorService = codeGeneratorService; |
| | | this.lWhFormProcureService = lWhFormProcureService; |
| | | this.baseWarehouseService = baseWarehouseService; |
| | | this.lWhFormProcureGoodsService = lWhFormProcureGoodsService; |
| | | this.lWhProcureModelService = lWhProcureModelService; |
| | | this.baseGoodsTemplateService = baseGoodsTemplateService; |
| | | this.lWhGoodsService = lWhGoodsService; |
| | | this.lWhFormInventoryService = lWhFormInventoryService; |
| | | this.lWhFormProcureCoreService = lWhFormProcureCoreService; |
| | | this.lWhFormOutputService = lWhFormOutputService; |
| | | } |
| | | |
| | | /** |
| | | * 根据 盘点单 生成 出库单 和 入库单 |
| | | * 盘点单中 盘盈物品生成入库单,盘亏生成出库单 |
| | | * |
| | | * @param whformInventoryId 盘点单id |
| | | * @return status true/false |
| | | * errMsg 错误消息 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Map<String, Object> createInOutFormByInventoryId(Long whformInventoryId, S_user_core currentUser, FinSysTenantUser sysInfo) { |
| | | HashMap<String, Object> rtnMap = new HashMap<>(); |
| | | List<LWhFormInventoryGoods> lWhFormInventoryGoods = this.lWhFormInventoryGoods.getByInventoryId(whformInventoryId); |
| | | if (CollectionUtils.isEmpty(lWhFormInventoryGoods)) { |
| | | rtnMap.put("status", false); |
| | | rtnMap.put("errMsg", "没有找到物品"); |
| | | return rtnMap; |
| | | } |
| | | Map<Integer, List<LWhFormInventoryGoods>> inventoryGoodsMap = lWhFormInventoryGoods.stream() |
| | | .filter(goods -> goods.getInventoryResult() == 2 || goods.getInventoryResult() == 3) |
| | | .collect(Collectors.groupingBy(LWhFormInventoryGoods::getInventoryResult)); |
| | | if (CollectionUtils.isEmpty(lWhFormInventoryGoods)) { |
| | | rtnMap.put("status", true); |
| | | return rtnMap; |
| | | } |
| | | LWhFormInventory lWhFormInventory = lWhFormInventoryService.get(new LWhFormInventory(whformInventoryId)); |
| | | Long warehouseId = lWhFormInventory.getWarehouseId(); |
| | | Long stopTime = lWhFormInventory.getStopTime(); |
| | | |
| | | for (Map.Entry<Integer, List<LWhFormInventoryGoods>> entry : inventoryGoodsMap.entrySet()) { |
| | | //盘点结果(1=正常;2=盘盈;3=盘亏) |
| | | Integer inventoryResult = entry.getKey(); |
| | | List<LWhFormInventoryGoods> inventoryGoods = entry.getValue(); |
| | | if (inventoryResult == 2) { |
| | | // 创建入库单并入库 |
| | | // 返回入库单号 |
| | | Long inFormByInventoryId = createInFormByInventoryId(warehouseId, stopTime, inventoryGoods, currentUser); |
| | | if (inFormByInventoryId == null) { |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | // throw new RuntimeException("创建入库单失败"); |
| | | log.error("创建入库单失败"); |
| | | rtnMap.put("status", false); |
| | | rtnMap.put("errMsg", "创建入库单失败"); |
| | | return rtnMap; |
| | | } |
| | | String errMsg = lWhFormProcureCoreService.doProcure(warehouseId, currentUser); |
| | | if (errMsg != null) { |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | // throw new RuntimeException(errMsg); |
| | | log.error("创建入库单失败"); |
| | | rtnMap.put("status", false); |
| | | rtnMap.put("errMsg", "创建入库单失败"); |
| | | return rtnMap; |
| | | } |
| | | } else { |
| | | // 创建出库单并出库 |
| | | Long lWhFormOutputId = this.createOutFormByInventoryId(warehouseId, stopTime, inventoryGoods, currentUser, sysInfo); |
| | | if (lWhFormOutputId == null) { |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | // throw new RuntimeException("创建出库单失败"); |
| | | log.error("创建入库单失败"); |
| | | rtnMap.put("status", false); |
| | | rtnMap.put("errMsg", "创建入库单失败"); |
| | | return rtnMap; |
| | | } |
| | | //2.根据出库单出库 |
| | | Long lWarehouseFlowId = lWhFormOutputCoreService.outFormByTransId(lWhFormOutputId, currentUser, stopTime); |
| | | if (lWarehouseFlowId == null) { |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | // throw new RuntimeException("创建出库单失败"); |
| | | log.error("创建入库单失败"); |
| | | rtnMap.put("status", false); |
| | | rtnMap.put("errMsg", "创建入库单失败"); |
| | | return rtnMap; |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | return rtnMap; |
| | | } |
| | | |
| | | /** |
| | | * 根据信息创建入库单 |
| | | * |
| | | * @param warehouseId 仓库ID |
| | | * @param procureTime 采购时间 |
| | | * @param currentUser |
| | | */ |
| | | private Long createInFormByInventoryId(Long warehouseId, Long procureTime, List<LWhFormInventoryGoods> inventoryGoodsList, |
| | | S_user_core currentUser) { |
| | | if (CollectionUtils.isEmpty(inventoryGoodsList)) { |
| | | return null; |
| | | } |
| | | Long whFormProcureId = NumberGenerator.getLongSequenceNumber(); |
| | | BaseWarehouse baseWarehouse = baseWarehouseService.getById(warehouseId); |
| | | LWhFormProcure lWhFormProcure = new LWhFormProcure(); |
| | | lWhFormProcure.setId(whFormProcureId); |
| | | lWhFormProcure.setBusinessFormCode(codeGeneratorService.createCodeByPrefix(CodeGeneratorEnum.Procure_Warehouse.getValue(), 10)); |
| | | lWhFormProcure.setWarehouseId(warehouseId); |
| | | lWhFormProcure.setWarehouseName(baseWarehouse.getWarehouseName()); |
| | | lWhFormProcure.setBuyerId(currentUser.getId()); |
| | | lWhFormProcure.setBuyerName(currentUser.getNick_name()); |
| | | lWhFormProcure.setProcureTime(procureTime); |
| | | lWhFormProcure.setProcureDoc(null); |
| | | lWhFormProcure.setBuyType(2); |
| | | lWhFormProcure.setStates(1); |
| | | lWhFormProcure.setAgencyId(baseWarehouse.getAgencyId()); |
| | | lWhFormProcure.setAgencyName(baseWarehouse.getAgencyName()); |
| | | int result = lWhFormProcureService.insert(lWhFormProcure); |
| | | if (result == 0) return null; |
| | | |
| | | ArrayList<LWhFormProcureGoods> procureGoodList = new ArrayList<>(); |
| | | ArrayList<LWhProcureModel> whProcureModeLlist = new ArrayList<>(); |
| | | |
| | | for (LWhFormInventoryGoods inventoryGoods : inventoryGoodsList) { |
| | | Long baseGoodsModelsId = inventoryGoods.getBaseGoodsModelsId(); |
| | | Long baseGoodsTemplateId = inventoryGoods.getBaseGoodsTemplateId(); |
| | | //查询型号信息 |
| | | Map<String, Object> tempGoodsInfo = baseGoodsTemplateService.queryGoodsInfoByModelId(baseGoodsModelsId); |
| | | Long baseCategoryId = Long.valueOf(tempGoodsInfo.get("categoryid") + ""); |
| | | |
| | | LWhFormProcureGoods procureGood = new LWhFormProcureGoods(); |
| | | long fromProcureGoodsId = NumberGenerator.getLongSequenceNumber(); |
| | | procureGood.setId(fromProcureGoodsId); |
| | | procureGood.setWhFormProcureId(whFormProcureId); |
| | | procureGood.setBaseCategoryId(baseCategoryId); |
| | | procureGood.setBaseGoodsTemplateId(baseGoodsTemplateId); |
| | | procureGood.setGoodsTemplateName(null); |
| | | procureGood.setSupplier(null); |
| | | procureGood.setSort(null); |
| | | |
| | | Integer counts = inventoryGoods.getErrorCounts(); |
| | | if (counts == null || counts <= 0) { |
| | | continue; |
| | | } |
| | | // 查询型号库存 |
| | | int goodsModelNum = lWhGoodsService.queryGoodsModelNum(0, warehouseId, baseGoodsModelsId, (short) 1, null); |
| | | LWhProcureModel model = new LWhProcureModel(); |
| | | model.setId(NumberGenerator.getLongSequenceNumber()); |
| | | model.setFromProcureGoodsId(fromProcureGoodsId); |
| | | model.setBusinessType(WhBusinessEnum.CAIGOU.getValue() + 0); |
| | | model.setBusinessId(whFormProcureId); |
| | | model.setBaseGoodsModelsId(baseGoodsModelsId); |
| | | model.setPrice(0l); |
| | | model.setCounts(counts); |
| | | model.setWorehouseCount(goodsModelNum); |
| | | model.setSupplier(null); |
| | | whProcureModeLlist.add(model); |
| | | procureGoodList.add(procureGood); |
| | | } |
| | | lWhFormProcureGoodsService.insertBatch(procureGoodList); |
| | | lWhProcureModelService.insertBatch(whProcureModeLlist); |
| | | return whFormProcureId; |
| | | } |
| | | |
| | | /** |
| | | * 根据信息创建出库单 |
| | | * |
| | | * @param warehouseId 仓库ID |
| | | * @param procureTime 出库时间 |
| | | * @param currentUser |
| | | */ |
| | | private Long createOutFormByInventoryId(Long warehouseId, Long procureTime, List<LWhFormInventoryGoods> inventoryGoodsList, |
| | | S_user_core currentUser, FinSysTenantUser sysInfo) { |
| | | if (CollectionUtils.isEmpty(inventoryGoodsList)) { |
| | | return null; |
| | | } |
| | | //1.新增出库单记录 |
| | | LWhFormOutput lWhFormOutput = new LWhFormOutput(); |
| | | //出入库id |
| | | long lWhFormOutputId = IdUtil.generateId(); |
| | | lWhFormOutput.setId(lWhFormOutputId); |
| | | lWhFormOutput.setWarehouseId(warehouseId); |
| | | //根据仓库id查询仓库 |
| | | BaseWarehouse warehouse = this.baseWarehouseService.getById(warehouseId); |
| | | if (warehouse == null) { |
| | | log.error("仓库id不存在"); |
| | | return null; |
| | | } |
| | | lWhFormOutput.setWarehouseName(warehouse.getWarehouseName()); |
| | | lWhFormOutput.setOutputCode(BaseWarehouseParam1.In_OutPutTypeEnum.Inventory_Output.getValue() + ""); |
| | | lWhFormOutput.setOutputName("盘点出库"); |
| | | lWhFormOutput.setAgencyId(Long.valueOf(sysInfo.getTenantId())); |
| | | lWhFormOutput.setAgencyName(sysInfo.getTenantName()); |
| | | lWhFormOutput.setOperatorId(sysInfo.getId()); |
| | | lWhFormOutput.setOperatorName(sysInfo.getUserName()); |
| | | |
| | | lWhFormOutput.setDealTime(procureTime); |
| | | lWhFormOutput.setStates(1); |
| | | int flag1 = lWhFormOutputService.insert(lWhFormOutput); |
| | | if (flag1 != 1) { |
| | | return null; |
| | | } |
| | | for (LWhFormInventoryGoods inventoryGoods : inventoryGoodsList) { |
| | | Long baseGoodsModelsId = inventoryGoods.getBaseGoodsModelsId(); |
| | | Integer counts = inventoryGoods.getErrorCounts(); |
| | | if (counts == null || counts <= 0) { |
| | | continue; |
| | | } |
| | | //根据物品型号查询物品库存 |
| | | int goodsNum = lWhGoodsService.queryGoodsModelNum(0, warehouseId, baseGoodsModelsId, (short) 1, null); |
| | | //新增L_WH_PROCURE_MODEL记录 |
| | | LWhProcureModel lWhProcureModel = new LWhProcureModel(); |
| | | lWhProcureModel.setId(IdUtil.generateId()); |
| | | lWhProcureModel.setBusinessType(3); |
| | | lWhProcureModel.setBaseGoodsModelsId(baseGoodsModelsId); |
| | | lWhProcureModel.setCounts(counts); |
| | | lWhProcureModel.setWorehouseCount(goodsNum); |
| | | lWhProcureModelService.insert(lWhProcureModel); |
| | | } |
| | | |
| | | |
| | | return lWhFormOutputId; |
| | | |
| | | } |
| | | } |