Commit 9b11199665f00790ecabad6e10f449c4148635f1

Authored by YunaiV
1 parent 71add4b0

【功能新增】system:增加租户的下拉选择,用于登录界面

yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java
... ... @@ -7,14 +7,7 @@ import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
7 7 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
8 8 import cn.iocoder.yudao.framework.security.config.SecurityProperties;
9 9 import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
10   -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthLoginReqVO;
11   -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthLoginRespVO;
12   -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthPermissionInfoRespVO;
13   -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthRegisterReqVO;
14   -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthResetPasswordReqVO;
15   -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthSmsLoginReqVO;
16   -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthSmsSendReqVO;
17   -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthSocialLoginReqVO;
  10 +import cn.iocoder.yudao.module.system.controller.admin.auth.vo.*;
18 11 import cn.iocoder.yudao.module.system.convert.auth.AuthConvert;
19 12 import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO;
20 13 import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
... ... @@ -36,12 +29,7 @@ import jakarta.servlet.http.HttpServletRequest;
36 29 import jakarta.validation.Valid;
37 30 import lombok.extern.slf4j.Slf4j;
38 31 import org.springframework.validation.annotation.Validated;
39   -import org.springframework.web.bind.annotation.GetMapping;
40   -import org.springframework.web.bind.annotation.PostMapping;
41   -import org.springframework.web.bind.annotation.RequestBody;
42   -import org.springframework.web.bind.annotation.RequestMapping;
43   -import org.springframework.web.bind.annotation.RequestParam;
44   -import org.springframework.web.bind.annotation.RestController;
  32 +import org.springframework.web.bind.annotation.*;
45 33  
46 34 import java.util.Collections;
47 35 import java.util.List;
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/MenuController.java
... ... @@ -67,8 +67,8 @@ public class MenuController {
67 67 }
68 68  
69 69 @GetMapping({"/list-all-simple", "simple-list"})
70   - @Operation(summary = "获取菜单精简信息列表", description = "只包含被开启的菜单,用于【角色分配菜单】功能的选项。" +
71   - "在多租户的场景下,会只返回租户所在套餐有的菜单")
  70 + @Operation(summary = "获取菜单精简信息列表",
  71 + description = "只包含被开启的菜单,用于【角色分配菜单】功能的选项。在多租户的场景下,会只返回租户所在套餐有的菜单")
72 72 public CommonResult<List<MenuSimpleRespVO>> getSimpleMenuList() {
73 73 List<MenuDO> list = menuService.getMenuListByTenant(
74 74 new MenuListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus()));
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/TenantController.java
1 1 package cn.iocoder.yudao.module.system.controller.admin.tenant;
2 2  
3 3 import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
  4 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
4 5 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
5 6 import cn.iocoder.yudao.framework.common.pojo.PageParam;
6 7 import cn.iocoder.yudao.framework.common.pojo.PageResult;
... ... @@ -9,7 +10,6 @@ import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
9 10 import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO;
10 11 import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantRespVO;
11 12 import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantSaveReqVO;
12   -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantSimpleRespVO;
13 13 import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO;
14 14 import cn.iocoder.yudao.module.system.service.tenant.TenantService;
15 15 import io.swagger.v3.oas.annotations.Operation;
... ... @@ -27,6 +27,7 @@ import java.util.List;
27 27  
28 28 import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
29 29 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  30 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
30 31  
31 32 @Tag(name = "管理后台 - 租户")
32 33 @RestController
... ... @@ -45,13 +46,25 @@ public class TenantController {
45 46 return success(tenant != null ? tenant.getId() : null);
46 47 }
47 48  
  49 + @GetMapping({ "simple-list" })
  50 + @PermitAll
  51 + @Operation(summary = "获取租户精简信息列表", description = "只包含被开启的租户,用于【首页】功能的选择租户选项")
  52 + public CommonResult<List<TenantRespVO>> getTenantSimpleList() {
  53 + List<TenantDO> list = tenantService.getTenantListByStatus(CommonStatusEnum.ENABLE.getStatus());
  54 + return success(convertList(list, tenantDO ->
  55 + new TenantRespVO().setId(tenantDO.getId()).setName(tenantDO.getName())));
  56 + }
  57 +
