取消订单

localizer
lzq 2025-10-17 17:33:23 +08:00
parent 802fcd5608
commit af1ff014cd
3 changed files with 31 additions and 6 deletions

View File

@ -195,8 +195,10 @@ public class OrderInfoController {
* @param orderId Id
*/
@GetMapping("/cancel")
public R<?> cancel(@RequestParam("orderId") Long orderId) {
orderInfoService.cancel(orderId);
public R<?> cancel(@RequestParam("orderId") Long orderId,
@RequestParam(value = "reason", required = false) String reason
) {
orderInfoService.cancel(orderId, reason);
return R.success();
}

View File

@ -140,6 +140,7 @@ public class OrderInfoEntity {
* ; order_status
*/
private OrderStatus orderStatus;
private String cancelReason;
/**
* Id; sys_user.id

View File

@ -841,25 +841,47 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
}
@Transactional(rollbackFor = Exception.class)
public void cancel(Long orderId) {
public void cancel(Long orderId, String reason) {
OrderInfoEntity orderInfo = this.getById(orderId);
Assert.notNull(orderInfo, () -> Exceptions.clierr("订单不存在"));
OrderStatus orderStatus = orderInfo.getOrderStatus();
Assert.isTrue(orderStatus == OrderStatus.YiYuYue
|| orderStatus == OrderStatus.DaiPaiDan
|| orderStatus == OrderStatus.DaiJieDan
|| orderStatus == OrderStatus.YiJieDan,
|| orderStatus == OrderStatus.YiJieDan
|| orderStatus == OrderStatus.QingYunZhong,
() -> Exceptions.clierr("当前订单状态,无法取消"));
AuditStatus auditStatus = orderInfo.getAuditStatus();
Assert.isFalse(auditStatus == AuditStatus.TongGuo, () -> Exceptions.clierr("当前订单状态,无法取消"));
if (!SecurityUtil.isAdmin()) {
Assert.isFalse(orderStatus == OrderStatus.QingYunZhong,
() -> Exceptions.clierr("当前订单状态,无法取消"));
AuditStatus auditStatus = orderInfo.getAuditStatus();
Assert.isFalse(auditStatus == AuditStatus.TongGuo, () -> Exceptions.clierr("当前订单状态,无法取消"));
}
this.updateById(new OrderInfoEntity()
.setId(orderInfo.getId())
.setCancelReason(reason)
.setOrderStatus(OrderStatus.YiQuXiao)
);
Long driverId = orderInfo.getDriverId();
Long truckId = orderInfo.getTruckId();
if (driverId != null) baseMapper.busyDriver(driverId, Boolean.FALSE);
if (truckId != null) baseMapper.busyTruck(truckId, Boolean.FALSE);
CompletableFuture.runAsync(() -> {
String licensePlate = null;
if (truckId != null) {
BizTruckEntity truckInfo = baseMapper.getTruckInfo(truckId);
licensePlate = truckInfo.getLicensePlate();
}
Websocket.publish(new WsMsg().setEvent("down/order/status_change")
.setData(MapUtil.builder()
.put("sn", orderInfo.getSn())
.put("licensePlate", licensePlate)
.put("orderStatus", OrderStatus.YiJinChang)
.build()));
}).exceptionally(e -> {
log.error("订单状态改变事件发布失败,订单{},状态{}", orderInfo.getSn(), OrderStatus.YiQuXiao, e);
return null;
});
// TODO 关闭 GPS 定位
CompletableFuture.runAsync(() -> {
if (truckId == null) {