From d6e12f7608f2a2ec67695a98869e20002111c3c5 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 26 Dec 2024 00:03:56 +0800 Subject: [PATCH 01/34] =?UTF-8?q?feat:=20=E5=88=9D=E5=A7=8B=E5=8C=96=20com?= =?UTF-8?q?mon-api=20=E5=92=8C=20system-server=20=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新建 common-api 和 system-server 模块的目录结构 - 添加 .gitignore 文件,忽略编译和IDE相关文件 - 创建 Spring Boot 应用程序入口和测试类 - 定义公共错误码和 API 结果封装类 - 添加 Redis、MySQL 和 Lombok 依赖- 配置 Spring Cloud 版本管理 --- .gitignore | 33 ++++++++ common-api/.gitignore | 33 ++++++++ common-api/pom.xml | 49 ++++++++++++ .../whut/commonapi/CommonApiApplication.java | 14 ++++ .../commonapi/core/domain/api/ApiResult.java | 77 +++++++++++++++++++ .../core/domain/error/CommonErrorCodes.java | 39 ++++++++++ .../core/domain/error/ErrorCode.java | 8 ++ .../src/main/resources/application.properties | 1 + .../commonapi/CommonApiApplicationTests.java | 13 ++++ pom.xml | 57 ++++++++++++++ system-server/.gitignore | 33 ++++++++ system-server/pom.xml | 56 ++++++++++++++ .../systemserver/SystemServerApplication.java | 16 ++++ .../src/main/resources/application.properties | 1 + .../SystemServerApplicationTests.java | 13 ++++ 15 files changed, 443 insertions(+) create mode 100644 .gitignore create mode 100644 common-api/.gitignore create mode 100644 common-api/pom.xml create mode 100644 common-api/src/main/java/cn/edu/whut/commonapi/CommonApiApplication.java create mode 100644 common-api/src/main/java/cn/edu/whut/commonapi/core/domain/api/ApiResult.java create mode 100644 common-api/src/main/java/cn/edu/whut/commonapi/core/domain/error/CommonErrorCodes.java create mode 100644 common-api/src/main/java/cn/edu/whut/commonapi/core/domain/error/ErrorCode.java create mode 100644 common-api/src/main/resources/application.properties create mode 100644 common-api/src/test/java/cn/edu/whut/commonapi/CommonApiApplicationTests.java create mode 100644 pom.xml create mode 100644 system-server/.gitignore create mode 100644 system-server/pom.xml create mode 100644 system-server/src/main/java/cn/edu/whut/systemserver/SystemServerApplication.java create mode 100644 system-server/src/main/resources/application.properties create mode 100644 system-server/src/test/java/cn/edu/whut/systemserver/SystemServerApplicationTests.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/common-api/.gitignore b/common-api/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/common-api/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/common-api/pom.xml b/common-api/pom.xml new file mode 100644 index 0000000..3ac7ea6 --- /dev/null +++ b/common-api/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + + cn.edu.whut + exam-question + 0.0.1-SNAPSHOT + + + + + + common-api + 0.0.1-SNAPSHOT + common-api + common-api + + 17 + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.github.xiaoymin + knife4j-openapi3-jakarta-spring-boot-starter + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/common-api/src/main/java/cn/edu/whut/commonapi/CommonApiApplication.java b/common-api/src/main/java/cn/edu/whut/commonapi/CommonApiApplication.java new file mode 100644 index 0000000..9d9df42 --- /dev/null +++ b/common-api/src/main/java/cn/edu/whut/commonapi/CommonApiApplication.java @@ -0,0 +1,14 @@ +package cn.edu.whut.commonapi; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + + +@SpringBootApplication +public class CommonApiApplication { + + public static void main(String[] args) { + SpringApplication.run(CommonApiApplication.class, args); + } + +} diff --git a/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/api/ApiResult.java b/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/api/ApiResult.java new file mode 100644 index 0000000..a6314d3 --- /dev/null +++ b/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/api/ApiResult.java @@ -0,0 +1,77 @@ +package cn.edu.whut.commonapi.core.domain.api; + + +import cn.edu.whut.commonapi.core.domain.error.CommonErrorCodes; +import io.swagger.v3.oas.annotations.media.Schema; + +import java.io.Serial; +import java.io.Serializable; + + +/** + * api接口返回信息封装 + */ +@Schema(description = "API接口返回信息封装") +public class ApiResult implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * 状态码 + */ + @Schema(description = "状态码") + private Integer code; + + /** + * 提示信息 + */ + @Schema(description = "响应信息") + private String msg; + + /** + * 数据 + */ + @Schema(description = "数据") + private T data; + + public ApiResult(){ + + } + + public ApiResult(int code, String msg){ + this.code = code; + this.msg = msg; + } + + public ApiResult(int code, String msg, T data){ + this.code = code; + this.msg = msg; + this.data = data; + } + + public ApiResult(T data){ + this.code = CommonErrorCodes.SUCCESS.code(); + this.msg = CommonErrorCodes.SUCCESS.msg(); + this.data = data; + } + + public ApiResult(CommonErrorCodes errorCode, T data) { + this.code = errorCode.code(); + this.msg = errorCode.msg(); + this.data = data; + } + + public static ApiResult success(T data){ + return new ApiResult<>(data); + } + + public static ApiResult error(int code, String msg){ + return new ApiResult<>(code, msg); + } + + public static ApiResult error(CommonErrorCodes errorCode){ + return new ApiResult<>(errorCode, null); + } + +} diff --git a/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/error/CommonErrorCodes.java b/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/error/CommonErrorCodes.java new file mode 100644 index 0000000..45cbb66 --- /dev/null +++ b/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/error/CommonErrorCodes.java @@ -0,0 +1,39 @@ +package cn.edu.whut.commonapi.core.domain.error; + +public enum CommonErrorCodes implements ErrorCode{ + + SUCCESS(0, "成功"), + + PARAM_ERROR(400, "参数错误"), + + NOT_FOUND(404, "未找到资源"), + + UNAUTHORIZED(401, "未授权"), + + FORBIDDEN(403, "禁止访问"), + + NOT_IMPLEMENTED(501, "未实现"), + + SERVICE_UNAVAILABLE(503, "服务不可用"), + + GATEWAY_TIMEOUT(504, "网关超时"); + + private int code; + + private String msg; + + CommonErrorCodes(int code, String msg){ + this.code = code; + this.msg = msg; + } + + @Override + public int code() { + return this.code; + } + + @Override + public String msg() { + return this.msg; + } +} diff --git a/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/error/ErrorCode.java b/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/error/ErrorCode.java new file mode 100644 index 0000000..e8d07f7 --- /dev/null +++ b/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/error/ErrorCode.java @@ -0,0 +1,8 @@ +package cn.edu.whut.commonapi.core.domain.error; + +public interface ErrorCode { + + int code(); + + String msg(); +} diff --git a/common-api/src/main/resources/application.properties b/common-api/src/main/resources/application.properties new file mode 100644 index 0000000..30ff097 --- /dev/null +++ b/common-api/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=common-api diff --git a/common-api/src/test/java/cn/edu/whut/commonapi/CommonApiApplicationTests.java b/common-api/src/test/java/cn/edu/whut/commonapi/CommonApiApplicationTests.java new file mode 100644 index 0000000..83447b9 --- /dev/null +++ b/common-api/src/test/java/cn/edu/whut/commonapi/CommonApiApplicationTests.java @@ -0,0 +1,13 @@ +package cn.edu.whut.commonapi; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class CommonApiApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..c8ea332 --- /dev/null +++ b/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.4.0 + + + + cn.edu.whut + exam-question + 0.0.1-SNAPSHOT + exam-question + 在线刷题和考试 + pom + + + 17 + 2023.0.3 + 5.8.16 + 4.4.0 + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + cn.hutool + hutool-all + ${hutool.version} + + + + org.projectlombok + lombok + + + + com.github.xiaoymin + knife4j-openapi3-jakarta-spring-boot-starter + ${knife4j.version} + + + + + + diff --git a/system-server/.gitignore b/system-server/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/system-server/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/system-server/pom.xml b/system-server/pom.xml new file mode 100644 index 0000000..ed423f0 --- /dev/null +++ b/system-server/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.4.1 + + + + cn.edu.whut + system-server + 0.0.1-SNAPSHOT + system-server + system-server + + 17 + + + + org.springframework.boot + spring-boot-starter-data-redis + + + org.springframework.boot + spring-boot-starter-web + + + + com.mysql + mysql-connector-j + runtime + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/system-server/src/main/java/cn/edu/whut/systemserver/SystemServerApplication.java b/system-server/src/main/java/cn/edu/whut/systemserver/SystemServerApplication.java new file mode 100644 index 0000000..2f8993e --- /dev/null +++ b/system-server/src/main/java/cn/edu/whut/systemserver/SystemServerApplication.java @@ -0,0 +1,16 @@ +package cn.edu.whut.systemserver; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + + +// Generated by https://start.springboot.io +// 优质的 spring/boot/data/security/cloud 框架中文文档尽在 => https://springdoc.cn +@SpringBootApplication +public class SystemServerApplication { + + public static void main(String[] args) { + SpringApplication.run(SystemServerApplication.class, args); + } + +} diff --git a/system-server/src/main/resources/application.properties b/system-server/src/main/resources/application.properties new file mode 100644 index 0000000..f46b531 --- /dev/null +++ b/system-server/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=system-server diff --git a/system-server/src/test/java/cn/edu/whut/systemserver/SystemServerApplicationTests.java b/system-server/src/test/java/cn/edu/whut/systemserver/SystemServerApplicationTests.java new file mode 100644 index 0000000..d316aeb --- /dev/null +++ b/system-server/src/test/java/cn/edu/whut/systemserver/SystemServerApplicationTests.java @@ -0,0 +1,13 @@ +package cn.edu.whut.systemserver; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class SystemServerApplicationTests { + + @Test + void contextLoads() { + } + +} -- Gitee From e518241b5e7fe6de7934f0b5ba4ad57a1b060236 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 26 Dec 2024 00:42:06 +0800 Subject: [PATCH 02/34] =?UTF-8?q?build:=20=E6=9B=B4=E6=96=B0=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E7=BB=93=E6=9E=84=E5=92=8C=E9=85=8D=E7=BD=AE-=20?= =?UTF-8?q?=E5=88=A0=E9=99=A4=20common-api=20=E5=92=8C=20system-server=20?= =?UTF-8?q?=E7=9A=84=E6=BA=90=E4=BB=A3=E7=A0=81=20-=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=20system-server/pom.xml=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E9=85=8D=E7=BD=AE=20-=20=E4=BF=AE=E6=94=B9=E6=A0=B9?= =?UTF-8?q?=20pom.xml=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=20-=20=E5=88=A0=E9=99=A4=E5=A4=9A=E4=B8=AA?= =?UTF-8?q?=20.gitignore=20=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common-api/.gitignore | 33 ------------------- .../whut/commonapi/CommonApiApplication.java | 14 -------- .../src/main/resources/application.properties | 1 - pom.xml | 5 +++ system-server/pom.xml | 5 +++ .../systemserver/SystemServerApplication.java | 16 --------- .../src/main/resources/application.properties | 1 - .../SystemServerApplicationTests.java | 13 -------- 8 files changed, 10 insertions(+), 78 deletions(-) delete mode 100644 common-api/.gitignore delete mode 100644 common-api/src/main/java/cn/edu/whut/commonapi/CommonApiApplication.java delete mode 100644 common-api/src/main/resources/application.properties delete mode 100644 system-server/src/main/java/cn/edu/whut/systemserver/SystemServerApplication.java delete mode 100644 system-server/src/main/resources/application.properties delete mode 100644 system-server/src/test/java/cn/edu/whut/systemserver/SystemServerApplicationTests.java diff --git a/common-api/.gitignore b/common-api/.gitignore deleted file mode 100644 index 549e00a..0000000 --- a/common-api/.gitignore +++ /dev/null @@ -1,33 +0,0 @@ -HELP.md -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/**/target/ -!**/src/test/**/target/ - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ - -### VS Code ### -.vscode/ diff --git a/common-api/src/main/java/cn/edu/whut/commonapi/CommonApiApplication.java b/common-api/src/main/java/cn/edu/whut/commonapi/CommonApiApplication.java deleted file mode 100644 index 9d9df42..0000000 --- a/common-api/src/main/java/cn/edu/whut/commonapi/CommonApiApplication.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.edu.whut.commonapi; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - - -@SpringBootApplication -public class CommonApiApplication { - - public static void main(String[] args) { - SpringApplication.run(CommonApiApplication.class, args); - } - -} diff --git a/common-api/src/main/resources/application.properties b/common-api/src/main/resources/application.properties deleted file mode 100644 index 30ff097..0000000 --- a/common-api/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=common-api diff --git a/pom.xml b/pom.xml index c8ea332..999ddfa 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,11 @@ 4.4.0 + + common-api + system-server + + diff --git a/system-server/pom.xml b/system-server/pom.xml index ed423f0..c3ed160 100644 --- a/system-server/pom.xml +++ b/system-server/pom.xml @@ -14,9 +14,14 @@ 0.0.1-SNAPSHOT system-server system-server + pom 17 + + system-server-api + system-server-biz + org.springframework.boot diff --git a/system-server/src/main/java/cn/edu/whut/systemserver/SystemServerApplication.java b/system-server/src/main/java/cn/edu/whut/systemserver/SystemServerApplication.java deleted file mode 100644 index 2f8993e..0000000 --- a/system-server/src/main/java/cn/edu/whut/systemserver/SystemServerApplication.java +++ /dev/null @@ -1,16 +0,0 @@ -package cn.edu.whut.systemserver; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - - -// Generated by https://start.springboot.io -// 优质的 spring/boot/data/security/cloud 框架中文文档尽在 => https://springdoc.cn -@SpringBootApplication -public class SystemServerApplication { - - public static void main(String[] args) { - SpringApplication.run(SystemServerApplication.class, args); - } - -} diff --git a/system-server/src/main/resources/application.properties b/system-server/src/main/resources/application.properties deleted file mode 100644 index f46b531..0000000 --- a/system-server/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=system-server diff --git a/system-server/src/test/java/cn/edu/whut/systemserver/SystemServerApplicationTests.java b/system-server/src/test/java/cn/edu/whut/systemserver/SystemServerApplicationTests.java deleted file mode 100644 index d316aeb..0000000 --- a/system-server/src/test/java/cn/edu/whut/systemserver/SystemServerApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package cn.edu.whut.systemserver; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class SystemServerApplicationTests { - - @Test - void contextLoads() { - } - -} -- Gitee From 5319782bf9e5ee09c42458a5245f5928d3690c7d Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 26 Dec 2024 00:43:34 +0800 Subject: [PATCH 03/34] =?UTF-8?q?feat(system-server):=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E6=9C=8D=E5=8A=A1=E5=99=A8=20API=20=E5=92=8C?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 system-server-api 和 system-server-biz模块 - 配置应用名称和端口 - 创建启动类和测试类 --- system-server/system-server-api/pom.xml | 57 +++++++++++++++++++ .../system/SystemServerApiApplication.java | 16 ++++++ .../src/main/resources/application.yml | 1 + .../SystemServerApiApplicationTests.java | 13 +++++ system-server/system-server-biz/pom.xml | 57 +++++++++++++++++++ .../whut/system/SystemServerApplication.java | 14 +++++ .../src/main/resources/application.yml | 5 ++ .../SystemServerBizApplicationTests.java | 13 +++++ 8 files changed, 176 insertions(+) create mode 100644 system-server/system-server-api/pom.xml create mode 100644 system-server/system-server-api/src/main/java/cn/edu/whut/system/SystemServerApiApplication.java create mode 100644 system-server/system-server-api/src/main/resources/application.yml create mode 100644 system-server/system-server-api/src/test/java/cn/edu/whut/system/SystemServerApiApplicationTests.java create mode 100644 system-server/system-server-biz/pom.xml create mode 100644 system-server/system-server-biz/src/main/java/cn/edu/whut/system/SystemServerApplication.java create mode 100644 system-server/system-server-biz/src/main/resources/application.yml create mode 100644 system-server/system-server-biz/src/test/java/cn/edu/whut/system/SystemServerBizApplicationTests.java diff --git a/system-server/system-server-api/pom.xml b/system-server/system-server-api/pom.xml new file mode 100644 index 0000000..bdd5a7d --- /dev/null +++ b/system-server/system-server-api/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.4.1 + + + + + + cn.edu.whut + system-server-api + 0.0.1-SNAPSHOT + system-server-api + system-server-api + + + + + + + + + + + + + + + 17 + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/system-server/system-server-api/src/main/java/cn/edu/whut/system/SystemServerApiApplication.java b/system-server/system-server-api/src/main/java/cn/edu/whut/system/SystemServerApiApplication.java new file mode 100644 index 0000000..6d075e8 --- /dev/null +++ b/system-server/system-server-api/src/main/java/cn/edu/whut/system/SystemServerApiApplication.java @@ -0,0 +1,16 @@ +package cn.edu.whut.system; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + + +// Generated by https://start.springboot.io +// 优质的 spring/boot/data/security/cloud 框架中文文档尽在 => https://springdoc.cn +@SpringBootApplication +public class SystemServerApiApplication { + + public static void main(String[] args) { + SpringApplication.run(SystemServerApiApplication.class, args); + } + +} diff --git a/system-server/system-server-api/src/main/resources/application.yml b/system-server/system-server-api/src/main/resources/application.yml new file mode 100644 index 0000000..03b1ea4 --- /dev/null +++ b/system-server/system-server-api/src/main/resources/application.yml @@ -0,0 +1 @@ +spring.application.name=system-server-api diff --git a/system-server/system-server-api/src/test/java/cn/edu/whut/system/SystemServerApiApplicationTests.java b/system-server/system-server-api/src/test/java/cn/edu/whut/system/SystemServerApiApplicationTests.java new file mode 100644 index 0000000..2e26f64 --- /dev/null +++ b/system-server/system-server-api/src/test/java/cn/edu/whut/system/SystemServerApiApplicationTests.java @@ -0,0 +1,13 @@ +package cn.edu.whut.system; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class SystemServerApiApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/system-server/system-server-biz/pom.xml b/system-server/system-server-biz/pom.xml new file mode 100644 index 0000000..dfb8666 --- /dev/null +++ b/system-server/system-server-biz/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.4.1 + + + + + + cn.edu.whut + system-server-biz + 0.0.1-SNAPSHOT + system-server-biz + system-server-biz + + + + + + + + + + + + + + + 17 + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/SystemServerApplication.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/SystemServerApplication.java new file mode 100644 index 0000000..ebcb766 --- /dev/null +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/SystemServerApplication.java @@ -0,0 +1,14 @@ +package cn.edu.whut.system; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + + +@SpringBootApplication +public class SystemServerApplication { + + public static void main(String[] args) { + SpringApplication.run(SystemServerApplication.class, args); + } + +} diff --git a/system-server/system-server-biz/src/main/resources/application.yml b/system-server/system-server-biz/src/main/resources/application.yml new file mode 100644 index 0000000..74e48b4 --- /dev/null +++ b/system-server/system-server-biz/src/main/resources/application.yml @@ -0,0 +1,5 @@ +spring: + application: + name: system-server +server: + port: 8081 diff --git a/system-server/system-server-biz/src/test/java/cn/edu/whut/system/SystemServerBizApplicationTests.java b/system-server/system-server-biz/src/test/java/cn/edu/whut/system/SystemServerBizApplicationTests.java new file mode 100644 index 0000000..6811084 --- /dev/null +++ b/system-server/system-server-biz/src/test/java/cn/edu/whut/system/SystemServerBizApplicationTests.java @@ -0,0 +1,13 @@ +package cn.edu.whut.system; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class SystemServerBizApplicationTests { + + @Test + void contextLoads() { + } + +} -- Gitee From 629cf9829fd7d1db30b8d1bc842398dfe390190d Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 26 Dec 2024 22:42:47 +0800 Subject: [PATCH 04/34] =?UTF-8?q?refactor(common-api):=20=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E9=A1=B9=E7=9B=AE=E7=9B=AE=E5=BD=95=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E5=B9=B6=E6=B7=BB=E5=8A=A0=E5=9F=BA=E7=A1=80=E5=AE=9E=E4=BD=93?= =?UTF-8?q?=E7=B1=BB-=20=E5=B0=86=20ApiResult=20=E7=B1=BB=E4=BB=8E=20domai?= =?UTF-8?q?n/api=20=E5=8C=85=E7=A7=BB=E5=8A=A8=E5=88=B0=20core/api?= =?UTF-8?q?=E5=8C=85=20-=20=E5=B0=86=20CommonErrorCodes=20=E5=92=8C=20Erro?= =?UTF-8?q?rCode=20=E4=BB=8E=20domain/error=20=E5=8C=85=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E5=88=B0=20core/error=20=E5=8C=85=20-=20=E6=96=B0=E5=A2=9E=20B?= =?UTF-8?q?aseEntity=20=E5=9F=BA=E7=A1=80=E5=AE=9E=E4=BD=93=E7=B1=BB?= =?UTF-8?q?=EF=BC=8C=E5=8C=85=E5=90=AB=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E3=80=81=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4=E3=80=81=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E8=80=85=20ID=E3=80=81=E6=9B=B4=E6=96=B0=E8=80=85=20I?= =?UTF-8?q?D=20=E5=92=8C=E5=88=A0=E9=99=A4=E6=A0=87=E5=BF=97=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=20-=20=E5=9C=A8=20pom.xml=20=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20Lombok=20=E5=92=8C=20MyBatis-Plus=20=E4=BE=9D?= =?UTF-8?q?=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common-api/pom.xml | 9 ++++ .../core/{domain => }/api/ApiResult.java | 4 +- .../commonapi/core/domain/BaseEntity.java | 47 +++++++++++++++++++ .../{domain => }/error/CommonErrorCodes.java | 2 +- .../core/{domain => }/error/ErrorCode.java | 2 +- pom.xml | 9 ++++ system-server/system-server-biz/pom.xml | 16 +++++++ .../cn/edu/whut/system/vo/SysUserRes.java | 4 ++ .../src/main/resources/application-loc.yml | 0 9 files changed, 89 insertions(+), 4 deletions(-) rename common-api/src/main/java/cn/edu/whut/commonapi/core/{domain => }/api/ApiResult.java (93%) create mode 100644 common-api/src/main/java/cn/edu/whut/commonapi/core/domain/BaseEntity.java rename common-api/src/main/java/cn/edu/whut/commonapi/core/{domain => }/error/CommonErrorCodes.java (93%) rename common-api/src/main/java/cn/edu/whut/commonapi/core/{domain => }/error/ErrorCode.java (58%) create mode 100644 system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/SysUserRes.java create mode 100644 system-server/system-server-biz/src/main/resources/application-loc.yml diff --git a/common-api/pom.xml b/common-api/pom.xml index 3ac7ea6..630f926 100644 --- a/common-api/pom.xml +++ b/common-api/pom.xml @@ -35,6 +35,15 @@ knife4j-openapi3-jakarta-spring-boot-starter + + org.projectlombok + lombok + + + + com.baomidou + mybatis-plus-spring-boot3-starter + diff --git a/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/api/ApiResult.java b/common-api/src/main/java/cn/edu/whut/commonapi/core/api/ApiResult.java similarity index 93% rename from common-api/src/main/java/cn/edu/whut/commonapi/core/domain/api/ApiResult.java rename to common-api/src/main/java/cn/edu/whut/commonapi/core/api/ApiResult.java index a6314d3..3662b05 100644 --- a/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/api/ApiResult.java +++ b/common-api/src/main/java/cn/edu/whut/commonapi/core/api/ApiResult.java @@ -1,7 +1,7 @@ -package cn.edu.whut.commonapi.core.domain.api; +package cn.edu.whut.commonapi.core.api; -import cn.edu.whut.commonapi.core.domain.error.CommonErrorCodes; +import cn.edu.whut.commonapi.core.error.CommonErrorCodes; import io.swagger.v3.oas.annotations.media.Schema; import java.io.Serial; diff --git a/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/BaseEntity.java b/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/BaseEntity.java new file mode 100644 index 0000000..7b6e6bd --- /dev/null +++ b/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/BaseEntity.java @@ -0,0 +1,47 @@ +package cn.edu.whut.commonapi.core.domain; + + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; + +import java.io.Serializable; +import java.sql.Timestamp; + +@Data +@JsonIgnoreProperties(value = "transMap") +public class BaseEntity implements Serializable { + + /** + * 创建时间 + */ + @TableField(fill = FieldFill.INSERT) + private Timestamp createTime; + + /** + * 最后更新时间 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Timestamp updateTime; + + /** + * 创建者id + * + */ + @TableField(fill = FieldFill.INSERT) + private Integer creatorId; + + /** + * 更新者id + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Integer updaterId; + + /** + * 是否删除 + */ + @TableLogic + private Boolean deleted; +} diff --git a/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/error/CommonErrorCodes.java b/common-api/src/main/java/cn/edu/whut/commonapi/core/error/CommonErrorCodes.java similarity index 93% rename from common-api/src/main/java/cn/edu/whut/commonapi/core/domain/error/CommonErrorCodes.java rename to common-api/src/main/java/cn/edu/whut/commonapi/core/error/CommonErrorCodes.java index 45cbb66..96f84b9 100644 --- a/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/error/CommonErrorCodes.java +++ b/common-api/src/main/java/cn/edu/whut/commonapi/core/error/CommonErrorCodes.java @@ -1,4 +1,4 @@ -package cn.edu.whut.commonapi.core.domain.error; +package cn.edu.whut.commonapi.core.error; public enum CommonErrorCodes implements ErrorCode{ diff --git a/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/error/ErrorCode.java b/common-api/src/main/java/cn/edu/whut/commonapi/core/error/ErrorCode.java similarity index 58% rename from common-api/src/main/java/cn/edu/whut/commonapi/core/domain/error/ErrorCode.java rename to common-api/src/main/java/cn/edu/whut/commonapi/core/error/ErrorCode.java index e8d07f7..0bad29b 100644 --- a/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/error/ErrorCode.java +++ b/common-api/src/main/java/cn/edu/whut/commonapi/core/error/ErrorCode.java @@ -1,4 +1,4 @@ -package cn.edu.whut.commonapi.core.domain.error; +package cn.edu.whut.commonapi.core.error; public interface ErrorCode { diff --git a/pom.xml b/pom.xml index 999ddfa..fb179f8 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,8 @@ 2023.0.3 5.8.16 4.4.0 + 1.18.36 + 3.5.9 @@ -48,6 +50,7 @@ org.projectlombok lombok + ${lombok.version} @@ -56,6 +59,12 @@ ${knife4j.version} + + com.baomidou + mybatis-plus-spring-boot3-starter + ${mybatisplus.version} + + diff --git a/system-server/system-server-biz/pom.xml b/system-server/system-server-biz/pom.xml index dfb8666..ffc9153 100644 --- a/system-server/system-server-biz/pom.xml +++ b/system-server/system-server-biz/pom.xml @@ -43,6 +43,22 @@ spring-boot-starter-test test + + + org.springframework.boot + spring-boot-starter-web + + + + com.mysql + mysql-connector-j + runtime + + + org.projectlombok + lombok + true + diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/SysUserRes.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/SysUserRes.java new file mode 100644 index 0000000..39c9960 --- /dev/null +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/SysUserRes.java @@ -0,0 +1,4 @@ +package cn.edu.whut.system.vo; + +public class SysUserRes { +} diff --git a/system-server/system-server-biz/src/main/resources/application-loc.yml b/system-server/system-server-biz/src/main/resources/application-loc.yml new file mode 100644 index 0000000..e69de29 -- Gitee From 3fc63594cea68f1fa151df34cddf4bc492aabfb4 Mon Sep 17 00:00:00 2001 From: Tom Date: Fri, 27 Dec 2024 00:13:08 +0800 Subject: [PATCH 05/34] =?UTF-8?q?feat(common-api):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=88=86=E9=A1=B5=E5=8F=82=E6=95=B0=20DTO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commonapi/core/domain/PageEntity.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 common-api/src/main/java/cn/edu/whut/commonapi/core/domain/PageEntity.java diff --git a/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/PageEntity.java b/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/PageEntity.java new file mode 100644 index 0000000..38821c6 --- /dev/null +++ b/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/PageEntity.java @@ -0,0 +1,23 @@ +package cn.edu.whut.commonapi.core.domain; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import lombok.Data; + +@Data +@Schema(description = "分页参数 Request DTO") +public class PageEntity { + + /** 当前记录起始索引 */ + @Schema(description = "当前记录起始索引", example = "0", requiredMode = Schema.RequiredMode.REQUIRED) + @Min(value = 0, message = "当前记录起始索引不能小于0") + private Integer pageNum; + + /** 每页显示记录数 */ + @Schema(description = "每页显示记录数", example = "10", requiredMode = Schema.RequiredMode.REQUIRED) + @Min(value = 1, message = "每页显示记录数不能小于1") + @Max(value = 100, message = "每页显示记录数不能大于100") + private Integer pageSize; + +} -- Gitee From 10d16e59779d08952a42942d80657c5bca142001 Mon Sep 17 00:00:00 2001 From: Tom Date: Sun, 29 Dec 2024 23:32:21 +0800 Subject: [PATCH 06/34] =?UTF-8?q?docs(README):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E4=BB=8B=E7=BB=8D=E5=92=8C=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增项目介绍、技术栈、功能说明等内容- 删除 Gitee 平台说明等无关内容 - 优化文档结构,增加小标题和列表,提高可读性 --- README.en.md | 36 ------- README.md | 95 ++++++++++++++----- system-server/system-server-biz/pom.xml | 17 +++- .../system/repository/SysUserRepository.java | 14 +++ 4 files changed, 96 insertions(+), 66 deletions(-) delete mode 100644 README.en.md create mode 100644 system-server/system-server-biz/src/main/java/cn/edu/whut/system/repository/SysUserRepository.java diff --git a/README.en.md b/README.en.md deleted file mode 100644 index 410b3a1..0000000 --- a/README.en.md +++ /dev/null @@ -1,36 +0,0 @@ -# exam-question - -#### Description -{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**} - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README.md b/README.md index 0d6bdd4..f56dcd6 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,82 @@ # exam-question -#### 介绍 -{**以下是 Gitee 平台说明,您可以替换此简介** -Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 -无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)} +## 介绍 +该平台为教育机构、企业培训和个人学习提供了一套完整的解决方案。系统具备强大的功能集,包括但不限于租户管理、用户管理、部门管理、题库管理、题目管理、在线考试、随机出题、按知识点出题以及在线刷题等。通过灵活的配置和直观的界面,用户可以轻松创建和参与各种类型的测试活动。系统基于Spring Boot 3.4.0和Spring Cloud构建,采用微服务架构设计。该架构允许系统各部分独立开发、部署和扩展,提高了系统的灵活性和可维护性。通过使用Spring Cloud的相关组件,实现了服务发现、配置管理、负载均衡、熔断器等功能,确保了系统的高可用性和稳定性。 -#### 软件架构 -软件架构说明 +## 2. 技术栈 +## 功能说明 -#### 安装教程 +### 1. 租户管理 -1. xxxx -2. xxxx -3. xxxx +- 支持多租户架构,允许不同组织独立使用同一平台。 +- 租户可以自定义品牌化设置(如Logo、颜色主题)。 +- 每个租户拥有独立的数据存储空间,确保数据隔离。 +- 可复用于其他项目,便于快速部署新的业务场景。 -#### 使用说明 +### 2. 用户管理 -1. xxxx -2. xxxx -3. xxxx +- 用户角色划分(管理员、教师、学生等),权限控制精细。 +- 支持批量导入/导出用户信息,简化用户管理流程。 +- 提供用户活动日志记录,便于审计追踪。 +- 集成第三方认证服务,支持多种登录方式(如OAuth2, SSO)。 -#### 参与贡献 +### 3. 部门管理 -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request +- 组织结构树形展示,清晰呈现各部门层级关系。 +- 支持部门间转移人员,调整组织架构。 +- 自动同步部门变动至相关联的应用模块。 +- 同样适用于非考试类项目的组织管理需求。 +### 4. 题库管理 -#### 特技 +- 创建和分类管理各类题库,涵盖不同学科领域。 +- 题库可共享或私有化,根据需要设定访问权限。 +- 提供题库版本控制,方便更新维护。 -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +### 5. 题目管理 + +- 多种题型支持(选择题、填空题、简答题等)。 +- 图片、音频、视频等多媒体元素嵌入。 +- 题目难度分级,适应不同层次的学习者。 +- 题目解析与答案提示,帮助用户理解正确答案。 + +### 6. 在线考试 + +- 定时开考、限时作答,模拟真实考场环境。 +- 考试过程中防作弊机制(如摄像头监控、屏幕锁定)。 +- 实时统计考试进度,成绩即时反馈。 + +### 7. 随机出题 + +- 根据设定规则自动从题库中抽取题目组成试卷。 +- 支持指定题目数量、题型比例等参数。 + +### 8. 按知识点出题 + +- 精准定位知识点,构建有针对性的试题集合。 +- 有助于评估特定领域的知识掌握情况。 + +### 9. 在线刷题 + +- 个性化推荐练习题目,依据用户的答题历史和薄弱点。 +- 刷题记录保存,便于回顾复习。 +- 成绩跟踪与进步分析,激励持续学习。 + +## 技术栈 + +- **前端**:Vue.js +- **后端**:SpringBoot 3.4.0 +- **数据库**:MySQL +- **缓存**:Redis +- **搜索**:Elasticsearch +- **部署**:Docker +- **API文档生成**:Swagger + +## 贡献代码 + +我们欢迎任何形式的贡献,无论是修复bug、优化性能还是新增特性。请参照[贡献指南](https://tongyi.aliyun.com/qianwen/CONTRIBUTING.md)了解如何参与项目开发。 + +## 版权声明 + +本项目遵循MIT许可证发布。更多信息,请参阅[LICENSE](https://tongyi.aliyun.com/qianwen/LICENSE)文件。 diff --git a/system-server/system-server-biz/pom.xml b/system-server/system-server-biz/pom.xml index ffc9153..e16d4cc 100644 --- a/system-server/system-server-biz/pom.xml +++ b/system-server/system-server-biz/pom.xml @@ -3,15 +3,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.springframework.boot - spring-boot-starter-parent - 3.4.1 + cn.edu.whut + exam-question + 0.0.1-SNAPSHOT - cn.edu.whut system-server-biz 0.0.1-SNAPSHOT system-server-biz @@ -59,6 +58,16 @@ lombok true + + com.baomidou + mybatis-plus-spring-boot3-starter + + + cn.edu.whut + common-api + 0.0.1-SNAPSHOT + compile + diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/repository/SysUserRepository.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/repository/SysUserRepository.java new file mode 100644 index 0000000..ade6ad7 --- /dev/null +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/repository/SysUserRepository.java @@ -0,0 +1,14 @@ +package cn.edu.whut.system.repository; + +import cn.edu.whut.commonapi.core.domain.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +public class SysUserRepository extends BaseEntity { + + private Integer userId; + + private String username; +} -- Gitee From 7f87fd5f6e055159750393e480caf7448d91f8b5 Mon Sep 17 00:00:00 2001 From: Tom Date: Mon, 30 Dec 2024 00:19:43 +0800 Subject: [PATCH 07/34] =?UTF-8?q?docs(README):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E4=BB=8B=E7=BB=8D=E5=92=8C=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改项目名称为"乐考刷" - 增加模块设计章节,包括模块划分和模块描述 - 详细说明系统服务的职责,包括用户管理、部门管理、租户管理等 --- README.md | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f56dcd6..ebaa15f 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,7 @@ -# exam-question +# 乐考刷 ## 介绍 -该平台为教育机构、企业培训和个人学习提供了一套完整的解决方案。系统具备强大的功能集,包括但不限于租户管理、用户管理、部门管理、题库管理、题目管理、在线考试、随机出题、按知识点出题以及在线刷题等。通过灵活的配置和直观的界面,用户可以轻松创建和参与各种类型的测试活动。系统基于Spring Boot 3.4.0和Spring Cloud构建,采用微服务架构设计。该架构允许系统各部分独立开发、部署和扩展,提高了系统的灵活性和可维护性。通过使用Spring Cloud的相关组件,实现了服务发现、配置管理、负载均衡、熔断器等功能,确保了系统的高可用性和稳定性。 - -## 2. 技术栈 +乐考刷在线考试刷题系统具备强大的功能集,包括但不限于租户管理、用户管理、部门管理、题库管理、题目管理、在线考试、随机出题、按知识点出题以及在线刷题等。通过灵活的配置和直观的界面,用户可以轻松创建和参与各种类型的测试活动。系统基于Spring Boot 3.4.0和Spring Cloud构建,采用微服务架构设计。该架构允许系统各部分独立开发、部署和扩展,提高了系统的灵活性和可维护性。通过使用Spring Cloud的相关组件,实现了服务发现、配置管理、负载均衡、熔断器等功能,确保了系统的高可用性和稳定性。 ## 功能说明 @@ -63,6 +61,24 @@ - 刷题记录保存,便于回顾复习。 - 成绩跟踪与进步分析,激励持续学习。 +## 模块设计 + +### 模块划分 + +乐考刷在线考试刷题系统包含系统服务、API网关、消息通知服务、题目服务、考试服务、刷题服务等6个模块。 + +### 模块描述 + +#### 系统服务 + +系统服务主要包含维护租户、用户、部门、角色、权限、菜单等系统基础数据,其职责为: + +1. **用户管理**:管理用户信息,包括注册、登录、权限管理等,支持OAuth2和JWT进行身份验证。 +2. **部门管理**:维护组织结构,处理部门间的层级关系,支持部门人员的添加、删除和转移操作。 +3. **租户管理**:管理租户信息,支持多租户架构,实现租户级别的数据隔离,提供品牌化设置接口。 +4. **角色管理**: +5. **菜单管理**: + ## 技术栈 - **前端**:Vue.js -- Gitee From 82fbe0ecc737e15b050daf03c07804a8b7f28584 Mon Sep 17 00:00:00 2001 From: Tom Date: Mon, 30 Dec 2024 00:31:37 +0800 Subject: [PATCH 08/34] =?UTF-8?q?docs(README):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=88=92=E5=88=86=E5=92=8C=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在模块划分中添加了日志服务,使系统包含7个模块 - 详细描述了API网关的职责和功能,包括统一入口点、请求路由与负载均衡、安全性增强、流量管理和限流、监控与日志记录、版本管理和服务演进、静态响应处理 -简化了系统服务中的角色管理和菜单管理描述 --- README.md | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ebaa15f..f2da5cd 100644 --- a/README.md +++ b/README.md @@ -65,10 +65,28 @@ ### 模块划分 -乐考刷在线考试刷题系统包含系统服务、API网关、消息通知服务、题目服务、考试服务、刷题服务等6个模块。 +乐考刷在线考试刷题系统包含系统服务、API网关、消息通知服务、题目服务、考试服务、刷题服务、日志服务等7个模块。 ### 模块描述 +#### API网关 + +API网关作为单一入口点来管理API调用之间的交互,能够将多个微服务整合在一起,为外部提供统一且简化的接口,其职责为: + +1. **统一入口点**:API网关作为所有外部请求进入系统的唯一通道,它可以有效地隐藏后端微服务的具体部署信息,保护内部架构不被外界直接访问。 + +2. **请求路由与负载均衡**:API网关可以根据预定义的规则将请求分发给正确的后端服务实例。这不仅包括基本的路径匹配,还可以基于内容类型、地理位置、用户身份等因素进行更复杂的路由决策。此外,API网关通常内置了负载均衡机制,能够在多个服务实例之间分配流量,确保即使某个实例出现故障,也不会影响整体的服务可用性。 + +3. **安全性增强**:为了保障API的安全调用,API网关实施了严格的访问控制措施,如IP黑白名单、认证鉴权、防重放攻击、防止恶意请求等。这些安全策略可以集中配置在API网关层面,避免了每个微服务都需要单独处理这些问题,大大降低了开发成本和潜在的风险。 + +4. **流量管理和限流**:API网关支持多种算法实现精细化的流量控制,例如固定窗口、滑动窗口、令牌桶等。通过灵活自定义的流量控制策略,API网关可以帮助应对突发的大流量冲击,保证API服务的稳定性和连续性。当检测到异常高的请求量时,API网关还可以自动触发限流措施,限制某些用户的请求频率,防止过载。 + +5. **监控与日志记录**:API网关是监控微服务运行状况的理想位置,因为它可以捕获所有的入站和出站流量。通过集成监控工具,API网关能够实时收集有关API性能、延迟、错误率等关键指标的数据,并生成详细的日志文件供后续分析使用。这对于快速定位问题根源、优化系统性能至关重要。 + +6. **版本管理和服务演进**:随着业务的发展和技术的进步,API可能会经历多次迭代更新。API网关允许开发者在同一URL下同时维护多个版本的API,确保旧版本的兼容性不受新版本的影响。同时,API网关也支持灰度发布功能,使得新的特性或改进可以在不影响现有用户的情况下逐步推广。 + +7. **静态响应处理**:对于一些不需要动态计算的结果,API网关可以直接返回预先准备好的静态响应,减少对后端服务的压力。这类场景特别适用于那些访问频率高但数据变化较少的资源,如网站的常见问题解答页面、API文档等。 + #### 系统服务 系统服务主要包含维护租户、用户、部门、角色、权限、菜单等系统基础数据,其职责为: @@ -76,8 +94,8 @@ 1. **用户管理**:管理用户信息,包括注册、登录、权限管理等,支持OAuth2和JWT进行身份验证。 2. **部门管理**:维护组织结构,处理部门间的层级关系,支持部门人员的添加、删除和转移操作。 3. **租户管理**:管理租户信息,支持多租户架构,实现租户级别的数据隔离,提供品牌化设置接口。 -4. **角色管理**: -5. **菜单管理**: +4. **角色管理**:管理维护系统角色信息,包括角色数据权限管理、菜单权限管理等。 +5. **菜单管理**:维护菜单结构,处理菜单之间的层级管理,可修改、删除菜单图标、名称、对应路径等数据。 ## 技术栈 -- Gitee From 33b58e1bb34424619ca2761a414ed7bb46eb9872 Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 31 Dec 2024 09:18:45 +0800 Subject: [PATCH 09/34] =?UTF-8?q?docs(README):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E6=8F=8F=E8=BF=B0-=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E4=BA=86=20README.md=20=E4=B8=AD=E5=AF=B9=20Spring=20Boot=20?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E7=9A=84=E8=AF=A6=E7=BB=86=E8=AF=B4=E6=98=8E?= =?UTF-8?q?=20-=20=E7=AE=80=E5=8C=96=E4=BA=86=E7=B3=BB=E7=BB=9F=E6=9E=B6?= =?UTF-8?q?=E6=9E=84=E7=9A=84=E6=8F=8F=E8=BF=B0=EF=BC=8C=E4=BF=9D=E7=95=99?= =?UTF-8?q?=E4=BA=86=E5=85=B3=E9=94=AE=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f2da5cd..fd3b78c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # 乐考刷 ## 介绍 -乐考刷在线考试刷题系统具备强大的功能集,包括但不限于租户管理、用户管理、部门管理、题库管理、题目管理、在线考试、随机出题、按知识点出题以及在线刷题等。通过灵活的配置和直观的界面,用户可以轻松创建和参与各种类型的测试活动。系统基于Spring Boot 3.4.0和Spring Cloud构建,采用微服务架构设计。该架构允许系统各部分独立开发、部署和扩展,提高了系统的灵活性和可维护性。通过使用Spring Cloud的相关组件,实现了服务发现、配置管理、负载均衡、熔断器等功能,确保了系统的高可用性和稳定性。 +乐考刷在线考试刷题系统具备强大的功能集,包括但不限于租户管理、用户管理、部门管理、题库管理、题目管理、在线考试、随机出题、按知识点出题以及在线刷题等。通过灵活的配置和直观的界面,用户可以轻松创建和参与各种类型的测试活动。系统基于Spring Boot 3构建,采用微服务架构设计。该架构允许系统各部分独立开发、部署和扩展,提高了系统的灵活性和可维护性。通过使用Spring Cloud的相关组件,实现了服务发现、配置管理、负载均衡、熔断器等功能,确保了系统的高可用性和稳定性。 ## 功能说明 -- Gitee From fb7f5234b31917d6643f35f31de2dec5a5ebcf8c Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 31 Dec 2024 09:23:42 +0800 Subject: [PATCH 10/34] =?UTF-8?q?docs(README):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=88=92=E5=88=86=E5=92=8C=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E8=AE=BE=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改消息通知服务为消息服务 - 优化系统服务模块描述 - 新增消息服务、题目服务、考试服务、刷题服务、日志服务的说明(todo) - 添加数据库设计部分,包括数据库选型和结构说明 - 选择 MySQL 数据库并解释原因 --- README.md | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fd3b78c..9b6c56f 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ ### 模块划分 -乐考刷在线考试刷题系统包含系统服务、API网关、消息通知服务、题目服务、考试服务、刷题服务、日志服务等7个模块。 +乐考刷在线考试刷题系统包含系统服务、API网关、消息服务、题目服务、考试服务、刷题服务、日志服务等7个模块。 ### 模块描述 @@ -89,7 +89,7 @@ API网关作为单一入口点来管理API调用之间的交互,能够将多 #### 系统服务 -系统服务主要包含维护租户、用户、部门、角色、权限、菜单等系统基础数据,其职责为: +系统服务主要包含管理维护租户、用户、部门、角色、权限、菜单等系统基础数据,其职责为: 1. **用户管理**:管理用户信息,包括注册、登录、权限管理等,支持OAuth2和JWT进行身份验证。 2. **部门管理**:维护组织结构,处理部门间的层级关系,支持部门人员的添加、删除和转移操作。 @@ -97,6 +97,39 @@ API网关作为单一入口点来管理API调用之间的交互,能够将多 4. **角色管理**:管理维护系统角色信息,包括角色数据权限管理、菜单权限管理等。 5. **菜单管理**:维护菜单结构,处理菜单之间的层级管理,可修改、删除菜单图标、名称、对应路径等数据。 +#### 消息服务 + +todo + +#### 题目服务 + +todo + +#### 考试服务 + +todo + +#### 刷题服务 + +todo + +#### 日志服务 + +todo + +## 数据库设计 + +### 数据库选型 + +乐考刷在线考试刷题系统使用MySQL数据库,原因如下: + +- MySQL是一种高性能的关系型数据库管理系统,具有优秀的读写速度。通过优化数据库结构,如范式化设计、选择合适的数据类型、添加索引等,可以进一步提高MySQL的读写性能。 +- MySQL的数据管理能力非常关键。通过数据库分区、分表等技术,MySQL可以更好地管理数据,提高查询效率。 +- MySQL具有良好的可扩展性,可以随着系统的增长而不断扩展。无论是通过增加硬件资源还是通过分布式架构,MySQL都能够应对不断增长的数据量和用户量。 +- 报警管理服务数据请求并发量较小,使用MySQL即可很好地存储和管理数据。 + +### 数据库结构 + ## 技术栈 - **前端**:Vue.js -- Gitee From 306a18397a16ff8642ddb301cda0a2f0e3f80a03 Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 31 Dec 2024 15:59:34 +0800 Subject: [PATCH 11/34] =?UTF-8?q?build(system-server):=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=20MyBatis-Plus=20=E4=BE=9D=E8=B5=96=E5=B9=B6=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=96=B0=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 system-server-biz模块中添加 mybatis-plus-jsqlparser 依赖 - 在根 pom 中将 mybatis-plus-spring-boot3-starter 替换为 mybatis-plus-bom,并设置为 import 范围 - 更新 README.md,添加数据库表设计说明 --- README.md | 20 +++++++++++++++++++ pom.xml | 4 +++- system-server/system-server-biz/pom.xml | 6 ++++++ .../system/repository/SysUserRepository.java | 2 ++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b6c56f..9bb708c 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,26 @@ todo ### 数据库结构 +#### 表设计 + +系统用户信息表(sys_user)如下: + +| 字段名称 | 字段类型 | 长度 | 是否可为null | 描述 | 备注 | +| ----------- | -------- | ---- | ------------ | ---- | ---- | +| user_id | varchar | | | | | +| username | | | | | | +| nickname | | | | | | +| phone | | | | | | +| email | | | | | | +| user_status | | | | | | +| create_time | | | | | | +| creator_id | | | | | | +| update_time | | | | | | +| updater_id | | | | | | +| deleted | | | | | | + + + ## 技术栈 - **前端**:Vue.js diff --git a/pom.xml b/pom.xml index fb179f8..d5c1ab7 100644 --- a/pom.xml +++ b/pom.xml @@ -61,8 +61,10 @@ com.baomidou - mybatis-plus-spring-boot3-starter + mybatis-plus-bom ${mybatisplus.version} + pom + import diff --git a/system-server/system-server-biz/pom.xml b/system-server/system-server-biz/pom.xml index e16d4cc..66a1c01 100644 --- a/system-server/system-server-biz/pom.xml +++ b/system-server/system-server-biz/pom.xml @@ -62,6 +62,12 @@ com.baomidou mybatis-plus-spring-boot3-starter + + + com.baomidou + mybatis-plus-jsqlparser + + cn.edu.whut common-api diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/repository/SysUserRepository.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/repository/SysUserRepository.java index ade6ad7..c3640aa 100644 --- a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/repository/SysUserRepository.java +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/repository/SysUserRepository.java @@ -11,4 +11,6 @@ public class SysUserRepository extends BaseEntity { private Integer userId; private String username; + + private String password; } -- Gitee From ff7516d8378643ebac4ee4d9fffbb7ff37eca8fa Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 31 Dec 2024 16:55:48 +0800 Subject: [PATCH 12/34] =?UTF-8?q?feat(system-server):=20=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E9=A1=B9=E7=9B=AE=E9=85=8D=E7=BD=AE=E5=92=8C=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 MyBatis Plus、Knife4j 等依赖 - 配置 Jackson、MyBatis Plus、Swagger 等 - 修改 SysUserRepository,添加用户相关字段 - 更新 pom.xml 文件,管理依赖版本 --- .../commonapi/core/domain/BaseEntity.java | 2 +- pom.xml | 7 ++ system-server/pom.xml | 24 ------- system-server/system-server-biz/pom.xml | 8 +++ .../system/repository/SysUserRepository.java | 54 +++++++++++++++ .../src/main/resources/application.yml | 67 +++++++++++++++++++ 6 files changed, 137 insertions(+), 25 deletions(-) diff --git a/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/BaseEntity.java b/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/BaseEntity.java index 7b6e6bd..0e087d9 100644 --- a/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/BaseEntity.java +++ b/common-api/src/main/java/cn/edu/whut/commonapi/core/domain/BaseEntity.java @@ -43,5 +43,5 @@ public class BaseEntity implements Serializable { * 是否删除 */ @TableLogic - private Boolean deleted; + private Integer deleted; } diff --git a/pom.xml b/pom.xml index d5c1ab7..8a1f0f8 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,7 @@ 4.4.0 1.18.36 3.5.9 + 1.5.2 @@ -67,6 +68,12 @@ import + + com.github.yulichang + mybatis-plus-join-boot-starter + ${mybatisplusjoin.version} + + diff --git a/system-server/pom.xml b/system-server/pom.xml index c3ed160..36f2447 100644 --- a/system-server/pom.xml +++ b/system-server/pom.xml @@ -23,30 +23,6 @@ system-server-biz - - org.springframework.boot - spring-boot-starter-data-redis - - - org.springframework.boot - spring-boot-starter-web - - - - com.mysql - mysql-connector-j - runtime - - - org.projectlombok - lombok - true - - - org.springframework.boot - spring-boot-starter-test - test - diff --git a/system-server/system-server-biz/pom.xml b/system-server/system-server-biz/pom.xml index 66a1c01..b4cbfb4 100644 --- a/system-server/system-server-biz/pom.xml +++ b/system-server/system-server-biz/pom.xml @@ -67,6 +67,14 @@ com.baomidou mybatis-plus-jsqlparser + + com.github.xiaoymin + knife4j-openapi3-jakarta-spring-boot-starter + + + com.github.yulichang + mybatis-plus-join-boot-starter + cn.edu.whut diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/repository/SysUserRepository.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/repository/SysUserRepository.java index c3640aa..1cf5eb8 100644 --- a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/repository/SysUserRepository.java +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/repository/SysUserRepository.java @@ -1,16 +1,70 @@ package cn.edu.whut.system.repository; import cn.edu.whut.commonapi.core.domain.BaseEntity; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.EqualsAndHashCode; +@TableName("sys_user") @EqualsAndHashCode(callSuper = true) @Data public class SysUserRepository extends BaseEntity { + /** + * 用户id + */ + @TableId(value = "user_id", type = IdType.AUTO) private Integer userId; + /** + * 用户名 + */ private String username; + /** + * 昵称 + */ + private String nickname; + + /** + * 密码 + */ private String password; + + /** + * 手机号 + */ + private String phone; + + /** + * 邮箱 + */ + private String email; + + /** + * 性别 + */ + private Integer sex; + + /** + * 用户头像 + */ + private String avatar; + + /** + * 状态 + */ + private Integer userStatus; + + /** + * 备注 + */ + private String remark; + + /** + * 部门 ID + */ + private Integer deptId; } diff --git a/system-server/system-server-biz/src/main/resources/application.yml b/system-server/system-server-biz/src/main/resources/application.yml index 74e48b4..e9aecad 100644 --- a/system-server/system-server-biz/src/main/resources/application.yml +++ b/system-server/system-server-biz/src/main/resources/application.yml @@ -1,5 +1,72 @@ spring: application: name: system-server + profiles: + active: dev + + jackson: + serialization: + write-dates-as-timestamps: true # 设置 Date 的格式,使用时间戳 + write-date-timestamps-as-nanoseconds: false # 设置不使用 nanoseconds 的格式。例如说 1611460870.401,而是直接 1611460870401 + write-durations-as-timestamps: true # 设置 Duration 的格式,使用时间戳 + fail-on-empty-beans: false # 允许序列化无属性的 Bean + server: port: 8081 + servlet: + context-path: /api/common/system + +mybatis-plus: + global-config: + db-config: + id-type: NONE # “智能”模式,基于 IdTypeEnvironmentPostProcessor + 数据源的类型,自动适配成 AUTO、INPUT 模式。 + logic-delete-value: 1 # 逻辑已删除值(默认为 1) + logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) + banner: false # 关闭控制台的 Banner 打印 + type-aliases-package: cn.edu.whut.system.*.mapper + configuration: + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + mapper-locations: classpath:mapper/*Mapper.xml + +mybatis-plus-join: + banner: true # 是否打印 mybatis plus join banner,默认true + sub-table-logic: true # 全局启用副表逻辑删除,默认true。关闭后关联查询不会加副表逻辑删除 + ms-cache: true # 拦截器MappedStatement缓存,默认 true + table-alias: t # 表别名(默认 t) + logic-del-type: on # 副表逻辑删除条件的位置,支持 WHERE、ON,默认 ON + +springdoc: + swagger-ui: + path: /swagger-ui.html + # path: 配置swagger-ui.html/UI界面的访问路径,默认为/swagger-ui.html + tags-sorter: alpha + # tags-sorter: 接口文档中的tags排序规则,默认为alpha,可选值为alpha(按字母顺序排序)或as-is(按照在代码中定义的顺序排序) + operations-sorter: alpha + + api-docs: + path: /v3/api-docs + # path: 配置api-docs的访问路径,默认为/v3/api-docs + + group-configs: + # group-configs: 配置分组信息 + - group: 'default' + # group: 分组名称 + paths-to-match: '/**' + # paths-to-match: 配置要匹配的路径,默认为/** + packages-to-scan: cn.edu.whut.system + # packages-to-scan: 配置要扫描的包的路径,直接配置为Controller类所在的包名即可 + +# knife4j项目访问访问地址:http://127.0.0.1:8080/doc.html#/home +knife4j: + enable: true + # 设置为true以启用Knife4j增强功能,这将再应用程序中启用Knife4j UI + setting: + # language: 设置Knife4j UI的语言,默认为zh_cn,可选值为zh_cn或en + language: zh-CN + #开启生产环境屏蔽 + production: false + #是否启用登录认证 + basic: + enable: false + username: # 自己设置一个 + password: # 自己设置一个 \ No newline at end of file -- Gitee From 2f78aba5590610febe4ccc902b2121e12c9412c3 Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 31 Dec 2024 17:12:16 +0800 Subject: [PATCH 13/34] =?UTF-8?q?feat(system-server):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20Druid=20=E6=95=B0=E6=8D=AE=E6=BA=90=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=B9=B6=E9=9B=86=E6=88=90=20Redis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 application-loc.yml 中添加了 Druid 数据源和 Redis 配置 - 在 system-server-biz 和根 pom.xml 中添加了 Druid 相关依赖 - 配置了 MySQL 数据库和 Redis 连接信息 --- pom.xml | 7 +++++++ system-server/system-server-biz/pom.xml | 4 ++++ .../src/main/resources/application-loc.yml | 12 ++++++++++++ 3 files changed, 23 insertions(+) diff --git a/pom.xml b/pom.xml index 8a1f0f8..5fed7ff 100644 --- a/pom.xml +++ b/pom.xml @@ -24,6 +24,7 @@ 1.18.36 3.5.9 1.5.2 + 1.2.24 @@ -74,6 +75,12 @@ ${mybatisplusjoin.version} + + com.alibaba + druid-spring-boot-3-starter + ${druid.version} + + diff --git a/system-server/system-server-biz/pom.xml b/system-server/system-server-biz/pom.xml index b4cbfb4..16b34b6 100644 --- a/system-server/system-server-biz/pom.xml +++ b/system-server/system-server-biz/pom.xml @@ -75,6 +75,10 @@ com.github.yulichang mybatis-plus-join-boot-starter + + com.alibaba + druid-spring-boot-3-starter + cn.edu.whut diff --git a/system-server/system-server-biz/src/main/resources/application-loc.yml b/system-server/system-server-biz/src/main/resources/application-loc.yml index e69de29..9ee6f67 100644 --- a/system-server/system-server-biz/src/main/resources/application-loc.yml +++ b/system-server/system-server-biz/src/main/resources/application-loc.yml @@ -0,0 +1,12 @@ +spring: + datasource: + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3306/system_database?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8 + username: root + password: 123456 + data: + redis: + host: localhost + port: 6379 + password: \ No newline at end of file -- Gitee From d3122ef2f12e89df7333fa473628d08c6da11347 Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 31 Dec 2024 17:33:39 +0800 Subject: [PATCH 14/34] =?UTF-8?q?feat(system-server):=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=20API=20=E6=A8=A1=E5=9D=97=E5=B9=B6=E9=9B=86=E6=88=90=20Nacos?= =?UTF-8?q?=20=E5=8F=91=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除了 system-server-api 模块的全部代码 - 在 system-server-biz 模块中添加了 Nacos 发现的依赖 - 在根 pom.xml 中添加了 Spring Cloud Alibaba 的版本和依赖 - 移除了 application.yml 文件 --- pom.xml | 9 +++++++++ .../whut/system/SystemServerApiApplication.java | 16 ---------------- .../src/main/resources/application.yml | 1 - system-server/system-server-biz/pom.xml | 5 +++++ 4 files changed, 14 insertions(+), 17 deletions(-) delete mode 100644 system-server/system-server-api/src/main/java/cn/edu/whut/system/SystemServerApiApplication.java delete mode 100644 system-server/system-server-api/src/main/resources/application.yml diff --git a/pom.xml b/pom.xml index 5fed7ff..8c54ceb 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,7 @@ 17 2023.0.3 + 2023.0.3.2 5.8.16 4.4.0 1.18.36 @@ -42,6 +43,14 @@ pom import + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + ${spring-cloud-alibaba.version} + pom + import + cn.hutool diff --git a/system-server/system-server-api/src/main/java/cn/edu/whut/system/SystemServerApiApplication.java b/system-server/system-server-api/src/main/java/cn/edu/whut/system/SystemServerApiApplication.java deleted file mode 100644 index 6d075e8..0000000 --- a/system-server/system-server-api/src/main/java/cn/edu/whut/system/SystemServerApiApplication.java +++ /dev/null @@ -1,16 +0,0 @@ -package cn.edu.whut.system; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - - -// Generated by https://start.springboot.io -// 优质的 spring/boot/data/security/cloud 框架中文文档尽在 => https://springdoc.cn -@SpringBootApplication -public class SystemServerApiApplication { - - public static void main(String[] args) { - SpringApplication.run(SystemServerApiApplication.class, args); - } - -} diff --git a/system-server/system-server-api/src/main/resources/application.yml b/system-server/system-server-api/src/main/resources/application.yml deleted file mode 100644 index 03b1ea4..0000000 --- a/system-server/system-server-api/src/main/resources/application.yml +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=system-server-api diff --git a/system-server/system-server-biz/pom.xml b/system-server/system-server-biz/pom.xml index 16b34b6..0f4ef16 100644 --- a/system-server/system-server-biz/pom.xml +++ b/system-server/system-server-biz/pom.xml @@ -80,6 +80,11 @@ druid-spring-boot-3-starter + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + cn.edu.whut common-api -- Gitee From e5d4e048a1afe9fdfe25fe1e4b9820a45a64eefd Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 1 Jan 2025 23:40:29 +0800 Subject: [PATCH 15/34] =?UTF-8?q?build(system-server):=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E5=92=8C=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 application.yml 文件,将 profiles.active 从 dev改为 loc - 在 application-loc.yml 文件中添加 Nacos配置 - 更新 system-server-api 和 system-server 的 parent 依赖- 降低根项目的 Spring Boot版本 --- pom.xml | 2 +- system-server/pom.xml | 7 +++---- system-server/system-server-api/pom.xml | 7 +++---- .../src/main/resources/application-loc.yml | 5 ++++- .../system-server-biz/src/main/resources/application.yml | 3 ++- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 8c54ceb..ed9b95d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.4.0 + 3.3.7 diff --git a/system-server/pom.xml b/system-server/pom.xml index 36f2447..f2f1d5d 100644 --- a/system-server/pom.xml +++ b/system-server/pom.xml @@ -3,13 +3,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.springframework.boot - spring-boot-starter-parent - 3.4.1 + cn.edu.whut + exam-question + 0.0.1-SNAPSHOT - cn.edu.whut system-server 0.0.1-SNAPSHOT system-server diff --git a/system-server/system-server-api/pom.xml b/system-server/system-server-api/pom.xml index bdd5a7d..54cae96 100644 --- a/system-server/system-server-api/pom.xml +++ b/system-server/system-server-api/pom.xml @@ -3,15 +3,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.springframework.boot - spring-boot-starter-parent - 3.4.1 + cn.edu.whut + exam-question + 0.0.1-SNAPSHOT - cn.edu.whut system-server-api 0.0.1-SNAPSHOT system-server-api diff --git a/system-server/system-server-biz/src/main/resources/application-loc.yml b/system-server/system-server-biz/src/main/resources/application-loc.yml index 9ee6f67..83980ce 100644 --- a/system-server/system-server-biz/src/main/resources/application-loc.yml +++ b/system-server/system-server-biz/src/main/resources/application-loc.yml @@ -9,4 +9,7 @@ spring: redis: host: localhost port: 6379 - password: \ No newline at end of file + password: + cloud: + nacos: + server-addr: 127.0.0.1:8848 diff --git a/system-server/system-server-biz/src/main/resources/application.yml b/system-server/system-server-biz/src/main/resources/application.yml index e9aecad..59b6cba 100644 --- a/system-server/system-server-biz/src/main/resources/application.yml +++ b/system-server/system-server-biz/src/main/resources/application.yml @@ -1,8 +1,9 @@ spring: application: name: system-server + profiles: - active: dev + active: loc jackson: serialization: -- Gitee From ea1d4cec0c7ab3b4c765d161e54d55630c2a1f7b Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 2 Jan 2025 00:06:48 +0800 Subject: [PATCH 16/34] =?UTF-8?q?build(system-server):=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=20Nacos=E9=85=8D=E7=BD=AE=E5=B9=B6=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=20Spring=20Boot=20=E6=8F=92=E4=BB=B6=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新 Nacos配置:将 server-addr从 127.0.0.1:8848 改为 localhost:8848 - 升级 Spring Boot 插件版本:在多个模块中将 Spring Boot 插件版本升级到 3.3.7 --- common-api/pom.xml | 1 + system-server/pom.xml | 1 + system-server/system-server-api/pom.xml | 1 + system-server/system-server-biz/pom.xml | 1 + .../system-server-biz/src/main/resources/application-loc.yml | 3 ++- 5 files changed, 6 insertions(+), 1 deletion(-) diff --git a/common-api/pom.xml b/common-api/pom.xml index 630f926..bd78451 100644 --- a/common-api/pom.xml +++ b/common-api/pom.xml @@ -51,6 +51,7 @@ org.springframework.boot spring-boot-maven-plugin + 3.3.7 diff --git a/system-server/pom.xml b/system-server/pom.xml index f2f1d5d..9bb76af 100644 --- a/system-server/pom.xml +++ b/system-server/pom.xml @@ -29,6 +29,7 @@ org.springframework.boot spring-boot-maven-plugin + 3.3.7 diff --git a/system-server/system-server-api/pom.xml b/system-server/system-server-api/pom.xml index 54cae96..68c9970 100644 --- a/system-server/system-server-api/pom.xml +++ b/system-server/system-server-api/pom.xml @@ -49,6 +49,7 @@ org.springframework.boot spring-boot-maven-plugin + 3.3.7 diff --git a/system-server/system-server-biz/pom.xml b/system-server/system-server-biz/pom.xml index 0f4ef16..5fe6ba1 100644 --- a/system-server/system-server-biz/pom.xml +++ b/system-server/system-server-biz/pom.xml @@ -98,6 +98,7 @@ org.springframework.boot spring-boot-maven-plugin + 3.3.7 diff --git a/system-server/system-server-biz/src/main/resources/application-loc.yml b/system-server/system-server-biz/src/main/resources/application-loc.yml index 83980ce..4698747 100644 --- a/system-server/system-server-biz/src/main/resources/application-loc.yml +++ b/system-server/system-server-biz/src/main/resources/application-loc.yml @@ -12,4 +12,5 @@ spring: password: cloud: nacos: - server-addr: 127.0.0.1:8848 + discovery: + server-addr: localhost:8848 -- Gitee From 4560ac4ba12e1a93543de29ad714f25f6a224d0b Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 2 Jan 2025 00:47:27 +0800 Subject: [PATCH 17/34] =?UTF-8?q?feat(system-server):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E9=85=8D=E7=BD=AE=E5=92=8C=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF=E8=A1=A8=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改数据库连接端口为 3310 - 更新系统用户信息表结构,增加新字段并调整现有字段类型 - 添加用户信息表 --- README.md | 32 +++++++++++-------- sql/sys_user.sql | 20 ++++++++++++ .../src/main/resources/application-loc.yml | 2 +- 3 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 sql/sys_user.sql diff --git a/README.md b/README.md index 9bb708c..fbffa6f 100644 --- a/README.md +++ b/README.md @@ -134,19 +134,25 @@ todo 系统用户信息表(sys_user)如下: -| 字段名称 | 字段类型 | 长度 | 是否可为null | 描述 | 备注 | -| ----------- | -------- | ---- | ------------ | ---- | ---- | -| user_id | varchar | | | | | -| username | | | | | | -| nickname | | | | | | -| phone | | | | | | -| email | | | | | | -| user_status | | | | | | -| create_time | | | | | | -| creator_id | | | | | | -| update_time | | | | | | -| updater_id | | | | | | -| deleted | | | | | | +| 字段名称 | 字段类型 | 长度 | 是否可为null | 描述 | 备注 | +| ----------- | --------- | ---- | ------------ | ------------ | ----------------------- | +| user_id | int | | 否 | 用户id,主键 | | +| username | varchar | 64 | 否 | 用户名称 | | +| nickname | varchar | 64 | 否 | 用户昵称 | | +| password | varchar | 512 | 否 | 密码 | | +| phone | varchar | 11 | 否 | 手机号 | | +| email | varchar | 64 | 是 | 邮箱 | | +| sex | tinyint | | 是 | 性别 | 0男,1女,3未知 | +| avatar | varchar | 512 | 是 | 头像 | | +| user_status | tinyint | | 否 | 用户状态 | 0可用,1禁用,默认为0 | +| remark | varchar | 512 | 是 | 备注 | | +| dept_id | int | | 否 | 部门id | | +| tenant_id | int | | 否 | 租户id | | +| create_time | timestamp | | 否 | 创建时间 | | +| creator_id | int | | 否 | 创建者id | | +| update_time | timestamp | | 是 | 更新时间 | | +| updater_id | int | | 是 | 更新者id | | +| deleted | tinyint | | 否 | 删除标志 | 0未删除,1删除,默认为0 | diff --git a/sql/sys_user.sql b/sql/sys_user.sql new file mode 100644 index 0000000..fa0520e --- /dev/null +++ b/sql/sys_user.sql @@ -0,0 +1,20 @@ +CREATE TABLE sys_user ( + user_id INT NOT NULL AUTO_INCREMENT, -- 用户id,主键 + username VARCHAR(64) NOT NULL, -- 用户名称 + nickname VARCHAR(64) NOT NULL, -- 用户昵称 + password VARCHAR(512) NOT NULL, -- 密码 + phone VARCHAR(11) NOT NULL, -- 手机号 + email VARCHAR(64) DEFAULT NULL, -- 邮箱 + sex TINYINT DEFAULT NULL COMMENT '性别 0男,1女,3未知', -- 性别 + avatar VARCHAR(512) DEFAULT NULL, -- 头像 + user_status TINYINT NOT NULL DEFAULT 0 COMMENT '用户状态 0可用,1禁用,默认为0', -- 用户状态 + remark VARCHAR(512) DEFAULT NULL, -- 备注 + dept_id INT NOT NULL, -- 部门id + tenant_id INT NOT NULL, -- 租户id + create_time TIMESTAMP NOT NULL, -- 创建时间 + creator_id INT NOT NULL, -- 创建者id + update_time TIMESTAMP NULL, -- 更新时间 + updater_id INT DEFAULT NULL, -- 更新者id + deleted TINYINT NOT NULL DEFAULT 0 COMMENT '删除标志 0未删除,1删除,默认为0', -- 删除标志 + PRIMARY KEY (user_id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户信息表'; \ No newline at end of file diff --git a/system-server/system-server-biz/src/main/resources/application-loc.yml b/system-server/system-server-biz/src/main/resources/application-loc.yml index 4698747..4ba6d73 100644 --- a/system-server/system-server-biz/src/main/resources/application-loc.yml +++ b/system-server/system-server-biz/src/main/resources/application-loc.yml @@ -2,7 +2,7 @@ spring: datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3306/system_database?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8 + url: jdbc:mysql://localhost:3310/system_database?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8 username: root password: 123456 data: -- Gitee From 5c9698658a7931cb43704ce9db75b0677d473cb1 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 2 Jan 2025 20:08:20 +0800 Subject: [PATCH 18/34] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=BD=91?= =?UTF-8?q?=E5=85=B3=E6=9C=8D=E5=8A=A1=E6=A8=A1=E5=9D=97-=20=E5=9C=A8=20po?= =?UTF-8?q?m.xml=20=E4=B8=AD=E6=B7=BB=E5=8A=A0=20gateway-server=20?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=20-=20=E5=88=9B=E5=BB=BA=20gateway-server=20?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E7=9A=84=E7=9B=AE=E5=BD=95=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E5=92=8C=E5=9F=BA=E6=9C=AC=E6=96=87=E4=BB=B6=20-=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=BD=91=E5=85=B3=E6=9C=8D=E5=8A=A1=E7=9A=84=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=EF=BC=8C=E5=8C=85=E6=8B=AC=20Spring=20Cloud=20Gateway?= =?UTF-8?q?=E3=80=81Nacos=20=E5=8F=91=E7=8E=B0=E5=92=8C=E8=B4=9F=E8=BD=BD?= =?UTF-8?q?=E5=9D=87=E8=A1=A1=20-=20=E7=BC=96=E5=86=99=E7=BD=91=E5=85=B3?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E7=9A=84=E5=90=AF=E5=8A=A8=E7=B1=BB=E5=92=8C?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gateway-server/pom.xml | 47 +++++++++++++++++++ .../GatewayServerApplication.java | 14 ++++++ .../src/main/resources/application.properties | 1 + .../GatewayServerApplicationTests.java | 13 +++++ pom.xml | 1 + 5 files changed, 76 insertions(+) create mode 100644 gateway-server/pom.xml create mode 100644 gateway-server/src/main/java/cn/edu/whut/gatewayserver/GatewayServerApplication.java create mode 100644 gateway-server/src/main/resources/application.properties create mode 100644 gateway-server/src/test/java/cn/edu/whut/gatewayserver/GatewayServerApplicationTests.java diff --git a/gateway-server/pom.xml b/gateway-server/pom.xml new file mode 100644 index 0000000..f9cfbb1 --- /dev/null +++ b/gateway-server/pom.xml @@ -0,0 +1,47 @@ + + + 4.0.0 + + cn.edu.whut + exam-question + 0.0.1-SNAPSHOT + + + + gateway-server + 0.0.1-SNAPSHOT + gateway-server + gateway-server + + + 17 + + + + + org.springframework.cloud + spring-cloud-starter-gateway + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/gateway-server/src/main/java/cn/edu/whut/gatewayserver/GatewayServerApplication.java b/gateway-server/src/main/java/cn/edu/whut/gatewayserver/GatewayServerApplication.java new file mode 100644 index 0000000..6ba7d2c --- /dev/null +++ b/gateway-server/src/main/java/cn/edu/whut/gatewayserver/GatewayServerApplication.java @@ -0,0 +1,14 @@ +package cn.edu.whut.gatewayserver; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + + +@SpringBootApplication +public class GatewayServerApplication { + + public static void main(String[] args) { + SpringApplication.run(GatewayServerApplication.class, args); + } + +} diff --git a/gateway-server/src/main/resources/application.properties b/gateway-server/src/main/resources/application.properties new file mode 100644 index 0000000..115d15a --- /dev/null +++ b/gateway-server/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=gateway-server diff --git a/gateway-server/src/test/java/cn/edu/whut/gatewayserver/GatewayServerApplicationTests.java b/gateway-server/src/test/java/cn/edu/whut/gatewayserver/GatewayServerApplicationTests.java new file mode 100644 index 0000000..b1b0780 --- /dev/null +++ b/gateway-server/src/test/java/cn/edu/whut/gatewayserver/GatewayServerApplicationTests.java @@ -0,0 +1,13 @@ +package cn.edu.whut.gatewayserver; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class GatewayServerApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/pom.xml b/pom.xml index ed9b95d..d0b15fe 100644 --- a/pom.xml +++ b/pom.xml @@ -31,6 +31,7 @@ common-api system-server + gateway-server -- Gitee From d04b4d231674d1e151cd9c41ac356de4acf334c0 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 2 Jan 2025 20:16:30 +0800 Subject: [PATCH 19/34] =?UTF-8?q?refactor(system-server):=20=E9=87=8D?= =?UTF-8?q?=E6=9E=84=20SysUserRes=20=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 Swagger 注解用于 API 文档生成 - 使用 Lombok 注解简化代码- 增加用户信息相关字段并添加相应注释 --- .../cn/edu/whut/system/vo/SysUserRes.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/SysUserRes.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/SysUserRes.java index 39c9960..4055cdd 100644 --- a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/SysUserRes.java +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/SysUserRes.java @@ -1,4 +1,59 @@ package cn.edu.whut.system.vo; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +@Schema(description = "系统服务 - 用户信息Response VO") public class SysUserRes { + + /** + * 用户id + */ + @Schema(description = "用户id", example = "1") + private Integer userId; + + /** + * 用户名 + */ + @Schema(description = "用户名", example = "admin") + private String username; + + /** + * 昵称 + */ + @Schema(description = "昵称", example = "管理员") + private String nickname; + + /** + * 手机号 + */ + @Schema(description = "手机号", example = "13888888888") + private String phone; + + /** + * 邮箱 + */ + @Schema(description = "邮箱", example = "admin@whut.edu.cn") + private String email; + + /** + * 性别 + */ + @Schema(description = "性别", example = "1", allowableValues = {"0", "1", "2"}) + private Integer sex; + + /** + * 状态 + */ + @Schema(description = "状态", example = "1", allowableValues = {"0", "1"}) + private Integer userStatus; + + /** + * 备注 + */ + @Schema(description = "备注", example = "管理员") + private String remark; + + } -- Gitee From ae710b657e73a0f286e1da06e5564d74d59b3026 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 2 Jan 2025 20:54:05 +0800 Subject: [PATCH 20/34] =?UTF-8?q?feat(system):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增用户管理相关的接口、控制器、服务实现和映射文件 - 创建用户信息的请求和响应对象 - 集成 MyBatis-Plus 作为持久层框架 - 使用 Swagger进行 API 文档化 --- gateway-server/pom.xml | 5 ++ .../system/controller/SysUserController.java | 18 +++++ .../edu/whut/system/mapper/SysUserMapper.java | 9 +++ .../whut/system/service/ISysUserService.java | 7 ++ .../service/impl/SysUserServiceImpl.java | 11 +++ .../edu/whut/system/vo/user/SysUserReq.java | 78 +++++++++++++++++++ .../whut/system/vo/{ => user}/SysUserRes.java | 3 +- 7 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 system-server/system-server-biz/src/main/java/cn/edu/whut/system/controller/SysUserController.java create mode 100644 system-server/system-server-biz/src/main/java/cn/edu/whut/system/mapper/SysUserMapper.java create mode 100644 system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/ISysUserService.java create mode 100644 system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java create mode 100644 system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/user/SysUserReq.java rename system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/{ => user}/SysUserRes.java (97%) diff --git a/gateway-server/pom.xml b/gateway-server/pom.xml index f9cfbb1..88dbc64 100644 --- a/gateway-server/pom.xml +++ b/gateway-server/pom.xml @@ -33,6 +33,11 @@ org.springframework.cloud spring-cloud-starter-loadbalancer + + org.springframework.boot + spring-boot-starter-test + test + diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/controller/SysUserController.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/controller/SysUserController.java new file mode 100644 index 0000000..13e8c7b --- /dev/null +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/controller/SysUserController.java @@ -0,0 +1,18 @@ +package cn.edu.whut.system.controller; + +import cn.edu.whut.system.service.ISysUserService; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "系统服务 - 用户管理") +@RequestMapping("user") +@RestController +@RequiredArgsConstructor +public class SysUserController { + + private final ISysUserService sysUserService; + + +} diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/mapper/SysUserMapper.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/mapper/SysUserMapper.java new file mode 100644 index 0000000..05dda7f --- /dev/null +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/mapper/SysUserMapper.java @@ -0,0 +1,9 @@ +package cn.edu.whut.system.mapper; + +import cn.edu.whut.system.repository.SysUserRepository; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface SysUserMapper extends BaseMapper { +} diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/ISysUserService.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/ISysUserService.java new file mode 100644 index 0000000..47966da --- /dev/null +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/ISysUserService.java @@ -0,0 +1,7 @@ +package cn.edu.whut.system.service; + +import cn.edu.whut.system.repository.SysUserRepository; +import com.baomidou.mybatisplus.extension.service.IService; + +public interface ISysUserService extends IService { +} diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java new file mode 100644 index 0000000..bb16997 --- /dev/null +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java @@ -0,0 +1,11 @@ +package cn.edu.whut.system.service.impl; + +import cn.edu.whut.system.mapper.SysUserMapper; +import cn.edu.whut.system.repository.SysUserRepository; +import cn.edu.whut.system.service.ISysUserService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +@Service +public class SysUserServiceImpl extends ServiceImpl implements ISysUserService { +} diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/user/SysUserReq.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/user/SysUserReq.java new file mode 100644 index 0000000..7f159b3 --- /dev/null +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/user/SysUserReq.java @@ -0,0 +1,78 @@ +package cn.edu.whut.system.vo.user; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.List; + +@Data +@Schema(description = "系统服务 - 用户信息Request VO") +public class SysUserReq { + + /** + * 用户名 + */ + @Schema(description = "用户名", example = "admin") + private String username; + + /** + * 昵称 + */ + @Schema(description = "昵称", example = "管理员") + private String nickname; + + /** + * 密码 + */ + @Schema(description = "密码", example = "123456") + private String password; + + /** + * 手机号 + */ + @Schema(description = "手机号", example = "13888888888") + private String phone; + + /** + * 邮箱 + */ + @Schema(description = "邮箱", example = "admin@whut.edu.cn") + private String email; + + /** + * 性别 + */ + @Schema(description = "性别", example = "1", allowableValues = {"0", "1", "2"}) + private Integer sex; + + /** + * 状态 + */ + @Schema(description = "状态", example = "1", allowableValues = {"0", "1"}) + private Integer userStatus; + + /** + * 备注 + */ + @Schema(description = "备注", example = "管理员") + private String remark; + + /** + * 部门id + */ + @Schema(description = "部门id", example = "1") + private Integer deptId; + + /** + * 租户id + */ + @Schema(description = "租户id", example = "1") + private Integer tenantId; + + /** + * 角色id列表 + */ + @Schema(description = "角色id列表", example = "[1,2]") + private List roleIdList; + +} diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/SysUserRes.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/user/SysUserRes.java similarity index 97% rename from system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/SysUserRes.java rename to system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/user/SysUserRes.java index 4055cdd..9c014ef 100644 --- a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/SysUserRes.java +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/user/SysUserRes.java @@ -1,4 +1,4 @@ -package cn.edu.whut.system.vo; +package cn.edu.whut.system.vo.user; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -55,5 +55,4 @@ public class SysUserRes { @Schema(description = "备注", example = "管理员") private String remark; - } -- Gitee From 2885dd5bb8ae34ebf3bb2d228f7f40e987aef332 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 2 Jan 2025 21:10:30 +0800 Subject: [PATCH 21/34] =?UTF-8?q?feat(user):=20=E6=96=B0=E5=A2=9E=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=88=9B=E5=BB=BA=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 ISysUserService 接口中添加 createUser 方法 - 在 SysUserController 中添加 createUser 控制器方法 - 在 SysUserServiceImpl 中实现 createUser 方法 - 更新 SysUserReq 类,将所有字段标记为必需 - 在 pom.xml 中添加 hutool-all 依赖 --- system-server/system-server-biz/pom.xml | 18 +++++------------- .../system/controller/SysUserController.java | 10 +++++++++- .../whut/system/service/ISysUserService.java | 9 +++++++++ .../service/impl/SysUserServiceImpl.java | 15 +++++++++++++++ .../cn/edu/whut/system/vo/user/SysUserReq.java | 12 ++++++------ 5 files changed, 44 insertions(+), 20 deletions(-) diff --git a/system-server/system-server-biz/pom.xml b/system-server/system-server-biz/pom.xml index 5fe6ba1..eb34272 100644 --- a/system-server/system-server-biz/pom.xml +++ b/system-server/system-server-biz/pom.xml @@ -15,19 +15,6 @@ 0.0.1-SNAPSHOT system-server-biz system-server-biz - - - - - - - - - - - - - 17 @@ -85,6 +72,11 @@ spring-cloud-starter-alibaba-nacos-discovery + + cn.hutool + hutool-all + + cn.edu.whut common-api diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/controller/SysUserController.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/controller/SysUserController.java index 13e8c7b..ac663e5 100644 --- a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/controller/SysUserController.java +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/controller/SysUserController.java @@ -1,8 +1,12 @@ package cn.edu.whut.system.controller; +import cn.edu.whut.commonapi.core.api.ApiResult; import cn.edu.whut.system.service.ISysUserService; +import cn.edu.whut.system.vo.user.SysUserReq; +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -14,5 +18,9 @@ public class SysUserController { private final ISysUserService sysUserService; - + @PostMapping("/create") + @Operation(summary = "新增用户") + public ApiResult createUser(SysUserReq sysUserReq) { + return ApiResult.success(sysUserService.createUser(sysUserReq)); + } } diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/ISysUserService.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/ISysUserService.java index 47966da..a73a9cb 100644 --- a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/ISysUserService.java +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/ISysUserService.java @@ -1,7 +1,16 @@ package cn.edu.whut.system.service; import cn.edu.whut.system.repository.SysUserRepository; +import cn.edu.whut.system.vo.user.SysUserReq; import com.baomidou.mybatisplus.extension.service.IService; public interface ISysUserService extends IService { + + /** + * 创建用户 + * + * @param sysUserReq 用户信息 + * @return 创建的用户id + */ + Integer createUser(SysUserReq sysUserReq); } diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java index bb16997..96aefe2 100644 --- a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java @@ -3,9 +3,24 @@ package cn.edu.whut.system.service.impl; import cn.edu.whut.system.mapper.SysUserMapper; import cn.edu.whut.system.repository.SysUserRepository; import cn.edu.whut.system.service.ISysUserService; +import cn.edu.whut.system.vo.user.SysUserReq; +import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; @Service public class SysUserServiceImpl extends ServiceImpl implements ISysUserService { + + /** + * 创建用户 + * + * @param sysUserReq 用户信息 + * @return 创建的用户id + */ + @Override + public Integer createUser(SysUserReq sysUserReq) { + SysUserRepository sysUserRepository = BeanUtil.toBean(sysUserReq, SysUserRepository.class); + baseMapper.insert(sysUserRepository); + return sysUserRepository.getUserId(); + } } diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/user/SysUserReq.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/user/SysUserReq.java index 7f159b3..079a9bc 100644 --- a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/user/SysUserReq.java +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/user/SysUserReq.java @@ -12,25 +12,25 @@ public class SysUserReq { /** * 用户名 */ - @Schema(description = "用户名", example = "admin") + @Schema(description = "用户名", example = "admin", requiredMode = Schema.RequiredMode.REQUIRED) private String username; /** * 昵称 */ - @Schema(description = "昵称", example = "管理员") + @Schema(description = "昵称", example = "管理员", requiredMode = Schema.RequiredMode.REQUIRED) private String nickname; /** * 密码 */ - @Schema(description = "密码", example = "123456") + @Schema(description = "密码", example = "123456", requiredMode = Schema.RequiredMode.REQUIRED) private String password; /** * 手机号 */ - @Schema(description = "手机号", example = "13888888888") + @Schema(description = "手机号", example = "13888888888", requiredMode = Schema.RequiredMode.REQUIRED) private String phone; /** @@ -48,7 +48,7 @@ public class SysUserReq { /** * 状态 */ - @Schema(description = "状态", example = "1", allowableValues = {"0", "1"}) + @Schema(description = "状态", example = "1", allowableValues = {"0", "1"}, requiredMode = Schema.RequiredMode.REQUIRED) private Integer userStatus; /** @@ -66,7 +66,7 @@ public class SysUserReq { /** * 租户id */ - @Schema(description = "租户id", example = "1") + @Schema(description = "租户id", example = "1", requiredMode = Schema.RequiredMode.REQUIRED) private Integer tenantId; /** -- Gitee From 97effa14a4059de4b7e2690af0e68290be5eafb1 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 2 Jan 2025 21:37:27 +0800 Subject: [PATCH 22/34] =?UTF-8?q?feat(system):=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD=E5=B9=B6?= =?UTF-8?q?=E4=BC=98=E5=8C=96=20API=20=E8=BF=94=E5=9B=9E=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增用户创建接口,增加租户 ID 和创建时间字段 -优化 API 返回结果,使用 ApiResult 封装响应数据 - 添加 Lombok 注解和 Jackson 配置,提高代码可读性和性能 --- .../java/cn/edu/whut/commonapi/core/api/ApiResult.java | 6 +++++- .../cn/edu/whut/system/controller/SysUserController.java | 9 ++++++--- .../cn/edu/whut/system/repository/SysUserRepository.java | 5 +++++ .../edu/whut/system/service/impl/SysUserServiceImpl.java | 5 +++++ .../main/java/cn/edu/whut/system/vo/user/SysUserRes.java | 6 ++++++ 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/common-api/src/main/java/cn/edu/whut/commonapi/core/api/ApiResult.java b/common-api/src/main/java/cn/edu/whut/commonapi/core/api/ApiResult.java index 3662b05..6e3803a 100644 --- a/common-api/src/main/java/cn/edu/whut/commonapi/core/api/ApiResult.java +++ b/common-api/src/main/java/cn/edu/whut/commonapi/core/api/ApiResult.java @@ -2,7 +2,9 @@ package cn.edu.whut.commonapi.core.api; import cn.edu.whut.commonapi.core.error.CommonErrorCodes; +import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; import java.io.Serial; import java.io.Serializable; @@ -12,6 +14,8 @@ import java.io.Serializable; * api接口返回信息封装 */ @Schema(description = "API接口返回信息封装") +@JsonInclude(JsonInclude.Include.NON_NULL) +@Data public class ApiResult implements Serializable { @Serial @@ -63,7 +67,7 @@ public class ApiResult implements Serializable { } public static ApiResult success(T data){ - return new ApiResult<>(data); + return (ApiResult) new ApiResult(data); } public static ApiResult error(int code, String msg){ diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/controller/SysUserController.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/controller/SysUserController.java index ac663e5..8aa3796 100644 --- a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/controller/SysUserController.java +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/controller/SysUserController.java @@ -7,9 +7,12 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import static cn.edu.whut.commonapi.core.api.ApiResult.success; + @Tag(name = "系统服务 - 用户管理") @RequestMapping("user") @RestController @@ -18,9 +21,9 @@ public class SysUserController { private final ISysUserService sysUserService; - @PostMapping("/create") + @PostMapping("v1/create") @Operation(summary = "新增用户") - public ApiResult createUser(SysUserReq sysUserReq) { - return ApiResult.success(sysUserService.createUser(sysUserReq)); + public ApiResult createUser(@RequestBody SysUserReq sysUserReq) { + return success(sysUserService.createUser(sysUserReq)); } } diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/repository/SysUserRepository.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/repository/SysUserRepository.java index 1cf5eb8..42fc29e 100644 --- a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/repository/SysUserRepository.java +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/repository/SysUserRepository.java @@ -67,4 +67,9 @@ public class SysUserRepository extends BaseEntity { * 部门 ID */ private Integer deptId; + + /** + * 租户 ID + */ + private Integer tenantId; } diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java index 96aefe2..b8e1eb2 100644 --- a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java @@ -8,6 +8,8 @@ import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; +import java.sql.Timestamp; + @Service public class SysUserServiceImpl extends ServiceImpl implements ISysUserService { @@ -20,6 +22,9 @@ public class SysUserServiceImpl extends ServiceImpl Date: Fri, 3 Jan 2025 22:42:23 +0800 Subject: [PATCH 23/34] =?UTF-8?q?feat(system):=20=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=97=B6=E5=A2=9E=E5=8A=A0=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E5=8A=A0=E5=AF=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 SysUserServiceImpl 类中添加 PasswordEncoder 依赖 - 在用户创建方法中对密码进行加密处理 - 新增 encodePassword 方法用于密码加密 --- .../service/impl/SysUserServiceImpl.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java index b8e1eb2..724a8a7 100644 --- a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java @@ -6,13 +6,20 @@ import cn.edu.whut.system.service.ISysUserService; import cn.edu.whut.system.vo.user.SysUserReq; import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import jakarta.annotation.Resource; +import lombok.RequiredArgsConstructor; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import java.sql.Timestamp; @Service +@RequiredArgsConstructor public class SysUserServiceImpl extends ServiceImpl implements ISysUserService { + @Resource + private PasswordEncoder passwordEncoder; + /** * 创建用户 * @@ -24,8 +31,18 @@ public class SysUserServiceImpl extends ServiceImpl Date: Fri, 3 Jan 2025 22:47:40 +0800 Subject: [PATCH 24/34] =?UTF-8?q?feat(gateway):=20=E6=B7=BB=E5=8A=A0=20Nac?= =?UTF-8?q?os=20=E9=85=8D=E7=BD=AE=E5=92=8C=E8=B7=AF=E7=94=B1=E8=A7=84?= =?UTF-8?q?=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 application.properties 文件 - 新增 application.yml 文件,配置如下: - Spring 应用名称为 gateway-server - Nacos 服务器地址为 127.0.0.1:8848 - 添加系统服务器路由规则,路径为 /api/common/system/** - 配置服务器端口为 8080 --- .../src/main/resources/application.properties | 1 - .../src/main/resources/application.yml | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) delete mode 100644 gateway-server/src/main/resources/application.properties create mode 100644 gateway-server/src/main/resources/application.yml diff --git a/gateway-server/src/main/resources/application.properties b/gateway-server/src/main/resources/application.properties deleted file mode 100644 index 115d15a..0000000 --- a/gateway-server/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=gateway-server diff --git a/gateway-server/src/main/resources/application.yml b/gateway-server/src/main/resources/application.yml new file mode 100644 index 0000000..6cc7e64 --- /dev/null +++ b/gateway-server/src/main/resources/application.yml @@ -0,0 +1,16 @@ +spring: + application: + name: gateway-server + cloud: + nacos: + server-addr: 127.0.0.1:8848 + gateway: + routes: + - id: system-server + uri: lb://system-server + predicates: + - Path=/api/common/system/** + + +server: + port: 8080 -- Gitee From 6e870bf6509f5f00b1d8be1b7d10f4442fba2956 Mon Sep 17 00:00:00 2001 From: Tom Date: Fri, 3 Jan 2025 23:05:10 +0800 Subject: [PATCH 25/34] =?UTF-8?q?feat(system):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=88=9B=E5=BB=BA=E5=92=8C=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E9=AA=8C=E8=AF=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 SysUserMapper 中添加 findByUsername 方法,用于查询用户 - 在 SysUserServiceImpl 中增加用户创建和更新时的验证逻辑 - 新增验证用户是否存在和用户名是否唯一的方法 --- .../edu/whut/system/mapper/SysUserMapper.java | 5 ++ .../service/impl/SysUserServiceImpl.java | 47 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/mapper/SysUserMapper.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/mapper/SysUserMapper.java index 05dda7f..11e5b5e 100644 --- a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/mapper/SysUserMapper.java +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/mapper/SysUserMapper.java @@ -1,9 +1,14 @@ package cn.edu.whut.system.mapper; import cn.edu.whut.system.repository.SysUserRepository; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; @Mapper public interface SysUserMapper extends BaseMapper { + + default SysUserRepository findByUsername(String username){ + return selectOne(new LambdaQueryWrapper().eq(SysUserRepository::getUsername, username)); + } } diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java index 724a8a7..dd421e5 100644 --- a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java @@ -5,6 +5,7 @@ import cn.edu.whut.system.repository.SysUserRepository; import cn.edu.whut.system.service.ISysUserService; import cn.edu.whut.system.vo.user.SysUserReq; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import jakarta.annotation.Resource; import lombok.RequiredArgsConstructor; @@ -29,6 +30,7 @@ public class SysUserServiceImpl extends ServiceImpl Date: Sat, 4 Jan 2025 00:05:08 +0800 Subject: [PATCH 26/34] =?UTF-8?q?refactor(gateway):=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=AB=AF=E5=8F=A3=E5=B9=B6=E9=87=8D=E6=9E=84=E5=8C=85=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 GatewayServerApplication 的包名从 cn.edu.whut.gatewayserver 改为 cn.edu.whut.gateway - 更新应用配置文件中的服务器端口为 8070 - 更新相关测试类的包名 - 新增 SecurityConfig 类用于配置密码加密 - 修改 SystemServerApplication 类,指定扫描基础包 - 更新 SysUserServiceImpl 中 PasswordEncoder 的注入方式 --- .../GatewayServerApplication.java | 2 +- gateway-server/src/main/resources/application.yml | 2 +- .../GatewayServerApplicationTests.java | 2 +- .../edu/whut/system/SystemServerApplication.java | 6 ++++-- .../cn/edu/whut/system/config/SecurityConfig.java | 15 +++++++++++++++ .../system/service/impl/SysUserServiceImpl.java | 3 +-- 6 files changed, 23 insertions(+), 7 deletions(-) rename gateway-server/src/main/java/cn/edu/whut/{gatewayserver => gateway}/GatewayServerApplication.java (89%) rename gateway-server/src/test/java/cn/edu/whut/{gatewayserver => gateway}/GatewayServerApplicationTests.java (84%) create mode 100644 system-server/system-server-biz/src/main/java/cn/edu/whut/system/config/SecurityConfig.java diff --git a/gateway-server/src/main/java/cn/edu/whut/gatewayserver/GatewayServerApplication.java b/gateway-server/src/main/java/cn/edu/whut/gateway/GatewayServerApplication.java similarity index 89% rename from gateway-server/src/main/java/cn/edu/whut/gatewayserver/GatewayServerApplication.java rename to gateway-server/src/main/java/cn/edu/whut/gateway/GatewayServerApplication.java index 6ba7d2c..f002d9f 100644 --- a/gateway-server/src/main/java/cn/edu/whut/gatewayserver/GatewayServerApplication.java +++ b/gateway-server/src/main/java/cn/edu/whut/gateway/GatewayServerApplication.java @@ -1,4 +1,4 @@ -package cn.edu.whut.gatewayserver; +package cn.edu.whut.gateway; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/gateway-server/src/main/resources/application.yml b/gateway-server/src/main/resources/application.yml index 6cc7e64..888ce7b 100644 --- a/gateway-server/src/main/resources/application.yml +++ b/gateway-server/src/main/resources/application.yml @@ -13,4 +13,4 @@ spring: server: - port: 8080 + port: 8070 diff --git a/gateway-server/src/test/java/cn/edu/whut/gatewayserver/GatewayServerApplicationTests.java b/gateway-server/src/test/java/cn/edu/whut/gateway/GatewayServerApplicationTests.java similarity index 84% rename from gateway-server/src/test/java/cn/edu/whut/gatewayserver/GatewayServerApplicationTests.java rename to gateway-server/src/test/java/cn/edu/whut/gateway/GatewayServerApplicationTests.java index b1b0780..903c32d 100644 --- a/gateway-server/src/test/java/cn/edu/whut/gatewayserver/GatewayServerApplicationTests.java +++ b/gateway-server/src/test/java/cn/edu/whut/gateway/GatewayServerApplicationTests.java @@ -1,4 +1,4 @@ -package cn.edu.whut.gatewayserver; +package cn.edu.whut.gateway; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/SystemServerApplication.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/SystemServerApplication.java index ebcb766..91e7cd9 100644 --- a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/SystemServerApplication.java +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/SystemServerApplication.java @@ -2,13 +2,15 @@ package cn.edu.whut.system; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; -@SpringBootApplication +@SpringBootApplication(scanBasePackages = "cn.edu.whut.system") public class SystemServerApplication { public static void main(String[] args) { SpringApplication.run(SystemServerApplication.class, args); } - } diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/config/SecurityConfig.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/config/SecurityConfig.java new file mode 100644 index 0000000..db121cf --- /dev/null +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/config/SecurityConfig.java @@ -0,0 +1,15 @@ +package cn.edu.whut.system.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; + +@Configuration +public class SecurityConfig { + + @Bean + public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } +} diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java index dd421e5..21b86a0 100644 --- a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/service/impl/SysUserServiceImpl.java @@ -18,8 +18,7 @@ import java.sql.Timestamp; @RequiredArgsConstructor public class SysUserServiceImpl extends ServiceImpl implements ISysUserService { - @Resource - private PasswordEncoder passwordEncoder; + private final PasswordEncoder passwordEncoder; /** * 创建用户 -- Gitee From 03f4dda499a10e8e06e8634df5e8e84db388afb9 Mon Sep 17 00:00:00 2001 From: Tom Date: Sat, 4 Jan 2025 01:32:50 +0800 Subject: [PATCH 27/34] =?UTF-8?q?feat(auth):=20=E6=B7=BB=E5=8A=A0=E8=AE=A4?= =?UTF-8?q?=E8=AF=81=E9=85=8D=E7=BD=AE=E5=B1=9E=E6=80=A7=E5=B9=B6=E9=9B=86?= =?UTF-8?q?=E6=88=90=20Lombok?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 AuthConfigurationProperties 类,用于配置网关认证 - 在 GatewayServerApplication 中启用配置属性 - 添加 Lombok 依赖,提高代码可读性和易维护性 --- gateway-server/pom.xml | 7 ++++++- .../gateway/GatewayServerApplication.java | 2 ++ .../config/AuthConfigurationProperties.java | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 gateway-server/src/main/java/cn/edu/whut/gateway/config/AuthConfigurationProperties.java diff --git a/gateway-server/pom.xml b/gateway-server/pom.xml index 88dbc64..53a1d0e 100644 --- a/gateway-server/pom.xml +++ b/gateway-server/pom.xml @@ -38,7 +38,12 @@ spring-boot-starter-test test - + + org.projectlombok + lombok + provided + + diff --git a/gateway-server/src/main/java/cn/edu/whut/gateway/GatewayServerApplication.java b/gateway-server/src/main/java/cn/edu/whut/gateway/GatewayServerApplication.java index f002d9f..a61336d 100644 --- a/gateway-server/src/main/java/cn/edu/whut/gateway/GatewayServerApplication.java +++ b/gateway-server/src/main/java/cn/edu/whut/gateway/GatewayServerApplication.java @@ -2,9 +2,11 @@ package cn.edu.whut.gateway; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; @SpringBootApplication +@EnableConfigurationProperties public class GatewayServerApplication { public static void main(String[] args) { diff --git a/gateway-server/src/main/java/cn/edu/whut/gateway/config/AuthConfigurationProperties.java b/gateway-server/src/main/java/cn/edu/whut/gateway/config/AuthConfigurationProperties.java new file mode 100644 index 0000000..8f96417 --- /dev/null +++ b/gateway-server/src/main/java/cn/edu/whut/gateway/config/AuthConfigurationProperties.java @@ -0,0 +1,19 @@ +package cn.edu.whut.gateway.config; + + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import java.util.List; + +@Data +@ConfigurationProperties(prefix = "gateway.auth") +@Configuration +public class AuthConfigurationProperties { + + private List includePaths; + + + private List excludePaths; +} -- Gitee From 016ceb5367092c1a5b4a9b3e9dc55ce36a90732f Mon Sep 17 00:00:00 2001 From: Tom Date: Sat, 4 Jan 2025 23:11:21 +0800 Subject: [PATCH 28/34] =?UTF-8?q?feat(gateway):=20=E6=B7=BB=E5=8A=A0=20JWT?= =?UTF-8?q?=20=E8=AE=A4=E8=AF=81=E7=9B=B8=E5=85=B3=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 JwtConfigurationProperties 类,用于配置 JWT相关属性 - 添加 SecurityConfig 类,用于生成 KeyPair 对象 - 配置文件中可设置 JWT 密钥库位置、密码、别名等信息 --- .../config/JwtConfigurationProperties.java | 20 +++++++++++++++ .../whut/gateway/config/SecurityConfig.java | 25 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 gateway-server/src/main/java/cn/edu/whut/gateway/config/JwtConfigurationProperties.java create mode 100644 gateway-server/src/main/java/cn/edu/whut/gateway/config/SecurityConfig.java diff --git a/gateway-server/src/main/java/cn/edu/whut/gateway/config/JwtConfigurationProperties.java b/gateway-server/src/main/java/cn/edu/whut/gateway/config/JwtConfigurationProperties.java new file mode 100644 index 0000000..91e6a5a --- /dev/null +++ b/gateway-server/src/main/java/cn/edu/whut/gateway/config/JwtConfigurationProperties.java @@ -0,0 +1,20 @@ +package cn.edu.whut.gateway.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.core.io.Resource; + +import java.time.Duration; + +@Data +@ConfigurationProperties(prefix = "gateway.jwt") +public class JwtConfigurationProperties { + + private Resource location; + + private String password; + + private String alias; + + private Duration tokenExpire = Duration.ofMinutes(10); +} diff --git a/gateway-server/src/main/java/cn/edu/whut/gateway/config/SecurityConfig.java b/gateway-server/src/main/java/cn/edu/whut/gateway/config/SecurityConfig.java new file mode 100644 index 0000000..7c1bc22 --- /dev/null +++ b/gateway-server/src/main/java/cn/edu/whut/gateway/config/SecurityConfig.java @@ -0,0 +1,25 @@ +package cn.edu.whut.gateway.config; + +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.rsa.crypto.KeyStoreKeyFactory; + +import java.security.KeyPair; + +@Configuration +@EnableConfigurationProperties(JwtConfigurationProperties.class) +public class SecurityConfig { + + @Bean + public KeyPair keyPair(JwtConfigurationProperties jwtConfigurationProperties){ + // 获取秘钥工厂 + KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory( + jwtConfigurationProperties.getLocation(), + jwtConfigurationProperties.getPassword().toCharArray()); + return keyStoreKeyFactory.getKeyPair( + jwtConfigurationProperties.getAlias(), + jwtConfigurationProperties.getPassword().toCharArray() + ); + } +} -- Gitee From ed987aa5cddc614776c57d176c8e1554ebe00d9b Mon Sep 17 00:00:00 2001 From: Tom Date: Sat, 4 Jan 2025 23:27:30 +0800 Subject: [PATCH 29/34] =?UTF-8?q?feat(gateway-server):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20JWT=E8=AE=A4=E8=AF=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 application.yml 中配置 JWT 相关参数- 设置密钥别名、密钥库路径和密码 -定义 token 过期时间- 添加不需要认证的路径 --- .../src/main/resources/application.yml | 10 +++++++++- .../src/main/resources/examquestion.jks | Bin 0 -> 2756 bytes 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 gateway-server/src/main/resources/examquestion.jks diff --git a/gateway-server/src/main/resources/application.yml b/gateway-server/src/main/resources/application.yml index 888ce7b..97ed114 100644 --- a/gateway-server/src/main/resources/application.yml +++ b/gateway-server/src/main/resources/application.yml @@ -11,6 +11,14 @@ spring: predicates: - Path=/api/common/system/** - server: port: 8070 +gateway: + jwt: + alias: examquestion # 密钥别名 + location: classpath:examquestion.jks # 密钥库路径 + password: GYdx@2024.! # 密钥库密码 + tokenExpire: 30m # token过期时间 + auth: + exclude-paths: # 不需要认证的路径 + - /api/common/system/login diff --git a/gateway-server/src/main/resources/examquestion.jks b/gateway-server/src/main/resources/examquestion.jks new file mode 100644 index 0000000000000000000000000000000000000000..3492c78d6af4653f9140363ca9f5819eee3d6da0 GIT binary patch literal 2756 zcma)8XH=655=}xVL3#~JM?~7=3lIoWgg__~Kzdb*6e*D=0uR9uk)qO(P$e{_iXbh3 zp&1ZVAheYh@QH{hT|}fUdv=fS?62J)b7tn=x$|%C8Gyjr1pzYv1Xe#Lm|VPZ{4P6~ z8B8LuIztJp_9w74Kwxb9FN(1mN??3?0+*gd5!0#vsMuJ+5E6k=_XN}eynibg*#SoY z^>@n#$V2(03RvFtwOiF0%;!@SySVhvbBR|&ATnGKusFcR#PaWr5Evr}5MhG3#T$dY z7@%M|C|73a4K+`xx=TIzqHTgWV4uN+Esnzb)yk~LC@YZfY0 zqjFGh+R^&Y5*EdlSU7zOrlVNHE`9ZNLH-}nK!v}nQiQ%!CpN-47S(Wex9bBk>EL@N zsB-B*VfUaL^mF0)_wv#&obKF|tZMzj;Ys2Z(Teoj3>TI~ft#bkaBY4N+v z$;XM_y50t{oMBc_AKs2`vC!>XO2&Bl()9^XOFeCyngpmA!6ASe{4@yO7iYivm3*)e z8RnEK0lF&G+Ao=SaHL81sb-O<5A923|FUGl6~oFtloX+2?ZTB26(bj?NG5`N*twd+ z8~XX=Qrf+dHO`mL!n5ZW!Lr?x)U0S%jNWWGNksQzQMiS6#dTfRw}B0NJMHhShsqsb za)$8?uWj)SI|Pc#9GH9A)1l+x!=%Cu4z0Rzmi_$PWA!&Jo6I-ex7)97iSK?H%;-uv z^Kw$?m&rF<`JO@d9(>~Ll8M{JL^s%RL8pFuV}YIF zUZ=HW+?0)A)=&M-f-Md)m33<3t>|4$R=*Z%lzXq8PD%S#0OZ%^^Db(sAW$m~5JFNw?zY^{SyM`i(4XP9#8jbByk%_eQr`+0}#nwtq zUIAm(sv(bIf(C<3OhEaO!Tq}(xbT~MwQGM()3Pu>9s84B2E(j!mh5ekuQ(Ci93dNa zc@tT6LbaH3^TYBo$IFmJfd$L=NLBxOOy)<47Rl}W`+N+g3x{o2ZA;A7u0Pu}zVL#Z z#PTI5O_h+kF1Tq~j6^EbxzqryzXmG_Ie8j))E}6S@L+wi3vFAJER{Lu#; z(m3rfd$mc@dAxnrO4a;U+q=$AayG59I!z%@5xL^7E^a&NoFLb<(dwoukqGJJ`M&Nk z^@JImD!-a}hq;_e)sBkwW?(5UeNq6YYSvzydBe`zN1fg?^J^@o1kP=UJSz$9SHc$B z$tv~pOPP5chW*96J!p5BSvlW5)+>|2+^KZi)Di(VB2Nm_z%Xn`y_jAg z*G6@X5-xzJzC+2SwWez2?O021`M8&lYHvlMg$oqLoQ%i1GWppo90ejxh4((y)5^A$ z@3c0MFp3UlT?tYnO<%ovTdFkSk2PME=ATdL?ycc2vV0 zDJ&W>eJq0UMPLD$-*yS(L!1_cgSy2?10 zeKJUDTSb#Q|NpVi{H|w3>=Of6YtoCA2K;4>~?>J$Ie;9A!`;nz@*4Df1=R*U8%Qdg7FQ9_#GD&(T9~ z%rtRpl*(iw&y8FOkY)BK* zceftb{@HXp4}@?izuJ%jrAYV&T|19?EkLg;rHsqNC(=iOIB1;~=^G~*^8?!fyP;5& ze{+QvgckI0e($4Gl~)XRy(fSbF>=lkXF^X1VB+tOAIofABM%6|#2%(`9e6mHVD9MG z-ZyH+`o4Gab(->;@|9nfO=p`4zjh2cqc>1z{){Cziv@iFtHrVSe8plQ5m0N7_b*fv zZ40%yU5)7N$@TR%l%B1<{zaqcj4q-cNnkN@;KV*8MTpjI8w=*GORcMz>)MyS1GQ+fU;TaO@?OXLBEL!<=n0 zzNB&nu4jo;*vs;?qM*2+ZKLeJSUTIs;3@;F)>F$YhfOIctH{Y7@F@_mwp|66W*0gJv}o_j4gb*K|TsSwH^Vfwk) zUBh>YjW{!^)8}c^^bs%v5CHq{&kh1+1VP0UD--KHpL*cwtmn;5^d<0#feri*F>#3K kEy^%9NAL=ikMmff)_Nu8NHW`- Date: Sat, 4 Jan 2025 23:53:48 +0800 Subject: [PATCH 30/34] =?UTF-8?q?feat(system-server):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=99=BB=E5=BD=95=E6=8E=A5=E5=8F=A3=E5=92=8C?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 SysAuthController 控制器,包含用户登录接口 - 添加 SysAuthUserLoginReq 请求模型,用于用户登录 - 实现 SysAuthUserLoginRes 响应模型,用于用户登录成功后的返回信息 --- .../system/controller/SysAuthController.java | 27 ++++++++++++++ .../system/vo/auth/SysAuthUserLoginReq.java | 23 ++++++++++++ .../system/vo/auth/SysAuthUserLoginRes.java | 37 +++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 system-server/system-server-biz/src/main/java/cn/edu/whut/system/controller/SysAuthController.java create mode 100644 system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/auth/SysAuthUserLoginReq.java create mode 100644 system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/auth/SysAuthUserLoginRes.java diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/controller/SysAuthController.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/controller/SysAuthController.java new file mode 100644 index 0000000..9fc4c6a --- /dev/null +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/controller/SysAuthController.java @@ -0,0 +1,27 @@ +package cn.edu.whut.system.controller; + +import cn.edu.whut.commonapi.core.api.ApiResult; +import cn.edu.whut.system.vo.auth.SysAuthUserLoginReq; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import static cn.edu.whut.commonapi.core.api.ApiResult.success; + + +@Tag(name = "系统服务 - 用户验证") +@RequestMapping("auth") +@RestController +@RequiredArgsConstructor +public class SysAuthController { + + @PostMapping("v1/login") + @Operation(summary = "用户登录") + public ApiResult login(@RequestBody SysAuthUserLoginReq sysAuthUserLoginReq){ + return success(); + } +} diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/auth/SysAuthUserLoginReq.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/auth/SysAuthUserLoginReq.java new file mode 100644 index 0000000..5b04020 --- /dev/null +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/auth/SysAuthUserLoginReq.java @@ -0,0 +1,23 @@ +package cn.edu.whut.system.vo.auth; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.Pattern; +import jakarta.validation.constraints.Size; +import lombok.Data; + +@Data +@Schema(description = "系统服务 - 账号密码登录 Request VO") +public class SysAuthUserLoginReq { + + @Schema(description = "账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudaoyuanma") + @NotEmpty(message = "登录账号不能为空") + @Size(min = 4, max = 16, message = "账号长度为 4-16 位") + @Pattern(regexp = "^[A-Za-z0-9]+$", message = "账号格式为数字以及字母") + private String username; + + @Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "buzhidao") + @NotEmpty(message = "密码不能为空") + @Size(min = 8, max = 16, message = "密码长度为 8-16 位") + private String password; +} diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/auth/SysAuthUserLoginRes.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/auth/SysAuthUserLoginRes.java new file mode 100644 index 0000000..c421548 --- /dev/null +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/vo/auth/SysAuthUserLoginRes.java @@ -0,0 +1,37 @@ +package cn.edu.whut.system.vo.auth; + +import cn.edu.whut.system.vo.user.SysUserRes; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.time.LocalDateTime; + +@Schema(description = "系统服务 - 账号密码登录 Response VO") +@Data +public class SysAuthUserLoginRes implements Serializable { + + /** + * 访问令牌 + */ + @Schema(description = "访问令牌", requiredMode = Schema.RequiredMode.REQUIRED, example = "happy") + private String accessToken; + + /** + * 刷新令牌 + */ + @Schema(description = "刷新令牌", requiredMode = Schema.RequiredMode.REQUIRED, example = "nice") + private String refreshToken; + + /** + * 过期时间 + */ + @Schema(description = "过期时间", requiredMode = Schema.RequiredMode.REQUIRED) + private LocalDateTime expiresTime; + + /** + * 用户信息 + */ + @Schema(description = "用户信息", requiredMode = Schema.RequiredMode.REQUIRED) + private SysUserRes user; +} -- Gitee From 1197fe12d9130ffaae6a590be57985e0ae1518f9 Mon Sep 17 00:00:00 2001 From: Tom Date: Sat, 4 Jan 2025 23:53:57 +0800 Subject: [PATCH 31/34] =?UTF-8?q?feat(common-api):=20=E6=B7=BB=E5=8A=A0=20?= =?UTF-8?q?ApiResult=20=E6=88=90=E5=8A=9F=E5=9B=9E=E8=B0=83=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 ApiResult 类中新增 success() 静态方法,用于创建成功回调的 ApiResult 对象 - 该方法返回一个带有默认成功状态码和消息的 ApiResult 实例 --- .../main/java/cn/edu/whut/commonapi/core/api/ApiResult.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common-api/src/main/java/cn/edu/whut/commonapi/core/api/ApiResult.java b/common-api/src/main/java/cn/edu/whut/commonapi/core/api/ApiResult.java index 6e3803a..c8c8f9d 100644 --- a/common-api/src/main/java/cn/edu/whut/commonapi/core/api/ApiResult.java +++ b/common-api/src/main/java/cn/edu/whut/commonapi/core/api/ApiResult.java @@ -70,6 +70,10 @@ public class ApiResult implements Serializable { return (ApiResult) new ApiResult(data); } + public static ApiResult success(){ + return (ApiResult) new ApiResult(CommonErrorCodes.SUCCESS.code(), CommonErrorCodes.SUCCESS.msg()); + } + public static ApiResult error(int code, String msg){ return new ApiResult<>(code, msg); } -- Gitee From b69631943e12bfe12d615332799389fa9e1c3f75 Mon Sep 17 00:00:00 2001 From: Tom Date: Sun, 5 Jan 2025 10:33:59 +0800 Subject: [PATCH 32/34] =?UTF-8?q?refactor(gateway):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E7=BD=91=E5=85=B3=E6=9C=8D=E5=8A=A1=E5=99=A8=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 AuthConfigurationProperties 和 JwtConfigurationProperties 类移动到 config/properties 包中- 新增 AuthGlobalFilter 和 JwtUtil 类 - 更新 SecurityConfig 类以使用新的 JwtConfigurationProperties - 修改 SysAuthController 中的 login 方法返回类型 --- .../whut/gateway/config/SecurityConfig.java | 1 + .../AuthConfigurationProperties.java | 2 +- .../JwtConfigurationProperties.java | 2 +- .../whut/gateway/filter/AuthGlobalFilter.java | 30 +++++++++++++++++++ .../cn/edu/whut/gateway/util/JwtUtil.java | 7 +++++ .../system/controller/SysAuthController.java | 3 +- 6 files changed, 42 insertions(+), 3 deletions(-) rename gateway-server/src/main/java/cn/edu/whut/gateway/config/{ => properties}/AuthConfigurationProperties.java (89%) rename gateway-server/src/main/java/cn/edu/whut/gateway/config/{ => properties}/JwtConfigurationProperties.java (89%) create mode 100644 gateway-server/src/main/java/cn/edu/whut/gateway/filter/AuthGlobalFilter.java create mode 100644 gateway-server/src/main/java/cn/edu/whut/gateway/util/JwtUtil.java diff --git a/gateway-server/src/main/java/cn/edu/whut/gateway/config/SecurityConfig.java b/gateway-server/src/main/java/cn/edu/whut/gateway/config/SecurityConfig.java index 7c1bc22..2f95764 100644 --- a/gateway-server/src/main/java/cn/edu/whut/gateway/config/SecurityConfig.java +++ b/gateway-server/src/main/java/cn/edu/whut/gateway/config/SecurityConfig.java @@ -1,5 +1,6 @@ package cn.edu.whut.gateway.config; +import cn.edu.whut.gateway.config.properties.JwtConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/gateway-server/src/main/java/cn/edu/whut/gateway/config/AuthConfigurationProperties.java b/gateway-server/src/main/java/cn/edu/whut/gateway/config/properties/AuthConfigurationProperties.java similarity index 89% rename from gateway-server/src/main/java/cn/edu/whut/gateway/config/AuthConfigurationProperties.java rename to gateway-server/src/main/java/cn/edu/whut/gateway/config/properties/AuthConfigurationProperties.java index 8f96417..3eb4119 100644 --- a/gateway-server/src/main/java/cn/edu/whut/gateway/config/AuthConfigurationProperties.java +++ b/gateway-server/src/main/java/cn/edu/whut/gateway/config/properties/AuthConfigurationProperties.java @@ -1,4 +1,4 @@ -package cn.edu.whut.gateway.config; +package cn.edu.whut.gateway.config.properties; import lombok.Data; diff --git a/gateway-server/src/main/java/cn/edu/whut/gateway/config/JwtConfigurationProperties.java b/gateway-server/src/main/java/cn/edu/whut/gateway/config/properties/JwtConfigurationProperties.java similarity index 89% rename from gateway-server/src/main/java/cn/edu/whut/gateway/config/JwtConfigurationProperties.java rename to gateway-server/src/main/java/cn/edu/whut/gateway/config/properties/JwtConfigurationProperties.java index 91e6a5a..44cece7 100644 --- a/gateway-server/src/main/java/cn/edu/whut/gateway/config/JwtConfigurationProperties.java +++ b/gateway-server/src/main/java/cn/edu/whut/gateway/config/properties/JwtConfigurationProperties.java @@ -1,4 +1,4 @@ -package cn.edu.whut.gateway.config; +package cn.edu.whut.gateway.config.properties; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; diff --git a/gateway-server/src/main/java/cn/edu/whut/gateway/filter/AuthGlobalFilter.java b/gateway-server/src/main/java/cn/edu/whut/gateway/filter/AuthGlobalFilter.java new file mode 100644 index 0000000..1e89069 --- /dev/null +++ b/gateway-server/src/main/java/cn/edu/whut/gateway/filter/AuthGlobalFilter.java @@ -0,0 +1,30 @@ +package cn.edu.whut.gateway.filter; + +import cn.edu.whut.gateway.config.properties.AuthConfigurationProperties; +import cn.edu.whut.gateway.util.JwtUtil; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cloud.gateway.filter.GatewayFilterChain; +import org.springframework.cloud.gateway.filter.GlobalFilter; +import org.springframework.core.Ordered; +import org.springframework.stereotype.Component; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Mono; + +@Component +@EnableConfigurationProperties(AuthConfigurationProperties.class) +@RequiredArgsConstructor +public class AuthGlobalFilter implements GlobalFilter, Ordered { + + private final JwtUtil jwtUtil; + + @Override + public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { + return null; + } + + @Override + public int getOrder() { + return 0; + } +} diff --git a/gateway-server/src/main/java/cn/edu/whut/gateway/util/JwtUtil.java b/gateway-server/src/main/java/cn/edu/whut/gateway/util/JwtUtil.java new file mode 100644 index 0000000..7d41726 --- /dev/null +++ b/gateway-server/src/main/java/cn/edu/whut/gateway/util/JwtUtil.java @@ -0,0 +1,7 @@ +package cn.edu.whut.gateway.util; + +import org.springframework.stereotype.Component; + +@Component +public class JwtUtil { +} diff --git a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/controller/SysAuthController.java b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/controller/SysAuthController.java index 9fc4c6a..20913d7 100644 --- a/system-server/system-server-biz/src/main/java/cn/edu/whut/system/controller/SysAuthController.java +++ b/system-server/system-server-biz/src/main/java/cn/edu/whut/system/controller/SysAuthController.java @@ -2,6 +2,7 @@ package cn.edu.whut.system.controller; import cn.edu.whut.commonapi.core.api.ApiResult; import cn.edu.whut.system.vo.auth.SysAuthUserLoginReq; +import cn.edu.whut.system.vo.auth.SysAuthUserLoginRes; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; @@ -21,7 +22,7 @@ public class SysAuthController { @PostMapping("v1/login") @Operation(summary = "用户登录") - public ApiResult login(@RequestBody SysAuthUserLoginReq sysAuthUserLoginReq){ + public ApiResult login(@RequestBody SysAuthUserLoginReq sysAuthUserLoginReq){ return success(); } } -- Gitee From 3d9498b2b6c64184e0624bd043ae03753dda8d2a Mon Sep 17 00:00:00 2001 From: Tom Date: Sun, 5 Jan 2025 11:02:34 +0800 Subject: [PATCH 33/34] =?UTF-8?q?feat(gateway):=20token=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gateway-server/pom.xml | 4 +++ .../cn/edu/whut/gateway/util/JwtUtil.java | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/gateway-server/pom.xml b/gateway-server/pom.xml index 53a1d0e..0ca4adb 100644 --- a/gateway-server/pom.xml +++ b/gateway-server/pom.xml @@ -43,6 +43,10 @@ lombok provided + + cn.hutool + hutool-all + diff --git a/gateway-server/src/main/java/cn/edu/whut/gateway/util/JwtUtil.java b/gateway-server/src/main/java/cn/edu/whut/gateway/util/JwtUtil.java index 7d41726..1829272 100644 --- a/gateway-server/src/main/java/cn/edu/whut/gateway/util/JwtUtil.java +++ b/gateway-server/src/main/java/cn/edu/whut/gateway/util/JwtUtil.java @@ -1,7 +1,41 @@ package cn.edu.whut.gateway.util; +import cn.hutool.jwt.JWT; +import cn.hutool.jwt.signers.JWTSigner; +import cn.hutool.jwt.signers.JWTSignerUtil; import org.springframework.stereotype.Component; +import java.security.KeyPair; +import java.time.Duration; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + @Component public class JwtUtil { + + private final JWTSigner jwtSigner; + + public JwtUtil(KeyPair keyPair){ + this.jwtSigner = JWTSignerUtil.createSigner("rs256", keyPair); + } + + /** + * 创建token + * + * @param userId 用户id + * @param tenantId 租户id + * @param ttl token过期时间 + * @return token + */ + public String createToken(Integer userId, String tenantId, Duration ttl){ + Map payloadData = new HashMap<>(); + payloadData.put("userId", userId); + payloadData.put("tenantId", tenantId); + return JWT.create() + .setPayload("user", payloadData) + .setExpiresAt(new Date(System.currentTimeMillis() + ttl.toMillis())) + .setSigner(jwtSigner) + .sign(); + } } -- Gitee From 4beefa25f07d493fbaddb02432d840c02de84ba5 Mon Sep 17 00:00:00 2001 From: Tom Date: Sun, 5 Jan 2025 13:33:51 +0800 Subject: [PATCH 34/34] =?UTF-8?q?feat(gateway):=20=E6=B7=BB=E5=8A=A0=20tok?= =?UTF-8?q?en=20=E8=A7=A3=E6=9E=90=E5=8A=9F=E8=83=BD=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E7=9B=B8=E5=85=B3=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 CommonException 类作为自定义异常的基础类 - 在 JwtUtil 类中添加 parseToken 方法用于解析 token - 创建 UnauthorizedException 类用于处理未授权错误 - 更新 gateway-server 项目的 pom.xml,添加 common-api 依赖 --- .../commonapi/core/error/CommonException.java | 24 ++++++++++++ gateway-server/pom.xml | 8 +++- .../gateway/error/UnauthorizedException.java | 18 +++++++++ .../cn/edu/whut/gateway/util/JwtUtil.java | 38 ++++++++++++++++++- 4 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 common-api/src/main/java/cn/edu/whut/commonapi/core/error/CommonException.java create mode 100644 gateway-server/src/main/java/cn/edu/whut/gateway/error/UnauthorizedException.java diff --git a/common-api/src/main/java/cn/edu/whut/commonapi/core/error/CommonException.java b/common-api/src/main/java/cn/edu/whut/commonapi/core/error/CommonException.java new file mode 100644 index 0000000..a502d8e --- /dev/null +++ b/common-api/src/main/java/cn/edu/whut/commonapi/core/error/CommonException.java @@ -0,0 +1,24 @@ +package cn.edu.whut.commonapi.core.error; + +import lombok.Getter; + +@Getter +public class CommonException extends RuntimeException{ + + private int code; + + public CommonException(String message, int code) { + super(message); + this.code = code; + } + + public CommonException(String message, Throwable cause, int code) { + super(message, cause); + this.code = code; + } + + public CommonException(Throwable cause, int code) { + super(cause); + this.code = code; + } +} diff --git a/gateway-server/pom.xml b/gateway-server/pom.xml index 0ca4adb..4be4e7e 100644 --- a/gateway-server/pom.xml +++ b/gateway-server/pom.xml @@ -47,7 +47,13 @@ cn.hutool hutool-all - + + cn.edu.whut + common-api + 0.0.1-SNAPSHOT + compile + + diff --git a/gateway-server/src/main/java/cn/edu/whut/gateway/error/UnauthorizedException.java b/gateway-server/src/main/java/cn/edu/whut/gateway/error/UnauthorizedException.java new file mode 100644 index 0000000..50a9237 --- /dev/null +++ b/gateway-server/src/main/java/cn/edu/whut/gateway/error/UnauthorizedException.java @@ -0,0 +1,18 @@ +package cn.edu.whut.gateway.error; + +import cn.edu.whut.commonapi.core.error.CommonException; + +public class UnauthorizedException extends CommonException { + + public UnauthorizedException(String message) { + super(message, 401); + } + + public UnauthorizedException(String message, Throwable cause) { + super(message, cause, 401); + } + + public UnauthorizedException(Throwable cause) { + super(cause, 401); + } +} diff --git a/gateway-server/src/main/java/cn/edu/whut/gateway/util/JwtUtil.java b/gateway-server/src/main/java/cn/edu/whut/gateway/util/JwtUtil.java index 1829272..e13cd38 100644 --- a/gateway-server/src/main/java/cn/edu/whut/gateway/util/JwtUtil.java +++ b/gateway-server/src/main/java/cn/edu/whut/gateway/util/JwtUtil.java @@ -1,6 +1,8 @@ package cn.edu.whut.gateway.util; +import cn.edu.whut.gateway.error.UnauthorizedException; import cn.hutool.jwt.JWT; +import cn.hutool.jwt.JWTValidator; import cn.hutool.jwt.signers.JWTSigner; import cn.hutool.jwt.signers.JWTSignerUtil; import org.springframework.stereotype.Component; @@ -28,8 +30,8 @@ public class JwtUtil { * @param ttl token过期时间 * @return token */ - public String createToken(Integer userId, String tenantId, Duration ttl){ - Map payloadData = new HashMap<>(); + public String createToken(Integer userId, Integer tenantId, Duration ttl){ + Map payloadData = new HashMap<>(); payloadData.put("userId", userId); payloadData.put("tenantId", tenantId); return JWT.create() @@ -38,4 +40,36 @@ public class JwtUtil { .setSigner(jwtSigner) .sign(); } + + /** + * 解析token + * @param token token + * @return 用户id和租户id + */ + public Map parseToken(String token) { + if (token == null) { + throw new UnauthorizedException("用户未登录"); + } + JWT jwt; + try { + jwt = JWT.of(token).setSigner(jwtSigner); + } catch (Exception e) { + throw new UnauthorizedException("无效的token", e); + } + // 验证token是否有效 + if (!jwt.verify()) { + throw new UnauthorizedException("无效的token"); + } + try { + JWTValidator.of(jwt).validateDate(); + } catch (Exception e) { + throw new UnauthorizedException("token已过期"); + } + Object userPayloadData = jwt.getPayload("user"); + if (userPayloadData == null) { + throw new UnauthorizedException("无效的token"); + }else{ + return (Map) jwt.getPayload("user"); + } + } } -- Gitee