|
|
@ -57,7 +57,12 @@ public class InventoryDiscrepancyServiceImpl implements InventoryDiscrepancyServ |
|
|
List<PalletDetailData> wmsDetailList = wcsIntegrationMapper.getPalletDetailsData( |
|
|
List<PalletDetailData> wmsDetailList = wcsIntegrationMapper.getPalletDetailsData( |
|
|
callback.getSite(), callback.getPalletId()); |
|
|
callback.getSite(), callback.getPalletId()); |
|
|
|
|
|
|
|
|
// 3. 解析WCS扫描的条码列表 - rqrq |
|
|
|
|
|
|
|
|
// 3. 提取WMS所有条码 - rqrq |
|
|
|
|
|
List<String> wmsBarcodeList = wmsDetailList.stream() |
|
|
|
|
|
.map(PalletDetailData::getSerialNo) |
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
// 4. 解析WCS扫描的条码列表 - rqrq |
|
|
List<String> wcsBarcodeList = new ArrayList<>(); |
|
|
List<String> wcsBarcodeList = new ArrayList<>(); |
|
|
if (callback.getWcsBarcodeList() != null && !callback.getWcsBarcodeList().isEmpty()) { |
|
|
if (callback.getWcsBarcodeList() != null && !callback.getWcsBarcodeList().isEmpty()) { |
|
|
try { |
|
|
try { |
|
|
@ -70,74 +75,58 @@ public class InventoryDiscrepancyServiceImpl implements InventoryDiscrepancyServ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 4. 按物料分组对比 - rqrq |
|
|
|
|
|
Map<String, List<String>> wmsPartBarcodes = wmsDetailList.stream() |
|
|
|
|
|
.collect(Collectors.groupingBy( |
|
|
|
|
|
PalletDetailData::getPartNo, |
|
|
|
|
|
Collectors.mapping(PalletDetailData::getSerialNo, Collectors.toList()) |
|
|
|
|
|
)); |
|
|
|
|
|
|
|
|
// 5. 对比整个栈板的差异(不按物料分组)- rqrq |
|
|
|
|
|
Set<String> wmsSet = new HashSet<>(wmsBarcodeList); |
|
|
|
|
|
Set<String> wcsSet = new HashSet<>(wcsBarcodeList); |
|
|
|
|
|
|
|
|
// WCS按物料分组(需要从handlingUnit表查询serialNo对应的partNo)- rqrq |
|
|
|
|
|
Map<String, List<String>> wcsPartBarcodes = groupWcsBarcodesByPartNo(callback.getSite(), wcsBarcodeList); |
|
|
|
|
|
|
|
|
// WMS有但WCS没有的条码 - rqrq |
|
|
|
|
|
Set<String> missingBarcodes = new HashSet<>(wmsSet); |
|
|
|
|
|
missingBarcodes.removeAll(wcsSet); |
|
|
|
|
|
|
|
|
// 5. 对比并生成差异记录 - rqrq |
|
|
|
|
|
List<WmsWcsInventoryDiscrepancy> discrepancyList = new ArrayList<>(); |
|
|
|
|
|
Set<String> allPartNos = new HashSet<>(); |
|
|
|
|
|
allPartNos.addAll(wmsPartBarcodes.keySet()); |
|
|
|
|
|
allPartNos.addAll(wcsPartBarcodes.keySet()); |
|
|
|
|
|
|
|
|
// WCS有但WMS没有的条码 - rqrq |
|
|
|
|
|
Set<String> extraBarcodes = new HashSet<>(wcsSet); |
|
|
|
|
|
extraBarcodes.removeAll(wmsSet); |
|
|
|
|
|
|
|
|
for (String partNo : allPartNos) { |
|
|
|
|
|
List<String> wmsBarcodes = wmsPartBarcodes.getOrDefault(partNo, new ArrayList<>()); |
|
|
|
|
|
List<String> wcsBarcodes = wcsPartBarcodes.getOrDefault(partNo, new ArrayList<>()); |
|
|
|
|
|
|
|
|
|
|
|
// 计算差异 - rqrq |
|
|
|
|
|
Set<String> wmsSet = new HashSet<>(wmsBarcodes); |
|
|
|
|
|
Set<String> wcsSet = new HashSet<>(wcsBarcodes); |
|
|
|
|
|
|
|
|
|
|
|
// WMS有但WCS没有的条码 - rqrq |
|
|
|
|
|
Set<String> missingBarcodes = new HashSet<>(wmsSet); |
|
|
|
|
|
missingBarcodes.removeAll(wcsSet); |
|
|
|
|
|
|
|
|
|
|
|
// WCS有但WMS没有的条码 - rqrq |
|
|
|
|
|
Set<String> extraBarcodes = new HashSet<>(wcsSet); |
|
|
|
|
|
extraBarcodes.removeAll(wmsSet); |
|
|
|
|
|
|
|
|
|
|
|
// 如果有差异,生成记录 - rqrq |
|
|
|
|
|
if (!missingBarcodes.isEmpty() || !extraBarcodes.isEmpty()) { |
|
|
|
|
|
WmsWcsInventoryDiscrepancy discrepancy = new WmsWcsInventoryDiscrepancy(); |
|
|
|
|
|
discrepancy.setSite(callback.getSite()); |
|
|
|
|
|
discrepancy.setCallbackId(callback.getId()); |
|
|
|
|
|
discrepancy.setPalletId(callback.getPalletId()); |
|
|
|
|
|
discrepancy.setTaskNo(callback.getTaskNo()); |
|
|
|
|
|
discrepancy.setItemNo(callback.getItemNo()); |
|
|
|
|
|
discrepancy.setOperationType("picking"); |
|
|
|
|
|
discrepancy.setOperationTime(callback.getWcsScanTime()); |
|
|
|
|
|
discrepancy.setPartNo(partNo); |
|
|
|
|
|
|
|
|
|
|
|
discrepancy.setWmsTotalQuantity(wmsBarcodes.size()); |
|
|
|
|
|
discrepancy.setWcsTotalQuantity(wcsBarcodes.size()); |
|
|
|
|
|
|
|
|
|
|
|
discrepancy.setWmsBarcodeList(JSONObject.toJSONString(wmsBarcodes)); |
|
|
|
|
|
discrepancy.setWcsBarcodeList(JSONObject.toJSONString(wcsBarcodes)); |
|
|
|
|
|
discrepancy.setWmsMissingBarcodes(JSONObject.toJSONString(new ArrayList<>(missingBarcodes))); |
|
|
|
|
|
discrepancy.setWcsExtraBarcodes(JSONObject.toJSONString(new ArrayList<>(extraBarcodes))); |
|
|
|
|
|
|
|
|
|
|
|
discrepancy.setStatus(0); // 待处理 - rqrq |
|
|
|
|
|
discrepancy.setRemark("系统自动对账生成"); |
|
|
|
|
|
|
|
|
|
|
|
discrepancyList.add(discrepancy); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 6. 生成一条差异记录(无论是否有差异都记录,便于追踪)- rqrq |
|
|
|
|
|
WmsWcsInventoryDiscrepancy discrepancy = new WmsWcsInventoryDiscrepancy(); |
|
|
|
|
|
discrepancy.setSite(callback.getSite()); |
|
|
|
|
|
discrepancy.setCallbackId(callback.getId()); |
|
|
|
|
|
discrepancy.setPalletId(callback.getPalletId()); |
|
|
|
|
|
discrepancy.setTaskNo(callback.getTaskNo()); |
|
|
|
|
|
discrepancy.setItemNo(callback.getItemNo()); |
|
|
|
|
|
discrepancy.setOperationType("picking"); |
|
|
|
|
|
discrepancy.setOperationTime(callback.getWcsScanTime()); |
|
|
|
|
|
discrepancy.setPartNo(""); // 不再按物料分组,留空 - rqrq |
|
|
|
|
|
|
|
|
|
|
|
discrepancy.setWmsTotalQuantity(wmsBarcodeList.size()); |
|
|
|
|
|
discrepancy.setWcsTotalQuantity(wcsBarcodeList.size()); |
|
|
|
|
|
|
|
|
|
|
|
discrepancy.setWmsBarcodeList(JSONObject.toJSONString(wmsBarcodeList)); |
|
|
|
|
|
discrepancy.setWcsBarcodeList(JSONObject.toJSONString(wcsBarcodeList)); |
|
|
|
|
|
discrepancy.setWmsMissingBarcodes(JSONObject.toJSONString(new ArrayList<>(missingBarcodes))); |
|
|
|
|
|
discrepancy.setWcsExtraBarcodes(JSONObject.toJSONString(new ArrayList<>(extraBarcodes))); |
|
|
|
|
|
|
|
|
// 6. 批量插入差异记录 - rqrq |
|
|
|
|
|
if (!discrepancyList.isEmpty()) { |
|
|
|
|
|
wmsWcsInventoryDiscrepancyMapper.batchInsert(discrepancyList); |
|
|
|
|
|
System.out.println("生成库存差异记录 - rqrq,数量=" + discrepancyList.size()); |
|
|
|
|
|
|
|
|
// 如果有差异,标记为待处理;无差异,标记为已处理 - rqrq |
|
|
|
|
|
if (!missingBarcodes.isEmpty() || !extraBarcodes.isEmpty()) { |
|
|
|
|
|
discrepancy.setStatus(0); // 待处理 - rqrq |
|
|
|
|
|
discrepancy.setRemark("系统自动对账生成 - 发现差异"); |
|
|
} else { |
|
|
} else { |
|
|
System.out.println("对账完成,无差异记录 - rqrq"); |
|
|
|
|
|
|
|
|
discrepancy.setStatus(2); // 已处理(无差异)- rqrq |
|
|
|
|
|
discrepancy.setRemark("系统自动对账生成 - 无差异"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 7. 更新回调记录状态为已完成 - rqrq |
|
|
|
|
|
|
|
|
// 7. 插入差异记录(改为单条插入)- rqrq |
|
|
|
|
|
List<WmsWcsInventoryDiscrepancy> discrepancyList = new ArrayList<>(); |
|
|
|
|
|
discrepancyList.add(discrepancy); |
|
|
|
|
|
wmsWcsInventoryDiscrepancyMapper.batchInsert(discrepancyList); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("生成库存差异记录 - rqrq,栈板=" + callback.getPalletId() |
|
|
|
|
|
+ ",WMS条码数=" + wmsBarcodeList.size() |
|
|
|
|
|
+ ",WCS条码数=" + wcsBarcodeList.size() |
|
|
|
|
|
+ ",缺失=" + missingBarcodes.size() |
|
|
|
|
|
+ ",多余=" + extraBarcodes.size()); |
|
|
|
|
|
|
|
|
|
|
|
// 8. 更新回调记录状态为已完成 - rqrq |
|
|
wcsCallbackPalletScanMapper.updateProcessStatus(callback.getId(), "COMPLETED", null); |
|
|
wcsCallbackPalletScanMapper.updateProcessStatus(callback.getId(), "COMPLETED", null); |
|
|
|
|
|
|
|
|
System.out.println("WCS回调扫描记录对账完成 - rqrq,palletId=" + callback.getPalletId() |
|
|
System.out.println("WCS回调扫描记录对账完成 - rqrq,palletId=" + callback.getPalletId() |
|
|
@ -157,34 +146,6 @@ public class InventoryDiscrepancyServiceImpl implements InventoryDiscrepancyServ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @Description 将WCS条码按物料分组 - rqrq |
|
|
|
|
|
* @Title groupWcsBarcodesByPartNo |
|
|
|
|
|
* @param site 工厂编码 |
|
|
|
|
|
* @param wcsBarcodeList WCS条码列表 |
|
|
|
|
|
* @return Map<String, List<String>> |
|
|
|
|
|
* @author rqrq |
|
|
|
|
|
* @date 2025/10/07 |
|
|
|
|
|
*/ |
|
|
|
|
|
private Map<String, List<String>> groupWcsBarcodesByPartNo(String site, List<String> wcsBarcodeList) { |
|
|
|
|
|
Map<String, List<String>> result = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
for (String serialNo : wcsBarcodeList) { |
|
|
|
|
|
try { |
|
|
|
|
|
// 从handlingUnit表查询serialNo对应的partNo - rqrq |
|
|
|
|
|
Map<String, Object> labelInfo = wcsIntegrationMapper.validateLabel(site, serialNo); |
|
|
|
|
|
if (labelInfo != null && labelInfo.get("part_no") != null) { |
|
|
|
|
|
String partNo = (String) labelInfo.get("part_no"); |
|
|
|
|
|
result.computeIfAbsent(partNo, k -> new ArrayList<>()).add(serialNo); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
System.err.println("查询条码对应物料失败 - rqrq,serialNo=" + serialNo + ",错误:" + e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @Description 分页查询库存差异记录 - rqrq |
|
|
* @Description 分页查询库存差异记录 - rqrq |
|
|
* @Title queryPage |
|
|
* @Title queryPage |
|
|
@ -215,11 +176,6 @@ public class InventoryDiscrepancyServiceImpl implements InventoryDiscrepancyServ |
|
|
wrapper.like("task_no", data.getTaskNo()); |
|
|
wrapper.like("task_no", data.getTaskNo()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 物料编号条件 - rqrq |
|
|
|
|
|
if (StringUtils.hasText(data.getPartNo())) { |
|
|
|
|
|
wrapper.like("part_no", data.getPartNo()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 状态条件 - rqrq |
|
|
// 状态条件 - rqrq |
|
|
if (data.getStatus() != null) { |
|
|
if (data.getStatus() != null) { |
|
|
wrapper.eq("status", data.getStatus()); |
|
|
wrapper.eq("status", data.getStatus()); |
|
|
|