package com.ssj.service.sys.push.service.task;

import com.ssj.push.util.jiguang.MessagePushUtils;
import com.ssj.taskthread.Task;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * @author yangcan
 * 类描述:腾讯信鸽异步推送线程
 * 创建时间:2018年5月15日 下午5:06:36

 */
public class XingePushThreadTask extends Task{
	
	private String title; //极光id
	private String content; //推送内容
	private String androidToken; //信鸽token 安卓端
	private String iosToken; //信鸽token ios端
	private int platformType;//1:贝壳端 2:家长端 3:学生端 4:老师端 5:校长端
	private String messageType; //notify:通知栏消息 ,message:应用内/透传消息/静默消息
	private String sound; //推送声音
	private Map<String,Object> custom;//ios自定义下发的参数
	private int iosEnv = 2;//ios生产环境IOSENV_PROD = 1,ios开发环境 IOSENV_DEV = 2
    private int bagde = 0;//ios_app推送设置角标
	
	public XingePushThreadTask(String title, String content, String androidToken, String iosToken, int platformType,String messageType,String sound,Map<String,Object> custom,int iosEnv,int bagde) {
		super();
		this.title = title;
		this.content = content;
		this.androidToken = androidToken;
		this.iosToken = iosToken;
		this.platformType = platformType;
		this.messageType = messageType;
		this.sound = sound;
		this.custom = custom;
		this.iosEnv = iosEnv;	
		this.bagde = bagde;
	}

	public void run() {
		logger.error("信鸽异步开始推送---------------");
		try {
			if(StringUtils.isNotBlank(androidToken)) {
				MessagePushUtils.pushByAndroid(androidToken, title, content, platformType,messageType, custom);
			}
			if(StringUtils.isNotBlank(iosToken)) {
				MessagePushUtils.pushByIos(iosToken, content, platformType,sound,custom,iosEnv,bagde);
			}
		}catch (Exception e) {
			logger.error("腾讯信鸽推送异常...");
		}
		logger.error(Thread.currentThread().getName()+"信鸽异步结束推送---------------");
	}
}
