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;
|
}
|
}
|
}
|
|
}
|