package com.fufan.mtsaas.listener;

//import com.fufan.mtsaas.modules.sysmgr.dao.journal.AiLoginLogoutDao;
//import com.fufan.mtsaas.modules.sysmgr.journal.model.AiLoginLogout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * Session监听器
 *
 * @version 1.0
 * @auther Liby
 * @create 2018/5/4
 **/
@Component
@WebListener
public class SessionListener implements HttpSessionListener {

    public static final Logger LOGGER = LoggerFactory.getLogger(SessionListener.class);
//    @Autowired
//    private AiLoginLogoutDao aiLoginLogoutDao;

    @Override
    public void sessionCreated(HttpSessionEvent httpSessionEvent) {

    }

    @Override
    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
        HttpSession session = httpSessionEvent.getSession();
        /**
         * 更新登录登出日志表的退出时间
         * */
        if(session.getAttribute(session.getId()+"login") != null){
//            AiLoginLogout aiLoginLogout = new AiLoginLogout();
//            aiLoginLogout.setSysId((String) session.getAttribute(session.getId()+"login"));
//            aiLoginLogout = aiLoginLogoutDao.selectOne(aiLoginLogout);
//            aiLoginLogout.setLogoutTime(new Date());
//            aiLoginLogoutDao.updateById(aiLoginLogout);
        }
    }
}
