package com.gaowj.service.jobs.identity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import static org.quartz.JobBuilder.newJob;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.gaowj.business.SystemOpeBusiness;
import com.gaowj.business.comp.BusinessManager;
import com.gaowj.business.util.Java_tool;
import com.gaowj.business.util.RequestUtils;
import com.gaowj.service.client.utils.httpClientPostData;
import com.gaowj.service.jobs.common.MainJob;
import com.jw.app.business.utils.QueryParamUtil;
import com.jw.app.pushData.util.PushDataUtils;

public class RemotePushUserJob extends MainJob{
	
	/**
	 * 人员/单位数据推送
	 * 2015-04-03
	 * 宁波金网
	 * 高伟杰
	 */
	public void execute(JobExecutionContext context) throws JobExecutionException {
		Java_tool  tool = new Java_tool();
		String startTime = tool.now_datetime();
		System.out.println("Job(RemotePushUserJob)--------------------start");
		PushDataUtils pushdata = new PushDataUtils();
		pushdata.PushData();
		System.out.println("Job(RemotePushUserJob)-----end(start:"+startTime+",end:"+tool.now_datetime()+")");
//		JobDataMap dataMap = context.getJobDetail().getJobDataMap();
//		String datasource = dataMap.getString("DATASOURCE");
//		if(datasource!=null && datasource.equals("ACTION")){
//			Map<String,Object> data = new HashMap<String,Object>();
//			data.put("ID_NUMBER", dataMap.get("ID_NUMBER"));data.put("USER_NAME", dataMap.get("USER_NAME"));
//			data.put("UNIT_ID", dataMap.get("UNIT_ID"));    data.put("MOBILE", dataMap.get("MOBILE"));
//			data.put("USER_SEX", dataMap.get("USER_SEX"));  data.put("ORDER_ID", dataMap.get("ORDER_ID"));
//			data.put("EMAIL", dataMap.get("EMAIL"));        data.put("IP", dataMap.get("IP"));
//			data.put("TELEPHONE", dataMap.get("TELEPHONE"));data.put("CARD_TYPE", dataMap.get("CARD_TYPE"));
//			data.put("CARD_ID", dataMap.get("CARD_ID"));    data.put("TECHNIC", dataMap.get("TECHNIC"));
//			data.put("IS_SFZB", dataMap.get("IS_SFZB"));    data.put("ZBLB", dataMap.get("ZBLB"));
//			data.put("POST", dataMap.get("POST"));          data.put("BEGIN_TIME", "DATE_"+dataMap.get("BEGIN_TIME"));
//			data.put("IS_ACTIVE", dataMap.get("IS_ACTIVE"));data.put("REMARK", dataMap.get("REMARK"));
//			data.put("UPDATE_TIME", "DATE_"+dataMap.get("UPDATE_TIME"));
//			data.put("DELETE_FLAG", dataMap.get("DELETE_FLAG"));
//			List<Map<String,Object>> listData = new ArrayList<Map<String,Object>>();
//			listData.add(data);
//			JSONObject jsonObject = new JSONObject();
//			jsonObject.putAll(data);
//			String jsondata = jsonObject.toString();
//			//获取要推送人员数据的单位
//			SystemOpeBusiness business = BusinessManager.getBusiness(SystemOpeBusiness.class);
//			Map<String,Object> query = new HashMap<String,Object>();
//			query.put("ISPUSH", "1");
//			List<Map<String, Object>> s_user = business.listLoginServiceUserInfo(query);
//			for(Map<String, Object> s:s_user){
//				httpClientPostData myhttp = new httpClientPostData();
//				String ret = myhttp.requestSystem((String)s.get("PUSH_LOGIN_URL"),(String)s.get("PUSH_NAME"), (String)s.get("PUSH_PASS"), jsondata, (String)s.get("PUSH_URL"), (String)s.get("PUSH_ENCODE"));
//				System.out.println(ret);
//				if(ret.contains("成功")){
//					System.out.println("成功");
//				}else{
//					System.out.println("失败");
//					//把数据存到推送失败的临时表里
//				}
//			}
//			//
//		}else{
//			//启用quartz任务执行此job
//		}
	}
	
//	 private void pushData(String isaction, Map<String, Object> data) {//其它地方调用此job,传参方式
//		    SchedulerBusiness businessSche = QrtzManager.getSchedulerBusiness("scheduler1");
//		    JobDataMap dataMap = new JobDataMap();
//		    dataMap.put("DATASOURCE", isaction);
//		    dataMap.put("ID_NUMBER", data.get("ID_NUMBER")); dataMap.put("USER_NAME", data.get("USER_NAME"));
//		    dataMap.put("UNIT_ID", data.get("UNIT_ID")); dataMap.put("MOBILE", data.get("MOBILE"));
//		    dataMap.put("USER_SEX", data.get("USER_SEX")); dataMap.put("ORDER_ID", data.get("ORDER_ID"));
//		    dataMap.put("EMAIL", data.get("EMAIL")); dataMap.put("IP", data.get("IP"));
//		    dataMap.put("TELEPHONE", data.get("TELEPHONE")); dataMap.put("CARD_TYPE", data.get("CARD_TYPE"));
//		    dataMap.put("CARD_ID", data.get("CARD_ID")); dataMap.put("TECHNIC", data.get("TECHNIC"));
//		    dataMap.put("IS_SFZB", data.get("IS_SFZB")); dataMap.put("ZBLB", data.get("ZBLB"));
//		    dataMap.put("POST", data.get("POST")); dataMap.put("BEGIN_TIME", data.get("BEGIN_TIME"));
//		    dataMap.put("IS_ACTIVE", data.get("IS_ACTIVE")); dataMap.put("REMARK", data.get("REMARK"));
//		    dataMap.put("UPDATE_TIME", data.get("UPDATE_TIME"));
//		    dataMap.put("DELETE_FLAG", data.get("DELETE_FLAG"));
//		    businessSche.schedule(new RemotePushUserJob().getClass().getName(), "nbjwGroup", new RemotePushUserJob(), dataMap, DateBuilder.evenMinuteDate(new Date()), null, 0, 0);
//		    businessSche.start();
//		  }
}
