This commit is contained in:
1009473166@qq.com
2026-07-31 10:17:43 +08:00
parent 0a021caba6
commit af4c0a274d
63 changed files with 12920 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
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();
}
}