zxl
2026-03-25 963a8c24874c2e10a329a6ea39774bc5eda0f762
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
package com.tievd.jyz.plugin;
 
import com.tievd.jyz.util.MultiMinioUtil;
import org.apache.ibatis.executor.resultset.ResultSetHandler;
import org.apache.ibatis.plugin.*;
import org.springframework.beans.factory.annotation.Autowired;
 
import java.lang.reflect.Field;
import java.sql.Statement;
import java.util.List;
 
/**
 * Author: wqy
 */
@Intercepts({@Signature(
        type= ResultSetHandler.class,
        method = "handleResultSets",
        args = {Statement.class})})
public class EventInterceptPlugin implements Interceptor {
 
    @Autowired
    MultiMinioUtil s3Util;
 
    /**
     * 全局s3路径转换
     * @param invocation
     * @return
     * @throws Throwable
     */
    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        Object returnValue = invocation.proceed();
        if (returnValue != null && returnValue instanceof List) {
            try {
                List dataList = (List) returnValue;
                if (dataList.size() == 0) {
                    return returnValue;
                }
                Class clazz = dataList.get(0).getClass();
                if (clazz.getAnnotation(S3DataParse.class) == null) {
                    return returnValue;
                }
                Field[] fields = clazz.getDeclaredFields();
                for (Field field : fields) {
                    if (field.getAnnotation(S3DataParse.class) == null) {
                        continue;
                    }
                    field.setAccessible(true);
                    String split = field.getAnnotation(S3DataParse.class).value();
                    for (Object o : dataList) {
                        Object val = field.get(o);
                        String path[] = String.valueOf(val).split(split);
                        if (path.length == 2) {
                            String url = s3Util.getObjectURL(path[0], path[1], 6000);
                            field.set(o, url);
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return returnValue;
    }
 
    @Override
    public Object plugin(Object target) {
        if (target instanceof ResultSetHandler) {
            return Plugin.wrap(target, this);
        }
        return target;
    }
}