【新增】租户套餐的管理,可配置每个租户的可使用的功能

This commit is contained in:
YunaiV 2022-02-20 12:24:47 +08:00
parent 79311ecc71
commit 6b6d676a6b
38 changed files with 1088 additions and 49 deletions

View File

@ -102,16 +102,20 @@ public interface ErrorCodeConstants {
ErrorCode SMS_CODE_IS_EXISTS = new ErrorCode(1002013007, "手机号已被使用"); ErrorCode SMS_CODE_IS_EXISTS = new ErrorCode(1002013007, "手机号已被使用");
ErrorCode SMS_CODE_IS_UNUSED = new ErrorCode(1002013008, "验证码未被使用"); ErrorCode SMS_CODE_IS_UNUSED = new ErrorCode(1002013008, "验证码未被使用");
// ========== 租户模块 1002014000 ========== // ========== 租户信息 1002014000 ==========
ErrorCode TENANT_NOT_EXISTS = new ErrorCode(1002014000, "租户不存在"); ErrorCode TENANT_NOT_EXISTS = new ErrorCode(1002014000, "租户不存在");
// ========== 错误码模块 1002015000 ========== // ========== 租户套餐 1002015000 ==========
ErrorCode ERROR_CODE_NOT_EXISTS = new ErrorCode(1002015000, "错误码不存在"); ErrorCode TENANT_PACKAGE_NOT_EXISTS = new ErrorCode(1002015000, "租户套餐不存在");
ErrorCode ERROR_CODE_DUPLICATE = new ErrorCode(1002015001, "已经存在编码为【{}】的错误码"); ErrorCode TENANT_PACKAGE_USED = new ErrorCode(1002015001, "租户正在使用该套餐,请给租户重新设置套餐后再尝试删除");
// ========== 社交用户 1002015000 ========== // ========== 错误码模块 1002016000 ==========
ErrorCode SOCIAL_USER_AUTH_FAILURE = new ErrorCode(1002015000, "社交授权失败,原因是:{}"); ErrorCode ERROR_CODE_NOT_EXISTS = new ErrorCode(1002016000, "错误码不存在");
ErrorCode SOCIAL_USER_UNBIND_NOT_SELF = new ErrorCode(1002015001, "社交解绑失败,非当前用户绑定"); ErrorCode ERROR_CODE_DUPLICATE = new ErrorCode(1002016001, "已经存在编码为【{}】的错误码");
ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1002015001, "社交授权失败,找不到对应的用户");
// ========== 社交用户 1002017000 ==========
ErrorCode SOCIAL_USER_AUTH_FAILURE = new ErrorCode(1002017000, "社交授权失败,原因是:{}");
ErrorCode SOCIAL_USER_UNBIND_NOT_SELF = new ErrorCode(1002017001, "社交解绑失败,非当前用户绑定");
ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1002017001, "社交授权失败,找不到对应的用户");
} }

View File

@ -6,6 +6,8 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull;
@ApiModel("管理后台 - 菜单精简信息 Response VO") @ApiModel("管理后台 - 菜单精简信息 Response VO")
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@ -21,4 +23,8 @@ public class MenuSimpleRespVO {
@ApiModelProperty(value = "父菜单 ID", required = true, example = "1024") @ApiModelProperty(value = "父菜单 ID", required = true, example = "1024")
private Long parentId; private Long parentId;
@ApiModelProperty(value = "类型", required = true, example = "1", notes = "参见 MenuTypeEnum 枚举类")
@NotNull(message = "菜单类型不能为空")
private Integer type;
} }

View File

@ -1,6 +1,6 @@
package cn.iocoder.yudao.module.system.controller.admin.tenant; package cn.iocoder.yudao.module.system.controller.admin.tenant;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.*; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.*;
import cn.iocoder.yudao.module.system.convert.tenant.TenantConvert; import cn.iocoder.yudao.module.system.convert.tenant.TenantConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO;
import cn.iocoder.yudao.module.system.service.tenant.TenantService; import cn.iocoder.yudao.module.system.service.tenant.TenantService;

View File

