commit e89a34a348596ab6b3bc74ea2bf771fea04e7c11 Author: meethigher Date: Mon Nov 21 18:11:36 2022 +0800 init diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..919ce1f --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..ee93d41 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..63574ec --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d5cd614 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/saveactions_settings.xml b/.idea/saveactions_settings.xml new file mode 100644 index 0000000..033ad7e --- /dev/null +++ b/.idea/saveactions_settings.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..8911f0b --- /dev/null +++ b/pom.xml @@ -0,0 +1,231 @@ + + + 4.0.0 + + com.example.workflow + camunda + 1.0.0-SNAPSHOT + + + UTF-8 + 8 + 8 + + + + + + org.springframework.boot + spring-boot-dependencies + 2.5.4 + pom + import + + + + org.camunda.bpm + camunda-bom + 7.15.0 + import + pom + + + + org.codehaus.groovy + groovy-all + 2.4.21 + + + + org.codehaus.groovy.modules.http-builder + http-builder + 0.7.1 + + + + org.camunda.bpm.springboot + camunda-bpm-spring-boot-starter-rest + 7.15.0 + + + + + + org.camunda.spin + camunda-spin-dataformat-all + 1.9.0 + + + + + + org.camunda.bpm.extension.swagger + camunda-bpm-swagger-json + 7.8.0 + + + + + org.webjars + swagger-ui + ${swagger-ui.version} + + + + org.webjars.bower + swagger-ui-themes + 3.0.0 + + + io.springfox + springfox-swagger2 + ${springfox.version} + + + io.springfox + springfox-swagger-ui + ${springfox.version} + + + + + + + + + org.camunda.connect + camunda-connect-bom + 1.5.2 + import + pom + + + + + + org.camunda.bpm.extension.reactor + camunda-bpm-reactor-spring-starter + 2.1.2 + + + + org.camunda.connect + camunda-connect-core + 1.5.2 + + + org.camunda.connect + camunda-connect-connectors-all + 1.5.2 + + + org.camunda.bpm + camunda-engine-plugin-connect + 7.15.0 + + + org.camunda.bpm.springboot + camunda-bpm-spring-boot-starter-webapp + 7.15.0 + + + org.springframework.boot + spring-boot-starter-web + + + + + org.postgresql + postgresql + 42.5.0 + + + com.alibaba + druid-spring-boot-starter + 1.2.6 + + + com.alibaba + fastjson + 1.2.78 + + + org.springframework.boot + spring-boot-starter-test + 2.5.4 + test + + + org.projectlombok + lombok + test + + + junit + junit + 4.13.2 + test + + + + + + + + org.springframework.boot + spring-boot-starter-test + + + org.camunda.bpm.springboot + camunda-bpm-spring-boot-starter-rest + + + + org.camunda.bpm.springboot + camunda-bpm-spring-boot-starter-webapp + + + + org.camunda.bpm + camunda-engine-plugin-spin + + + + org.camunda.spin + camunda-spin-dataformat-all + + + + org.camunda.bpm + camunda-external-task-client + 7.15.0 + + + + org.postgresql + postgresql + + + + org.springframework.boot + spring-boot-starter-jdbc + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/src/main/java/com/example/workflow/Application.java b/src/main/java/com/example/workflow/Application.java new file mode 100644 index 0000000..d90510a --- /dev/null +++ b/src/main/java/com/example/workflow/Application.java @@ -0,0 +1,13 @@ +package com.example.workflow; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String... args) { + SpringApplication.run(Application.class, args); + } + +} \ No newline at end of file diff --git a/src/main/java/com/example/workflow/listener/SayHaloWodeListener.java b/src/main/java/com/example/workflow/listener/SayHaloWodeListener.java new file mode 100644 index 0000000..4d6678c --- /dev/null +++ b/src/main/java/com/example/workflow/listener/SayHaloWodeListener.java @@ -0,0 +1,12 @@ +package com.example.workflow.listener; + +import org.camunda.bpm.engine.delegate.DelegateTask; +import org.camunda.bpm.engine.delegate.TaskListener; + +public class SayHaloWodeListener implements TaskListener { + + @Override + public void notify(DelegateTask delegateTask) { + System.out.println("halo wode"); + } +} diff --git a/src/main/java/com/example/workflow/rest/controller/ProcessController.java b/src/main/java/com/example/workflow/rest/controller/ProcessController.java new file mode 100644 index 0000000..282e057 --- /dev/null +++ b/src/main/java/com/example/workflow/rest/controller/ProcessController.java @@ -0,0 +1,75 @@ +package com.example.workflow.rest.controller; + +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.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 一个常规的说HaloWode的流程 + * k + * + * @author chenchuancheng + * @since 2022/11/21 10:08 + */ +@RestController +public class ProcessController { + + @Resource + private RepositoryService repositoryService; + + @Resource + private RuntimeService runtimeService; + + @Resource + private TaskService taskService; + + @GetMapping("/deploy") + public String deploy() { + Deployment deploy = repositoryService.createDeployment() + .name("流程") + .addClasspathResource("process.bpmn") + .deploy(); + + return deploy.getId(); + } + + @GetMapping("/queryProcess/{deployId}") + public List queryProcess(@PathVariable("deployId") String deployId) { + List list = repositoryService.createProcessDefinitionQuery() + .deploymentId(deployId) + .list(); + return list.stream().map(ProcessDefinition::getId).collect(Collectors.toList()); + } + + @GetMapping("/start/{processDefinitionId}") + public String start(@PathVariable("processDefinitionId") String processDefinitionId) { + ProcessInstance processInstance = runtimeService + .startProcessInstanceById(processDefinitionId); + return processInstance.getId(); + } + + @GetMapping("/queryTask/{processInstanceId}") + public List queryTask(@PathVariable("processInstanceId") String processInstanceId) { + List list = taskService.createTaskQuery() + .processInstanceId(processInstanceId) + .list(); + return list.stream().map(Task::getId).collect(Collectors.toList()); + } + + @GetMapping("/finishTask/{taskId}") + public void finishTask(@PathVariable("taskId") String taskId) { + taskService.complete(taskId); + } + +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..2998935 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,24 @@ +spring: + datasource: + url: jdbc:postgresql://192.168.110.198:5432/camunda + type: com.zaxxer.hikari.HikariDataSource + driver-class-name: org.postgresql.Driver + hikari: + username: postgres + password: postgres +server: + port: 1111 + +#camunda.bpm.admin-user: +# id: admin +# password: admin +camunda: + bpm: + admin-user: + id: admin + password: admin + database: + # 乱写类型会出错,不如不写,camunda会自己判断。Error while building ibatis SqlSessionFactory: null + # type: postgresql + schema-update: drop-create + auto-deployment-enabled: false diff --git a/src/main/resources/payment-form.form b/src/main/resources/payment-form.form new file mode 100644 index 0000000..08c02d2 --- /dev/null +++ b/src/main/resources/payment-form.form @@ -0,0 +1,31 @@ +{ + "components": [ + { + "label": "Amount", + "type": "number", + "id": "Field_13olf2v", + "key": "amount" + }, + { + "label": "Item", + "type": "textfield", + "id": "Field_01i827y", + "key": "item" + }, + { + "label": "Approved?", + "type": "checkbox", + "id": "Field_01klvvc", + "key": "approved" + } + ], + "type": "default", + "id": "payment-form", + "exporter": { + "name": "Camunda Modeler", + "version": "5.5.0" + }, + "executionPlatform": "Camunda Platform", + "executionPlatformVersion": "7.18.0", + "schemaVersion": 5 +} \ No newline at end of file diff --git a/src/main/resources/payment-retrieval.bpmn b/src/main/resources/payment-retrieval.bpmn new file mode 100644 index 0000000..38f35e3 --- /dev/null +++ b/src/main/resources/payment-retrieval.bpmn @@ -0,0 +1,44 @@ + + + + + Flow_0c2ozia + + + + Flow_14ceptg + + + + Flow_0c2ozia + Flow_14ceptg + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/payment-retrieval1.bpmn b/src/main/resources/payment-retrieval1.bpmn new file mode 100644 index 0000000..a98c804 --- /dev/null +++ b/src/main/resources/payment-retrieval1.bpmn @@ -0,0 +1,58 @@ + + + + + Flow_17chpj9 + + + + + Flow_1maa5hg + + + + + Flow_17chpj9 + Flow_0jc5m04 + + + + Flow_0jc5m04 + Flow_1maa5hg + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/process.bpmn b/src/main/resources/process.bpmn new file mode 100644 index 0000000..af8ff32 --- /dev/null +++ b/src/main/resources/process.bpmn @@ -0,0 +1,41 @@ + + + + + SequenceFlow_1fp17al + + + + SequenceFlow_16gzt2m + + + + + + + SequenceFlow_1fp17al + SequenceFlow_16gzt2m + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/com/example/workflow/rest/controller/ChargeCardWorker.java b/src/test/java/com/example/workflow/rest/controller/ChargeCardWorker.java new file mode 100644 index 0000000..19070cb --- /dev/null +++ b/src/test/java/com/example/workflow/rest/controller/ChargeCardWorker.java @@ -0,0 +1,37 @@ +package com.example.workflow.rest.controller; + +import org.camunda.bpm.client.ExternalTaskClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.awt.*; +import java.net.URI; + +public class ChargeCardWorker { + + private static final Logger log = LoggerFactory.getLogger(ChargeCardWorker.class); + + public static void main(String[] args) { + ExternalTaskClient client = ExternalTaskClient.create() + .baseUrl("http://localhost:8080/engine-rest") + .asyncResponseTimeout(10000) // 长轮询超时时间 + .build(); + // 订阅指定的外部任务 + client.subscribe("charge-card") + .lockDuration(1000) + .handler(((externalTask, externalTaskService) -> { + // 获取流程变量 + String item = (String) externalTask.getVariable("item"); + Integer amount = (Integer) externalTask.getVariable("amount"); + System.out.println("item--->"+item + " amount-->" + amount); + try { + Desktop.getDesktop().browse(new URI("https://docs.camunda.org/get-started/quick-start/complete")); + } catch (Exception e) { + e.printStackTrace(); + } + + // 完成任务 + externalTaskService.complete(externalTask); + })).open(); + } +} diff --git a/src/test/java/com/example/workflow/rest/controller/ProcessControllerTest.java b/src/test/java/com/example/workflow/rest/controller/ProcessControllerTest.java new file mode 100644 index 0000000..4e33ec8 --- /dev/null +++ b/src/test/java/com/example/workflow/rest/controller/ProcessControllerTest.java @@ -0,0 +1,48 @@ +package com.example.workflow.rest.controller; + +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.repository.ProcessDefinitionQuery; +import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.camunda.bpm.engine.task.Task; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + +import javax.annotation.Resource; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +@SpringBootTest +class ProcessControllerTest { + + @Resource + private RepositoryService repositoryService; + + @Resource + private RuntimeService runtimeService; + + @Resource + private TaskService taskService; + + + @Test + void finishTask() { + Deployment deploy = repositoryService.createDeployment() + .name("流程") + .addClasspathResource("process.bpmn") + .deploy(); + List processDefinitionList = repositoryService.createProcessDefinitionQuery() + .deploymentId(deploy.getId()) + .list(); + ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinitionList.get(0).getId()); + List taskList = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list(); + Task task = taskList.get(0); + taskService.complete(task.getId()); + } +} diff --git a/target/classes/application.yml b/target/classes/application.yml new file mode 100644 index 0000000..2998935 --- /dev/null +++ b/target/classes/application.yml @@ -0,0 +1,24 @@ +spring: + datasource: + url: jdbc:postgresql://192.168.110.198:5432/camunda + type: com.zaxxer.hikari.HikariDataSource + driver-class-name: org.postgresql.Driver + hikari: + username: postgres + password: postgres +server: + port: 1111 + +#camunda.bpm.admin-user: +# id: admin +# password: admin +camunda: + bpm: + admin-user: + id: admin + password: admin + database: + # 乱写类型会出错,不如不写,camunda会自己判断。Error while building ibatis SqlSessionFactory: null + # type: postgresql + schema-update: drop-create + auto-deployment-enabled: false diff --git a/target/classes/com/example/workflow/Application.class b/target/classes/com/example/workflow/Application.class new file mode 100644 index 0000000..5bffb72 Binary files /dev/null and b/target/classes/com/example/workflow/Application.class differ diff --git a/target/classes/com/example/workflow/listener/SayHaloWodeListener.class b/target/classes/com/example/workflow/listener/SayHaloWodeListener.class new file mode 100644 index 0000000..93c1c0f Binary files /dev/null and b/target/classes/com/example/workflow/listener/SayHaloWodeListener.class differ diff --git a/target/classes/com/example/workflow/rest/controller/ProcessController.class b/target/classes/com/example/workflow/rest/controller/ProcessController.class new file mode 100644 index 0000000..80d1284 Binary files /dev/null and b/target/classes/com/example/workflow/rest/controller/ProcessController.class differ diff --git a/target/classes/payment-form.form b/target/classes/payment-form.form new file mode 100644 index 0000000..08c02d2 --- /dev/null +++ b/target/classes/payment-form.form @@ -0,0 +1,31 @@ +{ + "components": [ + { + "label": "Amount", + "type": "number", + "id": "Field_13olf2v", + "key": "amount" + }, + { + "label": "Item", + "type": "textfield", + "id": "Field_01i827y", + "key": "item" + }, + { + "label": "Approved?", + "type": "checkbox", + "id": "Field_01klvvc", + "key": "approved" + } + ], + "type": "default", + "id": "payment-form", + "exporter": { + "name": "Camunda Modeler", + "version": "5.5.0" + }, + "executionPlatform": "Camunda Platform", + "executionPlatformVersion": "7.18.0", + "schemaVersion": 5 +} \ No newline at end of file diff --git a/target/classes/payment-retrieval.bpmn b/target/classes/payment-retrieval.bpmn new file mode 100644 index 0000000..38f35e3 --- /dev/null +++ b/target/classes/payment-retrieval.bpmn @@ -0,0 +1,44 @@ + + + + + Flow_0c2ozia + + + + Flow_14ceptg + + + + Flow_0c2ozia + Flow_14ceptg + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/target/classes/payment-retrieval1.bpmn b/target/classes/payment-retrieval1.bpmn new file mode 100644 index 0000000..a98c804 --- /dev/null +++ b/target/classes/payment-retrieval1.bpmn @@ -0,0 +1,58 @@ + + + + + Flow_17chpj9 + + + + + Flow_1maa5hg + + + + + Flow_17chpj9 + Flow_0jc5m04 + + + + Flow_0jc5m04 + Flow_1maa5hg + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/target/classes/process.bpmn b/target/classes/process.bpmn new file mode 100644 index 0000000..af8ff32 --- /dev/null +++ b/target/classes/process.bpmn @@ -0,0 +1,41 @@ + + + + + SequenceFlow_1fp17al + + + + SequenceFlow_16gzt2m + + + + + + + SequenceFlow_1fp17al + SequenceFlow_16gzt2m + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/target/test-classes/com/example/workflow/rest/controller/ChargeCardWorker.class b/target/test-classes/com/example/workflow/rest/controller/ChargeCardWorker.class new file mode 100644 index 0000000..68ccf46 Binary files /dev/null and b/target/test-classes/com/example/workflow/rest/controller/ChargeCardWorker.class differ diff --git a/target/test-classes/com/example/workflow/rest/controller/ProcessControllerTest.class b/target/test-classes/com/example/workflow/rest/controller/ProcessControllerTest.class new file mode 100644 index 0000000..f954f9a Binary files /dev/null and b/target/test-classes/com/example/workflow/rest/controller/ProcessControllerTest.class differ