zxl
2026-03-25 8819762ad58f77e606431fca4072c19e542e6055
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
package com.tievd.jyz.aspect;
 
import com.tievd.cube.commons.utils.SystemContextUtil;
import com.tievd.cube.modules.system.model.LoginUser;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
 
import java.lang.reflect.Field;
import java.util.Map;
 
 
@Aspect
@Component
public class PermissionFilter {
    
    /**
     * 列表查询增加用户自身的orgCode参数,以过滤数据
     * @param joinPoint
     */
    @Before("execution(* com.tievd.jyz.controller.*.*List(..)) || " +
            "execution(* com.tievd.jyz.controller.*.exportXls(..)) || execution(* com.tievd.jyz.controller.DataTableController.*(..))")
    public void beforeReq(JoinPoint joinPoint) {
        Object[] args = joinPoint.getArgs();
        if (args.length == 0) {
            return;
        }
        LoginUser user = SystemContextUtil.currentLoginUser();
        if (user == null) {
            return;
        }
        for (Object param : args) {
            try {
                Class clazz = param.getClass();
                if (param instanceof Map) {
                    ((Map) param).putIfAbsent("orgCode", user.getOrgCode());
                } else if(clazz.getPackage().getName().contains("com.tievd.jyz.entity")) {
                    Field field = clazz.getDeclaredField("orgCode");
                    field.setAccessible(true);
                    Object val = field.get(param);
                    if (val == null || val.toString().trim().equals("")) {
                        field.set(param, user.getOrgCode());
                        return;
                    }
                }
            } catch (Exception e) {
                continue;
            }
        }
    }
    
}