Merge branch 'develop' into test
This commit is contained in:
commit
df92c856af
|
|
@ -68,8 +68,8 @@ public class EDDataController {
|
||||||
|
|
||||||
@ApiOperation(value = "下载",notes = "")
|
@ApiOperation(value = "下载",notes = "")
|
||||||
@RequestMapping(value = "/download",method = RequestMethod.GET)
|
@RequestMapping(value = "/download",method = RequestMethod.GET)
|
||||||
public ResponseEntity<InputStreamResource> download(@RequestBody FileDownloadDTO fileDownloadDTO, HttpServletResponse response) throws IOException {
|
public ResponseEntity<InputStreamResource> download(@RequestParam String dataId, HttpServletResponse response) throws IOException {
|
||||||
return edDataFacade.download(fileDownloadDTO, response);
|
return edDataFacade.download(dataId, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -80,9 +80,9 @@ public class EDDataController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "数据导出",notes = "")
|
@ApiOperation(value = "数据导出",notes = "")
|
||||||
@RequestMapping(value = "/batchExport",method = RequestMethod.POST)
|
@RequestMapping(value = "/batchExport",method = RequestMethod.GET)
|
||||||
public ElectromagneticResult<?> batchExport(@RequestBody EDDataRequest request){
|
public ResponseEntity<InputStreamResource> batchExport(@RequestParam String dataIdArr, HttpServletResponse response) throws IOException {
|
||||||
return edDataFacade.batchExport(request);
|
return edDataFacade.batchExport(dataIdArr, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "获取已经上传的分片",notes = "")
|
@ApiOperation(value = "获取已经上传的分片",notes = "")
|
||||||
|
|
|
||||||
|
|
@ -39,3 +39,5 @@ data.file.storage.dir=/szsd/fileStorage/
|
||||||
data.upload.cache.dir=upload
|
data.upload.cache.dir=upload
|
||||||
#导出数据时文件的缓存文件夹名称
|
#导出数据时文件的缓存文件夹名称
|
||||||
data.export.cache.dir=export
|
data.export.cache.dir=export
|
||||||
|
#导入数据时文件的缓存文件夹名称
|
||||||
|
data.import.cache.dir=import
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,25 @@ import java.util.Map;
|
||||||
|
|
||||||
public interface EDDataService {
|
public interface EDDataService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据存储目录
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String getDataStoragePath();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据缓存目录
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String getDataCachePath();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件的文件夹路径
|
||||||
|
* @param categoryId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String getFilePathOfFolder(String categoryId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建文件/文件夹数据信息
|
* 创建文件/文件夹数据信息
|
||||||
* @param edDataInfo
|
* @param edDataInfo
|
||||||
|
|
@ -44,13 +63,6 @@ public interface EDDataService {
|
||||||
*/
|
*/
|
||||||
Integer getChildFileCount(EDDataParams parames);
|
Integer getChildFileCount(EDDataParams parames);
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取文件的文件夹路径
|
|
||||||
* @param categoryId
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
String getFilePathOfFolder(String categoryId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件上传
|
* 文件上传
|
||||||
* @param parames
|
* @param parames
|
||||||
|
|
@ -67,10 +79,10 @@ public interface EDDataService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出数据
|
* 导出数据
|
||||||
* @param parames
|
* @param dataIdList
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String exportData(EDDataParams parames);
|
String exportData(List<String> dataIdList);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解压后的数据目录
|
* 解压后的数据目录
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.util.ZipUtil;
|
import cn.hutool.core.util.ZipUtil;
|
||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
import cn.hutool.crypto.symmetric.AES;
|
import cn.hutool.crypto.symmetric.AES;
|
||||||
|
import cn.hutool.json.JSONArray;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
import cn.hutool.poi.excel.cell.CellSetter;
|
import cn.hutool.poi.excel.cell.CellSetter;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
@ -17,8 +19,10 @@ import com.electromagnetic.industry.software.data.manage.domain.boardservice.ind
|
||||||
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.electromagnetic.industry.software.data.manage.domain.boardservice.user.repository.CategoryRepository;
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
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;
|
||||||
|
|
@ -35,9 +39,11 @@ import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -100,6 +106,37 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
return osName.startsWith("win") ? windowsDir + fileCacheDir : fileCacheDir;
|
return osName.startsWith("win") ? windowsDir + fileCacheDir : fileCacheDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件的文件夹路径
|
||||||
|
* @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 edDataInfo
|
* @param edDataInfo
|
||||||
|
|
@ -193,8 +230,7 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
}
|
}
|
||||||
|
|
||||||
EDDataInfo edDataInfo = edDataInfoList.get(0);
|
EDDataInfo edDataInfo = edDataInfoList.get(0);
|
||||||
JSONObject implantJsonObject = JSON.parseObject(edDataInfo.getImplantJson());
|
String filePathOfFolder = getFilePathOfFolder(edDataInfo.getCategoryId());
|
||||||
String filePathOfFolder = implantJsonObject.getString("folderPath");
|
|
||||||
String fileStorageFullPath = dataStoragePath + filePathOfFolder + File.separator + edDataInfo.getDataName();
|
String fileStorageFullPath = dataStoragePath + filePathOfFolder + File.separator + edDataInfo.getDataName();
|
||||||
|
|
||||||
if (!FileUtil.exist(fileStorageFullPath)){
|
if (!FileUtil.exist(fileStorageFullPath)){
|
||||||
|
|
@ -202,7 +238,9 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
}
|
}
|
||||||
|
|
||||||
String fileNameNew = parames.getName();
|
String fileNameNew = parames.getName();
|
||||||
|
if(fileNameNew != null && fileNameNew != "" && !fileNameNew.equals(edDataInfo.getDataName())) {
|
||||||
FileUtil.rename(Paths.get(fileStorageFullPath) ,fileNameNew,true);
|
FileUtil.rename(Paths.get(fileStorageFullPath) ,fileNameNew,true);
|
||||||
|
}
|
||||||
|
|
||||||
edDataRepository.updateFileInfo(parames);
|
edDataRepository.updateFileInfo(parames);
|
||||||
|
|
||||||
|
|
@ -219,6 +257,7 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
Integer childFileCount = 0;
|
Integer childFileCount = 0;
|
||||||
|
|
||||||
List<EDDataInfo> edDataInfoList = edDataRepository.getDataInfoList(parames);
|
List<EDDataInfo> edDataInfoList = edDataRepository.getDataInfoList(parames);
|
||||||
|
parames.setDataId(null);
|
||||||
for (EDDataInfo edDataInfo : edDataInfoList) {
|
for (EDDataInfo edDataInfo : edDataInfoList) {
|
||||||
if(edDataInfo.getDataType().equals("folder"))
|
if(edDataInfo.getDataType().equals("folder"))
|
||||||
{
|
{
|
||||||
|
|
@ -234,37 +273,6 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
return childFileCount;
|
return childFileCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取文件的文件夹路径
|
|
||||||
* @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
|
||||||
|
|
@ -330,11 +338,6 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
edDataInfo.setDataStatus("publish");
|
edDataInfo.setDataStatus("publish");
|
||||||
edDataInfo.setSaveStatus("saving");
|
edDataInfo.setSaveStatus("saving");
|
||||||
|
|
||||||
JSONObject newImplantJsonObject = new JSONObject();
|
|
||||||
newImplantJsonObject.put("folderPath", filePathOfFolder);
|
|
||||||
|
|
||||||
edDataInfo.setImplantJson(newImplantJsonObject.toJSONString());
|
|
||||||
|
|
||||||
boolean isSuccess = edDataRepository.createDataInfo(edDataInfo);
|
boolean isSuccess = edDataRepository.createDataInfo(edDataInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -344,6 +347,9 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
// 文件保存目录路径
|
// 文件保存目录路径
|
||||||
String fileSavePath = dataStoragePath + File.separator + filePathOfFolder;
|
String fileSavePath = dataStoragePath + File.separator + filePathOfFolder;
|
||||||
String newFileName = edDataInfo.getDataId() + FOLDER_NAME_SEPARATOR + fileFullName;
|
String newFileName = edDataInfo.getDataId() + FOLDER_NAME_SEPARATOR + fileFullName;
|
||||||
|
if (!FileUtil.exist(fileSavePath)){
|
||||||
|
FileUtil.mkdir(fileSavePath);
|
||||||
|
}
|
||||||
|
|
||||||
String dataCachePath = getDataCachePath();
|
String dataCachePath = getDataCachePath();
|
||||||
String uploadFileCachePath = dataCachePath + uploadCacheDir + FOLDER_NAME_SEPARATOR + getTimeStampString();
|
String uploadFileCachePath = dataCachePath + uploadCacheDir + FOLDER_NAME_SEPARATOR + getTimeStampString();
|
||||||
|
|
@ -417,8 +423,7 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
EDDataInfo edDataInfo = edDataRepository.getDataInfo(paramesFileInfo);
|
EDDataInfo edDataInfo = edDataRepository.getDataInfo(paramesFileInfo);
|
||||||
if(edDataInfo != null)
|
if(edDataInfo != null)
|
||||||
{
|
{
|
||||||
JSONObject implantJsonObject = JSON.parseObject(edDataInfo.getImplantJson());
|
String filePathOfFolder = getFilePathOfFolder(dataId);
|
||||||
String filePathOfFolder = implantJsonObject.getString("folderPath");
|
|
||||||
String fileStoragePath = dataStoragePath + File.separator + filePathOfFolder;
|
String fileStoragePath = dataStoragePath + File.separator + filePathOfFolder;
|
||||||
String fileStorageFullPath = fileStoragePath + File.separator + edDataInfo.getDataName();
|
String fileStorageFullPath = fileStoragePath + File.separator + edDataInfo.getDataName();
|
||||||
if (FileUtil.exist(fileStoragePath)) {
|
if (FileUtil.exist(fileStoragePath)) {
|
||||||
|
|
@ -442,19 +447,23 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出数据
|
* 导出数据
|
||||||
* @param parames
|
* @param dataIdList
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String exportData(EDDataParams parames)
|
public String exportData(List<String> dataIdList)
|
||||||
{
|
{
|
||||||
|
String zipPathFileName = "";
|
||||||
|
String exportDataCachePath = "";
|
||||||
|
String enCodeZipPathFileName = "";
|
||||||
|
|
||||||
|
try {
|
||||||
// 获取文件夹编码ID数组
|
// 获取文件夹编码ID数组
|
||||||
List<String> categoryIdInputList = Arrays.asList(parames.getDataIdArr());
|
List<String> categoryIdInputList = dataIdList;
|
||||||
|
|
||||||
String dataCachePath = getDataCachePath();
|
String dataCachePath = getDataCachePath();
|
||||||
|
|
||||||
// 导出数据时的临时存放目录
|
// 导出数据时的临时存放目录
|
||||||
String exportDataCachePath = dataCachePath + exportCacheDir + FOLDER_NAME_SEPARATOR + getTimeStampString();
|
exportDataCachePath = dataCachePath + exportCacheDir + FOLDER_NAME_SEPARATOR + getTimeStampString();
|
||||||
if (!FileUtil.exist(exportDataCachePath)) {
|
if (!FileUtil.exist(exportDataCachePath)) {
|
||||||
FileUtil.mkdir(exportDataCachePath);
|
FileUtil.mkdir(exportDataCachePath);
|
||||||
}
|
}
|
||||||
|
|
@ -474,87 +483,50 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
|
|
||||||
List<Category> categoryInputList = new ArrayList(); //客户端输入的目录数组
|
List<Category> categoryInputList = new ArrayList(); //客户端输入的目录数组
|
||||||
Map<String, Category> categoryInputMap = new HashMap(); //客户端输入的目录数组map
|
Map<String, Category> categoryInputMap = new HashMap(); //客户端输入的目录数组map
|
||||||
List<EDDataInfo> fileInputList = new ArrayList(); //客户端输入的目录下的文件夹数组
|
|
||||||
Map<String, EDDataInfo> fileInputMap = new HashMap(); //客户端输入的目录下的文件夹数组map
|
|
||||||
for (String categoryId : categoryIdInputList) {
|
for (String categoryId : categoryIdInputList) {
|
||||||
Category category = categoryAllMap.get(categoryId);
|
Category category = categoryAllMap.get(categoryId);
|
||||||
if (category != null) {
|
if (category != null) {
|
||||||
categoryInputList.add(category);
|
categoryInputList.add(category);
|
||||||
categoryInputMap.put(categoryId, 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字符串
|
// 将List<Category>转换为JSON字符串
|
||||||
try {
|
String jsonStringCategory = JSONUtil.toJsonStr(categoryInputList);
|
||||||
String jsonString = objectMapper.writeValueAsString(categoryInputList);
|
String categoryListFileFullPath = exportDataCachePath + "/categoryList.json";
|
||||||
// 将JSON字符串写入文件
|
FileUtil.writeString(jsonStringCategory, categoryListFileFullPath, "utf-8");
|
||||||
File jsonFile = new File(exportDataCachePath + "/categoryList.json");
|
log.info("目录树数据已成功导出为JSON文件。" + categoryListFileFullPath);
|
||||||
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(); //需要导出的文件信息数据数组
|
List<EDDataInfo> fileExportList = new ArrayList(); //需要导出的文件信息数据数组
|
||||||
|
Map<String, EDDataInfo> fileExportMap = new HashMap(); //需要导出的文件信息数据数组map
|
||||||
for (EDDataInfo fileFinfo : fileAllList) {
|
for (EDDataInfo fileFinfo : fileAllList) {
|
||||||
if(fileFinfo.getDataType().equals("folder")) {
|
|
||||||
if (categoryInputMap.get(fileFinfo.getCategoryId()) != null) {
|
if (categoryInputMap.get(fileFinfo.getCategoryId()) != null) {
|
||||||
fileExportList.add(fileFinfo);
|
fileExportList.add(fileFinfo);
|
||||||
|
fileExportMap.put(fileFinfo.getDataId(), fileFinfo);
|
||||||
}
|
}
|
||||||
} else if(fileFinfo.getDataType().equals("file")) {
|
}
|
||||||
if(fileInputMap.get(fileFinfo.getCategoryId()) != null) {
|
// 找出子文件夹下的文件
|
||||||
fileExportList.add(fileFinfo);
|
for (EDDataInfo fileFinfo : fileAllList) {
|
||||||
} else if(categoryInputMap.get(fileFinfo.getCategoryId()) != null) {
|
if (fileExportMap.get(fileFinfo.getCategoryId()) != null) {
|
||||||
fileExportList.add(fileFinfo);
|
fileExportList.add(fileFinfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
// 将文件信息数据导出为json文件
|
||||||
|
String jsonStringFile = JSONUtil.toJsonStr(fileExportList);
|
||||||
|
String fileListFileFullPath = exportDataCachePath + "/fileInfoList.json";
|
||||||
|
FileUtil.writeString(jsonStringFile, fileListFileFullPath, "utf-8");
|
||||||
|
log.info("文件数据已成功导出为JSON文件。" + fileListFileFullPath);
|
||||||
|
|
||||||
// 创建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 dataStoragePath = getDataStoragePath();
|
||||||
String needExportfolder = "";
|
String needExportfolder = "";
|
||||||
for (Category category : categoryInputList)
|
for (Category category : categoryInputList) {
|
||||||
{
|
|
||||||
needExportfolder = dataStoragePath + category.getCategoryId() + FOLDER_NAME_SEPARATOR + category.getCategoryName();
|
needExportfolder = dataStoragePath + category.getCategoryId() + FOLDER_NAME_SEPARATOR + category.getCategoryName();
|
||||||
if (FileUtil.exist(needExportfolder)) {
|
if (FileUtil.exist(needExportfolder)) {
|
||||||
Path source = Paths.get(needExportfolder);
|
Path source = Paths.get(needExportfolder);
|
||||||
|
|
@ -564,12 +536,15 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("文件数据已成功复制到目标目录。");
|
log.info("文件数据已成功复制到目标目录。");
|
||||||
}
|
|
||||||
|
|
||||||
// 将目录树数据 和 文件夹及文件夹内数据 进行压缩打包
|
// 将目录树数据 和 文件夹及文件夹内数据 进行压缩打包
|
||||||
{
|
Date date = new Date();
|
||||||
String zipPathFileName = dataCachePath + "/comac_exportData1.comac";
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss");
|
||||||
String enCodeZipPathFileName = dataCachePath + "/comac_exportData.comac";
|
String dateString = sdf.format(date);
|
||||||
|
|
||||||
|
zipPathFileName = dataCachePath + "/exportData_" + dateString;
|
||||||
|
enCodeZipPathFileName = dataCachePath + "/exportData_" + dateString + ".comac";
|
||||||
// EleZipUtil.zipFile(exportDataDirectory, zipPathFileName, passwordZIP);
|
// EleZipUtil.zipFile(exportDataDirectory, zipPathFileName, passwordZIP);
|
||||||
|
|
||||||
ZipUtil.zip(exportDataCachePath, zipPathFileName);
|
ZipUtil.zip(exportDataCachePath, zipPathFileName);
|
||||||
|
|
@ -584,15 +559,19 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
log.error("文件加密错误..", e);
|
log.error("文件加密错误..", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
//FileUtil.del(zipPathFileName);//删除临时目录
|
|
||||||
|
|
||||||
log.info("目录树数据+文件数据已成功复制到目标目录。" + zipPathFileName);
|
log.info("目录树数据+文件数据已成功复制到目标目录。" + zipPathFileName);
|
||||||
}
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
log.error("导出数据异常..", e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
//删除临时文件
|
||||||
|
//FileUtil.del(zipPathFileName);
|
||||||
// 删除 导出数据的 缓存目录
|
// 删除 导出数据的 缓存目录
|
||||||
FileUtil.del(exportDataCachePath);
|
FileUtil.del(exportDataCachePath);
|
||||||
|
}
|
||||||
|
|
||||||
return dataCachePath + "/comac_exportData.comac";
|
return enCodeZipPathFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -605,8 +584,7 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
// 获取所有目录树节点数据
|
// 获取所有目录树节点数据
|
||||||
List<Category> categoryAllList = categoryRepository.getAllCategories();
|
List<Category> categoryAllList = categoryRepository.getAllCategories();
|
||||||
Map<String, Category> categoryAllMap = new HashMap(); //所有目录数组map
|
Map<String, Category> categoryAllMap = new HashMap(); //所有目录数组map
|
||||||
for (Category category : categoryAllList)
|
for (Category category : categoryAllList) {
|
||||||
{
|
|
||||||
categoryAllMap.put(category.getCategoryId(), category);
|
categoryAllMap.put(category.getCategoryId(), category);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -614,76 +592,45 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
EDDataParams parames = new EDDataParams();
|
EDDataParams parames = new EDDataParams();
|
||||||
List<EDDataInfo> fileInfoAllList = edDataRepository.getDataInfoList(parames);
|
List<EDDataInfo> fileInfoAllList = edDataRepository.getDataInfoList(parames);
|
||||||
Map<String, EDDataInfo> fileInfoAllMap = new HashMap(); //所有文件数组map
|
Map<String, EDDataInfo> fileInfoAllMap = new HashMap(); //所有文件数组map
|
||||||
for (EDDataInfo fileInfo : fileInfoAllList)
|
for (EDDataInfo fileInfo : fileInfoAllList) {
|
||||||
{
|
|
||||||
fileInfoAllMap.put(fileInfo.getDataId(), fileInfo);
|
fileInfoAllMap.put(fileInfo.getDataId(), fileInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 读取并反序列化目录树的JSON文件数据为List<Category>;然后写入到数据库中。
|
// 读取并反序列化目录树的JSON文件数据为List<Category>;然后写入到数据库中。
|
||||||
List<Category> categoryImportList = null;
|
String jsonStringCategory = FileUtil.readString(folderPath + "/categoryList.json", StandardCharsets.UTF_8);
|
||||||
{
|
JSONArray jsonArrayCategory = JSONUtil.parseArray(jsonStringCategory);
|
||||||
// 读取文件数据
|
List<Category> categoryImportList = JSONUtil.toList(jsonArrayCategory, Category.class);
|
||||||
|
|
||||||
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) {
|
if (categoryImportList == null) {
|
||||||
log.error("读取并反序列化JSON文件数据为List<Category>失败!");
|
log.error("读取并反序列化JSON文件数据为List<Category>失败!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 将目录树数据写入到数据库中
|
// 将目录树数据写入到数据库中
|
||||||
for (Category category : categoryImportList) {
|
for (Category category : categoryImportList) {
|
||||||
if (categoryAllMap.get(category.getCategoryId()) == null) {
|
if (categoryAllMap.get(category.getCategoryId()) == null) {
|
||||||
categoryRepository.createCategory(category);
|
categoryRepository.createCategory(category);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 读取并反序列化文件信息的JSON文件数据为List<EDDataInfo>;然后写入到数据库中。
|
// 读取并反序列化文件信息的JSON文件数据为List<EDDataInfo>;然后写入到数据库中。
|
||||||
List<EDDataInfo> fileInfoImportList = null;
|
String jsonStringFile = FileUtil.readString(folderPath + "/fileInfoList.json", StandardCharsets.UTF_8);
|
||||||
{
|
JSONArray jsonArrayFile = JSONUtil.parseArray(jsonStringFile);
|
||||||
// 读取文件数据
|
List<EDDataInfo> fileInfoImportList = JSONUtil.toList(jsonArrayFile, EDDataInfo.class);
|
||||||
|
|
||||||
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) {
|
if (fileInfoImportList == null) {
|
||||||
log.error("读取并反序列化JSON文件数据为List<EDDataInfo>失败!");
|
log.error("读取并反序列化JSON文件数据为List<EDDataInfo>失败!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 将文件信息数据写入到数据库中
|
// 将文件信息数据写入到数据库中
|
||||||
for (EDDataInfo fileInfo : fileInfoImportList) {
|
for (EDDataInfo fileInfo : fileInfoImportList) {
|
||||||
if (fileInfoAllMap.get(fileInfo.getDataId()) == null) {
|
if (fileInfoAllMap.get(fileInfo.getDataId()) == null) {
|
||||||
edDataRepository.createDataInfo(fileInfo);
|
edDataRepository.createDataInfo(fileInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 将解压后的文件夹和文件 移动到 上传文件的存储目录中
|
// 将解压后的文件夹和文件 移动到 上传文件的存储目录中
|
||||||
List<String> importFileSuccess = new ArrayList();
|
List<String> importFileSuccess = new ArrayList();
|
||||||
List<String> importFileFail = new ArrayList();
|
List<String> importFileFail = new ArrayList();
|
||||||
{
|
|
||||||
String dataStoragePath = getDataStoragePath();
|
String dataStoragePath = getDataStoragePath();
|
||||||
if (!FileUtil.exist(dataStoragePath)){
|
if (!FileUtil.exist(dataStoragePath)){
|
||||||
FileUtil.mkdir(dataStoragePath);
|
FileUtil.mkdir(dataStoragePath);
|
||||||
|
|
@ -696,13 +643,11 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
String fileStoragePath = ""; //文件存储的文件夹路径
|
String fileStoragePath = ""; //文件存储的文件夹路径
|
||||||
String fileStorageFullPath = ""; //文件存储的文件全路径
|
String fileStorageFullPath = ""; //文件存储的文件全路径
|
||||||
|
|
||||||
try {
|
|
||||||
for (EDDataInfo fileInfo : fileInfoImportList) {
|
for (EDDataInfo fileInfo : fileInfoImportList) {
|
||||||
JSONObject newImplantJsonObject = JSONObject.parseObject(fileInfo.getImplantJson());
|
fileStorageFolder = getFilePathOfFolder(fileInfo.getCategoryId());
|
||||||
fileStorageFolder = newImplantJsonObject.getString("folderPath");
|
importFileCachePath = importDataCachePath + File.separator + fileStorageFolder;
|
||||||
importFileCachePath = importDataCachePath + fileStorageFolder;
|
|
||||||
importFileCacheFullPath = importFileCachePath + File.separator + fileInfo.getDataName();
|
importFileCacheFullPath = importFileCachePath + File.separator + fileInfo.getDataName();
|
||||||
fileStoragePath = dataStoragePath + fileStorageFolder;
|
fileStoragePath = dataStoragePath + File.separator + fileStorageFolder;
|
||||||
fileStorageFullPath = fileStoragePath + File.separator + fileInfo.getDataName();
|
fileStorageFullPath = fileStoragePath + File.separator + fileInfo.getDataName();
|
||||||
|
|
||||||
if (fileInfoAllMap.get(fileInfo.getDataId()) == null
|
if (fileInfoAllMap.get(fileInfo.getDataId()) == null
|
||||||
|
|
@ -712,14 +657,15 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
&& !FileUtil.exist(fileStorageFullPath)
|
&& !FileUtil.exist(fileStorageFullPath)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if(!FileUtil.exist(fileStoragePath)){
|
if(fileInfo.getDataType().equals("folder")) {
|
||||||
FileUtil.mkdir(fileStoragePath);
|
if (!FileUtil.exist(fileStorageFullPath)) {
|
||||||
|
FileUtil.mkdir(fileStorageFullPath);
|
||||||
}
|
}
|
||||||
|
} else if(fileInfo.getDataType().equals("file")) {
|
||||||
Path source = Paths.get(importFileCacheFullPath);
|
Path source = Paths.get(importFileCacheFullPath);
|
||||||
Path target = Paths.get(fileStorageFullPath);
|
Path target = Paths.get(fileStorageFullPath);
|
||||||
|
FileUtil.move(source,target,true);
|
||||||
Files.move(source, target);
|
}
|
||||||
|
|
||||||
importFileSuccess.add(fileInfo.getDataId() + FOLDER_NAME_SEPARATOR + fileInfo.getDataName());
|
importFileSuccess.add(fileInfo.getDataId() + FOLDER_NAME_SEPARATOR + fileInfo.getDataName());
|
||||||
}
|
}
|
||||||
|
|
@ -728,11 +674,7 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
importFileFail.add(fileInfo.getDataId() + FOLDER_NAME_SEPARATOR + fileInfo.getDataName());
|
importFileFail.add(fileInfo.getDataId() + FOLDER_NAME_SEPARATOR + fileInfo.getDataName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, List<String>> result = new HashMap<>();
|
Map<String, List<String>> result = new HashMap<>();
|
||||||
result.put("success", importFileSuccess);
|
result.put("success", importFileSuccess);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ 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.FileChunkDTO;
|
||||||
import com.electromagnetic.industry.software.data.manage.request.indicator.FileChunkResultDTO;
|
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.core.io.InputStreamResource;
|
||||||
|
|
@ -55,20 +54,20 @@ public interface EDDataFacade {
|
||||||
/**
|
/**
|
||||||
* 下载
|
* 下载
|
||||||
*
|
*
|
||||||
* @param fileDownloadDTO
|
* @param dataId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ResponseEntity<InputStreamResource> download(FileDownloadDTO fileDownloadDTO, HttpServletResponse response) throws IOException;
|
ResponseEntity<InputStreamResource> download(String dataId, HttpServletResponse response) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出
|
* 导出数据
|
||||||
* @param request
|
* @param dataIdArr
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ElectromagneticResult<Map<String, String>> batchExport(EDDataRequest request);
|
ResponseEntity<InputStreamResource> batchExport(String dataIdArr, HttpServletResponse response) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导入
|
* 导入数据
|
||||||
* @param fileChunkDTO
|
* @param fileChunkDTO
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,22 @@ public class EDDataResponse implements Serializable {
|
||||||
* 状态:publish:发布,occupy:占用
|
* 状态:publish:发布,occupy:占用
|
||||||
*/
|
*/
|
||||||
private String dataStatus;
|
private String dataStatus;
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String note;
|
||||||
|
/**
|
||||||
|
* 编辑人
|
||||||
|
*/
|
||||||
|
private String editor;
|
||||||
|
/**
|
||||||
|
* 批量上传时间
|
||||||
|
*/
|
||||||
|
private Date gmtBatchUpload;
|
||||||
|
/**
|
||||||
|
* 保存状态
|
||||||
|
*/
|
||||||
|
private String saveStatus;
|
||||||
/**
|
/**
|
||||||
* 创建人
|
* 创建人
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
<result column="data_no" jdbcType="VARCHAR" property="dataNo" />
|
<result column="data_no" jdbcType="VARCHAR" property="dataNo" />
|
||||||
<result column="data_name" jdbcType="VARCHAR" property="dataName" />
|
<result column="data_name" jdbcType="VARCHAR" property="dataName" />
|
||||||
<result column="data_type" jdbcType="VARCHAR" property="dataType" />
|
<result column="data_type" jdbcType="VARCHAR" property="dataType" />
|
||||||
|
<result column="file_type" jdbcType="VARCHAR" property="fileType" />
|
||||||
<result column="version" jdbcType="VARCHAR" property="version" />
|
<result column="version" jdbcType="VARCHAR" property="version" />
|
||||||
<result column="content" jdbcType="VARCHAR" property="content" />
|
<result column="content" jdbcType="VARCHAR" property="content" />
|
||||||
<result column="implant_json" jdbcType="VARCHAR" property="implantJson" />
|
<result column="implant_json" jdbcType="VARCHAR" property="implantJson" />
|
||||||
|
|
@ -37,7 +38,7 @@
|
||||||
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
|
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
|
||||||
SELECT LAST_INSERT_ID()
|
SELECT LAST_INSERT_ID()
|
||||||
</selectKey>
|
</selectKey>
|
||||||
insert into ed_data_info (id, category_id,
|
insert into ed_data_info (category_id,
|
||||||
data_id, data_no, data_name,
|
data_id, data_no, data_name,
|
||||||
data_type, file_type, version,
|
data_type, file_type, version,
|
||||||
content, implant_json, data_status,
|
content, implant_json, data_status,
|
||||||
|
|
@ -46,7 +47,7 @@
|
||||||
modifier, modifier_name, gmt_modified,
|
modifier, modifier_name, gmt_modified,
|
||||||
effect_flag
|
effect_flag
|
||||||
)
|
)
|
||||||
values (#{id,jdbcType=VARCHAR}, #{categoryId,jdbcType=VARCHAR},
|
values (#{categoryId,jdbcType=VARCHAR},
|
||||||
#{dataId,jdbcType=VARCHAR}, #{dataNo,jdbcType=VARCHAR}, #{dataName,jdbcType=VARCHAR},
|
#{dataId,jdbcType=VARCHAR}, #{dataNo,jdbcType=VARCHAR}, #{dataName,jdbcType=VARCHAR},
|
||||||
#{dataType,jdbcType=VARCHAR}, #{fileType,jdbcType=VARCHAR},#{version,jdbcType=VARCHAR},
|
#{dataType,jdbcType=VARCHAR}, #{fileType,jdbcType=VARCHAR},#{version,jdbcType=VARCHAR},
|
||||||
#{content,jdbcType=VARCHAR}, #{implantJson,jdbcType=VARCHAR}, #{dataStatus,jdbcType=VARCHAR},
|
#{content,jdbcType=VARCHAR}, #{implantJson,jdbcType=VARCHAR}, #{dataStatus,jdbcType=VARCHAR},
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@ package com.electromagnetic.industry.software.data.manage.service.facade;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import cn.hutool.core.text.StrFormatter;
|
||||||
import cn.hutool.core.util.ZipUtil;
|
import cn.hutool.core.util.ZipUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import cn.hutool.crypto.symmetric.AES;
|
||||||
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;
|
||||||
|
|
@ -14,7 +15,6 @@ 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.FileChunkDTO;
|
||||||
import com.electromagnetic.industry.software.data.manage.request.indicator.FileChunkResultDTO;
|
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;
|
||||||
|
|
@ -32,6 +32,8 @@ import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
@ -54,6 +56,8 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
||||||
private String uploadCacheDir;
|
private String uploadCacheDir;
|
||||||
@Value("${data.export.cache.dir}")
|
@Value("${data.export.cache.dir}")
|
||||||
private String exportCacheDir;
|
private String exportCacheDir;
|
||||||
|
@Value("${data.import.cache.dir}")
|
||||||
|
private String importCacheDir;
|
||||||
|
|
||||||
private static final String UPLOAD_FILE_CHUNK_SUFFIX = ".part";
|
private static final String UPLOAD_FILE_CHUNK_SUFFIX = ".part";
|
||||||
|
|
||||||
|
|
@ -83,12 +87,14 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
||||||
edDataInfo.setCategoryId(request.getParentId());
|
edDataInfo.setCategoryId(request.getParentId());
|
||||||
edDataInfo.setDataName(request.getName());
|
edDataInfo.setDataName(request.getName());
|
||||||
edDataInfo.setNote(request.getNote());
|
edDataInfo.setNote(request.getNote());
|
||||||
|
edDataInfo.setGmtBatchUpload(new Date());
|
||||||
|
|
||||||
edDataInfo.setDataId(IdWorker.getSnowFlakeIdString());
|
edDataInfo.setDataId(IdWorker.getSnowFlakeIdString());
|
||||||
edDataInfo.setDataNo(edDataInfo.getDataId());
|
edDataInfo.setDataNo(edDataInfo.getDataId());
|
||||||
edDataInfo.setDataType("folder");
|
edDataInfo.setDataType("folder");
|
||||||
edDataInfo.setVersion("1.0.0");
|
edDataInfo.setVersion("1.0.0");
|
||||||
edDataInfo.setDataStatus("publish");
|
edDataInfo.setDataStatus("publish");
|
||||||
|
edDataInfo.setSaveStatus("success");
|
||||||
|
|
||||||
Boolean isSuccess = edDataService.createDataInfo(edDataInfo);
|
Boolean isSuccess = edDataService.createDataInfo(edDataInfo);
|
||||||
return ElectromagneticResultUtil.success(isSuccess);
|
return ElectromagneticResultUtil.success(isSuccess);
|
||||||
|
|
@ -163,32 +169,37 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
||||||
* WISDOM_DOWNLOAD
|
* WISDOM_DOWNLOAD
|
||||||
* /data/ed/file/download
|
* /data/ed/file/download
|
||||||
*
|
*
|
||||||
* @param fileDownloadDTO
|
* @param dataId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public ResponseEntity<InputStreamResource> download(FileDownloadDTO fileDownloadDTO, HttpServletResponse response) throws IOException
|
public ResponseEntity<InputStreamResource> download(String dataId, HttpServletResponse response) throws IOException
|
||||||
{
|
{
|
||||||
|
|
||||||
// 获取文件存储的文件夹路径
|
// 获取文件存储的文件夹路径
|
||||||
String osName = System.getProperty("os.name").toLowerCase();
|
String osName = System.getProperty("os.name").toLowerCase();
|
||||||
String storageFilePath = osName.startsWith("win") ? uploadFilePath + fileStorageDir : fileStorageDir;
|
String storageFilePath = osName.startsWith("win") ? uploadFilePath + fileStorageDir : fileStorageDir;
|
||||||
EDDataParams parames = new EDDataParams();
|
EDDataParams parames = new EDDataParams();
|
||||||
String dataId = fileDownloadDTO.getDataId();
|
|
||||||
parames.setDataId(dataId);
|
parames.setDataId(dataId);
|
||||||
EDDataInfo edDataInfo = edDataService.getDataInfo(parames);
|
EDDataInfo edDataInfo = edDataService.getDataInfo(parames);
|
||||||
Assert.isTrue(edDataInfo != null, "没有找到该下载文件");
|
Assert.isTrue(edDataInfo != null, "没有找到该下载文件");
|
||||||
JSONObject implantJsonObject = JSON.parseObject(edDataInfo.getImplantJson());
|
String filePathOfFolder = edDataService.getFilePathOfFolder(edDataInfo.getCategoryId());
|
||||||
String filePath = storageFilePath + "/" + implantJsonObject.getString("folderPath") + "/" + edDataInfo.getDataName();
|
String filePath = storageFilePath + "/" + filePathOfFolder + "/" + edDataInfo.getDataName();
|
||||||
|
|
||||||
Assert.isTrue(FileUtil.exist(filePath), "下载文件不存在。");
|
Assert.isTrue(FileUtil.exist(filePath), "下载文件不存在。");
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
FileSystemResource fileSystemResource = new FileSystemResource(file);
|
FileSystemResource fileSystemResource = new FileSystemResource(file);
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
|
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||||
headers.add("Content-Disposition", String.format("attachment; filename=\"%s\"", fileSystemResource.getFilename()));
|
String fileName = fileSystemResource.getFilename();
|
||||||
|
byte[] fileNameBytes = fileName.getBytes(StandardCharsets.UTF_8);
|
||||||
|
fileName = new String(fileNameBytes, 0, fileNameBytes.length, StandardCharsets.ISO_8859_1);
|
||||||
|
String attachment = StrFormatter.format("attachment;filename={}", fileName);
|
||||||
|
//headers.add("Content-Disposition", attachment);
|
||||||
|
// headers.set("attachment", fileName);
|
||||||
headers.add("Pragma", "no-cache");
|
headers.add("Pragma", "no-cache");
|
||||||
headers.add("Expires", "0");
|
headers.add("Expires", "0");
|
||||||
|
response.setHeader("content-disposition","attachment;filename=" + URLEncoder.encode(fileName,"UTF-8"));
|
||||||
|
// response.setHeader("Content-Disposition", "attachment; filename=\"" + new String(fileSystemResource.getFilename().getBytes("UTF-8"), "ISO8859-1"));
|
||||||
// 构建响应实体(可以返回<byte[]或Resource,返回类型取决body入参类型)
|
// 构建响应实体(可以返回<byte[]或Resource,返回类型取决body入参类型)
|
||||||
return ResponseEntity
|
return ResponseEntity
|
||||||
.ok()
|
.ok()
|
||||||
|
|
@ -201,22 +212,49 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出
|
* 导出
|
||||||
* @param request
|
* @param dataIdArr
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ElectromagneticResult<Map<String, String>> batchExport(EDDataRequest request) {
|
public ResponseEntity<InputStreamResource> batchExport(String dataIdArr, HttpServletResponse response) throws IOException {
|
||||||
//1、根据用户选择层级树编码查出所有文件和文件夹list
|
//1、根据用户选择层级树编码查出所有文件和文件夹list
|
||||||
//2、循环list将每个文件复制到新建目录并进行重命名,命名规则:目录树编码+,+文件夹编码(有则填写无则为空)+,+文件编码
|
//2、循环list将每个文件复制到新建目录并进行重命名,命名规则:目录树编码+,+文件夹编码(有则填写无则为空)+,+文件编码
|
||||||
//3、打包新建为zip,并根据生产下载地址(域名+文件路径+文件)
|
//3、打包新建为zip,并根据生产下载地址(域名+文件路径+文件)
|
||||||
//4、返回前端下载的地址
|
//4、返回前端下载的地址
|
||||||
|
|
||||||
// **********在导出的过程中可能会出现有用户上传文件的情况
|
// **********在导出的过程中可能会出现有用户上传文件的情况
|
||||||
EDDataParams parames= EDDataMappers.INSTANCE.getEDDataParames(request);
|
|
||||||
String fileUrl = edDataService.exportData(parames);
|
|
||||||
Map<String, String> result = new HashMap<>();
|
Map<String, String> result = new HashMap<>();
|
||||||
result.put("url", fileUrl);
|
List<String> dataIdList = Arrays.asList(dataIdArr.split(","));
|
||||||
return ElectromagneticResultUtil.success(result);
|
if(dataIdList.size() > 0) {
|
||||||
|
String filePath = edDataService.exportData(dataIdList);
|
||||||
|
|
||||||
|
Assert.isTrue(FileUtil.exist(filePath), "下载文件不存在。");
|
||||||
|
File file = new File(filePath);
|
||||||
|
FileSystemResource fileSystemResource = new FileSystemResource(file);
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||||
|
String fileName = fileSystemResource.getFilename();
|
||||||
|
byte[] fileNameBytes = fileName.getBytes(StandardCharsets.UTF_8);
|
||||||
|
fileName = new String(fileNameBytes, 0, fileNameBytes.length, StandardCharsets.ISO_8859_1);
|
||||||
|
String attachment = StrFormatter.format("attachment;filename={}", fileName);
|
||||||
|
headers.add("Pragma", "no-cache");
|
||||||
|
headers.add("Expires", "0");
|
||||||
|
response.setHeader("content-disposition","attachment;filename=" + URLEncoder.encode(fileName,"UTF-8"));
|
||||||
|
|
||||||
|
// 构建响应实体(可以返回<byte[]或Resource,返回类型取决body入参类型)
|
||||||
|
return ResponseEntity
|
||||||
|
.ok()
|
||||||
|
.headers(headers)
|
||||||
|
.contentLength(fileSystemResource.contentLength())
|
||||||
|
.contentType(MediaType.parseMediaType("application/octet-stream"))
|
||||||
|
.body(new InputStreamResource(fileSystemResource.getInputStream()));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -230,21 +268,24 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
||||||
String identifier = fileChunkDTO.getIdentifier();
|
String identifier = fileChunkDTO.getIdentifier();
|
||||||
String fileName = fileChunkDTO.getFileName();
|
String fileName = fileChunkDTO.getFileName();
|
||||||
|
|
||||||
|
String dataCachePath = edDataService.getDataCachePath();
|
||||||
|
String importDataCachePath = dataCachePath + importCacheDir;
|
||||||
|
|
||||||
// 首先检查文件是否存在,如果存在则不允许重复上传。
|
// 首先检查文件是否存在,如果存在则不允许重复上传。
|
||||||
String destZipPath = uploadFilePath + identifier + File.separator + fileName;
|
String destZipPath = importDataCachePath + identifier + File.separator + fileName;
|
||||||
boolean existFile = FileUtil.exist(new File(destZipPath));
|
boolean existFile = FileUtil.exist(new File(destZipPath));
|
||||||
if (existFile) {
|
if (existFile) {
|
||||||
return ElectromagneticResultUtil.fail("-1", "文件已经存在,请勿重复上传。");
|
return ElectromagneticResultUtil.fail("-1", "文件已经存在,请勿重复上传。");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查该分片有没被上传过
|
// 检查该分片有没被上传过
|
||||||
String destChunkPath = uploadFilePath + identifier + File.separator + fileChunkDTO.getChunkNumber() + UPLOAD_FILE_CHUNK_SUFFIX;
|
String destChunkPath = importDataCachePath + identifier + File.separator + fileChunkDTO.getChunkNumber() + UPLOAD_FILE_CHUNK_SUFFIX;
|
||||||
boolean existChunk = FileUtil.exist(new File(destChunkPath));
|
boolean existChunk = FileUtil.exist(new File(destChunkPath));
|
||||||
if (existChunk) {
|
if (existChunk) {
|
||||||
return ElectromagneticResultUtil.success(true);
|
return ElectromagneticResultUtil.success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
File dir = new File(uploadFilePath + identifier + File.separator);
|
File dir = new File(importDataCachePath + identifier + File.separator);
|
||||||
if (!dir.exists()) {
|
if (!dir.exists()) {
|
||||||
dir.mkdir();
|
dir.mkdir();
|
||||||
}
|
}
|
||||||
|
|
@ -266,7 +307,9 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Integer> getUploadedChunks(String identifier) {
|
private List<Integer> getUploadedChunks(String identifier) {
|
||||||
String destPath = uploadFilePath + identifier;
|
String dataCachePath = edDataService.getDataCachePath();
|
||||||
|
String importDataCachePath = dataCachePath + importCacheDir;
|
||||||
|
String destPath = importDataCachePath + identifier;
|
||||||
|
|
||||||
if (!FileUtil.exist(new File(destPath))) {
|
if (!FileUtil.exist(new File(destPath))) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
|
|
@ -284,10 +327,12 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
||||||
// TODO 需要验证如果一个分片上传一半网络断开,则该分片的存储情况。
|
// TODO 需要验证如果一个分片上传一半网络断开,则该分片的存储情况。
|
||||||
@Override
|
@Override
|
||||||
public ElectromagneticResult<?> mergeChunks(String identifier, String fileName, Integer totalChunks) {
|
public ElectromagneticResult<?> mergeChunks(String identifier, String fileName, Integer totalChunks) {
|
||||||
|
String dataCachePath = edDataService.getDataCachePath();
|
||||||
|
String importDataCachePath = dataCachePath + importCacheDir;
|
||||||
|
|
||||||
// 检查所有分片是否已经上传完成,分片编号从1开始
|
// 检查所有分片是否已经上传完成,分片编号从1开始
|
||||||
for (int i = 1; i <= totalChunks; i++) {
|
for (int i = 1; i <= totalChunks; i++) {
|
||||||
String tmpPath = uploadFilePath + identifier + File.separator + i + UPLOAD_FILE_CHUNK_SUFFIX;
|
String tmpPath = importDataCachePath + identifier + File.separator + i + UPLOAD_FILE_CHUNK_SUFFIX;
|
||||||
if (!FileUtil.exist(new File(tmpPath))) {
|
if (!FileUtil.exist(new File(tmpPath))) {
|
||||||
log.error("第{}个分片没有上传完成,请上传完成后再合并。", i);
|
log.error("第{}个分片没有上传完成,请上传完成后再合并。", i);
|
||||||
ElectromagneticResultUtil.fail("-1", "文件尚未上传完成。");
|
ElectromagneticResultUtil.fail("-1", "文件尚未上传完成。");
|
||||||
|
|
@ -295,13 +340,13 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 合并分片
|
// 合并分片
|
||||||
String destZipPath = uploadFilePath + identifier + File.separator + fileName;
|
String destZipPath = importDataCachePath + identifier + File.separator + fileName;
|
||||||
File mergedFile = new File(destZipPath);
|
File mergedFile = new File(destZipPath);
|
||||||
try {
|
try {
|
||||||
RandomAccessFile targetFile = new RandomAccessFile(mergedFile, "rw");
|
RandomAccessFile targetFile = new RandomAccessFile(mergedFile, "rw");
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
for (int i = 1; i <= totalChunks; i++) {
|
for (int i = 1; i <= totalChunks; i++) {
|
||||||
String tmpPath = uploadFilePath + identifier + File.separator + i + UPLOAD_FILE_CHUNK_SUFFIX;
|
String tmpPath = importDataCachePath + identifier + File.separator + i + UPLOAD_FILE_CHUNK_SUFFIX;
|
||||||
RandomAccessFile tmp = new RandomAccessFile(new File(tmpPath), "r");
|
RandomAccessFile tmp = new RandomAccessFile(new File(tmpPath), "r");
|
||||||
int len;
|
int len;
|
||||||
while ((len = tmp.read(buffer)) != -1) {
|
while ((len = tmp.read(buffer)) != -1) {
|
||||||
|
|
@ -316,28 +361,48 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
||||||
|
|
||||||
// 删除分片
|
// 删除分片
|
||||||
for (int i = 1; i <= totalChunks; i++) {
|
for (int i = 1; i <= totalChunks; i++) {
|
||||||
String tmpPath = uploadFilePath + identifier + File.separator + i + UPLOAD_FILE_CHUNK_SUFFIX;
|
String tmpPath = importDataCachePath + identifier + File.separator + i + UPLOAD_FILE_CHUNK_SUFFIX;
|
||||||
FileUtil.del(tmpPath);
|
FileUtil.del(tmpPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检验文件的MD5值
|
// 检验文件的MD5值
|
||||||
|
|
||||||
|
// 解密文件
|
||||||
|
String decryptFilePath = destZipPath + "_decrypted";
|
||||||
|
String password = "adknfhkj87654knd";
|
||||||
|
AES aes = SecureUtil.aes(password.getBytes()); // aesKey是加密密钥
|
||||||
|
try(
|
||||||
|
InputStream inputStream = new FileInputStream(destZipPath);
|
||||||
|
OutputStream outputStream = new FileOutputStream(decryptFilePath);
|
||||||
|
) {
|
||||||
|
aes.decrypt(inputStream, outputStream, true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("文件加密错误..", e);
|
||||||
|
}
|
||||||
|
|
||||||
// 解压文件
|
// 解压文件
|
||||||
ZipUtil.unzip(destZipPath, uploadFilePath + identifier + File.separator);
|
String unzipFileOutputPath = importDataCachePath + identifier + File.separator;
|
||||||
|
ZipUtil.unzip(decryptFilePath, unzipFileOutputPath);
|
||||||
|
|
||||||
// 文件信息存入数据库
|
// 文件信息存入数据库
|
||||||
Map<String, List<String>> result = edDataService.importData(destZipPath);
|
Map<String, List<String>> result = edDataService.importData(importDataCachePath + identifier);
|
||||||
|
|
||||||
|
// 删除 解压数据的 缓存目录
|
||||||
|
FileUtil.del(unzipFileOutputPath);
|
||||||
|
|
||||||
return ElectromagneticResultUtil.success(result);
|
return ElectromagneticResultUtil.success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ElectromagneticResult<FileChunkResultDTO> checkChunkExist(FileChunkDTO fileChunkDTO) {
|
public ElectromagneticResult<FileChunkResultDTO> checkChunkExist(FileChunkDTO fileChunkDTO) {
|
||||||
|
String dataCachePath = edDataService.getDataCachePath();
|
||||||
|
String importDataCachePath = dataCachePath + importCacheDir;
|
||||||
|
|
||||||
FileChunkResultDTO res = new FileChunkResultDTO();
|
FileChunkResultDTO res = new FileChunkResultDTO();
|
||||||
// 首先判断zip文件是否存在,如果不存在则表示还没有上传完成。
|
// 首先判断zip文件是否存在,如果不存在则表示还没有上传完成。
|
||||||
String identifier = fileChunkDTO.getIdentifier();
|
String identifier = fileChunkDTO.getIdentifier();
|
||||||
String fileName = fileChunkDTO.getFileName();
|
String fileName = fileChunkDTO.getFileName();
|
||||||
String destZipPath = uploadFilePath + identifier + File.separator + fileName;
|
String destZipPath = importDataCachePath + identifier + File.separator + fileName;
|
||||||
boolean existFile = FileUtil.exist(new File(destZipPath));
|
boolean existFile = FileUtil.exist(new File(destZipPath));
|
||||||
|
|
||||||
if (existFile) {
|
if (existFile) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue