fix(DeadlineOrderJob): 优化逾期商品处理逻辑并添加用户姓名显示

使用 UpdateWrapper 替代直接更新实体来清除商品关联,确保字段正确设置为 null
在逾期通知和日志中添加用户姓名信息,提高可追溯性
This commit is contained in:
dzq 2025-07-21 15:02:30 +08:00
parent 9e9b3a5cb5
commit 3ee313b1a3
1 changed files with 9 additions and 5 deletions

View File

@ -19,6 +19,7 @@ import com.agileboot.domain.shop.order.db.ShopOrderService;
import com.agileboot.domain.shop.paymentOperationLog.PaymentOperationLogApplicationService;
import com.agileboot.domain.shop.paymentOperationLog.command.AddPaymentOperationLogCommand;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
@ -136,9 +137,12 @@ public class DeadlineOrderJob {
shopOrderGoodsService.updateById(orderGoods); // 更新数据库
// 2. 将商品从智能柜格口下架
cabinetCell.setGoodsId(null); // 清除关联商品ID
cabinetCell.setUsageStatus(1); // 使用状态改为1-空闲
cabinetCellService.updateById(cabinetCell); // 更新数据库
// 使用 UpdateWrapper 更新字段为 null
UpdateWrapper<CabinetCellEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("cell_id", cabinetCell.getCellId()); // 根据格口 ID 确定更新记录
updateWrapper.set("goods_id", null); // 设置商品 ID null
updateWrapper.set("usage_status", 1); // 设置使用状态为 1-空闲
cabinetCellService.update(updateWrapper); // 执行更新操作
log.info("成功处理逾期商品订单商品ID[{}]状态更新为已逾期并从格口ID[{}]下架。", orderGoods.getOrderGoodsId(), cabinetCell.getCellId());
@ -175,7 +179,7 @@ public class DeadlineOrderJob {
paymentOperationLogCommand.setOperationType("DeadlineOrder");
paymentOperationLogCommand.setStatus(1);
paymentOperationLogCommand.setRemark(
String.format("逾期订单商品:订单号[%s], 商品ID[%s], 名称[%s]。创建时间[%s], 归还期限[%s天], 截止日期[%s].",
String.format("逾期订单商品:用户姓名[%s], 订单号[%s], 商品ID[%s], 名称[%s]。创建时间[%s], 归还期限[%s天], 截止日期[%s].", order.getName(),
order.getOrderId(), orderGoods.getOrderGoodsId(), orderGoods.getGoodsName(), DateUtil.formatDateTime(order.getCreateTime()), returnDeadlineDays, DateUtil.formatDateTime(deadlineDate)));
paymentOperationLogCommand.initBaseEntity();
paymentOperationLogApplicationService.addPaymentOperationLog(paymentOperationLogCommand);
@ -196,7 +200,7 @@ public class DeadlineOrderJob {
List<NewsArticle> articles = new ArrayList<>();
NewsArticle article = new NewsArticle();
article.setTitle("逾期商品自动下架通知");
article.setDescription(String.format("订单号: %s, 商品名称: %s, 创建时间: %s, 归还期限: %s天, 截止日期: %s",
article.setDescription(String.format("用户姓名: %s, 订单号: %s, 商品名称: %s, 创建时间: %s, 归还期限: %s天, 截止日期: %s", order.getName(),
order.getOrderId(), orderGoods.getGoodsName(), DateUtil.formatDateTime(order.getCreateTime()), returnDeadlineDays, DateUtil.formatDateTime(deadlineDate)));
article.setPicurl(orderGoods.getCoverImg());
article.setUrl("http://wxshop.ab98.cn/shop-api/api/shop/qy/wechatAuth");