package com.xxl.job.executor.service.jobhandler;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.spacetech.gateway.BaseDataApiHub;
import com.spacetech.gateway.SqxyApiHub;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;


/**
 * 任务Handler示例（Bean模式）
 * 
 * 开发步骤：
 * 1、继承"IJobHandler"：“com.xxl.job.core.handler.IJobHandler”；
 * 2、注册到Spring容器：添加“@Component”注解，被Spring容器扫描为Bean实例；
 * 3、注册到执行器工厂：添加“@JobHandler(value="自定义jobhandler名称")”注解，注解value值对应的是调度中心新建任务的JobHandler属性的值。
 * 4、执行日志：需要通过 "XxlJobLogger.log" 打印执行日志；
 * 
 * @author xuxueli 2015-12-19 19:43:36
 */
@JobHandler(value="pushKcDateHandler")
@Component
public class PushKcDateHandler extends IJobHandler {

	private static Long SQXY_CAMPUSID = 3418L;
	private static Integer TYPE_TEACHER = 1;
	private static Integer TYPE_STUDENT = 2;
	
	@Autowired
	private SqxyApiHub sqxyApiHub;
	
	@Override
	public ReturnT<String> execute(String param) throws Exception {
		XxlJobLogger.log("XXL-JOB, Hello World.");
		
		String api = "sqxy_kcsj_push";

		XxlJobLogger.log(" start - 课程开课提醒接口调用启动;time:" + new Date());

		for (Integer type = TYPE_TEACHER; type <= TYPE_STUDENT; type++) {
			JSONObject params = new JSONObject();
			params.put("campusid", SQXY_CAMPUSID);
			
			sqxyApiHub.callApi(api.split("_")[1] + "_" + api.split("_")[2], false, params);
		}

		XxlJobLogger.log(" end -  课程开课提醒接口调用结束;time:" + new Date());
		return SUCCESS;
	}
	
}
