diff --git a/mt-pay/pom.xml b/mt-pay/pom.xml index e7055c3..13a7aa4 100644 --- a/mt-pay/pom.xml +++ b/mt-pay/pom.xml @@ -56,6 +56,13 @@ mybatis-plus-boot-starter 3.5.7 + + + + com.aliyun.oss + aliyun-sdk-oss + 3.17.4 + com.alibaba diff --git a/mt-pay/src/main/java/com/mtkj/mtpay/config/DruidDataSourceConfig.java b/mt-pay/src/main/java/com/mtkj/mtpay/config/DruidDataSourceConfig.java new file mode 100644 index 0000000..9fb1d92 --- /dev/null +++ b/mt-pay/src/main/java/com/mtkj/mtpay/config/DruidDataSourceConfig.java @@ -0,0 +1,49 @@ +package com.mtkj.mtpay.config; + +import com.alibaba.druid.pool.DruidDataSource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +import javax.sql.DataSource; + +/** + * Druid数据源配置 + * 支持主从数据源配置 + */ +@Slf4j +@Configuration +public class DruidDataSourceConfig { + + /** + * 主数据源配置 + * 使用@Primary注解确保这是默认数据源 + */ + @Bean + @Primary + @ConfigurationProperties(prefix = "spring.datasource.druid.master") + public DataSource masterDataSource() { + log.info("初始化Druid主数据源"); + DruidDataSource dataSource = new DruidDataSource(); + log.info("Druid主数据源配置完成"); + return dataSource; + } + + /** + * 从数据源配置(可选) + * 只有当slave.enabled=true时才会创建 + */ + @Bean(name = "slaveDataSource") + @ConditionalOnProperty(prefix = "spring.datasource.druid.slave", name = "enabled", havingValue = "true") + @ConfigurationProperties(prefix = "spring.datasource.druid.slave") + public DataSource slaveDataSource() { + log.info("初始化Druid从数据源"); + DruidDataSource dataSource = new DruidDataSource(); + log.info("Druid从数据源配置完成"); + return dataSource; + } +} + diff --git a/mt-pay/src/main/java/com/mtkj/mtpay/dto/risk/DeviceDTO.java b/mt-pay/src/main/java/com/mtkj/mtpay/dto/risk/DeviceDTO.java new file mode 100644 index 0000000..98b3ec7 --- /dev/null +++ b/mt-pay/src/main/java/com/mtkj/mtpay/dto/risk/DeviceDTO.java @@ -0,0 +1,19 @@ +package com.mtkj.mtpay.dto.risk; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 设备信息DTO + */ +@Data +public class DeviceDTO implements Serializable { + + private String orderTerminal; + + private String fingerprintId; + + private String browserInfo; +} + diff --git a/mt-pay/src/main/java/com/mtkj/mtpay/dto/risk/EcommerceDTO.java b/mt-pay/src/main/java/com/mtkj/mtpay/dto/risk/EcommerceDTO.java new file mode 100644 index 0000000..6396520 --- /dev/null +++ b/mt-pay/src/main/java/com/mtkj/mtpay/dto/risk/EcommerceDTO.java @@ -0,0 +1,17 @@ +package com.mtkj.mtpay.dto.risk; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 电商信息DTO + */ +@Data +public class EcommerceDTO implements Serializable { + + private String freeShipping; + + private String shippingMethod; +} + diff --git a/mt-pay/src/main/java/com/mtkj/mtpay/exception/GlobalExceptionHandler.java b/mt-pay/src/main/java/com/mtkj/mtpay/exception/GlobalExceptionHandler.java new file mode 100644 index 0000000..2d9f40d --- /dev/null +++ b/mt-pay/src/main/java/com/mtkj/mtpay/exception/GlobalExceptionHandler.java @@ -0,0 +1,68 @@ +package com.mtkj.mtpay.exception; + +import com.mtkj.mtpay.common.Result; +import com.mtkj.mtpay.common.ResultCode; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.FieldError; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import java.util.HashMap; +import java.util.Map; + +/** + * 全局异常处理器 + */ +@Slf4j +@RestControllerAdvice +public class GlobalExceptionHandler { + + /** + * 处理业务异常 + */ + @ExceptionHandler(BusinessException.class) + public ResponseEntity> handleBusinessException(BusinessException e) { + log.warn("业务异常: {}", e.getMessage()); + return ResponseEntity.ok(Result.fail(e.getCode(), e.getMessage())); + } + + /** + * 处理参数验证异常 + */ + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity>> handleValidationException(MethodArgumentNotValidException e) { + Map errors = new HashMap<>(); + e.getBindingResult().getAllErrors().forEach(error -> { + String fieldName = ((FieldError) error).getField(); + String errorMessage = error.getDefaultMessage(); + errors.put(fieldName, errorMessage); + }); + + log.warn("参数验证失败: {}", errors); + return ResponseEntity.badRequest() + .body(Result.fail(ResultCode.VALIDATION_ERROR.getCode(), ResultCode.VALIDATION_ERROR.getMessage(), errors)); + } + + /** + * 处理运行时异常 + */ + @ExceptionHandler(RuntimeException.class) + public ResponseEntity> handleRuntimeException(RuntimeException e) { + log.error("运行时异常", e); + return ResponseEntity.internalServerError() + .body(Result.fail(ResultCode.SYSTEM_ERROR.getCode(), e.getMessage())); + } + + /** + * 处理其他异常 + */ + @ExceptionHandler(Exception.class) + public ResponseEntity> handleException(Exception e) { + log.error("系统异常", e); + return ResponseEntity.internalServerError() + .body(Result.fail(ResultCode.SYSTEM_ERROR)); + } +} + diff --git a/mt-pay/src/main/java/com/mtkj/mtpay/util/DateUtils.java b/mt-pay/src/main/java/com/mtkj/mtpay/util/DateUtils.java new file mode 100644 index 0000000..8218ea6 --- /dev/null +++ b/mt-pay/src/main/java/com/mtkj/mtpay/util/DateUtils.java @@ -0,0 +1,52 @@ +package com.mtkj.mtpay.util; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +/** + * 日期工具类 + */ +public class DateUtils { + + /** + * 默认日期时间格式:yyyyMMddHHmmss + */ + public static final String DEFAULT_DATETIME_FORMAT = "yyyyMMddHHmmss"; + + /** + * 标准日期时间格式:yyyy-MM-dd HH:mm:ss + */ + public static final String STANDARD_DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; + + /** + * 格式化日期时间为字符串(yyyyMMddHHmmss) + */ + public static String formatDateTime(LocalDateTime dateTime) { + return formatDateTime(dateTime, DEFAULT_DATETIME_FORMAT); + } + + /** + * 格式化日期时间为字符串 + */ + public static String formatDateTime(LocalDateTime dateTime, String pattern) { + if (dateTime == null) { + return null; + } + return dateTime.format(DateTimeFormatter.ofPattern(pattern)); + } + + /** + * 获取当前时间字符串(yyyyMMddHHmmss) + */ + public static String getCurrentDateTimeString() { + return formatDateTime(LocalDateTime.now()); + } + + /** + * 获取当前时间字符串(标准格式) + */ + public static String getCurrentDateTimeStringStandard() { + return formatDateTime(LocalDateTime.now(), STANDARD_DATETIME_FORMAT); + } +} + diff --git a/mt-pay/src/main/resources/application-dev.yml b/mt-pay/src/main/resources/application-dev.yml index 1bbf396..a24bad5 100644 --- a/mt-pay/src/main/resources/application-dev.yml +++ b/mt-pay/src/main/resources/application-dev.yml @@ -5,7 +5,7 @@ spring: druid: # 主库数据源(开发环境) master: - url: jdbc:mysql://rm-j6c3u06k2afwn8hxw6o.mysql.rds.aliyuncs.com:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai + url: jdbc:mysql://rm-j6c3u06k2afwn8hxw6o.mysql.rds.aliyuncs.com:3306/mtpay?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai username: mtkj2025 password: aXs-Q876#pxBesA # 初始连接数 diff --git a/mt-pay/src/main/resources/application.yml b/mt-pay/src/main/resources/application.yml index 99115bc..030b4f5 100644 --- a/mt-pay/src/main/resources/application.yml +++ b/mt-pay/src/main/resources/application.yml @@ -72,6 +72,14 @@ pingpong: # 服务器配置 server: port: 8080 + +# 阿里云OSS相关配置 +aliyun: + oss: + accessId: LTAI5tHbwvzWfANvNxju2yN1 + accessKey: sAQR2swByBgmMOofH97hSJT638aVcJ + endpoint: https://oss-cn-hangzhou.aliyuncs.com + bucketName: mtkj2025 servlet: context-path: / diff --git a/pom.xml b/pom.xml index aad9e88..93cf5ee 100644 --- a/pom.xml +++ b/pom.xml @@ -34,6 +34,10 @@ org.springframework.boot spring-boot-starter-restclient + + org.springframework.boot + spring-boot-starter-webmvc + org.springframework.boot diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 4489d9f..b596f7e 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1,3 @@ spring.application.name=MTKJPAY +server.port=8080 +spring.profiles.active=dev