| | |
| | | * @since 2025-01-XX |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/api/plcSend/task/notification") |
| | | @RequestMapping("task/notification") |
| | | @Api(tags = "任务状态通知") |
| | | @RequiredArgsConstructor |
| | | @CrossOrigin(origins = "*", maxAge = 3600) |
| | | public class TaskStatusNotificationController { |
| | | |
| | | private final TaskStatusNotificationService notificationService; |
| | | |
| | | @GetMapping(value = "/sse", produces = "text/event-stream") |
| | | @ApiOperation("创建SSE连接,监听任务状态变化") |
| | | @CrossOrigin(origins = "*") |
| | | public SseEmitter createConnection(@RequestParam(required = false) String taskId) { |
| | | SseEmitter emitter = notificationService.createConnection(taskId); |
| | | if (emitter == null) { |
| | |
| | | return emitter; |
| | | } |
| | | |
| | | @RequestMapping(value = "/sse", method = RequestMethod.OPTIONS) |
| | | @CrossOrigin(origins = "*") |
| | | public void options() { |
| | | // 处理 OPTIONS 预检请求 |
| | | } |
| | | |
| | | @GetMapping(value = "/sse/all", produces = "text/event-stream") |
| | | @ApiOperation("创建SSE连接,监听所有任务状态变化") |
| | | @CrossOrigin(origins = "*") |
| | | public SseEmitter createConnectionForAllTasks() { |
| | | return createConnection(null); |
| | | } |