1. 实现空的 bpm UserGroupManager

2. 去除任务分配时,candidateUsers 协调者
pull/2/head
YunaiV 2022-01-15 23:55:00 +08:00
parent bacf741f77
commit 9b26c3e98a
6 changed files with 46 additions and 31 deletions

View File

@ -2,12 +2,14 @@ package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.config;
import cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.behavior.BpmActivityBehaviorFactory; import cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.behavior.BpmActivityBehaviorFactory;
import cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.behavior.script.BpmTaskAssignScript; import cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.behavior.script.BpmTaskAssignScript;
import cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.identity.EmptyUserGroupManager;
import cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.listener.BpmTackActivitiEventListener; import cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.listener.BpmTackActivitiEventListener;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskAssignRuleService; import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskAssignRuleService;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmUserGroupService; import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmUserGroupService;
import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService; import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService;
import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService;
import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService;
import org.activiti.api.runtime.shared.identity.UserGroupManager;
import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer; import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -24,7 +26,7 @@ import static org.activiti.spring.boot.ProcessEngineAutoConfiguration.BEHAVIOR_F
public class BpmActivitiConfiguration { public class BpmActivitiConfiguration {
/** /**
* BPM ProcessEngineConfigurationConfigurer * BPM ProcessEngineConfigurationConfigurer
*/ */
@Bean @Bean
public ProcessEngineConfigurationConfigurer bpmProcessEngineConfigurationConfigurer( public ProcessEngineConfigurationConfigurer bpmProcessEngineConfigurationConfigurer(
@ -32,6 +34,8 @@ public class BpmActivitiConfiguration {
return configuration -> { return configuration -> {
// 注册监听器,例如说 BpmActivitiEventListener // 注册监听器,例如说 BpmActivitiEventListener
configuration.setEventListeners(Collections.singletonList(taskActivitiEventListener)); configuration.setEventListeners(Collections.singletonList(taskActivitiEventListener));
// 用户组
configuration.setUserGroupManager(new EmptyUserGroupManager());
}; };
} }

View File

@ -39,13 +39,7 @@ import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString
* assignee * assignee
* *
* *
* assignee candidateUsers * assignee
* candidateUsers
*
* assignee
* assignee candidateUsers
* assignee使 candidateUsers使 TaskQuery taskCandidateUser
* WHERE RES.ASSIGNEE_ is null
* *
* @author * @author
*/ */
@ -83,15 +77,9 @@ public class BpmUserTaskActivitiBehavior extends UserTaskActivityBehavior {
BpmTaskAssignRuleDO rule = getTaskRule(task); BpmTaskAssignRuleDO rule = getTaskRule(task);
// 第二步,获得任务的候选用户们 // 第二步,获得任务的候选用户们
Set<Long> candidateUserIds = calculateTaskCandidateUsers(task, rule); Set<Long> candidateUserIds = calculateTaskCandidateUsers(task, rule);
// 情况一,只有一个 candidateUserIds则设置负责人 // 第三步,设置一个作为负责人
if (CollU)
Long assigneeUserId = chooseTaskAssignee(candidateUserIds); Long assigneeUserId = chooseTaskAssignee(candidateUserIds);
taskEntityManager.changeTaskAssignee(task, String.valueOf(assigneeUserId)); taskEntityManager.changeTaskAssignee(task, String.valueOf(assigneeUserId));
// 设置候选人们
candidateUserIds.remove(assigneeUserId); // 已经成为负责人了,就不要在扮演候选人了
if (CollUtil.isNotEmpty(candidateUserIds)) {
task.addCandidateUsers(convertSet(candidateUserIds, String::valueOf));
}
} }
private BpmTaskAssignRuleDO getTaskRule(TaskEntity task) { private BpmTaskAssignRuleDO getTaskRule(TaskEntity task) {

View File

@ -0,0 +1,37 @@
package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.identity;
import org.activiti.api.runtime.shared.identity.UserGroupManager;
import java.util.Collections;
import java.util.List;
/**
* UserGroupManager Activiti
* 使 Activiti
*
*
* @author
*/
public class EmptyUserGroupManager implements UserGroupManager {
@Override
public List<String> getUserGroups(String s) {
return Collections.emptyList();
}
@Override
public List<String> getUserRoles(String s) {
return Collections.emptyList();
}
@Override
public List<String> getGroups() {
return Collections.emptyList();
}
@Override
public List<String> getUsers() {
return Collections.emptyList();
}
}

View File

@ -98,11 +98,8 @@ public class BpmTaskServiceImpl implements BpmTaskService {
public PageResult<BpmTaskTodoPageItemRespVO> getTodoTaskPage(Long userId, BpmTaskTodoPageReqVO pageVO) { public PageResult<BpmTaskTodoPageItemRespVO> getTodoTaskPage(Long userId, BpmTaskTodoPageReqVO pageVO) {
// 查询待办任务 // 查询待办任务
TaskQuery taskQuery = taskService.createTaskQuery() TaskQuery taskQuery = taskService.createTaskQuery()
// .or() .taskAssignee(String.valueOf(userId)) // 分配给自己
// .taskAssignee(String.valueOf(userId)) // 分配给自己
// .taskCandidateOrAssigned(String.valueOf(userId))
.taskCandidateUser(String.valueOf(userId)) .taskCandidateUser(String.valueOf(userId))
// .endOr()
.orderByTaskCreateTime().desc(); // 创建时间倒序 .orderByTaskCreateTime().desc(); // 创建时间倒序
if (StrUtil.isNotBlank(pageVO.getName())) { if (StrUtil.isNotBlank(pageVO.getName())) {
taskQuery.taskNameLike("%" + pageVO.getName() + "%"); taskQuery.taskNameLike("%" + pageVO.getName() + "%");

View File

@ -325,7 +325,6 @@ public class SysAuthServiceImpl implements SysAuthService {
// 补全字段 // 补全字段
loginUser.setDeptId(user.getDeptId()); loginUser.setDeptId(user.getDeptId());
loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId()));
loginUser.setGroups(this.getUserPosts(user.getPostIds()));
return loginUser; return loginUser;
} }

View File

@ -65,11 +65,6 @@ public class LoginUser implements UserDetails {
* *
*/ */
private Set<Long> postIds; private Set<Long> postIds;
/**
* group
*/
// TODO jason这个字段改成 postCodes 明确更好哈
private List<String> groups;
// ========== 上下文 ========== // ========== 上下文 ==========
/** /**
@ -100,12 +95,7 @@ public class LoginUser implements UserDetails {
@Override @Override
@JsonIgnore// 避免序列化 @JsonIgnore// 避免序列化
public Collection<? extends GrantedAuthority> getAuthorities() { public Collection<? extends GrantedAuthority> getAuthorities() {
List<GrantedAuthority> list = new ArrayList<>(1); return new HashSet<>();
// 设置 ROLE_ACTIVITI_USER 角色,保证 activiti7 在 Security 验证时,可以通过。参考 https://juejin.cn/post/6972369247041224712 文章
// TODO 芋艿:这里估计得优化下
// TODO @芋艿:看看有没更优化的方案
list.add(new SimpleGrantedAuthority("ROLE_ACTIVITI_USER"));
return list;
} }
@Override @Override