diff --git a/mt-pay/src/main/java/com/mtkj/mtpay/common/Result.java b/mt-pay/src/main/java/com/mtkj/mtpay/common/Result.java new file mode 100644 index 0000000..a3674a6 --- /dev/null +++ b/mt-pay/src/main/java/com/mtkj/mtpay/common/Result.java @@ -0,0 +1,106 @@ +package com.mtkj.mtpay.common; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 统一响应结果类 + */ +@Data +public class Result implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 响应码 + */ + private String code; + + /** + * 响应消息 + */ + private String message; + + /** + * 响应数据 + */ + private T data; + + /** + * 时间戳 + */ + private Long timestamp; + + public Result() { + this.timestamp = System.currentTimeMillis(); + } + + public Result(String code, String message) { + this(); + this.code = code; + this.message = message; + } + + public Result(String code, String message, T data) { + this(code, message); + this.data = data; + } + + /** + * 成功响应 + */ + public static Result success() { + return new Result<>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage()); + } + + /** + * 成功响应(带数据) + */ + public static Result success(T data) { + return new Result<>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data); + } + + /** + * 成功响应(自定义消息) + */ + public static Result success(String message) { + return new Result<>(ResultCode.SUCCESS.getCode(), message); + } + + /** + * 成功响应(自定义消息和数据) + */ + public static Result success(String message, T data) { + return new Result<>(ResultCode.SUCCESS.getCode(), message, data); + } + + /** + * 失败响应 + */ + public static Result fail() { + return new Result<>(ResultCode.FAIL.getCode(), ResultCode.FAIL.getMessage()); + } + + /** + * 失败响应(自定义消息) + */ + public static Result fail(String message) { + return new Result<>(ResultCode.FAIL.getCode(), message); + } + + /** + * 失败响应(自定义码和消息) + */ + public static Result fail(String code, String message) { + return new Result<>(code, message); + } + + /** + * 失败响应(使用ResultCode) + */ + public static Result fail(ResultCode resultCode) { + return new Result<>(resultCode.getCode(), resultCode.getMessage()); + } +} + diff --git a/mt-pay/src/main/java/com/mtkj/mtpay/config/DruidMasterProperties.java b/mt-pay/src/main/java/com/mtkj/mtpay/config/DruidMasterProperties.java new file mode 100644 index 0000000..42dd078 --- /dev/null +++ b/mt-pay/src/main/java/com/mtkj/mtpay/config/DruidMasterProperties.java @@ -0,0 +1,29 @@ +package com.mtkj.mtpay.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * Druid主数据源配置属性 + */ +@Data +@ConfigurationProperties(prefix = "spring.datasource.druid.master") +public class DruidMasterProperties { + private String url; + private String username; + private String password; + private Integer initialSize; + private Integer minIdle; + private Integer maxActive; + private Long maxWait; + private Integer connectTimeout; + private Integer socketTimeout; + private Long timeBetweenEvictionRunsMillis; + private Long minEvictableIdleTimeMillis; + private Long maxEvictableIdleTimeMillis; + private String validationQuery; + private Boolean testWhileIdle; + private Boolean testOnBorrow; + private Boolean testOnReturn; +} + diff --git a/mt-pay/src/main/java/com/mtkj/mtpay/config/DruidSlaveProperties.java b/mt-pay/src/main/java/com/mtkj/mtpay/config/DruidSlaveProperties.java new file mode 100644 index 0000000..3fe66e1 --- /dev/null +++ b/mt-pay/src/main/java/com/mtkj/mtpay/config/DruidSlaveProperties.java @@ -0,0 +1,29 @@ +package com.mtkj.mtpay.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * Druid从数据源配置属性 + */ +@Data +@ConfigurationProperties(prefix = "spring.datasource.druid.slave") +public class DruidSlaveProperties { + private String url; + private String username; + private String password; + private Integer initialSize; + private Integer minIdle; + private Integer maxActive; + private Long maxWait; + private Integer connectTimeout; + private Integer socketTimeout; + private Long timeBetweenEvictionRunsMillis; + private Long minEvictableIdleTimeMillis; + private Long maxEvictableIdleTimeMillis; + private String validationQuery; + private Boolean testWhileIdle; + private Boolean testOnBorrow; + private Boolean testOnReturn; +} + diff --git a/mt-pay/src/main/java/com/mtkj/mtpay/config/RestClientConfig.java b/mt-pay/src/main/java/com/mtkj/mtpay/config/RestClientConfig.java new file mode 100644 index 0000000..6fd029b --- /dev/null +++ b/mt-pay/src/main/java/com/mtkj/mtpay/config/RestClientConfig.java @@ -0,0 +1,32 @@ +package com.mtkj.mtpay.config; + + +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.web.client.RestClient; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * RestClient配置 + */ +@Slf4j +@Configuration +public class RestClientConfig { + + @Bean + public RestClient restClient(ObjectMapper objectMapper) { + log.info("初始化RestClient,配置JSON消息转换器"); + RestClient restClient = RestClient.builder() + .messageConverters(converters -> { + MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); + converter.setObjectMapper(objectMapper); + converters.add(converter); + }) + .build(); + log.info("RestClient配置完成"); + return restClient; + } +} + diff --git a/mt-startup/pom.xml b/mt-startup/pom.xml new file mode 100644 index 0000000..7077bd5 --- /dev/null +++ b/mt-startup/pom.xml @@ -0,0 +1,82 @@ + + + 4.0.0 + + com.mtkj + MTKJPAY + 0.0.1-SNAPSHOT + ../pom.xml + + mt-startup + jar + mt-startup + MTKJ PAY 启动模块 + + + 17 + 1.18.30 + + + + + + com.mtkj + mt-pay + 0.0.1-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-web + + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + + + org.projectlombok + lombok + ${lombok.version} + true + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + ${lombok.version} + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/mt-startup/src/main/java/com/mtkj/mtkjpay/MtkjpayApplication.java b/mt-startup/src/main/java/com/mtkj/mtkjpay/MtkjpayApplication.java new file mode 100644 index 0000000..385c5eb --- /dev/null +++ b/mt-startup/src/main/java/com/mtkj/mtkjpay/MtkjpayApplication.java @@ -0,0 +1,99 @@ +package com.mtkj.mtkjpay; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.core.env.Environment; + +/** + * MTKJ PAY 支付系统启动类 + * 这是项目的唯一启动入口 + */ +@Slf4j +@SpringBootApplication( + scanBasePackages = {"com.mtkj.mtpay", "com.mtkj.mtkjpay"}, + exclude = { + com.alibaba.druid.spring.boot3.autoconfigure.DruidDataSourceAutoConfigure.class + } +) +public class MtkjpayApplication { + + public static void main(String[] args) { + try { + log.info(""" + + ╔══════════════════════════════════════════════════════════╗ + ║ ║ + ║ MTKJ PAY 支付系统正在启动... ║ + ║ ║ + ╚══════════════════════════════════════════════════════════╝ + """); + + SpringApplication app = new SpringApplication(MtkjpayApplication.class); + Environment env = app.run(args).getEnvironment(); + + String applicationName = env.getProperty("spring.application.name", "MTKJPAY"); + String serverPort = env.getProperty("server.port", "8082"); + String contextPath = env.getProperty("server.servlet.context-path", ""); + String activeProfiles = String.join(",", env.getActiveProfiles()); + + // 构建完整的访问地址 + String baseUrl = "http://localhost:" + serverPort + contextPath; + String apiUrl = baseUrl + "/api"; + String druidUrl = baseUrl + "/druid"; + + // 打印醒目的启动成功标识 + log.info(""" + + ╔══════════════════════════════════════════════════════════╗ + ║ ║ + ║ ✅ MTKJ PAY 支付系统启动成功! ✅ ║ + ║ ║ + ╠══════════════════════════════════════════════════════════╣ + ║ 应用信息 ║ + ╠══════════════════════════════════════════════════════════╣ + ║ 应用名称: {:<45} ║ + ║ 运行环境: {:<45} ║ + ║ 服务端口: {:<45} ║ + ╠══════════════════════════════════════════════════════════╣ + ║ 访问地址 ║ + ╠══════════════════════════════════════════════════════════╣ + ║ 后端服务: {:<45} ║ + ║ API接口: {:<45} ║ + ║ Druid监控: {:<45} ║ + ╠══════════════════════════════════════════════════════════╣ + ║ 状态: 🟢 服务运行中,可以接收请求 ║ + ╚══════════════════════════════════════════════════════════╝ + """, + applicationName, + activeProfiles.isEmpty() ? "default" : activeProfiles, + serverPort, + baseUrl, + apiUrl, + druidUrl); + + // 额外提示信息 + log.info(""" + + 📌 提示: + - 前端代理地址: http://localhost:3000 + - 后端API地址: {} + - 图片上传接口: {}/product/upload/image + - 商品管理接口: {}/product + """, apiUrl, apiUrl, apiUrl); + + } catch (Exception e) { + log.error(""" + + ╔══════════════════════════════════════════════════════════╗ + ║ ║ + ║ ❌ MTKJ PAY 支付系统启动失败! ❌ ║ + ║ ║ + ╚══════════════════════════════════════════════════════════╝ + """, e); + throw e; + } + } + +} +