feat(system): 完善租户创建权限控制
- 在 TenantType 枚举中添加 SUPERADMIN 类型 - 实现 allowCreateByType 方法控制租户创建权限- 调整 SysTenantController 中的权限注解 -优化 SysTenantServiceImpl 中的租户创建逻辑
This commit is contained in:
parent
bf728cee9b
commit
2dd6ac0631
@ -14,9 +14,23 @@ public enum TenantType {
|
||||
|
||||
PROXY(1, "代理"),
|
||||
|
||||
REFERENCE(2, "达人");
|
||||
REFERENCE(2, "达人"),
|
||||
|
||||
private final int status;
|
||||
SUPERADMIN(3, "平台");
|
||||
|
||||
private final int type;
|
||||
|
||||
private final String desc;
|
||||
|
||||
public static boolean allowCreateByType(Integer currentTenantType, Integer newTenantType) {
|
||||
boolean allow = false;
|
||||
if(currentTenantType == SUPERADMIN.type){
|
||||
// 超级管理租户创建租户没有限制
|
||||
allow = true;
|
||||
} else if (currentTenantType == TenantType.PROXY.type ){
|
||||
// 代理商只能创建商铺或达人
|
||||
allow = newTenantType == TenantType.SHOP.type || newTenantType == TenantType.REFERENCE.type;
|
||||
}
|
||||
return allow;
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ public class SysMenuController extends BaseController {
|
||||
/**
|
||||
* 获取菜单下拉树列表
|
||||
*/
|
||||
@SaCheckPermission("system:menu:query")
|
||||
@SaCheckPermission(value = "system:menu:query", orRole = TenantConstants.TENANT_ADMIN_ROLE_KEY)
|
||||
@GetMapping("/treeselect")
|
||||
public R<List<Tree<Long>>> treeselect(SysMenuBo menu) {
|
||||
List<SysMenuVo> menus = menuService.selectMenuList(menu, LoginHelper.getUserId());
|
||||
@ -92,7 +92,7 @@ public class SysMenuController extends BaseController {
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
*/
|
||||
@SaCheckPermission("system:menu:query")
|
||||
@SaCheckPermission(value = "system:menu:query", orRole = TenantConstants.TENANT_ADMIN_ROLE_KEY)
|
||||
@GetMapping(value = "/roleMenuTreeselect/{roleId}")
|
||||
public R<MenuTreeSelectVo> roleMenuTreeselect(@PathVariable("roleId") Long roleId) {
|
||||
List<SysMenuVo> menus = menuService.selectMenuList(LoginHelper.getUserId());
|
||||
|
@ -92,7 +92,7 @@ public class SysTenantController extends BaseController {
|
||||
/**
|
||||
* 新增租户
|
||||
*/
|
||||
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
// @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
@SaCheckPermission("system:tenant:add")
|
||||
@Log(title = "租户管理", businessType = BusinessType.INSERT)
|
||||
@Lock4j
|
||||
@ -108,7 +108,7 @@ public class SysTenantController extends BaseController {
|
||||
/**
|
||||
* 修改租户
|
||||
*/
|
||||
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
// @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
@SaCheckPermission("system:tenant:edit")
|
||||
@Log(title = "租户管理", businessType = BusinessType.UPDATE)
|
||||
@RepeatSubmit()
|
||||
@ -124,7 +124,7 @@ public class SysTenantController extends BaseController {
|
||||
/**
|
||||
* 状态修改
|
||||
*/
|
||||
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
// @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
@SaCheckPermission("system:tenant:edit")
|
||||
@Log(title = "租户管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/changeStatus")
|
||||
@ -179,7 +179,7 @@ public class SysTenantController extends BaseController {
|
||||
*/
|
||||
@Tag(name = "删除租户表")
|
||||
@Log(title = "租户表", businessType = BusinessType.DELETE)
|
||||
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
@SaCheckRole(value = {TenantConstants.SUPER_ADMIN_ROLE_KEY, TenantConstants.TENANT_ADMIN_ROLE_KEY})
|
||||
@SaCheckPermission("system:tenant:remove")
|
||||
@DeleteMapping("/remove")
|
||||
public R batchRemove(@RequestParam("ids") String ids) {
|
||||
@ -196,7 +196,7 @@ public class SysTenantController extends BaseController {
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
*/
|
||||
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
// @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
@GetMapping("/dynamic/{tenantId}")
|
||||
public R<Void> dynamicTenant(@NotBlank(message = "租户ID不能为空") @PathVariable String tenantId) {
|
||||
TenantHelper.setDynamic(tenantId, true);
|
||||
@ -206,7 +206,7 @@ public class SysTenantController extends BaseController {
|
||||
/**
|
||||
* 清除动态租户
|
||||
*/
|
||||
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
// @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
@GetMapping("/dynamic/clear")
|
||||
public R<Void> dynamicClear() {
|
||||
TenantHelper.clearDynamic();
|
||||
@ -220,7 +220,7 @@ public class SysTenantController extends BaseController {
|
||||
* @param tenantId 租户id
|
||||
* @param packageId 套餐id
|
||||
*/
|
||||
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
// @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
@SaCheckPermission("system:tenant:edit")
|
||||
@Log(title = "租户管理", businessType = BusinessType.UPDATE)
|
||||
@GetMapping("/syncTenantPackage")
|
||||
@ -232,7 +232,7 @@ public class SysTenantController extends BaseController {
|
||||
/**
|
||||
* 同步租户字典
|
||||
*/
|
||||
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
// @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
@Log(title = "租户管理", businessType = BusinessType.INSERT)
|
||||
@GetMapping("/syncTenantDict")
|
||||
public R<Void> syncTenantDict() {
|
||||
|
@ -43,8 +43,8 @@ public class SysTenantPackageController extends BaseController {
|
||||
/**
|
||||
* 查询租户套餐列表
|
||||
*/
|
||||
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
@SaCheckPermission("system:tenantPackage:list")
|
||||
// @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
// @SaCheckPermission("system:tenantPackage:list")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<SysTenantPackageVo> list(SysTenantPackageBo bo, PageQuery pageQuery) {
|
||||
return tenantPackageService.queryPageList(bo, pageQuery);
|
||||
@ -53,8 +53,8 @@ public class SysTenantPackageController extends BaseController {
|
||||
/**
|
||||
* 查询租户套餐下拉选列表
|
||||
*/
|
||||
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
@SaCheckPermission("system:tenantPackage:list")
|
||||
// @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
// @SaCheckPermission("system:tenantPackage:list")
|
||||
@GetMapping("/selectList")
|
||||
public R<List<SysTenantPackageVo>> selectList() {
|
||||
return R.ok(tenantPackageService.selectList());
|
||||
@ -63,8 +63,8 @@ public class SysTenantPackageController extends BaseController {
|
||||
/**
|
||||
* 导出租户套餐列表
|
||||
*/
|
||||
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
@SaCheckPermission("system:tenantPackage:export")
|
||||
// @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
// @SaCheckPermission("system:tenantPackage:export")
|
||||
@Log(title = "租户套餐", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(SysTenantPackageBo bo, HttpServletResponse response) {
|
||||
@ -77,8 +77,8 @@ public class SysTenantPackageController extends BaseController {
|
||||
*
|
||||
* @param packageId 主键
|
||||
*/
|
||||
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
@SaCheckPermission("system:tenantPackage:query")
|
||||
// @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||
// @SaCheckPermission("system:tenantPackage:query")
|
||||
@GetMapping("/{packageId}")
|
||||
public R<SysTenantPackageVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long packageId) {
|
||||
|
@ -3,6 +3,7 @@ package org.dromara.system.domain.bo;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@ -159,6 +160,7 @@ public class SysTenantExtendBo {
|
||||
private String qualification;
|
||||
|
||||
@Schema(description = "类型(0.店铺 1.代理 2.推广人)")
|
||||
@NotNull(message = "租户类型不能为空")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "推广人姓名")
|
||||
|
@ -3,6 +3,8 @@ package org.dromara.system.mapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import org.dromara.common.mybatis.annotation.DataColumn;
|
||||
import org.dromara.common.mybatis.annotation.DataPermission;
|
||||
import org.dromara.system.domain.SysTenant;
|
||||
import org.dromara.system.domain.bo.SysTenantBo;
|
||||
import org.dromara.system.domain.bo.SysTenantExtendBo;
|
||||
@ -44,6 +46,10 @@ public interface SysTenantMapper extends BaseMapperPlus<SysTenant, SysTenantVo>
|
||||
"LIMIT 20")
|
||||
List<Map<String, Object>> getTop20Stores();
|
||||
|
||||
@DataPermission({
|
||||
@DataColumn(key = "deptName", value = "t.create_dept"),
|
||||
@DataColumn(key = "userName", value = "t.create_by")
|
||||
})
|
||||
IPage<TenantDTO> getlist(@Param("page") Page<SysTenant> page,@Param("query") SysTenantExtendBo query);
|
||||
|
||||
@Select(" SELECT\n" +
|
||||
|
@ -19,6 +19,7 @@ import org.dromara.common.core.constant.Constants;
|
||||
import org.dromara.common.core.constant.SystemConstants;
|
||||
import org.dromara.common.core.constant.TenantConstants;
|
||||
import org.dromara.common.core.enums.TenantSignStatus;
|
||||
import org.dromara.common.core.enums.TenantType;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.service.WorkflowService;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
@ -131,39 +132,13 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean insertByBo(SysTenantExtendBo bo) {
|
||||
|
||||
if (bo.getType() == null){
|
||||
throw new ServiceException("租户类型不能为空");
|
||||
}
|
||||
|
||||
// 处理sys_tenant表数据
|
||||
SysTenant tenant = new SysTenant();
|
||||
|
||||
String currentTenantId = LoginHelper.getTenantId();
|
||||
|
||||
if (bo.getExpiryDate() != null) {
|
||||
SysTenant sysTenant = baseMapper.selectByTenantId(currentTenantId);
|
||||
if (sysTenant != null) {
|
||||
Integer type = sysTenant.getType();
|
||||
if (type != 1 && type != 3) {
|
||||
throw new RuntimeException("只有代理能添加推广人");
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("未查询到对应的租户信息");
|
||||
}
|
||||
}
|
||||
|
||||
if (bo.getStoreName() != null) {
|
||||
SysTenant sysTenant = baseMapper.selectByTenantId(currentTenantId);
|
||||
if (sysTenant != null) {
|
||||
Integer type = sysTenant.getType();
|
||||
if (type != 2 && type != 3) {
|
||||
throw new RuntimeException("只有推广人能添加店铺");
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("未查询到对应的租户信息");
|
||||
}
|
||||
}
|
||||
|
||||
Assert.isTrue(TenantType.allowCreateByType(sysTenant.getType(), bo.getType()), () -> new ServiceException("您无权限创建此类型的租户"));
|
||||
|
||||
// 生成租户ID
|
||||
List<String> tenantIds = baseMapper.selectObjs(
|
||||
@ -199,10 +174,10 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
||||
tenant.setBirthday(bo.getBirthday());
|
||||
tenant.setQualification(bo.getQualification());
|
||||
tenant.setType(bo.getType());
|
||||
if (bo.getType() == 2){
|
||||
if (bo.getType() == TenantType.REFERENCE.getType()){
|
||||
tenant.setAgencyTenantId(currentTenantId);
|
||||
}
|
||||
if (bo.getType() == 0){
|
||||
if (bo.getType() == TenantType.SHOP.getType()){
|
||||
tenant.setPromoterTenantId(currentTenantId);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user