@ -0,0 +1,85 @@
package cn.iocoder.yudao.module.system.controller.admin.tenant;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageCreateReqVO;
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.TenantPackageUpdateReqVO;
import cn.iocoder.yudao.module.system.convert.tenant.TenantPackageConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO;
import cn.iocoder.yudao.module.system.service.tenant.TenantPackageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Api(tags = "管理后台 - 租户套餐")
@RestController
@RequestMapping("/system/tenant-package")
@Validated
public class TenantPackageController {
@Resource
private TenantPackageService tenantPackageService;
@PostMapping("/create")
@ApiOperation("创建租户套餐")
@PreAuthorize("@ss.hasPermission('system:tenant-package:create')")
public CommonResult<Long> createTenantPackage(@Valid @RequestBody TenantPackageCreateReqVO createReqVO) {
return success(tenantPackageService.createTenantPackage(createReqVO));
}
@PutMapping("/update")
@ApiOperation("更新租户套餐")
@PreAuthorize("@ss.hasPermission('system:tenant-package:update')")
public CommonResult<Boolean> updateTenantPackage(@Valid @RequestBody TenantPackageUpdateReqVO updateReqVO) {
tenantPackageService.updateTenantPackage(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@ApiOperation("删除租户套餐")
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('system:tenant-package:delete')")
public CommonResult<Boolean> deleteTenantPackage(@RequestParam("id") Long id) {
tenantPackageService.deleteTenantPackage(id);
return success(true);
}
@GetMapping("/get")
@ApiOperation("获得租户套餐")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('system:tenant-package:query')")
public CommonResult<TenantPackageRespVO> getTenantPackage(@RequestParam("id") Long id) {
TenantPackageDO tenantPackage = tenantPackageService.getTenantPackage(id);
return success(TenantPackageConvert.INSTANCE.convert(tenantPackage));
}
@GetMapping("/list")
@ApiOperation("获得租户套餐列表")
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
@PreAuthorize("@ss.hasPermission('system:tenant-package:query')")
public CommonResult<List<TenantPackageRespVO>> getTenantPackageList(@RequestParam("ids") Collection<Long> ids) {
List<TenantPackageDO> list = tenantPackageService.getTenantPackageList(ids);
return success(TenantPackageConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@ApiOperation("获得租户套餐分页")
@PreAuthorize("@ss.hasPermission('system:tenant-package:query')")
public CommonResult<PageResult<TenantPackageRespVO>> getTenantPackagePage(@Valid TenantPackagePageReqVO pageVO) {
PageResult<TenantPackageDO> pageResult = tenantPackageService.getTenantPackagePage(pageVO);
return success(TenantPackageConvert.INSTANCE.convertPage(pageResult));
}
}

View File

@ -0,0 +1,31 @@
package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* 租户套餐 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Data
public class TenantPackageBaseVO {
@ApiModelProperty(value = "套餐名", required = true, example = "VIP")
@NotNull(message = "套餐名不能为空")
private String name;
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 CommonStatusEnum 枚举")
@NotNull(message = "状态不能为空")
private Integer status;
@ApiModelProperty(value = "备注", example = "")
private String remark;
@ApiModelProperty(value = "关联的菜单编号", required = true)
@NotNull(message = "关联的菜单编号不能为空")
private List<Long> menuIds;
}

View File

@ -0,0 +1,14 @@
package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ApiModel("管理后台 - 租户套餐创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class TenantPackageCreateReqVO extends TenantPackageBaseVO {
}

View File

@ -0,0 +1,38 @@
package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ApiModel("管理后台 - 租户套餐分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class TenantPackagePageReqVO extends PageParam {
@ApiModelProperty(value = "套餐名", example = "VIP")
private String name;
@ApiModelProperty(value = "状态", example = "1")
private Integer status;
@ApiModelProperty(value = "备注", example = "")
private String remark;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "开始创建时间")
private Date beginCreateTime;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "结束创建时间")
private Date endCreateTime;
}

View File

@ -0,0 +1,23 @@
package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.Date;
@ApiModel("管理后台 - 租户套餐 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class TenantPackageRespVO extends TenantPackageBaseVO {
@ApiModelProperty(value = "套餐编号", required = true, example = "1024")
private Long id;
@ApiModelProperty(value = "创建时间", required = true)
private Date createTime;
}

View File

@ -0,0 +1,18 @@
package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
import javax.validation.constraints.*;
@ApiModel("管理后台 - 租户套餐更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class TenantPackageUpdateReqVO extends TenantPackageBaseVO {
@ApiModelProperty(value = "套餐编号", required = true, example = "1024")
@NotNull(message = "套餐编号不能为空")
private Long id;
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.system.controller.admin.tenant.vo; package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant;
import lombok.*; import lombok.*;
import io.swagger.annotations.*; import io.swagger.annotations.*;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.system.controller.admin.tenant.vo; package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant;
import lombok.*; import lombok.*;
import io.swagger.annotations.*; import io.swagger.annotations.*;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.system.controller.admin.tenant.vo; package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant;
import lombok.*; import lombok.*;
import java.util.*; import java.util.*;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.system.controller.admin.tenant.vo; package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.system.controller.admin.tenant.vo; package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant;
import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.system.controller.admin.tenant.vo; package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant;
import lombok.*; import lombok.*;
import java.util.*; import java.util.*;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.system.controller.admin.tenant.vo; package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant;
import lombok.*; import lombok.*;
import io.swagger.annotations.*; import io.swagger.annotations.*;

View File

@ -1,9 +1,9 @@
package cn.iocoder.yudao.module.system.convert.tenant; package cn.iocoder.yudao.module.system.convert.tenant;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantExcelVO; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantExcelVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantRespVO; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantRespVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantUpdateReqVO; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantUpdateReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;

View File

@ -0,0 +1,33 @@
package cn.iocoder.yudao.module.system.convert.tenant;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageRespVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageUpdateReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 租户套餐 Convert
*
* @author 芋道源码
*/
@Mapper
public interface TenantPackageConvert {
TenantPackageConvert INSTANCE = Mappers.getMapper(TenantPackageConvert.class);
TenantPackageDO convert(TenantPackageCreateReqVO bean);
TenantPackageDO convert(TenantPackageUpdateReqVO bean);
TenantPackageRespVO convert(TenantPackageDO bean);
List<TenantPackageRespVO> convertList(List<TenantPackageDO> list);
PageResult<TenantPackageRespVO> convertPage(PageResult<TenantPackageDO> page);
}

View File

@ -2,9 +2,12 @@ package cn.iocoder.yudao.module.system.dal.dataobject.tenant;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*; import lombok.*;
import java.util.Date;
/** /**
* 租户 DO * 租户 DO
* *
@ -27,6 +30,12 @@ public class TenantDO extends BaseDO {
* 租户名唯一 * 租户名唯一
*/ */
private String name; private String name;
/**
* 联系人的用户编号
*
* 关联 {@link AdminUserDO#getId()}
*/
private Long contactUserId;
/** /**
* 联系人 * 联系人
*/ */
@ -36,10 +45,30 @@ public class TenantDO extends BaseDO {
*/ */
private String contactMobile; private String contactMobile;
/** /**
* 帐号状态 * 租户状态
* *
* 枚举 {@link CommonStatusEnum} * 枚举 {@link CommonStatusEnum}
*/ */
private Integer status; private Integer status;
/**
* 绑定域名
*
* TODO 芋艿目前是预留字段未来会支持根据域名自动查询到对应的租户等等
*/
private String domain;
/**
* 租户套餐编号
*
* 关联 {@link TenantPackageDO#getId()}
*/
private Long packageId;
/**
* 过期时间
*/
private Date expireTime;
/**
* 账号数量
*/
private Integer accountCount;
} }

View File

@ -0,0 +1,50 @@
package cn.iocoder.yudao.module.system.dal.dataobject.tenant;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import java.util.Set;
/**
* 租户套餐 DO
*
* @author 芋道源码
*/
@TableName(value = "system_tenant_package", autoResultMap = true)
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class TenantPackageDO extends BaseDO {
/**
* 套餐编号自增
*/
private Long id;
/**
* 套餐名唯一
*/
private String name;
/**
* 租户状态
*
* 枚举 {@link CommonStatusEnum}
*/
private Integer status;
/**
* 备注
*/
private String remark;
/**
* 关联的菜单编号
*/
@TableField(typeHandler = JsonLongSetTypeHandler.class)
private Set<Long> menuIds;
}

View File

@ -1 +1,9 @@
/**
* DAL = Data Access Layer 数据访问层
* 1. data object数据对象
* 2. redisRedis CRUD 操作
* 3. mysqlMySQL CRUD 操作
*
* 其中MySQL 的表以 system_ 作为前缀
*/
package cn.iocoder.yudao.module.system.dal.mysql; package cn.iocoder.yudao.module.system.dal.mysql;

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.module.system.dal.mysql.tenant; package cn.iocoder.yudao.module.system.dal.mysql.tenant;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantExportReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
@ -41,4 +41,9 @@ public interface TenantMapper extends BaseMapperX<TenantDO> {
default TenantDO selectByName(String name) { default TenantDO selectByName(String name) {
return selectOne(TenantDO::getName, name); return selectOne(TenantDO::getName, name);
} }
default Integer selectCountByPackageId(Long packageId) {
return selectCount("package_id", packageId);
}
} }

View File

@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.system.dal.mysql.tenant;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackagePageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO;
import org.apache.ibatis.annotations.Mapper;
/**
* 租户套餐 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface TenantPackageMapper extends BaseMapperX<TenantPackageDO> {
default PageResult<TenantPackageDO> selectPage(TenantPackagePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<TenantPackageDO>()
.likeIfPresent(TenantPackageDO::getName, reqVO.getName())
.eqIfPresent(TenantPackageDO::getStatus, reqVO.getStatus())
.eqIfPresent(TenantPackageDO::getRemark, reqVO.getRemark())
.betweenIfPresent(TenantPackageDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc(TenantPackageDO::getId));
}
}

View File

@ -0,0 +1,66 @@
package cn.iocoder.yudao.module.system.service.tenant;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackagePageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageUpdateReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
/**
* 租户套餐 Service 接口
*
* @author 芋道源码
*/
public interface TenantPackageService {
/**
* 创建租户套餐
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createTenantPackage(@Valid TenantPackageCreateReqVO createReqVO);
/**
* 更新租户套餐
*
* @param updateReqVO 更新信息
*/
void updateTenantPackage(@Valid TenantPackageUpdateReqVO updateReqVO);
/**
* 删除租户套餐
*
* @param id 编号
*/
void deleteTenantPackage(Long id);
/**
* 获得租户套餐
*
* @param id 编号
* @return 租户套餐
*/
TenantPackageDO getTenantPackage(Long id);
/**
* 获得租户套餐列表
*
* @param ids 编号
* @return 租户套餐列表
*/
List<TenantPackageDO> getTenantPackageList(Collection<Long> ids);
/**
* 获得租户套餐分页
*
* @param pageReqVO 分页查询
* @return 租户套餐分页
*/
PageResult<TenantPackageDO> getTenantPackagePage(TenantPackagePageReqVO pageReqVO);
}

View File

@ -0,0 +1,91 @@
package cn.iocoder.yudao.module.system.service.tenant;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackagePageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageUpdateReqVO;
import cn.iocoder.yudao.module.system.convert.tenant.TenantPackageConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO;
import cn.iocoder.yudao.module.system.dal.mysql.tenant.TenantPackageMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.TENANT_PACKAGE_NOT_EXISTS;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.TENANT_PACKAGE_USED;
/**
* 租户套餐 Service 实现类
*
* @author 芋道源码
*/
@Service
@Validated
public class TenantPackageServiceImpl implements TenantPackageService {
@Resource
private TenantPackageMapper tenantPackageMapper;
@Resource
private TenantService tenantService;
@Override
public Long createTenantPackage(TenantPackageCreateReqVO createReqVO) {
// 插入
TenantPackageDO tenantPackage = TenantPackageConvert.INSTANCE.convert(createReqVO);
tenantPackageMapper.insert(tenantPackage);
// 返回
return tenantPackage.getId();
}
@Override
public void updateTenantPackage(TenantPackageUpdateReqVO updateReqVO) {
// 校验存在
this.validateTenantPackageExists(updateReqVO.getId());
// 更新
TenantPackageDO updateObj = TenantPackageConvert.INSTANCE.convert(updateReqVO);
tenantPackageMapper.updateById(updateObj);
}
@Override
public void deleteTenantPackage(Long id) {
// 校验存在
this.validateTenantPackageExists(id);
// 校验正在使用
this.validateTenantUsed(id);
// 删除
tenantPackageMapper.deleteById(id);
}
private void validateTenantPackageExists(Long id) {
if (tenantPackageMapper.selectById(id) == null) {
throw exception(TENANT_PACKAGE_NOT_EXISTS);
}
}
private void validateTenantUsed(Long id) {
if (tenantService.getTenantCountByPackageId(id) > 0) {
throw exception(TENANT_PACKAGE_USED);
}
}
@Override
public TenantPackageDO getTenantPackage(Long id) {
return tenantPackageMapper.selectById(id);
}
@Override
public List<TenantPackageDO> getTenantPackageList(Collection<Long> ids) {
return tenantPackageMapper.selectBatchIds(ids);
}
@Override
public PageResult<TenantPackageDO> getTenantPackagePage(TenantPackagePageReqVO pageReqVO) {
return tenantPackageMapper.selectPage(pageReqVO);
}
}

View File

@ -2,10 +2,10 @@ package cn.iocoder.yudao.module.system.service.tenant;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.tenant.core.service.TenantFrameworkService; import cn.iocoder.yudao.framework.tenant.core.service.TenantFrameworkService;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantExportReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantUpdateReqVO; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantUpdateReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO;
import javax.validation.Valid; import javax.validation.Valid;
@ -81,4 +81,12 @@ public interface TenantService extends TenantFrameworkService {
*/ */
TenantDO getTenantByName(String name); TenantDO getTenantByName(String name);
/**
* 获得使用指定套餐的租户数量
*
* @param packageId 租户套餐编号
* @return 租户数量
*/
Integer getTenantCountByPackageId(Long packageId);
} }

