1、数据查询中文件相关的导出接口
This commit is contained in:
4
1-sql/2026-01-09/project/simulation_work.sql
Normal file
4
1-sql/2026-01-09/project/simulation_work.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
ALTER TABLE simulation_work CHANGE planFinishTask shouldProgress varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL COMMENT '应完成任务';
|
||||
ALTER TABLE simulation_work CHANGE actualFinishTask actualProgress varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL COMMENT '实际完成任务';
|
||||
ALTER TABLE simulation_work ADD workName varchar(512) NULL COMMENT '基础信息';
|
||||
ALTER TABLE simulation_work ADD taskId varchar(255) NULL COMMENT '关联的任务id';
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.sdm.common.entity.req.export;
|
||||
|
||||
import com.sdm.common.entity.ExportExcelFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class FileAnalysisExportExcelFormat {
|
||||
|
||||
/**
|
||||
* 导出的基本属性值
|
||||
*/
|
||||
private List<ExportExcelFormat> excelHeaders;
|
||||
|
||||
/**
|
||||
* 导出文件的可选查询参数
|
||||
*/
|
||||
private FileAnalysisExportExcelParam params;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.sdm.common.entity.req.export;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.sdm.common.entity.enums.FileBizTypeEnum;
|
||||
import com.sdm.common.entity.req.data.BaseReq;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class FileAnalysisExportExcelParam extends BaseReq {
|
||||
|
||||
@Schema(description = "文件所属项目节点uuid")
|
||||
private String uuid;
|
||||
|
||||
@Schema(description = "文件类型", implementation = FileBizTypeEnum.class)
|
||||
Integer fileBizType;
|
||||
|
||||
@Schema(description = "文件名")
|
||||
private String fileName;
|
||||
|
||||
@Schema(description = "上传人id")
|
||||
private List<Long> uploadUserId;
|
||||
|
||||
@Schema(description = "开始时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
@Schema(description = "结束时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime endTime;
|
||||
|
||||
@Schema(description = "标签1")
|
||||
private String tag1;
|
||||
|
||||
@Schema(description = "标签2")
|
||||
private String tag2;
|
||||
|
||||
@Schema(description = "标签3")
|
||||
private String tag3;
|
||||
|
||||
@Schema(description = "标签4")
|
||||
private String tag4;
|
||||
|
||||
@Schema(description = "标签5")
|
||||
private String tag5;
|
||||
|
||||
@Schema(description = "标签6")
|
||||
private String tag6;
|
||||
|
||||
@Schema(description = "标签7")
|
||||
private String tag7;
|
||||
|
||||
@Schema(description = "标签8")
|
||||
private String tag8;
|
||||
|
||||
@Schema(description = "标签9")
|
||||
private String tag9;
|
||||
|
||||
@Schema(description = "标签10")
|
||||
private String tag10;
|
||||
|
||||
}
|
||||
@@ -45,14 +45,4 @@ public class PerformanceAnalysisExportExcelParam {
|
||||
@Schema( description = "名称(兼容数据总览使用)")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 导出的基本属性值
|
||||
*/
|
||||
private List<ExportExcelFormat> excelHeaders;
|
||||
|
||||
/**
|
||||
* 导出任务的可选查询参数
|
||||
*/
|
||||
private TaskExportExcelParam params;
|
||||
|
||||
}
|
||||
|
||||
84
data/src/main/java/com/sdm/data/bo/ExportOperate.java
Normal file
84
data/src/main/java/com/sdm/data/bo/ExportOperate.java
Normal file
@@ -0,0 +1,84 @@
|
||||
package com.sdm.data.bo;
|
||||
|
||||
import com.sdm.common.utils.SystemOperate;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ExportOperate {
|
||||
|
||||
@Value("${file.scriptPath}")
|
||||
private String scriptPath;
|
||||
|
||||
private static final String TEMP_EXPORT_PATH = "/opt/export/";
|
||||
|
||||
/**
|
||||
* 将任务文件信息导出为excel格式
|
||||
*/
|
||||
public String convertToFile(String taskAssociationFile, String colunms) {
|
||||
String taskJsonFileName = TEMP_EXPORT_PATH + System.currentTimeMillis() + "taskAssociationFile.json";
|
||||
String columnFileName = TEMP_EXPORT_PATH + System.currentTimeMillis() + "colunms2.json";
|
||||
String exportFileName = "";
|
||||
if (!saveContentsToFile(taskAssociationFile, taskJsonFileName) || !saveContentsToFile(colunms, columnFileName)) {
|
||||
log.error("保存任务文件失败");
|
||||
} else {
|
||||
String shellPath = scriptPath + File.separator + "exportExcel.py";
|
||||
exportFileName = TEMP_EXPORT_PATH + System.currentTimeMillis() + "taskAssociationFile.xlsx";
|
||||
String cmd = "python " + shellPath + " " + taskJsonFileName + " " + exportFileName + " " + columnFileName;
|
||||
try {
|
||||
String resultString = SystemOperate.exeShellCmd(cmd);
|
||||
if (resultString.contains("error")) {
|
||||
log.error("生成任务文件失败");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
File taskFile = new File(taskJsonFileName);
|
||||
if (taskFile.exists()) {
|
||||
// taskFile.delete();
|
||||
}
|
||||
File columnFile = new File(columnFileName);
|
||||
if (columnFile.exists()) {
|
||||
// columnFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
return exportFileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将文本内容保存为文件
|
||||
*
|
||||
* @param contents
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
private boolean saveContentsToFile(String contents, String fileName) {
|
||||
File file = new File(fileName);
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
FileOutputStream outputStream = new FileOutputStream(file);
|
||||
outputStream.write(contents.getBytes(Charset.forName("utf8")));
|
||||
outputStream.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package com.sdm.data.controller;
|
||||
|
||||
import com.sdm.common.common.SdmResponse;
|
||||
import com.sdm.common.entity.req.data.GetSimulationTaskFileReq;
|
||||
import com.sdm.common.entity.req.export.FileAnalysisExportExcelFormat;
|
||||
import com.sdm.common.entity.req.export.TaskAnalysisExportExcelFormat;
|
||||
import com.sdm.common.entity.resp.PageDataResp;
|
||||
import com.sdm.common.entity.resp.data.SimulationTaskResultCurveResp;
|
||||
import com.sdm.common.feign.inter.data.IDataAnalysisFeignClient;
|
||||
@@ -9,6 +11,7 @@ import com.sdm.data.service.IDataAnalysisService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -46,4 +49,11 @@ public class DataAnalysisController implements IDataAnalysisFeignClient {
|
||||
public SdmResponse getCSVData(@Parameter(description = "文件id列表") @RequestParam List<Long> fileId) {
|
||||
return dataAnalysisService.getCSVData(fileId);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/exportTaskFileByScript")
|
||||
@ResponseBody
|
||||
SdmResponse exportTaskFileByScript(HttpServletResponse response , @RequestBody FileAnalysisExportExcelFormat req) {
|
||||
return dataAnalysisService.exportTaskFileByScript(response,req);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.sdm.data.service;
|
||||
|
||||
import com.sdm.common.common.SdmResponse;
|
||||
import com.sdm.common.entity.req.data.GetSimulationTaskFileReq;
|
||||
import com.sdm.common.entity.req.export.FileAnalysisExportExcelFormat;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -16,4 +18,12 @@ public interface IDataAnalysisService {
|
||||
*/
|
||||
SdmResponse getCSVData(List<Long> fileIds);
|
||||
|
||||
/**
|
||||
* 导出任务相关文件(模型文件、仿真报告、计算文件、曲线文件、云图文件)
|
||||
* @param response
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
SdmResponse exportTaskFileByScript(HttpServletResponse response, FileAnalysisExportExcelFormat req);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
package com.sdm.data.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.sdm.common.common.SdmResponse;
|
||||
import com.sdm.common.common.ThreadLocalContext;
|
||||
import com.sdm.common.entity.req.export.FileAnalysisExportExcelFormat;
|
||||
import com.sdm.common.entity.req.export.FileAnalysisExportExcelParam;
|
||||
import com.sdm.common.entity.req.export.TaskAnalysisExportExcelParam;
|
||||
import com.sdm.common.entity.resp.PageDataResp;
|
||||
import com.sdm.common.utils.PageUtils;
|
||||
import com.sdm.common.utils.SystemOperate;
|
||||
import com.sdm.data.bo.ExportOperate;
|
||||
import com.sdm.data.model.entity.FileMetadataInfo;
|
||||
import com.sdm.data.model.entity.FileStorage;
|
||||
import com.sdm.common.entity.req.data.GetSimulationTaskFileReq;
|
||||
@@ -15,6 +21,7 @@ import com.sdm.data.service.DataStorageAnalysis;
|
||||
import com.sdm.data.service.IDataAnalysisService;
|
||||
import com.sdm.data.service.IFileMetadataInfoService;
|
||||
import com.sdm.data.service.IMinioService;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
@@ -24,6 +31,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
@@ -44,6 +52,9 @@ public class DataAnalysisServiceImpl implements IDataAnalysisService {
|
||||
@Autowired
|
||||
private FileMetadataHierarchyHelper hierarchyHelper;
|
||||
|
||||
@Autowired
|
||||
private ExportOperate exportOperate;
|
||||
|
||||
@Override
|
||||
public SdmResponse<PageDataResp<List<SimulationTaskResultCurveResp>>> getSimulationTaskFile(GetSimulationTaskFileReq getSimulationTaskFileReq) {
|
||||
// 1. 构造查询条件
|
||||
@@ -139,4 +150,51 @@ public class DataAnalysisServiceImpl implements IDataAnalysisService {
|
||||
return SdmResponse.failed("获取CSV数据失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SdmResponse exportTaskFileByScript(HttpServletResponse httpServletResponse, FileAnalysisExportExcelFormat req) {
|
||||
GetSimulationTaskFileReq taskFileReq = new GetSimulationTaskFileReq();
|
||||
FileAnalysisExportExcelParam params = req.getParams();
|
||||
BeanUtils.copyProperties(params, taskFileReq);
|
||||
taskFileReq.setCurrent(1);
|
||||
taskFileReq.setSize(10000);
|
||||
SdmResponse response = getSimulationTaskFile(taskFileReq);
|
||||
if (ObjectUtils.isEmpty(response)) {
|
||||
log.error("exportTaskFileByScript,未查询到数据");
|
||||
return SdmResponse.success(new ArrayList<>());
|
||||
} else {
|
||||
String taskAssociationFile = exportOperate.convertToFile(JSON.toJSONString(response), JSON.toJSONString(req));
|
||||
File file = new File(taskAssociationFile);
|
||||
if(!file.exists()) {
|
||||
response = SdmResponse.failed("任务文件不存在");
|
||||
}else {
|
||||
String taskAssociationFileSavePrefixName;
|
||||
switch (params.getFileBizType()) {
|
||||
case 1:
|
||||
taskAssociationFileSavePrefixName = "模型文件";
|
||||
break;
|
||||
case 2:
|
||||
taskAssociationFileSavePrefixName = "仿真报告";
|
||||
break;
|
||||
case 3:
|
||||
taskAssociationFileSavePrefixName = "计算文件";
|
||||
break;
|
||||
case 4:
|
||||
taskAssociationFileSavePrefixName = "曲线文件";
|
||||
break;
|
||||
case 5:
|
||||
taskAssociationFileSavePrefixName = "云图文件";
|
||||
break;
|
||||
default:
|
||||
taskAssociationFileSavePrefixName = "未知文件";
|
||||
break;
|
||||
}
|
||||
String taskAssociationFileSaveName = taskAssociationFileSavePrefixName + ".xlsx";
|
||||
SystemOperate.outputHttpFileStream(httpServletResponse, taskAssociationFile, taskAssociationFileSaveName);
|
||||
// file.delete();
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -95,6 +95,7 @@ lombok:
|
||||
file:
|
||||
rootPath: /data/home/sdm
|
||||
privatePath: /data/home
|
||||
scriptPath : /opt/script
|
||||
|
||||
#logging:
|
||||
# config: ./config/logback.xml
|
||||
|
||||
@@ -95,6 +95,7 @@ lombok:
|
||||
file:
|
||||
rootPath: /data/home/sdm
|
||||
privatePath: /data/home
|
||||
scriptPath : /opt/script
|
||||
|
||||
#logging:
|
||||
# config: ./config/logback.xml
|
||||
|
||||
@@ -77,6 +77,7 @@ lombok:
|
||||
file:
|
||||
rootPath: /data/home/sdm
|
||||
privatePath: /data/home
|
||||
scriptPath : /opt/script
|
||||
|
||||
#logging:
|
||||
# config: ./config/logback.xml
|
||||
|
||||
@@ -95,6 +95,7 @@ lombok:
|
||||
file:
|
||||
rootPath: /data/home/sdm
|
||||
privatePath: /data/home
|
||||
scriptPath : /opt/script
|
||||
|
||||
#logging:
|
||||
# config: ./config/logback.xml
|
||||
|
||||
@@ -95,6 +95,7 @@ lombok:
|
||||
file:
|
||||
rootPath: /data/home/sdm
|
||||
privatePath: /data/home
|
||||
scriptPath : /opt/script
|
||||
|
||||
#logging:
|
||||
# config: ./config/logback.xml
|
||||
|
||||
@@ -96,6 +96,7 @@ lombok:
|
||||
file:
|
||||
rootPath: /SPDM/server
|
||||
viewDataPath: /SPDM/simright/viewdata
|
||||
scriptPath : /opt/script
|
||||
|
||||
hpc:
|
||||
url: http://172.27.3.135/JSONAPI/JSONAPI.ashx
|
||||
|
||||
@@ -95,6 +95,7 @@ lombok:
|
||||
file:
|
||||
rootPath: /data/home/sdm
|
||||
privatePath: /data/home
|
||||
scriptPath : /opt/script
|
||||
|
||||
#logging:
|
||||
# config: ./config/logback.xml
|
||||
|
||||
Reference in New Issue
Block a user