whyclxw
2025-05-28 e16302f9d475c7cc4dd18c5abf1a23cb5502e362
src/main/java/com/whyc/task/AccountLockStrategyTask.java
@@ -1,8 +1,13 @@
package com.whyc.task;
import com.github.pagehelper.PageInfo;
import com.whyc.pojo.PageParam;
import com.whyc.service.PageParamService;
import com.whyc.service.UserService;
import com.whyc.util.ActionUtil;
import com.whyc.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.servlet.ServletContext;
@@ -15,8 +20,10 @@
 * 账号登录失败时间超过24小时,移除
 * TODO 尚未测试
 */
@Component
public class AccountLockStrategyTask extends TimerTask {
    @Autowired
    private ServletContext servletContext;
    @Resource
@@ -25,23 +32,20 @@
    @Resource
    private PageParamService pageParamService;
    public AccountLockStrategyTask(ServletContext servletContext) {
        this.servletContext = servletContext;
    }
    @Override
    public void run() {
        //临时账号检测是否过期,如果过期,更改状态为注销
        userService.updateExpiredAccount();
        //查询账号解锁策略
        PageParam accountUnLock = (PageParam) ((List)pageParamService.findByCategoryId(9).getData()).get(1);
        PageParam accountUnLock = (PageParam) ((PageInfo)pageParamService.findByCategoryId(9).getData()).getList().get(1);
        if(accountUnLock.getStatus()==2){ //自动解锁策略
            //查询账号锁定时间,超过20分钟解锁
            userService.unLock();
        }
        //登录失败时间超过24小时记录,内存中application移除
        //servletContext = ActionUtil.getApplication();
        Enumeration<String> attributeNames = servletContext.getAttributeNames();
        //24小时前的时间戳
        long oneDayBefore = System.currentTimeMillis()-24*60*60*1000;