| | |
| | | package com.terra.common.aspect; |
| | | |
| | | import com.terra.common.annotation.SysLog; |
| | | import com.terra.common.helper.TokenHelper; |
| | | import com.terra.common.helper.WebHelper; |
| | | import com.terra.common.mapper.CommonMapper; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | |
| | | import org.aspectj.lang.reflect.MethodSignature; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.lang.reflect.Method; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 日志切面类 |
| | |
| | | @Aspect |
| | | @Component |
| | | public class LogAspect { |
| | | @Resource |
| | | CommonMapper commonMapper; |
| | | |
| | | private final static String SELECT = "select"; |
| | | |
| | | private final static String INSERT = "insert"; |
| | |
| | | |
| | | private static final Log log = LogFactory.getLog(LogAspect.class); |
| | | |
| | | @Pointcut("@annotation(com.terra.system.annotation.SysLog)") |
| | | @Pointcut("@annotation(com.terra.common.annotation.SysLog)") |
| | | public void logPointCut() { |
| | | // |
| | | } |
| | |
| | | MethodSignature signature = (MethodSignature) joinPoint.getSignature(); |
| | | Class<?> clazz = joinPoint.getTarget().getClass(); |
| | | Method method = signature.getMethod(); |
| | | |
| | | HttpServletRequest req = WebHelper.getRequest(); |
| | | String url = req.getServletPath(); |
| | | |
| | | /*OperateEntity oe = new OperateEntity(); |
| | | oe.setIp(WebHelper.getIpAddress(req)); |
| | | oe.setUrl(url); |
| | | oe.setExec(time); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("url", req.getServletPath()); |
| | | map.put("ip", WebHelper.getIpAddress(req)); |
| | | map.put("exec", time); |
| | | map.put("userid", TokenHelper.getCurrentUserId()); |
| | | |
| | | // 设置模块 |
| | | Tag tag = clazz.getAnnotation(Tag.class); |
| | | if (tag != null) { |
| | | String[] strs = tag.name().split(SPLIT); |
| | | oe.setModular1(strs[0]); |
| | | oe.setModular2(strs[1]); |
| | | map.put("modular1", strs[0]); |
| | | map.put("modular2", strs[1]); |
| | | } |
| | | |
| | | // 设置类名\方法名、类别 |
| | | oe.setClazz(clazz.getName() + "." + method.getName()); |
| | | oe.setType(getType(method.getName())); |
| | | map.put("clazz", clazz.getName() + "." + method.getName()); |
| | | map.put("type", getType(method.getName())); |
| | | |
| | | // 设置备注 |
| | | SysLog sysLog = method.getAnnotation(SysLog.class); |
| | | if (sysLog != null) { |
| | | oe.setBak(sysLog.value()); |
| | | map.put("bak", sysLog.value()); |
| | | } |
| | | |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | oe.setUserid(ue.getId()); |
| | | } |
| | | |
| | | operateService.insertOperate(oe);*/ |
| | | commonMapper.insertOperate(map); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |