...
|
...
|
@@ -109,7 +109,7 @@ public class CouponServiceImpl implements ICouponService { |
|
|
validityRange = Range.open(now, end);
|
|
|
}
|
|
|
|
|
|
return sendCoupons(uid, couponTokens.stream().collect(Collectors.joining(",")), repeatable, validityRange);
|
|
|
return sendCoupons(uid, couponTokens.stream().collect(Collectors.joining(",")), repeatable, validityRange, true);
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -118,6 +118,8 @@ public class CouponServiceImpl implements ICouponService { |
|
|
|
|
|
// 允许重复发放
|
|
|
boolean repeatable;
|
|
|
//是否需要校验可领取时间
|
|
|
boolean receiveStartTimeChkNecessary = false;
|
|
|
// 有效期
|
|
|
Range<Integer> validityRange;
|
|
|
|
...
|
...
|
@@ -129,15 +131,20 @@ public class CouponServiceImpl implements ICouponService { |
|
|
}else if(CouponSendType.PLATFORM_SEND_COUPON.equals(sendType)){
|
|
|
repeatable = true;
|
|
|
validityRange = null;
|
|
|
} else {
|
|
|
} else {//用户领取
|
|
|
repeatable = false;
|
|
|
validityRange = null;
|
|
|
receiveStartTimeChkNecessary = true;
|
|
|
}
|
|
|
|
|
|
return sendCoupons(uid, couponTokens, repeatable, validityRange);
|
|
|
return sendCoupons(uid, couponTokens, repeatable, validityRange, receiveStartTimeChkNecessary);
|
|
|
}
|
|
|
|
|
|
private List<CouponSendBo> sendCoupons(Integer uid, String couponTokens, boolean repeatable, Range<Integer> validityRange) {
|
|
|
private List<CouponSendBo> sendCoupons(Integer uid,
|
|
|
String couponTokens,
|
|
|
boolean repeatable,
|
|
|
Range<Integer> validityRange,
|
|
|
boolean receiveStartTimeChkNecessary) {
|
|
|
|
|
|
if (uid == null || uid.intValue() <=0
|
|
|
|| StringUtils.isEmpty(couponTokens)){
|
...
|
...
|
@@ -154,7 +161,7 @@ public class CouponServiceImpl implements ICouponService { |
|
|
CouponSendBo couponSendBo = new CouponSendBo();
|
|
|
couponSendBo.setCouponToken(couponToken);
|
|
|
try {
|
|
|
couponSendBo.setCouponCode(sendPerCoupon(uid, couponToken, repeatable,validityRange));
|
|
|
couponSendBo.setCouponCode(sendPerCoupon(uid, couponToken, repeatable,validityRange, receiveStartTimeChkNecessary));
|
|
|
couponSendBo.setSuccess(true);
|
|
|
} catch (ServiceException ex) {
|
|
|
logger.info("happened serviceException,uid:{},couponTokens:{}", uid, couponTokens, ex);
|
...
|
...
|
@@ -171,23 +178,43 @@ public class CouponServiceImpl implements ICouponService { |
|
|
return couponSendBoList;
|
|
|
}
|
|
|
|
|
|
private String sendPerCoupon(Integer uid, String couponToken, boolean repeatable, Range<Integer> validityRange) {
|
|
|
private void checkReceiveStartTime(int uid, Coupon coupon){
|
|
|
Integer receiveStartTime;
|
|
|
Integer currentDT = DateUtil.getCurrentTimeSecond();
|
|
|
if (Objects.nonNull(receiveStartTime = coupon.getReceiveStartTime())
|
|
|
&& currentDT < receiveStartTime){
|
|
|
logger.warn("sendCoupon find current time not reach receiveStartTime,uid {} couponToken {} [{} {}]", uid, coupon.getCouponToken(), currentDT, receiveStartTime);
|
|
|
throw new ServiceException(ServiceError.PROMOTION_COUPON_NOT_ARRIVE_GET_START_TIME);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
logger.info("senCoupon enter,{},{},{}", uid, couponToken, repeatable);
|
|
|
private String sendPerCoupon(Integer uid,
|
|
|
String couponToken,
|
|
|
boolean repeatable,
|
|
|
Range<Integer> validityRange,
|
|
|
boolean receiveStartTimeChkNecessary) {
|
|
|
|
|
|
logger.info("sendCoupon enter,{},{},{},{},{}", uid, couponToken, repeatable, validityRange, receiveStartTimeChkNecessary);
|
|
|
|
|
|
// 根据 couponToken 获取coupon&couponType信息
|
|
|
CouponAndType couponAndType = couponCacheService.getCouponAndType(couponToken);
|
|
|
if (couponAndType == null){
|
|
|
logger.warn("query coupon info,coupontype is null:{}", couponToken);
|
|
|
logger.warn("sendCoupon query coupon info,coupontype is null:{}", couponToken);
|
|
|
throw new ServiceException(ServiceError.PROMOTION_COUPON_HAS_NOT_EXISTS);
|
|
|
}
|
|
|
Coupon coupon = couponAndType.getCoupon();
|
|
|
//check receive start time
|
|
|
if(receiveStartTimeChkNecessary){
|
|
|
//
|
|
|
checkReceiveStartTime(uid, coupon);
|
|
|
}
|
|
|
|
|
|
if(!repeatable){
|
|
|
// 校验是否可以领取(重复领取,时间是否合法,状态)
|
|
|
checkCanAcquire(uid, couponToken, couponAndType);
|
|
|
}
|
|
|
|
|
|
if (couponAndType.getCoupon().getStatus() != CouponsStatusEnum.VALID.getCode()){
|
|
|
if (coupon.getStatus() != CouponsStatusEnum.VALID.getCode()){
|
|
|
logger.info("couponrulebo status is not valid:{},{}",uid, couponToken);
|
|
|
throw new ServiceException(ServiceError.PROMOTION_COUPON_IS_NOT_VAILD);
|
|
|
}
|
...
|
...
|
|