fix: 修复订单审批状态不更新的问题
主要修复: 1. 添加 MetaObjectHandler 自动填充时间字段 2. 启用 @EnableTransactionManagement 显式事务管理 3. 使用 LambdaUpdateWrapper 强制更新订单状态 4. 完善 MyBatis Plus 配置和字段更新策略 5. 添加详细的调试日志配置 6. 前端集成 vconsole 调试工具 关键修改文件: - SpcCloudApplication.java: 添加 @EnableTransactionManagement - FundService.java: 使用 LambdaUpdateWrapper 显式更新 - MyBatisPlusMetaObjectHandler.java: 自动填充时间字段 - application-dev.yml: 完善配置和日志 - monisuo-admin: 添加 vconsole 调试工具
This commit is contained in:
@@ -7,11 +7,13 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
|
||||
@SpringBootApplication
|
||||
@ServletComponentScan(basePackages ={"com.it.rattan"})
|
||||
@ComponentScan(basePackages ={"com.it.rattan"})
|
||||
@EnableTransactionManagement
|
||||
/*@EnableAsync
|
||||
@EnableAspectJAutoProxy*/
|
||||
public class SpcCloudApplication {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.it.rattan.monisuo.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.it.rattan.monisuo.entity.AccountFund;
|
||||
@@ -395,38 +396,57 @@ public class FundService {
|
||||
}
|
||||
}
|
||||
|
||||
// 更新订单状态
|
||||
// 更新订单状态 - 使用 LambdaUpdateWrapper 强制更新所有字段
|
||||
System.out.println("[FundService.approve] 步骤5: 更新订单状态...");
|
||||
System.out.println(" - 当前状态: " + order.getStatus());
|
||||
System.out.println(" - 目标状态: " + finalStatus);
|
||||
|
||||
order.setStatus(finalStatus);
|
||||
order.setApproveAdminId(adminId);
|
||||
order.setApproveAdminName(adminName);
|
||||
order.setApproveTime(LocalDateTime.now());
|
||||
order.setAdminRemark(adminRemark);
|
||||
order.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
System.out.println(" - 准备执行数据库更新...");
|
||||
int orderUpdateResult = orderFundMapper.updateById(order);
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
// 使用 LambdaUpdateWrapper 明确指定要更新的字段
|
||||
LambdaUpdateWrapper<OrderFund> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(OrderFund::getId, order.getId())
|
||||
.set(OrderFund::getStatus, finalStatus)
|
||||
.set(OrderFund::getApproveAdminId, adminId)
|
||||
.set(OrderFund::getApproveAdminName, adminName)
|
||||
.set(OrderFund::getApproveTime, now)
|
||||
.set(OrderFund::getConfirmTime, order.getConfirmTime())
|
||||
.set(OrderFund::getRejectReason, order.getRejectReason())
|
||||
.set(OrderFund::getAdminRemark, adminRemark)
|
||||
.set(OrderFund::getUpdateTime, now);
|
||||
|
||||
System.out.println(" - 准备执行数据库更新 (使用 LambdaUpdateWrapper)...");
|
||||
System.out.println(" - UPDATE SQL 将更新: status=" + finalStatus + ", approveAdminId=" + adminId);
|
||||
|
||||
int orderUpdateResult = orderFundMapper.update(null, updateWrapper);
|
||||
System.out.println(" - 订单更新结果: " + orderUpdateResult + " (1=成功, 0=失败)");
|
||||
|
||||
// 验证更新是否成功
|
||||
|
||||
// 验证更新是否成功 - 使用新的查询确保从数据库读取
|
||||
if (orderUpdateResult > 0) {
|
||||
System.out.println("[FundService.approve] 步骤6: 验证更新结果...");
|
||||
OrderFund verifyOrder = orderFundMapper.selectById(order.getId());
|
||||
System.out.println(" - 验证查询结果: ID=" + verifyOrder.getId() +
|
||||
|
||||
// 清除可能的缓存,强制从数据库读取
|
||||
OrderFund verifyOrder = orderFundMapper.selectOne(
|
||||
new LambdaQueryWrapper<OrderFund>()
|
||||
.eq(OrderFund::getId, order.getId())
|
||||
.select(OrderFund::getId, OrderFund::getOrderNo, OrderFund::getStatus,
|
||||
OrderFund::getApproveAdminId, OrderFund::getApproveTime));
|
||||
|
||||
System.out.println(" - 验证查询结果: ID=" + verifyOrder.getId() +
|
||||
", 订单号=" + verifyOrder.getOrderNo() +
|
||||
", 状态=" + verifyOrder.getStatus());
|
||||
|
||||
|
||||
if (!verifyOrder.getStatus().equals(finalStatus)) {
|
||||
System.err.println("[FundService.approve] 警告: 订单状态更新后验证失败!");
|
||||
System.err.println("[FundService.approve] 严重错误: 订单状态更新后验证失败!");
|
||||
System.err.println(" - 期望状态: " + finalStatus);
|
||||
System.err.println(" - 实际状态: " + verifyOrder.getStatus());
|
||||
throw new RuntimeException("订单状态更新失败,请检查数据库配置");
|
||||
} else {
|
||||
System.out.println(" - 状态验证通过 ✓");
|
||||
}
|
||||
} else {
|
||||
System.err.println("[FundService.approve] 订单更新失败! updateById返回: " + orderUpdateResult);
|
||||
System.err.println("[FundService.approve] 订单更新失败! update返回: " + orderUpdateResult);
|
||||
throw new RuntimeException("订单更新失败");
|
||||
}
|
||||
|
||||
System.out.println("[审批完成] 订单号: " + orderNo + ", 订单类型: " + (order.getType() == 1 ? "充值" : "提现") +
|
||||
|
||||
@@ -41,6 +41,18 @@ mybatis-plus:
|
||||
# 打印 SQL 日志(开发环境)
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
# 日志配置
|
||||
logging:
|
||||
level:
|
||||
root: INFO
|
||||
com.it.rattan.monisuo: DEBUG
|
||||
com.it.rattan.monisuo.mapper: DEBUG
|
||||
org.springframework.jdbc: DEBUG
|
||||
org.springframework.transaction: DEBUG
|
||||
org.mybatis: DEBUG
|
||||
pattern:
|
||||
console: "%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n"
|
||||
|
||||
bean-searcher:
|
||||
packages: com.it.rattan.monisuo
|
||||
params:
|
||||
|
||||
Reference in New Issue
Block a user