package com.blueland.bpm.manage.interceptor;

import cn.hutool.core.util.URLUtil;
import com.blueland.bpm.common.util.SysConfig;
import com.blueland.bpm.manage.util.MyContants;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URI;

/**
 * @description token校验拦截器
 * @author hanj
 */
public class ProcessModelerUrlInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String url = request.getRequestURL().toString();
        URI uri = URLUtil.toURI(url);
        if(uri.getHost().contains("222.244")){
            MyContants.resetBpmProcessModelerPath(uri.getScheme() + "://" + uri.getHost() + ":39082/bpmc-md/");
        } else {
            MyContants.resetBpmProcessModelerPath((String) SysConfig.getValue("bpm_process_modeler_path"));
        }
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

    }

}
