add 新增 忽略数据权限写法 防止异常不执行关闭问题

This commit is contained in:
疯狂的狮子li 2023-04-21 09:42:55 +08:00
parent 1bfcbfa456
commit 093e7212cf

View File

@ -10,6 +10,7 @@ import lombok.NoArgsConstructor;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
/**
* 数据权限助手
@ -61,4 +62,32 @@ public class DataPermissionHelper {
InterceptorIgnoreHelper.clearIgnoreStrategy();
}
/**
* 在忽略数据权限中执行
*
* @param handle 处理执行方法
*/
public static void ignore(Runnable handle) {
enableIgnore();
try {
handle.run();
} finally {
disableIgnore();
}
}
/**
* 在忽略数据权限中执行
*
* @param handle 处理执行方法
*/
public static <T> T ignore(Supplier<T> handle) {
enableIgnore();
try {
return handle.get();
} finally {
disableIgnore();
}
}
}