From 3c1f04d76fdd1f60bd78696f8a1aac6dafbbb543 Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期三, 25 九月 2019 11:35:36 +0800
Subject: [PATCH] Merge branch 'div' of ssh://193.112.35.168:29418/fanli-server into div

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/push/OPPOPushServiceImpl.java |  238 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 238 insertions(+), 0 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/push/OPPOPushServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/push/OPPOPushServiceImpl.java
new file mode 100644
index 0000000..d31cd66
--- /dev/null
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/push/OPPOPushServiceImpl.java
@@ -0,0 +1,238 @@
+package com.yeshi.fanli.service.impl.push;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.annotation.Resource;
+
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+
+import com.yeshi.fanli.dto.push.PushTypeEnum;
+import com.yeshi.fanli.entity.AppVersionInfo;
+import com.yeshi.fanli.entity.bus.user.UserCustomSettings;
+import com.yeshi.fanli.entity.bus.user.UserCustomSettings.UserSettingTypeEnum;
+import com.yeshi.fanli.entity.push.DeviceTokenHW;
+import com.yeshi.fanli.entity.push.DeviceTokenOPPO;
+import com.yeshi.fanli.exception.push.PushException;
+import com.yeshi.fanli.log.PushLogHelper;
+import com.yeshi.fanli.service.inter.config.AppVersionService;
+import com.yeshi.fanli.service.inter.push.DeviceTokenOPPOService;
+import com.yeshi.fanli.service.inter.push.OPPOPushService;
+import com.yeshi.fanli.service.inter.user.UserCustomSettingsService;
+import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.util.push.HWPushUtil;
+import com.yeshi.fanli.util.push.OPPOPushUtil;
+
+@Service
+public class OPPOPushServiceImpl implements OPPOPushService {
+
+	@Resource
+	private DeviceTokenOPPOService deviceTokenOPPOService;
+
+	@Resource
+	private AppVersionService appVersionService;
+
+	@Resource
+	private UserCustomSettingsService userCustomSettingsService;
+
+	private List<Integer> getVersionCodeList(List<Integer> versionCodeList) {
+		List<Integer> versionList = new ArrayList<>();
+		if (versionCodeList == null) {// 鍏ㄦ帹
+			List<AppVersionInfo> appInfoList = appVersionService.listByPlatformAndMinVersionCode("android", 49);
+			if (appInfoList != null)
+				for (AppVersionInfo version : appInfoList) {
+					versionList.add(version.getVersionCode());
+				}
+
+		} else {// 鎸夌増鏈帹閫�
+			for (Integer versionCode : versionCodeList) {
+				if (versionCode.intValue() >= 49) {// 2.0.1寮�濮嬫敮鎸�
+					versionList.add(versionCode);
+				}
+			}
+		}
+		return versionList;
+	}
+
+	@Async("pushExecutor")
+	@Override
+	public void pushGoods(Long uid, Long auctionId, String title, String content, List<Integer> versionCodeList)
+			throws PushException {
+		push(PushTypeEnum.goodsdetail, uid, title, content, null, null, auctionId, versionCodeList);
+	}
+
+	@Async("pushExecutor")
+	@Override
+	public void pushUrl(Long uid, String url, String title, String content, List<Integer> versionCodeList)
+			throws PushException {
+		push(PushTypeEnum.url, uid, title, content, null, url, null, versionCodeList);
+	}
+
+	@Async("pushExecutor")
+	@Override
+	public void pushZNX(Long uid, String title, String content, List<Integer> versionCodeList) throws PushException {
+		push(PushTypeEnum.ZNX, uid, title, content, null, null, null, versionCodeList);
+	}
+
+	@Async("pushExecutor")
+	@Override
+	public void pushWEEX(Long uid, String title, String content, String weexUrl, List<Integer> versionCodeList)
+			throws PushException {
+		push(PushTypeEnum.weex, uid, title, content, weexUrl, null, null, versionCodeList);
+	}
+
+	@Async("pushExecutor")
+	@Override
+	public void pushBaiChuanUrl(Long uid, String title, String content, String url, List<Integer> versionCodeList)
+			throws PushException {
+
+		push(PushTypeEnum.baichuan, uid, title, content, null, url, null, versionCodeList);
+	}
+
+	@Async("pushExecutor")
+	@Override
+	public void pushWelfareCenter(Long uid, String title, String content, List<Integer> versionCodeList)
+			throws PushException {
+		push(PushTypeEnum.welfare, uid, title, content, null, null, null, versionCodeList);
+	}
+
+	@Override
+	public void pushUserSignInNotification(Long uid, String title, String content, List<Integer> versionCodeList)
+			throws PushException {
+		push(PushTypeEnum.signin, uid, title, content, null, null, null, versionCodeList);
+	}
+
+	private List<DeviceTokenOPPO> filterDeviceToken(List<DeviceTokenOPPO> deviceList, int hour) {
+		// 澶勭悊娑堟伅鍏嶆墦鎵�
+		if (hour >= 20 || hour < 8) {
+			Set<Long> uidSets = new HashSet<>();
+			for (DeviceTokenOPPO dt : deviceList)
+				if (dt.getUid() != null)
+					uidSets.add(dt.getUid());
+			List<Long> uidList = new ArrayList<>();
+			uidList.addAll(uidSets);
+			List<UserCustomSettings> settingList = userCustomSettingsService.listByUidListAndTypeAndState(uidList,
+					UserSettingTypeEnum.cancelNotice.name(), UserCustomSettings.STATE_VALID);
+			uidSets.clear();
+			if (settingList != null) {
+				for (UserCustomSettings seeting : settingList)
+					uidSets.add(seeting.getUserInfo().getId());
+			}
+			if (uidSets.size() > 0)
+				for (int i = 0; i < deviceList.size(); i++) {
+					if (deviceList.get(i).getUid() != null && uidSets.contains(deviceList.get(i).getUid())) {
+						deviceList.remove(i--);
+					}
+				}
+		}
+		return deviceList;
+	}
+
+	/**
+	 * 鎺ㄩ��
+	 * 
+	 * @param type
+	 * @param uid
+	 * @param title
+	 * @param content
+	 * @param url
+	 * @param webUrl
+	 * @param versionCodeList
+	 */
+	private void push(PushTypeEnum type, Long uid, String title, String content, String url, String webUrl,
+			Long goodsId, List<Integer> versionCodeList) throws PushException {
+		int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
+		List<Integer> newVersionList = getVersionCodeList(versionCodeList);
+		// 1.6.5鍚庡紑濮嬫帹閫�
+		for (int i = 0; i < newVersionList.size(); i++) {
+			if (newVersionList.get(i) < 47)
+				newVersionList.remove(i--);
+		}
+
+		if (uid == null || uid == 0) {
+			int pageSize = 200;
+			long deviceCount = deviceTokenOPPOService.countDeviceToken(newVersionList);
+			int page = (int) (deviceCount % pageSize == 0 ? deviceCount / pageSize : deviceCount / pageSize + 1);
+			for (int p = 1; p <= page; p++) {
+				List<DeviceTokenOPPO> deviceList = deviceTokenOPPOService.listDeviceToken(p, pageSize, newVersionList);
+				deviceList = filterDeviceToken(deviceList, hour);
+
+				List<String> tokenList = new ArrayList<>();
+				for (DeviceTokenOPPO token : deviceList)
+					tokenList.add(token.getRegisterId());
+				try {
+					if (type == PushTypeEnum.goodsdetail) {// 鍟嗗搧璇︽儏
+						if (goodsId == null)
+							throw new PushException(2, "鍙傛暟涓嶅畬鏁�");
+						OPPOPushUtil.pushGoods(tokenList, title, content, 1, goodsId);
+					} else if (type == PushTypeEnum.url) {// 閾炬帴
+						if (StringUtil.isNullOrEmpty(webUrl))
+							throw new PushException(2, "鍙傛暟涓嶅畬鏁�");
+						OPPOPushUtil.pushUrl(tokenList, title, content, webUrl);
+					} else if (type == PushTypeEnum.ZNX) {// 绔欏唴淇�
+						OPPOPushUtil.pushZNX(tokenList, title, content);
+					} else if (type == PushTypeEnum.weex) {// weex
+						if (StringUtil.isNullOrEmpty(url))
+							throw new PushException(2, "鍙傛暟涓嶅畬鏁�");
+						OPPOPushUtil.pushWEEX(tokenList, title, content, url);
+					} else if (type == PushTypeEnum.baichuan) {// 鐧惧窛閾炬帴
+						if (StringUtil.isNullOrEmpty(webUrl))
+							throw new PushException(2, "鍙傛暟涓嶅畬鏁�");
+						OPPOPushUtil.pushBaiChuanUrl(tokenList, title, content, webUrl);
+					} else if (type == PushTypeEnum.welfare) {// 绂忓埄涓績
+						OPPOPushUtil.pushWelfareCenter(tokenList, title, content);
+					} else if (type == PushTypeEnum.signin) {// 绛惧埌
+						OPPOPushUtil.pushUserSignInNotification(tokenList, title, content);
+					}
+				} catch (Exception e) {
+					PushLogHelper.hwError(e);
+				}
+
+			}
+		} else {
+			// 鍗庝负鍗曟帹
+			List<DeviceTokenOPPO> deviceList = deviceTokenOPPOService.listByUid(uid, newVersionList);
+			List<String> tokenList = new ArrayList<>();
+			if (deviceList != null) {
+				deviceList = filterDeviceToken(deviceList, hour);
+				for (DeviceTokenOPPO token : deviceList)
+					tokenList.add(token.getRegisterId());
+			}
+			if (tokenList.size() == 0)
+				return;
+
+			try {
+				if (type == PushTypeEnum.goodsdetail) {// 鍟嗗搧璇︽儏
+					if (goodsId == null)
+						throw new PushException(2, "鍙傛暟涓嶅畬鏁�");
+					OPPOPushUtil.pushGoods(tokenList, title, content, 1, goodsId);
+				} else if (type == PushTypeEnum.url) {// 閾炬帴
+					if (StringUtil.isNullOrEmpty(webUrl))
+						throw new PushException(2, "鍙傛暟涓嶅畬鏁�");
+					OPPOPushUtil.pushUrl(tokenList, title, content, webUrl);
+				} else if (type == PushTypeEnum.ZNX) {// 绔欏唴淇�
+					OPPOPushUtil.pushZNX(tokenList, title, content);
+				} else if (type == PushTypeEnum.weex) {// weex
+					if (StringUtil.isNullOrEmpty(url))
+						throw new PushException(2, "鍙傛暟涓嶅畬鏁�");
+					OPPOPushUtil.pushWEEX(tokenList, title, content, url);
+				} else if (type == PushTypeEnum.baichuan) {// 鐧惧窛閾炬帴
+					if (StringUtil.isNullOrEmpty(webUrl))
+						throw new PushException(2, "鍙傛暟涓嶅畬鏁�");
+					OPPOPushUtil.pushBaiChuanUrl(tokenList, title, content, webUrl);
+				} else if (type == PushTypeEnum.welfare) {// 绂忓埄涓績
+					OPPOPushUtil.pushWelfareCenter(tokenList, title, content);
+				} else if (type == PushTypeEnum.signin) {// 绛惧埌
+					OPPOPushUtil.pushUserSignInNotification(tokenList, title, content);
+				}
+			} catch (Exception e) {
+				PushLogHelper.oppoError(e);
+			}
+
+		}
+	}
+}

--
Gitblit v1.8.0