diff --git a/smart-switch-service/src/main/java/com/ruoyi/task/vip/VipTask.java b/smart-switch-service/src/main/java/com/ruoyi/task/vip/VipTask.java new file mode 100644 index 00000000..0b3f37f0 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/task/vip/VipTask.java @@ -0,0 +1,53 @@ +package com.ruoyi.task.vip; + +import java.time.LocalDate; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.ruoyi.common.utils.ServiceUtil; +import com.ruoyi.common.utils.collection.CollectionUtils; +import com.ruoyi.ss.vip.domain.VipQuery; +import com.ruoyi.ss.vip.domain.VipVO; +import com.ruoyi.ss.vip.service.VipService; +import com.ruoyi.ss.vipLevel.domain.enums.VipLevelLimitType; + +import lombok.extern.slf4j.Slf4j; + +@Component +@Slf4j +public class VipTask { + + @Autowired + private VipService vipService; + + /** + * 每天执行一次,刷新今天需要刷新的VIP周期计数 + */ + public void resetVipRoundCount() { + + // 查询今天需要刷新的VIP周期计数 + VipQuery query = new VipQuery(); + query.setNextResetDate(LocalDate.now()); + query.setLimitTypes(VipLevelLimitType.needReset()); + query.setInValid(true); + List vipList = vipService.selectVipList(query); + + if (CollectionUtils.isEmpty(vipList)) { + log.info("今天没有需要刷新的VIP周期计数"); + return; + } + + // 清除今天需要刷新的VIP周期计数 + for (VipVO vip : vipList) { + try { + int result = vipService.resetVipRoundCount(vip); + ServiceUtil.assertion(result != 1, "刷新VIP周期计数失败,VIPID:{}", vip.getId()); + } catch (Exception e) { + log.error("刷新VIP周期计数失败", e); + } + } + } + +}