能力导入采用全异步;所属部门不存在时默认deptId 为1
This commit is contained in:
parent
64b44da859
commit
e1c7d34edc
|
@ -38,6 +38,7 @@ import java.io.IOException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 资源表
|
* 资源表
|
||||||
|
@ -221,15 +222,23 @@ public class ResourceController {
|
||||||
// 对上传的文件重命名,避免文件重名
|
// 对上传的文件重命名,避免文件重名
|
||||||
String oldName = uploadFile.getOriginalFilename();
|
String oldName = uploadFile.getOriginalFilename();
|
||||||
String newName = UUID.randomUUID().toString()
|
String newName = UUID.randomUUID().toString()
|
||||||
+ oldName.substring(oldName.lastIndexOf("."), oldName.length());
|
+ oldName.substring(oldName.lastIndexOf("."));
|
||||||
try {
|
try {
|
||||||
// 文件保存
|
// 文件保存
|
||||||
File file = new File(folder, newName);
|
File file = new File(folder, newName);
|
||||||
uploadFile.transferTo(file);
|
uploadFile.transferTo(file);
|
||||||
EasyExcel.read(file, new ResourceExcelImportListener(0, dept, resourceService)).sheet(0).headRowNumber(6).doRead();
|
CompletableFuture.runAsync(() -> {
|
||||||
EasyExcel.read(file, new ResourceExcelImportListener(1, dept, resourceService)).sheet(1).headRowNumber(5).doRead();
|
EasyExcel.read(file, new ResourceExcelImportListener(0, dept, resourceService)).sheet(0).headRowNumber(1).doReadSync();
|
||||||
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(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) {
|
} catch (IOException e) {
|
||||||
return new Result<String>().error(e.getMessage());
|
return new Result<String>().error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,9 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,6 +32,8 @@ public class ResourceExcelImportListener extends AnalysisEventListener<Map<Integ
|
||||||
|
|
||||||
Map<Integer, String> headMap = null;
|
Map<Integer, String> headMap = null;
|
||||||
|
|
||||||
|
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
public ResourceExcelImportListener(int sheet, List<Map<String, Object>> deptList, ResourceService resourceService) {
|
public ResourceExcelImportListener(int sheet, List<Map<String, Object>> deptList, ResourceService resourceService) {
|
||||||
this.sheet = sheet;
|
this.sheet = sheet;
|
||||||
this.deptList = deptList;
|
this.deptList = deptList;
|
||||||
|
@ -79,7 +83,11 @@ public class ResourceExcelImportListener extends AnalysisEventListener<Map<Integ
|
||||||
deptList.stream().filter(dept -> index.values().contains(dept.getOrDefault("name", "").toString())).findAny();
|
deptList.stream().filter(dept -> index.values().contains(dept.getOrDefault("name", "").toString())).findAny();
|
||||||
if (!deptOptional.isPresent()) {
|
if (!deptOptional.isPresent()) {
|
||||||
logger.info("找不到部门:{}", index.toString());
|
logger.info("找不到部门:{}", index.toString());
|
||||||
return null;
|
deptOptional = Optional.of(new LinkedHashMap<String, Object>() {
|
||||||
|
{
|
||||||
|
put("id", 1L);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
ResourceDTO resourceDTO = new ResourceDTO();
|
ResourceDTO resourceDTO = new ResourceDTO();
|
||||||
switch (sheet) {
|
switch (sheet) {
|
||||||
|
@ -99,9 +107,14 @@ public class ResourceExcelImportListener extends AnalysisEventListener<Map<Integ
|
||||||
logger.error("不支持该sheet");
|
logger.error("不支持该sheet");
|
||||||
}
|
}
|
||||||
return resourceDTO;
|
return resourceDTO;
|
||||||
}).filter(index -> index != null && StringUtils.isNotEmpty(index.getName())).forEach(index -> {
|
}).filter(index -> index != null).forEach(index -> {
|
||||||
resourceService.insertWithAttrs(index);
|
try {
|
||||||
logger.info("完成导入:{}", index.getName());
|
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<Map<Integ
|
||||||
|
|
||||||
AttrEntity attrEntity3 = new AttrEntity();
|
AttrEntity attrEntity3 = new AttrEntity();
|
||||||
attrEntity3.setAttrType("应用领域");
|
attrEntity3.setAttrType("应用领域");
|
||||||
attrEntity3.setAttrValue(date.get(3));
|
attrEntity3.setAttrValue(date.get(3).replaceAll("\\s*", ""));
|
||||||
infoList.add(attrEntity3); // 应用领域
|
infoList.add(attrEntity3); // 应用领域
|
||||||
|
|
||||||
resourceDTO.setDescription(date.get(4)); // 描述
|
resourceDTO.setDescription(date.get(4)); // 描述
|
||||||
|
@ -210,6 +223,11 @@ public class ResourceExcelImportListener extends AnalysisEventListener<Map<Integ
|
||||||
resourceDTO.setType("组件服务");
|
resourceDTO.setType("组件服务");
|
||||||
resourceDTO.setName(date.get(0));
|
resourceDTO.setName(date.get(0));
|
||||||
|
|
||||||
|
AttrEntity attrEntity = new AttrEntity();
|
||||||
|
attrEntity.setAttrType("组件类型");
|
||||||
|
attrEntity.setAttrValue("智能算法");
|
||||||
|
infoList.add(attrEntity); // 组件类型
|
||||||
|
|
||||||
AttrEntity attrEntity1 = new AttrEntity();
|
AttrEntity attrEntity1 = new AttrEntity();
|
||||||
attrEntity1.setAttrType("算法类别");
|
attrEntity1.setAttrType("算法类别");
|
||||||
attrEntity1.setAttrValue(date.get(1));
|
attrEntity1.setAttrValue(date.get(1));
|
||||||
|
@ -232,7 +250,7 @@ public class ResourceExcelImportListener extends AnalysisEventListener<Map<Integ
|
||||||
|
|
||||||
AttrEntity attrEntity5 = new AttrEntity();
|
AttrEntity attrEntity5 = new AttrEntity();
|
||||||
attrEntity5.setAttrType("应用领域");
|
attrEntity5.setAttrType("应用领域");
|
||||||
attrEntity5.setAttrValue(date.get(5));
|
attrEntity5.setAttrValue(date.get(5).replaceAll("\\s*", ""));
|
||||||
infoList.add(attrEntity5); // 应用领域
|
infoList.add(attrEntity5); // 应用领域
|
||||||
|
|
||||||
resourceDTO.setShareCondition(date.get(6)); // 共享条件
|
resourceDTO.setShareCondition(date.get(6)); // 共享条件
|
||||||
|
@ -244,7 +262,7 @@ public class ResourceExcelImportListener extends AnalysisEventListener<Map<Integ
|
||||||
AttrEntity attrEntity6 = new AttrEntity();
|
AttrEntity attrEntity6 = new AttrEntity();
|
||||||
attrEntity6.setAttrType("算法介绍视频");
|
attrEntity6.setAttrType("算法介绍视频");
|
||||||
attrEntity6.setAttrValue(date.get(9));
|
attrEntity6.setAttrValue(date.get(9));
|
||||||
infoList.add(attrEntity5); // 应用领域
|
infoList.add(attrEntity5); // 算法介绍视频
|
||||||
|
|
||||||
AttrEntity attrEntity7 = new AttrEntity();
|
AttrEntity attrEntity7 = new AttrEntity();
|
||||||
attrEntity7.setAttrType("服务商");
|
attrEntity7.setAttrType("服务商");
|
||||||
|
@ -310,9 +328,13 @@ public class ResourceExcelImportListener extends AnalysisEventListener<Map<Integ
|
||||||
resourceDTO.setName(date.get(0));
|
resourceDTO.setName(date.get(0));
|
||||||
resourceDTO.setLink(date.get(1));
|
resourceDTO.setLink(date.get(1));
|
||||||
resourceDTO.setDescription(date.get(2));
|
resourceDTO.setDescription(date.get(2));
|
||||||
|
try {
|
||||||
|
Date createDate = sdf.parse(date.get(4).trim());
|
||||||
|
resourceDTO.setCreateDate(createDate);
|
||||||
|
} catch (Exception exception) {
|
||||||
|
logger.error("时间异常", exception);
|
||||||
|
}
|
||||||
|
|
||||||
Date createDate = new Date(Long.parseLong(date.get(4)));
|
|
||||||
resourceDTO.setCreateDate(createDate);
|
|
||||||
|
|
||||||
AttrEntity attrEntity = new AttrEntity();
|
AttrEntity attrEntity = new AttrEntity();
|
||||||
attrEntity.setAttrType("文件类型");
|
attrEntity.setAttrType("文件类型");
|
||||||
|
@ -328,6 +350,7 @@ public class ResourceExcelImportListener extends AnalysisEventListener<Map<Integ
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
case 3: {
|
case 3: {
|
||||||
resourceDTO.setType("基础设施");
|
resourceDTO.setType("基础设施");
|
||||||
resourceDTO.setName(date.get(0));
|
resourceDTO.setName(date.get(0));
|
||||||
|
@ -342,9 +365,9 @@ public class ResourceExcelImportListener extends AnalysisEventListener<Map<Integ
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
resourceDTO.setInfoList(infoList);
|
resourceDTO.setInfoList(infoList.stream().distinct().filter(info -> StringUtils.isNotEmpty(info.getAttrValue())).collect(Collectors.toList())); // infoList内空属性不导入
|
||||||
resourceDTO.setDelFlag(0);
|
resourceDTO.setDelFlag(0);
|
||||||
resourceDTO.setDeptId(deptId); // 所属部门
|
// resourceDTO.setDeptId(deptId); // 所属部门
|
||||||
return resourceDTO;
|
return resourceDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue