springboot整合Camunda实现业务

1.bean实现 业务 

1.画流程图

系统任务,实现方式

 

2.定义bean 

package com.jmj.camunda7test.process.config;

import lombok.extern.slf4j.Slf4j;
import org.camunda.bpm.engine.TaskService;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.camunda.bpm.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.awt.*;
import java.net.URI;
import java.util.Map;

@Configuration
@Slf4j
public class ProcessConfiguration {

    @Autowired
    TaskService taskService;



    @Bean("baidu")
    public JavaDelegate baidu() {
        return execution -> {
            String processDefinitionId = execution.getProcessDefinitionId();
            log.info("processDefinitionId:{}", processDefinitionId);
            Map<String, Object> variables = execution.getVariables();
            log.info("approved:{}", variables.get("approved"));
            try {
                System.out.println("来访问百度了");
            } catch (Exception e) {
                e.printStackTrace();
            }
        };
    }


    @Bean("hao123")
    public JavaDelegate hao123() {
        return execution -> {
            String processDefinitionId = execution.getProcessDefinitionId();
            log.info("processDefinitionId:{}", processDefinitionId);
            Map<String, Object> variables = execution.getVariables();
            log.info("approved:{}", variables.get("approved"));
            try {
                System.out.println("来访问hao123了");
            } catch (Exception e) {
                e.printStackTrace();
            }

        };
    }


}

 3.会对应Bean去执行

package com.jmj.camunda7test.controller;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.TaskService;
import org.camunda.bpm.engine.repository.Deployment;
import org.camunda.bpm.engine.repository.ProcessDefinition;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.bpm.engine.task.Task;
import org.camunda.bpm.engine.task.TaskQuery;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest
class ResServiceTest {
    @Autowired
    private ResService resService;
    @Autowired
    private RepositoryService repositoryService;
    @Autowired
    private RuntimeService runtimeService;
    @Autowired
    private TaskService taskService;


    @Test
    //部署
    void deploy() {
        Deployment deploy = repositoryService.createDeployment().name("测试bean")
                .addClasspathResource("bpmn/process.bpmn")//绑定需要部署的流程文件
                .enableDuplicateFiltering(true)
                .deploy();
        System.out.println(deploy.getId() + ":" + deploy.getName());

    }

    @Test
    //运行
    void run() {

        ProcessInstance processInstance = runtimeService.startProcessInstanceById("my-project-process:5:21b5c0c8-399e-11ef-b3eb-005056c00008");
        String processDefinitionId = processInstance.getProcessDefinitionId();
        String businessKey = processInstance.getBusinessKey();
        String processInstanceId = processInstance.getProcessInstanceId();
        System.out.println(processDefinitionId);
        System.out.println(businessKey);
        System.out.println(processInstanceId);

    }

    public static final String Approved = "approved";

    @Test
    //运行
    void run1() {
        Map<String, Object> map = new HashMap<>();
        map.put(Approved, true);
        map.put("user", new DataB("testId","TestName"));
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-project-process", map);
        System.out.println("流程启动成功: 流程实例ID=" + processInstance.getProcessInstanceId());
    }

    @Test
    //完成用户任务
    void compelete() {
        TaskQuery taskQuery = taskService.createTaskQuery().processDefinitionKey("my-project-process")
                .orderByProcessInstanceId()
                .desc()
                .active();
        String taskId = taskQuery.list().get(0).getId();
        Map<String, Object> map = new HashMap<>();

        map.put("user", "admin");

        taskService.complete(taskId, map);

    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    //参数
    static class DataB implements Serializable {
        private String id;
        private String name;
    }

    @Test
    //完成用户任务 
    void compelete1() {


        Task task = taskService.createTaskQuery().taskAssignee("admin").list().get(0);
        Map<String, Object> variables = taskService.getVariables(task.getId());
        variables.forEach((k, v) -> {
            System.out.println(k + ":" + v);
        });
        taskService.setVariable(task.getId(), Approved, false);
        taskService.complete(task.getId());


    }

    @Test
    //级联删除所有部署
    void deleteDeploy() {
        for (ProcessDefinition processDefinition : repositoryService.createProcessDefinitionQuery().list()) {
            System.out.println(processDefinition.getId() + ":" + processDefinition.getName());
        }
        repositoryService.createDeploymentQuery().list().forEach(deployment -> {
            repositoryService.deleteDeployment(deployment.getId(), true);

        });
    }

    @Test
    //删除部署
    void delete() {
        repositoryService.deleteDeployment("86cf1536-39a5-11ef-ba9b-005056c00008", true);
    }
}

2.JavaClass:

package com.jmj.camunda7test.process.config;

import lombok.extern.slf4j.Slf4j;
import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.camunda.bpm.engine.repository.Deployment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class Hao123Delegate implements JavaDelegate {
    @Autowired
    private RepositoryService repositoryService;
    @Override
    public void execute(DelegateExecution execution) throws Exception {
        List<Deployment> list = repositoryService.createDeploymentQuery().list();
        for (Deployment deployment : list) {
            System.out.println(deployment.getId()+":"+deployment.getName());
        }
        log.info("进入Java;类执行 hao123");
    }
}

3.Expression

下面两种可使用spring的配置

EL表达式,调用java类的方法 ,规范:

expression=“#{monitorExecution.execution(execution)}”

