管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-01-09 4f83150fbdfbbf2e5021be56595a4429a866756e
1
已修改3个文件
已删除2个文件
858 ■■■■ 文件已修改
src/main/java/com/lf/server/controller/data/upload/UploadController.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/all/BaseUploadService.java 262 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/data/DataLoaderService.java 477 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/data/DataUploadService.java 88 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/data/UploadService.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/data/upload/UploadController.java
@@ -11,9 +11,7 @@
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.StringHelper;
import com.lf.server.helper.WebHelper;
import com.lf.server.service.all.BaseUploadService;
import com.lf.server.service.data.DataLoaderService;
import com.lf.server.service.data.DataUploadService;
import com.lf.server.service.data.UploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
@@ -34,20 +32,14 @@
@RequestMapping("/dataUpload")
public class UploadController extends QueryController {
    @Autowired
    protected DataLoaderService dataLoaderService;
    @Autowired
    protected BaseUploadService baseUploadService;
    @Autowired
    protected DataUploadService dataUploadService;
    UploadService uploadService;
    @SysLog()
    @ApiOperation(value = "查询路径")
    @GetMapping(value = "/selectPath")
    public ResponseMsg<String> selectPath() {
        try {
            String pathName = baseUploadService.selectPath();
            String pathName = uploadService.selectPath();
            return success(pathName);
        } catch (Exception ex) {
@@ -64,7 +56,7 @@
    @PostMapping(value = "/uploadFiles")
    public ResponseMsg<Object> uploadFiles(String path, HttpServletRequest req, HttpServletResponse res) {
        try {
            List<MetaFileEntity> list = baseUploadService.uploadData(null, path, req, res);
            List<MetaFileEntity> list = uploadService.uploadData(null, path, req, res);
            if (null == list || list.isEmpty()) {
                return fail("没有找到上传文件", null);
            }
@@ -83,7 +75,7 @@
    @GetMapping(value = "/selectFiles")
    public ResponseMsg<List<MetaFileEntity>> selectFiles(String path) {
        try {
            List<MetaFileEntity> list = baseUploadService.selectFiles(path, StaticData.ALL_EXTENSION);
            List<MetaFileEntity> list = uploadService.selectFiles(path, StaticData.ALL_EXTENSION);
            return success(list);
        } catch (Exception ex) {
@@ -108,7 +100,7 @@
                return fail("没有找到文件", null);
            }
            int rows = baseUploadService.deleteFiles(list);
            int rows = uploadService.deleteFiles(list);
            return success("成功", rows);
        } catch (Exception ex) {
@@ -137,7 +129,7 @@
                return fail("目录ID=" + dirid + "不存在");
            }
            List<TabMapperEntity> list = dataLoaderService.selectMappers(path);
            List<TabMapperEntity> list = uploadService.selectMappers(path);
            return success(list);
        } catch (Exception ex) {
@@ -171,9 +163,9 @@
            // me.setBatch(StringHelper.YMDHMS_FORMAT.format(new Date(me.getCreateTime().getTime())))
            me.setCreateUser(ue.getId());
            int rows = dataUploadService.insertFiles(me, entity.getFileEntities());
            // int rows = uploadService.insertFiles(me, entity.getFileEntities())
            return success("成功", rows);
            return success("成功", 0);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
@@ -205,7 +197,7 @@
            // me.setBatch(StringHelper.YMDHMS_FORMAT.format(new Date(me.getCreateTime().getTime())))
            me.setCreateUser(ue.getId());
            dataLoaderService.insertFiles(me, entity.getFileEntities(), entity.getTabEntities());
            // uploadService.insertFiles(me, entity.getFileEntities(), entity.getTabEntities())
            return success("成功", entity.getTabEntities());
        } catch (Exception ex) {
src/main/java/com/lf/server/service/all/BaseUploadService.java
@@ -1,10 +1,8 @@
package com.lf.server.service.all;
import com.lf.server.entity.data.MetaEntity;
import com.lf.server.entity.ctrl.TabMapperEntity;
import com.lf.server.entity.data.MetaFileEntity;
import com.lf.server.helper.FileHelper;
import com.lf.server.helper.PathHelper;
import com.lf.server.helper.StringHelper;
import com.lf.server.helper.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -15,7 +13,6 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.sql.Timestamp;
import java.util.*;
@@ -26,50 +23,22 @@
 */
@Service
public class BaseUploadService {
    private final static String XLS = ".xls";
    private final static String MDB = ".mdb";
    private final static String GDB = ".gdb";
    private final static String SHP_ZIP = ".shp.zip";
    private final static String GDB_ZIP = ".gdb.zip";
    private final static String ZIP = ".zip";
    @Autowired
    public PathHelper pathHelper;
    public final Log log = LogFactory.getLog(getClass());
    /**
     * æŸ¥è¯¢æ–‡ä»¶
     */
    public List<MetaFileEntity> selectFiles(String subPath, List<String> extList) {
        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;
        }
        List<MetaFileEntity> list = new ArrayList<>();
        for (File f : files) {
            String fileName = FileHelper.getFileName(f.getPath());
            if (null != extList) {
                String extName = FileHelper.getExtension(fileName);
                if (!extList.contains(extName)) {
                    continue;
                }
            }
            double sizes = FileHelper.sizeToMb(f.length());
            String filePath = subPath + File.separator + fileName;
            MetaFileEntity mf = new MetaFileEntity();
            mf.setName(fileName);
            mf.setSizes(sizes);
            mf.setPath(filePath);
            mf.setGuid(FileHelper.getFileMd5(f.getPath()));
            list.add(mf);
        }
        return list;
    }
    /**
     * æŸ¥è¯¢ç›®å½•
@@ -161,6 +130,46 @@
    }
    /**
     * æŸ¥è¯¢æ–‡ä»¶
     */
    public List<MetaFileEntity> selectFiles(String subPath, List<String> extList) {
        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;
        }
        List<MetaFileEntity> list = new ArrayList<>();
        for (File f : files) {
            String fileName = FileHelper.getFileName(f.getPath());
            if (null != extList) {
                String extName = FileHelper.getExtension(fileName);
                if (!extList.contains(extName)) {
                    continue;
                }
            }
            double sizes = FileHelper.sizeToMb(f.length());
            String filePath = subPath + File.separator + fileName;
            MetaFileEntity mf = new MetaFileEntity();
            mf.setName(fileName);
            mf.setSizes(sizes);
            mf.setPath(filePath);
            mf.setGuid(FileHelper.getFileMd5(f.getPath()));
            list.add(mf);
        }
        return list;
    }
    /**
     * åˆ é™¤æ–‡ä»¶
     */
    public Integer deleteFiles(List<MetaFileEntity> list) {
@@ -183,6 +192,169 @@
    }
    /**
     * æŸ¥è¯¢æ˜ å°„
     */
    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) {
        String temp = pathHelper.getConfig().getTempPath();
        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)) {
                // æš‚时不实现
            }
        }
        return list;
    }
    /**
     * èŽ·å–Shp文件
     */
    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));
        }
    }
    /**
     * èŽ·å–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 = 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));
            }
        }
    }
    /**
     * èŽ·å–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;
    }
    /**
     * èŽ·å–å‚æ•°
     * Enumeration<String> headers = req.getHeaderNames();
     * Enumeration<String> attributes = req.getAttributeNames();
src/main/java/com/lf/server/service/data/DataLoaderService.java
ÎļþÒÑɾ³ý
src/main/java/com/lf/server/service/data/DataUploadService.java
ÎļþÒÑɾ³ý
src/main/java/com/lf/server/service/data/UploadService.java
@@ -4,6 +4,7 @@
import com.lf.server.entity.data.DirEntity;
import com.lf.server.entity.data.FmeLogEntity;
import com.lf.server.mapper.data.UploadMapper;
import com.lf.server.service.all.BaseUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -14,7 +15,7 @@
 * @author WWW
 */
@Service
public class UploadService implements UploadMapper {
public class UploadService extends BaseUploadService implements UploadMapper {
    @Autowired
    UploadMapper uploadMapper;