2 Commits 4ab6071c1a ... cd14d057ec

Autore SHA1 Messaggio Data
  fengyanjie cd14d057ec Merge remote-tracking branch 'origin/master' 3 anni fa
  fengyanjie 59fb457a53 修改枚举值从知识库取值 3 anni fa

+ 1 - 1
dmp-rwd-datautils/src/test/java/com/persagy/dmp/rwd/dic/ExcelUtils.java

@@ -58,7 +58,7 @@ public class ExcelUtils {
     }
 
 
-    private String basepath = "C:/Users/24341/Downloads/数据字典附表(20210311)";
+    private String basepath = "C:\\Users\\24341\\Downloads\\数据字典附表(20210412)";
 
     @Test
     public void test1() throws Exception {

+ 167 - 116
dmp-rwd-datautils/src/test/java/com/persagy/dmp/rwd/dic/FuncidUtils.java

@@ -1,13 +1,21 @@
 package com.persagy.dmp.rwd.dic;
 
+import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
 import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.common.criteria.JacksonCriteria;
+import com.persagy.common.json.JacksonMapper;
+import com.persagy.dmp.common.http.HttpUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * @author: yaoll
@@ -16,120 +24,163 @@ import java.util.Set;
  */
 public class FuncidUtils {
 
-	private final static Set<String> baseFuncid = new HashSet<>();
-
-	static {
-		baseFuncid.add("ProjID");
-		baseFuncid.add("ProjName");
-		baseFuncid.add("ProjLocalID");
-		baseFuncid.add("ProjLocalName");
-		baseFuncid.add("BuildID");
-		baseFuncid.add("BuildName");
-		baseFuncid.add("BuildLocalID");
-		baseFuncid.add("BuildLocalName");
-		baseFuncid.add("FloorID");
-		baseFuncid.add("FloorName");
-		baseFuncid.add("FloorLocalID");
-		baseFuncid.add("FloorLocalName");
-		baseFuncid.add("RoomID");
-		baseFuncid.add("RoomName");
-		baseFuncid.add("RoomLocalID");
-		baseFuncid.add("RoomLocalName");
-		baseFuncid.add("ShaftID");
-		baseFuncid.add("ShaftName");
-		baseFuncid.add("ShaftLocalID");
-		baseFuncid.add("ShaftLocalName");
-		baseFuncid.add("SysID");
-		baseFuncid.add("SysName");
-		baseFuncid.add("SysLocalID");
-		baseFuncid.add("SysLocalName");
-		baseFuncid.add("EquipID");
-		baseFuncid.add("EquipName");
-		baseFuncid.add("EquipLocalID");
-		baseFuncid.add("EquipLocalName");
-		baseFuncid.add("ToolID");
-		baseFuncid.add("ToolName");
-		baseFuncid.add("ToolLocalID");
-		baseFuncid.add("ToolLocalName");
-		baseFuncid.add("ConsumID");
-		baseFuncid.add("ConsumName");
-		baseFuncid.add("ConsumLocalID");
-		baseFuncid.add("ConsumLocalName");
-
-		baseFuncid.add("ECModelID");
-		baseFuncid.add("ECModelName");
-		baseFuncid.add("ECModelLocalID");
-		baseFuncid.add("ECModelLocalName");
-
-		baseFuncid.add("SubentryID");
-		baseFuncid.add("SubentryName");
-		baseFuncid.add("SubentryLocalID");
-		baseFuncid.add("SubentryLocalName");
-
-		baseFuncid.add("BranchID");
-		baseFuncid.add("BranchName");
-		baseFuncid.add("BranchLocalID");
-		baseFuncid.add("BranchLocalName");
-
-		baseFuncid.add("BeaconID");
-		baseFuncid.add("BeaconlName");
-		baseFuncid.add("BeaconLocalID");
-		baseFuncid.add("BeaconLocalName");
-
-		baseFuncid.add("TenantID");
-		baseFuncid.add("TenantName");
-		baseFuncid.add("TenantLocalID");
-		baseFuncid.add("TenantLocalName");
-
-	}
-
-	public static boolean isBase(String code) {
-		return baseFuncid.contains(code);
-	}
-
-	public static ArrayNode transEnumDataSource(String dataSource) {
-		ArrayNode array = JsonNodeFactory.instance.arrayNode();
-		if (dataSource == null) {
-			return null;
-		}
-		// 包含换行符 直接返回
-		if (dataSource.indexOf("\n") > -1) {
-			return null;
-		}
-		// 预处理 ". " -> "."
-		while (dataSource.indexOf(". ") > -1) {
-			dataSource = dataSource.replace(". ", ".");
-		}
-		if (dataSource.startsWith("见《")) {
-			return null;
-		} else if (dataSource.indexOf(".") > -1) {
-
-			// 预处理
-			String tmp = dataSource.replace("(多选)", "")
-					.replace("(可多选)", "")
-					.replace("(可以多选)", "");
-
-			// 尝试解析
-			// 1.铸铁 2.钢 3.铝合金 4.铜管 5.复合型 99.其他
-			String[] split = tmp.split(" ");
-			if (split.length == 0) {
-				return null;
-			}
-			Map<String, String> data = new HashMap<>();
-			for (int i = 0; i < split.length; i++) {
-				String temp = split[i];
-				int idx = temp.indexOf(".");
-				if (idx == -1) {
-					continue;
-				}
-				String key = temp.substring(0, idx);
-				String value = temp.substring(idx + 1);
-				data.put(key, value);
-				ObjectNode item = array.addObject();
-				item.put("code", key);
-				item.put("name", value);
-			}
-		}
-		return array;
-	}
+    private final static Set<String> baseFuncid = new HashSet<>();
+
+    @Value("${persagy.dmp.rwdedit.server}")
+    private String rwdeditServer;
+
+    @Autowired
+    private HttpUtils httpUtils;
+
+    static {
+        baseFuncid.add("ProjID");
+        baseFuncid.add("ProjName");
+        baseFuncid.add("ProjLocalID");
+        baseFuncid.add("ProjLocalName");
+        baseFuncid.add("BuildID");
+        baseFuncid.add("BuildName");
+        baseFuncid.add("BuildLocalID");
+        baseFuncid.add("BuildLocalName");
+        baseFuncid.add("FloorID");
+        baseFuncid.add("FloorName");
+        baseFuncid.add("FloorLocalID");
+        baseFuncid.add("FloorLocalName");
+        baseFuncid.add("RoomID");
+        baseFuncid.add("RoomName");
+        baseFuncid.add("RoomLocalID");
+        baseFuncid.add("RoomLocalName");
+        baseFuncid.add("ShaftID");
+        baseFuncid.add("ShaftName");
+        baseFuncid.add("ShaftLocalID");
+        baseFuncid.add("ShaftLocalName");
+        baseFuncid.add("SysID");
+        baseFuncid.add("SysName");
+        baseFuncid.add("SysLocalID");
+        baseFuncid.add("SysLocalName");
+        baseFuncid.add("EquipID");
+        baseFuncid.add("EquipName");
+        baseFuncid.add("EquipLocalID");
+        baseFuncid.add("EquipLocalName");
+        baseFuncid.add("ToolID");
+        baseFuncid.add("ToolName");
+        baseFuncid.add("ToolLocalID");
+        baseFuncid.add("ToolLocalName");
+        baseFuncid.add("ConsumID");
+        baseFuncid.add("ConsumName");
+        baseFuncid.add("ConsumLocalID");
+        baseFuncid.add("ConsumLocalName");
+
+        baseFuncid.add("ECModelID");
+        baseFuncid.add("ECModelName");
+        baseFuncid.add("ECModelLocalID");
+        baseFuncid.add("ECModelLocalName");
+
+        baseFuncid.add("SubentryID");
+        baseFuncid.add("SubentryName");
+        baseFuncid.add("SubentryLocalID");
+        baseFuncid.add("SubentryLocalName");
+
+        baseFuncid.add("BranchID");
+        baseFuncid.add("BranchName");
+        baseFuncid.add("BranchLocalID");
+        baseFuncid.add("BranchLocalName");
+
+        baseFuncid.add("BeaconID");
+        baseFuncid.add("BeaconlName");
+        baseFuncid.add("BeaconLocalID");
+        baseFuncid.add("BeaconLocalName");
+
+        baseFuncid.add("TenantID");
+        baseFuncid.add("TenantName");
+        baseFuncid.add("TenantLocalID");
+        baseFuncid.add("TenantLocalName");
+
+    }
+
+    public static boolean isBase(String code) {
+        return baseFuncid.contains(code);
+    }
+
+    public ArrayNode transEnumDataSource(String dataSource) {
+        ArrayNode array = JsonNodeFactory.instance.arrayNode();
+        if (dataSource == null) {
+            return null;
+        }
+        // 包含换行符 直接返回
+        if (dataSource.indexOf("\n") > -1) {
+            return null;
+        }
+        // 预处理 ". " -> "."
+        while (dataSource.indexOf(". ") > -1) {
+            dataSource = dataSource.replace(". ", ".");
+        }
+        if (dataSource.startsWith("见《")) {
+            String name = null;
+            String refKey = null;
+            Pattern pattern = Pattern.compile("《(.*?)》");
+            Matcher matcher = pattern.matcher("见《城市发展水平分级》");
+            while (matcher.find()) {
+                name = matcher.group(1);
+            }
+
+            String url = rwdeditServer + "/rwdedit/ref/type/query";
+            JacksonCriteria criteria = JacksonCriteria.newInstance();
+            criteria.add("name", name);
+            HttpUtils.HttpResult response = httpUtils.post(url, JacksonMapper.toSimpleJson(criteria), 3600000);
+            if (!response.success()) {
+                return null;
+            }
+            String content = response.getContent();
+            ObjectNode objectNode = JacksonMapper.toObject(content, ObjectNode.class);
+            ArrayNode data = JacksonMapper.getArray(objectNode, "data", JsonNodeFactory.instance.arrayNode());
+            refKey = JacksonMapper.getString((ObjectNode) data.get(0), "refKey");
+            if (null == refKey) {
+                return null;
+            }
+            criteria = JacksonCriteria.newInstance();
+            criteria.add("refKey", refKey);
+            response = httpUtils.post(url, JacksonMapper.toSimpleJson(criteria), 3600000);
+            if (!response.success()) {
+                return null;
+            }
+            content = response.getContent();
+            objectNode = JacksonMapper.toObject(content, ObjectNode.class);
+            data = JacksonMapper.getArray(objectNode, "data", JsonNodeFactory.instance.arrayNode());
+            for (JsonNode datum : data) {
+                ObjectNode obj = (ObjectNode) datum;
+                ObjectNode item = array.addObject();
+                item.put("code", JacksonMapper.getString(obj, "code"));
+                item.put("name", JacksonMapper.getString(obj, "name"));
+                item.put("parentCode", JacksonMapper.getString(obj, "parentCode"));
+            }
+        } else if (dataSource.indexOf(".") > -1) {
+
+            // 预处理
+            String tmp = dataSource.replace("(多选)", "")
+                    .replace("(可多选)", "")
+                    .replace("(可以多选)", "");
+
+            // 尝试解析
+            // 1.铸铁 2.钢 3.铝合金 4.铜管 5.复合型 99.其他
+            String[] split = tmp.split(" ");
+            if (split.length == 0) {
+                return null;
+            }
+            Map<String, String> data = new HashMap<>();
+            for (int i = 0; i < split.length; i++) {
+                String temp = split[i];
+                int idx = temp.indexOf(".");
+                if (idx == -1) {
+                    continue;
+                }
+                String key = temp.substring(0, idx);
+                String value = temp.substring(idx + 1);
+                data.put(key, value);
+                ObjectNode item = array.addObject();
+                item.put("code", key);
+                item.put("name", value);
+            }
+        }
+        return array;
+    }
 }

+ 3 - 2
dmp-rwd-datautils/src/test/java/com/persagy/dmp/rwd/dic/ImportClass.java

@@ -24,9 +24,9 @@ import java.util.*;
 @Slf4j
 public class ImportClass {
 
-    private String basepath = "C:/Users/24341/Downloads/数据字典附表(20210311)";
+    private String basepath = "C:\\Users\\24341\\Downloads\\数据字典附表(20210412)";
 
-    private String outPath = "C:/Users/24341/Downloads/20200316/class-" + DateUtils.format(new Date()) + ".dml.sql";
+    private String outPath = "C:/Users/24341/Downloads/20210413/class-" + DateUtils.format(new Date()) + ".dml.sql";
 
     @Test
     public void importClassData() throws Exception {
@@ -280,6 +280,7 @@ public class ImportClass {
         classes.add(prepareModel("space", "SecurityZone", "安防分区", "space", null, null));
         classes.add(prepareModel("space", "TenantZone", "租户分区", "space", null, null));
         classes.add(prepareModel("space", "FunctionZone", "功能分区", "space", null, null));
+        classes.add(prepareModel("space", "PassengerFlowZone", "客流分区", "space", null, null));
         classes.add(prepareModel("space", "OtherZone", "其他分区", "space", null, null));
     }
 

+ 5 - 3
dmp-rwd-datautils/src/test/java/com/persagy/dmp/rwd/dic/ImportFuncid.java

@@ -25,9 +25,9 @@ import java.util.UUID;
 @Slf4j
 public class ImportFuncid {
 
-    private String basepath = "C:/Users/24341/Downloads/数据字典附表(20210311)";
+    private String basepath = "C:\\Users\\24341\\Downloads\\数据字典附表(20210412)";
 
-    private String outPath = "C:/Users/24341/Downloads/20200316/funcid-" + DateUtils.format(new Date()) + ".dml.sql";
+    private String outPath = "C:/Users/24341/Downloads/20210413/funcid-" + DateUtils.format(new Date()) + ".dml.sql";
 
     @Test
     public void importFuncidDef() throws IOException {
@@ -168,7 +168,8 @@ public class ImportFuncid {
             funcid.setOrigDataSource(model.origDataSource.replace("\n", "nn")); // 去掉换行符
         }
         if (funcid.getDataType() == FuncidDataType.ENUM || funcid.getDataType() == FuncidDataType.MENUM || funcid.getDataType() == FuncidDataType.BOOLEAN) {
-            funcid.setDataSource(FuncidUtils.transEnumDataSource(model.origDataSource)); // 解析datasource
+            FuncidUtils funcidUtils = new FuncidUtils();
+            funcid.setDataSource(funcidUtils.transEnumDataSource(model.origDataSource)); // 解析datasource
         }
         return funcid;
     }
@@ -684,6 +685,7 @@ public class ImportFuncid {
         funcids.addAll(readSheet("SETDHSIP", "/附表9-部件类对象分类属性点表/附表9.1-强电专业部件.xlsx", "TDHSIP综合保护装置"));
         funcids.addAll(readSheet("SETDLSDW", "/附表9-部件类对象分类属性点表/附表9.1-强电专业部件.xlsx", "TDLSDW低压配电抽屉"));
         funcids.addAll(readSheet("WEBADCBP", "/附表9-部件类对象分类属性点表/附表9.2-弱电专业部件.xlsx", "BADCBP总线端口"));
+        funcids.addAll(readSheet("ACCCSCMT", "/附表9-部件类对象分类属性点表/附表9.3-空调专业部件.xlsx", "CCSCMT螺杆式冷水机组电机"));
         funcids.addAll(readSheet("ACCCGHBP", "/附表9-部件类对象分类属性点表/附表9.3-空调专业部件.xlsx", "CCGHBP地埋管"));
         funcids.addAll(readSheet("ACCCOTFN", "/附表9-部件类对象分类属性点表/附表9.3-空调专业部件.xlsx", "CCOTFN冷却塔风机"));
 //        funcids.addAll(readSheet("WSSheet1", "/附表9-部件类对象分类属性点表/附表9.4-给排水专业部件.xlsx", "Sheet1"));

+ 2 - 1
dmp-rwd-datautils/src/test/java/com/persagy/dmp/rwd/dic/ImportFuncid2.java

@@ -161,7 +161,8 @@ public class ImportFuncid2 {
 			funcid.setOrigDataSource(model.origDataSource.replace("\n", "nn")); // 去掉换行符
 		}
 		if (funcid.getDataType() == FuncidDataType.ENUM || funcid.getDataType() == FuncidDataType.MENUM || funcid.getDataType() == FuncidDataType.BOOLEAN) {
-			funcid.setDataSource(FuncidUtils.transEnumDataSource(model.origDataSource)); // 解析datasource
+			FuncidUtils funcidUtils = new FuncidUtils();
+			funcid.setDataSource(funcidUtils.transEnumDataSource(model.origDataSource)); // 解析datasource
 		}
 		return funcid;
 	}

+ 4 - 2
dmp-rwd-datautils/src/test/java/com/persagy/dmp/rwd/dic/ImportGroupProjectFuncid.java

@@ -102,7 +102,8 @@ public class ImportGroupProjectFuncid {
 			}
 			model.setOrigDataSource(origDataSource);
 			if (model.getDataType() == FuncidDataType.ENUM || model.getDataType() == FuncidDataType.MENUM || model.getDataType() == FuncidDataType.BOOLEAN) {
-				model.setDataSource(FuncidUtils.transEnumDataSource(origDataSource)); // 解析datasource
+				FuncidUtils funcidUtils = new FuncidUtils();
+				model.setDataSource(funcidUtils.transEnumDataSource(origDataSource)); // 解析datasource
 			}
 
 			String note = (String) ExcelUtils.parseCell(row.getCell(12), "string");
@@ -234,7 +235,8 @@ public class ImportGroupProjectFuncid {
 			funcid.setOrigDataSource(model.origDataSource.replace("\n", "nn")); // 去掉换行符
 		}
 		if (funcid.getDataType() == FuncidDataType.ENUM || funcid.getDataType() == FuncidDataType.MENUM || funcid.getDataType() == FuncidDataType.BOOLEAN) {
-			funcid.setDataSource(FuncidUtils.transEnumDataSource(model.origDataSource)); // 解析datasource
+			FuncidUtils funcidUtils = new FuncidUtils();
+			funcid.setDataSource(funcidUtils.transEnumDataSource(model.origDataSource)); // 解析datasource
 		}
 		return funcid;
 	}

+ 332 - 331
dmp-rwd-datautils/src/test/java/com/persagy/dmp/rwd/dic/UpdateInfoCodeTag.java

@@ -25,338 +25,339 @@ import java.util.UUID;
 @Slf4j
 public class UpdateInfoCodeTag {
 
-	private String basepath = "/Users/devsaga/trans";
-
-	private String outPath = "/Users/devsaga/trans/funcid-" + DateUtils.format(new Date()) + ".dml.sql";
-
-	@Test
-	public void test1() throws IOException {
-		String majorCode = "OT";
-		String file = basepath + "/85-传感器.xlsx";
-
-		FileInputStream inputStream = new FileInputStream(file);
-		Workbook workbook = new XSSFWorkbook(inputStream);
-
-		int numberOfSheets = workbook.getNumberOfSheets();
-
-		List<FuncidDefModel> data = new LinkedList<>();
-
-		for (int i = 0; i < numberOfSheets; i++) {
-			Sheet sheet = workbook.getSheetAt(i);
-			String sheetName = sheet.getSheetName();
-			System.out.println(sheetName);
-
-			String classCode = majorCode + sheetName.substring(0, 4);
-
-
-			int startRowNum = 2;
-			int lastRowNum = sheet.getLastRowNum();
-			CacheModel cache = new CacheModel();
-			for (int rowIndex = startRowNum; rowIndex <= lastRowNum; rowIndex++) {
-				Row row = sheet.getRow(rowIndex);
-				if (row == null) {
-					log.info("file: {}, sheet: {}, row[{}] is null", null, sheetName, rowIndex);
-					continue;
-				}
-				// 0:firstTag, 1:secondTag, 2:name, 3:origCode, 4:unit, 5:origDataType, 6:priorite, 7:imputMode, 8:origDataSource, 9:remark
-				CacheModel target = new CacheModel();
-				target.classCode = classCode;
-				target.firstTag = (String) ExcelUtils.parseCell(row.getCell(0), "string");
-				target.secondTag = (String) ExcelUtils.parseCell(row.getCell(1), "string");
-				target.name = (String) ExcelUtils.parseCell(row.getCell(2), "string");
-				target.origCode = (String) ExcelUtils.parseCell(row.getCell(3), "string");
-				target.unit = (String) ExcelUtils.parseCell(row.getCell(4), "string");
-				target.origDataType = (String) ExcelUtils.parseCell(row.getCell(5), "string");
-				target.priority = (String) ExcelUtils.parseCell(row.getCell(6), "string");
-				target.inputMode = (String) ExcelUtils.parseCell(row.getCell(7), "string");
-				target.origDataSource = (String) ExcelUtils.parseCell(row.getCell(8), "string");
-				target.remark = (String) ExcelUtils.parseCell(row.getCell(9), "string");
-
-				if (target.origCode == null || "".equals(target.origCode) || "`".equals(target.origCode)) {
-					continue;
-				}
-				if (FuncidUtils.isBase(target.origCode)) {
-					continue;
-				}
-
-				// firstTag不为空
-				if (target.firstTag != null) {
-					cache.firstTag = target.firstTag;
-					cache.secondTag = null;
-				} else {
-					target.firstTag = cache.firstTag;
-				}
-
-				// secondTag
-				if (target.secondTag != null) {
-					cache.secondTag = target.secondTag;
-				} else {
-					target.secondTag = cache.secondTag;
-				}
-				FuncidDefModel funcidDefModel = toFuncidDefModel(target);
-				if (funcidDefModel == null) {
-					log.info("file: {}, sheet: {}, row: {} data type [{}] error", null, sheetName, rowIndex, target.origDataType);
-				} else {
-					data.add(funcidDefModel);
-				}
-			}
-		}
-
-		List<String> sqls = new LinkedList<>();
-		for (FuncidDefModel funcid : data) {
-			//System.out.println(funcid.getClassCode() + "\t" + funcid.getFirstTag() + "\t" + funcid.getSecondTag() + "\t" + funcid.getOrigCode() + "\t" + funcid.getName());
-			// update rwd_def_funcid set first_tag = '', second_tag = '' where class_code = '' and orig_code = '';
-			StringBuilder sql = new StringBuilder();
-			sql.append("update rwd_def_funcid set first_tag = ")
-					.append(funcid.getFirstTag() == null ? null : "'" + funcid.getFirstTag().trim() + "'")
-					.append(", ")
-					.append("second_tag = ")
-					.append(funcid.getSecondTag() == null ? null : "'" + funcid.getSecondTag().trim() + "'")
-					.append(" where class_code = '").append(funcid.getClassCode()).append("'")
-					.append(" and orig_code = '").append(funcid.getOrigCode()).append("';")
-					;
-
-			sqls.add(sql.toString());
-		}
-
-		for (String sql : sqls) {
-			System.out.println(sql);
-		}
-
-		workbook.close();
-		inputStream.close();
-
-	}
-
-	@Test
-	public void importFuncidDef() throws IOException {
-		List<FuncidDefModel> funcids = new LinkedList<>();
-		importEquipment(funcids);
-
-		FileOutputStream fos = new FileOutputStream(outPath);
-		PrintWriter writer = new PrintWriter(new BufferedOutputStream(fos));
-		writer.println("commit;");
-		funcids.forEach(item -> {
+    private String basepath = "/Users/devsaga/trans";
+
+    private String outPath = "/Users/devsaga/trans/funcid-" + DateUtils.format(new Date()) + ".dml.sql";
+
+    @Test
+    public void test1() throws IOException {
+        String majorCode = "OT";
+        String file = basepath + "/85-传感器.xlsx";
+
+        FileInputStream inputStream = new FileInputStream(file);
+        Workbook workbook = new XSSFWorkbook(inputStream);
+
+        int numberOfSheets = workbook.getNumberOfSheets();
+
+        List<FuncidDefModel> data = new LinkedList<>();
+
+        for (int i = 0; i < numberOfSheets; i++) {
+            Sheet sheet = workbook.getSheetAt(i);
+            String sheetName = sheet.getSheetName();
+            System.out.println(sheetName);
+
+            String classCode = majorCode + sheetName.substring(0, 4);
+
+
+            int startRowNum = 2;
+            int lastRowNum = sheet.getLastRowNum();
+            CacheModel cache = new CacheModel();
+            for (int rowIndex = startRowNum; rowIndex <= lastRowNum; rowIndex++) {
+                Row row = sheet.getRow(rowIndex);
+                if (row == null) {
+                    log.info("file: {}, sheet: {}, row[{}] is null", null, sheetName, rowIndex);
+                    continue;
+                }
+                // 0:firstTag, 1:secondTag, 2:name, 3:origCode, 4:unit, 5:origDataType, 6:priorite, 7:imputMode, 8:origDataSource, 9:remark
+                CacheModel target = new CacheModel();
+                target.classCode = classCode;
+                target.firstTag = (String) ExcelUtils.parseCell(row.getCell(0), "string");
+                target.secondTag = (String) ExcelUtils.parseCell(row.getCell(1), "string");
+                target.name = (String) ExcelUtils.parseCell(row.getCell(2), "string");
+                target.origCode = (String) ExcelUtils.parseCell(row.getCell(3), "string");
+                target.unit = (String) ExcelUtils.parseCell(row.getCell(4), "string");
+                target.origDataType = (String) ExcelUtils.parseCell(row.getCell(5), "string");
+                target.priority = (String) ExcelUtils.parseCell(row.getCell(6), "string");
+                target.inputMode = (String) ExcelUtils.parseCell(row.getCell(7), "string");
+                target.origDataSource = (String) ExcelUtils.parseCell(row.getCell(8), "string");
+                target.remark = (String) ExcelUtils.parseCell(row.getCell(9), "string");
+
+                if (target.origCode == null || "".equals(target.origCode) || "`".equals(target.origCode)) {
+                    continue;
+                }
+                if (FuncidUtils.isBase(target.origCode)) {
+                    continue;
+                }
+
+                // firstTag不为空
+                if (target.firstTag != null) {
+                    cache.firstTag = target.firstTag;
+                    cache.secondTag = null;
+                } else {
+                    target.firstTag = cache.firstTag;
+                }
+
+                // secondTag
+                if (target.secondTag != null) {
+                    cache.secondTag = target.secondTag;
+                } else {
+                    target.secondTag = cache.secondTag;
+                }
+                FuncidDefModel funcidDefModel = toFuncidDefModel(target);
+                if (funcidDefModel == null) {
+                    log.info("file: {}, sheet: {}, row: {} data type [{}] error", null, sheetName, rowIndex, target.origDataType);
+                } else {
+                    data.add(funcidDefModel);
+                }
+            }
+        }
+
+        List<String> sqls = new LinkedList<>();
+        for (FuncidDefModel funcid : data) {
+            //System.out.println(funcid.getClassCode() + "\t" + funcid.getFirstTag() + "\t" + funcid.getSecondTag() + "\t" + funcid.getOrigCode() + "\t" + funcid.getName());
+            // update rwd_def_funcid set first_tag = '', second_tag = '' where class_code = '' and orig_code = '';
+            StringBuilder sql = new StringBuilder();
+            sql.append("update rwd_def_funcid set first_tag = ")
+                    .append(funcid.getFirstTag() == null ? null : "'" + funcid.getFirstTag().trim() + "'")
+                    .append(", ")
+                    .append("second_tag = ")
+                    .append(funcid.getSecondTag() == null ? null : "'" + funcid.getSecondTag().trim() + "'")
+                    .append(" where class_code = '").append(funcid.getClassCode()).append("'")
+                    .append(" and orig_code = '").append(funcid.getOrigCode()).append("';")
+            ;
+
+            sqls.add(sql.toString());
+        }
+
+        for (String sql : sqls) {
+            System.out.println(sql);
+        }
+
+        workbook.close();
+        inputStream.close();
+
+    }
+
+    @Test
+    public void importFuncidDef() throws IOException {
+        List<FuncidDefModel> funcids = new LinkedList<>();
+        importEquipment(funcids);
+
+        FileOutputStream fos = new FileOutputStream(outPath);
+        PrintWriter writer = new PrintWriter(new BufferedOutputStream(fos));
+        writer.println("commit;");
+        funcids.forEach(item -> {
 //			System.out.println(JacksonMapper.toSimpleJson(item));
-			writer.println(toSql(item));
-		});
-		writer.println("commit;");
-		writer.flush();
-		writer.close();
-	}
-
-	private String toSql(FuncidDefModel model) {
-		StringBuilder buff = new StringBuilder("");
-		buff.append("insert into rwd_def_funcid ");
-		buff.append("(id,code,orig_code,name,alias_code,alias_name,class_code,type,group_code,project_id,category,");
-		buff.append("first_tag,second_tag,priority,input_mode,unit,data_type,orig_data_type,is_multiple,is_region,formater,data_source,orig_data_source,note,sub_flag,weak_point) ");
-		buff.append("values (");
-		buff.append("'").append(UUID.randomUUID().toString().replace("-", "")).append("',"); // id
-		buff.append("'").append(model.getCode()).append("',"); // code
-		buff.append("'").append(model.getOrigCode()).append("',"); // orig_code
-		buff.append("'").append(model.getName()).append("',"); // name
-		buff.append("'").append(model.getAliasCode()).append("',"); // alias_code
-		buff.append("'").append(model.getAliasName()).append("',"); // alias_name
-		buff.append("'").append(model.getClassCode()).append("',"); // class_code
-		buff.append("'").append(model.getType()).append("',"); // type
-		buff.append("'").append(model.getGroupCode()).append("',"); // group_code
-		buff.append("'").append(model.getProjectId()).append("',"); // project_id
-		buff.append("'").append(model.getCategory().name()).append("',"); // category
-		if (model.getFirstTag() != null) {
-			buff.append("'").append(model.getFirstTag()).append("',"); // first_tag
-		} else {
-			buff.append("null,");
-		}
-		if (model.getSecondTag() != null) {
-			buff.append("'").append(model.getSecondTag()).append("',"); // second_tag
-		} else {
-			buff.append("null,");
-		}
-		if (model.getPriority() != null) {
-			buff.append("'").append(model.getPriority()).append("',"); // priority
-		} else {
-			buff.append("null,");
-		}
-		if (model.getInputMode() != null) {
-			buff.append("'").append(model.getInputMode()).append("',"); // input_mode
-		} else {
-			buff.append("null,");
-		}
-		if (model.getUnit() != null) {
-			buff.append("'").append(model.getUnit()).append("',"); // unit
-		} else {
-			buff.append("null,");
-		}
-
-		buff.append("'").append(model.getDataType().name()).append("',"); // data_type
-		buff.append("'").append(model.getOrigDataType()).append("',"); // orig_data_type
-		buff.append(model.getIsMultiple() ? 1 : 0).append(","); // is_multiple
-		buff.append(model.getIsRegion() ? 1 : 0).append(","); // is_region
-		if (model.getFormater() != null) {
-			buff.append("'").append(model.getFormater()).append("',"); // formater
-		} else {
-			buff.append("null,");
-		}
-		if (model.getDataSource() != null) {
-			buff.append("'").append(model.getDataSource().toString()).append("',"); // data_source
-		} else {
-			buff.append("null,");
-		}
-		if (model.getOrigDataSource() != null) { // orig_data_source
-			buff.append("'").append(model.getOrigDataSource()).append("',"); // data_source
-		} else {
-			buff.append("null,");
-		}
-		if (model.getNote() != null) {
-			buff.append("'").append(model.getNote()).append("',"); // note}
-		} else {
-			buff.append("null,");
-		}
-		buff.append(model.getSubFlag() ? 1 : 0).append(","); // sub_flag
-		buff.append(model.getWeakPoint() ? 1 : 0).append(","); // weak_point
-		buff.deleteCharAt(buff.length() - 1);
-		buff.append(");");
-		return buff.toString();
-	}
-
-	private FuncidDefModel toFuncidDefModel(CacheModel model) {
-		FuncidDefModel funcid = new FuncidDefModel();
-		funcid.setGroupCode("0");
-		funcid.setProjectId("0");
-		funcid.setType("common");
-		funcid.setClassCode(model.classCode);
-		funcid.setFirstTag(model.firstTag != null ? model.firstTag.replace("\n", "") : null);
-		funcid.setSecondTag(model.secondTag != null ? model.secondTag.replace("\n", "") : null);
-		funcid.setCode(model.origCode.substring(0, 1).toLowerCase() + model.origCode.substring(1));
-		funcid.setOrigCode(model.origCode);
-		funcid.setAliasCode(model.origCode);
-		if (model.name != null) {
-			funcid.setName(model.name.replace("\n", ""));
-			funcid.setAliasName(model.name.replace("\n", ""));
-		} else {
-			log.error("funcid name is null : {}", JacksonMapper.toSimpleJson(funcid));
-		}
-		funcid.setUnit(model.unit);
-		funcid.setPriority(model.priority);
-		funcid.setInputMode(model.inputMode);
-		funcid.setOrigDataType(model.origDataType);
-		funcid.setSubFlag(false);
-		funcid.setWeakPoint(false);
-		FuncidDefModel dataType = DataTypeMapping.getDataType(model.origDataType);
-		if (dataType != null) {
-			funcid.setCategory(dataType.getCategory());
-			funcid.setDataType(dataType.getDataType());
-			funcid.setIsMultiple(dataType.getIsMultiple());
-			funcid.setIsRegion(dataType.getIsRegion());
-		} else {
-			return null;
-		}
-		funcid.setSubFlag(false);
-		if (model.remark != null) {
-			funcid.setNote(model.remark.replace("\n", ""));
-		}
-
-		if (model.origDataSource != null) {
-			funcid.setOrigDataSource(model.origDataSource.replace("\n", "nn")); // 去掉换行符
-		}
-		if (funcid.getDataType() == FuncidDataType.ENUM || funcid.getDataType() == FuncidDataType.MENUM || funcid.getDataType() == FuncidDataType.BOOLEAN) {
-			funcid.setDataSource(FuncidUtils.transEnumDataSource(model.origDataSource)); // 解析datasource
-		}
-		return funcid;
-	}
-
-	private void importEquipment(List<FuncidDefModel> funcids) throws IOException {
-
-		funcids.addAll(readSheet("SELTLT", "/85-传感器.xlsx", "LTLT照明灯具"));
-
-		funcids.addAll(readSheet("SELTCC", "/17-照明系统设备.xlsx", "LTCC照明回路"));
-		funcids.addAll(readSheet("SELTLG", "/17-照明系统设备.xlsx", "LTLG照明灯组"));
-
-		funcids.addAll(readSheet("SELTCU", "/17-照明系统设备.xlsx", "LTCU照明控制箱"));
-		funcids.addAll(readSheet("SELTCP", "/17-照明系统设备.xlsx", "LTCP照明控制面板"));
-
-
-	}
-
-	@Data
-	private static class CacheModel {
-		private String classCode;
-		private String firstTag;
-		private String secondTag;
-		private String origCode;
-		private String name;
-		private String unit;
-		private String origDataType;
-		private String priority; // 优先级
-		private String inputMode;
-		private String origDataSource; // 字典选择
-		private String remark; // 备注
-	}
-
-	private List<FuncidDefModel> readSheet(String classCode, String fileName, String sheetName) throws IOException {
-		List<FuncidDefModel> data = new LinkedList<>();
-		String classFile = basepath + fileName;
-		FileInputStream inputStream = new FileInputStream(classFile);
-		Workbook workbook = new XSSFWorkbook(inputStream);
-		Sheet sheet = workbook.getSheet(sheetName);
-		if (sheet == null) {
-			return data;
-		}
-
-		// 行号从0开始, 从第2行开始读数据
-		int startRowNum = 2;
-		int lastRowNum = sheet.getLastRowNum();
-		CacheModel cache = new CacheModel();
-		for (int rowIndex = startRowNum; rowIndex <= lastRowNum; rowIndex++) {
-			Row row = sheet.getRow(rowIndex);
-			if (row == null) {
-				log.info("file: {}, sheet: {}, row[{}] is null", fileName, sheetName, rowIndex);
-				continue;
-			}
-			// 0:firstTag, 1:secondTag, 2:name, 3:origCode, 4:unit, 5:origDataType, 6:priorite, 7:imputMode, 8:origDataSource, 9:remark
-			CacheModel target = new CacheModel();
-			target.classCode = classCode;
-			target.firstTag = (String) ExcelUtils.parseCell(row.getCell(0), "string");
-			target.secondTag = (String) ExcelUtils.parseCell(row.getCell(1), "string");
-			target.name = (String) ExcelUtils.parseCell(row.getCell(2), "string");
-			target.origCode = (String) ExcelUtils.parseCell(row.getCell(3), "string");
-			target.unit = (String) ExcelUtils.parseCell(row.getCell(4), "string");
-			target.origDataType = (String) ExcelUtils.parseCell(row.getCell(5), "string");
-			target.priority = (String) ExcelUtils.parseCell(row.getCell(6), "string");
-			target.inputMode = (String) ExcelUtils.parseCell(row.getCell(7), "string");
-			target.origDataSource = (String) ExcelUtils.parseCell(row.getCell(8), "string");
-			target.remark = (String) ExcelUtils.parseCell(row.getCell(9), "string");
-
-			if (target.origCode == null || "".equals(target.origCode) || "`".equals(target.origCode)) {
-				continue;
-			}
-			if (FuncidUtils.isBase(target.origCode)) {
-				continue;
-			}
-
-			// firstTag不为空
-			if (target.firstTag != null) {
-				cache.firstTag = target.firstTag;
-				cache.secondTag = null;
-			} else {
-				target.firstTag = cache.firstTag;
-			}
-
-			// secondTag
-			if (target.secondTag != null) {
-				cache.secondTag = target.secondTag;
-			} else {
-				target.secondTag = cache.secondTag;
-			}
-			FuncidDefModel funcidDefModel = toFuncidDefModel(target);
-			if (funcidDefModel == null) {
-				log.info("file: {}, sheet: {}, row: {} data type [{}] error", fileName, sheetName, rowIndex, target.origDataType);
-			} else {
-				data.add(funcidDefModel);
-			}
-		}
-		return data;
-	}
+            writer.println(toSql(item));
+        });
+        writer.println("commit;");
+        writer.flush();
+        writer.close();
+    }
+
+    private String toSql(FuncidDefModel model) {
+        StringBuilder buff = new StringBuilder("");
+        buff.append("insert into rwd_def_funcid ");
+        buff.append("(id,code,orig_code,name,alias_code,alias_name,class_code,type,group_code,project_id,category,");
+        buff.append("first_tag,second_tag,priority,input_mode,unit,data_type,orig_data_type,is_multiple,is_region,formater,data_source,orig_data_source,note,sub_flag,weak_point) ");
+        buff.append("values (");
+        buff.append("'").append(UUID.randomUUID().toString().replace("-", "")).append("',"); // id
+        buff.append("'").append(model.getCode()).append("',"); // code
+        buff.append("'").append(model.getOrigCode()).append("',"); // orig_code
+        buff.append("'").append(model.getName()).append("',"); // name
+        buff.append("'").append(model.getAliasCode()).append("',"); // alias_code
+        buff.append("'").append(model.getAliasName()).append("',"); // alias_name
+        buff.append("'").append(model.getClassCode()).append("',"); // class_code
+        buff.append("'").append(model.getType()).append("',"); // type
+        buff.append("'").append(model.getGroupCode()).append("',"); // group_code
+        buff.append("'").append(model.getProjectId()).append("',"); // project_id
+        buff.append("'").append(model.getCategory().name()).append("',"); // category
+        if (model.getFirstTag() != null) {
+            buff.append("'").append(model.getFirstTag()).append("',"); // first_tag
+        } else {
+            buff.append("null,");
+        }
+        if (model.getSecondTag() != null) {
+            buff.append("'").append(model.getSecondTag()).append("',"); // second_tag
+        } else {
+            buff.append("null,");
+        }
+        if (model.getPriority() != null) {
+            buff.append("'").append(model.getPriority()).append("',"); // priority
+        } else {
+            buff.append("null,");
+        }
+        if (model.getInputMode() != null) {
+            buff.append("'").append(model.getInputMode()).append("',"); // input_mode
+        } else {
+            buff.append("null,");
+        }
+        if (model.getUnit() != null) {
+            buff.append("'").append(model.getUnit()).append("',"); // unit
+        } else {
+            buff.append("null,");
+        }
+
+        buff.append("'").append(model.getDataType().name()).append("',"); // data_type
+        buff.append("'").append(model.getOrigDataType()).append("',"); // orig_data_type
+        buff.append(model.getIsMultiple() ? 1 : 0).append(","); // is_multiple
+        buff.append(model.getIsRegion() ? 1 : 0).append(","); // is_region
+        if (model.getFormater() != null) {
+            buff.append("'").append(model.getFormater()).append("',"); // formater
+        } else {
+            buff.append("null,");
+        }
+        if (model.getDataSource() != null) {
+            buff.append("'").append(model.getDataSource().toString()).append("',"); // data_source
+        } else {
+            buff.append("null,");
+        }
+        if (model.getOrigDataSource() != null) { // orig_data_source
+            buff.append("'").append(model.getOrigDataSource()).append("',"); // data_source
+        } else {
+            buff.append("null,");
+        }
+        if (model.getNote() != null) {
+            buff.append("'").append(model.getNote()).append("',"); // note}
+        } else {
+            buff.append("null,");
+        }
+        buff.append(model.getSubFlag() ? 1 : 0).append(","); // sub_flag
+        buff.append(model.getWeakPoint() ? 1 : 0).append(","); // weak_point
+        buff.deleteCharAt(buff.length() - 1);
+        buff.append(");");
+        return buff.toString();
+    }
+
+    private FuncidDefModel toFuncidDefModel(CacheModel model) {
+        FuncidDefModel funcid = new FuncidDefModel();
+        funcid.setGroupCode("0");
+        funcid.setProjectId("0");
+        funcid.setType("common");
+        funcid.setClassCode(model.classCode);
+        funcid.setFirstTag(model.firstTag != null ? model.firstTag.replace("\n", "") : null);
+        funcid.setSecondTag(model.secondTag != null ? model.secondTag.replace("\n", "") : null);
+        funcid.setCode(model.origCode.substring(0, 1).toLowerCase() + model.origCode.substring(1));
+        funcid.setOrigCode(model.origCode);
+        funcid.setAliasCode(model.origCode);
+        if (model.name != null) {
+            funcid.setName(model.name.replace("\n", ""));
+            funcid.setAliasName(model.name.replace("\n", ""));
+        } else {
+            log.error("funcid name is null : {}", JacksonMapper.toSimpleJson(funcid));
+        }
+        funcid.setUnit(model.unit);
+        funcid.setPriority(model.priority);
+        funcid.setInputMode(model.inputMode);
+        funcid.setOrigDataType(model.origDataType);
+        funcid.setSubFlag(false);
+        funcid.setWeakPoint(false);
+        FuncidDefModel dataType = DataTypeMapping.getDataType(model.origDataType);
+        if (dataType != null) {
+            funcid.setCategory(dataType.getCategory());
+            funcid.setDataType(dataType.getDataType());
+            funcid.setIsMultiple(dataType.getIsMultiple());
+            funcid.setIsRegion(dataType.getIsRegion());
+        } else {
+            return null;
+        }
+        funcid.setSubFlag(false);
+        if (model.remark != null) {
+            funcid.setNote(model.remark.replace("\n", ""));
+        }
+
+        if (model.origDataSource != null) {
+            funcid.setOrigDataSource(model.origDataSource.replace("\n", "nn")); // 去掉换行符
+        }
+        if (funcid.getDataType() == FuncidDataType.ENUM || funcid.getDataType() == FuncidDataType.MENUM || funcid.getDataType() == FuncidDataType.BOOLEAN) {
+            FuncidUtils funcidUtils = new FuncidUtils();
+            funcid.setDataSource(funcidUtils.transEnumDataSource(model.origDataSource)); // 解析datasource
+        }
+        return funcid;
+    }
+
+    private void importEquipment(List<FuncidDefModel> funcids) throws IOException {
+
+        funcids.addAll(readSheet("SELTLT", "/85-传感器.xlsx", "LTLT照明灯具"));
+
+        funcids.addAll(readSheet("SELTCC", "/17-照明系统设备.xlsx", "LTCC照明回路"));
+        funcids.addAll(readSheet("SELTLG", "/17-照明系统设备.xlsx", "LTLG照明灯组"));
+
+        funcids.addAll(readSheet("SELTCU", "/17-照明系统设备.xlsx", "LTCU照明控制箱"));
+        funcids.addAll(readSheet("SELTCP", "/17-照明系统设备.xlsx", "LTCP照明控制面板"));
+
+
+    }
+
+    @Data
+    private static class CacheModel {
+        private String classCode;
+        private String firstTag;
+        private String secondTag;
+        private String origCode;
+        private String name;
+        private String unit;
+        private String origDataType;
+        private String priority; // 优先级
+        private String inputMode;
+        private String origDataSource; // 字典选择
+        private String remark; // 备注
+    }
+
+    private List<FuncidDefModel> readSheet(String classCode, String fileName, String sheetName) throws IOException {
+        List<FuncidDefModel> data = new LinkedList<>();
+        String classFile = basepath + fileName;
+        FileInputStream inputStream = new FileInputStream(classFile);
+        Workbook workbook = new XSSFWorkbook(inputStream);
+        Sheet sheet = workbook.getSheet(sheetName);
+        if (sheet == null) {
+            return data;
+        }
+
+        // 行号从0开始, 从第2行开始读数据
+        int startRowNum = 2;
+        int lastRowNum = sheet.getLastRowNum();
+        CacheModel cache = new CacheModel();
+        for (int rowIndex = startRowNum; rowIndex <= lastRowNum; rowIndex++) {
+            Row row = sheet.getRow(rowIndex);
+            if (row == null) {
+                log.info("file: {}, sheet: {}, row[{}] is null", fileName, sheetName, rowIndex);
+                continue;
+            }
+            // 0:firstTag, 1:secondTag, 2:name, 3:origCode, 4:unit, 5:origDataType, 6:priorite, 7:imputMode, 8:origDataSource, 9:remark
+            CacheModel target = new CacheModel();
+            target.classCode = classCode;
+            target.firstTag = (String) ExcelUtils.parseCell(row.getCell(0), "string");
+            target.secondTag = (String) ExcelUtils.parseCell(row.getCell(1), "string");
+            target.name = (String) ExcelUtils.parseCell(row.getCell(2), "string");
+            target.origCode = (String) ExcelUtils.parseCell(row.getCell(3), "string");
+            target.unit = (String) ExcelUtils.parseCell(row.getCell(4), "string");
+            target.origDataType = (String) ExcelUtils.parseCell(row.getCell(5), "string");
+            target.priority = (String) ExcelUtils.parseCell(row.getCell(6), "string");
+            target.inputMode = (String) ExcelUtils.parseCell(row.getCell(7), "string");
+            target.origDataSource = (String) ExcelUtils.parseCell(row.getCell(8), "string");
+            target.remark = (String) ExcelUtils.parseCell(row.getCell(9), "string");
+
+            if (target.origCode == null || "".equals(target.origCode) || "`".equals(target.origCode)) {
+                continue;
+            }
+            if (FuncidUtils.isBase(target.origCode)) {
+                continue;
+            }
+
+            // firstTag不为空
+            if (target.firstTag != null) {
+                cache.firstTag = target.firstTag;
+                cache.secondTag = null;
+            } else {
+                target.firstTag = cache.firstTag;
+            }
+
+            // secondTag
+            if (target.secondTag != null) {
+                cache.secondTag = target.secondTag;
+            } else {
+                target.secondTag = cache.secondTag;
+            }
+            FuncidDefModel funcidDefModel = toFuncidDefModel(target);
+            if (funcidDefModel == null) {
+                log.info("file: {}, sheet: {}, row: {} data type [{}] error", fileName, sheetName, rowIndex, target.origDataType);
+            } else {
+                data.add(funcidDefModel);
+            }
+        }
+        return data;
+    }
 
 }