package com.usky.iot;



import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
import com.usky.iot.constant.constant;
import io.swagger.annotations.SwaggerDefinition;
import lombok.val;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.impl.WxMpMapConfigImpl;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 系统模块
 * 
 * @author ruoyi
 */

//@EnableSwagger2
@EnableCustomSwagger2
@EnableFeignClients(basePackages = "com.usky")
@MapperScan(value = "com.usky.iot.mapper")
@ComponentScan("com.usky")
@SpringBootApplication
//开启异步
//@EnableAsync
//@EnableRabbit
public class RuoYiSystemApplication
{
    private static final Logger LOGGER = LoggerFactory.getLogger(RuoYiSystemApplication.class);

    @Bean
    public WxMpService wxMpService(){
        WxMpMapConfigImpl wxMpMapConfig = new WxMpMapConfigImpl();
        wxMpMapConfig.setAppId(constant.WE_CHAT_APP_ID);
        wxMpMapConfig.setSecret(constant.WE_CHAT_SECRET);
        val wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxMpMapConfig);

        return wxMpService;
    }

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(RuoYiSystemApplication.class, args);
        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        LOGGER.info("\n----------------------------------------------------------\n\t" +
                "Application is running! Access URLs:\n\t" +
                "Local: \t\thttp://localhost:" + port + (null==path?"":path) + "/\n\t" +
                "External: \thttp://" + ip + ":" + port + (null==path?"":path) + "/\n\t" +
                "Api: \t\thttp://" + ip + ":" + port + (null==path?"":path) + "/swagger-ui/index.html\n\t" +
                "----------------------------------------------------------");
    }
}
