Compare commits
9 Commits
010eb97a26
...
464f46cbf7
| Author | SHA1 | Date |
|---|---|---|
|
|
464f46cbf7 | |
|
|
92699d253d | |
|
|
9709d6a691 | |
|
|
c91f2cc8a9 | |
|
|
1f18245c8f | |
|
|
286f23ad21 | |
|
|
4bc0c04706 | |
|
|
a53b06385f | |
|
|
516e81ba91 |
|
|
@ -2,14 +2,21 @@ package com.electromagnetic.industry.software.data.manage.controller;
|
||||||
|
|
||||||
import com.electromagnetic.industry.software.data.manage.facade.EDDataFacade;
|
import com.electromagnetic.industry.software.data.manage.facade.EDDataFacade;
|
||||||
import com.electromagnetic.industry.software.data.manage.request.indicator.EDDataRequest;
|
import com.electromagnetic.industry.software.data.manage.request.indicator.EDDataRequest;
|
||||||
|
import com.electromagnetic.industry.software.data.manage.request.indicator.FileChunkDTO;
|
||||||
|
import com.electromagnetic.industry.software.data.manage.request.indicator.FileDownloadDTO;
|
||||||
import electromagnetic.data.framework.share.model.ElectromagneticResult;
|
import electromagnetic.data.framework.share.model.ElectromagneticResult;
|
||||||
import electromagnetic.data.framework.share.model.ElectromagneticResultUtil;
|
import electromagnetic.data.framework.share.model.ElectromagneticResultUtil;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.core.io.InputStreamResource;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RequestMapping("/data/ed/file")
|
@RequestMapping("/data/ed/file")
|
||||||
@RestController
|
@RestController
|
||||||
|
|
@ -55,14 +62,14 @@ public class EDDataController {
|
||||||
request.setParentId(parentId);
|
request.setParentId(parentId);
|
||||||
request.setFileData(file);
|
request.setFileData(file);
|
||||||
request.setGmtBatchUpload(new Date(gmtBatchUpload));
|
request.setGmtBatchUpload(new Date(gmtBatchUpload));
|
||||||
return edDataFacade.upload(request);
|
return edDataFacade.uploadFile(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation(value = "下载",notes = "")
|
@ApiOperation(value = "下载",notes = "")
|
||||||
@RequestMapping(value = "/download",method = RequestMethod.POST)
|
@RequestMapping(value = "/download",method = RequestMethod.GET)
|
||||||
public ElectromagneticResult<?> download(@RequestBody EDDataRequest request){
|
public ResponseEntity<InputStreamResource> download(@RequestBody FileDownloadDTO fileDownloadDTO, HttpServletResponse response) throws IOException {
|
||||||
return edDataFacade.download(request);
|
return edDataFacade.download(fileDownloadDTO, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -72,5 +79,36 @@ public class EDDataController {
|
||||||
return ElectromagneticResultUtil.success("复制");
|
return ElectromagneticResultUtil.success("复制");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "数据导出",notes = "")
|
||||||
|
@RequestMapping(value = "/batchExport",method = RequestMethod.POST)
|
||||||
|
public ElectromagneticResult<?> batchExport(@RequestBody EDDataRequest request){
|
||||||
|
return edDataFacade.batchExport(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "获取已经上传的分片",notes = "")
|
||||||
|
@RequestMapping(value = "/getUploadedChunkNums",method = RequestMethod.GET)
|
||||||
|
public ElectromagneticResult<?> getUploadedChunkNums(@RequestParam String identifier) {
|
||||||
|
return edDataFacade.getUploadedChunkNums(identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "合并分片",notes = "")
|
||||||
|
@RequestMapping(value = "/mergeChunks",method = RequestMethod.GET)
|
||||||
|
public ElectromagneticResult<?> mergeChunks(@RequestParam String identifier,
|
||||||
|
@RequestParam String fileName,
|
||||||
|
@RequestParam Integer totalChunks) {
|
||||||
|
return edDataFacade.mergeChunks(identifier, fileName, totalChunks);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "分片上传",notes = "")
|
||||||
|
@RequestMapping(value = "/batchImport",method = RequestMethod.POST)
|
||||||
|
public ElectromagneticResult<?> batchImport(FileChunkDTO fileChunkDTO) {
|
||||||
|
return edDataFacade.batchImport(fileChunkDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "检查分片是否存在",notes = "")
|
||||||
|
@RequestMapping(value = "/batchImport",method = RequestMethod.GET)
|
||||||
|
public ElectromagneticResult<?> checkChunkExist(FileChunkDTO fileChunkDTO) {
|
||||||
|
return edDataFacade.checkChunkExist(fileChunkDTO);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#required
|
#required
|
||||||
spring.application.name=electromagnetic-data
|
spring.application.name=electromagnetic-data
|
||||||
# security
|
# security
|
||||||
run.mode=NORMAL
|
run.mode=NORMAL
|
||||||
|
|
@ -18,7 +18,8 @@ spring.datasource.typd=com.alibaba.druid.pool.DruidDataSource
|
||||||
spring.datasource.url=jdbc:mysql://139.224.43.89:3306/em_data?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true&rewriteBatchedStatements=true
|
spring.datasource.url=jdbc:mysql://139.224.43.89:3306/em_data?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true&rewriteBatchedStatements=true
|
||||||
spring.datasource.username=comac
|
spring.datasource.username=comac
|
||||||
spring.datasource.password=2024*Comac
|
spring.datasource.password=2024*Comac
|
||||||
|
spring.servlet.multipart.max-file-size=500MB
|
||||||
|
spring.servlet.multipart.max-request-size=10MB
|
||||||
|
|
||||||
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
|
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
|
||||||
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
|
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
|
||||||
|
|
@ -26,4 +27,15 @@ mybatis.mapper-locations=classpath:sqlmapper/*.xml
|
||||||
pagehelper.helperDialect=mysql
|
pagehelper.helperDialect=mysql
|
||||||
pagehelper.reasonable=false
|
pagehelper.reasonable=false
|
||||||
server.port=8888
|
server.port=8888
|
||||||
|
zip.password=~~BYE6cWGBJJjsU9DczYtZIQ==
|
||||||
|
|
||||||
|
#windows文件存储目录
|
||||||
|
data.windows.path=E:/comacFileStorage/
|
||||||
|
#文件缓存路径
|
||||||
|
data.file.cache.dir=/szsd/cache/
|
||||||
|
#文件存储路径
|
||||||
|
data.file.storage.dir=/szsd/fileStorage/
|
||||||
|
#上传文件时文件的缓存文件夹名称
|
||||||
|
data.upload.cache.dir=upload
|
||||||
|
#导出数据时文件的缓存文件夹名称
|
||||||
|
data.export.cache.dir=export
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,14 @@ public class EDDataParams implements Serializable {
|
||||||
* 每页数据
|
* 每页数据
|
||||||
*/
|
*/
|
||||||
private Integer pageSize = 10;
|
private Integer pageSize = 10;
|
||||||
|
/**
|
||||||
|
* 操作用户id
|
||||||
|
*/
|
||||||
|
private String userId;
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String userName;
|
||||||
/**
|
/**
|
||||||
* 上级文件夹数据码,为空是顶级
|
* 上级文件夹数据码,为空是顶级
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -42,12 +42,4 @@ public interface EDDataRepository {
|
||||||
*/
|
*/
|
||||||
Boolean updateFileInfo(EDDataParams parames);
|
Boolean updateFileInfo(EDDataParams parames);
|
||||||
|
|
||||||
/**
|
|
||||||
* 下载
|
|
||||||
* @param parames
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
Boolean download(EDDataParams parames);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -4,6 +4,9 @@ import com.electromagnetic.industry.software.data.manage.domain.boardservice.ind
|
||||||
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.model.EDDataPage;
|
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.model.EDDataPage;
|
||||||
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.parames.EDDataParams;
|
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.parames.EDDataParams;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public interface EDDataService {
|
public interface EDDataService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -42,24 +45,38 @@ public interface EDDataService {
|
||||||
Integer getChildFileCount(EDDataParams parames);
|
Integer getChildFileCount(EDDataParams parames);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载
|
* 获取文件的文件夹路径
|
||||||
|
* @param categoryId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String getFilePathOfFolder(String categoryId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件上传
|
||||||
* @param parames
|
* @param parames
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Boolean download(EDDataParams parames);
|
Boolean uploadFile(EDDataParams parames);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查文件夹是否存在
|
* 文件下载
|
||||||
* @param path
|
* @param parames
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Boolean checkFolderIsExist(String path);
|
List<String> downloadFile(EDDataParams parames);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建多级目录
|
* 导出数据
|
||||||
* @param path
|
* @param parames
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Boolean createMultiLevelDirectory(String path);
|
String exportData(EDDataParams parames);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解压后的数据目录
|
||||||
|
* @param folderPath
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Map<String, List<String>> importData(String folderPath);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,36 +3,102 @@
|
||||||
*/
|
*/
|
||||||
package com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.service.impl;
|
package com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.util.ZipUtil;
|
||||||
|
import cn.hutool.crypto.SecureUtil;
|
||||||
|
import cn.hutool.crypto.symmetric.AES;
|
||||||
|
import cn.hutool.poi.excel.cell.CellSetter;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model.Category;
|
||||||
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.model.EDDataInfo;
|
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.model.EDDataInfo;
|
||||||
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.model.EDDataPage;
|
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.model.EDDataPage;
|
||||||
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.parames.EDDataParams;
|
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.parames.EDDataParams;
|
||||||
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.repository.EDDataRepository;
|
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.repository.EDDataRepository;
|
||||||
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.service.EDDataService;
|
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.service.EDDataService;
|
||||||
|
import com.electromagnetic.industry.software.data.manage.domain.boardservice.user.repository.CategoryRepository;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import electromagnetic.data.framework.share.exception.LoggerConstant;
|
import electromagnetic.data.framework.share.exception.LoggerConstant;
|
||||||
|
import electromagnetic.data.framework.share.id.IdWorker;
|
||||||
|
import electromagnetic.data.framework.share.model.ElectromagneticResultUtil;
|
||||||
|
import electromagnetic.data.framework.share.util.EleZipUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.IOException;
|
import java.io.*;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author
|
* @author
|
||||||
* @version $Id: IndicatorCardServiceImpl.java, v 0.1 2024-07-26 17:20
|
* @version $Id: IndicatorCardServiceImpl.java, v 0.1 2024-07-26 17:20
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
public class EDDataServiceImpl implements EDDataService {
|
public class EDDataServiceImpl implements EDDataService {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(LoggerConstant.DOMAIN_SERVICE);
|
// private static final Logger LOGGER = LoggerFactory.getLogger(LoggerConstant.DOMAIN_SERVICE);
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private EDDataRepository edDataRepository;
|
private EDDataRepository edDataRepository;
|
||||||
|
@Resource
|
||||||
|
private CategoryRepository categoryRepository;
|
||||||
|
|
||||||
|
@Value("${zip.password}")
|
||||||
|
private String passwordZIP;
|
||||||
|
@Value("${data.windows.path}")
|
||||||
|
private String windowsDir;
|
||||||
|
@Value("${data.file.cache.dir}")
|
||||||
|
private String fileCacheDir;
|
||||||
|
@Value("${data.file.storage.dir}")
|
||||||
|
private String fileStorageDir;
|
||||||
|
@Value("${data.upload.cache.dir}")
|
||||||
|
private String uploadCacheDir;
|
||||||
|
@Value("${data.export.cache.dir}")
|
||||||
|
private String exportCacheDir;
|
||||||
|
|
||||||
|
// 文件夹名称分隔符
|
||||||
|
private static final String FOLDER_NAME_SEPARATOR = "_";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取时间戳字符串
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getTimeStampString() {
|
||||||
|
long timestamp = System.currentTimeMillis();
|
||||||
|
return String.valueOf(timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据存储目录
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getDataStoragePath()
|
||||||
|
{
|
||||||
|
String osName = System.getProperty("os.name").toLowerCase();
|
||||||
|
return osName.startsWith("win") ? windowsDir + fileStorageDir : fileStorageDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据缓存目录
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getDataCachePath()
|
||||||
|
{
|
||||||
|
String osName = System.getProperty("os.name").toLowerCase();
|
||||||
|
return osName.startsWith("win") ? windowsDir + fileCacheDir : fileCacheDir;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建文件/文件夹数据信息
|
* 创建文件/文件夹数据信息
|
||||||
|
|
@ -41,7 +107,42 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
*/
|
*/
|
||||||
public Boolean createDataInfo(EDDataInfo edDataInfo)
|
public Boolean createDataInfo(EDDataInfo edDataInfo)
|
||||||
{
|
{
|
||||||
edDataRepository.createDataInfo(edDataInfo);
|
// 获取上级目录的名称
|
||||||
|
Category categoryParent = new Category();
|
||||||
|
categoryParent.setCategoryId(edDataInfo.getCategoryId());
|
||||||
|
List<Category> categoryParentList = categoryRepository.selectCategories(categoryParent);
|
||||||
|
if(categoryParentList.size() < 1)
|
||||||
|
{
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 获取新文件夹路径信息
|
||||||
|
categoryParent = categoryParentList.get(0);
|
||||||
|
|
||||||
|
String dataStoragePath = getDataStoragePath();
|
||||||
|
String folderParent = categoryParent.getCategoryId() + FOLDER_NAME_SEPARATOR + categoryParent.getCategoryName() ;
|
||||||
|
String folderNew = dataStoragePath + File.separator + folderParent + File.separator + edDataInfo.getDataName();
|
||||||
|
|
||||||
|
// 判断文件夹名称是否存在
|
||||||
|
EDDataParams folderParames = new EDDataParams();
|
||||||
|
folderParames.setParentId(edDataInfo.getCategoryId());
|
||||||
|
List<EDDataInfo> childFileInfoList = edDataRepository.getDataInfoList(folderParames);
|
||||||
|
for(EDDataInfo fileInfo : childFileInfoList)
|
||||||
|
{
|
||||||
|
if(fileInfo.getDataName() == edDataInfo.getDataName()){
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将文件夹数据写到数据库中
|
||||||
|
if(edDataRepository.createDataInfo(edDataInfo)) {
|
||||||
|
if (!FileUtil.exist(folderNew)){
|
||||||
|
FileUtil.mkdir(folderNew);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,7 +179,33 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
*/
|
*/
|
||||||
public Boolean updateFileInfo(EDDataParams parames)
|
public Boolean updateFileInfo(EDDataParams parames)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
String dataStoragePath = getDataStoragePath();
|
||||||
|
if (!FileUtil.exist(dataStoragePath)){
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
EDDataParams paramesFind = new EDDataParams();
|
||||||
|
paramesFind.setDataId(parames.getDataId());
|
||||||
|
List<EDDataInfo> edDataInfoList = edDataRepository.getDataInfoList(paramesFind);
|
||||||
|
if(edDataInfoList.size() < 1) {
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
EDDataInfo edDataInfo = edDataInfoList.get(0);
|
||||||
|
JSONObject implantJsonObject = JSON.parseObject(edDataInfo.getImplantJson());
|
||||||
|
String filePathOfFolder = implantJsonObject.getString("folderPath");
|
||||||
|
String fileStorageFullPath = dataStoragePath + filePathOfFolder + File.separator + edDataInfo.getDataName();
|
||||||
|
|
||||||
|
if (!FileUtil.exist(fileStorageFullPath)){
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
String fileNameNew = parames.getName();
|
||||||
|
FileUtil.rename(Paths.get(fileStorageFullPath) ,fileNameNew,true);
|
||||||
|
|
||||||
edDataRepository.updateFileInfo(parames);
|
edDataRepository.updateFileInfo(parames);
|
||||||
|
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,39 +235,510 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载
|
* 获取文件的文件夹路径
|
||||||
|
* @param categoryId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getFilePathOfFolder(String categoryId)
|
||||||
|
{
|
||||||
|
String filePathOfFolder = ""; //文件存放在文件夹的路径
|
||||||
|
|
||||||
|
String categoryIdHighest = categoryId; //最高级的目录编码
|
||||||
|
EDDataParams folderParames = new EDDataParams();
|
||||||
|
folderParames.setDataId(categoryId);
|
||||||
|
EDDataInfo edDataInfoParent = edDataRepository.getDataInfo(folderParames);
|
||||||
|
if(edDataInfoParent != null) {
|
||||||
|
categoryIdHighest = edDataInfoParent.getCategoryId();
|
||||||
|
}
|
||||||
|
|
||||||
|
Category categoryParent = new Category();
|
||||||
|
categoryParent.setCategoryId(categoryIdHighest);
|
||||||
|
List<Category> categoryParentList = categoryRepository.selectCategories(categoryParent);
|
||||||
|
if(categoryParentList.size() > 0){
|
||||||
|
categoryParent = categoryParentList.get(0);
|
||||||
|
filePathOfFolder = categoryParent.getCategoryId() + FOLDER_NAME_SEPARATOR + categoryParent.getCategoryName();
|
||||||
|
if(edDataInfoParent != null){
|
||||||
|
filePathOfFolder = filePathOfFolder + File.separator + edDataInfoParent.getDataName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filePathOfFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件上传
|
||||||
* @param parames
|
* @param parames
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Boolean download(EDDataParams parames)
|
public Boolean uploadFile(EDDataParams parames)
|
||||||
{
|
{
|
||||||
edDataRepository.download(parames);
|
|
||||||
return Boolean.TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// 获取目录编码ID
|
||||||
* 检查文件夹是否存在
|
String categoryId = parames.getParentId();
|
||||||
* @param path
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public Boolean checkFolderIsExist(String path)
|
|
||||||
{
|
|
||||||
return Files.exists(Paths.get(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// 获取要上传的文件
|
||||||
* 创建多级目录
|
MultipartFile fileInput = parames.getFileData();
|
||||||
* @param path
|
|
||||||
* @return
|
// 检查文件是否为空
|
||||||
*/
|
if (fileInput == null || fileInput.isEmpty()) {
|
||||||
public Boolean createMultiLevelDirectory(String path)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
Files.createDirectories(Paths.get(path));
|
|
||||||
return Boolean.TRUE;
|
|
||||||
} catch (IOException e) {
|
|
||||||
return Boolean.FALSE;
|
return Boolean.FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取文件名
|
||||||
|
String fileFullName = fileInput.getOriginalFilename();
|
||||||
|
// 获取文件类型
|
||||||
|
String fileType = "";
|
||||||
|
// 获取文件名称
|
||||||
|
String fileName = "";
|
||||||
|
if (fileFullName.lastIndexOf(".") != -1 && fileFullName.lastIndexOf(".") != 0) {
|
||||||
|
fileType = fileFullName.substring(fileFullName.lastIndexOf(".") + 1);
|
||||||
|
fileName = fileFullName.substring(fileFullName.lastIndexOf("."));
|
||||||
|
}
|
||||||
|
|
||||||
|
String dataStoragePath = getDataStoragePath();
|
||||||
|
if (!FileUtil.exist(dataStoragePath)){
|
||||||
|
FileUtil.mkdir(dataStoragePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取文件存放在文件夹的路径
|
||||||
|
String filePathOfFolder = getFilePathOfFolder(categoryId);
|
||||||
|
|
||||||
|
// 将文件数据信息写到数据库
|
||||||
|
EDDataInfo edDataInfo = new EDDataInfo();
|
||||||
|
{
|
||||||
|
// 临时数据设置
|
||||||
|
if (Boolean.TRUE) {
|
||||||
|
if (parames.getUserId() == null || parames.getUserId().isEmpty()) parames.setUserId(IdWorker.getSnowFlakeIdString());
|
||||||
|
if (parames.getUserName() == null || parames.getUserName().isEmpty()) parames.setUserName("user");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建新文件数据
|
||||||
|
edDataInfo.setCreator(parames.getUserId());
|
||||||
|
edDataInfo.setCreatorName(parames.getUserName());
|
||||||
|
edDataInfo.setModifier(parames.getUserId());
|
||||||
|
edDataInfo.setModifierName(parames.getUserName());
|
||||||
|
edDataInfo.setCategoryId(parames.getParentId());
|
||||||
|
edDataInfo.setDataName(fileFullName);
|
||||||
|
edDataInfo.setNote(parames.getNote());
|
||||||
|
edDataInfo.setFileType(fileType);
|
||||||
|
edDataInfo.setGmtBatchUpload(parames.getGmtBatchUpload());
|
||||||
|
|
||||||
|
edDataInfo.setDataId(IdWorker.getSnowFlakeIdString());
|
||||||
|
edDataInfo.setDataNo(edDataInfo.getDataId());
|
||||||
|
edDataInfo.setDataType("file");
|
||||||
|
edDataInfo.setVersion("1.0.0");
|
||||||
|
edDataInfo.setDataStatus("publish");
|
||||||
|
edDataInfo.setSaveStatus("saving");
|
||||||
|
|
||||||
|
JSONObject newImplantJsonObject = new JSONObject();
|
||||||
|
newImplantJsonObject.put("folderPath", filePathOfFolder);
|
||||||
|
|
||||||
|
edDataInfo.setImplantJson(newImplantJsonObject.toJSONString());
|
||||||
|
|
||||||
|
boolean isSuccess = edDataRepository.createDataInfo(edDataInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存文件数据 到 文件存储目录
|
||||||
|
{
|
||||||
|
|
||||||
|
// 文件保存目录路径
|
||||||
|
String fileSavePath = dataStoragePath + File.separator + filePathOfFolder;
|
||||||
|
String newFileName = edDataInfo.getDataId() + FOLDER_NAME_SEPARATOR + fileFullName;
|
||||||
|
|
||||||
|
String dataCachePath = getDataCachePath();
|
||||||
|
String uploadFileCachePath = dataCachePath + uploadCacheDir + FOLDER_NAME_SEPARATOR + getTimeStampString();
|
||||||
|
if (!FileUtil.exist(uploadFileCachePath)){
|
||||||
|
FileUtil.mkdir(uploadFileCachePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
String fileCacheFullPath = uploadFileCachePath + File.separator + newFileName;
|
||||||
|
String fileSaveFullPath = fileSavePath + File.separator + fileFullName;
|
||||||
|
log.info("文件缓存路径为: " + fileCacheFullPath);
|
||||||
|
|
||||||
|
|
||||||
|
// 这里可以添加将文件保存到本地磁盘或其他存储介质的逻辑
|
||||||
|
File saveFile = new File(fileCacheFullPath);
|
||||||
|
|
||||||
|
// 将文件保存到硬盘
|
||||||
|
try {
|
||||||
|
fileInput.transferTo(saveFile);
|
||||||
|
|
||||||
|
EDDataParams fileParames = new EDDataParams();
|
||||||
|
fileParames.setDataId(edDataInfo.getDataId());
|
||||||
|
if(fileInput.getSize() == saveFile.length())
|
||||||
|
{
|
||||||
|
Path source = Paths.get(fileCacheFullPath);
|
||||||
|
Path target = Paths.get(fileSaveFullPath);
|
||||||
|
Files.move(source, target);
|
||||||
|
fileParames.setSaveStatus("success");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
saveFile.delete();
|
||||||
|
fileParames.setSaveStatus("failure");
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isSuccess = edDataRepository.updateFileInfo(fileParames);
|
||||||
|
|
||||||
|
FileUtil.del(uploadFileCachePath);//删除临时目录
|
||||||
|
|
||||||
|
log.info("文件保存成功: " + fileSaveFullPath);
|
||||||
|
|
||||||
|
return Boolean.TRUE;
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件下载
|
||||||
|
* @param parames
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<String> downloadFile(EDDataParams parames)
|
||||||
|
{
|
||||||
|
|
||||||
|
// 获取文件存储的文件夹路径
|
||||||
|
String dataStoragePath = getDataStoragePath();
|
||||||
|
EDDataParams paramesFileInfo = new EDDataParams();
|
||||||
|
List<String> dataPathArr = new ArrayList();
|
||||||
|
if (!FileUtil.exist(dataStoragePath)) {
|
||||||
|
dataPathArr.add("error : The directory where the file was stored was not found!");
|
||||||
|
return dataPathArr;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(String dataId : parames.getDataIdArr())
|
||||||
|
{
|
||||||
|
paramesFileInfo.setDataId(dataId);
|
||||||
|
EDDataInfo edDataInfo = edDataRepository.getDataInfo(paramesFileInfo);
|
||||||
|
if(edDataInfo != null)
|
||||||
|
{
|
||||||
|
JSONObject implantJsonObject = JSON.parseObject(edDataInfo.getImplantJson());
|
||||||
|
String filePathOfFolder = implantJsonObject.getString("folderPath");
|
||||||
|
String fileStoragePath = dataStoragePath + File.separator + filePathOfFolder;
|
||||||
|
String fileStorageFullPath = fileStoragePath + File.separator + edDataInfo.getDataName();
|
||||||
|
if (FileUtil.exist(fileStoragePath)) {
|
||||||
|
if (!FileUtil.exist(fileStorageFullPath)) {
|
||||||
|
fileStorageFullPath = "error : No file found : " + fileStorageFullPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//获取文件存放在文件夹的路径
|
||||||
|
String filePathOfFolderByDB = getFilePathOfFolder(edDataInfo.getCategoryId());
|
||||||
|
if (!FileUtil.exist(filePathOfFolderByDB)) {
|
||||||
|
fileStorageFullPath = "error : The directory path does not exist : " + edDataInfo.getCategoryId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dataPathArr.add(fileStorageFullPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dataPathArr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出数据
|
||||||
|
* @param parames
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String exportData(EDDataParams parames)
|
||||||
|
{
|
||||||
|
|
||||||
|
// 获取文件夹编码ID数组
|
||||||
|
List<String> categoryIdInputList = Arrays.asList(parames.getDataIdArr());
|
||||||
|
|
||||||
|
String dataCachePath = getDataCachePath();
|
||||||
|
|
||||||
|
// 导出数据时的临时存放目录
|
||||||
|
String exportDataCachePath = dataCachePath + exportCacheDir + FOLDER_NAME_SEPARATOR + getTimeStampString();
|
||||||
|
if (!FileUtil.exist(exportDataCachePath)){
|
||||||
|
FileUtil.mkdir(exportDataCachePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Category> categoryAllList = categoryRepository.getAllCategories();
|
||||||
|
Map<String, Category> categoryAllMap = new HashMap(); //所有目录数组map
|
||||||
|
for (Category category : categoryAllList) {
|
||||||
|
categoryAllMap.put(category.getCategoryId(), category);
|
||||||
|
}
|
||||||
|
|
||||||
|
EDDataParams folderParames = new EDDataParams();
|
||||||
|
List<EDDataInfo> fileAllList = edDataRepository.getDataInfoList(folderParames); //获取所有文件信息数据
|
||||||
|
Map<String, EDDataInfo> fileAllMap = new HashMap(); //所有文件数组map
|
||||||
|
for (EDDataInfo fileFinfo : fileAllList) {
|
||||||
|
fileAllMap.put(fileFinfo.getDataId(), fileFinfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Category> categoryInputList = new ArrayList(); //客户端输入的目录数组
|
||||||
|
Map<String, Category> categoryInputMap = new HashMap(); //客户端输入的目录数组map
|
||||||
|
List<EDDataInfo> fileInputList = new ArrayList(); //客户端输入的目录下的文件夹数组
|
||||||
|
Map<String, EDDataInfo> fileInputMap = new HashMap(); //客户端输入的目录下的文件夹数组map
|
||||||
|
for (String categoryId : categoryIdInputList) {
|
||||||
|
Category category = categoryAllMap.get(categoryId);
|
||||||
|
if(category != null) {
|
||||||
|
categoryInputList.add(category);
|
||||||
|
categoryInputMap.put(categoryId, category);
|
||||||
|
} else {
|
||||||
|
EDDataInfo folder = fileAllMap.get(categoryId);
|
||||||
|
if(folder != null) {
|
||||||
|
fileInputList.add(folder);
|
||||||
|
fileInputMap.put(categoryId, folder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 导出目录树数据为json文件
|
||||||
|
{
|
||||||
|
|
||||||
|
// 创建ObjectMapper对象,用于JSON处理
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
// 将List<Category>转换为JSON字符串
|
||||||
|
try {
|
||||||
|
String jsonString = objectMapper.writeValueAsString(categoryInputList);
|
||||||
|
// 将JSON字符串写入文件
|
||||||
|
File jsonFile = new File(exportDataCachePath + "/categoryList.json");
|
||||||
|
objectMapper.writeValue(jsonFile, jsonString);
|
||||||
|
log.info("目录树数据已成功导出为JSON文件。" + jsonFile.getAbsolutePath());
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 导出文件信息数据和文件数据
|
||||||
|
{
|
||||||
|
// 保存文件信息数据为json文件
|
||||||
|
|
||||||
|
List<EDDataInfo> fileExportList = new ArrayList(); //需要导出的文件信息数据数组
|
||||||
|
for (EDDataInfo fileFinfo : fileAllList) {
|
||||||
|
if(fileFinfo.getDataType().equals("folder")) {
|
||||||
|
if(categoryInputMap.get(fileFinfo.getCategoryId()) != null) {
|
||||||
|
fileExportList.add(fileFinfo);
|
||||||
|
}
|
||||||
|
} else if(fileFinfo.getDataType().equals("file")) {
|
||||||
|
if(fileInputMap.get(fileFinfo.getCategoryId()) != null) {
|
||||||
|
fileExportList.add(fileFinfo);
|
||||||
|
} else if(categoryInputMap.get(fileFinfo.getCategoryId()) != null) {
|
||||||
|
fileExportList.add(fileFinfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 创建ObjectMapper对象,用于JSON处理
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
// 将List<EDDataInfo>转换为JSON字符串
|
||||||
|
try {
|
||||||
|
String jsonString = objectMapper.writeValueAsString(fileExportList);
|
||||||
|
// 将JSON字符串写入文件
|
||||||
|
File jsonFile = new File(exportDataCachePath + "/fileInfoList.json");
|
||||||
|
objectMapper.writeValue(jsonFile, jsonString);
|
||||||
|
log.info("目录树数据已成功导出为JSON文件。" + jsonFile.getAbsolutePath());
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将文件 复制到 数据导出的缓存目录中
|
||||||
|
String dataStoragePath = getDataStoragePath();
|
||||||
|
String needExportfolder = "";
|
||||||
|
for (Category category : categoryInputList)
|
||||||
|
{
|
||||||
|
needExportfolder = dataStoragePath + category.getCategoryId() + FOLDER_NAME_SEPARATOR + category.getCategoryName();
|
||||||
|
if (FileUtil.exist(needExportfolder)){
|
||||||
|
Path source = Paths.get(needExportfolder);
|
||||||
|
Path target = Paths.get(exportDataCachePath);
|
||||||
|
FileUtil.copy(source, target); // StandardCopyOption.REPLACE_EXISTING
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("文件数据已成功复制到目标目录。");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将目录树数据 和 文件夹及文件夹内数据 进行压缩打包
|
||||||
|
{
|
||||||
|
String zipPathFileName = dataCachePath + "/comac_exportData1.comac";
|
||||||
|
String enCodeZipPathFileName = dataCachePath + "/comac_exportData.comac";
|
||||||
|
// EleZipUtil.zipFile(exportDataDirectory, zipPathFileName, passwordZIP);
|
||||||
|
|
||||||
|
ZipUtil.zip(exportDataCachePath, zipPathFileName);
|
||||||
|
String password = "adknfhkj87654knd";
|
||||||
|
AES aes = SecureUtil.aes(password.getBytes()); // aesKey是加密密钥
|
||||||
|
try(
|
||||||
|
InputStream inputStream = new FileInputStream(zipPathFileName);
|
||||||
|
OutputStream outputStream = new FileOutputStream(enCodeZipPathFileName);
|
||||||
|
) {
|
||||||
|
aes.encrypt(inputStream, outputStream, true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("文件加密错误..", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
//FileUtil.del(zipPathFileName);//删除临时目录
|
||||||
|
|
||||||
|
log.info("目录树数据+文件数据已成功复制到目标目录。" + zipPathFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除 导出数据的 缓存目录
|
||||||
|
FileUtil.del(exportDataCachePath);
|
||||||
|
|
||||||
|
return dataCachePath + "/comac_exportData.comac";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将解压后的数据导入到数据库中
|
||||||
|
* @param folderPath 解压后的数据目录
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Map<String, List<String>> importData(String folderPath)
|
||||||
|
{
|
||||||
|
// 获取所有目录树节点数据
|
||||||
|
List<Category> categoryAllList = categoryRepository.getAllCategories();
|
||||||
|
Map<String, Category> categoryAllMap = new HashMap(); //所有目录数组map
|
||||||
|
for (Category category : categoryAllList)
|
||||||
|
{
|
||||||
|
categoryAllMap.put(category.getCategoryId(), category);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取所有文件信息数据
|
||||||
|
EDDataParams parames = new EDDataParams();
|
||||||
|
List<EDDataInfo> fileInfoAllList = edDataRepository.getDataInfoList(parames);
|
||||||
|
Map<String, EDDataInfo> fileInfoAllMap = new HashMap(); //所有文件数组map
|
||||||
|
for (EDDataInfo fileInfo : fileInfoAllList)
|
||||||
|
{
|
||||||
|
fileInfoAllMap.put(fileInfo.getDataId(), fileInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 读取并反序列化目录树的JSON文件数据为List<Category>;然后写入到数据库中。
|
||||||
|
List<Category> categoryImportList = null;
|
||||||
|
{
|
||||||
|
// 读取文件数据
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 创建ObjectMapper对象,用于JSON处理
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
// 指定要读取的JSON文件路径
|
||||||
|
File jsonFile = new File(folderPath + "/categoryList.json");
|
||||||
|
|
||||||
|
// 将JSON数据从文件中读取并反序列化为List<Person>
|
||||||
|
categoryImportList = objectMapper.readValue(jsonFile, objectMapper.getTypeFactory().constructCollectionType(List.class, Category.class));
|
||||||
|
if (categoryImportList == null) {
|
||||||
|
log.error("读取并反序列化JSON文件数据为List<Category>失败!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将目录树数据写入到数据库中
|
||||||
|
for (Category category : categoryImportList) {
|
||||||
|
if (categoryAllMap.get(category.getCategoryId()) == null) {
|
||||||
|
categoryRepository.createCategory(category);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取并反序列化文件信息的JSON文件数据为List<EDDataInfo>;然后写入到数据库中。
|
||||||
|
List<EDDataInfo> fileInfoImportList = null;
|
||||||
|
{
|
||||||
|
// 读取文件数据
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 创建ObjectMapper对象,用于JSON处理
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
// 指定要读取的JSON文件路径
|
||||||
|
File jsonFile = new File(folderPath + "/fileInfoList.json");
|
||||||
|
|
||||||
|
// 将JSON数据从文件中读取并反序列化为List<Person>
|
||||||
|
fileInfoImportList = objectMapper.readValue(jsonFile, objectMapper.getTypeFactory().constructCollectionType(List.class, Category.class));
|
||||||
|
if (fileInfoImportList == null) {
|
||||||
|
log.error("读取并反序列化JSON文件数据为List<EDDataInfo>失败!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将文件信息数据写入到数据库中
|
||||||
|
for (EDDataInfo fileInfo : fileInfoImportList) {
|
||||||
|
if (fileInfoAllMap.get(fileInfo.getDataId()) == null) {
|
||||||
|
edDataRepository.createDataInfo(fileInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将解压后的文件夹和文件 移动到 上传文件的存储目录中
|
||||||
|
List<String> importFileSuccess = new ArrayList();
|
||||||
|
List<String> importFileFail = new ArrayList();
|
||||||
|
{
|
||||||
|
String dataStoragePath = getDataStoragePath();
|
||||||
|
if (!FileUtil.exist(dataStoragePath)){
|
||||||
|
FileUtil.mkdir(dataStoragePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
String importDataCachePath = folderPath; //导入数据时 数据文件解压后的目录
|
||||||
|
String importFileCachePath = ""; //需要导入的文件的缓存路径
|
||||||
|
String importFileCacheFullPath = ""; //需要导入的文件的全路径
|
||||||
|
String fileStorageFolder = ""; //文件存储的文件夹
|
||||||
|
String fileStoragePath = ""; //文件存储的文件夹路径
|
||||||
|
String fileStorageFullPath = ""; //文件存储的文件全路径
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (EDDataInfo fileInfo : fileInfoImportList) {
|
||||||
|
JSONObject newImplantJsonObject = JSONObject.parseObject(fileInfo.getImplantJson());
|
||||||
|
fileStorageFolder = newImplantJsonObject.getString("folderPath");
|
||||||
|
importFileCachePath = importDataCachePath + fileStorageFolder;
|
||||||
|
importFileCacheFullPath = importFileCachePath + File.separator + fileInfo.getDataName();
|
||||||
|
fileStoragePath = dataStoragePath + fileStorageFolder;
|
||||||
|
fileStorageFullPath = fileStoragePath + File.separator + fileInfo.getDataName();
|
||||||
|
|
||||||
|
if (fileInfoAllMap.get(fileInfo.getDataId()) == null
|
||||||
|
&& !fileStorageFolder.isEmpty()
|
||||||
|
&& FileUtil.exist(importFileCachePath)
|
||||||
|
&& FileUtil.exist(importFileCacheFullPath)
|
||||||
|
&& !FileUtil.exist(fileStorageFullPath)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if(!FileUtil.exist(fileStoragePath)){
|
||||||
|
FileUtil.mkdir(fileStoragePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
Path source = Paths.get(importFileCacheFullPath);
|
||||||
|
Path target = Paths.get(fileStorageFullPath);
|
||||||
|
|
||||||
|
Files.move(source, target);
|
||||||
|
|
||||||
|
importFileSuccess.add(fileInfo.getDataId() + FOLDER_NAME_SEPARATOR + fileInfo.getDataName());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
importFileFail.add(fileInfo.getDataId() + FOLDER_NAME_SEPARATOR + fileInfo.getDataName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, List<String>> result = new HashMap<>();
|
||||||
|
result.put("success", importFileSuccess);
|
||||||
|
result.put("fail", importFileFail);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@ package com.electromagnetic.industry.software.data.manage.domain.boardservice.us
|
||||||
|
|
||||||
import com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model.Category;
|
import com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model.Category;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public interface CategoryRepository {
|
public interface CategoryRepository {
|
||||||
|
|
||||||
|
|
@ -30,4 +32,37 @@ public interface CategoryRepository {
|
||||||
*/
|
*/
|
||||||
List<Category> selectChildCategories(Category category);
|
List<Category> selectChildCategories(Category category);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建目录树节点数据
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Boolean createCategory(Category category);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 节点 获取到顶级节点的树路径 从指定的节点数组中
|
||||||
|
* @param category
|
||||||
|
* @param categoryMap
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<Category> getTopCategoriesPathList(Category category, Map<String, Category> categoryMap);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 节点 获取父节点 从指定的节点数组中
|
||||||
|
* @param category
|
||||||
|
* @param categoryList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Category getParentCategories(Category category, List<Category> categoryList);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获通过 节点ID 获取父节点 从指定的节点数组中
|
||||||
|
* @param categoryId
|
||||||
|
* @param categoryList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Category getParentCategories(String categoryId, List<Category> categoryList);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.electromagnetic.industry.software.data.manage.domain.boardservice.us
|
||||||
import com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model.Category;
|
import com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model.Category;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public interface CategoryService {
|
public interface CategoryService {
|
||||||
|
|
||||||
|
|
@ -32,7 +33,23 @@ public interface CategoryService {
|
||||||
List<Category> selectChildCategories(Category category);
|
List<Category> selectChildCategories(Category category);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取 指定节点的 父节点 从所有节点数组中
|
* 通过 节点 获取到顶级节点的树路径 从指定的节点数组中
|
||||||
|
* @param category
|
||||||
|
* @param categoryMap
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<Category> getTopCategoriesPathList(Category category, Map<String, Category> categoryMap);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 节点 获取父节点 从指定的节点数组中
|
||||||
|
* @param category
|
||||||
|
* @param categoryList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Category getParentCategories(Category category, List<Category> categoryList);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 节点ID 获取父节点 从指定的节点数组中
|
||||||
* @param categoryId
|
* @param categoryId
|
||||||
* @param categoryList
|
* @param categoryList
|
||||||
* @return
|
* @return
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,10 @@ import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class CategoryServiceImpl implements CategoryService {
|
public class CategoryServiceImpl implements CategoryService {
|
||||||
|
|
||||||
|
|
@ -102,24 +104,38 @@ public class CategoryServiceImpl implements CategoryService {
|
||||||
public List<Category> selectChildCategories(Category category) { return categoryRepository.selectChildCategories(category); }
|
public List<Category> selectChildCategories(Category category) { return categoryRepository.selectChildCategories(category); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取 指定节点的 父节点 从所有节点数组中
|
* 通过 节点 获取到顶级节点的树路径 从指定的节点数组中
|
||||||
* @param categoryId
|
* @param category
|
||||||
|
* @param categoryMap
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<Category> getTopCategoriesPathList(Category category, Map<String, Category> categoryMap)
|
||||||
|
{
|
||||||
|
Category categoryParent = categoryMap.get(category.getParentId());
|
||||||
|
if(categoryParent != null)
|
||||||
|
{
|
||||||
|
List<Category> topCategoriesPathList = getTopCategoriesPathList(categoryParent, categoryMap);
|
||||||
|
if(topCategoriesPathList == null)
|
||||||
|
{
|
||||||
|
topCategoriesPathList = new ArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
topCategoriesPathList.add(0, categoryParent);
|
||||||
|
return topCategoriesPathList;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 节点 获取父节点 从指定的节点数组中
|
||||||
|
* @param category
|
||||||
* @param categoryList
|
* @param categoryList
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Category getParentCategories(String categoryId, List<Category> categoryList)
|
public Category getParentCategories(Category category, List<Category> categoryList)
|
||||||
{
|
{
|
||||||
Category category = null;
|
|
||||||
Category categoryParent = null;
|
Category categoryParent = null;
|
||||||
for(Category iter : categoryList)
|
for(Category iter : categoryList)
|
||||||
{
|
|
||||||
if(category == null && iter.getCategoryId().equals(categoryId))
|
|
||||||
{
|
|
||||||
category = iter;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(Category iter : categoryList)
|
|
||||||
{
|
{
|
||||||
if(categoryParent == null && iter.getCategoryId().equals(category.getParentId()))
|
if(categoryParent == null && iter.getCategoryId().equals(category.getParentId()))
|
||||||
{
|
{
|
||||||
|
|
@ -127,8 +143,29 @@ public class CategoryServiceImpl implements CategoryService {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return categoryParent;
|
return categoryParent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获通过 节点ID 获取父节点 从指定的节点数组中
|
||||||
|
* @param categoryId
|
||||||
|
* @param categoryList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Category getParentCategories(String categoryId, List<Category> categoryList)
|
||||||
|
{
|
||||||
|
Category category = null;
|
||||||
|
for(Category iter : categoryList)
|
||||||
|
{
|
||||||
|
if(category == null && iter.getCategoryId().equals(categoryId))
|
||||||
|
{
|
||||||
|
category = iter;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getParentCategories(category, categoryList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,11 @@
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-webmvc</artifactId>
|
<artifactId>spring-webmvc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.lingala.zip4j</groupId>
|
||||||
|
<artifactId>zip4j</artifactId>
|
||||||
|
<version>2.11.5</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
@ -0,0 +1,149 @@
|
||||||
|
package electromagnetic.data.framework.share.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import net.lingala.zip4j.ZipFile;
|
||||||
|
import net.lingala.zip4j.exception.ZipException;
|
||||||
|
import net.lingala.zip4j.model.ZipParameters;
|
||||||
|
import net.lingala.zip4j.model.enums.AesKeyStrength;
|
||||||
|
import net.lingala.zip4j.model.enums.CompressionLevel;
|
||||||
|
import net.lingala.zip4j.model.enums.CompressionMethod;
|
||||||
|
import net.lingala.zip4j.model.enums.EncryptionMethod;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @desc zip解压缩工具
|
||||||
|
* @author: wcy
|
||||||
|
* @date: 2024/1/12
|
||||||
|
* @version: 1.0
|
||||||
|
*/
|
||||||
|
public class EleZipUtil {
|
||||||
|
/**
|
||||||
|
* 压缩指定路径的文件
|
||||||
|
* @param srcFilePath 待压缩文件路径
|
||||||
|
* @param zipPathFileName zip文件全路径名
|
||||||
|
* @param password 加密密码
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean zipFile(String srcFilePath, String zipPathFileName, String password){
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 生成的压缩文件
|
||||||
|
ZipFile zipFile = new ZipFile(zipPathFileName);
|
||||||
|
if (StrUtil.isNotEmpty(password)) {
|
||||||
|
zipFile.setPassword(password.toCharArray());
|
||||||
|
}
|
||||||
|
ZipParameters parameters = new ZipParameters();
|
||||||
|
// 压缩级别
|
||||||
|
parameters.setCompressionMethod(CompressionMethod.DEFLATE);
|
||||||
|
parameters.setCompressionLevel(CompressionLevel.NORMAL);
|
||||||
|
|
||||||
|
if(StrUtil.isNotEmpty(password)){
|
||||||
|
parameters.setEncryptFiles(true);
|
||||||
|
parameters.setEncryptionMethod(EncryptionMethod.AES);
|
||||||
|
parameters.setAesKeyStrength(AesKeyStrength.KEY_STRENGTH_256);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 要打包的文件夹
|
||||||
|
File file = new File(srcFilePath);
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
zipFile.addFolder(file, parameters);
|
||||||
|
} else {
|
||||||
|
zipFile.addFile(file, parameters);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (ZipException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param zipFileFullName zip文件所在的路径名
|
||||||
|
* @param filePath 解压到的路径
|
||||||
|
* @param password 需要解压的密码
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean unZipFile(String zipFileFullName, String filePath, String password) {
|
||||||
|
try {
|
||||||
|
ZipFile zipFile = new ZipFile(zipFileFullName);
|
||||||
|
// 如果解压需要密码
|
||||||
|
if(StrUtil.isNotEmpty(password) && zipFile.isEncrypted()) {
|
||||||
|
zipFile.setPassword(password.toCharArray());
|
||||||
|
}
|
||||||
|
zipFile.extractAll(filePath);
|
||||||
|
return true;
|
||||||
|
} catch (ZipException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加文件到压缩文件中
|
||||||
|
* @param zipFullFileName zip文件所在路径及全名
|
||||||
|
* @param fullFileNameList 待添加的文件全路径集合
|
||||||
|
* @param rootFolderInZip 在压缩文件里的文件夹名
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean addFilesToZip(String zipFullFileName, List<String> fullFileNameList, String rootFolderInZip) {
|
||||||
|
try {
|
||||||
|
ZipFile zipFile = new ZipFile(zipFullFileName);
|
||||||
|
ArrayList<File> addFiles = new ArrayList<>();
|
||||||
|
for (String fileName : fullFileNameList) {
|
||||||
|
addFiles.add(new File(fileName));
|
||||||
|
}
|
||||||
|
|
||||||
|
ZipParameters parameters = new ZipParameters();
|
||||||
|
parameters.setCompressionMethod(CompressionMethod.DEFLATE);
|
||||||
|
parameters.setCompressionLevel(CompressionLevel.NORMAL);
|
||||||
|
if(StrUtil.isNotEmpty(rootFolderInZip)){
|
||||||
|
if(!rootFolderInZip.endsWith("/")){
|
||||||
|
rootFolderInZip = rootFolderInZip+"/";
|
||||||
|
}
|
||||||
|
parameters.setRootFolderNameInZip(rootFolderInZip);
|
||||||
|
}
|
||||||
|
zipFile.addFiles(addFiles, parameters);
|
||||||
|
return true;
|
||||||
|
} catch (ZipException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
// log.error("添加文件失败:\n"+e.getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从压缩文件中删除路径
|
||||||
|
* @param zipFullFileName
|
||||||
|
* @param fileName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean deleteFileInZip(String zipFullFileName, String fileName) {
|
||||||
|
try {
|
||||||
|
ZipFile zipFile = new ZipFile(zipFullFileName);
|
||||||
|
zipFile.removeFile(fileName);
|
||||||
|
return true;
|
||||||
|
} catch (ZipException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// public static void main(String[] args) throws ZipException {
|
||||||
|
// String srcFilePath = "G:/comac_desk_app";
|
||||||
|
// String desFilePath = "C:\\Users\\test\\Desktop\\project\\file";
|
||||||
|
// String zipPathFileName = "G:/tmp/comac_desk_app.zip";
|
||||||
|
// String password = "123456";
|
||||||
|
// long begin = System.currentTimeMillis();
|
||||||
|
// boolean zipResult = zipFile(srcFilePath, zipPathFileName, password);
|
||||||
|
// long end = System.currentTimeMillis();
|
||||||
|
// System.out.println("压缩结果:" + zipResult + ",耗时:" + (end - begin) + "ms");
|
||||||
|
//
|
||||||
|
// boolean unZipResult = unZipFile(zipPathFileName, desFilePath, password);
|
||||||
|
// long end2 = System.currentTimeMillis();
|
||||||
|
// System.out.println("解压结果:" + unZipResult + ",耗时:" + (end2 - end) + "ms");
|
||||||
|
// System.out.println(unZipResult);
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,16 @@
|
||||||
package com.electromagnetic.industry.software.data.manage.facade;
|
package com.electromagnetic.industry.software.data.manage.facade;
|
||||||
|
|
||||||
import com.electromagnetic.industry.software.data.manage.request.indicator.EDDataRequest;
|
import com.electromagnetic.industry.software.data.manage.request.indicator.EDDataRequest;
|
||||||
|
import com.electromagnetic.industry.software.data.manage.request.indicator.FileChunkDTO;
|
||||||
|
import com.electromagnetic.industry.software.data.manage.request.indicator.FileChunkResultDTO;
|
||||||
|
import com.electromagnetic.industry.software.data.manage.request.indicator.FileDownloadDTO;
|
||||||
import com.electromagnetic.industry.software.data.manage.response.indicator.EDDataPageResponse;
|
import com.electromagnetic.industry.software.data.manage.response.indicator.EDDataPageResponse;
|
||||||
import electromagnetic.data.framework.share.model.ElectromagneticResult;
|
import electromagnetic.data.framework.share.model.ElectromagneticResult;
|
||||||
|
import org.springframework.core.io.InputStreamResource;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -43,27 +50,53 @@ public interface EDDataFacade {
|
||||||
* @param request
|
* @param request
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ElectromagneticResult<Boolean> upload(EDDataRequest request);
|
ElectromagneticResult<Boolean> uploadFile(EDDataRequest request);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载
|
* 下载
|
||||||
* @param request
|
*
|
||||||
|
* @param fileDownloadDTO
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ElectromagneticResult<Map<String, List<String>>> download(EDDataRequest request);
|
ResponseEntity<InputStreamResource> download(FileDownloadDTO fileDownloadDTO, HttpServletResponse response) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出
|
* 导出
|
||||||
* @param request
|
* @param request
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ElectromagneticResult<String> batchExport(EDDataRequest request);
|
ElectromagneticResult<Map<String, String>> batchExport(EDDataRequest request);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导入
|
* 导入
|
||||||
* @param request
|
* @param fileChunkDTO
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ElectromagneticResult<String> batchImport(EDDataRequest request);
|
ElectromagneticResult<?> batchImport(FileChunkDTO fileChunkDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取已经上传的分片
|
||||||
|
* @param identifier
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ElectromagneticResult<List<Integer>> getUploadedChunkNums(String identifier);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 合并分片
|
||||||
|
* @param identifier
|
||||||
|
* @param fileName
|
||||||
|
* @param totalChunks
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ElectromagneticResult<?> mergeChunks(String identifier, String fileName, Integer totalChunks);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查分片是否存在
|
||||||
|
* @param fileChunkDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ElectromagneticResult<FileChunkResultDTO> checkChunkExist(FileChunkDTO fileChunkDTO);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.electromagnetic.industry.software.data.manage.request.indicator;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class FileChunkDTO {
|
||||||
|
|
||||||
|
private String identifier;
|
||||||
|
private long totalSize;
|
||||||
|
private MultipartFile file;
|
||||||
|
private String fileName;
|
||||||
|
private Integer chunkNumber;
|
||||||
|
private Long chunkSize;
|
||||||
|
private Long currentChunkSize;
|
||||||
|
private Integer totalChunks;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.electromagnetic.industry.software.data.manage.request.indicator;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class FileChunkResultDTO {
|
||||||
|
private Boolean skipUpload;
|
||||||
|
private Set<Integer> uploaded;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package com.electromagnetic.industry.software.data.manage.request.indicator;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class FileDownloadDTO {
|
||||||
|
private String dataId;
|
||||||
|
}
|
||||||
|
|
@ -31,4 +31,11 @@ public interface CategoryMapper {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<Category> selectChildCategories(Category category);
|
List<Category> selectChildCategories(Category category);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建目录树节点数据
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Boolean createCategory(Category category);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,9 @@ import com.electromagnetic.industry.software.data.manage.repository.dao.Category
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public class CategoryRepositoryImpl implements CategoryRepository {
|
public class CategoryRepositoryImpl implements CategoryRepository {
|
||||||
|
|
@ -44,4 +46,76 @@ public class CategoryRepositoryImpl implements CategoryRepository {
|
||||||
@Override
|
@Override
|
||||||
public List<Category> selectChildCategories(Category category) { return categoryMapper.selectChildCategories(category); }
|
public List<Category> selectChildCategories(Category category) { return categoryMapper.selectChildCategories(category); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建目录树节点数据
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean createCategory(Category category) { return categoryMapper.createCategory(category); }
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 节点 获取到顶级节点的树路径 从指定的节点数组中
|
||||||
|
* @param category
|
||||||
|
* @param categoryMap
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<Category> getTopCategoriesPathList(Category category, Map<String, Category> categoryMap)
|
||||||
|
{
|
||||||
|
Category categoryParent = categoryMap.get(category.getParentId());
|
||||||
|
if(categoryParent != null)
|
||||||
|
{
|
||||||
|
List<Category> topCategoriesPathList = getTopCategoriesPathList(categoryParent, categoryMap);
|
||||||
|
if(topCategoriesPathList == null)
|
||||||
|
{
|
||||||
|
topCategoriesPathList = new ArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
topCategoriesPathList.add(0, categoryParent);
|
||||||
|
return topCategoriesPathList;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 节点 获取父节点 从指定的节点数组中
|
||||||
|
* @param category
|
||||||
|
* @param categoryList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Category getParentCategories(Category category, List<Category> categoryList)
|
||||||
|
{
|
||||||
|
Category categoryParent = null;
|
||||||
|
for(Category iter : categoryList)
|
||||||
|
{
|
||||||
|
if(categoryParent == null && iter.getCategoryId().equals(category.getParentId()))
|
||||||
|
{
|
||||||
|
categoryParent = iter;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return categoryParent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获通过 节点ID 获取父节点 从指定的节点数组中
|
||||||
|
* @param categoryId
|
||||||
|
* @param categoryList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Category getParentCategories(String categoryId, List<Category> categoryList)
|
||||||
|
{
|
||||||
|
Category category = null;
|
||||||
|
for(Category iter : categoryList)
|
||||||
|
{
|
||||||
|
if(category == null && iter.getCategoryId().equals(categoryId))
|
||||||
|
{
|
||||||
|
category = iter;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getParentCategories(category, categoryList);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,18 +71,5 @@ public class EDDataRepositoryImpl implements EDDataRepository {
|
||||||
return edDataMapper.updateFileInfo(parames);
|
return edDataMapper.updateFileInfo(parames);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 下载
|
|
||||||
* @param parames
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Boolean download(EDDataParams parames)
|
|
||||||
{
|
|
||||||
//return edDataMapper.download(parames);
|
|
||||||
return Boolean.TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -36,13 +36,32 @@
|
||||||
<select id="selectCategories" resultMap="CategoryResultMap"
|
<select id="selectCategories" resultMap="CategoryResultMap"
|
||||||
parameterType="com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model.Category">
|
parameterType="com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model.Category">
|
||||||
<include refid="selectUserVo" />
|
<include refid="selectUserVo" />
|
||||||
where category_id = categoryId and category_status="available"
|
where category_id = #{categoryId,jdbcType=VARCHAR} and category_status="available"
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectChildCategories" resultMap="CategoryResultMap"
|
<select id="selectChildCategories" resultMap="CategoryResultMap"
|
||||||
parameterType="com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model.Category">
|
parameterType="com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model.Category">
|
||||||
<include refid="selectUserVo" />
|
<include refid="selectUserVo" />
|
||||||
where parent_id = parentId and category_status="available"
|
where parent_id = #{parentId,jdbcType=VARCHAR} and category_status="available"
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<insert id="createCategory" parameterType="com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model.Category">
|
||||||
|
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
|
||||||
|
SELECT LAST_INSERT_ID()
|
||||||
|
</selectKey>
|
||||||
|
insert into ed_data_info (id,
|
||||||
|
category_type_id, parent_id, category_id,
|
||||||
|
category_name, category_status,
|
||||||
|
creator, creator_name, gmt_create,
|
||||||
|
modifier, modifier_name, gmt_modified,
|
||||||
|
effect_flag
|
||||||
|
)
|
||||||
|
values (#{id,jdbcType=VARCHAR}, #{categoryTypeId,jdbcType=VARCHAR},
|
||||||
|
#{parentId,jdbcType=VARCHAR}, #{categoryId,jdbcType=VARCHAR},
|
||||||
|
#{categoryName,jdbcType=VARCHAR}, #{categoryStatus,jdbcType=VARCHAR},
|
||||||
|
#{creator,jdbcType=VARCHAR}, #{creatorName,jdbcType=VARCHAR}, now(), #{modifier,jdbcType=VARCHAR},
|
||||||
|
#{modifierName,jdbcType=VARCHAR},now(),1
|
||||||
|
)
|
||||||
|
</insert>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
1
pom.xml
1
pom.xml
|
|
@ -255,6 +255,7 @@
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
<finalName>electromagnetic</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,21 @@
|
||||||
package com.electromagnetic.industry.software.data.manage.service.aop;
|
package com.electromagnetic.industry.software.data.manage.service.aop;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import electromagnetic.data.framework.share.exception.LoggerConstant;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import electromagnetic.data.framework.share.log.LogUtils;
|
import org.apache.catalina.connector.ResponseFacade;
|
||||||
import electromagnetic.data.framework.share.log.ServiceResultHandleUtil;
|
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.Signature;
|
|
||||||
import org.aspectj.lang.annotation.Around;
|
import org.aspectj.lang.annotation.Around;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.slf4j.Logger;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.StopWatch;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
|
import javax.servlet.ServletResponse;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
/**
|
/**
|
||||||
* service 通用日志切面
|
* service 通用日志切面
|
||||||
*
|
*
|
||||||
|
|
@ -21,33 +24,56 @@ import org.springframework.stereotype.Component;
|
||||||
*/
|
*/
|
||||||
@Aspect
|
@Aspect
|
||||||
@Component
|
@Component
|
||||||
|
@Slf4j
|
||||||
public class ServiceAspect {
|
public class ServiceAspect {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(LoggerConstant.DOMAIN_SERVICE);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日志切面
|
* 日志切面
|
||||||
*/
|
*/
|
||||||
@Around("execution(* com.electromagnetic.industry.software.data.manage.facade..*.*(..)))")
|
@Around("execution(* com.electromagnetic.industry.software.data.manage.facade..*.*(..)))")
|
||||||
public Object logAspect(ProceedingJoinPoint pjd) {
|
public Object process(ProceedingJoinPoint jp) throws Throwable {
|
||||||
long startTime = System.currentTimeMillis();
|
String methodInfo = jp.getTarget().getClass().getSimpleName() + "."
|
||||||
Object[] args = pjd.getArgs();
|
+ jp.getSignature().getName();
|
||||||
Object arg = args.length < 1 ? "" : args[0];
|
Object[] args = jp.getArgs();
|
||||||
Signature signature = pjd.getSignature();
|
String paramInfo = "";
|
||||||
String declaringTypeName = signature.getDeclaringTypeName();
|
if (args != null && args.length > 0) {
|
||||||
String logPattern = declaringTypeName.substring(declaringTypeName.lastIndexOf(".") + 1) + "@" + signature.getName() + " request={0}, response={1}, cost={2}ms";
|
if (args[0] != null && args[0].getClass() != ResponseFacade.class) {
|
||||||
Object proceed = null;
|
try {
|
||||||
try {
|
List<Object> list = new ArrayList<>();
|
||||||
proceed = pjd.proceed(args);
|
for (Object obj : jp.getArgs()) {
|
||||||
} catch (Throwable t) {
|
|
||||||
LogUtils.error(t,LOGGER, "Executing " + logPattern+",Throwable:"+t,
|
|
||||||
arg == null ? "" : JSON.toJSONString(arg), JSON.toJSONString(proceed), System.currentTimeMillis() - startTime);
|
|
||||||
return ServiceResultHandleUtil.serviceError(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 正常返回日志
|
if (obj instanceof ServletResponse) {
|
||||||
LogUtils.info(LOGGER, "End " + logPattern,
|
log.info("参数中有response");
|
||||||
arg == null ? "" : JSON.toJSONString(arg), JSON.toJSONString(proceed), System.currentTimeMillis() - startTime);
|
} else if (obj instanceof ServletRequest) {
|
||||||
return proceed;
|
log.info("参数中有request");
|
||||||
|
} else if (obj instanceof MultipartFile) {
|
||||||
|
//文件不输出
|
||||||
|
MultipartFile obj1 = (MultipartFile) obj;
|
||||||
|
log.info("参数中文件;文件名:{},文件大小:{}", obj1.getName(), obj1.getSize());
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
list.add(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
paramInfo = JSON.toJSONString(list);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("切面异常", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.info("请求接口开始:{},参数:{}", methodInfo, paramInfo);
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
StopWatch stopwatch = new StopWatch();
|
||||||
|
stopwatch.start("接口:" + methodInfo);
|
||||||
|
Object rvt = jp.proceed();
|
||||||
|
if (rvt instanceof ResponseEntity) {
|
||||||
|
return rvt;
|
||||||
|
}
|
||||||
|
String returnInfo = JSON.toJSONString(rvt);
|
||||||
|
log.info("请求接口结束:{},返回参数:{},接口耗时:{}", methodInfo, returnInfo, (System.currentTimeMillis() - startTime) + "毫秒");
|
||||||
|
stopwatch.stop();
|
||||||
|
log.debug(stopwatch.prettyPrint());
|
||||||
|
return rvt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,40 +1,62 @@
|
||||||
package com.electromagnetic.industry.software.data.manage.service.facade;
|
package com.electromagnetic.industry.software.data.manage.service.facade;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.io.IoUtil;
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import cn.hutool.core.util.ZipUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model.Category;
|
|
||||||
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.model.EDDataInfo;
|
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.model.EDDataInfo;
|
||||||
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.model.EDDataPage;
|
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.model.EDDataPage;
|
||||||
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.parames.EDDataParams;
|
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.parames.EDDataParams;
|
||||||
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.service.EDDataService;
|
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.service.EDDataService;
|
||||||
import com.electromagnetic.industry.software.data.manage.domain.boardservice.user.service.CategoryService;
|
|
||||||
import com.electromagnetic.industry.software.data.manage.facade.EDDataFacade;
|
import com.electromagnetic.industry.software.data.manage.facade.EDDataFacade;
|
||||||
import com.electromagnetic.industry.software.data.manage.request.indicator.EDDataRequest;
|
import com.electromagnetic.industry.software.data.manage.request.indicator.EDDataRequest;
|
||||||
|
import com.electromagnetic.industry.software.data.manage.request.indicator.FileChunkDTO;
|
||||||
|
import com.electromagnetic.industry.software.data.manage.request.indicator.FileChunkResultDTO;
|
||||||
|
import com.electromagnetic.industry.software.data.manage.request.indicator.FileDownloadDTO;
|
||||||
import com.electromagnetic.industry.software.data.manage.response.indicator.EDDataPageResponse;
|
import com.electromagnetic.industry.software.data.manage.response.indicator.EDDataPageResponse;
|
||||||
import com.electromagnetic.industry.software.data.manage.service.mappers.EDDataMappers;
|
import com.electromagnetic.industry.software.data.manage.service.mappers.EDDataMappers;
|
||||||
import electromagnetic.data.framework.share.id.IdWorker;
|
import electromagnetic.data.framework.share.id.IdWorker;
|
||||||
import electromagnetic.data.framework.share.model.ElectromagneticResult;
|
import electromagnetic.data.framework.share.model.ElectromagneticResult;
|
||||||
import electromagnetic.data.framework.share.model.ElectromagneticResultUtil;
|
import electromagnetic.data.framework.share.model.ElectromagneticResultUtil;
|
||||||
import org.springframework.http.HttpStatus;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
|
||||||
|
import org.springframework.core.io.FileSystemResource;
|
||||||
|
import org.springframework.core.io.InputStreamResource;
|
||||||
|
import org.springframework.http.*;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.File;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.nio.file.Files;
|
import java.io.*;
|
||||||
import java.nio.file.Path;
|
import java.io.IOException;
|
||||||
import java.nio.file.Paths;
|
import java.util.*;
|
||||||
import java.util.ArrayList;
|
import java.util.stream.Collectors;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
public class EDDataFacadeImpl implements EDDataFacade {
|
public class EDDataFacadeImpl implements EDDataFacade {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private EDDataService edDataService;
|
private EDDataService edDataService;
|
||||||
private CategoryService categoryService;
|
|
||||||
|
@Value("${data.windows.path}")
|
||||||
|
private String uploadFilePath;
|
||||||
|
@Value("${data.windows.path}")
|
||||||
|
private String windowsDir;
|
||||||
|
@Value("${data.file.cache.dir}")
|
||||||
|
private String fileCacheDir;
|
||||||
|
@Value("${data.file.storage.dir}")
|
||||||
|
private String fileStorageDir;
|
||||||
|
@Value("${data.upload.cache.dir}")
|
||||||
|
private String uploadCacheDir;
|
||||||
|
@Value("${data.export.cache.dir}")
|
||||||
|
private String exportCacheDir;
|
||||||
|
|
||||||
|
private static final String UPLOAD_FILE_CHUNK_SUFFIX = ".part";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建文件夹
|
* 创建文件夹
|
||||||
|
|
@ -52,8 +74,6 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
||||||
if(Boolean.TRUE) {
|
if(Boolean.TRUE) {
|
||||||
if (request.getUserId() == null || request.getUserId().isEmpty()) request.setUserId(IdWorker.getSnowFlakeIdString());
|
if (request.getUserId() == null || request.getUserId().isEmpty()) request.setUserId(IdWorker.getSnowFlakeIdString());
|
||||||
if (request.getUserName() == null || request.getUserName().isEmpty()) request.setUserName("user");
|
if (request.getUserName() == null || request.getUserName().isEmpty()) request.setUserName("user");
|
||||||
if (request.getName() == null || request.getName().isEmpty()) request.setName("testFolder");
|
|
||||||
//if (request.getParentId() == null || request.getParentId().isEmpty()) request.setParentId(IdWorker.getSnowFlakeIdString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
edDataInfo.setCreator(request.getUserId());
|
edDataInfo.setCreator(request.getUserId());
|
||||||
|
|
@ -70,51 +90,8 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
||||||
edDataInfo.setVersion("1.0.0");
|
edDataInfo.setVersion("1.0.0");
|
||||||
edDataInfo.setDataStatus("publish");
|
edDataInfo.setDataStatus("publish");
|
||||||
|
|
||||||
String parentFolderPath = "";
|
Boolean isSuccess = edDataService.createDataInfo(edDataInfo);
|
||||||
// 获取上级目录的名称
|
return ElectromagneticResultUtil.success(isSuccess);
|
||||||
if(!request.getParentId().isEmpty()) {
|
|
||||||
EDDataParams parames = new EDDataParams();
|
|
||||||
parames.setDataId(request.getParentId());
|
|
||||||
EDDataInfo edDataInfoParent = edDataService.getDataInfo(parames);
|
|
||||||
if(edDataInfoParent == null) {
|
|
||||||
ElectromagneticResultUtil.fail(HttpStatus.BAD_REQUEST.toString(),"上级文件夹为空!");
|
|
||||||
}
|
|
||||||
|
|
||||||
String folderNameParent = edDataInfoParent.getDataName();
|
|
||||||
String folderIdParent = edDataInfoParent.getDataId();
|
|
||||||
|
|
||||||
// 记录当前目录的文件夹路径和文件夹id路径
|
|
||||||
JSONObject implantJsonObject = JSON.parseObject(edDataInfoParent.getImplantJson());
|
|
||||||
if(implantJsonObject == null) {
|
|
||||||
implantJsonObject = new JSONObject();
|
|
||||||
parentFolderPath = folderNameParent;
|
|
||||||
implantJsonObject.put("folderPath", parentFolderPath);
|
|
||||||
implantJsonObject.put("folderIdPath", folderIdParent);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
String folderPath = implantJsonObject.getString("folderPath");
|
|
||||||
String folderIdPath = implantJsonObject.getString("folderIdPath");
|
|
||||||
parentFolderPath = folderPath + "/" + folderNameParent;
|
|
||||||
implantJsonObject.put("folderPath", parentFolderPath);
|
|
||||||
implantJsonObject.put("folderIdPath", folderIdPath + "/" + folderIdParent);
|
|
||||||
}
|
|
||||||
|
|
||||||
String newImplantJson = implantJsonObject.toJSONString();
|
|
||||||
edDataInfo.setImplantJson(newImplantJson);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isSuccess = edDataService.createDataInfo(edDataInfo);
|
|
||||||
if(isSuccess)
|
|
||||||
{
|
|
||||||
// 获取文件存储的文件夹路径
|
|
||||||
String storageDirectory = "D:/fileTemp/" + parentFolderPath + "/" + edDataInfo.getDataName();
|
|
||||||
if(!edDataService.checkFolderIsExist(storageDirectory)) {
|
|
||||||
edDataService.createMultiLevelDirectory(storageDirectory);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ElectromagneticResultUtil.success(Boolean.TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -174,184 +151,52 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
||||||
* @param request
|
* @param request
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public ElectromagneticResult<Boolean> upload(EDDataRequest request)
|
public ElectromagneticResult<Boolean> uploadFile(EDDataRequest request)
|
||||||
{
|
{
|
||||||
EDDataParams parames= EDDataMappers.INSTANCE.getEDDataParames(request);
|
EDDataParams parames= EDDataMappers.INSTANCE.getEDDataParames(request);
|
||||||
|
Boolean isSuccess = edDataService.uploadFile(parames);
|
||||||
try {
|
return ElectromagneticResultUtil.success(isSuccess);
|
||||||
// 获取目录编码ID
|
|
||||||
String categoryId = request.getParentId();
|
|
||||||
|
|
||||||
// 获取要上传的文件
|
|
||||||
MultipartFile fileInput = request.getFileData();
|
|
||||||
|
|
||||||
// 检查文件是否为空
|
|
||||||
if (fileInput == null || fileInput.isEmpty()) {
|
|
||||||
return ElectromagneticResultUtil.fail(HttpStatus.BAD_REQUEST.toString(),"上传的文件为空");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取文件名
|
|
||||||
String fileFullName = fileInput.getOriginalFilename();
|
|
||||||
// 获取文件类型
|
|
||||||
String fileType = "";
|
|
||||||
// 获取文件名称
|
|
||||||
String fileName = "";
|
|
||||||
if (fileFullName.lastIndexOf(".") != -1 && fileFullName.lastIndexOf(".") != 0) {
|
|
||||||
fileType = fileFullName.substring(fileFullName.lastIndexOf(".") + 1);
|
|
||||||
fileName = fileFullName.substring(fileFullName.lastIndexOf("."));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取文件存储的文件夹路径
|
|
||||||
String storageDirectory = "D:/fileTemp";
|
|
||||||
if(!edDataService.checkFolderIsExist(storageDirectory)) {
|
|
||||||
edDataService.createMultiLevelDirectory(storageDirectory);
|
|
||||||
}
|
|
||||||
|
|
||||||
String parentFolderPath = ""; //上级文件夹路径
|
|
||||||
String parentFolderIdPath = ""; //上级文件夹ID路径
|
|
||||||
String parentFolderName = ""; //上级文件夹名称
|
|
||||||
|
|
||||||
// 获取上级文件夹路径
|
|
||||||
{
|
|
||||||
EDDataParams folderParames = new EDDataParams();
|
|
||||||
folderParames.setDataId(categoryId);
|
|
||||||
EDDataInfo edDataInfoParent = edDataService.getDataInfo(folderParames);
|
|
||||||
if(edDataInfoParent == null) {
|
|
||||||
ElectromagneticResultUtil.fail(HttpStatus.BAD_REQUEST.toString(),"上级文件夹为空!");
|
|
||||||
}
|
|
||||||
JSONObject implantJsonObject = JSON.parseObject(edDataInfoParent.getImplantJson());
|
|
||||||
parentFolderPath = implantJsonObject.getString("folderPath");
|
|
||||||
parentFolderIdPath = implantJsonObject.getString("folderIdPath");
|
|
||||||
if(!parentFolderPath.isEmpty())
|
|
||||||
parentFolderPath += "/" ;
|
|
||||||
if(!parentFolderIdPath.isEmpty())
|
|
||||||
parentFolderIdPath += "/" ;
|
|
||||||
parentFolderPath += edDataInfoParent.getDataName();
|
|
||||||
parentFolderIdPath += edDataInfoParent.getDataId();
|
|
||||||
parentFolderName = edDataInfoParent.getDataName();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 文件保存目录路径
|
|
||||||
String fileSavePath = storageDirectory + "/" + parentFolderPath;
|
|
||||||
String treeName = "目录树名称";
|
|
||||||
//String newFileName = treeName + "," + parentFolderName + "," + fileFullName;
|
|
||||||
String newFileName = fileFullName;
|
|
||||||
|
|
||||||
// 文件数据信息写到数据库
|
|
||||||
{
|
|
||||||
// 临时数据设置
|
|
||||||
if(Boolean.TRUE) {
|
|
||||||
if (request.getUserId() == null || request.getUserId().isEmpty()) request.setUserId(IdWorker.getSnowFlakeIdString());
|
|
||||||
if (request.getUserName() == null || request.getUserName().isEmpty()) request.setUserName("user");
|
|
||||||
//if (request.getName() == null || request.getName().isEmpty()) request.setName("testFolder");
|
|
||||||
if (request.getParentId() == null || request.getParentId().isEmpty()) request.setParentId(IdWorker.getSnowFlakeIdString());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建新文件数据
|
|
||||||
EDDataInfo edDataInfo = new EDDataInfo();
|
|
||||||
edDataInfo.setCreator(request.getUserId());
|
|
||||||
edDataInfo.setCreatorName(request.getUserName());
|
|
||||||
edDataInfo.setModifier(request.getUserId());
|
|
||||||
edDataInfo.setModifierName(request.getUserName());
|
|
||||||
edDataInfo.setCategoryId(request.getParentId());
|
|
||||||
edDataInfo.setDataName(newFileName);
|
|
||||||
edDataInfo.setNote(request.getNote());
|
|
||||||
edDataInfo.setFileType(fileType);
|
|
||||||
edDataInfo.setGmtBatchUpload(request.getGmtBatchUpload());
|
|
||||||
|
|
||||||
edDataInfo.setDataId(IdWorker.getSnowFlakeIdString());
|
|
||||||
edDataInfo.setDataNo(edDataInfo.getDataId());
|
|
||||||
edDataInfo.setDataType("file");
|
|
||||||
edDataInfo.setVersion("1.0.0");
|
|
||||||
edDataInfo.setDataStatus("publish");
|
|
||||||
edDataInfo.setSaveStatus("saving");
|
|
||||||
|
|
||||||
JSONObject newImplantJsonObject = new JSONObject();
|
|
||||||
newImplantJsonObject.put("folderPath", parentFolderPath);
|
|
||||||
newImplantJsonObject.put("folderIdPath", parentFolderIdPath);
|
|
||||||
edDataInfo.setImplantJson(newImplantJsonObject.toJSONString());
|
|
||||||
|
|
||||||
boolean isSuccess = edDataService.createDataInfo(edDataInfo);
|
|
||||||
|
|
||||||
String userHome = System.getProperty("user.home");
|
|
||||||
File cacheDirectory = new File(userHome + "\\AppData\\Local\\Temp\\EDData\\Upload");
|
|
||||||
if (!cacheDirectory.exists()) {
|
|
||||||
cacheDirectory.mkdirs();
|
|
||||||
}
|
|
||||||
|
|
||||||
String cacheFolder = cacheDirectory.getAbsolutePath();
|
|
||||||
|
|
||||||
String cachePath = cacheFolder + "/" + newFileName;
|
|
||||||
System.out.println("文件缓存路径为: " + cacheDirectory.getAbsolutePath());
|
|
||||||
fileSavePath += "/" + newFileName;
|
|
||||||
|
|
||||||
|
|
||||||
// 这里可以添加将文件保存到本地磁盘或其他存储介质的逻辑
|
|
||||||
File saveFile = new File(cachePath);//fileSavePath
|
|
||||||
|
|
||||||
// 将文件保存到硬盘
|
|
||||||
fileInput.transferTo(saveFile);
|
|
||||||
|
|
||||||
EDDataParams fileParames = new EDDataParams();
|
|
||||||
fileParames.setDataId(edDataInfo.getDataId());
|
|
||||||
if(fileInput.getSize() == saveFile.length())
|
|
||||||
{
|
|
||||||
Path source = Paths.get(cachePath);
|
|
||||||
Path target = Paths.get(fileSavePath);
|
|
||||||
Files.move(source, target);
|
|
||||||
fileParames.setSaveStatus("success");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
saveFile.delete();
|
|
||||||
fileParames.setSaveStatus("failure");
|
|
||||||
}
|
|
||||||
|
|
||||||
isSuccess = edDataService.updateFileInfo(fileParames);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果文件上传成功,返回成功消息
|
|
||||||
return ElectromagneticResultUtil.success(Boolean.TRUE);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// 如果出现异常,返回异常消息
|
|
||||||
return ElectromagneticResultUtil.fail(HttpStatus.INTERNAL_SERVER_ERROR.toString(),"文件上传失败" + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载
|
* 下载
|
||||||
* WISDOM_DOWNLOAD
|
* WISDOM_DOWNLOAD
|
||||||
* /data/ed/file/download
|
* /data/ed/file/download
|
||||||
* @param request
|
*
|
||||||
|
* @param fileDownloadDTO
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public ElectromagneticResult<Map<String, List<String>>> download(EDDataRequest request)
|
public ResponseEntity<InputStreamResource> download(FileDownloadDTO fileDownloadDTO, HttpServletResponse response) throws IOException
|
||||||
{
|
{
|
||||||
//EDDataParams parames= EDDataMappers.INSTANCE.getEDDataParames(request);
|
|
||||||
|
|
||||||
// 获取文件存储的文件夹路径
|
// 获取文件存储的文件夹路径
|
||||||
String storageDirectory = "D:/fileTemp";
|
String osName = System.getProperty("os.name").toLowerCase();
|
||||||
|
String storageFilePath = osName.startsWith("win") ? uploadFilePath + fileStorageDir : fileStorageDir;
|
||||||
EDDataParams parames = new EDDataParams();
|
EDDataParams parames = new EDDataParams();
|
||||||
List<String> dataPathArr = new ArrayList();
|
String dataId = fileDownloadDTO.getDataId();
|
||||||
for(String dataId : request.getDataIdArr())
|
parames.setDataId(dataId);
|
||||||
{
|
EDDataInfo edDataInfo = edDataService.getDataInfo(parames);
|
||||||
parames.setDataId(dataId);
|
Assert.isTrue(edDataInfo != null, "没有找到该下载文件");
|
||||||
EDDataInfo edDataInfo = edDataService.getDataInfo(parames);
|
JSONObject implantJsonObject = JSON.parseObject(edDataInfo.getImplantJson());
|
||||||
if(edDataInfo != null)
|
String filePath = storageFilePath + "/" + implantJsonObject.getString("folderPath") + "/" + edDataInfo.getDataName();
|
||||||
{
|
|
||||||
JSONObject implantJsonObject = JSON.parseObject(edDataInfo.getImplantJson());
|
|
||||||
String filePath = implantJsonObject.getString("folderPath");
|
|
||||||
filePath = storageDirectory + "/" + filePath + "/" + edDataInfo.getDataName();
|
|
||||||
dataPathArr.add(filePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, List<String>> result = new HashMap<>();
|
Assert.isTrue(FileUtil.exist(filePath), "下载文件不存在。");
|
||||||
result.put("urlArr", dataPathArr);
|
File file = new File(filePath);
|
||||||
|
FileSystemResource fileSystemResource = new FileSystemResource(file);
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||||
|
headers.add("Content-Disposition", String.format("attachment; filename=\"%s\"", fileSystemResource.getFilename()));
|
||||||
|
headers.add("Pragma", "no-cache");
|
||||||
|
headers.add("Expires", "0");
|
||||||
|
|
||||||
|
// 构建响应实体(可以返回<byte[]或Resource,返回类型取决body入参类型)
|
||||||
|
return ResponseEntity
|
||||||
|
.ok()
|
||||||
|
.headers(headers)
|
||||||
|
.contentLength(fileSystemResource.contentLength())
|
||||||
|
.contentType(MediaType.parseMediaType("application/octet-stream"))
|
||||||
|
.body(new InputStreamResource(fileSystemResource.getInputStream()));
|
||||||
|
|
||||||
return ElectromagneticResultUtil.success(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -360,94 +205,149 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ElectromagneticResult<String> batchExport(EDDataRequest request) {
|
public ElectromagneticResult<Map<String, String>> batchExport(EDDataRequest request) {
|
||||||
//1、根据用户选择层级树编码查出所有文件和文件夹list
|
//1、根据用户选择层级树编码查出所有文件和文件夹list
|
||||||
//2、循环list将每个文件复制到新建目录并进行重命名,命名规则:目录树编码+,+文件夹编码(有则填写无则为空)+,+文件编码
|
//2、循环list将每个文件复制到新建目录并进行重命名,命名规则:目录树编码+,+文件夹编码(有则填写无则为空)+,+文件编码
|
||||||
//3、打包新建为zip,并根据生产下载地址(域名+文件路径+文件)
|
//3、打包新建为zip,并根据生产下载地址(域名+文件路径+文件)
|
||||||
//4、返回前端下载的地址
|
//4、返回前端下载的地址
|
||||||
|
|
||||||
// **********在导出的过程中可能会出现有用户上传文件的情况
|
// **********在导出的过程中可能会出现有用户上传文件的情况
|
||||||
|
EDDataParams parames= EDDataMappers.INSTANCE.getEDDataParames(request);
|
||||||
// 获取目录编码ID
|
String fileUrl = edDataService.exportData(parames);
|
||||||
String categoryId = request.getParentId();
|
Map<String, String> result = new HashMap<>();
|
||||||
|
result.put("url", fileUrl);
|
||||||
// 获取缓存文件夹的绝对路径
|
return ElectromagneticResultUtil.success(result);
|
||||||
String userHome = System.getProperty("user.home");
|
|
||||||
File cacheDirectory = new File(userHome + "\\AppData\\Local\\Temp\\EDData\\Export");
|
|
||||||
if (!cacheDirectory.exists()) {
|
|
||||||
cacheDirectory.mkdirs();
|
|
||||||
}
|
|
||||||
|
|
||||||
String cacheFolder = cacheDirectory.getAbsolutePath(); // 缓存文件夹的绝对路径
|
|
||||||
|
|
||||||
|
|
||||||
List<Category> categoryList = categoryService.selectAllCategories();
|
|
||||||
|
|
||||||
{
|
|
||||||
// 遍历客户端上传的
|
|
||||||
EDDataParams folderParames = new EDDataParams();
|
|
||||||
for (String dataId : request.getDataIdArr()) {
|
|
||||||
Category category = new Category();
|
|
||||||
category.setCategoryId(dataId);
|
|
||||||
categoryService.selectCategories(category);
|
|
||||||
|
|
||||||
//folderParames.setDataId(dataId);
|
|
||||||
//EDDataInfo edDataInfo = edDataService.getDataInfo(folderParames);
|
|
||||||
//if(edDataInfo != null)
|
|
||||||
//{
|
|
||||||
// JSONObject implantJsonObject = JSON.parseObject(edDataInfo.getImplantJson());
|
|
||||||
// String filePath = implantJsonObject.getString("folderPath");
|
|
||||||
// filePath = storageDirectory + "/" + filePath + "/" + edDataInfo.getDataName();
|
|
||||||
// dataPathArr.add(filePath);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
String parentFolderPath = ""; //上级文件夹路径
|
|
||||||
String parentFolderIdPath = ""; //上级文件夹ID路径
|
|
||||||
String parentFolderName = ""; //上级文件夹名称
|
|
||||||
|
|
||||||
// 获取上级文件夹路径
|
|
||||||
{
|
|
||||||
EDDataParams folderParames = new EDDataParams();
|
|
||||||
folderParames.setDataId(categoryId);
|
|
||||||
EDDataInfo edDataInfoParent = edDataService.getDataInfo(folderParames);
|
|
||||||
if(edDataInfoParent == null) {
|
|
||||||
ElectromagneticResultUtil.fail(HttpStatus.BAD_REQUEST.toString(),"上级文件夹为空!");
|
|
||||||
}
|
|
||||||
JSONObject implantJsonObject = JSON.parseObject(edDataInfoParent.getImplantJson());
|
|
||||||
parentFolderPath = implantJsonObject.getString("folderPath");
|
|
||||||
parentFolderIdPath = implantJsonObject.getString("folderIdPath");
|
|
||||||
if(!parentFolderPath.isEmpty())
|
|
||||||
parentFolderPath += "/" ;
|
|
||||||
if(!parentFolderIdPath.isEmpty())
|
|
||||||
parentFolderIdPath += "/" ;
|
|
||||||
parentFolderPath += edDataInfoParent.getDataName();
|
|
||||||
parentFolderIdPath += edDataInfoParent.getDataId();
|
|
||||||
parentFolderName = edDataInfoParent.getDataName();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导入
|
* 导入
|
||||||
* @param request
|
* @param fileChunkDTO
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ElectromagneticResult<String> batchImport(EDDataRequest request) {
|
public ElectromagneticResult<?> batchImport(FileChunkDTO fileChunkDTO) {
|
||||||
//1、上传文件到指定目录,并重命名
|
|
||||||
//2、接下压缩包
|
String identifier = fileChunkDTO.getIdentifier();
|
||||||
//3、扫码解压文件夹的所有文件
|
String fileName = fileChunkDTO.getFileName();
|
||||||
//4、循环处理文件:读取文件名称,根据名称规则,进行数据库查询,匹配层级树、文件夹和文件是否跳过
|
|
||||||
//5、如果不存在则新建文件记录
|
// 首先检查文件是否存在,如果存在则不允许重复上传。
|
||||||
//6、并移动文件到上传目录
|
String destZipPath = uploadFilePath + identifier + File.separator + fileName;
|
||||||
//7、处理完成返回成功
|
boolean existFile = FileUtil.exist(new File(destZipPath));
|
||||||
return null;
|
if (existFile) {
|
||||||
|
return ElectromagneticResultUtil.fail("-1", "文件已经存在,请勿重复上传。");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查该分片有没被上传过
|
||||||
|
String destChunkPath = uploadFilePath + identifier + File.separator + fileChunkDTO.getChunkNumber() + UPLOAD_FILE_CHUNK_SUFFIX;
|
||||||
|
boolean existChunk = FileUtil.exist(new File(destChunkPath));
|
||||||
|
if (existChunk) {
|
||||||
|
return ElectromagneticResultUtil.success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
File dir = new File(uploadFilePath + identifier + File.separator);
|
||||||
|
if (!dir.exists()) {
|
||||||
|
dir.mkdir();
|
||||||
|
}
|
||||||
|
|
||||||
|
try (
|
||||||
|
InputStream inputStream = fileChunkDTO.getFile().getInputStream();
|
||||||
|
FileOutputStream fileOutputStream = new FileOutputStream(destChunkPath);
|
||||||
|
) {
|
||||||
|
IoUtil.copy(inputStream, fileOutputStream);
|
||||||
|
} catch (IOException ioException) {
|
||||||
|
log.error("上传文件错误...", ioException);
|
||||||
|
}
|
||||||
|
return ElectromagneticResultUtil.success(fileChunkDTO.getIdentifier());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ElectromagneticResult<List<Integer>> getUploadedChunkNums(String identifier) {
|
||||||
|
return ElectromagneticResultUtil.success(getUploadedChunks(identifier));
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Integer> getUploadedChunks(String identifier) {
|
||||||
|
String destPath = uploadFilePath + identifier;
|
||||||
|
|
||||||
|
if (!FileUtil.exist(new File(destPath))) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Integer> uploadedFileChunkNums = FileUtil.listFileNames(destPath)
|
||||||
|
.stream()
|
||||||
|
.filter(e -> !e.endsWith(".zip"))
|
||||||
|
.map(e -> e.replace(UPLOAD_FILE_CHUNK_SUFFIX, ""))
|
||||||
|
.map(Integer::parseInt)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
return uploadedFileChunkNums;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO 需要验证如果一个分片上传一半网络断开,则该分片的存储情况。
|
||||||
|
@Override
|
||||||
|
public ElectromagneticResult<?> mergeChunks(String identifier, String fileName, Integer totalChunks) {
|
||||||
|
|
||||||
|
// 检查所有分片是否已经上传完成,分片编号从1开始
|
||||||
|
for (int i = 1; i <= totalChunks; i++) {
|
||||||
|
String tmpPath = uploadFilePath + identifier + File.separator + i + UPLOAD_FILE_CHUNK_SUFFIX;
|
||||||
|
if (!FileUtil.exist(new File(tmpPath))) {
|
||||||
|
log.error("第{}个分片没有上传完成,请上传完成后再合并。", i);
|
||||||
|
ElectromagneticResultUtil.fail("-1", "文件尚未上传完成。");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 合并分片
|
||||||
|
String destZipPath = uploadFilePath + identifier + File.separator + fileName;
|
||||||
|
File mergedFile = new File(destZipPath);
|
||||||
|
try {
|
||||||
|
RandomAccessFile targetFile = new RandomAccessFile(mergedFile, "rw");
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
for (int i = 1; i <= totalChunks; i++) {
|
||||||
|
String tmpPath = uploadFilePath + identifier + File.separator + i + UPLOAD_FILE_CHUNK_SUFFIX;
|
||||||
|
RandomAccessFile tmp = new RandomAccessFile(new File(tmpPath), "r");
|
||||||
|
int len;
|
||||||
|
while ((len = tmp.read(buffer)) != -1) {
|
||||||
|
targetFile.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
tmp.close();
|
||||||
|
}
|
||||||
|
targetFile.close();
|
||||||
|
} catch (IOException ioException) {
|
||||||
|
ElectromagneticResultUtil.fail("-1", "文件合并失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除分片
|
||||||
|
for (int i = 1; i <= totalChunks; i++) {
|
||||||
|
String tmpPath = uploadFilePath + identifier + File.separator + i + UPLOAD_FILE_CHUNK_SUFFIX;
|
||||||
|
FileUtil.del(tmpPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检验文件的MD5值
|
||||||
|
|
||||||
|
// 解压文件
|
||||||
|
ZipUtil.unzip(destZipPath, uploadFilePath + identifier + File.separator);
|
||||||
|
|
||||||
|
// 文件信息存入数据库
|
||||||
|
Map<String, List<String>> result = edDataService.importData(destZipPath);
|
||||||
|
|
||||||
|
return ElectromagneticResultUtil.success(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ElectromagneticResult<FileChunkResultDTO> checkChunkExist(FileChunkDTO fileChunkDTO) {
|
||||||
|
FileChunkResultDTO res = new FileChunkResultDTO();
|
||||||
|
// 首先判断zip文件是否存在,如果不存在则表示还没有上传完成。
|
||||||
|
String identifier = fileChunkDTO.getIdentifier();
|
||||||
|
String fileName = fileChunkDTO.getFileName();
|
||||||
|
String destZipPath = uploadFilePath + identifier + File.separator + fileName;
|
||||||
|
boolean existFile = FileUtil.exist(new File(destZipPath));
|
||||||
|
|
||||||
|
if (existFile) {
|
||||||
|
return ElectromagneticResultUtil.success(new FileChunkResultDTO(true, new HashSet<>()));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Integer> uploadedChunks = getUploadedChunks(identifier);
|
||||||
|
return ElectromagneticResultUtil.success(new FileChunkResultDTO(false, new HashSet<>(uploadedChunks)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue