xieb
2023-08-01 3fde6b45ddfcccb76bcb86c8b0e415342c443ce1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package cn.gistack.sm.updaterecord;
 
import io.geekidea.updaterecord.api.entity.UpdateRecordColumnLog;
import io.geekidea.updaterecord.api.entity.UpdateRecordLog;
import io.geekidea.updaterecord.api.entity.UpdateRecordTableLog;
import io.geekidea.updaterecord.core.aop.UpdateRecordAopSupport;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
 
import javax.servlet.http.HttpServletRequest;
import java.util.List;
 
/**
 * @PROJECT_NAME: skjcmanager
 * @DESCRIPTION:
 * @USER: aix
 * @DATE: 2023/7/13 14:16
 */
@Slf4j
@Aspect
@Component
public class UpdateRecordAop extends UpdateRecordAopSupport {
 
    /**
     * 切点
     */
    private static final String POINTCUT = "@annotation(io.geekidea.updaterecord.annotation.UpdateRecord)";
 
    /**
     * 方法执行之前
     *
     * @param joinPoint
     * @throws Throwable
     */
    @Before(POINTCUT)
    @Override
    protected void doBefore(JoinPoint joinPoint) throws Throwable {
        super.doBeforeHandle(joinPoint);
    }
 
    /**
     * 方法正常执行并成功返回
     *
     * @param joinPoint
     * @param result
     * @throws Throwable
     */
    @AfterReturning(value = POINTCUT, returning = RESULT)
    @Override
    protected void doAfterReturning(JoinPoint joinPoint, Object result) throws Throwable {
        super.doAfterReturningHandle(joinPoint, result);
    }
 
    /**
     * 异常处理
     *
     * @param exception
     * @throws Throwable
     */
    @AfterThrowing(value = POINTCUT, throwing = EXCEPTION)
    @Override
    protected void doAfterThrowing(Throwable exception) throws Throwable {
        super.doAfterThrowingHandle(exception);
    }
 
    @Override
    protected String getToken(HttpServletRequest request) {
        return super.getToken(request);
    }
 
    @Override
    protected void handleUpdateRecord(UpdateRecordLog updateRecordLog, List<UpdateRecordTableLog> updateRecordTableLogs, List<UpdateRecordColumnLog> updateRecordColumnLogs) {
        // 需自己完善当前登陆用户ID和用户名称,IP对应的区域,备注信息等
        updateRecordLog.setUserId(String.valueOf(AuthUtil.getUserId()));
        updateRecordLog.setUserName(AuthUtil.getUserName());
        updateRecordLog.setArea("");
        updateRecordLog.setRemark("update...");
    }
 
    @Async
    @Override
    protected void save(UpdateRecordLog updateRecordLog, List<UpdateRecordTableLog> updateRecordTableLogs, List<UpdateRecordColumnLog> updateRecordColumnLogs) {
        super.save(updateRecordLog, updateRecordTableLogs, updateRecordColumnLogs);
    }
 
 
}