1、新增导入指标接口
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
package com.sdm.project.bo;
|
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.common.SdmResponse;
|
||||||
import com.sdm.common.entity.ExportExcelFormat;
|
import com.sdm.common.entity.req.project.SimulationPerformance;
|
||||||
import com.sdm.common.utils.SystemOperate;
|
import com.sdm.common.utils.SystemOperate;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@@ -117,59 +118,50 @@ public class ExportOperate {
|
|||||||
String columnFileName = TEMP_EXPORT_PATH + System.currentTimeMillis() + "column.json";
|
String columnFileName = TEMP_EXPORT_PATH + System.currentTimeMillis() + "column.json";
|
||||||
if(!saveContentsToFile(columns,columnFileName)) {
|
if(!saveContentsToFile(columns,columnFileName)) {
|
||||||
response = SdmResponse.failed("保存指标字段信息失败");
|
response = SdmResponse.failed("保存指标字段信息失败");
|
||||||
}
|
}else {
|
||||||
else {
|
|
||||||
// 脚本解析导入的指标文件
|
// 脚本解析导入的指标文件
|
||||||
String shellPath = scriptPath + File.separator + "inputExcel.py";
|
String shellPath = scriptPath + File.separator + "inputExcel.py";
|
||||||
String poolJsonFileName = TEMP_EXPORT_PATH + System.currentTimeMillis() + "performance.json";
|
String performanceJsonFileName = TEMP_EXPORT_PATH + System.currentTimeMillis() + "performance.json";
|
||||||
String pythonCmd = "python " + shellPath + " '" + poolJsonFileName + " '" + " '" + performanceFileName + "' " + " '" + columnFileName + " '" ;
|
String pythonCmd = "python " + shellPath + " " + performanceJsonFileName + " " + performanceFileName + " " + columnFileName + " " + "1";
|
||||||
try
|
InputStream inputStream = null;
|
||||||
{
|
try {
|
||||||
log.info("shell begin time:"+System.currentTimeMillis());
|
log.info("shell begin time:"+System.currentTimeMillis());
|
||||||
String resultString = SystemOperate.exeShellCmd(pythonCmd);
|
String resultString = SystemOperate.exeShellCmd(pythonCmd);
|
||||||
log.info("shell end time:"+System.currentTimeMillis());
|
log.info("shell end time:"+System.currentTimeMillis());
|
||||||
if(resultString.contains("error")) {
|
if(resultString.contains("error")) {
|
||||||
response = SdmResponse.failed("解析指标文件脚本执行错误");
|
response = SdmResponse.failed("解析指标文件脚本执行错误");
|
||||||
}
|
} else {
|
||||||
else {
|
inputStream = new FileInputStream(performanceJsonFileName);
|
||||||
InputStream is = new FileInputStream(poolJsonFileName);
|
byte[] jsonContents = inputStream.readAllBytes();
|
||||||
byte[] jsonContents = is.readAllBytes();
|
String performanceJsonString = new String(jsonContents, "utf-8");
|
||||||
String poolJsonString = new String(jsonContents, "utf-8");
|
List<SimulationPerformance> performanceJsonObjectList = JSONArray.parseArray(performanceJsonString, SimulationPerformance.class);
|
||||||
if (poolJsonString != null && poolJsonString.length() > 0) {
|
log.info("performanceJsonObjectList为:{}",performanceJsonObjectList);
|
||||||
JSONObject poolJsonObj = JSONObject.parseObject(poolJsonString);
|
if (CollectionUtils.isNotEmpty(performanceJsonObjectList)) {
|
||||||
response.setData(poolJsonObj);
|
response.setData(performanceJsonObjectList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
} finally {
|
||||||
finally
|
if (inputStream != null) {
|
||||||
{
|
try {
|
||||||
// if(poolFileName != null && poolFileName.length() > 0)
|
inputStream.close();
|
||||||
// {
|
} catch (IOException e) {
|
||||||
// File pFile = new File(poolFileName);
|
throw new RuntimeException(e);
|
||||||
// if(pFile.exists()) {
|
}
|
||||||
// pFile.delete();
|
}
|
||||||
// }
|
File pJsonFile = new File(performanceJsonFileName);
|
||||||
// }
|
if(pJsonFile.exists()) {
|
||||||
// File dictFile = new File(dictFileName);
|
pJsonFile.delete();
|
||||||
// if(dictFile.exists())
|
}
|
||||||
// {
|
File pFile = new File(performanceFileName);
|
||||||
// dictFile.delete();
|
if(pFile.exists()) {
|
||||||
// }
|
pFile.delete();
|
||||||
// File poolJsonFile = new File(poolJsonFileName);
|
}
|
||||||
// if(poolJsonFile.exists())
|
File cFile = new File(columnFileName);
|
||||||
// {
|
if(cFile.exists()) {
|
||||||
// poolJsonFile.delete();
|
cFile.delete();
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// File columnFile = new File(columnFileName);
|
|
||||||
// if(columnFile.exists())
|
|
||||||
// {
|
|
||||||
// columnFile.delete();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
|
|||||||
@@ -310,8 +310,8 @@ public class SimulationTaskController implements ISimulationTaskFeignClient {
|
|||||||
*/
|
*/
|
||||||
@PostMapping(value = "/importSimulationPerformance")
|
@PostMapping(value = "/importSimulationPerformance")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
SdmResponse importSimulationPerformance(@RequestParam("file") MultipartFile file, @RequestParam("columns")String columns) {
|
SdmResponse importSimulationPerformance(@RequestParam("file") MultipartFile file, @RequestParam("columns")String columns, @RequestParam("taskId") String taskId, @RequestParam("taskName") String taskName) {
|
||||||
return taskService.importSimulationPerformance(file,columns);
|
return taskService.importSimulationPerformance(file,columns,taskId,taskName);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,6 +106,6 @@ public interface ITaskService {
|
|||||||
|
|
||||||
SdmResponse batchOperation(SpdmBatchTaskOpr batchTaskOpr);
|
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.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@@ -150,6 +151,9 @@ public class TaskServiceImpl implements ITaskService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private LyricVProjectResourcePlanDMService lyricVProjectResourcePlanDMService;
|
private LyricVProjectResourcePlanDMService lyricVProjectResourcePlanDMService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DataClientFeignClientImpl dataFeignClient;
|
||||||
|
|
||||||
// 通过标识判断是否走查询现场视图逻辑(0不查询,1查询)
|
// 通过标识判断是否走查询现场视图逻辑(0不查询,1查询)
|
||||||
@Value("${lyricFlag:1}")
|
@Value("${lyricFlag:1}")
|
||||||
private int lyricFlag;
|
private int lyricFlag;
|
||||||
@@ -4184,18 +4188,58 @@ public class TaskServiceImpl implements ITaskService {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SdmResponse importSimulationPerformance(MultipartFile file, String columns) {
|
@Transactional(rollbackFor = Exception.class)
|
||||||
SdmResponse response = exportOperate.parsePerformance(file,columns);
|
public SdmResponse importSimulationPerformance(MultipartFile file, String columns,String taskId,String taskName) {
|
||||||
if(response.getCode() != ResultCode.SUCCESS.getCode()) {
|
// 通过脚本解析导入的指标excel文件
|
||||||
return response;
|
SdmResponse response = exportOperate.parsePerformance(file,columns);
|
||||||
}
|
if(response.getCode() != ResultCode.SUCCESS.getCode()) {
|
||||||
else {
|
|
||||||
JSONObject poolTreeObj = (JSONObject) response.getData();
|
|
||||||
response.setData(poolTreeObj);
|
|
||||||
}
|
|
||||||
log.info("import endTime:"+System.currentTimeMillis());
|
|
||||||
return response;
|
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