新增接口:getTenantId/{key}

This commit is contained in:
2024-07-18 16:30:36 +08:00
parent adb97187e0
commit 202fc07b35

View File

@@ -3,6 +3,8 @@ package com.gxwebsoft.common.system.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.gxwebsoft.common.core.exception.BusinessException; 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.core.web.BaseController;
import com.gxwebsoft.common.system.entity.*; import com.gxwebsoft.common.system.entity.*;
import com.gxwebsoft.common.system.param.PlugParam; import com.gxwebsoft.common.system.param.PlugParam;
@@ -25,6 +27,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@@ -45,6 +48,8 @@ public class TenantController extends BaseController {
private RoleMenuService roleMenuService; private RoleMenuService roleMenuService;
@Resource @Resource
private CompanyService companyService; private CompanyService companyService;
@Resource
private RedisUtil redisUtil;
@PreAuthorize("hasAuthority('sys:tenant:list')") @PreAuthorize("hasAuthority('sys:tenant:list')")
@ApiOperation("分页查询租户") @ApiOperation("分页查询租户")
@@ -75,12 +80,22 @@ public class TenantController extends BaseController {
return success(tenant); return success(tenant);
} }
@ApiOperation("根据关键词搜索租户ID") @ApiOperation("根据code搜索租户")
@GetMapping("/getTenantId/{key}") @GetMapping("/getTenantId/{code}")
public ApiResult<Tenant> getTenantIdByKeywords(@PathVariable("key") String keywords) { public ApiResult<Integer> 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<Tenant>().eq(Tenant::getTenantId, keywords).or().eq(Tenant::getTenantCode, keywords).last("limit 1")); final Tenant tenant = tenantService.getOne(new LambdaUpdateWrapper<Tenant>().eq(Tenant::getTenantId, code).or().eq(Tenant::getTenantCode, code).last("limit 1"));
return success(tenant); if(tenant == null){
return fail("应用不存在或已过期",null);
}
redisUtil.set(key,tenant.getTenantId().toString(),1L, TimeUnit.DAYS);
return success(tenant.getTenantId());
} }
@PreAuthorize("hasAuthority('sys:tenant:save')") @PreAuthorize("hasAuthority('sys:tenant:save')")