package com.jiayue.ssi.job;


import com.jiayue.ssi.service.SysPolicyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

/**
* 自动检测并发会话数是否存在超时
*
* @author xsl
* @since 2023/06/28
*/
//@Service
//@EnableScheduling
//@Slf4j
public class AutoCheckSessionMap {
//    @Autowired
//    SysPolicyService sysPolicyService;

    /**
     * 每分钟执行
     */
//    @Scheduled(cron = "0 0/1 * * * ?")
    public void auditBak() throws Exception{
//        SysPolicy sysPolicy = sysPolicyService.getOne(new QueryWrapper<>());
//        // 非活动登出时间（分钟）
//        int inactiveLogout = sysPolicy.getInactiveLogout();
//
//        long iil = inactiveLogout * 1000 * 60;
//
//        Iterator<Map.Entry<String, UserVisitInfoDto>> entries = LoginConstants.sessionMap.entrySet().iterator();
//        while (entries.hasNext()) {
//            Map.Entry<String, UserVisitInfoDto> entry = entries.next();
//            // 判断会话连接里失效的用户
//            UserVisitInfoDto userVisitInfoDto = entry.getValue();
//            Long userTime = userVisitInfoDto.getVtime();
//            if (System.currentTimeMillis()> userTime + iil){
//                // 踢用户
//                LoginConstants.sessionMap.remove(entry.getKey());
//                Iterator<Map.Entry<String, String>> countMap = CacheConstants.IP_USER_MAP.entrySet().iterator();
//                while (countMap.hasNext()) {
//                    Map.Entry<String, String> entry1 = countMap.next();
//                    String cacheusername = entry1.getValue();
//                    if (cacheusername.equals(userVisitInfoDto.getUsername())){
//                        countMap.remove();
//                    }
//                }
//                // 记录用户退出日志
//                LoginFactory.autoRecordLogininfor(userVisitInfoDto, Constants.LOGIN_SUCCESS, "超时登出");
//            }
//        }
    }
}
