管道基础大数据平台系统开发-【后端】-Server
3
13693261870
2023-01-10 3af5e8f2335b3d5cd4528f9ee9f326eef5fe2f9a
3
已修改4个文件
151 ■■■■ 文件已修改
src/main/java/com/lf/server/entity/all/StaticData.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/helper/FileHelper.java 32 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/helper/Md5Helper.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/all/BaseUploadService.java 116 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/entity/all/StaticData.java
@@ -10,7 +10,7 @@
 */
public class StaticData {
    /**
     * 权限排除路径:/proxy
     * 权限排除路径:/proxy,要求全部小写
     */
    public static String[] EXCLUDE_PATH = new String[]{"/swagger", "/sign/", "/fmeit/", "/floatserver/", "/error"};
src/main/java/com/lf/server/helper/FileHelper.java
@@ -1,7 +1,6 @@
package com.lf.server.helper;
import com.lf.server.entity.all.StaticData;
import com.lf.server.entity.data.MetaEntity;
import com.lf.server.entity.data.MetaFileEntity;
import com.twmacinta.util.MD5;
import org.apache.commons.codec.digest.DigestUtils;
@@ -13,6 +12,7 @@
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.text.DecimalFormat;
import java.util.List;
@@ -198,7 +198,7 @@
    }
    /**
     * 获取文件MD5码(JDK)
     * 3.获取文件MD5码(JDK)
     */
    public static String getMd5ByJdk(String filePath) throws IOException {
        FileInputStream fileStream = new FileInputStream(filePath);
@@ -209,7 +209,7 @@
    }
    /**
     * 获取快速 MD5 码
     * 2.获取快速 MD5 码
     */
    public static String getFastMd5(String filePath) throws IOException {
        String hash = MD5.asHex(MD5.getHash(new File(filePath)));
@@ -305,9 +305,7 @@
    }
    /**
     * 获取文件的MD5
     * @param filePath
     * @return
     * 1.获取文件的MD5
     */
    @SuppressWarnings("unused")
    public static String getFileMd5(String filePath) {
@@ -341,6 +339,9 @@
        }
    }
    /**
     * 字节码转16进制
     */
    public static String byteToHexString(byte[] tmp) {
        // 每个字节用 16 进制表示的话,使用两个字符,
        char[] str = new char[16 * 2];
@@ -359,4 +360,23 @@
        // 换后的结果转换为字符串
        return new String(str);
    }
    /**
     * 获取字符串的MD5码
     */
    public static String getStringMd5(String text) {
        StringBuilder builder = new StringBuilder();
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            byte[] bytes = md5.digest(text.getBytes(StandardCharsets.UTF_8));
            for (byte aByte : bytes) {
                builder.append(Integer.toHexString((0x000000FF & aByte) | 0xFFFFFF00).substring(6));
            }
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
        }
        return builder.toString();
    }
}
src/main/java/com/lf/server/helper/Md5Helper.java
@@ -94,7 +94,6 @@
        StringBuilder sb = new StringBuilder(pass);
        return sb.reverse().toString();
    }
    /**
src/main/java/com/lf/server/service/all/BaseUploadService.java
@@ -259,7 +259,7 @@
            boolean isShp = StaticData.SHP.equals(extName);
            if (isGdb) {
                //
                String md5 = getGdbMd5(f.getPath());
                continue;
            }
@@ -270,7 +270,7 @@
            mf.setPath(f.getPath().substring(subPath.length()));
            if (isShp) {
                mf.setTab(fileName);
                //
                mf.setGuid(getShpMd5(f.getPath()));
            } else {
                mf.setGuid(FileHelper.getFileMd5(f.getPath()));
            }
@@ -295,89 +295,59 @@
        return mf;
    }
    /*private List<TabMapperEntity> getMappers(String zipPath, File[] files) {
        String temp = pathHelper.getConfig().getTempPath();
    /**
     * 获取SHP文件的MD5码
     */
    private String getShpMd5(String shpPath) {
        List<String> files = new ArrayList<>();
        files.add(shpPath);
        List<TabMapperEntity> list = new ArrayList<>();
        for (File f : files) {
            String fileName = FileHelper.getFileName(f.getPath());
            if (fileName.contains(XLS)) {
                String path = f.getPath().replace(temp + File.separator, "");
                list.add(new TabMapperEntity(fileName, "xls", null, path));
                continue;
            }
            if (fileName.contains(MDB)) {
                String path = f.getPath().replace(temp + File.separator, "");
                List<String> tabs = MdbHelper.getTabNames(f.getPath());
                for (String tab : tabs) {
                    list.add(new TabMapperEntity(fileName, "mdb", tab, path));
                }
                continue;
            }
            if (fileName.contains(SHP_ZIP)) {
                String subPath = zipPath + File.separator + f.getName().toLowerCase().replace(".zip", "");
                ZipHelper.unzip(f.getPath(), subPath);
                getShpFiles(f.getName(), subPath, list);
                continue;
            }
            if (fileName.contains(GDB_ZIP)) {
                String subPath = zipPath + File.separator + f.getName().toLowerCase().replace(".zip", "");
                ZipHelper.unzip(f.getPath(), subPath);
                getGdbFiles(f.getName(), subPath, list);
                continue;
            }
            if (fileName.contains(ZIP)) {
                // 暂时不实现
        for (int i = 1, c = StaticData.SHP_EXTENSION.size(); i < c; i++) {
            String path = shpPath.replace(".shp", StaticData.SHP_EXTENSION.get(i));
            File f = new File(path);
            if (f.exists() && !f.isDirectory()) {
                files.add(path);
            }
        }
        return list;
        return getFilesMd5(files);
    }
    private void getShpFiles(String sourceName, String subPath, List<TabMapperEntity> list) {
        List<String> files = new ArrayList<>();
        getShpFiles(subPath, files);
        String root = pathHelper.getConfig().getTempPath() + File.separator;
        for (String file : files) {
            String name = FileHelper.getFileName(file);
            String path = file.replace(root, "");
            list.add(new TabMapperEntity(sourceName, "shp", name, path));
        }
    }
    private void getGdbFiles(String sourceName, String subPath, List<TabMapperEntity> list) {
        List<String> files = new ArrayList<>();
        getGdbFiles(subPath, files);
        String root = pathHelper.getConfig().getTempPath() + File.separator;
        for (String file : files) {
            String path = file.replace(root, "");
            List<String> tabs = GdbHelper.getTabNames(file);
            for (String tab : tabs) {
                list.add(new TabMapperEntity(sourceName, "gdb", tab, path));
            }
        }
    }*/
    private void getShpFiles(String shpPath, List<String> list) {
        File file = new File(shpPath);
        File[] files = file.listFiles();
    /**
     * 获取GDB文件的MD5码
     */
    private String getGdbMd5(String path) {
        File[] files = new File(path).listFiles();
        if (null == files || files.length == 0) {
            return;
            return StringHelper.getGuid();
        }
        List<String> list = new ArrayList<>();
        for (File f : files) {
            if (f.isDirectory()) {
                getShpFiles(f.getPath(), list);
                continue;
            }
            list.add(f.getPath());
        }
            if (f.getName().toLowerCase().endsWith(".shp")) {
                list.add(f.getPath());
        return getFilesMd5(list);
    }
    /**
     * 获取多文件的MD5
     */
    private String getFilesMd5(List<String> list) {
        StringBuilder sb = new StringBuilder();
        for (String str : list) {
            String md5 = FileHelper.getFileMd5(str);
            if (null != md5) {
                sb.append(sb + ",");
            }
        }
        if (sb.length() > 0) {
            return FileHelper.getStringMd5(sb.toString());
        }
        return StringHelper.getGuid();
    }
    private void getGdbFiles(String shpPath, List<String> list) {
@@ -423,7 +393,7 @@
    }
    /**
     * 获取参数
     * 获取参数 *
     * Enumeration<String> headers = req.getHeaderNames();
     * Enumeration<String> attributes = req.getAttributeNames();
     */