package com.gic.haoban.manage.web.init;

import com.alibaba.fastjson.JSONObject;
import com.gic.commons.util.DateUtil;
import com.gic.quartz.api.dto.QuartzTaskDTO;
import com.gic.quartz.api.service.QuartzService;

import java.util.Calendar;
import java.util.Date;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class MyApplicationContextAware implements ApplicationContextAware {
    private Logger log = LogManager.getLogger(MyApplicationContextAware.class);

    private static ApplicationContext applicationContext;
    
    @Autowired
	private QuartzService quartzService; 

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		log.info("【定时开始】----------------------");
//		QuartzTaskDTO taskDTO = buildQuartzMessageDTO("haoban-message-status-time3");
//		taskDTO.setTaskParam("");
//		taskDTO.setTaskStatus(1);
//		taskDTO.setTaskTimeInfo("0 30 1 * * *");
////		taskDTO.setTaskTimeInfo("0 0/5 * * * *");
//		quartzService.addOrUpdateQuartzTask(taskDTO);
		
		/*QuartzTaskDTO memberExportTask =buildMemberExportQuartzTaskDTO("haoban-member-export3");
		memberExportTask.setTaskParam("-1");
		memberExportTask.setTaskStatus(1);
		memberExportTask.setTaskTimeInfo("0 0/15 * * * *");
		quartzService.addOrUpdateQuartzTask(memberExportTask);
		
		
		QuartzTaskDTO taskDTO = buildQuartzTaskDTO("hb-fresh-wx-friend");
		taskDTO.setTaskParam("-1");
		taskDTO.setTaskStatus(1);
		taskDTO.setTaskTimeInfo("0 0 4 * * *");
		quartzService.addOrUpdateQuartzTask(taskDTO);*/
	}
	
//	private QuartzTaskDTO buildQuartzMessageDTO(String id) {
//  	  QuartzTaskDTO taskDTO = new QuartzTaskDTO();
//        taskDTO.setReferId(id);
//        taskDTO.setTaskMethod("quartzUpdateMessageStatus");
//        taskDTO.setTaskService("com.gic.haoban.app.customer.service.api.service.MessageLogApiService");
//        return taskDTO;
//	}
	
	private QuartzTaskDTO buildQuartzTaskDTO(String id) {
	   	 QuartzTaskDTO taskDTO = new QuartzTaskDTO();
         taskDTO.setReferId(id);
         taskDTO.setTaskMethod("quartWxFriendClerk");
         taskDTO.setTaskService("com.gic.haoban.manage.api.service.DealSyncOperationApiService");
         return taskDTO;
	}

	 private QuartzTaskDTO buildMemberExportQuartzTaskDTO(String id) {
		 QuartzTaskDTO taskDTO = new QuartzTaskDTO();
         taskDTO.setReferId(id);
         taskDTO.setTaskMethod("quartzMemberExport");
         taskDTO.setTaskService("com.gic.haoban.app.customer.service.api.service.MemberExportApiService");
         return taskDTO;
	}
}
