|
|
@ -1,14 +1,17 @@ |
|
|
|
package com.ccsens.cache_test.aspect; |
|
|
|
package com.ccsens.cloudutil.aspect; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.ccsens.cache_test.bean.dto.CacheTest; |
|
|
|
import com.ccsens.cache_test.bean.vo.CacheTestVo; |
|
|
|
import com.ccsens.cache_test.util.JsonResponse; |
|
|
|
import com.ccsens.cache_test.util.Md5Util; |
|
|
|
import com.ccsens.util.JsonResponse; |
|
|
|
import com.ccsens.util.Md5Util; |
|
|
|
import com.ccsens.util.WebConstant; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.aspectj.lang.ProceedingJoinPoint; |
|
|
|
import org.aspectj.lang.annotation.*; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.web.context.request.RequestContextHolder; |
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
@ -20,21 +23,6 @@ public class CacheMd5Aspect { |
|
|
|
public void cacheMd5(){ |
|
|
|
|
|
|
|
} |
|
|
|
//
|
|
|
|
// @After("cacheMd5()")
|
|
|
|
// public void cacheMd5TestAspect(JoinPoint joinPoint) throws JsonProcessingException {
|
|
|
|
// Object[] args = joinPoint.getArgs();
|
|
|
|
//// Object proceed = joinPoint.(args);
|
|
|
|
// Signature signature = joinPoint.getSignature();
|
|
|
|
// String kind = joinPoint.getKind();
|
|
|
|
// SourceLocation sourceLocation = joinPoint.getSourceLocation();
|
|
|
|
// JoinPoint.StaticPart staticPart = joinPoint.getStaticPart();
|
|
|
|
// Object target = joinPoint.getTarget();
|
|
|
|
// Object aThis = joinPoint.getThis();
|
|
|
|
// System.out.println(joinPoint);
|
|
|
|
//
|
|
|
|
// System.out.println("============================================---");
|
|
|
|
// }
|
|
|
|
|
|
|
|
@Around("cacheMd5()") |
|
|
|
public Object cacheMd5TestAspect1(ProceedingJoinPoint joinPoint) throws Throwable { |
|
|
@ -42,11 +30,12 @@ public class CacheMd5Aspect { |
|
|
|
//拿到入参
|
|
|
|
Object[] args = joinPoint.getArgs(); |
|
|
|
|
|
|
|
CacheTest cacheTest = args == null || args.length < 1 ? null : (CacheTest)args[0]; |
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) |
|
|
|
RequestContextHolder.getRequestAttributes()).getRequest(); |
|
|
|
//获取入参的md5值
|
|
|
|
String inMd5 = cacheTest == null ? null : cacheTest.getMd5(); |
|
|
|
final String inMd5 = request.getHeader(WebConstant.HEADER_KEY_TOKEN); |
|
|
|
//获取返回值
|
|
|
|
JsonResponse<Object> proceed = (JsonResponse<Object>) joinPoint.proceed(args); |
|
|
|
JsonResponse<? extends Object> proceed = (JsonResponse<? extends Object>) joinPoint.proceed(args); |
|
|
|
//入参没有md5直接返回
|
|
|
|
if(inMd5 == null){ |
|
|
|
log.info("cache---入参md5为空"); |
|
|
@ -73,7 +62,10 @@ public class CacheMd5Aspect { |
|
|
|
log.info("md5:{}",outMd5); |
|
|
|
if(inMd5.equalsIgnoreCase(outMd5)){ |
|
|
|
log.info("md5相同则返回空"); |
|
|
|
proceed.setMd5Status(JsonResponse.MD5Status.CHECK_SAME_YES); |
|
|
|
proceed.setData(null); |
|
|
|
} else { |
|
|
|
proceed.setMd5Status(JsonResponse.MD5Status.CHECK_SAME_NO); |
|
|
|
} |
|
|
|
long e = System.currentTimeMillis(); |
|
|
|
log.info("切面时间:{}",e-s); |
|
|
|