package com.bonus.tcp;

import com.bonus.common.security.annotation.EnableCustomConfig;
import com.bonus.common.security.annotation.EnableRyFeignClients;
import com.bonus.common.swagger.annotation.EnableCustomSwagger2;
import com.bonus.tcp.server.server.BootNettyServer;
import com.bonus.tcp.warn.DevWarnImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.scheduling.annotation.Async;

@EnableCustomConfig
@EnableCustomSwagger2
@EnableRyFeignClients
@SpringBootApplication(exclude = MongoAutoConfiguration.class)
public class BonusTcpApplication implements CommandLineRunner {//实现CommandLineRunner


    @Value("${tcp.server.port}")
    private  int port;

    @Value("${dev.video.ip}")
    private  String videIp;

    @Value("${dev.video.port}")
    private  int videPort;

    @Value("${dev.video.username}")
    private  String username;

    @Value("${dev.video.pwd}")
    private  String pwd;

    @Value("${dev.video.msgId}")
    private  String msgId;
    public static void main(String[] args) {
        SpringApplication.run(BonusTcpApplication.class, args);
        System.err.println("(♥◠‿◠)ﾉﾞ  TCP模块启动成功   ლ(´ڡ`ლ)ﾞ");
    }


    //异步方法
    @Async
    @Override
    public void run(String... args) throws Exception {
        clientDevWarn();
        new BootNettyServer().bind(port);
    }

    /**
     * 创建链接数据推送接口
     * @throws Exception
     */
    public void  clientDevWarn() throws Exception {
        DevWarnImpl client = new DevWarnImpl();
        client.setLog(false);
        client.setHost(videIp);
        client.setPort(videPort);
        client.setUserName(username);
        client.setPwd(pwd);
        client.setSubMsgIds(msgId);
        client.setDesc("测试客户端");
        client.start();

    }



}