|
@@ -173,56 +173,61 @@ public class WbsTreeServiceImpl extends BaseServiceImpl<WbsTreeMapper, WbsTree>
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public Boolean importWbsTree(MultipartFile excelFile, WbsTree wbsTreeFu, WbsTree wbsTree1) throws IOException {
|
|
|
+ public String importWbsTree(MultipartFile excelFile, WbsTree wbsTreeFu, WbsTree wbsTree1) throws IOException {
|
|
|
//赋值
|
|
|
wbsTreeFu.setAncestors("0");
|
|
|
wbsTree1.setProjectNodeId(wbsTree1.getId());
|
|
|
//获取文件路径
|
|
|
File file = WbsExcelUtil.convert(excelFile);
|
|
|
String canonicalPath = file.getCanonicalPath();
|
|
|
- //解析excel
|
|
|
- WbsExcelUtil excelUtil = new WbsExcelUtil();
|
|
|
- ArrayList<Map<String, String>> result = excelUtil.readExcelToObj(canonicalPath);
|
|
|
- for (Map<String, String> map : result) {
|
|
|
- map.forEach((nodeType, nodeName) -> {
|
|
|
- WbsTree wbsTreeZi = new WbsTree();
|
|
|
- if (StringUtils.isNotEmpty(nodeName)) {
|
|
|
- //初始化默认值
|
|
|
- wbsTreeZi.setTenantId(AuthUtil.getTenantId());
|
|
|
- wbsTreeZi.setDeptName(nodeName);
|
|
|
- wbsTreeZi.setDeptCategory(Integer.valueOf(nodeType));
|
|
|
- wbsTreeZi.setWbsId(wbsTreeFu.getWbsId());
|
|
|
- wbsTreeZi.setParentId(wbsTreeFu.getParentId());
|
|
|
- wbsTreeZi.setAncestors(wbsTreeFu.getAncestors());
|
|
|
- wbsTreeZi.setProjectNodeId(wbsTree1.getProjectNodeId());
|
|
|
- //新增节点返回未创建成功查询出来的wbsTree对象、创建成功后的wbsTreeZi对象
|
|
|
- WbsTree wbsTree = importTree(wbsTreeZi);
|
|
|
- //后置初始化默认值
|
|
|
- if (wbsTree == null) {
|
|
|
- Long id = wbsTreeZi.getId();
|
|
|
- //设置ancestors祖级id集合
|
|
|
- StringBuilder stringBuffer = new StringBuilder();
|
|
|
- StringBuilder appendStr = stringBuffer.append(",").append(wbsTreeZi.getParentId());
|
|
|
- String ancestors = wbsTreeZi.getAncestors() + appendStr;
|
|
|
- //修改ancestors的值
|
|
|
- updateDate(ancestors, id);
|
|
|
- wbsTreeFu.setParentId(id);
|
|
|
- wbsTreeFu.setAncestors(ancestors);
|
|
|
- } else {
|
|
|
- wbsTreeFu.setParentId(wbsTree.getId());
|
|
|
- wbsTreeFu.setAncestors(wbsTree.getAncestors());
|
|
|
+ try {
|
|
|
+ //解析excel
|
|
|
+ WbsExcelUtil excelUtil = new WbsExcelUtil();
|
|
|
+ ArrayList<Map<String, String>> result = excelUtil.readExcelToObj(canonicalPath);
|
|
|
+ for (Map<String, String> map : result) {
|
|
|
+ map.forEach((nodeType, nodeName) -> {
|
|
|
+ WbsTree wbsTreeZi = new WbsTree();
|
|
|
+ if (StringUtils.isNotEmpty(nodeName)) {
|
|
|
+ //初始化默认值
|
|
|
+ wbsTreeZi.setTenantId(AuthUtil.getTenantId());
|
|
|
+ wbsTreeZi.setDeptName(nodeName);
|
|
|
+ wbsTreeZi.setDeptCategory(Integer.valueOf(nodeType));
|
|
|
+ wbsTreeZi.setWbsId(wbsTreeFu.getWbsId());
|
|
|
+ wbsTreeZi.setParentId(wbsTreeFu.getParentId());
|
|
|
+ wbsTreeZi.setAncestors(wbsTreeFu.getAncestors());
|
|
|
+ wbsTreeZi.setProjectNodeId(wbsTree1.getProjectNodeId());
|
|
|
+ //新增节点返回未创建成功查询出来的wbsTree对象、创建成功后的wbsTreeZi对象
|
|
|
+ WbsTree wbsTree = importTree(wbsTreeZi);
|
|
|
+ //后置初始化默认值
|
|
|
+ if (wbsTree == null) {
|
|
|
+ Long id = wbsTreeZi.getId();
|
|
|
+ //设置ancestors祖级id集合
|
|
|
+ StringBuilder stringBuffer = new StringBuilder();
|
|
|
+ StringBuilder appendStr = stringBuffer.append(",").append(wbsTreeZi.getParentId());
|
|
|
+ String ancestors = wbsTreeZi.getAncestors() + appendStr;
|
|
|
+ //修改ancestors的值
|
|
|
+ updateDate(ancestors, id);
|
|
|
+ wbsTreeFu.setParentId(id);
|
|
|
+ wbsTreeFu.setAncestors(ancestors);
|
|
|
+ } else {
|
|
|
+ wbsTreeFu.setParentId(wbsTree.getId());
|
|
|
+ wbsTreeFu.setAncestors(wbsTree.getAncestors());
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- //修改根节点ProjectNodeId
|
|
|
- baseMapper.updateById(wbsTree1);
|
|
|
- File file2 = new File(canonicalPath);
|
|
|
- if (file2.isFile() && file2.exists()) {
|
|
|
- System.gc(); //回收资源
|
|
|
- file2.delete();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //修改根节点ProjectNodeId
|
|
|
+ baseMapper.updateById(wbsTree1);
|
|
|
+ return "2";
|
|
|
+ } catch (Exception e) {
|
|
|
+ return "1";
|
|
|
+ } finally {
|
|
|
+ File file2 = new File(canonicalPath);
|
|
|
+ if (file2.isFile() && file2.exists()) {
|
|
|
+ file2.delete();
|
|
|
+ System.gc(); //回收资源
|
|
|
+ }
|
|
|
}
|
|
|
- return true;
|
|
|
}
|
|
|
|
|
|
|