package com.lingyue.config.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

/**
 * 请求参数日志记录拦截器
 *
 * @author lingyue
 */
@Slf4j
@Component
public class RequestParameterLoggingInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        if (log.isDebugEnabled()) {
            String method = request.getMethod();
            String uri = request.getRequestURI();
            String queryString = request.getQueryString();
            
            log.debug("Request: {} {}", method, uri);
            if (queryString != null) {
                log.debug("Query Parameters: {}", queryString);
            }
        }
        return true;
    }
}

