1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
@RestController @RequestMapping("/order-timeout") public class OrderTimeoutController { @Autowired private OrderTimeoutService orderTimeoutService; @Autowired private OrderStatusService orderStatusService;
@PostMapping("/process/{orderId}") public ResponseEntity<Map<String, Object>> processTimeoutOrder(@PathVariable Long orderId) { try { OrderTimeoutResult result = orderTimeoutService.processTimeoutOrder( orderRepository.findById(orderId).orElse(null)); Map<String, Object> response = new HashMap<>(); response.put("success", result.isSuccess()); response.put("action", result.getAction()); response.put("message", result.getMessage()); response.put("releasedResources", result.getReleasedResources()); return ResponseEntity.ok(response); } catch (Exception e) { log.error("手动处理超时订单失败: orderId={}", orderId, e); Map<String, Object> response = new HashMap<>(); response.put("success", false); response.put("message", "处理失败: " + e.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); } }
@PostMapping("/extend/{orderId}") public ResponseEntity<Map<String, Object>> extendOrderTimeout( @PathVariable Long orderId, @RequestParam int extendMinutes) { try { Order order = orderRepository.findById(orderId) .orElseThrow(() -> new BusinessException("订单不存在")); order.setTimeoutTime(order.getTimeoutTime().plusMinutes(extendMinutes)); orderRepository.save(order); Map<String, Object> response = new HashMap<>(); response.put("success", true); response.put("message", "订单超时时间延长成功"); response.put("newTimeoutTime", order.getTimeoutTime()); return ResponseEntity.ok(response); } catch (Exception e) { log.error("延长订单超时时间失败: orderId={}", orderId, e); Map<String, Object> response = new HashMap<>(); response.put("success", false); response.put("message", "延长失败: " + e.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); } }
@GetMapping("/timeout-orders") public ResponseEntity<Map<String, Object>> getTimeoutOrders( @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "20") int size) { try { List<Order> timeoutOrders = orderRepository.findTimeoutOrders( LocalDateTime.now().minusMinutes(30), size); Map<String, Object> response = new HashMap<>(); response.put("success", true); response.put("orders", timeoutOrders); response.put("total", timeoutOrders.size()); return ResponseEntity.ok(response); } catch (Exception e) { log.error("获取超时订单列表失败", e); Map<String, Object> response = new HashMap<>(); response.put("success", false); response.put("message", "获取失败: " + e.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); } }
@GetMapping("/records/{orderId}") public ResponseEntity<Map<String, Object>> getOrderTimeoutRecords(@PathVariable Long orderId) { try { List<OrderTimeoutRecord> records = timeoutRecordRepository.findByOrderId(orderId); Map<String, Object> response = new HashMap<>(); response.put("success", true); response.put("records", records); return ResponseEntity.ok(response); } catch (Exception e) { log.error("获取订单超时记录失败: orderId={}", orderId, e); Map<String, Object> response = new HashMap<>(); response.put("success", false); response.put("message", "获取失败: " + e.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); } } }
|