|
|
@ -108,4 +108,38 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { |
|
|
|
ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${sceneEnum.prefixClass}${table.className}ExcelVO.class, datas); |
|
|
|
} |
|
|
|
|
|
|
|
@GetMapping("/get-import-template") |
|
|
|
@Operation(summary = "获得导入${table.classComment}模板") |
|
|
|
public void importTemplate(HttpServletResponse response) throws IOException { |
|
|
|
List<${table.className}ExcelVO> list = Arrays.asList(); |
|
|
|
// 输出 |
|
|
|
ExcelUtils.write(response, "${table.classComment}基本信息导入模板.xls", "${table.classComment}基本信息列表", ${table.className}ExcelVo.class, list); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("/import") |
|
|
|
@Operation(summary = "导入${table.classComment}基本信息") |
|
|
|
@Parameters({ |
|
|
|
@Parameter(name = "file", description = "Excel 文件", required = true), |
|
|
|
@Parameter(name = "mode", description = "导入模式1更新2追加3覆盖", example = "1"), |
|
|
|
@Parameter(name = "updatePart", description = "部分更新,默认为 true", example = "true") |
|
|
|
}) |
|
|
|
#if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:import')")#end |
|
|
|
|
|
|
|
public CommonResult<Map<String, Object>> importExcel(HttpServletResponse response, |
|
|
|
@RequestParam("file") MultipartFile file, |
|
|
|
@RequestParam(value = "mode") Integer mode, |
|
|
|
@RequestParam(value = "updatePart", required = false, defaultValue = "false") Boolean updatePart) throws Exception { |
|
|
|
|
|
|
|
List<${table.className}ExcelVO> list = ExcelUtils.read(file, ${table.className}ExcelVO.class); |
|
|
|
List<${table.className}ExcelVO> errorList = ${classNameVar}Service.import${table.className}List(list, mode, updatePart); |
|
|
|
|
|
|
|
Map<String, Object> returnMap = new HashMap<>(); |
|
|
|
returnMap.put("errorCount", errorList.size()); |
|
|
|
if(!errorList.isEmpty()) { |
|
|
|
String url = ExcelUtils.writeLocalFile("${table.classComment}基本信息导入错误数据" + LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")) + ".xlsx", "错误列表", errorList); |
|
|
|
returnMap.put("errorFile", url); |
|
|
|
} |
|
|
|
|
|
|
|
return success(returnMap); |
|
|
|
} |
|
|
|
} |
|
|
|