|
|
@@ -1,22 +1,20 @@
|
|
|
package shop.alien.job.store;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
-import shop.alien.entity.store.LifeCoupon;
|
|
|
-import shop.alien.entity.store.LifeGroupBuyMain;
|
|
|
-import shop.alien.entity.store.LifeUserOrder;
|
|
|
-import shop.alien.mapper.LifeCouponMapper;
|
|
|
-import shop.alien.mapper.LifeGroupBuyMainMapper;
|
|
|
-import shop.alien.mapper.LifeUserOrderMapper;
|
|
|
-import shop.alien.util.common.AlipayTradeRefund;
|
|
|
-import shop.alien.util.common.constant.CouponStatusEnum;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Calendar;
|
|
|
-import java.util.Date;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+import shop.alien.entity.store.*;
|
|
|
+import shop.alien.mapper.*;
|
|
|
+import shop.alien.util.common.constant.DiscountCouponEnum;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -31,338 +29,102 @@ import java.util.List;
|
|
|
@RequiredArgsConstructor
|
|
|
public class LifeCouponJob {
|
|
|
|
|
|
- private final LifeCouponMapper lifeCouponMapper;
|
|
|
-
|
|
|
- private final LifeUserOrderMapper lifeUserOrderMapper;
|
|
|
-
|
|
|
- private final AlipayTradeRefund alipayTradeRefund;
|
|
|
- private final LifeGroupBuyMainMapper lifeGroupBuyMainMapper;
|
|
|
+ private static final int HOURS_72_DAYS = 3;
|
|
|
+ private static final int HOURS_24_DAYS = 1;
|
|
|
+ private static final String RECEIVE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
|
|
|
+ private final LifeDiscountCouponUserMapper lifeDiscountCouponUserMapper;
|
|
|
+ private final LifeDiscountCouponMapper lifeDiscountCouponMapper;
|
|
|
+ private final LifeUserMapper lifeUserMapper;
|
|
|
+ private final LifeNoticeMapper lifeNoticeMapper;
|
|
|
+ private final StoreInfoMapper storeInfoMapper;
|
|
|
|
|
|
/**
|
|
|
- * 该方法用于定时更新生活优惠券(LifeCoupon)的状态
|
|
|
+ * 优惠券即将到期提醒:查询 life_discount_coupon_user 表,若距离到期时间为 72 小时(3 天)或 24 小时(1 天),则给用户发送站内通知。
|
|
|
*/
|
|
|
- @XxlJob("quanStatusUpdateTask")
|
|
|
- @Deprecated
|
|
|
- public void quanStatusUpdateTask() {
|
|
|
- //执行修改代金券状态
|
|
|
- System.out.println("执行修改代金券状态 ===>");
|
|
|
- // 获取当前时间
|
|
|
- Date now = new Date();
|
|
|
- // 创建一个 Calendar 实例,用于对日期进行操作
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- // 将 Calendar 的时间设置为当前时间
|
|
|
- calendar.setTime(now);
|
|
|
- // 将 Calendar 的小时设置为 0
|
|
|
- calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
- // 将 Calendar 的分钟设置为 0
|
|
|
- calendar.set(Calendar.MINUTE, 0);
|
|
|
- // 将 Calendar 的秒设置为 0
|
|
|
- calendar.set(Calendar.SECOND, 0);
|
|
|
- // 将 Calendar 的毫秒设置为 0
|
|
|
- calendar.set(Calendar.MILLISECOND, 0);
|
|
|
- // 获取处理后的时间,即当前日期的零点
|
|
|
- now = calendar.getTime();
|
|
|
+ @XxlJob("couponExpiringNoticeJob")
|
|
|
+ public void couponExpiringNotice() {
|
|
|
+ LocalDate now = LocalDate.now();
|
|
|
+ LocalDate expireIn3Days = now.plusDays(HOURS_72_DAYS);
|
|
|
+ LocalDate expireIn1Day = now.plusDays(HOURS_24_DAYS);
|
|
|
+
|
|
|
+ // 查询 72h(3天) 和 24h(1天) 后到期的、待使用的用户优惠券(仅优惠券,不含代金券)
|
|
|
+ LambdaQueryWrapper<LifeDiscountCouponUser> wrapper = new LambdaQueryWrapper<LifeDiscountCouponUser>()
|
|
|
+ .eq(LifeDiscountCouponUser::getStatus, Integer.parseInt(DiscountCouponEnum.WAITING_USED.getValue()))
|
|
|
+ .isNotNull(LifeDiscountCouponUser::getCouponId)
|
|
|
+ .in(LifeDiscountCouponUser::getExpirationTime, expireIn1Day, expireIn3Days);
|
|
|
+
|
|
|
+ List<LifeDiscountCouponUser> userCoupons = lifeDiscountCouponUserMapper.selectList(wrapper);
|
|
|
+ if (CollectionUtils.isEmpty(userCoupons)) {
|
|
|
+ log.info("优惠券到期提醒: 无符合条件(72h/24h 内到期)的用户优惠券");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ SimpleDateFormat receiveSdf = new SimpleDateFormat(RECEIVE_TIME_PATTERN);
|
|
|
+ DateTimeFormatter expirationFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
|
|
- // 创建一个 LambdaUpdateWrapper 用于查询生活优惠券,这里实际上主要用于查询操作
|
|
|
- LambdaUpdateWrapper<LifeCoupon> selectWrapper = new LambdaUpdateWrapper<>();
|
|
|
- // 创建一个集合,用于存储要查询的优惠券状态值
|
|
|
- List<Integer> ids = new ArrayList<>();
|
|
|
- // 待审核
|
|
|
- ids.add(0);
|
|
|
- // 进行中
|
|
|
- ids.add(1);
|
|
|
- // 已暂停
|
|
|
- ids.add(2);
|
|
|
- // 设置查询条件,查询状态为 0、1 或 2 的生活优惠券
|
|
|
- selectWrapper.in(LifeCoupon::getStatus, ids);
|
|
|
- // 调用 lifeCouponMapper 的 selectList 方法,根据上述条件查询生活优惠券列表
|
|
|
- List<LifeCoupon> jinxingzhongList = lifeCouponMapper.selectList(selectWrapper);
|
|
|
- // 判断查询结果列表是否不为空
|
|
|
- if (!jinxingzhongList.isEmpty()) {
|
|
|
- // 遍历查询到的生活优惠券列表
|
|
|
- for (LifeCoupon quan : jinxingzhongList) {
|
|
|
- // 获取当前优惠券的结束日期
|
|
|
- Date endTime = quan.getEndDate();
|
|
|
- // 比较当前日期(零点)和优惠券的结束日期,如果当前日期大于结束日期 将状态变成已结束
|
|
|
- if (now.compareTo(endTime) > 0) {
|
|
|
- // 创建一个 LambdaUpdateWrapper 用于更新生活优惠券的状态
|
|
|
- LambdaUpdateWrapper<LifeCoupon> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- // 设置更新条件,根据优惠券的 ID 进行更新
|
|
|
- updateWrapper.eq(LifeCoupon::getId, quan.getId())
|
|
|
- // 设置要更新的字段,将优惠券的状态更新为 3
|
|
|
- .set(LifeCoupon::getStatus, 3);
|
|
|
- // 调用 lifeCouponMapper 的 update 方法,根据上述条件更新优惠券的状态
|
|
|
- lifeCouponMapper.update(null, updateWrapper);
|
|
|
+ int sendCount = 0;
|
|
|
+ for (LifeDiscountCouponUser userCoupon : userCoupons) {
|
|
|
+ try {
|
|
|
+ LifeDiscountCoupon coupon = lifeDiscountCouponMapper.selectById(userCoupon.getCouponId());
|
|
|
+ if (coupon == null) {
|
|
|
+ log.warn("优惠券不存在, couponId={}", userCoupon.getCouponId());
|
|
|
+ continue;
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- // 创建另一个 LambdaUpdateWrapper 用于查询状态为 0 的生活优惠券
|
|
|
- LambdaUpdateWrapper<LifeCoupon> selectWrapper2 = new LambdaUpdateWrapper<>();
|
|
|
- // 设置查询条件,查询状态为 0 的生活优惠券
|
|
|
- selectWrapper2.eq(LifeCoupon::getStatus, 0);
|
|
|
- // 调用 lifeCouponMapper 的 selectList 方法,根据上述条件查询生活优惠券列表
|
|
|
- List<LifeCoupon> weikaishiList = lifeCouponMapper.selectList(selectWrapper2);
|
|
|
- // 判断查询结果列表是否不为空
|
|
|
- if (!weikaishiList.isEmpty()) {
|
|
|
- // 遍历查询到的生活优惠券列表
|
|
|
- for (LifeCoupon quan : weikaishiList) {
|
|
|
- // 获取当前优惠券的开始日期
|
|
|
- Date startTime = quan.getStartDate();
|
|
|
- // 获取当前优惠券的结束日期
|
|
|
- Date endTime = quan.getEndDate();
|
|
|
- // 判断当前日期(零点)是否在优惠券的开始日期和结束日期之间 将待使用变成进行中
|
|
|
- if (now.compareTo(startTime) >= 0 && now.compareTo(endTime) <= 0) {
|
|
|
- // 创建一个 LambdaUpdateWrapper 用于更新生活优惠券的状态
|
|
|
- LambdaUpdateWrapper<LifeCoupon> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- // 设置更新条件,根据优惠券的 ID 进行更新
|
|
|
- updateWrapper.eq(LifeCoupon::getId, quan.getId())
|
|
|
- // 设置要更新的字段,将优惠券的状态更新为 1
|
|
|
- .set(LifeCoupon::getStatus, 1);
|
|
|
- // 调用 lifeCouponMapper 的 update 方法,根据上述条件更新优惠券的状态
|
|
|
- lifeCouponMapper.update(null, updateWrapper);
|
|
|
+ LifeUser user = lifeUserMapper.selectById(userCoupon.getUserId());
|
|
|
+ if (user == null || !StringUtils.hasText(user.getUserPhone())) {
|
|
|
+ log.warn("用户不存在或手机号为空, userId={}", userCoupon.getUserId());
|
|
|
+ continue;
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 过期自动退
|
|
|
- */
|
|
|
- @XxlJob("orderStatusUpdateTask")
|
|
|
- @Deprecated
|
|
|
- public void orderStatusUpdateTask() {
|
|
|
- Date now = new Date();
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(now);
|
|
|
- calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
- calendar.set(Calendar.MINUTE, 0);
|
|
|
- calendar.set(Calendar.SECOND, 0);
|
|
|
- calendar.set(Calendar.MILLISECOND, 0);
|
|
|
- now = calendar.getTime();
|
|
|
- LambdaUpdateWrapper<LifeUserOrder> selectWrapper = new LambdaUpdateWrapper<>();
|
|
|
- List<Integer> ids = new ArrayList<>();
|
|
|
- ids.add(0);
|
|
|
- ids.add(3);
|
|
|
- selectWrapper.in(LifeUserOrder::getStatus, ids);
|
|
|
- List<LifeUserOrder> orderList = lifeUserOrderMapper.selectList(selectWrapper);
|
|
|
- if (!orderList.isEmpty()) {
|
|
|
- for (LifeUserOrder order : orderList) {
|
|
|
- Date payTime = order.getPayTime();
|
|
|
- LifeCoupon quan = lifeCouponMapper.selectById(order.getQuanId());
|
|
|
- calendar.setTime(payTime);
|
|
|
- calendar.add(Calendar.DAY_OF_MONTH, quan.getExpirationDate());
|
|
|
- Date guoqiDate = calendar.getTime();
|
|
|
- Date endDate = quan.getEndDate();
|
|
|
- if (now.compareTo(guoqiDate) > 0 || now.compareTo(endDate) > 0) {
|
|
|
- String result = alipayTradeRefund.processRefund(order.getOrderNo(), order.getFinalPrice(), "过期自动退");
|
|
|
- if (result.equals("调用成功")) {
|
|
|
- LambdaUpdateWrapper<LifeUserOrder> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- updateWrapper.eq(LifeUserOrder::getId, order.getId()).set(LifeUserOrder::getStatus, 4).set(LifeUserOrder::getRefundTime, new Date());
|
|
|
- lifeUserOrderMapper.update(null, updateWrapper);
|
|
|
+ String storeName = "未知店铺";
|
|
|
+ if (StringUtils.hasText(coupon.getStoreId())) {
|
|
|
+ try {
|
|
|
+ StoreInfo store = storeInfoMapper.selectById(Integer.parseInt(coupon.getStoreId().trim()));
|
|
|
+ if (store != null && StringUtils.hasText(store.getStoreName())) {
|
|
|
+ storeName = store.getStoreName();
|
|
|
+ }
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ log.debug("优惠券 storeId 非数字, couponId={}, storeId={}", coupon.getId(), coupon.getStoreId());
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 代金券状态更新 (到时间定时上架,过期自动下架)
|
|
|
- */
|
|
|
- @XxlJob("couponStatusUpdateTask")
|
|
|
- public void couponStatusUpdateTask(){
|
|
|
- //执行修改代金券状态
|
|
|
- System.out.println("执行修改代金券状态 ===>");
|
|
|
- // 获取当前时间
|
|
|
- Date now = new Date();
|
|
|
- // 创建一个 Calendar 实例,用于对日期进行操作
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- // 将 Calendar 的时间设置为当前时间
|
|
|
- calendar.setTime(now);
|
|
|
- // 将 Calendar 的小时设置为 0
|
|
|
- calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
- // 将 Calendar 的分钟设置为 0
|
|
|
- calendar.set(Calendar.MINUTE, 0);
|
|
|
- // 将 Calendar 的秒设置为 0
|
|
|
- calendar.set(Calendar.SECOND, 0);
|
|
|
- // 将 Calendar 的毫秒设置为 0
|
|
|
- calendar.set(Calendar.MILLISECOND, 0);
|
|
|
- // 获取处理后的时间,即当前日期的零点
|
|
|
- now = calendar.getTime();
|
|
|
-
|
|
|
- // 创建一个 LambdaUpdateWrapper 用于查询生活优惠券,这里实际上主要用于查询操作
|
|
|
- LambdaUpdateWrapper<LifeCoupon> selectWrapper = new LambdaUpdateWrapper<>();
|
|
|
- // 创建一个集合,用于存储要查询的优惠券状态值
|
|
|
- List<Integer> status = new ArrayList<>();
|
|
|
- //
|
|
|
- status.add(CouponStatusEnum.NOT_START.getCode());
|
|
|
- status.add(CouponStatusEnum.SOLD_OUT.getCode());
|
|
|
- status.add(CouponStatusEnum.ONGOING.getCode());
|
|
|
- status.add(CouponStatusEnum.SOLD_OFF.getCode());
|
|
|
|
|
|
- // 设置查询条件,查询状态为2,4,5,6 的生活优惠券
|
|
|
- selectWrapper.in(LifeCoupon::getStatus, status);
|
|
|
- // 调用 lifeCouponMapper 的 selectList 方法,根据上述条件查询生活优惠券列表
|
|
|
- List<LifeCoupon> jinxingzhongList = lifeCouponMapper.selectList(selectWrapper);
|
|
|
- System.out.println("执行修改代金券状态 ===> 未开始 已售罄 进行中,已下架 优惠券列表 ===> " + jinxingzhongList);
|
|
|
- List<String> endCouponIds = new ArrayList<>();
|
|
|
- // 判断查询结果列表是否不为空
|
|
|
- if (!jinxingzhongList.isEmpty()) {
|
|
|
- // 遍历查询到的生活优惠券列表
|
|
|
- for (LifeCoupon quan : jinxingzhongList) {
|
|
|
- // 获取当前优惠券的结束日期
|
|
|
- Date endTime = quan.getEndDate();
|
|
|
- // 比较当前日期(零点)和优惠券的结束日期,如果当前日期大于结束日期 将状态变成已结束
|
|
|
- if (now.compareTo(endTime) > 0) {
|
|
|
- endCouponIds.add(quan.getId());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if(!endCouponIds.isEmpty()){
|
|
|
- // 创建一个 LambdaUpdateWrapper 用于更新生活优惠券的状态
|
|
|
- LambdaUpdateWrapper<LifeCoupon> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- // 设置更新条件,根据优惠券的 ID 进行更新
|
|
|
- updateWrapper.in(LifeCoupon::getId,endCouponIds)
|
|
|
- // 设置要更新的字段,将优惠券的状态更新为 3
|
|
|
- .set(LifeCoupon::getStatus, CouponStatusEnum.ENDED.getCode());
|
|
|
- // 调用 lifeCouponMapper 的 update 方法,根据上述条件更新优惠券的状态
|
|
|
- int updateNum = lifeCouponMapper.update(null, updateWrapper);
|
|
|
- System.out.println("执行修改代金券状态 ===> 已结束 优惠券列表 ===> " + endCouponIds);
|
|
|
- System.out.println("执行修改代金券状态 ===> 已结束 优惠券数量 ===> " + updateNum);
|
|
|
- }
|
|
|
-// --------------------------------------------------------------------------------------------------------
|
|
|
- // 创建另一个 LambdaUpdateWrapper 用于查询状态为 0 的生活优惠券
|
|
|
- LambdaUpdateWrapper<LifeCoupon> selectWrapper2 = new LambdaUpdateWrapper<>();
|
|
|
- // 设置查询条件,查询状态为 0 的生活优惠券
|
|
|
- selectWrapper2.eq(LifeCoupon::getStatus, CouponStatusEnum.NOT_START.getCode());
|
|
|
- // 调用 lifeCouponMapper 的 selectList 方法,根据上述条件查询生活优惠券列表
|
|
|
- List<LifeCoupon> weikaishiList = lifeCouponMapper.selectList(selectWrapper2);
|
|
|
- List<String> startCouponIds = new ArrayList<>();
|
|
|
- // 判断查询结果列表是否不为空
|
|
|
- if (!weikaishiList.isEmpty()) {
|
|
|
- // 遍历查询到的生活优惠券列表
|
|
|
- for (LifeCoupon quan : weikaishiList) {
|
|
|
- // 获取当前优惠券的开始日期
|
|
|
- Date startTime = quan.getStartDate();
|
|
|
- // 获取当前优惠券的结束日期
|
|
|
- Date endTime = quan.getEndDate();
|
|
|
- // 判断当前日期(零点)是否在优惠券的开始日期和结束日期之间 将待使用变成进行中
|
|
|
- if (now.compareTo(startTime) >= 0 && now.compareTo(endTime) <= 0) {
|
|
|
- startCouponIds.add(quan.getId());
|
|
|
- }
|
|
|
+ String receiveTimeStr = userCoupon.getReceiveTime() != null
|
|
|
+ ? receiveSdf.format(userCoupon.getReceiveTime())
|
|
|
+ : "";
|
|
|
+
|
|
|
+ String expirationTimeStr = userCoupon.getExpirationTime() != null
|
|
|
+ ? userCoupon.getExpirationTime().format(expirationFormatter) + " 23:59:59"
|
|
|
+ : "";
|
|
|
+
|
|
|
+ String amountDesc = coupon.getNominalValue() != null && coupon.getNominalValue().compareTo(BigDecimal.ZERO) > 0
|
|
|
+ ? coupon.getNominalValue().intValue() + "元"
|
|
|
+ : "优惠";
|
|
|
+ String couponName = StringUtils.hasText(coupon.getName()) ? coupon.getName() : "优惠券";
|
|
|
+
|
|
|
+ String context = String.format(
|
|
|
+ "您在%s领取的%s店铺的%s优惠券(%s);在%s到期,可在我的券包中查看,快去使用吧",
|
|
|
+ receiveTimeStr,
|
|
|
+ storeName,
|
|
|
+ amountDesc,
|
|
|
+ couponName,
|
|
|
+ expirationTimeStr
|
|
|
+ );
|
|
|
+
|
|
|
+ LifeNotice notice = new LifeNotice();
|
|
|
+ notice.setSenderId("system");
|
|
|
+ notice.setReceiverId("user_" + user.getUserPhone());
|
|
|
+ notice.setContext(context);
|
|
|
+ notice.setTitle("优惠券即将到期");
|
|
|
+ notice.setIsRead(0);
|
|
|
+ notice.setNoticeType(2);
|
|
|
+ lifeNoticeMapper.insert(notice);
|
|
|
+ sendCount++;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("优惠券到期提醒发送失败, userCouponId={}, userId={}", userCoupon.getId(), userCoupon.getUserId(), e);
|
|
|
}
|
|
|
}
|
|
|
- if(!startCouponIds.isEmpty()){
|
|
|
- // 创建一个 LambdaUpdateWrapper 用于更新生活优惠券的状态
|
|
|
- LambdaUpdateWrapper<LifeCoupon> updateWrapper2 = new LambdaUpdateWrapper<>();
|
|
|
- // 设置更新条件,根据优惠券的 ID 进行更新
|
|
|
- updateWrapper2.in(LifeCoupon::getId, startCouponIds)
|
|
|
- // 设置要更新的字段,将优惠券的状态更新为 1
|
|
|
- .set(LifeCoupon::getStatus, CouponStatusEnum.ONGOING.getCode());
|
|
|
- // 调用 lifeCouponMapper 的 update 方法,根据上述条件更新优惠券的状态
|
|
|
- int updateNum2 = lifeCouponMapper.update(null, updateWrapper2);
|
|
|
- System.out.println("执行修改代金券状态 ===> 进行中 优惠券列表 ===> " + startCouponIds);
|
|
|
- System.out.println("执行修改代金券状态 ===> 进行中 优惠券数量 ===> " + updateNum2);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 团购状态更新
|
|
|
- */
|
|
|
- @XxlJob("groupBuyStatusUpdateTask")
|
|
|
- public void groupBuyStatusUpdateTask(){
|
|
|
- //执行修改团购状态
|
|
|
- System.out.println("执行修改团购状态 ===>");
|
|
|
- // 获取当前时间
|
|
|
- Date now = new Date();
|
|
|
- // 创建一个 Calendar 实例,用于对日期进行操作
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- // 将 Calendar 的时间设置为当前时间
|
|
|
- calendar.setTime(now);
|
|
|
- // 将 Calendar 的小时设置为 0
|
|
|
- calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
- // 将 Calendar 的分钟设置为 0
|
|
|
- calendar.set(Calendar.MINUTE, 0);
|
|
|
- // 将 Calendar 的秒设置为 0
|
|
|
- calendar.set(Calendar.SECOND, 0);
|
|
|
- // 将 Calendar 的毫秒设置为 0
|
|
|
- calendar.set(Calendar.MILLISECOND, 0);
|
|
|
- // 获取处理后的时间,即当前日期的零点
|
|
|
- now = calendar.getTime();
|
|
|
|
|
|
- // 创建一个 LambdaUpdateWrapper 用于查询生活优惠券,这里实际上主要用于查询操作
|
|
|
- LambdaUpdateWrapper<LifeGroupBuyMain> selectWrapper = new LambdaUpdateWrapper<>();
|
|
|
- // 创建一个集合,用于存储要查询的优惠券状态值
|
|
|
- List<Integer> status = new ArrayList<>();
|
|
|
- //
|
|
|
- status.add(CouponStatusEnum.NOT_START.getCode());
|
|
|
- status.add(CouponStatusEnum.SOLD_OUT.getCode());
|
|
|
- status.add(CouponStatusEnum.ONGOING.getCode());
|
|
|
- status.add(CouponStatusEnum.SOLD_OFF.getCode());
|
|
|
-
|
|
|
- // 设置查询条件,查询状态为2,4,5,6 的生活优惠券
|
|
|
- selectWrapper.in(LifeGroupBuyMain::getStatus, status);
|
|
|
- // 调用 lifeCouponMapper 的 selectList 方法,根据上述条件查询生活优惠券列表
|
|
|
- List<LifeGroupBuyMain> jinxingzhongList = lifeGroupBuyMainMapper.selectList(selectWrapper);
|
|
|
- System.out.println("执行修改团购状态 ===> 未开始 已售罄 进行中,已下架 优惠券列表 ===> " + jinxingzhongList);
|
|
|
- List<Integer> endCouponIds = new ArrayList<>();
|
|
|
- // 判断查询结果列表是否不为空
|
|
|
- if (!jinxingzhongList.isEmpty()) {
|
|
|
- // 遍历查询到的生活优惠券列表
|
|
|
- for (LifeGroupBuyMain groupBuy : jinxingzhongList) {
|
|
|
- // 获取当前优惠券的结束日期
|
|
|
- Date endTime = groupBuy.getEndTime();
|
|
|
- // 比较当前日期(零点)和优惠券的结束日期,如果当前日期大于结束日期 将状态变成已结束
|
|
|
- if (now.compareTo(endTime) > 0) {
|
|
|
- endCouponIds.add(groupBuy.getId());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if(!endCouponIds.isEmpty()) {
|
|
|
- // 创建一个 LambdaUpdateWrapper 用于更新生活优惠券的状态
|
|
|
- LambdaUpdateWrapper<LifeGroupBuyMain> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- // 设置更新条件,根据优惠券的 ID 进行更新
|
|
|
- updateWrapper.in(LifeGroupBuyMain::getId, endCouponIds)
|
|
|
- // 设置要更新的字段,将优惠券的状态更新为 7
|
|
|
- .set(LifeGroupBuyMain::getStatus, CouponStatusEnum.ENDED.getCode());
|
|
|
- // 调用 lifeCouponMapper 的 update 方法,根据上述条件更新优惠券的状态
|
|
|
- int updateNum = lifeGroupBuyMainMapper.update(null, updateWrapper);
|
|
|
- System.out.println("执行修改团购状态 ===> 已结束 优惠券列表 ===> " + endCouponIds);
|
|
|
- System.out.println("执行修改团购状态 ===> 已结束 优惠券数量 ===> " + updateNum);
|
|
|
- }
|
|
|
-// --------------------------------------------------------------------------------------------------------
|
|
|
- // 创建另一个 LambdaUpdateWrapper 用于查询状态为 0 的生活优惠券
|
|
|
- LambdaUpdateWrapper<LifeGroupBuyMain> selectWrapper2 = new LambdaUpdateWrapper<>();
|
|
|
- // 设置查询条件,查询状态为 0 的生活优惠券
|
|
|
- selectWrapper2.eq(LifeGroupBuyMain::getStatus, CouponStatusEnum.NOT_START.getCode());
|
|
|
- // 调用 lifeCouponMapper 的 selectList 方法,根据上述条件查询生活优惠券列表
|
|
|
- List<LifeGroupBuyMain> weikaishiList = lifeGroupBuyMainMapper.selectList(selectWrapper2);
|
|
|
- List<Integer> startCouponIds = new ArrayList<>();
|
|
|
- // 判断查询结果列表是否不为空
|
|
|
- if (!weikaishiList.isEmpty()) {
|
|
|
- // 遍历查询到的生活优惠券列表
|
|
|
- for (LifeGroupBuyMain quan : weikaishiList) {
|
|
|
- // 获取当前优惠券的开始日期
|
|
|
- Date startTime = quan.getStartTimeValue();
|
|
|
- // 获取当前优惠券的结束日期
|
|
|
- Date endTime = quan.getEndTime();
|
|
|
- // 判断当前日期(零点)是否在优惠券的开始日期和结束日期之间 将待使用变成进行中
|
|
|
- if (now.compareTo(startTime) >= 0 && now.compareTo(endTime) <= 0) {
|
|
|
- startCouponIds.add(quan.getId());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (!startCouponIds.isEmpty()) {
|
|
|
- // 创建一个 LambdaUpdateWrapper 用于更新生活优惠券的状态
|
|
|
- LambdaUpdateWrapper<LifeGroupBuyMain> updateWrapper2 = new LambdaUpdateWrapper<>();
|
|
|
- // 设置更新条件,根据优惠券的 ID 进行更新
|
|
|
- updateWrapper2.in(LifeGroupBuyMain::getId, startCouponIds)
|
|
|
- // 设置要更新的字段,将优惠券的状态更新为 1
|
|
|
- .set(LifeGroupBuyMain::getStatus, CouponStatusEnum.ONGOING.getCode());
|
|
|
- // 调用 lifeCouponMapper 的 update 方法,根据上述条件更新优惠券的状态
|
|
|
- int updateNum2 = lifeGroupBuyMainMapper.update(null, updateWrapper2);
|
|
|
- System.out.println("执行修改团购状态 ===> 进行中 优惠券列表 ===> " + startCouponIds);
|
|
|
- System.out.println("执行修改团购状态 ===> 进行中 优惠券数量 ===> " + updateNum2);
|
|
|
- }
|
|
|
+ log.info("优惠券到期提醒: 共处理 {} 条, 成功发送 {} 条通知", userCoupons.size(), sendCount);
|
|
|
}
|
|
|
}
|