完成 TenantApi 的 feign 支持

This commit is contained in:
YunaiV
2022-06-16 22:14:08 +08:00
parent 71930d492e
commit 5598f62456
31 changed files with 128 additions and 1235 deletions

View File

@@ -33,6 +33,7 @@ public interface DeptApi {
CommonResult<List<DeptRespDTO>> getDepts(@RequestParam("ids") Collection<Long> ids);
@GetMapping(PREFIX + "/valid")
@ApiOperation("校验部门是否合法")
@ApiImplicitParam(name = "ids", value = "部门编号数组", example = "1,2", required = true, allowMultiple = true)
CommonResult<Boolean> validDepts(@RequestParam("ids") Collection<Long> ids);

View File

@@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.enums.ApiConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@@ -17,7 +18,8 @@ public interface PostApi {
String PREFIX = ApiConstants.PREFIX + "/post";
@GetMapping(PREFIX + "/valid")
@ApiImplicitParam(name = "ids", value = "部门编号数组", example = "1,2", required = true, allowMultiple = true)
@ApiOperation("校验岗位是否合法")
@ApiImplicitParam(name = "ids", value = "岗位编号数组", example = "1,2", required = true, allowMultiple = true)
CommonResult<Boolean> validPosts(@RequestParam("ids") Collection<Long> ids);
}

View File

@@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.enums.ApiConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@@ -17,6 +18,7 @@ public interface RoleApi {
String PREFIX = ApiConstants.PREFIX + "/role";
@GetMapping(PREFIX + "/valid")
@ApiOperation("校验角色是否合法")
@ApiImplicitParam(name = "ids", value = "角色编号数组", example = "1,2", required = true, allowMultiple = true)
CommonResult<Boolean> validRoles(@RequestParam("ids") Collection<Long> ids);

View File

@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
@Api(tags = "RPC 服务 - 社交用户")
@Api(tags = "RPC 服务 - 社交用户")
public interface SocialUserApi {
String PREFIX = ApiConstants.PREFIX + "/social-user";

View File

@@ -0,0 +1,29 @@
package cn.iocoder.yudao.module.system.api.tenant;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.enums.ApiConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
@Api(tags = "RPC 服务 - 多租户")
public interface TenantApi {
String PREFIX = ApiConstants.PREFIX + "/tenant";
@GetMapping(PREFIX + "/id-list")
@ApiOperation("获得所有租户编号")
CommonResult<List<Long>> getTenantIds();
@GetMapping(PREFIX + "/valid")
@ApiOperation("校验租户是否合法")
@ApiImplicitParam(name = "id", value = "租户编号", required = true, example = "1024", dataTypeClass = Long.class)
CommonResult<Boolean> validTenant(@RequestParam("id") Long id);
}

View File

@@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.system.api.tenant;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.service.tenant.TenantService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.module.system.enums.ApiConstants.VERSION;
@RestController // 提供 RESTful API 接口,给 Feign 调用
@DubboService(version = VERSION) // 提供 Dubbo RPC 接口,给 Dubbo Consumer 调用
@Validated
public class TenantApiImpl implements TenantApi {
@Resource
private TenantService tenantService;
@Override
public CommonResult<List<Long>> getTenantIds() {
return success(tenantService.getTenantIds());
}
@Override
public CommonResult<Boolean> validTenant(Long id) {
tenantService.validTenant(id);
return success(true);
}
}

View File

@@ -20,7 +20,7 @@ import java.util.Set;
*
* @author 芋道源码
*/
public interface TenantService extends TenantFrameworkService {
public interface TenantService {
/**
* 初始化租户的本地缓存
@@ -120,4 +120,18 @@ public interface TenantService extends TenantFrameworkService {
* @param handler 处理器
*/
void handleTenantMenu(TenantMenuHandler handler);
/**
* 获得所有租户
*
* @return 租户编号数组
*/
List<Long> getTenantIds();
/**
* 校验租户是否合法
*
* @param id 租户编号
*/
void validTenant(Long id);
}

View File

@@ -77,6 +77,7 @@ yudao:
- /admin-api/system/tenant/get-id-by-name # 基于名字获取租户,不许带租户编号
- /admin-api/system/captcha/get-image # 获取图片验证码,和租户无关
- /admin-api/system/sms/callback/* # 短信回调接口,无法带上租户编号
- /rpc-api/system/tenant/valid # 防止递归。避免调用 /rpc-api/system/tenant/valid 接口时,又去触发 /rpc-api/system/tenant/valid 去校验
ignore-tables:
- system_tenant
- system_tenant_package