puzhibing
2024-09-18 2b8f76b2b39ec7e69d9a59133346776c2297e808
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/task/TaskUtil.java
@@ -1,8 +1,11 @@
package com.ruoyi.account.task;
import com.ruoyi.account.api.model.TAppUser;
import com.ruoyi.account.api.model.TAppUserVipDetail;
import com.ruoyi.account.service.TAppUserService;
import com.ruoyi.account.service.TAppUserVipDetailService;
import org.intellij.lang.annotations.RegExp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -21,6 +24,8 @@
    @Resource
    private TAppUserVipDetailService tAppUserVipDetailService;
    @Resource
    private TAppUserService appUserService;
    /**
@@ -48,6 +53,27 @@
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Scheduled(fixedRate = 1000 * 60)
    public void changeVipId(){
        LocalDate currentDate = LocalDate.now();
        List<TAppUserVipDetail> recentDetails = tAppUserVipDetailService.lambdaQuery()
                .le(TAppUserVipDetail::getStartTime, currentDate)
                .ge(TAppUserVipDetail::getEndTime, currentDate)
                .orderByDesc(TAppUserVipDetail::getStartTime).list();
        for (TAppUserVipDetail recentDetail : recentDetails) {
            TAppUser byId = appUserService.getById(recentDetail.getAppUserId());
            if (byId!=null) {
                byId.setVipId(recentDetail.getVipId());
                appUserService.updateById(byId);
            }
        }
    }