feat(盘点单创建):修改查询逻辑1.1

This commit is contained in:
chengzhaofeng 2024-12-20 10:02:41 +08:00
parent 159488e871
commit c03e6e29b9

View File

@ -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<ZWmsInventoryCheckSnapshotMapper, ZWmsInventoryCheckSnapshot> implements ZWmsInventoryCheckSnapshotService {
private final ZWmsInventoryCheckCountService zWmsInventoryCheckCountService;
private final WmsItemService wmsItemService;
@Override
@ -82,82 +84,98 @@ public class ZWmsInventoryCheckSnapshotServiceImpl extends ServiceImpl<ZWmsInven
String tenantId = TenantContextHolder.getTenantId();
// 获取快照列表
List<ZWmsInventoryCheckSnapshot> zWmsInventoryCheckSnapshotList = this.list(
Wrappers.<ZWmsInventoryCheckSnapshot>lambdaQuery()
.eq(ZWmsInventoryCheckSnapshot::getSite, tenantId)
Wrappers.<ZWmsInventoryCheckSnapshot>lambdaQuery().eq(ZWmsInventoryCheckSnapshot::getSite, tenantId)
.eq(ZWmsInventoryCheckSnapshot::getCheckNo, checkNo));
List<String> snapshotInventoryIds = zWmsInventoryCheckSnapshotList.stream().map(
ZWmsInventoryCheckSnapshot::getInventoryId).collect(Collectors.toList());
// 获取盘点列表
List<ZWmsInventoryCheckCount> zWmsInventoryCheckCountList = zWmsInventoryCheckCountService.list(
Wrappers.<ZWmsInventoryCheckCount>lambdaQuery()
.eq(ZWmsInventoryCheckCount::getSite, tenantId)
Wrappers.<ZWmsInventoryCheckCount>lambdaQuery().eq(ZWmsInventoryCheckCount::getSite, tenantId)
.eq(ZWmsInventoryCheckCount::getCheckNo, checkNo));
List<String> countInventoryIds = zWmsInventoryCheckCountList.stream().map(
ZWmsInventoryCheckCount::getInventoryId).collect(Collectors.toList());
List<ZWmsInventoryCheckSnapshot> result = new ArrayList<>();
// 1、有快照数据
if (CollectionUtils.isNotEmpty(zWmsInventoryCheckSnapshotList)) {
List<ZWmsInventoryCheckSnapshot> 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<String> union = (ArrayList<String>) CollectionUtil.union(snapshotInventoryIds, countInventoryIds);
List<ZWmsInventoryCheckSnapshot> result1 = new ArrayList<>();
List<ZWmsInventoryCheckSnapshot> result2 = new ArrayList<>();
List<ZWmsInventoryCheckSnapshot> result3 = new ArrayList<>();
List<ZWmsInventoryCheckSnapshot> result4 = new ArrayList<>();
List<ZWmsInventoryCheckSnapshot> 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<ZWmsInventoryCheckSnapshot> 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<ZWmsInven
// result根据inventoryId排序
result.sort(Comparator.comparing(ZWmsInventoryCheckSnapshot::getInventoryId));
return result;
//
// List<ZWmsInventoryCheckSnapshot> result = new ArrayList<>();
// // 1、有快照数据
// if (CollectionUtils.isNotEmpty(zWmsInventoryCheckSnapshotList)) {
// List<ZWmsInventoryCheckSnapshot> 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);
// }
// }
// 查询物料描述
}
}