管道基础大数据平台系统开发-【后端】-Server
12
13693261870
2022-11-21 c518caf85891966a0e57f5760731c7f4e7044a05
src/main/java/com/lf/server/service/data/DataLoaderService.java
@@ -8,6 +8,7 @@
import com.lf.server.helper.ClassHelper;
import com.lf.server.helper.ExcelHelper;
import com.lf.server.helper.FileHelper;
import com.lf.server.helper.ZipHelper;
import com.lf.server.mapper.all.GeomBaseMapper;
import com.lf.server.service.all.BaseQueryService;
import com.lf.server.service.all.BaseUploadService;
@@ -16,6 +17,7 @@
import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
/**
@@ -34,9 +36,167 @@
    private final static String MDB = ".mdb";
    private final static String SHP = ".shp.zip";
    private final static String GDB = ".gdb";
    private final static String GDB = ".gdb.zip";
    private final static String SHP_ZIP = ".shp.zip";
    private final static String GDB_ZIP = ".gdb.zip";
    private final static String ZIP = ".zip";
    /**
     * 查询映射
     */
    public List<TabMapperEntity> selectMappers(String subPath) {
        String root = pathHelper.getConfig().getTempPath() + File.separator + subPath;
        File file = new File(root);
        if (!file.exists() && !file.isDirectory()) {
            return null;
        }
        File[] files = file.listFiles();
        if (null == files || files.length == 0) {
            return null;
        }
        File zipFile = new File(root + "_zip");
        if (!zipFile.exists() || !zipFile.isDirectory()) {
            zipFile.mkdirs();
        }
        return getMappers(zipFile.getPath(), files);
    }
    /**
     * 获取映射
     */
    private List<TabMapperEntity> getMappers(String zipPath, File[] files) {
        List<TabMapperEntity> list = new ArrayList<>();
        for (File f : files) {
            String fileName = FileHelper.getFileName(f.getPath());
            if (fileName.contains(XLS)) {
                list.add(new TabMapperEntity(fileName, "xls", fileName));
                continue;
            }
            if (fileName.contains(MDB)) {
                list.add(new TabMapperEntity(fileName, "mdb", fileName));
                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)){
                //
            }
        }
        return list;
    }
    /**
     * 获取Shp文件
     */
    private void getShpFiles(String sourceName, String subPath, List<TabMapperEntity> list) {
        List<String> files = new ArrayList<>();
        getShpFiles(subPath, files);
        String root = subPath.substring(0, subPath.lastIndexOf(File.separator) + 1);
        for (String file : files) {
            String name = FileHelper.getFileName(file);
            String path = file.replace(root, "");
            list.add(new TabMapperEntity(sourceName, "shp", name, path));
        }
    }
    /**
     * 获取Shp文件
     */
    private void getShpFiles(String shpPath, List<String> list) {
        File file = new File(shpPath);
        File[] files = file.listFiles();
        if (null == files || files.length == 0) {
            return;
        }
        for (File f : files) {
            if (f.isDirectory()) {
                getShpFiles(f.getPath(), list);
                continue;
            }
            if (f.getName().toLowerCase().endsWith(".shp")) {
                list.add(f.getPath());
            }
        }
    }
    /**
     * 获取Gdb文件
     */
    private void getGdbFiles(String sourceName, String subPath, List<TabMapperEntity> list){
        List<String> files = new ArrayList<>();
        getGdbFiles(subPath, files);
        String root = subPath.substring(0, subPath.lastIndexOf(File.separator) + 1);
        for (String file : files) {
            String name = FileHelper.getFileName(file);
            String path = file.replace(root, "");
            list.add(new TabMapperEntity(sourceName, "shp", name, path));
        }
    }
    /**
     * 获取Gdb文件
     */
    private void getGdbFiles(String shpPath, List<String> list) {
        File file = new File(shpPath);
        File[] files = file.listFiles();
        if (null == files || files.length == 0) {
            return;
        }
        for (File f : files) {
            if (!f.isDirectory()) {
                continue;
            }
            if (isGdbFile(f)) {
                list.add(f.getPath());
                continue;
            }
            getGdbFiles(f.getPath(), list);
        }
    }
    private boolean isGdbFile(File f) {
        if (f.getName().toLowerCase().endsWith(GDB)) {
            File[] files = f.listFiles();
            if (null == files || files.length == 0) {
                return false;
            }
            for (File file : files) {
                if ("gdb".equals(file.getName())) {
                    return true;
                }
            }
        }
        return false;
    }
    /**
     * 插入文件
@@ -152,10 +312,10 @@
        if (name.contains(MDB)) {
            return "mdb";
        }
        if (name.contains(SHP)) {
        if (name.contains(SHP_ZIP)) {
            return "shp";
        }
        if (name.contains(GDB)) {
        if (name.contains(GDB_ZIP)) {
            return "gdb";
        }