 直接调用容器中对象的方法

package com.jmj.camunda7test.getStarted.chargecard;

import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Component;

@Component("testA")
public class TestA {
    public void add(DelegateExecution delegateExecution) {
        String processDefinitionId = delegateExecution.getProcessDefinitionId();
        System.out.println("testA:"+processDefinitionId);
    }
}

 4.创建用户 组

package com.jmj.camunda7test.controller;

import org.camunda.bpm.engine.IdentityService;
import org.camunda.bpm.engine.identity.Group;
import org.camunda.bpm.engine.identity.GroupQuery;
import org.camunda.bpm.engine.identity.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
public class IdentityActivity {

    @Autowired
    IdentityService identityService;

    @Test
    void createUser() {
        List<User> list = identityService.createUserQuery().list();
        for (User user : list) {
            System.out.println(user.getId());
            System.out.println(user.getFirstName());
            System.out.println(user.getEmail());
            System.out.println(user.getPassword());
            System.out.println(user.getLastName());
        }
    }

    @Test
    void selectUserGroup() {
        List<Group> list = identityService.createGroupQuery().groupId("camunda-admin").list();
        System.out.println(list.get(0).getName());
    }

    @Test
    void getCurrentAuth() {
        identityService.setAuthenticatedUserId("admin");
        String userId = identityService.getCurrentAuthentication().getUserId();
        System.out.println(userId);
    }

    @Test
    void createUserID() {
        User jmj = identityService.newUser("jmj");
        jmj.setFirstName("mingji");
        jmj.setLastName("jiang");
        jmj.setPassword("123456");
        jmj.setEmail("123@qq");
        identityService.saveUser(jmj);
    }

    @Test
    void bindGroup() {
        identityService.createMembership("jmj","camunda-admin");



    }
}

官网Spring Boot Version Compatibility | docs.camunda.org

5.获取候选人用户

候选人或者主要审批人或者候选组的所有用户都会有审批的权限,谁审批了,就过去了

   @Test
    //完成用户任务
    void compelete1() {

        identityService.setAuthenticatedUserId("jmj");

        Authentication currentAuthentication = identityService.getCurrentAuthentication();
        List<String> groupIds = currentAuthentication.getGroupIds();
        List<String> tenantIds = currentAuthentication.getTenantIds();
        System.out.println(groupIds);
        System.out.println(tenantIds);

        String userId = currentAuthentication.getUserId();
        System.out.println(userId);


        Task task = taskService.createTaskQuery().taskAssignee("admin").list().get(0);

        List<IdentityLink> identityLinksForTask = taskService.getIdentityLinksForTask(task.getId());
        for (IdentityLink identityLink : identityLinksForTask) {
            String type = identityLink.getType();
            System.out.println(type+":"+identityLink.getUserId());
        }
        Map<String, Object> variables = taskService.getVariables(task.getId());
        variables.forEach((k, v) -> {
            System.out.println(k + ":" + v);
        });
//        taskService.setVariable(task.getId(), Approved, false);
//        taskService.complete(task.getId());

        taskService.complete(task.getId());
    }

 6.监听器

package com.jmj.camunda7test.process.config;

import org.camunda.bpm.engine.TaskService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.ExecutionListener;
import org.camunda.bpm.engine.delegate.TaskListener;
import org.camunda.bpm.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;

@Configuration
public class EvenListenerConfig {

