脚本宝典收集整理的这篇文章主要介绍了自定义注解拦截,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
@Slf4j @AsPEct @component public class CheckCorpTypeAspect { PRivate QyWechatAuthService qyWechatAuthService; @Autowired private void setManage(QyWechatAuthService qyWechatAuthService){ this.qyWechatAuthService = qyWechatAuthService; } @Pointcut("@annotation(com.edu.Archive.COMmon.annotation.CheckCorpType)") public void pointcut(){ } @Around(value = "pointcut()") public Object checkCorpType(ProceedingJoinPoint joinPoint) throws Throwable { LOG.info("#### 进入校验授权企业类型方法 ####"); // 获取注解参数事件类型 MethodSignature signature = (MethodSignature) joinPoint.getSignature(); CheckCorpType annotation = signature.getMethod().getAnnotation(CheckCorpType.class); // 获取参数 Object[] args = joinPoint.getArgs(); HomeSchoolEvent eventParams = (HomeSchoolEvent)args[0]; log.info("授权企业事件回调参数!事件类型 eventType={}, eventParams={} ", annotation.eventType().name(),JSON.toJSONString(eventParams)); // 授权企业ID String authCorpId = eventParams.getAuthCorpId(); log.info("事件回调授权企业ID={}", authCorpId); if (StringUtils.isBlank(authCorpId)) { log.error("回调事件请求参数!corpId is null lock fail"); throw new BusinessException("回调事件请求参数!corpId is null lock fail"); } if (this.checkCorpType(authCorpId)){ return joinPoint.proceed(); } return null; } /** * 校验企业类型 */ private boolean checkCorpType(String authCorpId){ // 校验企业类型 QyWechatAuth qyWechatAuth = qyWechatAuthService.selectByCorpid(authCorpId); if (ObjectUtil.iSEMpty(qyWechatAuth)){ log.info("未查询到该企业的授权信息!corpId={}", authCorpId); return false; } if (QyWeChatTypeEnum.NON_EDUCATIONAL.getCode().equals(qyWechatAuth.getType())){ log.info("非教育类企业事件回调不做处理! corpId={}", authCorpId); return false; } return true; } }备注:环绕通知=前置+目标方法执行+后置通知,proceed方法就是用于启动目标方法执行的
以上是脚本宝典为你收集整理的自定义注解拦截全部内容,希望文章能够帮你解决自定义注解拦截所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。