From 4b0bc711b15affc1c27023938eb0091818d976b3 Mon Sep 17 00:00:00 2001 From: PigBaoBei <2739175034@qq.com> Date: Thu, 15 Aug 2024 14:27:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=AC=E5=BA=93=E5=AD=98=E5=93=81BUG?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DistributionParcelListServiceImpl.java | 264 +++++++++--------- 1 file changed, 139 insertions(+), 125 deletions(-) diff --git a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionParcelListServiceImpl.java b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionParcelListServiceImpl.java index ef8b8d95d..1f43499c7 100644 --- a/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionParcelListServiceImpl.java +++ b/blade-service/logpm-distribution/src/main/java/com/logpm/distribution/service/impl/DistributionParcelListServiceImpl.java @@ -901,140 +901,154 @@ public class DistributionParcelListServiceImpl extends BaseServiceImpl distributionParcelListEntities = this.listByIds(packageIds); List materialId = distributionParcelListEntities.stream().map(DistributionParcelListEntity::getMaterialId).distinct().collect(Collectors.toList()); List materialCode = distributionParcelListEntities.stream().map(DistributionParcelListEntity::getMaterialCode).distinct().collect(Collectors.toList()); - List materialUnit = distributionParcelListEntities.stream().map(DistributionParcelListEntity::getMaterialUnit).distinct().collect(Collectors.toList()); - List mallId = distributionParcelListEntities.stream().map(DistributionParcelListEntity::getMarketId).distinct().collect(Collectors.toList()); - List materialName = distributionParcelListEntities.stream().map(DistributionParcelListEntity::getMaterialName).distinct().collect(Collectors.toList()); - List brandName = distributionParcelListEntities.stream().map(DistributionParcelListEntity::getBrandName).distinct().collect(Collectors.toList()); - List brandId = distributionParcelListEntities.stream().map(DistributionParcelListEntity::getBrandId).distinct().collect(Collectors.toList()); - if (materialId.size() != 1 || materialCode.size() != 1 || materialUnit.size() != 1 || mallId.size() != 1 || materialName.size() != 1 || brandName.size() != 1) { - //该批次包件出现多种物料包件 - return null; - } - - int num = distributionParcelListEntities.stream().mapToInt(DistributionParcelListEntity::getQuantity).sum(); - if (num <= 0) { - //无有效的在库数量 - return null; - } - DistributionStockListEntity distributionStockListEntity = new DistributionStockListEntity(); - //直接添加 -// distributionStockListEntity.setIncomingBatch(distributionStockArticleEntity.get); //入库批次号 - distributionStockListEntity.setServiceNumber(Optional.ofNullable(distributionStockArticleEntity.getServiceNumber()).orElse(null)); //服务号 - distributionStockListEntity.setDescriptionGoods(materialName.get(0)); //物料名称 - distributionStockListEntity.setCargoNumber(materialCode.get(0)); //物料编号 - distributionStockListEntity.setWarehouseName(Optional.ofNullable(distributionStockArticleEntity.getWarehouse()).orElse(null)); //仓库 - distributionStockListEntity.setWarehouseId(Optional.ofNullable(distributionStockArticleEntity.getWarehouseId()).orElse(null)); //仓库ID - distributionStockListEntity.setMarketId(Optional.ofNullable(distributionStockArticleEntity.getMallId()).orElse(null)); //商场 - distributionStockListEntity.setCargoUnit(materialUnit.get(0)); //货物单位 +// List materialUnit = distributionParcelListEntities.stream().map(DistributionParcelListEntity::getMaterialUnit).distinct().collect(Collectors.toList()); +// List mallId = distributionParcelListEntities.stream().map(DistributionParcelListEntity::getMarketId).distinct().collect(Collectors.toList()); +// List materialName = distributionParcelListEntities.stream().map(DistributionParcelListEntity::getMaterialName).distinct().collect(Collectors.toList()); +// List brandName = distributionParcelListEntities.stream().map(DistributionParcelListEntity::getBrandName).distinct().collect(Collectors.toList()); +// List brandId = distributionParcelListEntities.stream().map(DistributionParcelListEntity::getBrandId).distinct().collect(Collectors.toList()); +// if (materialId.size() != 1 || materialCode.size() != 1 || materialUnit.size() != 1 || mallId.size() != 1 || materialName.size() != 1 || brandName.size() != 1) { +// //该批次包件出现多种物料包件 +// return null; +// } + List infoEntities = new ArrayList<>(); - distributionStockListEntity.setMallName(Optional.ofNullable(distributionStockArticleEntity.getMallName()).orElse(null)); //商场名称 - distributionStockListEntity.setQuantityStock(num); //库存数量(包件数量) - distributionStockListEntity.setIncomingBatch(Optional.ofNullable(distributionStockArticleEntity.getOrderCode()).orElse(null)); //入库批次 - distributionStockListEntity.setOutboundQuantity(0); //出库数量 + if (!distributionParcelListEntities.isEmpty()) { + Map> listMap = distributionParcelListEntities.stream().collect(Collectors.groupingBy(DistributionParcelListEntity::getMaterialName)); + listMap.forEach((k,v)->{ + //校验品牌 + List brandList = v.stream().map(DistributionParcelListEntity::getBrandName).collect(Collectors.toList()); + if (brandList.size()>1){ + //多个品牌 + throw new RuntimeException(k+"多个品牌"); + } + List mallList = v.stream().map(DistributionParcelListEntity::getMallName).collect(Collectors.toList()); + if (mallList.size()>1){ + //多个商场 + throw new RuntimeException(k+"多个商场"); + } + List brandId = v.stream().map(DistributionParcelListEntity::getBrandId).distinct().collect(Collectors.toList()); + if (brandId.size()>1){ + //多个品牌 + throw new RuntimeException(k+"多个品牌"); + } + List materialName = distributionParcelListEntities.stream().map(DistributionParcelListEntity::getMaterialName).distinct().collect(Collectors.toList()); + if (materialName.size()>1){ + throw new RuntimeException(k+"存在多个物料单位"); + } + List materialUnit = distributionParcelListEntities.stream().map(DistributionParcelListEntity::getMaterialUnit).distinct().collect(Collectors.toList()); + if (materialUnit.size()>1){ + //多个物料单位 + throw new RuntimeException(k+"存在多个物料单位"); + } + int num = v.stream().mapToInt(DistributionParcelListEntity::getQuantity).sum(); + if (num <= 0) { + //无有效的在库数量 + throw new RuntimeException("无有效的在库数量"); + } + DistributionStockListEntity distributionStockListEntity = new DistributionStockListEntity(); + //直接添加 + distributionStockListEntity.setServiceNumber(Optional.ofNullable(distributionStockArticleEntity.getServiceNumber()).orElse(null)); //服务号 + distributionStockListEntity.setDescriptionGoods(materialName.get(0)); //物料名称 + distributionStockListEntity.setCargoNumber(materialCode.get(0)); //物料编号 + distributionStockListEntity.setWarehouseName(Optional.ofNullable(distributionStockArticleEntity.getWarehouse()).orElse(null)); //仓库 + distributionStockListEntity.setWarehouseId(Optional.ofNullable(distributionStockArticleEntity.getWarehouseId()).orElse(null)); //仓库ID + distributionStockListEntity.setMarketId(Optional.ofNullable(distributionStockArticleEntity.getMallId()).orElse(null)); //商场 + distributionStockListEntity.setCargoUnit(materialUnit.get(0)); //货物单位 + + distributionStockListEntity.setMallName(Optional.ofNullable(distributionStockArticleEntity.getMallName()).orElse(null)); //商场名称 + distributionStockListEntity.setQuantityStock(num); //库存数量(包件数量) + distributionStockListEntity.setIncomingBatch(Optional.ofNullable(distributionStockArticleEntity.getOrderCode()).orElse(null)); //入库批次 + distributionStockListEntity.setOutboundQuantity(0); //出库数量 // distributionStockListEntity.setCargoUnit(Optional.ofNullable(distributionParcelList.getMaterialUnit()).orElse(null));//单位 - distributionStockListEntity.setStoreId(Optional.ofNullable(distributionStockArticleEntity.getStoreId()).orElse(null));//门店ID - distributionStockListEntity.setMarketCode(Optional.ofNullable(distributionStockArticleEntity.getMallCode()).orElse(null));//商场编码 - distributionStockListEntity.setMarketName(Optional.ofNullable(distributionStockArticleEntity.getMallName()).orElse(null));//商场名称 - distributionStockListEntity.setStoreCode(Optional.ofNullable(distributionStockArticleEntity.getStoreCode()).orElse(null));//门店编码 - distributionStockListEntity.setStoreName(Optional.ofNullable(distributionStockArticleEntity.getStoreName()).orElse(null));//门店名称 + distributionStockListEntity.setStoreId(Optional.ofNullable(distributionStockArticleEntity.getStoreId()).orElse(null));//门店ID + distributionStockListEntity.setMarketCode(Optional.ofNullable(distributionStockArticleEntity.getMallCode()).orElse(null));//商场编码 + distributionStockListEntity.setMarketName(Optional.ofNullable(distributionStockArticleEntity.getMallName()).orElse(null));//商场名称 + distributionStockListEntity.setStoreCode(Optional.ofNullable(distributionStockArticleEntity.getStoreCode()).orElse(null));//门店编码 + distributionStockListEntity.setStoreName(Optional.ofNullable(distributionStockArticleEntity.getStoreName()).orElse(null));//门店名称 // distributionStockListEntity.setCategory(Optional.ofNullable(distributionParcelList.getBrandId()+"").orElse(null));//品分类 - // 品牌 - distributionStockListEntity.setBrandId(brandId.get(0)); - distributionStockListEntity.setBrandName(brandName.get(0)); - distributionStockListEntity.setUnpackingQuantity(0); - distributionStockListEntity.setSourceType("1"); //类型 - - BasicMaterialEntity materialOwnId = basicMaterialClient.getMaterialOwnId(materialId.get(0)); - distributionStockListEntity.setSku(materialOwnId.getSku()); - distributionStockListEntity.setMaterialId(materialId.get(0));//货物ID -// distributionStockListEntity.setParcelListId(distributionParcelListEntities.getId());//包件id - distributionStockListEntity.setQuantityOccupied(0);//冻结数量 - distributionStockListEntity.setServiceType(distributionStockArticleEntity.getTypeService());//冻结数量 - DistributionStockListEntity stockListEntity = distributionStockListService.getStockListEntity(distributionStockArticleEntity.getMallId(), distributionParcelListEntities.get(0).getMaterialId(), distributionStockArticleEntity.getOrderCode(), distributionStockArticleEntity.getStoreId(), distributionStockArticleEntity.getWarehouseId()); - if (ObjectUtils.isNotNull(stockListEntity)) { - distributionStockListEntity.setId(stockListEntity.getId()); - //有记录 - DistributionStockListEntity listEntity = new DistributionStockListEntity(); - listEntity.setId(stockListEntity.getId());//id -// Integer quantity = ObjectUtils.isNull(distributionParcelListEntities.get(0).getQuantity()) ? 0 : distributionParcelListEntities.get(0).getQuantity(); - Integer quantityStock = ObjectUtils.isNull(stockListEntity.getQuantityStock()) ? 0 : stockListEntity.getQuantityStock(); - listEntity.setQuantityStock(num + quantityStock); - distributionStockListService.updateById(listEntity); - } else { - log.info("###########distributionStockListEntity>>>>>>>>,{}", distributionStockListEntity); - distributionStockListService.save(distributionStockListEntity); - } -// distributionStockListEntity.setTrayName(Optional.ofNullable(distributionParcelList.getPallet()).orElse(null)); //托盘 -// distributionStockListEntity.setStorageLocation(Optional.ofNullable(distributionParcelList.getGoodsAllocation()).orElse(null)); //库位信息 -// distributionStockListEntity.setFactory(Optional.ofNullable(distributionStockArticleEntity.getFactoryTrain()).orElse(null));//工厂车次 -// distributionStockListEntity.setDespatch(Optional.ofNullable(distributionStockArticleEntity.getTrainNumber()).orElse(null));//车次号 -// distributionStockListEntity.setStockArticleId(Optional.ofNullable(distributionStockArticleEntity.getId()).orElse(null)); //订单ID -// distributionStockListEntity.setOrderCode(Optional.ofNullable(distributionParcelListEntities.get(0).getOrderCode()).orElse(null)); //订单自编号 + // 品牌 + distributionStockListEntity.setBrandId(brandId.get(0)); + distributionStockListEntity.setBrandName(brandList.get(0)); + distributionStockListEntity.setUnpackingQuantity(0); + distributionStockListEntity.setSourceType("1"); //类型 + + BasicMaterialEntity materialOwnId = basicMaterialClient.getMaterialOwnId(materialId.get(0)); + distributionStockListEntity.setSku(materialOwnId.getSku()); + distributionStockListEntity.setMaterialId(materialId.get(0));//货物ID + distributionStockListEntity.setQuantityOccupied(0);//冻结数量 + distributionStockListEntity.setServiceType(distributionStockArticleEntity.getTypeService());//冻结数量 + DistributionStockListEntity stockListEntity = distributionStockListService.getStockListEntity(distributionStockArticleEntity.getMallId(), distributionParcelListEntities.get(0).getMaterialId(), distributionStockArticleEntity.getOrderCode(), distributionStockArticleEntity.getStoreId(), distributionStockArticleEntity.getWarehouseId()); + if (ObjectUtils.isNotNull(stockListEntity)) { + distributionStockListEntity.setId(stockListEntity.getId()); + //有记录 + DistributionStockListEntity listEntity = new DistributionStockListEntity(); + listEntity.setId(stockListEntity.getId());//id + Integer quantityStock = ObjectUtils.isNull(stockListEntity.getQuantityStock()) ? 0 : stockListEntity.getQuantityStock(); + listEntity.setQuantityStock(num + quantityStock); + distributionStockListService.updateById(listEntity); + } else { + log.info("###########distributionStockListEntity>>>>>>>>,{}", distributionStockListEntity); + distributionStockListService.save(distributionStockListEntity); + } - List infoEntities = new ArrayList<>(); - for (DistributionParcelListEntity distributionParcelListEntity : distributionParcelListEntities) { - //添加库存品记录 - DistributionStockListInfoEntity distributionStockListInfo = new DistributionStockListInfoEntity(); -// BeanUtil.copyProperties(distributionStockListEntity,distributionStockListInfo); - - distributionStockListInfo.setServiceNumber(distributionStockListEntity.getServiceNumber()); //服务号 - distributionStockListInfo.setStockListId(distributionStockListEntity.getId()); //库存品ID - distributionStockListInfo.setDescriptionGoods(distributionStockListEntity.getMallName()); //物料名称 - distributionStockListInfo.setCargoNumber(distributionStockListEntity.getCargoNumber()); //物料编号 - distributionStockListInfo.setWarehouseName(distributionStockListEntity.getWarehouseName()); //仓库 - distributionStockListInfo.setWarehouseId(distributionStockListEntity.getWarehouseId()); //仓库ID - distributionStockListInfo.setMarketId(distributionStockListEntity.getMarketId()); //商场 - distributionStockListInfo.setCargoUnit(distributionStockListEntity.getCargoUnit()); //货物单位 - distributionStockListInfo.setStorageLocation(distributionParcelListEntity.getPallet()); //货物单位 - - distributionStockListInfo.setMallName(distributionStockListEntity.getMallName()); //商场名称 - distributionStockListInfo.setQuantityStock(distributionParcelListEntity.getQuantity()); //库存数量(包件数量) - distributionStockListInfo.setIncomingBatch(distributionStockListEntity.getIncomingBatch()); //入库批次 - distributionStockListInfo.setOutboundQuantity(0); //出库数量 - distributionStockListInfo.setOutboundQuantity(0); //入库时间 + for (DistributionParcelListEntity distributionParcelListEntity : v) { + //添加库存品记录 + DistributionStockListInfoEntity distributionStockListInfo = new DistributionStockListInfoEntity(); + distributionStockListInfo.setServiceNumber(distributionStockListEntity.getServiceNumber()); //服务号 + distributionStockListInfo.setStockListId(distributionStockListEntity.getId()); //库存品ID + distributionStockListInfo.setDescriptionGoods(distributionStockListEntity.getMallName()); //物料名称 + distributionStockListInfo.setCargoNumber(distributionStockListEntity.getCargoNumber()); //物料编号 + distributionStockListInfo.setWarehouseName(distributionStockListEntity.getWarehouseName()); //仓库 + distributionStockListInfo.setWarehouseId(distributionStockListEntity.getWarehouseId()); //仓库ID + distributionStockListInfo.setMarketId(distributionStockListEntity.getMarketId()); //商场 + distributionStockListInfo.setCargoUnit(distributionStockListEntity.getCargoUnit()); //货物单位 + distributionStockListInfo.setStorageLocation(distributionParcelListEntity.getPallet()); //货物单位 + distributionStockListInfo.setMallName(distributionStockListEntity.getMallName()); //商场名称 + distributionStockListInfo.setQuantityStock(distributionParcelListEntity.getQuantity()); //库存数量(包件数量) + distributionStockListInfo.setIncomingBatch(distributionStockListEntity.getIncomingBatch()); //入库批次 + distributionStockListInfo.setOutboundQuantity(0); //出库数量 + distributionStockListInfo.setOutboundQuantity(0); //入库时间 + distributionStockListInfo.setStoreId(distributionStockListEntity.getStoreId());//门店ID + distributionStockListInfo.setMarketCode(distributionStockListEntity.getMarketCode());//商场编码 + distributionStockListInfo.setMarketName(distributionStockListEntity.getMarketName());//商场名称 + distributionStockListInfo.setStoreCode(distributionStockListEntity.getStoreCode());//门店编码 + distributionStockListInfo.setStoreName(distributionStockListEntity.getStoreName());//门店名称 + // 品牌 + distributionStockListInfo.setBrandId(distributionStockListEntity.getBrandId()); + distributionStockListInfo.setBrandName(distributionStockListEntity.getBrandName()); + distributionStockListInfo.setUnpackingQuantity(0); + distributionStockListInfo.setSourceType("1"); //类型 + distributionStockListInfo.setSku(distributionStockListEntity.getSku()); + distributionStockListInfo.setMaterialId(distributionStockListEntity.getMaterialId());//货物ID + distributionStockListInfo.setQuantityOccupied(0);//冻结数量 + distributionStockListInfo.setServiceType(distributionStockListEntity.getServiceType());//冻结数 + //需要包件维度的详情 + WarehouseUpdownGoodsEntity warehouseUpdownGoodsEntity = new WarehouseUpdownGoodsEntity(); + warehouseUpdownGoodsEntity.setWarehouseId(myCurrentWarehouse.getId()); + warehouseUpdownGoodsEntity.setAssociationType("3"); + warehouseUpdownGoodsEntity.setAssociationValue(distributionParcelListEntity.getOrderPackageCode()); + WarehouseUpdownGoodsEntity locationInformation = warehouseUpdownGoodsClient.getLocationInformation(warehouseUpdownGoodsEntity); + if (Func.isNotEmpty(locationInformation)) { + distributionStockListInfo.setStorageLocation(locationInformation.getAllocationTitle()); + } + distributionStockListInfo.setFactory(distributionStockArticleEntity.getFactoryTrain()); + distributionStockListInfo.setDespatch(distributionStockArticleEntity.getTrainNumber()); + distributionStockListInfo.setStockArticleId(distributionStockArticleEntity.getId()); + distributionStockListInfo.setOrderCode(distributionStockArticleEntity.getOrderCode()); + distributionStockListInfo.setParcelListId(distributionParcelListEntity.getId()); + distributionStockListInfo.setPackageCode(distributionParcelListEntity.getOrderPackageCode()); + distributionStockListInfo.setDespatch(distributionParcelListEntity.getWaybillNumber()); + infoEntities.add(distributionStockListInfo); + } -// distributionStockListEntity.setCargoUnit(Optional.ofNullable(distributionParcelList.getMaterialUnit()).orElse(null));//单位 - distributionStockListInfo.setStoreId(distributionStockListEntity.getStoreId());//门店ID - distributionStockListInfo.setMarketCode(distributionStockListEntity.getMarketCode());//商场编码 - distributionStockListInfo.setMarketName(distributionStockListEntity.getMarketName());//商场名称 - distributionStockListInfo.setStoreCode(distributionStockListEntity.getStoreCode());//门店编码 - distributionStockListInfo.setStoreName(distributionStockListEntity.getStoreName());//门店名称 + }); -// distributionStockListEntity.setCategory(Optional.ofNullable(distributionParcelList.getBrandId()+"").orElse(null));//品分类 - // 品牌 - distributionStockListInfo.setBrandId(distributionStockListEntity.getBrandId()); - distributionStockListInfo.setBrandName(distributionStockListEntity.getBrandName()); - distributionStockListInfo.setUnpackingQuantity(0); - distributionStockListInfo.setSourceType("1"); //类型 - - distributionStockListInfo.setSku(distributionStockListEntity.getSku()); - distributionStockListInfo.setMaterialId(distributionStockListEntity.getMaterialId());//货物ID -// distributionStockListEntity.setParcelListId(distributionParcelListEntities.getId());//包件id - distributionStockListInfo.setQuantityOccupied(0);//冻结数量 - distributionStockListInfo.setServiceType(distributionStockListEntity.getServiceType());//冻结数 - - //需要包件维度的详情 - WarehouseUpdownGoodsEntity warehouseUpdownGoodsEntity = new WarehouseUpdownGoodsEntity(); - warehouseUpdownGoodsEntity.setWarehouseId(myCurrentWarehouse.getId()); - warehouseUpdownGoodsEntity.setAssociationType("3"); - warehouseUpdownGoodsEntity.setAssociationValue(distributionParcelListEntity.getOrderPackageCode()); - WarehouseUpdownGoodsEntity locationInformation = warehouseUpdownGoodsClient.getLocationInformation(warehouseUpdownGoodsEntity); - if (Func.isNotEmpty(locationInformation)) { -// distributionStockListInfo.setTrayName(locationInformation.get); - distributionStockListInfo.setStorageLocation(locationInformation.getAllocationTitle()); - } - distributionStockListInfo.setFactory(distributionStockArticleEntity.getFactoryTrain()); - distributionStockListInfo.setDespatch(distributionStockArticleEntity.getTrainNumber()); - distributionStockListInfo.setStockArticleId(distributionStockArticleEntity.getId()); - distributionStockListInfo.setOrderCode(distributionStockArticleEntity.getOrderCode()); - distributionStockListInfo.setParcelListId(distributionParcelListEntity.getId()); - distributionStockListInfo.setPackageCode(distributionParcelListEntity.getOrderPackageCode()); - distributionStockListInfo.setDespatch(distributionParcelListEntity.getWaybillNumber()); - infoEntities.add(distributionStockListInfo); } - distributionStockListInfoService.saveBatch(infoEntities); + if (!infoEntities.isEmpty()) { + distributionStockListInfoService.saveBatch(infoEntities); + } return distributionStockArticleEntity; }