diff --git a/src/main/java/com/budwk/app/zhgh/democratic/opinion/service/impl/OpinionSchoolAuditServiceImpl.java b/src/main/java/com/budwk/app/zhgh/democratic/opinion/service/impl/OpinionSchoolAuditServiceImpl.java index 845a30cf..cf50f85e 100644 --- a/src/main/java/com/budwk/app/zhgh/democratic/opinion/service/impl/OpinionSchoolAuditServiceImpl.java +++ b/src/main/java/com/budwk/app/zhgh/democratic/opinion/service/impl/OpinionSchoolAuditServiceImpl.java @@ -82,8 +82,19 @@ public class OpinionSchoolAuditServiceImpl extends BaseServiceImpl @Override public ExcelImportRes importAuditResult(TempFile file, String sessionId) { - List importRows = ExcelImportUtil.importExcel(file.getFile(), OpinionSchoolAuditImportExcelMode.class, new ImportParams()); ExcelImportRes excelImportRes = new ExcelImportRes<>(); + List 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()); Set importedCodes = new HashSet<>(); @@ -93,8 +104,13 @@ public class OpinionSchoolAuditServiceImpl extends BaseServiceImpl continue; } - // 逐行校验并执行流程,导入失败的行只记录错误,不影响后续行继续处理。 - handleAuditImportRow(row, i, sessionId, importedCodes); + try { + // 逐行校验并执行流程,导入失败的行只记录错误,不影响后续行继续处理。 + handleAuditImportRow(row, i, sessionId, importedCodes); + } catch (Exception e) { + // 单行数据或流程执行异常时返回到导入结果,避免异常直接抛给前端导致整批导入失败。 + row.setErrInfo("导入处理失败:" + getErrorMessage(e), i + 2); + } } List errorDetails = importRows.stream() @@ -125,27 +141,38 @@ public class OpinionSchoolAuditServiceImpl extends BaseServiceImpl Record taskInfo = StrUtil.isBlank(code) ? null : fetchDoingSchoolAuditTask(code, sessionId); if (taskInfo == null && StrUtil.isNotBlank(code)) { - errors.add("未找到当前届次下可审核的校工会待办意见"); + errors.add("仅允许导入当前节点为校工会审核的未审核意见"); } OpinionType type = null; ProposalUndertake masterUnit = null; List slaveUnits = new ArrayList<>(); 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("意见类别不存在"); } - masterUnit = fetchUndertake(row.getMasterUnitName()); - if (masterUnit == null) { + if (StrUtil.isBlank(row.getMasterUnitName())) { + errors.add("主办单位不能为空"); + } else { + masterUnit = fetchUndertake(row.getMasterUnitName()); + } + if (StrUtil.isNotBlank(row.getMasterUnitName()) && masterUnit == null) { errors.add("主办单位不存在"); } slaveUnits = parseSlaveUnits(row.getSlaveUnitNames(), errors); - String masterUnitId = masterUnit.getId(); - if (masterUnit != null && slaveUnits.stream().anyMatch(unit -> StrUtil.equals(unit.getId(), masterUnitId))) { - errors.add("协办单位不能包含主办单位"); + if (masterUnit != null) { + String masterUnitId = masterUnit.getId(); + if (slaveUnits.stream().anyMatch(unit -> StrUtil.equals(unit.getId(), masterUnitId))) { + errors.add("协办单位不能包含主办单位"); + } } } @@ -318,6 +345,10 @@ public class OpinionSchoolAuditServiceImpl extends BaseServiceImpl && StrUtil.isBlank(row.getAuditOpinion()); } + private String getErrorMessage(Exception e) { + return StrUtil.isBlank(e.getMessage()) ? e.getClass().getSimpleName() : e.getMessage(); + } + /** * 导入审核结果与流程参数之间的映射。 */