新增接口: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.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<Tenant> getTenantIdByKeywords(@PathVariable("key") String keywords) {
@ApiOperation("根据code搜索租户")
@GetMapping("/getTenantId/{code}")
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"));
return success(tenant);
final Tenant tenant = tenantService.getOne(new LambdaUpdateWrapper<Tenant>().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')")