| | |
| | | package com.yeshi.fanli.service.impl.push;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
| | | import com.yeshi.fanli.service.inter.push.PushCouponRecordService;
|
| | | import com.yeshi.fanli.service.inter.push.PushCouponService;
|
| | | import com.yeshi.fanli.service.inter.push.PushService;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | @Service
|
| | | public class PushCouponServiceImpl implements PushCouponService {
|
| | |
| | | }
|
| | |
|
| | | 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) {
|
| | |
| | | PushCoupon current = selectByPrimaryKey(id);
|
| | | if (current == null) {
|
| | | throw new PushCouponException(1, "该记录已不存在");
|
| | | }
|
| | | |
| | | if(current.isPushed()) {
|
| | | throw new PushCouponException(1, "已推送的信息不能修改");
|
| | | }
|
| | |
|
| | | current.setTitle(title);
|
| | |
| | | if(pushCoupon.isPushed()) {
|
| | | throw new PushCouponException(1, "该信息不能重复推送");
|
| | | }
|
| | | String versions = pushCoupon.getVersions();
|
| | | if (versions == null || versions.trim().length() == 0 ) {
|
| | | throw new PushCouponException(1, "推送版本不能为空");
|
| | | }
|
| | |
|
| | |
|
| | | String title = pushCoupon.getTitle();
|
| | |
| | | throw new PushCouponException(1, "标题或内容不能为空");
|
| | | }
|
| | |
|
| | | List<String> listVersion = null;
|
| | | String versions = pushCoupon.getVersions();
|
| | | if (versions != null && versions.trim().length() > 0) {
|
| | | listVersion = Arrays.asList(versions.split(","));
|
| | | }
|
| | | |
| | | 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> listIOS = new ArrayList<String>();
|
| | | JSONObject json = JSONObject.fromObject(versions);
|
| | | String versionsIOS = json.getString("IOS");
|
| | | if (versionsIOS != null && versionsIOS.trim().length() > 0) {
|
| | | if (versionsIOS.contains("全推")) {
|
| | | listIOS = null;
|
| | | } else {
|
| | | listIOS = Arrays.asList(versionsIOS.split(","));
|
| | | }
|
| | | }
|
| | | |
| | | List<String> listAndroid = new ArrayList<String>();
|
| | | String versionsAndroid = json.getString("Android");
|
| | | if (versionsAndroid != null && versionsAndroid.trim().length() > 0) {
|
| | | if (versionsAndroid.contains("全推")) {
|
| | | listAndroid = null;
|
| | | } else {
|
| | | listAndroid = Arrays.asList(versionsAndroid.split(","));
|
| | | }
|
| | | }
|
| | | |
| | | |
| | | if (listuid == null) {
|
| | | // 全推
|
| | | pushService.pushWelfareCenter(null, title, content, listVersion);
|
| | | pushService.pushWelfareCenter(null, title, content, listIOS, listAndroid);
|
| | |
|
| | | } 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.pushWelfareCenter(Long.parseLong(str_uid), title, content, listVersion);
|
| | | }
|
| | | for (String str_uid: listuid) {
|
| | | if (str_uid != null && str_uid.trim().length() > 0) {
|
| | | pushService.pushWelfareCenter(Long.parseLong(str_uid), title, content, listIOS, listAndroid);
|
| | | }
|
| | | }
|
| | | |
| | | }
|
| | |
|
| | | // 已推送
|
| | |
| | |
|
| | | for (Long id: list) {
|
| | | long receivedCount = pushCouponRecordService.countByPushId(id);
|
| | | // 领取数量
|
| | | if (receivedCount > 0) {
|
| | | continue;
|
| | | }
|