package com.unis.detectionnum.server;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.net.ServerSocket;
import java.util.Date;

@EnableFeignClients(basePackages = "com.unis")
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
@EnableDiscoveryClient
@EnableScheduling
@ComponentScan("com.unis")
@MapperScan("com.unis.detectionnum.server.dao")
@EnableAsync
@Slf4j
public class DetectionnumApplication 
{
    public static void main( String[] args )
    {
    	SpringApplication.run(DetectionnumApplication.class, args);
        System.out.println("-----------------------------启动成功--------------------------");
    }

    @Bean(name = "serverSocket")
    @Order
    public ServerSocket serverSocket(){
        ServerSocket server = null;
        try {
            log.info(new Date().toString() + "***开启监听扫描端口***");
            server = new ServerSocket(8899);
            //超过10秒没有连接返回数据自动断开连接
//            server.setSoTimeout(20000);
        }catch (Exception e){
            e.printStackTrace();
            log.error("监听扫描端口失败:"+e.getMessage());
        }
        return  server;
    }
}