48 58 @GetMapping("/get-by-website")
49 59 @PermitAll
50 60 @Operation(summary = "使用域名,获得租户信息", description = "登录界面,根据用户的域名,获得租户信息")
51 61 @Parameter(name = "website", description = "域名", required = true, example = "www.iocoder.cn")
52   - public CommonResult<TenantSimpleRespVO> getTenantByWebsite(@RequestParam("website") String website) {
  62 + public CommonResult<TenantRespVO> getTenantByWebsite(@RequestParam("website") String website) {
53 63 TenantDO tenant = tenantService.getTenantByWebsite(website);
54   - return success(BeanUtils.toBean(tenant, TenantSimpleRespVO.class));
  64 + if (tenant == null || CommonStatusEnum.isDisable(tenant.getStatus())) {
  65 + return success(null);
  66 + }
  67 + return success(new TenantRespVO().setId(tenant.getId()).setName(tenant.getName()));
55 68 }
56 69  
57 70 @PostMapping("/create")
... ... @@ -99,8 +112,7 @@ public class TenantController {
99 112 @Operation(summary = "导出租户 Excel")
100 113 @PreAuthorize("@ss.hasPermission('system:tenant:export')")
101 114 @ApiAccessLog(operateType = EXPORT)
102   - public void exportTenantExcel(@Valid TenantPageReqVO exportReqVO,
103   - HttpServletResponse response) throws IOException {
  115 + public void exportTenantExcel(@Valid TenantPageReqVO exportReqVO, HttpServletResponse response) throws IOException {
104 116 exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
105 117 List<TenantDO> list = tenantService.getTenantPage(exportReqVO).getList();
106 118 // 导出 Excel
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantSimpleRespVO.java deleted
1   -package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant;
2   -
3   -import io.swagger.v3.oas.annotations.media.Schema;
4   -import lombok.Data;
5   -
6   -@Schema(description = "管理后台 - 租户精简 Response VO")
7   -@Data
8   -public class TenantSimpleRespVO {
9   -
10   - @Schema(description = "租户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
11   - private Long id;
12   -
13   - @Schema(description = "租户名", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
14   - private String name;
15   -
16   -}
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenant/TenantMapper.java
... ... @@ -43,4 +43,8 @@ public interface TenantMapper extends BaseMapperX&lt;TenantDO&gt; {
43 43 return selectList(TenantDO::getPackageId, packageId);
44 44 }
45 45  
  46 + default List<TenantDO> selectListByStatus(Integer status) {
  47 + return selectList(TenantDO::getStatus, status);
  48 + }
  49 +
46 50 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantService.java
... ... @@ -38,7 +38,7 @@ public interface TenantService {
38 38 * 更新租户的角色菜单
39 39 *
40 40 * @param tenantId 租户编号
41   - * @param menuIds 菜单编号数组
  41 + * @param menuIds 菜单编号数组
42 42 */
43 43 void updateTenantRoleMenu(Long tenantId, Set<Long> menuIds);
44 44  
... ... @@ -98,6 +98,14 @@ public interface TenantService {
98 98 List<TenantDO> getTenantListByPackageId(Long packageId);
99 99  
100 100 /**
  101 + * 获得指定状态的租户列表
  102 + *
  103 + * @param status 状态
  104 + * @return 租户列表
  105 + */
  106 + List<TenantDO> getTenantListByStatus(Integer status);
  107 +
  108 + /**
101 109 * 进行租户的信息处理逻辑
102 110 * 其中,租户编号从 {@link TenantContextHolder} 上下文中获取
103 111 *
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java
... ... @@ -266,6 +266,11 @@ public class TenantServiceImpl implements TenantService {
266 266 }
267 267  
268 268 @Override
  269 + public List<TenantDO> getTenantListByStatus(Integer status) {
  270 + return tenantMapper.selectListByStatus(status);
  271 + }
  272 +
  273 + @Override
269 274 public void handleTenantInfo(TenantInfoHandler handler) {
270 275 // 如果禁用,则不执行逻辑
271 276 if (isTenantDisable()) {
... ...
yudao-server/src/main/resources/application.yaml
... ... @@ -271,6 +271,7 @@ yudao:
271 271 ignore-urls:
272 272 - /admin-api/system/tenant/get-id-by-name # 基于名字获取租户,不许带租户编号
273 273 - /admin-api/system/tenant/get-by-website # 基于域名获取租户,不许带租户编号
  274 + - /admin-api/system/tenant/simple-list # 获取租户列表,不许带租户编号
274 275 - /admin-api/system/captcha/get # 获取图片验证码,和租户无关
275 276 - /admin-api/system/captcha/check # 校验图片验证码,和租户无关
276 277 - /admin-api/infra/file/*/get/** # 获取图片,和租户无关
... ...