|
|
|
@ -1021,7 +1021,7 @@ public class IssureNotifyServiceImpl implements IssureNotifyService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<ImportPartAttrVo> uploadNoorderNotifyExcel(MultipartFile file, String site, String notifyNo) throws Exception{ |
|
|
|
public List<ShopOrderAndMaterialVo> uploadNoorderNotifyExcel(MultipartFile file, String site, String notifyNo) throws Exception{ |
|
|
|
// 校验文件格式 |
|
|
|
if (file == null || file.isEmpty()) { |
|
|
|
throw new RuntimeException("请选择要上传的文件"); |
|
|
|
@ -1044,148 +1044,49 @@ public class IssureNotifyServiceImpl implements IssureNotifyService { |
|
|
|
throw new RuntimeException("Excel文件中没有有效数据"); |
|
|
|
} |
|
|
|
|
|
|
|
// 转换为NotifyExcelData列表 |
|
|
|
List<NotifyExcelData> notifyExcelDataList = new ArrayList<>(); |
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
// 转换为ImportPartAttrVo列表 |
|
|
|
List<ShopOrderAndMaterialVo> importPartAttrVoList = new ArrayList<>(); |
|
|
|
|
|
|
|
for (int i = 0; i < excelDataList.size(); i++) { |
|
|
|
Map<String, Object> rowData = excelDataList.get(i); |
|
|
|
int rowIndex = i + 2; // Excel行号(考虑表头) |
|
|
|
|
|
|
|
try { |
|
|
|
NotifyExcelData notifyData = new NotifyExcelData(); |
|
|
|
ShopOrderAndMaterialVo importPartAttrVo = new ShopOrderAndMaterialVo(); |
|
|
|
|
|
|
|
// 第一列:site |
|
|
|
Object siteObj = rowData.get("0"); |
|
|
|
if (siteObj == null || StringUtils.isBlank(siteObj.toString())) { |
|
|
|
throw new RuntimeException("第" + rowIndex + "行的工厂编码(site)不能为空"); |
|
|
|
} |
|
|
|
if (!siteObj.toString().trim().equals(site)){ |
|
|
|
throw new RuntimeException("第" + rowIndex + "行的工厂编码(site)与当前工厂不一致"); |
|
|
|
} |
|
|
|
notifyData.setSite(siteObj.toString().trim()); |
|
|
|
|
|
|
|
// 第二列:orderNo |
|
|
|
Object orderNoObj = rowData.get("1"); |
|
|
|
if (orderNoObj == null || StringUtils.isBlank(orderNoObj.toString())) { |
|
|
|
throw new RuntimeException("第" + rowIndex + "行的订单号(orderNo)不能为空"); |
|
|
|
} |
|
|
|
notifyData.setOrderNo(orderNoObj.toString().trim()); |
|
|
|
|
|
|
|
// 第三列:releaseNo |
|
|
|
Object releaseNoObj = rowData.get("2"); |
|
|
|
if (releaseNoObj == null || StringUtils.isBlank(releaseNoObj.toString())) { |
|
|
|
throw new RuntimeException("第" + rowIndex + "行的发布号(releaseNo)不能为空"); |
|
|
|
} |
|
|
|
notifyData.setReleaseNo(releaseNoObj.toString().trim()); |
|
|
|
|
|
|
|
// 第四列:sequenceNo |
|
|
|
Object sequenceNoObj = rowData.get("3"); |
|
|
|
if (sequenceNoObj == null || StringUtils.isBlank(sequenceNoObj.toString())) { |
|
|
|
throw new RuntimeException("第" + rowIndex + "行的序列号(sequenceNo)不能为空"); |
|
|
|
} |
|
|
|
notifyData.setSequenceNo(sequenceNoObj.toString().trim()); |
|
|
|
|
|
|
|
// 第五列:bomLineNo |
|
|
|
Object bomLineNoObj = rowData.get("4"); |
|
|
|
if (bomLineNoObj == null || StringUtils.isBlank(bomLineNoObj.toString())) { |
|
|
|
throw new RuntimeException("第" + rowIndex + "行的BOM行号(bomLineNo)不能为空"); |
|
|
|
} |
|
|
|
try { |
|
|
|
Integer bomLineNo = Integer.valueOf(bomLineNoObj.toString().trim()); |
|
|
|
if (bomLineNo <= 0) { |
|
|
|
throw new RuntimeException("第" + rowIndex + "行的BOM行号(bomLineNo)必须是大于0的整数"); |
|
|
|
} |
|
|
|
notifyData.setBomLineNo(bomLineNo); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
throw new RuntimeException("第" + rowIndex + "行的BOM行号(bomLineNo)必须是有效的整数"); |
|
|
|
} |
|
|
|
// 设置站点 |
|
|
|
importPartAttrVo.setSite(site); |
|
|
|
|
|
|
|
// 第六列:materialPartNo |
|
|
|
Object materialPartNoObj = rowData.get("5"); |
|
|
|
if (materialPartNoObj == null || StringUtils.isBlank(materialPartNoObj.toString())) { |
|
|
|
throw new RuntimeException("第" + rowIndex + "行的物料编码(materialPartNo)不能为空"); |
|
|
|
// 第一列:料号(A列,索引0) |
|
|
|
Object partNoObj = rowData.get("0"); |
|
|
|
if (partNoObj == null || StringUtils.isBlank(partNoObj.toString())) { |
|
|
|
throw new RuntimeException("第" + rowIndex + "行的料号不能为空"); |
|
|
|
} |
|
|
|
notifyData.setMaterialPartNo(materialPartNoObj.toString().trim()); |
|
|
|
importPartAttrVo.setComponentPartNo(partNoObj.toString().trim()); |
|
|
|
|
|
|
|
// 第七列:needDate |
|
|
|
Object needDateObj = rowData.get("6"); |
|
|
|
if (needDateObj == null || StringUtils.isBlank(needDateObj.toString())) { |
|
|
|
throw new RuntimeException("第" + rowIndex + "行的需求日期(needDate)不能为空"); |
|
|
|
} |
|
|
|
try { |
|
|
|
Date needDate = dateFormat.parse(needDateObj.toString().trim()); |
|
|
|
notifyData.setNeedDate(needDate); |
|
|
|
} catch (ParseException e) { |
|
|
|
throw new RuntimeException("第" + rowIndex + "行的需求日期(needDate)格式不正确,请使用YYYY-MM-DD格式"); |
|
|
|
} |
|
|
|
|
|
|
|
// 第八列:qty |
|
|
|
Object qtyObj = rowData.get("7"); |
|
|
|
// 第二列:数量(B列,索引1) |
|
|
|
Object qtyObj = rowData.get("1"); |
|
|
|
if (qtyObj == null || StringUtils.isBlank(qtyObj.toString())) { |
|
|
|
throw new RuntimeException("第" + rowIndex + "行的数量(qty)不能为空"); |
|
|
|
throw new RuntimeException("第" + rowIndex + "行的数量不能为空"); |
|
|
|
} |
|
|
|
try { |
|
|
|
BigDecimal qty = new BigDecimal(qtyObj.toString().trim()); |
|
|
|
if (qty.compareTo(BigDecimal.ZERO) <= 0) { |
|
|
|
throw new RuntimeException("第" + rowIndex + "行的数量(qty)必须大于0"); |
|
|
|
throw new RuntimeException("第" + rowIndex + "行的数量必须大于0"); |
|
|
|
} |
|
|
|
notifyData.setQty(qty); |
|
|
|
importPartAttrVo.setQtyIssued(qty); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
throw new RuntimeException("第" + rowIndex + "行的数量(qty)必须是有效的数字"); |
|
|
|
throw new RuntimeException("第" + rowIndex + "行的数量必须是有效的数字"); |
|
|
|
} |
|
|
|
|
|
|
|
notifyExcelDataList.add(notifyData); |
|
|
|
importPartAttrVoList.add(importPartAttrVo); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
throw new RuntimeException("第" + rowIndex + "行数据处理异常: " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 打印解析结果到控制台 |
|
|
|
System.out.println("=== Excel解析结果 ==="); |
|
|
|
System.out.println("共解析到 " + notifyExcelDataList.size() + " 条数据:"); |
|
|
|
for (int i = 0; i < notifyExcelDataList.size(); i++) { |
|
|
|
NotifyExcelData data = notifyExcelDataList.get(i); |
|
|
|
System.out.println("第" + (i + 1) + "条: site=" + data.getSite() |
|
|
|
+ ", orderNo=" + data.getOrderNo() |
|
|
|
+ ", releaseNo=" + data.getReleaseNo() |
|
|
|
+ ", sequenceNo=" + data.getSequenceNo() |
|
|
|
+ ", bomLineNo=" + data.getBomLineNo() |
|
|
|
+ ", materialPartNo=" + data.getMaterialPartNo() |
|
|
|
+ ", needDate=" + dateFormat.format(data.getNeedDate()) |
|
|
|
+ ", qty=" + data.getQty()); |
|
|
|
} |
|
|
|
System.out.println("=== 解析完成 ==="); |
|
|
|
|
|
|
|
// 按 site+orderNo+releaseNo+sequenceNo 分组 |
|
|
|
Map<String, List<NotifyExcelData>> groupedDataMap = notifyExcelDataList.stream() |
|
|
|
.collect(Collectors.groupingBy(data -> |
|
|
|
data.getSite() + "|" + data.getOrderNo() + "|" + data.getReleaseNo() + "|" + data.getSequenceNo() |
|
|
|
)); |
|
|
|
|
|
|
|
System.out.println("=== 分组处理开始 ==="); |
|
|
|
System.out.println("共分为 " + groupedDataMap.size() + " 个工单组:"); |
|
|
|
|
|
|
|
// 遍历每个分组,进行业务处理 |
|
|
|
for (Map.Entry<String, List<NotifyExcelData>> entry : groupedDataMap.entrySet()) { |
|
|
|
String groupKey = entry.getKey(); |
|
|
|
List<NotifyExcelData> groupData = entry.getValue(); |
|
|
|
|
|
|
|
// 解析分组key |
|
|
|
String[] keyParts = groupKey.split("\\|"); |
|
|
|
String site2 = keyParts[0]; |
|
|
|
String orderNo = keyParts[1]; |
|
|
|
String releaseNo = keyParts[2]; |
|
|
|
String sequenceNo = keyParts[3]; |
|
|
|
|
|
|
|
System.out.println("处理工单组: site=" + site2 + ", orderNo=" + orderNo + |
|
|
|
", releaseNo=" + releaseNo + ", sequenceNo=" + sequenceNo + |
|
|
|
", 包含物料数量=" + groupData.size()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
return importPartAttrVoList; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|