//package com.teaching.backend.utils; // ///** // * @Author:youhang // * @Date:2024-06-17-23:15 // * @Description: // */ // // // //import cn.hutool.json.JSONObject; //import cn.hutool.json.JSONUtil; //import com.teaching.backend.common.ErrorCode; //import com.teaching.backend.exception.BusinessException; //import org.aspectj.lang.JoinPoint; //import org.aspectj.lang.annotation.Aspect; //import org.aspectj.lang.annotation.Before; //import org.aspectj.lang.reflect.MethodSignature; //import org.springframework.core.LocalVariableTableParameterNameDiscoverer; //import org.springframework.stereotype.Component; // //import javax.servlet.http.HttpServletRequest; //import javax.servlet.http.HttpServletResponse; //import java.lang.reflect.Method; //import java.util.Arrays; //import java.util.List; //import java.util.stream.Collectors; // // //@Component //@Aspect //public class ParamOutAspect { // // // //对包下所有的controller结尾的类的所有方法增强 // private final String executeExpr = "execution(public * com.teaching.backend.controller..*.*(..))"; // // @Before(executeExpr) // public void processLog(JoinPoint joinPoint) { // Method method = ((MethodSignature) joinPoint.getSignature()).getMethod(); // //获取方法名称 // String methodName = method.getName(); // //获取参数名称 // LocalVariableTableParameterNameDiscoverer paramNames = new LocalVariableTableParameterNameDiscoverer(); // String[] params = paramNames.getParameterNames(method); // // // //获取参数f // Object[] args = joinPoint.getArgs(); // //过滤掉request和response,不能序列化 // List filteredArgs = Arrays.stream(args) // .filter(arg -> (!(arg instanceof HttpServletRequest) && !(arg instanceof HttpServletResponse))).collect(Collectors.toList()); // final Object[] array = filteredArgs.stream().toArray(); // // for (int i = 0; i < array.length; i++) { // System.out.println(array[i]); // String jsonStr = JSONUtil.toJsonStr(array[i]); // System.out.println(jsonStr); // Class myClass = array[i].getClass(); // 获取类的 Class 对象 // System.out.println("class "+myClass); // JSONObject entries = JSONUtil.parseObj(jsonStr); // System.out.println(entries); // // 遍历JSONObject的属性 // entries.forEach((key, value) -> { // if(value == null || "".equals(value)){ // //可以设置为空的字段 // if(key.equals( "sortField")||key.equals( "sortOrder")){ // }else{ // throw new BusinessException(ErrorCode.PARAMS_NULL); // } // // } // System.out.println(key + ": " + value); // }); // } // } // } // // //