Files
FT546MWS/ruoyi-license/src/main/java/com/ruoyi/license/task/LicenseCheckTask.java
1009473166@qq.com af4c0a274d 1
2026-07-31 10:17:43 +08:00

48 lines
1.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.ruoyi.license.task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.license.service.ISysLicenseService;
/**
* 授权检查定时任务
*
* @author ruoyi
*/
@Component
public class LicenseCheckTask
{
@Autowired
private ISysLicenseService licenseService;
@Autowired
private RedisCache redisCache;
@Value("${license.enabled:false}")
private boolean licenseEnabled;
/**
* 每5分钟检查一次授权状态
*/
@Scheduled(cron = "0 */5 * * * ?")
public void checkLicense()
{
if (!licenseEnabled)
{
return;
}
if (!licenseService.checkLicenseValid())
{
// 授权无效,删除 Redis 中所有登录 token,强制踢出所有在线用户
redisCache.deleteObject(redisCache.keys(CacheConstants.LOGIN_TOKEN_KEY + "*"));
}
licenseService.updateExpiredLicenses();
}
}