Commit 053e03d068e17889f28017e889062acda132b263
1 parent
5519fdcd
仿钉钉流程设计- 表单字段权限设置
Showing
5 changed files
with
37 additions
and
27 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskRespVO.java
| ... | ... | @@ -67,6 +67,8 @@ public class BpmTaskRespVO { |
| 67 | 67 | private List<String> formFields; |
| 68 | 68 | @Schema(description = "提交的表单值", requiredMode = Schema.RequiredMode.REQUIRED) |
| 69 | 69 | private Map<String, Object> formVariables; |
| 70 | + @Schema(description = "表单字段权限值") | |
| 71 | + private Map<String,String> fieldsPermission; | |
| 70 | 72 | |
| 71 | 73 | @Data |
| 72 | 74 | @Schema(description = "流程实例") | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/task/BpmTaskConvert.java
| ... | ... | @@ -9,6 +9,8 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 9 | 9 | import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceRespVO; |
| 10 | 10 | import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskRespVO; |
| 11 | 11 | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO; |
| 12 | +import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum; | |
| 13 | +import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; | |
| 12 | 14 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils; |
| 13 | 15 | import cn.iocoder.yudao.module.bpm.service.message.dto.BpmMessageSendWhenTaskCreatedReqDTO; |
| 14 | 16 | import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; |
| ... | ... | @@ -86,7 +88,8 @@ public interface BpmTaskConvert { |
| 86 | 88 | BpmnModel bpmnModel) { |
| 87 | 89 | List<BpmTaskRespVO> taskVOList = CollectionUtils.convertList(taskList, task -> { |
| 88 | 90 | BpmTaskRespVO taskVO = BeanUtils.toBean(task, BpmTaskRespVO.class); |
| 89 | - taskVO.setStatus(FlowableUtils.getTaskStatus(task)).setReason(FlowableUtils.getTaskReason(task)); | |
| 91 | + Integer taskStatus = FlowableUtils.getTaskStatus(task); | |
| 92 | + taskVO.setStatus(taskStatus).setReason(FlowableUtils.getTaskReason(task)); | |
| 90 | 93 | // 流程实例 |
| 91 | 94 | AdminUserRespDTO startUser = userMap.get(NumberUtils.parseLong(processInstance.getStartUserId())); |
| 92 | 95 | taskVO.setProcessInstance(BeanUtils.toBean(processInstance, BpmTaskRespVO.ProcessInstance.class)); |
| ... | ... | @@ -94,12 +97,6 @@ public interface BpmTaskConvert { |
| 94 | 97 | // 表单信息 |
| 95 | 98 | BpmFormDO form = MapUtil.get(formMap, NumberUtils.parseLong(task.getFormKey()), BpmFormDO.class); |
| 96 | 99 | if (form != null) { |
| 97 | - // 测试一下权限处理 | |
| 98 | - // TODO @jason:这里是不是还没实现完哈? | |
| 99 | - // TODO @芋艿 测试了一下。 暂时注释掉。 前端不知道要怎样改, 可能需要讨论一下如何改 | |
| 100 | -// List<String> afterChangedFields = BpmnFormUtils.changeCreateFormFiledPermissionRule(form.getFields(), | |
| 101 | -// BpmnModelUtils.parseFormFieldsPermission(bpmnModel, task.getTaskDefinitionKey())); | |
| 102 | - | |
| 103 | 100 | taskVO.setFormId(form.getId()).setFormName(form.getName()).setFormConf(form.getConf()) |
| 104 | 101 | .setFormFields(form.getFields()).setFormVariables(FlowableUtils.getTaskFormVariable(task)); |
| 105 | 102 | } |
| ... | ... | @@ -114,7 +111,11 @@ public interface BpmTaskConvert { |
| 114 | 111 | taskVO.setOwnerUser(BeanUtils.toBean(ownerUser, BpmProcessInstanceRespVO.User.class)); |
| 115 | 112 | findAndThen(deptMap, ownerUser.getDeptId(), dept -> taskVO.getOwnerUser().setDeptName(dept.getName())); |
| 116 | 113 | } |
| 117 | - return taskVO; | |
| 114 | + if(BpmTaskStatusEnum.RUNNING.getStatus().equals(taskStatus)){ | |
| 115 | + // 设置表单权限 TODO @芋艿 是不是还要加一个全局的权限 基于 processInstance 的权限 | |
| 116 | + taskVO.setFieldsPermission(BpmnModelUtils.parseFormFieldsPermission(bpmnModel, task.getTaskDefinitionKey())); | |
| 117 | + } | |
| 118 | + return taskVO; | |
| 118 | 119 | }); |
| 119 | 120 | |
| 120 | 121 | // 拼接父子关系 |
| ... | ... | @@ -159,12 +160,12 @@ public interface BpmTaskConvert { |
| 159 | 160 | |
| 160 | 161 | /** |
| 161 | 162 | * 将父任务的属性,拷贝到子任务(加签任务) |
| 162 | - * | |
| 163 | + * <p> | |
| 163 | 164 | * 为什么不使用 mapstruct 映射?因为 TaskEntityImpl 还有很多其他属性,这里我们只设置我们需要的。 |
| 164 | 165 | * 使用 mapstruct 会将里面嵌套的各个属性值都设置进去,会出现意想不到的问题。 |
| 165 | 166 | * |
| 166 | 167 | * @param parentTask 父任务 |
| 167 | - * @param childTask 加签任务 | |
| 168 | + * @param childTask 加签任务 | |
| 168 | 169 | */ |
| 169 | 170 | default void copyTo(TaskEntityImpl parentTask, TaskEntityImpl childTask) { |
| 170 | 171 | childTask.setName(parentTask.getName()); | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/listener/BpmTaskEventListener.java
| 1 | 1 | package cn.iocoder.yudao.module.bpm.framework.flowable.core.listener; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.hutool.core.util.StrUtil; | |
| 3 | 5 | import cn.iocoder.yudao.module.bpm.service.task.BpmActivityService; |
| 4 | 6 | import cn.iocoder.yudao.module.bpm.service.task.BpmTaskService; |
| 5 | 7 | import com.google.common.collect.ImmutableSet; |
| ... | ... | @@ -9,10 +11,12 @@ import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent; |
| 9 | 11 | import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType; |
| 10 | 12 | import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener; |
| 11 | 13 | import org.flowable.engine.delegate.event.FlowableActivityCancelledEvent; |
| 14 | +import org.flowable.engine.history.HistoricActivityInstance; | |
| 12 | 15 | import org.flowable.task.api.Task; |
| 13 | 16 | import org.springframework.context.annotation.Lazy; |
| 14 | 17 | import org.springframework.stereotype.Component; |
| 15 | 18 | |
| 19 | +import java.util.List; | |
| 16 | 20 | import java.util.Set; |
| 17 | 21 | |
| 18 | 22 | /** |
| ... | ... | @@ -55,18 +59,20 @@ public class BpmTaskEventListener extends AbstractFlowableEngineEventListener { |
| 55 | 59 | @Override |
| 56 | 60 | protected void activityCancelled(FlowableActivityCancelledEvent event) { |
| 57 | 61 | // TODO @jason:如果用户主动取消,可能需要考虑这个 |
| 62 | + // TODO @芋艿 如果在 rejectTask 处理了。 这里又要查询一次。感觉有点多余。 主动取消是不是也要处理一下。要不然有加签的任务也会报错 | |
| 58 | 63 | // @芋艿。 这里是不是就可以不要了, 取消的任务状态,在rejectTask 里面做了, 如果在 updateTaskStatusWhenCanceled 里面修改会报错。 |
| 59 | -// List<HistoricActivityInstance> activityList = activityService.getHistoricActivityListByExecutionId(event.getExecutionId()); | |
| 60 | -// if (CollUtil.isEmpty(activityList)) { | |
| 61 | -// log.error("[activityCancelled][使用 executionId({}) 查找不到对应的活动实例]", event.getExecutionId()); | |
| 62 | -// return; | |
| 63 | -// } | |
| 64 | -// // 遍历处理 | |
| 65 | -// activityList.forEach(activity -> { | |
| 66 | -// if (StrUtil.isEmpty(activity.getTaskId())) { | |
| 67 | -// return; | |
| 68 | -// } | |
| 69 | -// taskService.updateTaskStatusWhenCanceled(activity.getTaskId()); | |
| 70 | -// }); | |
| 64 | + List<HistoricActivityInstance> activityList = activityService.getHistoricActivityListByExecutionId(event.getExecutionId()); | |
| 65 | + if (CollUtil.isEmpty(activityList)) { | |
| 66 | + log.error("[activityCancelled][使用 executionId({}) 查找不到对应的活动实例]", event.getExecutionId()); | |
| 67 | + return; | |
| 68 | + } | |
| 69 | + // 遍历处理 | |
| 70 | + activityList.forEach(activity -> { | |
| 71 | + if (StrUtil.isEmpty(activity.getTaskId())) { | |
| 72 | + return; | |
| 73 | + } | |
| 74 | + taskService.updateTaskStatusWhenCanceled(activity.getTaskId()); | |
| 75 | + }); | |
| 71 | 76 | } |
| 77 | + | |
| 72 | 78 | } | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java
| ... | ... | @@ -60,19 +60,18 @@ public class BpmnModelUtils { |
| 60 | 60 | return element != null ? element.getElementText() : null; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - // TODO @jason:貌似这个没地方调用??? @芋艿 在 BpmTaskConvert里面。暂时注释掉了。 | |
| 64 | - public static Map<String, Integer> parseFormFieldsPermission(BpmnModel bpmnModel, String flowElementId) { | |
| 63 | + public static Map<String, String> parseFormFieldsPermission(BpmnModel bpmnModel, String flowElementId) { | |
| 65 | 64 | FlowElement flowElement = getFlowElementById(bpmnModel, flowElementId); |
| 66 | 65 | if (flowElement == null) { |
| 67 | 66 | return null; |
| 68 | 67 | } |
| 69 | - Map<String, Integer> fieldsPermission = MapUtil.newHashMap(); | |
| 68 | + Map<String, String> fieldsPermission = MapUtil.newHashMap(); | |
| 70 | 69 | List<ExtensionElement> extensionElements = flowElement.getExtensionElements().get(FORM_FIELD_PERMISSION_ELEMENT); |
| 71 | 70 | extensionElements.forEach(element -> { |
| 72 | 71 | String field = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, FORM_FIELD_PERMISSION_ELEMENT_FIELD_ATTRIBUTE); |
| 73 | 72 | String permission = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, FORM_FIELD_PERMISSION_ELEMENT_PERMISSION_ATTRIBUTE); |
| 74 | 73 | if (StrUtil.isNotEmpty(field) && StrUtil.isNotEmpty(permission)) { |
| 75 | - fieldsPermission.put(field, Integer.parseInt(permission)); | |
| 74 | + fieldsPermission.put(field, permission); | |
| 76 | 75 | } |
| 77 | 76 | }); |
| 78 | 77 | return fieldsPermission; | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
| ... | ... | @@ -213,6 +213,8 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 213 | 213 | // 其中,variables 是存储动态表单到 local 任务级别。过滤一下,避免 ProcessInstance 系统级的变量被占用 |
| 214 | 214 | if (CollUtil.isNotEmpty(reqVO.getVariables())) { |
| 215 | 215 | Map<String, Object> variables = FlowableUtils.filterTaskFormVariable(reqVO.getVariables()); |
| 216 | + // 修改表单的值需要存储到 ProcessInstance 变量 | |
| 217 | + runtimeService.setVariables(task.getProcessInstanceId(), variables); | |
| 216 | 218 | taskService.complete(task.getId(), variables, true); |
| 217 | 219 | } else { |
| 218 | 220 | taskService.complete(task.getId()); |
| ... | ... | @@ -371,7 +373,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 371 | 373 | } |
| 372 | 374 | |
| 373 | 375 | // 4.2.1 更新其它正在运行的任务状态为取消。需要过滤掉当前任务和被加签的任务 |
| 374 | - // TODO @jason:如果过滤掉被加签的任务,这些任务被对应的审批人看到是啥状态哈? | |
| 376 | + // TODO @jason:如果过滤掉被加签的任务,这些任务被对应的审批人看到是啥状态哈? @芋艿 为不通过状态。 | |
| 375 | 377 | List<Task> taskList = getRunningTaskListByProcessInstanceId(instance.getProcessInstanceId(), false, null, null); |
| 376 | 378 | updateTaskStatusWhenCanceled( |
| 377 | 379 | CollectionUtils.filterList(taskList, item -> !item.getId().equals(task.getId()) && !item.getId().equals(task.getParentTaskId())), | ... | ... |