| | |
| | | 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;
|
| | |
| | | private List<Integer> getVersionCodeList(List<Integer> versionCodeList) {
|
| | | List<Integer> versionList = new ArrayList<>();
|
| | | if (versionCodeList == null) {// 全推
|
| | | List<AppVersionInfo> appInfoList = appVersionService.listByPlatformAndMinVersionCode("android", 49);
|
| | | List<AppVersionInfo> appInfoList = appVersionService.listByPlatformAndMinVersionCode("android", 51);
|
| | | if (appInfoList != null)
|
| | | for (AppVersionInfo version : appInfoList) {
|
| | | versionList.add(version.getVersionCode());
|
| | |
| | |
|
| | | } else {// 按版本推送
|
| | | for (Integer versionCode : versionCodeList) {
|
| | | if (versionCode.intValue() >= 49) {// 2.0.1开始支持
|
| | | if (versionCode.intValue() >= 51) {// 2.0.1开始支持
|
| | | versionList.add(versionCode);
|
| | | }
|
| | | }
|
| | |
| | | push(PushTypeEnum.signin, uid, title, content, null, null, null, versionCodeList);
|
| | | }
|
| | |
|
| | | 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,
|
| | |
| | | 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;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | }
|
| | |
|
| | | if (uid == null || uid == 0) {
|
| | | long deviceCount = deviceTokenHWService.countDeviceToken(newVersionList);
|
| | | int page = (int) (deviceCount % 100 == 0 ? deviceCount / 100 : deviceCount / 100 + 1);
|
| | | 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<DeviceTokenHW> hwDeviceList = deviceTokenHWService.getDeviceTokenList(p, 100, newVersionList);
|
| | | hwDeviceList = filterDeviceToken(hwDeviceList, hour);
|
| | | List<DeviceTokenOPPO> deviceList = deviceTokenOPPOService.listDeviceToken(p, pageSize, newVersionList);
|
| | | 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, title, content, 1, goodsId);
|
| | | } else if (type == PushTypeEnum.url) {// 链接
|
| | | if (StringUtil.isNullOrEmpty(webUrl))
|
| | | throw new PushException(2, "参数不完整");
|
| | | HWPushUtil.pushUrl(tokenList, title, content, webUrl);
|
| | | OPPOPushUtil.pushUrl(tokenList, title, content, webUrl);
|
| | | } else if (type == PushTypeEnum.ZNX) {// 站内信
|
| | | HWPushUtil.pushZNX(tokenList, title, content);
|
| | | OPPOPushUtil.pushZNX(tokenList, title, content);
|
| | | } else if (type == PushTypeEnum.weex) {// weex
|
| | | if (StringUtil.isNullOrEmpty(url))
|
| | | throw new PushException(2, "参数不完整");
|
| | | HWPushUtil.pushWEEX(tokenList, title, content, url);
|
| | | OPPOPushUtil.pushWEEX(tokenList, title, content, url);
|
| | | } else if (type == PushTypeEnum.baichuan) {// 百川链接
|
| | | if (StringUtil.isNullOrEmpty(webUrl))
|
| | | throw new PushException(2, "参数不完整");
|
| | | HWPushUtil.pushBaiChuanUrl(tokenList, title, content, webUrl);
|
| | | OPPOPushUtil.pushBaiChuanUrl(tokenList, title, content, webUrl);
|
| | | } else if (type == PushTypeEnum.welfare) {// 福利中心
|
| | | HWPushUtil.pushWelfareCenter(tokenList, title, content);
|
| | | OPPOPushUtil.pushWelfareCenter(tokenList, title, content);
|
| | | } else if (type == PushTypeEnum.signin) {// 签到
|
| | | HWPushUtil.pushUserSignInNotification(tokenList, title, content);
|
| | | OPPOPushUtil.pushUserSignInNotification(tokenList, title, content);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | PushLogHelper.hwError(e);
|
| | |
| | | }
|
| | | } 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;
|
| | |
| | | if (type == PushTypeEnum.goodsdetail) {// 商品详情
|
| | | if (goodsId == null)
|
| | | throw new PushException(2, "参数不完整");
|
| | | HWPushUtil.pushGoods(tokenList, title, content, 1, goodsId);
|
| | | OPPOPushUtil.pushGoods(tokenList, title, content, 1, goodsId);
|
| | | } else if (type == PushTypeEnum.url) {// 链接
|
| | | if (StringUtil.isNullOrEmpty(webUrl))
|
| | | throw new PushException(2, "参数不完整");
|
| | | HWPushUtil.pushUrl(tokenList, title, content, webUrl);
|
| | | OPPOPushUtil.pushUrl(tokenList, title, content, webUrl);
|
| | | } else if (type == PushTypeEnum.ZNX) {// 站内信
|
| | | HWPushUtil.pushZNX(tokenList, title, content);
|
| | | OPPOPushUtil.pushZNX(tokenList, title, content);
|
| | | } else if (type == PushTypeEnum.weex) {// weex
|
| | | if (StringUtil.isNullOrEmpty(url))
|
| | | throw new PushException(2, "参数不完整");
|
| | | HWPushUtil.pushWEEX(tokenList, title, content, url);
|
| | | OPPOPushUtil.pushWEEX(tokenList, title, content, url);
|
| | | } else if (type == PushTypeEnum.baichuan) {// 百川链接
|
| | | if (StringUtil.isNullOrEmpty(webUrl))
|
| | | throw new PushException(2, "参数不完整");
|
| | | HWPushUtil.pushBaiChuanUrl(tokenList, title, content, webUrl);
|
| | | OPPOPushUtil.pushBaiChuanUrl(tokenList, title, content, webUrl);
|
| | | } else if (type == PushTypeEnum.welfare) {// 福利中心
|
| | | HWPushUtil.pushWelfareCenter(tokenList, title, content);
|
| | | OPPOPushUtil.pushWelfareCenter(tokenList, title, content);
|
| | | } else if (type == PushTypeEnum.signin) {// 签到
|
| | | HWPushUtil.pushUserSignInNotification(tokenList, title, content);
|
| | | OPPOPushUtil.pushUserSignInNotification(tokenList, title, content);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | PushLogHelper.hwError(e);
|
| | | PushLogHelper.oppoError(e);
|
| | | }
|
| | |
|
| | | }
|