From 16343d2e99a9cff5b0bac8428f3ab2ba69d5778d Mon Sep 17 00:00:00 2001 From: wsm <2746563060@qq.com> Date: Tue, 30 Jun 2026 10:05:13 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(xispeak):=20=E6=96=B0=E5=A2=9EExcel?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=8F=AA=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E4=B8=8D=E4=BF=9D=E5=AD=98=E5=88=B0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - JeecgController 新增 checkExcelByEasyExcel 基类方法,batchHandler 传 null 跳过入库 - ExcelImportListener 支持 batchHandler 为 null 时不攒 batch 内存 - BgXiSpeakController 新增 /checkExcelByEasyExcel 接口 Co-Authored-By: Claude Opus 4.7 --- .../base/controller/JeecgController.java | 34 +++++++++++++++++++ .../util/excel/ExcelImportListener.java | 16 +++++---- .../controller/BgXiSpeakController.java | 8 +++++ 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/system/base/controller/JeecgController.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/system/base/controller/JeecgController.java index 79cc33c..7e2d5b1 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/system/base/controller/JeecgController.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/system/base/controller/JeecgController.java @@ -237,6 +237,40 @@ public class JeecgController> { } } + /** + * 通过EasyExcel校验数据,只返回校验结果,不保存到数据库 + */ + protected Result checkExcelByEasyExcel(HttpServletRequest request, Class clazz) { + MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; + Map fileMap = multipartRequest.getFileMap(); + MultipartFile file = fileMap.values().stream().findFirst().orElse(null); + if (file == null) { + return Result.error("未找到上传文件!"); + } + try (InputStream inputStream = file.getInputStream()) { + long start = System.currentTimeMillis(); + List errors = new ArrayList<>(); + int total = ExcelAnnotationUtils.read( + inputStream, + clazz, + null, + BATCH_NUM, + errors::addAll, + dictQuery()); + log.info("【EasyExcel校验】校验完成, 数据行数: {}, 耗时: {}毫秒", total, System.currentTimeMillis() - start); + if (!errors.isEmpty()) { + for (ExcelAnnotationUtils.ValidationError err : errors) { + log.warn("【EasyExcel校验】校验失败, 行号: {}, 错误: {}", err.row(), err.messages()); + } + return Result.error("文件校验不通过: 存在" + errors.size() + "行数据校验不通过,请修改后重新导入", errors); + } + return Result.ok("文件校验通过!数据行数:" + total); + } catch (IOException e) { + log.error("【EasyExcel校验】文件读取失败", e); + return Result.error("文件校验失败:" + e.getMessage()); + } + } + /** * 通过excel导入数据 * diff --git a/jeecg-boot-module/jeecg-module-tools/src/main/java/org/jeecg/common/util/excel/ExcelImportListener.java b/jeecg-boot-module/jeecg-module-tools/src/main/java/org/jeecg/common/util/excel/ExcelImportListener.java index 30f348f..2094a5b 100644 --- a/jeecg-boot-module/jeecg-module-tools/src/main/java/org/jeecg/common/util/excel/ExcelImportListener.java +++ b/jeecg-boot-module/jeecg-module-tools/src/main/java/org/jeecg/common/util/excel/ExcelImportListener.java @@ -47,7 +47,7 @@ public class ExcelImportListener implements ReadListener this.displayToCode = displayToCode; this.batchHandler = batchHandler; this.errorHandler = errorHandler; - this.batch = new ArrayList<>(batchSize); + this.batch = batchHandler != null ? new ArrayList<>(batchSize) : null; this.errorBatch = new ArrayList<>(batchSize); } @@ -133,12 +133,14 @@ public class ExcelImportListener implements ReadListener return; } - // 4. 成功加入批次 - batch.add(obj); + // 4. 成功计数 successCount[0]++; - if (batch.size() >= batchSize) { - batchHandler.accept(new ArrayList<>(batch)); - batch.clear(); + if (batchHandler != null) { + batch.add(obj); + if (batch.size() >= batchSize) { + batchHandler.accept(new ArrayList<>(batch)); + batch.clear(); + } } } catch (Exception e) { @@ -158,7 +160,7 @@ public class ExcelImportListener implements ReadListener @Override public void doAfterAllAnalysed(AnalysisContext context) { - if (!batch.isEmpty()) { + if (batchHandler != null && batch != null && !batch.isEmpty()) { batchHandler.accept(new ArrayList<>(batch)); batch.clear(); } diff --git a/jeecg-module-supervision/src/main/java/org/jeecg/modules/bg/xispeak/controller/BgXiSpeakController.java b/jeecg-module-supervision/src/main/java/org/jeecg/modules/bg/xispeak/controller/BgXiSpeakController.java index 0e6fce4..2266ee2 100644 --- a/jeecg-module-supervision/src/main/java/org/jeecg/modules/bg/xispeak/controller/BgXiSpeakController.java +++ b/jeecg-module-supervision/src/main/java/org/jeecg/modules/bg/xispeak/controller/BgXiSpeakController.java @@ -382,6 +382,14 @@ public class BgXiSpeakController extends JeecgController checkExcelByEasyExcel(HttpServletRequest request) { + return super.checkExcelByEasyExcel(request, BgXiSpeak.class); + } /** From adcb72c3d2dfa5598c2e0e97c5ef73a8b24c18cc Mon Sep 17 00:00:00 2001 From: wsm <2746563060@qq.com> Date: Tue, 30 Jun 2026 10:29:46 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat(inspectimprove):=20=E5=AE=9E=E4=BD=93?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0ExcelColumn=E6=B3=A8=E8=A7=A3=EF=BC=8C?= =?UTF-8?q?=E6=96=B0=E5=A2=9EEasyExcel=E5=AF=BC=E5=85=A5=E5=92=8C=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - DjInspectImprove 实体所有@Excel字段补全@ExcelColumn注解 - DjInspectImproveController 新增/importExcelByEasyExcel和/checkExcelByEasyExcel接口 Co-Authored-By: Claude Opus 4.7 --- .../DjInspectImproveController.java | 36 ++++++++++++++----- .../entity/DjInspectImprove.java | 18 ++++++++++ 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/jeecg-module-supervision/src/main/java/org/jeecg/modules/dj/inspectimprove/controller/DjInspectImproveController.java b/jeecg-module-supervision/src/main/java/org/jeecg/modules/dj/inspectimprove/controller/DjInspectImproveController.java index c85eba2..0a1bee2 100644 --- a/jeecg-module-supervision/src/main/java/org/jeecg/modules/dj/inspectimprove/controller/DjInspectImproveController.java +++ b/jeecg-module-supervision/src/main/java/org/jeecg/modules/dj/inspectimprove/controller/DjInspectImproveController.java @@ -282,14 +282,6 @@ public class DjInspectImproveController extends JeecgController importExcelByEasyExcel(HttpServletRequest request) { + return super.importExcelByEasyExcel(request, DjInspectImprove.class); + } + + /** + * 通过EasyExcel校验数据,只返回校验结果,不保存到数据库 + */ + @RequiresPermissions("dj.inspectimprove:dj_inspect_improve:importExcel") + @RequestMapping(value = "/checkExcelByEasyExcel", method = RequestMethod.POST) + public Result checkExcelByEasyExcel(HttpServletRequest request) { + return super.checkExcelByEasyExcel(request, DjInspectImprove.class); + } + + } diff --git a/jeecg-module-supervision/src/main/java/org/jeecg/modules/dj/inspectimprove/entity/DjInspectImprove.java b/jeecg-module-supervision/src/main/java/org/jeecg/modules/dj/inspectimprove/entity/DjInspectImprove.java index 20c7928..ad820c1 100644 --- a/jeecg-module-supervision/src/main/java/org/jeecg/modules/dj/inspectimprove/entity/DjInspectImprove.java +++ b/jeecg-module-supervision/src/main/java/org/jeecg/modules/dj/inspectimprove/entity/DjInspectImprove.java @@ -13,6 +13,7 @@ import lombok.Data; import com.fasterxml.jackson.annotation.JsonFormat; import org.springframework.format.annotation.DateTimeFormat; import org.jeecgframework.poi.excel.annotation.Excel; +import org.jeecg.common.util.excel.annotation.ExcelColumn; import org.jeecg.common.aspect.annotation.Dict; import io.swagger.v3.oas.annotations.media.Schema; @@ -64,73 +65,90 @@ public class DjInspectImprove implements Serializable { private java.lang.String hasChild; /**问题分类*/ @Excel(name = "问题分类", width = 15) + @ExcelColumn(name = "问题分类", width = 15, dicCode = "inspect_improve_type") @Schema(description = "问题分类") @Dict(dicCode = "inspect_improve_type") private java.lang.Integer questionCategory; /**面上问题*/ @Excel(name = "面上问题", width = 15) + @ExcelColumn(name = "面上问题", width = 15) @Schema(description = "面上问题") private java.lang.String mianshangQuestion; /**具体问题*/ @Excel(name = "具体问题", width = 15) + @ExcelColumn(name = "具体问题", width = 15) @Schema(description = "具体问题") private java.lang.String specicalQuestion; /**巡视建议*/ @Excel(name = "巡视建议", width = 15) + @ExcelColumn(name = "巡视建议", width = 15) @Schema(description = "巡视建议") private java.lang.String inspectAdvice; /**整改措施*/ @Excel(name = "整改措施", width = 15) + @ExcelColumn(name = "整改措施", width = 15) @Schema(description = "整改措施") private java.lang.String improveMeasure; /**完成时限*/ @Excel(name = "完成时限", width = 15, format = "yyyy-MM-dd") + @ExcelColumn(name = "完成时限", width = 15, format = "yyyy-MM-dd") @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd") @DateTimeFormat(pattern="yyyy-MM-dd") @Schema(description = "完成时限") private java.util.Date deadline; /**目标节点*/ @Excel(name = "目标节点", width = 15) + @ExcelColumn(name = "目标节点", width = 15) @Schema(description = "目标节点") private java.lang.String targetNode; /**问题责任领导*/ @Excel(name = "问题责任领导", width = 15) + @ExcelColumn(name = "问题责任领导", width = 15, dictTable = "sys_user", dicText = "realname", dicCode = "username") @Schema(description = "问题责任领导") private java.lang.String questionResLeader; /**问题责任部门*/ @Excel(name = "问题责任部门", width = 15) + @ExcelColumn(name = "问题责任部门", width = 15, dictTable = "sys_depart", dicText = "depart_name", dicCode = "id") @Schema(description = "问题责任部门") private java.lang.String questionResDept; /**措施责任领导*/ @Excel(name = "措施责任领导", width = 15) + @ExcelColumn(name = "措施责任领导", width = 15, dictTable = "sys_user", dicText = "realname", dicCode = "username") @Schema(description = "措施责任领导") private java.lang.String measureResLeader; /**措施责任部门*/ @Excel(name = "措施责任部门", width = 15) + @ExcelColumn(name = "措施责任部门", width = 15, dictTable = "sys_depart", dicText = "depart_name", dicCode = "id") @Schema(description = "措施责任部门") private java.lang.String measureResDept; /**整改交付成果*/ @Excel(name = "整改交付成果", width = 15) + @ExcelColumn(name = "整改交付成果", width = 15) @Schema(description = "整改交付成果") private java.lang.String rectificationEvidence; /**成效评价标准*/ @Excel(name = "成效评价标准", width = 15) + @ExcelColumn(name = "成效评价标准", width = 15) @Schema(description = "成效评价标准") private java.lang.String evaluationCriterion; /**工作进展*/ @Excel(name = "工作进展", width = 15) + @ExcelColumn(name = "工作进展", width = 15) @Schema(description = "工作进展") private java.lang.String workProgress; /**检查情况*/ @Excel(name = "检查情况", width = 15) + @ExcelColumn(name = "检查情况", width = 15) @Schema(description = "检查情况") private java.lang.String inspectionStatus; /**监督意见*/ @Excel(name = "监督意见", width = 15) + @ExcelColumn(name = "监督意见", width = 15) @Schema(description = "监督意见") private java.lang.String supervisoryOpinion; /**措施数量*/ @Excel(name = "措施数量", width = 15) + @ExcelColumn(name = "措施数量", width = 15) @Schema(description = "措施数量") private java.lang.Integer measureCount; }