Commit 053e03d068e17889f28017e889062acda132b263

Authored by jason
1 parent 5519fdcd

仿钉钉流程设计- 表单字段权限设置

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,6 +67,8 @@ public class BpmTaskRespVO {
67 private List<String> formFields; 67 private List<String> formFields;
68 @Schema(description = "提交的表单值", requiredMode = Schema.RequiredMode.REQUIRED) 68 @Schema(description = "提交的表单值", requiredMode = Schema.RequiredMode.REQUIRED)
69 private Map<String, Object> formVariables; 69 private Map<String, Object> formVariables;
  70 + @Schema(description = "表单字段权限值")
  71 + private Map<String,String> fieldsPermission;
70 72
71 @Data 73 @Data
72 @Schema(description = "流程实例") 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,6 +9,8 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
9 import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceRespVO; 9 import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceRespVO;
10 import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskRespVO; 10 import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskRespVO;
11 import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO; 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 import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils; 14 import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
13 import cn.iocoder.yudao.module.bpm.service.message.dto.BpmMessageSendWhenTaskCreatedReqDTO; 15 import cn.iocoder.yudao.module.bpm.service.message.dto.BpmMessageSendWhenTaskCreatedReqDTO;
14 import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; 16 import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
@@ -86,7 +88,8 @@ public interface BpmTaskConvert { @@ -86,7 +88,8 @@ public interface BpmTaskConvert {
86 BpmnModel bpmnModel) { 88 BpmnModel bpmnModel) {
87 List<BpmTaskRespVO> taskVOList = CollectionUtils.convertList(taskList, task -> { 89 List<BpmTaskRespVO> taskVOList = CollectionUtils.convertList(taskList, task -> {
88 BpmTaskRespVO taskVO = BeanUtils.toBean(task, BpmTaskRespVO.class); 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 AdminUserRespDTO startUser = userMap.get(NumberUtils.parseLong(processInstance.getStartUserId())); 94 AdminUserRespDTO startUser = userMap.get(NumberUtils.parseLong(processInstance.getStartUserId()));
92 taskVO.setProcessInstance(BeanUtils.toBean(processInstance, BpmTaskRespVO.ProcessInstance.class)); 95 taskVO.setProcessInstance(BeanUtils.toBean(processInstance, BpmTaskRespVO.ProcessInstance.class));
@@ -94,12 +97,6 @@ public interface BpmTaskConvert { @@ -94,12 +97,6 @@ public interface BpmTaskConvert {
94 // 表单信息 97 // 表单信息
95 BpmFormDO form = MapUtil.get(formMap, NumberUtils.parseLong(task.getFormKey()), BpmFormDO.class); 98 BpmFormDO form = MapUtil.get(formMap, NumberUtils.parseLong(task.getFormKey()), BpmFormDO.class);
96 if (form != null) { 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 taskVO.setFormId(form.getId()).setFormName(form.getName()).setFormConf(form.getConf()) 100 taskVO.setFormId(form.getId()).setFormName(form.getName()).setFormConf(form.getConf())
104 .setFormFields(form.getFields()).setFormVariables(FlowableUtils.getTaskFormVariable(task)); 101 .setFormFields(form.getFields()).setFormVariables(FlowableUtils.getTaskFormVariable(task));
105 } 102 }
@@ -114,7 +111,11 @@ public interface BpmTaskConvert { @@ -114,7 +111,11 @@ public interface BpmTaskConvert {
114 taskVO.setOwnerUser(BeanUtils.toBean(ownerUser, BpmProcessInstanceRespVO.User.class)); 111 taskVO.setOwnerUser(BeanUtils.toBean(ownerUser, BpmProcessInstanceRespVO.User.class));
115 findAndThen(deptMap, ownerUser.getDeptId(), dept -> taskVO.getOwnerUser().setDeptName(dept.getName())); 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,12 +160,12 @@ public interface BpmTaskConvert {
159 160
160 /** 161 /**
161 * 将父任务的属性,拷贝到子任务(加签任务) 162 * 将父任务的属性,拷贝到子任务(加签任务)
162 - * 163 + * <p>
163 * 为什么不使用 mapstruct 映射?因为 TaskEntityImpl 还有很多其他属性,这里我们只设置我们需要的。 164 * 为什么不使用 mapstruct 映射?因为 TaskEntityImpl 还有很多其他属性,这里我们只设置我们需要的。
164 * 使用 mapstruct 会将里面嵌套的各个属性值都设置进去,会出现意想不到的问题。 165 * 使用 mapstruct 会将里面嵌套的各个属性值都设置进去,会出现意想不到的问题。
165 * 166 *
166 * @param parentTask 父任务 167 * @param parentTask 父任务
167 - * @param childTask 加签任务 168 + * @param childTask 加签任务
168 */ 169 */
169 default void copyTo(TaskEntityImpl parentTask, TaskEntityImpl childTask) { 170 default void copyTo(TaskEntityImpl parentTask, TaskEntityImpl childTask) {
170 childTask.setName(parentTask.getName()); 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 package cn.iocoder.yudao.module.bpm.framework.flowable.core.listener; 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 import cn.iocoder.yudao.module.bpm.service.task.BpmActivityService; 5 import cn.iocoder.yudao.module.bpm.service.task.BpmActivityService;
4 import cn.iocoder.yudao.module.bpm.service.task.BpmTaskService; 6 import cn.iocoder.yudao.module.bpm.service.task.BpmTaskService;
5 import com.google.common.collect.ImmutableSet; 7 import com.google.common.collect.ImmutableSet;
@@ -9,10 +11,12 @@ import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent; @@ -9,10 +11,12 @@ import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
9 import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType; 11 import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
10 import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener; 12 import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener;
11 import org.flowable.engine.delegate.event.FlowableActivityCancelledEvent; 13 import org.flowable.engine.delegate.event.FlowableActivityCancelledEvent;
  14 +import org.flowable.engine.history.HistoricActivityInstance;
12 import org.flowable.task.api.Task; 15 import org.flowable.task.api.Task;
13 import org.springframework.context.annotation.Lazy; 16 import org.springframework.context.annotation.Lazy;
14 import org.springframework.stereotype.Component; 17 import org.springframework.stereotype.Component;
15 18
  19 +import java.util.List;
16 import java.util.Set; 20 import java.util.Set;
17 21
18 /** 22 /**
@@ -55,18 +59,20 @@ public class BpmTaskEventListener extends AbstractFlowableEngineEventListener { @@ -55,18 +59,20 @@ public class BpmTaskEventListener extends AbstractFlowableEngineEventListener {
55 @Override 59 @Override
56 protected void activityCancelled(FlowableActivityCancelledEvent event) { 60 protected void activityCancelled(FlowableActivityCancelledEvent event) {
57 // TODO @jason:如果用户主动取消,可能需要考虑这个 61 // TODO @jason:如果用户主动取消,可能需要考虑这个
  62 + // TODO @芋艿 如果在 rejectTask 处理了。 这里又要查询一次。感觉有点多余。 主动取消是不是也要处理一下。要不然有加签的任务也会报错
58 // @芋艿。 这里是不是就可以不要了, 取消的任务状态,在rejectTask 里面做了, 如果在 updateTaskStatusWhenCanceled 里面修改会报错。 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,19 +60,18 @@ public class BpmnModelUtils {
60 return element != null ? element.getElementText() : null; 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 FlowElement flowElement = getFlowElementById(bpmnModel, flowElementId); 64 FlowElement flowElement = getFlowElementById(bpmnModel, flowElementId);
66 if (flowElement == null) { 65 if (flowElement == null) {
67 return null; 66 return null;
68 } 67 }
69 - Map<String, Integer> fieldsPermission = MapUtil.newHashMap(); 68 + Map<String, String> fieldsPermission = MapUtil.newHashMap();
70 List<ExtensionElement> extensionElements = flowElement.getExtensionElements().get(FORM_FIELD_PERMISSION_ELEMENT); 69 List<ExtensionElement> extensionElements = flowElement.getExtensionElements().get(FORM_FIELD_PERMISSION_ELEMENT);
71 extensionElements.forEach(element -> { 70 extensionElements.forEach(element -> {
72 String field = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, FORM_FIELD_PERMISSION_ELEMENT_FIELD_ATTRIBUTE); 71 String field = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, FORM_FIELD_PERMISSION_ELEMENT_FIELD_ATTRIBUTE);
73 String permission = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, FORM_FIELD_PERMISSION_ELEMENT_PERMISSION_ATTRIBUTE); 72 String permission = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, FORM_FIELD_PERMISSION_ELEMENT_PERMISSION_ATTRIBUTE);
74 if (StrUtil.isNotEmpty(field) && StrUtil.isNotEmpty(permission)) { 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 return fieldsPermission; 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,6 +213,8 @@ public class BpmTaskServiceImpl implements BpmTaskService {
213 // 其中,variables 是存储动态表单到 local 任务级别。过滤一下,避免 ProcessInstance 系统级的变量被占用 213 // 其中,variables 是存储动态表单到 local 任务级别。过滤一下,避免 ProcessInstance 系统级的变量被占用
214 if (CollUtil.isNotEmpty(reqVO.getVariables())) { 214 if (CollUtil.isNotEmpty(reqVO.getVariables())) {
215 Map<String, Object> variables = FlowableUtils.filterTaskFormVariable(reqVO.getVariables()); 215 Map<String, Object> variables = FlowableUtils.filterTaskFormVariable(reqVO.getVariables());
  216 + // 修改表单的值需要存储到 ProcessInstance 变量
  217 + runtimeService.setVariables(task.getProcessInstanceId(), variables);
216 taskService.complete(task.getId(), variables, true); 218 taskService.complete(task.getId(), variables, true);
217 } else { 219 } else {
218 taskService.complete(task.getId()); 220 taskService.complete(task.getId());
@@ -371,7 +373,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { @@ -371,7 +373,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
371 } 373 }
372 374
373 // 4.2.1 更新其它正在运行的任务状态为取消。需要过滤掉当前任务和被加签的任务 375 // 4.2.1 更新其它正在运行的任务状态为取消。需要过滤掉当前任务和被加签的任务
374 - // TODO @jason:如果过滤掉被加签的任务,这些任务被对应的审批人看到是啥状态哈? 376 + // TODO @jason:如果过滤掉被加签的任务,这些任务被对应的审批人看到是啥状态哈? @芋艿 为不通过状态。
375 List<Task> taskList = getRunningTaskListByProcessInstanceId(instance.getProcessInstanceId(), false, null, null); 377 List<Task> taskList = getRunningTaskListByProcessInstanceId(instance.getProcessInstanceId(), false, null, null);
376 updateTaskStatusWhenCanceled( 378 updateTaskStatusWhenCanceled(
377 CollectionUtils.filterList(taskList, item -> !item.getId().equals(task.getId()) && !item.getId().equals(task.getParentTaskId())), 379 CollectionUtils.filterList(taskList, item -> !item.getId().equals(task.getId()) && !item.getId().equals(task.getParentTaskId())),