1
0
Просмотр исходного кода

地籍管理上传文件,入库文件实现

chenendian 3 месяцев назад
Родитель
Сommit
eefddf0c24

+ 42 - 1
.gitignore

@@ -43,4 +43,45 @@ nbdist/
 
 !*/build/*.java
 !*/build/*.html
-!*/build/*.xml
+!*/build/*.xml
+/lib/ejml-core-0.39.jar
+/siwei-modules/siwei-apply/lib/ejml-core-0.39.jar
+/lib/ejml-ddense-0.32.jar
+/siwei-modules/siwei-apply/lib/ejml-ddense-0.32.jar
+/lib/gdal.jar
+/siwei-modules/siwei-apply/lib/gdal.jar
+/siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/cadastre/GdbController.java
+/lib/gt-api-19.2.jar
+/siwei-modules/siwei-apply/lib/gt-api-19.2.jar
+/lib/gt-data-19.2.jar
+/siwei-modules/siwei-apply/lib/gt-data-19.2.jar
+/lib/gt-epsg-hsql-2.6.0.jar
+/siwei-modules/siwei-apply/lib/gt-epsg-hsql-2.6.0.jar
+/lib/gt-geojson-19.2.jar
+/siwei-modules/siwei-apply/lib/gt-geojson-19.2.jar
+/lib/gt-main-19.2.jar
+/siwei-modules/siwei-apply/lib/gt-main-19.2.jar
+/lib/gt-metadata-19.2.jar
+/siwei-modules/siwei-apply/lib/gt-metadata-19.2.jar
+/lib/gt-opengis-19.2.jar
+/siwei-modules/siwei-apply/lib/gt-opengis-19.2.jar
+/lib/gt-referencing-19.2.jar
+/siwei-modules/siwei-apply/lib/gt-referencing-19.2.jar
+/lib/gt-render-19.2.jar
+/siwei-modules/siwei-apply/lib/gt-render-19.2.jar
+/lib/gt-shapefile-19.2.jar
+/siwei-modules/siwei-apply/lib/gt-shapefile-19.2.jar
+/lib/json-simple-1.1.1.jar
+/siwei-modules/siwei-apply/lib/json-simple-1.1.1.jar
+/lib/json-simple-1.1.jar
+/siwei-modules/siwei-apply/lib/json-simple-1.1.jar
+/lib/jsr-275-1.0-beta-2.jar
+/siwei-modules/siwei-apply/lib/jsr-275-1.0-beta-2.jar
+/lib/jts-1.13.jar
+/siwei-modules/siwei-apply/lib/jts-1.13.jar
+/lib/spire.doc.free-5.2.0.jar
+/siwei-modules/siwei-apply/lib/spire.doc.free-5.2.0.jar
+/siwei-modules/siwei-apply/src/main/java/com/siwei/apply/domain/cadastre/TdgySjDTO.java
+/siwei-modules/siwei-apply/src/main/java/com/siwei/apply/mapper/cadastre/TdgySjMapper.java
+/siwei-modules/siwei-apply/src/main/resources/mapper/cadastre/TdgySjMapper.xml
+/.vscode/settings.json

+ 17 - 9
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/cadastre/CadastreManageController.java

@@ -11,7 +11,6 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import javax.xml.crypto.dsig.spec.XSLTTransformParameterSpec;
 import java.util.*;
 
 @RestController
@@ -24,14 +23,24 @@ public class CadastreManageController extends BaseController {
     @Autowired
     private CadastreManageService cadastreManageService;
 
+
+    /**
+     *
+     *             //1.先获取相关信息,进行入库
+     *             //2.日志记录写入
+     *             //3.读取文件进行录入
+     *             //4.质量进行检查
+     *
+     * @param theFileName
+     * @param theFilePath
+     * @param fileType
+     * @param updateType
+     * @return
+     */
     @PostMapping("/checkUploadDquality")
