admin
2019-03-15 a8e45a802600ca1cde28fe8522a26635328bbd99
fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushCouponServiceImpl.java
@@ -1,5 +1,7 @@
package com.yeshi.fanli.service.impl.push;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@@ -93,9 +95,18 @@
      }
      Integer amount = record.getAmount();
      if (amount == null || amount < 1) {
         throw new PushCouponException(1, "券数量不能小于1");
      if (amount == null) {
         throw new PushCouponException(1, "券数量不能为空");
      } else if (amount < 1 || amount > 5) {
         throw new PushCouponException(1, "券数量范围是 1~5");
      }
      BigDecimal percent = record.getPercent();
      if (percent != null && (percent.compareTo(new BigDecimal(60)) > 0
            || percent.compareTo(new BigDecimal(1)) < 0)) {
         throw new PushCouponException(1, "券比例范围是1~60 的正整数");
      }
      Long id = record.getId();
      if (id == null) {
@@ -112,6 +123,10 @@
         if (current == null) {
            throw new PushCouponException(1, "该记录已不存在");
         }
         if(current.isPushed()) {
            throw new PushCouponException(1, "已推送的信息不能修改");
         }
         current.setTitle(title);
         current.setContent(content);
@@ -124,7 +139,6 @@
         // 更新数据
         updateByPrimaryKey(current);
      }
   }
   @Override
@@ -135,6 +149,11 @@
      if (pushCoupon == null) {
         throw new PushCouponException(1, "推送信息已不存在");
      }
      if(pushCoupon.isPushed()) {
         throw new PushCouponException(1, "该信息不能重复推送");
      }
      String title = pushCoupon.getTitle();
      String content = pushCoupon.getContent();
@@ -143,27 +162,35 @@
      }
      
      
      // TODO 推送跳转
      List<String> listuid = null;
      String uids = pushCoupon.getUids();
      if (uids == null || uids.trim().length() == 0) {
      if (uids != null && uids.trim().length() > 0) {
         listuid = Arrays.asList(uids.split(","));
         if (listuid == null || listuid.size() == 0) {
            throw new PushCouponException(1, "用户id格式不正确");
         }
      }
      List<String> listVersion = null;
      String versions = pushCoupon.getVersions();
      if (versions != null && versions.trim().length() > 0) {
         listVersion  = Arrays.asList(versions.split(","));
         if (listVersion == null || listVersion.size() == 0) {
            throw new PushCouponException(1, "版本号格式不正确\"");
         }
      }
      if (listuid == null) {
         // 全推
         //pushService.pushZNX(null, title, content);
         pushService.pushWelfareCenter(null, title, content, listVersion);
         
      } else {
         // 指定用户推送
         String[] uidArray = uids.split(",");
         if (uidArray != null) {
            for (int i = 0; i < uidArray.length; i++) {
               String str_uid = uidArray[i];
               if (str_uid != null && str_uid.trim().length() > 0) {
                  //pushService.pushZNX(Long.parseLong(str_uid), title, content);
               }
         for (String str_uid: listuid) {
            if (str_uid != null && str_uid.trim().length() > 0) {
               pushService.pushWelfareCenter(Long.parseLong(str_uid), title, content, listVersion);
            }
         }
      }
      
      // 已推送
@@ -186,6 +213,7 @@
      
      for (Long id: list) {
         long receivedCount = pushCouponRecordService.countByPushId(id);
         // 领取数量
         if (receivedCount > 0) {
            continue;
         }