Merge branch 'main' of http://192.168.65.198:3000/toolchaintechnologycenter/spdm-backend
This commit is contained in:
@@ -33,4 +33,13 @@ public class SpdmReportReq {
|
||||
*/
|
||||
private String flowPath;
|
||||
|
||||
/**
|
||||
* 算例id
|
||||
*/
|
||||
private String runId;
|
||||
/**
|
||||
* 前端传的参数
|
||||
*/
|
||||
private String reportContent;
|
||||
|
||||
}
|
||||
@@ -418,14 +418,6 @@ public class DataFileController implements IDataFeignClient {
|
||||
return IDataFileService.getMinioDownloadUrl(fileId);
|
||||
}
|
||||
|
||||
@GetMapping("/getMinioPresignedUrlTest")
|
||||
@Operation(summary = "获取MinIO文件下载的预签名URL", description = "获取MinIO文件的预签名URL")
|
||||
public SdmResponse<MinioDownloadUrlResp> getMinioPresignedUrlTest(@Parameter(description = "文件id") @RequestParam("fileId") Long fileId) {
|
||||
MinioDownloadUrlResp minioDownloadUrlResp = new MinioDownloadUrlResp();
|
||||
minioDownloadUrlResp.setMinioDownloadUrl("https://minio.sdm.com/sdm/file/download/fileId");
|
||||
return SdmResponse.success(minioDownloadUrlResp);
|
||||
}
|
||||
|
||||
@GetMapping("/queryFileMetadataInfo")
|
||||
@Operation(summary = "根据节点uuid获取节点文件夹信息", description = "获取节点文件夹信息")
|
||||
public SdmResponse<FileMetadataInfoResp> queryFileMetadataInfo(@RequestParam(value = "uuid") String uuid, @RequestParam(value = "uuidOwnType") String uuidOwnType, @RequestParam(value = "dirId") Long dirId) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||
import com.sdm.common.common.SdmResponse;
|
||||
import com.sdm.common.common.ThreadLocalContext;
|
||||
import com.sdm.common.entity.req.project.GetAllTasksByDisciplineReq;
|
||||
import com.sdm.common.entity.resp.PageDataResp;
|
||||
import com.sdm.common.feign.inter.project.ISimulationTaskFeignClient;
|
||||
@@ -66,7 +67,7 @@ public class DataStorageAnalysisController {
|
||||
|
||||
// 如果未指定节点名称,获取默认的top10
|
||||
if (CollectionUtils.isEmpty(queryNodeNames)) {
|
||||
queryNodeNames = fileStorageService.getdefaultNodeSizeUUID(queryNodeType, 10);
|
||||
queryNodeNames = fileStorageService.getdefaultNodeSizeUUID(queryNodeType, 10, ThreadLocalContext.getTenantId());
|
||||
}
|
||||
|
||||
// 直接调用批量查询接口
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.List;
|
||||
* @since 2025-11-04
|
||||
*/
|
||||
public interface FileStorageMapper extends BaseMapper<FileStorage> {
|
||||
List<String> getdefaultNodeNameByNodeSize(@Param("queryNodeType") String queryNodeType, @Param("limitNum") Integer limitNum);
|
||||
List<String> getdefaultNodeNameByNodeSize(@Param("queryNodeType") String queryNodeType, @Param("limitNum") Integer limitNum,@Param("tenantId") Long tenantId);
|
||||
|
||||
List<NodeSizeDTO> selectNodeSizeByNodeType(@Param("directoryIds") List<Long> directoryIds, @Param("intervalMonths") Integer intervalMonths, @Param("tenantId") Long tenantId);
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.List;
|
||||
* @since 2025-11-04
|
||||
*/
|
||||
public interface IFileStorageService extends IService<FileStorage> {
|
||||
List<String> getdefaultNodeSizeUUID(String queryNodeType, Integer limitNum);
|
||||
List<String> getdefaultNodeSizeUUID(String queryNodeType, Integer limitNum,Long tenantId);
|
||||
List<NodeSizeDTO> selectNodeSizeByNodeType(List<Long> directoryIds, Integer intervalMonths, Long tenantId);
|
||||
|
||||
List<NodeSizeDTO> statDirStorageByTargetYm(List<Long> dirIds, String targetYm, Long tenantId);
|
||||
|
||||
@@ -22,8 +22,8 @@ import java.util.List;
|
||||
@Service
|
||||
public class FileStorageServiceImpl extends ServiceImpl<FileStorageMapper, FileStorage> implements IFileStorageService {
|
||||
@Override
|
||||
public List<String> getdefaultNodeSizeUUID(String queryNodeType, Integer limitNum) {
|
||||
return baseMapper.getdefaultNodeNameByNodeSize(queryNodeType,limitNum);
|
||||
public List<String> getdefaultNodeSizeUUID(String queryNodeType, Integer limitNum,Long tenantId) {
|
||||
return baseMapper.getdefaultNodeNameByNodeSize(queryNodeType,limitNum,tenantId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,11 +18,12 @@
|
||||
file_storage fs
|
||||
where
|
||||
fs.dirId
|
||||
in(select id from file_metadata_info fmi where fmi.relatedResourceUuidOwnType = #{queryNodeType})
|
||||
in(select id from file_metadata_info fmi where fmi.relatedResourceUuidOwnType = #{queryNodeType} and fmi.tenantId = #{tenantId} )
|
||||
group by
|
||||
fs.dirId) dirSize
|
||||
left join file_metadata_info ON
|
||||
dirSize.dirId = file_metadata_info.id
|
||||
where file_metadata_info.tenantId = #{tenantId}
|
||||
group by
|
||||
file_metadata_info.originalName
|
||||
order by
|
||||
|
||||
@@ -128,7 +128,7 @@ public class PostgreSQLCompatibilityTest {
|
||||
void testLimitQuery() {
|
||||
List<String> result = fileStorageMapper.getdefaultNodeNameByNodeSize(
|
||||
"node",
|
||||
5 // LIMIT 5
|
||||
5 ,1L // LIMIT 5
|
||||
);
|
||||
|
||||
assertNotNull(result);
|
||||
|
||||
@@ -1340,6 +1340,121 @@ public class SimulationRunServiceImpl extends ServiceImpl<SimulationRunMapper, S
|
||||
deleteFolder(new File(TEMP_REPORT_PATH + randomId));
|
||||
}
|
||||
|
||||
public void generateReport2(SpdmReportReq req, HttpServletResponse response) {
|
||||
log.info("生成自动化报告参数为:{}", req);
|
||||
String randomId = RandomUtil.generateString(16);
|
||||
Path folder = Paths.get(TEMP_REPORT_PATH + randomId);
|
||||
if (!Files.exists(folder) || !Files.isDirectory(folder)) {
|
||||
if (!new File(TEMP_REPORT_PATH + randomId).mkdir()) {
|
||||
log.error("创建临时文件夹:{}失败",TEMP_REPORT_PATH + randomId);
|
||||
throw new RuntimeException("生成报告失败,原因为:创建临时文件夹失败");
|
||||
}
|
||||
}
|
||||
log.info("临时路径为:{}", randomId);
|
||||
|
||||
String reportContent = req.getReportContent();
|
||||
// 前端参数写入临时目录
|
||||
FileOutputStream projectInfoOutputStream = null;
|
||||
try {
|
||||
projectInfoOutputStream = new FileOutputStream(TEMP_REPORT_PATH + randomId + File.separator + "reportContent.json");
|
||||
projectInfoOutputStream.write(reportContent.getBytes(StandardCharsets.UTF_8));
|
||||
projectInfoOutputStream.flush();
|
||||
projectInfoOutputStream.close();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
String commands = "python /opt/script/exportWord.py " + TEMP_REPORT_PATH + randomId + File.separator + TEMPLATE_PATH + "Analyse";
|
||||
|
||||
// 调用脚本
|
||||
log.info("调用脚本中。。。。。。");
|
||||
log.info("command:" + commands);
|
||||
List<String> result = new ArrayList<>();
|
||||
int runningStatus = -1;
|
||||
try {
|
||||
log.info("开始同步执行脚本");
|
||||
Process process = Runtime.getRuntime().exec(commands);
|
||||
log.info("准备获取脚本输出");
|
||||
log.info("开始获取脚本输出");
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
log.info("executePython:" + line);
|
||||
result.add(line);
|
||||
}
|
||||
log.info("脚本执行完成");
|
||||
runningStatus = process.waitFor();
|
||||
log.info("脚本运行状态:" + runningStatus);
|
||||
} catch (IOException | InterruptedException e) {
|
||||
log.error("执行脚本失败:" + e);
|
||||
return;
|
||||
}
|
||||
if (runningStatus != 0) {
|
||||
log.error("执行脚本失败");
|
||||
return;
|
||||
} else {
|
||||
log.info(commands + "执行脚本完成!");
|
||||
}
|
||||
byte[] fileData = null;
|
||||
if (response != null) {
|
||||
try {
|
||||
// 获取临时路径中脚本生成的报告
|
||||
String reportName = "report.docx";
|
||||
FileInputStream fileInputStream = new FileInputStream(TEMP_REPORT_PATH + randomId + File.separator + "report" + File.separator + "report.docx");
|
||||
fileData = fileInputStream.readAllBytes();
|
||||
|
||||
// 上传到算例下的报告文件夹下
|
||||
KeyResultReq resultReq = new KeyResultReq();
|
||||
resultReq.setKeyResultType(KeyResultTypeEnum.DOCUMENT.getKeyResultType());
|
||||
resultReq.setRunId(req.getRunId());
|
||||
resultReq.setName(reportName);
|
||||
// 创建临时MultipartFile
|
||||
MockMultipartFile multipartFile = new MockMultipartFile(
|
||||
reportName,
|
||||
reportName,
|
||||
"application/json",
|
||||
fileData);
|
||||
resultReq.setFile(multipartFile);
|
||||
resultReq.setFileName(reportName);
|
||||
resultReq.setFileType(FileBizTypeEnum.REPORT_FILE.getValue());
|
||||
SdmResponse sdmResponse = addSimulationKeyResult(resultReq);
|
||||
if (!sdmResponse.isSuccess()) {
|
||||
throw new RuntimeException("生成自动化报告上传报告结果目录失败");
|
||||
}
|
||||
|
||||
// 设置响应头
|
||||
response.reset();
|
||||
response.setContentType("application/octet-stream;charset=UTF-8");
|
||||
response.addHeader("Content-Length", String.valueOf(fileData.length));
|
||||
// 写入响应流
|
||||
OutputStream outputStream = response.getOutputStream();
|
||||
outputStream.write(fileData);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
fileInputStream.close();
|
||||
} catch (Exception ex) {
|
||||
log.error("生成自动化报告失败:{}", ex.getMessage());
|
||||
throw new RuntimeException("生成自动化报告失败");
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(req.getFlowPath()) && fileData != null) {
|
||||
// 将生成的报告上传到flowPath路径下
|
||||
// 写入响应流
|
||||
FileOutputStream outputStream = null;
|
||||
try {
|
||||
outputStream = new FileOutputStream(req.getFlowPath());
|
||||
outputStream.write(fileData);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
// 删除临时路径
|
||||
log.info("删除临时路径:{},中。。。。。。", randomId);
|
||||
deleteFolder(new File(TEMP_REPORT_PATH + randomId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void editReport(EditReportReq req, HttpServletResponse response) {
|
||||
log.info("编辑报告参数为:{}", req);
|
||||
@@ -1426,6 +1541,9 @@ public class SimulationRunServiceImpl extends ServiceImpl<SimulationRunMapper, S
|
||||
String reportName = "report_" +
|
||||
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) +
|
||||
".docx";
|
||||
FileInputStream fileInputStream = new FileInputStream(TEMP_REPORT_PATH + randomId + File.separator + reportName);
|
||||
fileData = fileInputStream.readAllBytes();
|
||||
|
||||
// 上传到算例下的报告文件夹下
|
||||
KeyResultReq resultReq = new KeyResultReq();
|
||||
resultReq.setKeyResultType(KeyResultTypeEnum.DOCUMENT.getKeyResultType());
|
||||
@@ -1446,8 +1564,6 @@ public class SimulationRunServiceImpl extends ServiceImpl<SimulationRunMapper, S
|
||||
}
|
||||
|
||||
// 下载到本地
|
||||
FileInputStream fileInputStream = new FileInputStream(TEMP_REPORT_PATH + randomId + File.separator + reportName);
|
||||
fileData = fileInputStream.readAllBytes();
|
||||
// 设置响应头
|
||||
response.reset();
|
||||
response.setContentType("application/octet-stream;charset=UTF-8");
|
||||
|
||||
Reference in New Issue
Block a user