yujian
2020-04-02 0ec22dcf4fd9c4496e6f681e7fab89f56c6e4e8a
fanli/src/main/java/com/yeshi/fanli/service/impl/push/HWPushServiceImpl.java
@@ -8,15 +8,15 @@
import javax.annotation.Resource;
import org.checkerframework.checker.units.qual.h;
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.exception.PushException;
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;
@@ -60,27 +60,27 @@
   @Override
   public void pushGoods(Long uid, Long auctionId, String title, String content, List<Integer> versionCodeList)
         throws PushException {
      push("goodsdetail", uid, title, content, null, null, auctionId, versionCodeList);
      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("url", uid, title, content, null, url, null, versionCodeList);
      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("ZNX", uid, title, content, null, null, null, versionCodeList);
      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("weex", uid, title, content, weexUrl, null, null, versionCodeList);
      push(PushTypeEnum.weex, uid, title, content, weexUrl, null, null, versionCodeList);
   }
   @Async("pushExecutor")
@@ -88,17 +88,26 @@
   public void pushBaiChuanUrl(Long uid, String title, String content, String url, List<Integer> versionCodeList)
         throws PushException {
      push("baichuan", uid, title, content, null, url, null, versionCodeList);
      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("welfare", uid, title, content, null, null, null, versionCodeList);
      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<DeviceTokenHW> filterDeviceToken(List<DeviceTokenHW> hwDeviceList, int hour) {
      // TODO 暂时不处理消息免打扰
      if (1 > 0)
         return hwDeviceList;
      // 处理消息免打扰
      if (hour >= 20 || hour < 8) {
         Set<Long> uidSets = new HashSet<>();
@@ -136,10 +145,16 @@
    * @param webUrl
    * @param versionCodeList
    */
   private void push(String 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 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) {
         long deviceCount = deviceTokenHWService.countDeviceToken(newVersionList);
         int page = (int) (deviceCount % 100 == 0 ? deviceCount / 100 : deviceCount / 100 + 1);
@@ -151,26 +166,28 @@
            for (DeviceTokenHW token : hwDeviceList)
               tokenList.add(token.getDeviceToken());
            try {
               if (type.equalsIgnoreCase("goodsdetail")) {// 商品详情
               if (type == PushTypeEnum.goodsdetail) {// 商品详情
                  if (goodsId == null)
                     throw new PushException(2, "参数不完整");
                  HWPushUtil.pushGoods(tokenList, title, content, 1, goodsId);
               } else if (type.equalsIgnoreCase("url")) {// 链接
               } else if (type == PushTypeEnum.url) {// 链接
                  if (StringUtil.isNullOrEmpty(webUrl))
                     throw new PushException(2, "参数不完整");
                  HWPushUtil.pushUrl(tokenList, title, content, webUrl);
               } else if (type.equalsIgnoreCase("ZNX")) {// 站内信
               } else if (type == PushTypeEnum.ZNX) {// 站内信
                  HWPushUtil.pushZNX(tokenList, title, content);
               } else if (type.equalsIgnoreCase("weex")) {// weex
               } else if (type == PushTypeEnum.weex) {// weex
                  if (StringUtil.isNullOrEmpty(url))
                     throw new PushException(2, "参数不完整");
                  HWPushUtil.pushWEEX(tokenList, title, content, url);
               } else if (type.equalsIgnoreCase("baichuan")) {// 百川链接
               } else if (type == PushTypeEnum.baichuan) {// 百川链接
                  if (StringUtil.isNullOrEmpty(webUrl))
                     throw new PushException(2, "参数不完整");
                  HWPushUtil.pushBaiChuanUrl(tokenList, title, content, webUrl);
               } else if (type.equalsIgnoreCase("welfare")) {// 福利中心
               } else if (type == PushTypeEnum.welfare) {// 福利中心
                  HWPushUtil.pushWelfareCenter(tokenList, title, content);
               } else if (type == PushTypeEnum.signin) {// 签到
                  HWPushUtil.pushUserSignInNotification(tokenList, title, content);
               }
            } catch (Exception e) {
               PushLogHelper.hwError(e);
@@ -190,26 +207,28 @@
            return;
         try {
            if (type.equalsIgnoreCase("goodsdetail")) {// 商品详情
            if (type == PushTypeEnum.goodsdetail) {// 商品详情
               if (goodsId == null)
                  throw new PushException(2, "参数不完整");
               HWPushUtil.pushGoods(tokenList, title, content, 1, goodsId);
            } else if (type.equalsIgnoreCase("url")) {// 链接
            } else if (type == PushTypeEnum.url) {// 链接
               if (StringUtil.isNullOrEmpty(webUrl))
                  throw new PushException(2, "参数不完整");
               HWPushUtil.pushUrl(tokenList, title, content, webUrl);
            } else if (type.equalsIgnoreCase("ZNX")) {// 站内信
            } else if (type == PushTypeEnum.ZNX) {// 站内信
               HWPushUtil.pushZNX(tokenList, title, content);
            } else if (type.equalsIgnoreCase("weex")) {// weex
            } else if (type == PushTypeEnum.weex) {// weex
               if (StringUtil.isNullOrEmpty(url))
                  throw new PushException(2, "参数不完整");
               HWPushUtil.pushWEEX(tokenList, title, content, url);
            } else if (type.equalsIgnoreCase("baichuan")) {// 百川链接
            } else if (type == PushTypeEnum.baichuan) {// 百川链接
               if (StringUtil.isNullOrEmpty(webUrl))
                  throw new PushException(2, "参数不完整");
               HWPushUtil.pushBaiChuanUrl(tokenList, title, content, webUrl);
            } else if (type.equalsIgnoreCase("welfare")) {// 福利中心
            } else if (type == PushTypeEnum.welfare) {// 福利中心
               HWPushUtil.pushWelfareCenter(tokenList, title, content);
            } else if (type == PushTypeEnum.signin) {// 签到
               HWPushUtil.pushUserSignInNotification(tokenList, title, content);
            }
         } catch (Exception e) {
            PushLogHelper.hwError(e);