生成报告脚本

This commit is contained in:
2025-12-09 20:31:20 +08:00
parent 5dfe3e58a5
commit dda4e046e5
15 changed files with 259 additions and 100 deletions

View File

@@ -1,6 +1,5 @@
package com.sdm.project.model.req; package com.sdm.common.entity.req.project;
import jakarta.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;

View File

@@ -1,4 +1,4 @@
package com.sdm.project.model.entity; package com.sdm.common.entity.req.project;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;

View File

@@ -1,16 +1,10 @@
package com.sdm.project.model.req; package com.sdm.common.entity.req.project;
import com.sdm.project.model.bo.TaskNode;
import com.sdm.project.model.entity.SimulationPerformance;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
/**
* @Author xuyundi
* @Date 2024/3/5
* @Note
*/
@Data @Data
public class SpdmReportReq { public class SpdmReportReq {
@@ -28,5 +22,10 @@ public class SpdmReportReq {
* 算例父节点信息 * 算例父节点信息
*/ */
private ProjecInfoReq projecInfoReq; private ProjecInfoReq projecInfoReq;
/**
* 报告复制路径地址
*/
private String outPutDirPath;
} }

View File

@@ -1,6 +1,7 @@
package com.sdm.common.feign.impl.project; package com.sdm.common.feign.impl.project;
import com.sdm.common.common.SdmResponse; import com.sdm.common.common.SdmResponse;
import com.sdm.common.entity.req.project.SpdmReportReq;
import com.sdm.common.entity.req.system.LaunchApproveReq; import com.sdm.common.entity.req.system.LaunchApproveReq;
import com.sdm.common.entity.resp.AllNodeByProjectIdAndTypeResp; import com.sdm.common.entity.resp.AllNodeByProjectIdAndTypeResp;
import com.sdm.common.feign.inter.project.ISimulationRunFeignClient; import com.sdm.common.feign.inter.project.ISimulationRunFeignClient;
@@ -39,4 +40,15 @@ public class SimulationRunFeignClientImpl implements ISimulationRunFeignClient {
} }
return response; return response;
} }
@Override
public SdmResponse<Void> generateReportInternal(SpdmReportReq req) {
try {
simulationRunFeignClient.generateReportInternal(req);
return SdmResponse.success();
}catch (Exception e){
log.error("内部调用生成自动化报告失败", e);
return SdmResponse.failed("内部调用生成自动化报告失败");
}
}
} }

View File

