package com.chinacreator.process.job;

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

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.PersistJobDataAfterExecution;
import org.springframework.beans.factory.annotation.Autowired;

import com.chinacreator.common.util.URLUtil;
import com.chinacreator.process.dao.DictionaryDao;
import com.chinacreator.video.queue.MessageService;
import com.chinacreator.video.queue.bean.MessagePipe;

@PersistJobDataAfterExecution
@DisallowConcurrentExecution
public class HnSmsJob {

	private static Map<String,String> spMap = new HashMap<String, String>();
	
	@Autowired
	private DictionaryDao dictionaryDao;
	
	@Autowired
	private MessageService messageService;
	
	static{
		spMap.put("51", "斗牛直播定向流量包月（原WO+直播定向流量包月）");
		spMap.put("11", "WO+视频PPTV定向流量包月");
		spMap.put("6", "WO+视频腾讯定向流量包月");
		spMap.put("99119423", "WO+视频腾讯定向流量首免包月");
		spMap.put("1", "WO+视频搜狐定向流量包月");
		spMap.put("960", "WO+视频搜狐定向流量VIP包月");
		spMap.put("20", "WO+新视界包月");
		spMap.put("21132", "WO+乐视vip联通包月");
		spMap.put("43", "务工亲情卡WO+视频服务腾讯视频定向流量包月");
		spMap.put("42", "务工亲情卡WO+视频服务PPTV视频定向流量包月");
		spMap.put("74", "青年市场WO+视频三合一定向流量包月");
		spMap.put("21156", "优土联通包月");
		spMap.put("21160", "优土vip联通包月");
		spMap.put("21195", "WO+视频优酷特惠包");
	}
	
	private Logger log = Logger.getLogger("hnsmslog");
	
	public void doProcess() throws Exception {
		log.debug("海南短信发送");
		if(dictionaryDao.getValue("recivemq").equals("0")){
			List<MessagePipe> list = messageService
					.reciveBatchMessage("hnSmsSend", 500);
			for (MessagePipe messagePipe : list) {
				String result = "2";
				Map<String,Object> map = messagePipe.getBody();
				String userid = (String)map.get("userid");
				String spid = (String)map.get("spid");
				String cpid = (String)map.get("cpid");
				String status = (String)map.get("status");
				try{
				if(!StringUtils.isEmpty(spMap.get(spid))){
					String content  = "";
					if(status.equals("0")){
						content = "尊敬的用户，您好！您订购的"+spMap.get(spid)+"产品已经在合作方平台生效，请下载最新手机客户端，登录个人中心仔细阅读相关介绍后激活使用";
					}else{
						content = "尊敬的用户，您好！您发起"+spMap.get(spid)+"产品退订，已经在合作方平台退订成功";
					}
					 result = URLUtil.get("http://111.206.135.40:8080/sms-platform/sms?mob="+userid+"&content="+content, 10000);
				}
				}catch(Exception e){
					e.printStackTrace();
				}finally{
					log.info("{userid:"+userid+",cpid:"+cpid+",spid:"+spid+",status:"+status+",result:"+result+"}");
				}
			}
	}else{
		log.debug("海南短信发送队列停止接受");
	}
}
	
	public static void main(String[] args) {
		Map<String,String> spMap = new HashMap<String, String>();
		spMap.put("51", "斗牛直播定向流量包月（原WO+直播定向流量包月）");
		spMap.put("11", "WO+视频PPTV定向流量包月");
		spMap.put("6", "WO+视频腾讯定向流量包月");
		spMap.put("99119423", "WO+视频腾讯定向流量首免包月");
		spMap.put("1", "WO+视频搜狐定向流量包月");
		spMap.put("960", "WO+视频搜狐定向流量VIP包月");
		spMap.put("20", "WO+新视界包月");
		spMap.put("21132", "WO+乐视vip联通包月");
		spMap.put("43", "务工亲情卡WO+视频服务腾讯视频定向流量包月");
		spMap.put("42", "务工亲情卡WO+视频服务PPTV视频定向流量包月");
		spMap.put("74", "青年市场WO+视频三合一定向流量包月");
		spMap.put("21156", "优土联通包月");
		spMap.put("21160", "优土vip联通包月");
		spMap.put("21195", "WO+视频优酷特惠包");
		System.out.println(spMap.get("1"));
	}
}
