Browse Source

Merge remote-tracking branch 'origin/master'

linhuili 3 years ago
parent
commit
c6239de722

+ 1 - 1
dmp-dic/src/main/resources/bootstrap-dev.yml

@@ -1,6 +1,6 @@
 spring:
   application:
-    name: dmp-rwd
+    name: dmp-dic
   cloud:
     config:
       profile: dev2

+ 172 - 6
dmp-rwd-datautils/src/test/java/com/persagy/dmp/rwd/datautils/ImportFuncid.java

@@ -30,10 +30,9 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
 import java.io.*;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.UUID;
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * @author: yaoll
@@ -167,7 +166,7 @@ public class ImportFuncid {
         return buff.toString();
     }
 
-    private FuncidDefModel toFuncidDefModel(CacheModel model) {
+    private FuncidDefModel toFuncidDefModel(CacheModel model,String classCode, String fileName, String sheetName) {
         FuncidDefModel funcid = new FuncidDefModel();
         funcid.setGroupCode("0");
         funcid.setProjectId("0");
@@ -218,10 +217,177 @@ public class ImportFuncid {
         }
         if (funcid.getDataType() == FuncidDataType.ENUM || funcid.getDataType() == FuncidDataType.MENUM || funcid.getDataType() == FuncidDataType.BOOLEAN) {
             funcid.setDataSource(FuncidUtils.transEnumDataSource(model.origDataSource)); // 解析datasource
+            //funcid.setDataSource(transEnumDataSource(model.origDataSource, classCode,  fileName, sheetName,model.origCode)); // 解析datasource
         }
         return funcid;
     }
 
+    private static void writeErrorDataSourceToFile(String message) throws IOException {
+        FileWriter writer = new FileWriter("D:/资料/工作资料/原型图/数据中台/out/错误信息点.txt",true);
+        writer.append(message);
+        writer.append("\n");
+        writer.flush();
+        writer.close();
+    }
+
+    public static ArrayNode transEnumDataSource(String dataSource,String classCode, String fileName, String sheetName,String origCode) {
+        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.contains("《")) {
+            String name = null;
+            String refKey = null;
+            Pattern pattern = Pattern.compile("《(.*?)》");
+            Matcher matcher = pattern.matcher(dataSource);
+            while (matcher.find()) {
+                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 =  FuncidUtils.rwdeditServer+ "/rwdedit/ref/type/query";
+            JacksonCriteria criteria = JacksonCriteria.newInstance();
+            criteria.add("aliasName", name);
+            HttpUtils.HttpResult response = FuncidUtils.httpUtils.post(url, JacksonMapper.toSimpleJson(criteria), 300000);
+            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;
+            }
+
+            //查询知识库详情
+            url = FuncidUtils.rwdeditServer + "/rwdedit/ref/type/infos/query";
+            criteria = JacksonCriteria.newInstance();
+            criteria.add("refKey", refKey);
+            response = FuncidUtils.httpUtils.post(url, JacksonMapper.toSimpleJson(criteria), 300000);
+            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"));
+                String parentCode = JacksonMapper.getString(obj, "parentCode");
+                if (parentCode != null && !("-9999".equals(parentCode))) {
+                    item.put("parentCode", parentCode);
+                }
+            }
+        } else if (dataSource.indexOf(".") > -1) {
+
+            // 预处理
+            String tmp = dataSource.replace("(多选)", "")
+                    .replace("(可多选)", "")
+                    .replace("(可以多选)", "");
+            log.info("Excel名称:"+fileName+",sheet表名:"+sheetName+",信息点code:"+origCode);
+            try {
+                writeErrorDataSourceToFile("Excel名称:"+fileName+",sheet表名:"+sheetName+",信息点code:"+origCode);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+
+            /*// 尝试解析
+            // 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;
+                }
+                if (temp.matches("^([0-9]+[.]){2,}[^.]+$")){
+                    // 1) 11.1. 测试 2)11.1.测试
+                    String key = temp.substring(0,temp.lastIndexOf("."));
+                    String value = temp.substring(temp.lastIndexOf(".")+1).trim();
+                    data.put(key, value);
+                    ObjectNode item = array.addObject();
+                    item.put("code", key);
+                    item.put("name", value);
+                    continue;
+                }
+                if (temp.matches("^([0-9]+[.])+[0-9]+[.]?[^.]+$")){
+                    // 1)11.1 测试
+                    String[] temps = temp.split(" ");
+                    String key = temps[0];
+                    String value = temps[1];
+                    data.put(key, value);
+                    ObjectNode item = array.addObject();
+                    item.put("code", key);
+                    item.put("name", value);
+                    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 void importSpace(List<FuncidDefModel> funcids) throws IOException {
         funcids.addAll(readSheet("project", "/附表5-建筑空间类对象属性点表/附表5.1-项目.xlsx", "项目"));
         funcids.addAll(readSheet("building", "/附表5-建筑空间类对象属性点表/附表5.2-建筑.xlsx", "建筑"));
@@ -859,7 +1025,7 @@ public class ImportFuncid {
             } else {
                 target.secondTag = cache.secondTag;
             }
-            FuncidDefModel funcidDefModel = toFuncidDefModel(target);
+            FuncidDefModel funcidDefModel = toFuncidDefModel(target,classCode,fileName,sheetName);
 
             if (FuncidUtils.isBase(target.origCode)) {
                 continue;

+ 21 - 0
dmp-rwd-datautils/src/test/java/com/persagy/dmp/rwd/dic/FuncidUtils.java

@@ -222,6 +222,27 @@ public class FuncidUtils {
                 if (idx == -1) {
                     continue;
                 }
+                /*if (temp.matches("^([0-9]+[.]){2,}[^.]+$")){
+                    // 1) 11.1. 测试 2)11.1.测试
+                    String key = temp.substring(0,temp.lastIndexOf("."));
+                    String value = temp.substring(temp.lastIndexOf(".")+1).trim();
+                    data.put(key, value);
+                    ObjectNode item = array.addObject();
+                    item.put("code", key);
+                    item.put("name", value);
+                    continue;
+                }
+                if (temp.matches("^([0-9]+[.])+[0-9]+[.]?[^.]+$")){
+                    // 1)11.1 测试
+                    String[] temps = temp.split(" ");
+                    String key = temps[0];
+                    String value = temps[1];
+                    data.put(key, value);
+                    ObjectNode item = array.addObject();
+                    item.put("code", key);
+                    item.put("name", value);
+                    continue;
+                }*/
                 String key = temp.substring(0, idx);
                 String value = temp.substring(idx + 1);
                 data.put(key, value);

+ 25 - 0
dmp-rwd-edit/src/test/java/com/persagy/dmp/rwd/edit/service/DemoTest.java

@@ -0,0 +1,25 @@
+package com.persagy.dmp.rwd.edit.service;
+
+import cn.hutool.core.text.CharSequenceUtil;
+import cn.hutool.core.util.EscapeUtil;
+import cn.hutool.core.util.HexUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.poi.excel.ExcelUtil;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+import java.nio.charset.Charset;
+
+public class DemoTest {
+
+    public static void main(String[] args) {
+        String testStr = "\nafefefa非\t\neife";
+        ObjectMapper objectMapper = new ObjectMapper();
+        ObjectNode objectNode = objectMapper.createObjectNode();
+        String s = StrUtil.removeAllLineBreaks(testStr);
+        String removeAll = StrUtil.removeAll(testStr, StrUtil.C_CR, StrUtil.C_LF, StrUtil.C_TAB);
+        System.out.println(s);
+        System.out.println(removeAll);
+    }
+
+}