CrudCommandAop.java 2.5 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
package com.lyms.talkonlineweb.aop;

import com.alibaba.fastjson.JSON;
import com.lyms.talkonlineweb.annotation.LogAnnotation;
import com.lyms.talkonlineweb.domain.LymsLogsCrud;
import com.lyms.talkonlineweb.service.LymsLogsCrudService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
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 javax.servlet.http.HttpServletRequest;
import javax.xml.ws.spi.http.HttpContext;
import java.lang.reflect.Method;
import java.util.Date;

@Aspect
@Component
public class CrudCommandAop {

@Autowired
private LymsLogsCrudService lymsLogsCrudService;

//定义切点 @Pointcut
//在注解的位置切入代码
@Pointcut("@annotation( com.lyms.talkonlineweb.annotation.LogAnnotation)")
public void logPoinCut() {
}

//切面 配置通知,返回结果之后通知
@AfterReturning("logPoinCut()")
public void saveSysLog(JoinPoint joinPoint) {
System.out.println("切面。。。。。");
//日志实体
LymsLogsCrud lymsLogsCrud = new LymsLogsCrud();

//从切面织入点处通过反射机制获取织入点处的方法
// MethodSignature signature = (MethodSignature) joinPoint.getSignature();
//获取切入点所在的方法
// Method method = signature.getMethod();

//获取操作
// LogAnnotation logAnnotation =method.getAnnotation(LogAnnotation.class);
// if (logAnnotation != null) {
// String value = logAnnotation.value();
// lymsLogsCrud.setCrud(value);//保存获取的操作
// }

//获取请求的类名
// String className = joinPoint.getTarget().getClass().getName();
//获取请求的方法名
// String methodName = method.getName();
// lymsLogsCrud.setMethod(className + "." + methodName);

//请求的参数
// Object[] args = joinPoint.getArgs();
//将参数所在的数组转换成json
// String params = JSON.toJSONString(args);
// lymsLogsCrud.setParams(params);

// lymsLogsCrud.setCreatdata(new Date());
//获取用户名
// lymsLogsCrud.setUsername(ShiroUtils.getUserEntity().getUsername());


//调用service保存 LymsLogsCrud实体类到数据库
// lymsLogsCrudService.save(lymsLogsCrud);
}
}