From dc5be7d38446f70e6ff86df311119c32b41fe7f8 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期六, 28 十一月 2020 16:37:05 +0800 Subject: [PATCH] 大淘客搜索接口升级 --- fanli/src/main/java/com/yeshi/fanli/service/impl/push/OPPOPushServiceImpl.java | 136 +++++++++++++++++++++++---------------------- 1 files changed, 69 insertions(+), 67 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 index 4712110..cac79b3 100644 --- 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 @@ -1,13 +1,12 @@ 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 java.util.*; import javax.annotation.Resource; +import com.yeshi.fanli.dto.push.PushBaseContent; +import com.yeshi.fanli.entity.SystemEnum; +import com.yeshi.fanli.util.Constant; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -15,21 +14,21 @@ 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.DeviceTokenHWService; +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 DeviceTokenHWService deviceTokenHWService; + private DeviceTokenOPPOService deviceTokenOPPOService; @Resource private AppVersionService appVersionService; @@ -37,10 +36,10 @@ @Resource private UserCustomSettingsService userCustomSettingsService; - private List<Integer> getVersionCodeList(List<Integer> versionCodeList) { + private List<Integer> getVersionCodeList(List<Integer> versionCodeList,SystemEnum system) { List<Integer> versionList = new ArrayList<>(); if (versionCodeList == null) {// 鍏ㄦ帹 - List<AppVersionInfo> appInfoList = appVersionService.listByPlatformAndMinVersionCode("android", 49); + List<AppVersionInfo> appInfoList = appVersionService.listByPlatformAndMinVersionCode("android", 51,system); if (appInfoList != null) for (AppVersionInfo version : appInfoList) { versionList.add(version.getVersionCode()); @@ -48,7 +47,7 @@ } else {// 鎸夌増鏈帹閫� for (Integer versionCode : versionCodeList) { - if (versionCode.intValue() >= 49) {// 2.0.1寮�濮嬫敮鎸� + if (versionCode.intValue() >= 51) {// 2.0.1寮�濮嬫敮鎸� versionList.add(versionCode); } } @@ -58,59 +57,63 @@ @Async("pushExecutor") @Override - public void pushGoods(Long uid, Long auctionId, String title, String content, List<Integer> versionCodeList) + public void pushGoods(Long uid, Long auctionId, PushBaseContent baseContent) throws PushException { - push(PushTypeEnum.goodsdetail, uid, title, content, null, null, auctionId, versionCodeList); + push(PushTypeEnum.goodsdetail, uid, null, null, auctionId, baseContent); } @Async("pushExecutor") @Override - public void pushUrl(Long uid, String url, String title, String content, List<Integer> versionCodeList) + public void pushUrl(Long uid, String url, PushBaseContent baseContent) throws PushException { - push(PushTypeEnum.url, uid, title, content, null, url, null, versionCodeList); + push(PushTypeEnum.url, uid, null, url, null, baseContent); } @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); + public void pushZNX(Long uid, PushBaseContent baseContent) throws PushException { + push(PushTypeEnum.ZNX, uid, null, null, null, baseContent); } @Async("pushExecutor") @Override - public void pushWEEX(Long uid, String title, String content, String weexUrl, List<Integer> versionCodeList) + public void pushWEEX(Long uid,String weexUrl, PushBaseContent baseContent) throws PushException { - push(PushTypeEnum.weex, uid, title, content, weexUrl, null, null, versionCodeList); + push(PushTypeEnum.weex, uid, weexUrl, null, null, baseContent); } @Async("pushExecutor") @Override - public void pushBaiChuanUrl(Long uid, String title, String content, String url, List<Integer> versionCodeList) + public void pushBaiChuanUrl(Long uid,String url, PushBaseContent baseContent) throws PushException { - - push(PushTypeEnum.baichuan, uid, title, content, null, url, null, versionCodeList); + push(PushTypeEnum.baichuan, uid, null, url, null, baseContent); } @Async("pushExecutor") @Override - public void pushWelfareCenter(Long uid, String title, String content, List<Integer> versionCodeList) + public void pushWelfareCenter(Long uid, PushBaseContent baseContent) throws PushException { - push(PushTypeEnum.welfare, uid, title, content, null, null, null, versionCodeList); + push(PushTypeEnum.welfare, uid, null, null, null, baseContent); } @Override - public void pushUserSignInNotification(Long uid, String title, String content, List<Integer> versionCodeList) + public void pushUserSignInNotification(Long uid, PushBaseContent baseContent) throws PushException { - push(PushTypeEnum.signin, uid, title, content, null, null, null, versionCodeList); + push(PushTypeEnum.signin, uid, null, null, null, baseContent); } - private List<DeviceTokenHW> filterDeviceToken(List<DeviceTokenHW> hwDeviceList, int hour) { + private List<DeviceTokenOPPO> filterDeviceToken(List<DeviceTokenOPPO> deviceList, int hour) { + + // TODO 娑堟伅鍏嶆墦鎵板叧闂� + if (1 > 0) + return deviceList; + // 澶勭悊娑堟伅鍏嶆墦鎵� if (hour >= 20 || hour < 8) { Set<Long> uidSets = new HashSet<>(); - for (DeviceTokenHW dt : hwDeviceList) - if (dt.getUser() != null) - uidSets.add(dt.getUser().getId()); + 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, @@ -121,14 +124,13 @@ uidSets.add(seeting.getUserInfo().getId()); } if (uidSets.size() > 0) - for (int i = 0; i < hwDeviceList.size(); i++) { - if (hwDeviceList.get(i).getUser() != null - && uidSets.contains(hwDeviceList.get(i).getUser().getId())) { - hwDeviceList.remove(i--); + for (int i = 0; i < deviceList.size(); i++) { + if (deviceList.get(i).getUid() != null && uidSets.contains(deviceList.get(i).getUid())) { + deviceList.remove(i--); } } } - return hwDeviceList; + return deviceList; } /** @@ -136,16 +138,14 @@ * * @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 { + private void push(PushTypeEnum type, Long uid, String url, String webUrl, + Long goodsId,PushBaseContent content) throws PushException { int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); - List<Integer> newVersionList = getVersionCodeList(versionCodeList); + List<Integer> newVersionList = getVersionCodeList(content.getVersionCodeList(),content.getSystem()); // 1.6.5鍚庡紑濮嬫帹閫� for (int i = 0; i < newVersionList.size(); i++) { if (newVersionList.get(i) < 47) @@ -153,38 +153,40 @@ } if (uid == null || uid == 0) { - long deviceCount = deviceTokenHWService.countDeviceToken(newVersionList); - int page = (int) (deviceCount % 100 == 0 ? deviceCount / 100 : deviceCount / 100 + 1); + Date minUpdatetime=new Date(System.currentTimeMillis()- Constant.PUSH_MIN_TIME); + int pageSize = 200; + long deviceCount = deviceTokenOPPOService.countDeviceToken(newVersionList,minUpdatetime); + int page = (int) (deviceCount % pageSize == 0 ? deviceCount / pageSize : deviceCount / pageSize + 1); for (int p = 1; p <= page; p++) { - List<DeviceTokenHW> hwDeviceList = deviceTokenHWService.getDeviceTokenList(p, 100, newVersionList); - hwDeviceList = filterDeviceToken(hwDeviceList, hour); + List<DeviceTokenOPPO> deviceList = deviceTokenOPPOService.listDeviceToken(p, pageSize, newVersionList,minUpdatetime); + deviceList = filterDeviceToken(deviceList, hour); List<String> tokenList = new ArrayList<>(); - for (DeviceTokenHW token : hwDeviceList) - tokenList.add(token.getDeviceToken()); + for (DeviceTokenOPPO token : deviceList) + tokenList.add(token.getRegisterId()); try { if (type == PushTypeEnum.goodsdetail) {// 鍟嗗搧璇︽儏 if (goodsId == null) throw new PushException(2, "鍙傛暟涓嶅畬鏁�"); - HWPushUtil.pushGoods(tokenList, title, content, 1, goodsId); + OPPOPushUtil.pushGoods(tokenList, content.getTitle(), content.getContent(), 1, goodsId); } else if (type == PushTypeEnum.url) {// 閾炬帴 if (StringUtil.isNullOrEmpty(webUrl)) throw new PushException(2, "鍙傛暟涓嶅畬鏁�"); - HWPushUtil.pushUrl(tokenList, title, content, webUrl); + OPPOPushUtil.pushUrl(tokenList, content.getTitle(), content.getContent(), webUrl); } else if (type == PushTypeEnum.ZNX) {// 绔欏唴淇� - HWPushUtil.pushZNX(tokenList, title, content); + OPPOPushUtil.pushZNX(tokenList, content.getTitle(), content.getContent()); } else if (type == PushTypeEnum.weex) {// weex if (StringUtil.isNullOrEmpty(url)) throw new PushException(2, "鍙傛暟涓嶅畬鏁�"); - HWPushUtil.pushWEEX(tokenList, title, content, url); + OPPOPushUtil.pushWEEX(tokenList,content.getTitle(), content.getContent(), url); } else if (type == PushTypeEnum.baichuan) {// 鐧惧窛閾炬帴 if (StringUtil.isNullOrEmpty(webUrl)) throw new PushException(2, "鍙傛暟涓嶅畬鏁�"); - HWPushUtil.pushBaiChuanUrl(tokenList, title, content, webUrl); + OPPOPushUtil.pushBaiChuanUrl(tokenList,content.getTitle(), content.getContent(), webUrl); } else if (type == PushTypeEnum.welfare) {// 绂忓埄涓績 - HWPushUtil.pushWelfareCenter(tokenList, title, content); + OPPOPushUtil.pushWelfareCenter(tokenList,content.getTitle(), content.getContent()); } else if (type == PushTypeEnum.signin) {// 绛惧埌 - HWPushUtil.pushUserSignInNotification(tokenList, title, content); + OPPOPushUtil.pushUserSignInNotification(tokenList, content.getTitle(), content.getContent()); } } catch (Exception e) { PushLogHelper.hwError(e); @@ -193,12 +195,12 @@ } } else { // 鍗庝负鍗曟帹 - List<DeviceTokenHW> hwDeviceList = deviceTokenHWService.getDeviceTokenByUid(uid, newVersionList); + List<DeviceTokenOPPO> deviceList = deviceTokenOPPOService.listByUid(uid, newVersionList); List<String> tokenList = new ArrayList<>(); - if (hwDeviceList != null) { - hwDeviceList = filterDeviceToken(hwDeviceList, hour); - for (DeviceTokenHW token : hwDeviceList) - tokenList.add(token.getDeviceToken()); + if (deviceList != null) { + deviceList = filterDeviceToken(deviceList, hour); + for (DeviceTokenOPPO token : deviceList) + tokenList.add(token.getRegisterId()); } if (tokenList.size() == 0) return; @@ -207,28 +209,28 @@ if (type == PushTypeEnum.goodsdetail) {// 鍟嗗搧璇︽儏 if (goodsId == null) throw new PushException(2, "鍙傛暟涓嶅畬鏁�"); - HWPushUtil.pushGoods(tokenList, title, content, 1, goodsId); + OPPOPushUtil.pushGoods(tokenList, content.getTitle(), content.getContent(), 1, goodsId); } else if (type == PushTypeEnum.url) {// 閾炬帴 if (StringUtil.isNullOrEmpty(webUrl)) throw new PushException(2, "鍙傛暟涓嶅畬鏁�"); - HWPushUtil.pushUrl(tokenList, title, content, webUrl); + OPPOPushUtil.pushUrl(tokenList, content.getTitle(), content.getContent(), webUrl); } else if (type == PushTypeEnum.ZNX) {// 绔欏唴淇� - HWPushUtil.pushZNX(tokenList, title, content); + OPPOPushUtil.pushZNX(tokenList, content.getTitle(), content.getContent()); } else if (type == PushTypeEnum.weex) {// weex if (StringUtil.isNullOrEmpty(url)) throw new PushException(2, "鍙傛暟涓嶅畬鏁�"); - HWPushUtil.pushWEEX(tokenList, title, content, url); + OPPOPushUtil.pushWEEX(tokenList, content.getTitle(), content.getContent(), url); } else if (type == PushTypeEnum.baichuan) {// 鐧惧窛閾炬帴 if (StringUtil.isNullOrEmpty(webUrl)) throw new PushException(2, "鍙傛暟涓嶅畬鏁�"); - HWPushUtil.pushBaiChuanUrl(tokenList, title, content, webUrl); + OPPOPushUtil.pushBaiChuanUrl(tokenList, content.getTitle(), content.getContent(), webUrl); } else if (type == PushTypeEnum.welfare) {// 绂忓埄涓績 - HWPushUtil.pushWelfareCenter(tokenList, title, content); + OPPOPushUtil.pushWelfareCenter(tokenList, content.getTitle(), content.getContent()); } else if (type == PushTypeEnum.signin) {// 绛惧埌 - HWPushUtil.pushUserSignInNotification(tokenList, title, content); + OPPOPushUtil.pushUserSignInNotification(tokenList, content.getTitle(), content.getContent()); } } catch (Exception e) { - PushLogHelper.hwError(e); + PushLogHelper.oppoError(e); } } -- Gitblit v1.8.0