springboot practical demonstration activiti workflow (2)

Before sharing the actual combat demonstration, you need to refer to the above two blogs:

bpmn flowchart drag and drop process

Integrated boot basic configuration

The springboot actual demonstration activiti workflow (2) is based on the previous article, and is carried out according to the business flow chart of the previous article:

1. Business code configuration public class

This article demonstrates commonly used serviceTask business tasks, the business class must implement the execute method of the JavaDelegate interface

Core pseudocode:


/**
 * 核心是实现 JavaDelegate 接口的 execute方法
 */
public abstract class CommonTaskDelefate implements JavaDelegate {
    /**
     * 作为父类的工作方法
     * @param execution
     */
    @Override
    public void execute(DelegateExecution execution) {
        FlowElement currentFlowElement = execution.getCurrentFlowElement();
        String currentFlowElementName = currentFlowElement.getName();

        String name = (String) execution.getVariable("name");
        /**
         * 进入子类调用
         */
        execute(execution,name);
    }

    /**
     * 其子类重写的抽象类
     * @param execution
     * @param name
     */
    public abstract void execute(DelegateExecution execution, String name);
}

2. The corresponding 7 subcategories shown in the installation

For example one of them:


import org.activiti.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Service;

@Service
public class QueryFileDelegate extends CommonTaskDelefate{
    @Override
    public void execute(DelegateExecution execution,String name) {
        System.out.println("查询文件:"+name);
    }
}

 The basic shelf is like this, as for the business code, write it yourself according to the business.

Note: Under normal circumstances, you don’t need to set the parent and child classes. You can directly separate the 7 business classes and implement JavaDelegate. The parent class is written here mainly for business abstraction, and the public part is extracted.

3. Start this workflow configuration

@RequestMapping("/getS")
    public String getS(){
        //设置工作流的自定义参数
        Map<String, Object> map = new HashMap<>();
        EvectionVO evection = new EvectionVO();
        evection.setNum(2d);
        map.put("evection",evection);//可以配置参数条件<![CDATA[${evection.num<3}]]>
        map.put("name","lisi");
        map.put("state",true);
        map.put("isZip",true);//此处就是判断文件是压缩包的条件参数,对应流程图
        map.put("type",1);
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("nandaoTest", map);
        String processDefinitionId = processInstance.getProcessDefinitionId();
        String businessKey = processInstance.getBusinessKey();
        Integer appVersion = processInstance.getAppVersion();
        String deploymentId = processInstance.getDeploymentId();
        String description = processInstance.getDescription();
        System.out.println("processDefinitionId:"+processDefinitionId);
        System.out.println("businessKey:"+businessKey);
        System.out.println("appVersion:"+appVersion);
        System.out.println("deploymentId:"+deploymentId);
        System.out.println("description:"+description);
        return "ok";
    }

4. Start the service

Print the log after the interface is disconnected

The log shows that the file is in a compressed format, because the decompression is performed, and the parameter configuration is also true. 

Here, the entire process is executed, and the implementer process can be completely nested in the core business code, which is powerful and easy to operate. In the next article, we will share another artifact of dragging npmn graphs, which is more powerful, please start it!

 

 

Guess you like

Origin blog.csdn.net/nandao158/article/details/129637675