Преглед изворни кода

文件入库后更新状态

chenendian пре 2 месеци
родитељ
комит
17efee9a36

+ 5 - 163
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/cadastre/MdbController.java

@@ -1,4 +1,5 @@
 package com.siwei.apply.controller.cadastre;
+import com.siwei.apply.utils.MdbUtil;
 import com.siwei.common.core.utils.StringUtils;
 import com.siwei.common.core.web.controller.BaseController;
 import org.json.simple.JSONObject;
@@ -20,16 +21,15 @@ import java.util.*;
 public class MdbController extends BaseController {
 
 
-
     @GetMapping("/gettablesMdb")
     public void gettablesMdb() throws Exception {
         String folderURL = "C:\\Users\\Administrator\\Desktop\\06\\XZQData.mdb";
-        List<Map<String, Object>> resList = MdbTables(folderURL, null, null);
+        List<Map<String, Object>> resList = MdbUtil.MdbTables(folderURL, null, null);
 
         Map<String, Object> map = resList.get(0);
         String tablename = map.get("name").toString();
 
-        Map<String, Object> resMap = MdbTableContent(folderURL,tablename, null, null, 1, 10);
+        Map<String, Object> resMap = MdbUtil.MdbTableContent(folderURL,tablename, null, null, 1, 10);
         System.out.println(resMap);
 
         System.out.println(resMap);
@@ -64,7 +64,7 @@ public class MdbController extends BaseController {
             if (StringUtils.isEmpty(folderURL)) {
                 return;
             }
-            List<Map<String, Object>> res = MdbTables(folderURL, null, null);
+            List<Map<String, Object>> res = MdbUtil.MdbTables(folderURL, null, null);
             JSONObject respJSON = new JSONObject();
             respJSON.put("data", res);
             respJSON.put("code", 200);
@@ -122,7 +122,7 @@ public class MdbController extends BaseController {
             if (StringUtils.isEmpty(folderURL)) {
                 return;
             }
-            Map<String, Object> res = MdbTableContent(folderURL, tablename, null, null, page, limit);
+            Map<String, Object> res = MdbUtil.MdbTableContent(folderURL, tablename, null, null, page, limit);
             JSONObject respJSON = new JSONObject();
             respJSON.put("data", res);
             respJSON.put("code", 200);
@@ -147,163 +147,5 @@ public class MdbController extends BaseController {
         return;
     }
 
-    /**
-     * 读取.mdb文件下面的所有表名
-     *
-     * @param mdbPath  mdb文件地址
-     * @param username 用户名
-     * @param password 密码
-     */
-    public List<Map<String, Object>> MdbTables(String mdbPath, String username, String password) throws Exception {
-        List<Map<String, Object>> list = new ArrayList<>();
-        Properties Prop = new Properties();
-        //设置编码
-        Prop.put("charSet", "UTF-8");
-        if (!StringUtils.isEmpty(username)) {
-            Prop.put("user", username);
-        }
-        if (!StringUtils.isEmpty(password)) {
-            Prop.put("password", password);
-        }
-        //数据地址
-        String dbUrl = "jdbc:ucanaccess://" + mdbPath;
-        //引入驱动
-        Class.forName("net.ucanaccess.jdbc.UcanaccessDriver").newInstance();
-        Connection conn = null;
-        ResultSet tables = null;
-        PreparedStatement preparedStatement = null;
-        ResultSet rs = null;
-        try {
-            //连接数据库资源
-            conn = DriverManager.getConnection(dbUrl, Prop);
-            tables = conn.getMetaData().getTables(mdbPath, null, null, new String[]{"TABLE"});
-            //遍历表
-            while (tables.next()) {
-                Map<String, Object> tableMap = new HashMap<>();
-                String tableName = tables.getString(3);
-                String tableAlias = tables.getString(4);
-                tableMap.put("name", tableName);
-                tableMap.put("alias", tableName);
-                if (!tableName.contains("GDB_")) {
-                    list.add(tableMap);
-                }
-                String cur = "";
-                for (int u = 0; u < tables.getMetaData().getColumnCount(); u++) {
-                    String key = tables.getMetaData().getColumnLabel(u + 1);
-                    cur += ";" + key + ":" + tables.getString(key);
-                }
-                System.out.println(cur);
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-            System.out.println("resolverMdb is error!!!");
-        } finally {
-            closeA1l(conn, preparedStatement, tables, rs);
-        }
-        return list;
-    }
 
-
-    /**
-     * 读取.mdb文件中指定表
-     *
-     * @param mdbPath  mdb文件地址
-     * @param username 用户名
-     * @param password 密码
-     */
-    public Map<String, Object> MdbTableContent(String mdbPath, String tablename, String username, String password, Integer page, Integer limit) throws Exception {
-        Map<String, Object> tableMap = new HashMap<>(16);
-        Properties Prop = new Properties();
-        //设置编码
-        Prop.put("charSet", "UTF-8");
-        if (!StringUtils.isEmpty(username)) {
-            Prop.put("user", username);
-        }
-        if (!StringUtils.isEmpty(password)) {
-            Prop.put("password", password);
-        }
-        //数据地址
-        String dbUrl = "jdbc:ucanaccess://" + mdbPath;
-        //引入驱动
-        Class.forName("net.ucanaccess.jdbc.UcanaccessDriver").newInstance();
-        Connection conn = null;
-        ResultSet tables = null;
-        PreparedStatement preparedStatement = null;
-        ResultSet rs = null;
-        PreparedStatement countPreparedStatement = null;
-        ResultSet currs = null;
-        try {
-            //连接数据库资源
-            conn = DriverManager.getConnection(dbUrl, Prop);
-            Integer RowStart = (page - 1) * limit;
-            Integer RowEnd = (page - 0) * limit;
-            preparedStatement = conn.prepareStatement("select * from " + tablename + " t limit " + RowStart + "," + limit);
-            List<String> columnList = new ArrayList<>();
-            List<Map<String, String>> dataList = new ArrayList<>();
-            rs = preparedStatement.executeQuery();
-            ResultSetMetaData data = rs.getMetaData();
-            for (int i = 1; i <= data.getColumnCount(); i++) {
-                //列名
-                String columnName = data.getColumnName(i);
-                columnList.add(columnName);
-            }
-            while (rs.next()) {
-                Map<String, String> map = new HashMap<>();
-                for (int i = 1; i <= data.getColumnCount(); i++) {
-                    //列名
-                    String columnName = data.getColumnName(i);
-                    //map.put(columnName, rs.getString(i));
-                    Object value = rs.getObject(i);
-                    if (value instanceof Blob) {
-                        map.put(columnName, "[BLOB]"); //todo 这里先简单处理一下blob类型,后续可以根据实际需求进行优化
-                    } else {
-                        map.put(columnName, String.valueOf(value));
-                    }
-                }
-                dataList.add(map);
-            }
-            //查询总记录数
-            countPreparedStatement = conn.prepareStatement("select count(1) from " + tablename + " t ");
-            currs = countPreparedStatement.executeQuery();
-            while (currs.next()) {
-                tableMap.put("count", Integer.valueOf(currs.getString(1)));
-            }
-            tableMap.put("name", tablename);
-            tableMap.put("column", columnList);
-            tableMap.put("rows", dataList);
-        } catch (Exception e) {
-            e.printStackTrace();
-            System.out.println("resolverMdb is error!!!");
-        } finally {
-            closeA1l(conn, preparedStatement, tables, rs);
-            closeA1l(conn, countPreparedStatement, null, currs);
-        }
-        return tableMap;
-    }
-
-    /**
-     * 关闭所有的资源链接
-     *
-     * @param conn              连接
-     * @param preparedStatement 初始化 执行语句
-     * @param tables            结果集
-     * @param rs                结果集
-     */
-    public void closeA1l(Connection conn, PreparedStatement preparedStatement, ResultSet tables, ResultSet rs) {
-        try {
-            if (null != rs) {
-                rs.close();
-            }
-            if (null != tables) {
-                tables.close();
-            }
-            if (null != preparedStatement) {
-                preparedStatement.close();
-            }
-            if (null != conn) {
-                conn.close();
-            }
-        } catch (Exception ignore) {
-        }
-    }
 }

+ 12 - 6
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/cadastre/impl/CadastreManageServiceImpl.java

@@ -117,6 +117,13 @@ public class CadastreManageServiceImpl implements CadastreManageService {
                     addRes = fullDataStorage(layerName, theValueList);
                 }
 
+                //成功则更新状态
+                cadastreFile = new CadastreFile();
+                cadastreFile.setId(cadastreFile.getId());
+                cadastreFile.setStatus("2");//校验通过
+                cadastreFile.setReadMessage("入库成功");//校验通过
+                cadastreFileMapper.update(cadastreFile);
+
                 log.error("当前图层{},入库结果 {}", layerName, addRes);
             }
         } catch (Exception e) {
@@ -195,12 +202,12 @@ public class CadastreManageServiceImpl implements CadastreManageService {
                 log.warn("处理文件失败:filePath不能为空");
                 return null;
             }
-            Path file = Paths.get(theFilePath);
-            if (!Files.exists(file)) {
+            Path currentFilePath = Paths.get(theFilePath);
+            if (!Files.exists(currentFilePath)) {
                 log.warn("处理文件失败:文件不存在: {}", theFilePath);
                 return null;
             }
-            Long  fileSize = Files.size(file);
+            Long  fileSize = Files.size(currentFilePath);
 
             // 判断是否为压缩文件
             if (FileExtractUtil.isCompressedFile(theFilePath)) {
@@ -212,8 +219,7 @@ public class CadastreManageServiceImpl implements CadastreManageService {
                 }
 
                 //这里解压文件名称作为文件名
-                Path extractPath = Paths.get(extractRes);
-                String fileName = extractPath.getFileName().toString();
+                String fileName = currentFilePath.getFileName().toString();
                 theFileName = fileName.substring(0, fileName.lastIndexOf('.'));
 
                 //解压成功文件保存
@@ -246,7 +252,7 @@ public class CadastreManageServiceImpl implements CadastreManageService {
                     cadastreFile.setStatus("0");
                     cadastreFile.setUploadUser("admin");
                     cadastreFile.setUploadTime(new Date());
-                    cadastreFile.setReadMessage("入库成功");
+                    cadastreFile.setReadMessage("入库中。。。");
                     cadastreFile.setUpdateTime(new Date());
                     cadastreFileMapper.add(cadastreFile);
                     return cadastreFile;

+ 176 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/utils/MdbUtil.java

@@ -0,0 +1,176 @@
+package com.siwei.apply.utils;
+
+import com.siwei.common.core.utils.StringUtils;
+
+import java.sql.*;
+import java.util.*;
+
+/**
+ * 资源码工具
+ */
+public class MdbUtil {
+
+
+    /**
+     * 读取.mdb文件下面的所有表名
+     *
+     * @param mdbPath  mdb文件地址
+     * @param username 用户名
+     * @param password 密码
+     */
+    public static List<Map<String, Object>> MdbTables(String mdbPath, String username, String password) throws Exception {
+        List<Map<String, Object>> list = new ArrayList<>();
+        Properties Prop = new Properties();
+        //设置编码
+        Prop.put("charSet", "UTF-8");
+        if (!StringUtils.isEmpty(username)) {
+            Prop.put("user", username);
+        }
+        if (!StringUtils.isEmpty(password)) {
+            Prop.put("password", password);
+        }
+        //数据地址
+        String dbUrl = "jdbc:ucanaccess://" + mdbPath;
+        //引入驱动
+        Class.forName("net.ucanaccess.jdbc.UcanaccessDriver").newInstance();
+        Connection conn = null;
+        ResultSet tables = null;
+        PreparedStatement preparedStatement = null;
+        ResultSet rs = null;
+        try {
+            //连接数据库资源
+            conn = DriverManager.getConnection(dbUrl, Prop);
+            tables = conn.getMetaData().getTables(mdbPath, null, null, new String[]{"TABLE"});
+            //遍历表
+            while (tables.next()) {
+                Map<String, Object> tableMap = new HashMap<>();
+                String tableName = tables.getString(3);
+                String tableAlias = tables.getString(4);
+                tableMap.put("name", tableName);
+                tableMap.put("alias", tableName);
+                if (!tableName.contains("GDB_")) {
+                    list.add(tableMap);
+                }
+                String cur = "";
+                for (int u = 0; u < tables.getMetaData().getColumnCount(); u++) {
+                    String key = tables.getMetaData().getColumnLabel(u + 1);
+                    cur += ";" + key + ":" + tables.getString(key);
+                }
+                System.out.println(cur);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            System.out.println("resolverMdb is error!!!");
+        } finally {
+            closeA1l(conn, preparedStatement, tables, rs);
+        }
+        return list;
+    }
+
+
+    /**
+     * 读取.mdb文件中指定表
+     *
+     * @param mdbPath  mdb文件地址
+     * @param username 用户名
+     * @param password 密码
+     */
+    public static Map<String, Object> MdbTableContent(String mdbPath, String tablename, String username, String password, Integer page, Integer limit) throws Exception {
+        Map<String, Object> tableMap = new HashMap<>(16);
+        Properties Prop = new Properties();
+        //设置编码
+        Prop.put("charSet", "UTF-8");
+        if (!StringUtils.isEmpty(username)) {
+            Prop.put("user", username);
+        }
+        if (!StringUtils.isEmpty(password)) {
+            Prop.put("password", password);
+        }
+        //数据地址
+        String dbUrl = "jdbc:ucanaccess://" + mdbPath;
+        //引入驱动
+        Class.forName("net.ucanaccess.jdbc.UcanaccessDriver").newInstance();
+        Connection conn = null;
+        ResultSet tables = null;
+        PreparedStatement preparedStatement = null;
+        ResultSet rs = null;
+        PreparedStatement countPreparedStatement = null;
+        ResultSet currs = null;
+        try {
+            //连接数据库资源
+            conn = DriverManager.getConnection(dbUrl, Prop);
+            Integer RowStart = (page - 1) * limit;
+            Integer RowEnd = (page - 0) * limit;
+            preparedStatement = conn.prepareStatement("select * from " + tablename + " t limit " + RowStart + "," + limit);
+            List<String> columnList = new ArrayList<>();
+            List<Map<String, String>> dataList = new ArrayList<>();
+            rs = preparedStatement.executeQuery();
+            ResultSetMetaData data = rs.getMetaData();
+            for (int i = 1; i <= data.getColumnCount(); i++) {
+                //列名
+                String columnName = data.getColumnName(i);
+                columnList.add(columnName);
+            }
+            while (rs.next()) {
+                Map<String, String> map = new HashMap<>();
+                for (int i = 1; i <= data.getColumnCount(); i++) {
+                    //列名
+                    String columnName = data.getColumnName(i);
+                    //map.put(columnName, rs.getString(i));
+                    Object value = rs.getObject(i);
+                    if (value instanceof Blob) {
+                        map.put(columnName, "[BLOB]"); //todo 这里先简单处理一下blob类型,后续可以根据实际需求进行优化
+                    } else {
+                        map.put(columnName, String.valueOf(value));
+                    }
+                }
+                dataList.add(map);
+            }
+            //查询总记录数
+            countPreparedStatement = conn.prepareStatement("select count(1) from " + tablename + " t ");
+            currs = countPreparedStatement.executeQuery();
+            while (currs.next()) {
+                tableMap.put("count", Integer.valueOf(currs.getString(1)));
+            }
+            tableMap.put("name", tablename);
+            tableMap.put("column", columnList);
+            tableMap.put("rows", dataList);
+        } catch (Exception e) {
+            e.printStackTrace();
+            System.out.println("resolverMdb is error!!!");
+        } finally {
+            closeA1l(conn, preparedStatement, tables, rs);
+            closeA1l(conn, countPreparedStatement, null, currs);
+        }
+        return tableMap;
+    }
+
+    /**
+     * 关闭所有的资源链接
+     *
+     * @param conn              连接
+     * @param preparedStatement 初始化 执行语句
+     * @param tables            结果集
+     * @param rs                结果集
+     */
+    public static void closeA1l(Connection conn, PreparedStatement preparedStatement, ResultSet tables, ResultSet rs) {
+        try {
+            if (null != rs) {
+                rs.close();
+            }
+            if (null != tables) {
+                tables.close();
+            }
+            if (null != preparedStatement) {
+                preparedStatement.close();
+            }
+            if (null != conn) {
+                conn.close();
+            }
+        } catch (Exception ignore) {
+        }
+    }
+
+
+
+}