mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 02:08:43 +08:00 
			
		
		
		
	【新增】租户套餐的管理,可配置每个租户的可使用的功能
This commit is contained in:
		| @@ -6,6 +6,8 @@ import lombok.AllArgsConstructor; | ||||
| import lombok.Data; | ||||
| import lombok.NoArgsConstructor; | ||||
|  | ||||
| import javax.validation.constraints.NotNull; | ||||
|  | ||||
| @ApiModel("管理后台 - 菜单精简信息 Response VO") | ||||
| @Data | ||||
| @NoArgsConstructor | ||||
| @@ -21,4 +23,8 @@ public class MenuSimpleRespVO { | ||||
|     @ApiModelProperty(value = "父菜单 ID", required = true, example = "1024") | ||||
|     private Long parentId; | ||||
|  | ||||
|     @ApiModelProperty(value = "类型", required = true, example = "1", notes = "参见 MenuTypeEnum 枚举类") | ||||
|     @NotNull(message = "菜单类型不能为空") | ||||
|     private Integer type; | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| 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.dal.dataobject.tenant.TenantDO; | ||||
| import cn.iocoder.yudao.module.system.service.tenant.TenantService; | ||||
|   | ||||
| @@ -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)); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -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; | ||||
|  | ||||
| } | ||||
| @@ -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 { | ||||
|  | ||||
| } | ||||
| @@ -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; | ||||
|  | ||||
| } | ||||
| @@ -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; | ||||
|  | ||||
| } | ||||
| @@ -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; | ||||
|  | ||||
| } | ||||
| @@ -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 io.swagger.annotations.*; | ||||
| @@ -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 io.swagger.annotations.*; | ||||
| @@ -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 java.util.*; | ||||
| @@ -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.ApiModelProperty; | ||||
| @@ -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 io.swagger.annotations.ApiModel; | ||||
| @@ -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 java.util.*; | ||||
| @@ -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 io.swagger.annotations.*; | ||||
| @@ -1,9 +1,9 @@ | ||||
| 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.TenantExcelVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantRespVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantUpdateReqVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantCreateReqVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantExcelVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantRespVO; | ||||
| 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.framework.common.pojo.PageResult; | ||||
| import org.mapstruct.Mapper; | ||||
|   | ||||
| @@ -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); | ||||
|  | ||||
| } | ||||
| @@ -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.mybatis.core.dataobject.BaseDO; | ||||
| import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; | ||||
| import com.baomidou.mybatisplus.annotation.TableName; | ||||
| import lombok.*; | ||||
|  | ||||
| import java.util.Date; | ||||
|  | ||||
| /** | ||||
|  * 租户 DO | ||||
|  * | ||||
| @@ -27,6 +30,12 @@ public class TenantDO extends BaseDO { | ||||
|      * 租户名,唯一 | ||||
|      */ | ||||
|     private String name; | ||||
|     /** | ||||
|      * 联系人的用户编号 | ||||
|      * | ||||
|      * 关联 {@link AdminUserDO#getId()} | ||||
|      */ | ||||
|     private Long contactUserId; | ||||
|     /** | ||||
|      * 联系人 | ||||
|      */ | ||||
| @@ -36,10 +45,30 @@ public class TenantDO extends BaseDO { | ||||
|      */ | ||||
|     private String contactMobile; | ||||
|     /** | ||||
|      * 帐号状态 | ||||
|      * 租户状态 | ||||
|      * | ||||
|      * 枚举 {@link CommonStatusEnum} | ||||
|      */ | ||||
|     private Integer status; | ||||
|     /** | ||||
|      * 绑定域名 | ||||
|      * | ||||
|      * TODO 芋艿:目前是预留字段,未来会支持根据域名,自动查询到对应的租户。等等 | ||||
|      */ | ||||
|     private String domain; | ||||
|     /** | ||||
|      * 租户套餐编号 | ||||
|      * | ||||
|      * 关联 {@link TenantPackageDO#getId()} | ||||
|      */ | ||||
|     private Long packageId; | ||||
|     /** | ||||
|      * 过期时间 | ||||
|      */ | ||||
|     private Date expireTime; | ||||
|     /** | ||||
|      * 账号数量 | ||||
|      */ | ||||
|     private Integer accountCount; | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
|  | ||||
| } | ||||
| @@ -1 +1,9 @@ | ||||
| /** | ||||
|  * DAL = Data Access Layer 数据访问层 | ||||
|  * 1. data object:数据对象 | ||||
|  * 2. redis:Redis 的 CRUD 操作 | ||||
|  * 3. mysql:MySQL 的 CRUD 操作 | ||||
|  * | ||||
|  * 其中,MySQL 的表以 system_ 作为前缀 | ||||
|  */ | ||||
| package cn.iocoder.yudao.module.system.dal.mysql; | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| 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.TenantPageReqVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantExportReqVO; | ||||
| 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.framework.common.pojo.PageResult; | ||||
| import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||||
| @@ -41,4 +41,9 @@ public interface TenantMapper extends BaseMapperX<TenantDO> { | ||||
|     default TenantDO selectByName(String name) { | ||||
|         return selectOne(TenantDO::getName, name); | ||||
|     } | ||||
|  | ||||
|     default Integer selectCountByPackageId(Long packageId) { | ||||
|         return selectCount("package_id", packageId); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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)); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -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); | ||||
|  | ||||
| } | ||||
| @@ -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); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -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.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.TenantExportReqVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantPageReqVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantUpdateReqVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantCreateReqVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantExportReqVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantUpdateReqVO; | ||||
| import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; | ||||
|  | ||||
| import javax.validation.Valid; | ||||
| @@ -81,4 +81,12 @@ public interface TenantService extends TenantFrameworkService { | ||||
|      */ | ||||
|     TenantDO getTenantByName(String name); | ||||
|  | ||||
|     /** | ||||
|      * 获得使用指定套餐的租户数量 | ||||
|      * | ||||
|      * @param packageId 租户套餐编号 | ||||
|      * @return 租户数量 | ||||
|      */ | ||||
|     Integer getTenantCountByPackageId(Long packageId); | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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.util.collection.CollectionUtils; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantCreateReqVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantExportReqVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantPageReqVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantUpdateReqVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantCreateReqVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantExportReqVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO; | ||||
| 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.dal.dataobject.tenant.TenantDO; | ||||
| import cn.iocoder.yudao.module.system.dal.mysql.tenant.TenantMapper; | ||||
| @@ -94,4 +94,9 @@ public class TenantServiceImpl implements TenantService { | ||||
|         return tenantMapper.selectByName(name); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Integer getTenantCountByPackageId(Long packageId) { | ||||
|         return tenantMapper.selectCountByPackageId(packageId); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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)); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -1,9 +1,9 @@ | ||||
| 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.TenantExportReqVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantPageReqVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.TenantUpdateReqVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantCreateReqVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantExportReqVO; | ||||
| import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO; | ||||
| 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.mysql.tenant.TenantMapper; | ||||
| import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||||
|   | ||||
| @@ -16,3 +16,4 @@ DELETE FROM "system_sms_log"; | ||||
| DELETE FROM "system_error_code"; | ||||
| DELETE FROM "system_social_user"; | ||||
| DELETE FROM "system_tenant"; | ||||
| DELETE FROM "system_tenant_package"; | ||||
|   | ||||
| @@ -404,3 +404,17 @@ CREATE TABLE IF NOT EXISTS "system_tenant" ( | ||||
|     "deleted" bit NOT NULL DEFAULT FALSE, | ||||
|     PRIMARY KEY ("id") | ||||
| ) 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 '租户套餐表'; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV