| package com.zy.system.timer; | 
|   | 
| import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
| import com.core.common.Cools; | 
| import com.zy.system.entity.UserLogin; | 
| import com.zy.system.service.UserLoginService; | 
| import lombok.extern.slf4j.Slf4j; | 
| 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 java.util.List; | 
|   | 
| /** | 
|  * token定时任务,删除过期的token | 
|  */ | 
| @Component | 
| @Slf4j | 
| public class TokenTimer { | 
|   | 
|     @Autowired | 
|     private UserLoginService userLoginService; | 
|   | 
|     @Autowired | 
|     private LoadingConfigTimer loadingConfigTimer; | 
|   | 
|     @Value("${super.pwd}") | 
|     private String superPwd; | 
|   | 
|     @Scheduled(cron = "0/30 * * * * ? ") | 
|     public void timer() { | 
|         if (loadingConfigTimer.getTokenNumber() == 1) { | 
|             return; | 
|         } | 
|         List<UserLogin> userLogins = userLoginService.selectList(new EntityWrapper<>()); | 
|         for (UserLogin userLogin : userLogins) { | 
|             String deToken = Cools.deTokn(userLogin.getToken(), superPwd); | 
|             if (deToken != null) { | 
|                 long timestamp = Long.parseLong(deToken.substring(0, 13)); | 
|                 // 半小时后过期 | 
|                 if (System.currentTimeMillis() - timestamp > loadingConfigTimer.getTokenExpire()) { | 
|                     userLoginService.deleteById(userLogin.getId()); | 
|                 } | 
|   | 
|             } | 
|         } | 
|     } | 
|   | 
| } |