|
|
|
|
@ -2,9 +2,12 @@ package org.dromara.workflow.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
|
|
import org.dromara.common.json.utils.JsonUtils;
|
|
|
|
|
import org.dromara.system.api.RemoteDictService;
|
|
|
|
|
import org.dromara.system.api.domain.vo.RemoteDictTypeVo;
|
|
|
|
|
import org.dromara.warm.flow.ui.service.NodeExtService;
|
|
|
|
|
@ -12,9 +15,13 @@ import org.dromara.warm.flow.ui.vo.NodeExt;
|
|
|
|
|
import org.dromara.workflow.common.ConditionalOnEnable;
|
|
|
|
|
import org.dromara.workflow.common.enums.ButtonPermissionEnum;
|
|
|
|
|
import org.dromara.workflow.common.enums.NodeExtEnum;
|
|
|
|
|
import org.dromara.workflow.domain.vo.ButtonPermissionVo;
|
|
|
|
|
import org.dromara.workflow.service.IFlwNodeExtService;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 流程设计器-节点扩展属性
|
|
|
|
|
@ -25,14 +32,15 @@ import java.util.*;
|
|
|
|
|
@Slf4j
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
@Service
|
|
|
|
|
public class FlwNodeExtServiceImpl implements NodeExtService {
|
|
|
|
|
public class FlwNodeExtServiceImpl implements NodeExtService, IFlwNodeExtService {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 存储不同 dictType 对应的配置信息
|
|
|
|
|
*/
|
|
|
|
|
private static final Map<String, ButtonPermission> CHILD_NODE_MAP = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
record ButtonPermission(String label, Integer type, Boolean must, Boolean multiple) {}
|
|
|
|
|
record ButtonPermission(String label, Integer type, Boolean must, Boolean multiple) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
CHILD_NODE_MAP.put(ButtonPermissionEnum.class.getSimpleName(),
|
|
|
|
|
@ -164,4 +172,74 @@ public class FlwNodeExtServiceImpl implements NodeExtService {
|
|
|
|
|
return childNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 从扩展属性构建按钮权限列表:根据 ext 中记录的权限值,标记每个按钮是否勾选
|
|
|
|
|
*
|
|
|
|
|
* @param ext 扩展属性 JSON 字符串
|
|
|
|
|
* @return 按钮权限 VO 列表
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<ButtonPermissionVo> buildButtonPermissionsFromExt(String ext) {
|
|
|
|
|
// 解析 ext 为 Map<code, Set<value>>,用于标记权限
|
|
|
|
|
Map<String, Set<String>> permissionMap = JsonUtils.parseArray(ext, ButtonPermissionVo.class)
|
|
|
|
|
.stream()
|
|
|
|
|
.collect(Collectors.toMap(
|
|
|
|
|
ButtonPermissionVo::getCode,
|
|
|
|
|
item -> StringUtils.splitList(item.getValue()).stream()
|
|
|
|
|
.map(String::trim)
|
|
|
|
|
.filter(StrUtil::isNotBlank)
|
|
|
|
|
.collect(Collectors.toSet()),
|
|
|
|
|
(a, b) -> b,
|
|
|
|
|
HashMap::new
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
// 构建按钮权限列表,标记哪些按钮在 permissionMap 中出现(表示已勾选)
|
|
|
|
|
return buildPermissionsFromSources(permissionMap, List.of(ButtonPermissionEnum.class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将权限映射与按钮权限来源(枚举类或字典类型)进行匹配,生成权限视图列表
|
|
|
|
|
* <p>
|
|
|
|
|
* 使用说明:
|
|
|
|
|
* - sources 支持传入多个来源类型,支持 NodeExtEnum 枚举类 或 字典类型字符串(dictType)
|
|
|
|
|
* - 若需要扩展更多按钮权限,只需在 sources 中新增对应的枚举类或字典类型
|
|
|
|
|
* <p>
|
|
|
|
|
* 示例:
|
|
|
|
|
* buildPermissionsFromSources(permissionMap, List.of(ButtonPermissionEnum.class, "custom_button_dict"));
|
|
|
|
|
*
|
|
|
|
|
* @param permissionMap 权限映射
|
|
|
|
|
* @param sources 枚举类或字典类型列表
|
|
|
|
|
* @return 按钮权限视图对象列表
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("unchecked cast")
|
|
|
|
|
private List<ButtonPermissionVo> buildPermissionsFromSources(Map<String, Set<String>> permissionMap, List<Object> sources) {
|
|
|
|
|
return sources.stream()
|
|
|
|
|
.flatMap(source -> {
|
|
|
|
|
if (source instanceof Class<?> clazz && NodeExtEnum.class.isAssignableFrom(clazz)) {
|
|
|
|
|
Set<String> selectedSet = permissionMap.getOrDefault(clazz.getSimpleName(), Collections.emptySet());
|
|
|
|
|
return extractDictItems(this.buildChildNode((Class<? extends NodeExtEnum>) clazz), selectedSet).stream();
|
|
|
|
|
} else if (source instanceof String dictType) {
|
|
|
|
|
Set<String> selectedSet = permissionMap.getOrDefault(dictType, Collections.emptySet());
|
|
|
|
|
return extractDictItems(this.buildChildNode(dictType), selectedSet).stream();
|
|
|
|
|
}
|
|
|
|
|
return Stream.empty();
|
|
|
|
|
}).toList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 从节点子项中提取字典项,并构建按钮权限视图对象列表
|
|
|
|
|
*
|
|
|
|
|
* @param childNode 子节点
|
|
|
|
|
* @param selectedSet 已选中的值集
|
|
|
|
|
* @return 按钮权限视图对象列表
|
|
|
|
|
*/
|
|
|
|
|
private List<ButtonPermissionVo> extractDictItems(NodeExt.ChildNode childNode, Set<String> selectedSet) {
|
|
|
|
|
return Optional.ofNullable(childNode)
|
|
|
|
|
.map(NodeExt.ChildNode::getDict)
|
|
|
|
|
.orElse(List.of())
|
|
|
|
|
.stream()
|
|
|
|
|
.map(dict -> new ButtonPermissionVo(dict.getValue(), selectedSet.contains(dict.getValue())))
|
|
|
|
|
.toList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|