| | |
| | | package com.zy.asrs.openapi.config; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.zy.asrs.common.openapi.service.ApiLogService; |
| | | import com.zy.asrs.common.utils.IpTools; |
| | | import com.zy.asrs.framework.common.R; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.aspectj.lang.ProceedingJoinPoint; |
| | | import org.aspectj.lang.annotation.Around; |
| | | import org.aspectj.lang.annotation.Aspect; |
| | | import org.aspectj.lang.annotation.Pointcut; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | |
| | | @Aspect |
| | | @Slf4j |
| | | public class AspectConfig { |
| | | |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | |
| | | @Pointcut("execution(* com.zy.asrs.openapi.controller..*.*(..))") |
| | | private void webLog() { |
| | |
| | | long start = System.currentTimeMillis(); |
| | | Object result = joinPoint.proceed(joinPoint.getArgs()); |
| | | log.info("请求响应参数{}", JSONObject.toJSONString(result)); |
| | | |
| | | // 保存接口日志 |
| | | Object appAuth = request.getAttribute("appAuth"); |
| | | String appkey = request.getHeader("appkey"); |
| | | apiLogService.saveLog( |
| | | String.valueOf(appAuth), |
| | | request.getRequestURI(), |
| | | appkey, |
| | | IpTools.gainRealIp(request), |
| | | JSONObject.toJSONString(filterArgs(joinPoint.getArgs())), |
| | | JSON.toJSONString(result), |
| | | String.valueOf(((R) result).get("code")).equalsIgnoreCase("200") |
| | | ); |
| | | |
| | | long end = System.currentTimeMillis(); |
| | | log.info("执行耗时:{}", end - start); |
| | | return result; |