mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-20 18:15:56 +08:00
update 优化 添加用户 增加租户账号数量校验
This commit is contained in:
parent
3f24337b4b
commit
cc4a6b59fa
@ -0,0 +1,41 @@
|
||||
package com.ruoyi.common.core.constant;
|
||||
|
||||
/**
|
||||
* 租户常量信息
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
public interface TenantConstants {
|
||||
|
||||
/**
|
||||
* 租户正常状态
|
||||
*/
|
||||
String NORMAL = "0";
|
||||
|
||||
/**
|
||||
* 租户封禁状态
|
||||
*/
|
||||
String DISABLE = "1";
|
||||
|
||||
/**
|
||||
* 校验返回结果码
|
||||
*/
|
||||
String PASS = "0";
|
||||
String NOT_PASS = "1";
|
||||
|
||||
/**
|
||||
* 超级管理员ID
|
||||
*/
|
||||
Long SUPER_ADMIN_ID = 1L;
|
||||
|
||||
/**
|
||||
* 管理员角色 roleKey
|
||||
*/
|
||||
String ADMIN_ROLE_KEY = "admin";
|
||||
|
||||
/**
|
||||
* 管理员角色名称
|
||||
*/
|
||||
String ADMIN_ROLE_NAME = "管理员";
|
||||
|
||||
}
|
||||
@ -130,24 +130,4 @@ public interface UserConstants {
|
||||
int PASSWORD_MIN_LENGTH = 5;
|
||||
int PASSWORD_MAX_LENGTH = 20;
|
||||
|
||||
/**
|
||||
* 超级管理员ID
|
||||
*/
|
||||
Long SUPER_ADMIN_ID = 1L;
|
||||
|
||||
/**
|
||||
* 管理员角色 roleKey
|
||||
*/
|
||||
String ADMIN_ROLE_KEY = "admin";
|
||||
|
||||
/**
|
||||
* 管理员角色名称
|
||||
*/
|
||||
String ADMIN_ROLE_NAME = "管理员";
|
||||
|
||||
/**
|
||||
* 管理员角色排序
|
||||
*/
|
||||
Integer ADMIN_ROLE_SORT = 5;
|
||||
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.ruoyi.common.core.constant.TenantConstants;
|
||||
import com.ruoyi.common.core.constant.UserConstants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.utils.StreamUtils;
|
||||
@ -16,16 +17,14 @@ import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.log.enums.BusinessType;
|
||||
import com.ruoyi.common.mybatis.core.page.PageQuery;
|
||||
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.mybatis.helper.TenantHelper;
|
||||
import com.ruoyi.common.satoken.utils.LoginHelper;
|
||||
import com.ruoyi.common.web.core.BaseController;
|
||||
import com.ruoyi.system.domain.SysDept;
|
||||
import com.ruoyi.system.domain.bo.SysUserBo;
|
||||
import com.ruoyi.system.domain.vo.*;
|
||||
import com.ruoyi.system.listener.SysUserImportListener;
|
||||
import com.ruoyi.system.service.ISysDeptService;
|
||||
import com.ruoyi.system.service.ISysPostService;
|
||||
import com.ruoyi.system.service.ISysRoleService;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import com.ruoyi.system.service.*;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.MediaType;
|
||||
@ -51,6 +50,7 @@ public class SysUserController extends BaseController {
|
||||
private final ISysRoleService roleService;
|
||||
private final ISysPostService postService;
|
||||
private final ISysDeptService deptService;
|
||||
private final ISysTenantService tenantService;
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
@ -141,6 +141,12 @@ public class SysUserController extends BaseController {
|
||||
&& UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) {
|
||||
return R.fail("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
||||
}
|
||||
if (TenantHelper.isEnable()) {
|
||||
String status = tenantService.checkAccountBalance(LoginHelper.getTenantId());
|
||||
if (TenantConstants.NOT_PASS.equals(status)) {
|
||||
return R.fail("当前租户下用户名额不足,请联系管理员");
|
||||
}
|
||||
}
|
||||
user.setPassword(BCrypt.hashpw(user.getPassword()));
|
||||
return toAjax(userService.insertUser(user));
|
||||
}
|
||||
|
||||
@ -54,4 +54,14 @@ public interface ISysTenantService {
|
||||
* 校验并批量删除租户信息
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
/**
|
||||
* 校验账号余额
|
||||
*/
|
||||
String checkAccountBalance(String tenantId);
|
||||
|
||||
/**
|
||||
* 校验有效期
|
||||
*/
|
||||
String checkExpireTime(String tenantId);
|
||||
}
|
||||
|
||||
@ -10,8 +10,9 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ruoyi.common.core.constant.CacheNames;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
import com.ruoyi.common.core.constant.UserConstants;
|
||||
import com.ruoyi.common.core.constant.TenantConstants;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.core.utils.SpringUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.mybatis.core.page.PageQuery;
|
||||
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
|
||||
@ -28,6 +29,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -190,10 +192,10 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
||||
// 创建角色
|
||||
SysRole role = new SysRole();
|
||||
role.setTenantId(tenantId);
|
||||
role.setRoleName(UserConstants.ADMIN_ROLE_NAME);
|
||||
role.setRoleKey(UserConstants.ADMIN_ROLE_KEY);
|
||||
role.setRoleSort(UserConstants.ADMIN_ROLE_SORT);
|
||||
role.setStatus(UserConstants.NORMAL);
|
||||
role.setRoleName(TenantConstants.ADMIN_ROLE_NAME);
|
||||
role.setRoleKey(TenantConstants.ADMIN_ROLE_KEY);
|
||||
role.setRoleSort(1);
|
||||
role.setStatus(TenantConstants.NORMAL);
|
||||
sysRoleMapper.insert(role);
|
||||
Long roleId = role.getRoleId();
|
||||
|
||||
@ -246,4 +248,40 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验账号余额
|
||||
*/
|
||||
@Override
|
||||
public String checkAccountBalance(String tenantId) {
|
||||
SysTenantVo tenant = SpringUtils.getAopProxy(this).queryByTenantId(tenantId);
|
||||
// 如果余额为-1代表不限制
|
||||
if (tenant.getAccountCount() == -1) {
|
||||
return TenantConstants.PASS;
|
||||
}
|
||||
Long userNumber = sysUserMapper.selectCount(new LambdaQueryWrapper<>());
|
||||
// 如果余额大于0代表还有可用名额
|
||||
if (tenant.getAccountCount() - userNumber > 0) {
|
||||
return TenantConstants.PASS;
|
||||
}
|
||||
return TenantConstants.NOT_PASS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验有效期
|
||||
*/
|
||||
@Override
|
||||
public String checkExpireTime(String tenantId) {
|
||||
SysTenantVo tenant = SpringUtils.getAopProxy(this).queryByTenantId(tenantId);
|
||||
// 如果未设置过期时间代表不限制
|
||||
if (ObjectUtil.isNull(tenant.getExpireTime())) {
|
||||
return TenantConstants.PASS;
|
||||
}
|
||||
// 如果当前时间在过期时间之前则通过
|
||||
if (new Date().before(tenant.getExpireTime())) {
|
||||
return TenantConstants.PASS;
|
||||
}
|
||||
return TenantConstants.NOT_PASS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user