View File

@ -2,10 +2,10 @@ package cn.iocoder.yudao.module.system.service.tenant;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantExportReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantUpdateReqVO; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantUpdateReqVO;
import cn.iocoder.yudao.module.system.convert.tenant.TenantConvert; import cn.iocoder.yudao.module.system.convert.tenant.TenantConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO;
import cn.iocoder.yudao.module.system.dal.mysql.tenant.TenantMapper; import cn.iocoder.yudao.module.system.dal.mysql.tenant.TenantMapper;
@ -94,4 +94,9 @@ public class TenantServiceImpl implements TenantService {
return tenantMapper.selectByName(name); return tenantMapper.selectByName(name);
} }
@Override
public Integer getTenantCountByPackageId(Long packageId) {
return tenantMapper.selectCountByPackageId(packageId);
}
} }

View File

@ -0,0 +1,134 @@
package cn.iocoder.yudao.module.system.service.tenant;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackagePageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageUpdateReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO;
import cn.iocoder.yudao.module.system.dal.mysql.tenant.TenantPackageMapper;
import cn.iocoder.yudao.module.system.test.BaseDbUnitTest;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.TENANT_PACKAGE_NOT_EXISTS;
import static org.junit.jupiter.api.Assertions.*;
/**
* {@link TenantPackageServiceImpl} 的单元测试类
*
* @author 芋道源码
*/
@Import(TenantPackageServiceImpl.class)
public class TenantPackageServiceImplTest extends BaseDbUnitTest {
@Resource
private TenantPackageServiceImpl tenantPackageService;
@Resource
private TenantPackageMapper tenantPackageMapper;
@Test
public void testCreateTenantPackage_success() {
// 准备参数
TenantPackageCreateReqVO reqVO = randomPojo(TenantPackageCreateReqVO.class);
// 调用
Long tenantPackageId = tenantPackageService.createTenantPackage(reqVO);
// 断言
assertNotNull(tenantPackageId);
// 校验记录的属性是否正确
TenantPackageDO tenantPackage = tenantPackageMapper.selectById(tenantPackageId);
assertPojoEquals(reqVO, tenantPackage);
}
@Test
public void testUpdateTenantPackage_success() {
// mock 数据
TenantPackageDO dbTenantPackage = randomPojo(TenantPackageDO.class);
tenantPackageMapper.insert(dbTenantPackage);// @Sql: 先插入出一条存在的数据
// 准备参数
TenantPackageUpdateReqVO reqVO = randomPojo(TenantPackageUpdateReqVO.class, o -> {
o.setId(dbTenantPackage.getId()); // 设置更新的 ID
});
// 调用
tenantPackageService.updateTenantPackage(reqVO);
// 校验是否更新正确
TenantPackageDO tenantPackage = tenantPackageMapper.selectById(reqVO.getId()); // 获取最新的
assertPojoEquals(reqVO, tenantPackage);
}
@Test
public void testUpdateTenantPackage_notExists() {
// 准备参数
TenantPackageUpdateReqVO reqVO = randomPojo(TenantPackageUpdateReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> tenantPackageService.updateTenantPackage(reqVO), TENANT_PACKAGE_NOT_EXISTS);
}
@Test
public void testDeleteTenantPackage_success() {
// mock 数据
TenantPackageDO dbTenantPackage = randomPojo(TenantPackageDO.class);
tenantPackageMapper.insert(dbTenantPackage);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbTenantPackage.getId();
// 调用
tenantPackageService.deleteTenantPackage(id);
// 校验数据不存在了
assertNull(tenantPackageMapper.selectById(id));
}
@Test
public void testDeleteTenantPackage_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> tenantPackageService.deleteTenantPackage(id), TENANT_PACKAGE_NOT_EXISTS);
}
@Test // TODO 请修改 null 为需要的值
public void testGetTenantPackagePage() {
// mock 数据
TenantPackageDO dbTenantPackage = randomPojo(TenantPackageDO.class, o -> { // 等会查询到
o.setName(null);
o.setStatus(null);
o.setRemark(null);
o.setCreateTime(null);
});
tenantPackageMapper.insert(dbTenantPackage);
// 测试 name 不匹配
tenantPackageMapper.insert(cloneIgnoreId(dbTenantPackage, o -> o.setName(null)));
// 测试 status 不匹配
tenantPackageMapper.insert(cloneIgnoreId(dbTenantPackage, o -> o.setStatus(null)));
// 测试 remark 不匹配
tenantPackageMapper.insert(cloneIgnoreId(dbTenantPackage, o -> o.setRemark(null)));
// 测试 createTime 不匹配
tenantPackageMapper.insert(cloneIgnoreId(dbTenantPackage, o -> o.setCreateTime(null)));
// 准备参数
TenantPackagePageReqVO reqVO = new TenantPackagePageReqVO();
reqVO.setName(null);
reqVO.setStatus(null);
reqVO.setRemark(null);
reqVO.setBeginCreateTime(null);
reqVO.setEndCreateTime(null);
// 调用
PageResult<TenantPackageDO> pageResult = tenantPackageService.getTenantPackagePage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbTenantPackage, pageResult.getList().get(0));
}
}

