| | |
| | | |
| | | import com.yeshi.fanli.dto.push.PushBaseContent; |
| | | import com.yeshi.fanli.entity.SystemEnum; |
| | | import com.yeshi.fanli.entity.config.SystemConfigKeyEnum; |
| | | import com.yeshi.fanli.service.inter.config.SystemConfigService; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | @Service |
| | | public class OPPOPushServiceImpl implements OPPOPushService { |
| | | |
| | | @Resource |
| | | private DeviceTokenOPPOService deviceTokenOPPOService; |
| | | @Resource |
| | | private DeviceTokenOPPOService deviceTokenOPPOService; |
| | | |
| | | @Resource |
| | | private AppVersionService appVersionService; |
| | | @Resource |
| | | private AppVersionService appVersionService; |
| | | |
| | | @Resource |
| | | private UserCustomSettingsService userCustomSettingsService; |
| | | @Resource |
| | | private UserCustomSettingsService userCustomSettingsService; |
| | | |
| | | private List<Integer> getVersionCodeList(List<Integer> versionCodeList,SystemEnum system) { |
| | | List<Integer> versionList = new ArrayList<>(); |
| | | if (versionCodeList == null) {// 全推 |
| | | List<AppVersionInfo> appInfoList = appVersionService.listByPlatformAndMinVersionCode("android", 51,system); |
| | | if (appInfoList != null) |
| | | for (AppVersionInfo version : appInfoList) { |
| | | versionList.add(version.getVersionCode()); |
| | | } |
| | | @Resource |
| | | private SystemConfigService systemConfigService; |
| | | |
| | | } else {// 按版本推送 |
| | | for (Integer versionCode : versionCodeList) { |
| | | if (versionCode.intValue() >= 51) {// 2.0.1开始支持 |
| | | versionList.add(versionCode); |
| | | } |
| | | } |
| | | } |
| | | return versionList; |
| | | } |
| | | private List<Integer> getVersionCodeList(List<Integer> versionCodeList, SystemEnum system) { |
| | | List<Integer> versionList = new ArrayList<>(); |
| | | if (versionCodeList == null) {// 全推 |
| | | List<AppVersionInfo> appInfoList = appVersionService.listByPlatformAndMinVersionCode("android", 51, system); |
| | | if (appInfoList != null) |
| | | for (AppVersionInfo version : appInfoList) { |
| | | versionList.add(version.getVersionCode()); |
| | | } |
| | | |
| | | @Async("pushExecutor") |
| | | @Override |
| | | public void pushGoods(Long uid, Long auctionId, PushBaseContent baseContent) |
| | | throws PushException { |
| | | push(PushTypeEnum.goodsdetail, uid, null, null, auctionId, baseContent); |
| | | } |
| | | } else {// 按版本推送 |
| | | for (Integer versionCode : versionCodeList) { |
| | | if (versionCode.intValue() >= 51) {// 2.0.1开始支持 |
| | | versionList.add(versionCode); |
| | | } |
| | | } |
| | | } |
| | | return versionList; |
| | | } |
| | | |
| | | @Async("pushExecutor") |
| | | @Override |
| | | public void pushUrl(Long uid, String url, PushBaseContent baseContent) |
| | | throws PushException { |
| | | push(PushTypeEnum.url, uid, null, url, null, baseContent); |
| | | } |
| | | @Async("pushExecutor") |
| | | @Override |
| | | public void pushGoods(Long uid, String auctionId, PushBaseContent baseContent) |
| | | throws PushException { |
| | | push(PushTypeEnum.goodsdetail, uid, null, null, auctionId, baseContent); |
| | | } |
| | | |
| | | @Async("pushExecutor") |
| | | @Override |
| | | public void pushZNX(Long uid, PushBaseContent baseContent) throws PushException { |
| | | push(PushTypeEnum.ZNX, uid, null, null, null, baseContent); |
| | | } |
| | | @Async("pushExecutor") |
| | | @Override |
| | | public void pushUrl(Long uid, String url, PushBaseContent baseContent) |
| | | throws PushException { |
| | | push(PushTypeEnum.url, uid, null, url, null, baseContent); |
| | | } |
| | | |
| | | @Async("pushExecutor") |
| | | @Override |
| | | public void pushWEEX(Long uid,String weexUrl, PushBaseContent baseContent) |
| | | throws PushException { |
| | | push(PushTypeEnum.weex, uid, weexUrl, null, null, baseContent); |
| | | } |
| | | @Async("pushExecutor") |
| | | @Override |
| | | public void pushZNX(Long uid, PushBaseContent baseContent) throws PushException { |
| | | push(PushTypeEnum.ZNX, uid, null, null, null, baseContent); |
| | | } |
| | | |
| | | @Async("pushExecutor") |
| | | @Override |
| | | public void pushBaiChuanUrl(Long uid,String url, PushBaseContent baseContent) |
| | | throws PushException { |
| | | push(PushTypeEnum.baichuan, uid, null, url, null, baseContent); |
| | | } |
| | | @Async("pushExecutor") |
| | | @Override |
| | | public void pushWEEX(Long uid, String weexUrl, PushBaseContent baseContent) |
| | | throws PushException { |
| | | push(PushTypeEnum.weex, uid, weexUrl, null, null, baseContent); |
| | | } |
| | | |
| | | @Async("pushExecutor") |
| | | @Override |
| | | public void pushWelfareCenter(Long uid, PushBaseContent baseContent) |
| | | throws PushException { |
| | | push(PushTypeEnum.welfare, uid, null, null, null, baseContent); |
| | | } |
| | | @Async("pushExecutor") |
| | | @Override |
| | | public void pushBaiChuanUrl(Long uid, String url, PushBaseContent baseContent) |
| | | throws PushException { |
| | | push(PushTypeEnum.baichuan, uid, null, url, null, baseContent); |
| | | } |
| | | |
| | | @Override |
| | | public void pushUserSignInNotification(Long uid, PushBaseContent baseContent) |
| | | throws PushException { |
| | | push(PushTypeEnum.signin, uid, null, null, null, baseContent); |
| | | } |
| | | @Async("pushExecutor") |
| | | @Override |
| | | public void pushWelfareCenter(Long uid, PushBaseContent baseContent) |
| | | throws PushException { |
| | | push(PushTypeEnum.welfare, uid, null, null, null, baseContent); |
| | | } |
| | | |
| | | private List<DeviceTokenOPPO> filterDeviceToken(List<DeviceTokenOPPO> deviceList, int hour) { |
| | | @Override |
| | | public void pushUserSignInNotification(Long uid, PushBaseContent baseContent) |
| | | throws PushException { |
| | | push(PushTypeEnum.signin, uid, null, null, null, baseContent); |
| | | } |
| | | |
| | | // TODO 消息免打扰关闭 |
| | | if (1 > 0) |
| | | return deviceList; |
| | | 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; |
| | | } |
| | | // TODO 消息免打扰关闭 |
| | | if (1 > 0) |
| | | return deviceList; |
| | | |
| | | /** |
| | | * 推送 |
| | | * |
| | | * @param type |
| | | * @param uid |
| | | * @param content |
| | | * @param url |
| | | * @param webUrl |
| | | */ |
| | | 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(content.getVersionCodeList(),content.getSystem()); |
| | | // 1.6.5后开始推送 |
| | | for (int i = 0; i < newVersionList.size(); i++) { |
| | | if (newVersionList.get(i) < 47) |
| | | newVersionList.remove(i--); |
| | | } |
| | | // 处理消息免打扰 |
| | | 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; |
| | | } |
| | | |
| | | if (uid == null || uid == 0) { |
| | | 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<DeviceTokenOPPO> deviceList = deviceTokenOPPOService.listDeviceToken(p, pageSize, newVersionList,minUpdatetime); |
| | | deviceList = filterDeviceToken(deviceList, hour); |
| | | /** |
| | | * 推送 |
| | | * |
| | | * @param type |
| | | * @param uid |
| | | * @param content |
| | | * @param url |
| | | * @param webUrl |
| | | */ |
| | | private void push(PushTypeEnum type, Long uid, String url, String webUrl, |
| | | String goodsId, PushBaseContent content) throws PushException { |
| | | int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); |
| | | List<Integer> newVersionList = getVersionCodeList(content.getVersionCodeList(), content.getSystem()); |
| | | // 1.6.5后开始推送 |
| | | for (int i = 0; i < newVersionList.size(); i++) { |
| | | if (newVersionList.get(i) < 47) |
| | | newVersionList.remove(i--); |
| | | } |
| | | |
| | | 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, content.getTitle(), content.getContent(), 1, goodsId); |
| | | } else if (type == PushTypeEnum.url) {// 链接 |
| | | if (StringUtil.isNullOrEmpty(webUrl)) |
| | | throw new PushException(2, "参数不完整"); |
| | | OPPOPushUtil.pushUrl(tokenList, content.getTitle(), content.getContent(), webUrl); |
| | | } else if (type == PushTypeEnum.ZNX) {// 站内信 |
| | | OPPOPushUtil.pushZNX(tokenList, content.getTitle(), content.getContent()); |
| | | } else if (type == PushTypeEnum.weex) {// weex |
| | | if (StringUtil.isNullOrEmpty(url)) |
| | | throw new PushException(2, "参数不完整"); |
| | | OPPOPushUtil.pushWEEX(tokenList,content.getTitle(), content.getContent(), url); |
| | | } else if (type == PushTypeEnum.baichuan) {// 百川链接 |
| | | if (StringUtil.isNullOrEmpty(webUrl)) |
| | | throw new PushException(2, "参数不完整"); |
| | | OPPOPushUtil.pushBaiChuanUrl(tokenList,content.getTitle(), content.getContent(), webUrl); |
| | | } else if (type == PushTypeEnum.welfare) {// 福利中心 |
| | | OPPOPushUtil.pushWelfareCenter(tokenList,content.getTitle(), content.getContent()); |
| | | } else if (type == PushTypeEnum.signin) {// 签到 |
| | | OPPOPushUtil.pushUserSignInNotification(tokenList, content.getTitle(), content.getContent()); |
| | | } |
| | | } catch (Exception e) { |
| | | PushLogHelper.hwError(e); |
| | | } |
| | | String androidBaseActivity = systemConfigService.getValueCache(SystemConfigKeyEnum.androidBaseActivityName, content.getSystem()); |
| | | |
| | | } |
| | | } 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; |
| | | if (uid == null || uid == 0) { |
| | | 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<DeviceTokenOPPO> deviceList = deviceTokenOPPOService.listDeviceToken(p, pageSize, newVersionList, minUpdatetime); |
| | | deviceList = filterDeviceToken(deviceList, hour); |
| | | |
| | | try { |
| | | if (type == PushTypeEnum.goodsdetail) {// 商品详情 |
| | | if (goodsId == null) |
| | | throw new PushException(2, "参数不完整"); |
| | | OPPOPushUtil.pushGoods(tokenList, content.getTitle(), content.getContent(), 1, goodsId); |
| | | } else if (type == PushTypeEnum.url) {// 链接 |
| | | if (StringUtil.isNullOrEmpty(webUrl)) |
| | | throw new PushException(2, "参数不完整"); |
| | | OPPOPushUtil.pushUrl(tokenList, content.getTitle(), content.getContent(), webUrl); |
| | | } else if (type == PushTypeEnum.ZNX) {// 站内信 |
| | | OPPOPushUtil.pushZNX(tokenList, content.getTitle(), content.getContent()); |
| | | } else if (type == PushTypeEnum.weex) {// weex |
| | | if (StringUtil.isNullOrEmpty(url)) |
| | | throw new PushException(2, "参数不完整"); |
| | | OPPOPushUtil.pushWEEX(tokenList, content.getTitle(), content.getContent(), url); |
| | | } else if (type == PushTypeEnum.baichuan) {// 百川链接 |
| | | if (StringUtil.isNullOrEmpty(webUrl)) |
| | | throw new PushException(2, "参数不完整"); |
| | | OPPOPushUtil.pushBaiChuanUrl(tokenList, content.getTitle(), content.getContent(), webUrl); |
| | | } else if (type == PushTypeEnum.welfare) {// 福利中心 |
| | | OPPOPushUtil.pushWelfareCenter(tokenList, content.getTitle(), content.getContent()); |
| | | } else if (type == PushTypeEnum.signin) {// 签到 |
| | | OPPOPushUtil.pushUserSignInNotification(tokenList, content.getTitle(), content.getContent()); |
| | | } |
| | | } catch (Exception e) { |
| | | PushLogHelper.oppoError(e); |
| | | } |
| | | 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, content.getTitle(), content.getContent(), 1, goodsId,androidBaseActivity); |
| | | } else if (type == PushTypeEnum.url) {// 链接 |
| | | if (StringUtil.isNullOrEmpty(webUrl)) |
| | | throw new PushException(2, "参数不完整"); |
| | | OPPOPushUtil.pushUrl(tokenList, content.getTitle(), content.getContent(), webUrl,androidBaseActivity); |
| | | } else if (type == PushTypeEnum.ZNX) {// 站内信 |
| | | OPPOPushUtil.pushZNX(tokenList, content.getTitle(), content.getContent()); |
| | | } else if (type == PushTypeEnum.weex) {// weex |
| | | if (StringUtil.isNullOrEmpty(url)) |
| | | throw new PushException(2, "参数不完整"); |
| | | OPPOPushUtil.pushWEEX(tokenList, content.getTitle(), content.getContent(), url,androidBaseActivity); |
| | | } else if (type == PushTypeEnum.baichuan) {// 百川链接 |
| | | if (StringUtil.isNullOrEmpty(webUrl)) |
| | | throw new PushException(2, "参数不完整"); |
| | | OPPOPushUtil.pushBaiChuanUrl(tokenList, content.getTitle(), content.getContent(), webUrl); |
| | | } else if (type == PushTypeEnum.welfare) {// 福利中心 |
| | | OPPOPushUtil.pushWelfareCenter(tokenList, content.getTitle(), content.getContent(),androidBaseActivity); |
| | | } else if (type == PushTypeEnum.signin) {// 签到 |
| | | OPPOPushUtil.pushUserSignInNotification(tokenList, content.getTitle(), content.getContent(),androidBaseActivity); |
| | | } |
| | | } 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, content.getTitle(), content.getContent(), 1, goodsId,androidBaseActivity); |
| | | } else if (type == PushTypeEnum.url) {// 链接 |
| | | if (StringUtil.isNullOrEmpty(webUrl)) |
| | | throw new PushException(2, "参数不完整"); |
| | | OPPOPushUtil.pushUrl(tokenList, content.getTitle(), content.getContent(), webUrl,androidBaseActivity); |
| | | } else if (type == PushTypeEnum.ZNX) {// 站内信 |
| | | OPPOPushUtil.pushZNX(tokenList, content.getTitle(), content.getContent()); |
| | | } else if (type == PushTypeEnum.weex) {// weex |
| | | if (StringUtil.isNullOrEmpty(url)) |
| | | throw new PushException(2, "参数不完整"); |
| | | OPPOPushUtil.pushWEEX(tokenList, content.getTitle(), content.getContent(), url,androidBaseActivity); |
| | | } else if (type == PushTypeEnum.baichuan) {// 百川链接 |
| | | if (StringUtil.isNullOrEmpty(webUrl)) |
| | | throw new PushException(2, "参数不完整"); |
| | | OPPOPushUtil.pushBaiChuanUrl(tokenList, content.getTitle(), content.getContent(), webUrl); |
| | | } else if (type == PushTypeEnum.welfare) {// 福利中心 |
| | | OPPOPushUtil.pushWelfareCenter(tokenList, content.getTitle(), content.getContent(),androidBaseActivity); |
| | | } else if (type == PushTypeEnum.signin) {// 签到 |
| | | OPPOPushUtil.pushUserSignInNotification(tokenList, content.getTitle(), content.getContent(),androidBaseActivity); |
| | | } |
| | | } catch (Exception e) { |
| | | PushLogHelper.oppoError(e); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |