mirror of
				https://github.com/YunaiV/ruoyi-vue-pro.git
				synced 2025-10-31 10:37:41 +08:00 
			
		
		
		
	仿钉钉流程设计- 操作按钮权限设置
This commit is contained in:
		| @ -65,11 +65,14 @@ public class BpmSimpleModelNodeVO { | ||||
|     @InEnum(BpmApproveMethodEnum.class) | ||||
|     private Integer approveMethod; // 用于审批节点 | ||||
|  | ||||
|     @Schema(description = "通过比例", example = "100") | ||||
|     private Integer approveRatio; // 通过比例,当多人审批方式为:多人会签(按通过比例) 需要设置 | ||||
|  | ||||
|     @Schema(description = "表单权限", example = "[]") | ||||
|     private List<Map<String, String>> fieldsPermission; | ||||
|  | ||||
|     @Schema(description = "通过比例", example = "100") | ||||
|     private Integer approveRatio; // 通过比例,当多人审批方式为:多人会签(按通过比例) 需要设置 | ||||
|     @Schema(description = "操作按钮设置", example = "[]") | ||||
|     private List<OperationButtonSetting> buttonsSetting;  // 用于审批节点 | ||||
|  | ||||
|     /** | ||||
|      * 审批节点拒绝处理 | ||||
| @ -111,6 +114,19 @@ public class BpmSimpleModelNodeVO { | ||||
|         private Integer maxRemindCount; | ||||
|     } | ||||
|  | ||||
|     @Data | ||||
|     @Schema(description = "操作按钮设置") | ||||
|     public static class OperationButtonSetting { | ||||
|  | ||||
|         @Schema(description = "按钮 Id", example = "1") | ||||
|         private  Integer id; | ||||
|  | ||||
|         @Schema(description = "显示名称", example = "审批") | ||||
|         private String displayName; | ||||
|  | ||||
|         @Schema(description = "是否启用", example = "true") | ||||
|         private Boolean enable; | ||||
|     } | ||||
|  | ||||
|     // Map<String, Integer> formPermissions; 表单权限;仅发起、审批、抄送节点会使用 | ||||
|     // Integer approveMethod; 审批方式;仅审批节点会使用 | ||||
|  | ||||
| @ -69,6 +69,8 @@ public class BpmTaskRespVO { | ||||
|     private Map<String, Object> formVariables; | ||||
|     @Schema(description = "表单字段权限值") | ||||
|     private Map<String,String> fieldsPermission; | ||||
|     @Schema(description = "操作按钮设置值") | ||||
|     private Map<Integer,OperationButtonSetting> buttonsSetting; | ||||
|  | ||||
|     @Data | ||||
|     @Schema(description = "流程实例") | ||||
| @ -93,4 +95,15 @@ public class BpmTaskRespVO { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Data | ||||
|     @Schema(description = "操作按钮设置") | ||||
|     public static class OperationButtonSetting { | ||||
|  | ||||
|         @Schema(description = "显示名称", example = "审批") | ||||
|         private String displayName; | ||||
|  | ||||
|         @Schema(description = "是否启用", example = "true") | ||||
|         private Boolean enable; | ||||
|     } | ||||
|  | ||||
| } | ||||
|  | ||||
| @ -114,6 +114,8 @@ public interface BpmTaskConvert { | ||||
|             if(BpmTaskStatusEnum.RUNNING.getStatus().equals(taskStatus)){ | ||||
|                 // 设置表单权限 TODO @芋艿 是不是还要加一个全局的权限 基于 processInstance 的权限 | ||||
|                 taskVO.setFieldsPermission(BpmnModelUtils.parseFormFieldsPermission(bpmnModel, task.getTaskDefinitionKey())); | ||||
|                 // 操作按钮设置 | ||||
|                 taskVO.setButtonsSetting(BpmnModelUtils.parseButtonsSetting(bpmnModel, task.getTaskDefinitionKey())); | ||||
|             } | ||||
|            return taskVO; | ||||
|         }); | ||||
|  | ||||
| @ -71,6 +71,26 @@ public interface BpmnModelConstants { | ||||
|      */ | ||||
|     String FORM_FIELD_PERMISSION_ELEMENT_PERMISSION_ATTRIBUTE = "permission"; | ||||
|  | ||||
|     /** | ||||
|      * BPMN ExtensionElement 操作按钮设置元素, 用于审批节点操作按钮设置 | ||||
|      */ | ||||
|     String BUTTON_SETTING_ELEMENT = "buttonsSettings"; | ||||
|  | ||||
|     /** | ||||
|      * BPMN ExtensionElement Attribute, 用于标记按钮编号 | ||||
|      */ | ||||
|     String BUTTON_SETTING_ELEMENT_ID_ATTRIBUTE = "id"; | ||||
|  | ||||
|     /** | ||||
|      * BPMN ExtensionElement Attribute, 用于标记按钮显示名称 | ||||
|      */ | ||||
|     String BUTTON_SETTING_ELEMENT_DISPLAY_NAME_ATTRIBUTE = "displayName"; | ||||
|  | ||||
|     /** | ||||
|      * BPMN ExtensionElement Attribute, 用于标记按钮是否启用 | ||||
|      */ | ||||
|     String BUTTON_SETTING_ELEMENT_ENABLE_ATTRIBUTE = "enable"; | ||||
|  | ||||
|     // TODO @芋艿:这里后面得关注下; | ||||
|     /** | ||||
|      * BPMN End Event 节点 Id, 用于后端生成 End Event 节点 | ||||
|  | ||||
| @ -5,6 +5,7 @@ import cn.hutool.core.map.MapUtil; | ||||
| import cn.hutool.core.util.ArrayUtil; | ||||
| import cn.hutool.core.util.StrUtil; | ||||
| import cn.iocoder.yudao.framework.common.util.number.NumberUtils; | ||||
| import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskRespVO; | ||||
| import cn.iocoder.yudao.module.bpm.enums.definition.BpmUserTaskRejectHandlerType; | ||||
| import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants; | ||||
| import org.flowable.bpmn.converter.BpmnXMLConverter; | ||||
| @ -65,8 +66,11 @@ public class BpmnModelUtils { | ||||
|         if (flowElement == null) { | ||||
|             return null; | ||||
|         } | ||||
|         Map<String, String> fieldsPermission = MapUtil.newHashMap(); | ||||
|         List<ExtensionElement> extensionElements = flowElement.getExtensionElements().get(FORM_FIELD_PERMISSION_ELEMENT); | ||||
|         if (CollUtil.isEmpty(extensionElements)) { | ||||
|             return null; | ||||
|         } | ||||
|         Map<String, String> fieldsPermission = MapUtil.newHashMap(); | ||||
|         extensionElements.forEach(element -> { | ||||
|             String field = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, FORM_FIELD_PERMISSION_ELEMENT_FIELD_ATTRIBUTE); | ||||
|             String permission = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, FORM_FIELD_PERMISSION_ELEMENT_PERMISSION_ATTRIBUTE); | ||||
| @ -77,6 +81,28 @@ public class BpmnModelUtils { | ||||
|         return fieldsPermission; | ||||
|     } | ||||
|  | ||||
|     public static Map<Integer, BpmTaskRespVO.OperationButtonSetting> parseButtonsSetting(BpmnModel bpmnModel, String flowElementId) { | ||||
|         FlowElement flowElement = getFlowElementById(bpmnModel, flowElementId); | ||||
|         if (flowElement == null) { | ||||
|             return null; | ||||
|         } | ||||
|         List<ExtensionElement> extensionElements = flowElement.getExtensionElements().get(BUTTON_SETTING_ELEMENT); | ||||
|         if (CollUtil.isEmpty(extensionElements)) { | ||||
|             return null; | ||||
|         } | ||||
|         Map<Integer, BpmTaskRespVO.OperationButtonSetting> buttonSettings = MapUtil.newHashMap(16); | ||||
|         extensionElements.forEach(element -> { | ||||
|             String id = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, BUTTON_SETTING_ELEMENT_ID_ATTRIBUTE); | ||||
|             String displayName = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, BUTTON_SETTING_ELEMENT_DISPLAY_NAME_ATTRIBUTE); | ||||
|             String enable = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, BUTTON_SETTING_ELEMENT_ENABLE_ATTRIBUTE); | ||||
|             if (StrUtil.isNotEmpty(id)) { | ||||
|                 BpmTaskRespVO.OperationButtonSetting setting = new BpmTaskRespVO.OperationButtonSetting(); | ||||
|                 buttonSettings.put(Integer.valueOf(id), setting.setDisplayName(displayName).setEnable(Boolean.parseBoolean(enable))); | ||||
|             } | ||||
|         }); | ||||
|         return buttonSettings; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 根据节点,获取入口连线 | ||||
|      * | ||||
|  | ||||
| @ -23,6 +23,7 @@ import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.Objects; | ||||
|  | ||||
| import static cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO.OperationButtonSetting; | ||||
| import static cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO.TimeoutHandler; | ||||
| import static cn.iocoder.yudao.module.bpm.enums.definition.BpmBoundaryEventType.USER_TASK_TIMEOUT; | ||||
| import static cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType.*; | ||||
| @ -454,6 +455,8 @@ public class SimpleModelUtils { | ||||
|         addCandidateElements(node.getCandidateStrategy(), node.getCandidateParam(), userTask); | ||||
|         // 添加表单字段权限属性元素 | ||||
|         addFormFieldsPermission(node.getFieldsPermission(), userTask); | ||||
|         // 添加操作按钮配置属性元素 | ||||
|         addButtonsSetting(node.getButtonsSetting(), userTask); | ||||
|         // 处理多实例 | ||||
|         processMultiInstanceLoopCharacteristics(node.getApproveMethod(), node.getApproveRatio(), userTask); | ||||
|         // 添加任务被拒绝的处理元素 | ||||
| @ -461,6 +464,7 @@ public class SimpleModelUtils { | ||||
|         return userTask; | ||||
|     } | ||||
|  | ||||
|  | ||||
|     private static void addTaskRejectElements(RejectHandler rejectHandler, UserTask userTask) { | ||||
|         if (rejectHandler == null) { | ||||
|             return; | ||||
| @ -498,6 +502,22 @@ public class SimpleModelUtils { | ||||
|         userTask.setLoopCharacteristics(multiInstanceCharacteristics); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 给节点添加操作按钮设置元素 | ||||
|      */ | ||||
|     private static void addButtonsSetting(List<OperationButtonSetting> buttonsSetting, UserTask userTask) { | ||||
|         if (CollUtil.isNotEmpty(buttonsSetting)) { | ||||
|             List<Map<String, String>> list = CollectionUtils.convertList(buttonsSetting, item -> { | ||||
|                 Map<String, String> settingMap = MapUtil.newHashMap(16); | ||||
|                 settingMap.put(BUTTON_SETTING_ELEMENT_ID_ATTRIBUTE, String.valueOf(item.getId())); | ||||
|                 settingMap.put(BUTTON_SETTING_ELEMENT_DISPLAY_NAME_ATTRIBUTE, item.getDisplayName()); | ||||
|                 settingMap.put(BUTTON_SETTING_ELEMENT_ENABLE_ATTRIBUTE, String.valueOf(item.getEnable())); | ||||
|                 return settingMap; | ||||
|             }); | ||||
|             list.forEach(item -> addExtensionElement(userTask, BUTTON_SETTING_ELEMENT, item)); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 给节点添加表单字段权限元素 | ||||
|      */ | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 jason
					jason