diff --git a/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java b/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java index 157215e3..2aa94c42 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java @@ -39,7 +39,7 @@ import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; - +import java.util.concurrent.CompletableFuture; /** * 资源表 * @@ -222,15 +222,23 @@ public class ResourceController { // 对上传的文件重命名,避免文件重名 String oldName = uploadFile.getOriginalFilename(); String newName = UUID.randomUUID().toString() - + oldName.substring(oldName.lastIndexOf("."), oldName.length()); + + oldName.substring(oldName.lastIndexOf(".")); try { // 文件保存 File file = new File(folder, newName); uploadFile.transferTo(file); - EasyExcel.read(file, new ResourceExcelImportListener(0, dept, resourceService)).sheet(0).headRowNumber(6).doRead(); - EasyExcel.read(file, new ResourceExcelImportListener(1, dept, resourceService)).sheet(1).headRowNumber(5).doRead(); - EasyExcel.read(file, new ResourceExcelImportListener(2, dept, resourceService)).sheet(2).headRowNumber(5).doRead(); - EasyExcel.read(file, new ResourceExcelImportListener(3, dept, resourceService)).sheet(3).headRowNumber(6).doRead(); + CompletableFuture.runAsync(() -> { + EasyExcel.read(file, new ResourceExcelImportListener(0, dept, resourceService)).sheet(0).headRowNumber(1).doReadSync(); + }); + CompletableFuture.runAsync(() -> { + EasyExcel.read(file, new ResourceExcelImportListener(1, dept, resourceService)).sheet(1).headRowNumber(1).doReadSync(); + }); + CompletableFuture.runAsync(() -> { + EasyExcel.read(file, new ResourceExcelImportListener(2, dept, resourceService)).sheet(2).headRowNumber(1).doReadSync(); + }); + CompletableFuture.runAsync(() -> { + EasyExcel.read(file, new ResourceExcelImportListener(3, dept, resourceService)).sheet(3).headRowNumber(1).doReadSync(); + }); } catch (IOException e) { return new Result().error(e.getMessage()); } diff --git a/renren-admin/src/main/java/io/renren/modules/resource/excel/ResourceExcelImportListener.java b/renren-admin/src/main/java/io/renren/modules/resource/excel/ResourceExcelImportListener.java index 15271aaa..d7f20dcf 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/excel/ResourceExcelImportListener.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/excel/ResourceExcelImportListener.java @@ -10,7 +10,9 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.text.SimpleDateFormat; import java.util.*; +import java.util.stream.Collectors; /** @@ -30,6 +32,8 @@ public class ResourceExcelImportListener extends AnalysisEventListener headMap = null; + private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + public ResourceExcelImportListener(int sheet, List> deptList, ResourceService resourceService) { this.sheet = sheet; this.deptList = deptList; @@ -79,7 +83,11 @@ public class ResourceExcelImportListener extends AnalysisEventListener index.values().contains(dept.getOrDefault("name", "").toString())).findAny(); if (!deptOptional.isPresent()) { logger.info("找不到部门:{}", index.toString()); - return null; + deptOptional = Optional.of(new LinkedHashMap() { + { + put("id", 1L); + } + }); } ResourceDTO resourceDTO = new ResourceDTO(); switch (sheet) { @@ -99,9 +107,14 @@ public class ResourceExcelImportListener extends AnalysisEventListener index != null && StringUtils.isNotEmpty(index.getName())).forEach(index -> { - resourceService.insertWithAttrs(index); - logger.info("完成导入:{}", index.getName()); + }).filter(index -> index != null).forEach(index -> { + try { + logger.info("准备插入:" + JSON.toJSONString(index)); + resourceService.insertWithAttrs(index); + logger.info("完成导入:{}", index.getName()); + } catch (Exception exception) { + logger.error("导入异常", exception); + } }); } @@ -130,7 +143,7 @@ public class ResourceExcelImportListener extends AnalysisEventListener StringUtils.isNotEmpty(info.getAttrValue())).collect(Collectors.toList())); // infoList内空属性不导入 resourceDTO.setDelFlag(0); - resourceDTO.setDeptId(deptId); // 所属部门 +// resourceDTO.setDeptId(deptId); // 所属部门 return resourceDTO; }