This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package jnpf.util.auth;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jnpf.util.auth.fallback.V2AuthPermissionApiFallback;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 登录人数据权限-组织范围 API(与 FTB 内 {@code V2AuthPermissionUtils#getLoginUserAuthOrganizeIds()} 语义一致)。
|
||||
* <p>
|
||||
* 返回值约定:{@code null} 表示全部;空列表表示无权限;非空为组织/门店 id 列表(已排除班组)。
|
||||
* Feign 降级时抛出异常,不会返回空列表以免误判为无权限(当前暂无正式熔断占位策略)。
|
||||
*/
|
||||
@FeignClient(name = "jnpf-ftb", contextId = "v2AuthPermissionApi", path = "/permission/auth", fallbackFactory = V2AuthPermissionApiFallback.class)
|
||||
public interface V2AuthPermissionApi {
|
||||
|
||||
@Operation(summary = "[API] 当前登录人在权限范围内的组织/门店 id 列表(未包裹 ActionResult)")
|
||||
@GetMapping("/login-user-organize-ids")
|
||||
List<String> getLoginUserAuthOrganizeIds();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package jnpf.util.auth.fallback;
|
||||
|
||||
import jnpf.util.auth.V2AuthPermissionApi;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 无有效熔断占位数据:调用失败时直接失败,避免将空列表误判为「无人事数据权限」。
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class V2AuthPermissionApiFallback implements FallbackFactory<V2AuthPermissionApi> {
|
||||
|
||||
@Override
|
||||
public V2AuthPermissionApi create(Throwable cause) {
|
||||
if (cause != null) {
|
||||
log.error("V2AuthPermissionApi 调用失败(将向上抛出,不返回空权限): {}", cause.getMessage(), cause);
|
||||
}
|
||||
return () -> {
|
||||
String msg = "人事数据权限服务暂不可用(V2AuthPermissionApi/getLoginUserAuthOrganizeIds),请稍后重试";
|
||||
if (cause != null) {
|
||||
throw new IllegalStateException(msg, cause);
|
||||
}
|
||||
throw new IllegalStateException(msg);
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user