From c03e6e29b96ce02f5de0e4d4a01e25a026cee28f Mon Sep 17 00:00:00 2001 From: chengzhaofeng Date: Fri, 20 Dec 2024 10:02:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=9B=98=E7=82=B9=E5=8D=95=E5=88=9B?= =?UTF-8?q?=E5=BB=BA)=EF=BC=9A=E4=BF=AE=E6=94=B9=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=80=BB=E8=BE=911.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ZWmsInventoryCheckSnapshotServiceImpl.java | 211 +++++++++++++----- 1 file changed, 151 insertions(+), 60 deletions(-) diff --git a/mom-wms-core/src/main/java/com/foreverwin/mom/wms/service/impl/ZWmsInventoryCheckSnapshotServiceImpl.java b/mom-wms-core/src/main/java/com/foreverwin/mom/wms/service/impl/ZWmsInventoryCheckSnapshotServiceImpl.java index 05894ca..d0a3ec6 100644 --- a/mom-wms-core/src/main/java/com/foreverwin/mom/wms/service/impl/ZWmsInventoryCheckSnapshotServiceImpl.java +++ b/mom-wms-core/src/main/java/com/foreverwin/mom/wms/service/impl/ZWmsInventoryCheckSnapshotServiceImpl.java @@ -2,6 +2,7 @@ package com.foreverwin.mom.wms.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -40,6 +41,7 @@ import java.util.stream.Collectors; public class ZWmsInventoryCheckSnapshotServiceImpl extends ServiceImpl implements ZWmsInventoryCheckSnapshotService { private final ZWmsInventoryCheckCountService zWmsInventoryCheckCountService; + private final WmsItemService wmsItemService; @Override @@ -82,82 +84,98 @@ public class ZWmsInventoryCheckSnapshotServiceImpl extends ServiceImpl zWmsInventoryCheckSnapshotList = this.list( - Wrappers.lambdaQuery() - .eq(ZWmsInventoryCheckSnapshot::getSite, tenantId) + Wrappers.lambdaQuery().eq(ZWmsInventoryCheckSnapshot::getSite, tenantId) .eq(ZWmsInventoryCheckSnapshot::getCheckNo, checkNo)); - + List snapshotInventoryIds = zWmsInventoryCheckSnapshotList.stream().map( + ZWmsInventoryCheckSnapshot::getInventoryId).collect(Collectors.toList()); // 获取盘点列表 List zWmsInventoryCheckCountList = zWmsInventoryCheckCountService.list( - Wrappers.lambdaQuery() - .eq(ZWmsInventoryCheckCount::getSite, tenantId) + Wrappers.lambdaQuery().eq(ZWmsInventoryCheckCount::getSite, tenantId) .eq(ZWmsInventoryCheckCount::getCheckNo, checkNo)); + List countInventoryIds = zWmsInventoryCheckCountList.stream().map( + ZWmsInventoryCheckCount::getInventoryId).collect(Collectors.toList()); - List result = new ArrayList<>(); - // 1、有快照数据 - if (CollectionUtils.isNotEmpty(zWmsInventoryCheckSnapshotList)) { - List notifySnapshotList = new ArrayList<>(); - // 判断是否有盘点数据 - for (ZWmsInventoryCheckSnapshot wmsInventoryCheckSnapshot : zWmsInventoryCheckSnapshotList) { - if (CollectionUtil.isNotEmpty(zWmsInventoryCheckCountList)) { - for (ZWmsInventoryCheckCount zWmsInventoryCheckCount : zWmsInventoryCheckCountList) { - if (Objects.equals(zWmsInventoryCheckCount.getInventoryId(), wmsInventoryCheckSnapshot.getInventoryId())) { - // 快照 - String wmsStorageBin = wmsInventoryCheckSnapshot.getWmsStorageBin(); - BigDecimal qtyOnHand = wmsInventoryCheckSnapshot.getQtyOnHand(); - // 盘点 - String wmsStorageBinA = zWmsInventoryCheckCount.getWmsStorageBin(); - BigDecimal qtyOnHandA = zWmsInventoryCheckCount.getQtyOnHand(); - wmsInventoryCheckSnapshot.setWmsStorageBinActual(wmsStorageBinA); - wmsInventoryCheckSnapshot.setQtyOnHandActual(qtyOnHandA); - wmsInventoryCheckSnapshot.setDifferenceType("5"); - if (!Objects.equals(wmsStorageBin, wmsStorageBinA)) { - // 货格不一致 - wmsInventoryCheckSnapshot.setDifferenceType("4"); - } - if (!Objects.equals(qtyOnHand, qtyOnHandA)) { - // 数量不一致 - wmsInventoryCheckSnapshot.setDifferenceType("1"); - } - result.add(wmsInventoryCheckSnapshot); - } else { - // 判断一下,是否存在,并且不在盘点列表中 - if (!notifySnapshotList.contains(wmsInventoryCheckSnapshot) && - !zWmsInventoryCheckCountList.stream().map(ZWmsInventoryCheckCount::getInventoryId).collect(Collectors.toList()).contains(wmsInventoryCheckSnapshot.getInventoryId())) { - notifySnapshotList.add(wmsInventoryCheckSnapshot); - } - } - } - - }else { - // 不存在于盘点中,但在快照中 - wmsInventoryCheckSnapshot.setDifferenceType("3"); - result.add(wmsInventoryCheckSnapshot); - } - } + // 获取snapshotInventoryIds与countInventoryIds的并集,并去重 + List union = (ArrayList) CollectionUtil.union(snapshotInventoryIds, countInventoryIds); + + List result1 = new ArrayList<>(); + List result2 = new ArrayList<>(); + List result3 = new ArrayList<>(); + List result4 = new ArrayList<>(); + List result5 = new ArrayList<>(); + + for (String inventoryId : union) { - if (!notifySnapshotList.isEmpty()) { - for (ZWmsInventoryCheckSnapshot wmsInventoryCheckSnapshot2 : notifySnapshotList) { - // 不存在于快照中 - wmsInventoryCheckSnapshot2.setDifferenceType("3"); - result.add(wmsInventoryCheckSnapshot2); - } - } + boolean contains_S = snapshotInventoryIds.contains(inventoryId); + boolean contains_C = countInventoryIds.contains(inventoryId); - } else { - // 直接不存在于快照中 - for (ZWmsInventoryCheckCount zWmsInventoryCheckCount : zWmsInventoryCheckCountList) { + if (!contains_S && contains_C) { ZWmsInventoryCheckSnapshot zWmsInventoryCheckSnapshotAdd = new ZWmsInventoryCheckSnapshot(); - BeanUtil.copyProperties(zWmsInventoryCheckCount, zWmsInventoryCheckSnapshotAdd, "handle", "dateUpdate", "updater", "dateCreate", "creator"); + ZWmsInventoryCheckCount zWmsInventoryCheckCount = zWmsInventoryCheckCountList.stream().filter( + o -> o.getInventoryId().equals(inventoryId)).findFirst().orElse(null); + BeanUtil.copyProperties(zWmsInventoryCheckCount, zWmsInventoryCheckSnapshotAdd, "handle", "dateUpdate", + "updater", "dateCreate", "creator"); zWmsInventoryCheckSnapshotAdd.setCreator(SecurityUtils.getUserName()); zWmsInventoryCheckSnapshotAdd.setDateCreate(LocalDateTime.now()); zWmsInventoryCheckSnapshotAdd.setWmsStorageBinActual(zWmsInventoryCheckSnapshotAdd.getWmsStorageBin()); zWmsInventoryCheckSnapshotAdd.setQtyOnHandActual(zWmsInventoryCheckSnapshotAdd.getQtyOnHand()); zWmsInventoryCheckSnapshotAdd.setDifferenceType("2"); - result.add(zWmsInventoryCheckSnapshotAdd); + result2.add(zWmsInventoryCheckSnapshotAdd); + } + + if (contains_S && contains_C) { + ZWmsInventoryCheckCount zWmsInventoryCheckCount = zWmsInventoryCheckCountList.stream().filter( + o -> o.getInventoryId().equals(inventoryId)).findFirst().orElse(null); + + ZWmsInventoryCheckSnapshot zWmsInventoryCheckSnapshotAdd = zWmsInventoryCheckSnapshotList.stream().filter( + o -> o.getInventoryId().equals(inventoryId)).findFirst().orElse(null); + + // 快照 + String wmsStorageBin = zWmsInventoryCheckSnapshotAdd.getWmsStorageBin(); + BigDecimal qtyOnHand = zWmsInventoryCheckSnapshotAdd.getQtyOnHand(); + // 盘点 + String wmsStorageBinA = zWmsInventoryCheckCount.getWmsStorageBin(); + BigDecimal qtyOnHandA = zWmsInventoryCheckCount.getQtyOnHand(); + zWmsInventoryCheckSnapshotAdd.setWmsStorageBinActual(wmsStorageBinA); + zWmsInventoryCheckSnapshotAdd.setQtyOnHandActual(qtyOnHandA); + zWmsInventoryCheckSnapshotAdd.setDifferenceType("5"); + result5.add(zWmsInventoryCheckSnapshotAdd); + if (!Objects.equals(wmsStorageBin, wmsStorageBinA)) { + // 货格不一致 + zWmsInventoryCheckSnapshotAdd.setDifferenceType("4"); + result4.add(zWmsInventoryCheckSnapshotAdd); + } + if (!Objects.equals(qtyOnHand, qtyOnHandA)) { + // 数量不一致 + zWmsInventoryCheckSnapshotAdd.setDifferenceType("1"); + result1.add(zWmsInventoryCheckSnapshotAdd); + } + } + + if (contains_S && !contains_C) { + ZWmsInventoryCheckSnapshot zWmsInventoryCheckSnapshotAdd = zWmsInventoryCheckSnapshotList.stream().filter( + o -> o.getInventoryId().equals(inventoryId)).findFirst().orElse(null); + + zWmsInventoryCheckSnapshotAdd.setDifferenceType("3"); + result3.add(zWmsInventoryCheckSnapshotAdd); } } - // 查询物料描述 + // 将5个合并为result + List result = new ArrayList<>(); + result.addAll(result1); + result.addAll(result2); + result.addAll(result3); + result.addAll(result4); + result.addAll(result5); + + // 判断是否有条件 + if (StrUtil.isNotBlank(zWmsInventoryCheckSnapshot.getDifferenceType())) { + result = result.stream().filter( + o -> o.getDifferenceType().equals(zWmsInventoryCheckSnapshot.getDifferenceType())).collect( + Collectors.toList()); + } + result.forEach(item -> { Item item1 = wmsItemService.selectCurrentByMes(tenantId, item.getItem()); if (item1 != null) { @@ -168,5 +186,78 @@ public class ZWmsInventoryCheckSnapshotServiceImpl extends ServiceImpl result = new ArrayList<>(); + // // 1、有快照数据 + // if (CollectionUtils.isNotEmpty(zWmsInventoryCheckSnapshotList)) { + // List notifySnapshotList = new ArrayList<>(); + // // 判断是否有盘点数据 + // for (ZWmsInventoryCheckSnapshot wmsInventoryCheckSnapshot : zWmsInventoryCheckSnapshotList) { + // if (CollectionUtil.isNotEmpty(zWmsInventoryCheckCountList)) { + // for (ZWmsInventoryCheckCount zWmsInventoryCheckCount : zWmsInventoryCheckCountList) { + // if (Objects.equals(zWmsInventoryCheckCount.getInventoryId(), + // wmsInventoryCheckSnapshot.getInventoryId())) { + // // 快照 + // String wmsStorageBin = wmsInventoryCheckSnapshot.getWmsStorageBin(); + // BigDecimal qtyOnHand = wmsInventoryCheckSnapshot.getQtyOnHand(); + // // 盘点 + // String wmsStorageBinA = zWmsInventoryCheckCount.getWmsStorageBin(); + // BigDecimal qtyOnHandA = zWmsInventoryCheckCount.getQtyOnHand(); + // wmsInventoryCheckSnapshot.setWmsStorageBinActual(wmsStorageBinA); + // wmsInventoryCheckSnapshot.setQtyOnHandActual(qtyOnHandA); + // wmsInventoryCheckSnapshot.setDifferenceType("5"); + // if (!Objects.equals(wmsStorageBin, wmsStorageBinA)) { + // // 货格不一致 + // wmsInventoryCheckSnapshot.setDifferenceType("4"); + // } + // if (!Objects.equals(qtyOnHand, qtyOnHandA)) { + // // 数量不一致 + // wmsInventoryCheckSnapshot.setDifferenceType("1"); + // } + // result.add(wmsInventoryCheckSnapshot); + // } else { + // // 判断一下,是否存在,并且不在盘点列表中 + // if (!notifySnapshotList.contains(wmsInventoryCheckSnapshot) + // && !zWmsInventoryCheckCountList.stream().map( + // ZWmsInventoryCheckCount::getInventoryId).collect(Collectors.toList()).contains( + // wmsInventoryCheckSnapshot.getInventoryId())) { + // notifySnapshotList.add(wmsInventoryCheckSnapshot); + // } + // } + // } + // + // } else { + // // 不存在于盘点中,但在快照中 + // wmsInventoryCheckSnapshot.setDifferenceType("3"); + // result.add(wmsInventoryCheckSnapshot); + // } + // } + // + // if (!notifySnapshotList.isEmpty()) { + // for (ZWmsInventoryCheckSnapshot wmsInventoryCheckSnapshot2 : notifySnapshotList) { + // // 不存在于快照中 + // wmsInventoryCheckSnapshot2.setDifferenceType("3"); + // result.add(wmsInventoryCheckSnapshot2); + // } + // } + // + // } else { + // // 直接不存在于快照中 + // for (ZWmsInventoryCheckCount zWmsInventoryCheckCount : zWmsInventoryCheckCountList) { + // ZWmsInventoryCheckSnapshot zWmsInventoryCheckSnapshotAdd = new ZWmsInventoryCheckSnapshot(); + // BeanUtil.copyProperties(zWmsInventoryCheckCount, zWmsInventoryCheckSnapshotAdd, "handle", "dateUpdate", + // "updater", "dateCreate", "creator"); + // zWmsInventoryCheckSnapshotAdd.setCreator(SecurityUtils.getUserName()); + // zWmsInventoryCheckSnapshotAdd.setDateCreate(LocalDateTime.now()); + // zWmsInventoryCheckSnapshotAdd.setWmsStorageBinActual(zWmsInventoryCheckSnapshotAdd.getWmsStorageBin()); + // zWmsInventoryCheckSnapshotAdd.setQtyOnHandActual(zWmsInventoryCheckSnapshotAdd.getQtyOnHand()); + // zWmsInventoryCheckSnapshotAdd.setDifferenceType("2"); + // result.add(zWmsInventoryCheckSnapshotAdd); + // } + // } + + // 查询物料描述 + } }