mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-21 02:25:56 +08:00
update 优化 租户业务逻辑
This commit is contained in:
parent
6b8fbfcb54
commit
21ed566b4d
@ -1,27 +1,32 @@
|
|||||||
package com.ruoyi.system.controller.system;
|
package com.ruoyi.system.controller.system;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.baomidou.lock.annotation.Lock4j;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
import jakarta.validation.constraints.*;
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import com.baomidou.lock.annotation.Lock4j;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import com.ruoyi.common.core.constant.UserConstants;
|
||||||
import com.ruoyi.common.idempotent.annotation.RepeatSubmit;
|
|
||||||
import com.ruoyi.common.log.annotation.Log;
|
|
||||||
import com.ruoyi.common.web.core.BaseController;
|
|
||||||
import com.ruoyi.common.mybatis.core.page.PageQuery;
|
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.core.exception.ServiceException;
|
||||||
import com.ruoyi.common.core.validate.AddGroup;
|
import com.ruoyi.common.core.validate.AddGroup;
|
||||||
import com.ruoyi.common.core.validate.EditGroup;
|
import com.ruoyi.common.core.validate.EditGroup;
|
||||||
import com.ruoyi.common.log.enums.BusinessType;
|
|
||||||
import com.ruoyi.common.excel.utils.ExcelUtil;
|
import com.ruoyi.common.excel.utils.ExcelUtil;
|
||||||
import com.ruoyi.system.domain.vo.SysTenantVo;
|
import com.ruoyi.common.idempotent.annotation.RepeatSubmit;
|
||||||
import com.ruoyi.system.domain.bo.SysTenantBo;
|
import com.ruoyi.common.log.annotation.Log;
|
||||||
import com.ruoyi.system.service.ISysTenantService;
|
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.core.page.TableDataInfo;
|
||||||
|
import com.ruoyi.common.web.core.BaseController;
|
||||||
|
import com.ruoyi.system.domain.bo.SysTenantBo;
|
||||||
|
import com.ruoyi.system.domain.bo.SysUserBo;
|
||||||
|
import com.ruoyi.system.domain.vo.SysTenantVo;
|
||||||
|
import com.ruoyi.system.service.ISysTenantService;
|
||||||
|
import com.ruoyi.system.service.ISysUserService;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 租户管理
|
* 租户管理
|
||||||
@ -35,6 +40,7 @@ import com.ruoyi.common.mybatis.core.page.TableDataInfo;
|
|||||||
public class SysTenantController extends BaseController {
|
public class SysTenantController extends BaseController {
|
||||||
|
|
||||||
private final ISysTenantService iSysTenantService;
|
private final ISysTenantService iSysTenantService;
|
||||||
|
private final ISysUserService sysUserService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询租户列表
|
* 查询租户列表
|
||||||
@ -77,6 +83,12 @@ public class SysTenantController extends BaseController {
|
|||||||
@RepeatSubmit()
|
@RepeatSubmit()
|
||||||
@PostMapping()
|
@PostMapping()
|
||||||
public R<Void> add(@Validated(AddGroup.class) @RequestBody SysTenantBo bo) {
|
public R<Void> add(@Validated(AddGroup.class) @RequestBody SysTenantBo bo) {
|
||||||
|
SysUserBo userBo = new SysUserBo();
|
||||||
|
userBo.setUserName(bo.getUsername());
|
||||||
|
// 判断用户名是否重复
|
||||||
|
if (UserConstants.NOT_UNIQUE.equals(sysUserService.checkUserNameUnique(userBo))) {
|
||||||
|
throw new ServiceException("新增用户'" + bo.getUsername() + "'失败,登录账号已存在");
|
||||||
|
}
|
||||||
return toAjax(iSysTenantService.insertByBo(bo));
|
return toAjax(iSysTenantService.insertByBo(bo));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,15 @@
|
|||||||
package com.ruoyi.system.domain;
|
package com.ruoyi.system.domain;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.ruoyi.common.mybatis.core.domain.BaseEntity;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import com.ruoyi.common.mybatis.core.domain.BaseEntity;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 租户对象 sys_tenant
|
* 租户对象 sys_tenant
|
||||||
*
|
*
|
||||||
@ -26,54 +28,67 @@ public class SysTenant extends BaseEntity {
|
|||||||
*/
|
*/
|
||||||
@TableId(value = "id")
|
@TableId(value = "id")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 租户编号
|
* 租户编号
|
||||||
*/
|
*/
|
||||||
private String tenantId;
|
private String tenantId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 联系人
|
* 联系人
|
||||||
*/
|
*/
|
||||||
private String contactUserName;
|
private String contactUserName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 联系电话
|
* 联系电话
|
||||||
*/
|
*/
|
||||||
private String contactPhone;
|
private String contactPhone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 企业名称
|
* 企业名称
|
||||||
*/
|
*/
|
||||||
private String companyName;
|
private String companyName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统一社会信用代码
|
* 统一社会信用代码
|
||||||
*/
|
*/
|
||||||
private String licenseNumber;
|
private String licenseNumber;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 地址
|
* 地址
|
||||||
*/
|
*/
|
||||||
private String address;
|
private String address;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 企业简介
|
* 企业简介
|
||||||
*/
|
*/
|
||||||
private String intro;
|
private String intro;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 备注
|
* 备注
|
||||||
*/
|
*/
|
||||||
private String remark;
|
private String remark;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 租户套餐编号
|
* 租户套餐编号
|
||||||
*/
|
*/
|
||||||
private Long packageId;
|
private Long packageId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 过期时间
|
* 过期时间
|
||||||
*/
|
*/
|
||||||
private Date expireTime;
|
private Date expireTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户数量(-1不限制)
|
* 用户数量(-1不限制)
|
||||||
*/
|
*/
|
||||||
private Long accountCount;
|
private Long accountCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 租户状态(0正常 1停用)
|
* 租户状态(0正常 1停用)
|
||||||
*/
|
*/
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除标志(0代表存在 2代表删除)
|
* 删除标志(0代表存在 2代表删除)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -2,12 +2,15 @@ package com.ruoyi.system.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import com.ruoyi.common.core.exception.ServiceException;
|
||||||
import com.ruoyi.common.core.utils.StringUtils;
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
|
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
|
||||||
import com.ruoyi.common.mybatis.core.page.PageQuery;
|
import com.ruoyi.common.mybatis.core.page.PageQuery;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.ruoyi.system.domain.SysTenant;
|
||||||
|
import com.ruoyi.system.mapper.SysTenantMapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.ruoyi.system.domain.bo.SysTenantPackageBo;
|
import com.ruoyi.system.domain.bo.SysTenantPackageBo;
|
||||||
@ -32,6 +35,7 @@ import java.util.Collection;
|
|||||||
public class SysTenantPackageServiceImpl implements ISysTenantPackageService {
|
public class SysTenantPackageServiceImpl implements ISysTenantPackageService {
|
||||||
|
|
||||||
private final SysTenantPackageMapper baseMapper;
|
private final SysTenantPackageMapper baseMapper;
|
||||||
|
private final SysTenantMapper tenantMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询租户套餐
|
* 查询租户套餐
|
||||||
@ -75,7 +79,6 @@ public class SysTenantPackageServiceImpl implements ISysTenantPackageService {
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Boolean insertByBo(SysTenantPackageBo bo) {
|
public Boolean insertByBo(SysTenantPackageBo bo) {
|
||||||
SysTenantPackage add = BeanUtil.toBean(bo, SysTenantPackage.class);
|
SysTenantPackage add = BeanUtil.toBean(bo, SysTenantPackage.class);
|
||||||
validEntityBeforeSave(add);
|
|
||||||
// 保存菜单id
|
// 保存菜单id
|
||||||
List<Long> menuIds = Arrays.asList(bo.getMenuIds());
|
List<Long> menuIds = Arrays.asList(bo.getMenuIds());
|
||||||
if (CollUtil.isNotEmpty(menuIds)) {
|
if (CollUtil.isNotEmpty(menuIds)) {
|
||||||
@ -97,7 +100,6 @@ public class SysTenantPackageServiceImpl implements ISysTenantPackageService {
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Boolean updateByBo(SysTenantPackageBo bo) {
|
public Boolean updateByBo(SysTenantPackageBo bo) {
|
||||||
SysTenantPackage update = BeanUtil.toBean(bo, SysTenantPackage.class);
|
SysTenantPackage update = BeanUtil.toBean(bo, SysTenantPackage.class);
|
||||||
validEntityBeforeSave(update);
|
|
||||||
// 保存菜单id
|
// 保存菜单id
|
||||||
List<Long> menuIds = Arrays.asList(bo.getMenuIds());
|
List<Long> menuIds = Arrays.asList(bo.getMenuIds());
|
||||||
if (CollUtil.isNotEmpty(menuIds)) {
|
if (CollUtil.isNotEmpty(menuIds)) {
|
||||||
@ -120,13 +122,6 @@ public class SysTenantPackageServiceImpl implements ISysTenantPackageService {
|
|||||||
return baseMapper.updateById(tenantPackage);
|
return baseMapper.updateById(tenantPackage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 保存前的数据校验
|
|
||||||
*/
|
|
||||||
private void validEntityBeforeSave(SysTenantPackage entity){
|
|
||||||
//TODO 做一些数据校验,如唯一约束
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量删除租户套餐
|
* 批量删除租户套餐
|
||||||
*/
|
*/
|
||||||
@ -134,7 +129,10 @@ public class SysTenantPackageServiceImpl implements ISysTenantPackageService {
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||||
if(isValid){
|
if(isValid){
|
||||||
//TODO 做一些业务上的校验,判断是否需要校验
|
boolean exists = tenantMapper.exists(new LambdaQueryWrapper<SysTenant>().in(SysTenant::getPackageId, ids));
|
||||||
|
if (exists) {
|
||||||
|
throw new ServiceException("租户套餐已被使用");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return baseMapper.deleteBatchIds(ids) > 0;
|
return baseMapper.deleteBatchIds(ids) > 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,30 +5,27 @@ import cn.hutool.core.bean.BeanUtil;
|
|||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.RandomUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.ruoyi.common.core.constant.Constants;
|
import com.ruoyi.common.core.constant.Constants;
|
||||||
import com.ruoyi.common.core.constant.UserConstants;
|
import com.ruoyi.common.core.constant.UserConstants;
|
||||||
import com.ruoyi.common.core.exception.ServiceException;
|
import com.ruoyi.common.core.exception.ServiceException;
|
||||||
import com.ruoyi.common.core.utils.StringUtils;
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
|
|
||||||
import com.ruoyi.common.mybatis.core.page.PageQuery;
|
import com.ruoyi.common.mybatis.core.page.PageQuery;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
||||||
import com.ruoyi.system.domain.*;
|
import com.ruoyi.system.domain.*;
|
||||||
import com.ruoyi.system.domain.bo.SysUserBo;
|
|
||||||
import com.ruoyi.system.mapper.*;
|
|
||||||
import com.ruoyi.system.service.ISysUserService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import com.ruoyi.system.domain.bo.SysTenantBo;
|
import com.ruoyi.system.domain.bo.SysTenantBo;
|
||||||
import com.ruoyi.system.domain.vo.SysTenantVo;
|
import com.ruoyi.system.domain.vo.SysTenantVo;
|
||||||
|
import com.ruoyi.system.mapper.*;
|
||||||
import com.ruoyi.system.service.ISysTenantService;
|
import com.ruoyi.system.service.ISysTenantService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 租户Service业务层处理
|
* 租户Service业务层处理
|
||||||
@ -39,7 +36,6 @@ import java.util.Collection;
|
|||||||
@Service
|
@Service
|
||||||
public class SysTenantServiceImpl implements ISysTenantService {
|
public class SysTenantServiceImpl implements ISysTenantService {
|
||||||
|
|
||||||
private final ISysUserService iSysUserService;
|
|
||||||
private final SysTenantMapper baseMapper;
|
private final SysTenantMapper baseMapper;
|
||||||
private final SysTenantPackageMapper sysTenantPackageMapper;
|
private final SysTenantPackageMapper sysTenantPackageMapper;
|
||||||
private final SysUserMapper sysUserMapper;
|
private final SysUserMapper sysUserMapper;
|
||||||
@ -77,7 +73,6 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private LambdaQueryWrapper<SysTenant> buildQueryWrapper(SysTenantBo bo) {
|
private LambdaQueryWrapper<SysTenant> buildQueryWrapper(SysTenantBo bo) {
|
||||||
Map<String, Object> params = bo.getParams();
|
|
||||||
LambdaQueryWrapper<SysTenant> lqw = Wrappers.lambdaQuery();
|
LambdaQueryWrapper<SysTenant> lqw = Wrappers.lambdaQuery();
|
||||||
lqw.eq(StringUtils.isNotBlank(bo.getTenantId()), SysTenant::getTenantId, bo.getTenantId());
|
lqw.eq(StringUtils.isNotBlank(bo.getTenantId()), SysTenant::getTenantId, bo.getTenantId());
|
||||||
lqw.like(StringUtils.isNotBlank(bo.getContactUserName()), SysTenant::getContactUserName, bo.getContactUserName());
|
lqw.like(StringUtils.isNotBlank(bo.getContactUserName()), SysTenant::getContactUserName, bo.getContactUserName());
|
||||||
@ -101,13 +96,6 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|||||||
public Boolean insertByBo(SysTenantBo bo) {
|
public Boolean insertByBo(SysTenantBo bo) {
|
||||||
SysTenant add = BeanUtil.toBean(bo, SysTenant.class);
|
SysTenant add = BeanUtil.toBean(bo, SysTenant.class);
|
||||||
|
|
||||||
SysUserBo userBo = new SysUserBo();
|
|
||||||
userBo.setUserName(bo.getUsername());
|
|
||||||
// 判断用户名是否重复
|
|
||||||
if (UserConstants.NOT_UNIQUE.equals(iSysUserService.checkUserNameUnique(userBo))) {
|
|
||||||
throw new ServiceException("新增用户'" + bo.getUsername() + "'失败,登录账号已存在");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取所有租户编号
|
// 获取所有租户编号
|
||||||
List<String> tenantIds = baseMapper.selectObjs(
|
List<String> tenantIds = baseMapper.selectObjs(
|
||||||
new LambdaQueryWrapper<SysTenant>().select(SysTenant::getTenantId), Convert::toStr);
|
new LambdaQueryWrapper<SysTenant>().select(SysTenant::getTenantId), Convert::toStr);
|
||||||
@ -214,11 +202,11 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|||||||
* 修改租户
|
* 修改租户
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public Boolean updateByBo(SysTenantBo bo) {
|
public Boolean updateByBo(SysTenantBo bo) {
|
||||||
SysTenant update = BeanUtil.toBean(bo, SysTenant.class);
|
SysTenant tenant = BeanUtil.toBean(bo, SysTenant.class);
|
||||||
validEntityBeforeSave(update);
|
tenant.setTenantId(null);
|
||||||
return baseMapper.updateById(update) > 0;
|
tenant.setPackageId(null);
|
||||||
|
return baseMapper.updateById(tenant) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -233,13 +221,6 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|||||||
return baseMapper.updateById(tenant);
|
return baseMapper.updateById(tenant);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 保存前的数据校验
|
|
||||||
*/
|
|
||||||
private void validEntityBeforeSave(SysTenant entity){
|
|
||||||
//TODO 做一些数据校验,如唯一约束
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量删除租户
|
* 批量删除租户
|
||||||
*/
|
*/
|
||||||
@ -247,7 +228,7 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||||
if(isValid){
|
if(isValid){
|
||||||
//TODO 做一些业务上的校验,判断是否需要校验
|
// 做一些业务上的校验,判断是否需要校验
|
||||||
}
|
}
|
||||||
return baseMapper.deleteBatchIds(ids) > 0;
|
return baseMapper.deleteBatchIds(ids) > 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user