package com.persagy.adm.diagram.frame;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 处理bdtp请求参数，创建/销毁请求对象封装
 */
@Component
public class BdtpInterceptor extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		BdtpRequest req = BdtpRequest.get(request.getParameter("groupCode"), request.getParameter("projectId"), request.getParameter("userId"));
		BdtpRequest.setCurrent(req);
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
		BdtpRequest.removeCurrent();
	}

}
