月球大数据地理空间分析展示平台-【后端】-月球后台服务
1
13693261870
2024-11-11 fee67ca8a0760315047a52fc4101a8f4f80b7a7f
src/main/java/com/moon/server/aspect/LogAspect.java
@@ -1,8 +1,10 @@
package com.moon.server.aspect;
import com.moon.server.annotation.SysLog;
import com.moon.server.entity.all.StaticData;
import com.moon.server.entity.sys.OperateEntity;
import com.moon.server.entity.sys.UserEntity;
import com.moon.server.helper.AsyncHelper;
import com.moon.server.helper.WebHelper;
import com.moon.server.service.sys.OperateService;
import com.moon.server.service.sys.TokenService;
@@ -19,13 +21,11 @@
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.util.TimerTask;
/**
 * 日志切面类
 * @author WWW
 */
@Aspect
@Component
@SuppressWarnings("ALL")
public class LogAspect {
    @Autowired
    private TokenService tokenService;
@@ -47,8 +47,6 @@
    private final static String COUNT = "count";
    private final static String SPLIT = "\\\\";
    private static final Log log = LogFactory.getLog(LogAspect.class);
    @Pointcut("@annotation(com.moon.server.annotation.SysLog)")
@@ -57,27 +55,21 @@
    }
    /**
     * 环绕通知 @Around,也可以使用 @Before (前置通知) 或 @After (后置通知)
     * @Around,@Before,@After
     */
    @Around("logPointCut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        long beginTime = System.currentTimeMillis();
        // 执行方法
        Object result = point.proceed();
        // 执行时长(毫秒)
        long time = System.currentTimeMillis() - beginTime;
        // 保存日志
        saveLog(point, time);
        return result;
    }
    /**
     * 保存日志
     */
    private void saveLog(ProceedingJoinPoint joinPoint, long time) {
        try {
            MethodSignature signature = (MethodSignature) joinPoint.getSignature();
@@ -92,19 +84,16 @@
            oe.setUrl(url);
            oe.setExec(time);
            // 设置模块
            Api api = clazz.getAnnotation(Api.class);
            if (api != null) {
                String[] strs = api.tags()[0].split(SPLIT);
                String[] strs = api.tags()[0].split(StaticData.BACKSLASH);
                oe.setModular1(strs[0]);
                oe.setModular2(strs[1]);
            }
            // 设置类名\方法名、类别
            oe.setClazz(clazz.getName() + "." + method.getName());
            oe.setType(getType(method.getName()));
            // 设置备注
            SysLog sysLog = method.getAnnotation(SysLog.class);
            if (sysLog != null) {
                oe.setBak(sysLog.value());
@@ -115,15 +104,19 @@
                oe.setUserid(ue.getId());
            }
            operateService.insertOperate(oe);
            // operateService.insertOperate(oe)
            AsyncHelper helper = new AsyncHelper();
            helper.execute(new TimerTask() {
                @Override
                public void run() {
                    operateService.insertOperate(oe);
                }
            });
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
        }
    }
    /**
     * 获取操作类型
     */
    private static int getType(String methodName) {
        if (methodName.contains(SELECT)) {
            return 1;