Commit 58e250c4eb39924ce6daf6aed64e5348276792ab

Authored by jason
1 parent 053e03d0

仿钉钉流程设计- 操作按钮权限设置

yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/simple/BpmSimpleModelNodeVO.java
@@ -65,11 +65,14 @@ public class BpmSimpleModelNodeVO { @@ -65,11 +65,14 @@ public class BpmSimpleModelNodeVO {
65 @InEnum(BpmApproveMethodEnum.class) 65 @InEnum(BpmApproveMethodEnum.class)
66 private Integer approveMethod; // 用于审批节点 66 private Integer approveMethod; // 用于审批节点
67 67
  68 + @Schema(description = "通过比例", example = "100")
  69 + private Integer approveRatio; // 通过比例,当多人审批方式为:多人会签(按通过比例) 需要设置
  70 +
68 @Schema(description = "表单权限", example = "[]") 71 @Schema(description = "表单权限", example = "[]")
69 private List<Map<String, String>> fieldsPermission; 72 private List<Map<String, String>> fieldsPermission;
70 73
71 - @Schema(description = "通过比例", example = "100")  
72 - private Integer approveRatio; // 通过比例,当多人审批方式为:多人会签(按通过比例) 需要设置 74 + @Schema(description = "操作按钮设置", example = "[]")
  75 + private List<OperationButtonSetting> buttonsSetting; // 用于审批节点
73 76
74 /** 77 /**
75 * 审批节点拒绝处理 78 * 审批节点拒绝处理
@@ -111,6 +114,19 @@ public class BpmSimpleModelNodeVO { @@ -111,6 +114,19 @@ public class BpmSimpleModelNodeVO {
111 private Integer maxRemindCount; 114 private Integer maxRemindCount;
112 } 115 }
113 116
  117 + @Data
  118 + @Schema(description = "操作按钮设置")
  119 + public static class OperationButtonSetting {
  120 +
  121 + @Schema(description = "按钮 Id", example = "1")
  122 + private Integer id;
  123 +
  124 + @Schema(description = "显示名称", example = "审批")
  125 + private String displayName;
  126 +
  127 + @Schema(description = "是否启用", example = "true")
  128 + private Boolean enable;
  129 + }
114 130
115 // Map<String, Integer> formPermissions; 表单权限;仅发起、审批、抄送节点会使用 131 // Map<String, Integer> formPermissions; 表单权限;仅发起、审批、抄送节点会使用
116 // Integer approveMethod; 审批方式;仅审批节点会使用 132 // Integer approveMethod; 审批方式;仅审批节点会使用
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskRespVO.java
@@ -69,6 +69,8 @@ public class BpmTaskRespVO { @@ -69,6 +69,8 @@ public class BpmTaskRespVO {
69 private Map<String, Object> formVariables; 69 private Map<String, Object> formVariables;
70 @Schema(description = "表单字段权限值") 70 @Schema(description = "表单字段权限值")
71 private Map<String,String> fieldsPermission; 71 private Map<String,String> fieldsPermission;
  72 + @Schema(description = "操作按钮设置值")
  73 + private Map<Integer,OperationButtonSetting> buttonsSetting;
72 74
73 @Data 75 @Data
74 @Schema(description = "流程实例") 76 @Schema(description = "流程实例")
@@ -93,4 +95,15 @@ public class BpmTaskRespVO { @@ -93,4 +95,15 @@ public class BpmTaskRespVO {
93 95
94 } 96 }
95 97
  98 + @Data
  99 + @Schema(description = "操作按钮设置")
  100 + public static class OperationButtonSetting {
  101 +
  102 + @Schema(description = "显示名称", example = "审批")
  103 + private String displayName;
  104 +
  105 + @Schema(description = "是否启用", example = "true")
  106 + private Boolean enable;
  107 + }
  108 +
96 } 109 }
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/task/BpmTaskConvert.java
@@ -114,6 +114,8 @@ public interface BpmTaskConvert { @@ -114,6 +114,8 @@ public interface BpmTaskConvert {
114 if(BpmTaskStatusEnum.RUNNING.getStatus().equals(taskStatus)){ 114 if(BpmTaskStatusEnum.RUNNING.getStatus().equals(taskStatus)){
115 // 设置表单权限 TODO @芋艿 是不是还要加一个全局的权限 基于 processInstance 的权限 115 // 设置表单权限 TODO @芋艿 是不是还要加一个全局的权限 基于 processInstance 的权限
116 taskVO.setFieldsPermission(BpmnModelUtils.parseFormFieldsPermission(bpmnModel, task.getTaskDefinitionKey())); 116 taskVO.setFieldsPermission(BpmnModelUtils.parseFormFieldsPermission(bpmnModel, task.getTaskDefinitionKey()));
  117 + // 操作按钮设置
  118 + taskVO.setButtonsSetting(BpmnModelUtils.parseButtonsSetting(bpmnModel, task.getTaskDefinitionKey()));
117 } 119 }
118 return taskVO; 120 return taskVO;
119 }); 121 });
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/enums/BpmnModelConstants.java
@@ -71,6 +71,26 @@ public interface BpmnModelConstants { @@ -71,6 +71,26 @@ public interface BpmnModelConstants {
71 */ 71 */
72 String FORM_FIELD_PERMISSION_ELEMENT_PERMISSION_ATTRIBUTE = "permission"; 72 String FORM_FIELD_PERMISSION_ELEMENT_PERMISSION_ATTRIBUTE = "permission";
73 73
  74 + /**
  75 + * BPMN ExtensionElement 操作按钮设置元素, 用于审批节点操作按钮设置
  76 + */
  77 + String BUTTON_SETTING_ELEMENT = "buttonsSettings";
  78 +
  79 + /**
  80 + * BPMN ExtensionElement Attribute, 用于标记按钮编号
  81 + */
  82 + String BUTTON_SETTING_ELEMENT_ID_ATTRIBUTE = "id";
  83 +
  84 + /**
  85 + * BPMN ExtensionElement Attribute, 用于标记按钮显示名称
  86 + */
  87 + String BUTTON_SETTING_ELEMENT_DISPLAY_NAME_ATTRIBUTE = "displayName";
  88 +
  89 + /**
  90 + * BPMN ExtensionElement Attribute, 用于标记按钮是否启用
  91 + */
  92 + String BUTTON_SETTING_ELEMENT_ENABLE_ATTRIBUTE = "enable";
  93 +
74 // TODO @芋艿:这里后面得关注下; 94 // TODO @芋艿:这里后面得关注下;
75 /** 95 /**
76 * BPMN End Event 节点 Id, 用于后端生成 End Event 节点 96 * BPMN End Event 节点 Id, 用于后端生成 End Event 节点
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java
@@ -5,6 +5,7 @@ import cn.hutool.core.map.MapUtil; @@ -5,6 +5,7 @@ import cn.hutool.core.map.MapUtil;
5 import cn.hutool.core.util.ArrayUtil; 5 import cn.hutool.core.util.ArrayUtil;
6 import cn.hutool.core.util.StrUtil; 6 import cn.hutool.core.util.StrUtil;
7 import cn.iocoder.yudao.framework.common.util.number.NumberUtils; 7 import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
  8 +import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskRespVO;
8 import cn.iocoder.yudao.module.bpm.enums.definition.BpmUserTaskRejectHandlerType; 9 import cn.iocoder.yudao.module.bpm.enums.definition.BpmUserTaskRejectHandlerType;
9 import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants; 10 import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants;
10 import org.flowable.bpmn.converter.BpmnXMLConverter; 11 import org.flowable.bpmn.converter.BpmnXMLConverter;
@@ -65,8 +66,11 @@ public class BpmnModelUtils { @@ -65,8 +66,11 @@ public class BpmnModelUtils {
65 if (flowElement == null) { 66 if (flowElement == null) {
66 return null; 67 return null;
67 } 68 }
68 - Map<String, String> fieldsPermission = MapUtil.newHashMap();  
69 List<ExtensionElement> extensionElements = flowElement.getExtensionElements().get(FORM_FIELD_PERMISSION_ELEMENT); 69 List<ExtensionElement> extensionElements = flowElement.getExtensionElements().get(FORM_FIELD_PERMISSION_ELEMENT);
  70 + if (CollUtil.isEmpty(extensionElements)) {
  71 + return null;
  72 + }
  73 + Map<String, String> fieldsPermission = MapUtil.newHashMap();
70 extensionElements.forEach(element -> { 74 extensionElements.forEach(element -> {
71 String field = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, FORM_FIELD_PERMISSION_ELEMENT_FIELD_ATTRIBUTE); 75 String field = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, FORM_FIELD_PERMISSION_ELEMENT_FIELD_ATTRIBUTE);
72 String permission = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, FORM_FIELD_PERMISSION_ELEMENT_PERMISSION_ATTRIBUTE); 76 String permission = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, FORM_FIELD_PERMISSION_ELEMENT_PERMISSION_ATTRIBUTE);
@@ -77,6 +81,28 @@ public class BpmnModelUtils { @@ -77,6 +81,28 @@ public class BpmnModelUtils {
77 return fieldsPermission; 81 return fieldsPermission;
78 } 82 }
79 83
  84 + public static Map<Integer, BpmTaskRespVO.OperationButtonSetting> parseButtonsSetting(BpmnModel bpmnModel, String flowElementId) {
  85 + FlowElement flowElement = getFlowElementById(bpmnModel, flowElementId);
  86 + if (flowElement == null) {
  87 + return null;
  88 + }
  89 + List<ExtensionElement> extensionElements = flowElement.getExtensionElements().get(BUTTON_SETTING_ELEMENT);
  90 + if (CollUtil.isEmpty(extensionElements)) {
  91 + return null;
  92 + }
  93 + Map<Integer, BpmTaskRespVO.OperationButtonSetting> buttonSettings = MapUtil.newHashMap(16);
  94 + extensionElements.forEach(element -> {
  95 + String id = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, BUTTON_SETTING_ELEMENT_ID_ATTRIBUTE);
  96 + String displayName = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, BUTTON_SETTING_ELEMENT_DISPLAY_NAME_ATTRIBUTE);
  97 + String enable = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, BUTTON_SETTING_ELEMENT_ENABLE_ATTRIBUTE);
  98 + if (StrUtil.isNotEmpty(id)) {
  99 + BpmTaskRespVO.OperationButtonSetting setting = new BpmTaskRespVO.OperationButtonSetting();
  100 + buttonSettings.put(Integer.valueOf(id), setting.setDisplayName(displayName).setEnable(Boolean.parseBoolean(enable)));
  101 + }
  102 + });
  103 + return buttonSettings;
  104 + }
  105 +
80 /** 106 /**
81 * 根据节点,获取入口连线 107 * 根据节点,获取入口连线
82 * 108 *
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/SimpleModelUtils.java
@@ -23,6 +23,7 @@ import java.util.List; @@ -23,6 +23,7 @@ import java.util.List;
23 import java.util.Map; 23 import java.util.Map;
24 import java.util.Objects; 24 import java.util.Objects;
25 25
  26 +import static cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO.OperationButtonSetting;
26 import static cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO.TimeoutHandler; 27 import static cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO.TimeoutHandler;
27 import static cn.iocoder.yudao.module.bpm.enums.definition.BpmBoundaryEventType.USER_TASK_TIMEOUT; 28 import static cn.iocoder.yudao.module.bpm.enums.definition.BpmBoundaryEventType.USER_TASK_TIMEOUT;
28 import static cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType.*; 29 import static cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType.*;
@@ -454,6 +455,8 @@ public class SimpleModelUtils { @@ -454,6 +455,8 @@ public class SimpleModelUtils {
454 addCandidateElements(node.getCandidateStrategy(), node.getCandidateParam(), userTask); 455 addCandidateElements(node.getCandidateStrategy(), node.getCandidateParam(), userTask);
455 // 添加表单字段权限属性元素 456 // 添加表单字段权限属性元素
456 addFormFieldsPermission(node.getFieldsPermission(), userTask); 457 addFormFieldsPermission(node.getFieldsPermission(), userTask);
  458 + // 添加操作按钮配置属性元素
  459 + addButtonsSetting(node.getButtonsSetting(), userTask);
457 // 处理多实例 460 // 处理多实例
458 processMultiInstanceLoopCharacteristics(node.getApproveMethod(), node.getApproveRatio(), userTask); 461 processMultiInstanceLoopCharacteristics(node.getApproveMethod(), node.getApproveRatio(), userTask);
459 // 添加任务被拒绝的处理元素 462 // 添加任务被拒绝的处理元素
@@ -461,6 +464,7 @@ public class SimpleModelUtils { @@ -461,6 +464,7 @@ public class SimpleModelUtils {
461 return userTask; 464 return userTask;
462 } 465 }
463 466
  467 +
464 private static void addTaskRejectElements(RejectHandler rejectHandler, UserTask userTask) { 468 private static void addTaskRejectElements(RejectHandler rejectHandler, UserTask userTask) {
465 if (rejectHandler == null) { 469 if (rejectHandler == null) {
466 return; 470 return;
@@ -499,6 +503,22 @@ public class SimpleModelUtils { @@ -499,6 +503,22 @@ public class SimpleModelUtils {
499 } 503 }
500 504
501 /** 505 /**
  506 + * 给节点添加操作按钮设置元素
  507 + */
  508 + private static void addButtonsSetting(List<OperationButtonSetting> buttonsSetting, UserTask userTask) {
  509 + if (CollUtil.isNotEmpty(buttonsSetting)) {
  510 + List<Map<String, String>> list = CollectionUtils.convertList(buttonsSetting, item -> {
  511 + Map<String, String> settingMap = MapUtil.newHashMap(16);
  512 + settingMap.put(BUTTON_SETTING_ELEMENT_ID_ATTRIBUTE, String.valueOf(item.getId()));
  513 + settingMap.put(BUTTON_SETTING_ELEMENT_DISPLAY_NAME_ATTRIBUTE, item.getDisplayName());
  514 + settingMap.put(BUTTON_SETTING_ELEMENT_ENABLE_ATTRIBUTE, String.valueOf(item.getEnable()));
  515 + return settingMap;
  516 + });
  517 + list.forEach(item -> addExtensionElement(userTask, BUTTON_SETTING_ELEMENT, item));
  518 + }
  519 + }
  520 +
  521 + /**
502 * 给节点添加表单字段权限元素 522 * 给节点添加表单字段权限元素
503 */ 523 */
504 private static void addFormFieldsPermission(List<Map<String, String>> fieldsPermissions, FlowElement flowElement) { 524 private static void addFormFieldsPermission(List<Map<String, String>> fieldsPermissions, FlowElement flowElement) {