|  |  |  | 
|---|
|  |  |  | package com.zy.common.config; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
|---|
|  |  |  | import com.core.annotations.ManagerAuth; | 
|---|
|  |  |  | import com.core.common.BaseRes; | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.zy.common.utils.Http; | 
|---|
|  |  |  | import com.zy.system.entity.OperateLog; | 
|---|
|  |  |  | import com.zy.system.entity.User; | 
|---|
|  |  |  | import com.zy.system.entity.UserLogin; | 
|---|
|  |  |  | import com.zy.system.service.OperateLogService; | 
|---|
|  |  |  | import com.zy.system.service.UserLoginService; | 
|---|
|  |  |  | import com.zy.system.service.UserService; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | 
|---|
|  |  |  | import java.lang.reflect.Method; | 
|---|
|  |  |  | import java.util.Arrays; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Optional; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Component | 
|---|
|  |  |  | 
|---|
|  |  |  | private UserLoginService userLoginService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserService userService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private OperateLogService operateLogService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Pointcut("execution(* com.zy.asrs.controller..*.*(..))") | 
|---|
|  |  |  | @Pointcut("execution(* com.zy.asrs.controller.*(..))") | 
|---|
|  |  |  | private void webLog() { | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | "||@within(org.springframework.stereotype.Controller)") | 
|---|
|  |  |  | public Object after(ProceedingJoinPoint joinPoint) throws Throwable{ | 
|---|
|  |  |  | ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); | 
|---|
|  |  |  | //if(requestAttributes != null){ | 
|---|
|  |  |  | //    return joinPoint.proceed(); | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | HttpServletRequest request = requestAttributes.getRequest(); | 
|---|
|  |  |  | long start = System.currentTimeMillis(); | 
|---|
|  |  |  | Object result = joinPoint.proceed(joinPoint.getArgs()); | 
|---|
|  |  |  | 
|---|
|  |  |  | ManagerAuth annotation = method.getAnnotation(ManagerAuth.class); | 
|---|
|  |  |  | if (annotation.value().equals(ManagerAuth.Auth.CHECK)){ | 
|---|
|  |  |  | if (!Cools.isEmpty(annotation.memo())) { | 
|---|
|  |  |  | saveLog(joinPoint, request, result); | 
|---|
|  |  |  | saveLog(joinPoint, request, result,annotation.memo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | && !(obj instanceof HttpServletRequest)).collect(Collectors.toList()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void saveLog(ProceedingJoinPoint joinPoint, HttpServletRequest request, Object result) { | 
|---|
|  |  |  | private void saveLog(ProceedingJoinPoint joinPoint, HttpServletRequest request, Object result,String memo) { | 
|---|
|  |  |  | Long userId = 9527L; | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  | UserLogin userLogin = userLoginService.selectOne(new EntityWrapper<UserLogin>().eq("token", token).eq("system", "WMS")); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 记录操作日志 | 
|---|
|  |  |  | OperateLog operateLog = new OperateLog(); | 
|---|
|  |  |  | operateLog.setAction(request.getRequestURI()); | 
|---|
|  |  |  | operateLog.setAction(Cools.isEmpty(memo)?request.getRequestURI():memo); | 
|---|
|  |  |  | operateLog.setIp(request.getRemoteAddr()); | 
|---|
|  |  |  | operateLog.setUserId(userId); | 
|---|
|  |  |  | operateLog.setRequest(JSONObject.toJSONString(filterArgs(joinPoint.getArgs()))); | 
|---|
|  |  |  | operateLog.setResponse(JSONObject.toJSONString(result)); | 
|---|
|  |  |  | request.setAttribute("operateLog", operateLog); | 
|---|
|  |  |  | operateLogService.insert(operateLog); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|