文章目录
引擎端实现自动部署
1、在resource下创建META-INF文件夹,并创建一个processes.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<process-application
xmlns="http://www.camunda.org/schema/1.0/ProcessApplication"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<process-archive>
<process-engine>default</process-engine>
<properties>
<property name="isDeleteUponUndeploy">false</property>
<property name="isScanForProcessDefinitions">true</property>
</properties>
</process-archive>
</process-application>
2、在resource目录下,创建BPMN文件夹,以后流程设计器生成的bpmn文件都保存到该文件夹下,启动引擎端时就会自动部署
一、业务任务分类
二、需求DEMO
三、流程图设计
1、预约上门维修
我们使用Java Class类的业务任务实现,需要先在引擎端创建一个类,如下
package com.gykalc.workflow.servicetask;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
public class ReverseRepairService implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
System.out.println("进入到预约家电修理任务");
/**
* 预约业务逻辑的处理
*/
// 这里我们分配一个师傅给用户
String repairManName = "张三";
execution.setVariable("repairManName", repairManName);
System.out.println("请等待 " + repairManName + " 上门维修");
}
}
流程图设置如下
2、师傅上门维修
师傅上门维修流程我们采用Delegate Expression的方式,如下
流程定义好之后,在引擎端创建一个Service,代码如下,Service名字可以随意
package com.gykalc.workflow.servicetask;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Service;
@Service("doRepair")
public class DoRepairService implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
System.out.println("进入到师傅上门的任务");
String repairManName = String.valueOf(execution.getVariable("repairManName"));
System.out.println(repairManName + " 接收到维修任务,正在上门!");
}
}
3、公司电话回访
公司电话回访流程我们采用Expression的方式,如下
流程设计好之后,引擎端创建一个Service,如下
package com.gykalc.workflow.servicetask;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Service;
import java.util.Map;
@Service("telCall")
public class TelCallService {
public int doCall(DelegateExecution execution) {
System.out.println("开始电话回访");
// 获取所有的变量
Map<String, Object> variables = execution.getVariables();
System.out.println("您对" + variables.get("repairManName") + "打几分?");
return 10;
}
}
4、获取评分
package com.gykalc.workflow.servicetask;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Service;
import java.util.Map;
@Service("telCall")
public class TelCallService {
/**
* 电话回访调用的方法
* @param execution
* @return
*/
public int doCall(DelegateExecution execution) {
System.out.println("维修完毕,开始电话回访");
// 获取所有的变量
Map<String, Object> variables = execution.getVariables();
System.out.println("您对" + variables.get("repairManName") + "打几分?");
return 10;
}
/**
* 获取用户评分
* @param execution
* @return
*/
public int getScore(DelegateExecution execution) {
System.out.println("获取用户评分!");
int score = Integer.parseInt(String.valueOf(execution.getVariable("score")));
System.out.println("用户评分为:" + score);
return score;
}
}