This commit is contained in:
2026-06-10 14:39:08 +08:00
@@ -82,8 +82,19 @@ public class OpinionSchoolAuditServiceImpl extends BaseServiceImpl<OpinionInfo>
@Override @Override
public ExcelImportRes<OpinionSchoolAuditImportExcelMode> importAuditResult(TempFile file, String sessionId) { public ExcelImportRes<OpinionSchoolAuditImportExcelMode> importAuditResult(TempFile file, String sessionId) {
List<OpinionSchoolAuditImportExcelMode> importRows = ExcelImportUtil.importExcel(file.getFile(), OpinionSchoolAuditImportExcelMode.class, new ImportParams());
ExcelImportRes<OpinionSchoolAuditImportExcelMode> excelImportRes = new ExcelImportRes<>(); ExcelImportRes<OpinionSchoolAuditImportExcelMode> excelImportRes = new ExcelImportRes<>();
List<OpinionSchoolAuditImportExcelMode> importRows;
try {
importRows = ExcelImportUtil.importExcel(file.getFile(), OpinionSchoolAuditImportExcelMode.class, new ImportParams());
} catch (Exception e) {
// 文件解析类错误也按导入结果返回,避免直接抛给前端。
OpinionSchoolAuditImportExcelMode errorRow = new OpinionSchoolAuditImportExcelMode();
errorRow.setErrInfo("文件读取失败:" + getErrorMessage(e), 1);
excelImportRes.setTotalRecords(1);
excelImportRes.setFailedCount(1);
excelImportRes.setErrorDetails(Collections.singletonList(errorRow));
return excelImportRes;
}
excelImportRes.setTotalRecords(importRows.size()); excelImportRes.setTotalRecords(importRows.size());
Set<String> importedCodes = new HashSet<>(); Set<String> importedCodes = new HashSet<>();
@@ -93,8 +104,13 @@ public class OpinionSchoolAuditServiceImpl extends BaseServiceImpl<OpinionInfo>
continue; continue;
} }
// 逐行校验并执行流程,导入失败的行只记录错误,不影响后续行继续处理。 try {
handleAuditImportRow(row, i, sessionId, importedCodes); // 逐行校验并执行流程,导入失败的行只记录错误,不影响后续行继续处理。
handleAuditImportRow(row, i, sessionId, importedCodes);
} catch (Exception e) {
// 单行数据或流程执行异常时返回到导入结果,避免异常直接抛给前端导致整批导入失败。
row.setErrInfo("导入处理失败:" + getErrorMessage(e), i + 2);
}
} }
List<OpinionSchoolAuditImportExcelMode> errorDetails = importRows.stream() List<OpinionSchoolAuditImportExcelMode> errorDetails = importRows.stream()
@@ -125,27 +141,38 @@ public class OpinionSchoolAuditServiceImpl extends BaseServiceImpl<OpinionInfo>
Record taskInfo = StrUtil.isBlank(code) ? null : fetchDoingSchoolAuditTask(code, sessionId); Record taskInfo = StrUtil.isBlank(code) ? null : fetchDoingSchoolAuditTask(code, sessionId);
if (taskInfo == null && StrUtil.isNotBlank(code)) { if (taskInfo == null && StrUtil.isNotBlank(code)) {
errors.add("未找到当前届次下可审核的校工会待办意见"); errors.add("仅允许导入当前节点为校工会审核的未审核意见");
} }
OpinionType type = null; OpinionType type = null;
ProposalUndertake masterUnit = null; ProposalUndertake masterUnit = null;
List<ProposalUndertake> slaveUnits = new ArrayList<>(); List<ProposalUndertake> slaveUnits = new ArrayList<>();
if (auditResult == AuditResult.PASS) { if (auditResult == AuditResult.PASS) {
type = fetchOpinionType(row.getTypeName()); // 审核通过时与页面必填规则保持一致:意见类别、主办单位、审核意见必须填写。
if (type == null) { if (StrUtil.isBlank(row.getTypeName())) {
errors.add("意见类别不能为空");
} else {
type = fetchOpinionType(row.getTypeName());
}
if (StrUtil.isNotBlank(row.getTypeName()) && type == null) {
errors.add("意见类别不存在"); errors.add("意见类别不存在");
} }
masterUnit = fetchUndertake(row.getMasterUnitName()); if (StrUtil.isBlank(row.getMasterUnitName())) {
if (masterUnit == null) { errors.add("主办单位不能为空");
} else {
masterUnit = fetchUndertake(row.getMasterUnitName());
}
if (StrUtil.isNotBlank(row.getMasterUnitName()) && masterUnit == null) {
errors.add("主办单位不存在"); errors.add("主办单位不存在");
} }
slaveUnits = parseSlaveUnits(row.getSlaveUnitNames(), errors); slaveUnits = parseSlaveUnits(row.getSlaveUnitNames(), errors);
String masterUnitId = masterUnit.getId(); if (masterUnit != null) {
if (masterUnit != null && slaveUnits.stream().anyMatch(unit -> StrUtil.equals(unit.getId(), masterUnitId))) { String masterUnitId = masterUnit.getId();
errors.add("协办单位不能包含主办单位"); if (slaveUnits.stream().anyMatch(unit -> StrUtil.equals(unit.getId(), masterUnitId))) {
errors.add("协办单位不能包含主办单位");
}
} }
} }
@@ -318,6 +345,10 @@ public class OpinionSchoolAuditServiceImpl extends BaseServiceImpl<OpinionInfo>
&& StrUtil.isBlank(row.getAuditOpinion()); && StrUtil.isBlank(row.getAuditOpinion());
} }
private String getErrorMessage(Exception e) {
return StrUtil.isBlank(e.getMessage()) ? e.getClass().getSimpleName() : e.getMessage();
}
/** /**
* 导入审核结果与流程参数之间的映射。 * 导入审核结果与流程参数之间的映射。
*/ */