@@ -1,16 +1,13 @@
package com.sdm.common.feign.inter.project; package com.sdm.common.feign.inter.project;
import com.sdm.common.common.SdmResponse; import com.sdm.common.common.SdmResponse;
import com.sdm.common.entity.req.project.SpdmReportReq;
import com.sdm.common.entity.req.system.LaunchApproveReq; import com.sdm.common.entity.req.system.LaunchApproveReq;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
@FeignClient(name = "project",contextId = "runFeignClient") @FeignClient(name = "project",contextId = "runFeignClient")
public interface ISimulationRunFeignClient { public interface ISimulationRunFeignClient {
@@ -19,5 +16,14 @@ public interface ISimulationRunFeignClient {
@GetMapping(value = "/run/getSimulationKeyResultFileIds") @GetMapping(value = "/run/getSimulationKeyResultFileIds")
SdmResponse<List<Long>> getSimulationKeyResultFileIds(@RequestParam String runId); SdmResponse<List<Long>> getSimulationKeyResultFileIds(@RequestParam String runId);
/**
* 内部调用生成报告
*
* @param req 报告请求参数
* @return SdmResponse<Void>
*/
@PostMapping("/run/generateReportInternal")
SdmResponse<Void> generateReportInternal(@RequestBody SpdmReportReq req);
} }

View File

@@ -261,7 +261,8 @@ public class ModelServiceImpl implements IModelService {
} }
if (trainingModel.getHandleStatus().equals("失败")) { if (trainingModel.getHandleStatus().equals("失败")) {
String errLog = parseStringFromStream(dataFileService.getMinioInputStream(trainingModel.getTrainingDataHandleErrorLogFileId())); String errLog = parseStringFromStream(dataFileService.getMinioInputStream(trainingModel.getTrainingDataHandleErrorLogFileId()));
return SdmResponse.failed("数据处理失败: errLog: " + errLog); log.error("数据处理失败: errLog: {}", errLog);
return SdmResponse.failed("数据处理失败");
} }
Long trainingDataHandleFileId = trainingModel.getTrainingDataHandleFileId(); Long trainingDataHandleFileId = trainingModel.getTrainingDataHandleFileId();
if (trainingDataHandleFileId == null) { if (trainingDataHandleFileId == null) {
@@ -280,7 +281,7 @@ public class ModelServiceImpl implements IModelService {
return SdmResponse.success(jsonObject); return SdmResponse.success(jsonObject);
} catch (Exception e) { } catch (Exception e) {
log.error("处理JSON文件失败", e); log.error("处理JSON文件失败", e);
return SdmResponse.failed("处理JSON文件失败: " + e.getMessage()); return SdmResponse.failed("处理JSON文件失败");
} finally { } finally {
try { try {
if (minioInputStream != null) { if (minioInputStream != null) {

View File

@@ -5,14 +5,20 @@ import com.sdm.common.common.SdmResponse;
import com.sdm.common.entity.flowable.executeConfig.ExportWordScriptExecuteConfig; import com.sdm.common.entity.flowable.executeConfig.ExportWordScriptExecuteConfig;
import com.sdm.common.entity.req.data.GetFileBaseInfoReq; import com.sdm.common.entity.req.data.GetFileBaseInfoReq;
import com.sdm.common.entity.req.data.UploadFilesReq; import com.sdm.common.entity.req.data.UploadFilesReq;
import com.sdm.common.entity.req.project.ProjecInfoReq;
import com.sdm.common.entity.req.project.SimulationPerformance;
import com.sdm.common.entity.req.project.SpdmReportReq;
import com.sdm.common.entity.resp.data.FileMetadataInfoResp; import com.sdm.common.entity.resp.data.FileMetadataInfoResp;
import com.sdm.common.entity.resp.task.PerformanceResp;
import com.sdm.common.feign.inter.data.IDataFeignClient; import com.sdm.common.feign.inter.data.IDataFeignClient;
import com.sdm.common.feign.inter.project.ISimulationRunFeignClient;
import com.sdm.common.feign.inter.task.ISimuluationPerformanceFeignClient;
import com.sdm.flowable.constants.FlowableConfig; import com.sdm.flowable.constants.FlowableConfig;
import com.sdm.flowable.entity.ProcessNodeParam; import com.sdm.flowable.entity.ProcessNodeParam;
import com.sdm.flowable.service.IProcessNodeParamService; import com.sdm.flowable.service.IProcessNodeParamService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@@ -39,6 +45,12 @@ public class ExportWordScriptHandler implements ExecutionHandler<Map<String, Obj
@Autowired @Autowired
private IProcessNodeParamService processNodeParamService; private IProcessNodeParamService processNodeParamService;
@Autowired
private ISimuluationPerformanceFeignClient simuluationPerformanceFeignClient;
@Autowired
private ISimulationRunFeignClient simulationRunFeignClient;
@Override @Override
public void execute(DelegateExecution execution, Map<String, Object> params, ExportWordScriptExecuteConfig config) { public void execute(DelegateExecution execution, Map<String, Object> params, ExportWordScriptExecuteConfig config) {
try { try {
@@ -50,15 +62,32 @@ public class ExportWordScriptHandler implements ExecutionHandler<Map<String, Obj
// 获取当前流程实例参数 // 获取当前流程实例参数
String runId = (String) execution.getVariable("runId"); String runId = (String) execution.getVariable("runId");
String processDefinitionId = execution.getProcessDefinitionId(); String processDefinitionId = execution.getProcessDefinitionId();
log.info("ExportWordScriptHandler 开始执行 runId:{},processDefinitionId:{}, beforeNodeId:{}, currentNodeId:{},fileRegularStr:{}", runId,processDefinitionId, beforeNodeId, currentNodeId,fileRegularStr); log.info("ExportWordScriptHandler 开始执行 runId:{},processDefinitionId:{}, beforeNodeId:{}, currentNodeId:{},fileRegularStr:{}", runId,processDefinitionId, beforeNodeId, currentNodeId,fileRegularStr);
// 获取前置节点的输出文件夹信息 ProjecInfoReq projecInfoReq = buildprojectInfoReq(params);
ProcessNodeParam beforeProcessNodeParam = processNodeParamService.lambdaQuery() log.info("ExportWordScriptHandler的请求参数 projectInfoReq:{}", projecInfoReq);
.eq(ProcessNodeParam::getRunId, runId)
.eq(ProcessNodeParam::getNodeId, beforeNodeId)
.eq(ProcessNodeParam::getProcessDefinitionId, processDefinitionId) SdmResponse<List<PerformanceResp>> runPerformance = simuluationPerformanceFeignClient.getRunPerformance(runId);
.one(); if(!runPerformance.isSuccess()){
log.error("获取算列性能指标失败");
throw new RuntimeException("获取算列性能指标失败");
}
List<SimulationPerformance> performanceList = new ArrayList<>();
for (PerformanceResp datum : runPerformance.getData()) {
SimulationPerformance performance = new SimulationPerformance();
BeanUtils.copyProperties(datum, performance);
performanceList.add(performance);
}
log.info("ExportWordScriptHandler的返回参数 runPerformance:{}", runPerformance);
SdmResponse<List<Long>> simulationKeyResultFileIds = simulationRunFeignClient.getSimulationKeyResultFileIds(runId);
if(!simulationKeyResultFileIds.isSuccess()){
log.error("获取算列关键结果文件失败");
throw new RuntimeException("获取算列关键结果文件失败");
}
log.info("ExportWordScriptHandler的返回参数 simulationKeyResultFileIds:{}", simulationKeyResultFileIds);
ProcessNodeParam currentProcessNodeParam = processNodeParamService.lambdaQuery() ProcessNodeParam currentProcessNodeParam = processNodeParamService.lambdaQuery()
.eq(ProcessNodeParam::getRunId, runId) .eq(ProcessNodeParam::getRunId, runId)
@@ -66,18 +95,6 @@ public class ExportWordScriptHandler implements ExecutionHandler<Map<String, Obj
.eq(ProcessNodeParam::getProcessDefinitionId, processDefinitionId) .eq(ProcessNodeParam::getProcessDefinitionId, processDefinitionId)
.one(); .one();
if (beforeProcessNodeParam == null || currentProcessNodeParam == null) {
log.error(" 获取节点参数失败runId:{}, beforeNodeId:{}, currentNodeId:{}", runId, beforeNodeId, currentNodeId);
throw new RuntimeException("获取节点参数失败");
}
// 获取前置节点输出文件夹信息
String beforeNodeParamJson = beforeProcessNodeParam.getParamJson();
JSONObject beforeParamJsonObject = JSONObject.parseObject(beforeNodeParamJson);
Long beforeNodeOutputDirId = beforeParamJsonObject.getLong("outputDirId");
FileMetadataInfoResp beforeNodeFileMetadataInfoResp = getFileBaseInfo(beforeNodeOutputDirId);
String beforeNodeObjectKey = beforeNodeFileMetadataInfoResp.getObjectKey();
log.info("前置节点配置参数:{}", beforeNodeParamJson);
// 获取当前节点输出文件夹信息 // 获取当前节点输出文件夹信息
String currentNodeParamJson = currentProcessNodeParam.getParamJson(); String currentNodeParamJson = currentProcessNodeParam.getParamJson();
@@ -86,56 +103,25 @@ public class ExportWordScriptHandler implements ExecutionHandler<Map<String, Obj
FileMetadataInfoResp currentNodeFileMetadataInfoResp = getFileBaseInfo(currentNodeOutputDirId); FileMetadataInfoResp currentNodeFileMetadataInfoResp = getFileBaseInfo(currentNodeOutputDirId);
String currentNodeObjectKey = currentNodeFileMetadataInfoResp.getObjectKey(); String currentNodeObjectKey = currentNodeFileMetadataInfoResp.getObjectKey();
log.info("当前节点配置参数:{}", currentNodeParamJson); log.info("当前节点配置参数:{}", currentNodeParamJson);
String currentNodeOutputDirPath = FlowableConfig.FLOWABLE_SIMULATION_BASEDIR + currentNodeObjectKey;
log.info("当前节点输出文件夹:{}", currentNodeOutputDirPath);
// 前置节点输出文件夹的所有文件通过正则过滤后直接复制到当前脚本节点的输出文件夹,并使用正则表达式过滤文件 // todo 生成脚本的接口
String sourcePath = FlowableConfig.FLOWABLE_SIMULATION_BASEDIR + beforeNodeObjectKey; SpdmReportReq req = new SpdmReportReq();
String targetPath = FlowableConfig.FLOWABLE_SIMULATION_BASEDIR + currentNodeObjectKey; req.setProjecInfoReq(projecInfoReq);
copyFilesWithRegex(sourcePath, targetPath, fileRegularStr); req.setOutPutDirPath(currentNodeOutputDirPath);
req.setImageFileIdList(simulationKeyResultFileIds.getData());
// 下载处理脚本文件到本地 req.setPerformanceList(performanceList);
Long exportScriptFileId = config.getExportScriptFileId(); SdmResponse<Void> voidSdmResponse = simulationRunFeignClient.generateReportInternal(req);
if (ObjectUtils.isEmpty(exportScriptFileId)) { if(!voidSdmResponse.isSuccess()){
log.error("未设置导出报告脚本文件"); log.error("生成自动化报告失败");
throw new RuntimeException("未设置导出报告脚本文件"); throw new RuntimeException("生成自动化报告失败");
}
dataFeignClient.downloadFileToLocal(exportScriptFileId, targetPath);
FileMetadataInfoResp scriptFileBaseInfo = getFileBaseInfo(exportScriptFileId);
String scriptPath = targetPath + scriptFileBaseInfo.getOriginalName();
log.info("脚本文件路径:{}", scriptPath);
// 调用脚本
log.info("调用脚本中。。。。。。");
String commands = "python" + " " + scriptPath + " " + targetPath;
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 + "执行脚本完成!");
} }
try { try {
String reportPath = currentNodeOutputDirPath + "report.docx";
log.info("报告路径:{}", reportPath);
// 获取临时路径中脚本生成的报告 // 获取临时路径中脚本生成的报告
uploadResultFileToMinio(targetPath + "report.docx",currentNodeOutputDirId); uploadResultFileToMinio(currentNodeOutputDirPath + "report.docx",currentNodeOutputDirId);
} catch (Exception ex) { } catch (Exception ex) {
log.error("生成自动化报告失败:{}", ex.getMessage(), ex); log.error("生成自动化报告失败:{}", ex.getMessage(), ex);
throw new RuntimeException("生成自动化报告失败"); throw new RuntimeException("生成自动化报告失败");
@@ -147,6 +133,26 @@ public class ExportWordScriptHandler implements ExecutionHandler<Map<String, Obj
} }
} }
private static ProjecInfoReq buildprojectInfoReq(Map<String, Object> params) {
ProjecInfoReq projectInfoReq = new ProjecInfoReq();
projectInfoReq.setDepartment((String)params.get("department"));
projectInfoReq.setApplicants((String)params.get("applicants"));
projectInfoReq.setDate((String)params.get("date"));
projectInfoReq.setProjectNum((String)params.get("projectNum"));
projectInfoReq.setWorkspaceNum((String)params.get("workspaceNum"));
projectInfoReq.setWorkspace((String)params.get("workspace"));
projectInfoReq.setTaskType((String)params.get("taskType"));
projectInfoReq.setReportVer((String)params.get("reportVer"));
projectInfoReq.setFileNum((String)params.get("fileNum"));
projectInfoReq.setFormulateTime((String)params.get("formulateTime"));
projectInfoReq.setCheckTime((String)params.get("checkTime"));
projectInfoReq.setApproveTime((String)params.get("approveTime"));
projectInfoReq.setIsBatch(Boolean.parseBoolean((String) params.get("isBatch")));
projectInfoReq.setLoadcaseName((String)params.get("loadcaseName"));
projectInfoReq.setReportCommand((String)params.get("reportCommand"));
return projectInfoReq;
}
private FileMetadataInfoResp getFileBaseInfo(Long outputDirId) { private FileMetadataInfoResp getFileBaseInfo(Long outputDirId) {
GetFileBaseInfoReq getFileBaseInfoReq = new GetFileBaseInfoReq(); GetFileBaseInfoReq getFileBaseInfoReq = new GetFileBaseInfoReq();
getFileBaseInfoReq.setFileId(outputDirId); getFileBaseInfoReq.setFileId(outputDirId);

View File

@@ -1,11 +1,10 @@
package com.sdm.project.controller; package com.sdm.project.controller;
import com.sdm.common.common.SdmResponse; import com.sdm.common.common.SdmResponse;
import com.sdm.common.entity.req.capability.FlowNodeDto;
import com.sdm.common.entity.req.data.CreateDirReq; import com.sdm.common.entity.req.data.CreateDirReq;
import com.sdm.common.entity.req.data.KnowledgeCallBackReq;
import com.sdm.common.entity.req.data.QueryDirReq; import com.sdm.common.entity.req.data.QueryDirReq;
import com.sdm.common.entity.req.data.UploadFilesReq; import com.sdm.common.entity.req.data.UploadFilesReq;
import com.sdm.common.entity.req.project.SpdmReportReq;
import com.sdm.common.entity.req.system.LaunchApproveReq; import com.sdm.common.entity.req.system.LaunchApproveReq;
import com.sdm.common.entity.resp.PageDataResp; import com.sdm.common.entity.resp.PageDataResp;
import com.sdm.common.entity.resp.data.BatchAddFileInfoResp; import com.sdm.common.entity.resp.data.BatchAddFileInfoResp;
@@ -15,7 +14,6 @@ import com.sdm.common.log.annotation.SysLog;
import com.sdm.project.model.entity.SimulationRun; import com.sdm.project.model.entity.SimulationRun;
import com.sdm.project.model.entity.SimulationRunKeyResult; import com.sdm.project.model.entity.SimulationRunKeyResult;
import com.sdm.project.model.req.*; import com.sdm.project.model.req.*;
import com.sdm.project.model.req.*;
import com.sdm.project.model.resp.FlowInfoDto; import com.sdm.project.model.resp.FlowInfoDto;
import com.sdm.project.model.resp.KeyResultAndTaskInfoResp; import com.sdm.project.model.resp.KeyResultAndTaskInfoResp;
import com.sdm.project.model.resp.RunVersionInfoResp; import com.sdm.project.model.resp.RunVersionInfoResp;
@@ -211,6 +209,17 @@ public class SimulationRunController implements ISimulationRunFeignClient {
public void generateReport(@RequestBody SpdmReportReq req, HttpServletResponse response) { public void generateReport(@RequestBody SpdmReportReq req, HttpServletResponse response) {
runService.generateReport(req,response); runService.generateReport(req,response);
} }
/**
* 内部调用生成报告
*
* @return
*/
@PostMapping("/generateReportInternal")
@Operation(summary = "内部调用生成报告", description = "内部调用生成报告")
public SdmResponse<Void> generateReportInternal(@RequestBody SpdmReportReq req) {
return runService.generateReportInternal(req);
}
/** /**
* 任务执行 一键执行 启动流程 * 任务执行 一键执行 启动流程
@@ -237,4 +246,4 @@ public class SimulationRunController implements ISimulationRunFeignClient {
return runService.listFlowNodes(req); return runService.listFlowNodes(req);
} }
} }

View File

@@ -1,6 +1,6 @@
package com.sdm.project.dao; package com.sdm.project.dao;
import com.sdm.project.model.entity.SimulationPerformance; import com.sdm.common.entity.req.project.SimulationPerformance;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/** /**

View File

@@ -1,6 +1,6 @@
package com.sdm.project.model.resp; package com.sdm.project.model.resp;
import com.sdm.project.model.entity.SimulationPerformance; import com.sdm.common.entity.req.project.SimulationPerformance;
import com.sdm.project.model.entity.SimulationRun; import com.sdm.project.model.entity.SimulationRun;
import lombok.Data; import lombok.Data;

View File

@@ -1,6 +1,6 @@
package com.sdm.project.service; package com.sdm.project.service;
import com.sdm.project.model.entity.SimulationPerformance; import com.sdm.common.entity.req.project.SimulationPerformance;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
/** /**

View File

@@ -1,11 +1,10 @@
package com.sdm.project.service; package com.sdm.project.service;
import com.sdm.common.common.SdmResponse; import com.sdm.common.common.SdmResponse;
import com.sdm.common.entity.req.capability.FlowNodeDto;
import com.sdm.common.entity.req.data.CreateDirReq; import com.sdm.common.entity.req.data.CreateDirReq;
import com.sdm.common.entity.req.data.KnowledgeCallBackReq;
import com.sdm.common.entity.req.data.QueryDirReq; import com.sdm.common.entity.req.data.QueryDirReq;
import com.sdm.common.entity.req.data.UploadFilesReq; import com.sdm.common.entity.req.data.UploadFilesReq;
import com.sdm.common.entity.req.project.SpdmReportReq;
import com.sdm.common.entity.req.system.LaunchApproveReq; import com.sdm.common.entity.req.system.LaunchApproveReq;
import com.sdm.common.entity.resp.PageDataResp; import com.sdm.common.entity.resp.PageDataResp;
import com.sdm.common.entity.resp.data.BatchAddFileInfoResp; import com.sdm.common.entity.resp.data.BatchAddFileInfoResp;
@@ -66,10 +65,16 @@ public interface ISimulationRunService extends IService<SimulationRun> {
SdmResponse deleteSimulationKeyResult(KeyResultReq req); SdmResponse deleteSimulationKeyResult(KeyResultReq req);
void generateReport(SpdmReportReq req, HttpServletResponse response); void generateReport(SpdmReportReq req, HttpServletResponse response);
/**
* 内部调用生成报告
* @param req 报告请求参数
*/
SdmResponse<Void> generateReportInternal(SpdmReportReq req);
SdmResponse startProcessInstance(SpdmTaskRunReq req); SdmResponse startProcessInstance(SpdmTaskRunReq req);
SdmResponse saveNodeParams(SpdmNodeParamReq req); SdmResponse saveNodeParams(SpdmNodeParamReq req);
SdmResponse<FlowInfoDto> listFlowNodes(SpdmTaskRunReq req); SdmResponse<FlowInfoDto> listFlowNodes(SpdmTaskRunReq req);
} }

View File

@@ -1,6 +1,6 @@
package com.sdm.project.service.impl; package com.sdm.project.service.impl;
import com.sdm.project.model.entity.SimulationPerformance; import com.sdm.common.entity.req.project.SimulationPerformance;
import com.sdm.project.dao.SimulationPerformanceMapper; import com.sdm.project.dao.SimulationPerformanceMapper;
import com.sdm.project.service.ISimulationPerformanceService; import com.sdm.project.service.ISimulationPerformanceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

View File

@@ -17,6 +17,9 @@ import com.sdm.common.entity.flowable.dto.FlowElementDTO;
import com.sdm.common.entity.flowable.dto.ProcessDefinitionDTO; import com.sdm.common.entity.flowable.dto.ProcessDefinitionDTO;
import com.sdm.common.entity.req.capability.FlowNodeDto; import com.sdm.common.entity.req.capability.FlowNodeDto;
import com.sdm.common.entity.req.data.*; import com.sdm.common.entity.req.data.*;
import com.sdm.common.entity.req.project.ProjecInfoReq;
import com.sdm.common.entity.req.project.SimulationPerformance;
import com.sdm.common.entity.req.project.SpdmReportReq;
import com.sdm.common.entity.req.system.LaunchApproveReq; import com.sdm.common.entity.req.system.LaunchApproveReq;
import com.sdm.common.entity.req.system.UserQueryReq; import com.sdm.common.entity.req.system.UserQueryReq;
import com.sdm.common.entity.resp.PageDataResp; import com.sdm.common.entity.resp.PageDataResp;
@@ -1214,6 +1217,127 @@ public class SimulationRunServiceImpl extends ServiceImpl<SimulationRunMapper, S
deleteFolder(new File(TEMP_REPORT_PATH + randomId)); deleteFolder(new File(TEMP_REPORT_PATH + randomId));
} }
@Override
public SdmResponse<Void> generateReportInternal(SpdmReportReq req) {
log.info("内部调用生成自动化报告参数为:{}", req);
// 父节点信息
ProjecInfoReq projecInfoReq = req.getProjecInfoReq();
if (ObjectUtils.isEmpty(projecInfoReq) || StringUtils.isBlank(projecInfoReq.getLoadcaseName())) {
log.error("父节点信息不能为空");
return SdmResponse.failed("父节点信息不能为空");
}
// 根据文件id下载文件到临时目录
List<Long> imageFileIdList = req.getImageFileIdList();
String randomId = RandomUtil.generateString(16);
String tempPath = TEMP_REPORT_PATH + randomId;
if (CollectionUtils.isNotEmpty(imageFileIdList)) {
for (Long fileId : imageFileIdList) {
dataFeignClient.downloadFileToLocal(fileId, tempPath);
}
}
Path folder = Paths.get(tempPath);
if (!Files.exists(folder) || !Files.isDirectory(folder)) {
if (!new File(tempPath).mkdir()) {
log.error("创建临时文件夹:{}失败", tempPath);
throw new RuntimeException("生成报告失败,原因为:创建临时文件夹失败");
}
}
log.info("临时路径为:{}", randomId);
String commands = "python /opt/script/exportWord.py " + tempPath + File.separator + TEMPLATE_PATH + projecInfoReq.getLoadcaseName() + "Analyse";
// 生成projectInfo.json
projecInfoReq.setReportCommand(commands);
try (FileOutputStream projectInfoOutputStream = new FileOutputStream(tempPath + File.separator + "projectInfo.json")) {
projectInfoOutputStream.write(JSON.toJSONString(projecInfoReq).getBytes(StandardCharsets.UTF_8));
projectInfoOutputStream.flush();
} catch (Exception e) {
throw new RuntimeException(e);
}
// 生成performance.json
List<SimulationPerformance> performanceList = req.getPerformanceList();
if (CollectionUtils.isNotEmpty(performanceList)) {
JSONObject allPerformanceInfoJson = new JSONObject();
for (SimulationPerformance performance : performanceList) {
PerformanceInfoReq performanceInfoReq = new PerformanceInfoReq();
performanceInfoReq.setValue(StringUtils.isNotBlank(performance.getTargetValue()) ? performance.getTargetValue() : "");
performanceInfoReq.setEnglishName(StringUtils.isNotBlank(performance.getEnglishName()) ? performance.getEnglishName() : "");
performanceInfoReq.setHighValue(StringUtils.isNotBlank(performance.getHighValue()) ? performance.getHighValue() : "");
performanceInfoReq.setPerformanceName(StringUtils.isNotBlank(performance.getPerformanceName()) ? performance.getPerformanceName() : "");
performanceInfoReq.setMethod(StringUtils.isNotBlank(performance.getMethod()) ? performance.getMethod() : "");
performanceInfoReq.setUnit(StringUtils.isNotBlank(performance.getUnit()) ? performance.getUnit() : "");
allPerformanceInfoJson.put(performanceInfoReq.getEnglishName(), performanceInfoReq);
}
allPerformanceInfoJson.put("type", "insert");
try (FileOutputStream performanceOutputStream = new FileOutputStream(tempPath + File.separator + "performance.json")) {
performanceOutputStream.write(JSON.toJSONString(allPerformanceInfoJson).getBytes(StandardCharsets.UTF_8));
performanceOutputStream.flush();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
// 调用脚本
log.info("调用脚本中。。。。。。");
log.info("command:" + commands);
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);
}
log.info("脚本执行完成");
runningStatus = process.waitFor();
log.info("脚本运行状态:" + runningStatus);
} catch (IOException | InterruptedException e) {
log.error("执行脚本失败:" + e);
return SdmResponse.failed("执行脚本失败:" + e.getMessage());
}
if (runningStatus != 0) {
log.error("执行脚本失败");
return SdmResponse.failed("执行脚本失败");
} else {
log.info(commands + "执行脚本完成!");
}
try {
// 获取临时路径中脚本生成的报告
Path reportPath = Paths.get(tempPath + File.separator + "report" + File.separator + "report.docx");
Path outputPath = Paths.get(req.getOutPutDirPath());
// 移动文件到目标路径
if (Files.exists(reportPath) && Files.exists(outputPath) && Files.isDirectory(outputPath)) {
Path targetPath = outputPath.resolve("report.docx");
Files.move(reportPath, targetPath, StandardCopyOption.REPLACE_EXISTING);
log.info("报告已移动至: {}", targetPath);
} else {
log.error("源文件或目标目录不存在");
return SdmResponse.failed("源文件或目标目录不存在");
}
} catch (Exception ex) {
log.error("移动报告文件失败:{}", ex.getMessage());
throw new RuntimeException("移动报告文件失败");
} finally {
// 删除临时路径
log.info("删除临时路径:{},中。。。。。。", randomId);
deleteFolder(new File(tempPath));
}
return SdmResponse.success();
}
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)

View File

@@ -1,6 +1,5 @@
package com.sdm.project.service.impl; package com.sdm.project.service.impl;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.sdm.common.common.ResultCode; import com.sdm.common.common.ResultCode;
@@ -11,13 +10,13 @@ import com.sdm.common.entity.constants.ProjectConstants;
import com.sdm.common.entity.enums.DirTypeEnum; import com.sdm.common.entity.enums.DirTypeEnum;
import com.sdm.common.entity.enums.NodeTypeEnum; import com.sdm.common.entity.enums.NodeTypeEnum;
import com.sdm.common.entity.req.data.CreateDirReq; import com.sdm.common.entity.req.data.CreateDirReq;
import com.sdm.common.entity.req.project.SimulationPerformance;
import com.sdm.common.entity.req.system.UserQueryReq; import com.sdm.common.entity.req.system.UserQueryReq;
import com.sdm.common.entity.req.task.TaskExportExcelFormat; import com.sdm.common.entity.req.task.TaskExportExcelFormat;
import com.sdm.common.entity.req.task.TaskExportExcelParam; import com.sdm.common.entity.req.task.TaskExportExcelParam;
import com.sdm.common.entity.resp.system.CIDUserResp; import com.sdm.common.entity.resp.system.CIDUserResp;
import com.sdm.common.feign.impl.data.DataClientFeignClientImpl; import com.sdm.common.feign.impl.data.DataClientFeignClientImpl;
import com.sdm.common.feign.impl.system.SysUserFeignClientImpl; import com.sdm.common.feign.impl.system.SysUserFeignClientImpl;
import com.sdm.common.utils.RandomUtil;
import com.sdm.common.utils.excel.ExcelUtil; import com.sdm.common.utils.excel.ExcelUtil;
import com.sdm.project.common.MemberTypeEnum; import com.sdm.project.common.MemberTypeEnum;
import com.sdm.project.common.RunPerformanceStatusEnum; import com.sdm.project.common.RunPerformanceStatusEnum;
@@ -39,7 +38,6 @@ import com.sdm.project.service.*;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;