feat(core): 初始化支付系统核心配置与启动模块
- 添加Druid主从数据源配置属性类 - 创建支付系统主启动类MtkjpayApplication - 配置mt-startup模块pom.xml引入必要依赖 - 添加RestClient配置类用于HTTP请求 - 创建统一响应结果类Result及响应码枚举 - 实现美观的系统启动成功/失败日志输出 - 配置Lombok注解处理器支持
This commit is contained in:
106
mt-pay/src/main/java/com/mtkj/mtpay/common/Result.java
Normal file
106
mt-pay/src/main/java/com/mtkj/mtpay/common/Result.java
Normal file
@@ -0,0 +1,106 @@
|
||||
package com.mtkj.mtpay.common;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 统一响应结果类
|
||||
*/
|
||||
@Data
|
||||
public class Result<T> 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 <T> Result<T> success() {
|
||||
return new Result<>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功响应(带数据)
|
||||
*/
|
||||
public static <T> Result<T> success(T data) {
|
||||
return new Result<>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功响应(自定义消息)
|
||||
*/
|
||||
public static <T> Result<T> success(String message) {
|
||||
return new Result<>(ResultCode.SUCCESS.getCode(), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功响应(自定义消息和数据)
|
||||
*/
|
||||
public static <T> Result<T> success(String message, T data) {
|
||||
return new Result<>(ResultCode.SUCCESS.getCode(), message, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*/
|
||||
public static <T> Result<T> fail() {
|
||||
return new Result<>(ResultCode.FAIL.getCode(), ResultCode.FAIL.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应(自定义消息)
|
||||
*/
|
||||
public static <T> Result<T> fail(String message) {
|
||||
return new Result<>(ResultCode.FAIL.getCode(), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应(自定义码和消息)
|
||||
*/
|
||||
public static <T> Result<T> fail(String code, String message) {
|
||||
return new Result<>(code, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应(使用ResultCode)
|
||||
*/
|
||||
public static <T> Result<T> fail(ResultCode resultCode) {
|
||||
return new Result<>(resultCode.getCode(), resultCode.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user