package com.ruoyi.web.controller;

import com.ruoyi.common.annotation.Dev;
import com.ruoyi.common.sse.SseApiSupport;
import com.ruoyi.common.sse.SseEmitter;
import com.ruoyi.common.utils.IdUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sse-test")
@Dev
@Slf4j
public class SseTestApi extends SseApiSupport {

  @PostMapping
  public SseEmitter getSseEmitter() {
    return handleSubscribe(null);
  }

  @Scheduled(fixedRate = 1000)
  public void rate() {
    String id = IdUtils.nextDateId("sse-test", 17);
//    log.info(id);
    sendAll(id);
  }
}
