|
|
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
|
|
import cn.hutool.core.lang.Pair;
|
|
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
@ -14,6 +15,7 @@ import org.dromara.common.core.domain.model.TaskAssigneeBody;
|
|
|
|
|
import org.dromara.common.core.enums.FormatsType;
|
|
|
|
|
import org.dromara.common.core.service.*;
|
|
|
|
|
import org.dromara.common.core.utils.DateUtils;
|
|
|
|
|
import org.dromara.common.core.utils.StreamUtils;
|
|
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
|
|
import org.dromara.warm.flow.ui.dto.HandlerFunDto;
|
|
|
|
|
import org.dromara.warm.flow.ui.dto.HandlerQuery;
|
|
|
|
|
@ -28,6 +30,7 @@ import org.dromara.workflow.service.IFlwTaskAssigneeService;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 流程设计器-获取办理人权限设置列表
|
|
|
|
|
@ -90,31 +93,25 @@ public class FlwTaskAssigneeServiceImpl implements IFlwTaskAssigneeService, Hand
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
// 解析并归类 ID,同时记录原始顺序和对应解析结果
|
|
|
|
|
Map<TaskAssigneeEnum, List<Long>> typeIdMap = new EnumMap<>(TaskAssigneeEnum.class);
|
|
|
|
|
Map<String, Pair<TaskAssigneeEnum, Long>> parsedMap = new LinkedHashMap<>();
|
|
|
|
|
List<String> spelList = new ArrayList<>();
|
|
|
|
|
Map<TaskAssigneeEnum, List<String>> typeIdMap = new EnumMap<>(TaskAssigneeEnum.class);
|
|
|
|
|
Map<String, Pair<TaskAssigneeEnum, String>> parsedMap = new LinkedHashMap<>();
|
|
|
|
|
for (String storageId : storageIds) {
|
|
|
|
|
Pair<TaskAssigneeEnum, Long> parsed = this.parseStorageId(storageId);
|
|
|
|
|
Pair<TaskAssigneeEnum, String> parsed = this.parseStorageId(storageId);
|
|
|
|
|
parsedMap.put(storageId, parsed);
|
|
|
|
|
if (parsed != null) {
|
|
|
|
|
typeIdMap.computeIfAbsent(parsed.getKey(), k -> new ArrayList<>()).add(parsed.getValue());
|
|
|
|
|
} else if (StringUtils.startsWith(storageId, "$") || StringUtils.startsWith(storageId, "#")) {
|
|
|
|
|
// $前缀表示默认办理人变量策略
|
|
|
|
|
// #前缀表示spel办理人变量策略
|
|
|
|
|
spelList.add(storageId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询所有类型对应的 ID 名称映射
|
|
|
|
|
Map<TaskAssigneeEnum, Map<Long, String>> nameMap = new EnumMap<>(TaskAssigneeEnum.class);
|
|
|
|
|
Map<TaskAssigneeEnum, Map<String, String>> nameMap = new EnumMap<>(TaskAssigneeEnum.class);
|
|
|
|
|
typeIdMap.forEach((type, ids) -> nameMap.put(type, this.getNamesByType(type, ids)));
|
|
|
|
|
Map<String, String> spelMap = spelService.selectRemarksBySpels(spelList);
|
|
|
|
|
// 组装返回结果,保持原始顺序
|
|
|
|
|
return parsedMap.entrySet().stream()
|
|
|
|
|
.map(entry -> {
|
|
|
|
|
String storageId = entry.getKey();
|
|
|
|
|
Pair<TaskAssigneeEnum, Long> parsed = entry.getValue();
|
|
|
|
|
String handlerName = (parsed == null) ? spelMap.get(storageId)
|
|
|
|
|
Pair<TaskAssigneeEnum, String> parsed = entry.getValue();
|
|
|
|
|
String handlerName = (parsed == null) ? null
|
|
|
|
|
: nameMap.getOrDefault(parsed.getKey(), Collections.emptyMap())
|
|
|
|
|
.get(parsed.getValue());
|
|
|
|
|
return new HandlerFeedBackVo(storageId, handlerName);
|
|
|
|
|
@ -138,12 +135,29 @@ public class FlwTaskAssigneeServiceImpl implements IFlwTaskAssigneeService, Hand
|
|
|
|
|
* 根据任务办理类型获取部门数据
|
|
|
|
|
*/
|
|
|
|
|
private List<DeptDTO> fetchDeptData(TaskAssigneeEnum type) {
|
|
|
|
|
if (type == TaskAssigneeEnum.USER || type == TaskAssigneeEnum.DEPT || type == TaskAssigneeEnum.POST) {
|
|
|
|
|
if (type.needsDeptService()) {
|
|
|
|
|
return deptService.selectDeptsByList();
|
|
|
|
|
}
|
|
|
|
|
return new ArrayList<>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取权限分组名称
|
|
|
|
|
*
|
|
|
|
|
* @param type 任务分配人枚举
|
|
|
|
|
* @param groupName 权限分组
|
|
|
|
|
* @return 权限分组名称
|
|
|
|
|
*/
|
|
|
|
|
private String getGroupName(TaskAssigneeEnum type, String groupName) {
|
|
|
|
|
if (StringUtils.isEmpty(groupName)) {
|
|
|
|
|
return DEFAULT_GROUP_NAME;
|
|
|
|
|
}
|
|
|
|
|
if (type.needsDeptService()) {
|
|
|
|
|
return deptService.selectDeptNameByIds(groupName);
|
|
|
|
|
}
|
|
|
|
|
return DEFAULT_GROUP_NAME;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构建部门树状结构
|
|
|
|
|
*/
|
|
|
|
|
@ -162,10 +176,7 @@ public class FlwTaskAssigneeServiceImpl implements IFlwTaskAssigneeService, Hand
|
|
|
|
|
.setStorageId(assignee -> type.getCode() + assignee.getStorageId())
|
|
|
|
|
.setHandlerCode(assignee -> StringUtils.blankToDefault(assignee.getHandlerCode(), "无"))
|
|
|
|
|
.setHandlerName(assignee -> StringUtils.blankToDefault(assignee.getHandlerName(), "无"))
|
|
|
|
|
.setGroupName(assignee -> StringUtils.defaultIfBlank(
|
|
|
|
|
Optional.ofNullable(assignee.getGroupName())
|
|
|
|
|
.map(deptService::selectDeptNameByIds)
|
|
|
|
|
.orElse(DEFAULT_GROUP_NAME), DEFAULT_GROUP_NAME))
|
|
|
|
|
.setGroupName(assignee -> this.getGroupName(type, assignee.getGroupName()))
|
|
|
|
|
.setCreateTime(assignee -> DateUtils.parseDateToStr(FormatsType.YYYY_MM_DD_HH_MM_SS, assignee.getCreateTime()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -182,9 +193,9 @@ public class FlwTaskAssigneeServiceImpl implements IFlwTaskAssigneeService, Hand
|
|
|
|
|
if (StringUtils.isEmpty(storageIds)) {
|
|
|
|
|
return List.of();
|
|
|
|
|
}
|
|
|
|
|
Map<TaskAssigneeEnum, List<Long>> typeIdMap = new EnumMap<>(TaskAssigneeEnum.class);
|
|
|
|
|
Map<TaskAssigneeEnum, List<String>> typeIdMap = new EnumMap<>(TaskAssigneeEnum.class);
|
|
|
|
|
for (String storageId : storageIds.split(StringUtils.SEPARATOR)) {
|
|
|
|
|
Pair<TaskAssigneeEnum, Long> parsed = this.parseStorageId(storageId);
|
|
|
|
|
Pair<TaskAssigneeEnum, String> parsed = this.parseStorageId(storageId);
|
|
|
|
|
if (parsed != null) {
|
|
|
|
|
typeIdMap.computeIfAbsent(parsed.getKey(), k -> new ArrayList<>()).add(parsed.getValue());
|
|
|
|
|
}
|
|
|
|
|
@ -205,13 +216,17 @@ public class FlwTaskAssigneeServiceImpl implements IFlwTaskAssigneeService, Hand
|
|
|
|
|
* 如果类型为部门(DEPT),则通过部门ID列表查询;
|
|
|
|
|
* 如果类型为岗位(POST)或无法识别的类型,则返回空列表
|
|
|
|
|
*/
|
|
|
|
|
private List<UserDTO> getUsersByType(TaskAssigneeEnum type, List<Long> ids) {
|
|
|
|
|
private List<UserDTO> getUsersByType(TaskAssigneeEnum type, List<String> ids) {
|
|
|
|
|
if (type == TaskAssigneeEnum.SPEL) {
|
|
|
|
|
return new ArrayList<>();
|
|
|
|
|
}
|
|
|
|
|
List<Long> longIds = StreamUtils.toList(ids, Convert::toLong);
|
|
|
|
|
return switch (type) {
|
|
|
|
|
case USER -> userService.selectListByIds(ids);
|
|
|
|
|
case ROLE -> userService.selectUsersByRoleIds(ids);
|
|
|
|
|
case DEPT -> userService.selectUsersByDeptIds(ids);
|
|
|
|
|
case POST -> userService.selectUsersByPostIds(ids);
|
|
|
|
|
case SPEL -> new ArrayList<>();
|
|
|
|
|
case USER -> userService.selectListByIds(longIds);
|
|
|
|
|
case ROLE -> userService.selectUsersByRoleIds(longIds);
|
|
|
|
|
case DEPT -> userService.selectUsersByDeptIds(longIds);
|
|
|
|
|
case POST -> userService.selectUsersByPostIds(longIds);
|
|
|
|
|
default -> new ArrayList<>();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -222,14 +237,28 @@ public class FlwTaskAssigneeServiceImpl implements IFlwTaskAssigneeService, Hand
|
|
|
|
|
* @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 -> userService.selectUserNamesByIds(ids);
|
|
|
|
|
case ROLE -> roleService.selectRoleNamesByIds(ids);
|
|
|
|
|
case DEPT -> deptService.selectDeptNamesByIds(ids);
|
|
|
|
|
case POST -> postService.selectPostNamesByIds(ids);
|
|
|
|
|
case SPEL -> new HashMap<>();
|
|
|
|
|
private Map<String, String> getNamesByType(TaskAssigneeEnum type, List<String> ids) {
|
|
|
|
|
if (type == TaskAssigneeEnum.SPEL) {
|
|
|
|
|
return spelService.selectRemarksBySpels(ids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Long> longIds = StreamUtils.toList(ids, Convert::toLong);
|
|
|
|
|
Map<Long, String> rawMap = switch (type) {
|
|
|
|
|
case USER -> userService.selectUserNamesByIds(longIds);
|
|
|
|
|
case ROLE -> roleService.selectRoleNamesByIds(longIds);
|
|
|
|
|
case DEPT -> deptService.selectDeptNamesByIds(longIds);
|
|
|
|
|
case POST -> postService.selectPostNamesByIds(longIds);
|
|
|
|
|
default -> Collections.emptyMap();
|
|
|
|
|
};
|
|
|
|
|
if (MapUtil.isEmpty(rawMap)) {
|
|
|
|
|
return Collections.emptyMap();
|
|
|
|
|
}
|
|
|
|
|
return rawMap.entrySet()
|
|
|
|
|
.stream()
|
|
|
|
|
.collect(Collectors.toMap(
|
|
|
|
|
e -> Convert.toStr(e.getKey()),
|
|
|
|
|
Map.Entry::getValue
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -238,24 +267,20 @@ public class FlwTaskAssigneeServiceImpl implements IFlwTaskAssigneeService, Hand
|
|
|
|
|
* @param storageId 例如 "user:123" 或 "456"
|
|
|
|
|
* @return Pair(TaskAssigneeEnum, Long),如果格式非法返回 null
|
|
|
|
|
*/
|
|
|
|
|
private Pair<TaskAssigneeEnum, Long> parseStorageId(String storageId) {
|
|
|
|
|
private Pair<TaskAssigneeEnum, String> parseStorageId(String storageId) {
|
|
|
|
|
if (StringUtils.isBlank(storageId)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
// 跳过以 $ 或 # 开头的字符串
|
|
|
|
|
if (StringUtils.startsWith(storageId, "$") || StringUtils.startsWith(storageId, "#")) {
|
|
|
|
|
// $前缀表示默认办理人变量策略
|
|
|
|
|
// #前缀表示spel办理人变量策略
|
|
|
|
|
log.debug("跳过 storageId 解析,检测到内置变量表达式:{}", storageId);
|
|
|
|
|
return null;
|
|
|
|
|
if (TaskAssigneeEnum.isSpelExpression(storageId)) {
|
|
|
|
|
return Pair.of(TaskAssigneeEnum.SPEL, storageId);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
String[] parts = storageId.split(StrUtil.COLON, 2);
|
|
|
|
|
if (parts.length < 2) {
|
|
|
|
|
return Pair.of(TaskAssigneeEnum.USER, Convert.toLong(parts[0]));
|
|
|
|
|
return Pair.of(TaskAssigneeEnum.USER, parts[0]);
|
|
|
|
|
} else {
|
|
|
|
|
TaskAssigneeEnum type = TaskAssigneeEnum.fromCode(parts[0] + StrUtil.COLON);
|
|
|
|
|
return Pair.of(type, Convert.toLong(parts[1]));
|
|
|
|
|
return Pair.of(type, parts[1]);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.warn("解析 storageId 失败,格式非法:{},错误信息:{}", storageId, e.getMessage());
|
|
|
|
|
|