/* */ package cn.cloudwalk.service.aop; /* */ /* */ import cn.cloudwalk.cloud.annotation.CloudwalkParamsValidate; /* */ import cn.cloudwalk.cloud.result.CloudwalkResult; /* */ import java.lang.reflect.Method; /* */ import java.util.Iterator; /* */ import java.util.Set; /* */ import javax.validation.ConstraintViolation; /* */ import javax.validation.Validator; /* */ import javax.validation.groups.Default; /* */ import org.aspectj.lang.ProceedingJoinPoint; /* */ import org.aspectj.lang.annotation.Around; /* */ import org.aspectj.lang.annotation.Aspect; /* */ import org.aspectj.lang.annotation.Pointcut; /* */ import org.aspectj.lang.reflect.MethodSignature; /* */ import org.slf4j.Logger; /* */ import org.slf4j.LoggerFactory; /* */ import org.springframework.beans.factory.annotation.Autowired; /* */ import org.springframework.context.MessageSource; /* */ import org.springframework.context.i18n.LocaleContextHolder; /* */ import org.springframework.core.annotation.Order; /* */ import org.springframework.stereotype.Component; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ @Aspect /* */ @Order(-100) /* */ @Component /* */ public class CloudwalkParamsValidateAspect /* */ { /* 43 */ private final Logger logger = LoggerFactory.getLogger(getClass()); /* */ /* */ /* */ /* */ /* */ /* */ @Autowired /* */ private Validator validator; /* */ /* */ /* */ /* */ /* */ /* */ @Autowired /* */ private MessageSource messageSource; /* */ /* */ /* */ /* */ /* */ /* */ public String getMessage(String code) { /* 64 */ return this.messageSource.getMessage(code, null, LocaleContextHolder.getLocale()); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ @Pointcut("@annotation(cn.cloudwalk.cloud.annotation.CloudwalkParamsValidate)") /* */ public void validatePointcat() {} /* */ /* */ /* */ /* */ /* */ /* */ @Around("validatePointcat()") /* */ public Object around(ProceedingJoinPoint joinPoint) throws Throwable { /* 80 */ MethodSignature methodSignature = (MethodSignature)joinPoint.getSignature(); /* 81 */ Method targetMethod = joinPoint.getTarget().getClass().getMethod(methodSignature /* 82 */ .getName(), methodSignature.getParameterTypes()); /* */ /* 84 */ this.logger.debug("正在进行对类{}中方法{}进行参数检查开始", joinPoint.getTarget().getClass().getName(), targetMethod.getName()); /* */ /* */ /* 87 */ CloudwalkParamsValidate paramsValidate = targetMethod.getAnnotation(CloudwalkParamsValidate.class); /* 88 */ if (paramsValidate == null) { /* 89 */ return joinPoint.proceed(); /* */ } /* */ /* */ /* 93 */ int[] needCheckParamIndexs = paramsValidate.argsIndexs(); /* 94 */ if (needCheckParamIndexs == null) { /* 95 */ return joinPoint.proceed(); /* */ } /* */ /* */ /* 99 */ Class[] groupsClazz = paramsValidate.groups(); /* 100 */ if (groupsClazz == null) { /* 101 */ groupsClazz = new Class[] { Default.class }; /* */ } /* */ /* 104 */ Object[] args = joinPoint.getArgs(); /* 105 */ for (int index : needCheckParamIndexs) { /* 106 */ Object arg = args[index]; /* */ /* 108 */ Set> constraintViolationSet = this.validator.validate(arg, groupsClazz); /* 109 */ if (constraintViolationSet != null && constraintViolationSet.size() > 0) { /* 110 */ Iterator> iterator = constraintViolationSet.iterator(); if (iterator.hasNext()) { ConstraintViolation constraintViolation = iterator.next(); /* 111 */ String code = constraintViolation.getMessage(); /* 112 */ return CloudwalkResult.fail(code, getMessage(code)); } /* */ /* */ } /* */ } /* */ /* 117 */ this.logger.debug("正在进行对类{}中方法{}进行参数检查通过", joinPoint.getTarget().getClass().getName(), targetMethod.getName()); /* */ /* 119 */ return joinPoint.proceed(); /* */ } /* */ } /* Location: D:\星中心\cw-elevator-application-V1.0.0.20211103\cw-elevator-application-V1.0.0.20211103\lib\cloudwalk-common-service-3.7.2-Brussels-SRX.jar!\cn\cloudwalk\service\aop\CloudwalkParamsValidateAspect.class * Java compiler version: 7 (51.0) * JD-Core Version: 1.1.3 */