Flowable自定义描述

admin2024-07-03  14

public interface DataStrategy {
   
    Object execute(Map<String, Object> param);
}
@Component
public class DictDataStrategy implements DataStrategy {
   
    @Override
    public Object execute(Map<String, Object> param) {
   
        String dictCode = (String)param.get("dictCode");

        return Arrays.asList(
                MapUtil.builder().put("label", "同意").put("value", "Y").put("order", "1").build(),
                MapUtil.builder().put("label", "不同意").put("value", "N").put("order", "2").build()
        );
    }
}
/**
 * 元素描述配置(可以配置在UserTask、GateWay、SequenceFlow上)
 */
@Data
public class ElementConf {
   
    /** 是否强制跳过条件表达式 */
    private boolean isForceSkipConditionExpression;
    private boolean isReturn;

}
@Component
public class EndEventStrategy implements FlowNodeStrategy{
   
    @Override
    public void handleConfig(TaskConfigVo configVo, TaskConfigVo.Modal modal, FlowNode currentNode, SequenceFlow outgoingFlow, SequenceFlowConf outgoingFlowConf, FlowElement targetFlowElement, ElementConf targetConf) {
   

    }

    @Override
    public void afterPropertiesSet() throws Exception {
   
        FlowNodeStrategyFactory.regist(EndEvent.class, this);
    }
}
@Data
public class ExclusiveGatewayConf extends ElementConf  {
   
    private String result;
    private List<TaskConfigVo.FormItem> formItems;
}
@Component
public class ExclusiveGatewayStrategy implements FlowNodeStrategy {
   
    @Override
    public void handleConfig(TaskConfigVo configVo, TaskConfigVo.Modal modal, FlowNode currentNode, SequenceFlow outgoingFlow, SequenceFlowConf outgoingFlowConf, FlowElement targetElement, ElementConf targetConf) {
   
        if (targetConf == null) {
   
            return;
        }

        ExclusiveGatewayConf exclusiveGatewayConf = (ExclusiveGatewayConf)targetConf;
        // 支持 radio、select、upload等组件
        for (TaskConfigVo.FormItem formItem : exclusiveGatewayConf.getFormItems()) {
   
            if (StringUtils.equals(formItem.getType(), "radio")) {
   
                String beanName = formItem.getDataStrategy();
                Map<String, Object> args = formItem.getArgs();
                DictDataStrategy dataStrategy = SpringUtil.getBean(beanName);
                Object data = dataStrategy.execute(args);
                formItem.setData(data);

                formItem.setValue(exclusiveGatewayConf.getResult());
            }
        }

        modal.setFormItems(exclusiveGatewayConf.getFormItems());
    }

    @Override
    public void afterPropertiesSet() throws Exception {
   
        FlowNodeStrategyFactory.regist(ExclusiveGateway.class, this);
    }
}

public interface FlowNodeStrategy extends InitializingBean {
   

    void handleConfig(TaskConfigVo configVo,
                      TaskConfigVo.Modal modal,
                      FlowNode currentNode,
                      SequenceFlow outgoingFlow,
                      SequenceFlowConf outgoingFlowConf,
                      FlowElement targetFlowElement,
                      ElementConf targetConf);
}
public class FlowNodeStrategyFactory {
   
    private FlowNodeStrategyFactory() {
   }

    private static Map<Class, FlowNodeStrategy> factory = new HashMap<>();

    public static void regist(Class clazz, FlowNodeStrategy strategyFactory) {
   
        factory.put(clazz, strategyFactory);
    }

    public static FlowNodeStrategy get(Class clazz) {
   
        return factory.get(clazz);
    }
}
@Data
public class SequenceFlowConf extends ElementConf {
   
    private int order;
    private Map<String, Object> localVariables;
}
@Data
public class TaskConfigBo {
   
    private String taskId;
}
@Data
public class TaskConfigVo {
   
    private String procInstId;
    private String procDefId;
    private String taskId;
    private String currentTaskDefKey;
    private String name;

    /** 是否允许撤回 */
    private Boolean isRevoke;

    /** outgoingFlows */
    private List<Button> buttons;


    /**
     * 按钮
     */
    @Data
    public static class Button 
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明原文出处。如若内容造成侵权/违法违规/事实不符,请联系SD编程学习网:675289112@qq.com进行投诉反馈,一经查实,立即删除!