bpm:code review 快搭实现

This commit is contained in:
YunaiV 2024-04-18 12:38:38 +08:00
parent 1e30e4851a
commit 5d390d2d65
8 changed files with 28 additions and 11 deletions

View File

@ -13,14 +13,22 @@ import lombok.Getter;
@AllArgsConstructor @AllArgsConstructor
public enum BpmFieldPermissionEnum { public enum BpmFieldPermissionEnum {
// TODO @jason改成 WRITEREADNONE更符合权限的感觉哈
EDITABLE(1, "可编辑"), EDITABLE(1, "可编辑"),
READONLY(2, "只读"), READONLY(2, "只读"),
HIDE(3, "隐藏"); HIDE(3, "隐藏");
/**
* 权限
*/
private final Integer permission; private final Integer permission;
/**
* 名字
*/
private final String name; private final String name;
public static BpmFieldPermissionEnum valueOf(Integer permission) { public static BpmFieldPermissionEnum valueOf(Integer permission) {
return ArrayUtil.firstMatch(item -> item.getPermission().equals(permission), values()); return ArrayUtil.firstMatch(item -> item.getPermission().equals(permission), values());
} }
} }

View File

@ -38,6 +38,7 @@ public enum BpmSimpleModelNodeType implements IntArrayValuable {
/** /**
* 判断是否为分支节点 * 判断是否为分支节点
*
* @param type 节点类型 * @param type 节点类型
*/ */
public static boolean isBranchNode(Integer type) { public static boolean isBranchNode(Integer type) {

View File

@ -141,7 +141,7 @@ public class BpmTaskController {
// 获得 BpmnModel // 获得 BpmnModel
BpmnModel bpmnModel = bpmProcessDefinitionService.getProcessDefinitionBpmnModel(processInstance.getProcessDefinitionId()); BpmnModel bpmnModel = bpmProcessDefinitionService.getProcessDefinitionBpmnModel(processInstance.getProcessDefinitionId());
return success(BpmTaskConvert.INSTANCE.buildTaskListByProcessInstanceId(taskList, processInstance, return success(BpmTaskConvert.INSTANCE.buildTaskListByProcessInstanceId(taskList, processInstance,
formMap, userMap, deptMap,bpmnModel)); formMap, userMap, deptMap, bpmnModel));
} }
@PutMapping("/approve") @PutMapping("/approve")

View File

@ -95,6 +95,7 @@ public interface BpmTaskConvert {
BpmFormDO form = MapUtil.get(formMap, NumberUtils.parseLong(task.getFormKey()), BpmFormDO.class); BpmFormDO form = MapUtil.get(formMap, NumberUtils.parseLong(task.getFormKey()), BpmFormDO.class);
if (form != null) { if (form != null) {
// 测试一下权限处理 // 测试一下权限处理
// TODO @jason这里是不是还没实现完哈
// List<String> afterChangedFields = BpmnFormUtils.changeCreateFormFiledPermissionRule(form.getFields(), // List<String> afterChangedFields = BpmnFormUtils.changeCreateFormFiledPermissionRule(form.getFields(),
// BpmnModelUtils.parseFormFieldsPermission(bpmnModel, task.getTaskDefinitionKey())); // BpmnModelUtils.parseFormFieldsPermission(bpmnModel, task.getTaskDefinitionKey()));

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.bpm.framework.flowable.core.enums; package cn.iocoder.yudao.module.bpm.framework.flowable.core.enums;
// TODO @jason这个类挪到 BpmnModelConstants 会不会好点因为后续 BPMN 标准也需要使用这些字段哈
/** /**
* 仿钉钉快搭 JSON 常量信息 * 仿钉钉快搭 JSON 常量信息
* *
@ -7,18 +8,20 @@ package cn.iocoder.yudao.module.bpm.framework.flowable.core.enums;
*/ */
public interface SimpleModelConstants { public interface SimpleModelConstants {
// TODO @jason改成 FORM_FIELD_PERMISSION_ELEMENT 会不会更精准哈
/** /**
* 流程表单字段权限, 用于标记字段权限 * 流程表单字段权限, 用于标记字段权限
*/ */
String FIELDS_PERMISSION = "fieldsPermission"; String FIELDS_PERMISSION = "fieldsPermission";
// TODO @jason改成 FORM_FIELD_PERMISSION_ELEMENT_FIELD_ATTRIBUTE 会不会更精准哈
/** /**
* 字段属性 * 字段属性
*/ */
String FIELD_ATTRIBUTE = "field"; String FIELD_ATTRIBUTE = "field";
// TODO @jason改成 FORM_FIELD_PERMISSION_ELEMENT_PERMISSION_ATTRIBUTE 会不会更精准哈
/** /**
* 权限属性 * 权限属性
*/ */
String PERMISSION_ATTRIBUTE = "permission"; String PERMISSION_ATTRIBUTE = "permission";
} }

View File

@ -25,11 +25,12 @@ public class BpmnModelUtils {
public static Integer parseCandidateStrategy(FlowElement userTask) { public static Integer parseCandidateStrategy(FlowElement userTask) {
Integer candidateStrategy = NumberUtils.parseInt(userTask.getAttributeValue( Integer candidateStrategy = NumberUtils.parseInt(userTask.getAttributeValue(
BpmnModelConstants.NAMESPACE, BpmnModelConstants.USER_TASK_CANDIDATE_STRATEGY)); BpmnModelConstants.NAMESPACE, BpmnModelConstants.USER_TASK_CANDIDATE_STRATEGY));
// @芋艿 尝试从 ExtensionElement . 后续相关扩展是否都可以 extensionElement 如表单权限 按钮权限 // TODO @芋艿 尝试从 ExtensionElement . 后续相关扩展是否都可以 extensionElement 如表单权限 按钮权限
if (candidateStrategy == null) { if (candidateStrategy == null) {
ExtensionElement element = CollUtil.getFirst(userTask.getExtensionElements().get(BpmnModelConstants.USER_TASK_CANDIDATE_STRATEGY)); ExtensionElement element = CollUtil.getFirst(userTask.getExtensionElements().get(BpmnModelConstants.USER_TASK_CANDIDATE_STRATEGY));
// TODO @jason改成下面这样是不是看着更简洁哈
// candidateStrategy = element != null ? NumberUtils.parseInt(element.getElementText()) : null;
candidateStrategy = NumberUtils.parseInt(Optional.ofNullable(element).map(ExtensionElement::getElementText).orElse(null)); candidateStrategy = NumberUtils.parseInt(Optional.ofNullable(element).map(ExtensionElement::getElementText).orElse(null));
} }
return candidateStrategy; return candidateStrategy;
} }
@ -44,16 +45,17 @@ public class BpmnModelUtils {
return candidateParam; return candidateParam;
} }
public static Map<String,Integer> parseFormFieldsPermission(BpmnModel bpmnModel, String flowElementId) { // TODO @jason貌似这个没地方调用
public static Map<String, Integer> parseFormFieldsPermission(BpmnModel bpmnModel, String flowElementId) {
FlowElement flowElement = getFlowElementById(bpmnModel, flowElementId); FlowElement flowElement = getFlowElementById(bpmnModel, flowElementId);
if (flowElement == null) { if (flowElement == null) {
return null; return null;
} }
final HashMap<String, Integer> fieldsPermission = MapUtil.newHashMap(); Map<String, Integer> fieldsPermission = MapUtil.newHashMap();
List<ExtensionElement> extensionElements = flowElement.getExtensionElements().get(SimpleModelConstants.FIELDS_PERMISSION); List<ExtensionElement> extensionElements = flowElement.getExtensionElements().get(SimpleModelConstants.FIELDS_PERMISSION);
extensionElements.forEach(el -> { extensionElements.forEach(element -> {
String field = el.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, FIELD_ATTRIBUTE); String field = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, FIELD_ATTRIBUTE);
String permission = el.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, SimpleModelConstants.PERMISSION_ATTRIBUTE); String permission = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, SimpleModelConstants.PERMISSION_ATTRIBUTE);
if (StrUtil.isNotEmpty(field) && StrUtil.isNotEmpty(permission)) { if (StrUtil.isNotEmpty(field) && StrUtil.isNotEmpty(permission)) {
fieldsPermission.put(field, Integer.parseInt(permission)); fieldsPermission.put(field, Integer.parseInt(permission));
} }

View File

@ -207,7 +207,6 @@ public class SimpleModelUtils {
// TODO @jason建议使用 ServiceTask通过 executionListeners 实现 // TODO @jason建议使用 ServiceTask通过 executionListeners 实现
// @芋艿 ServiceTask 就可以了吧 不需要 executionListeners // @芋艿 ServiceTask 就可以了吧 不需要 executionListeners
addCandidateElements(node, serviceTask); addCandidateElements(node, serviceTask);
return serviceTask; return serviceTask;
} }

View File

@ -15,12 +15,14 @@ import java.util.Map;
import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.SimpleModelConstants.FIELD_ATTRIBUTE; import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.SimpleModelConstants.FIELD_ATTRIBUTE;
// TODO @jason这个类挪到 framework 那的 util 包下哈
/** /**
* Bpmn 流程表单相关工具方法 * Bpmn 流程表单相关工具方法
* *
* @author jason * @author jason
*/ */
public class BpmnFormUtils { public class BpmnFormUtils {
private static final String CREATE_FORM_DISPLAY_ATTRIBUTE = "display"; private static final String CREATE_FORM_DISPLAY_ATTRIBUTE = "display";
private static final String CREATE_FORM_DISABLED_ATTRIBUTE = "disabled"; private static final String CREATE_FORM_DISABLED_ATTRIBUTE = "disabled";
@ -65,4 +67,5 @@ public class BpmnFormUtils {
}); });
return afterChangedFields; return afterChangedFields;
} }
} }