package thyyxxk.webserver.config.springboot;


import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import thyyxxk.webserver.service.PublicServer;
import thyyxxk.webserver.service.externalhttp.ServerSrvc;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Slf4j
@Component
public class ServerStartupAndShutdown {

    private final ServerSrvc server;

    private final PublicServer publicServer;

    public ServerStartupAndShutdown(ServerSrvc server, PublicServer publicServer) {
        this.server = server;
        this.publicServer = publicServer;
    }


    /**
     * 每 30 分钟执行一次,发送消息
     */
    @Scheduled(cron = "0 0/30 * * * ?")
    public void sendAMessage() {
        publicServer.sendSystemAnnouncement();
    }

    @PostConstruct
    public void run() {
        try {
//            server.startServer();
        } catch (Exception ignored) {
        } finally {
            log.info("软件启动");
        }
    }

    @PreDestroy
    public void showdown() {
        try {
//            server.endServer();
        } catch (Exception ignored) {
        } finally {
            log.info("软件关闭");
        }
    }


}
