package com.gyee.alarm.config.interceptor;


import com.gyee.alarm.config.exception.LoginModeException;
import com.gyee.alarm.service.TokenService;
import com.gyee.alarm.util.SpringUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
 * 自定义拦截器
 * @author fc
 *
 */
public class MyInterceptor  implements HandlerInterceptor {


	public static TokenService tokenService= SpringUtils.getBean(TokenService.class);
	/*************演示模式需要 end*************/
	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)throws Exception {
		// System.out.println(">>>MyInterceptor1>>>>>>>在整个请求结束之后被调用，也就是在DispatcherServlet 渲染了对应的视图之后执行（主要是用于进行资源清理工作）");
	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)throws Exception {

	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
//		String token = request.getHeader("token");
//		if (!tokenService.sessionMap.containsKey(token)) {
//			throw new LoginModeException();
//		}
		return true;// 只有返回true才会继续向下执行，返回false取消当前请求
	}
	

}

