package top.imwork.commons.core.handler;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import top.imwork.commons.core.constants.Constants;

import java.util.UUID;

/**
 * Copyright (C), 2015-2021
 * FileName: ImworkRequestHandlerInterceptor
 * Author(作者姓名):   stars
 * CreateDate(创建时间):     2021/8/2 15:28
 * UpdateDate(修改时间):     2021/8/2 15:28
 * Description(功能描述):    通用请求拦截器
 * Since(版本号)  1.0.0
 * History:
 */
public class BaseCoreRequestHandlerInterceptor implements HandlerInterceptor {
    static final Logger logger = LoggerFactory.getLogger(BaseCoreRequestHandlerInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        request.setAttribute(Constants.REQUEST_HEAD_ID, UUID.randomUUID());
        logger.info(Constants.REQUEST_HEAD_ID + " = {}", request.getAttribute(Constants.REQUEST_HEAD_ID));
        return true;
    }

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

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