fix:优化流程需求同步创建任务
This commit is contained in:
@@ -225,6 +225,19 @@ public class DataClientFeignClientImpl implements IDataFeignClient {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SdmResponse batchUpdatePermission(BatchUpdatePermissionReq req) {
|
||||
SdmResponse response;
|
||||
try {
|
||||
response = dataClient.batchUpdatePermission(req);
|
||||
log.info("批量更新权限成功:{}", response);
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
log.error("批量更新权限失败", e);
|
||||
return SdmResponse.failed("批量更新权限失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SdmResponse<List<FileMetadataInfoResp>> queryFileListByIdList(QueryFileReq queryFileReq) {
|
||||
SdmResponse response;
|
||||
|
||||
@@ -89,6 +89,9 @@ public interface IDataFeignClient {
|
||||
@PostMapping("/data/updatePermission")
|
||||
SdmResponse updatePermission(@RequestBody UpdatePermissionReq req);
|
||||
|
||||
@PostMapping("/data/batchUpdatePermission")
|
||||
SdmResponse batchUpdatePermission(@RequestBody BatchUpdatePermissionReq req);
|
||||
|
||||
@PostMapping("/data/queryFileListByIdList")
|
||||
SdmResponse<List<FileMetadataInfoResp>> queryFileListByIdList(@RequestBody QueryFileReq queryFileReq);
|
||||
|
||||
|
||||
@@ -215,6 +215,19 @@ public class DataFileController implements IDataFeignClient {
|
||||
return IDataFileService.updatePermission(req);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新文件权限
|
||||
*
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@SysLog("批量更新文件权限")
|
||||
@PostMapping("/batchUpdatePermission")
|
||||
@Operation(summary = "批量更新文件权限", description = "批量更新多个文件的用户权限(优化版)")
|
||||
public SdmResponse batchUpdatePermission(@RequestBody @Validated BatchUpdatePermissionReq req) {
|
||||
return IDataFileService.batchUpdatePermission(req);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件用户的综合访问权限,该权限可以从祖先继承
|
||||
*
|
||||
|
||||
@@ -152,6 +152,15 @@ public interface IDataFileService {
|
||||
*/
|
||||
SdmResponse updatePermission(UpdatePermissionReq req);
|
||||
|
||||
/**
|
||||
* 批量更新文件权限(优化版,支持多文件批量操作)
|
||||
* @param req 批量更新权限请求参数
|
||||
* @return 更新结果响应
|
||||
*/
|
||||
default SdmResponse batchUpdatePermission(BatchUpdatePermissionReq req) {
|
||||
return SdmResponse.failed("该实现未支持批量更新权限功能");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化系统目录
|
||||
|
||||
@@ -986,50 +986,212 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SdmResponse updatePermission(UpdatePermissionReq req) {
|
||||
Map<Long, Byte> userPermissions = req.getUserPermissions();
|
||||
if (ObjectUtils.isEmpty(userPermissions)) return SdmResponse.failed("参数错误,缺少userPermissions参数");
|
||||
|
||||
Long fileId = req.getFileId();
|
||||
FileMetadataInfo fileMetadataInfo = null;
|
||||
if(ObjectUtils.isNotEmpty(fileId)){
|
||||
fileMetadataInfo = fileMetadataInfoService.lambdaQuery().eq(FileMetadataInfo::getId, fileId).one();
|
||||
}else if (ObjectUtils.isNotEmpty(req.getUuid())) {
|
||||
fileMetadataInfo = fileMetadataInfoService.lambdaQuery().eq(FileMetadataInfo::getRelatedResourceUuid, req.getUuid()).one();
|
||||
if (fileMetadataInfo == null) {
|
||||
return SdmResponse.failed("根据UUID未找到对应的文件");
|
||||
}
|
||||
fileId = fileMetadataInfo.getId();
|
||||
if (ObjectUtils.isEmpty(userPermissions)) {
|
||||
return SdmResponse.failed("参数错误,缺少userPermissions参数");
|
||||
}
|
||||
|
||||
if (fileMetadataInfo == null) {
|
||||
// 1. 获取文件ID
|
||||
Long fileId = getFileIdFromRequest(req);
|
||||
if (fileId == null) {
|
||||
return SdmResponse.failed("文件不存在");
|
||||
}
|
||||
|
||||
Long finalFileId = fileId;
|
||||
// 2. 批量查询现有权限(一次查询)
|
||||
List<FileUserPermission> existingPermissions = fileUserPermissionService.lambdaQuery()
|
||||
.eq(FileUserPermission::getTFilemetaId, fileId)
|
||||
.in(FileUserPermission::getUserId, userPermissions.keySet())
|
||||
.list();
|
||||
|
||||
// 3. 构建现有用户ID集合
|
||||
Set<Long> existingUserIds = existingPermissions.stream()
|
||||
.map(FileUserPermission::getUserId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// 4. 分离更新和新增
|
||||
List<FileUserPermission> toUpdate = new ArrayList<>();
|
||||
List<FileUserPermission> toInsert = new ArrayList<>();
|
||||
Long tenantId = ThreadLocalContext.getTenantId();
|
||||
|
||||
userPermissions.forEach((userId, permission) -> {
|
||||
FileUserPermission one = fileUserPermissionService.lambdaQuery()
|
||||
.eq(FileUserPermission::getTFilemetaId, finalFileId)
|
||||
.eq(FileUserPermission::getUserId, userId)
|
||||
.one();
|
||||
if (one != null) {
|
||||
//更新权限
|
||||
fileUserPermissionService.lambdaUpdate()
|
||||
.set(FileUserPermission::getPermission, permission)
|
||||
.eq(FileUserPermission::getUserId, userId)
|
||||
.eq(FileUserPermission::getTFilemetaId, finalFileId)
|
||||
.update();
|
||||
if (existingUserIds.contains(userId)) {
|
||||
// 需要更新
|
||||
FileUserPermission update = existingPermissions.stream()
|
||||
.filter(p -> p.getUserId().equals(userId))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (update != null) {
|
||||
update.setPermission(permission);
|
||||
toUpdate.add(update);
|
||||
}
|
||||
} else {
|
||||
// 新增权限
|
||||
FileUserPermission fileUserPermission = new FileUserPermission();
|
||||
fileUserPermission.setTFilemetaId(finalFileId);
|
||||
fileUserPermission.setUserId(userId);
|
||||
fileUserPermission.setTenantId(ThreadLocalContext.getTenantId());
|
||||
fileUserPermission.setPermission(permission);
|
||||
fileUserPermissionService.save(fileUserPermission);
|
||||
// 需要新增
|
||||
FileUserPermission insert = new FileUserPermission();
|
||||
insert.setTFilemetaId(fileId);
|
||||
insert.setUserId(userId);
|
||||
insert.setTenantId(tenantId);
|
||||
insert.setPermission(permission);
|
||||
toInsert.add(insert);
|
||||
}
|
||||
});
|
||||
|
||||
// 5. 批量更新和插入
|
||||
if (CollectionUtils.isNotEmpty(toUpdate)) {
|
||||
fileUserPermissionService.updateBatchById(toUpdate);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(toInsert)) {
|
||||
fileUserPermissionService.saveBatch(toInsert);
|
||||
}
|
||||
|
||||
return SdmResponse.success("更新权限成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 从请求中获取文件ID
|
||||
*/
|
||||
private Long getFileIdFromRequest(UpdatePermissionReq req) {
|
||||
Long fileId = req.getFileId();
|
||||
if (ObjectUtils.isNotEmpty(fileId)) {
|
||||
FileMetadataInfo fileMetadataInfo = fileMetadataInfoService.lambdaQuery()
|
||||
.eq(FileMetadataInfo::getId, fileId)
|
||||
.one();
|
||||
return fileMetadataInfo != null ? fileMetadataInfo.getId() : null;
|
||||
}
|
||||
|
||||
if (ObjectUtils.isNotEmpty(req.getUuid())) {
|
||||
FileMetadataInfo fileMetadataInfo = fileMetadataInfoService.lambdaQuery()
|
||||
.eq(FileMetadataInfo::getRelatedResourceUuid, req.getUuid())
|
||||
.one();
|
||||
return fileMetadataInfo != null ? fileMetadataInfo.getId() : null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SdmResponse batchUpdatePermission(BatchUpdatePermissionReq req) {
|
||||
if (req == null || CollectionUtils.isEmpty(req.getFilePermissions())) {
|
||||
return SdmResponse.failed("文件权限列表不能为空");
|
||||
}
|
||||
|
||||
try {
|
||||
// 1. 构建文件权限映射 Map<fileId, Map<userId, permission>>
|
||||
Map<Long, Map<Long, Byte>> filePermissionMap = buildFilePermissionMap(req);
|
||||
if (filePermissionMap.isEmpty()) {
|
||||
return SdmResponse.failed("未找到有效的文件");
|
||||
}
|
||||
|
||||
// 2. 批量查询现有权限(一次查询所有文件的所有用户权限)
|
||||
Set<Long> allFileIds = filePermissionMap.keySet();
|
||||
Set<Long> allUserIds = filePermissionMap.values().stream()
|
||||
.flatMap(map -> map.keySet().stream())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
List<FileUserPermission> existingPermissions = fileUserPermissionService.lambdaQuery()
|
||||
.in(FileUserPermission::getTFilemetaId, allFileIds)
|
||||
.in(FileUserPermission::getUserId, allUserIds)
|
||||
.list();
|
||||
|
||||
// 3. 构建现有权限的索引 Map<fileId_userId, FileUserPermission>
|
||||
Map<String, FileUserPermission> existingPermissionIndex = existingPermissions.stream()
|
||||
.collect(Collectors.toMap(
|
||||
p -> p.getTFilemetaId() + "_" + p.getUserId(),
|
||||
p -> p
|
||||
));
|
||||
|
||||
// 4. 分离更新和新增列表
|
||||
List<FileUserPermission> toUpdate = new ArrayList<>();
|
||||
List<FileUserPermission> toInsert = new ArrayList<>();
|
||||
Long tenantId = ThreadLocalContext.getTenantId();
|
||||
|
||||
filePermissionMap.forEach((fileId, userPerms) -> {
|
||||
userPerms.forEach((userId, permission) -> {
|
||||
String key = fileId + "_" + userId;
|
||||
FileUserPermission existing = existingPermissionIndex.get(key);
|
||||
|
||||
if (existing != null) {
|
||||
// 需要更新
|
||||
existing.setPermission(permission);
|
||||
toUpdate.add(existing);
|
||||
} else {
|
||||
// 需要新增
|
||||
FileUserPermission insert = new FileUserPermission();
|
||||
insert.setTFilemetaId(fileId);
|
||||
insert.setUserId(userId);
|
||||
insert.setTenantId(tenantId);
|
||||
insert.setPermission(permission);
|
||||
toInsert.add(insert);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 5. 批量执行更新和插入(两次数据库操作)
|
||||
int updateCount = 0, insertCount = 0;
|
||||
if (CollectionUtils.isNotEmpty(toUpdate)) {
|
||||
fileUserPermissionService.updateBatchById(toUpdate);
|
||||
updateCount = toUpdate.size();
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(toInsert)) {
|
||||
fileUserPermissionService.saveBatch(toInsert);
|
||||
insertCount = toInsert.size();
|
||||
}
|
||||
|
||||
log.info("批量更新权限成功,更新{}\u6761,新增{}\u6761", updateCount, insertCount);
|
||||
return SdmResponse.success("批量更新权限成功");
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("批量更新权限失败", e);
|
||||
throw new RuntimeException("批量更新权限失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建文件权限映射 Map<fileId, Map<userId, permission>>
|
||||
*/
|
||||
private Map<Long, Map<Long, Byte>> buildFilePermissionMap(BatchUpdatePermissionReq req) {
|
||||
Map<Long, Map<Long, Byte>> filePermissionMap = new HashMap<>();
|
||||
|
||||
// 收集所有uuid用于批量查询
|
||||
List<String> uuids = req.getFilePermissions().stream()
|
||||
.filter(item -> ObjectUtils.isEmpty(item.getFileId()) && StringUtils.hasText(item.getUuid()))
|
||||
.map(BatchUpdatePermissionReq.FilePermissionItem::getUuid)
|
||||
.distinct()
|
||||
.toList();
|
||||
|
||||
// 批量查询uuid对应的fileId
|
||||
Map<String, Long> uuidToFileIdMap = new HashMap<>();
|
||||
if (CollectionUtils.isNotEmpty(uuids)) {
|
||||
List<FileMetadataInfo> fileMetadataInfos = fileMetadataInfoService.lambdaQuery()
|
||||
.in(FileMetadataInfo::getRelatedResourceUuid, uuids)
|
||||
.list();
|
||||
uuidToFileIdMap = fileMetadataInfos.stream()
|
||||
.collect(Collectors.toMap(
|
||||
FileMetadataInfo::getRelatedResourceUuid,
|
||||
FileMetadataInfo::getId
|
||||
));
|
||||
}
|
||||
|
||||
// 构建最终的映射关系
|
||||
for (BatchUpdatePermissionReq.FilePermissionItem item : req.getFilePermissions()) {
|
||||
if (MapUtils.isEmpty(item.getUserPermissions())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Long fileId = item.getFileId();
|
||||
if (fileId == null && StringUtils.hasText(item.getUuid())) {
|
||||
fileId = uuidToFileIdMap.get(item.getUuid());
|
||||
}
|
||||
|
||||
if (fileId != null) {
|
||||
filePermissionMap.put(fileId, item.getUserPermissions());
|
||||
} else {
|
||||
log.warn("未找到文件:fileId={}, uuid={}", item.getFileId(), item.getUuid());
|
||||
}
|
||||
}
|
||||
|
||||
return filePermissionMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SdmResponse fileExists(String path) {
|
||||
String filePath = getDirMinioObjectKey(path);
|
||||
|
||||
@@ -3136,10 +3136,16 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
|
||||
Long currentUserId) {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
ThreadLocalContext.setTenantId(tenantId);
|
||||
ThreadLocalContext.setUserId(currentUserId);
|
||||
demandMapper.addDemand(demandAddReq, tenantId, currentUserId);
|
||||
if (CollectionUtils.isNotEmpty(memberList)) {
|
||||
demandMapper.addDemandMember(memberList);
|
||||
}
|
||||
|
||||
SimulationDemand demand = new SimulationDemand();
|
||||
BeanUtils.copyProperties(demandAddReq, demand);
|
||||
simulationTaskService.batchCreateTaskFromDemand(List.of(demand));
|
||||
log.info("异步保存需求成功,需求ID:{}", demandAddReq.getUuid());
|
||||
} catch (Exception e) {
|
||||
log.error("异步保存需求失败,需求ID:{}", demandAddReq.getUuid(), e);
|
||||
|
||||
@@ -5,14 +5,22 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.sdm.common.common.SdmResponse;
|
||||
import com.sdm.common.common.ThreadLocalContext;
|
||||
import com.sdm.common.entity.enums.DirTypeEnum;
|
||||
import com.sdm.common.entity.enums.FilePermissionEnum;
|
||||
import com.sdm.common.entity.enums.NodeTypeEnum;
|
||||
import com.sdm.common.entity.req.data.BatchUpdatePermissionReq;
|
||||
import com.sdm.common.entity.req.data.CreateDirReq;
|
||||
import com.sdm.common.entity.req.data.UpdatePermissionReq;
|
||||
import com.sdm.common.feign.inter.data.IDataFeignClient;
|
||||
import com.sdm.common.utils.RandomUtil;
|
||||
import com.sdm.project.common.MemberTypeEnum;
|
||||
import com.sdm.project.dao.SimulationTaskAttentionMapper;
|
||||
import com.sdm.project.model.bo.TaskExtraNode;
|
||||
import com.sdm.project.model.bo.TaskNode;
|
||||
import com.sdm.project.model.entity.SimulationNode;
|
||||
import com.sdm.project.model.entity.SimulationTask;
|
||||
import com.sdm.project.dao.SimulationTaskMapper;
|
||||
import com.sdm.project.model.entity.SimulationTaskAttention;
|
||||
import com.sdm.project.model.entity.SimulationTaskMember;
|
||||
import com.sdm.project.model.req.SpdmEditNodeForDataReq;
|
||||
import com.sdm.project.model.req.SpdmEditTaskForDataReq;
|
||||
@@ -22,12 +30,14 @@ import com.sdm.project.service.ISimulationTaskService;
|
||||
import com.sdm.project.service.ISimulationDemandExtraService;
|
||||
import com.sdm.project.service.ISimulationDemandMemberService;
|
||||
import com.sdm.project.service.ISimulationTaskExtraService;
|
||||
import com.sdm.project.service.ISimulationTaskAttentionService;
|
||||
import com.sdm.common.service.TagMapService;
|
||||
import com.sdm.project.model.entity.SimulationDemand;
|
||||
import com.sdm.project.model.entity.SimulationDemandExtra;
|
||||
import com.sdm.project.model.entity.SimulationDemandMember;
|
||||
import com.sdm.project.model.entity.SimulationTaskExtra;
|
||||
import com.sdm.common.enums.DemandMemberTypeEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import java.util.stream.Collectors;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
@@ -49,6 +59,7 @@ import java.util.stream.Collectors;
|
||||
* @author author
|
||||
* @since 2025-11-03
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SimulationTaskServiceImpl extends ServiceImpl<SimulationTaskMapper, SimulationTask> implements ISimulationTaskService {
|
||||
|
||||
@@ -64,9 +75,15 @@ public class SimulationTaskServiceImpl extends ServiceImpl<SimulationTaskMapper,
|
||||
@Autowired
|
||||
private ISimulationTaskExtraService simulationTaskExtraService;
|
||||
|
||||
@Autowired
|
||||
private ISimulationTaskAttentionService simulationTaskAttentionService;
|
||||
|
||||
@Autowired
|
||||
private TagMapService tagMapService;
|
||||
|
||||
@Autowired
|
||||
private IDataFeignClient dataFeignClient;
|
||||
|
||||
@Override
|
||||
public boolean updateSimulationTask(SpdmTaskOprReq req) {
|
||||
LambdaUpdateWrapper<SimulationTask> wrapper = new LambdaUpdateWrapper<>();
|
||||
@@ -138,6 +155,7 @@ public class SimulationTaskServiceImpl extends ServiceImpl<SimulationTaskMapper,
|
||||
List<SimulationTask> tasksToCreate = new ArrayList<>();
|
||||
List<SimulationTaskExtra> taskExtrasToCreate = new ArrayList<>();
|
||||
List<SimulationTaskMember> taskMembersToCreate = new ArrayList<>();
|
||||
List<SimulationTaskAttention> taskAttentionsToCreate = new ArrayList<>();
|
||||
|
||||
Map<String, String> tagMap = tagMapService.getTagMapName();
|
||||
|
||||
@@ -147,11 +165,30 @@ public class SimulationTaskServiceImpl extends ServiceImpl<SimulationTaskMapper,
|
||||
|
||||
taskExtrasToCreate.addAll(createTaskExtras(demand, task.getUuid()));
|
||||
taskMembersToCreate.addAll(createTaskMembers(demand, task.getUuid()));
|
||||
taskAttentionsToCreate.addAll(createTaskAttentions(demand, task.getUuid()));
|
||||
}
|
||||
|
||||
// 批量保存任务主表、扩展表、成员表、关注表
|
||||
this.saveBatch(tasksToCreate);
|
||||
simulationTaskExtraService.saveBatch(taskExtrasToCreate);
|
||||
simulationTaskMemberService.saveBatch(taskMembersToCreate);
|
||||
if (CollectionUtils.isNotEmpty(taskExtrasToCreate)) {
|
||||
simulationTaskExtraService.saveBatch(taskExtrasToCreate);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(taskMembersToCreate)) {
|
||||
simulationTaskMemberService.saveBatch(taskMembersToCreate);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(taskAttentionsToCreate)) {
|
||||
simulationTaskAttentionService.saveBatch(taskAttentionsToCreate);
|
||||
}
|
||||
|
||||
// 批量创建任务目录和更新权限
|
||||
for (SimulationTask task : tasksToCreate) {
|
||||
// 任务挂载在workspace工位节点下,需要从task的tag中获取workspaceId
|
||||
String workspaceId = getWorkspaceIdFromTask(task, tagMap);
|
||||
createTaskDir(task.getUuid(), workspaceId, task.getTaskName());
|
||||
}
|
||||
|
||||
// 批量更新任务权限(使用批量接口)
|
||||
batchUpdateTaskPermissions(tasksToCreate);
|
||||
}
|
||||
|
||||
private SimulationTask convertDemandToTask(SimulationDemand demand, Map<String, String> tagMap) {
|
||||
@@ -242,10 +279,207 @@ public class SimulationTaskServiceImpl extends ServiceImpl<SimulationTaskMapper,
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建任务关注人列表(从需求关注人复制)
|
||||
*/
|
||||
private List<SimulationTaskAttention> createTaskAttentions(SimulationDemand demand, String taskUuid) {
|
||||
LambdaQueryWrapper<SimulationDemandMember> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SimulationDemandMember::getDemandId, demand.getUuid());
|
||||
queryWrapper.eq(SimulationDemandMember::getType, DemandMemberTypeEnum.FOLLOWER.getCode());
|
||||
|
||||
List<SimulationDemandMember> attentionMembers = simulationDemandMemberService.list(queryWrapper);
|
||||
|
||||
if (CollectionUtils.isEmpty(attentionMembers)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
String currentTime = DateUtil.now();
|
||||
Long currentUserId = ThreadLocalContext.getUserId();
|
||||
|
||||
return attentionMembers.stream().map(attentionMember -> {
|
||||
SimulationTaskAttention taskAttention = new SimulationTaskAttention();
|
||||
taskAttention.setTaskId(taskUuid);
|
||||
taskAttention.setUserId(attentionMember.getUserId());
|
||||
taskAttention.setCreator(String.valueOf(currentUserId));
|
||||
taskAttention.setCreateTime(currentTime);
|
||||
return taskAttention;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 从任务的tag中获取workspaceId(任务挂载的父节点)
|
||||
* @throws RuntimeException 如果无法获取workspace信息
|
||||
*/
|
||||
private String getWorkspaceIdFromTask(SimulationTask task, Map<String, String> tagMap) {
|
||||
try {
|
||||
// 如果tagMap包含workspace映射,则从task的对应tag字段获取workspaceId
|
||||
if (tagMap.containsKey(NodeTypeEnum.WORKSPACE.getValue())) {
|
||||
String tagName = tagMap.get(NodeTypeEnum.WORKSPACE.getValue());
|
||||
// 通过反射获取tag字段的值
|
||||
String workspaceId = (String) task.getClass()
|
||||
.getMethod("get" + StringUtils.capitalize(tagName))
|
||||
.invoke(task);
|
||||
if (StringUtils.isNotBlank(workspaceId)) {
|
||||
return workspaceId;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
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);
|
||||
throw new RuntimeException("任务缺少workspace信息,无法创建任务目录,任务UUID:" + task.getUuid());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建任务目录
|
||||
*/
|
||||
private void createTaskDir(String taskUuid, String parentNodeUuid, String taskName) {
|
||||
try {
|
||||
CreateDirReq createDirReq = new CreateDirReq();
|
||||
createDirReq.setUuId(taskUuid);
|
||||
createDirReq.setParentUuId(parentNodeUuid); // 任务文件夹挂在workspace工位节点下
|
||||
createDirReq.setUuIdOwnType(NodeTypeEnum.TASK.getValue());
|
||||
createDirReq.setDirName(taskName);
|
||||
createDirReq.setDirType(DirTypeEnum.PROJECT_NODE_DIR.getValue());
|
||||
|
||||
log.info("从需求创建任务时,调用创建文件夹的参数为:{}", createDirReq);
|
||||
SdmResponse response = dataFeignClient.createDir(createDirReq);
|
||||
log.info("从需求创建任务时,调用创建文件夹的返回值为:{}", response);
|
||||
|
||||
if (!response.isSuccess()) {
|
||||
log.error("创建任务目录失败,任务UUID:{},父节点UUID:{},错误信息:{}", taskUuid, parentNodeUuid, response.getMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("创建任务目录异常,任务UUID:{},父节点UUID:{}", taskUuid, parentNodeUuid, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新任务权限(使用批量接口)
|
||||
*/
|
||||
private void batchUpdateTaskPermissions(List<SimulationTask> tasks) {
|
||||
if (CollectionUtils.isEmpty(tasks)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 1. 收集所有任务的UUID
|
||||
List<String> taskUuids = tasks.stream()
|
||||
.map(SimulationTask::getUuid)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 2. 批量查询所有任务的成员(负责人、执行人)
|
||||
LambdaQueryWrapper<SimulationTaskMember> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.in(SimulationTaskMember::getTaskId, taskUuids);
|
||||
queryWrapper.in(SimulationTaskMember::getType,
|
||||
MemberTypeEnum.PRINCIPAL.getCode(),
|
||||
MemberTypeEnum.EXECUTOR.getCode());
|
||||
List<SimulationTaskMember> allMembers = simulationTaskMemberService.list(queryWrapper);
|
||||
|
||||
// 3. 构建 taskUuid -> 成员userId列表 的映射
|
||||
Map<String, List<Long>> taskMemberMap = allMembers.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
SimulationTaskMember::getTaskId,
|
||||
Collectors.mapping(SimulationTaskMember::getUserId, Collectors.toList())
|
||||
));
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 执行批量更新
|
||||
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());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("批量更新任务权限异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新任务相关人员的权限(创建人、负责人、执行人)
|
||||
* @deprecated 请使用 batchUpdateTaskPermissions 批量更新
|
||||
*/
|
||||
@Deprecated
|
||||
private void updateTaskPermissions(SimulationTask task) {
|
||||
try {
|
||||
Set<Long> userIds = new HashSet<>();
|
||||
|
||||
// 添加创建人
|
||||
if (task.getCreator() != null) {
|
||||
userIds.add(task.getCreator());
|
||||
}
|
||||
|
||||
// 添加负责人和执行人
|
||||
LambdaQueryWrapper<SimulationTaskMember> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SimulationTaskMember::getTaskId, task.getUuid());
|
||||
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()));
|
||||
}
|
||||
|
||||
// 批量更新权限
|
||||
if (CollectionUtils.isNotEmpty(userIds)) {
|
||||
for (Long userId : userIds) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("更新任务权限异常,任务UUID:{}", task.getUuid(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user