|
@@ -0,0 +1,53 @@
|
|
|
+package com.shawn.monitor;
|
|
|
+
|
|
|
+import com.shawn.web.exception.MyException;
|
|
|
+import lombok.extern.apachecommons.CommonsLog;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.commons.lang3.time.StopWatch;
|
|
|
+import org.aspectj.lang.JoinPoint;
|
|
|
+import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
+import org.aspectj.lang.Signature;
|
|
|
+import org.aspectj.lang.annotation.Around;
|
|
|
+import org.aspectj.lang.annotation.Aspect;
|
|
|
+import org.aspectj.lang.annotation.Before;
|
|
|
+import org.aspectj.lang.annotation.Pointcut;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.context.request.RequestAttributes;
|
|
|
+import org.springframework.web.context.request.RequestContextHolder;
|
|
|
+import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author 吴洪双
|
|
|
+ */
|
|
|
+@CommonsLog
|
|
|
+@Aspect
|
|
|
+@Component
|
|
|
+public class PerformanceMonitor {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 所有请求,
|
|
|
+ * 排除了登录
|
|
|
+ * 排除微信TWeixinController 的所有方法
|
|
|
+ */
|
|
|
+ @Pointcut("execution(public * com.shawn.web.controller..*(..)) && !execution(public * com.shawn.web.controller.TAdminController.userLogin(..)) && !execution(public * com.shawn.web.controller.TWeixinController.*(..))")
|
|
|
+ private void allCell() {
|
|
|
+ }
|
|
|
+ @Before("allCell()")
|
|
|
+ public void setDataSourceKey(JoinPoint point) {
|
|
|
+ RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
|
|
+ ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) requestAttributes;
|
|
|
+ HttpServletRequest request = servletRequestAttributes.getRequest();
|
|
|
+ String token = null!=request.getHeader("token")?request.getHeader("token"):"";
|
|
|
+ boolean isLogin = true;
|
|
|
+ if(StringUtils.isEmpty(token)){
|
|
|
+ // TODO 做token的逻辑判断
|
|
|
+ isLogin = false;
|
|
|
+ }
|
|
|
+ if(!isLogin){
|
|
|
+ throw new MyException("请登录");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|