fix:dongyang现场代码

This commit is contained in:
2026-03-25 16:02:54 +08:00
parent 93f2b0d34b
commit 99a82a21b8
8 changed files with 167 additions and 131 deletions

View File

@@ -626,7 +626,8 @@ public class FilesUtil {
// 5. 创建输入输出流
in = new BufferedInputStream(connection.getInputStream());
out = new BufferedOutputStream(new FileOutputStream(savePath));
int lastIndexOf = fileUrl.lastIndexOf("/");
out = new BufferedOutputStream(new FileOutputStream(savePath + File.separator + fileUrl.substring(lastIndexOf + 1)));
// 6. 缓冲区读写数据
byte[] buffer = new byte[4096]; // 4KB缓冲区
@@ -680,20 +681,7 @@ public class FilesUtil {
* @param savePath 完整的文件保存路径
*/
private static void createDirectoryIfNotExists(String savePath) {
// 1. 创建File对象
File file = new File(savePath);
// 2. 获取文件所在的目录(去掉文件名部分)
File parentDir = file.getParentFile();
// 3. 如果目录不为空且不存在则创建mkdirs会创建多级目录
if (parentDir != null && !parentDir.exists()) {
boolean isCreated = parentDir.mkdirs();
if (isCreated) {
log.info("目录不存在,已自动创建:" + parentDir.getAbsolutePath());
} else {
log.error("创建目录失败:" + parentDir.getAbsolutePath());
}
}
try { Files.createDirectories(Paths.get(savePath)); } catch (IOException e) { e.printStackTrace(); }
}
/**

View File

@@ -28,7 +28,7 @@ public class LyricVAttachmentConfigToDM {
private String name;
@Schema(description = "文件链接地址")
@TableField(value = "project_name")
@TableField(value = "file_path")
private String filePath;
@Schema(description = "缩略图地址")

View File

@@ -9,6 +9,7 @@ import com.sdm.project.model.req.SpdmTaskOprReq;
import com.sdm.project.model.req.TaskEditNodeReq;
import java.util.List;
import java.util.Map;
/**
* <p>
@@ -24,6 +25,6 @@ public interface ISimulationTaskService extends IService<SimulationTask> {
SdmResponse editTaskForData(TaskEditNodeReq req);
void batchCreateTaskFromDemand(List<SimulationDemand> demandList,Boolean isDownloadFlag);
void batchCreateTaskFromDemand(List<SimulationDemand> demandList, Boolean isDownloadFlag, Map<String,String> fileNameMap);
}

View File

@@ -342,7 +342,7 @@ public class DemandServiceImpl extends BaseService implements IDemandService {
if (req.getIsLyric()) {
SimulationDemand demand = new SimulationDemand();
BeanUtils.copyProperties(req, demand);
simulationTaskService.batchCreateTaskFromDemand(Collections.singletonList(demand),false);
simulationTaskService.batchCreateTaskFromDemand(Collections.singletonList(demand),false,null);
}
return SdmResponse.success(req.getUuid());
@@ -1851,7 +1851,7 @@ public class DemandServiceImpl extends BaseService implements IDemandService {
if (req.getIsLyric()) {
SimulationDemand demand = new SimulationDemand();
BeanUtils.copyProperties(req, demand);
simulationTaskService.batchCreateTaskFromDemand(Collections.singletonList(demand),false);
simulationTaskService.batchCreateTaskFromDemand(Collections.singletonList(demand),false,null);
}
return SdmResponse.success(req.getUuid());

View File

@@ -457,9 +457,12 @@ public class LyricInternalServiceImpl implements ILyricInternalService {
usernameToUserIdMap = userList.stream().collect(Collectors.toMap(CIDUserResp::getUsername, CIDUserResp::getUserId));
}
// 构建一个需求todoId到resultFileId的映射
Map<Long,String> resultFileIdMap = todoInfoList.stream().collect(Collectors.toMap(LyricVTodoEmulationInfoDM::getTodoId,LyricVTodoEmulationInfoDM::getResultFileId,(oldValue, newValue) -> oldValue));
Map<Long,String> resultFileIdMap = todoInfoList.stream().filter(todo -> StringUtils.isNotBlank(todo.getResultFileId()))
.collect(Collectors.toMap(LyricVTodoEmulationInfoDM::getTodoId,LyricVTodoEmulationInfoDM::getResultFileId,(oldValue, newValue) -> oldValue));
// 构建一个resultFileId到filePath的映射
Map<Integer,String> filePathMap = new HashMap<>();
// 构建一个filePath到fileName的映射
Map<String,String> fileNameMap = new HashMap<>();
// 查询filePath
List<String> resultFileIdStrList = todoInfoList.stream().map(LyricVTodoEmulationInfoDM::getResultFileId).filter(StringUtils::isNotBlank)
.collect(Collectors.toList());
@@ -481,6 +484,8 @@ public class LyricInternalServiceImpl implements ILyricInternalService {
.list();
if (CollectionUtils.isNotEmpty(attachmentConfigToDMList)) {
filePathMap = attachmentConfigToDMList.stream().collect(Collectors.toMap(LyricVAttachmentConfigToDM::getId,LyricVAttachmentConfigToDM::getFilePath,(oldValue, newValue) -> oldValue));
fileNameMap = attachmentConfigToDMList.stream().filter(attachment -> StringUtils.isNotBlank(attachment.getFilePath()))
.collect(Collectors.toMap(LyricVAttachmentConfigToDM::getFilePath,LyricVAttachmentConfigToDM::getName,(oldValue, newValue) -> oldValue));
}
}
}
@@ -555,7 +560,7 @@ public class LyricInternalServiceImpl implements ILyricInternalService {
}
simulationDemand.setReportFileUrlList(reportFileUrlList);
}
simulationTaskService.batchCreateTaskFromDemand(demandToCreateTaskList,true);
simulationTaskService.batchCreateTaskFromDemand(demandToCreateTaskList,true,fileNameMap);
}
return SdmResponse.success();
} catch (Exception e) {
@@ -4242,7 +4247,7 @@ public class LyricInternalServiceImpl implements ILyricInternalService {
SimulationDemand demand = new SimulationDemand();
BeanUtils.copyProperties(req, demand);
simulationTaskService.batchCreateTaskFromDemand(Collections.singletonList(demand),false);
simulationTaskService.batchCreateTaskFromDemand(Collections.singletonList(demand),false,null);
return SdmResponse.success(req.getUuid());
}
@@ -4279,17 +4284,26 @@ public class LyricInternalServiceImpl implements ILyricInternalService {
log.error("demandCodeList为空");
return SdmResponse.failed("demandCodeList为空");
}
List<LyricVTodoEmulationInfoDM> todoInfoList = lyricVTodoInfoService.lambdaQuery().in(LyricVTodoEmulationInfoDM::getTodoId, demandCodeList).list();
List<LyricVTodoEmulationInfoDM> todoInfoList = lyricVTodoInfoService.lambdaQuery()
.in(LyricVTodoEmulationInfoDM::getTodoId, demandCodeList).list();
if (CollectionUtils.isEmpty(todoInfoList)) {
log.error("todoInfoList为空");
return SdmResponse.failed("todoInfoList为空");
}
todoInfoList = todoInfoList.stream()
// 过滤掉todoId为null的数据
.filter(dm -> dm.getSubject() != null && StringUtils.isNotBlank(dm.getResultFileId()))
.collect(Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(LyricVTodoEmulationInfoDM::getSubject))),
ArrayList::new
));
// 构建一个需求todoId到resultFileId的映射
Map<Long,String> resultFileIdMap = todoInfoList.stream().collect(Collectors.toMap(LyricVTodoEmulationInfoDM::getTodoId,LyricVTodoEmulationInfoDM::getResultFileId,(oldValue, newValue) -> oldValue));
// 构建一个resultFileId到filePath的映射
Map<Integer,String> filePathMap = new HashMap<>();
// 构建一个filePath到fileName的映射
Map<String,String> fileNameMap = new HashMap<>();
// 查询filePath
List<String> resultFileIdStrList = todoInfoList.stream().map(LyricVTodoEmulationInfoDM::getResultFileId).filter(StringUtils::isNotBlank)
.collect(Collectors.toList());
@@ -4311,6 +4325,8 @@ public class LyricInternalServiceImpl implements ILyricInternalService {
.list();
if (CollectionUtils.isNotEmpty(attachmentConfigToDMList)) {
filePathMap = attachmentConfigToDMList.stream().collect(Collectors.toMap(LyricVAttachmentConfigToDM::getId,LyricVAttachmentConfigToDM::getFilePath,(oldValue, newValue) -> oldValue));
fileNameMap = attachmentConfigToDMList.stream().filter(attachment -> StringUtils.isNotBlank(attachment.getFilePath()))
.collect(Collectors.toMap(LyricVAttachmentConfigToDM::getFilePath,LyricVAttachmentConfigToDM::getName,(oldValue, newValue) -> oldValue));
}
}
}
@@ -4352,6 +4368,7 @@ public class LyricInternalServiceImpl implements ILyricInternalService {
log.info("共处理{}条任务的报告数据",taskList.size());
Map<String, String> finalFileNameMap = fileNameMap;
for (SimulationTask task : taskList) {
// 异步下载待办的结果文件到任务文件夹下
if (CollectionUtils.isEmpty(task.getReportFileUrlList())) {
@@ -4366,28 +4383,39 @@ public class LyricInternalServiceImpl implements ILyricInternalService {
try {
FilesUtil.downloadFile(task.getReportFileUrlList(), savePath);
// 上传到minio
String fileName = "";
FileInputStream fileInputStream = new FileInputStream(REPORT_PATH_PREFIX + task.getUuid() + File.separator + fileName);
byte[] fileData = fileInputStream.readAllBytes();
MockMultipartFile multipartFile = new MockMultipartFile(
fileName,
fileName,
"application/octet-stream",
fileData);
UploadFilesReq fileReq = new UploadFilesReq();
fileReq.setFile(multipartFile);
// 传任务uuid
fileReq.setUuid(task.getUuid());
fileReq.setFileName(fileName);
fileReq.setFileTypeDictValue(String.valueOf(FileBizTypeEnum.REPORT_FILE.getValue()));
fileReq.setFileTypeDictClass(FileDictTagEnum.FILE_TYPE.getDictClass());
fileReq.setDictTags(Arrays.asList(FileDictTagEnum.FILE_TYPE.getDictClassFieldName(), FileDictTagEnum.FILE_TYPE.getDictValueFieldName()));
fileReq.setTagReq(tagReq);
if (fileReq.getTagReq() != null) {
fileReq.setTagReqStr(JSON.toJSONString(fileReq.getTagReq()));
List<String> reportFileUrlList = task.getReportFileUrlList();
for (String reportFileUrl : reportFileUrlList) {
File file = new File(reportFileUrl);
String fileName = file.getName();
String realFileName = finalFileNameMap.get(reportFileUrl);
if (StringUtils.isBlank(realFileName)) {
log.info("reportFileUrl{},对应的文件名称为空",reportFileUrl);
realFileName = fileName;
}
FileInputStream fileInputStream = new FileInputStream(savePath + File.separator + fileName);
byte[] fileData = fileInputStream.readAllBytes();
MockMultipartFile multipartFile = new MockMultipartFile(
realFileName,
realFileName,
"application/octet-stream",
fileData);
UploadFilesReq fileReq = new UploadFilesReq();
fileReq.setFile(multipartFile);
// 传任务uuid
fileReq.setUuid(task.getUuid());
fileReq.setFileName(fileName);
fileReq.setFileTypeDictValue(String.valueOf(FileBizTypeEnum.REPORT_FILE.getValue()));
fileReq.setFileTypeDictClass(FileDictTagEnum.FILE_TYPE.getDictClass());
fileReq.setDictTags(Arrays.asList(FileDictTagEnum.FILE_TYPE.getDictClassFieldName(), FileDictTagEnum.FILE_TYPE.getDictValueFieldName()));
fileReq.setTagReq(tagReq);
if (fileReq.getTagReq() != null) {
fileReq.setTagReqStr(JSON.toJSONString(fileReq.getTagReq()));
}
log.info("手动上传仿真报告到minio的参数为{}",fileReq);
SdmResponse uploadRespond = dataFeignClient.uploadFiles(fileReq);
log.info("手动上传仿真报告到minio的响应值为{}",uploadRespond);
}
SdmResponse uploadRespond = dataFeignClient.uploadFiles(fileReq);
log.info("手动上传仿真报告到minio的响应值为{}",uploadRespond);
} catch (IOException e) {
log.error("手动上传仿真报告到minio的异常{}",e.getMessage());
}finally {

View File

@@ -921,7 +921,7 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
// 查询当前阶段
LyricVProjectToDM lyricVProject = null;
try {
lyricVProject = lyricVProjectToDmService.lambdaQuery()
lyricVProject = lyricVProjectToDmService.lambdaQuery()
.eq(LyricVProjectToDM::getProjectNum, spdmProjectNodeEditReq.getNodeCode())
.one();
} catch (MyBatisSystemException ex) {
@@ -2119,7 +2119,7 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
validateWorkspaces(context.getWorkspaceUuids());
processWorkspaceExtras(context);
executeBatchOperations(context);
// 根据 syncToTask 字段决定是否同步任务扩展属性
if (Boolean.TRUE.equals(req.getSyncToTask())) {
log.info("[batchUpdateWorkspaceExtra] 开启任务扩展属性同步功能");
@@ -2127,11 +2127,11 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
} else {
log.info("[batchUpdateWorkspaceExtra] 未开启任务扩展属性同步功能");
}
String message = Boolean.TRUE.equals(req.getSyncToTask())
? "批量更新工位及任务扩展属性成功"
String message = Boolean.TRUE.equals(req.getSyncToTask())
? "批量更新工位及任务扩展属性成功"
: "批量更新工位扩展属性成功";
log.info("[batchUpdateWorkspaceExtra] {},工位数量={},工位更新数量={},工位新增数量={}",
log.info("[batchUpdateWorkspaceExtra] {},工位数量={},工位更新数量={},工位新增数量={}",
message, context.getWorkspaceUuids().size(), context.getUpdateList().size(), context.getInsertList().size());
return SdmResponse.success(message);
} catch (IllegalArgumentException | IllegalStateException e) {
@@ -2171,13 +2171,13 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
}
// nodeId -> (propertyName -> SimulationNodeExtra)
Map<String, Map<String, SimulationNodeExtra>> existingExtrasMap =
Map<String, Map<String, SimulationNodeExtra>> existingExtrasMap =
simulationNodeExtraService.batchGetNodeExtraMap(workspaceUuids, new ArrayList<>(propertyNames));
Long userId = ThreadLocalContext.getUserId();
String currentTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
UserContext userContext = new UserContext(userId, currentTime);
return new BatchUpdateContext(workspaceExtrasList, workspaceUuids, existingExtrasMap, userContext);
}
@@ -2211,7 +2211,7 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
continue;
}
Map<String, SimulationNodeExtra> workspaceExtras =
Map<String, SimulationNodeExtra> workspaceExtras =
context.getExistingExtrasMap().getOrDefault(workspaceUuid, Collections.emptyMap());
for (BatchUpdateWorkspaceExtraReq.WorkspaceExtraItem extraItem : workspaceData.getExtras()) {
@@ -2254,7 +2254,7 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
int result = nodeMapper.editNodeExtraWithNull(updateReq);
if (result <= 0) {
throw new IllegalStateException(
String.format("更新扩展属性失败 nodeId=%s, propertyName=%s",
String.format("更新扩展属性失败 nodeId=%s, propertyName=%s",
updateReq.getNodeId(), updateReq.getPropertyName()));
}
}
@@ -2284,9 +2284,9 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
private final List<SpdmNodeExtraReq> insertList = new ArrayList<>();
public BatchUpdateContext(List<BatchUpdateWorkspaceExtraReq.WorkspaceExtraData> workspaceExtrasList,
List<String> workspaceUuids,
Map<String, Map<String, SimulationNodeExtra>> existingExtrasMap,
UserContext userContext) {
List<String> workspaceUuids,
Map<String, Map<String, SimulationNodeExtra>> existingExtrasMap,
UserContext userContext) {
this.workspaceExtrasList = workspaceExtrasList;
this.workspaceUuids = workspaceUuids;
this.existingExtrasMap = existingExtrasMap;
@@ -2333,7 +2333,7 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
List<String> taskIds = allTasks.stream()
.map(SimulationTask::getUuid)
.collect(Collectors.toList());
List<String> propertyNames = context.getWorkspaceExtrasList().stream()
.flatMap(data -> data.getExtras().stream())
.map(BatchUpdateWorkspaceExtraReq.WorkspaceExtraItem::getPropertyName)
@@ -2343,34 +2343,34 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
// 3. 批量查询任务已存在的扩展属性,构建映射关系
// taskId -> (propertyName -> TaskExtra) 的嵌套Map
Map<String, Map<String, SimulationTaskExtra>> taskExtrasMap =
Map<String, Map<String, SimulationTaskExtra>> taskExtrasMap =
simulationTaskExtraService.batchGetTaskExtraMap(taskIds, propertyNames);
Map<String, List<SimulationTask>> nodeTasksMap = allTasks.stream()
.collect(Collectors.groupingBy(SimulationTask::getNodeId));
// 4. 构建批量操作数据:遍历工位->任务->属性,区分更新和新增
TaskExtraBatchOperations operations = new TaskExtraBatchOperations(context.getUserContext());
context.getWorkspaceExtrasList().forEach(workspaceData -> {
List<SimulationTask> tasks = nodeTasksMap.getOrDefault(
workspaceData.getWorkspaceUuid(), emptyList());
tasks.forEach(task ->
workspaceData.getExtras().forEach(extraItem -> {
if (StringUtils.isBlank(extraItem.getPropertyName())) {
return;
}
SimulationTaskExtra existingExtra = taskExtrasMap
.getOrDefault(task.getUuid(), Collections.emptyMap())
.get(extraItem.getPropertyName());
SpdmNodeExtraReq taskExtraReq = buildTaskExtraReq(
task.getUuid(), extraItem, existingExtra, operations.getUserContext());
operations.addOperation(taskExtraReq, existingExtra != null);
})
tasks.forEach(task ->
workspaceData.getExtras().forEach(extraItem -> {
if (StringUtils.isBlank(extraItem.getPropertyName())) {
return;
}
SimulationTaskExtra existingExtra = taskExtrasMap
.getOrDefault(task.getUuid(), Collections.emptyMap())
.get(extraItem.getPropertyName());
SpdmNodeExtraReq taskExtraReq = buildTaskExtraReq(
task.getUuid(), extraItem, existingExtra, operations.getUserContext());
operations.addOperation(taskExtraReq, existingExtra != null);
})
);
});
@@ -2399,15 +2399,15 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
* 构建任务扩展属性请求对象
*/
private SpdmNodeExtraReq buildTaskExtraReq(String taskId,
BatchUpdateWorkspaceExtraReq.WorkspaceExtraItem extraItem,
SimulationTaskExtra existingExtra,
UserContext userContext) {
BatchUpdateWorkspaceExtraReq.WorkspaceExtraItem extraItem,
SimulationTaskExtra existingExtra,
UserContext userContext) {
SpdmNodeExtraReq taskExtraReq = new SpdmNodeExtraReq();
taskExtraReq.setNodeId(taskId);
taskExtraReq.setPropertyName(extraItem.getPropertyName());
taskExtraReq.setPropertyValue(StringUtils.isNotBlank(extraItem.getPropertyValue())
taskExtraReq.setPropertyValue(StringUtils.isNotBlank(extraItem.getPropertyValue())
? extraItem.getPropertyValue() : null);
taskExtraReq.setValueType(StringUtils.isNotBlank(extraItem.getValueType())
taskExtraReq.setValueType(StringUtils.isNotBlank(extraItem.getValueType())
? extraItem.getValueType() : "string");
taskExtraReq.setPropertyClass(extraItem.getPropertyClass());
@@ -2985,13 +2985,13 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
.isNotNull(SimulationTask::getDiscipline)
.ne(SimulationTask::getDiscipline, "")
.isNotNull(SimulationTask::getExeStatus);
// 处理 discipline 字段,支持逗号分隔的多个值
if (StringUtils.isNotBlank(req.getDiscipline())) {
String[] disciplines = req.getDiscipline().split(",");
query.in(SimulationTask::getDiscipline, Arrays.asList(disciplines));
}
// 处理 tag1-tag10支持逗号分隔的多个 ID
if (StringUtils.isNotBlank(req.getTag1())) {
String[] tag1Values = req.getTag1().split(",");
@@ -3029,9 +3029,9 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
String[] tag10Values = req.getTag10().split(",");
query.in(SimulationTask::getTag10, Arrays.asList(tag10Values));
}
List<SimulationTask> simulationTasks = query.list();
// 按学科 (discipline) 分组统计任务完成状态
Set<String> allExeStatus = new HashSet<>();
Map<String, CommonStatisticsVo> statisticsMap = buildCommonStatistics(
@@ -3040,7 +3040,7 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
SimulationTask::getExeStatus,
allExeStatus
);
return buildStatisticsResponse(statisticsMap, allExeStatus, "allExeStatus");
}
@@ -3790,9 +3790,12 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
}
// 构建一个需求todoId到resultFileId的映射
Map<Long,String> resultFileIdMap = todoInfoList.stream().collect(Collectors.toMap(LyricVTodoEmulationInfoDM::getTodoId,LyricVTodoEmulationInfoDM::getResultFileId,(oldValue, newValue) -> oldValue));
Map<Long,String> resultFileIdMap = todoInfoList.stream().filter(todoInfo -> StringUtils.isNotBlank(todoInfo.getResultFileId()))
.collect(Collectors.toMap(LyricVTodoEmulationInfoDM::getTodoId,LyricVTodoEmulationInfoDM::getResultFileId,(oldValue, newValue) -> oldValue));
// 构建一个resultFileId到filePath的映射
Map<Integer,String> filePathMap = new HashMap<>();
// 构建一个filePath到fileName的映射
Map<String,String> fileNameMap = new HashMap<>();
// 查询filePath
List<String> resultFileIdStrList = todoInfoList.stream().map(LyricVTodoEmulationInfoDM::getResultFileId).filter(StringUtils::isNotBlank)
.collect(Collectors.toList());
@@ -3814,6 +3817,8 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
.list();
if (CollectionUtils.isNotEmpty(attachmentConfigToDMList)) {
filePathMap = attachmentConfigToDMList.stream().collect(Collectors.toMap(LyricVAttachmentConfigToDM::getId,LyricVAttachmentConfigToDM::getFilePath,(oldValue, newValue) -> oldValue));
fileNameMap = attachmentConfigToDMList.stream().filter(attachment -> StringUtils.isNotBlank(attachment.getFilePath()))
.collect(Collectors.toMap(LyricVAttachmentConfigToDM::getFilePath,LyricVAttachmentConfigToDM::getName,(oldValue, newValue) -> oldValue));
}
}
}
@@ -3846,7 +3851,7 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
demandDirNodeList.add(demandDirNode);
// 4. 异步保存需求和成员信息
saveDemandAndMembersAsync(demandAddReq, memberList, tenantId, currentUserId, usernameToUserIdMap,resultFileIdMap,filePathMap);
saveDemandAndMembersAsync(demandAddReq, memberList, tenantId, currentUserId, usernameToUserIdMap,resultFileIdMap,filePathMap,fileNameMap);
} catch (Exception e) {
log.error("处理待办事项失败待办ID{},错误信息:{}", todoItem.getTodoId(), e.getMessage(), e);
@@ -4125,7 +4130,8 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
Long currentUserId,
Map<String, Long> usernameToUserIdMap,
Map<Long,String> resultFileIdMap,
Map<Integer,String> filePathMap) {
Map<Integer,String> filePathMap,
Map<String,String> fileNameMap) {
CompletableFuture.runAsync(() -> {
try {
ThreadLocalContext.setTenantId(tenantId);
@@ -4154,7 +4160,7 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
simulationTaskService.batchCreateTaskFromDemand(List.of(demand),true);
simulationTaskService.batchCreateTaskFromDemand(List.of(demand),true,fileNameMap);
log.info("异步保存需求成功需求ID{}", demandAddReq.getUuid());
} catch (Exception e) {
log.error("异步保存需求失败需求ID{}", demandAddReq.getUuid(), e);

View File

@@ -2519,12 +2519,13 @@ public class ProjectServiceImpl extends BaseService implements IProjectService {
// 关注人
String attentionMemberList = taskNode.getAMemberList();
req.setCreateTime(curDateStr);
req.setUuid(RandomUtil.generateString(32));
req.setUuid(taskNode.getDemandId());
req.setDemandName(taskNode.getTaskName());
req.setProjectId(String.join(",", taskNode.getTag1()));
req.setPhaseId(String.join(",", taskNode.getTag2()));
req.setMachineId(String.join(",", taskNode.getTag4()));
req.setWorkspaceId(String.join(",", taskNode.getTag5()));
req.setDemandType(DemandTypeEnum.FINITE_ELEMENT_SIMULATION.getName());
req.setSimType(taskNode.getDiscipline());
req.setBeginTime(taskNode.getBeginTime());
req.setEndTime(taskNode.getEndTime());

View File

@@ -142,7 +142,7 @@ public class SimulationTaskServiceImpl extends ServiceImpl<SimulationTaskMapper,
* @param demandList 需求列表
*/
@Override
public void batchCreateTaskFromDemand(List<SimulationDemand> demandList,Boolean isDownloadFlag) {
public void batchCreateTaskFromDemand(List<SimulationDemand> demandList,Boolean isDownloadFlag,Map<String,String> fileNameMap) {
log.info("从需求批量创建任务,需求数量:{}", demandList);
if (CollectionUtils.isEmpty(demandList)) {
return;
@@ -215,6 +215,7 @@ public class SimulationTaskServiceImpl extends ServiceImpl<SimulationTaskMapper,
}
// 批量创建任务目录和更新权限
Map<String, String> finalFileNameMap = fileNameMap;
for (SimulationTask task : tasksToCreate) {
// 任务挂载在workspace工位节点下需要从task的tag中获取workspaceId
String workspaceId = task.getNodeId();
@@ -233,33 +234,44 @@ public class SimulationTaskServiceImpl extends ServiceImpl<SimulationTaskMapper,
if (CollectionUtils.isEmpty(task.getReportFileUrlList())) {
continue;
}
CompletableFuture.runAsync(() -> {
String savePath = REPORT_PATH_PREFIX + task.getUuid();
try {
FilesUtil.downloadFile(task.getReportFileUrlList(), savePath);
// 上传到minio
String fileName = "";
FileInputStream fileInputStream = new FileInputStream(REPORT_PATH_PREFIX + task.getUuid() + File.separator + fileName);
byte[] fileData = fileInputStream.readAllBytes();
MockMultipartFile multipartFile = new MockMultipartFile(
fileName,
fileName,
"application/octet-stream",
fileData);
UploadFilesReq fileReq = new UploadFilesReq();
fileReq.setFile(multipartFile);
// 传任务uuid
fileReq.setUuid(task.getUuid());
fileReq.setFileName(fileName);
fileReq.setFileTypeDictValue(String.valueOf(FileBizTypeEnum.REPORT_FILE.getValue()));
fileReq.setFileTypeDictClass(FileDictTagEnum.FILE_TYPE.getDictClass());
fileReq.setDictTags(Arrays.asList(FileDictTagEnum.FILE_TYPE.getDictClassFieldName(), FileDictTagEnum.FILE_TYPE.getDictValueFieldName()));
fileReq.setTagReq(tagReq);
if (fileReq.getTagReq() != null) {
fileReq.setTagReqStr(JSON.toJSONString(fileReq.getTagReq()));
List<String> reportFileUrlList = task.getReportFileUrlList();
for (String reportFileUrl : reportFileUrlList) {
// 上传到minio
File file = new File(reportFileUrl);
String fileName = file.getName();
String realFileName = finalFileNameMap.get(reportFileUrl);
if (StringUtils.isBlank(realFileName)) {
log.info("reportFileUrl{},对应的文件名称为空",reportFileUrl);
realFileName = fileName;
}
FileInputStream fileInputStream = new FileInputStream(savePath + File.separator + fileName);
byte[] fileData = fileInputStream.readAllBytes();
MockMultipartFile multipartFile = new MockMultipartFile(
realFileName,
realFileName,
"application/octet-stream",
fileData);
UploadFilesReq fileReq = new UploadFilesReq();
fileReq.setFile(multipartFile);
// 传任务uuid
fileReq.setUuid(task.getUuid());
fileReq.setFileName(fileName);
fileReq.setFileTypeDictValue(String.valueOf(FileBizTypeEnum.REPORT_FILE.getValue()));
fileReq.setFileTypeDictClass(FileDictTagEnum.FILE_TYPE.getDictClass());
fileReq.setDictTags(Arrays.asList(FileDictTagEnum.FILE_TYPE.getDictClassFieldName(), FileDictTagEnum.FILE_TYPE.getDictValueFieldName()));
fileReq.setTagReq(tagReq);
if (fileReq.getTagReq() != null) {
fileReq.setTagReqStr(JSON.toJSONString(fileReq.getTagReq()));
}
log.info("上传仿真报告到minio的参数为{}",fileReq);
SdmResponse uploadRespond = dataFeignClient.uploadFiles(fileReq);
log.info("上传仿真报告到minio的响应值为{}",uploadRespond);
}
SdmResponse uploadRespond = dataFeignClient.uploadFiles(fileReq);
log.info("上传仿真报告到minio的响应值为{}",uploadRespond);
} catch (IOException e) {
log.error("上传仿真报告到minio的异常{}",e.getMessage());
}finally {
@@ -418,7 +430,7 @@ public class SimulationTaskServiceImpl extends ServiceImpl<SimulationTaskMapper,
log.error("获取任务workspace标签失败任务UUID{}需求UUID{}", task.getUuid(), task.getDemandId(), e);
throw new RuntimeException("获取任务workspace标签失败任务UUID" + task.getUuid(), e);
}
// 如果没有workspace信息抛出异常
// log.error("任务缺少workspace信息任务UUID{}需求UUID{}tagMap{}",
// task.getUuid(), task.getDemandId(), tagMap);
@@ -441,7 +453,7 @@ public class SimulationTaskServiceImpl extends ServiceImpl<SimulationTaskMapper,
log.info("从需求创建任务时,调用创建文件夹的参数为:{}", createDirReq);
SdmResponse response = dataFeignClient.createDir(createDirReq);
log.info("从需求创建任务时,调用创建文件夹的返回值为:{}", response);
if (!response.isSuccess()) {
log.error("创建任务目录失败任务UUID{}父节点UUID{},错误信息:{}", taskUuid, parentNodeUuid, response.getMessage());
}
@@ -481,30 +493,30 @@ public class SimulationTaskServiceImpl extends ServiceImpl<SimulationTaskMapper,
// 4. 构建批量权限更新请求
List<BatchUpdatePermissionReq.FilePermissionItem> filePermissions = new ArrayList<>();
for (SimulationTask task : tasks) {
Set<Long> userIds = new HashSet<>();
// 添加创建人
if (task.getCreator() != null) {
userIds.add(task.getCreator());
}
// 添加负责人和执行人
List<Long> memberIds = taskMemberMap.get(task.getUuid());
if (CollectionUtils.isNotEmpty(memberIds)) {
userIds.addAll(memberIds);
}
// 构建单个任务的权限配置
if (CollectionUtils.isNotEmpty(userIds)) {
BatchUpdatePermissionReq.FilePermissionItem item = new BatchUpdatePermissionReq.FilePermissionItem();
item.setUuid(task.getUuid());
Map<Long, Byte> userPermissions = new HashMap<>();
userIds.forEach(userId -> userPermissions.put(userId, FilePermissionEnum.ALL.getValue()));
item.setUserPermissions(userPermissions);
filePermissions.add(item);
}
}
@@ -513,11 +525,11 @@ public class SimulationTaskServiceImpl extends ServiceImpl<SimulationTaskMapper,
if (CollectionUtils.isNotEmpty(filePermissions)) {
BatchUpdatePermissionReq batchReq = new BatchUpdatePermissionReq();
batchReq.setFilePermissions(filePermissions);
log.info("从需求批量创建任务时,批量更新权限,任务数量:{}", filePermissions.size());
SdmResponse response = dataFeignClient.batchUpdatePermission(batchReq);
log.info("从需求批量创建任务时,批量更新权限结果:{}", response);
if (!response.isSuccess()) {
log.error("批量更新任务权限失败:{}", response.getMessage());
}
@@ -535,7 +547,7 @@ public class SimulationTaskServiceImpl extends ServiceImpl<SimulationTaskMapper,
private void updateTaskPermissions(SimulationTask task) {
try {
Set<Long> userIds = new HashSet<>();
// 添加创建人
if (task.getCreator() != null) {
userIds.add(task.getCreator());
@@ -544,10 +556,10 @@ public class SimulationTaskServiceImpl extends ServiceImpl<SimulationTaskMapper,
// 添加负责人和执行人
LambdaQueryWrapper<SimulationTaskMember> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SimulationTaskMember::getTaskId, task.getUuid());
queryWrapper.in(SimulationTaskMember::getType,
MemberTypeEnum.PRINCIPAL.getCode(),
queryWrapper.in(SimulationTaskMember::getType,
MemberTypeEnum.PRINCIPAL.getCode(),
MemberTypeEnum.EXECUTOR.getCode());
List<SimulationTaskMember> members = simulationTaskMemberService.list(queryWrapper);
if (CollectionUtils.isNotEmpty(members)) {
members.forEach(member -> userIds.add(member.getUserId()));
@@ -559,11 +571,11 @@ public class SimulationTaskServiceImpl extends ServiceImpl<SimulationTaskMapper,
UpdatePermissionReq updatePermissionReq = new UpdatePermissionReq();
updatePermissionReq.setUserId(userId);
updatePermissionReq.setUuid(task.getUuid());
Map<Long, Byte> userPermissions = new HashMap<>();
userPermissions.put(userId, FilePermissionEnum.ALL.getValue());
updatePermissionReq.setUserPermissions(userPermissions);
log.info("从需求创建任务时,更新用户权限的参数为:{}", updatePermissionReq);
SdmResponse updatePermissionResponse = dataFeignClient.updatePermission(updatePermissionReq);
log.info("从需求创建任务时,更新用户权限的返回值为:{}", updatePermissionResponse);