|
|
|
@ -2,6 +2,7 @@ package org.dromara.workflow.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
|
|
|
import cn.hutool.core.lang.Pair;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
@ -21,6 +22,7 @@ import org.dromara.warm.flow.ui.dto.HandlerFunDto;
|
|
|
|
import org.dromara.warm.flow.ui.dto.HandlerQuery;
|
|
|
|
import org.dromara.warm.flow.ui.dto.HandlerQuery;
|
|
|
|
import org.dromara.warm.flow.ui.dto.TreeFunDto;
|
|
|
|
import org.dromara.warm.flow.ui.dto.TreeFunDto;
|
|
|
|
import org.dromara.warm.flow.ui.service.HandlerSelectService;
|
|
|
|
import org.dromara.warm.flow.ui.service.HandlerSelectService;
|
|
|
|
|
|
|
|
import org.dromara.warm.flow.ui.vo.HandlerFeedBackVo;
|
|
|
|
import org.dromara.warm.flow.ui.vo.HandlerSelectVo;
|
|
|
|
import org.dromara.warm.flow.ui.vo.HandlerSelectVo;
|
|
|
|
import org.dromara.workflow.common.ConditionalOnEnable;
|
|
|
|
import org.dromara.workflow.common.ConditionalOnEnable;
|
|
|
|
import org.dromara.workflow.common.enums.TaskAssigneeEnum;
|
|
|
|
import org.dromara.workflow.common.enums.TaskAssigneeEnum;
|
|
|
|
@ -79,6 +81,49 @@ public class FlwTaskAssigneeServiceImpl implements IFlwTaskAssigneeService, Hand
|
|
|
|
return getHandlerSelectVo(buildHandlerData(dto, type), buildDeptTree(depts));
|
|
|
|
return getHandlerSelectVo(buildHandlerData(dto, type), buildDeptTree(depts));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 办理人权限名称回显
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param storageIds 入库主键集合
|
|
|
|
|
|
|
|
* @return 结果
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<HandlerFeedBackVo> handlerFeedback(List<String> storageIds) {
|
|
|
|
|
|
|
|
if (CollUtil.isEmpty(storageIds)) {
|
|
|
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 解析并归类 ID,同时记录原始顺序和对应解析结果
|
|
|
|
|
|
|
|
Map<TaskAssigneeEnum, List<Long>> typeIdMap = new EnumMap<>(TaskAssigneeEnum.class);
|
|
|
|
|
|
|
|
Map<String, Pair<TaskAssigneeEnum, Long>> parsedMap = new LinkedHashMap<>();
|
|
|
|
|
|
|
|
for (String storageId : storageIds) {
|
|
|
|
|
|
|
|
Pair<TaskAssigneeEnum, Long> parsed = this.parseStorageId(storageId);
|
|
|
|
|
|
|
|
parsedMap.put(storageId, parsed);
|
|
|
|
|
|
|
|
if (parsed != null) {
|
|
|
|
|
|
|
|
typeIdMap.computeIfAbsent(parsed.getKey(), k -> new ArrayList<>()).add(parsed.getValue());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查询所有类型对应的 ID 名称映射
|
|
|
|
|
|
|
|
Map<TaskAssigneeEnum, Map<Long, String>> nameMap = new EnumMap<>(TaskAssigneeEnum.class);
|
|
|
|
|
|
|
|
typeIdMap.forEach((type, ids) -> nameMap.put(type, this.getNamesByType(type, ids)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 组装返回结果,保持原始顺序
|
|
|
|
|
|
|
|
return parsedMap.entrySet().stream()
|
|
|
|
|
|
|
|
.map(entry -> {
|
|
|
|
|
|
|
|
String storageId = entry.getKey();
|
|
|
|
|
|
|
|
Pair<TaskAssigneeEnum, Long> parsed = entry.getValue();
|
|
|
|
|
|
|
|
String handlerName = "格式错误";
|
|
|
|
|
|
|
|
if (parsed != null) {
|
|
|
|
|
|
|
|
Map<Long, String> nameMapping = nameMap.getOrDefault(parsed.getKey(), Collections.emptyMap());
|
|
|
|
|
|
|
|
handlerName = nameMapping.getOrDefault(parsed.getValue(), "未知名称");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
HandlerFeedBackVo backVo = new HandlerFeedBackVo();
|
|
|
|
|
|
|
|
backVo.setStorageId(storageId);
|
|
|
|
|
|
|
|
backVo.setHandlerName(handlerName);
|
|
|
|
|
|
|
|
return backVo;
|
|
|
|
|
|
|
|
}).toList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 根据任务办理类型查询对应的数据
|
|
|
|
* 根据任务办理类型查询对应的数据
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ -88,7 +133,6 @@ public class FlwTaskAssigneeServiceImpl implements IFlwTaskAssigneeService, Hand
|
|
|
|
case ROLE -> remoteTaskAssigneeService.selectRolesByTaskAssigneeList(taskQuery);
|
|
|
|
case ROLE -> remoteTaskAssigneeService.selectRolesByTaskAssigneeList(taskQuery);
|
|
|
|
case DEPT -> remoteTaskAssigneeService.selectDeptsByTaskAssigneeList(taskQuery);
|
|
|
|
case DEPT -> remoteTaskAssigneeService.selectDeptsByTaskAssigneeList(taskQuery);
|
|
|
|
case POST -> remoteTaskAssigneeService.selectPostsByTaskAssigneeList(taskQuery);
|
|
|
|
case POST -> remoteTaskAssigneeService.selectPostsByTaskAssigneeList(taskQuery);
|
|
|
|
default -> throw new ServiceException("Unsupported handler type");
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -129,33 +173,41 @@ public class FlwTaskAssigneeServiceImpl implements IFlwTaskAssigneeService, Hand
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 根据存储标识符(storageId)解析分配类型和ID,并获取对应的用户列表
|
|
|
|
* 根据存储标识符(storageId)解析分配类型和ID,并获取对应的用户列表
|
|
|
|
|
|
|
|
* 支持单个标识(例如 "user:123" 或 "456"),格式非法将返回空列表
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param storageId 包含分配类型和ID的字符串(例如 "user:123" 或 "role:456")
|
|
|
|
* @param storageId 包含分配类型和ID的字符串
|
|
|
|
* @return 与分配类型和ID匹配的用户列表,如果格式无效则返回空列表
|
|
|
|
* @return 匹配的用户列表,格式非法返回空列表
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<RemoteUserVo> fetchUsersByStorageId(String storageId) {
|
|
|
|
public List<RemoteUserVo> fetchUsersByStorageId(String storageId) {
|
|
|
|
List<RemoteUserVo> list = new ArrayList<>();
|
|
|
|
Pair<TaskAssigneeEnum, Long> parsed = this.parseStorageId(storageId);
|
|
|
|
Map<TaskAssigneeEnum, List<Long>> typeIdMap = new EnumMap<>(TaskAssigneeEnum.class);
|
|
|
|
if (parsed == null) {
|
|
|
|
for (String str : storageId.split(StrUtil.COMMA)) {
|
|
|
|
return Collections.emptyList();
|
|
|
|
String[] parts = str.split(StrUtil.COLON, 2);
|
|
|
|
|
|
|
|
TaskAssigneeEnum type;
|
|
|
|
|
|
|
|
Long id;
|
|
|
|
|
|
|
|
if (parts.length < 2) {
|
|
|
|
|
|
|
|
// 无前缀时默认是用户类型
|
|
|
|
|
|
|
|
type = TaskAssigneeEnum.USER;
|
|
|
|
|
|
|
|
id = Long.valueOf(parts[0]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 根据前缀解析类型(如 "role:123" -> ROLE 类型)
|
|
|
|
|
|
|
|
type = TaskAssigneeEnum.fromCode(parts[0] + StrUtil.COLON);
|
|
|
|
|
|
|
|
id = Long.valueOf(parts[1]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
typeIdMap.computeIfAbsent(type, k -> new ArrayList<>()).add(id);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
typeIdMap.entrySet().stream()
|
|
|
|
return this.getUsersByType(parsed.getKey(), Collections.singletonList(parsed.getValue()));
|
|
|
|
.filter(entry -> CollUtil.isNotEmpty(entry.getValue()))
|
|
|
|
}
|
|
|
|
.forEach(entry -> list.addAll(getUsersByType(entry.getKey(), entry.getValue())));
|
|
|
|
|
|
|
|
return list.stream().distinct().toList();
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 批量解析多个存储标识符(storageIds),按类型分类并合并查询用户列表
|
|
|
|
|
|
|
|
* 输入格式支持多个以逗号分隔的标识(如 "user:123,role:456,789")
|
|
|
|
|
|
|
|
* 会自动去重返回结果,非法格式的标识将被忽略
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param storageIds 多个存储标识符字符串(逗号分隔)
|
|
|
|
|
|
|
|
* @return 合并后的用户列表,去重后返回,非法格式的标识将被跳过
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<RemoteUserVo> fetchUsersByStorageIds(String storageIds) {
|
|
|
|
|
|
|
|
Map<TaskAssigneeEnum, List<Long>> typeIdMap = new EnumMap<>(TaskAssigneeEnum.class);
|
|
|
|
|
|
|
|
for (String storageId : storageIds.split(StrUtil.COMMA)) {
|
|
|
|
|
|
|
|
Pair<TaskAssigneeEnum, Long> parsed = this.parseStorageId(storageId);
|
|
|
|
|
|
|
|
if (parsed != null) {
|
|
|
|
|
|
|
|
typeIdMap.computeIfAbsent(parsed.getKey(), k -> new ArrayList<>()).add(parsed.getValue());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return typeIdMap.entrySet().stream()
|
|
|
|
|
|
|
|
.flatMap(entry -> this.getUsersByType(entry.getKey(), entry.getValue()).stream())
|
|
|
|
|
|
|
|
.distinct()
|
|
|
|
|
|
|
|
.toList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@ -177,4 +229,41 @@ public class FlwTaskAssigneeServiceImpl implements IFlwTaskAssigneeService, Hand
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 根据任务分配类型和对应 ID 列表,批量查询名称映射关系
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param type 分配类型(用户、角色、部门、岗位)
|
|
|
|
|
|
|
|
* @param ids ID 列表(如用户ID、角色ID等)
|
|
|
|
|
|
|
|
* @return 返回 Map,其中 key 为 ID,value 为对应的名称
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private Map<Long, String> getNamesByType(TaskAssigneeEnum type, List<Long> ids) {
|
|
|
|
|
|
|
|
return switch (type) {
|
|
|
|
|
|
|
|
case USER -> remoteUserService.selectUserNamesByIds(ids);
|
|
|
|
|
|
|
|
case ROLE -> remoteUserService.selectRoleNamesByIds(ids);
|
|
|
|
|
|
|
|
case DEPT -> remoteUserService.selectDeptNamesByIds(ids);
|
|
|
|
|
|
|
|
case POST -> remoteUserService.selectPostNamesByIds(ids);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 解析 storageId 字符串,返回类型和ID的组合
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param storageId 例如 "user:123" 或 "456"
|
|
|
|
|
|
|
|
* @return Pair(TaskAssigneeEnum, Long),如果格式非法返回 null
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private Pair<TaskAssigneeEnum, Long> parseStorageId(String storageId) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
String[] parts = storageId.split(StrUtil.COLON, 2);
|
|
|
|
|
|
|
|
if (parts.length < 2) {
|
|
|
|
|
|
|
|
return Pair.of(TaskAssigneeEnum.USER, Long.valueOf(parts[0]));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
TaskAssigneeEnum type = TaskAssigneeEnum.fromCode(parts[0] + StrUtil.COLON);
|
|
|
|
|
|
|
|
return Pair.of(type, Long.valueOf(parts[1]));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
log.warn("解析 storageId 失败,格式非法:{},错误信息:{}", storageId, e.getMessage());
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|