feat: 新增租户批量删除接口
This commit is contained in:
parent
18fcc8fbc5
commit
28bba9776c
|
@ -95,6 +95,15 @@ public class TenantController {
|
|||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号列表", required = true)
|
||||
@Operation(summary = "批量删除租户")
|
||||
@PreAuthorize("@ss.hasPermission('system:tenant:delete')")
|
||||
public CommonResult<Boolean> deleteTenantList(@RequestParam("ids") List<Long> ids) {
|
||||
tenantService.deleteTenantList(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得租户")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
|
|
|
@ -4,18 +4,21 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
|||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.*;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackagePageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageRespVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageSimpleRespVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO;
|
||||
import cn.iocoder.yudao.module.system.service.tenant.TenantPackageService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
@ -53,6 +56,15 @@ public class TenantPackageController {
|
|||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号列表", required = true)
|
||||
@Operation(summary = "批量删除租户套餐")
|
||||
@PreAuthorize("@ss.hasPermission('system:tenant-package:delete')")
|
||||
public CommonResult<Boolean> deleteTenantPackageList(@RequestParam("ids") List<Long> ids) {
|
||||
tenantPackageService.deleteTenantPackageList(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得租户套餐")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
|
|
|
@ -4,8 +4,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|||
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackagePageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -37,6 +37,13 @@ public interface TenantPackageService {
|
|||
*/
|
||||
void deleteTenantPackage(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除租户套餐
|
||||
*
|
||||
* @param ids 编号数组
|
||||
*/
|
||||
void deleteTenantPackageList(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得租户套餐
|
||||
*
|
||||
|
|
|
@ -12,11 +12,11 @@ import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO;
|
|||
import cn.iocoder.yudao.module.system.dal.mysql.tenant.TenantPackageMapper;
|
||||
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
@ -76,6 +76,19 @@ public class TenantPackageServiceImpl implements TenantPackageService {
|
|||
tenantPackageMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTenantPackageList(List<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
// 校验存在
|
||||
ids.forEach(this::validateTenantPackageExists);
|
||||
// 校验正在使用
|
||||
validateTenantUsedBatch(ids);
|
||||
// 批量删除
|
||||
tenantPackageMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
private TenantPackageDO validateTenantPackageExists(Long id) {
|
||||
TenantPackageDO tenantPackage = tenantPackageMapper.selectById(id);
|
||||
if (tenantPackage == null) {
|
||||
|
@ -90,6 +103,20 @@ public class TenantPackageServiceImpl implements TenantPackageService {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验租户套餐是否被使用 - 批量
|
||||
*
|
||||
* @param ids 租户套餐编号数组
|
||||
*/
|
||||
private void validateTenantUsedBatch(List<Long> ids) {
|
||||
// 查询是否有租户正在使用该套餐
|
||||
for (Long id : ids) {
|
||||
if (tenantService.getTenantCountByPackageId(id) > 0) {
|
||||
throw exception(TENANT_PACKAGE_USED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TenantPackageDO getTenantPackage(Long id) {
|
||||
return tenantPackageMapper.selectById(id);
|
||||
|
|
|
@ -7,8 +7,8 @@ import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantSa
|
|||
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO;
|
||||
import cn.iocoder.yudao.module.system.service.tenant.handler.TenantInfoHandler;
|
||||
import cn.iocoder.yudao.module.system.service.tenant.handler.TenantMenuHandler;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -49,6 +49,13 @@ public interface TenantService {
|
|||
*/
|
||||
void deleteTenant(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除租户
|
||||
*
|
||||
* @param ids 编号数组
|
||||
*/
|
||||
void deleteTenantList(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得租户
|
||||
*
|
||||
|
|
|
@ -31,13 +31,13 @@ import cn.iocoder.yudao.module.system.service.tenant.handler.TenantInfoHandler;
|
|||
import cn.iocoder.yudao.module.system.service.tenant.handler.TenantMenuHandler;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
@ -225,6 +225,17 @@ public class TenantServiceImpl implements TenantService {
|
|||
tenantMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTenantList(List<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
// 校验存在
|
||||
validateUpdateTenantBatch(ids);
|
||||
// 批量删除
|
||||
tenantMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
private TenantDO validateUpdateTenant(Long id) {
|
||||
TenantDO tenant = tenantMapper.selectById(id);
|
||||
if (tenant == null) {
|
||||
|
@ -237,6 +248,26 @@ public class TenantServiceImpl implements TenantService {
|
|||
return tenant;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验租户是否可以更新 - 批量
|
||||
*
|
||||
* @param ids 租户编号数组
|
||||
*/
|
||||
private void validateUpdateTenantBatch(List<Long> ids) {
|
||||
// 查询租户
|
||||
List<TenantDO> tenants = tenantMapper.selectByIds(ids);
|
||||
if (tenants.size() != ids.size()) {
|
||||
throw exception(TENANT_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 校验是否有系统内置租户
|
||||
tenants.forEach(tenant -> {
|
||||
if (isSystemTenant(tenant)) {
|
||||
throw exception(TENANT_CAN_NOT_UPDATE_SYSTEM);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public TenantDO getTenant(Long id) {
|
||||
return tenantMapper.selectById(id);
|
||||
|
|
Loading…
Reference in New Issue