1
0
chenendian 1 месяц назад
Родитель
Сommit
e185c308d6

+ 63 - 39
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/cadastre/impl/CadastreManageServiceImpl.java

@@ -138,8 +138,8 @@ public class CadastreManageServiceImpl implements CadastreManageService {
             //更新状态
             CadastreFile updateCadastreFile = new CadastreFile();
             updateCadastreFile.setId(uploadId);
-            updateCadastreFile.setStatus("2");//入库成功
-            updateCadastreFile.setReadMessage("入库失败");//入库成功
+            updateCadastreFile.setStatus("2");//入库失败
+            updateCadastreFile.setReadMessage("入库失败");//入库失败
             cadastreFileMapper.update(updateCadastreFile);
             fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "当前批次-" + uploadId + "-入库失败", "info");
             throw new ServiceException("矢量数据入库异常," + e.getMessage());
@@ -215,8 +215,8 @@ public class CadastreManageServiceImpl implements CadastreManageService {
             //更新状态
             CadastreFile updateCadastreFile = new CadastreFile();
             updateCadastreFile.setId(uploadId);
-            updateCadastreFile.setStatus("2");//入库成功
-            updateCadastreFile.setReadMessage("入库失败");//入库成功
+            updateCadastreFile.setStatus("2");//入库失败
+            updateCadastreFile.setReadMessage("入库失败");//入库失败
             cadastreFileMapper.update(updateCadastreFile);
             fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "当前批次-" + uploadId + "-入库失败", "info");
             throw new ServiceException("表格数据入库异常," + e.getMessage());
@@ -750,7 +750,6 @@ public class CadastreManageServiceImpl implements CadastreManageService {
         return haveGeom;
     }
 
-
     /**
      * 获取对比的矢量图层
      *
@@ -772,7 +771,6 @@ public class CadastreManageServiceImpl implements CadastreManageService {
                 }
                 // 将几何对象转换为 WKT 格式
                 ewkt = "SRID=" + 4326 + ";" + geom.ExportToWkt();
-                ;
             }
             list.add(ewkt);
         }
@@ -871,7 +869,6 @@ public class CadastreManageServiceImpl implements CadastreManageService {
                 return false;
             }
         }
-
         Object geom1 = map1.get("geom");
         Object geom2 = map2.get("geom");
         if (geom1 != null && geom2 != null && !geom1.equals(geom2)) return false;
@@ -991,40 +988,51 @@ public class CadastreManageServiceImpl implements CadastreManageService {
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
     @Override
     public String backToOldData(String uploadId) {
-        //1.获取所有表名。
-        //2.校验是否都有历史版本。
-        //3.如果都有历史版本,则把当前版本删除,把历史版本修改为当前版本。
-
-//        CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
-//        if(!"2".equals(cadastreFile.getReadStatus())){
-//            throw new ServiceException("可能入库失败或没有历史版本,无法回退");
-//        }
-
+        try {
+            CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
+            if (!"1".equals(cadastreFile.getStatus())) {
+                throw new ServiceException("可能未入库成功,无法回退");
+            }
 
-        List<String> layerNameList = getLayerNameList(uploadId);
-        for (String layerName : layerNameList) {
-            if (!layerName.equalsIgnoreCase("T_CGZJ_CWTC_M")
-                    && !layerName.equalsIgnoreCase("T_FZSS_FXRW_GIS")
-            ) {
-                continue;
+            List<String> fileTableNameList = new ArrayList<>();
+            if ("1".equals(cadastreFile.getFileType())) {//矢量数据
+                fileTableNameList = getLayerNameList(uploadId);
+            } else if ("2".equals(cadastreFile.getFileType())) { //表格数据
+                fileTableNameList = getMdbTableNameList(uploadId);
             }
 
-            //校验是否都有历史版本
-            Integer count = cadastreFileMapper.countByValidFlag("1", layerName.toLowerCase(Locale.ROOT));
-            if (count == 0) {
-                throw new ServiceException("表" + layerName + "没有历史版本,无法回退");
+            for (String layerName : fileTableNameList) {
+                if (!layerName.equalsIgnoreCase("T_CGZJ_CWTC_M")
+                        && !layerName.equalsIgnoreCase("T_FZSS_FXRW_GIS")
+                        && !layerName.equalsIgnoreCase("City")
+                        && !layerName.equalsIgnoreCase("XZQ")
+                ) {
+                    continue;
+                }
+                //校验是否都有历史版本
+                Integer count = cadastreFileMapper.countByValidFlag("1", layerName.toLowerCase(Locale.ROOT));
+                if (count == 0) {
+                    throw new ServiceException("表" + layerName + "没有历史版本,无法回退");
+                }
             }
-        }
 
-        for (String layerName : layerNameList) {
-            if (
-                    !layerName.equalsIgnoreCase("T_CGZJ_CWTC_M") &&
-                            !layerName.equalsIgnoreCase("T_FZSS_FXRW_GIS")) {
-                continue;
+            for (String layerName : fileTableNameList) {
+                if (
+                        !layerName.equalsIgnoreCase("T_CGZJ_CWTC_M")
+                                && !layerName.equalsIgnoreCase("T_FZSS_FXRW_GIS")
+                                && !layerName.equalsIgnoreCase("City")
+                                && !layerName.equalsIgnoreCase("XZQ")
+                ) {
+                    continue;
+                }
+
+                cadastreFileMapper.deleteByValidFlag("0", layerName.toLowerCase(Locale.ROOT));
+                cadastreFileMapper.updateValidFlag("0", "1", layerName.toLowerCase(Locale.ROOT));
+                log.info("正在回退表:{}。。。", layerName);
             }
-            cadastreFileMapper.deleteByValidFlag("0", layerName.toLowerCase(Locale.ROOT));
-            cadastreFileMapper.updateValidFlag("0", "1", layerName.toLowerCase(Locale.ROOT));
-            log.info("正在回退表:{}。。。", layerName);
+        } catch (Exception e) {
+            log.error("数据回退异常,uploadId: {}", uploadId, e);
+            throw new ServiceException("数据回退异常," + e.getMessage());
         }
 
 //        //成功则更新状态
@@ -1061,6 +1069,25 @@ public class CadastreManageServiceImpl implements CadastreManageService {
     }
 
 
+    /**
+     *
+     * 获取mdb文件中表名称
+     *
+     * @param uploadId
+     * @return
+     */
+    public List<String> getMdbTableNameList(String uploadId) throws Exception {
+        List<String> nameList = new ArrayList<>();
+        CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
+        String gdbPath = cadastreFile.getUnzipPath();
+        List<Map<String, Object>> allMdbTableList = MdbUtil.MdbTables(gdbPath + "/" + cadastreFile.getName(), "", "");
+        for (Map<String, Object> tableMap : allMdbTableList) {
+            String talbleName = String.valueOf(tableMap.get("name"));
+            nameList.add(talbleName);
+        }
+        return nameList;
+    }
+
     //1.获取图层中所有数据
     //2.获取库中所有数据
     //3.进行对比返回
@@ -1121,6 +1148,7 @@ public class CadastreManageServiceImpl implements CadastreManageService {
 
     /**
      * 获取表格数据进行对比
+     *
      * @param uploadId
      * @return
      */
@@ -1168,9 +1196,6 @@ public class CadastreManageServiceImpl implements CadastreManageService {
     }
 
 
-
-
-
     @Override
     public List<MdbAndDbData> getMdbCompareData(String uploadId) {
         List<MdbAndDbData> resList = new ArrayList<>();
@@ -1232,5 +1257,4 @@ public class CadastreManageServiceImpl implements CadastreManageService {
     }
 
 
-
 }