代码优化

This commit is contained in:
yanglei 2026-02-27 14:22:34 +08:00
parent 05d06d1286
commit 754848d33c

View File

@ -83,7 +83,7 @@ import static com.cdzy.user.model.entity.table.EbikeRefundTableDef.EBIKE_REFUND;
public class EbikeOrderServiceImpl extends ServiceImpl<EbikeOrderMapper, EbikeOrder> implements EbikeOrderService { public class EbikeOrderServiceImpl extends ServiceImpl<EbikeOrderMapper, EbikeOrder> implements EbikeOrderService {
@Resource @Resource
private EbikeOrderMapper ebikeOrderTransactionMapper; private EbikeOrderMapper orderMapper;
@Resource @Resource
private OperationsFeignClient operationsFeignClient; private OperationsFeignClient operationsFeignClient;
@ -103,7 +103,7 @@ public class EbikeOrderServiceImpl extends ServiceImpl<EbikeOrderMapper, EbikeOr
Long userId = orderDto.getUserId(); Long userId = orderDto.getUserId();
String bikeCode = orderDto.getBikeCode(); String bikeCode = orderDto.getBikeCode();
// 校验用户当前是否存在订单 // 校验用户当前是否存在订单
EbikeOrder history = checkExitHistoryOrder(userId); EbikeOrder history = checkExistHistoryOrder(userId);
if (Objects.nonNull(history)) { if (Objects.nonNull(history)) {
if (history.getOrderStatus() == OrderStatus.IN_PROGRESS) { if (history.getOrderStatus() == OrderStatus.IN_PROGRESS) {
throw new EbikeException("请完成当前订单后再试"); throw new EbikeException("请完成当前订单后再试");
@ -402,7 +402,7 @@ public class EbikeOrderServiceImpl extends ServiceImpl<EbikeOrderMapper, EbikeOr
QueryWrapper queryWrapper = QueryWrapper.create() QueryWrapper queryWrapper = QueryWrapper.create()
.where(EBIKE_ORDER.BIKE_CODE.eq(dto.getBikeCode())) .where(EBIKE_ORDER.BIKE_CODE.eq(dto.getBikeCode()))
.where(EBIKE_ORDER.ORDER_STATUS.eq(OrderStatus.IN_PROGRESS)); .where(EBIKE_ORDER.ORDER_STATUS.eq(OrderStatus.IN_PROGRESS));
EbikeOrder order = ebikeOrderTransactionMapper.selectOneByQuery(queryWrapper); EbikeOrder order = orderMapper.selectOneByQuery(queryWrapper);
if (Objects.isNull(order)) { if (Objects.isNull(order)) {
throw new EbikeException("当前车辆不存在骑行订单"); throw new EbikeException("当前车辆不存在骑行订单");
} }
@ -600,18 +600,19 @@ public class EbikeOrderServiceImpl extends ServiceImpl<EbikeOrderMapper, EbikeOr
.where(EBIKE_ORDER.BIKE_CODE.eq(endDto.getBikeCode())) .where(EBIKE_ORDER.BIKE_CODE.eq(endDto.getBikeCode()))
.where(EBIKE_ORDER.USER_ID.eq(endDto.getUserId())) .where(EBIKE_ORDER.USER_ID.eq(endDto.getUserId()))
.where(EBIKE_ORDER.ORDER_STATUS.eq(OrderStatus.IN_PROGRESS)); .where(EBIKE_ORDER.ORDER_STATUS.eq(OrderStatus.IN_PROGRESS));
EbikeOrder userOrders = ebikeOrderTransactionMapper.selectOneByQuery(queryWrapper); EbikeOrder userOrders = orderMapper.selectOneByQuery(queryWrapper);
if (userOrders == null) { if (userOrders == null) {
throw new EbikeException("该订单不存在"); throw new EbikeException("该订单不存在");
} }
return userOrders; return userOrders;
} }
private EbikeOrder checkExitHistoryOrder(Long userId) { private EbikeOrder checkExistHistoryOrder(Long userId) {
QueryWrapper queryWrapper = QueryWrapper.create() QueryWrapper queryWrapper = QueryWrapper.create()
.where(EBIKE_ORDER.USER_ID.eq(userId)) .where(EBIKE_ORDER.USER_ID.eq(userId))
.where(EBIKE_ORDER.ORDER_STATUS.eq(OrderStatus.IN_PROGRESS).or(EBIKE_ORDER.ORDER_STATUS.eq(OrderStatus.PENDING_PAYMENT))); .where(EBIKE_ORDER.ORDER_STATUS.in(OrderStatus.IN_PROGRESS, OrderStatus.PENDING_PAYMENT))
return ebikeOrderTransactionMapper.selectOneByQuery(queryWrapper); .limit(1);
return orderMapper.selectOneByQuery(queryWrapper);
} }
/** /**