管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-11-19 d5baa6ea163058129f35f9b8657ccdf5e21e7a63
1
已修改5个文件
112 ■■■■ 文件已修改
src/main/java/com/lf/server/controller/data/DataUploadController.java 33 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/helper/PathHelper.java 28 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/all/BaseUploadService.java 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/data/DataLoaderService.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/data/DataUploadService.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/data/DataUploadController.java
@@ -5,7 +5,7 @@
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.data.MetaFileEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.service.data.UploaderService;
import com.lf.server.service.data.DataUploadService;
import com.lf.server.service.sys.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@@ -30,15 +30,32 @@
    TokenService tokenService;
    @Autowired
    UploaderService uploaderService;
    DataUploadService dataUploadService;
    @SysLog()
    @ApiOperation(value = "查询目录")
    public ResponseMsg<String> selectPath(HttpServletRequest req) {
    @GetMapping(value = "/selectPath")
    public ResponseMsg<String> selectPath() {
        try {
            //
            String pathName = dataUploadService.selectPath();
            return success("");
            return success(pathName);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @SysLog()
    @ApiOperation(value = "查询文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query")
    })
    @GetMapping(value = "/selectFiles")
    public ResponseMsg<List<MetaFileEntity>> selectFiles(String path) {
        try {
            List<MetaFileEntity> list = dataUploadService.selectFiles(path);
            return success(list);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
@@ -58,12 +75,12 @@
                return fail("用户未登录", null);
            }
            List<MetaFileEntity> list = uploaderService.uploadData(null, path, req, res);
            List<MetaFileEntity> list = dataUploadService.uploadData(null, path, req, res);
            if (null == list || list.isEmpty()) {
                return fail("没有找到上传文件", null);
            }
            return success(list);
            return success(list.size());
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
@@ -86,7 +103,7 @@
                return fail("没有找到文件", null);
            }
            int rows = uploaderService.deleteFiles(list);
            int rows = dataUploadService.deleteFiles(list);
            return success("成功", rows);
        } catch (Exception ex) {
src/main/java/com/lf/server/helper/PathHelper.java
@@ -65,7 +65,7 @@
            }
            File[] files = file.listFiles();
            if (files.length < SettingData.MAX_FILES) {
            if (null == files || files.length < SettingData.MAX_FILES) {
                return subPath;
            }
@@ -105,20 +105,29 @@
     */
    public String getTempPath() {
        String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date());
        String tempPath = config.getTempPath();
        String path = tempPath + File.separator + tempName;
        String path = config.getTempPath() + File.separator + tempName;
        File file = new File(path);
        if (!file.exists() && !file.isDirectory()) {
            file.mkdirs();
        }
        double ran = Math.random() * 99;
        if (ran > D90) {
            deleteOldPath(tempPath);
        return path;
    }
    /**
     * 获取临时路径名称
     */
    public String getTempPathName() {
        String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date());
        String path = config.getTempPath() + File.separator + tempName;
        File file = new File(path);
        if (!file.exists() && !file.isDirectory()) {
            file.mkdirs();
        }
        return path;
        return tempName;
    }
    /**
@@ -142,6 +151,11 @@
     */
    public void deleteOldPath(String tempPath) {
        try {
            double ran = Math.random() * 99;
            if (ran < D90) {
                return;
            }
            File file = new File(tempPath);
            String str = StringHelper.YMD__FORMAT.format(new Date());
src/main/java/com/lf/server/service/all/BaseUploadService.java
@@ -13,6 +13,7 @@
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,6 +27,46 @@
    PathHelper pathHelper;
    private final Log log = LogFactory.getLog(getClass());
    /**
     * 查询目录
     */
    public String selectPath() {
        return pathHelper.getTempPathName();
    }
    /**
     * 查询文件
     */
    public List<MetaFileEntity> selectFiles(String subPath) throws IOException {
        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<MetaFileEntity>();
        for (File f : files) {
            String fileName = FileHelper.getFileName(f.getPath());
            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;
    }
    /**
     * 上传文件
@@ -83,7 +124,7 @@
    /**
     * 获取文件
     */
    private List<MetaFileEntity> getFiles(String subPath, StandardMultipartHttpServletRequest req) throws Exception {
    public List<MetaFileEntity> getFiles(String subPath, StandardMultipartHttpServletRequest req) throws Exception {
        List<MetaFileEntity> list = new ArrayList<MetaFileEntity>();
        String path = pathHelper.getTempPath(subPath);
src/main/java/com/lf/server/service/data/DataLoaderService.java
@@ -1,5 +1,6 @@
package com.lf.server.service.data;
import com.lf.server.service.all.BaseUploadService;
import org.springframework.stereotype.Service;
/**
@@ -7,5 +8,6 @@
 * @author WWW
 */
@Service
public class DataLoaderService {
public class DataLoaderService extends BaseUploadService {
    //
}
src/main/java/com/lf/server/service/data/DataUploadService.java
@@ -1,5 +1,6 @@
package com.lf.server.service.data;
import com.lf.server.service.all.BaseUploadService;
import org.springframework.stereotype.Service;
/**
@@ -7,5 +8,6 @@
 * @author WWW
 */
@Service
public class DataUploadService {
public class DataUploadService extends BaseUploadService {
    //
}