-    public R<CheckInfoResultVo> checkData(String theFileName, String theFilePath, String fromRoute) {
+    public R<CheckInfoResultVo> checkData(String theFileName, String theFilePath, String fileType,String updateType) {
         try {
-            //1.先获取相关信息,进行入库
-            //2.日志记录写入
-            //3.读取文件进行录入
-            //4.质量进行检查
-            CheckInfoResultVo res = cadastreManageService.checkFileData(theFileName, theFilePath, fromRoute);
+            CheckInfoResultVo res = cadastreManageService.checkFileData(theFileName, theFilePath, fileType,updateType);
             return R.ok(res);
         } catch (Exception e) {
             e.printStackTrace();
@@ -41,7 +50,7 @@ public class CadastreManageController extends BaseController {
 
 
     @PostMapping("/getCompareData")
-    public R<CompareResultVo> compareData(String uploadId, String theFilePath) {
+    public R<CompareResultVo> compareData(String uploadId) {
         try {
             CompareResultVo res = cadastreManageService.getCompareData(uploadId);
             return R.ok(res);
@@ -52,7 +61,6 @@ public class CadastreManageController extends BaseController {
     }
 
 
-
     @PostMapping("/addBatchGdbData")
     public R<String> addBatchGdbData(String uploadId) {
         try {

+ 1 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/domain/CadastreFile.java

@@ -23,6 +23,7 @@ public class CadastreFile extends BaseId {
     //1 为矢量,2为表格属性
     private String fileType;
     private String storage;
+    //0 为全量,1为矢量
     private String status;
     private String readStatus;
     private String readMessage;

+ 2 - 2
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/domain/vo/CheckInfoResultVo.java

@@ -11,7 +11,7 @@ import java.util.List;
 public class CheckInfoResultVo {
     private String uploadId; //上传批次id
     private Boolean resultStatus; //检查是否通过
-    private List<CheckInfoVo> checkSuccessList; // 用地位置
-    private List<CheckInfoVo> checkFailList; // 用地位置
+    private List<CheckInfoVo> checkSuccessList; // 成功信息
+    private List<CheckInfoVo> checkFailList; // 失败信息
 
 }

+ 5 - 2
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/mapper/CadastreFileMapper.java

@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Param;
 
 import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 
 @Mapper
 public interface CadastreFileMapper {
@@ -39,7 +40,9 @@ public interface CadastreFileMapper {
     /**
      * 查询当前表的所有列
      */
-    List<String> selectTableCollum(String name);
+    List<String> selectTableCollum(String tableName);
+
+    List<Map<String,String>> selectTableCollumAndType(@Param("tableName") String tableName);
 
     /**
      * 查询所有表名
@@ -53,7 +56,7 @@ public interface CadastreFileMapper {
     List<String> selectAllTableNoView();
 
 
-    int insertTableData(@Param("tableName") String tableName, @Param("keyList")Collection<String> keyList, @Param("valueList")Collection<String> valueList);
+    int insertTableData(@Param("tableName") String tableName, @Param("keyList")Collection<String> keyList, @Param("valueList")Collection<Object> valueList);
 
 
     String selectGeoms(String tableName);

+ 3 - 9
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/cadastre/CadastreManageService.java

@@ -1,25 +1,19 @@
 package com.siwei.apply.service.cadastre;
 
-
 import com.siwei.apply.domain.CadastreFile;
 import com.siwei.apply.domain.vo.CheckInfoResultVo;
-import com.siwei.apply.domain.vo.CheckInfoVo;
 import com.siwei.apply.domain.vo.CompareResultVo;
-import com.siwei.apply.domain.vo.JsydghxkVo;
-import com.siwei.common.core.domain.R;
 
-import java.util.List;
-import java.util.Map;
 
 public interface CadastreManageService {
 
     CompareResultVo getCompareData(String uploadId) ;
 
-    CadastreFile saveUploadFile(String theFileName, String theFilePath, String fromRoute);
+    CadastreFile saveUploadFile(String theFileName, String theFilePath, String fileType,String updateType);
 
-    CheckInfoResultVo checkFileData(String theFileName, String theFilePath, String fromRoute);
+    String addBatchGdbData(String uploadId);
 
+    CheckInfoResultVo checkFileData(String theFileName, String theFilePath, String fileType,String updateType);
 
-    String addBatchGdbData(String uploadId);
 
 }

+ 78 - 26
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/cadastre/impl/CadastreManageServiceImpl.java

@@ -23,6 +23,7 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.*;
+import java.util.stream.Collectors;
 
 
 /**
@@ -43,6 +44,9 @@ public class CadastreManageServiceImpl implements CadastreManageService {
 
 
     /**
+     *
+     * 解析文件内容,insert 到表中
+     *
      *
      * 1.进行解析数据成为list<map></map>
      * 2.进行调用方法动态插入到当前表中
@@ -84,9 +88,17 @@ public class CadastreManageServiceImpl implements CadastreManageService {
                 if (dbFieldNameList.contains("geom")) {
                     haveGeom = true;
                 }
-                List<Map<String, String>> theValueList = getValueList(layer, haveGeom);
+
+                List<Map<String,String>> dbFieldNameAndTypeList = cadastreFileMapper.selectTableCollumAndType(layerName.toLowerCase(Locale.ROOT));
+                Map<String,String> dbFieldNameAndTypeMap = dbFieldNameAndTypeList.stream().collect(Collectors.toMap(
+                        s ->  s.get("column_name"),
+                        s -> s.get("data_type"),
+                        (existing, replacement) -> existing // 如果有重复键,保留第一个值
+                ));
+
+                List<Map<String, Object>> theValueList = getValueList(layer,dbFieldNameAndTypeMap, haveGeom);
                 //这里直接数据入库,区分增量或者全量
-                Boolean addRes = fullDataStorage(layerName,theValueList);
+                Boolean addRes = fullDataStorage(layerName, theValueList);
                 log.error("当前图层{},入库结果 {}", layerName, addRes);
                 //Boolean checkRes2 = incrementalDataStorage(layer);
             }
@@ -110,6 +122,19 @@ public class CadastreManageServiceImpl implements CadastreManageService {
         CompareResultVo compareResultVo = new CompareResultVo();
         compareResultVo.setUploadId(uploadId);
         compareResultVo.setResultStatus(true);
+
+
+
+//        //todo 这里进行
+//        List<Map<String,String>> collumTypes =  cadastreFileMapper.selectTableCollumAndType("mzdzw");
+//        if(true){
+//            log.info(collumTypes.toString());
+//            return compareResultVo;
+//        }
+
+
+
+
         try {
             List<CompareGemoVo> gemos = new ArrayList<>();
             CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
@@ -146,15 +171,15 @@ public class CadastreManageServiceImpl implements CadastreManageService {
 
 
     /**
-     * 文件入库
+     * 文件upload入库
      *
      * @param theFileName
      * @param theFilePath
-     * @param fromRoute
+     * @param fileType
      * @return
      */
     @Override
-    public CadastreFile saveUploadFile(String theFileName, String theFilePath, String fromRoute) {
+    public CadastreFile saveUploadFile(String theFileName, String theFilePath, String fileType, String updateType) {
         try {
             if (theFilePath == null || theFilePath.trim().isEmpty()) {
                 log.warn("处理文件失败:filePath不能为空");
@@ -180,6 +205,15 @@ public class CadastreManageServiceImpl implements CadastreManageService {
                     cadastreFile.setFilePath(theFilePath);
                     cadastreFile.setUnzipPath(unZipPath);
                     cadastreFile.setFileType("1");//矢量/表格
+                    if (StringUtils.isNotBlank(fileType)) {
+                        cadastreFile.setFileType(fileType);
+                    }
+
+                    //0 为全量更新,1为增量更新
+                    if (StringUtils.isNotBlank(updateType)) {
+                        cadastreFile.setStatus(updateType);
+                    }
+
                     cadastreFile.setUploadUser("admin");
                     cadastreFile.setUploadTime(new Date());
                     cadastreFile.setReadMessage("入库成功");
@@ -207,17 +241,19 @@ public class CadastreManageServiceImpl implements CadastreManageService {
      *
      * @param theFileName
      * @param theFilePath
-     * @param fromRoute
+     * @param fileType
+     * @param updateType
      * @return
      */
     @Override
-    public CheckInfoResultVo checkFileData(String theFileName, String theFilePath, String fromRoute) {
+    public CheckInfoResultVo checkFileData(String theFileName, String theFilePath, String fileType, String updateType) {
         CheckInfoResultVo checkInfoResult = new CheckInfoResultVo();
         checkInfoResult.setResultStatus(true);
         List<CheckInfoVo> checkInfoSuccessList = new ArrayList<>();
         List<CheckInfoVo> checkInfoFailList = new ArrayList<>();
 
-        CadastreFile uploadFile = this.saveUploadFile(theFileName, theFilePath, fromRoute);
+        CadastreFile uploadFile = this.saveUploadFile(theFileName, theFilePath, fileType, updateType);
+
         if (Objects.nonNull(uploadFile)) {
             //入库成功
             fzssFxrwrzHandleService.insertFxrwrz(uploadFile.getId(), "地籍库管理", "上传文件成功", "info");
@@ -294,7 +330,7 @@ public class CadastreManageServiceImpl implements CadastreManageService {
             haveGeom = true;
         }
 
-        List<String> layerFieldNameList = getFieldName(layer, haveGeom);
+        List<String> layerFieldNameList = this.getFieldName(layer, haveGeom);
         // 判断是否包含相同的元素(不考虑顺序)
         boolean areCollectionsEqual = CollectionUtils.isEqualCollection(dbFieldNameList, layerFieldNameList);
         if (!areCollectionsEqual) {
@@ -302,22 +338,23 @@ public class CadastreManageServiceImpl implements CadastreManageService {
             checkInfoVo.setCheckStatus(false);
         }
 
-        //todo 检查字段数据是否为空
-        //仅仅获取图层属性
-        List<Map<String, String>> theValueList = getValueList(layer, false);
+        //检查字段数据是否为空
         //todo 这里根据表名获取相关校验字段信息
         List<String> checkFieldList = new ArrayList<>();
         //checkFieldList.add("111");
         checkFieldList.add("bz");
-        for (Map<String, String> theMap : theValueList) {
+        //仅获取图层属性
+        List<Map<String, Object>> theValueList = getValueList(layer,new LinkedHashMap<>(), false);
+        for (Map<String, Object> theMap : theValueList) {
             for (String fieldName : checkFieldList) {
-                if (com.siwei.common.core.utils.StringUtils.isBlank(theMap.get(fieldName))) {
+                if (Objects.isNull(theMap.get(fieldName))) {
                     checkInfoList.add(name + "--" + fieldName + "字段不能为空!");
                     checkInfoVo.setCheckStatus(false);
                 }
             }
         }
         checkInfoVo.setCheckInfoList(checkInfoList);
+        //todo 这里需要放入到缓存中,并且可以下载为txt内容
         return checkInfoVo;
     }
 
@@ -349,15 +386,33 @@ public class CadastreManageServiceImpl implements CadastreManageService {
      * @param layer
      * @return
      */
-    private List<Map<String, String>> getValueList(Layer layer, Boolean haveGeom) {
-        List<Map<String, String>> list = new ArrayList<>();
-        Map<String, String> map = new LinkedHashMap<>();
+    private List<Map<String, Object>> getValueList(Layer layer,Map<String,String> fieldNameAndTypeMap , Boolean haveGeom) {
+        List<Map<String, Object>> list = new ArrayList<>();
+        Map<String, Object> map = new LinkedHashMap<>();
         layer.ResetReading();
         Feature feature;
         while ((feature = layer.GetNextFeature()) != null) {
             for (int i = 0; i < feature.GetFieldCount(); i++) {
-                map.put(feature.GetFieldDefnRef(i).GetName(), feature.GetFieldAsString(i));
+                String fieldName = feature.GetFieldDefnRef(i).GetName();
+                if(fieldNameAndTypeMap.containsKey(fieldName.toLowerCase())) {
+                    String fieldType = fieldNameAndTypeMap.get(fieldName);
+                    if (StringUtils.containsIgnoreCase(fieldType, "character")) {
+                        map.put(fieldName, feature.GetFieldAsString(i));
+                    } else if (StringUtils.containsIgnoreCase(fieldType, "integer")) {
+                        map.put(fieldName, feature.GetFieldAsInteger(i));
+                    } else if (StringUtils.containsIgnoreCase(fieldType, "date")) {
+                        //todo 日期转化
+                        map.put(fieldName, feature.GetFieldAsString(i));
+                    } else if (StringUtils.containsIgnoreCase(fieldType, "numeric")) {
+                        map.put(fieldName, feature.GetFieldAsDouble(i));
+                    } else {
+                        map.put(fieldName, feature.GetFieldAsString(i));
+                    }
+                }else {
+                    map.put(fieldName, feature.GetFieldAsString(i));
+                }
             }
+
             if (haveGeom.equals(true)) {
                 String wkt = null;
                 Geometry geom = feature.GetGeometryRef();
@@ -462,30 +517,27 @@ public class CadastreManageServiceImpl implements CadastreManageService {
     }
 
 
-
-
     /**
      * 这里需要开启事务
      * 数据全量入库
+     *
      * @param tableName
      * @param theValueList
      * @return
      */
-    private Boolean fullDataStorage(String tableName,List<Map<String, String>> theValueList) {
+    private Boolean fullDataStorage(String tableName, List<Map<String, Object>> theValueList) {
         boolean addRes = false;
         if (!CollectionUtils.isEmpty(theValueList)) {
-            for (Map<String, String> map : theValueList) {
-                Collection<String> values = map.values();
+            for (Map<String, Object> map : theValueList) {
+                Collection<Object> values = map.values();
                 Collection<String> keys = map.keySet();
-                cadastreFileMapper.insertTableData(tableName,keys,values);
+                cadastreFileMapper.insertTableData(tableName, keys, values);
             }
         }
         return addRes;
     }
 
 
-
-
     /**
      * 数据增量入库
      *

+ 12 - 1
siwei-modules/siwei-apply/src/main/resources/mapper/cadastre/CadastreFileMapper.xml

@@ -77,13 +77,24 @@
         </where>
     </select>
 
-    <select id="selectTableCollum" parameterType="String" resultType="string">
+    <select id="selectTableCollum" parameterType="String" resultType="String">
         select COLUMN_NAME FROM  information_schema.COLUMNS
         WHERE
             table_schema = 'vector'
           AND TABLE_NAME = #{tableName}
     </select>
 
+
+    <select id="selectTableCollumAndType" parameterType="String" resultType="map">
+        select COLUMN_NAME, DATA_TYPE FROM  information_schema.COLUMNS
+        WHERE
+            table_schema = 'vector'
+          AND TABLE_NAME = #{tableName}
+    </select>
+
+
+
+
     <select id="selectAllTable"  resultType="string">
         select table_name from information_schema.tables
         where table_schema = 'vector'