From 28396b1bcf7be814fd27f7931b8cb0c94c7dc48d Mon Sep 17 00:00:00 2001 From: jiangdingxuan Date: Mon, 8 Jan 2024 09:12:54 +0800 Subject: [PATCH] init commit --- .editorconfig | 18 + .gitignore | 50 +++ LICENSE | 20 + README.md | 89 +++++ common/pom.xml | 20 + pom.xml | 378 ++++++++++++++++++ service/pom.xml | 146 +++++++ service/system/pom.xml | 21 + .../java/net/rzdata/demo/DemoApplication.java | 12 + .../src/main/resources/config/application.yml | 21 + 10 files changed, 775 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 common/pom.xml create mode 100644 pom.xml create mode 100644 service/pom.xml create mode 100644 service/system/pom.xml create mode 100644 service/system/src/main/java/net/rzdata/demo/DemoApplication.java create mode 100644 service/system/src/main/resources/config/application.yml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..25b312e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +# http://editorconfig.org +root = true + +# 空格替代Tab缩进在各种编辑工具下效果一致 +[*] +indent_style = space +indent_size = 4 +charset = utf-8 +end_of_line = lf +trim_trailing_whitespace = true +insert_final_newline = true + +[*.{json,yml,yaml}] +indent_size = 2 + +[*.md] +insert_final_newline = false +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2a6e107 --- /dev/null +++ b/.gitignore @@ -0,0 +1,50 @@ +###################################################################### +# Build Tools + +.gradle +/build/ +!gradle/wrapper/gradle-wrapper.jar + +target/ +!.mvn/wrapper/maven-wrapper.jar + +###################################################################### +# IDE + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### JRebel ### +rebel.xml + +### NetBeans ### +nbproject/private/ +build/* +nbbuild/ +nbdist/ +.nb-gradle/ + +###################################################################### +# Others +*.log +*.xml.versionsBackup +*.swp + +!*/build/*.java +!*/build/*.html +!*/build/*.xml + +.flattened-pom.xml +.gitee +application-local.yml diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3311774 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2019 bis + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..9814cb8 --- /dev/null +++ b/README.md @@ -0,0 +1,89 @@ + +## 代码架构 + +```mermaid +flowchart LR + demo-service-aaa-->demo-common + demo-service-bbb-->demo-common + demo-service-bbb-->demo-sdk + demo-common-->demo-core + demo-sdk--> demo-core +``` + +- demo + - demo-core + - demo-sdk + - demo-common + - demo-service + - demo-service-aaa + - net.rzdata + - AaaApplication + - aaa + - xxx + - XxxController + - XxxService + - XxxRepository + - service + - IXxxService4Yyy + - IXxxService4Zzz + - mapper + - XxxMapper + - domain + - Xxx + - XxxAddReq + - XxxModifyReq + - yyy + - zzz + - demo-service-bbb + +### 工程结构 + +demo 是一个系统的顶级POM,其 parent 为公司的顶级POM,对系统内部的依赖进行管理。 + +demo-service 下是该系统的全部后端服务,每一个子模块对应一个后端服务。最终发布为一个 Docker 镜像。 +demo-service 的 POM 中添加所有服务的公共依赖,如 spring-boot-starter-web、mybatis-spring-boot-starter 等。 + +demo-common 中为该系统内服务的公共配置、公共接口、异常定义等。 + +demo-sdk 是各服务之间相互调用的 SDK,最终发布为一个 jar 包。 +当 aaa 服务需要调用 bbb 服务时,则引入 demo-sdk 依赖,并使用其中的 BbbClient 进行调用。 + +demo-core 包含本系统内使用的 util 和服务间通信模型 DTO。 + +### 包结构 + +XxxService 是该包的逻辑组织中枢。 +其方法分为 3 部分 —— protected 方法,用于向 XxxController 提供服务;public 方法,是对 service 包中的接口的实现。private 方法,对 protected 方法和 public 方法提供服务。 +如果要依赖其他包的服务,只能注入对应的接口(如 yyy 包需要依赖 xxx 包的服务,则在 YyyService 中注入 IXxxService4Yyy)。IXxxService4Yyy 向其他包提供有限的方法,由 XxxService 实现。 + +XxxController 是向前端提供服务的门面。通常只依赖于 XxxService。 + +domain.Xxx 是该包的核心模型,也是唯一的充血模型。Service 是基于核心模型进行逻辑组织。 + +domain.XxxReq、domain.XxxResp 对应 Controller 中不同请求和响应的返回模型。 +大部分请求是不需要核心模型的全部字段的,比如新增请求不需要id,修改请求有部分字段不可变,不同的请求需要不同的返回字段等,这时可以定义 XxxReq、XxxResp 来实现,并在 Controller 层转换为核心模型。有些请求需要用到完整的核心模型的结构,则可以省略这一步骤。 + +mapper 包下的类均继承自 mybatis-plus 的 BaseMapper,每一个类对应一张数据库表。 +XxxRepository 是对 XxxMapper 的封装。 + +## 部署架构 + +## 如何运行 + +### 本地运行 + +复制服务配置文件 application.yml 中的可配置项到 application-local.yml。 + +在 application-local.yml 中修改配置,其中的配置项会覆盖 application.yml,但不会提交到 git。 + +### 项目发布 + +通过 jib-maven-plugin 发布 Docker 镜像到镜像仓库。 + +### 线上部署 + +将 opentelemetry-javaagent.jar 映射到容器中的 /opt/agent 目录。 + +与本地开发不同,部署时通过环境变量进行配置。application.yml 中有如 ${CONTEXT_PATH} 的可配置项,则能在环境变量中设置 CONTEXT_PATH 的值。 + +## [开发规范](https://github.com/alibaba/p3c) diff --git a/common/pom.xml b/common/pom.xml new file mode 100644 index 0000000..58601bd --- /dev/null +++ b/common/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + net.rzdata + demo + 5.1.0-SNAPSHOT + + demo-common + jar + + + 17 + 17 + UTF-8 + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..d0730f6 --- /dev/null +++ b/pom.xml @@ -0,0 +1,378 @@ + + + 4.0.0 + + com.rzdata + rzdata-framework + 0.0.1 + + net.rzdata + demo + 5.1.0-SNAPSHOT + pom + + + service + common + + + + 5.1.0-SNAPSHOT + UTF-8 + UTF-8 + 17 + + 3.0.7 + 3.0.1 + 2.1.0 + 0.15.0 + 5.2.3 + 3.2.1 + 2.3 + 1.37.0 + 3.5.3.1 + 3.9.1 + 5.8.18 + 4.10.0 + 3.0.4 + 3.20.1 + 2.2.4 + 3.6.1 + 2.14.2 + 2.4.0 + 1.5.5.Final + 1.2.3 + 0.2.0 + 1.18.26 + 1.72 + 13.1 + 2023.0.0 + + 2.7.0 + + + 1.33 + + + 1.12.400 + + 2.1.1 + + + 3.2.2 + 3.2.2 + 3.11.0 + 3.0.0 + 1.3.0 + + + + + + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + ${springdoc.version} + + + + com.github.therapi + therapi-runtime-javadoc + ${therapi-javadoc.version} + + + + org.projectlombok + lombok + ${lombok.version} + + + + org.apache.poi + poi + ${poi.version} + + + org.apache.poi + poi-ooxml + ${poi.version} + + + com.alibaba + easyexcel + ${easyexcel.version} + + + org.apache.poi + poi-ooxml-schemas + + + + + + + org.apache.velocity + velocity-engine-core + ${velocity.version} + + + + + com.baomidou + dynamic-datasource-spring-boot-starter + ${dynamic-ds.version} + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + ${spring-boot.mybatis} + + + org.mapstruct + mapstruct + ${mapstruct.version} + + + + com.baomidou + mybatis-plus-boot-starter + ${mybatis-plus.version} + + + + com.baomidou + mybatis-plus-annotation + ${mybatis-plus.version} + + + + + p6spy + p6spy + ${p6spy.version} + + + + com.squareup.okhttp3 + okhttp + ${okhttp.version} + + + + com.amazonaws + aws-java-sdk-s3 + ${aws-java-sdk-s3.version} + + + + org.dromara.sms4j + sms4j-spring-boot-starter + ${sms4j.version} + + + + de.codecentric + spring-boot-admin-starter-server + ${spring-boot-admin.version} + + + de.codecentric + spring-boot-admin-starter-client + ${spring-boot-admin.version} + + + + + org.redisson + redisson-spring-boot-starter + ${redisson.version} + + + + com.baomidou + lock4j-redisson-spring-boot-starter + ${lock4j.version} + + + com.alibaba + transmittable-thread-local + ${alibaba-ttl.version} + + + io.github.linpeilie + mapstruct-plus-spring-boot-starter + ${mapstruct-plus.version} + + + + org.lionsoul + ip2region + ${ip2region.version} + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + cn.hutool + hutool-bom + ${hutool.version} + pom + import + + + io.github.openfeign + feign-bom + ${openfeign.version} + pom + import + + + cn.dev33 + sa-token-bom + ${satoken.version} + pom + import + + + + + + + cn.hutool + hutool-core + true + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.verison} + + ${java.version} + ${java.version} + ${project.build.sourceEncoding} + + + com.github.therapi + therapi-runtime-javadoc-scribe + ${therapi-javadoc.version} + + + org.projectlombok + lombok + ${lombok.version} + + + org.springframework.boot + spring-boot-configuration-processor + ${spring-boot.version} + + + io.github.linpeilie + mapstruct-plus-processor + ${mapstruct-plus.version} + + + org.projectlombok + lombok-mapstruct-binding + ${mapstruct-plus.lombok.version} + + + + -parameters + + + + + + org.codehaus.mojo + flatten-maven-plugin + ${flatten-maven-plugin.version} + + true + resolveCiFriendliesOnly + + + + flatten + process-resources + + flatten + + + + flatten.clean + clean + + clean + + + + + + + + src/main/resources + + false + + + src/main/resources + + + application* + bootstrap* + banner* + + + true + + + + + + + public + aliyun nexus + https://maven.aliyun.com/repository/public/ + + true + + + + + + + public + aliyun nexus + https://maven.aliyun.com/repository/public/ + + true + + + false + + + + + + + diff --git a/service/pom.xml b/service/pom.xml new file mode 100644 index 0000000..5c6f4eb --- /dev/null +++ b/service/pom.xml @@ -0,0 +1,146 @@ + + + 4.0.0 + + net.rzdata + demo + 5.1.0-SNAPSHOT + + demo-service + pom + + + system + + + + 17 + 17 + UTF-8 + + 8080 + + ${project.build.directory}/java-agents + + /opt/agent + /app + + + opentelemetry-javaagent + otel-ali-extension + + + + + net.rzdata + demo-common + 5.1.0-SNAPSHOT + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-validation + + + com.baomidou + mybatis-plus-boot-starter + + + org.springframework.boot + spring-boot-starter-data-redis + + + com.mysql + mysql-connector-j + + + org.projectlombok + lombok + provided + + + org.mapstruct + mapstruct + + + org.liquibase + liquibase-core + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + src/main/resources + true + + + + + + + docker + + + + com.google.cloud.tools + jib-maven-plugin + 3.4.0 + + + + + amd64 + linux + + + + + ${docker.host}${project.artifactId}:${project.version} + + + + prod + otlp + ${project.artifactId} + true + ${agent-path}/${otel-ali-extension.name}.jar + + + ${app.port} + + + ${workdir}/resources + ${agent-path} + + + + ${workdir} + ${workdir} + Docker + + + + + deploy + + build + + + + + + + + + diff --git a/service/system/pom.xml b/service/system/pom.xml new file mode 100644 index 0000000..5843d8a --- /dev/null +++ b/service/system/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + + net.rzdata + demo-service + 5.1.0-SNAPSHOT + + demo-service-system + jar + + + 17 + 17 + UTF-8 + 4567 + + + diff --git a/service/system/src/main/java/net/rzdata/demo/DemoApplication.java b/service/system/src/main/java/net/rzdata/demo/DemoApplication.java new file mode 100644 index 0000000..54f54cb --- /dev/null +++ b/service/system/src/main/java/net/rzdata/demo/DemoApplication.java @@ -0,0 +1,12 @@ +package net.rzdata.demo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DemoApplication { + + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } +} diff --git a/service/system/src/main/resources/config/application.yml b/service/system/src/main/resources/config/application.yml new file mode 100644 index 0000000..8e7d599 --- /dev/null +++ b/service/system/src/main/resources/config/application.yml @@ -0,0 +1,21 @@ +server: + port: @app.port@ + servlet: + context-path: ${CONTEXT_PATH:} +spring: + application: + name: @project.artifactId@ + profiles: + active: + - ${SPRING_PROFILES_ACTIVE:local} + datasource: + type: com.zaxxer.hikari.HikariDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://${DB_URL}/${DB_NAME}?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true + username: ${DB_USERNAME} + password: ${DB_PASSWORD} + hikari: + minimum-idle: 5 + maximum-pool-size: 20 + idle-timeout: 30000 + max-lifetime: 1800000