| | |
| | | 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; |
| | |
| | | * errMsg 错误消息 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Map<String, Object> createInOutFormByInventoryId(Long whformInventoryId, S_user_core currentUser, FinSysTenantUser sysInfo) { |
| | | HashMap<String, Object> rtnMap = new HashMap<>(); |
| | | public String createInOutFormByInventoryId(Long whformInventoryId, S_user_core currentUser, FinSysTenantUser sysInfo) { |
| | | LWhFormInventory lWhFormInventory = lWhFormInventoryService.get(new LWhFormInventory(whformInventoryId)); |
| | | if (lWhFormInventory == null) { |
| | | // rtnMap.put("status", false); |
| | | // rtnMap.put("errMsg", "没有找到盘点单"); |
| | | return "没有找到盘点单"; |
| | | } |
| | | if (lWhFormInventory.getStates() != 1) { |
| | | // rtnMap.put("status", false); |
| | | // rtnMap.put("errMsg", "请检查盘点单状态"); |
| | | return "请检查盘点单状态"; |
| | | } |
| | | List<LWhFormInventoryGoods> lWhFormInventoryGoods = this.lWhFormInventoryGoods.getByInventoryId(whformInventoryId); |
| | | if (CollectionUtils.isEmpty(lWhFormInventoryGoods)) { |
| | | rtnMap.put("status", false); |
| | | rtnMap.put("errMsg", "没有找到物品"); |
| | | return rtnMap; |
| | | // rtnMap.put("status", false); |
| | | // rtnMap.put("errMsg", "没有找到盘点单结果物品"); |
| | | return "没有找到盘点单结果物品"; |
| | | } |
| | | 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; |
| | | // rtnMap.put("status", true); |
| | | return null; |
| | | } |
| | | LWhFormInventory lWhFormInventory = lWhFormInventoryService.get(new LWhFormInventory(whformInventoryId)); |
| | | |
| | | Long warehouseId = lWhFormInventory.getWarehouseId(); |
| | | Long stopTime = lWhFormInventory.getStopTime(); |
| | | Map<String, Object> inOutMap = new HashMap<>(); |
| | | |
| | | for (Map.Entry<Integer, List<LWhFormInventoryGoods>> entry : inventoryGoodsMap.entrySet()) { |
| | | //盘点结果(1=正常;2=盘盈;3=盘亏) |
| | |
| | | if (inventoryResult == 2) { |
| | | // 创建入库单并入库 |
| | | // 返回入库单号 |
| | | Long inFormByInventoryId = createInFormByInventoryId(warehouseId, stopTime, inventoryGoods, currentUser); |
| | | if (inFormByInventoryId == null) { |
| | | Map<String, Object> rkMap = createInFormByInventoryId(warehouseId, stopTime, inventoryGoods, currentUser); |
| | | if (rkMap == null) { |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | // throw new RuntimeException("创建入库单失败"); |
| | | log.error("创建入库单失败"); |
| | | rtnMap.put("status", false); |
| | | rtnMap.put("errMsg", "创建入库单失败"); |
| | | return rtnMap; |
| | | // rtnMap.put("status", false); |
| | | // rtnMap.put("errMsg", "创建入库单失败"); |
| | | return "创建入库单失败"; |
| | | } |
| | | String errMsg = lWhFormProcureCoreService.doProcure(warehouseId, currentUser); |
| | | Long inFormByInventoryId = (Long) inOutMap.get("inId"); |
| | | inOutMap.putAll(rkMap); |
| | | String errMsg = lWhFormProcureCoreService.doProcure(inFormByInventoryId, currentUser); |
| | | if (errMsg != null) { |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | // throw new RuntimeException(errMsg); |
| | | log.error("创建入库单失败"); |
| | | rtnMap.put("status", false); |
| | | rtnMap.put("errMsg", "创建入库单失败"); |
| | | return rtnMap; |
| | | // rtnMap.put("status", false); |
| | | // rtnMap.put("errMsg", "创建入库单失败"); |
| | | return "创建入库单失败"; |
| | | } |
| | | } else { |
| | | // 创建出库单并出库 |
| | | Long lWhFormOutputId = this.createOutFormByInventoryId(warehouseId, stopTime, inventoryGoods, currentUser, sysInfo); |
| | | if (lWhFormOutputId == null) { |
| | | Map<String, Object> ckMap = createOutFormByInventoryId(warehouseId, stopTime, inventoryGoods, currentUser, sysInfo); |
| | | if (ckMap == null) { |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | // throw new RuntimeException("创建出库单失败"); |
| | | log.error("创建入库单失败"); |
| | | rtnMap.put("status", false); |
| | | rtnMap.put("errMsg", "创建入库单失败"); |
| | | return rtnMap; |
| | | // rtnMap.put("status", false); |
| | | // rtnMap.put("errMsg", "创建入库单失败"); |
| | | return "创建入库单失败"; |
| | | } |
| | | inOutMap.putAll(ckMap); |
| | | Long lWhFormOutputId = (Long) inOutMap.get("outId"); |
| | | //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; |
| | | // rtnMap.put("status", false); |
| | | // rtnMap.put("errMsg", "创建入库单失败"); |
| | | return "创建入库单失败"; |
| | | } |
| | | |
| | | } |
| | | } |
| | | // |
| | | lWhFormInventory = new LWhFormInventory(whformInventoryId); |
| | | lWhFormInventory.setStates(2); |
| | | lWhFormInventory.setInWarehouseFormId((Long) inOutMap.get("inId")); |
| | | lWhFormInventory.setInBusinessFormCode((String) inOutMap.get("inCode")); |
| | | lWhFormInventory.setOutWarehouseFormId((Long) inOutMap.get("outId")); |
| | | lWhFormInventory.setOutBusinessFormCode((String) inOutMap.get("outCode")); |
| | | lWhFormInventoryService.update(lWhFormInventory); |
| | | |
| | | return rtnMap; |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param procureTime 采购时间 |
| | | * @param currentUser |
| | | */ |
| | | private Long createInFormByInventoryId(Long warehouseId, Long procureTime, List<LWhFormInventoryGoods> inventoryGoodsList, |
| | | S_user_core currentUser) { |
| | | private Map<String, Object> createInFormByInventoryId(Long warehouseId, Long procureTime, List<LWhFormInventoryGoods> inventoryGoodsList, |
| | | S_user_core currentUser) { |
| | | if (CollectionUtils.isEmpty(inventoryGoodsList)) { |
| | | return null; |
| | | } |
| | |
| | | BaseWarehouse baseWarehouse = baseWarehouseService.getById(warehouseId); |
| | | LWhFormProcure lWhFormProcure = new LWhFormProcure(); |
| | | lWhFormProcure.setId(whFormProcureId); |
| | | lWhFormProcure.setBusinessFormCode(codeGeneratorService.createCodeByPrefix(CodeGeneratorEnum.Procure_Warehouse.getValue(), 10)); |
| | | String inCode = codeGeneratorService.createCodeByPrefix(CodeGeneratorEnum.Procure_Warehouse.getValue(), 10); |
| | | lWhFormProcure.setBusinessFormCode(inCode); |
| | | lWhFormProcure.setWarehouseId(warehouseId); |
| | | lWhFormProcure.setWarehouseName(baseWarehouse.getWarehouseName()); |
| | | lWhFormProcure.setBuyerId(currentUser.getId()); |
| | |
| | | lWhFormProcure.setAgencyId(baseWarehouse.getAgencyId()); |
| | | lWhFormProcure.setAgencyName(baseWarehouse.getAgencyName()); |
| | | int result = lWhFormProcureService.insert(lWhFormProcure); |
| | | if (result == 0) return null; |
| | | if (result == 0) { |
| | | return null; |
| | | } |
| | | |
| | | ArrayList<LWhFormProcureGoods> procureGoodList = new ArrayList<>(); |
| | | ArrayList<LWhProcureModel> whProcureModeLlist = new ArrayList<>(); |
| | |
| | | } |
| | | lWhFormProcureGoodsService.insertBatch(procureGoodList); |
| | | lWhProcureModelService.insertBatch(whProcureModeLlist); |
| | | return whFormProcureId; |
| | | |
| | | HashMap<String, Object> rtnMap = new HashMap<>(); |
| | | rtnMap.put("inId", whFormProcureId); |
| | | rtnMap.put("inCode", inCode); |
| | | return rtnMap; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param procureTime 出库时间 |
| | | * @param currentUser |
| | | */ |
| | | private Long createOutFormByInventoryId(Long warehouseId, Long procureTime, List<LWhFormInventoryGoods> inventoryGoodsList, |
| | | S_user_core currentUser, FinSysTenantUser sysInfo) { |
| | | private Map<String, Object> createOutFormByInventoryId(Long warehouseId, Long procureTime, List<LWhFormInventoryGoods> inventoryGoodsList, |
| | | S_user_core currentUser, FinSysTenantUser sysInfo) { |
| | | if (CollectionUtils.isEmpty(inventoryGoodsList)) { |
| | | return null; |
| | | } |
| | |
| | | return null; |
| | | } |
| | | lWhFormOutput.setWarehouseName(warehouse.getWarehouseName()); |
| | | lWhFormOutput.setOutputCode(BaseWarehouseParam1.In_OutPutTypeEnum.Inventory_Output.getValue() + ""); |
| | | String outCode = codeGeneratorService.createCodeByPrefix(CodeGeneratorEnum.OutPut_Warehouse.getValue(), 10); |
| | | lWhFormOutput.setOutputCode(outCode); |
| | | lWhFormOutput.setOutputName("盘点出库"); |
| | | lWhFormOutput.setAgencyId(Long.valueOf(sysInfo.getTenantId())); |
| | | lWhFormOutput.setAgencyName(sysInfo.getTenantName()); |
| | |
| | | lWhProcureModel.setWorehouseCount(goodsNum); |
| | | lWhProcureModelService.insert(lWhProcureModel); |
| | | } |
| | | |
| | | |
| | | return lWhFormOutputId; |
| | | HashMap<String, Object> rtnMap = new HashMap<>(); |
| | | rtnMap.put("outId", lWhFormOutputId); |
| | | rtnMap.put("outCode", outCode); |
| | | return rtnMap; |
| | | |
| | | } |
| | | } |