Skip to content

Commit

Permalink
Merge pull request didi#38 from lthaoshao/feature_v1.0.2_opt
Browse files Browse the repository at this point in the history
optimize maven dependency and code
  • Loading branch information
lthaoshao authored Feb 21, 2023
2 parents c84b566 + f6fbdb6 commit d755636
Show file tree
Hide file tree
Showing 43 changed files with 537 additions and 365 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,6 @@ spring.datasource.dynamic.datasource.engine.password=password
spring.datasource.dynamic.datasource.engine.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.dynamic.datasource.engine.url=jdbc:mysql://127.0.0.1:3306/db_engine
# 非必要属性
hook.url=http://127.0.0.1:8031/data/refresh
hook.timeout=3000
```

## 4. 根据demo开始你的Turbo之旅吧
Expand Down
31 changes: 23 additions & 8 deletions demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,46 @@
<parent>
<groupId>com.didiglobal.turbo</groupId>
<artifactId>turbo</artifactId>
<version>1.0.1</version>
<version>1.0.2-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>

<artifactId>demo</artifactId>
<version>1.0.1</version>
<version>1.0.2-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>

<spring-boot.version>1.5.10.RELEASE</spring-boot.version>
<turbo.engine.version>1.0.2-SNAPSHOT</turbo.engine.version>
<h2.version>1.4.200</h2.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.10.RELEASE</version>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring-boot.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.didiglobal.turbo</groupId>
<artifactId>engine</artifactId>
<version>1.0.1</version>
<version>${turbo.engine.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
package com.didiglobal.turbo.demo;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import com.didiglobal.turbo.engine.annotation.EnableTurboEngine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@EnableAutoConfiguration(exclude = {DruidDataSourceAutoConfigure.class})
@ComponentScan(basePackages = {"com.didiglobal.turbo.engine", "com.didiglobal.turbo.demo"})
@MapperScan(basePackages = {"com.didiglobal.turbo.engine.dao"})
@EnableTurboEngine
@SpringBootApplication(scanBasePackages = {"com.didiglobal.turbo.demo"})
public class DemoApplication {
private static final Logger LOGGER = LoggerFactory.getLogger(DemoApplication.class);

public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
*/
@Service
public class AfterSaleServiceImpl {
private static final Logger LOGGER = LoggerFactory.getLogger(LeaveServiceImpl.class);

private static final Logger LOGGER = LoggerFactory.getLogger(AfterSaleServiceImpl.class);

@Resource
private ProcessEngine processEngine;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.didiglobal.turbo.demo.service;

import com.didiglobal.turbo.engine.model.InstanceData;
import com.didiglobal.turbo.engine.spi.HookService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class HookServiceImpl implements HookService {
private static final Logger LOGGER = LoggerFactory.getLogger(HookServiceImpl.class);

@Override
public List<InstanceData> invoke(String flowInstanceId, String nodeInstanceId, String nodeKey, String hookInfoParam) {
LOGGER.info("flowInstance={}||nodeInstanceId={}||nodeKey={}||hookInfoParam={}",
flowInstanceId, nodeInstanceId, nodeKey, hookInfoParam);
// do sth , eg: refresh info
return new ArrayList<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private static Object buildAfterSaleFlowModelEntity() {
egOutgoings.add("SequenceFlow_168uou4");
exclusiveGateway.setOutgoing(egOutgoings);
Map<String, Object> properties = new HashMap<>();
properties.put("hookInfoIds", "");
properties.put("hookInfoIds", "testInfo");
exclusiveGateway.setProperties(properties);
flowElementList.add(exclusiveGateway);

Expand Down
2 changes: 0 additions & 2 deletions demo/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ mybatis.configuration.map-underscore-to-camel-case=true

logging.config=classpath:logback-spring.xml

hook.url=http://127.0.0.1:8031/globalInfo/refresh
hook.timeout=3000
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.didiglobal.turbo.demo;

import com.didiglobal.turbo.demo.DemoApplication;
import com.didiglobal.turbo.demo.service.AfterSaleServiceImpl;
import com.didiglobal.turbo.demo.service.LeaveServiceImpl;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public class FlowControllerTest {
@Resource
private FlowController flowController;

private String flowModuleId = null;
private String flowModuleId = "e7f6a27e-7cc3-11ec-b11c-02420abe030c";

private String flowDeployId = null;
private String flowDeployId = "450a101f-ae74-11ed-a29f-42f50c2c0006";

/**
* 创建流程接口
Expand Down Expand Up @@ -64,6 +64,7 @@ public void createFlow() {
@Test
public void saveFlowModel() {
String flowModel = "{\"flowElementList\":[{\"incoming\":[],\"outgoing\":[\"Flow_3599vu7\"],\"dockers\":[],\"type\":2,\"properties\":{\"name\":\"开始\",\"x\":310,\"y\":200,\"text\":{\"x\":310,\"y\":240,\"value\":\"开始\"}},\"key\":\"Event_0vbtunu\"},{\"incoming\":[\"Flow_3599vu7\"],\"outgoing\":[\"Flow_1f2ei89\"],\"dockers\":[],\"type\":4,\"properties\":{\"name\":\"\",\"x\":520,\"y\":200,\"text\":\"\"},\"key\":\"Activity_0ivtksn\"},{\"incoming\":[\"Flow_1f2ei89\"],\"outgoing\":[\"Flow_1rkk099\"],\"dockers\":[],\"type\":6,\"properties\":{\"name\":\"\",\"x\":730,\"y\":200,\"text\":\"\"},\"key\":\"Gateway_2qj55i1\"},{\"incoming\":[\"Flow_1rkk099\"],\"outgoing\":[],\"dockers\":[],\"type\":3,\"properties\":{\"name\":\"结束\",\"x\":950,\"y\":200,\"text\":{\"x\":950,\"y\":240,\"value\":\"结束\"}},\"key\":\"Event_03pjf39\"},{\"incoming\":[\"Event_0vbtunu\"],\"outgoing\":[\"Activity_0ivtksn\"],\"type\":1,\"dockers\":[],\"properties\":{\"name\":\"\",\"text\":\"\",\"startPoint\":\"{\\\"x\\\":328,\\\"y\\\":200}\",\"endPoint\":\"{\\\"x\\\":470,\\\"y\\\":200}\",\"pointsList\":\"\\\"\\\"\"},\"key\":\"Flow_3599vu7\"},{\"incoming\":[\"Activity_0ivtksn\"],\"outgoing\":[\"Gateway_2qj55i1\"],\"type\":1,\"dockers\":[],\"properties\":{\"name\":\"\",\"text\":\"\",\"startPoint\":\"{\\\"x\\\":570,\\\"y\\\":200}\",\"endPoint\":\"{\\\"x\\\":705,\\\"y\\\":200}\",\"pointsList\":\"\\\"\\\"\"},\"key\":\"Flow_1f2ei89\"},{\"incoming\":[\"Gateway_2qj55i1\"],\"outgoing\":[\"Event_03pjf39\"],\"type\":1,\"dockers\":[],\"properties\":{\"conditionsequenceflow\":\"a==1\",\"name\":\"\",\"text\":\"\",\"startPoint\":\"{\\\"x\\\":755,\\\"y\\\":200}\",\"endPoint\":\"{\\\"x\\\":932,\\\"y\\\":200}\",\"pointsList\":\"\\\"\\\"\"},\"key\":\"Flow_1rkk099\"}]}";
System.out.println(flowModel);
UpdateFlowRequest updateFlowRequest = new UpdateFlowRequest();
updateFlowRequest.setFlowModuleId(flowModuleId); //模型唯一标识 必需 (使用createFlow中返回的flowModuleId)
updateFlowRequest.setFlowModel(flowModel);//模型内容 必需
Expand All @@ -74,11 +75,9 @@ public void saveFlowModel() {
updateFlowRequest.setRemark("备注test");//备注 非必需
updateFlowRequest.setOperator("testOperator");// 操作人 非必需
BaseResponse<String> res = flowController.saveFlowModel(updateFlowRequest);
Assert.assertTrue(res.getErrCode() == 1000); //1000 成功

Assert.assertEquals(1000, res.getErrCode()); //1000 成功
}


/**
* 发布流程接口
*/
Expand Down Expand Up @@ -142,7 +141,5 @@ public void queryFlowList() {
String str = "queryFlowList 处理成功 总条数:%s 当前页:%s 每页条数:%s";
str = String.format(str, res.getData().getTotal(), res.getData().getCurrent(), res.getData().getSize());
System.out.println(str);

}

}
22 changes: 22 additions & 0 deletions demo/src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# ?????
spring.datasource.url=jdbc:h2:mem:test
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=root
spring.datasource.password=

spring.datasource.dynamic.primary=engine
spring.datasource.dynamic.datasource.engine.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.dynamic.datasource.engine.username=username
spring.datasource.dynamic.datasource.engine.password=password
spring.datasource.dynamic.datasource.engine.driver-class-name=org.h2.Driver
spring.datasource.dynamic.datasource.engine.url=jdbc:h2:mem:t_engine;MODE=MYSQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=TRUE


# DDL??
spring.datasource.schema=classpath:script/turbo-mysql-h2-ddl.sql

# DML??
spring.datasource.data=classpath:script/turbo-mysql-h2-dml.sql

logging.config=classpath:logback-spring.xml

35 changes: 35 additions & 0 deletions demo/src/test/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
<property name="LOG_HOME" value="./logs"/>
<!-- 控制台输出 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>
[%level][%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ}][%logger:%L][%thread]||traceid=%X{X-B3-TraceId:-}||%msg%n
</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
<FileNamePattern>${LOG_HOME}/turbo.demo.log.%d{yyyyMMddHH}</FileNamePattern>
<!--日志文件保留数量-->
<MaxHistory>240</MaxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>
[%level][%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ}][%logger:%L][%thread]||traceid=%X{X-B3-TraceId:-}||%msg%n
</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<logger name="org.springframework" level="INFO"/>
<!-- 日志输出级别 -->
<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
</root>
</configuration>
Loading

0 comments on commit d755636

Please sign in to comment.