forked from toolchaintechnologycenter/spdm-backend
1、新增导入指标接口
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
package com.sdm.project.bo;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.sdm.common.common.SdmResponse;
|
||||
import com.sdm.common.entity.ExportExcelFormat;
|
||||
import com.sdm.common.entity.req.project.SimulationPerformance;
|
||||
import com.sdm.common.utils.SystemOperate;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -117,59 +118,50 @@ public class ExportOperate {
|
||||
String columnFileName = TEMP_EXPORT_PATH + System.currentTimeMillis() + "column.json";
|
||||
if(!saveContentsToFile(columns,columnFileName)) {
|
||||
response = SdmResponse.failed("保存指标字段信息失败");
|
||||
}
|
||||
else {
|
||||
}else {
|
||||
// 脚本解析导入的指标文件
|
||||
String shellPath = scriptPath + File.separator + "inputExcel.py";
|
||||
String poolJsonFileName = TEMP_EXPORT_PATH + System.currentTimeMillis() + "performance.json";
|
||||
String pythonCmd = "python " + shellPath + " '" + poolJsonFileName + " '" + " '" + performanceFileName + "' " + " '" + columnFileName + " '" ;
|
||||
try
|
||||
{
|
||||
String performanceJsonFileName = TEMP_EXPORT_PATH + System.currentTimeMillis() + "performance.json";
|
||||
String pythonCmd = "python " + shellPath + " " + performanceJsonFileName + " " + performanceFileName + " " + columnFileName + " " + "1";
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
log.info("shell begin time:"+System.currentTimeMillis());
|
||||
String resultString = SystemOperate.exeShellCmd(pythonCmd);
|
||||
log.info("shell end time:"+System.currentTimeMillis());
|
||||
if(resultString.contains("error")) {
|
||||
response = SdmResponse.failed("解析指标文件脚本执行错误");
|
||||
}
|
||||
else {
|
||||
InputStream is = new FileInputStream(poolJsonFileName);
|
||||
byte[] jsonContents = is.readAllBytes();
|
||||
String poolJsonString = new String(jsonContents, "utf-8");
|
||||
if (poolJsonString != null && poolJsonString.length() > 0) {
|
||||
JSONObject poolJsonObj = JSONObject.parseObject(poolJsonString);
|
||||
response.setData(poolJsonObj);
|
||||
} else {
|
||||
inputStream = new FileInputStream(performanceJsonFileName);
|
||||
byte[] jsonContents = inputStream.readAllBytes();
|
||||
String performanceJsonString = new String(jsonContents, "utf-8");
|
||||
List<SimulationPerformance> performanceJsonObjectList = JSONArray.parseArray(performanceJsonString, SimulationPerformance.class);
|
||||
log.info("performanceJsonObjectList为:{}",performanceJsonObjectList);
|
||||
if (CollectionUtils.isNotEmpty(performanceJsonObjectList)) {
|
||||
response.setData(performanceJsonObjectList);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
// if(poolFileName != null && poolFileName.length() > 0)
|
||||
// {
|
||||
// File pFile = new File(poolFileName);
|
||||
// if(pFile.exists()) {
|
||||
// pFile.delete();
|
||||
// }
|
||||
// }
|
||||
// File dictFile = new File(dictFileName);
|
||||
// if(dictFile.exists())
|
||||
// {
|
||||
// dictFile.delete();
|
||||
// }
|
||||
// File poolJsonFile = new File(poolJsonFileName);
|
||||
// if(poolJsonFile.exists())
|
||||
// {
|
||||
// poolJsonFile.delete();
|
||||
// }
|
||||
//
|
||||
// File columnFile = new File(columnFileName);
|
||||
// if(columnFile.exists())
|
||||
// {
|
||||
// columnFile.delete();
|
||||
// }
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
File pJsonFile = new File(performanceJsonFileName);
|
||||
if(pJsonFile.exists()) {
|
||||
pJsonFile.delete();
|
||||
}
|
||||
File pFile = new File(performanceFileName);
|
||||
if(pFile.exists()) {
|
||||
pFile.delete();
|
||||
}
|
||||
File cFile = new File(columnFileName);
|
||||
if(cFile.exists()) {
|
||||
cFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
return response;
|
||||
|
||||
@@ -310,8 +310,8 @@ public class SimulationTaskController implements ISimulationTaskFeignClient {
|
||||
*/
|
||||
@PostMapping(value = "/importSimulationPerformance")
|
||||
@ResponseBody
|
||||
SdmResponse importSimulationPerformance(@RequestParam("file") MultipartFile file, @RequestParam("columns")String columns) {
|
||||
return taskService.importSimulationPerformance(file,columns);
|
||||
SdmResponse importSimulationPerformance(@RequestParam("file") MultipartFile file, @RequestParam("columns")String columns, @RequestParam("taskId") String taskId, @RequestParam("taskName") String taskName) {
|
||||
return taskService.importSimulationPerformance(file,columns,taskId,taskName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -106,6 +106,6 @@ public interface ITaskService {
|
||||
|
||||
SdmResponse batchOperation(SpdmBatchTaskOpr batchTaskOpr);
|
||||
|
||||
SdmResponse importSimulationPerformance(MultipartFile file, String columns);
|
||||
SdmResponse importSimulationPerformance(MultipartFile file, String columns,String taskId,String taskName);
|
||||
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
@@ -150,6 +151,9 @@ public class TaskServiceImpl implements ITaskService {
|
||||
@Autowired
|
||||
private LyricVProjectResourcePlanDMService lyricVProjectResourcePlanDMService;
|
||||
|
||||
@Autowired
|
||||
private DataClientFeignClientImpl dataFeignClient;
|
||||
|
||||
// 通过标识判断是否走查询现场视图逻辑(0不查询,1查询)
|
||||
@Value("${lyricFlag:1}")
|
||||
private int lyricFlag;
|
||||
@@ -4184,18 +4188,58 @@ public class TaskServiceImpl implements ITaskService {
|
||||
|
||||
|
||||
@Override
|
||||
public SdmResponse importSimulationPerformance(MultipartFile file, String columns) {
|
||||
SdmResponse response = exportOperate.parsePerformance(file,columns);
|
||||
if(response.getCode() != ResultCode.SUCCESS.getCode()) {
|
||||
return response;
|
||||
}
|
||||
else {
|
||||
JSONObject poolTreeObj = (JSONObject) response.getData();
|
||||
response.setData(poolTreeObj);
|
||||
}
|
||||
log.info("import endTime:"+System.currentTimeMillis());
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SdmResponse importSimulationPerformance(MultipartFile file, String columns,String taskId,String taskName) {
|
||||
// 通过脚本解析导入的指标excel文件
|
||||
SdmResponse response = exportOperate.parsePerformance(file,columns);
|
||||
if(response.getCode() != ResultCode.SUCCESS.getCode()) {
|
||||
return response;
|
||||
|
||||
}
|
||||
List<SimulationPerformance> performanceList = (List<SimulationPerformance>) response.getData();
|
||||
if (CollectionUtils.isEmpty(performanceList)) {
|
||||
return response;
|
||||
}
|
||||
// 创建指标
|
||||
LocalDateTime createTime = LocalDateTime.now();
|
||||
BatchCreateDirItem batchCreateDirItem = new BatchCreateDirItem();
|
||||
DirNodeInfo taskDirNodeInfo = new DirNodeInfo();
|
||||
taskDirNodeInfo.setUuId(taskId);
|
||||
taskDirNodeInfo.setUuIdOwnType(NodeTypeEnum.TASK.getValue());
|
||||
taskDirNodeInfo.setDirName(taskName);
|
||||
batchCreateDirItem.setParentDirNodeInfo(taskDirNodeInfo);
|
||||
List<DirNodeInfo> childDirNodeInfos = new ArrayList<>();
|
||||
for (SimulationPerformance performance : performanceList) {
|
||||
performance.setUuid(RandomUtil.generateString(32));
|
||||
performance.setNodeId(taskId);
|
||||
performance.setTaskId(taskId);
|
||||
performance.setCreateTime(createTime);
|
||||
if (StringUtils.isBlank(performance.getNodeName())) {
|
||||
performance.setNodeName(performance.getPerformanceName());
|
||||
}
|
||||
// 设置指标文件夹相关信息
|
||||
DirNodeInfo performanceDirNodeInfo = new DirNodeInfo();
|
||||
performanceDirNodeInfo.setUuId(performance.getUuid());
|
||||
performanceDirNodeInfo.setUuIdOwnType(NodeTypeEnum.PERFORMANCE.getValue());
|
||||
performanceDirNodeInfo.setParentUuId(taskId);
|
||||
performanceDirNodeInfo.setDirName(StringUtils.isNotBlank(performance.getNodeName()) ? performance.getNodeName() : performance.getPerformanceName());
|
||||
childDirNodeInfos.add(performanceDirNodeInfo);
|
||||
}
|
||||
simulationPerformanceService.saveBatch(performanceList);
|
||||
// 批量创建指标文件夹
|
||||
batchCreateDirItem.setChildDirNodeInfos(childDirNodeInfos);
|
||||
BatchCreateDirReq batchCreateDirReq = new BatchCreateDirReq();
|
||||
List<BatchCreateDirItem> createDirItemList = new ArrayList<>();
|
||||
createDirItemList.add(batchCreateDirItem);
|
||||
batchCreateDirReq.setItems(createDirItemList);
|
||||
batchCreateDirReq.setDirType(DirTypeEnum.PROJECT_NODE_DIR.getValue());
|
||||
log.info("任务执行导入指标创建文件夹参数: {}", batchCreateDirReq);
|
||||
SdmResponse dirCreateResp = dataFeignClient.batchCreateDir(batchCreateDirReq);
|
||||
log.info("任务执行导入指标创建文件夹响应: {}", dirCreateResp);
|
||||
if (!dirCreateResp.isSuccess()) {
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return SdmResponse.failed("导入指标失败,原因:{}",dirCreateResp.getMessage());
|
||||
}
|
||||
return SdmResponse.success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user