|
@@ -7,14 +7,102 @@ import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
+import org.springblade.core.secure.BladeUser;
|
|
|
+import org.springblade.core.secure.utils.SecureUtil;
|
|
|
+import org.springblade.core.tool.utils.Func;
|
|
|
+import org.springblade.manager.vo.ImportWbsNodeVO;
|
|
|
+import org.springblade.manager.vo.WbsTreeContractVO;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.*;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
public class WbsExcelUtil {
|
|
|
|
|
|
+ /*public static void main(String[] args) throws IOException, ClassNotFoundException {
|
|
|
+ WbsExcelUtil excelUtil = new WbsExcelUtil();
|
|
|
+ //读取excel数据
|
|
|
+ ArrayList<Map<String, String>> result = excelUtil.readExcelToObj("C:\\Users\\泓创开发\\Desktop\\excel节点模板\\隧道工程.xls");
|
|
|
+ //result.forEach(System.out::println);
|
|
|
+
|
|
|
+ //构造
|
|
|
+ List<ImportWbsNodeVO> list = new ArrayList<>();
|
|
|
+ int rowNumber = 1;
|
|
|
+ for (Map<String, String> row : result) { //行
|
|
|
+
|
|
|
+ List<String> parentCode = new ArrayList<>();
|
|
|
+ Map<String, ImportWbsNodeVO> mapCol = new HashMap<>();
|
|
|
+
|
|
|
+ for (Map.Entry<String, String> col : row.entrySet()) { //列
|
|
|
+ ImportWbsNodeVO wbsNodeVO = new ImportWbsNodeVO();
|
|
|
+ if (col.getValue().equals("")) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (mapCol.size() > 0) {
|
|
|
+ wbsNodeVO.setRow(rowNumber);
|
|
|
+ wbsNodeVO.setId(SnowFlakeUtil.getId());
|
|
|
+ wbsNodeVO.setNodeName(col.getValue());
|
|
|
+ wbsNodeVO.setNodeType(col.getKey());
|
|
|
+ wbsNodeVO.setAncestors(null);
|
|
|
+ wbsNodeVO.setCode(rowNumber + "-" + col.getKey());
|
|
|
+
|
|
|
+ parentCode.add(wbsNodeVO.getCode());
|
|
|
+ Iterator<String> iterator = parentCode.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ String next = iterator.next();
|
|
|
+ if (!next.equals(wbsNodeVO.getCode())) {
|
|
|
+ wbsNodeVO.setParentCode(next);
|
|
|
+ if (wbsNodeVO.getParentCode() != null) {
|
|
|
+ iterator.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取上级obj
|
|
|
+ Iterator<Map.Entry<String, ImportWbsNodeVO>> iteratorMap = mapCol.entrySet().iterator();
|
|
|
+ while (iteratorMap.hasNext()) {
|
|
|
+ Map.Entry<String, ImportWbsNodeVO> importWbsNodeVOEntry = iteratorMap.next();
|
|
|
+ if (wbsNodeVO.getParentCode().equals(importWbsNodeVOEntry.getValue().getCode())) {
|
|
|
+ wbsNodeVO.setParentId(importWbsNodeVOEntry.getValue().getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ mapCol.put(wbsNodeVO.getNodeType(), wbsNodeVO);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ wbsNodeVO.setRow(rowNumber);
|
|
|
+ wbsNodeVO.setId(SnowFlakeUtil.getId());
|
|
|
+ wbsNodeVO.setNodeName(col.getValue());
|
|
|
+ wbsNodeVO.setNodeType(col.getKey());
|
|
|
+ wbsNodeVO.setParentId(0L);
|
|
|
+ wbsNodeVO.setAncestors(null);
|
|
|
+ wbsNodeVO.setCode(rowNumber + "-" + col.getKey());
|
|
|
+
|
|
|
+ parentCode.add(wbsNodeVO.getCode());
|
|
|
+ Iterator<String> iterator = parentCode.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ String next = iterator.next();
|
|
|
+ if (!next.equals(wbsNodeVO.getCode())) {
|
|
|
+ wbsNodeVO.setParentCode(next);
|
|
|
+ if (wbsNodeVO.getParentCode() != null) {
|
|
|
+ iterator.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mapCol.put(wbsNodeVO.getNodeType(), wbsNodeVO);
|
|
|
+ }
|
|
|
+ list.add(wbsNodeVO);
|
|
|
+ }
|
|
|
+ rowNumber++;
|
|
|
+ }
|
|
|
+
|
|
|
+ list.forEach(System.out::println);
|
|
|
+
|
|
|
+ }*/
|
|
|
|
|
|
/**
|
|
|
* 读取excel数据
|