View File

@ -1,9 +1,9 @@
package cn.iocoder.yudao.module.system.service.tenant; package cn.iocoder.yudao.module.system.service.tenant;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantExportReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantUpdateReqVO; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantUpdateReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO;
import cn.iocoder.yudao.module.system.dal.mysql.tenant.TenantMapper; import cn.iocoder.yudao.module.system.dal.mysql.tenant.TenantMapper;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;

View File

@ -16,3 +16,4 @@ DELETE FROM "system_sms_log";
DELETE FROM "system_error_code"; DELETE FROM "system_error_code";
DELETE FROM "system_social_user"; DELETE FROM "system_social_user";
DELETE FROM "system_tenant"; DELETE FROM "system_tenant";
DELETE FROM "system_tenant_package";

View File

@ -404,3 +404,17 @@ CREATE TABLE IF NOT EXISTS "system_tenant" (
"deleted" bit NOT NULL DEFAULT FALSE, "deleted" bit NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id") PRIMARY KEY ("id")
) COMMENT '租户'; ) COMMENT '租户';
CREATE TABLE IF NOT EXISTS "system_tenant_package" (
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"name" varchar(30) NOT NULL,
"status" tinyint NOT NULL,
"remark" varchar(256),
"menu_ids" varchar(2048) NOT NULL,
"creator" varchar(64) DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar(64) DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id")
) COMMENT '租户套餐表';

