!59 feat(inspectimprove): 实体添加ExcelColumn注解,新增EasyExcel导入和校验接口
Merge pull request !59 from wsm/feature/excel_val
This commit is contained in:
+34
@@ -237,6 +237,40 @@ public class JeecgController<T, S extends IService<T>> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过EasyExcel校验数据,只返回校验结果,不保存到数据库
|
||||
*/
|
||||
protected Result<?> checkExcelByEasyExcel(HttpServletRequest request, Class<T> clazz) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> 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<ExcelAnnotationUtils.ValidationError> 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导入数据
|
||||
*
|
||||
|
||||
+9
-7
@@ -47,7 +47,7 @@ public class ExcelImportListener<T> implements ReadListener<Map<Integer, String>
|
||||
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<T> implements ReadListener<Map<Integer, String>
|
||||
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<T> implements ReadListener<Map<Integer, String>
|
||||
|
||||
@Override
|
||||
public void doAfterAllAnalysed(AnalysisContext context) {
|
||||
if (!batch.isEmpty()) {
|
||||
if (batchHandler != null && batch != null && !batch.isEmpty()) {
|
||||
batchHandler.accept(new ArrayList<>(batch));
|
||||
batch.clear();
|
||||
}
|
||||
|
||||
+8
@@ -382,6 +382,14 @@ public class BgXiSpeakController extends JeecgController<BgXiSpeak, IBgXiSpeakSe
|
||||
return super.importExcelByEasyExcel(request, BgXiSpeak.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过EasyExcel校验数据,只返回校验结果,不保存到数据库
|
||||
*/
|
||||
@RequiresPermissions("bg.xispeak:bg_xi_speak:importExcel")
|
||||
@RequestMapping(value = "/checkExcelByEasyExcel", method = RequestMethod.POST)
|
||||
public Result<?> checkExcelByEasyExcel(HttpServletRequest request) {
|
||||
return super.checkExcelByEasyExcel(request, BgXiSpeak.class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
+27
-9
@@ -282,14 +282,6 @@ public class DjInspectImproveController extends JeecgController<DjInspectImprove
|
||||
return super.exportXls(request, djInspectImprove, DjInspectImprove.class, "巡视整改台账");
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅导出Excel表头(EasyExcel)
|
||||
*/
|
||||
@RequiresPermissions("dj.inspectimprove:dj_inspect_improve:exportXls")
|
||||
@GetMapping(value = "/exportXlsHeaders")
|
||||
public void exportXlsHeaders(HttpServletResponse response) throws IOException {
|
||||
super.exportXlsHeadersByEasyExcel(response, DjInspectImprove.class, "巡视整改台账");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
@@ -304,4 +296,30 @@ public class DjInspectImproveController extends JeecgController<DjInspectImprove
|
||||
return super.importExcel(request, response, DjInspectImprove.class);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 仅导出Excel表头(EasyExcel)
|
||||
*/
|
||||
@RequiresPermissions("dj.inspectimprove:dj_inspect_improve:exportXls")
|
||||
@GetMapping(value = "/exportXlsHeaders")
|
||||
public void exportXlsHeaders(HttpServletResponse response) throws IOException {
|
||||
super.exportXlsHeadersByEasyExcel(response, DjInspectImprove.class, "巡视整改台账");
|
||||
}
|
||||
/**
|
||||
* 通过EasyExcel导入数据
|
||||
*/
|
||||
@RequiresPermissions("dj.inspectimprove:dj_inspect_improve:importExcel")
|
||||
@RequestMapping(value = "/importExcelByEasyExcel", method = RequestMethod.POST)
|
||||
public Result<?> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+18
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user