123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- package com.fdkankan.fusion.aop;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.http.ContentType;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.fdkankan.fusion.common.ResultCode;
- import com.fdkankan.fusion.common.ResultData;
- import com.fdkankan.fusion.config.FusionConfig;
- import com.fdkankan.fusion.down.CaseDownService;
- import com.fdkankan.fusion.exception.BusinessException;
- import com.fdkankan.fusion.httpClient.client.OtherClient;
- import com.fdkankan.fusion.mq.vo.JmGaEventVo;
- import com.fdkankan.rabbitmq.util.RabbitMqProducer;
- import lombok.extern.slf4j.Slf4j;
- import org.aspectj.lang.JoinPoint;
- import org.aspectj.lang.ProceedingJoinPoint;
- import org.aspectj.lang.annotation.After;
- 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.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Component;
- import org.springframework.util.StringUtils;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.context.request.RequestContextHolder;
- import org.springframework.web.context.request.ServletRequestAttributes;
- import org.springframework.web.multipart.MultipartFile;
- import javax.servlet.http.HttpServletRequest;
- import java.lang.annotation.Annotation;
- import java.lang.reflect.Method;
- import java.util.HashMap;
- import java.util.Map;
- @Slf4j
- @Aspect
- @Component
- public class PushJmAspect {
- @Autowired
- RabbitMqProducer rabbitMqProducer;
- @Autowired
- FusionConfig fusionConfig;
- @Autowired
- OtherClient otherClient;
- @Autowired
- CaseDownService caseDownService;
- @Pointcut("@annotation(com.fdkankan.fusion.aop.PushJm)")
- public void servicePush() {
- }
- @Around("servicePush()")
- public Object servicePush(ProceedingJoinPoint joinPoint) {
- Object result = null;
- try {
- HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
- //获取参数
- JSONObject params = this.getParams(joinPoint, request);
- log.info("请求参数:{}",params);
- //放行
- result = joinPoint.proceed();
- ResultData resultData = (ResultData) result;
- if(resultData.getCode() != 0){
- return result;
- }
- MethodSignature signature = (MethodSignature)joinPoint.getSignature();
- Method method = signature.getMethod();
- PushJm methodAnnotation = method.getAnnotation(PushJm.class);
- String method1 = methodAnnotation.method();
- String event_type = methodAnnotation.event_type();
- String event_content = methodAnnotation.event_content();
- JmGaEventVo vo = new JmGaEventVo();
- vo.setMethod(method1);
- vo.setEvent_type(event_type);
- if(org.apache.commons.lang3.StringUtils.isBlank(event_content)){
- event_content = event_type;
- }
- vo.setEvent_content(event_content);
- String ryid = "";
- String platform_id = "";
- String ajbh = params != null ? params.getString("caseId") : null;
- vo.setRyid(ryid);
- vo.setPlatform_id(platform_id);
- vo.setAjbh(ajbh);
- rabbitMqProducer.sendByWorkQueue("jmga-event-notice",BeanUtil.beanToMap(vo));
- if(params != null && params.getInteger("caseId")!=null){
- caseDownService.cleckDownUrl(params.getInteger("caseId"));
- }
- return result;
- }catch (BusinessException e){
- log.info("servicePush-BusinessException-error:{}",e);
- return ResultData.error(e.getCode(),e.getMessage());
- }catch (Exception e){
- log.info("servicePush-Exception-error:{}",e);
- }catch (Throwable throwable){
- log.info("servicePush-throwable-error:{}",throwable);
- }
- return ResultData.error(ResultCode.SYSTEM_ERROR);
- }
- private JSONObject getParams(JoinPoint pjp, HttpServletRequest request){
- try {
- MethodSignature signature = (MethodSignature) pjp.getSignature();
- Method method = signature.getMethod();
- Annotation[][] parameterAnnotations = method.getParameterAnnotations();
- Object[] args = pjp.getArgs();
- for (int i = 0; i < parameterAnnotations.length; i++) {
- for (Annotation annotation : parameterAnnotations[i]) {
- if (annotation instanceof RequestBody) {
- log.info("请求体内容: " + args[i]);
- Object arg = args[i];
- String jsonString = JSONObject.toJSONString(arg);
- return JSON.parseObject(jsonString);
- }
- }
- }
- }catch (Exception e){
- e.printStackTrace();
- }
- return null;
- }
- }
|