@Aspect
@Configuration
public class LogAop {
private Logger log = LoggerFactory.getLogger(getClass());
@Autowired
TokenHelper tokenHelper;
@Autowired
UserMapper userMapper;
@Autowired
MongoTemplate mongoTemplate;
@Autowired
AllRoleService allRoleService;
@Pointcut("execution(* com.trvideo.controller.*.*.*(..))")
public void excudeService() {
System.out.println("时间:"+ this.getDate());
}
@Around("execution(* com.trvideo.controller.*.*.*(..))")
public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
RequestAttributes ra = RequestContextHolder.getRequestAttributes();
ServletRequestAttributes sra = (ServletRequestAttributes) ra;
HttpServletRequest request = sra.getRequest();
String url = request.getRequestURL().toString();
String method = request.getMethod();
String uri = request.getRequestURI();
String queryString = request.getQueryString();
System.out.println("请求开始, 各个参数, url: "+url+", method: "+method+", uri: "+uri+", params: "+queryString);
Object result = pjp.proceed();
Gson gson = new Gson();
String msg = JSONObject.parseObject(gson.toJson(result)).getString("msg");
return result;
}
public static String getDate() {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = df.format(new Date());
return time;
}
}