BPM 模型重构 7:增加任务分配规则的列表 UI 界面(增加角色的规则配置)

This commit is contained in:
YunaiV 2022-01-13 21:23:00 +08:00
parent 9f0cd04fa6
commit 8e9cb110c7
13 changed files with 90 additions and 18 deletions

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.controller.definition;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleUpdateReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskAssignRuleService;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import io.swagger.annotations.Api;
@ -36,7 +37,8 @@ public class BpmTaskAssignRuleController {
}
@PutMapping("/update")
public CommonResult<Boolean> updateTaskAssignRule(@Valid @RequestBody BpmTaskAssignRuleCreateReqVO reqVO) {
public CommonResult<Boolean> updateTaskAssignRule(@Valid @RequestBody BpmTaskAssignRuleUpdateReqVO reqVO) {
taskAssignRuleService.updateTaskAssignRule(reqVO);
return success(true);
}

View File

@ -1,7 +1,10 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule;
import lombok.Data;
import java.util.Set;
@Data
public class BpmTaskAssignRuleUpdateReqVO extends BpmTaskAssignRuleBaseVO {
private Long id;

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.convert.definition;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleUpdateReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import org.activiti.bpmn.model.UserTask;
@ -36,4 +37,6 @@ public interface BpmTaskAssignRuleConvert {
BpmTaskAssignRuleDO convert(BpmTaskAssignRuleCreateReqVO bean);
BpmTaskAssignRuleDO convert(BpmTaskAssignRuleUpdateReqVO bean);
}

View File

@ -42,6 +42,8 @@ public interface BpmErrorCodeConstants {
// ========== 流程任务分配规则 1-009-006-000 ==========
ErrorCode TASK_ASSIGN_RULE_EXISTS = new ErrorCode(1009006000, "流程({}) 的任务({}) 已经存在分配规则");
ErrorCode TASK_ASSIGN_RULE_NOT_EXISTS = new ErrorCode(1009006000, "流程任务分配规则不存在");
ErrorCode TASK_UPDATE_FAIL_NOT_MODEL = new ErrorCode(1009006000, "只有流程模型的任务分配规则,才允许被修改");
// ========== 动态表单模块 1-009-010-000 ==========
ErrorCode FORM_NOT_EXISTS = new ErrorCode(1009010000, "动态表单不存在");

View File

@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO;
import cn.iocoder.yudao.adminserver.modules.bpm.enums.definition.BpmTaskAssignRuleTypeEnum;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskAssignRuleService;
import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import lombok.Setter;
import org.activiti.bpmn.model.UserTask;
@ -29,6 +30,8 @@ public class BpmUserTaskActivitiBehavior extends UserTaskActivityBehavior {
@Setter
private BpmTaskAssignRuleService bpmTaskRuleService;
@Setter
private SysPermissionService permissionService;
public BpmUserTaskActivitiBehavior(UserTask userTask) {
super(userTask);
@ -96,10 +99,9 @@ public class BpmUserTaskActivitiBehavior extends UserTaskActivityBehavior {
}
private Set<Long> calculateTaskCandidateUsersByRole(TaskEntity task, BpmTaskAssignRuleDO rule) {
throw new UnsupportedOperationException("暂不支持该任务规则");
return permissionService.getUserRoleIdListByRoleIds(rule.getOptions());
}
private Set<Long> calculateTaskCandidateUsersByDept(TaskEntity task, BpmTaskAssignRuleDO rule) {
throw new UnsupportedOperationException("暂不支持该任务规则");
}

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.definition;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleUpdateReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO;
import org.springframework.lang.Nullable;
@ -51,6 +52,11 @@ public interface BpmTaskAssignRuleService {
*/
Long createTaskAssignRule(@Valid BpmTaskAssignRuleCreateReqVO reqVO);
// TODO 芋艿复制任务规则
/**
* 更新任务分配规则
*
* @param reqVO 创建信息
*/
void updateTaskAssignRule(@Valid BpmTaskAssignRuleUpdateReqVO reqVO);
}

View File

@ -4,17 +4,16 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleUpdateReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.convert.definition.BpmTaskAssignRuleConvert;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.definition.BpmTaskAssignRuleMapper;
import cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants;
import cn.iocoder.yudao.adminserver.modules.bpm.enums.definition.BpmTaskAssignRuleTypeEnum;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmModelService;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmProcessDefinitionService;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskAssignRuleService;
import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysRoleService;
import cn.iocoder.yudao.framework.activiti.core.util.ActivitiUtils;
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
import lombok.extern.slf4j.Slf4j;
import org.activiti.bpmn.model.BpmnModel;
import org.activiti.bpmn.model.UserTask;
@ -28,6 +27,7 @@ import java.util.List;
import java.util.Objects;
import java.util.Set;
import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.*;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
/**
@ -95,8 +95,7 @@ public class BpmTaskAssignRuleServiceImpl implements BpmTaskAssignRuleService {
BpmTaskAssignRuleDO existRule = taskRuleMapper.selectListByModelIdAndTaskDefinitionKey(
reqVO.getModelId(), reqVO.getTaskDefinitionKey());
if (existRule != null) {
throw exception(BpmErrorCodeConstants.TASK_ASSIGN_RULE_EXISTS,
reqVO.getModelId(), reqVO.getTaskDefinitionKey());
throw exception(TASK_ASSIGN_RULE_EXISTS, reqVO.getModelId(), reqVO.getTaskDefinitionKey());
}
// 存储
@ -106,12 +105,30 @@ public class BpmTaskAssignRuleServiceImpl implements BpmTaskAssignRuleService {
return rule.getId();
}
@Override
public void updateTaskAssignRule(BpmTaskAssignRuleUpdateReqVO reqVO) {
// 校验参数
validTaskAssignRuleOptions(reqVO.getType(), reqVO.getOptions());
// 校验是否存在
BpmTaskAssignRuleDO existRule = taskRuleMapper.selectById(reqVO.getId());
if (existRule == null) {
throw exception(TASK_ASSIGN_RULE_NOT_EXISTS);
}
// 只允许修改流程模型的规则
if (!Objects.equals(BpmTaskAssignRuleDO.PROCESS_DEFINITION_ID_NULL, existRule.getProcessDefinitionId())) {
throw exception(TASK_UPDATE_FAIL_NOT_MODEL);
}
// 执行更新
taskRuleMapper.updateById(BpmTaskAssignRuleConvert.INSTANCE.convert(reqVO));
}
private void validTaskAssignRuleOptions(Integer type, Set<Long> options) {
if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.ROLE.getType())) {
roleService.validRoles(options);
return;
}
// TODO 其它的
}
}

View File

@ -59,7 +59,7 @@ public class SysPermissionController {
@GetMapping("/list-user-roles")
// @RequiresPermissions("system:permission:assign-user-role")
public CommonResult<Set<Long>> listAdminRoles(@RequestParam("userId") Long userId) {
return success(permissionService.listUserRoleIs(userId));
return success(permissionService.getUserRoleIdListByUserId(userId));
}
@ApiOperation("赋予用户角色")

View File

@ -65,7 +65,7 @@ public class SysUserProfileController {
SysUserDO user = userCoreService.getUser(getLoginUserId());
SysUserProfileRespVO resp = SysUserConvert.INSTANCE.convert03(user);
// 获得用户角色
List<SysRoleDO> userRoles = roleService.getRolesFromCache(permissionService.listUserRoleIs(user.getId()));
List<SysRoleDO> userRoles = roleService.getRolesFromCache(permissionService.getUserRoleIdListByUserId(user.getId()));
resp.setRoles(SysUserConvert.INSTANCE.convertList(userRoles));
// 获得部门信息
if (user.getDeptId() != null) {

View File

@ -16,6 +16,14 @@ public interface SysUserRoleMapper extends BaseMapperX<SysUserRoleDO> {
return selectList(new QueryWrapper<SysUserRoleDO>().eq("user_id", userId));
}
default List<SysUserRoleDO> selectListByRoleId(Long roleId) {
return selectList(new QueryWrapper<SysUserRoleDO>().eq("role_id", roleId));
}
default List<SysUserRoleDO> selectListByRoleIds(Collection<Long> roleIds) {
return selectList("role_id", roleIds);
}
default void insertList(Long userId, Collection<Long> roleIds) {
List<SysUserRoleDO> list = roleIds.stream().map(roleId -> {
SysUserRoleDO entity = new SysUserRoleDO();

View File

@ -67,7 +67,23 @@ public interface SysPermissionService extends SecurityPermissionFrameworkService
* @param userId 用户编号
* @return 角色编号集合
*/
Set<Long> listUserRoleIs(Long userId);
Set<Long> getUserRoleIdListByUserId(Long userId);
/**
* 获得拥有某个角色的用户编号集合
*
* @param roleId 角色编号
* @return 用户编号集合
*/
Set<Long> getUserRoleIdListByRoleId(Long roleId);
/**
* 获得拥有多个角色的用户编号集合
*
* @param roleIds 角色编号集合
* @return 用户编号集合
*/
Set<Long> getUserRoleIdListByRoleIds(Collection<Long> roleIds);
/**
* 设置用户角色

View File

@ -216,11 +216,23 @@ public class SysPermissionServiceImpl implements SysPermissionService {
}
@Override
public Set<Long> listUserRoleIs(Long userId) {
public Set<Long> getUserRoleIdListByUserId(Long userId) {
return CollectionUtils.convertSet(userRoleMapper.selectListByUserId(userId),
SysUserRoleDO::getRoleId);
}
@Override
public Set<Long> getUserRoleIdListByRoleId(Long roleId) {
return CollectionUtils.convertSet(userRoleMapper.selectListByRoleId(roleId),
SysUserRoleDO::getRoleId);
}
@Override
public Set<Long> getUserRoleIdListByRoleIds(Collection<Long> roleIds) {
return CollectionUtils.convertSet(userRoleMapper.selectListByRoleIds(roleIds),
SysUserRoleDO::getRoleId);
}
@Override
public void assignUserRole(Long userId, Set<Long> roleIds) {
// 获得角色拥有角色编号

View File

@ -204,13 +204,13 @@
<el-dialog title="任务分配规则" :visible.sync="taskAssignRule.listOpen" width="800px" append-to-body>
<el-table v-loading="taskAssignRule.loading" :data="taskAssignRule.list">
<el-table-column label="任务名" align="center" prop="taskDefinitionName" width="120" fixed />
<el-table-column label="任务标识" align="center" prop="taskDefinitionKey" width="300" />
<el-table-column label="规则类型" align="center" prop="type">
<el-table-column label="任务标识" align="center" prop="taskDefinitionKey" width="120" show-tooltip-when-overflow />
<el-table-column label="规则类型" align="center" prop="type" width="120">
<template slot-scope="scope">
<span>{{ getDictDataLabel(DICT_TYPE.BPM_TASK_ASSIGN_RULE_TYPE, scope.row.type) }}</span>
</template>
</el-table-column>
<el-table-column label="规则范围" align="center" prop="options" width="200px">
<el-table-column label="规则范围" align="center" prop="options" width="300px">
<template slot-scope="scope">
<el-tag size="medium" v-if="scope.row.options" v-for="option in scope.row.options">
{{ getAssignRuleOptionName(scope.row.type, option) }}
@ -608,11 +608,12 @@ export default {
//
this.taskAssignRule.form = {
...row,
options: []
options: [],
roleIds: [],
};
// options roleIds
if (row.type === 10) {
this.taskAssignRule.form.roleIds = row.options;
this.taskAssignRule.form.roleIds.push(...row.options);
}
this.taskAssignRule.open = true;
},