   public String inject;

    @Autowired
    private TaskService taskService;
    @Bean("start")
    public ExecutionListener start() {
        return execution -> {
            String processInstanceId = execution.getProcessInstanceId();
            System.out.println(processInstanceId+"开始执行了");
        };
    }

    @Bean("end")
    public ExecutionListener end() {
        return execution -> {
            String processInstanceId = execution.getProcessInstanceId();
            System.out.println(processInstanceId+"执行结束了");
        };
    }

}

Camunda工作流集成SpringBoot(三)_camunda springboot 监听-CSDN博客 可以看看这个

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/776029.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【一】m2芯片的mac中安装ubuntu24虚拟机集群

文章目录 1. 虚拟机配置2. 复制虚拟机2.1 修改主机名2.2 修改网络 1. 虚拟机配置 在官方网站下载好ubuntu24-arm版镜像开始安装&#xff0c;安装使用VMWare Fusion的社区免费授权版,使用一台m2芯片的mac电脑作为物理机平台。 为什么选择ubuntu24&#xff1f;因为centOS7目前已…

php简单商城小程序系统源码

&#x1f6cd;️【简单商城小程序】&#x1f6cd;️ &#x1f680;一键开启&#xff0c;商城搭建新体验&#x1f680; 你还在为繁琐的商城搭建流程头疼吗&#xff1f;现在&#xff0c;有了简单商城系统小程序&#xff0c;一切变得轻松又快捷&#xff01;无需复杂的编程知识&a…

CTF常用sql注入(三)无列名注入

0x06 无列名 适用于无法正确的查出结果&#xff0c;比如把information_schema给过滤了 join 联合 select * from users;select 1,2,3 union select * from users;列名被替换成了1,2,3&#xff0c; 我们再利用子查询和别名查 select 2 from (select 1,2,3 union select * f…

为什么使用StartAI文生图进行AI绘画?

什么是文生图&#xff1f; 文生图是AIGC中一种先进的图像生成技术&#xff0c;它能够根据用户输入的文字描述&#xff0c;智能地生成相应的图像。无论是抽象的概念&#xff0c;还是具体的物体&#xff0c;文生图都能够以惊人的准确性和艺术性呈现出来。 StartAI文生图如何进行…

南方航空阿里v2滑块验证码逆向分析思路学习

目录 一、声明&#xff01; 二、介绍 三、请求流程分析&#xff1a; 1.拿验证码 2.提交第一次设备信息 3.提交第二次设备信息 4.提交验证 ​编辑 四、接口响应数据分析&#xff1a; 1.拿验证码 2.提交第一次设备信息 3.提交第二次设备信息 4.提…

暑期大数据人工智能学习-企业项目试岗实训开营

暑期企业项目-试岗实训活动全面开启啦 跟张良均老师学大数据人工智能 不仅可以提供实习证明&#xff0c;有需要话也可以提供实习鉴定报告 √54个热门案例拆解 √40项目实战课程 √27个项目可选 √4个项目方向

8种方案解决移动端1px边框的问题

&#x1f9d1;‍&#x1f4bb; 写在开头 点赞 收藏 学会&#x1f923;&#x1f923;&#x1f923; 8 种方案解决移动端1px边框的问题 造成边框变粗的原因 css中的1px并不等于移动设备的1px&#xff0c;这是由不同手机由不同像素密度&#xff0c;在window对象中有一个devic…

Aigtek功率放大器的参数及应用是什么

功率放大器是电子电路中的重要组成部分&#xff0c;用于将输入信号的功率增加到更高的水平。它们在各种电子设备和应用中发挥着关键作用。下面Aigtek安泰电子将介绍功率放大器的主要参数以及它们在不同领域的应用。 1.功率放大器的基本参数 增益 功率放大器的增益是指输出信号的…

C++基于协同过滤算法的超市外卖小程序-计算机毕业设计源码62482

摘要 随着社会生活节奏加快和消费习惯的变化&#xff0c;外卖服务成为人们日常生活中不可或缺的一部分。超市外卖作为新兴业态备受关注&#xff0c;然而传统外卖平台在推荐精准度和用户体验方面存在挑战。 本研究旨在基于协同过滤算法&#xff0c;结合C语言和MySQL数据库&#…

View->裁剪框View的绘制,手势处理

XML文件 <?xml version"1.0" encoding"utf-8"?> <RelativeLayout xmlns:android"http://schemas.android.com/apk/res/android"android:layout_width"match_parent"android:layout_height"match_parent"android…

无人机对地面运动目标定位---获取目标的移动方向和速度

目录 一、引子 我们利用单目无人机通过等时间间隔拍照的形式对地面某移动目标进行定位&#xff0c;当前&#xff0c;我们已经获得了每张相片上该目标的三维坐标&#xff0c;并且知道该无人机在飞行过程中拍照的时间间隔&#xff0c;那么我们就可以通过一定的计算&#xff0c;得…

溶酶体靶向嵌合体制备方法和技术

网盘 https://pan.baidu.com/s/1dhCCryatp71j7yXTDdrrTw?pwdynr4 具有聚集诱导发光性质的比率型溶酶体pH探针及应用.pdf 内体-溶酶体转运靶向嵌合体降解剂及其制备方法与应用.pdf 可降解PDGFR-β的蛋白降解靶向嵌合体及其制备方法和应用.pdf 溶酶体膜包覆纳米颗粒的制备方法.…

华夏女中师生深入同仁堂,感悟中医药文化之精髓

华夏女中师生深入同仁堂&#xff0c;感悟中医药文化之精髓 2024年7月4日下午&#xff0c;北京师范大学实验华夏女子中学15名学生在薛艳老师的带领下来到北京同仁堂中医医院&#xff0c;开展职业影随活动。何泽扬院长对她们的到来表示欢迎。随后&#xff0c;在“冯建春全国名老中…

初识布隆过滤|工作场景

作用 检查一个元素是否在一个集合中 优缺点 优点&#xff1a;空间效率和查询时间比一般算法好&#xff0c;时间复杂度低&#xff0c;O(k) k是函数的个数&#xff0c;节省空间 缺点&#xff1a;有一定的错误几率&#xff0c;没有的也可能判定为存在&#xff0c;删除困难&…

一份适合新手的软件测试练习项目

最近&#xff0c;不少读者托我找一个能实际练手的测试项目。开始&#xff0c;我觉得这是很简单的一件事&#xff0c;但当我付诸行动时&#xff0c;却发现&#xff0c;要找到一个对新手友好的练手项目&#xff0c;着实困难。 我翻了不下一百个web网页&#xff0c;包括之前推荐练…

基于深度学习的图像背景剔除

在过去几年的机器学习领域&#xff0c;我一直想打造真正的机器学习产品。 几个月前&#xff0c;在参加了精彩的 Fast.AI 深度学习课程后&#xff0c;似乎一切皆有可能&#xff0c;我有机会&#xff1a;深度学习技术的进步使许多以前不可能实现的事情成为可能&#xff0c;而且开…

【SpringCloud】Hystrix源码解析

hystrix是一个微服务容错组件&#xff0c;提供了资源隔离、服务降级、服务熔断的功能。这一章重点分析hystrix的实现原理 1、服务降级 当服务实例所在服务器承受的压力过大或者受到网络因素影响没法及时响应请求时&#xff0c;请求会阻塞堆积&#xff0c;情况严重的话整个系统…

【算法笔记自学】入门篇(2)——算法初步

4.1排序 自己写的题解 #include <stdio.h> #include <stdlib.h>void selectSort(int A[], int n) {for(int i 0; i < n - 1; i) { // 修正索引范围int k i;for(int j i 1; j < n; j) { // 修正索引范围if(A[j] < A[k]) {k j;}}if (k ! i) { // 仅在…

取证与数据恢复:冷系统分析,实时系统分析与镜像分析之间的过渡办法

天津鸿萌科贸发展有限公司是 ElcomSoft 系列取证软件的授权代理商。 ElcomSoft 系列取证软件 ElcomSoft 系列取证软件支持从计算机和移动设备进行数据提取、解锁文档、解密压缩文件、破解加密容器、查看和分析证据。 计算机和手机取证的完整集合硬件加速解密最多支持10,000计…

面向对象案例:电影院

TOC 思路 代码 结构 具体代码 Movie.java public class Movie {//一共七个private int id;private String name;private double price;private double score;private String director;private String actors;private String info;//get和setpublic int getId() {return id;…