package cn.com.countrygarden.bi.main.service.project.Scheduling;

import cn.com.countrygarden.bi.main.constant.wcx.ApplicationContextRegister;
import cn.com.countrygarden.bi.main.dao.project.BiApplnoteMapper;
import cn.com.countrygarden.bi.main.dao.project.BiEmergencyMapper;
import cn.com.countrygarden.bi.main.service.common.CommService;
import cn.com.countrygarden.bi.main.service.dup.DupCommService;
import cn.com.countrygarden.bi.main.service.project.BiEmergencyService;
import cn.com.countrygarden.bi.main.util.AxisUtils;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
@Slf4j
@Configuration  
@EnableScheduling 
public class projectSchedu {
	@Autowired
    private CommService commService;
	@Autowired
	private DupCommService dupCommService;
	@Autowired
	private BiEmergencyService biEmergencyService;
	 @Autowired
	BiEmergencyMapper biEmergencyMapper;
	 @Autowired
	BiApplnoteMapper biApplnoteMapper;
	//http://bip.countrygarden.com.cn/sys/webservice/kmReviewThirdWebserviceService?wsdl		
	//http://ekptestv12.countrygarden.com.cn:8080/sys/webservice/kmReviewThirdWebserviceService?wsdl
	String  url = "http://bip.countrygarden.com.cn/sys/webservice/kmReviewThirdWebserviceService?wsdl";
	String metod = "getEmergencyReview";
	//String metod = "getCommunityReview";
	
	@Scheduled(cron = "0 0 0 * * ?")  
    public void test(){  
        System.out.println("项目预警定时器启动");  
        commService.warningLight();
        System.out.println("项目预警定时器结束"); 
    }  

	@Scheduled(cron = "0 */30 * * * ?") 
//	@Scheduled(cron="0/5 * *  * * ? ")
	public void dupOrg(){

        dupCommService.synchronizationOrg();
        System.out.println("地区同步结束"); 
    }  
	/** 
	 * bi突发事件
	 */
//	@Scheduled(cron="0/5 * *  * * ? ")
//	@Scheduled(cron = "0 */30 * * * ?") 
//@Scheduled(cron="0/5 * *  * * ? ")
	@Scheduled(cron = "0 0 3 * * ?")//每天两点执行定时调度
	public void emergency() {
		//查询调度时间.如果调度时间不存在则获取当前时间
		try {

			log.info("-------开始进入bi突发事件定时任务--------  ");
			//	TbDupContractTimedEmergency time = biEmergencyService.findDateStart();
			Object[] args = new Object[2];
			//	args[0] = sdate;
			//	args[1] = edate;
			//args[0] = time.getStartDate();
			//args[1] = time.getEndDate();
			String a = AxisUtils.callService(url, metod, args);
			System.out.println(a);
			Gson g = new Gson();
			cn.com.countrygarden.bi.main.service.project.impl.vo.outburst.Result r = g.fromJson(a, cn.com.countrygarden.bi.main.service.project.impl.vo.outburst.Result.class);
			BiEmergencyService bean= ApplicationContextRegister.getApplicationContext().getBean(BiEmergencyService.class);

			//	biEmergencyMapper.delete(null);
			//	biApplnoteMapper.delete(null);
			bean.json2Date(r.data);
			//dupCommService.synchronizationOrg();
			log.info("-------结束bi突发事件定时任务--------  ");
		} catch (Exception e) {
			log.error("", e);
		}
	}
}
