From cdcbed9af813b2a02cdc01eefa24db8bec6b51a9 Mon Sep 17 00:00:00 2001 From: yujian <yujian> Date: 星期三, 27 三月 2019 12:17:33 +0800 Subject: [PATCH] 主分类 + 子分类 DAO改造 --- fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushCouponServiceImpl.java | 78 ++++++++++++++++++++++++++++++++------ 1 files changed, 65 insertions(+), 13 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushCouponServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushCouponServiceImpl.java index a0e3225..201eb00 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushCouponServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushCouponServiceImpl.java @@ -1,5 +1,8 @@ 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; @@ -16,6 +19,8 @@ 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 { @@ -93,9 +98,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) { @@ -111,6 +125,10 @@ PushCoupon current = selectByPrimaryKey(id); if (current == null) { throw new PushCouponException(1, "璇ヨ褰曞凡涓嶅瓨鍦�"); + } + + if(current.isPushed()) { + throw new PushCouponException(1, "宸叉帹閫佺殑淇℃伅涓嶈兘淇敼"); } current.setTitle(title); @@ -134,6 +152,15 @@ if (pushCoupon == null) { throw new PushCouponException(1, "鎺ㄩ�佷俊鎭凡涓嶅瓨鍦�"); } + + 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(); String content = pushCoupon.getContent(); @@ -142,24 +169,48 @@ } + 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); + 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); - } + for (String str_uid: listuid) { + if (str_uid != null && str_uid.trim().length() > 0) { + pushService.pushWelfareCenter(Long.parseLong(str_uid), title, content, listIOS, listAndroid); } } - } // 宸叉帹閫� @@ -182,6 +233,7 @@ for (Long id: list) { long receivedCount = pushCouponRecordService.countByPushId(id); + // 棰嗗彇鏁伴噺 if (receivedCount > 0) { continue; } -- Gitblit v1.8.0