update 优化 使用工具类简化代码
This commit is contained in:
+6
-5
@@ -5,7 +5,6 @@ import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.TypeReference;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.enums.BusinessStatusEnum;
|
||||
@@ -48,6 +47,8 @@ import java.util.*;
|
||||
@RequiredArgsConstructor
|
||||
public class WorkflowGlobalListener implements GlobalListener {
|
||||
|
||||
private static final String NODE_KEY_SEPARATOR = ":";
|
||||
|
||||
private final IFlwTaskService flwTaskService;
|
||||
private final IFlwInstanceService flwInstanceService;
|
||||
private final FlowProcessEventHandler flowProcessEventHandler;
|
||||
@@ -138,7 +139,7 @@ public class WorkflowGlobalListener implements GlobalListener {
|
||||
* @param taskStatus 任务状态
|
||||
*/
|
||||
private void processTaskPermission(Map<String, Object> variable, Task flowTask, String taskStatus) {
|
||||
String nodeKey = taskStatus + StrUtil.COLON + flowTask.getNodeCode();
|
||||
String nodeKey = taskStatus + NODE_KEY_SEPARATOR + flowTask.getNodeCode();
|
||||
|
||||
// 检查是否存在状态相关的变量
|
||||
if (!variable.containsKey(nodeKey)) {
|
||||
@@ -157,9 +158,9 @@ public class WorkflowGlobalListener implements GlobalListener {
|
||||
}
|
||||
|
||||
// 分割用户ID并设置权限列表
|
||||
String[] userIdArray = userIds.split(StringUtils.SEPARATOR);
|
||||
if (userIdArray.length > 0) {
|
||||
flowTask.setPermissionList(List.of(userIdArray));
|
||||
List<String> userIdList = StringUtils.str2List(userIds, StringUtils.SEPARATOR, true, true);
|
||||
if (CollUtil.isNotEmpty(userIdList)) {
|
||||
flowTask.setPermissionList(userIdList);
|
||||
// 移除已处理的状态变量
|
||||
variable.remove(nodeKey);
|
||||
FlowEngine.insService().removeVariables(flowTask.getInstanceId(), nodeKey);
|
||||
|
||||
+1
-1
@@ -259,7 +259,7 @@ public class FlwNodeExtServiceImpl implements NodeExtService, IFlwNodeExtService
|
||||
} else if (VariablesEnum.class.getSimpleName().equals(code)) {
|
||||
// 解析自定义参数
|
||||
// 将 key=value 字符串拆分为 Map
|
||||
Map<String, String> variables = Arrays.stream(StringUtils.split(value, StringUtils.SEPARATOR))
|
||||
Map<String, String> variables = StringUtils.str2List(value, StringUtils.SEPARATOR, true, true).stream()
|
||||
.map(s -> StringUtils.split(s, "="))
|
||||
.filter(arr -> arr.length == 2)
|
||||
.collect(Collectors.toMap(arr -> arr[0], arr -> arr[1]));
|
||||
|
||||
+5
-4
@@ -5,7 +5,6 @@ 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;
|
||||
import org.dromara.common.core.utils.DateUtils;
|
||||
@@ -45,6 +44,8 @@ import java.util.stream.Collectors;
|
||||
public class FlwTaskAssigneeServiceImpl implements IFlwTaskAssigneeService, HandlerSelectService {
|
||||
|
||||
private static final String DEFAULT_GROUP_NAME = "默认分组";
|
||||
private static final String STORAGE_ID_SEPARATOR = ":";
|
||||
|
||||
private final TaskAssigneeService taskAssigneeService;
|
||||
private final UserService userService;
|
||||
private final DeptService deptService;
|
||||
@@ -208,7 +209,7 @@ public class FlwTaskAssigneeServiceImpl implements IFlwTaskAssigneeService, Hand
|
||||
return List.of();
|
||||
}
|
||||
Map<TaskAssigneeEnum, List<String>> typeIdMap = new EnumMap<>(TaskAssigneeEnum.class);
|
||||
for (String storageId : storageIds.split(StringUtils.SEPARATOR)) {
|
||||
for (String storageId : StringUtils.str2List(storageIds, StringUtils.SEPARATOR, true, true)) {
|
||||
Pair<TaskAssigneeEnum, String> parsed = this.parseStorageId(storageId);
|
||||
if (parsed != null) {
|
||||
typeIdMap.computeIfAbsent(parsed.getKey(), k -> new ArrayList<>()).add(parsed.getValue());
|
||||
@@ -311,11 +312,11 @@ public class FlwTaskAssigneeServiceImpl implements IFlwTaskAssigneeService, Hand
|
||||
return Pair.of(TaskAssigneeEnum.SPEL, storageId);
|
||||
}
|
||||
try {
|
||||
String[] parts = storageId.split(StrUtil.COLON, 2);
|
||||
String[] parts = storageId.split(STORAGE_ID_SEPARATOR, 2);
|
||||
if (parts.length < 2) {
|
||||
return Pair.of(TaskAssigneeEnum.USER, parts[0]);
|
||||
} else {
|
||||
TaskAssigneeEnum type = TaskAssigneeEnum.fromCode(parts[0] + StrUtil.COLON);
|
||||
TaskAssigneeEnum type = TaskAssigneeEnum.fromCode(parts[0] + STORAGE_ID_SEPARATOR);
|
||||
return Pair.of(type, parts[1]);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
+9
-8
@@ -5,7 +5,6 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.lock.annotation.Lock4j;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -77,6 +76,8 @@ import static org.dromara.workflow.common.constant.FlowConstant.*;
|
||||
@Service
|
||||
public class FlwTaskServiceImpl implements IFlwTaskService {
|
||||
|
||||
private static final String NODE_KEY_SEPARATOR = ":";
|
||||
|
||||
private final TaskService taskService;
|
||||
private final InsService insService;
|
||||
private final DefService defService;
|
||||
@@ -311,17 +312,17 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
||||
if (StringUtils.isNotBlank(userIds)) {
|
||||
Set<String> hashSet = new HashSet<>();
|
||||
//弹窗传入的选人
|
||||
List<String> popUserIds = Arrays.asList(entry.getValue().toString().split(StringUtils.SEPARATOR));
|
||||
List<String> popUserIds = StringUtils.str2List(entry.getValue().toString(), StringUtils.SEPARATOR, true, true);
|
||||
//已有的选人
|
||||
List<String> variableUserIds = Arrays.asList(userIds.split(StringUtils.SEPARATOR));
|
||||
List<String> variableUserIds = StringUtils.str2List(userIds, StringUtils.SEPARATOR, true, true);
|
||||
hashSet.addAll(popUserIds);
|
||||
hashSet.addAll(variableUserIds);
|
||||
map.put(TaskStatusEnum.PASS.getStatus() + StrUtil.COLON + entry.getKey(), StringUtils.joinComma(hashSet));
|
||||
map.put(TaskStatusEnum.BACK.getStatus() + StrUtil.COLON + entry.getKey(), StringUtils.joinComma(hashSet));
|
||||
map.put(TaskStatusEnum.PASS.getStatus() + NODE_KEY_SEPARATOR + entry.getKey(), StringUtils.joinComma(hashSet));
|
||||
map.put(TaskStatusEnum.BACK.getStatus() + NODE_KEY_SEPARATOR + entry.getKey(), StringUtils.joinComma(hashSet));
|
||||
}
|
||||
} else {
|
||||
map.put(TaskStatusEnum.PASS.getStatus() + StrUtil.COLON + entry.getKey(), entry.getValue());
|
||||
map.put(TaskStatusEnum.BACK.getStatus() + StrUtil.COLON + entry.getKey(), entry.getValue());
|
||||
map.put(TaskStatusEnum.PASS.getStatus() + NODE_KEY_SEPARATOR + entry.getKey(), entry.getValue());
|
||||
map.put(TaskStatusEnum.BACK.getStatus() + NODE_KEY_SEPARATOR + entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
return map;
|
||||
@@ -838,7 +839,7 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
||||
// 操作执行成功后再发送消息
|
||||
if (result && CollUtil.isNotEmpty(bo.getMessageType())) {
|
||||
List<Long> userIdList = new ArrayList<>();
|
||||
if (StrUtil.isNotBlank(bo.getUserId())) {
|
||||
if (StringUtils.isNotBlank(bo.getUserId())) {
|
||||
userIdList.add(Convert.toLong(bo.getUserId()));
|
||||
}
|
||||
if (CollUtil.isNotEmpty(bo.getUserIds())) {
|
||||
|
||||
Reference in New Issue
Block a user