|
@@ -9,9 +9,7 @@ import org.junit.Test;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -21,135 +19,165 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
public class ExcelUtils {
|
|
|
|
|
|
- public static Object parseCell(Cell cell, String type) {
|
|
|
- if (cell == null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- CellType cellType = cell.getCellTypeEnum();
|
|
|
- if ("string".equalsIgnoreCase(type)) {
|
|
|
- if (cellType == CellType.STRING) {
|
|
|
- String val = cell.getStringCellValue();
|
|
|
- return val == null ? null : val.trim();
|
|
|
- } else if (cellType == CellType.NUMERIC) {
|
|
|
- return cell.getNumericCellValue() + "";
|
|
|
- }
|
|
|
- } else if ("integer".equalsIgnoreCase(type)) {
|
|
|
- if (cellType == CellType.STRING) {
|
|
|
- String stringCellValue = cell.getStringCellValue();
|
|
|
- return stringCellValue == null ? null : Double.valueOf(stringCellValue).intValue();
|
|
|
- } else if (cellType == CellType.NUMERIC) {
|
|
|
- return Double.valueOf(cell.getNumericCellValue()).intValue();
|
|
|
- }
|
|
|
- } else if ("double".equalsIgnoreCase(type)) {
|
|
|
- if (cellType == CellType.STRING) {
|
|
|
- String stringCellValue = cell.getStringCellValue();
|
|
|
- return stringCellValue == null ? null : Double.valueOf(stringCellValue);
|
|
|
- } else if (cellType == CellType.NUMERIC) {
|
|
|
- return cell.getNumericCellValue();
|
|
|
- }
|
|
|
- } else if ("date".equalsIgnoreCase(type)) {
|
|
|
- if (cellType == CellType.NUMERIC) {
|
|
|
- Date dateCellValue = cell.getDateCellValue();
|
|
|
- return dateCellValue == null ? null : dateCellValue;
|
|
|
- } else if (cellType == CellType.STRING) {
|
|
|
- String val = cell.getStringCellValue();
|
|
|
- return val == null ? null : val.trim();
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
+ public static Object parseCell(Cell cell, String type) {
|
|
|
+ if (cell == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ CellType cellType = cell.getCellTypeEnum();
|
|
|
+ if ("string".equalsIgnoreCase(type)) {
|
|
|
+ if (cellType == CellType.STRING) {
|
|
|
+ String val = cell.getStringCellValue();
|
|
|
+ return val == null ? null : val.trim();
|
|
|
+ } else if (cellType == CellType.NUMERIC) {
|
|
|
+ return cell.getNumericCellValue() + "";
|
|
|
+ }
|
|
|
+ } else if ("integer".equalsIgnoreCase(type)) {
|
|
|
+ if (cellType == CellType.STRING) {
|
|
|
+ String stringCellValue = cell.getStringCellValue();
|
|
|
+ return stringCellValue == null ? null : Double.valueOf(stringCellValue).intValue();
|
|
|
+ } else if (cellType == CellType.NUMERIC) {
|
|
|
+ return Double.valueOf(cell.getNumericCellValue()).intValue();
|
|
|
+ }
|
|
|
+ } else if ("double".equalsIgnoreCase(type)) {
|
|
|
+ if (cellType == CellType.STRING) {
|
|
|
+ String stringCellValue = cell.getStringCellValue();
|
|
|
+ return stringCellValue == null ? null : Double.valueOf(stringCellValue);
|
|
|
+ } else if (cellType == CellType.NUMERIC) {
|
|
|
+ return cell.getNumericCellValue();
|
|
|
+ }
|
|
|
+ } else if ("date".equalsIgnoreCase(type)) {
|
|
|
+ if (cellType == CellType.NUMERIC) {
|
|
|
+ Date dateCellValue = cell.getDateCellValue();
|
|
|
+ return dateCellValue == null ? null : dateCellValue;
|
|
|
+ } else if (cellType == CellType.STRING) {
|
|
|
+ String val = cell.getStringCellValue();
|
|
|
+ return val == null ? null : val.trim();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- private String basepath = "/Users/devsaga/persagy/数据字典20201118/Ch2-物理世界";
|
|
|
+ private String basepath = "C:/Users/24341/Downloads/数据字典附表(20210311)";
|
|
|
|
|
|
- @Test
|
|
|
- public void test1() throws Exception {
|
|
|
- String path = basepath + "/2.2-设备设施类对象/2.2.3-系统";
|
|
|
- showPath(path);
|
|
|
- }
|
|
|
+ @Test
|
|
|
+ public void test1() throws Exception {
|
|
|
+ String path = basepath + "/附表7-系统类对象分类属性点表";
|
|
|
+ showPath(path);
|
|
|
+ }
|
|
|
|
|
|
- public void showPath(String path) throws Exception {
|
|
|
- List<String> names = listFile(path);
|
|
|
- if (names != null) {
|
|
|
- for (String name : names) {
|
|
|
+ public void showPath(String path) throws Exception {
|
|
|
+ Map<String, String> dtType = new HashMap<>();
|
|
|
+ dtType.put("SE", "强电");
|
|
|
+ dtType.put("WE", "弱电");
|
|
|
+ dtType.put("AC", "空调");
|
|
|
+ dtType.put("FF", "消防");
|
|
|
+ dtType.put("SP", "安防");
|
|
|
+ dtType.put("WS", "给排水");
|
|
|
+ dtType.put("CF", "土建");
|
|
|
+ dtType.put("OT", "其他");
|
|
|
+ List<String> names = listFile(path);
|
|
|
+ if (names != null) {
|
|
|
+ for (String name : names) {
|
|
|
// System.out.println("----------------------");
|
|
|
- String fileName = path + "/" + name;
|
|
|
- FileInputStream inputStream = new FileInputStream(fileName);
|
|
|
+ String fileName = path + "/" + name;
|
|
|
+ FileInputStream inputStream = new FileInputStream(fileName);
|
|
|
// System.out.println(fileName);
|
|
|
- Workbook workbook = new XSSFWorkbook(inputStream);
|
|
|
- int numberOfSheets = workbook.getNumberOfSheets();
|
|
|
- for (int i = 0; i < numberOfSheets; i++) {
|
|
|
- Sheet sheet = workbook.getSheetAt(i);
|
|
|
- String sheetName = sheet.getSheetName();
|
|
|
- // funcids.addAll(readSheet("FFFA", "/2.2-设备设施类对象/2.2.3-系统/50-消防专业系统.xlsx", "FA火灾报警系统"));
|
|
|
- System.out.println("funcids.addAll(readSheet(\"" + sheetName.substring(0, 4) + "\", \"" + fileName + "\", \"" + sheetName + "\"));");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ Workbook workbook = new XSSFWorkbook(inputStream);
|
|
|
+ int numberOfSheets = workbook.getNumberOfSheets();
|
|
|
+ for (int i = 0; i < numberOfSheets; i++) {
|
|
|
+ Sheet sheet = workbook.getSheetAt(i);
|
|
|
+ String sheetName = sheet.getSheetName();
|
|
|
+ // funcids.addAll(readSheet("FFFA", "/2.2-设备设施类对象/2.2.3-系统/50-消防专业系统.xlsx", "FA火灾报警系统"));
|
|
|
+ dtType.entrySet().forEach(item -> {
|
|
|
+ String key = item.getKey();
|
|
|
+ String value = item.getValue();
|
|
|
+ if (name.contains(value)) {
|
|
|
+ System.out.println("funcids.addAll(readSheet(\"" + key + sheetName.substring(0, 2) + "\", \"/附表7-系统类对象分类属性点表/" + name + "\", \"" + sheetName + "\"));");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- @Test
|
|
|
- public void test2() throws Exception {
|
|
|
- showPathForEquipment(basepath + "/2.2-设备设施类对象/2.2.4-设备设施/" + "1-强电专业");
|
|
|
- showPathForEquipment(basepath + "/2.2-设备设施类对象/2.2.4-设备设施/" + "2-弱电专业");
|
|
|
- showPathForEquipment(basepath + "/2.2-设备设施类对象/2.2.4-设备设施/" + "3-空调专业");
|
|
|
- showPathForEquipment(basepath + "/2.2-设备设施类对象/2.2.4-设备设施/" + "4-给排水专业");
|
|
|
- showPathForEquipment(basepath + "/2.2-设备设施类对象/2.2.4-设备设施/" + "5-消防专业");
|
|
|
- showPathForEquipment(basepath + "/2.2-设备设施类对象/2.2.4-设备设施/" + "6-安防专业");
|
|
|
- showPathForEquipment(basepath + "/2.2-设备设施类对象/2.2.4-设备设施/" + "7-土建精装专业");
|
|
|
- showPathForEquipment(basepath + "/2.2-设备设施类对象/2.2.4-设备设施/" + "8-其他");
|
|
|
- }
|
|
|
+ @Test
|
|
|
+ public void test2() throws Exception {
|
|
|
+ showPathForEquipment(basepath, "/附表8-设备类对象分类属性点表/" + "附表8.1-强电专业设备", "SE");
|
|
|
+ showPathForEquipment(basepath, "/附表8-设备类对象分类属性点表/" + "附表8.2-弱电专业设备", "WE");
|
|
|
+ showPathForEquipment(basepath, "/附表8-设备类对象分类属性点表/" + "附表8.3-空调专业设备", "AC");
|
|
|
+ showPathForEquipment(basepath, "/附表8-设备类对象分类属性点表/" + "附表8.4-给排水专业设备", "WS");
|
|
|
+ showPathForEquipment(basepath, "/附表8-设备类对象分类属性点表/" + "附表8.5-消防专业设备", "FF");
|
|
|
+ showPathForEquipment(basepath, "/附表8-设备类对象分类属性点表/" + "附表8.6-安防专业设备", "SP");
|
|
|
+ showPathForEquipment(basepath, "/附表8-设备类对象分类属性点表/" + "附表8.7-土建精装专业设备", "CF");
|
|
|
+ showPathForEquipment(basepath, "/附表8-设备类对象分类属性点表/" + "附表8.8-其他专业设备", "OT");
|
|
|
+ }
|
|
|
|
|
|
- public void showPathForEquipment(String path) throws Exception {
|
|
|
- List<String> names = listFile(path);
|
|
|
- if (names != null) {
|
|
|
- for (String name : names) {
|
|
|
+ public void showPathForEquipment(String path, String pathName, String key) throws Exception {
|
|
|
+ List<String> names = listFile(path + pathName);
|
|
|
+ if (names != null) {
|
|
|
+ for (String name : names) {
|
|
|
// System.out.println("----------------------");
|
|
|
- String fileName = path + "/" + name;
|
|
|
- FileInputStream inputStream = new FileInputStream(fileName);
|
|
|
+ String fileName = path + pathName + "/" + name;
|
|
|
+ FileInputStream inputStream = new FileInputStream(fileName);
|
|
|
// System.out.println(fileName);
|
|
|
- Workbook workbook = new XSSFWorkbook(inputStream);
|
|
|
- int numberOfSheets = workbook.getNumberOfSheets();
|
|
|
- for (int i = 0; i < numberOfSheets; i++) {
|
|
|
- Sheet sheet = workbook.getSheetAt(i);
|
|
|
- String sheetName = sheet.getSheetName();
|
|
|
- // funcids.addAll(readSheet("FFFA", "/2.2-设备设施类对象/2.2.3-系统/50-消防专业系统.xlsx", "FA火灾报警系统"));
|
|
|
- System.out.println("funcids.addAll(readSheet(\"" + sheetName.substring(0, 4) + "\", \"" + fileName + "\", \"" + sheetName + "\"));");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ Workbook workbook = new XSSFWorkbook(inputStream);
|
|
|
+ int numberOfSheets = workbook.getNumberOfSheets();
|
|
|
+ for (int i = 0; i < numberOfSheets; i++) {
|
|
|
+ Sheet sheet = workbook.getSheetAt(i);
|
|
|
+ String sheetName = sheet.getSheetName();
|
|
|
+ // funcids.addAll(readSheet("FFFA", "/2.2-设备设施类对象/2.2.3-系统/50-消防专业系统.xlsx", "FA火灾报警系统"));
|
|
|
+ System.out.println("funcids.addAll(readSheet(\"" + key + sheetName.substring(0, 4) + "\", \"" + pathName + "/" + name + "\", \"" + sheetName + "\"));");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- @Test
|
|
|
- public void test3() throws Exception {
|
|
|
- showPathForComponent(basepath + "/2.2-设备设施类对象/2.2.5-部件");
|
|
|
- }
|
|
|
+ @Test
|
|
|
+ public void test3() throws Exception {
|
|
|
+ showPathForComponent(basepath + "/附表9-部件类对象分类属性点表");
|
|
|
+ }
|
|
|
|
|
|
- public void showPathForComponent(String path) throws Exception {
|
|
|
- List<String> names = listFile(path);
|
|
|
- if (names != null) {
|
|
|
- for (String name : names) {
|
|
|
+ public void showPathForComponent(String path) throws Exception {
|
|
|
+ Map<String, String> dtType = new HashMap<>();
|
|
|
+ dtType.put("SE", "强电");
|
|
|
+ dtType.put("WE", "弱电");
|
|
|
+ dtType.put("AC", "空调");
|
|
|
+ dtType.put("FF", "消防");
|
|
|
+ dtType.put("SP", "安防");
|
|
|
+ dtType.put("WS", "给排水");
|
|
|
+ dtType.put("CF", "土建");
|
|
|
+ dtType.put("OT", "其他");
|
|
|
+ List<String> names = listFile(path);
|
|
|
+ if (names != null) {
|
|
|
+ for (String name : names) {
|
|
|
// System.out.println("----------------------");
|
|
|
- String fileName = path + "/" + name;
|
|
|
- FileInputStream inputStream = new FileInputStream(fileName);
|
|
|
+ String fileName = path + "/" + name;
|
|
|
+ FileInputStream inputStream = new FileInputStream(fileName);
|
|
|
// System.out.println(fileName);
|
|
|
- Workbook workbook = new XSSFWorkbook(inputStream);
|
|
|
- int numberOfSheets = workbook.getNumberOfSheets();
|
|
|
- for (int i = 0; i < numberOfSheets; i++) {
|
|
|
- Sheet sheet = workbook.getSheetAt(i);
|
|
|
- String sheetName = sheet.getSheetName();
|
|
|
- // funcids.addAll(readSheet("FFFA", "/2.2-设备设施类对象/2.2.3-系统/50-消防专业系统.xlsx", "FA火灾报警系统"));
|
|
|
- System.out.println("funcids.addAll(readSheet(\"" + sheetName.substring(0, 6) + "\", \"" + fileName + "\", \"" + sheetName + "\"));");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ Workbook workbook = new XSSFWorkbook(inputStream);
|
|
|
+ int numberOfSheets = workbook.getNumberOfSheets();
|
|
|
+ for (int i = 0; i < numberOfSheets; i++) {
|
|
|
+ Sheet sheet = workbook.getSheetAt(i);
|
|
|
+ String sheetName = sheet.getSheetName();
|
|
|
+ // funcids.addAll(readSheet("FFFA", "/2.2-设备设施类对象/2.2.3-系统/50-消防专业系统.xlsx", "FA火灾报警系统"));
|
|
|
+ dtType.entrySet().forEach(item -> {
|
|
|
+ String key = item.getKey();
|
|
|
+ String value = item.getValue();
|
|
|
+ if (name.contains(value)) {
|
|
|
+ System.out.println("funcids.addAll(readSheet(\"" + key + sheetName.substring(0, 6) + "\", \"/附表9-部件类对象分类属性点表/" + name + "\", \"" + sheetName + "\"));");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- private List<String> listFile(String path) {
|
|
|
- File file = new File(path);
|
|
|
- File[] files = file.listFiles();
|
|
|
- return Arrays.stream(files).map(File::getName).filter(item -> !item.startsWith("~")).collect(Collectors.toList());
|
|
|
- }
|
|
|
+ private List<String> listFile(String path) {
|
|
|
+ File file = new File(path);
|
|
|
+ File[] files = file.listFiles();
|
|
|
+ return Arrays.stream(files).map(File::getName).filter(item -> !item.startsWith("~")).collect(Collectors.toList());
|
|
|
+ }
|
|
|
|
|
|
}
|