测试基本proto生成

This commit is contained in:
tiger_zhou 2023-05-24 15:53:50 +08:00
parent c9c4396fe9
commit c8f71d1d25
6 changed files with 202 additions and 95 deletions

178
pom.xml
View File

@ -1,44 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?> <?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" <project xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<modelVersion>4.0.0</modelVersion> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.boot</groupId> <parent>
<artifactId>spring-boot-starter-parent</artifactId> <groupId>org.springframework.boot</groupId>
<version>3.1.0</version> <artifactId>spring-boot-starter-parent</artifactId>
<relativePath/> <!-- lookup parent from repository --> <version>3.1.0</version>
</parent> <relativePath/> <!-- lookup parent from repository -->
<groupId>club.joylink</groupId> </parent>
<artifactId>xian-ncc-da</artifactId> <groupId>club.joylink</groupId>
<version>0.1</version> <artifactId>xian-ncc-da</artifactId>
<name>xian-ncc-da</name> <version>0.1</version>
<description>xian 城市轨道交通ncc决策辅助系统</description> <name>xian-ncc-da</name>
<properties> <description>xian 城市轨道交通ncc决策辅助系统</description>
<java.version>17</java.version> <properties>
<java.version>17</java.version>
<spring-boot.version>3.1.0</spring-boot.version> <spring-boot.version>3.1.0</spring-boot.version>
<mybatis-plus-version>3.5.3.1</mybatis-plus-version> <mybatis-plus-version>3.5.3.1</mybatis-plus-version>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId> <artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId> <artifactId>spring-boot-starter-security</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId> <artifactId>spring-boot-starter-validation</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId> <artifactId>spring-boot-starter-websocket</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
@ -77,55 +78,60 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId> <artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope> <scope>runtime</scope>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.mysql</groupId> <groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId> <artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId> <artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.security</groupId> <groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId> <artifactId>spring-security-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> <dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.23.1</version>
</dependency>
</dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version> <version>${spring-boot.version}</version>
<configuration> <configuration>
<excludes> <excludes>
<exclude> <exclude>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
</exclude> </exclude>
</excludes> </excludes>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

View File

@ -0,0 +1,6 @@
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.3.233:3306/xian-ncc-da?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
username: root
password: joylink0503

View File

@ -2,20 +2,22 @@ server:
port: 9071 port: 9071
spring: spring:
profiles:
default: dev
datasource: datasource:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.3.233:3306/xian-ncc-da?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true url: jdbc:mysql://192.168.3.233:3306/xian-ncc-da?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
username: root username: root
password: joylink0503 password: joylink0503
hikari: hikari:
minimum-idle: 5 # ????????????? minimum-idle: 5 # 连接池维护的最小空闲连接数
maximum-pool-size: 10 # ????????? maximum-pool-size: 10 #配置最大连接池大小
auto-commit: true # ?????????????????? auto-commit: true #配置从池返回的连接的默认自动提交行为
idle-timeout: 30000 # ???????????????????ms idle-timeout: 30000 # 允许连接在连接池中空闲的最长时间,单位ms
pool-name: HikariPool pool-name: HikariPool
max-lifetime: 1800000 # ?????????????????ms max-lifetime: 1800000 # 池中连接关闭后的最长生命周期,单位ms
connection-timeout: 30000 # ????????????ms connection-timeout: 30000 # 等待连接的超时时间,单位ms
connection-test-query: select 1 # ??????? connection-test-query: select 1
security: security:
oauth2: oauth2:
resource-server: resource-server:

View File

@ -0,0 +1,93 @@
package club.joylink.xiannccda;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.List;
import org.assertj.core.util.Lists;
public class GenertateProtoBufUtil {
private final static String EXE_BIN_FILE = String.join(File.separator,
System.getProperty("user.dir"), "xian-ncc-da-message",
"protoc-23.1-win64", "bin",
"protoc");
private File protoFilePath;
private String outPath;
private boolean pullMessage;
// private String gitPullPath;
public GenertateProtoBufUtil(String rootPath, boolean pullMessage) {
this.pullMessage = pullMessage;
String sourcePath = String.join(File.separator, rootPath,
"xian-ncc-da-message", "protos");
this.outPath = String.join(File.separator, rootPath,
"src", "main", "java");
this.protoFilePath = new File(sourcePath);
if (!protoFilePath.exists() || !protoFilePath.isDirectory()) {
throw new RuntimeException("proto不是目录或目录不存在");
}
}
public List<File> findFiles() {
return this.findFiles(this.protoFilePath);
}
public void execCommand() throws IOException {
if (this.pullMessage) {
this.PullTmmsMessage();
}
for (File file : this.findFiles()) {
String command = String.format("%s --proto_path=%s -I=%s --java_out=%s %s", EXE_BIN_FILE,
this.protoFilePath.getPath(), file.getParentFile().getAbsolutePath(), this.outPath,
file.getName());
this.genertateFile(command);
}
}
private void genertateFile(String command) throws IOException {
System.out.println(String.format("执行指令: %s", command));
InputStream errorStream = Runtime.getRuntime().exec(command).getErrorStream();
byte[] ebs = new byte[512];
StringBuilder sb = new StringBuilder();
int size;
while ((size = errorStream.read(ebs)) > 0) {
String err = new String(Arrays.copyOf(ebs, size), Charset.forName("UTF-8"));
sb.append(err);
}
System.out.println(sb);
}
private List<File> findFiles(File file) {
List<File> findFiles = Lists.newArrayList();
for (File files : file.listFiles()) {
if (files.isDirectory()) {
findFiles.addAll(this.findFiles(files));
} else if (files.getName().endsWith(".proto")) {
findFiles.add(files);
}
}
return findFiles;
}
private void PullTmmsMessage() throws IOException {
InputStream inputStream = Runtime.getRuntime()
.exec("git pull", null, protoFilePath).getInputStream();
byte[] ebs = new byte[512];
StringBuilder sb = new StringBuilder();
int size;
while ((size = inputStream.read(ebs)) > 0) {
String err = new String(Arrays.copyOf(ebs, size), Charset.forName("UTF-8"));
sb.append(err);
}
System.out.println(sb);
}
public static void main(String[] args) throws IOException {
GenertateProtoBufUtil gu = new GenertateProtoBufUtil(System.getProperty("user.dir"), true);
gu.execCommand();
}
}

View File

@ -45,7 +45,7 @@ public class MybatisPlusGenerator {
.strategyConfig(builder -> { .strategyConfig(builder -> {
builder.addExclude(ExcludeTableList); builder.addExclude(ExcludeTableList);
// entity // entity
builder.entityBuilder() builder.entityBuilder().enableLombok()
.disableSerialVersionUID() .disableSerialVersionUID()
.enableFileOverride() // 覆盖旧文件 .enableFileOverride() // 覆盖旧文件
.enableColumnConstant() // 开启生成字段常量 .enableColumnConstant() // 开启生成字段常量

@ -1 +1 @@
Subproject commit 9aa54608cd592ff96fc506e310fb19caff67f809 Subproject commit 51743f0de38e3abf76bc2f6456000a25acbff33e