Camunda——业务任务DEMO(实现引擎端自动部署)

引擎端实现自动部署

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;
    }
}

四、启动引擎代码,创建一个流程实例进行调试

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值