From 202fc07b3578b9e972e4cd439c8b940b4f40705b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Thu, 18 Jul 2024 16:30:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3=EF=BC=9Age?= =?UTF-8?q?tTenantId/{key}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/controller/TenantController.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gxwebsoft/common/system/controller/TenantController.java b/src/main/java/com/gxwebsoft/common/system/controller/TenantController.java index 5194f24..70f3de1 100644 --- a/src/main/java/com/gxwebsoft/common/system/controller/TenantController.java +++ b/src/main/java/com/gxwebsoft/common/system/controller/TenantController.java @@ -3,6 +3,8 @@ package com.gxwebsoft.common.system.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.gxwebsoft.common.core.exception.BusinessException; +import com.gxwebsoft.common.core.utils.JSONUtil; +import com.gxwebsoft.common.core.utils.RedisUtil; import com.gxwebsoft.common.core.web.BaseController; import com.gxwebsoft.common.system.entity.*; import com.gxwebsoft.common.system.param.PlugParam; @@ -25,6 +27,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; /** @@ -45,6 +48,8 @@ public class TenantController extends BaseController { private RoleMenuService roleMenuService; @Resource private CompanyService companyService; + @Resource + private RedisUtil redisUtil; @PreAuthorize("hasAuthority('sys:tenant:list')") @ApiOperation("分页查询租户") @@ -75,12 +80,22 @@ public class TenantController extends BaseController { return success(tenant); } - @ApiOperation("根据关键词搜索租户ID") - @GetMapping("/getTenantId/{key}") - public ApiResult getTenantIdByKeywords(@PathVariable("key") String keywords) { + @ApiOperation("根据code搜索租户") + @GetMapping("/getTenantId/{code}") + public ApiResult getTenantIdByKeywords(@PathVariable("code") String code) { + String key = "TenantCode:".concat(code); + // 查询缓存 + final String string = redisUtil.get(key); + if(string != null){ + return success(JSONUtil.parseObject(string, Integer.class)); + } // 使用关联查询 - final Tenant tenant = tenantService.getOne(new LambdaUpdateWrapper().eq(Tenant::getTenantId, keywords).or().eq(Tenant::getTenantCode, keywords).last("limit 1")); - return success(tenant); + final Tenant tenant = tenantService.getOne(new LambdaUpdateWrapper().eq(Tenant::getTenantId, code).or().eq(Tenant::getTenantCode, code).last("limit 1")); + if(tenant == null){ + return fail("应用不存在或已过期",null); + } + redisUtil.set(key,tenant.getTenantId().toString(),1L, TimeUnit.DAYS); + return success(tenant.getTenantId()); } @PreAuthorize("hasAuthority('sys:tenant:save')")