package dhht.seal.hn.gate.config;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author sh
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface ApiInfoAnnotion {
String name() default "";
String version() default "";
}
package dhht.seal.hn.gate.config;
import dhht.seal.hn.gate.util.VersionInfo;
import dhht.seal.hn.gate.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
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.springframework.stereotype.Component;
import java.lang.reflect.Method;
/**
* @Author: sh
* @Description:
* @Version:
* @Date: 2020/12/28
*/
@Slf4j
@Component
@Aspect
public class ApiInfoControllerAop {
@Pointcut("execution(* dhht.seal.hn.gate..*Controller.*(..))")
public void pointCut() {
}
@Around(value = "pointCut()")
public Object around(ProceedingJoinPoint joinPoint) {
String name = "";
try {
Class<?> aClass = joinPoint.getTarget().getClass();
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method declaredMethod = aClass.getDeclaredMethod(signature.getName(), signature.getParameterTypes());
ApiInfoAnnotion annotation = declaredMethod.getAnnotation(ApiInfoAnnotion.class);
boolean bl = (null != annotation);
if (bl) {
name = annotation.name();
log.info("===start opt===" + name + "===version" + VersionInfo.VERION);
}
//return joinPoint.proceed();
Object proceed = joinPoint.proceed();
if (bl) {
log.info("===end opt===" + name + "===version" + VersionInfo.VERION);
}
return proceed;
} catch (Throwable throwable) {
log.error(throwable.getMessage());
log.error("===end opt===" + name + "===version" + VersionInfo.VERION);
return ResultVO.fail(throwable.getMessage(), null);
}
}
}
@ApiInfoAnnotion(name = "用章单位备案")
@PostMapping(value = "approval", produces = "application/json;charset=UTF-8", name = "用章单位备案")
public ResultVO approval(@RequestBody @Valid ReqCropApprovalVO data, BindingResult bindingResult) {
ResultVO resultVO = cropService.cropApproval(data);
return resultVO;
}