View File

@ -40,6 +40,7 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
@PostMapping("/create") @PostMapping("/create")
@ApiOperation("创建${table.classComment}") @ApiOperation("创建${table.classComment}")
#if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:create')")#end #if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:create')")#end
public CommonResult<${primaryColumn.javaType}> create${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}CreateReqVO createReqVO) { public CommonResult<${primaryColumn.javaType}> create${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}CreateReqVO createReqVO) {
return success(${classNameVar}Service.create${simpleClassName}(createReqVO)); return success(${classNameVar}Service.create${simpleClassName}(createReqVO));
} }
@ -47,6 +48,7 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
@PutMapping("/update") @PutMapping("/update")
@ApiOperation("更新${table.classComment}") @ApiOperation("更新${table.classComment}")
#if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:update')")#end #if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:update')")#end
public CommonResult<Boolean> update${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}UpdateReqVO updateReqVO) { public CommonResult<Boolean> update${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}UpdateReqVO updateReqVO) {
${classNameVar}Service.update${simpleClassName}(updateReqVO); ${classNameVar}Service.update${simpleClassName}(updateReqVO);
return success(true); return success(true);
@ -56,6 +58,7 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
@ApiOperation("删除${table.classComment}") @ApiOperation("删除${table.classComment}")
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = ${primaryColumn.javaType}.class) @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = ${primaryColumn.javaType}.class)
#if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")#end #if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")#end
public CommonResult<Boolean> delete${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) { public CommonResult<Boolean> delete${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) {
${classNameVar}Service.delete${simpleClassName}(id); ${classNameVar}Service.delete${simpleClassName}(id);
return success(true); return success(true);
@ -64,7 +67,8 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
@GetMapping("/get") @GetMapping("/get")
@ApiOperation("获得${table.classComment}") @ApiOperation("获得${table.classComment}")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = ${primaryColumn.javaType}.class) @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = ${primaryColumn.javaType}.class)
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')") #if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")#end
public CommonResult<${sceneEnum.prefixClass}${table.className}RespVO> get${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) { public CommonResult<${sceneEnum.prefixClass}${table.className}RespVO> get${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) {
${table.className}DO ${classNameVar} = ${classNameVar}Service.get${simpleClassName}(id); ${table.className}DO ${classNameVar} = ${classNameVar}Service.get${simpleClassName}(id);
return success(${table.className}Convert.INSTANCE.convert(${classNameVar})); return success(${table.className}Convert.INSTANCE.convert(${classNameVar}));
@ -74,6 +78,7 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
@ApiOperation("获得${table.classComment}列表") @ApiOperation("获得${table.classComment}列表")
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
#if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")#end #if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")#end
public CommonResult<List<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}List(@RequestParam("ids") Collection<${primaryColumn.javaType}> ids) { public CommonResult<List<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}List(@RequestParam("ids") Collection<${primaryColumn.javaType}> ids) {
List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(ids); List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(ids);
return success(${table.className}Convert.INSTANCE.convertList(list)); return success(${table.className}Convert.INSTANCE.convertList(list));
@ -82,6 +87,7 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
@GetMapping("/page") @GetMapping("/page")
@ApiOperation("获得${table.classComment}分页") @ApiOperation("获得${table.classComment}分页")
#if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")#end #if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")#end
public CommonResult<PageResult<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}Page(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageVO) { public CommonResult<PageResult<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}Page(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageVO) {
PageResult<${table.className}DO> pageResult = ${classNameVar}Service.get${simpleClassName}Page(pageVO); PageResult<${table.className}DO> pageResult = ${classNameVar}Service.get${simpleClassName}Page(pageVO);
return success(${table.className}Convert.INSTANCE.convertPage(pageResult)); return success(${table.className}Convert.INSTANCE.convertPage(pageResult));
@ -90,6 +96,7 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
@GetMapping("/export-excel") @GetMapping("/export-excel")
@ApiOperation("导出${table.classComment} Excel") @ApiOperation("导出${table.classComment} Excel")
#if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:export')")#end #if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:export')")#end
@OperateLog(type = EXPORT) @OperateLog(type = EXPORT)
public void export${simpleClassName}Excel(@Valid ${sceneEnum.prefixClass}${table.className}ExportReqVO exportReqVO, public void export${simpleClassName}Excel(@Valid ${sceneEnum.prefixClass}${table.className}ExportReqVO exportReqVO,
HttpServletResponse response) throws IOException { HttpServletResponse response) throws IOException {

View File

@ -74,7 +74,7 @@
#elseif("" != $column.dictType)## 数据字典 #elseif("" != $column.dictType)## 数据字典
<el-table-column label="${comment}" align="center" prop="${javaField}"> <el-table-column label="${comment}" align="center" prop="${javaField}">
<template slot-scope="scope"> <template slot-scope="scope">
<dict-type :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.${column.javaField}" /> <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.${column.javaField}" />
</template> </template>
</el-table-column> </el-table-column>
#else #else

View File

@ -80,7 +80,7 @@ yudao:
tenant: # 多租户相关配置项 tenant: # 多租户相关配置项
enable: true enable: true
ignore-urls: /admin-api/system/captcha/get-image, /admin-api/infra/file/get/* ignore-urls: /admin-api/system/captcha/get-image, /admin-api/infra/file/get/*
ignore-tables: infra_config, infra_file, infra_job, infra_job_log, infra_job_log, system_tenant, system_dict_data, system_dict_type, system_error_code, system_menu, system_role, system_role_menu, system_sms_channel, tool_codegen_column, tool_codegen_table, tool_test_demo ignore-tables: infra_config, infra_file, infra_job, infra_job_log, infra_job_log, system_tenant, system_tenant_package, system_dict_data, system_dict_type, system_error_code, system_menu, system_role, system_role_menu, system_sms_channel, tool_codegen_column, tool_codegen_table, tool_test_demo, tables, columns
sms-code: # 短信验证码相关的配置项 sms-code: # 短信验证码相关的配置项
expire-times: 10m expire-times: 10m
send-frequency: 1m send-frequency: 1m

View File

@ -0,0 +1,54 @@
import request from '@/utils/request'
// 创建租户套餐
export function createTenantPackage(data) {
return request({
url: '/system/tenant-package/create',
method: 'post',
data: data
})
}
// 更新租户套餐
export function updateTenantPackage(data) {
return request({
url: '/system/tenant-package/update',
method: 'put',
data: data
})
}
// 删除租户套餐
export function deleteTenantPackage(id) {
return request({
url: '/system/tenant-package/delete?id=' + id,
method: 'delete'
})
}
// 获得租户套餐
export function getTenantPackage(id) {
return request({
url: '/system/tenant-package/get?id=' + id,
method: 'get'
})
}
// 获得租户套餐分页
export function getTenantPackagePage(query) {
return request({
url: '/system/tenant-package/page',
method: 'get',
params: query
})
}
// 导出租户套餐 Excel
export function exportTenantPackageExcel(query) {
return request({
url: '/system/tenant-package/export-excel',
method: 'get',
params: query,
responseType: 'blob'
})
}

View File

@ -149,16 +149,8 @@
<el-form-item label="菜单权限"> <el-form-item label="菜单权限">
<el-checkbox v-model="menuExpand" @change="handleCheckedTreeExpand($event, 'menu')">展开/折叠</el-checkbox> <el-checkbox v-model="menuExpand" @change="handleCheckedTreeExpand($event, 'menu')">展开/折叠</el-checkbox>
<el-checkbox v-model="menuNodeAll" @change="handleCheckedTreeNodeAll($event, 'menu')">全选/全不选</el-checkbox> <el-checkbox v-model="menuNodeAll" @change="handleCheckedTreeNodeAll($event, 'menu')">全选/全不选</el-checkbox>
<el-tree <el-tree class="tree-border" :data="menuOptions" show-checkbox ref="menu" node-key="id"
class="tree-border" :check-strictly="form.menuCheckStrictly" empty-text="加载中,请稍后" :props="defaultProps"></el-tree>
:data="menuOptions"
show-checkbox
ref="menu"
node-key="id"
:check-strictly="form.menuCheckStrictly"
empty-text="加载中,请稍后"
:props="defaultProps"
></el-tree>
</el-form-item> </el-form-item>
</el-form> </el-form>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">

View File

@ -0,0 +1,293 @@
<template>
<div class="app-container">
<!-- 搜索工作栏 -->
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="套餐名" prop="name">
<el-input v-model="queryParams.name" placeholder="请输入套餐名" clearable size="small" @keyup.enter.native="handleQuery"/>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)"
:key="dict.value" :label="dict.label" :value="dict.value"/>
</el-select>
</el-form-item>
<el-form-item label="创建时间">
<el-date-picker v-model="dateRangeCreateTime" size="small" style="width: 240px" value-format="yyyy-MM-dd"
type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" />
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<!-- 操作工具栏 -->
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
v-hasPermi="['system:tenant-package:create']">新增</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<!-- 列表 -->
<el-table v-loading="loading" :data="list">
<el-table-column label="套餐编号" align="center" prop="id" width="120" />
<el-table-column label="套餐名" align="center" prop="name" />
<el-table-column label="状态" align="center" prop="status" width="100">
<template slot-scope="scope">
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
v-hasPermi="['system:tenant-package:update']">修改</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
v-hasPermi="['system:tenant-package:delete']">删除</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页组件 -->
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
@pagination="getList"/>
<!-- 对话框(添加 / 修改) -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="套餐名" prop="name">
<el-input v-model="form.name" placeholder="请输入套餐名" />
</el-form-item>
<el-form-item label="菜单权限">
<el-checkbox v-model="menuExpand" @change="handleCheckedTreeExpand($event)">展开/折叠</el-checkbox>
<el-checkbox v-model="menuNodeAll" @change="handleCheckedTreeNodeAll($event)">全选/全不选</el-checkbox>
<el-tree class="tree-border" :data="menuOptions" show-checkbox ref="menu" node-key="id"
:check-strictly="menuCheckStrictly" empty-text="加载中,请稍后" :props="defaultProps"></el-tree>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-radio-group v-model="form.status">
<el-radio v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)"
:key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" placeholder="请输入备注" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { createTenantPackage, updateTenantPackage, deleteTenantPackage, getTenantPackage, getTenantPackagePage} from "@/api/system/tenantPackage";
import {CommonStatusEnum, SystemMenuTypeEnum} from "@/utils/constants";
import {listSimpleMenus} from "@/api/system/menu";
export default {
name: "TenantPackage",
components: {
},
data() {
return {
//
loading: true,
//
exportLoading: false,
//
showSearch: true,
//
total: 0,
//
list: [],
//
title: "",
//
open: false,
dateRangeCreateTime: [],
//
queryParams: {
pageNo: 1,
pageSize: 10,
name: null,
status: null,
remark: null,
},
//
form: {},
menuExpand: false,
menuNodeAll: false,
menuCheckStrictly: true,
defaultProps: {
label: "name",
children: "children"
},
menuOptions: [], //
//
rules: {
name: [{ required: true, message: "套餐名不能为空", trigger: "blur" }],
status: [{ required: true, message: "状态不能为空", trigger: "blur" }],
menuIds: [{ required: true, message: "关联的菜单编号不能为空", trigger: "blur" }],
}
};
},
created() {
this.getList();
this.getMenus();
},
methods: {
/** 查询列表 */
getList() {
this.loading = true;
//
let params = {...this.queryParams};
this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
//
getTenantPackagePage(params).then(response => {
this.list = response.data.list;
this.total = response.data.total;
this.loading = false;
});
},
/** 取消按钮 */
cancel() {
this.open = false;
this.reset();
},
/** 表单重置 */
reset() {
//
if (this.$refs.menu !== undefined) {
this.$refs.menu.setCheckedKeys([]);
}
this.menuExpand = false;
this.menuNodeAll = false;
this.menuCheckStrictly = true;
//
this.form = {
id: undefined,
name: undefined,
status: CommonStatusEnum.ENABLE,
remark: undefined,
menuIds: undefined,
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNo = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.dateRangeCreateTime = [];
//
this.resetForm("queryForm");
this.handleQuery();
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加租户套餐";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.id;
this.open = true;
this.title = "修改租户套餐";
//
getTenantPackage(id).then(response => {
this.form = response.data;
//
//
this.menuCheckStrictly = true
//
this.$refs.menu.setCheckedKeys(response.data.menuIds);
// 使
this.menuCheckStrictly = false
});
},
/** 获得菜单 */
getMenus() {
listSimpleMenus().then(response => {
// BUTTON DIRMENU
for (let i = response.data.length -1; i >= 0 ; i--) {
if (response.data[i].type === SystemMenuTypeEnum.BUTTON) {
response.data.splice(i, 1);
}
}
// menuOptions
this.menuOptions = [];
//
this.menuOptions.push(...this.handleTree(response.data, "id"));
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (!valid) {
return;
}
//
if (this.form.id != null) {
updateTenantPackage({
...this.form,
menuIds: [...this.$refs.menu.getCheckedKeys(), ...this.$refs.menu.getHalfCheckedKeys()]
}).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
return;
}
//
createTenantPackage({
...this.form,
menuIds: [...this.$refs.menu.getCheckedKeys(), ...this.$refs.menu.getHalfCheckedKeys()]
}).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
});
},
/** 删除按钮操作 */
handleDelete(row) {
const id = row.id;
this.$modal.confirm('是否确认删除租户套餐编号为"' + id + '"的数据项?').then(function() {
return deleteTenantPackage(id);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
// /
handleCheckedTreeExpand(value, type) {
let treeList = this.menuOptions;
for (let i = 0; i < treeList.length; i++) {
this.$refs.menu.store.nodesMap[treeList[i].id].expanded = value;
}
},
// /
handleCheckedTreeNodeAll(value) {
this.$refs.menu.setCheckedNodes(value ? this.menuOptions: []);
},
//
handleCheckedTreeConnect(value) {
this.form.menuCheckStrictly = value;
},
}
};
</script>

View File

@ -26,7 +26,10 @@ TODO
### ⭐ New Features ### ⭐ New Features
TODO * 【新增】后端 `yudao.tenant.enable` 配置项,前端 `VUE_APP_TENANT_ENABLE` 配置项,用于开关租户功能。 [commit](https://gitee.com/zhijiantianya/ruoyi-vue-pro/commit/79311ecc71f0c6beabe0e5f84e1423ce745a5f09)
* 【优化】调整默认所有表开启多租户的特性,可通过 `yudao.tenant.ignore-tables` 配置项进行忽略,替代原本默认不开启的策略 [commit](https://gitee.com/zhijiantianya/ruoyi-vue-pro/commit/79311ecc71f0c6beabe0e5f84e1423ce745a5f09)
* 【新增】通过 `yudao.tenant.ignore-urls` 配置忽略多租户的请求,例如说 ,例如说短信回调、支付回调等 Open API [commit](https://gitee.com/zhijiantianya/ruoyi-vue-pro/commit/79311ecc71f0c6beabe0e5f84e1423ce745a5f09)
* 【新增】租户套餐的管理,可配置每个租户的可使用的功能
### 🐞 Bug Fixes ### 🐞 Bug Fixes