From 173c77762c4f8736842f4df82edda4fcab15123f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A3=B7=E5=8F=B6?= <14103883+leaf-phos@user.noreply.gitee.com> Date: Tue, 21 Jan 2025 16:10:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=9A=E5=91=98=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/ruoyi/task/vip/VipTask.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 smart-switch-service/src/main/java/com/ruoyi/task/vip/VipTask.java 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); + } + } + } + +}