48 lines
1.2 KiB
Java
48 lines
1.2 KiB
Java
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();
|
||
}
|
||
}
|