diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/BpmTaskAssignRuleController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/BpmTaskAssignRuleController.java index 4a17d9fc2..e00dad1ab 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/BpmTaskAssignRuleController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/BpmTaskAssignRuleController.java @@ -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 updateTaskAssignRule(@Valid @RequestBody BpmTaskAssignRuleCreateReqVO reqVO) { + public CommonResult updateTaskAssignRule(@Valid @RequestBody BpmTaskAssignRuleUpdateReqVO reqVO) { + taskAssignRuleService.updateTaskAssignRule(reqVO); return success(true); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/vo/rule/BpmTaskAssignRuleUpdateReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/vo/rule/BpmTaskAssignRuleUpdateReqVO.java index 8918a1c8f..ed4700d51 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/vo/rule/BpmTaskAssignRuleUpdateReqVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/vo/rule/BpmTaskAssignRuleUpdateReqVO.java @@ -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; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/definition/BpmTaskAssignRuleConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/definition/BpmTaskAssignRuleConvert.java index 09d056e1c..d21837567 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/definition/BpmTaskAssignRuleConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/definition/BpmTaskAssignRuleConvert.java @@ -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); + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java index c54131a12..54e76fc66 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java @@ -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, "动态表单不存在"); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/core/behavior/BpmUserTaskActivitiBehavior.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/core/behavior/BpmUserTaskActivitiBehavior.java index 077824f6b..31b59a061 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/core/behavior/BpmUserTaskActivitiBehavior.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/core/behavior/BpmUserTaskActivitiBehavior.java @@ -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 calculateTaskCandidateUsersByRole(TaskEntity task, BpmTaskAssignRuleDO rule) { - throw new UnsupportedOperationException("暂不支持该任务规则"); + return permissionService.getUserRoleIdListByRoleIds(rule.getOptions()); } - private Set calculateTaskCandidateUsersByDept(TaskEntity task, BpmTaskAssignRuleDO rule) { throw new UnsupportedOperationException("暂不支持该任务规则"); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmTaskAssignRuleService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmTaskAssignRuleService.java index 3c04bfc0b..b346ec58a 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmTaskAssignRuleService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmTaskAssignRuleService.java @@ -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); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmTaskAssignRuleServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmTaskAssignRuleServiceImpl.java index 8fcc607e8..702eae6fc 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmTaskAssignRuleServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmTaskAssignRuleServiceImpl.java @@ -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 options) { if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.ROLE.getType())) { roleService.validRoles(options); return; } - + // TODO 其它的 } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/permission/SysPermissionController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/permission/SysPermissionController.java index ea04c89fd..cbd1197ae 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/permission/SysPermissionController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/permission/SysPermissionController.java @@ -59,7 +59,7 @@ public class SysPermissionController { @GetMapping("/list-user-roles") // @RequiresPermissions("system:permission:assign-user-role") public CommonResult> listAdminRoles(@RequestParam("userId") Long userId) { - return success(permissionService.listUserRoleIs(userId)); + return success(permissionService.getUserRoleIdListByUserId(userId)); } @ApiOperation("赋予用户角色") diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.java index 0b85016c1..4b47d3c55 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.java @@ -65,7 +65,7 @@ public class SysUserProfileController { SysUserDO user = userCoreService.getUser(getLoginUserId()); SysUserProfileRespVO resp = SysUserConvert.INSTANCE.convert03(user); // 获得用户角色 - List userRoles = roleService.getRolesFromCache(permissionService.listUserRoleIs(user.getId())); + List userRoles = roleService.getRolesFromCache(permissionService.getUserRoleIdListByUserId(user.getId())); resp.setRoles(SysUserConvert.INSTANCE.convertList(userRoles)); // 获得部门信息 if (user.getDeptId() != null) { diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/permission/SysUserRoleMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/permission/SysUserRoleMapper.java index f6f5f383d..79f218b16 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/permission/SysUserRoleMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/permission/SysUserRoleMapper.java @@ -16,6 +16,14 @@ public interface SysUserRoleMapper extends BaseMapperX { return selectList(new QueryWrapper().eq("user_id", userId)); } + default List selectListByRoleId(Long roleId) { + return selectList(new QueryWrapper().eq("role_id", roleId)); + } + + default List selectListByRoleIds(Collection roleIds) { + return selectList("role_id", roleIds); + } + default void insertList(Long userId, Collection roleIds) { List list = roleIds.stream().map(roleId -> { SysUserRoleDO entity = new SysUserRoleDO(); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/permission/SysPermissionService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/permission/SysPermissionService.java index 883a11f4f..78eeb9ad0 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/permission/SysPermissionService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/permission/SysPermissionService.java @@ -67,7 +67,23 @@ public interface SysPermissionService extends SecurityPermissionFrameworkService * @param userId 用户编号 * @return 角色编号集合 */ - Set listUserRoleIs(Long userId); + Set getUserRoleIdListByUserId(Long userId); + + /** + * 获得拥有某个角色的用户编号集合 + * + * @param roleId 角色编号 + * @return 用户编号集合 + */ + Set getUserRoleIdListByRoleId(Long roleId); + + /** + * 获得拥有多个角色的用户编号集合 + * + * @param roleIds 角色编号集合 + * @return 用户编号集合 + */ + Set getUserRoleIdListByRoleIds(Collection roleIds); /** * 设置用户角色 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/permission/impl/SysPermissionServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/permission/impl/SysPermissionServiceImpl.java index 90e320057..32f61c1d8 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/permission/impl/SysPermissionServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/permission/impl/SysPermissionServiceImpl.java @@ -216,11 +216,23 @@ public class SysPermissionServiceImpl implements SysPermissionService { } @Override - public Set listUserRoleIs(Long userId) { + public Set getUserRoleIdListByUserId(Long userId) { return CollectionUtils.convertSet(userRoleMapper.selectListByUserId(userId), SysUserRoleDO::getRoleId); } + @Override + public Set getUserRoleIdListByRoleId(Long roleId) { + return CollectionUtils.convertSet(userRoleMapper.selectListByRoleId(roleId), + SysUserRoleDO::getRoleId); + } + + @Override + public Set getUserRoleIdListByRoleIds(Collection roleIds) { + return CollectionUtils.convertSet(userRoleMapper.selectListByRoleIds(roleIds), + SysUserRoleDO::getRoleId); + } + @Override public void assignUserRole(Long userId, Set roleIds) { // 获得角色拥有角色编号 diff --git a/yudao-admin-ui/src/views/bpm/model/index.vue b/yudao-admin-ui/src/views/bpm/model/index.vue index 22df3d1ed..637f2e803 100644 --- a/yudao-admin-ui/src/views/bpm/model/index.vue +++ b/yudao-admin-ui/src/views/bpm/model/index.vue @@ -204,13 +204,13 @@ - - + + - +