Commit 28bba9776ce8d08f74ecd98b871f16a7bf85951d
1 parent
18fcc8fb
feat: 新增租户批量删除接口
Showing
6 changed files
with
102 additions
and
9 deletions
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/TenantController.java
| @@ -95,6 +95,15 @@ public class TenantController { | @@ -95,6 +95,15 @@ public class TenantController { | ||
| 95 | return success(true); | 95 | return success(true); |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | + @DeleteMapping("/delete-list") | ||
| 99 | + @Parameter(name = "ids", description = "编号列表", required = true) | ||
| 100 | + @Operation(summary = "批量删除租户") | ||
| 101 | + @PreAuthorize("@ss.hasPermission('system:tenant:delete')") | ||
| 102 | + public CommonResult<Boolean> deleteTenantList(@RequestParam("ids") List<Long> ids) { | ||
| 103 | + tenantService.deleteTenantList(ids); | ||
| 104 | + return success(true); | ||
| 105 | + } | ||
| 106 | + | ||
| 98 | @GetMapping("/get") | 107 | @GetMapping("/get") |
| 99 | @Operation(summary = "获得租户") | 108 | @Operation(summary = "获得租户") |
| 100 | @Parameter(name = "id", description = "编号", required = true, example = "1024") | 109 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/TenantPackageController.java
| @@ -4,18 +4,21 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | @@ -4,18 +4,21 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.*; | 7 | +import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackagePageReqVO; |
| 8 | +import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageRespVO; | ||
| 9 | +import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageSaveReqVO; | ||
| 10 | +import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageSimpleRespVO; | ||
| 8 | import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO; | 11 | import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO; |
| 9 | import cn.iocoder.yudao.module.system.service.tenant.TenantPackageService; | 12 | import cn.iocoder.yudao.module.system.service.tenant.TenantPackageService; |
| 10 | -import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 11 | -import io.swagger.v3.oas.annotations.Parameter; | ||
| 12 | import io.swagger.v3.oas.annotations.Operation; | 13 | import io.swagger.v3.oas.annotations.Operation; |
| 14 | +import io.swagger.v3.oas.annotations.Parameter; | ||
| 15 | +import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 16 | +import jakarta.annotation.Resource; | ||
| 17 | +import jakarta.validation.Valid; | ||
| 13 | import org.springframework.security.access.prepost.PreAuthorize; | 18 | import org.springframework.security.access.prepost.PreAuthorize; |
| 14 | import org.springframework.validation.annotation.Validated; | 19 | import org.springframework.validation.annotation.Validated; |
| 15 | import org.springframework.web.bind.annotation.*; | 20 | import org.springframework.web.bind.annotation.*; |
| 16 | 21 | ||
| 17 | -import jakarta.annotation.Resource; | ||
| 18 | -import jakarta.validation.Valid; | ||
| 19 | import java.util.List; | 22 | import java.util.List; |
| 20 | 23 | ||
| 21 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 24 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| @@ -53,6 +56,15 @@ public class TenantPackageController { | @@ -53,6 +56,15 @@ public class TenantPackageController { | ||
| 53 | return success(true); | 56 | return success(true); |
| 54 | } | 57 | } |
| 55 | 58 | ||
| 59 | + @DeleteMapping("/delete-list") | ||
| 60 | + @Parameter(name = "ids", description = "编号列表", required = true) | ||
| 61 | + @Operation(summary = "批量删除租户套餐") | ||
| 62 | + @PreAuthorize("@ss.hasPermission('system:tenant-package:delete')") | ||
| 63 | + public CommonResult<Boolean> deleteTenantPackageList(@RequestParam("ids") List<Long> ids) { | ||
| 64 | + tenantPackageService.deleteTenantPackageList(ids); | ||
| 65 | + return success(true); | ||
| 66 | + } | ||
| 67 | + | ||
| 56 | @GetMapping("/get") | 68 | @GetMapping("/get") |
| 57 | @Operation(summary = "获得租户套餐") | 69 | @Operation(summary = "获得租户套餐") |
| 58 | @Parameter(name = "id", description = "编号", required = true, example = "1024") | 70 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageService.java
| @@ -4,8 +4,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | @@ -4,8 +4,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackagePageReqVO; | 4 | import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackagePageReqVO; |
| 5 | import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageSaveReqVO; | 5 | import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageSaveReqVO; |
| 6 | import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO; | 6 | import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO; |
| 7 | - | ||
| 8 | import jakarta.validation.Valid; | 7 | import jakarta.validation.Valid; |
| 8 | + | ||
| 9 | import java.util.List; | 9 | import java.util.List; |
| 10 | 10 | ||
| 11 | /** | 11 | /** |
| @@ -38,6 +38,13 @@ public interface TenantPackageService { | @@ -38,6 +38,13 @@ public interface TenantPackageService { | ||
| 38 | void deleteTenantPackage(Long id); | 38 | void deleteTenantPackage(Long id); |
| 39 | 39 | ||
| 40 | /** | 40 | /** |
| 41 | + * 批量删除租户套餐 | ||
| 42 | + * | ||
| 43 | + * @param ids 编号数组 | ||
| 44 | + */ | ||
| 45 | + void deleteTenantPackageList(List<Long> ids); | ||
| 46 | + | ||
| 47 | + /** | ||
| 41 | * 获得租户套餐 | 48 | * 获得租户套餐 |
| 42 | * | 49 | * |
| 43 | * @param id 编号 | 50 | * @param id 编号 |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageServiceImpl.java
| @@ -12,11 +12,11 @@ import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO; | @@ -12,11 +12,11 @@ import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO; | ||
| 12 | import cn.iocoder.yudao.module.system.dal.mysql.tenant.TenantPackageMapper; | 12 | import cn.iocoder.yudao.module.system.dal.mysql.tenant.TenantPackageMapper; |
| 13 | import com.baomidou.dynamic.datasource.annotation.DSTransactional; | 13 | import com.baomidou.dynamic.datasource.annotation.DSTransactional; |
| 14 | import com.google.common.annotations.VisibleForTesting; | 14 | import com.google.common.annotations.VisibleForTesting; |
| 15 | +import jakarta.annotation.Resource; | ||
| 15 | import org.springframework.context.annotation.Lazy; | 16 | import org.springframework.context.annotation.Lazy; |
| 16 | import org.springframework.stereotype.Service; | 17 | import org.springframework.stereotype.Service; |
| 17 | import org.springframework.validation.annotation.Validated; | 18 | import org.springframework.validation.annotation.Validated; |
| 18 | 19 | ||
| 19 | -import jakarta.annotation.Resource; | ||
| 20 | import java.util.List; | 20 | import java.util.List; |
| 21 | 21 | ||
| 22 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 22 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| @@ -76,6 +76,19 @@ public class TenantPackageServiceImpl implements TenantPackageService { | @@ -76,6 +76,19 @@ public class TenantPackageServiceImpl implements TenantPackageService { | ||
| 76 | tenantPackageMapper.deleteById(id); | 76 | tenantPackageMapper.deleteById(id); |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | + @Override | ||
| 80 | + public void deleteTenantPackageList(List<Long> ids) { | ||
| 81 | + if (CollUtil.isEmpty(ids)) { | ||
| 82 | + return; | ||
| 83 | + } | ||
| 84 | + // 校验存在 | ||
| 85 | + ids.forEach(this::validateTenantPackageExists); | ||
| 86 | + // 校验正在使用 | ||
| 87 | + validateTenantUsedBatch(ids); | ||
| 88 | + // 批量删除 | ||
| 89 | + tenantPackageMapper.deleteByIds(ids); | ||
| 90 | + } | ||
| 91 | + | ||
| 79 | private TenantPackageDO validateTenantPackageExists(Long id) { | 92 | private TenantPackageDO validateTenantPackageExists(Long id) { |
| 80 | TenantPackageDO tenantPackage = tenantPackageMapper.selectById(id); | 93 | TenantPackageDO tenantPackage = tenantPackageMapper.selectById(id); |
| 81 | if (tenantPackage == null) { | 94 | if (tenantPackage == null) { |
| @@ -90,6 +103,20 @@ public class TenantPackageServiceImpl implements TenantPackageService { | @@ -90,6 +103,20 @@ public class TenantPackageServiceImpl implements TenantPackageService { | ||
| 90 | } | 103 | } |
| 91 | } | 104 | } |
| 92 | 105 | ||
| 106 | + /** | ||
| 107 | + * 校验租户套餐是否被使用 - 批量 | ||
| 108 | + * | ||
| 109 | + * @param ids 租户套餐编号数组 | ||
| 110 | + */ | ||
| 111 | + private void validateTenantUsedBatch(List<Long> ids) { | ||
| 112 | + // 查询是否有租户正在使用该套餐 | ||
| 113 | + for (Long id : ids) { | ||
| 114 | + if (tenantService.getTenantCountByPackageId(id) > 0) { | ||
| 115 | + throw exception(TENANT_PACKAGE_USED); | ||
| 116 | + } | ||
| 117 | + } | ||
| 118 | + } | ||
| 119 | + | ||
| 93 | @Override | 120 | @Override |
| 94 | public TenantPackageDO getTenantPackage(Long id) { | 121 | public TenantPackageDO getTenantPackage(Long id) { |
| 95 | return tenantPackageMapper.selectById(id); | 122 | return tenantPackageMapper.selectById(id); |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantService.java
| @@ -7,8 +7,8 @@ import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantSa | @@ -7,8 +7,8 @@ import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantSa | ||
| 7 | import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; | 7 | import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; |
| 8 | import cn.iocoder.yudao.module.system.service.tenant.handler.TenantInfoHandler; | 8 | import cn.iocoder.yudao.module.system.service.tenant.handler.TenantInfoHandler; |
| 9 | import cn.iocoder.yudao.module.system.service.tenant.handler.TenantMenuHandler; | 9 | import cn.iocoder.yudao.module.system.service.tenant.handler.TenantMenuHandler; |
| 10 | - | ||
| 11 | import jakarta.validation.Valid; | 10 | import jakarta.validation.Valid; |
| 11 | + | ||
| 12 | import java.util.List; | 12 | import java.util.List; |
| 13 | import java.util.Set; | 13 | import java.util.Set; |
| 14 | 14 | ||
| @@ -50,6 +50,13 @@ public interface TenantService { | @@ -50,6 +50,13 @@ public interface TenantService { | ||
| 50 | void deleteTenant(Long id); | 50 | void deleteTenant(Long id); |
| 51 | 51 | ||
| 52 | /** | 52 | /** |
| 53 | + * 批量删除租户 | ||
| 54 | + * | ||
| 55 | + * @param ids 编号数组 | ||
| 56 | + */ | ||
| 57 | + void deleteTenantList(List<Long> ids); | ||
| 58 | + | ||
| 59 | + /** | ||
| 53 | * 获得租户 | 60 | * 获得租户 |
| 54 | * | 61 | * |
| 55 | * @param id 编号 | 62 | * @param id 编号 |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java
| @@ -31,13 +31,13 @@ import cn.iocoder.yudao.module.system.service.tenant.handler.TenantInfoHandler; | @@ -31,13 +31,13 @@ import cn.iocoder.yudao.module.system.service.tenant.handler.TenantInfoHandler; | ||
| 31 | import cn.iocoder.yudao.module.system.service.tenant.handler.TenantMenuHandler; | 31 | import cn.iocoder.yudao.module.system.service.tenant.handler.TenantMenuHandler; |
| 32 | import cn.iocoder.yudao.module.system.service.user.AdminUserService; | 32 | import cn.iocoder.yudao.module.system.service.user.AdminUserService; |
| 33 | import com.baomidou.dynamic.datasource.annotation.DSTransactional; | 33 | import com.baomidou.dynamic.datasource.annotation.DSTransactional; |
| 34 | +import jakarta.annotation.Resource; | ||
| 34 | import lombok.extern.slf4j.Slf4j; | 35 | import lombok.extern.slf4j.Slf4j; |
| 35 | import org.springframework.beans.factory.annotation.Autowired; | 36 | import org.springframework.beans.factory.annotation.Autowired; |
| 36 | import org.springframework.context.annotation.Lazy; | 37 | import org.springframework.context.annotation.Lazy; |
| 37 | import org.springframework.stereotype.Service; | 38 | import org.springframework.stereotype.Service; |
| 38 | import org.springframework.validation.annotation.Validated; | 39 | import org.springframework.validation.annotation.Validated; |
| 39 | 40 | ||
| 40 | -import jakarta.annotation.Resource; | ||
| 41 | import java.util.List; | 41 | import java.util.List; |
| 42 | import java.util.Objects; | 42 | import java.util.Objects; |
| 43 | import java.util.Set; | 43 | import java.util.Set; |
| @@ -225,6 +225,17 @@ public class TenantServiceImpl implements TenantService { | @@ -225,6 +225,17 @@ public class TenantServiceImpl implements TenantService { | ||
| 225 | tenantMapper.deleteById(id); | 225 | tenantMapper.deleteById(id); |
| 226 | } | 226 | } |
| 227 | 227 | ||
| 228 | + @Override | ||
| 229 | + public void deleteTenantList(List<Long> ids) { | ||
| 230 | + if (CollUtil.isEmpty(ids)) { | ||
| 231 | + return; | ||
| 232 | + } | ||
| 233 | + // 校验存在 | ||
| 234 | + validateUpdateTenantBatch(ids); | ||
| 235 | + // 批量删除 | ||
| 236 | + tenantMapper.deleteByIds(ids); | ||
| 237 | + } | ||
| 238 | + | ||
| 228 | private TenantDO validateUpdateTenant(Long id) { | 239 | private TenantDO validateUpdateTenant(Long id) { |
| 229 | TenantDO tenant = tenantMapper.selectById(id); | 240 | TenantDO tenant = tenantMapper.selectById(id); |
| 230 | if (tenant == null) { | 241 | if (tenant == null) { |
| @@ -237,6 +248,26 @@ public class TenantServiceImpl implements TenantService { | @@ -237,6 +248,26 @@ public class TenantServiceImpl implements TenantService { | ||
| 237 | return tenant; | 248 | return tenant; |
| 238 | } | 249 | } |
| 239 | 250 | ||
| 251 | + /** | ||
| 252 | + * 校验租户是否可以更新 - 批量 | ||
| 253 | + * | ||
| 254 | + * @param ids 租户编号数组 | ||
| 255 | + */ | ||
| 256 | + private void validateUpdateTenantBatch(List<Long> ids) { | ||
| 257 | + // 查询租户 | ||
| 258 | + List<TenantDO> tenants = tenantMapper.selectByIds(ids); | ||
| 259 | + if (tenants.size() != ids.size()) { | ||
| 260 | + throw exception(TENANT_NOT_EXISTS); | ||
| 261 | + } | ||
| 262 | + | ||
| 263 | + // 校验是否有系统内置租户 | ||
| 264 | + tenants.forEach(tenant -> { | ||
| 265 | + if (isSystemTenant(tenant)) { | ||
| 266 | + throw exception(TENANT_CAN_NOT_UPDATE_SYSTEM); | ||
| 267 | + } | ||
| 268 | + }); | ||
| 269 | + } | ||
| 270 | + | ||
| 240 | @Override | 271 | @Override |
| 241 | public TenantDO getTenant(Long id) { | 272 | public TenantDO getTenant(Long id) { |
| 242 | return tenantMapper.selectById(id); | 273 | return tenantMapper.selectById(id); |