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 {@AutowiredTaskService 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 {@Autowiredprivate ResService resService;@Autowiredprivate RepositoryService repositoryService;@Autowiredprivate RuntimeService runtimeService;@Autowiredprivate 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 {@Autowiredprivate RepositoryService repositoryService;@Overridepublic 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 {@AutowiredIdentityService identityService;@Testvoid 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());}}@Testvoid selectUserGroup() {List<Group> list = identityService.createGroupQuery().groupId("camunda-admin").list();System.out.println(list.get(0).getName());}@Testvoid getCurrentAuth() {identityService.setAuthenticatedUserId("admin");String userId = identityService.getCurrentAuthentication().getUserId();System.out.println(userId);}@Testvoid createUserID() {User jmj = identityService.newUser("jmj");jmj.setFirstName("mingji");jmj.setLastName("jiang");jmj.setPassword("123456");jmj.setEmail("123@qq");identityService.saveUser(jmj);}@Testvoid 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;@Autowiredprivate 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.xdnf.cn/news/1472339.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

Linux 摄像头编号固化

一、前言 在工业领域&#xff0c;一台设备会有很多个摄像头&#xff0c;可以使用命令&#xff1a;ll /dev/video* 进行查看&#xff1b; 在代码中&#xff0c;如果需要使用摄像头&#xff0c;那么都是需要具体到哪个摄像头编号的&#xff0c;例如 open("/dev/video4"…

无线麦克风什么牌子的音质效果好,揭秘哪款领夹麦克风性价比高!

随着网络直播、短视频制作和在线教育的兴起&#xff0c;无线领夹麦克风因其便携性和出色的录音质量成为了众多内容创作者的首选工具。这类麦克风的流行并不是空穴来风&#xff0c;领夹麦克风不仅能够轻松夹在衣物上&#xff0c;减少了对活动自由度的限制&#xff0c;而且能够提…

无线网卡怎么连接台式电脑?让上网更便捷!

随着无线网络的普及&#xff0c;越来越多的台式电脑用户希望通过无线网卡连接到互联网。无线网卡为台式电脑提供了无线连接的便利性&#xff0c;避免了有线网络的束缚。本文将详细介绍无线网卡怎么连接台式电脑的四种方法&#xff0c;包括使用USB无线网卡、内置无线网卡以及使用…

2024年7月3日 (周三) 叶子游戏新闻

老板键工具来唤去: 它可以为常用程序自定义快捷键&#xff0c;实现一键唤起、一键隐藏的 Windows 工具&#xff0c;并且支持窗口动态绑定快捷键&#xff08;无需设置自动实现&#xff09;。 卸载工具 HiBitUninstaller: Windows上的软件卸载工具 《魅魔》新DLC《Elysian Fields…

智能井盖采集装置 开启井下安全新篇章

在现代城市的脉络之下&#xff0c;错综复杂的管网系统如同城市的血管&#xff0c;默默支撑着日常生活的有序进行。而管网的监测设备大多都安装在井下&#xff0c;如何给设备供电一直是一个难题&#xff0c;选用市电供电需经过多方审批&#xff0c;选用电池供电需要更换电池包&a…

JavaScript中闭包的理解

闭包&#xff08;Closure&#xff09;概念&#xff1a;一个函数对周围状态的引用捆绑在一起&#xff0c;内层函数中访问到其外层函数的作用域。简单来说;闭包内层函数引用外层函数的变量&#xff0c;如下图&#xff1a; 外层在使用一个函数包裹住闭包是对变量的保护&#xff0c…

Altium Designer专业PCB设计软件下载安装 Altium Designer安装包下载获取

在电子设计的广袤领域中&#xff0c;PCB设计无疑占据着重要的地位。而Altium Designer作为一款业界领先的电子设计自动化软件&#xff0c;其提供的先进布局工具&#xff0c;无疑为设计师们打开了一扇通往高效、精确设计的大门。 在PCB设计的核心环节——布局中&#xff0c;Alti…

html高级篇

1.2D转换 转换&#xff08;transform&#xff09;你可以简单理解为变形 移动&#xff1a;translate 旋转&#xff1a;rotate 缩放&#xff1a;sCale 移动&#xff1a;translate 1.移动具体值 /* 移动盒子的位置&#xff1a; 定位 盒子的外边距 2d转换移动 */div {width…

如何设计一个C++程序来模拟超市收银系统?

&#x1f3c6;本文收录于「Bug调优」专栏&#xff0c;主要记录项目实战过程中的Bug之前因后果及提供真实有效的解决方案&#xff0c;希望能够助你一臂之力&#xff0c;帮你早日登顶实现财富自由&#x1f680;&#xff1b;同时&#xff0c;欢迎大家关注&&收藏&&…

vue 中 使用腾讯地图 (动态引用腾讯地图及使用签名验证)

在设置定位的时候使用 腾讯地图 选择地址 在 mounted中引入腾讯地图&#xff1a; this.website.mapKey 为地图的 key // 异步加载腾讯地图APIconst script document.createElement(script);script.type text/javascript;script.src https://map.qq.com/api/js?v2.exp&…

昇思25天学习打卡营第17天|GAN图像生成

模型简介 GAN模型的核心在于提出了通过对抗过程来估计生成模型这一全新框架。在这个框架中&#xff0c;将会同时训练两个模型——捕捉数据分布的生成模型G和估计样本是否来自训练数据的判别模型D 。 在训练过程中&#xff0c;生成器会不断尝试通过生成更好的假图像来骗过判别…

昇思25天学习打卡营第8天|MindSpore保存与加载(保存和加载MindIR)

在MindIR中&#xff0c;一个函数图&#xff08;FuncGraph&#xff09;表示一个普通函数的定义&#xff0c;函数图一般由ParameterNode、ValueNode和CNode组成有向无环图&#xff0c;可以清晰地表达出从参数到返回值的计算过程。在上图中可以看出&#xff0c;python代码中两个函…

Python面试宝典第6题:有效的括号

题目 给定一个只包括 (、)、{、}、[、] 这些字符的字符串&#xff0c;判断该字符串是否有效。有效字符串需要满足以下的条件。 1、左括号必须用相同类型的右括号闭合。 2、左括号必须以正确的顺序闭合。 3、每个右括号都有一个对应的相同类型的左括号。 注意&#xff1a;空字符…

搞了个 WEB 串口终端,简单分享下

每次换电脑总要找各种串口终端软件&#xff0c;很烦。 有的软件要付费&#xff0c;有的软件要注册&#xff0c;很烦。 找到免费的&#xff0c;还得先下载下来&#xff0c;很烦。 开源的软件下载速度不稳定&#xff0c;很烦。 公司电脑有监控还得让 IT 同事来安装&#xff0…

后端之路——最规范、便捷的spring boot工程配置

一、参数配置化 上一篇我们学了阿里云OSS的使用&#xff0c;那么我们为了方便使用OSS来上传文件&#xff0c;就创建了一个【util】类&#xff0c;里面有一个【AliOSSUtils】类&#xff0c;虽然本人觉得没啥不方便的&#xff0c;但是黑马视频又说这样还是存在不便维护和管理问题…

生态系统NPP及碳源、碳汇模拟技术教程

原文链接&#xff1a;生态系统NPP及碳源、碳汇模拟技术教程https://mp.weixin.qq.com/s?__bizMzUzNTczMDMxMg&mid2247608293&idx3&sn2604c5c4e061b4f15bb8aa81cf6dadd1&chksmfa826602cdf5ef145c4d170bed2e803cd71266626d6a6818c167e8af0da93557c1288da21a71&a…

FPGA问题

fpga 问题 ep2c5t144 开发板 第一道坎&#xff0c;安装软件&#xff1b;没有注册&#xff0c;无法产生sop文件&#xff0c;无法下载 没有相应的库的quartus ii版本&#xff0c;需要另下载 第二道坎&#xff0c;模拟器的下载&#xff0c;安装&#xff1b; 第三道&#xff0c;v…

在window上搭建docker

1、打开Hyper-V安装 在地址栏输入控制面板&#xff0c;然后回车 勾选Hyper-V安装&#xff0c;如果没有找到Hyper-V&#xff0c;那么请走第2步 2、如果没有Hyper-V(可选&#xff09;第一步无法打开 家庭版本需要开启Hyper-V 创建一个文本文档&#xff0c;后缀名称为.bat.名称…

油猴Safari浏览器插件:Tampermonkey for Mac 下载

Tampermonkey 是一个强大的浏览器扩展&#xff0c;用于运行用户脚本&#xff0c;这些脚本可以自定义和增强网页的功能。它允许用户在网页上执行各种自动化任务&#xff0c;比如自动填写表单、移除广告、改变页面布局等。适用浏览器&#xff1a; Tampermonkey 适用于多数主流浏览…