3 Commits f88e2c4e7e ... a49cf0c301

Author SHA1 Message Date
  fengyanjie a49cf0c301 Merge remote-tracking branch 'origin/master' 3 years ago
  fengyanjie a9b2d217e2 更新数据字典导入工具 3 years ago
  fengyanjie 807130cc12 更新数据字典导入工具 3 years ago

+ 2 - 0
dmp-rwd-datautils/src/main/resources/application-dev.yml

@@ -2,6 +2,8 @@ persagy:
   dmp:
     rwd:
       server: http://39.102.54.110:8082
+    rwdedit:
+      server: http://39.102.54.110:8088
 #      server: http://localhost:8082
 #spring:
 #  datasource:

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

@@ -1,7 +1,17 @@
-package com.persagy.dmp.rwd.dic;
+package com.persagy.dmp.rwd.datautils;
 
+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.date.DateUtils;
 import com.persagy.common.json.JacksonMapper;
+import com.persagy.dmp.common.http.HttpUtils;
+import com.persagy.dmp.rwd.dic.DataTypeMapping;
+import com.persagy.dmp.rwd.dic.ExcelUtils;
+import com.persagy.dmp.rwd.dic.FuncidDefModel;
+import com.persagy.dmp.rwd.dic.FuncidUtils;
 import com.persagy.dmp.rwd.enums.FuncidDataType;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
@@ -9,7 +19,13 @@ import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
 
 import java.io.*;
 import java.util.Date;
@@ -23,15 +39,30 @@ import java.util.UUID;
  * @verison: 1.0
  */
 @Slf4j
+@SpringBootTest
+@RunWith(SpringRunner.class)
 public class ImportFuncid {
 
     private String basepath = "C:\\Users\\24341\\Downloads\\数据字典附表(20210412)";
 
     private String outPath = "C:/Users/24341/Downloads/20210413/funcid-" + DateUtils.format(new Date()) + ".dml.sql";
 
+    @Autowired
+    private HttpUtils httpUtils;
+
+    @Value("${persagy.dmp.rwdedit.server}")
+    private String rwdeditServer;
+
+    @Before
+    public void init() {
+        FuncidUtils.httpUtils = httpUtils;
+        FuncidUtils.rwdeditServer = rwdeditServer;
+    }
+
     @Test
     public void importFuncidDef() throws IOException {
         List<FuncidDefModel> funcids = new LinkedList<>();
+//        importBase(funcids);
         importSpace(funcids);
         importSystem(funcids);
         importEquipment(funcids);
@@ -53,6 +84,13 @@ public class ImportFuncid {
         writer.close();
     }
 
+    private void importBase(List<FuncidDefModel> funcids) throws IOException {
+        funcids.addAll(readSheet("system", "/附表6-机电精装类对象通用属性点表.xlsx", "系统类"));
+        funcids.addAll(readSheet("equipment", "/附表6-机电精装类对象通用属性点表.xlsx", "设备类"));
+        funcids.addAll(readSheet("component", "/附表6-机电精装类对象通用属性点表.xlsx", "部件类"));
+
+    }
+
     private String toSql(FuncidDefModel model) {
         StringBuilder buff = new StringBuilder("");
         buff.append("insert into rwd_def_funcid ");
@@ -162,14 +200,22 @@ public class ImportFuncid {
         funcid.setSubFlag(false);
         if (model.remark != null) {
             funcid.setNote(model.remark.replace("\n", ""));
+            if (model.remark != null) {
+                if (model.remark.contains("YYYYMMDD-YYYYMMDD")) {
+                    funcid.setFormater("YYYYMMDD-YYYYMMDD");
+                }else if (model.remark.contains("YYYYMMDD")) {
+                    funcid.setFormater("YYYYMMDD");
+                }else if (model.remark.contains("YYYY")) {
+                    funcid.setFormater("YYYY");
+                }
+            }
         }
 
         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
+            funcid.setDataSource(FuncidUtils.transEnumDataSource(model.origDataSource)); // 解析datasource
         }
         return funcid;
     }
@@ -191,6 +237,7 @@ public class ImportFuncid {
         funcids.addAll(readSheet("SecurityZone", "/附表5-建筑空间类对象属性点表/附表5.5-空间.xlsx", "SCZ安防分区"));
         funcids.addAll(readSheet("TenantZone", "/附表5-建筑空间类对象属性点表/附表5.5-空间.xlsx", "TNZ租户分区"));
         funcids.addAll(readSheet("FunctionZone", "/附表5-建筑空间类对象属性点表/附表5.5-空间.xlsx", "FCZ功能分区"));
+        funcids.addAll(readSheet("PassengerFlowZone", "/附表5-建筑空间类对象属性点表/附表5.5-空间.xlsx", "PFZ客流分区"));
         funcids.addAll(readSheet("OtherZone", "/附表5-建筑空间类对象属性点表/附表5.5-空间.xlsx", "OTZ其他分区"));
     }
 
@@ -813,5 +860,29 @@ public class ImportFuncid {
         return data;
     }
 
+    @Test
+    public void test() {
+        ArrayNode array = JsonNodeFactory.instance.arrayNode();
+        //查询知识库详情
+        String url = rwdeditServer + "/rwdedit/ref/type/infos/query";
+        JacksonCriteria criteria = JacksonCriteria.newInstance();
+        criteria.add("refKey", "classificationSystem");
+        HttpUtils.HttpResult response = httpUtils.post(url, JacksonMapper.toSimpleJson(criteria), 300000);
+        String content = response.getContent();
+        ObjectNode objectNode = JacksonMapper.toObject(content, ObjectNode.class);
+        ArrayNode 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"));
+            String parentCode = JacksonMapper.getString(obj, "parentCode");
+            if (parentCode != null) {
+                item.put("parentCode", parentCode);
+            }
+        }
+        System.err.println(JacksonMapper.toSimpleJson(array));
+    }
+
 }
 

