package cn.pluss.platform.user.impl;

import cn.pluss.platform.user.UserPushIdService;
import cn.pluss.platform.user.UserPushService;
import cn.pluss.platform.util.GetuiPushUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 推送服务类，目前只接入个推
 * @author djh
 */
@Service
public class UserPushServiceImpl implements UserPushService {

    @Autowired
    private UserPushIdService userPushIdService;

    @Override
    public void push(String notificationTitle, String msgContent, String extrasParam, Long... alias) {
        List<String> cidList = userPushIdService.getGetuiCidListByUserIds(alias);
        GetuiPushUtil.getInstance().sendAllPlatByAlias(cidList, notificationTitle, msgContent, extrasParam);
    }

    @Override
    public void push(String notificationTitle, String msgContent, String extrasParam, List<Long> alias) {
        Long[] aliasArr = new Long[alias.size()];
        for (int i = 0; i < alias.size(); i++) {
            aliasArr[i] = alias.get(i);
        }

        List<String> cidList = userPushIdService.getGetuiCidListByUserIds(aliasArr);
        GetuiPushUtil.getInstance().sendAllPlatByAlias(cidList, notificationTitle, msgContent, extrasParam);
    }

    @Override
    public void push(List<String> alias, String notificationTitle, String msgContent, String extrasParam) {
        Long[] aliasArr = new Long[alias.size()];
        for (int i = 0; i < alias.size(); i++) {
            aliasArr[i] = Long.parseLong(alias.get(i));
        }

        List<String> cidList = userPushIdService.getGetuiCidListByUserIds(aliasArr);
        if (!cidList.isEmpty()) {
            GetuiPushUtil.getInstance().sendAllPlatByAlias(cidList, notificationTitle, msgContent, extrasParam);
        }
    }
}
