package com.yeejoin.amos;

import com.yeejoin.amos.boot.biz.common.utils.oConvertUtils;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

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

/**
 * <pre>
 * 特种设备服务启动类
 * </pre>
 *
 * @author DELL
 */
@SpringBootApplication
@EnableTransactionManagement
@EnableConfigurationProperties
@ServletComponentScan
@EnableDiscoveryClient
@EnableFeignClients
@EnableAsync
@EnableSwagger2WebMvc
@EnableEurekaClient
//@EnableScheduling
@MapperScan({ "org.typroject.tyboot.demo.face.orm.dao*", "org.typroject.tyboot.face.*.orm.dao*",
		"org.typroject.tyboot.core.auth.face.orm.dao*", "org.typroject.tyboot.component.*.face.orm.dao*",
		"com.yeejoin.amos.boot.module.**.api.mapper", "com.yeejoin.amos.boot.biz.common.dao.mapper" })
@ComponentScan(basePackages = { "org.typroject", "com.yeejoin.amos" })
public class AmosJczsApplication {
	private static final Logger logger = LoggerFactory.getLogger(AmosJczsApplication.class);
//	@Autowired
//	private EmqKeeper emqKeeper;
//
//	@Autowired
//	private CarcylUnitInspectMqTtlListener carcylUnitInspectMqTtlListener;
//
//	@Autowired
//	private BaseEnterpriseMqTtlListener baseEnterpriseMqTtlListener;
//
//	@Autowired
//	private StartPlatformTokenService startPlatformTokenService;
//
//	@Autowired
//	private PrivilegeCompanyUpdateAddListener privilegeCompanyUpdateAddListener;
//
//	@Autowired
//	private PrivilegeCompanyDeleteListener privilegeCompanyDeleteListener;
//
//	@Autowired
//	private FillingRecordSyncListener fillingRecordSyncListener;
//
//	@Autowired
//	private AmosMqttListener amosMqTtlListener;
//
//	@Autowired
//	ICylinderInfoService cylinderInfoServiceImpl;

	public static void main(String[] args) throws UnknownHostException {
		ConfigurableApplicationContext context = SpringApplication.run(AmosJczsApplication.class, args);
		Environment env = context.getEnvironment();
		String ip = InetAddress.getLocalHost().getHostAddress();
		String port = env.getProperty("server.port");
		String path = oConvertUtils.getString(env.getProperty("server.servlet.context-path"));

		logger.info("\n----------------------------------------------------------\n\t"
				+ "Application Amos-Biz-Boot is running! Access URLs:\n\t" + "Swagger文档: \thttp://" + ip + ":" + port
				+ path + "/doc.html\n" + "----------------------------------------------------------");
	}

	/**
	 * 初始化MQTT
	 * 
	 * @throws MqttException
	 */
//	@Bean
//	public void initMqtt() throws Exception {
//		emqKeeper.subscript("/idx/idx_biz_carcyl_unit_inspect", 2, carcylUnitInspectMqTtlListener);
//		emqKeeper.subscript("/tm/tz_base_enterprise_info", 2, baseEnterpriseMqTtlListener);
//		emqKeeper.subscript("/tz/privilege_company_add_update", 2, privilegeCompanyUpdateAddListener);
//		emqKeeper.subscript("/tz/privilege_company_delete", 2, privilegeCompanyDeleteListener);
//		emqKeeper.subscript("/tzs/sync/fillingRecord", 2, fillingRecordSyncListener);
//		emqKeeper.subscript("tzs/oneCodePass/deviceSave", 2, amosMqTtlListener);
////		emqKeeper.getMqttClient().subscribe("topic_mqtt_exam", 1, examMqTtlListener);
////		emqKeeper.getMqttClient().subscribe("topic_mqtt_exam_record", 1, examMqTtRecordListener);
//	}

//	@Bean
//	public void initToken() {
//		startPlatformTokenService.getToken();
//	}
}
