From 332663f7c69b38ec85f3828f790683e3471eed80 Mon Sep 17 00:00:00 2001
From: zhangli <123879394@qq.com>
Date: Wed, 2 Jul 2025 02:28:19 +0800
Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 35 +++
readme.md => README.md | 0
pom.xml | 231 ++++++++++++++++++
src/main/java/com/sczx/app/Application.java | 29 +++
.../app/common/constant/SystemConstants.java | 23 ++
.../com/sczx/app/config/SpringDocConfig.java | 16 ++
.../java/com/sczx/app/config/WebConfig.java | 44 ++++
.../sczx/app/controller/DemoController.java | 16 ++
.../java/com/sczx/app/utils/ComputerInfo.java | 159 ++++++++++++
src/main/resources/application.yml | 71 ++++++
src/main/resources/logback.xml | 53 ++++
11 files changed, 677 insertions(+)
create mode 100644 .gitignore
rename readme.md => README.md (100%)
create mode 100644 pom.xml
create mode 100644 src/main/java/com/sczx/app/Application.java
create mode 100644 src/main/java/com/sczx/app/common/constant/SystemConstants.java
create mode 100644 src/main/java/com/sczx/app/config/SpringDocConfig.java
create mode 100644 src/main/java/com/sczx/app/config/WebConfig.java
create mode 100644 src/main/java/com/sczx/app/controller/DemoController.java
create mode 100644 src/main/java/com/sczx/app/utils/ComputerInfo.java
create mode 100644 src/main/resources/application.yml
create mode 100644 src/main/resources/logback.xml
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0d7f4db
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,35 @@
+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/
+logs/
+src/main/resources/rebel.xml
diff --git a/readme.md b/README.md
similarity index 100%
rename from readme.md
rename to README.md
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..1a47600
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,231 @@
+
+
+ 4.0.0
+
+ com.sczx
+ sczx-app
+ 1.0.0
+ jar
+
+ sczx-app
+ sczx-app service
+
+
+ 1.8
+ 2.1.18.RELEASE
+ Greenwich.SR6
+ 2.2.9.RELEASE
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.1.18.RELEASE
+
+
+
+
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-dependencies
+ ${spring-cloud.version}
+ pom
+ import
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-alibaba-dependencies
+ ${spring-cloud-alibaba.version}
+ pom
+ import
+
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
+
+
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-commons
+
+
+
+
+ org.projectlombok
+ lombok
+ 1.18.24
+ provided
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-openfeign
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-netflix-hystrix
+
+
+
+
+ org.springframework.retry
+ spring-retry
+ 1.3.1
+
+
+
+ org.springframework.boot
+ spring-boot-starter-aop
+
+
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+ 2.3.1
+
+
+
+
+ mysql
+ mysql-connector-java
+ 8.0.33
+
+
+
+
+ org.springdoc
+ springdoc-openapi-ui
+ 1.6.14
+
+
+
+ org.webjars
+ swagger-ui
+ 4.15.5
+
+
+
+
+ javax.xml.bind
+ jaxb-api
+ 2.3.1
+
+
+
+
+
+ sczx-app
+
+
+ src/main/resources
+
+ *.yml
+
+ true
+
+
+ src/main/resources
+
+ *.yml
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ ${java.version}
+ ${java.version}
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ repackage
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+ 3.6.0
+
+
+ unpack
+ process-resources
+
+ unpack
+
+
+
+
+ org.webjars
+ swagger-ui
+ 4.15.5
+ jar
+ ${project.build.outputDirectory}
+ META-INF/resources/**
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+
+ true
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/sczx/app/Application.java b/src/main/java/com/sczx/app/Application.java
new file mode 100644
index 0000000..9780603
--- /dev/null
+++ b/src/main/java/com/sczx/app/Application.java
@@ -0,0 +1,29 @@
+package com.sczx.app;
+
+import com.sczx.app.common.constant.SystemConstants;
+import com.sczx.app.utils.ComputerInfo;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.netflix.hystrix.EnableHystrix;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.core.env.Environment;
+import org.springframework.retry.annotation.EnableRetry;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+import java.io.IOException;
+
+@SpringBootApplication
+@EnableRetry
+@EnableFeignClients(basePackages = SystemConstants.FEIGN_CLIENT_BASE_PACKAGE )
+@EnableTransactionManagement
+@EnableHystrix
+public class Application {
+
+ public static void main(String[] args) throws IOException {
+ ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
+ Environment environment = context.getBean(Environment.class);
+ System.out.println("启动成功,后端服务API地址:http://" + ComputerInfo.getIpAddr() + ":"
+ + environment.getProperty("server.port") + "/doc.html");
+ }
+}
diff --git a/src/main/java/com/sczx/app/common/constant/SystemConstants.java b/src/main/java/com/sczx/app/common/constant/SystemConstants.java
new file mode 100644
index 0000000..eeadc5b
--- /dev/null
+++ b/src/main/java/com/sczx/app/common/constant/SystemConstants.java
@@ -0,0 +1,23 @@
+package com.sczx.app.common.constant;
+
+
+/**
+ * 应用模块名称
+ *
+ * 代码描述
+ *
+ * Copyright: Copyright (C) 2022 CD Finance Management Co., Ltd. All rights reserved.
+ *
+ * Company: 中和农信项目管理有限公司
+ *
+ * @author zhonghui
+ * @since 2022/4/1 3:33 PM
+ */
+public interface SystemConstants {
+
+ /***
+ * feign客户端所在包路径
+ */
+ String FEIGN_CLIENT_BASE_PACKAGE = "com.sczx.app.thirdpart.facade";
+
+}
diff --git a/src/main/java/com/sczx/app/config/SpringDocConfig.java b/src/main/java/com/sczx/app/config/SpringDocConfig.java
new file mode 100644
index 0000000..b8d3623
--- /dev/null
+++ b/src/main/java/com/sczx/app/config/SpringDocConfig.java
@@ -0,0 +1,16 @@
+package com.sczx.app.config;
+
+
+import org.springdoc.core.GroupedOpenApi;
+import org.springframework.context.annotation.Bean;
+
+//@Configuration
+public class SpringDocConfig {
+ @Bean
+ public GroupedOpenApi publicApi() {
+ return GroupedOpenApi.builder()
+ .group("sczx-service")
+ .packagesToScan("com.sczx.app.controller")
+ .build();
+ }
+}
diff --git a/src/main/java/com/sczx/app/config/WebConfig.java b/src/main/java/com/sczx/app/config/WebConfig.java
new file mode 100644
index 0000000..bef3184
--- /dev/null
+++ b/src/main/java/com/sczx/app/config/WebConfig.java
@@ -0,0 +1,44 @@
+package com.sczx.app.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.MediaType;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.StringHttpMessageConverter;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.List;
+
+@Configuration
+@EnableWebMvc
+public class WebConfig implements WebMvcConfigurer {
+
+ @Override
+ public void addResourceHandlers(ResourceHandlerRegistry registry) {
+ registry.addResourceHandler("/swagger-ui/**")
+ .addResourceLocations("classpath:/META-INF/resources/webjars/swagger-ui/4.15.5/");
+ registry.addResourceHandler("/swagger-ui.html")
+ .addResourceLocations("classpath:/META-INF/resources/swagger-ui.html");
+ registry.addResourceHandler("/v3/api-docs/**")
+ .addResourceLocations("classpath:/META-INF/resources/swagger-ui/");
+ }
+
+ @Override
+ public void configureMessageConverters(List> converters) {
+
+ converters.add(new StringHttpMessageConverter(StandardCharsets.UTF_8));
+ // 添加支持 application/json;charset=UTF-8 的 Jackson 转换器
+ converters.add(new MappingJackson2HttpMessageConverter() {
+ @Override
+ public List getSupportedMediaTypes() {
+ return Collections.singletonList(MediaType.APPLICATION_JSON_UTF8);
+ }
+ });
+
+
+ }
+}
diff --git a/src/main/java/com/sczx/app/controller/DemoController.java b/src/main/java/com/sczx/app/controller/DemoController.java
new file mode 100644
index 0000000..5b4f286
--- /dev/null
+++ b/src/main/java/com/sczx/app/controller/DemoController.java
@@ -0,0 +1,16 @@
+package com.sczx.app.controller;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@Tag(name = "示例接口", description = "用于演示 Springdoc 的接口")
+public class DemoController {
+ @GetMapping("/test")
+ @Operation(summary = "测试接口", description = "返回一个测试字符串")
+ public String test() {
+ return "OK";
+ }
+}
diff --git a/src/main/java/com/sczx/app/utils/ComputerInfo.java b/src/main/java/com/sczx/app/utils/ComputerInfo.java
new file mode 100644
index 0000000..38b0424
--- /dev/null
+++ b/src/main/java/com/sczx/app/utils/ComputerInfo.java
@@ -0,0 +1,159 @@
+package com.sczx.app.utils;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/*
+ * <取网卡物理地址--
+ * 1.在Windows,Linux系统下均可用;
+ * 2.通过ipconifg,ifconfig获得计算机信息;
+ * 3.再用模式匹配方式查找MAC地址,与操作系统的语言无关>
+ *
+ * //* Description: <取计算机名--从环境变量中取>
+ * abstract 限制继承/创建实例
+ */
+public abstract class ComputerInfo {
+ private static String macAddressStr = null;
+ private static String computerName = System.getenv().get("COMPUTERNAME");
+
+ private static final String[] windowsCommand = { "ipconfig", "/all" };
+ private static final String[] linuxCommand = { "/sbin/ifconfig", "-a" };
+ private static final String[] macCommand = { "ifconfig", "-a" };
+ private static final Pattern macPattern = Pattern.compile(".*((:?[0-9a-f]{2}[-:]){5}[0-9a-f]{2}).*",
+ Pattern.CASE_INSENSITIVE);
+
+ /**
+ * 获取多个网卡地址
+ *
+ * @return
+ * @throws IOException
+ */
+ private final static List getMacAddressList() throws IOException {
+ final ArrayList macAddressList = new ArrayList();
+ final String os = System.getProperty("os.name");
+ final String command[];
+
+ if (os.startsWith("Windows")) {
+ command = windowsCommand;
+ } else if (os.startsWith("Linux")) {
+ command = linuxCommand;
+ } else if (os.startsWith("Mac")){
+ command = macCommand;
+ }
+ else {
+ throw new IOException("Unknow operating system:" + os);
+ }
+ // 执行命令
+ final Process process = Runtime.getRuntime().exec(command);
+
+ BufferedReader bufReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
+ for (String line = null; (line = bufReader.readLine()) != null;) {
+ Matcher matcher = macPattern.matcher(line);
+ if (matcher.matches()) {
+ macAddressList.add(matcher.group(1));
+ // macAddressList.add(matcher.group(1).replaceAll("[-:]",
+ // ""));//去掉MAC中的“-”
+ }
+ }
+
+ process.destroy();
+ bufReader.close();
+ return macAddressList;
+ }
+
+ /**
+ * 获取一个网卡地址(多个网卡时从中获取一个)
+ *
+ * @return
+ */
+ public static String getMacAddress() {
+ if (macAddressStr == null || macAddressStr.equals("")) {
+ StringBuffer sb = new StringBuffer(); // 存放多个网卡地址用,目前只取一个非0000000000E0隧道的值
+ try {
+ List macList = getMacAddressList();
+ for (Iterator iter = macList.iterator(); iter.hasNext();) {
+ String amac = iter.next();
+ if (!"0000000000E0".equals(amac)) {
+ sb.append(amac);
+ break;
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ macAddressStr = sb.toString();
+
+ }
+
+ return macAddressStr;
+ }
+
+ /**
+ * 获取电脑名
+ *
+ * @return
+ */
+ public static String getComputerName() {
+ if (computerName == null || computerName.equals("")) {
+ computerName = System.getenv().get("COMPUTERNAME");
+ }
+ return computerName;
+ }
+
+ /**
+ * 获取客户端IP地址
+ *
+ * @return
+ */
+ public static String getIpAddrAndName() throws IOException {
+ return InetAddress.getLocalHost().toString();
+ }
+
+ /**
+ * 获取客户端IP地址
+ *
+ * @return
+ */
+ public static String getIpAddr() throws IOException {
+ return InetAddress.getLocalHost().getHostAddress().toString();
+ }
+
+ /**
+ * 获取电脑唯一标识
+ *
+ * @return
+ */
+ public static String getComputerID() {
+ String id = getMacAddress();
+ if (id == null || id.equals("")) {
+ try {
+ id = getIpAddrAndName();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return computerName;
+ }
+
+ /**
+ * 限制创建实例
+ */
+ private ComputerInfo() {
+
+ }
+
+ public static void main(String[] args) throws IOException {
+ System.out.println(ComputerInfo.getMacAddress());
+ System.out.println(ComputerInfo.getComputerName());
+ System.out.println(ComputerInfo.getIpAddr());
+ System.out.println(ComputerInfo.getIpAddrAndName());
+ }
+}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
new file mode 100644
index 0000000..9140b95
--- /dev/null
+++ b/src/main/resources/application.yml
@@ -0,0 +1,71 @@
+
+server:
+ port: 8088
+
+spring:
+ application:
+ name: sczx-service # 微服务名称
+ http:
+ encoding:
+ charset: UTF-8
+ enabled: true
+ force: true
+ mvc:
+ async:
+ request-timeout: -1
+
+ cloud:
+ nacos:
+ discovery:
+ server-addr: localhost:8848 # Nacos 地址
+
+ datasource:
+ url: jdbc:mysql://115.190.8.52:3306/sczx?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
+ username: sczx_user
+ password: Sczx123@
+ driver-class-name: com.mysql.cj.jdbc.Driver
+ hikari:
+ maximum-pool-size: 10
+ auto-commit: true
+
+ jpa:
+ hibernate:
+ ddl-auto: update
+ show-sql: true
+ database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
+
+ lifecycle:
+ timeout-per-shutdown-phase: 30s # 设置优雅停机时间
+
+management:
+ endpoints:
+ web:
+ exposure:
+ include: "*" # 暴露所有监控端点
+ endpoint:
+ health:
+ show-details: always
+
+feign:
+ client:
+ config:
+ default:
+ connectTimeout: 5000
+ readTimeout: 5000
+ hystrix:
+ enabled: true # 启用 Feign 的 Hystrix 支持
+
+hystrix:
+ command:
+ default:
+ execution:
+ isolation:
+ thread:
+ timeoutInMilliseconds: 10000 # 默认熔断超时时间
+
+springdoc:
+ swagger-ui:
+ url: /v3/api-docs
+ path: /doc.html
+ packages-to-scan: com.sczx.app.controller # 替换为你的 controller 包路径
+debug: true
\ No newline at end of file
diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml
new file mode 100644
index 0000000..e594345
--- /dev/null
+++ b/src/main/resources/logback.xml
@@ -0,0 +1,53 @@
+
+
+
+
+
+
+
+
+ ${PATTERN}
+
+
+
+
+
+ ${LOG_FILE_PATH}/${hostname}/info.%d{yyyy-MM-dd}.log
+ 31
+
+
+
+ ${PATTERN}
+
+
+
+ WARN
+ DENY
+ NEUTRAL
+
+
+ ERROR
+ DENY
+ NEUTRAL
+
+
+
+
+
+ WARN
+
+ ${LOG_FILE_PATH}/${hostname}/warn.log
+ true
+
+ ${PATTERN}
+
+
+
+
+
+
+
+
+
\ No newline at end of file