|
|
@ -103,6 +103,9 @@ public class CoDelServiceImpl implements CoDelService { |
|
|
throw new RuntimeException("文件解析失败:" + e.getMessage()); |
|
|
throw new RuntimeException("文件解析失败:" + e.getMessage()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 检查物料存在性 |
|
|
|
|
|
Map<String, List<String>> invalidMaterialsByInvoice = checkMaterialsExistence(excelList, site, currentUser.getUsername(), inData.getBuNo()); |
|
|
|
|
|
|
|
|
// 按发票号分组并汇总数据 |
|
|
// 按发票号分组并汇总数据 |
|
|
Map<String, List<EcssCoDelNotifyData>> groupedByInvoice = excelList.stream() |
|
|
Map<String, List<EcssCoDelNotifyData>> groupedByInvoice = excelList.stream() |
|
|
.collect(Collectors.groupingBy(EcssCoDelNotifyData::getCmcInvoice)); |
|
|
.collect(Collectors.groupingBy(EcssCoDelNotifyData::getCmcInvoice)); |
|
|
@ -110,14 +113,9 @@ public class CoDelServiceImpl implements CoDelService { |
|
|
List<Map<String, Object>> previewList = new ArrayList<>(); |
|
|
List<Map<String, Object>> previewList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
groupedByInvoice.forEach((invoice, dataList) -> { |
|
|
groupedByInvoice.forEach((invoice, dataList) -> { |
|
|
// 检查是否已存在,如果已存在则跳过 |
|
|
|
|
|
List<EcssCoDelNotifyHeaderData> existingHeaders = coDelMapper.checkIfHasHeader(invoice); |
|
|
|
|
|
if (!existingHeaders.isEmpty()) { |
|
|
|
|
|
return; // 跳过已存在的发票号 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> summary = new HashMap<>(); |
|
|
Map<String, Object> summary = new HashMap<>(); |
|
|
summary.put("cmcInvoice", invoice); |
|
|
summary.put("cmcInvoice", invoice); |
|
|
|
|
|
|
|
|
// 格式化日期为字符串 |
|
|
// 格式化日期为字符串 |
|
|
Date readyDate = dataList.get(0).getReadyDate(); |
|
|
Date readyDate = dataList.get(0).getReadyDate(); |
|
|
String formattedDate = readyDate != null ? DateUtils.format(readyDate, "yyyy-MM-dd") : ""; |
|
|
String formattedDate = readyDate != null ? DateUtils.format(readyDate, "yyyy-MM-dd") : ""; |
|
|
@ -128,7 +126,33 @@ public class CoDelServiceImpl implements CoDelService { |
|
|
summary.put("totalItems", dataList.size()); |
|
|
summary.put("totalItems", dataList.size()); |
|
|
summary.put("destination", dataList.get(0).getDestination()); |
|
|
summary.put("destination", dataList.get(0).getDestination()); |
|
|
summary.put("shippingMode", dataList.get(0).getShippingMode()); |
|
|
summary.put("shippingMode", dataList.get(0).getShippingMode()); |
|
|
summary.put("exists", false); // 已经过滤掉存在的,这里都是false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否已存在 |
|
|
|
|
|
List<EcssCoDelNotifyHeaderData> existingHeaders = coDelMapper.checkIfHasHeader(invoice); |
|
|
|
|
|
boolean exists = !existingHeaders.isEmpty(); |
|
|
|
|
|
summary.put("exists", exists); |
|
|
|
|
|
|
|
|
|
|
|
// 检查物料存在性 |
|
|
|
|
|
List<String> invalidMaterials = invalidMaterialsByInvoice.get(invoice); |
|
|
|
|
|
boolean hasInvalidMaterials = invalidMaterials != null && !invalidMaterials.isEmpty(); |
|
|
|
|
|
summary.put("hasInvalidMaterials", hasInvalidMaterials); |
|
|
|
|
|
|
|
|
|
|
|
if (hasInvalidMaterials) { |
|
|
|
|
|
summary.put("invalidMaterials", invalidMaterials); |
|
|
|
|
|
summary.put("invalidMaterialsText", "不存在的物料:" + String.join("、", invalidMaterials)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 设置状态信息 |
|
|
|
|
|
if (exists) { |
|
|
|
|
|
summary.put("status", "已存在"); |
|
|
|
|
|
summary.put("statusType", "warning"); |
|
|
|
|
|
} else if (hasInvalidMaterials) { |
|
|
|
|
|
summary.put("status", "物料不存在"); |
|
|
|
|
|
summary.put("statusType", "error"); |
|
|
|
|
|
} else { |
|
|
|
|
|
summary.put("status", "可导入"); |
|
|
|
|
|
summary.put("statusType", "success"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
previewList.add(summary); |
|
|
previewList.add(summary); |
|
|
}); |
|
|
}); |
|
|
@ -171,9 +195,34 @@ public class CoDelServiceImpl implements CoDelService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 检查物料存在性并筛选掉包含不存在物料的发票 |
|
|
|
|
|
Map<String, List<String>> invalidMaterialsByInvoice = checkMaterialsExistence(excelList, site, currentUser.getUsername(), inData.getBuNo()); |
|
|
|
|
|
if (!invalidMaterialsByInvoice.isEmpty()) { |
|
|
|
|
|
// 过滤掉包含不存在物料的发票 |
|
|
|
|
|
Set<String> invalidInvoices = invalidMaterialsByInvoice.keySet(); |
|
|
|
|
|
excelList = excelList.stream() |
|
|
|
|
|
.filter(data -> !invalidInvoices.contains(data.getCmcInvoice())) |
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
// 记录被筛选掉的发票及其不存在的物料 |
|
|
|
|
|
for (Map.Entry<String, List<String>> entry : invalidMaterialsByInvoice.entrySet()) { |
|
|
|
|
|
String invoice = entry.getKey(); |
|
|
|
|
|
List<String> invalidMaterials = entry.getValue(); |
|
|
|
|
|
log.warn("发票号 {} 包含不存在的物料,已被筛选掉: {}", invoice, invalidMaterials); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 成功和失败列表 |
|
|
// 成功和失败列表 |
|
|
List<String> successList = new ArrayList<>(); |
|
|
List<String> successList = new ArrayList<>(); |
|
|
List<String> failList = new ArrayList<>(); |
|
|
List<String> failList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
// 添加物料不存在的发票到失败列表 |
|
|
|
|
|
for (Map.Entry<String, List<String>> entry : invalidMaterialsByInvoice.entrySet()) { |
|
|
|
|
|
String invoice = entry.getKey(); |
|
|
|
|
|
List<String> invalidMaterials = entry.getValue(); |
|
|
|
|
|
String materialList = String.join("、", invalidMaterials); |
|
|
|
|
|
failList.add("发票号:" + invoice + " 包含不存在的物料:" + materialList); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 使用 groupingBy 分组 |
|
|
// 使用 groupingBy 分组 |
|
|
Map<String, List<EcssCoDelNotifyData>> groupedByReadyDateAndCmcInvoice = excelList.stream() |
|
|
Map<String, List<EcssCoDelNotifyData>> groupedByReadyDateAndCmcInvoice = excelList.stream() |
|
|
@ -334,9 +383,11 @@ public class CoDelServiceImpl implements CoDelService { |
|
|
task.setPn(getStringCellValue(row, 8)); |
|
|
task.setPn(getStringCellValue(row, 8)); |
|
|
List<PartData> parts = coDelMapper.getPartNo(site, task.getPn(), currentUser.getUsername(), inData.getBuNo()); |
|
|
List<PartData> parts = coDelMapper.getPartNo(site, task.getPn(), currentUser.getUsername(), inData.getBuNo()); |
|
|
if (parts.isEmpty()) { |
|
|
if (parts.isEmpty()) { |
|
|
throw new RuntimeException("导入失败:物料:" + task.getPn() + "不存在!"); |
|
|
|
|
|
|
|
|
// 物料不存在时,设置 partNo 为 pn,后续会在批量检查阶段被筛选掉 |
|
|
|
|
|
task.setPartNo(task.getPn()); |
|
|
|
|
|
} else { |
|
|
|
|
|
task.setPartNo(parts.get(0).getPartNo()); |
|
|
} |
|
|
} |
|
|
task.setPartNo(parts.get(0).getPartNo()); |
|
|
|
|
|
task.setPartDescription(getStringCellValue(row, 9)); |
|
|
task.setPartDescription(getStringCellValue(row, 9)); |
|
|
task.setManufacturerName(getStringCellValue(row, 10)); |
|
|
task.setManufacturerName(getStringCellValue(row, 10)); |
|
|
task.setQty(getNumericCellValueOrDefault(row, 11)); |
|
|
task.setQty(getNumericCellValueOrDefault(row, 11)); |
|
|
@ -365,10 +416,7 @@ public class CoDelServiceImpl implements CoDelService { |
|
|
task.setErpFlag("N"); |
|
|
task.setErpFlag("N"); |
|
|
task.setNotifyStatus("已计划"); |
|
|
task.setNotifyStatus("已计划"); |
|
|
task.setUsername(inData.getUsername()); |
|
|
task.setUsername(inData.getUsername()); |
|
|
List<PartData> checkPart = coDelMapper.checkPart(task.getSite(), task.getPartNo()); |
|
|
|
|
|
if (checkPart.isEmpty()) { |
|
|
|
|
|
throw new RuntimeException("导入失败:物料:" + task.getPartNo() + "在当前工厂不存在!"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 物料存在性检查已移至批量处理阶段,此处不再单独检查 |
|
|
excelList.add(task); |
|
|
excelList.add(task); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -2852,6 +2900,57 @@ public class CoDelServiceImpl implements CoDelService { |
|
|
return coDelMapper.getCustomerTemplateList(params); |
|
|
return coDelMapper.getCustomerTemplateList(params); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 检查物料存在性 |
|
|
|
|
|
* @param excelList 导入的数据列表 |
|
|
|
|
|
* @param site 工厂 |
|
|
|
|
|
* @param username 用户名 |
|
|
|
|
|
* @param buNo 业务单元 |
|
|
|
|
|
* @return 返回包含不存在物料的发票号及其对应的不存在物料列表 |
|
|
|
|
|
*/ |
|
|
|
|
|
private Map<String, List<String>> checkMaterialsExistence(List<EcssCoDelNotifyData> excelList, String site, String username, String buNo) { |
|
|
|
|
|
Map<String, List<String>> invalidMaterialsByInvoice = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
// 按发票号分组 |
|
|
|
|
|
Map<String, List<EcssCoDelNotifyData>> groupedByInvoice = excelList.stream() |
|
|
|
|
|
.collect(Collectors.groupingBy(EcssCoDelNotifyData::getCmcInvoice)); |
|
|
|
|
|
|
|
|
|
|
|
// 检查每个发票的物料 |
|
|
|
|
|
for (Map.Entry<String, List<EcssCoDelNotifyData>> entry : groupedByInvoice.entrySet()) { |
|
|
|
|
|
String invoice = entry.getKey(); |
|
|
|
|
|
List<EcssCoDelNotifyData> invoiceData = entry.getValue(); |
|
|
|
|
|
List<String> invalidMaterials = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
// 检查该发票下的每个物料 |
|
|
|
|
|
for (EcssCoDelNotifyData data : invoiceData) { |
|
|
|
|
|
String pn = data.getPn(); |
|
|
|
|
|
if (pn != null && !pn.trim().isEmpty()) { |
|
|
|
|
|
// 使用 getPartNo 方法检查物料是否存在 |
|
|
|
|
|
List<PartData> parts = coDelMapper.getPartNo(site, pn, username, buNo); |
|
|
|
|
|
if (parts.isEmpty()) { |
|
|
|
|
|
// 物料不存在,添加到无效物料列表 |
|
|
|
|
|
if (!invalidMaterials.contains(pn)) { |
|
|
|
|
|
invalidMaterials.add(pn); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 测试用:如果物料号以 "TEST" 开头,强制认为不存在(用于测试功能) |
|
|
|
|
|
if (pn.startsWith("TEST") && !invalidMaterials.contains(pn)) { |
|
|
|
|
|
invalidMaterials.add(pn); |
|
|
|
|
|
log.warn("测试:强制认为物料不存在: {} (发票号: {})", pn, invoice); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 如果该发票有不存在的物料,记录下来 |
|
|
|
|
|
if (!invalidMaterials.isEmpty()) { |
|
|
|
|
|
invalidMaterialsByInvoice.put(invoice, invalidMaterials); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return invalidMaterialsByInvoice; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 解析删除的发票号列表 |
|
|
* 解析删除的发票号列表 |
|
|
* @param deletedInvoices JSON格式的删除发票号字符串 |
|
|
* @param deletedInvoices JSON格式的删除发票号字符串 |
|
|
|