Browse Source

实现知识库管理-更改知识库类型的extend_properties为数组结构类型

lijie 3 years ago
parent
commit
51398ab922

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

@@ -34,7 +34,7 @@ public class ExcelUtils {
         } else if ("integer".equalsIgnoreCase(type)) {
             if (cellType == CellType.STRING) {
                 String stringCellValue = cell.getStringCellValue();
-                return stringCellValue == null ? null : Double.valueOf(stringCellValue).intValue();
+                return stringCellValue == null ? null : Double.valueOf(stringCellValue.trim()).intValue();
             } else if (cellType == CellType.NUMERIC) {
                 return Double.valueOf(cell.getNumericCellValue()).intValue();
             }

+ 87 - 13
dmp-rwd-datautils/src/test/java/com/persagy/dmp/rwd/dic/ImportKnowledgeForEdit.java

@@ -1,15 +1,14 @@
 package com.persagy.dmp.rwd.dic;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.common.date.DateUtils;
 import com.persagy.common.json.JacksonMapper;
 import com.persagy.dmp.rwd.enums.ObjType;
 import com.persagy.dmp.rwd.model.ClassDefModel;
 import com.persagy.dmp.rwd.model.RwdeditRefTypeInfosModel;
-import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
@@ -47,20 +46,94 @@ public class ImportKnowledgeForEdit {
         // initBaseClass(classes);
         // 空间分区
         // initSpace(classes);
-        // 专业\系统\设备\部件
-        initEquipment(classes,"major");
-        writeFuncSqlToFile(classes, "major");
-        classes.clear();
-        // 工具
-        initToolOrMaterial(classes,"tool","工具类");
-        writeFuncSqlToFile(classes, "tool");
-        classes.clear();
-        // 耗材
-        initToolOrMaterial(classes,"material","耗材类 ");
-        writeFuncSqlToFile(classes, "material");
+//        // 专业\系统\设备\部件
+//        initEquipment(classes,"major");
+//        writeFuncSqlToFile(classes, "major");
+//        classes.clear();
+//        // 工具
+//        initToolOrMaterial(classes,"tool","工具类");
+//        writeFuncSqlToFile(classes, "tool");
+//        classes.clear();
+//        // 耗材
+//        initToolOrMaterial(classes,"material","耗材类 ");
+//        writeFuncSqlToFile(classes, "material");
+//        classes.clear();
+//        // 省市区编号
+//        initCityLocation(classes,"cityLocation","省市区编号");
+//        writeFuncSqlToFile(classes, "cityLocation");
+//        classes.clear();
+        // 省市区编号
+        initCityLocation(classes,"cityLocation","省市区编号");
+        writeFuncSqlToFile(classes, "cityLocation");
         classes.clear();
 
 
+
+
+    }
+
+    public void initCityLocation(List<RwdeditRefTypeInfosModel> models, String refKey, String sheetName) throws Exception {
+        String file = basepath + "/附表14-地域性信息表.xlsx";
+
+        FileInputStream inputStream = new FileInputStream(file);
+        Workbook workbook = new XSSFWorkbook(inputStream);
+        Sheet sheet = workbook.getSheet(sheetName);
+
+        // 行号从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("row[{}] is null", rowIndex);
+                continue;
+            }
+            // 0专业, 3系统编码, 5系统名称, 6设备编码, 8设备名称
+            String cityCode = (String) ExcelUtils.parseCell(row.getCell(2), "string");// 市级code
+            String areaCode = (String) ExcelUtils.parseCell(row.getCell(4), "string");// 区级code
+            String name = (String) ExcelUtils.parseCell(row.getCell(5), "string");// 名称
+            Integer codeInt = (Integer)ExcelUtils.parseCell(row.getCell(6), "integer");// code
+            if (null==name || null == codeInt){
+                continue;
+            }
+            String code = codeInt.toString();
+            Double longitude = (Double) ExcelUtils.parseCell(row.getCell(7), "double");// 精度
+            Double latitude = (Double) ExcelUtils.parseCell(row.getCell(8), "double");// 维度
+            Double altitude = (Double) ExcelUtils.parseCell(row.getCell(9), "double");// 海拔
+            String climaticDivisionCode = (String) ExcelUtils.parseCell(row.getCell(10), "string");// 气候区
+            String cityDevelopmentLevelCode = (String) ExcelUtils.parseCell(row.getCell(11), "string");// 发展水平
+            RwdeditRefTypeInfosModel model = new RwdeditRefTypeInfosModel();
+            model.setRefKey(refKey);
+            model.setCode(code);
+            model.setName(name);
+            model.setParentCode(cache.equipCode);
+            if ("00".equals(cityCode) && "00".equals(areaCode)){
+                // 省
+                cache.systemCode = code;
+                cache.systemName = name;
+                model.setParentCode("-9999");
+            }
+            if (!"00".equals(cityCode) && "00".equals(areaCode)){
+                // 市
+                cache.equipCode = code;
+                cache.equipName = name;
+                model.setParentCode(cache.systemCode);
+            }
+            if (StringUtils.isNotBlank(climaticDivisionCode)){
+                cache.climaticDivisionCode = climaticDivisionCode;
+            }
+            ObjectNode objectNode = objectMapper.createObjectNode()
+                    .put("altitude", altitude)
+                    .put("latitude", latitude)
+                    .put("longitude", longitude)
+                    .put("climaticDivisionCode", cache.climaticDivisionCode)
+                    .put("cityDevelopmentLevelCode", cityDevelopmentLevelCode);
+            model.setDataSource(objectNode);
+            model.setCreateUser(CREATE_USER_ID);
+            model.setUpdateUser(UPDATE_USER_ID);
+            models.add(model);
+        }
     }
 
     private void writeFuncSqlToFile(List<RwdeditRefTypeInfosModel> classes,String refKey) throws IOException {
@@ -425,6 +498,7 @@ public class ImportKnowledgeForEdit {
         String componentCode;
         String componentName;
         String componentEnglishName;
+        String climaticDivisionCode;
 
     }
 

+ 11 - 7
dmp-rwd-edit/src/main/java/com/persagy/dmp/rwd/edit/entity/RwdeditRefType.java

@@ -1,18 +1,21 @@
 package com.persagy.dmp.rwd.edit.entity;
 
-import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.persagy.dmp.rwd.edit.model.RwdeditRefTypeModel;
+import com.vladmihalcea.hibernate.type.json.JsonStringType;
 import lombok.Getter;
 import lombok.Setter;
-import org.hibernate.annotations.CreationTimestamp;
-import org.hibernate.annotations.GenericGenerator;
-import org.hibernate.annotations.Type;
-import org.hibernate.annotations.UpdateTimestamp;
+import org.hibernate.annotations.*;
 
 import javax.persistence.*;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.Table;
 import java.util.Date;
 import java.util.List;
-
+@TypeDef(name = "json", typeClass = JsonStringType.class)
 @Setter
 @Getter
 @Entity
@@ -25,7 +28,8 @@ public class RwdeditRefType {
     private String refKey;
     private String name;
     @Type(type = "json")
-    private ObjectNode extendProperties;
+    @Column( columnDefinition = "json" )
+    private ArrayNode extendProperties;
     @Column(updatable = false)
     private Integer createUser;
     @CreationTimestamp

+ 3 - 1
dmp-rwd-edit/src/main/java/com/persagy/dmp/rwd/edit/model/RwdeditRefTypeModel.java

@@ -1,5 +1,7 @@
 package com.persagy.dmp.rwd.edit.model;
 
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.dmp.rwd.edit.entity.RwdeditRefTypeInfos;
 import lombok.Getter;
@@ -15,7 +17,7 @@ public class RwdeditRefTypeModel {
     private String refKey;
     private String name;
     private Integer createUser;
-    private ObjectNode extendProperties;
+    private ArrayNode extendProperties;
     private Date createTime;
     private Integer updateUser;
     private Date updateTime;