From c1ff1058eeb0067c224ee53e1dc61ace051375c8 Mon Sep 17 00:00:00 2001 From: 陶杰 <1378534974@qq.com> Date: 星期三, 11 九月 2024 17:14:02 +0800 Subject: [PATCH] 1.异常抛出信息修改 --- src/main/java/com/mzl/flower/service/impl/coupon/CouponRecordServiceImpl.java | 22 +++++++++++----------- src/main/java/com/mzl/flower/service/impl/coupon/CouponTemplateServiceImpl2.java | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/mzl/flower/service/impl/coupon/CouponRecordServiceImpl.java b/src/main/java/com/mzl/flower/service/impl/coupon/CouponRecordServiceImpl.java index a55612d..3a788f3 100644 --- a/src/main/java/com/mzl/flower/service/impl/coupon/CouponRecordServiceImpl.java +++ b/src/main/java/com/mzl/flower/service/impl/coupon/CouponRecordServiceImpl.java @@ -168,7 +168,7 @@ // 领取后有段时间 领取后有效时间 // 根据发放后有效期来设置时间 if (couponTemplateDO.getUsageTimeNum() == null || couponTemplateDO.getUsageTimeNum() <= 0) { - throw new IllegalArgumentException("使用时间数量必须为正整数"); + throw new ValidationException("使用时间数量必须为正整数"); } LocalDateTime currentTime = LocalDateTime.now(); couponRecordDO.setEffectiveStart(currentTime); @@ -437,50 +437,50 @@ public boolean useCoupon(String couponId, String orderId, BigDecimal orderMount) { // 优惠券为空 if(StringUtils.isBlank(couponId)){ - throw new IllegalArgumentException("无效的优惠券"); + throw new ValidationException("无效的优惠券"); } if(StringUtils.isBlank(orderId)){ - throw new IllegalArgumentException("订单id不能为空"); + throw new ValidationException("订单id不能为空"); } if(orderMount.compareTo(BigDecimal.ZERO)<=0){ - throw new IllegalArgumentException("订单金额不能小于0"); + throw new ValidationException("订单金额不能小于0"); } // 验证优惠券存在且有效 final CouponRecordDO couponRecordDO = baseMapper.selectById(couponId); if(null==couponRecordDO || StringUtils.isNotBlank(couponRecordDO.getOrderId()) ){ - throw new IllegalArgumentException("无效的优惠券"); + throw new ValidationException("无效的优惠券"); } if(couponRecordDO.getStatus().equals(CouponUsedStatusEnum.USED.getType())){ - throw new IllegalArgumentException("优惠券已经被使用"); + throw new ValidationException("优惠券已经被使用"); } if(couponRecordDO.getStatus().equals(CouponUsedStatusEnum.EXPIRED.getType()) || LocalDateTime.now().isAfter(couponRecordDO.getEffectiveEnd())){ - throw new IllegalArgumentException("优惠券已过期"); + throw new ValidationException("优惠券已过期"); } // 根据类型判断是无门槛还是满减,如果是无门槛 if(couponRecordDO.getCouponDiscountType().equals(CouponTypeEnum.ZERO.getType())){ // 无门槛,查看金额是否大于满减值 if(orderMount.compareTo(couponRecordDO.getCouponDiscountValue())<0){ - throw new IllegalArgumentException(String.format("订单金额(%s)小于无门槛的金额(%s)", orderMount, couponRecordDO.getCouponDiscountValue())); + throw new ValidationException(String.format("订单金额(%s)小于无门槛的金额(%s)", orderMount, couponRecordDO.getCouponDiscountValue())); } } if(couponRecordDO.getCouponDiscountType().equals(CouponTypeEnum.DISCOUNT.getType())){ //满减,查看金额是否满足最小订单额 if(orderMount.compareTo(couponRecordDO.getMinOrderAmount())<0){ - throw new IllegalArgumentException(String.format("订单金额(%s)小于最低折扣订单金额(%s)", orderMount, couponRecordDO.getMinOrderAmount())); + throw new ValidationException(String.format("订单金额(%s)小于最低折扣订单金额(%s)", orderMount, couponRecordDO.getMinOrderAmount())); } if(orderMount.compareTo(couponRecordDO.getCouponDiscountValue())<0){ - throw new IllegalArgumentException(String.format("订单金额(%s)小于折扣的金额(%s)", orderMount, couponRecordDO.getCouponDiscountValue())); + throw new ValidationException(String.format("订单金额(%s)小于折扣的金额(%s)", orderMount, couponRecordDO.getCouponDiscountValue())); } } // 查看当前的优惠券是否是当前人员的 if(!SecurityUtils.getUserId().equals(couponRecordDO.getUserId())){ - throw new IllegalArgumentException("优惠券不属于当前人员"); + throw new ValidationException("优惠券不属于当前人员"); } // 优惠券使用操作 diff --git a/src/main/java/com/mzl/flower/service/impl/coupon/CouponTemplateServiceImpl2.java b/src/main/java/com/mzl/flower/service/impl/coupon/CouponTemplateServiceImpl2.java index f5d61b6..4c11832 100644 --- a/src/main/java/com/mzl/flower/service/impl/coupon/CouponTemplateServiceImpl2.java +++ b/src/main/java/com/mzl/flower/service/impl/coupon/CouponTemplateServiceImpl2.java @@ -241,7 +241,7 @@ // 根据发放后有效期来设置时间 if (couponTemplateDO.getUsageTimeNum() == null || couponTemplateDO.getUsageTimeNum() <= 0) { - throw new IllegalArgumentException("使用时间数量必须为正整数"); + throw new ValidationException("使用时间数量必须为正整数"); } LocalDateTime currentTime = LocalDateTime.now(); couponTemplateDO.setUsageStartDate(currentTime); -- Gitblit v1.9.3