From cda958fe6e4359ba0f0eb47ced8b0a2b541e17bb Mon Sep 17 00:00:00 2001 From: 199901012 Date: Mon, 5 Apr 2021 14:29:25 +0800 Subject: [PATCH] =?UTF-8?q?'=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hai/schedule/HighCouponSchedule.java | 17 +++- .../hai/schedule/HighDiscountSchedule.java | 12 ++- .../com/hai/schedule/HighOrderSchedule.java | 11 ++- .../hai/service/HighUserCouponService.java | 2 +- .../impl/HighUserCouponServiceImpl.java | 79 ++++++++++--------- 5 files changed, 76 insertions(+), 45 deletions(-) diff --git a/hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java b/hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java index 76c5dd48..68c564db 100644 --- a/hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java +++ b/hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java @@ -1,10 +1,15 @@ package com.hai.schedule; +import com.hai.common.utils.ResponseMsgUtil; +import com.hai.entity.HighUserCoupon; import com.hai.service.HighUserCouponService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.Scheduled; import javax.annotation.Resource; +import java.util.List; /** * @Auther: 胡锐 @@ -14,6 +19,8 @@ import javax.annotation.Resource; @Configuration public class HighCouponSchedule { + private static Logger log = LoggerFactory.getLogger(HighCouponSchedule.class); + @Resource private HighUserCouponService highUserCouponService; @@ -25,6 +32,14 @@ public class HighCouponSchedule { // @Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次 @Scheduled(cron = "0 0 0 * * ?") //每天 凌晨0点执行 public void expiredCoupon() { - highUserCouponService.expiredCoupon(); + // 查询过期的卡券 + List userCoupons = highUserCouponService.getOverdueCoupon(); + for (HighUserCoupon userCoupon : userCoupons) { + try { + highUserCouponService.expiredCoupon(userCoupon.getId()); + } catch (Exception e) { + log.error("HighCouponSchedule --> expiredCoupon() error!", e); + } + } } } diff --git a/hai-schedule/src/main/java/com/hai/schedule/HighDiscountSchedule.java b/hai-schedule/src/main/java/com/hai/schedule/HighDiscountSchedule.java index 66dd437d..b370a79c 100644 --- a/hai-schedule/src/main/java/com/hai/schedule/HighDiscountSchedule.java +++ b/hai-schedule/src/main/java/com/hai/schedule/HighDiscountSchedule.java @@ -3,6 +3,8 @@ package com.hai.schedule; import com.hai.entity.HighDiscountUserRel; import com.hai.entity.HighOrder; import com.hai.service.HighDiscountUserRelService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.Scheduled; @@ -17,6 +19,8 @@ import java.util.List; @Configuration public class HighDiscountSchedule { + private static Logger log = LoggerFactory.getLogger(HighDiscountSchedule.class); + @Resource private HighDiscountUserRelService highDiscountUserRelService; @@ -29,8 +33,12 @@ public class HighDiscountSchedule { public void expiredDiscount() { List expiredDiscount = highDiscountUserRelService.getExpiredDiscount(); for (HighDiscountUserRel rel : expiredDiscount) { - rel.setStatus(0); - highDiscountUserRelService.updateDiscountUserRel(rel); + try { + rel.setStatus(0); + highDiscountUserRelService.updateDiscountUserRel(rel); + } catch (Exception e) { + log.error("HighCouponSchedule --> expiredCoupon() error!", e); + } } } diff --git a/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java b/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java index c6869d83..789bef83 100644 --- a/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java +++ b/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java @@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONObject; import com.hai.common.utils.HttpsUtils; import com.hai.entity.HighOrder; import com.hai.service.HighOrderService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.Scheduled; @@ -21,6 +23,8 @@ import java.util.Map; @Configuration public class HighOrderSchedule { + private static final Logger log = LoggerFactory.getLogger(HighOrderSchedule.class); + @Resource private HighOrderService highOrderService; @@ -31,11 +35,14 @@ public class HighOrderSchedule { **/ @Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次 public void cancelOrder() { - List orderList = highOrderService.getCloseOrder(); if (orderList != null && orderList.size() > 0) { for (HighOrder order : orderList) { - highOrderService.cancelOrder(order.getId()); + try { + highOrderService.cancelOrder(order.getId()); + } catch (Exception e) { + log.error("HighCouponSchedule --> expiredCoupon() error!", e); + } } } } diff --git a/hai-service/src/main/java/com/hai/service/HighUserCouponService.java b/hai-service/src/main/java/com/hai/service/HighUserCouponService.java index 82cfe0ba..ff924ea2 100644 --- a/hai-service/src/main/java/com/hai/service/HighUserCouponService.java +++ b/hai-service/src/main/java/com/hai/service/HighUserCouponService.java @@ -70,7 +70,7 @@ public interface HighUserCouponService { * @Description 处理过期的卡券 * @Date 2021/4/5 12:26 **/ - void expiredCoupon(); + void expiredCoupon(Long userCouponId); } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighUserCouponServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighUserCouponServiceImpl.java index 2ac140f5..9d206632 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighUserCouponServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighUserCouponServiceImpl.java @@ -172,44 +172,45 @@ public class HighUserCouponServiceImpl implements HighUserCouponService { } @Override - public void expiredCoupon() { - // 查询过期的卡券 - List userCoupons = getOverdueCoupon(); - for (HighUserCoupon highUserCoupon : userCoupons) { - highUserCoupon.setStatus(0); // 状态 0:已过期 1:未使用 2:已使用 - highUserCoupon.setQrCodeImg(null); - updateUserCoupon(highUserCoupon); - - // 查询销售码 - HighCouponCode couponCode = highCouponCodeService.getCouponCodeById(highUserCoupon.getCouponCodeId()); - couponCode.setChildOrderId(null); - couponCode.setReceiveTime(null); - - // 查询卡券信息 - HighCoupon coupon = highCouponService.getCouponById(highUserCoupon.getCouponId()); - - HighChildOrder childOrder = highOrderService.getChildOrderById(couponCode.getChildOrderId()); - HighOrder order = highOrderService.getOrderById(childOrder.getId()); - - - - // 归库记录 - HighCouponRecycle highCouponRecycle = new HighCouponRecycle(); - highCouponRecycle.setCouponId(coupon.getId()); - highCouponRecycle.setCouponName(coupon.getCouponName()); - highCouponRecycle.setMerchantId(coupon.getMerchantId()); - - highCouponRecycle.setCouponSalesCode(couponCode.getSalesCode()); - highCouponRecycle.setCouponCodeId(couponCode.getId()); - - highCouponRecycle.setOrderId(childOrder.getOrderId()); - highCouponRecycle.setOrderNo(order.getOrderNo()); - highCouponRecycle.setChildOrderId(childOrder.getId()); - - highCouponRecycle.setType(1); // 类型:1.过期 2.退款 - highCouponRecycle.setReceiveTime(highUserCoupon.getCreateTime()); // 领取时间 - highCouponRecycle.setCreateTime(new Date()); - highCouponRecycleService.insertCouponRecycle(highCouponRecycle); - } + @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) + public void expiredCoupon(Long userCouponId) { + HighUserCoupon highUserCoupon = highUserCouponMapper.selectByPrimaryKey(userCouponId); + highUserCoupon.setStatus(0); // 状态 0:已过期 1:未使用 2:已使用 + highUserCoupon.setQrCodeImg(null); + updateUserCoupon(highUserCoupon); + + // 查询销售码 + HighCouponCode couponCode = highCouponCodeService.getCouponCodeById(highUserCoupon.getCouponCodeId()); + couponCode.setChildOrderId(null); + couponCode.setReceiveTime(null); + + HighUser highUser = highUserService.findByUserId(highUserCoupon.getUserId()); + + // 查询卡券信息 + HighCoupon coupon = highCouponService.getCouponById(highUserCoupon.getCouponId()); + + HighChildOrder childOrder = highOrderService.getChildOrderById(couponCode.getChildOrderId()); + HighOrder order = highOrderService.getOrderById(childOrder.getId()); + + // 归库记录 + HighCouponRecycle highCouponRecycle = new HighCouponRecycle(); + highCouponRecycle.setCouponId(coupon.getId()); + highCouponRecycle.setCouponName(coupon.getCouponName()); + highCouponRecycle.setMerchantId(coupon.getMerchantId()); + + highCouponRecycle.setCouponSalesCode(couponCode.getSalesCode()); + highCouponRecycle.setCouponCodeId(couponCode.getId()); + + highCouponRecycle.setOrderId(childOrder.getOrderId()); + highCouponRecycle.setOrderNo(order.getOrderNo()); + highCouponRecycle.setChildOrderId(childOrder.getId()); + + highCouponRecycle.setUserId(highUser.getId()); + highCouponRecycle.setUserPhone(highUser.getPhone()); + + highCouponRecycle.setType(1); // 类型:1.过期 2.退款 + highCouponRecycle.setReceiveTime(highUserCoupon.getCreateTime()); // 领取时间 + highCouponRecycle.setCreateTime(new Date()); + highCouponRecycleService.insertCouponRecycle(highCouponRecycle); } }