+ 59 - 13
dmp-rwd-datautils/src/test/java/com/persagy/dmp/rwd/dic/FuncidUtils.java

@@ -7,8 +7,7 @@ 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 org.springframework.stereotype.Component;
 
 import java.util.HashMap;
 import java.util.HashSet;
@@ -22,15 +21,14 @@ import java.util.regex.Pattern;
  * @date: 2020-11-30
  * @verison: 1.0
  */
+@Component
 public class FuncidUtils {
 
     private final static Set<String> baseFuncid = new HashSet<>();
 
-    @Value("${persagy.dmp.rwdedit.server}")
-    private String rwdeditServer;
+    public static HttpUtils httpUtils;
 
-    @Autowired
-    private HttpUtils httpUtils;
+    public static String rwdeditServer;
 
     static {
         baseFuncid.add("ProjID");
@@ -101,7 +99,7 @@ public class FuncidUtils {
         return baseFuncid.contains(code);
     }
 
-    public ArrayNode transEnumDataSource(String dataSource) {
+    public static ArrayNode transEnumDataSource(String dataSource) {
         ArrayNode array = JsonNodeFactory.instance.arrayNode();
         if (dataSource == null) {
             return null;
@@ -114,19 +112,61 @@ public class FuncidUtils {
         while (dataSource.indexOf(". ") > -1) {
             dataSource = dataSource.replace(". ", ".");
         }
-        if (dataSource.startsWith("见《")) {
+        if (dataSource.contains("《")) {
             String name = null;
             String refKey = null;
             Pattern pattern = Pattern.compile("《(.*?)》");
-            Matcher matcher = pattern.matcher("见《城市发展水平分级》");
+            Matcher matcher = pattern.matcher(dataSource);
             while (matcher.find()) {
-                name = matcher.group(1);
+                String group = matcher.group(1);
+                if ("4天气状态".equals(group)) {
+                    name = "天气状态";
+                } else if ("6方向代码".equals(group)) {
+                    name = "方向代码";
+                } else if ("10抗震设防烈度".equals(group)) {
+                    name = "抗震设防烈度";
+                } else {
+                    name = group;
+                }
+            }
+            if ("见《推荐空间业态分类表》-项目类型".equals(dataSource)) {
+                name = "项目类型";
+            } else if ("见《枚举值释义》方向代码".equals(dataSource)) {
+                name = "方向代码";
+            } else if ("参考《11防护等级》".equals(dataSource)) {
+                // 预处理
+                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;
             }
 
+            //查询知识库引用
             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);
+            HttpUtils.HttpResult response = httpUtils.post(url, JacksonMapper.toSimpleJson(criteria), 300000);
             if (!response.success()) {
                 return null;
             }
@@ -137,9 +177,12 @@ public class FuncidUtils {
             if (null == refKey) {
                 return null;
             }
+
+            //查询知识库详情
+            url = rwdeditServer + "/rwdedit/ref/type/infos/query";
             criteria = JacksonCriteria.newInstance();
             criteria.add("refKey", refKey);
-            response = httpUtils.post(url, JacksonMapper.toSimpleJson(criteria), 3600000);
+            response = httpUtils.post(url, JacksonMapper.toSimpleJson(criteria), 300000);
             if (!response.success()) {
                 return null;
             }
@@ -151,7 +194,10 @@ public class FuncidUtils {
                 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"));
+                String parentCode = JacksonMapper.getString(obj, "parentCode");
+                if (parentCode != null) {
+                    item.put("parentCode", parentCode);
+                }
             }
         } else if (dataSource.indexOf(".") > -1) {
 

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

@@ -161,8 +161,7 @@ public class ImportFuncid2 {
 			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
+			funcid.setDataSource(FuncidUtils.transEnumDataSource(model.origDataSource)); // 解析datasource
 		}
 		return funcid;
 	}

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

@@ -102,8 +102,7 @@ public class ImportGroupProjectFuncid {
 			}
 			model.setOrigDataSource(origDataSource);
 			if (model.getDataType() == FuncidDataType.ENUM || model.getDataType() == FuncidDataType.MENUM || model.getDataType() == FuncidDataType.BOOLEAN) {
-				FuncidUtils funcidUtils = new FuncidUtils();
-				model.setDataSource(funcidUtils.transEnumDataSource(origDataSource)); // 解析datasource
+				model.setDataSource(FuncidUtils.transEnumDataSource(origDataSource)); // 解析datasource
 			}
 
 			String note = (String) ExcelUtils.parseCell(row.getCell(12), "string");
@@ -235,8 +234,7 @@ public class ImportGroupProjectFuncid {
 			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
+			funcid.setDataSource(FuncidUtils.transEnumDataSource(model.origDataSource)); // 解析datasource
 		}
 		return funcid;
 	}

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

@@ -260,8 +260,7 @@ public class UpdateInfoCodeTag {
             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
+            funcid.setDataSource(FuncidUtils.transEnumDataSource(model.origDataSource)); // 解析datasource
         }
         return funcid;
     }