This commit is contained in:
2026-03-24 00:30:22 +08:00
parent be962bf7b8
commit dc61d845a5
25 changed files with 1345 additions and 2998 deletions

View File

@@ -31,16 +31,16 @@ public class UserContext {
public static Long getUserId() {
UserContext context = get();
return context != null ? context.getUserId() : null;
return context != null ? context.userId : null;
}
public static String getUsername() {
UserContext context = get();
return context != null ? context.getUsername() : null;
return context != null ? context.username : null;
}
public static boolean isAdmin() {
UserContext context = get();
return context != null && "admin".equals(context.getType());
return context != null && "admin".equals(context.type);
}
}

View File

@@ -3,6 +3,8 @@ package com.it.rattan.monisuo.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.it.rattan.monisuo.common.Result;
import com.it.rattan.monisuo.context.UserContext;
import com.it.rattan.monisuo.dto.DepositRequest;
import com.it.rattan.monisuo.dto.WithdrawRequest;
import com.it.rattan.monisuo.entity.OrderFund;
import com.it.rattan.monisuo.service.FundService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -24,16 +26,16 @@ public class FundController {
* 申请充值
*/
@PostMapping("/deposit")
public Result<Map<String, Object>> deposit(@RequestBody Map<String, Object> params) {
public Result<Map<String, Object>> deposit(@RequestBody DepositRequest request) {
Long userId = UserContext.getUserId();
if (userId == null) {
return Result.unauthorized("请先登录");
}
BigDecimal amount = new BigDecimal(params.get("amount").toString());
String remark = (String) params.get("remark");
BigDecimal amount = request.getAmount();
String remark = request.getRemark();
if (amount.compareTo(BigDecimal.ZERO) <= 0) {
if (amount == null || amount.compareTo(BigDecimal.ZERO) <= 0) {
return Result.fail("充值金额必须大于0");
}
@@ -72,18 +74,18 @@ public class FundController {
* 申请提现
*/
@PostMapping("/withdraw")
public Result<Map<String, Object>> withdraw(@RequestBody Map<String, Object> params) {
public Result<Map<String, Object>> withdraw(@RequestBody WithdrawRequest request) {
Long userId = UserContext.getUserId();
if (userId == null) {
return Result.unauthorized("请先登录");
}
BigDecimal amount = new BigDecimal(params.get("amount").toString());
String withdrawAddress = (String) params.get("withdrawAddress");
String withdrawContact = (String) params.get("withdrawContact");
String remark = (String) params.get("remark");
BigDecimal amount = request.getAmount();
String withdrawAddress = request.getWithdrawAddress();
String withdrawContact = request.getWithdrawContact();
String remark = request.getRemark();
if (amount.compareTo(BigDecimal.ZERO) <= 0) {
if (amount == null || amount.compareTo(BigDecimal.ZERO) <= 0) {
return Result.fail("提现金额必须大于0");
}

View File

@@ -0,0 +1,13 @@
package com.it.rattan.monisuo.dto;
import lombok.Data;
import java.math.BigDecimal;
/**
* 充值请求DTO
*/
@Data
public class DepositRequest {
private BigDecimal amount;
private String remark;
}

View File

@@ -0,0 +1,15 @@
package com.it.rattan.monisuo.dto;
import lombok.Data;
import java.math.BigDecimal;
/**
* 提现请求DTO
*/
@Data
public class WithdrawRequest {
private BigDecimal amount;
private String withdrawAddress;
private String withdrawContact;
private String remark;
}

View File

@@ -1,6 +1,7 @@
package com.it.rattan.monisuo.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
@@ -22,6 +23,7 @@ public class User implements Serializable {
private String username;
/** 密码(BCrypt加密) */
@JsonIgnore
private String password;
/** 昵称 */
@@ -56,6 +58,7 @@ public class User implements Serializable {
/** 当前Token */
@TableField(select = false)
@JsonIgnore
private String token;
/** 创建时间 */

View File

@@ -18,6 +18,42 @@ import java.io.StringWriter;
@ControllerAdvice
public class GlobalExceptionHandler {
/**
* 处理 NestedServletException (Spring MVC 包装的异常)
*/
@ExceptionHandler(org.springframework.web.util.NestedServletException.class)
@ResponseBody
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public Result<Void> handleNestedServletException(org.springframework.web.util.NestedServletException e) {
Throwable rootCause = getRootCause(e);
// 如果根因是 StackOverflowError
if (rootCause instanceof StackOverflowError) {
StackOverflowError soe = (StackOverflowError) rootCause;
StackTraceElement[] stack = soe.getStackTrace();
StringBuilder sb = new StringBuilder("StackOverflowError at:\n");
for (int i = 0; i < Math.min(30, stack.length); i++) {
sb.append(" at ").append(stack[i]).append("\n");
}
log.error("StackOverflowError 发生 (via NestedServletException):\n{}", sb.toString());
return Result.fail("系统错误:序列化循环引用,请联系管理员");
}
log.error("NestedServletException 发生: {}", e.getMessage());
return Result.fail("系统异常: " + rootCause.getMessage());
}
/**
* 获取异常的根因
*/
private Throwable getRootCause(Throwable throwable) {
Throwable cause = throwable;
while (cause.getCause() != null && cause.getCause() != cause) {
cause = cause.getCause();
}
return cause;
}
/**
* 处理 StackOverflowError
*/
@@ -25,7 +61,13 @@ public class GlobalExceptionHandler {
@ResponseBody
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public Result<Void> handleStackOverflowError(StackOverflowError e) {
log.error("StackOverflowError 发生", e);
// 打印前30行堆栈避免递归
StackTraceElement[] stack = e.getStackTrace();
StringBuilder sb = new StringBuilder("StackOverflowError at:\n");
for (int i = 0; i < Math.min(30, stack.length); i++) {
sb.append(" at ").append(stack[i]).append("\n");
}
log.error("StackOverflowError 发生:\n{}", sb.toString());
return Result.fail("系统错误:序列化循环引用,请联系管理员");
}
@@ -58,7 +100,7 @@ public class GlobalExceptionHandler {
@ResponseBody
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public Result<Void> handleException(Exception e) {
log.error("Exception 发生", getStackTrace(e));
log.error("Exception 发生: {} - {}", e.getClass().getName(), e.getMessage());
return Result.fail("系统异常: " + e.getMessage());
}