From 0bc5e07b24c08c41f14b066597d693026ec5fb89 Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期六, 24 六月 2023 09:28:40 +0800 Subject: [PATCH] 修改bug --- user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/AppUserServiceImpl.java | 58 +++++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 37 insertions(+), 21 deletions(-) diff --git a/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/AppUserServiceImpl.java b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/AppUserServiceImpl.java index 1463862..e371ad1 100644 --- a/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/AppUserServiceImpl.java +++ b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/AppUserServiceImpl.java @@ -187,11 +187,25 @@ appUser.setStatus(1); appUser.setCreateTime(new Date()); appUser.setIsException(1); - appUser.setInviterId(signInToRegister.getInviterId()); - appUser.setInviterType(signInToRegister.getInviterType()); + if(null != signInToRegister.getInviterId()){ + appUser.setInviterId(signInToRegister.getInviterId()); + appUser.setInviterType(signInToRegister.getInviterType()); + } this.insert(appUser); //发送优惠券 - boolean lock = redisUtil.lock(); + boolean lock = redisUtil.lock(5); + if(!lock){ + int num1 = 1; + while (num1 <= 10){ + Thread.sleep(3000);//等待3秒 + lock = redisUtil.lock(5); + if(lock){ + break; + }else{ + num1++; + } + } + } if(lock){ List<CouponWarpper> list = pushCoupon(appUser.getId()); redisUtil.unlock(); @@ -260,28 +274,30 @@ .eq("coupon_state", 1).eq("status", 1).gt("remaining_quantity", 0)); List<CouponWarpper> list = new ArrayList<>(); for (Coupon coupon : coupons) { - UserToCoupon userToCoupon = new UserToCoupon(); - userToCoupon.setCouponId(coupon.getId()); - userToCoupon.setCreateTime(new Date()); - userToCoupon.setUserId(userId); - userToCoupon.setStatus(1); - userToCoupon.setCouponTotal(coupon.getCouponSendQuantity() > coupon.getRemainingQuantity() ? - coupon.getRemainingQuantity() : coupon.getCouponSendQuantity()); - userToCoupon.setValidCount(userToCoupon.getCouponTotal()); - userToCoupon.setExpireTime(new Date(System.currentTimeMillis() + (coupon.getCouponValidity().longValue() * 24L * 60L * 60L * 1000L))); - userToCouponService.insert(userToCoupon); + Integer num = coupon.getCouponSendQuantity() > coupon.getRemainingQuantity() ? + coupon.getRemainingQuantity() : coupon.getCouponSendQuantity(); + for (int i = 0; i < num; i++) { + UserToCoupon userToCoupon = new UserToCoupon(); + userToCoupon.setCouponId(coupon.getId()); + userToCoupon.setCreateTime(new Date()); + userToCoupon.setUserId(userId); + userToCoupon.setStatus(1); + userToCoupon.setCouponTotal(1); + userToCoupon.setValidCount(1); + userToCoupon.setExpireTime(new Date(System.currentTimeMillis() + (coupon.getCouponValidity().longValue() * 24L * 60L * 60L * 1000L))); + userToCouponService.insert(userToCoupon); + CouponWarpper couponWarpper = new CouponWarpper(); + couponWarpper.setCouponConditionalAmount(coupon.getCouponConditionalAmount()); + couponWarpper.setCouponPreferentialAmount(coupon.getCouponPreferentialAmount()); + couponWarpper.setCouponName(coupon.getCouponName()); + couponWarpper.setNumber(userToCoupon.getValidCount()); + couponWarpper.setExpirationDate(userToCoupon.getExpireTime().getTime()); + list.add(couponWarpper); + } coupon.setRemainingQuantity(coupon.getCouponSendQuantity() > coupon.getRemainingQuantity() ? 0 : coupon.getRemainingQuantity() - coupon.getCouponSendQuantity()); couponService.updateById(coupon); - - CouponWarpper couponWarpper = new CouponWarpper(); - couponWarpper.setCouponConditionalAmount(coupon.getCouponConditionalAmount()); - couponWarpper.setCouponPreferentialAmount(coupon.getCouponPreferentialAmount()); - couponWarpper.setCouponName(coupon.getCouponName()); - couponWarpper.setNumber(userToCoupon.getValidCount()); - couponWarpper.setExpirationDate(userToCoupon.getExpireTime().getTime()); - list.add(couponWarpper); } return list; } -- Gitblit v1.7.1