package com.yeshi.fanli.service.impl.push;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.stereotype.Service;
|
|
import com.yeshi.fanli.controller.admin.PushController;
|
import com.yeshi.fanli.entity.bus.user.AccountMessage;
|
import com.yeshi.fanli.entity.push.DeviceTokenHW;
|
import com.yeshi.fanli.entity.system.SystemZnx;
|
import com.yeshi.fanli.entity.xinge.MessageInfo;
|
import com.yeshi.fanli.entity.xinge.PushRecord;
|
import com.yeshi.fanli.exception.PushException;
|
import com.yeshi.fanli.log.PushLogHelper;
|
import com.yeshi.fanli.service.inter.push.DeviceTokenHWService;
|
import com.yeshi.fanli.service.inter.push.HWPushService;
|
import com.yeshi.fanli.util.Constant;
|
import com.yeshi.fanli.util.ThreadUtil;
|
import com.yeshi.fanli.util.push.HWPushUtil;
|
|
import net.sf.json.JSONObject;
|
|
@Service
|
public class HWPushServiceImpl implements HWPushService {
|
|
@Resource
|
private DeviceTokenHWService deviceTokenHWService;
|
|
@Async("pushExecutor")
|
@Override
|
public void pushGoods(Long uid, Long auctionId, String title, String content, String versions)
|
throws PushException {
|
if (1 > 0)
|
return;
|
String gid = auctionId + "";
|
JSONObject json = new JSONObject();
|
json.put("url", "");
|
json.put("id", gid);
|
json.put("type", "goodsdetail");
|
json.put("miPushUrl", String.format("%s.ui.recommend.GoodsBrowserActivity",
|
Constant.systemCommonConfig.getAndroidBaseactivityName()));
|
if (uid == null || uid == 0) {
|
// 华为全推送 --暂时设置推送100000用户
|
List<DeviceTokenHW> hwDeviceList = deviceTokenHWService.getDeviceTokenList(1, 100000);
|
ThreadUtil.run(new Runnable() {
|
@Override
|
public void run() {
|
while (hwDeviceList != null && hwDeviceList.size() > 0) {
|
List<String> deviceTokens = new ArrayList<>();
|
if (hwDeviceList.size() > 10000) {
|
List<DeviceTokenHW> pushList = hwDeviceList.subList(0, 1000);
|
for (DeviceTokenHW DeviceTokenHW : pushList) {
|
deviceTokens.add(DeviceTokenHW.getDeviceToken());
|
hwDeviceList.remove(DeviceTokenHW);
|
}
|
} else {
|
for (DeviceTokenHW DeviceTokenHW : hwDeviceList) {
|
deviceTokens.add(DeviceTokenHW.getDeviceToken());
|
hwDeviceList.remove(DeviceTokenHW);
|
}
|
}
|
try {
|
HWPushUtil.pushGoods(deviceTokens, title, content, 1, Long.parseLong(gid));
|
} catch (Exception e) {
|
PushLogHelper.hwError(e);
|
}
|
}
|
}
|
});
|
} else {
|
// 华为单推
|
List<DeviceTokenHW> hwDeviceList = deviceTokenHWService.getDeviceTokenByUid(uid);
|
if (hwDeviceList != null && hwDeviceList.size() > 0) {
|
List<String> deviceList = new ArrayList<>();
|
for (DeviceTokenHW dt : hwDeviceList)
|
deviceList.add(dt.getDeviceToken());
|
try {
|
HWPushUtil.pushGoods(deviceList, title, content, 1, Long.parseLong(gid));
|
} catch (Exception e) {
|
PushLogHelper.hwError(e);
|
}
|
}
|
}
|
}
|
|
@Async("pushExecutor")
|
@Override
|
public void pushUrl(Long uid, String url, String title, String content, String versions) throws PushException {
|
if (1 > 0)
|
return;
|
JSONObject json = new JSONObject();
|
json.put("url", url);
|
json.put("type", "url");
|
json.put("webUrl", url);
|
json.put("miPushUrl",
|
String.format("%s.ui.BrowserActivity", Constant.systemCommonConfig.getAndroidBaseactivityName()));
|
|
MessageInfo info = new MessageInfo();
|
info.setTitle(title);
|
info.setContent(content);
|
info.setDescription(content);
|
// 小米推送网页
|
info.setPackageName(Constant.systemCommonConfig.getAndroidPackageName());
|
info.setActivty(
|
String.format("%s.ui.BrowserActivity", Constant.systemCommonConfig.getAndroidBaseactivityName()));
|
|
PushRecord pushRecord = new PushRecord();
|
pushRecord.setState(1);
|
pushRecord.setType(PushController.URL);
|
pushRecord.setUrl(url);
|
pushRecord.setTitle(title);
|
pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName());
|
|
// 华为全推送 --暂时设置推送100000用户
|
if (uid == null || uid == 0) {
|
List<DeviceTokenHW> hwDeviceList = deviceTokenHWService.getDeviceTokenList(1, 100000);
|
ThreadUtil.run(new Runnable() {
|
@Override
|
public void run() {
|
while (hwDeviceList != null && hwDeviceList.size() > 0) {
|
List<String> deviceTokens = new ArrayList<>();
|
if (hwDeviceList.size() > 1000) {
|
List<DeviceTokenHW> pushList = hwDeviceList.subList(0, 1000);
|
for (DeviceTokenHW DeviceTokenHW : pushList) {
|
deviceTokens.add(DeviceTokenHW.getDeviceToken());
|
hwDeviceList.remove(DeviceTokenHW);
|
}
|
} else {
|
for (DeviceTokenHW DeviceTokenHW : hwDeviceList) {
|
deviceTokens.add(DeviceTokenHW.getDeviceToken());
|
hwDeviceList.remove(DeviceTokenHW);
|
}
|
}
|
try {
|
HWPushUtil.pushUrl(deviceTokens, title, content, url);
|
} catch (Exception e) {
|
PushLogHelper.hwError(e);
|
}
|
}
|
}
|
});
|
} else {
|
// 华为单推
|
List<DeviceTokenHW> hwDeviceList = deviceTokenHWService.getDeviceTokenByUid(uid);
|
if (hwDeviceList != null && hwDeviceList.size() > 0) {
|
List<String> deviceList = new ArrayList<>();
|
for (DeviceTokenHW dt : hwDeviceList)
|
deviceList.add(dt.getDeviceToken());
|
try {
|
HWPushUtil.pushUrl(deviceList, title, content, url);
|
} catch (Exception e) {
|
PushLogHelper.hwError(e);
|
}
|
}
|
}
|
}
|
|
@Async("pushExecutor")
|
@Override
|
public void pushZNX(Long uid, AccountMessage msg, SystemZnx systemZNX, String versions) throws PushException {
|
if (1 > 0)
|
return;
|
JSONObject contentJson = new JSONObject();
|
contentJson.put("isOpen", 0);
|
contentJson.put("createTime", java.lang.System.currentTimeMillis());
|
|
if (systemZNX != null) {
|
// 华为全推送 --暂时设置推送10000用户
|
List<DeviceTokenHW> hwDeviceList = deviceTokenHWService.getDeviceTokenList(1, 10000);
|
ThreadUtil.run(new Runnable() {
|
@Override
|
public void run() {
|
while (hwDeviceList != null && hwDeviceList.size() > 0) {
|
List<String> deviceTokens = new ArrayList<>();
|
if (hwDeviceList.size() > 1000) {
|
List<DeviceTokenHW> pushList = hwDeviceList.subList(0, 1000);
|
for (DeviceTokenHW DeviceTokenHW : pushList) {
|
deviceTokens.add(DeviceTokenHW.getDeviceToken());
|
hwDeviceList.remove(DeviceTokenHW);
|
}
|
} else {
|
for (DeviceTokenHW DeviceTokenHW : hwDeviceList) {
|
deviceTokens.add(DeviceTokenHW.getDeviceToken());
|
hwDeviceList.remove(DeviceTokenHW);
|
}
|
}
|
try {
|
HWPushUtil.pushZNX(deviceTokens, systemZNX.getTitle(), systemZNX.getContent());
|
} catch (Exception e) {
|
PushLogHelper.hwError(e);
|
}
|
}
|
}
|
});
|
|
} else if (msg != null) {
|
// 华为单推
|
List<DeviceTokenHW> hwDeviceList = deviceTokenHWService.getDeviceTokenByUid(uid);
|
if (hwDeviceList != null && hwDeviceList.size() > 0) {
|
List<String> deviceList = new ArrayList<>();
|
for (DeviceTokenHW dt : hwDeviceList)
|
deviceList.add(dt.getDeviceToken());
|
try {
|
HWPushUtil.pushZNX(deviceList, msg.getTitle(), msg.getContent());
|
} catch (Exception e) {
|
PushLogHelper.hwError(e);
|
}
|
}
|
}
|
}
|
|
@Async("pushExecutor")
|
@Override
|
public void pushWEEX(Long uid, String title, String content, String weexUrl, String versions) throws PushException {
|
// TODO 推送weex页面
|
|
}
|
|
@Async("pushExecutor")
|
@Override
|
public void pushBaiChuanUrl(Long uid, String title, String content, String url, String versions)
|
throws PushException {
|
// TODO 推送淘客百川链接
|
|
}
|
|
@Async("pushExecutor")
|
@Override
|
public void pushWelfareCenter(Long uid, String title, String content, String versions) throws PushException {
|
// TODO Auto-generated method stub
|
|
}
|
|
}
|