Commit d4cf945af710c67659dd9778aa59c0136f5eb43a
1 parent
5bb8fdca
🔧 简化 tenant 模块的 VO
Showing
22 changed files
with
161 additions
and
357 deletions
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/TenantController.java
| 1 | 1 | package cn.iocoder.yudao.module.system.controller.admin.tenant; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 5 | 7 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 6 | 8 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.*; | |
| 8 | -import cn.iocoder.yudao.module.system.convert.tenant.TenantConvert; | |
| 9 | +import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO; | |
| 10 | +import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantRespVO; | |
| 11 | +import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantSaveReqVO; | |
| 12 | +import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantSimpleRespVO; | |
| 9 | 13 | import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; |
| 10 | 14 | import cn.iocoder.yudao.module.system.service.tenant.TenantService; |
| 11 | -import io.swagger.v3.oas.annotations.tags.Tag; | |
| 12 | -import io.swagger.v3.oas.annotations.Parameter; | |
| 13 | 15 | import io.swagger.v3.oas.annotations.Operation; |
| 16 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 17 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 14 | 18 | import org.springframework.security.access.prepost.PreAuthorize; |
| 15 | 19 | import org.springframework.web.bind.annotation.*; |
| 16 | 20 | |
| ... | ... | @@ -47,20 +51,20 @@ public class TenantController { |
| 47 | 51 | @Parameter(name = "website", description = "域名", required = true, example = "www.iocoder.cn") |
| 48 | 52 | public CommonResult<TenantSimpleRespVO> getTenantByWebsite(@RequestParam("website") String website) { |
| 49 | 53 | TenantDO tenant = tenantService.getTenantByWebsite(website); |
| 50 | - return success(TenantConvert.INSTANCE.convert03(tenant)); | |
| 54 | + return success(BeanUtils.toBean(tenant, TenantSimpleRespVO.class)); | |
| 51 | 55 | } |
| 52 | 56 | |
| 53 | 57 | @PostMapping("/create") |
| 54 | 58 | @Operation(summary = "创建租户") |
| 55 | 59 | @PreAuthorize("@ss.hasPermission('system:tenant:create')") |
| 56 | - public CommonResult<Long> createTenant(@Valid @RequestBody TenantCreateReqVO createReqVO) { | |
| 60 | + public CommonResult<Long> createTenant(@Valid @RequestBody TenantSaveReqVO createReqVO) { | |
| 57 | 61 | return success(tenantService.createTenant(createReqVO)); |
| 58 | 62 | } |
| 59 | 63 | |
| 60 | 64 | @PutMapping("/update") |
| 61 | 65 | @Operation(summary = "更新租户") |
| 62 | 66 | @PreAuthorize("@ss.hasPermission('system:tenant:update')") |
| 63 | - public CommonResult<Boolean> updateTenant(@Valid @RequestBody TenantUpdateReqVO updateReqVO) { | |
| 67 | + public CommonResult<Boolean> updateTenant(@Valid @RequestBody TenantSaveReqVO updateReqVO) { | |
| 64 | 68 | tenantService.updateTenant(updateReqVO); |
| 65 | 69 | return success(true); |
| 66 | 70 | } |
| ... | ... | @@ -80,7 +84,7 @@ public class TenantController { |
| 80 | 84 | @PreAuthorize("@ss.hasPermission('system:tenant:query')") |
| 81 | 85 | public CommonResult<TenantRespVO> getTenant(@RequestParam("id") Long id) { |
| 82 | 86 | TenantDO tenant = tenantService.getTenant(id); |
| 83 | - return success(TenantConvert.INSTANCE.convert(tenant)); | |
| 87 | + return success(BeanUtils.toBean(tenant, TenantRespVO.class)); | |
| 84 | 88 | } |
| 85 | 89 | |
| 86 | 90 | @GetMapping("/page") |
| ... | ... | @@ -88,19 +92,20 @@ public class TenantController { |
| 88 | 92 | @PreAuthorize("@ss.hasPermission('system:tenant:query')") |
| 89 | 93 | public CommonResult<PageResult<TenantRespVO>> getTenantPage(@Valid TenantPageReqVO pageVO) { |
| 90 | 94 | PageResult<TenantDO> pageResult = tenantService.getTenantPage(pageVO); |
| 91 | - return success(TenantConvert.INSTANCE.convertPage(pageResult)); | |
| 95 | + return success(BeanUtils.toBean(pageResult, TenantRespVO.class)); | |
| 92 | 96 | } |
| 93 | 97 | |
| 94 | 98 | @GetMapping("/export-excel") |
| 95 | 99 | @Operation(summary = "导出租户 Excel") |
| 96 | 100 | @PreAuthorize("@ss.hasPermission('system:tenant:export')") |
| 97 | 101 | @OperateLog(type = EXPORT) |
| 98 | - public void exportTenantExcel(@Valid TenantExportReqVO exportReqVO, | |
| 102 | + public void exportTenantExcel(@Valid TenantPageReqVO exportReqVO, | |
| 99 | 103 | HttpServletResponse response) throws IOException { |
| 100 | - List<TenantDO> list = tenantService.getTenantList(exportReqVO); | |
| 104 | + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 105 | + List<TenantDO> list = tenantService.getTenantPage(exportReqVO).getList(); | |
| 101 | 106 | // 导出 Excel |
| 102 | - List<TenantExcelVO> datas = TenantConvert.INSTANCE.convertList02(list); | |
| 103 | - ExcelUtils.write(response, "租户.xls", "数据", TenantExcelVO.class, datas); | |
| 107 | + ExcelUtils.write(response, "租户.xls", "数据", TenantRespVO.class, | |
| 108 | + BeanUtils.toBean(list, TenantRespVO.class)); | |
| 104 | 109 | } |
| 105 | 110 | |
| 106 | 111 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/TenantPackageController.java
| ... | ... | @@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.system.controller.admin.tenant; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 6 | 7 | import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.*; |
| 7 | -import cn.iocoder.yudao.module.system.convert.tenant.TenantPackageConvert; | |
| 8 | 8 | import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO; |
| 9 | 9 | import cn.iocoder.yudao.module.system.service.tenant.TenantPackageService; |
| 10 | 10 | import io.swagger.v3.oas.annotations.tags.Tag; |
| ... | ... | @@ -32,14 +32,14 @@ public class TenantPackageController { |
| 32 | 32 | @PostMapping("/create") |
| 33 | 33 | @Operation(summary = "创建租户套餐") |
| 34 | 34 | @PreAuthorize("@ss.hasPermission('system:tenant-package:create')") |
| 35 | - public CommonResult<Long> createTenantPackage(@Valid @RequestBody TenantPackageCreateReqVO createReqVO) { | |
| 35 | + public CommonResult<Long> createTenantPackage(@Valid @RequestBody TenantPackageSaveReqVO createReqVO) { | |
| 36 | 36 | return success(tenantPackageService.createTenantPackage(createReqVO)); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | @PutMapping("/update") |
| 40 | 40 | @Operation(summary = "更新租户套餐") |
| 41 | 41 | @PreAuthorize("@ss.hasPermission('system:tenant-package:update')") |
| 42 | - public CommonResult<Boolean> updateTenantPackage(@Valid @RequestBody TenantPackageUpdateReqVO updateReqVO) { | |
| 42 | + public CommonResult<Boolean> updateTenantPackage(@Valid @RequestBody TenantPackageSaveReqVO updateReqVO) { | |
| 43 | 43 | tenantPackageService.updateTenantPackage(updateReqVO); |
| 44 | 44 | return success(true); |
| 45 | 45 | } |
| ... | ... | @@ -59,7 +59,7 @@ public class TenantPackageController { |
| 59 | 59 | @PreAuthorize("@ss.hasPermission('system:tenant-package:query')") |
| 60 | 60 | public CommonResult<TenantPackageRespVO> getTenantPackage(@RequestParam("id") Long id) { |
| 61 | 61 | TenantPackageDO tenantPackage = tenantPackageService.getTenantPackage(id); |
| 62 | - return success(TenantPackageConvert.INSTANCE.convert(tenantPackage)); | |
| 62 | + return success(BeanUtils.toBean(tenantPackage, TenantPackageRespVO.class)); | |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | @GetMapping("/page") |
| ... | ... | @@ -67,15 +67,14 @@ public class TenantPackageController { |
| 67 | 67 | @PreAuthorize("@ss.hasPermission('system:tenant-package:query')") |
| 68 | 68 | public CommonResult<PageResult<TenantPackageRespVO>> getTenantPackagePage(@Valid TenantPackagePageReqVO pageVO) { |
| 69 | 69 | PageResult<TenantPackageDO> pageResult = tenantPackageService.getTenantPackagePage(pageVO); |
| 70 | - return success(TenantPackageConvert.INSTANCE.convertPage(pageResult)); | |
| 70 | + return success(BeanUtils.toBean(pageResult, TenantPackageRespVO.class)); | |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - @GetMapping("/get-simple-list") | |
| 73 | + @GetMapping({"/get-simple-list", "simple-list"}) | |
| 74 | 74 | @Operation(summary = "获取租户套餐精简信息列表", description = "只包含被开启的租户套餐,主要用于前端的下拉选项") |
| 75 | 75 | public CommonResult<List<TenantPackageSimpleRespVO>> getTenantPackageList() { |
| 76 | - // 获得角色列表,只要开启状态的 | |
| 77 | 76 | List<TenantPackageDO> list = tenantPackageService.getTenantPackageListByStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 78 | - return success(TenantPackageConvert.INSTANCE.convertList02(list)); | |
| 77 | + return success(BeanUtils.toBean(list, TenantPackageSimpleRespVO.class)); | |
| 79 | 78 | } |
| 80 | 79 | |
| 81 | 80 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageCreateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | -import lombok.EqualsAndHashCode; | |
| 6 | -import lombok.ToString; | |
| 7 | - | |
| 8 | -@Schema(description = "管理后台 - 租户套餐创建 Request VO") | |
| 9 | -@Data | |
| 10 | -@EqualsAndHashCode(callSuper = true) | |
| 11 | -@ToString(callSuper = true) | |
| 12 | -public class TenantPackageCreateReqVO extends TenantPackageBaseVO { | |
| 13 | - | |
| 14 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageRespVO.java
| ... | ... | @@ -2,20 +2,29 @@ package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages; |
| 2 | 2 | |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 4 | import lombok.Data; |
| 5 | -import lombok.EqualsAndHashCode; | |
| 6 | -import lombok.ToString; | |
| 7 | 5 | |
| 8 | 6 | import java.time.LocalDateTime; |
| 7 | +import java.util.Set; | |
| 9 | 8 | |
| 10 | 9 | @Schema(description = "管理后台 - 租户套餐 Response VO") |
| 11 | 10 | @Data |
| 12 | -@EqualsAndHashCode(callSuper = true) | |
| 13 | -@ToString(callSuper = true) | |
| 14 | -public class TenantPackageRespVO extends TenantPackageBaseVO { | |
| 11 | +public class TenantPackageRespVO { | |
| 15 | 12 | |
| 16 | 13 | @Schema(description = "套餐编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 17 | 14 | private Long id; |
| 18 | 15 | |
| 16 | + @Schema(description = "套餐名", requiredMode = Schema.RequiredMode.REQUIRED, example = "VIP") | |
| 17 | + private String name; | |
| 18 | + | |
| 19 | + @Schema(description = "状态,参见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 20 | + private Integer status; | |
| 21 | + | |
| 22 | + @Schema(description = "备注", example = "好") | |
| 23 | + private String remark; | |
| 24 | + | |
| 25 | + @Schema(description = "关联的菜单编号", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 26 | + private Set<Long> menuIds; | |
| 27 | + | |
| 19 | 28 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) |
| 20 | 29 | private LocalDateTime createTime; |
| 21 | 30 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageBaseVO.java renamed to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageSaveReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 4 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 3 | 5 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 6 | import lombok.Data; |
| 5 | 7 | |
| 8 | +import javax.validation.constraints.NotEmpty; | |
| 6 | 9 | import javax.validation.constraints.NotNull; |
| 7 | 10 | import java.util.Set; |
| 8 | 11 | |
| 9 | -/** | |
| 10 | - * 租户套餐 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 11 | - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 12 | - */ | |
| 12 | +@Schema(description = "管理后台 - 租户套餐创建/修改 Request VO") | |
| 13 | 13 | @Data |
| 14 | -public class TenantPackageBaseVO { | |
| 14 | +public class TenantPackageSaveReqVO { | |
| 15 | + | |
| 16 | + @Schema(description = "套餐编号", example = "1024") | |
| 17 | + private Long id; | |
| 15 | 18 | |
| 16 | 19 | @Schema(description = "套餐名", requiredMode = Schema.RequiredMode.REQUIRED, example = "VIP") |
| 17 | - @NotNull(message = "套餐名不能为空") | |
| 20 | + @NotEmpty(message = "套餐名不能为空") | |
| 18 | 21 | private String name; |
| 19 | 22 | |
| 20 | 23 | @Schema(description = "状态,参见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 21 | 24 | @NotNull(message = "状态不能为空") |
| 25 | + @InEnum(value = CommonStatusEnum.class, message = "状态必须是 {value}") | |
| 22 | 26 | private Integer status; |
| 23 | 27 | |
| 24 | 28 | @Schema(description = "备注", example = "好") | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageUpdateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.*; | |
| 5 | -import javax.validation.constraints.*; | |
| 6 | - | |
| 7 | -@Schema(description = "管理后台 - 租户套餐更新 Request VO") | |
| 8 | -@Data | |
| 9 | -@EqualsAndHashCode(callSuper = true) | |
| 10 | -@ToString(callSuper = true) | |
| 11 | -public class TenantPackageUpdateReqVO extends TenantPackageBaseVO { | |
| 12 | - | |
| 13 | - @Schema(description = "套餐编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 14 | - @NotNull(message = "套餐编号不能为空") | |
| 15 | - private Long id; | |
| 16 | - | |
| 17 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantCreateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.*; | |
| 5 | -import org.hibernate.validator.constraints.Length; | |
| 6 | - | |
| 7 | -import javax.validation.constraints.NotBlank; | |
| 8 | -import javax.validation.constraints.NotEmpty; | |
| 9 | -import javax.validation.constraints.Pattern; | |
| 10 | -import javax.validation.constraints.Size; | |
| 11 | - | |
| 12 | -@Schema(description = "管理后台 - 租户创建 Request VO") | |
| 13 | -@Data | |
| 14 | -@EqualsAndHashCode(callSuper = true) | |
| 15 | -@ToString(callSuper = true) | |
| 16 | -public class TenantCreateReqVO extends TenantBaseVO { | |
| 17 | - | |
| 18 | - @Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao") | |
| 19 | - @NotBlank(message = "用户账号不能为空") | |
| 20 | - @Pattern(regexp = "^[a-zA-Z0-9]{4,30}$", message = "用户账号由 数字、字母 组成") | |
| 21 | - @Size(min = 4, max = 30, message = "用户账号长度为 4-30 个字符") | |
| 22 | - private String username; | |
| 23 | - | |
| 24 | - @Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456") | |
| 25 | - @NotEmpty(message = "密码不能为空") | |
| 26 | - @Length(min = 4, max = 16, message = "密码长度为 4-16 位") | |
| 27 | - private String password; | |
| 28 | - | |
| 29 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantExcelVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.module.system.enums.DictTypeConstants; | |
| 4 | -import lombok.*; | |
| 5 | -import java.time.LocalDateTime; | |
| 6 | - | |
| 7 | -import com.alibaba.excel.annotation.ExcelProperty; | |
| 8 | -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 9 | -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 10 | - | |
| 11 | - | |
| 12 | -/** | |
| 13 | - * 租户 Excel VO | |
| 14 | - * | |
| 15 | - * @author 芋道源码 | |
| 16 | - */ | |
| 17 | -@Data | |
| 18 | -public class TenantExcelVO { | |
| 19 | - | |
| 20 | - @ExcelProperty("租户编号") | |
| 21 | - private Long id; | |
| 22 | - | |
| 23 | - @ExcelProperty("租户名") | |
| 24 | - private String name; | |
| 25 | - | |
| 26 | - @ExcelProperty("联系人") | |
| 27 | - private String contactName; | |
| 28 | - | |
| 29 | - @ExcelProperty("联系手机") | |
| 30 | - private String contactMobile; | |
| 31 | - | |
| 32 | - @ExcelProperty(value = "状态", converter = DictConvert.class) | |
| 33 | - @DictFormat(DictTypeConstants.COMMON_STATUS) | |
| 34 | - private Integer status; | |
| 35 | - | |
| 36 | - @ExcelProperty("创建时间") | |
| 37 | - private LocalDateTime createTime; | |
| 38 | - | |
| 39 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantExportReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | -import org.springframework.format.annotation.DateTimeFormat; | |
| 6 | - | |
| 7 | -import java.time.LocalDateTime; | |
| 8 | - | |
| 9 | -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 10 | - | |
| 11 | -@Schema(description = "管理后台 - 租户 Excel 导出 Request VO,参数和 TenantPageReqVO 是一致的") | |
| 12 | -@Data | |
| 13 | -public class TenantExportReqVO { | |
| 14 | - | |
| 15 | - @Schema(description = "租户名", example = "芋道") | |
| 16 | - private String name; | |
| 17 | - | |
| 18 | - @Schema(description = "联系人", example = "芋艿") | |
| 19 | - private String contactName; | |
| 20 | - | |
| 21 | - @Schema(description = "联系手机", example = "15601691300") | |
| 22 | - private String contactMobile; | |
| 23 | - | |
| 24 | - @Schema(description = "租户状态(0正常 1停用)", example = "1") | |
| 25 | - private Integer status; | |
| 26 | - | |
| 27 | - @Schema(description = "创建时间") | |
| 28 | - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 29 | - private LocalDateTime[] createTime; | |
| 30 | - | |
| 31 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantRespVO.java
| 1 | 1 | package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 4 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 5 | +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; | |
| 6 | +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | |
| 7 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 3 | 8 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | -import lombok.*; | |
| 9 | +import lombok.Data; | |
| 5 | 10 | |
| 6 | 11 | import java.time.LocalDateTime; |
| 7 | 12 | |
| 8 | 13 | @Schema(description = "管理后台 - 租户 Response VO") |
| 9 | 14 | @Data |
| 10 | -@EqualsAndHashCode(callSuper = true) | |
| 11 | -@ToString(callSuper = true) | |
| 12 | -public class TenantRespVO extends TenantBaseVO { | |
| 15 | +@ExcelIgnoreUnannotated | |
| 16 | +public class TenantRespVO { | |
| 13 | 17 | |
| 14 | 18 | @Schema(description = "租户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 19 | + @ExcelProperty("租户编号") | |
| 15 | 20 | private Long id; |
| 16 | 21 | |
| 22 | + @Schema(description = "租户名", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") | |
| 23 | + @ExcelProperty("租户名") | |
| 24 | + private String name; | |
| 25 | + | |
| 26 | + @Schema(description = "联系人", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") | |
| 27 | + @ExcelProperty("联系人") | |
| 28 | + private String contactName; | |
| 29 | + | |
| 30 | + @Schema(description = "联系手机", example = "15601691300") | |
| 31 | + @ExcelProperty("联系手机") | |
| 32 | + private String contactMobile; | |
| 33 | + | |
| 34 | + @Schema(description = "租户状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 35 | + @ExcelProperty(value = "状态", converter = DictConvert.class) | |
| 36 | + @DictFormat(DictTypeConstants.COMMON_STATUS) | |
| 37 | + private Integer status; | |
| 38 | + | |
| 39 | + @Schema(description = "绑定域名", example = "https://www.iocoder.cn") | |
| 40 | + private String website; | |
| 41 | + | |
| 42 | + @Schema(description = "租户套餐编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 43 | + private Long packageId; | |
| 44 | + | |
| 45 | + @Schema(description = "过期时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 46 | + private LocalDateTime expireTime; | |
| 47 | + | |
| 48 | + @Schema(description = "账号数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 49 | + private Integer accountCount; | |
| 50 | + | |
| 17 | 51 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) |
| 52 | + @ExcelProperty("创建时间") | |
| 18 | 53 | private LocalDateTime createTime; |
| 19 | 54 | |
| 20 | 55 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantBaseVO.java renamed to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantSaveReqVO.java
100755 → 100644
| 1 | 1 | package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.util.ObjectUtil; | |
| 4 | +import com.fasterxml.jackson.annotation.JsonIgnore; | |
| 3 | 5 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | -import lombok.*; | |
| 6 | +import lombok.Data; | |
| 7 | +import org.hibernate.validator.constraints.Length; | |
| 5 | 8 | |
| 6 | -import javax.validation.constraints.*; | |
| 9 | +import javax.validation.constraints.AssertTrue; | |
| 10 | +import javax.validation.constraints.NotNull; | |
| 11 | +import javax.validation.constraints.Pattern; | |
| 12 | +import javax.validation.constraints.Size; | |
| 7 | 13 | import java.time.LocalDateTime; |
| 8 | 14 | |
| 9 | -/** | |
| 10 | - * 租户 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 11 | - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 12 | - */ | |
| 15 | +@Schema(description = "管理后台 - 租户创建/修改 Request VO") | |
| 13 | 16 | @Data |
| 14 | -public class TenantBaseVO { | |
| 17 | +public class TenantSaveReqVO { | |
| 18 | + | |
| 19 | + @Schema(description = "租户编号", example = "1024") | |
| 20 | + private Long id; | |
| 15 | 21 | |
| 16 | 22 | @Schema(description = "租户名", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") |
| 17 | 23 | @NotNull(message = "租户名不能为空") |
| ... | ... | @@ -43,4 +49,22 @@ public class TenantBaseVO { |
| 43 | 49 | @NotNull(message = "账号数量不能为空") |
| 44 | 50 | private Integer accountCount; |
| 45 | 51 | |
| 52 | + // ========== 仅【创建】时,需要传递的字段 ========== | |
| 53 | + | |
| 54 | + @Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao") | |
| 55 | + @Pattern(regexp = "^[a-zA-Z0-9]{4,30}$", message = "用户账号由 数字、字母 组成") | |
| 56 | + @Size(min = 4, max = 30, message = "用户账号长度为 4-30 个字符") | |
| 57 | + private String username; | |
| 58 | + | |
| 59 | + @Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456") | |
| 60 | + @Length(min = 4, max = 16, message = "密码长度为 4-16 位") | |
| 61 | + private String password; | |
| 62 | + | |
| 63 | + @AssertTrue(message = "用户账号、密码不能为空") | |
| 64 | + @JsonIgnore | |
| 65 | + public boolean isUsernameValid() { | |
| 66 | + return id != null // 修改时,不需要传递 | |
| 67 | + || (ObjectUtil.isAllNotEmpty(username, password)); // 新增时,必须都传递 username、password | |
| 68 | + } | |
| 69 | + | |
| 46 | 70 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantSimpleRespVO.java
| ... | ... | @@ -2,14 +2,10 @@ package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant; |
| 2 | 2 | |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 4 | import lombok.Data; |
| 5 | -import lombok.EqualsAndHashCode; | |
| 6 | -import lombok.ToString; | |
| 7 | 5 | |
| 8 | 6 | @Schema(description = "管理后台 - 租户精简 Response VO") |
| 9 | 7 | @Data |
| 10 | -@EqualsAndHashCode(callSuper = true) | |
| 11 | -@ToString(callSuper = true) | |
| 12 | -public class TenantSimpleRespVO extends TenantBaseVO { | |
| 8 | +public class TenantSimpleRespVO { | |
| 13 | 9 | |
| 14 | 10 | @Schema(description = "租户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 15 | 11 | private Long id; | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantUpdateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.*; | |
| 5 | -import javax.validation.constraints.*; | |
| 6 | - | |
| 7 | -@Schema(description = "管理后台 - 租户更新 Request VO") | |
| 8 | -@Data | |
| 9 | -@EqualsAndHashCode(callSuper = true) | |
| 10 | -@ToString(callSuper = true) | |
| 11 | -public class TenantUpdateReqVO extends TenantBaseVO { | |
| 12 | - | |
| 13 | - @Schema(description = "租户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 14 | - @NotNull(message = "租户编号不能为空") | |
| 15 | - private Long id; | |
| 16 | - | |
| 17 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/tenant/TenantConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.system.convert.tenant; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.*; | |
| 3 | +import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantSaveReqVO; | |
| 5 | 4 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserCreateReqVO; |
| 6 | -import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; | |
| 7 | 5 | import org.mapstruct.Mapper; |
| 8 | 6 | import org.mapstruct.factory.Mappers; |
| 9 | 7 | |
| 10 | -import java.util.List; | |
| 11 | - | |
| 12 | 8 | /** |
| 13 | 9 | * 租户 Convert |
| 14 | 10 | * |
| ... | ... | @@ -19,21 +15,7 @@ public interface TenantConvert { |
| 19 | 15 | |
| 20 | 16 | TenantConvert INSTANCE = Mappers.getMapper(TenantConvert.class); |
| 21 | 17 | |
| 22 | - TenantDO convert(TenantCreateReqVO bean); | |
| 23 | - | |
| 24 | - TenantDO convert(TenantUpdateReqVO bean); | |
| 25 | - | |
| 26 | - TenantRespVO convert(TenantDO bean); | |
| 27 | - | |
| 28 | - TenantSimpleRespVO convert03(TenantDO bean); | |
| 29 | - | |
| 30 | - List<TenantRespVO> convertList(List<TenantDO> list); | |
| 31 | - | |
| 32 | - PageResult<TenantRespVO> convertPage(PageResult<TenantDO> page); | |
| 33 | - | |
| 34 | - List<TenantExcelVO> convertList02(List<TenantDO> list); | |
| 35 | - | |
| 36 | - default UserCreateReqVO convert02(TenantCreateReqVO bean) { | |
| 18 | + default UserCreateReqVO convert02(TenantSaveReqVO bean) { | |
| 37 | 19 | UserCreateReqVO reqVO = new UserCreateReqVO(); |
| 38 | 20 | reqVO.setUsername(bean.getUsername()); |
| 39 | 21 | reqVO.setPassword(bean.getPassword()); | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/tenant/TenantPackageConvert.java deleted
| 1 | -package cn.iocoder.yudao.module.system.convert.tenant; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleSimpleRespVO; | |
| 5 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageCreateReqVO; | |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageRespVO; | |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageSimpleRespVO; | |
| 8 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageUpdateReqVO; | |
| 9 | -import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO; | |
| 10 | -import org.mapstruct.Mapper; | |
| 11 | -import org.mapstruct.factory.Mappers; | |
| 12 | - | |
| 13 | -import java.util.List; | |
| 14 | - | |
| 15 | -/** | |
| 16 | - * 租户套餐 Convert | |
| 17 | - * | |
| 18 | - * @author 芋道源码 | |
| 19 | - */ | |
| 20 | -@Mapper | |
| 21 | -public interface TenantPackageConvert { | |
| 22 | - | |
| 23 | - TenantPackageConvert INSTANCE = Mappers.getMapper(TenantPackageConvert.class); | |
| 24 | - | |
| 25 | - TenantPackageDO convert(TenantPackageCreateReqVO bean); | |
| 26 | - | |
| 27 | - TenantPackageDO convert(TenantPackageUpdateReqVO bean); | |
| 28 | - | |
| 29 | - TenantPackageRespVO convert(TenantPackageDO bean); | |
| 30 | - | |
| 31 | - List<TenantPackageRespVO> convertList(List<TenantPackageDO> list); | |
| 32 | - | |
| 33 | - PageResult<TenantPackageRespVO> convertPage(PageResult<TenantPackageDO> page); | |
| 34 | - | |
| 35 | - List<TenantPackageSimpleRespVO> convertList02(List<TenantPackageDO> list); | |
| 36 | - | |
| 37 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenant/TenantMapper.java
| ... | ... | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.dal.mysql.tenant; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantExportReqVO; | |
| 7 | 6 | import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO; |
| 8 | 7 | import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; |
| 9 | 8 | import org.apache.ibatis.annotations.Mapper; |
| ... | ... | @@ -28,16 +27,6 @@ public interface TenantMapper extends BaseMapperX<TenantDO> { |
| 28 | 27 | .orderByDesc(TenantDO::getId)); |
| 29 | 28 | } |
| 30 | 29 | |
| 31 | - default List<TenantDO> selectList(TenantExportReqVO reqVO) { | |
| 32 | - return selectList(new LambdaQueryWrapperX<TenantDO>() | |
| 33 | - .likeIfPresent(TenantDO::getName, reqVO.getName()) | |
| 34 | - .likeIfPresent(TenantDO::getContactName, reqVO.getContactName()) | |
| 35 | - .likeIfPresent(TenantDO::getContactMobile, reqVO.getContactMobile()) | |
| 36 | - .eqIfPresent(TenantDO::getStatus, reqVO.getStatus()) | |
| 37 | - .betweenIfPresent(TenantDO::getCreateTime, reqVO.getCreateTime()) | |
| 38 | - .orderByDesc(TenantDO::getId)); | |
| 39 | - } | |
| 40 | - | |
| 41 | 30 | default TenantDO selectByName(String name) { |
| 42 | 31 | return selectOne(TenantDO::getName, name); |
| 43 | 32 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageService.java
| 1 | 1 | package cn.iocoder.yudao.module.system.service.tenant; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageCreateReqVO; | |
| 5 | 4 | import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackagePageReqVO; |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageUpdateReqVO; | |
| 5 | +import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageSaveReqVO; | |
| 7 | 6 | import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO; |
| 8 | 7 | |
| 9 | 8 | import javax.validation.Valid; |
| ... | ... | @@ -22,14 +21,14 @@ public interface TenantPackageService { |
| 22 | 21 | * @param createReqVO 创建信息 |
| 23 | 22 | * @return 编号 |
| 24 | 23 | */ |
| 25 | - Long createTenantPackage(@Valid TenantPackageCreateReqVO createReqVO); | |
| 24 | + Long createTenantPackage(@Valid TenantPackageSaveReqVO createReqVO); | |
| 26 | 25 | |
| 27 | 26 | /** |
| 28 | 27 | * 更新租户套餐 |
| 29 | 28 | * |
| 30 | 29 | * @param updateReqVO 更新信息 |
| 31 | 30 | */ |
| 32 | - void updateTenantPackage(@Valid TenantPackageUpdateReqVO updateReqVO); | |
| 31 | + void updateTenantPackage(@Valid TenantPackageSaveReqVO updateReqVO); | |
| 33 | 32 | |
| 34 | 33 | /** |
| 35 | 34 | * 删除租户套餐 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageServiceImpl.java
| ... | ... | @@ -3,10 +3,9 @@ package cn.iocoder.yudao.module.system.service.tenant; |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageCreateReqVO; | |
| 6 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 7 | 7 | import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackagePageReqVO; |
| 8 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageUpdateReqVO; | |
| 9 | -import cn.iocoder.yudao.module.system.convert.tenant.TenantPackageConvert; | |
| 8 | +import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageSaveReqVO; | |
| 10 | 9 | import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; |
| 11 | 10 | import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO; |
| 12 | 11 | import cn.iocoder.yudao.module.system.dal.mysql.tenant.TenantPackageMapper; |
| ... | ... | @@ -38,9 +37,9 @@ public class TenantPackageServiceImpl implements TenantPackageService { |
| 38 | 37 | private TenantService tenantService; |
| 39 | 38 | |
| 40 | 39 | @Override |
| 41 | - public Long createTenantPackage(TenantPackageCreateReqVO createReqVO) { | |
| 40 | + public Long createTenantPackage(TenantPackageSaveReqVO createReqVO) { | |
| 42 | 41 | // 插入 |
| 43 | - TenantPackageDO tenantPackage = TenantPackageConvert.INSTANCE.convert(createReqVO); | |
| 42 | + TenantPackageDO tenantPackage = BeanUtils.toBean(createReqVO, TenantPackageDO.class); | |
| 44 | 43 | tenantPackageMapper.insert(tenantPackage); |
| 45 | 44 | // 返回 |
| 46 | 45 | return tenantPackage.getId(); |
| ... | ... | @@ -48,11 +47,11 @@ public class TenantPackageServiceImpl implements TenantPackageService { |
| 48 | 47 | |
| 49 | 48 | @Override |
| 50 | 49 | @DSTransactional // 多数据源,使用 @DSTransactional 保证本地事务,以及数据源的切换 |
| 51 | - public void updateTenantPackage(TenantPackageUpdateReqVO updateReqVO) { | |
| 50 | + public void updateTenantPackage(TenantPackageSaveReqVO updateReqVO) { | |
| 52 | 51 | // 校验存在 |
| 53 | 52 | TenantPackageDO tenantPackage = validateTenantPackageExists(updateReqVO.getId()); |
| 54 | 53 | // 更新 |
| 55 | - TenantPackageDO updateObj = TenantPackageConvert.INSTANCE.convert(updateReqVO); | |
| 54 | + TenantPackageDO updateObj = BeanUtils.toBean(updateReqVO, TenantPackageDO.class); | |
| 56 | 55 | tenantPackageMapper.updateById(updateObj); |
| 57 | 56 | // 如果菜单发生变化,则修改每个租户的菜单 |
| 58 | 57 | if (!CollUtil.isEqualList(tenantPackage.getMenuIds(), updateReqVO.getMenuIds())) { | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantService.java
| ... | ... | @@ -2,10 +2,8 @@ package cn.iocoder.yudao.module.system.service.tenant; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; |
| 5 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantCreateReqVO; | |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantExportReqVO; | |
| 7 | 5 | import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO; |
| 8 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantUpdateReqVO; | |
| 6 | +import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantSaveReqVO; | |
| 9 | 7 | import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; |
| 10 | 8 | import cn.iocoder.yudao.module.system.service.tenant.handler.TenantInfoHandler; |
| 11 | 9 | import cn.iocoder.yudao.module.system.service.tenant.handler.TenantMenuHandler; |
| ... | ... | @@ -27,14 +25,14 @@ public interface TenantService { |
| 27 | 25 | * @param createReqVO 创建信息 |
| 28 | 26 | * @return 编号 |
| 29 | 27 | */ |
| 30 | - Long createTenant(@Valid TenantCreateReqVO createReqVO); | |
| 28 | + Long createTenant(@Valid TenantSaveReqVO createReqVO); | |
| 31 | 29 | |
| 32 | 30 | /** |
| 33 | 31 | * 更新租户 |
| 34 | 32 | * |
| 35 | 33 | * @param updateReqVO 更新信息 |
| 36 | 34 | */ |
| 37 | - void updateTenant(@Valid TenantUpdateReqVO updateReqVO); | |
| 35 | + void updateTenant(@Valid TenantSaveReqVO updateReqVO); | |
| 38 | 36 | |
| 39 | 37 | /** |
| 40 | 38 | * 更新租户的角色菜单 |
| ... | ... | @@ -68,14 +66,6 @@ public interface TenantService { |
| 68 | 66 | PageResult<TenantDO> getTenantPage(TenantPageReqVO pageReqVO); |
| 69 | 67 | |
| 70 | 68 | /** |
| 71 | - * 获得租户列表, 用于 Excel 导出 | |
| 72 | - * | |
| 73 | - * @param exportReqVO 查询条件 | |
| 74 | - * @return 租户列表 | |
| 75 | - */ | |
| 76 | - List<TenantDO> getTenantList(TenantExportReqVO exportReqVO); | |
| 77 | - | |
| 78 | - /** | |
| 79 | 69 | * 获得名字对应的租户 |
| 80 | 70 | * |
| 81 | 71 | * @param name 租户名 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java
| ... | ... | @@ -8,14 +8,13 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 8 | 8 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 9 | 9 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 10 | 10 | import cn.iocoder.yudao.framework.common.util.date.DateUtils; |
| 11 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 11 | 12 | import cn.iocoder.yudao.framework.tenant.config.TenantProperties; |
| 12 | 13 | import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; |
| 13 | 14 | import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; |
| 14 | 15 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleSaveReqVO; |
| 15 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantCreateReqVO; | |
| 16 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantExportReqVO; | |
| 17 | 16 | import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO; |
| 18 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantUpdateReqVO; | |
| 17 | +import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantSaveReqVO; | |
| 19 | 18 | import cn.iocoder.yudao.module.system.convert.tenant.TenantConvert; |
| 20 | 19 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; |
| 21 | 20 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; |
| ... | ... | @@ -97,7 +96,7 @@ public class TenantServiceImpl implements TenantService { |
| 97 | 96 | |
| 98 | 97 | @Override |
| 99 | 98 | @DSTransactional // 多数据源,使用 @DSTransactional 保证本地事务,以及数据源的切换 |
| 100 | - public Long createTenant(TenantCreateReqVO createReqVO) { | |
| 99 | + public Long createTenant(TenantSaveReqVO createReqVO) { | |
| 101 | 100 | // 校验租户名称是否重复 |
| 102 | 101 | validTenantNameDuplicate(createReqVO.getName(), null); |
| 103 | 102 | // 校验租户域名是否重复 |
| ... | ... | @@ -106,9 +105,9 @@ public class TenantServiceImpl implements TenantService { |
| 106 | 105 | TenantPackageDO tenantPackage = tenantPackageService.validTenantPackage(createReqVO.getPackageId()); |
| 107 | 106 | |
| 108 | 107 | // 创建租户 |
| 109 | - TenantDO tenant = TenantConvert.INSTANCE.convert(createReqVO); | |
| 108 | + TenantDO tenant = BeanUtils.toBean(createReqVO, TenantDO.class); | |
| 110 | 109 | tenantMapper.insert(tenant); |
| 111 | - | |
| 110 | + // 创建租户的管理员 | |
| 112 | 111 | TenantUtils.execute(tenant.getId(), () -> { |
| 113 | 112 | // 创建角色 |
| 114 | 113 | Long roleId = createRole(tenantPackage); |
| ... | ... | @@ -120,7 +119,7 @@ public class TenantServiceImpl implements TenantService { |
| 120 | 119 | return tenant.getId(); |
| 121 | 120 | } |
| 122 | 121 | |
| 123 | - private Long createUser(Long roleId, TenantCreateReqVO createReqVO) { | |
| 122 | + private Long createUser(Long roleId, TenantSaveReqVO createReqVO) { | |
| 124 | 123 | // 创建用户 |
| 125 | 124 | Long userId = userService.createUser(TenantConvert.INSTANCE.convert02(createReqVO)); |
| 126 | 125 | // 分配角色 |
| ... | ... | @@ -140,8 +139,8 @@ public class TenantServiceImpl implements TenantService { |
| 140 | 139 | } |
| 141 | 140 | |
| 142 | 141 | @Override |
| 143 | - @DSTransactional | |
| 144 | - public void updateTenant(TenantUpdateReqVO updateReqVO) { | |
| 142 | + @DSTransactional // 多数据源,使用 @DSTransactional 保证本地事务,以及数据源的切换 | |
| 143 | + public void updateTenant(TenantSaveReqVO updateReqVO) { | |
| 145 | 144 | // 校验存在 |
| 146 | 145 | TenantDO tenant = validateUpdateTenant(updateReqVO.getId()); |
| 147 | 146 | // 校验租户名称是否重复 |
| ... | ... | @@ -152,7 +151,7 @@ public class TenantServiceImpl implements TenantService { |
| 152 | 151 | TenantPackageDO tenantPackage = tenantPackageService.validTenantPackage(updateReqVO.getPackageId()); |
| 153 | 152 | |
| 154 | 153 | // 更新租户 |
| 155 | - TenantDO updateObj = TenantConvert.INSTANCE.convert(updateReqVO); | |
| 154 | + TenantDO updateObj = BeanUtils.toBean(updateReqVO, TenantDO.class); | |
| 156 | 155 | tenantMapper.updateById(updateObj); |
| 157 | 156 | // 如果套餐发生变化,则修改其角色的权限 |
| 158 | 157 | if (ObjectUtil.notEqual(tenant.getPackageId(), updateReqVO.getPackageId())) { |
| ... | ... | @@ -247,11 +246,6 @@ public class TenantServiceImpl implements TenantService { |
| 247 | 246 | } |
| 248 | 247 | |
| 249 | 248 | @Override |
| 250 | - public List<TenantDO> getTenantList(TenantExportReqVO exportReqVO) { | |
| 251 | - return tenantMapper.selectList(exportReqVO); | |
| 252 | - } | |
| 253 | - | |
| 254 | - @Override | |
| 255 | 249 | public TenantDO getTenantByName(String name) { |
| 256 | 250 | return tenantMapper.selectByName(name); |
| 257 | 251 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageServiceImplTest.java
| ... | ... | @@ -3,9 +3,8 @@ package cn.iocoder.yudao.module.system.service.tenant; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageCreateReqVO; | |
| 7 | 6 | import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackagePageReqVO; |
| 8 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageUpdateReqVO; | |
| 7 | +import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageSaveReqVO; | |
| 9 | 8 | import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; |
| 10 | 9 | import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO; |
| 11 | 10 | import cn.iocoder.yudao.module.system.dal.mysql.tenant.TenantPackageMapper; |
| ... | ... | @@ -14,7 +13,6 @@ import org.springframework.boot.test.mock.mockito.MockBean; |
| 14 | 13 | import org.springframework.context.annotation.Import; |
| 15 | 14 | |
| 16 | 15 | import javax.annotation.Resource; |
| 17 | - | |
| 18 | 16 | import java.util.List; |
| 19 | 17 | |
| 20 | 18 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; |
| ... | ... | @@ -22,8 +20,7 @@ import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.bui |
| 22 | 20 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; |
| 23 | 21 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 24 | 22 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| 25 | -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; | |
| 26 | -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | |
| 23 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | |
| 27 | 24 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; |
| 28 | 25 | import static java.util.Arrays.asList; |
| 29 | 26 | import static org.junit.jupiter.api.Assertions.*; |
| ... | ... | @@ -51,7 +48,9 @@ public class TenantPackageServiceImplTest extends BaseDbUnitTest { |
| 51 | 48 | @Test |
| 52 | 49 | public void testCreateTenantPackage_success() { |
| 53 | 50 | // 准备参数 |
| 54 | - TenantPackageCreateReqVO reqVO = randomPojo(TenantPackageCreateReqVO.class); | |
| 51 | + TenantPackageSaveReqVO reqVO = randomPojo(TenantPackageSaveReqVO.class, | |
| 52 | + o -> o.setStatus(randomCommonStatus())) | |
| 53 | + .setId(null); // 防止 id 被赋值 | |
| 55 | 54 | |
| 56 | 55 | // 调用 |
| 57 | 56 | Long tenantPackageId = tenantPackageService.createTenantPackage(reqVO); |
| ... | ... | @@ -59,17 +58,19 @@ public class TenantPackageServiceImplTest extends BaseDbUnitTest { |
| 59 | 58 | assertNotNull(tenantPackageId); |
| 60 | 59 | // 校验记录的属性是否正确 |
| 61 | 60 | TenantPackageDO tenantPackage = tenantPackageMapper.selectById(tenantPackageId); |
| 62 | - assertPojoEquals(reqVO, tenantPackage); | |
| 61 | + assertPojoEquals(reqVO, tenantPackage, "id"); | |
| 63 | 62 | } |
| 64 | 63 | |
| 65 | 64 | @Test |
| 66 | 65 | public void testUpdateTenantPackage_success() { |
| 67 | 66 | // mock 数据 |
| 68 | - TenantPackageDO dbTenantPackage = randomPojo(TenantPackageDO.class); | |
| 67 | + TenantPackageDO dbTenantPackage = randomPojo(TenantPackageDO.class, | |
| 68 | + o -> o.setStatus(randomCommonStatus())); | |
| 69 | 69 | tenantPackageMapper.insert(dbTenantPackage);// @Sql: 先插入出一条存在的数据 |
| 70 | 70 | // 准备参数 |
| 71 | - TenantPackageUpdateReqVO reqVO = randomPojo(TenantPackageUpdateReqVO.class, o -> { | |
| 71 | + TenantPackageSaveReqVO reqVO = randomPojo(TenantPackageSaveReqVO.class, o -> { | |
| 72 | 72 | o.setId(dbTenantPackage.getId()); // 设置更新的 ID |
| 73 | + o.setStatus(randomCommonStatus()); | |
| 73 | 74 | }); |
| 74 | 75 | // mock 方法 |
| 75 | 76 | Long tenantId01 = randomLongId(); |
| ... | ... | @@ -91,7 +92,7 @@ public class TenantPackageServiceImplTest extends BaseDbUnitTest { |
| 91 | 92 | @Test |
| 92 | 93 | public void testUpdateTenantPackage_notExists() { |
| 93 | 94 | // 准备参数 |
| 94 | - TenantPackageUpdateReqVO reqVO = randomPojo(TenantPackageUpdateReqVO.class); | |
| 95 | + TenantPackageSaveReqVO reqVO = randomPojo(TenantPackageSaveReqVO.class); | |
| 95 | 96 | |
| 96 | 97 | // 调用, 并断言异常 |
| 97 | 98 | assertServiceException(() -> tenantPackageService.updateTenantPackage(reqVO), TENANT_PACKAGE_NOT_EXISTS); | ... | ... |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImplTest.java
| ... | ... | @@ -5,10 +5,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.tenant.config.TenantProperties; |
| 6 | 6 | import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; |
| 7 | 7 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 8 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantCreateReqVO; | |
| 9 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantExportReqVO; | |
| 10 | 8 | import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO; |
| 11 | -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantUpdateReqVO; | |
| 9 | +import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantSaveReqVO; | |
| 12 | 10 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; |
| 13 | 11 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; |
| 14 | 12 | import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; |
| ... | ... | @@ -152,7 +150,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { |
| 152 | 150 | }))).thenReturn(300L); |
| 153 | 151 | |
| 154 | 152 | // 准备参数 |
| 155 | - TenantCreateReqVO reqVO = randomPojo(TenantCreateReqVO.class, o -> { | |
| 153 | + TenantSaveReqVO reqVO = randomPojo(TenantSaveReqVO.class, o -> { | |
| 156 | 154 | o.setContactName("芋道"); |
| 157 | 155 | o.setContactMobile("15601691300"); |
| 158 | 156 | o.setPackageId(100L); |
| ... | ... | @@ -160,7 +158,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { |
| 160 | 158 | o.setWebsite("https://www.iocoder.cn"); |
| 161 | 159 | o.setUsername("yunai"); |
| 162 | 160 | o.setPassword("yuanma"); |
| 163 | - }); | |
| 161 | + }).setId(null); // 设置为 null,方便后面校验 | |
| 164 | 162 | |
| 165 | 163 | // 调用 |
| 166 | 164 | Long tenantId = tenantService.createTenant(reqVO); |
| ... | ... | @@ -168,7 +166,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { |
| 168 | 166 | assertNotNull(tenantId); |
| 169 | 167 | // 校验记录的属性是否正确 |
| 170 | 168 | TenantDO tenant = tenantMapper.selectById(tenantId); |
| 171 | - assertPojoEquals(reqVO, tenant); | |
| 169 | + assertPojoEquals(reqVO, tenant, "id"); | |
| 172 | 170 | assertEquals(300L, tenant.getContactUserId()); |
| 173 | 171 | // verify 分配权限 |
| 174 | 172 | verify(permissionService).assignRoleMenu(eq(200L), same(tenantPackage.getMenuIds())); |
| ... | ... | @@ -182,7 +180,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { |
| 182 | 180 | TenantDO dbTenant = randomPojo(TenantDO.class, o -> o.setStatus(randomCommonStatus())); |
| 183 | 181 | tenantMapper.insert(dbTenant);// @Sql: 先插入出一条存在的数据 |
| 184 | 182 | // 准备参数 |
| 185 | - TenantUpdateReqVO reqVO = randomPojo(TenantUpdateReqVO.class, o -> { | |
| 183 | + TenantSaveReqVO reqVO = randomPojo(TenantSaveReqVO.class, o -> { | |
| 186 | 184 | o.setId(dbTenant.getId()); // 设置更新的 ID |
| 187 | 185 | o.setStatus(randomCommonStatus()); |
| 188 | 186 | o.setWebsite(randomString()); |
| ... | ... | @@ -214,7 +212,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { |
| 214 | 212 | @Test |
| 215 | 213 | public void testUpdateTenant_notExists() { |
| 216 | 214 | // 准备参数 |
| 217 | - TenantUpdateReqVO reqVO = randomPojo(TenantUpdateReqVO.class); | |
| 215 | + TenantSaveReqVO reqVO = randomPojo(TenantSaveReqVO.class); | |
| 218 | 216 | |
| 219 | 217 | // 调用, 并断言异常 |
| 220 | 218 | assertServiceException(() -> tenantService.updateTenant(reqVO), TENANT_NOT_EXISTS); |
| ... | ... | @@ -226,7 +224,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { |
| 226 | 224 | TenantDO dbTenant = randomPojo(TenantDO.class, o -> o.setPackageId(PACKAGE_ID_SYSTEM)); |
| 227 | 225 | tenantMapper.insert(dbTenant);// @Sql: 先插入出一条存在的数据 |
| 228 | 226 | // 准备参数 |
| 229 | - TenantUpdateReqVO reqVO = randomPojo(TenantUpdateReqVO.class, o -> { | |
| 227 | + TenantSaveReqVO reqVO = randomPojo(TenantSaveReqVO.class, o -> { | |
| 230 | 228 | o.setId(dbTenant.getId()); // 设置更新的 ID |
| 231 | 229 | }); |
| 232 | 230 | |
| ... | ... | @@ -322,42 +320,6 @@ public class TenantServiceImplTest extends BaseDbUnitTest { |
| 322 | 320 | } |
| 323 | 321 | |
| 324 | 322 | @Test |
| 325 | - public void testGetTenantList() { | |
| 326 | - // mock 数据 | |
| 327 | - TenantDO dbTenant = randomPojo(TenantDO.class, o -> { // 等会查询到 | |
| 328 | - o.setName("芋道源码"); | |
| 329 | - o.setContactName("芋艿"); | |
| 330 | - o.setContactMobile("15601691300"); | |
| 331 | - o.setStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 332 | - o.setCreateTime(buildTime(2020, 12, 12)); | |
| 333 | - }); | |
| 334 | - tenantMapper.insert(dbTenant); | |
| 335 | - // 测试 name 不匹配 | |
| 336 | - tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setName(randomString()))); | |
| 337 | - // 测试 contactName 不匹配 | |
| 338 | - tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setContactName(randomString()))); | |
| 339 | - // 测试 contactMobile 不匹配 | |
| 340 | - tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setContactMobile(randomString()))); | |
| 341 | - // 测试 status 不匹配 | |
| 342 | - tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); | |
| 343 | - // 测试 createTime 不匹配 | |
| 344 | - tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setCreateTime(buildTime(2021, 12, 12)))); | |
| 345 | - // 准备参数 | |
| 346 | - TenantExportReqVO reqVO = new TenantExportReqVO(); | |
| 347 | - reqVO.setName("芋道"); | |
| 348 | - reqVO.setContactName("艿"); | |
| 349 | - reqVO.setContactMobile("1560"); | |
| 350 | - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 351 | - reqVO.setCreateTime(buildBetweenTime(2020, 12, 1, 2020, 12, 24)); | |
| 352 | - | |
| 353 | - // 调用 | |
| 354 | - List<TenantDO> list = tenantService.getTenantList(reqVO); | |
| 355 | - // 断言 | |
| 356 | - assertEquals(1, list.size()); | |
| 357 | - assertPojoEquals(dbTenant, list.get(0)); | |
| 358 | - } | |
| 359 | - | |
| 360 | - @Test | |
| 361 | 323 | public void testGetTenantByName() { |
| 362 | 324 | // mock 数据 |
| 363 | 325 | TenantDO dbTenant = randomPojo(TenantDO.class, o -> o.setName("芋道")); | ... | ... |