|
|
|
@ -1253,48 +1253,44 @@ public class IssureNotifyServiceImpl implements IssureNotifyService { |
|
|
|
throw new RuntimeException("文件格式不正确,只支持.xls和.xlsx格式的Excel文件"); |
|
|
|
} |
|
|
|
|
|
|
|
// 2. 读取Excel数据 - rqrq |
|
|
|
List<Map<String, Object>> excelDataList = ExcelUtil.readExcelToMapList(file); |
|
|
|
if (excelDataList.isEmpty()) { |
|
|
|
throw new RuntimeException("Excel文件中没有有效数据"); |
|
|
|
} |
|
|
|
|
|
|
|
// 3. 遍历每行数据,查询是否在立库和可用库存 - rqrq |
|
|
|
// 2. 用老导入同一套POI读取。跳过表头,空行跳过;不再走ExcelUtil,避免运行时缺少该类 - rqrq |
|
|
|
List<BaoFeiImportResultVo> resultList = new ArrayList<>(); |
|
|
|
for (int i = 0; i < excelDataList.size(); i++) { |
|
|
|
Map<String, Object> rowData = excelDataList.get(i); |
|
|
|
int rowIndex = i + 2; // Excel行号(考虑表头) |
|
|
|
try (InputStream is = file.getInputStream(); Workbook workbook = WorkbookFactory.create(is)) { |
|
|
|
Sheet sheet = workbook.getSheetAt(0); |
|
|
|
int lastRowNum = sheet.getLastRowNum(); |
|
|
|
for (int i = 1; i <= lastRowNum; i++) { |
|
|
|
Row row = sheet.getRow(i); |
|
|
|
if (row == null) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
int rowIndex = i + 1; |
|
|
|
// 列顺序与原报废模板一致:A物料号、B批次号、C数量。取值走老方法,后续校验仍按新逻辑 - rqrq |
|
|
|
String partNo = StringUtils.trim(getStringCellValue(row, 0)); |
|
|
|
String batchNoRaw = StringUtils.trim(getStringCellValue(row, 1)); |
|
|
|
String qtyRaw = StringUtils.trim(getStringCellValue(row, 2)); |
|
|
|
if (StringUtils.isBlank(partNo) && StringUtils.isBlank(batchNoRaw) && StringUtils.isBlank(qtyRaw)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
BaoFeiImportResultVo vo = new BaoFeiImportResultVo(); |
|
|
|
BaoFeiImportResultVo vo = new BaoFeiImportResultVo(); |
|
|
|
if (StringUtils.isBlank(partNo)) { |
|
|
|
throw new RuntimeException("第" + rowIndex + "行的物料号不能为空"); |
|
|
|
} |
|
|
|
vo.setPartNo(partNo); |
|
|
|
|
|
|
|
// 第一列:物料号(A列,索引0)- rqrq |
|
|
|
Object partNoObj = rowData.get("0"); |
|
|
|
if (partNoObj == null || StringUtils.isBlank(partNoObj.toString())) { |
|
|
|
throw new RuntimeException("第" + rowIndex + "行的物料号不能为空"); |
|
|
|
} |
|
|
|
String partNo = partNoObj.toString().trim(); |
|
|
|
vo.setPartNo(partNo); |
|
|
|
|
|
|
|
// 第二列:批次号(B列,索引1)- rqrq |
|
|
|
Object batchNoObj = rowData.get("1"); |
|
|
|
String batchNo = null; |
|
|
|
if (batchNoObj != null && StringUtils.isNotBlank(batchNoObj.toString())) { |
|
|
|
batchNo = batchNoObj.toString().trim(); |
|
|
|
} |
|
|
|
vo.setBatchNo(batchNo); |
|
|
|
String batchNo = StringUtils.isNotBlank(batchNoRaw) ? batchNoRaw : null; |
|
|
|
vo.setBatchNo(batchNo); |
|
|
|
|
|
|
|
// 第三列:数量(C列,索引2)- rqrq |
|
|
|
Object qtyObj = rowData.get("2"); |
|
|
|
BigDecimal remark = BigDecimal.ZERO; |
|
|
|
if (qtyObj != null && StringUtils.isNotBlank(qtyObj.toString())) { |
|
|
|
try { |
|
|
|
remark = new BigDecimal(qtyObj.toString().trim()); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
// 数量格式错误,设为0 |
|
|
|
remark = BigDecimal.ZERO; |
|
|
|
BigDecimal remark = BigDecimal.ZERO; |
|
|
|
if (StringUtils.isNotBlank(qtyRaw)) { |
|
|
|
try { |
|
|
|
remark = new BigDecimal(qtyRaw); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
// 数量格式错误,设为0,和原来报废导入一致 - rqrq |
|
|
|
remark = BigDecimal.ZERO; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
vo.setRemark(remark); |
|
|
|
vo.setRemark(remark); |
|
|
|
|
|
|
|
// 4. 查询是否在立库 - rqrq |
|
|
|
String isInWh = issureNotifyMapper.getPartIsInWh(site, partNo); |
|
|
|
@ -1328,7 +1324,15 @@ public class IssureNotifyServiceImpl implements IssureNotifyService { |
|
|
|
// 6. 设置申请数量为可用库存 - rqrq |
|
|
|
vo.setApplyQty(availableQty); |
|
|
|
|
|
|
|
resultList.add(vo); |
|
|
|
resultList.add(vo); |
|
|
|
} |
|
|
|
} catch (RuntimeException e) { |
|
|
|
throw e; |
|
|
|
} catch (Exception e) { |
|
|
|
throw new RuntimeException("读取Excel文件失败: " + e.getMessage(), e); |
|
|
|
} |
|
|
|
if (resultList.isEmpty()) { |
|
|
|
throw new RuntimeException("Excel文件中没有有效数据"); |
|
|
|
} |
|
|
|
|
|
|
|
System.out.println("报废Excel处理完成,共" + resultList.size() + "条数据 - rqrq"); |
|
|
|
|