mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-12 16:57:12 +08:00
refactor(tenant): 优化租户相关代码
This commit is contained in:
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package top.continew.admin.common.base.model.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户实体类基类
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* 通用字段:ID、创建人、创建时间、修改人、修改时间、租户 ID
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Charles7c
|
||||||
|
* @since 2025/7/17 20:20
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class TenantBaseDO extends BaseDO {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户 ID
|
||||||
|
*/
|
||||||
|
private Long tenantId;
|
||||||
|
}
|
@@ -35,6 +35,16 @@ import java.util.List;
|
|||||||
@ConfigurationProperties(prefix = PropertiesConstants.TENANT)
|
@ConfigurationProperties(prefix = PropertiesConstants.TENANT)
|
||||||
public class TenantExtensionProperties {
|
public class TenantExtensionProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否启用
|
||||||
|
*/
|
||||||
|
private boolean enabled;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求头中租户编码键名
|
||||||
|
*/
|
||||||
|
private String tenantCodeHeader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 忽略菜单 ID(租户不能使用的菜单)
|
* 忽略菜单 ID(租户不能使用的菜单)
|
||||||
*/
|
*/
|
||||||
|
@@ -60,10 +60,22 @@ public class RegexConstants {
|
|||||||
public static final String PACKAGE_NAME = "^(?:[a-zA-Z_][a-zA-Z0-9_]*\\.)*[a-zA-Z_][a-zA-Z0-9_]*$";
|
public static final String PACKAGE_NAME = "^(?:[a-zA-Z_][a-zA-Z0-9_]*\\.)*[a-zA-Z_][a-zA-Z0-9_]*$";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTTP 域名 URL 正则
|
* HTTP 域名 URL 正则(非 IP 地址)
|
||||||
*/
|
*/
|
||||||
public static final String HTTP_DOMAIN_URL = "^(https?:\\/\\/)([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(\\/[^\\s]*)?$";
|
public static final String HTTP_DOMAIN_URL = "^(https?:\\/\\/)([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(\\/[^\\s]*)?$";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTP HOST 正则
|
||||||
|
* <p>
|
||||||
|
* 域名、IPV4、IPV6
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
public static final String HTTP_HOST = """
|
||||||
|
^((?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}|
|
||||||
|
(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|
|
||||||
|
(?:(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|
|
||||||
|
""";
|
||||||
|
|
||||||
private RegexConstants() {
|
private RegexConstants() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,13 +17,17 @@
|
|||||||
package top.continew.admin.tenant.config;
|
package top.continew.admin.tenant.config;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import top.continew.admin.common.config.TenantExtensionProperties;
|
||||||
|
import top.continew.admin.tenant.model.entity.TenantDO;
|
||||||
import top.continew.admin.tenant.service.TenantService;
|
import top.continew.admin.tenant.service.TenantService;
|
||||||
|
import top.continew.starter.core.util.ServletUtils;
|
||||||
|
import top.continew.starter.core.util.validation.CheckUtils;
|
||||||
import top.continew.starter.extension.tenant.autoconfigure.TenantProperties;
|
import top.continew.starter.extension.tenant.autoconfigure.TenantProperties;
|
||||||
import top.continew.starter.extension.tenant.config.TenantProvider;
|
import top.continew.starter.extension.tenant.config.TenantProvider;
|
||||||
import top.continew.starter.extension.tenant.context.TenantContext;
|
import top.continew.starter.extension.tenant.context.TenantContext;
|
||||||
import top.continew.starter.extension.tenant.enums.TenantIsolationLevel;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认租户提供者
|
* 默认租户提供者
|
||||||
@@ -37,21 +41,38 @@ import top.continew.starter.extension.tenant.enums.TenantIsolationLevel;
|
|||||||
public class DefaultTenantProvider implements TenantProvider {
|
public class DefaultTenantProvider implements TenantProvider {
|
||||||
|
|
||||||
private final TenantProperties tenantProperties;
|
private final TenantProperties tenantProperties;
|
||||||
|
private final TenantExtensionProperties tenantExtensionProperties;
|
||||||
private final TenantService tenantService;
|
private final TenantService tenantService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TenantContext getByTenantId(String tenantIdAsString, boolean verify) {
|
public TenantContext getByTenantId(String tenantIdAsString, boolean verify) {
|
||||||
TenantContext context = new TenantContext();
|
TenantContext context = new TenantContext();
|
||||||
context.setIsolationLevel(TenantIsolationLevel.LINE);
|
|
||||||
// 超级租户
|
|
||||||
Long superTenantId = tenantProperties.getSuperTenantId();
|
Long superTenantId = tenantProperties.getSuperTenantId();
|
||||||
if (StrUtil.isBlank(tenantIdAsString) || superTenantId.toString().equals(tenantIdAsString)) {
|
context.setTenantId(superTenantId);
|
||||||
context.setTenantId(superTenantId);
|
// 超级租户
|
||||||
|
if (superTenantId.toString().equals(tenantIdAsString)) {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
// 获取租户信息
|
Long tenantId;
|
||||||
Long tenantId = Long.valueOf(tenantIdAsString);
|
// 未指定租户
|
||||||
tenantService.checkStatus(tenantId);
|
if (StrUtil.isBlank(tenantIdAsString)) {
|
||||||
|
// 检查是否指定了租户编码(登录相关接口)
|
||||||
|
HttpServletRequest request = ServletUtils.getRequest();
|
||||||
|
String tenantCode = request.getHeader(tenantExtensionProperties.getTenantCodeHeader());
|
||||||
|
if (StrUtil.isBlank(tenantCode)) {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
TenantDO tenant = tenantService.getByCode(tenantCode);
|
||||||
|
CheckUtils.throwIfNull(tenant, "编码为 [%s] 的租户不存在".formatted(tenantCode));
|
||||||
|
tenantId = tenant.getId();
|
||||||
|
} else {
|
||||||
|
// 指定租户
|
||||||
|
tenantId = Long.parseLong(tenantIdAsString);
|
||||||
|
}
|
||||||
|
// 检查租户状态
|
||||||
|
if (verify) {
|
||||||
|
tenantService.checkStatus(tenantId);
|
||||||
|
}
|
||||||
context.setTenantId(tenantId);
|
context.setTenantId(tenantId);
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
@@ -40,10 +40,10 @@ import java.util.List;
|
|||||||
@Tag(name = "公共 API")
|
@Tag(name = "公共 API")
|
||||||
@Log(ignore = true)
|
@Log(ignore = true)
|
||||||
@Validated
|
@Validated
|
||||||
@RestController
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@RestController("tenantCommonController")
|
||||||
@RequestMapping("/tenant/common")
|
@RequestMapping("/tenant/common")
|
||||||
public class TenantCommonController {
|
public class CommonController {
|
||||||
|
|
||||||
private final PackageService packageService;
|
private final PackageService packageService;
|
||||||
|
|
@@ -17,13 +17,15 @@
|
|||||||
package top.continew.admin.tenant.controller;
|
package top.continew.admin.tenant.controller;
|
||||||
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
import cn.dev33.satoken.annotation.SaIgnore;
|
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import top.continew.admin.common.base.controller.BaseController;
|
import top.continew.admin.common.base.controller.BaseController;
|
||||||
import top.continew.admin.common.util.SecureUtils;
|
import top.continew.admin.common.util.SecureUtils;
|
||||||
import top.continew.admin.system.model.entity.user.UserDO;
|
import top.continew.admin.system.model.entity.user.UserDO;
|
||||||
@@ -33,7 +35,6 @@ import top.continew.admin.tenant.model.entity.TenantDO;
|
|||||||
import top.continew.admin.tenant.model.query.TenantQuery;
|
import top.continew.admin.tenant.model.query.TenantQuery;
|
||||||
import top.continew.admin.tenant.model.req.TenantAdminUserPwdUpdateReq;
|
import top.continew.admin.tenant.model.req.TenantAdminUserPwdUpdateReq;
|
||||||
import top.continew.admin.tenant.model.req.TenantReq;
|
import top.continew.admin.tenant.model.req.TenantReq;
|
||||||
import top.continew.admin.tenant.model.resp.TenantCommonResp;
|
|
||||||
import top.continew.admin.tenant.model.resp.TenantDetailResp;
|
import top.continew.admin.tenant.model.resp.TenantDetailResp;
|
||||||
import top.continew.admin.tenant.model.resp.TenantResp;
|
import top.continew.admin.tenant.model.resp.TenantResp;
|
||||||
import top.continew.admin.tenant.service.TenantService;
|
import top.continew.admin.tenant.service.TenantService;
|
||||||
@@ -42,7 +43,6 @@ import top.continew.starter.core.util.validation.ValidationUtils;
|
|||||||
import top.continew.starter.extension.crud.annotation.CrudRequestMapping;
|
import top.continew.starter.extension.crud.annotation.CrudRequestMapping;
|
||||||
import top.continew.starter.extension.crud.enums.Api;
|
import top.continew.starter.extension.crud.enums.Api;
|
||||||
import top.continew.starter.extension.tenant.TenantHandler;
|
import top.continew.starter.extension.tenant.TenantHandler;
|
||||||
import top.continew.starter.extension.tenant.autoconfigure.TenantProperties;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 租户管理 API
|
* 租户管理 API
|
||||||
@@ -57,26 +57,15 @@ import top.continew.starter.extension.tenant.autoconfigure.TenantProperties;
|
|||||||
@CrudRequestMapping(value = "/tenant/management", api = {Api.PAGE, Api.GET, Api.CREATE, Api.UPDATE, Api.DELETE})
|
@CrudRequestMapping(value = "/tenant/management", api = {Api.PAGE, Api.GET, Api.CREATE, Api.UPDATE, Api.DELETE})
|
||||||
public class TenantController extends BaseController<TenantService, TenantResp, TenantDetailResp, TenantQuery, TenantReq> {
|
public class TenantController extends BaseController<TenantService, TenantResp, TenantDetailResp, TenantQuery, TenantReq> {
|
||||||
|
|
||||||
private final TenantProperties tenantProperties;
|
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
|
||||||
@SaIgnore
|
|
||||||
@GetMapping("/common")
|
|
||||||
@Operation(summary = "租户通用信息查询", description = "租户通用信息查询")
|
|
||||||
public TenantCommonResp common() {
|
|
||||||
TenantCommonResp commonResp = new TenantCommonResp();
|
|
||||||
commonResp.setIsEnabled(tenantProperties.isEnabled());
|
|
||||||
commonResp.setAvailableList(baseService.getAvailableList());
|
|
||||||
return commonResp;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "修改租户管理员密码", description = "修改租户管理员密码")
|
@Operation(summary = "修改租户管理员密码", description = "修改租户管理员密码")
|
||||||
@SaCheckPermission("tenant:management:updateAdminUserPwd")
|
@SaCheckPermission("tenant:management:updateAdminUserPwd")
|
||||||
@PutMapping("/{id}/admin/pwd")
|
@PutMapping("/{id}/admin/pwd")
|
||||||
public void updateAdminUserPwd(@Valid @RequestBody TenantAdminUserPwdUpdateReq req, @PathVariable Long id) {
|
public void updateAdminUserPwd(@Valid @RequestBody TenantAdminUserPwdUpdateReq req, @PathVariable Long id) {
|
||||||
TenantDO tenant = baseService.getById(id);
|
TenantDO tenant = baseService.getById(id);
|
||||||
String encryptPassword = req.getPassword();
|
String encryptPassword = req.getPassword();
|
||||||
SpringUtil.getBean(TenantHandler.class).execute(tenant.getId(), () -> {
|
SpringUtil.getBean(TenantHandler.class).execute(id, () -> {
|
||||||
UserDO user = userService.getById(tenant.getAdminUser());
|
UserDO user = userService.getById(tenant.getAdminUser());
|
||||||
String password = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(encryptPassword));
|
String password = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(encryptPassword));
|
||||||
ValidationUtils.throwIfNull(password, "新密码解密失败");
|
ValidationUtils.throwIfNull(password, "新密码解密失败");
|
||||||
|
@@ -49,7 +49,7 @@ public class TenantDO extends BaseDO {
|
|||||||
private String code;
|
private String code;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 域名
|
* 绑定域名
|
||||||
*/
|
*/
|
||||||
private String domain;
|
private String domain;
|
||||||
|
|
||||||
|
@@ -18,13 +18,13 @@ package top.continew.admin.tenant.model.req;
|
|||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.hibernate.validator.constraints.Length;
|
import org.hibernate.validator.constraints.Length;
|
||||||
import top.continew.admin.common.enums.DisEnableStatusEnum;
|
import top.continew.admin.common.enums.DisEnableStatusEnum;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,5 +78,6 @@ public class PackageReq implements Serializable {
|
|||||||
* 关联的菜单 ID 列表
|
* 关联的菜单 ID 列表
|
||||||
*/
|
*/
|
||||||
@Schema(description = "关联的菜单 ID 列表", example = "[1000, 1010, 1011]")
|
@Schema(description = "关联的菜单 ID 列表", example = "[1000, 1010, 1011]")
|
||||||
private List<Long> menuIds = new ArrayList<>();
|
@NotEmpty(message = "关联菜单不能为空")
|
||||||
|
private List<Long> menuIds;
|
||||||
}
|
}
|
@@ -54,10 +54,11 @@ public class TenantReq implements Serializable {
|
|||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 域名
|
* 绑定域名
|
||||||
*/
|
*/
|
||||||
@Schema(description = "域名", example = "https://T0sL6RWv0vFh.continew.top/")
|
@Schema(description = "绑定域名", example = "https://T0sL6RWv0vFh.continew.top/")
|
||||||
@Length(max = 255, message = "域名长度不能超过 {max} 个字符")
|
@Length(max = 255, message = "绑定域名长度不能超过 {max} 个字符")
|
||||||
|
@Pattern(regexp = RegexConstants.HTTP_HOST, message = "绑定域名格式不正确")
|
||||||
private String domain;
|
private String domain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -61,10 +61,10 @@ public class TenantResp extends BaseDetailResp {
|
|||||||
private String code;
|
private String code;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 域名
|
* 绑定域名
|
||||||
*/
|
*/
|
||||||
@Schema(description = "域名", example = "https://T0sL6RWv0vFh.continew.top/")
|
@Schema(description = "绑定域名", example = "https://T0sL6RWv0vFh.continew.top/")
|
||||||
@ExcelProperty(value = "域名", order = 4)
|
@ExcelProperty(value = "绑定域名", order = 4)
|
||||||
private String domain;
|
private String domain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -30,4 +30,12 @@ import top.continew.starter.data.service.IService;
|
|||||||
* @author 小熊
|
* @author 小熊
|
||||||
* @since 2024/11/26 11:25
|
* @since 2024/11/26 11:25
|
||||||
*/
|
*/
|
||||||
public interface PackageService extends BaseService<PackageResp, PackageDetailResp, PackageQuery, PackageReq>, IService<PackageDO> {}
|
public interface PackageService extends BaseService<PackageResp, PackageDetailResp, PackageQuery, PackageReq>, IService<PackageDO> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查套餐状态
|
||||||
|
*
|
||||||
|
* @param id ID
|
||||||
|
*/
|
||||||
|
void checkStatus(Long id);
|
||||||
|
}
|
@@ -20,7 +20,6 @@ import top.continew.admin.common.base.service.BaseService;
|
|||||||
import top.continew.admin.tenant.model.entity.TenantDO;
|
import top.continew.admin.tenant.model.entity.TenantDO;
|
||||||
import top.continew.admin.tenant.model.query.TenantQuery;
|
import top.continew.admin.tenant.model.query.TenantQuery;
|
||||||
import top.continew.admin.tenant.model.req.TenantReq;
|
import top.continew.admin.tenant.model.req.TenantReq;
|
||||||
import top.continew.admin.tenant.model.resp.TenantAvailableResp;
|
|
||||||
import top.continew.admin.tenant.model.resp.TenantDetailResp;
|
import top.continew.admin.tenant.model.resp.TenantDetailResp;
|
||||||
import top.continew.admin.tenant.model.resp.TenantResp;
|
import top.continew.admin.tenant.model.resp.TenantResp;
|
||||||
import top.continew.starter.data.service.IService;
|
import top.continew.starter.data.service.IService;
|
||||||
@@ -36,6 +35,22 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface TenantService extends BaseService<TenantResp, TenantDetailResp, TenantQuery, TenantReq>, IService<TenantDO> {
|
public interface TenantService extends BaseService<TenantResp, TenantDetailResp, TenantQuery, TenantReq>, IService<TenantDO> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据绑定域名查询
|
||||||
|
*
|
||||||
|
* @param domain 绑定域名
|
||||||
|
* @return 租户信息
|
||||||
|
*/
|
||||||
|
TenantDO getByDomain(String domain);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据编码查询
|
||||||
|
*
|
||||||
|
* @param code 编码
|
||||||
|
* @return 租户信息
|
||||||
|
*/
|
||||||
|
TenantDO getByCode(String code);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查租户状态
|
* 检查租户状态
|
||||||
*
|
*
|
||||||
@@ -44,7 +59,18 @@ public interface TenantService extends BaseService<TenantResp, TenantDetailResp,
|
|||||||
void checkStatus(Long id);
|
void checkStatus(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有可用的租户列表
|
* 更新租户菜单
|
||||||
|
*
|
||||||
|
* @param newMenuIds 新菜单 ID 列表
|
||||||
|
* @param packageId 套餐 ID
|
||||||
*/
|
*/
|
||||||
List<TenantAvailableResp> getAvailableList();
|
void updateTenantMenu(List<Long> newMenuIds, Long packageId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据套餐 ID 查询数量
|
||||||
|
*
|
||||||
|
* @param packageIds 套餐 ID 列表
|
||||||
|
* @return 租户数量
|
||||||
|
*/
|
||||||
|
Long countByPackageIds(List<Long> packageIds);
|
||||||
}
|
}
|
@@ -16,27 +16,23 @@
|
|||||||
|
|
||||||
package top.continew.admin.tenant.service.impl;
|
package top.continew.admin.tenant.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import jakarta.annotation.Resource;
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import top.continew.admin.common.base.service.BaseServiceImpl;
|
import top.continew.admin.common.base.service.BaseServiceImpl;
|
||||||
import top.continew.admin.system.model.entity.MenuDO;
|
import top.continew.admin.common.enums.DisEnableStatusEnum;
|
||||||
import top.continew.admin.system.service.MenuService;
|
|
||||||
import top.continew.admin.tenant.mapper.PackageMapper;
|
import top.continew.admin.tenant.mapper.PackageMapper;
|
||||||
import top.continew.admin.tenant.mapper.TenantMapper;
|
|
||||||
import top.continew.admin.tenant.model.entity.PackageDO;
|
import top.continew.admin.tenant.model.entity.PackageDO;
|
||||||
import top.continew.admin.tenant.model.entity.TenantDO;
|
|
||||||
import top.continew.admin.tenant.model.query.PackageQuery;
|
import top.continew.admin.tenant.model.query.PackageQuery;
|
||||||
import top.continew.admin.tenant.model.req.PackageReq;
|
import top.continew.admin.tenant.model.req.PackageReq;
|
||||||
import top.continew.admin.tenant.model.resp.PackageDetailResp;
|
import top.continew.admin.tenant.model.resp.PackageDetailResp;
|
||||||
import top.continew.admin.tenant.model.resp.PackageResp;
|
import top.continew.admin.tenant.model.resp.PackageResp;
|
||||||
import top.continew.admin.tenant.service.PackageMenuService;
|
import top.continew.admin.tenant.service.PackageMenuService;
|
||||||
import top.continew.admin.tenant.service.PackageService;
|
import top.continew.admin.tenant.service.PackageService;
|
||||||
|
import top.continew.admin.tenant.service.TenantService;
|
||||||
import top.continew.starter.core.util.validation.CheckUtils;
|
import top.continew.starter.core.util.validation.CheckUtils;
|
||||||
import top.continew.starter.extension.tenant.TenantHandler;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,8 +47,9 @@ import java.util.List;
|
|||||||
public class PackageServiceImpl extends BaseServiceImpl<PackageMapper, PackageDO, PackageResp, PackageDetailResp, PackageQuery, PackageReq> implements PackageService {
|
public class PackageServiceImpl extends BaseServiceImpl<PackageMapper, PackageDO, PackageResp, PackageDetailResp, PackageQuery, PackageReq> implements PackageService {
|
||||||
|
|
||||||
private final PackageMenuService packageMenuService;
|
private final PackageMenuService packageMenuService;
|
||||||
private final MenuService menuService;
|
@Lazy
|
||||||
private final TenantMapper tenantMapper;
|
@Resource
|
||||||
|
private TenantService tenantService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long create(PackageReq req) {
|
public Long create(PackageReq req) {
|
||||||
@@ -75,42 +72,18 @@ public class PackageServiceImpl extends BaseServiceImpl<PackageMapper, PackageDO
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 更新租户菜单
|
// 更新租户菜单
|
||||||
List<Long> tenantIdList = tenantMapper.lambdaQuery()
|
tenantService.updateTenantMenu(req.getMenuIds(), id);
|
||||||
.select(TenantDO::getId)
|
|
||||||
.eq(TenantDO::getPackageId, id)
|
|
||||||
.list()
|
|
||||||
.stream()
|
|
||||||
.map(TenantDO::getId)
|
|
||||||
.toList();
|
|
||||||
if (CollUtil.isEmpty(tenantIdList)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<Long> oldMenuIds = packageMenuService.listMenuIdsByPackageId(id);
|
|
||||||
List<Long> newMenuIds = req.getMenuIds();
|
|
||||||
// 如果有删除的菜单则绑定了套餐的租户对应的菜单也会删除
|
|
||||||
List<Long> deleteMenuIds = new ArrayList<>(oldMenuIds);
|
|
||||||
deleteMenuIds.removeAll(newMenuIds);
|
|
||||||
if (CollUtil.isNotEmpty(deleteMenuIds)) {
|
|
||||||
List<MenuDO> deleteMenus = menuService.listByIds(deleteMenuIds);
|
|
||||||
tenantIdList.forEach(tenantId -> SpringUtil.getBean(TenantHandler.class)
|
|
||||||
.execute(tenantId, () -> menuService.deleteTenantMenus(deleteMenus)));
|
|
||||||
}
|
|
||||||
// 如果有新增的菜单则绑定了套餐的租户对应的菜单也会新增
|
|
||||||
List<Long> addMenuIds = new ArrayList<>(newMenuIds);
|
|
||||||
addMenuIds.removeAll(oldMenuIds);
|
|
||||||
if (CollUtil.isNotEmpty(addMenuIds)) {
|
|
||||||
List<MenuDO> addMenus = menuService.listByIds(addMenuIds);
|
|
||||||
for (MenuDO addMenu : addMenus) {
|
|
||||||
MenuDO parentMenu = addMenu.getParentId() != 0 ? menuService.getById(addMenu.getParentId()) : null;
|
|
||||||
tenantIdList.forEach(tenantId -> SpringUtil.getBean(TenantHandler.class)
|
|
||||||
.execute(tenantId, () -> menuService.addTenantMenu(addMenu, parentMenu)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeDelete(List<Long> ids) {
|
public void beforeDelete(List<Long> ids) {
|
||||||
CheckUtils.throwIf(tenantMapper.lambdaQuery().in(TenantDO::getPackageId, ids).exists(), "所选套餐存在关联租户,不允许删除");
|
CheckUtils.throwIf(tenantService.countByPackageIds(ids) > 0, "所选套餐存在关联租户,不允许删除");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void checkStatus(Long id) {
|
||||||
|
PackageDO entity = this.getById(id);
|
||||||
|
CheckUtils.throwIfEqual(DisEnableStatusEnum.DISABLE, entity.getStatus(), "租户套餐已被禁用");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -16,25 +16,23 @@
|
|||||||
|
|
||||||
package top.continew.admin.tenant.service.impl;
|
package top.continew.admin.tenant.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import com.alicp.jetcache.anno.Cached;
|
import com.alicp.jetcache.anno.Cached;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import me.ahoo.cosid.provider.IdGeneratorProvider;
|
import me.ahoo.cosid.provider.IdGeneratorProvider;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import top.continew.admin.common.base.service.BaseServiceImpl;
|
import top.continew.admin.common.base.service.BaseServiceImpl;
|
||||||
import top.continew.admin.common.enums.DisEnableStatusEnum;
|
import top.continew.admin.common.enums.DisEnableStatusEnum;
|
||||||
|
import top.continew.admin.system.model.entity.MenuDO;
|
||||||
|
import top.continew.admin.system.service.MenuService;
|
||||||
import top.continew.admin.tenant.constant.TenantCacheConstants;
|
import top.continew.admin.tenant.constant.TenantCacheConstants;
|
||||||
import top.continew.admin.tenant.constant.TenantConstants;
|
import top.continew.admin.tenant.constant.TenantConstants;
|
||||||
import top.continew.admin.tenant.handler.TenantDataHandler;
|
import top.continew.admin.tenant.handler.TenantDataHandler;
|
||||||
import top.continew.admin.tenant.mapper.TenantMapper;
|
import top.continew.admin.tenant.mapper.TenantMapper;
|
||||||
import top.continew.admin.tenant.model.entity.PackageDO;
|
|
||||||
import top.continew.admin.tenant.model.entity.TenantDO;
|
import top.continew.admin.tenant.model.entity.TenantDO;
|
||||||
import top.continew.admin.tenant.model.query.TenantQuery;
|
import top.continew.admin.tenant.model.query.TenantQuery;
|
||||||
import top.continew.admin.tenant.model.req.TenantReq;
|
import top.continew.admin.tenant.model.req.TenantReq;
|
||||||
import top.continew.admin.tenant.model.resp.TenantAvailableResp;
|
|
||||||
import top.continew.admin.tenant.model.resp.TenantDetailResp;
|
import top.continew.admin.tenant.model.resp.TenantDetailResp;
|
||||||
import top.continew.admin.tenant.model.resp.TenantResp;
|
import top.continew.admin.tenant.model.resp.TenantResp;
|
||||||
import top.continew.admin.tenant.service.PackageMenuService;
|
import top.continew.admin.tenant.service.PackageMenuService;
|
||||||
@@ -42,12 +40,12 @@ import top.continew.admin.tenant.service.PackageService;
|
|||||||
import top.continew.admin.tenant.service.TenantService;
|
import top.continew.admin.tenant.service.TenantService;
|
||||||
import top.continew.starter.cache.redisson.util.RedisUtils;
|
import top.continew.starter.cache.redisson.util.RedisUtils;
|
||||||
import top.continew.starter.core.util.validation.CheckUtils;
|
import top.continew.starter.core.util.validation.CheckUtils;
|
||||||
import top.continew.starter.extension.crud.model.entity.BaseIdDO;
|
|
||||||
import top.continew.starter.extension.tenant.TenantHandler;
|
import top.continew.starter.extension.tenant.TenantHandler;
|
||||||
import top.continew.starter.extension.tenant.autoconfigure.TenantProperties;
|
import top.continew.starter.extension.tenant.autoconfigure.TenantProperties;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,17 +60,18 @@ import java.util.List;
|
|||||||
public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, TenantDO, TenantResp, TenantDetailResp, TenantQuery, TenantReq> implements TenantService {
|
public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, TenantDO, TenantResp, TenantDetailResp, TenantQuery, TenantReq> implements TenantService {
|
||||||
|
|
||||||
private final TenantProperties tenantProperties;
|
private final TenantProperties tenantProperties;
|
||||||
private final IdGeneratorProvider idGeneratorProvider;
|
|
||||||
private final PackageMenuService packageMenuService;
|
|
||||||
private final PackageService packageService;
|
private final PackageService packageService;
|
||||||
|
private final IdGeneratorProvider idGeneratorProvider;
|
||||||
private final TenantDataHandler tenantDataHandler;
|
private final TenantDataHandler tenantDataHandler;
|
||||||
|
private final PackageMenuService packageMenuService;
|
||||||
|
private final MenuService menuService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long create(TenantReq req) {
|
public Long create(TenantReq req) {
|
||||||
this.checkNameRepeat(req.getName(), null);
|
this.checkNameRepeat(req.getName(), null);
|
||||||
// 检查租户套餐
|
this.checkDomainRepeat(req.getDomain(), null);
|
||||||
List<Long> menuIds = packageMenuService.listMenuIdsByPackageId(req.getPackageId());
|
// 检查套餐
|
||||||
CheckUtils.throwIfEmpty(menuIds, "所选套餐无可用菜单");
|
packageService.checkStatus(req.getPackageId());
|
||||||
// 生成租户编码
|
// 生成租户编码
|
||||||
req.setCode(this.generateCode());
|
req.setCode(this.generateCode());
|
||||||
// 新增信息
|
// 新增信息
|
||||||
@@ -86,6 +85,12 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, TenantDO, T
|
|||||||
@Override
|
@Override
|
||||||
public void beforeUpdate(TenantReq req, Long id) {
|
public void beforeUpdate(TenantReq req, Long id) {
|
||||||
this.checkNameRepeat(req.getName(), id);
|
this.checkNameRepeat(req.getName(), id);
|
||||||
|
this.checkDomainRepeat(req.getDomain(), id);
|
||||||
|
TenantDO tenant = super.getById(id);
|
||||||
|
// 变更套餐
|
||||||
|
if (!tenant.getPackageId().equals(req.getPackageId())) {
|
||||||
|
packageService.checkStatus(req.getPackageId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -114,30 +119,63 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, TenantDO, T
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void checkStatus(Long id) {
|
public TenantDO getByDomain(String domain) {
|
||||||
TenantDO tenant = this.getById(id);
|
return baseMapper.lambdaQuery().eq(TenantDO::getDomain, domain).oneOpt().orElse(null);
|
||||||
if (!tenantProperties.isEnabled() || id.equals(tenantProperties.getSuperTenantId())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
CheckUtils.throwIfNotEqual(DisEnableStatusEnum.ENABLE, tenant.getStatus(), "此租户已被禁用");
|
|
||||||
CheckUtils.throwIf(tenant.getExpireTime() != null && tenant.getExpireTime()
|
|
||||||
.isBefore(LocalDateTime.now()), "此租户已过期");
|
|
||||||
// 检查套餐
|
|
||||||
PackageDO tenantPackage = packageService.getById(tenant.getPackageId());
|
|
||||||
CheckUtils.throwIfNotEqual(DisEnableStatusEnum.ENABLE, tenantPackage.getStatus(), "此租户套餐已被禁用");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TenantAvailableResp> getAvailableList() {
|
public TenantDO getByCode(String code) {
|
||||||
List<TenantDO> tenantList = baseMapper.selectList(Wrappers.lambdaQuery(TenantDO.class)
|
return baseMapper.lambdaQuery().eq(TenantDO::getCode, code).oneOpt().orElse(null);
|
||||||
.select(TenantDO::getName, BaseIdDO::getId, TenantDO::getDomain)
|
}
|
||||||
.eq(TenantDO::getStatus, DisEnableStatusEnum.ENABLE)
|
|
||||||
.and(t -> t.isNull(TenantDO::getExpireTime).or().ge(TenantDO::getExpireTime, DateUtil.date())));
|
@Override
|
||||||
return BeanUtil.copyToList(tenantList, TenantAvailableResp.class);
|
public void checkStatus(Long id) {
|
||||||
|
TenantDO tenant = this.getById(id);
|
||||||
|
if (id.equals(tenantProperties.getSuperTenantId())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CheckUtils.throwIfEqual(DisEnableStatusEnum.DISABLE, tenant.getStatus(), "租户已被禁用");
|
||||||
|
CheckUtils.throwIf(tenant.getExpireTime() != null && tenant.getExpireTime()
|
||||||
|
.isBefore(LocalDateTime.now()), "租户已过期");
|
||||||
|
// 检查套餐
|
||||||
|
packageService.checkStatus(tenant.getPackageId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateTenantMenu(List<Long> newMenuIds, Long packageId) {
|
||||||
|
List<Long> tenantIdList = this.listIdByPackageId(packageId);
|
||||||
|
if (CollUtil.isEmpty(tenantIdList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<Long> oldMenuIds = packageMenuService.listMenuIdsByPackageId(packageId);
|
||||||
|
// 如果有删除的菜单则绑定了套餐的租户对应的菜单也会删除
|
||||||
|
List<Long> deleteMenuIds = new ArrayList<>(oldMenuIds);
|
||||||
|
deleteMenuIds.removeAll(newMenuIds);
|
||||||
|
if (CollUtil.isNotEmpty(deleteMenuIds)) {
|
||||||
|
List<MenuDO> deleteMenus = menuService.listByIds(deleteMenuIds);
|
||||||
|
tenantIdList.forEach(tenantId -> SpringUtil.getBean(TenantHandler.class).execute(tenantId, () -> menuService
|
||||||
|
.deleteTenantMenus(deleteMenus)));
|
||||||
|
}
|
||||||
|
// 如果有新增的菜单则绑定了套餐的租户对应的菜单也会新增
|
||||||
|
List<Long> addMenuIds = new ArrayList<>(newMenuIds);
|
||||||
|
addMenuIds.removeAll(oldMenuIds);
|
||||||
|
if (CollUtil.isNotEmpty(addMenuIds)) {
|
||||||
|
List<MenuDO> addMenus = menuService.listByIds(addMenuIds);
|
||||||
|
for (MenuDO addMenu : addMenus) {
|
||||||
|
MenuDO parentMenu = addMenu.getParentId() != 0 ? menuService.getById(addMenu.getParentId()) : null;
|
||||||
|
tenantIdList.forEach(tenantId -> SpringUtil.getBean(TenantHandler.class).execute(tenantId, () -> menuService
|
||||||
|
.addTenantMenu(addMenu, parentMenu)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long countByPackageIds(List<Long> packageIds) {
|
||||||
|
return baseMapper.lambdaQuery().in(TenantDO::getPackageId, packageIds).count();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 名称是否存在
|
* 检查名称是否重复
|
||||||
*
|
*
|
||||||
* @param name 名称
|
* @param name 名称
|
||||||
* @param id ID
|
* @param id ID
|
||||||
@@ -149,6 +187,19 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, TenantDO, T
|
|||||||
.exists(), "名称为 [{}] 的租户已存在", name);
|
.exists(), "名称为 [{}] 的租户已存在", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查绑定域名是否重复
|
||||||
|
*
|
||||||
|
* @param domain 绑定域名
|
||||||
|
* @param id ID
|
||||||
|
*/
|
||||||
|
private void checkDomainRepeat(String domain, Long id) {
|
||||||
|
CheckUtils.throwIf(baseMapper.lambdaQuery()
|
||||||
|
.eq(TenantDO::getDomain, domain)
|
||||||
|
.ne(id != null, TenantDO::getId, id)
|
||||||
|
.exists(), "绑定域名为 [{}] 的租户已存在", domain);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成租户编码
|
* 生成租户编码
|
||||||
*
|
*
|
||||||
@@ -161,4 +212,20 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, TenantDO, T
|
|||||||
} while (baseMapper.lambdaQuery().eq(TenantDO::getCode, code).exists());
|
} while (baseMapper.lambdaQuery().eq(TenantDO::getCode, code).exists());
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据套餐 ID 查询租户 ID 列表
|
||||||
|
*
|
||||||
|
* @param id 套餐 ID
|
||||||
|
* @return 租户 ID 列表
|
||||||
|
*/
|
||||||
|
private List<Long> listIdByPackageId(Long id) {
|
||||||
|
return baseMapper.lambdaQuery()
|
||||||
|
.select(TenantDO::getId)
|
||||||
|
.eq(TenantDO::getPackageId, id)
|
||||||
|
.list()
|
||||||
|
.stream()
|
||||||
|
.map(TenantDO::getId)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
}
|
}
|
@@ -19,10 +19,18 @@ package top.continew.admin.config.satoken;
|
|||||||
import cn.dev33.satoken.fun.SaParamFunction;
|
import cn.dev33.satoken.fun.SaParamFunction;
|
||||||
import cn.dev33.satoken.interceptor.SaInterceptor;
|
import cn.dev33.satoken.interceptor.SaInterceptor;
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import cn.hutool.extra.servlet.JakartaServletUtil;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
|
import top.continew.admin.common.context.UserContext;
|
||||||
import top.continew.admin.common.context.UserContextHolder;
|
import top.continew.admin.common.context.UserContextHolder;
|
||||||
|
import top.continew.starter.extension.tenant.context.TenantContextHolder;
|
||||||
|
import top.continew.starter.web.model.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sa-Token 扩展拦截器
|
* Sa-Token 扩展拦截器
|
||||||
@@ -30,6 +38,7 @@ import top.continew.admin.common.context.UserContextHolder;
|
|||||||
* @author Charles7c
|
* @author Charles7c
|
||||||
* @since 2024/10/10 20:25
|
* @since 2024/10/10 20:25
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class SaExtensionInterceptor extends SaInterceptor {
|
public class SaExtensionInterceptor extends SaInterceptor {
|
||||||
|
|
||||||
public SaExtensionInterceptor(SaParamFunction<Object> auth) {
|
public SaExtensionInterceptor(SaParamFunction<Object> auth) {
|
||||||
@@ -41,11 +50,24 @@ public class SaExtensionInterceptor extends SaInterceptor {
|
|||||||
HttpServletResponse response,
|
HttpServletResponse response,
|
||||||
Object handler) throws Exception {
|
Object handler) throws Exception {
|
||||||
boolean flag = super.preHandle(request, response, handler);
|
boolean flag = super.preHandle(request, response, handler);
|
||||||
if (flag && StpUtil.isLogin()) {
|
if (!flag || !StpUtil.isLogin()) {
|
||||||
UserContextHolder.getContext();
|
return flag;
|
||||||
UserContextHolder.getExtraContext();
|
|
||||||
}
|
}
|
||||||
return flag;
|
// 设置上下文
|
||||||
|
UserContext userContext = UserContextHolder.getContext();
|
||||||
|
if (userContext == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// 检查用户租户权限
|
||||||
|
Long userTenantId = userContext.getTenantId();
|
||||||
|
Long tenantId = TenantContextHolder.getTenantId();
|
||||||
|
if (!userTenantId.equals(tenantId)) {
|
||||||
|
JakartaServletUtil.write(response, JSONUtil.toJsonStr(R.fail(String.valueOf(HttpStatus.FORBIDDEN
|
||||||
|
.value()), "您当前没有访问该租户的权限")), MediaType.APPLICATION_JSON_VALUE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
UserContextHolder.getExtraContext();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -53,6 +75,7 @@ public class SaExtensionInterceptor extends SaInterceptor {
|
|||||||
HttpServletResponse response,
|
HttpServletResponse response,
|
||||||
Object handler,
|
Object handler,
|
||||||
@Nullable Exception e) throws Exception {
|
@Nullable Exception e) throws Exception {
|
||||||
|
// 清除上下文
|
||||||
try {
|
try {
|
||||||
super.afterCompletion(request, response, handler, e);
|
super.afterCompletion(request, response, handler, e);
|
||||||
} finally {
|
} finally {
|
||||||
|
@@ -57,6 +57,7 @@ import top.continew.starter.core.autoconfigure.application.ApplicationProperties
|
|||||||
import top.continew.starter.core.util.TemplateUtils;
|
import top.continew.starter.core.util.TemplateUtils;
|
||||||
import top.continew.starter.core.util.validation.CheckUtils;
|
import top.continew.starter.core.util.validation.CheckUtils;
|
||||||
import top.continew.starter.core.util.validation.ValidationUtils;
|
import top.continew.starter.core.util.validation.ValidationUtils;
|
||||||
|
import top.continew.starter.extension.tenant.annotation.TenantIgnore;
|
||||||
import top.continew.starter.log.annotation.Log;
|
import top.continew.starter.log.annotation.Log;
|
||||||
import top.continew.starter.messaging.mail.util.MailUtils;
|
import top.continew.starter.messaging.mail.util.MailUtils;
|
||||||
import top.continew.starter.ratelimiter.annotation.RateLimiter;
|
import top.continew.starter.ratelimiter.annotation.RateLimiter;
|
||||||
@@ -78,6 +79,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* @since 2022/12/11 14:00
|
* @since 2022/12/11 14:00
|
||||||
*/
|
*/
|
||||||
@Tag(name = "验证码 API")
|
@Tag(name = "验证码 API")
|
||||||
|
@TenantIgnore
|
||||||
@SaIgnore
|
@SaIgnore
|
||||||
@Validated
|
@Validated
|
||||||
@RestController
|
@RestController
|
||||||
|
@@ -38,6 +38,7 @@ import top.continew.admin.system.service.*;
|
|||||||
import top.continew.starter.core.util.validation.ValidationUtils;
|
import top.continew.starter.core.util.validation.ValidationUtils;
|
||||||
import top.continew.starter.extension.crud.model.query.SortQuery;
|
import top.continew.starter.extension.crud.model.query.SortQuery;
|
||||||
import top.continew.starter.extension.crud.model.resp.LabelValueResp;
|
import top.continew.starter.extension.crud.model.resp.LabelValueResp;
|
||||||
|
import top.continew.starter.extension.tenant.annotation.TenantIgnore;
|
||||||
import top.continew.starter.log.annotation.Log;
|
import top.continew.starter.log.annotation.Log;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -111,6 +112,7 @@ public class CommonController {
|
|||||||
return dictItemService.listByDictCode(code);
|
return dictItemService.listByDictCode(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TenantIgnore
|
||||||
@SaIgnore
|
@SaIgnore
|
||||||
@Operation(summary = "查询系统配置参数", description = "查询系统配置参数")
|
@Operation(summary = "查询系统配置参数", description = "查询系统配置参数")
|
||||||
@GetMapping("/dict/option/site")
|
@GetMapping("/dict/option/site")
|
||||||
|
@@ -35,6 +35,7 @@ import top.continew.admin.system.model.entity.user.UserDO;
|
|||||||
import top.continew.admin.system.model.entity.user.UserSocialDO;
|
import top.continew.admin.system.model.entity.user.UserSocialDO;
|
||||||
import top.continew.starter.cache.redisson.util.RedisUtils;
|
import top.continew.starter.cache.redisson.util.RedisUtils;
|
||||||
import top.continew.starter.core.constant.StringConstants;
|
import top.continew.starter.core.constant.StringConstants;
|
||||||
|
import top.continew.starter.extension.tenant.annotation.TenantIgnore;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.BooleanSupplier;
|
import java.util.function.BooleanSupplier;
|
||||||
@@ -78,6 +79,7 @@ public class DemoEnvironmentJob {
|
|||||||
/**
|
/**
|
||||||
* 重置演示环境数据
|
* 重置演示环境数据
|
||||||
*/
|
*/
|
||||||
|
@TenantIgnore
|
||||||
@JobExecutor(name = "ResetEnvironmentData")
|
@JobExecutor(name = "ResetEnvironmentData")
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void resetEnvironmentData() {
|
public void resetEnvironmentData() {
|
||||||
|
@@ -33,6 +33,7 @@ import top.continew.admin.system.mapper.NoticeMapper;
|
|||||||
import top.continew.admin.system.model.entity.NoticeDO;
|
import top.continew.admin.system.model.entity.NoticeDO;
|
||||||
import top.continew.admin.system.service.NoticeService;
|
import top.continew.admin.system.service.NoticeService;
|
||||||
import top.continew.starter.core.constant.PropertiesConstants;
|
import top.continew.starter.core.constant.PropertiesConstants;
|
||||||
|
import top.continew.starter.extension.tenant.annotation.TenantIgnore;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -55,6 +56,7 @@ public class NoticePublishJob {
|
|||||||
@ConditionalOnProperty(prefix = "snail-job", name = PropertiesConstants.ENABLED, havingValue = "false")
|
@ConditionalOnProperty(prefix = "snail-job", name = PropertiesConstants.ENABLED, havingValue = "false")
|
||||||
public static class Scheduler {
|
public static class Scheduler {
|
||||||
|
|
||||||
|
@TenantIgnore
|
||||||
@Scheduled(cron = "0 * * * * ?")
|
@Scheduled(cron = "0 * * * * ?")
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void publishNoticeWithSchedule() {
|
public void publishNoticeWithSchedule() {
|
||||||
@@ -71,6 +73,7 @@ public class NoticePublishJob {
|
|||||||
@ConditionalOnEnabledScheduleJob
|
@ConditionalOnEnabledScheduleJob
|
||||||
public static class ScheduleJob {
|
public static class ScheduleJob {
|
||||||
|
|
||||||
|
@TenantIgnore
|
||||||
@JobExecutor(name = "NoticePublishJob")
|
@JobExecutor(name = "NoticePublishJob")
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void publishNoticeWithScheduleJob() {
|
public void publishNoticeWithScheduleJob() {
|
||||||
|
@@ -175,7 +175,7 @@ logging:
|
|||||||
--- ### 链路追踪配置
|
--- ### 链路追踪配置
|
||||||
continew-starter.trace:
|
continew-starter.trace:
|
||||||
enabled: true
|
enabled: true
|
||||||
trace-id-name: traceId
|
trace-id-name: X-Trace-Id
|
||||||
## TLog 配置
|
## TLog 配置
|
||||||
tlog:
|
tlog:
|
||||||
enable-invoke-time-print: false
|
enable-invoke-time-print: false
|
||||||
@@ -202,24 +202,27 @@ continew-starter.tenant:
|
|||||||
enabled: true
|
enabled: true
|
||||||
# 隔离级别(默认:LINE,行级)
|
# 隔离级别(默认:LINE,行级)
|
||||||
isolation-level: LINE
|
isolation-level: LINE
|
||||||
# 超级/默认租户 ID
|
# 超级/默认租户 ID:超管用户所在租户(默认:0)
|
||||||
super-tenant-id: 0
|
super-tenant-id: 0
|
||||||
|
# 请求头中租户 ID 键名
|
||||||
|
tenant-id-header: X-Tenant-Id
|
||||||
|
# 请求头中租户编码键名
|
||||||
|
tenant-code-header: X-Tenant-Code
|
||||||
# 忽略表(忽略拼接租户条件)
|
# 忽略表(忽略拼接租户条件)
|
||||||
ignore-tables:
|
ignore-tables:
|
||||||
- gen_config # 代码生成
|
- tenant # 租户表
|
||||||
- gen_field_config
|
- tenant_package # 租户套餐表
|
||||||
|
- tenant_package_menu # 租户套餐与菜单关联表
|
||||||
|
- gen_config # 代码生成配置表
|
||||||
|
- gen_field_config # 代码生成字段配置表
|
||||||
- sys_dict # 字典表
|
- sys_dict # 字典表
|
||||||
- sys_dict_item
|
- sys_dict_item # 字典项表
|
||||||
- sys_option # 参数
|
- sys_option # 参数表
|
||||||
- sys_storage # 存储配置
|
- sys_storage # 存储表
|
||||||
- tenant # 租户
|
- sys_sms_config # 短信配置表
|
||||||
- tenant_package
|
- sys_sms_log # 短信日志表
|
||||||
- tenant_package_menu
|
- sys_client # 客户端表
|
||||||
- tenant_datasource
|
- sys_app # 应用表
|
||||||
- sys_client # 客户端管理
|
|
||||||
- sys_sms_config
|
|
||||||
- sys_sms_log
|
|
||||||
- sys_app # 应用
|
|
||||||
# 忽略菜单 ID(租户不能使用的菜单)
|
# 忽略菜单 ID(租户不能使用的菜单)
|
||||||
ignore-menus:
|
ignore-menus:
|
||||||
- 1130 # 字典管理
|
- 1130 # 字典管理
|
||||||
@@ -229,7 +232,7 @@ continew-starter.tenant:
|
|||||||
- 3000 # 租户管理
|
- 3000 # 租户管理
|
||||||
- 7000 # 能力开放
|
- 7000 # 能力开放
|
||||||
- 8000 # 任务调度
|
- 8000 # 任务调度
|
||||||
- 9000 # 代码生成
|
- 9000 # 开发工具
|
||||||
|
|
||||||
--- ### 限流器配置
|
--- ### 限流器配置
|
||||||
continew-starter:
|
continew-starter:
|
||||||
|
@@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS `tenant` (
|
|||||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
|
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
|
||||||
`name` varchar(30) NOT NULL COMMENT '名称',
|
`name` varchar(30) NOT NULL COMMENT '名称',
|
||||||
`code` varchar(30) NOT NULL COMMENT '编码',
|
`code` varchar(30) NOT NULL COMMENT '编码',
|
||||||
`domain` varchar(255) DEFAULT NULL COMMENT '域名',
|
`domain` varchar(255) DEFAULT NULL COMMENT '绑定域名',
|
||||||
`expire_time` datetime DEFAULT NULL COMMENT '过期时间',
|
`expire_time` datetime DEFAULT NULL COMMENT '过期时间',
|
||||||
`description` varchar(200) DEFAULT NULL COMMENT '描述',
|
`description` varchar(200) DEFAULT NULL COMMENT '描述',
|
||||||
`status` tinyint(1) UNSIGNED NOT NULL DEFAULT 1 COMMENT '状态(1:启用;2:禁用)',
|
`status` tinyint(1) UNSIGNED NOT NULL DEFAULT 1 COMMENT '状态(1:启用;2:禁用)',
|
||||||
|
@@ -22,13 +22,12 @@ CREATE TABLE IF NOT EXISTS "tenant" (
|
|||||||
CREATE UNIQUE INDEX "uk_tenant_code" ON "tenant" ("code");
|
CREATE UNIQUE INDEX "uk_tenant_code" ON "tenant" ("code");
|
||||||
CREATE INDEX "idx_tenant_admin_user" ON "tenant" ("admin_user");
|
CREATE INDEX "idx_tenant_admin_user" ON "tenant" ("admin_user");
|
||||||
CREATE INDEX "idx_tenant_package_id" ON "tenant" ("package_id");
|
CREATE INDEX "idx_tenant_package_id" ON "tenant" ("package_id");
|
||||||
CREATE INDEX "idx_tenant_datasource_id" ON "tenant" ("datasource_id");
|
|
||||||
CREATE INDEX "idx_tenant_create_user" ON "tenant" ("create_user");
|
CREATE INDEX "idx_tenant_create_user" ON "tenant" ("create_user");
|
||||||
CREATE INDEX "idx_tenant_update_user" ON "tenant" ("update_user");
|
CREATE INDEX "idx_tenant_update_user" ON "tenant" ("update_user");
|
||||||
COMMENT ON COLUMN "tenant"."id" IS 'ID';
|
COMMENT ON COLUMN "tenant"."id" IS 'ID';
|
||||||
COMMENT ON COLUMN "tenant"."name" IS '名称';
|
COMMENT ON COLUMN "tenant"."name" IS '名称';
|
||||||
COMMENT ON COLUMN "tenant"."code" IS '编码';
|
COMMENT ON COLUMN "tenant"."code" IS '编码';
|
||||||
COMMENT ON COLUMN "tenant"."domain" IS '域名';
|
COMMENT ON COLUMN "tenant"."domain" IS '绑定域名';
|
||||||
COMMENT ON COLUMN "tenant"."expire_time" IS '过期时间';
|
COMMENT ON COLUMN "tenant"."expire_time" IS '过期时间';
|
||||||
COMMENT ON COLUMN "tenant"."description" IS '描述';
|
COMMENT ON COLUMN "tenant"."description" IS '描述';
|
||||||
COMMENT ON COLUMN "tenant"."status" IS '状态(1:启用;2:禁用)';
|
COMMENT ON COLUMN "tenant"."status" IS '状态(1:启用;2:禁用)';
|
||||||
|
@@ -29,13 +29,13 @@ import org.springframework.stereotype.Service;
|
|||||||
import top.continew.admin.auth.model.query.OnlineUserQuery;
|
import top.continew.admin.auth.model.query.OnlineUserQuery;
|
||||||
import top.continew.admin.auth.model.resp.OnlineUserResp;
|
import top.continew.admin.auth.model.resp.OnlineUserResp;
|
||||||
import top.continew.admin.auth.service.OnlineUserService;
|
import top.continew.admin.auth.service.OnlineUserService;
|
||||||
|
import top.continew.admin.common.config.TenantExtensionProperties;
|
||||||
import top.continew.admin.common.context.UserContext;
|
import top.continew.admin.common.context.UserContext;
|
||||||
import top.continew.admin.common.context.UserContextHolder;
|
import top.continew.admin.common.context.UserContextHolder;
|
||||||
import top.continew.admin.common.context.UserExtraContext;
|
import top.continew.admin.common.context.UserExtraContext;
|
||||||
import top.continew.starter.core.constant.StringConstants;
|
import top.continew.starter.core.constant.StringConstants;
|
||||||
import top.continew.starter.extension.crud.model.query.PageQuery;
|
import top.continew.starter.extension.crud.model.query.PageQuery;
|
||||||
import top.continew.starter.extension.crud.model.resp.PageResp;
|
import top.continew.starter.extension.crud.model.resp.PageResp;
|
||||||
import top.continew.starter.extension.tenant.autoconfigure.TenantProperties;
|
|
||||||
import top.continew.starter.extension.tenant.context.TenantContextHolder;
|
import top.continew.starter.extension.tenant.context.TenantContextHolder;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -52,7 +52,7 @@ import java.util.stream.Collectors;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class OnlineUserServiceImpl implements OnlineUserService {
|
public class OnlineUserServiceImpl implements OnlineUserService {
|
||||||
|
|
||||||
private final TenantProperties tenantProperties;
|
private final TenantExtensionProperties tenantExtensionProperties;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@AutoOperate(type = OnlineUserResp.class, on = "list")
|
@AutoOperate(type = OnlineUserResp.class, on = "list")
|
||||||
@@ -92,8 +92,8 @@ public class OnlineUserServiceImpl implements OnlineUserService {
|
|||||||
.isMatchClientId(query.getClientId(), userContext)) {
|
.isMatchClientId(query.getClientId(), userContext)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//租户数据过滤
|
// 只显示本租户数据
|
||||||
if (tenantProperties.isEnabled()) {
|
if (tenantExtensionProperties.isEnabled()) {
|
||||||
if (!TenantContextHolder.getTenantId().equals(userContext.getTenantId())) {
|
if (!TenantContextHolder.getTenantId().equals(userContext.getTenantId())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@@ -20,11 +20,11 @@ import com.baomidou.mybatisplus.annotation.FieldStrategy;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import top.continew.admin.common.base.model.entity.TenantBaseDO;
|
||||||
import top.continew.admin.common.config.mybatis.BCryptEncryptor;
|
import top.continew.admin.common.config.mybatis.BCryptEncryptor;
|
||||||
import top.continew.admin.common.enums.DisEnableStatusEnum;
|
import top.continew.admin.common.enums.DisEnableStatusEnum;
|
||||||
import top.continew.admin.common.enums.GenderEnum;
|
import top.continew.admin.common.enums.GenderEnum;
|
||||||
import top.continew.starter.extension.crud.annotation.DictModel;
|
import top.continew.starter.extension.crud.annotation.DictModel;
|
||||||
import top.continew.admin.common.base.model.entity.BaseDO;
|
|
||||||
import top.continew.starter.security.crypto.annotation.FieldEncrypt;
|
import top.continew.starter.security.crypto.annotation.FieldEncrypt;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
@@ -39,7 +39,7 @@ import java.time.LocalDateTime;
|
|||||||
@Data
|
@Data
|
||||||
@DictModel(labelKey = "nickname", extraKeys = {"username"})
|
@DictModel(labelKey = "nickname", extraKeys = {"username"})
|
||||||
@TableName("sys_user")
|
@TableName("sys_user")
|
||||||
public class UserDO extends BaseDO {
|
public class UserDO extends TenantBaseDO {
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
@@ -108,10 +108,4 @@ public class UserDO extends BaseDO {
|
|||||||
* 部门 ID
|
* 部门 ID
|
||||||
*/
|
*/
|
||||||
private Long deptId;
|
private Long deptId;
|
||||||
|
|
||||||
/**
|
|
||||||
* 租户 ID
|
|
||||||
*/
|
|
||||||
@TableField(select = false)
|
|
||||||
private Long tenantId;
|
|
||||||
}
|
}
|
||||||
|
@@ -62,6 +62,6 @@ public class MenuQuery implements Serializable {
|
|||||||
* 排除的菜单 ID 列表
|
* 排除的菜单 ID 列表
|
||||||
*/
|
*/
|
||||||
@Schema(hidden = true, description = "菜单 ID 列表", example = "[9000]")
|
@Schema(hidden = true, description = "菜单 ID 列表", example = "[9000]")
|
||||||
@Query(columns = "id", type = QueryType.NOT_IN)
|
@Query(columns = {"id", "parent_id"}, type = QueryType.NOT_IN)
|
||||||
private List<Long> excludeMenuIdList;
|
private List<Long> excludeMenuIdList;
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import top.continew.admin.common.base.service.BaseServiceImpl;
|
import top.continew.admin.common.base.service.BaseServiceImpl;
|
||||||
import top.continew.admin.common.enums.DisEnableStatusEnum;
|
import top.continew.admin.common.enums.DisEnableStatusEnum;
|
||||||
@@ -53,10 +54,10 @@ import java.util.Optional;
|
|||||||
public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptResp, DeptResp, DeptQuery, DeptReq> implements DeptService {
|
public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptResp, DeptResp, DeptQuery, DeptReq> implements DeptService {
|
||||||
|
|
||||||
private final RoleDeptService roleDeptService;
|
private final RoleDeptService roleDeptService;
|
||||||
|
private final DataSource dataSource;
|
||||||
|
@Lazy
|
||||||
@Resource
|
@Resource
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
@Resource
|
|
||||||
private DataSource dataSource;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeCreate(DeptReq req) {
|
public void beforeCreate(DeptReq req) {
|
||||||
|
@@ -28,6 +28,7 @@ import org.dromara.x.file.storage.core.FileInfo;
|
|||||||
import org.dromara.x.file.storage.core.FileStorageService;
|
import org.dromara.x.file.storage.core.FileStorageService;
|
||||||
import org.dromara.x.file.storage.core.ProgressListener;
|
import org.dromara.x.file.storage.core.ProgressListener;
|
||||||
import org.dromara.x.file.storage.core.upload.UploadPretreatment;
|
import org.dromara.x.file.storage.core.upload.UploadPretreatment;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import top.continew.admin.common.base.service.BaseServiceImpl;
|
import top.continew.admin.common.base.service.BaseServiceImpl;
|
||||||
@@ -64,6 +65,7 @@ import java.util.stream.Collectors;
|
|||||||
public class FileServiceImpl extends BaseServiceImpl<FileMapper, FileDO, FileResp, FileResp, FileQuery, FileReq> implements FileService {
|
public class FileServiceImpl extends BaseServiceImpl<FileMapper, FileDO, FileResp, FileResp, FileQuery, FileReq> implements FileService {
|
||||||
|
|
||||||
private final FileStorageService fileStorageService;
|
private final FileStorageService fileStorageService;
|
||||||
|
@Lazy
|
||||||
@Resource
|
@Resource
|
||||||
private StorageService storageService;
|
private StorageService storageService;
|
||||||
|
|
||||||
|
@@ -73,7 +73,7 @@ public class SmsConfigServiceImpl extends BaseServiceImpl<SmsConfigMapper, SmsCo
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 启用状态才能设为默认配置
|
// 启用状态才能设为默认配置
|
||||||
CheckUtils.throwIfNotEqual(DisEnableStatusEnum.ENABLE, smsConfig.getStatus(), "请先启用所选配置");
|
CheckUtils.throwIfEqual(DisEnableStatusEnum.DISABLE, smsConfig.getStatus(), "请先启用所选配置");
|
||||||
baseMapper.lambdaUpdate().eq(SmsConfigDO::getIsDefault, true).set(SmsConfigDO::getIsDefault, false).update();
|
baseMapper.lambdaUpdate().eq(SmsConfigDO::getIsDefault, true).set(SmsConfigDO::getIsDefault, false).update();
|
||||||
baseMapper.lambdaUpdate().eq(SmsConfigDO::getId, id).set(SmsConfigDO::getIsDefault, true).update();
|
baseMapper.lambdaUpdate().eq(SmsConfigDO::getId, id).set(SmsConfigDO::getIsDefault, true).update();
|
||||||
}
|
}
|
||||||
|
@@ -155,7 +155,7 @@ public class StorageServiceImpl extends BaseServiceImpl<StorageMapper, StorageDO
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 启用状态才能设为默认存储
|
// 启用状态才能设为默认存储
|
||||||
CheckUtils.throwIfNotEqual(DisEnableStatusEnum.ENABLE, storage.getStatus(), "请先启用所选存储");
|
CheckUtils.throwIfEqual(DisEnableStatusEnum.DISABLE, storage.getStatus(), "请先启用所选存储");
|
||||||
baseMapper.lambdaUpdate().eq(StorageDO::getIsDefault, true).set(StorageDO::getIsDefault, false).update();
|
baseMapper.lambdaUpdate().eq(StorageDO::getIsDefault, true).set(StorageDO::getIsDefault, false).update();
|
||||||
baseMapper.lambdaUpdate().eq(StorageDO::getId, id).set(StorageDO::getIsDefault, true).update();
|
baseMapper.lambdaUpdate().eq(StorageDO::getId, id).set(StorageDO::getIsDefault, true).update();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user