package com.chinaweal.aiccs;

import com.chinaweal.aiccs.aiccs.abnormal.service.CreatePdfService;
import com.chinaweal.aiccs.aiccs.abnormal.service.IGzaiccodeService;
import com.chinaweal.aiccs.aiccs.entbase.service.TREntPriseTypeService;
import com.chinaweal.aiccs.aiccs.system.service.TRBaseCodeService;
import com.chinaweal.aiccs.crgs.system.service.TDataTypeCodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.data.solr.repository.config.EnableSolrRepositories;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * 启动类
 */
@Slf4j
@EnableSolrRepositories(basePackages = {"com.chinaweal.solr","com.chinaweal.aiccs.aiccs.claim",})
@EnableAsync
@SpringBootApplication(scanBasePackages = {"com.chinaweal"})
public class AiccsApplication extends SpringBootServletInitializer implements ApplicationListener<ContextRefreshedEvent> {
    @Value("${applicationName}")
    private String applicationName;
    @Value("${version}")
    private String version;
    @Value("${description}")
    private String description;

    @Autowired
    private TREntPriseTypeService entPriseTypeService;
    @Autowired
    private TRBaseCodeService baseCodeService;
    @Autowired
    private TDataTypeCodeService tDataTypeCodeService;
    @Autowired
    private CreatePdfService createPdfService;
    @Autowired
    private IGzaiccodeService gzaiccodeService;

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) {
        return applicationBuilder.sources(AiccsApplication.class);
    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        if (event.getApplicationContext().getParent() == null) {
            log.info("========================== 程序启动成功！ ==========================");
            log.info("====== 程  序：{} ！", applicationName);
            log.info("====== 版本号：{} ", version);
            log.info("====== 描  述：{} ", description);
            log.info("====== 接口文档路径：/doc.html，账号：admin、密码：123456。注：如果乱码请指定VM -Dfile.encoding=UTF-8");
            log.info("====== Druid Monitor路径：/druid，账号：admin、密码：123456");
            log.info("====================================================================");
        }
        log.info("========================== 刷新缓存开始！ ==========================");
        entPriseTypeService.flushCache();
        baseCodeService.flushCache(null);
        tDataTypeCodeService.getDataTypeMapFormCache(null, true);
        gzaiccodeService.flushCache();
//        createPdfService.initPdfUtil();
        log.info("========================== 刷新缓存结束！ ==========================");
    }
    public static void main(String[] args) {
        SpringApplication.run(AiccsApplication.class, args);
    }
}
