Skip to content

Commit

Permalink
Merge pull request #487 from alibaba/jdk17-dev
Browse files Browse the repository at this point in the history
upgrade to Jdk17 and SpringBoot3
  • Loading branch information
significantfrank authored Jun 2, 2024
2 parents 8c1d2ee + 3590bc9 commit d9b0f5f
Show file tree
Hide file tree
Showing 203 changed files with 5,376 additions and 1,417 deletions.
30 changes: 30 additions & 0 deletions cola-archetypes/cola-archetype-light/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.alibaba.cola</groupId>
<artifactId>cola-archetype-light</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>maven-archetype</packaging>

<name>cola-archetype-light</name>

<build>
<extensions>
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
<version>3.2.1</version>
</extension>
</extensions>

<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-archetype-plugin</artifactId>
<version>3.2.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor xsi:schemaLocation="https://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.1.0 http://maven.apache.org/xsd/archetype-descriptor-1.1.0.xsd" name="charging-system"
xmlns="https://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8">
<directory>src/main/resources</directory>
<includes>
<include>**/*.yml</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/test/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory>src/test/resources</directory>
<includes>
<include>**/*.xml</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8">
<directory>src/test</directory>
<includes>
<include>**/*.http</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8">
<directory>src/test/resources</directory>
<includes>
<include>**/*.json</include>
<include>**/*.yml</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory>.idea</directory>
<includes>
<include>**/*.xml</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8">
<directory>.idea</directory>
<includes>
<include>**/*.gitignore</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8">
<directory></directory>
<includes>
<include>img_1.png</include>
<include>charge-parent.iml</include>
<include>charge.iml</include>
<include>img.png</include>
<include>charging-system.iml</include>
<include>README.md</include>
</includes>
</fileSet>
</fileSets>
</archetype-descriptor>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 运营商计费系统
计费系统是一个典型的复杂问题场景,比较适合采用COLA架构,且发挥Domain层的价值。故将其作为COLA的另一个Sample。

运营商计费系统的需求如下:

运营商向用户提供电话服务,支持用户拨打/接听电话,并对通话收取费用。
如:主动拨打电话收取 0.5 元/分钟的通话费用;接听电话收取 0.4 元/分钟的通话费用。

运营商为了吸引客户,定义了若干电话套餐,总共有三种类型的套餐。我们要设计一个**计费系统**用于套餐计费规则的执行,保存计费记录,并通知**账户系统**扣减费用。

_注意:在一次通话过程中,通话控制系统可能会调用多次计费系统进行计费。_

- 基础套餐
1. 主叫收费 0.5 元/分钟
2. 被叫收费 0.4 元/分钟


- 固定时长套餐
1. 套餐月固定费 100 元,包含:200 分钟主叫通话时间+200 分钟被叫接听时间
2. 套餐外部分不再参与打折优惠,主叫 0.5 元/分钟,被叫 0.4 元/分钟


- 家庭套餐
1. 套餐月固定费 20 元
2. 用户可以指定 N 个号码作为自己的亲情号
3. 用户接听/拨打亲情号均不收费
4. 与亲情号之外的号码通话,主叫 0.5 元/分钟,被叫 0.4 元/分钟

# 系统设计
## 统一语言
我经常说,建模就是在分析语言,对于任何问题域,熟悉领域知识、理清概念、统一语言都是非常必要且重要的事情。
对于这个系统也不例外。
![img_1.png](img_1.png)

## 计费系统和周边系统的关系
![img.png](img.png)



Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>

<properties>
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<springfox.version>3.0.0</springfox.version>
<archunit.version>1.3.0</archunit.version>
<spring.boot.version>3.2.0</spring.boot.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>
<!-- Unit Test Support start-->
<dependency>
<groupId>com.alibaba.cola</groupId>
<artifactId>cola-component-test-container</artifactId>
<version>4.4.0-SNAPSHOT</version>
</dependency>
<!--this for embedded database unit test-->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<!--this for dependent service mock, to avoid conflict, we'd better use standalone -->
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock-standalone</artifactId>
<version>3.5.4</version>
<scope>test</scope>
</dependency>
<!-- Unit Test Support End-->
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package};

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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.adapter;

import ${package}.application.ChargeServiceI;
import ${package}.application.dto.*;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;


@RestController
@Slf4j
public class ChargeController {

@Resource
private ChargeServiceI chargeService;

@PostMapping("session/{sessionId}/begin")
public Response begin(@PathVariable(name = "sessionId") String sessionId,
@RequestParam("callingPhoneNo") String callingPhoneNo,
@RequestParam("calledPhoneNo") String calledPhoneNo) {
log.debug(sessionId + " " + callingPhoneNo + " " + calledPhoneNo);
BeginSessionRequest request = new BeginSessionRequest(sessionId, Long.valueOf(callingPhoneNo), Long.valueOf(calledPhoneNo));
return chargeService.begin(request);
}

@PostMapping("session/{sessionId}/charge")
public Response charge(@PathVariable(name = "sessionId") String sessionId,
@RequestParam int duration) {
log.debug(sessionId + " " + duration);
ChargeRequest request = new ChargeRequest(sessionId, duration);
return chargeService.charge(request);
}

@PostMapping("session/{sessionId}/end")
public Response end(@PathVariable(name = "sessionId") String sessionId,
@RequestParam int duration) {
log.debug(sessionId + " " + duration);
EndSessionRequest request = new EndSessionRequest(sessionId, duration);
return chargeService.end(request);
}

@GetMapping("{sessionId}/chargeRecords")
public MultiResponse<ChargeRecordDto> getChargeRecord(@PathVariable(name = "sessionId") String sessionId) {
return chargeService.listChargeRecords(sessionId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.application;

import ${package}.application.dto.*;

public interface ChargeServiceI {
Response begin(BeginSessionRequest request);

Response charge(ChargeRequest request);

Response end(EndSessionRequest request);

MultiResponse<ChargeRecordDto> listChargeRecords(String sessionId);
}
Loading

0 comments on commit d9b0f5f

Please sign in to comment.