package com.java110.order;

import com.java110.common.factory.ApplicationContextFactory;
import com.java110.core.annotation.Java110ListenerDiscovery;
import com.java110.core.client.RestTemplate;
import com.java110.event.center.DataFlowEventPublishing;
import com.java110.order.smo.ICenterServiceCacheSMO;
import com.java110.service.init.ServiceStartInit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.StringHttpMessageConverter;

import java.nio.charset.Charset;


/**
 * spring boot 初始化启动类
 *
 * @version v0.1
 * @auther com.java110.wuxw
 * @mail 928255095@qq.com
 * @date 2016年8月6日
 * @tag
 */
@SpringBootApplication(scanBasePackages = {"com.java110.service", "com.java110.order",
        "com.java110.core", "com.java110.event.order", "com.java110.cache", "com.java110.db"})
@EnableDiscoveryClient
//@EnableConfigurationProperties(EventProperties.class)
@Java110ListenerDiscovery(listenerPublishClass = DataFlowEventPublishing.class,
        basePackages = {"com.java110.order.listener"})
@EnableFeignClients(basePackages = {"com.java110.core.smo"})
public class OrderServiceApplicationStart {

    private  static Logger logger = LoggerFactory.getLogger(OrderServiceApplicationStart.class);

    /**
     * 实例化RestTemplate，通过@LoadBalanced注解开启均衡负载能力.
     *
     * @return restTemplate
     */
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        StringHttpMessageConverter m = new StringHttpMessageConverter(Charset.forName("UTF-8"));
        RestTemplate restTemplate = new RestTemplateBuilder().additionalMessageConverters(m).build(RestTemplate.class);
        return restTemplate;
    }

    /**
     * 实例化RestTemplate
     *
     * @return restTemplate
     */
    @Bean
    public RestTemplate restTemplateNoLoadBalanced() {
        StringHttpMessageConverter m = new StringHttpMessageConverter(Charset.forName("UTF-8"));
        RestTemplate restTemplate = new RestTemplateBuilder().additionalMessageConverters(m).build(RestTemplate.class);
        return restTemplate;
    }

    public static void main(String[] args) throws Exception {
        ApplicationContext context = SpringApplication.run(OrderServiceApplicationStart.class, args);

        //服务启动加载
        ServiceStartInit.initSystemConfig(context);

        //加载事件数据
        //EventConfigInit.initSystemConfig();

        //刷新缓存
        flushMainCache(args);
    }


    /**
     * 刷新主要的缓存
     *
     * @param args
     */
    private static void flushMainCache(String[] args) {

        logger.debug("判断是否需要刷新日志，参数 args 为 {}", args);
        if (args == null || args.length == 0) {
            return;
        }
        for (int i = 0; i < args.length; i++) {
            if (args[i].equalsIgnoreCase("-Dcache")) {
                logger.debug("开始刷新日志，入参为：{}", args[i]);
                ICenterServiceCacheSMO centerServiceCacheSMO = (ICenterServiceCacheSMO) ApplicationContextFactory.getBean("centerServiceCacheSMOImpl");
                centerServiceCacheSMO.startFlush();
            }
        }
    }
}
@@ -17,24 +17,120 @@
 110.order;%0A%0A
+import com.java110.common.cache.MappingCache;%0Aimport com.java110.common.constant.DomainContant;%0A
 import com.j
@@ -174,24 +174,67 @@
 extFactory;%0A
+import com.java110.common.util.StringUtil;%0A
 import com.j
@@ -327,16 +327,59 @@
 mplate;%0A
+import com.java110.entity.mapping.Mapping;%0A
 import c
@@ -3250,24 +3250,436 @@
 %7B%7D%22, args);%0A
+%0A        //%E5%9B%A0%E4%B8%BA%E5%A5%BD%E5%A4%9A%E6%9C%8B%E5%8F%8B%E5%90%AF%E5%8A%A8%E6%97%B6 %E4%B8%8D%E5%8A%A0 %E5%8F%82%E6%95%B0-Dcache %E6%89%80%E4%BB%A5%E5%90%AF%E5%8A%A8%E6%97%B6%E6%A3%80%E6%B5%8B redis %E4%B8%AD%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8 java110_hc_version%0A        String mapping = MappingCache.getValue(%22java110_hc_version%22);%0A        if(StringUtil.isEmpty(mapping))%7B%0A            ICenterServiceCacheSMO centerServiceCacheSMO = (ICenterServiceCacheSMO) ApplicationContextFactory.getBean(%22centerServiceCacheSMOImpl%22);%0A            centerServiceCacheSMO.startFlush();%0A            return ;%0A        %7D%0A%0A
         if (

order 启动时判断 缓存中是否存在数据 如果没有数据直接刷新数据