package com.ssj.service.conch.common.service.impl;

import com.alibaba.fastjson.JSON;
import com.ssj.framework.core.util.SystemResourceLocator;
import com.ssj.push.util.jiguang.MessagePushUtils;
import com.ssj.service.conch.common.service.AppCommonService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service
@Transactional
public class AppCommonServiceImpl implements AppCommonService{



	@Override
	public void pushAllBySystemMessage(String type, String title) {
		Map<String, Object> custom = new HashMap<String, Object>();
		custom.put("type", "SYSTEM_MESSAGE");
		custom.put("time", new Date());
		Map<String, Object> map2 = new HashMap<String, Object>();
		map2.put("title", title);
		custom.put("data", map2);
		//系统消息推送所有设备
		//推送所有安卓端
		//推送所有ios端
		String sysEnv = (String) SystemResourceLocator.getValue("SYS_ENV");
        String content = JSON.toJSONString(custom);
		switch (Integer.parseInt(type)) {
		case 0:
			//所有端
			//信鸽各端定义 2:家长端 3:学生端 4:老师端 5:校长端
			//家长端
			MessagePushUtils.pushAllByAndroid("私塾家", content, 2, "message");
			MessagePushUtils.pushAllByIosAPNS(title, 2, null, custom, Integer.valueOf(sysEnv));
			
			//学生端
			MessagePushUtils.pushAllByAndroid("私塾家", content, 3, "message");
			MessagePushUtils.pushAllByIosAPNS(title, 3, null, custom, Integer.valueOf(sysEnv));
			
			//老师端
			MessagePushUtils.pushAllByAndroid("私塾家", content, 4, "message");
			MessagePushUtils.pushAllByIosAPNS(title, 4, null, custom, Integer.valueOf(sysEnv));
			
			//校长端
			MessagePushUtils.pushAllByAndroid("私塾家", content, 5, "message");
			MessagePushUtils.pushAllByIosAPNS(title, 5, null, custom, Integer.valueOf(sysEnv));
			break;
		case 1:
			//学生端
			MessagePushUtils.pushAllByAndroid("私塾家", content, 3, "message");
			MessagePushUtils.pushAllByIosAPNS(title, 3, null, custom, Integer.valueOf(sysEnv));
			break;
		case 2:
			//家长端
			MessagePushUtils.pushAllByAndroid("私塾家", content, 2, "message");
			MessagePushUtils.pushAllByIosAPNS(title, 2, null, custom, Integer.valueOf(sysEnv));
			break;
		case 3:
			//老师端
			MessagePushUtils.pushAllByAndroid("私塾家", content, 4, "message");
			MessagePushUtils.pushAllByIosAPNS(title, 4, null, custom, Integer.valueOf(sysEnv));
			break;
		case 4:
			//校长端
			MessagePushUtils.pushAllByAndroid("私塾家", content, 5, "message");
			MessagePushUtils.pushAllByIosAPNS(title, 5, null, custom, Integer.valueOf(sysEnv));
			break;
		default:
			break;
		}
	}

}
