From a9c8f6c8e9ae5aadce720373a66582cbf5e56ad7 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 2 Dec 2023 10:18:27 +0800 Subject: [PATCH 01/19] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20post?= =?UTF-8?q?=20=E5=92=8C=20dept=20=E6=A8=A1=E5=9D=97=E7=9A=84=20VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/system/api/dept/DeptApiImpl.java | 6 +-- .../admin/captcha/CaptchaController.java | 5 --- .../controller/admin/dept/DeptController.java | 38 +++++++++---------- .../controller/admin/dept/PostController.java | 2 +- .../admin/dept/vo/dept/DeptCreateReqVO.java | 12 ------ .../admin/dept/vo/dept/DeptRespVO.java | 26 ++++++++++--- .../{DeptBaseVO.java => DeptSaveReqVO.java} | 22 ++++++----- .../admin/dept/vo/dept/DeptUpdateReqVO.java | 18 --------- .../admin/dept/vo/post/PostRespVO.java | 4 ++ .../system/convert/dept/DeptConvert.java | 34 ----------------- .../system/service/dept/DeptService.java | 20 +++++----- .../system/service/dept/DeptServiceImpl.java | 17 +++++---- .../service/dept/DeptServiceImplTest.java | 10 ++--- .../service/dept/PostServiceImplTest.java | 6 ++- 14 files changed, 86 insertions(+), 134 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptCreateReqVO.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/{DeptBaseVO.java => DeptSaveReqVO.java} (65%) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptUpdateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dept/DeptConvert.java diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApiImpl.java index c1676ca53..8d11bdcf4 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApiImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApiImpl.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.system.api.dept; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; -import cn.iocoder.yudao.module.system.convert.dept.DeptConvert; import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; import cn.iocoder.yudao.module.system.service.dept.DeptService; import org.springframework.stereotype.Service; @@ -24,13 +24,13 @@ public class DeptApiImpl implements DeptApi { @Override public DeptRespDTO getDept(Long id) { DeptDO dept = deptService.getDept(id); - return DeptConvert.INSTANCE.convert03(dept); + return BeanUtils.toBean(dept, DeptRespDTO.class); } @Override public List getDeptList(Collection ids) { List depts = deptService.getDeptList(ids); - return DeptConvert.INSTANCE.convertList03(depts); + return BeanUtils.toBean(depts, DeptRespDTO.class); } @Override diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/captcha/CaptchaController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/captcha/CaptchaController.java index 029958e8c..25c5e88ee 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/captcha/CaptchaController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/captcha/CaptchaController.java @@ -17,11 +17,6 @@ import javax.annotation.Resource; import javax.annotation.security.PermitAll; import javax.servlet.http.HttpServletRequest; -/** - * 验证码 - * - * @author 芋道源码 - */ @Tag(name = "管理后台 - 验证码") @RestController("adminCaptchaController") @RequestMapping("/system/captcha") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/DeptController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/DeptController.java index 906ab646a..86cdeed1d 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/DeptController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/DeptController.java @@ -2,20 +2,22 @@ package cn.iocoder.yudao.module.system.controller.admin.dept; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.*; -import cn.iocoder.yudao.module.system.convert.dept.DeptConvert; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptRespVO; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; import cn.iocoder.yudao.module.system.service.dept.DeptService; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; 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.Comparator; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -32,16 +34,16 @@ public class DeptController { @PostMapping("create") @Operation(summary = "创建部门") @PreAuthorize("@ss.hasPermission('system:dept:create')") - public CommonResult createDept(@Valid @RequestBody DeptCreateReqVO reqVO) { - Long deptId = deptService.createDept(reqVO); + public CommonResult createDept(@Valid @RequestBody DeptSaveReqVO createReqVO) { + Long deptId = deptService.createDept(createReqVO); return success(deptId); } @PutMapping("update") @Operation(summary = "更新部门") @PreAuthorize("@ss.hasPermission('system:dept:update')") - public CommonResult updateDept(@Valid @RequestBody DeptUpdateReqVO reqVO) { - deptService.updateDept(reqVO); + public CommonResult updateDept(@Valid @RequestBody DeptSaveReqVO updateReqVO) { + deptService.updateDept(updateReqVO); return success(true); } @@ -59,20 +61,15 @@ public class DeptController { @PreAuthorize("@ss.hasPermission('system:dept:query')") public CommonResult> getDeptList(DeptListReqVO reqVO) { List list = deptService.getDeptList(reqVO); - list.sort(Comparator.comparing(DeptDO::getSort)); - return success(DeptConvert.INSTANCE.convertList(list)); + return success(BeanUtils.toBean(list, DeptRespVO.class)); } - @GetMapping("/list-all-simple") + @GetMapping(value = {"/list-all-simple", "/simple-list"}) @Operation(summary = "获取部门精简信息列表", description = "只包含被开启的部门,主要用于前端的下拉选项") public CommonResult> getSimpleDeptList() { - // 获得部门列表,只要开启状态的 - DeptListReqVO reqVO = new DeptListReqVO(); - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); - List list = deptService.getDeptList(reqVO); - // 排序后,返回给前端 - list.sort(Comparator.comparing(DeptDO::getSort)); - return success(DeptConvert.INSTANCE.convertList02(list)); + List list = deptService.getDeptList( + new DeptListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus())); + return success(BeanUtils.toBean(list, DeptSimpleRespVO.class)); } @GetMapping("/get") @@ -80,7 +77,8 @@ public class DeptController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('system:dept:query')") public CommonResult getDept(@RequestParam("id") Long id) { - return success(DeptConvert.INSTANCE.convert(deptService.getDept(id))); + DeptDO dept = deptService.getDept(id); + return success(BeanUtils.toBean(dept, DeptRespVO.class)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/PostController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/PostController.java index 53d029078..7c839f04e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/PostController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/PostController.java @@ -73,7 +73,7 @@ public class PostController { return success(BeanUtils.toBean(post, PostRespVO.class)); } - @GetMapping("/list-all-simple") + @GetMapping(value = {"/list-all-simple", "simple-list"}) @Operation(summary = "获取岗位全列表", description = "只包含被开启的岗位,主要用于前端的下拉选项") public CommonResult> getSimplePostList() { // 获得岗位列表,只要开启状态的 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptCreateReqVO.java deleted file mode 100644 index 66741f6da..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptCreateReqVO.java +++ /dev/null @@ -1,12 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -@Schema(description = "管理后台 - 部门创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class DeptCreateReqVO extends DeptBaseVO { -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptRespVO.java index d8d6a229b..777cb75de 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptRespVO.java @@ -2,19 +2,35 @@ package cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; import java.time.LocalDateTime; @Schema(description = "管理后台 - 部门信息 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -public class DeptRespVO extends DeptBaseVO { +public class DeptRespVO { - @Schema(description = "部门编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @Schema(description = "部门编号", example = "1024") private Long id; - @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") + private String name; + + @Schema(description = "父部门 ID", example = "1024") + private Long parentId; + + @Schema(description = "显示顺序不能为空", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer sort; + + @Schema(description = "负责人的用户编号", example = "2048") + private Long leaderUserId; + + @Schema(description = "联系电话", example = "15601691000") + private String phone; + + @Schema(description = "邮箱", example = "yudao@iocoder.cn") + private String email; + + @Schema(description = "状态,见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") private Integer status; @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptSaveReqVO.java similarity index 65% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptBaseVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptSaveReqVO.java index 5d3a4b6d7..fb9f29847 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptSaveReqVO.java @@ -1,5 +1,7 @@ package cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.validation.InEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -8,19 +10,19 @@ import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; -/** - * 部门 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ +@Schema(description = "管理后台 - 部门创建/修改 Request VO") @Data -public class DeptBaseVO { +public class DeptSaveReqVO { - @Schema(description = "菜单名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") + @Schema(description = "部门编号", example = "1024") + private Long id; + + @Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") @NotBlank(message = "部门名称不能为空") - @Size(max = 30, message = "部门名称长度不能超过30个字符") + @Size(max = 30, message = "部门名称长度不能超过 30 个字符") private String name; - @Schema(description = "父菜单 ID", example = "1024") + @Schema(description = "父部门 ID", example = "1024") private Long parentId; @Schema(description = "显示顺序不能为空", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @@ -36,12 +38,12 @@ public class DeptBaseVO { @Schema(description = "邮箱", example = "yudao@iocoder.cn") @Email(message = "邮箱格式不正确") - @Size(max = 50, message = "邮箱长度不能超过50个字符") + @Size(max = 50, message = "邮箱长度不能超过 50 个字符") private String email; @Schema(description = "状态,见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @NotNull(message = "状态不能为空") -// @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") + @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") private Integer status; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptUpdateReqVO.java deleted file mode 100644 index b63f79d85..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptUpdateReqVO.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 部门更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -public class DeptUpdateReqVO extends DeptBaseVO { - - @Schema(description = "部门编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "部门编号不能为空") - private Long id; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostRespVO.java index d4c659786..a037a132a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostRespVO.java @@ -1,7 +1,9 @@ package cn.iocoder.yudao.module.system.controller.admin.dept.vo.post; import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; import cn.iocoder.yudao.module.system.enums.DictTypeConstants; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -10,6 +12,7 @@ import java.time.LocalDateTime; @Schema(description = "管理后台 - 岗位信息 Response VO") @Data +@ExcelIgnoreUnannotated public class PostRespVO { @Schema(description = "岗位序号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @@ -29,6 +32,7 @@ public class PostRespVO { private Integer sort; @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "状态", converter = DictConvert.class) @DictFormat(DictTypeConstants.COMMON_STATUS) private Integer status; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dept/DeptConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dept/DeptConvert.java deleted file mode 100644 index e8ee7cee7..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dept/DeptConvert.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.dept; - -import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptRespVO; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptUpdateReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; -import java.util.Map; - -@Mapper -public interface DeptConvert { - - DeptConvert INSTANCE = Mappers.getMapper(DeptConvert.class); - - List convertList(List list); - - List convertList02(List list); - - DeptRespVO convert(DeptDO bean); - - DeptDO convert(DeptCreateReqVO bean); - - DeptDO convert(DeptUpdateReqVO bean); - - List convertList03(List list); - - DeptRespDTO convert03(DeptDO bean); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptService.java index 1029b424c..11cb5f42e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptService.java @@ -1,13 +1,14 @@ package cn.iocoder.yudao.module.system.service.dept; -import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; -import java.util.*; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * 部门 Service 接口 @@ -19,17 +20,17 @@ public interface DeptService { /** * 创建部门 * - * @param reqVO 部门信息 + * @param createReqVO 部门信息 * @return 部门编号 */ - Long createDept(DeptCreateReqVO reqVO); + Long createDept(DeptSaveReqVO createReqVO); /** * 更新部门 * - * @param reqVO 部门信息 + * @param updateReqVO 部门信息 */ - void updateDept(DeptUpdateReqVO reqVO); + void updateDept(DeptSaveReqVO updateReqVO); /** * 删除部门 @@ -69,9 +70,6 @@ public interface DeptService { * @return 部门 Map */ default Map getDeptMap(Collection ids) { - if (CollUtil.isEmpty(ids)) { - return Collections.emptyMap(); - } List list = getDeptList(ids); return CollectionUtils.convertMap(list, DeptDO::getId); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java index 08574fdfb..183f11fc7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java @@ -3,11 +3,10 @@ package cn.iocoder.yudao.module.system.service.dept; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.dept.DeptConvert; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; import cn.iocoder.yudao.module.system.dal.mysql.dept.DeptMapper; import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; @@ -41,7 +40,7 @@ public class DeptServiceImpl implements DeptService { @Override @CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST, allEntries = true) // allEntries 清空所有缓存,因为操作一个部门,涉及到多个缓存 - public Long createDept(DeptCreateReqVO createReqVO) { + public Long createDept(DeptSaveReqVO createReqVO) { if (createReqVO.getParentId() == null) { createReqVO.setParentId(DeptDO.PARENT_ID_ROOT); } @@ -51,7 +50,7 @@ public class DeptServiceImpl implements DeptService { validateDeptNameUnique(null, createReqVO.getParentId(), createReqVO.getName()); // 插入部门 - DeptDO dept = DeptConvert.INSTANCE.convert(createReqVO); + DeptDO dept = BeanUtils.toBean(createReqVO, DeptDO.class); deptMapper.insert(dept); return dept.getId(); } @@ -59,7 +58,7 @@ public class DeptServiceImpl implements DeptService { @Override @CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST, allEntries = true) // allEntries 清空所有缓存,因为操作一个部门,涉及到多个缓存 - public void updateDept(DeptUpdateReqVO updateReqVO) { + public void updateDept(DeptSaveReqVO updateReqVO) { if (updateReqVO.getParentId() == null) { updateReqVO.setParentId(DeptDO.PARENT_ID_ROOT); } @@ -71,7 +70,7 @@ public class DeptServiceImpl implements DeptService { validateDeptNameUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName()); // 更新部门 - DeptDO updateObj = DeptConvert.INSTANCE.convert(updateReqVO); + DeptDO updateObj = BeanUtils.toBean(updateReqVO, DeptDO.class); deptMapper.updateById(updateObj); } @@ -165,7 +164,9 @@ public class DeptServiceImpl implements DeptService { @Override public List getDeptList(DeptListReqVO reqVO) { - return deptMapper.selectList(reqVO); + List list = deptMapper.selectList(reqVO); + list.sort(Comparator.comparing(DeptDO::getSort)); + return list; } @Override diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImplTest.java index 99c44f777..abfa225da 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImplTest.java @@ -3,9 +3,8 @@ package cn.iocoder.yudao.module.system.service.dept; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; import cn.iocoder.yudao.module.system.dal.mysql.dept.DeptMapper; import org.junit.jupiter.api.Test; @@ -39,7 +38,8 @@ public class DeptServiceImplTest extends BaseDbUnitTest { @Test public void testCreateDept() { // 准备参数 - DeptCreateReqVO reqVO = randomPojo(DeptCreateReqVO.class, o -> { + DeptSaveReqVO reqVO = randomPojo(DeptSaveReqVO.class, o -> { + o.setId(null); // 防止 id 被设置 o.setParentId(DeptDO.PARENT_ID_ROOT); o.setStatus(randomCommonStatus()); }); @@ -50,7 +50,7 @@ public class DeptServiceImplTest extends BaseDbUnitTest { assertNotNull(deptId); // 校验记录的属性是否正确 DeptDO deptDO = deptMapper.selectById(deptId); - assertPojoEquals(reqVO, deptDO); + assertPojoEquals(reqVO, deptDO, "id"); } @Test @@ -59,7 +59,7 @@ public class DeptServiceImplTest extends BaseDbUnitTest { DeptDO dbDeptDO = randomPojo(DeptDO.class, o -> o.setStatus(randomCommonStatus())); deptMapper.insert(dbDeptDO);// @Sql: 先插入出一条存在的数据 // 准备参数 - DeptUpdateReqVO reqVO = randomPojo(DeptUpdateReqVO.class, o -> { + DeptSaveReqVO reqVO = randomPojo(DeptSaveReqVO.class, o -> { // 设置更新的 ID o.setParentId(DeptDO.PARENT_ID_ROOT); o.setId(dbDeptDO.getId()); diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImplTest.java index 6d117fddc..ecc17452c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImplTest.java @@ -43,7 +43,8 @@ public class PostServiceImplTest extends BaseDbUnitTest { public void testCreatePost_success() { // 准备参数 PostSaveReqVO reqVO = randomPojo(PostSaveReqVO.class, - o -> o.setStatus(randomEle(CommonStatusEnum.values()).getStatus())); + o -> o.setStatus(randomEle(CommonStatusEnum.values()).getStatus())) + .setId(null); // 防止 id 被设置 // 调用 Long postId = postService.createPost(reqVO); @@ -51,7 +52,7 @@ public class PostServiceImplTest extends BaseDbUnitTest { assertNotNull(postId); // 校验记录的属性是否正确 PostDO post = postMapper.selectById(postId); - assertPojoEquals(reqVO, post); + assertPojoEquals(reqVO, post, "id"); } @Test @@ -225,4 +226,5 @@ public class PostServiceImplTest extends BaseDbUnitTest { }; return randomPojo(PostDO.class, ArrayUtils.append(consumer, consumers)); } + } From c4933976530a1b4bd80d081a8c094aa22d4653de Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 2 Dec 2023 18:21:40 +0800 Subject: [PATCH 02/19] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20dictT?= =?UTF-8?q?ype=20=E5=92=8C=20dictData=20=E6=A8=A1=E5=9D=97=E7=9A=84=20VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/api/dict/DictDataApiImpl.java | 6 +-- .../admin/dict/DictDataController.java | 41 +++++++++------- .../admin/dict/DictTypeController.java | 45 +++++++++-------- .../dict/vo/data/DictDataCreateReqVO.java | 12 ----- .../admin/dict/vo/data/DictDataExcelVO.java | 34 ------------- .../dict/vo/data/DictDataExportReqVO.java | 23 --------- .../admin/dict/vo/data/DictDataPageReqVO.java | 3 ++ .../admin/dict/vo/data/DictDataRespVO.java | 45 ++++++++++++++--- ...DataBaseVO.java => DictDataSaveReqVO.java} | 15 +++--- .../dict/vo/data/DictDataUpdateReqVO.java | 18 ------- .../dict/vo/type/DictTypeCreateReqVO.java | 20 -------- .../admin/dict/vo/type/DictTypeExcelVO.java | 28 ----------- .../dict/vo/type/DictTypeExportReqVO.java | 28 ----------- .../admin/dict/vo/type/DictTypeRespVO.java | 28 ++++++++--- ...TypeBaseVO.java => DictTypeSaveReqVO.java} | 15 ++++-- .../dict/vo/type/DictTypeSimpleRespVO.java | 4 -- .../dict/vo/type/DictTypeUpdateReqVO.java | 18 ------- .../app/dict/AppDictDataController.java | 4 +- .../system/convert/dict/DictDataConvert.java | 34 ------------- .../system/convert/dict/DictTypeConvert.java | 28 ----------- .../system/dal/mysql/dict/DictDataMapper.java | 8 ---- .../system/dal/mysql/dict/DictTypeMapper.java | 13 +---- .../system/service/dict/DictDataService.java | 24 +++------- .../service/dict/DictDataServiceImpl.java | 48 +++++++------------ .../system/service/dict/DictTypeService.java | 24 +++------- .../service/dict/DictTypeServiceImpl.java | 48 ++++++++----------- .../service/dict/DictDataServiceImplTest.java | 41 +++------------- .../service/dict/DictTypeServiceImplTest.java | 45 +++-------------- 28 files changed, 200 insertions(+), 500 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataCreateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataExcelVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataExportReqVO.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/{DictDataBaseVO.java => DictDataSaveReqVO.java} (81%) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataUpdateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeCreateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeExcelVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeExportReqVO.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/{DictTypeBaseVO.java => DictTypeSaveReqVO.java} (64%) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeUpdateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictDataConvert.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictTypeConvert.java diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java index e88771fa7..3d045cd40 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.system.api.dict; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO; -import cn.iocoder.yudao.module.system.convert.dict.DictDataConvert; import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO; import cn.iocoder.yudao.module.system.service.dict.DictDataService; import org.springframework.stereotype.Service; @@ -28,13 +28,13 @@ public class DictDataApiImpl implements DictDataApi { @Override public DictDataRespDTO getDictData(String dictType, String value) { DictDataDO dictData = dictDataService.getDictData(dictType, value); - return DictDataConvert.INSTANCE.convert02(dictData); + return BeanUtils.toBean(dictData, DictDataRespDTO.class); } @Override public DictDataRespDTO parseDictData(String dictType, String label) { DictDataDO dictData = dictDataService.parseDictData(dictType, label); - return DictDataConvert.INSTANCE.convert02(dictData); + return BeanUtils.toBean(dictData, DictDataRespDTO.class); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/DictDataController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/DictDataController.java index 13c6f4855..4075e49df 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/DictDataController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/DictDataController.java @@ -1,16 +1,20 @@ package cn.iocoder.yudao.module.system.controller.admin.dict; -import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.*; -import cn.iocoder.yudao.module.system.convert.dict.DictDataConvert; +import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataPageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataRespVO; +import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataSaveReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataSimpleRespVO; +import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO; import cn.iocoder.yudao.module.system.service.dict.DictDataService; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -36,16 +40,16 @@ public class DictDataController { @PostMapping("/create") @Operation(summary = "新增字典数据") @PreAuthorize("@ss.hasPermission('system:dict:create')") - public CommonResult createDictData(@Valid @RequestBody DictDataCreateReqVO reqVO) { - Long dictDataId = dictDataService.createDictData(reqVO); + public CommonResult createDictData(@Valid @RequestBody DictDataSaveReqVO createReqVO) { + Long dictDataId = dictDataService.createDictData(createReqVO); return success(dictDataId); } @PutMapping("/update") @Operation(summary = "修改字典数据") @PreAuthorize("@ss.hasPermission('system:dict:update')") - public CommonResult updateDictData(@Valid @RequestBody DictDataUpdateReqVO reqVO) { - dictDataService.updateDictData(reqVO); + public CommonResult updateDictData(@Valid @RequestBody DictDataSaveReqVO updateReqVO) { + dictDataService.updateDictData(updateReqVO); return success(true); } @@ -63,14 +67,15 @@ public class DictDataController { // 无需添加权限认证,因为前端全局都需要 public CommonResult> getSimpleDictDataList() { List list = dictDataService.getDictDataList(); - return success(DictDataConvert.INSTANCE.convertList(list)); + return success(BeanUtils.toBean(list, DictDataSimpleRespVO.class)); } @GetMapping("/page") @Operation(summary = "/获得字典类型的分页列表") @PreAuthorize("@ss.hasPermission('system:dict:query')") - public CommonResult> getDictTypePage(@Valid DictDataPageReqVO reqVO) { - return success(DictDataConvert.INSTANCE.convertPage(dictDataService.getDictDataPage(reqVO))); + public CommonResult> getDictTypePage(@Valid DictDataPageReqVO pageReqVO) { + PageResult pageResult = dictDataService.getDictDataPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, DictDataRespVO.class)); } @GetMapping(value = "/get") @@ -78,18 +83,20 @@ public class DictDataController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('system:dict:query')") public CommonResult getDictData(@RequestParam("id") Long id) { - return success(DictDataConvert.INSTANCE.convert(dictDataService.getDictData(id))); + DictDataDO dictData = dictDataService.getDictData(id); + return success(BeanUtils.toBean(dictData, DictDataRespVO.class)); } @GetMapping("/export") @Operation(summary = "导出字典数据") @PreAuthorize("@ss.hasPermission('system:dict:export')") @OperateLog(type = EXPORT) - public void export(HttpServletResponse response, @Valid DictDataExportReqVO reqVO) throws IOException { - List list = dictDataService.getDictDataList(reqVO); - List data = DictDataConvert.INSTANCE.convertList02(list); + public void export(HttpServletResponse response, @Valid DictDataPageReqVO exportReqVO) throws IOException { + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = dictDataService.getDictDataPage(exportReqVO).getList(); // 输出 - ExcelUtils.write(response, "字典数据.xls", "数据列表", DictDataExcelVO.class, data); + ExcelUtils.write(response, "字典数据.xls", "数据", DictDataRespVO.class, + BeanUtils.toBean(list, DictDataRespVO.class)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/DictTypeController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/DictTypeController.java index 6fcdcdd9c..99b251f8b 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/DictTypeController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/DictTypeController.java @@ -1,16 +1,20 @@ package cn.iocoder.yudao.module.system.controller.admin.dict; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.*; -import cn.iocoder.yudao.module.system.convert.dict.DictTypeConvert; +import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypePageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeRespVO; +import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeSaveReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeSimpleRespVO; import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO; import cn.iocoder.yudao.module.system.service.dict.DictTypeService; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -36,16 +40,16 @@ public class DictTypeController { @PostMapping("/create") @Operation(summary = "创建字典类型") @PreAuthorize("@ss.hasPermission('system:dict:create')") - public CommonResult createDictType(@Valid @RequestBody DictTypeCreateReqVO reqVO) { - Long dictTypeId = dictTypeService.createDictType(reqVO); + public CommonResult createDictType(@Valid @RequestBody DictTypeSaveReqVO createReqVO) { + Long dictTypeId = dictTypeService.createDictType(createReqVO); return success(dictTypeId); } @PutMapping("/update") @Operation(summary = "修改字典类型") @PreAuthorize("@ss.hasPermission('system:dict:update')") - public CommonResult updateDictType(@Valid @RequestBody DictTypeUpdateReqVO reqVO) { - dictTypeService.updateDictType(reqVO); + public CommonResult updateDictType(@Valid @RequestBody DictTypeSaveReqVO updateReqVO) { + dictTypeService.updateDictType(updateReqVO); return success(true); } @@ -58,11 +62,12 @@ public class DictTypeController { return success(true); } - @Operation(summary = "/获得字典类型的分页列表") @GetMapping("/page") + @Operation(summary = "获得字典类型的分页列表") @PreAuthorize("@ss.hasPermission('system:dict:query')") - public CommonResult> pageDictTypes(@Valid DictTypePageReqVO reqVO) { - return success(DictTypeConvert.INSTANCE.convertPage(dictTypeService.getDictTypePage(reqVO))); + public CommonResult> pageDictTypes(@Valid DictTypePageReqVO pageReqVO) { + PageResult pageResult = dictTypeService.getDictTypePage(pageReqVO); + return success(BeanUtils.toBean(pageResult, DictTypeRespVO.class)); } @Operation(summary = "/查询字典类型详细") @@ -70,26 +75,28 @@ public class DictTypeController { @GetMapping(value = "/get") @PreAuthorize("@ss.hasPermission('system:dict:query')") public CommonResult getDictType(@RequestParam("id") Long id) { - return success(DictTypeConvert.INSTANCE.convert(dictTypeService.getDictType(id))); + DictTypeDO dictType = dictTypeService.getDictType(id); + return success(BeanUtils.toBean(dictType, DictTypeRespVO.class)); } - @GetMapping("/list-all-simple") + @GetMapping(value = {"/list-all-simple", "simple-list"}) @Operation(summary = "获得全部字典类型列表", description = "包括开启 + 禁用的字典类型,主要用于前端的下拉选项") // 无需添加权限认证,因为前端全局都需要 public CommonResult> getSimpleDictTypeList() { List list = dictTypeService.getDictTypeList(); - return success(DictTypeConvert.INSTANCE.convertList(list)); + return success(BeanUtils.toBean(list, DictTypeSimpleRespVO.class)); } @Operation(summary = "导出数据类型") @GetMapping("/export") @PreAuthorize("@ss.hasPermission('system:dict:query')") @OperateLog(type = EXPORT) - public void export(HttpServletResponse response, @Valid DictTypeExportReqVO reqVO) throws IOException { - List list = dictTypeService.getDictTypeList(reqVO); - List data = DictTypeConvert.INSTANCE.convertList02(list); - // 输出 - ExcelUtils.write(response, "字典类型.xls", "类型列表", DictTypeExcelVO.class, data); + public void export(HttpServletResponse response, @Valid DictTypePageReqVO exportReqVO) throws IOException { + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = dictTypeService.getDictTypePage(exportReqVO).getList(); + // 导出 + ExcelUtils.write(response, "字典类型.xls", "数据", DictTypeRespVO.class, + BeanUtils.toBean(list, DictTypeRespVO.class)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataCreateReqVO.java deleted file mode 100644 index 6f225eba4..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataCreateReqVO.java +++ /dev/null @@ -1,12 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.dict.vo.data; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Schema(description = "管理后台 - 字典数据创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -public class DictDataCreateReqVO extends DictDataBaseVO { - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataExcelVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataExcelVO.java deleted file mode 100644 index 6dcb9bb50..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataExcelVO.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.dict.vo.data; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import cn.iocoder.yudao.module.system.enums.DictTypeConstants; -import com.alibaba.excel.annotation.ExcelProperty; -import lombok.Data; - -/** - * 字典数据 Excel 导出响应 VO - */ -@Data -public class DictDataExcelVO { - - @ExcelProperty("字典编码") - private Long id; - - @ExcelProperty("字典排序") - private Integer sort; - - @ExcelProperty("字典标签") - private String label; - - @ExcelProperty("字典键值") - private String value; - - @ExcelProperty("字典类型") - private String dictType; - - @ExcelProperty(value = "状态", converter = DictConvert.class) - @DictFormat(DictTypeConstants.COMMON_STATUS) - private Integer status; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataExportReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataExportReqVO.java deleted file mode 100644 index 0d7fc748a..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataExportReqVO.java +++ /dev/null @@ -1,23 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.dict.vo.data; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import javax.validation.constraints.Size; - -@Schema(description = "管理后台 - 字典类型导出 Request VO") -@Data -public class DictDataExportReqVO { - - @Schema(description = "字典标签", example = "芋道") - @Size(max = 100, message = "字典标签长度不能超过100个字符") - private String label; - - @Schema(description = "字典类型,模糊匹配", example = "sys_common_sex") - @Size(max = 100, message = "字典类型类型长度不能超过100个字符") - private String dictType; - - @Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1") - private Integer status; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataPageReqVO.java index 7fcc2c96a..d9bd14af8 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataPageReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataPageReqVO.java @@ -1,6 +1,8 @@ package cn.iocoder.yudao.module.system.controller.admin.dict.vo.data; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.validation.InEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; @@ -21,6 +23,7 @@ public class DictDataPageReqVO extends PageParam { private String dictType; @Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1") + @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") private Integer status; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataRespVO.java index d9786c903..e0b940a58 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataRespVO.java @@ -1,23 +1,54 @@ package cn.iocoder.yudao.module.system.controller.admin.dict.vo.data; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; import java.time.LocalDateTime; @Schema(description = "管理后台 - 字典数据信息 Response VO") @Data -@NoArgsConstructor -@AllArgsConstructor -@EqualsAndHashCode(callSuper = true) -public class DictDataRespVO extends DictDataBaseVO { +@ExcelIgnoreUnannotated +public class DictDataRespVO { @Schema(description = "字典数据编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("字典编码") private Long id; + @Schema(description = "显示顺序不能为空", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("字典排序") + private Integer sort; + + @Schema(description = "字典标签", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") + @ExcelProperty("字典标签") + private String label; + + @Schema(description = "字典值", requiredMode = Schema.RequiredMode.REQUIRED, example = "iocoder") + @ExcelProperty("字典键值") + private String value; + + @Schema(description = "字典类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "sys_common_sex") + @ExcelProperty("字典类型") + private String dictType; + + @Schema(description = "状态,见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "状态", converter = DictConvert.class) + @DictFormat(DictTypeConstants.COMMON_STATUS) + private Integer status; + + @Schema(description = "颜色类型,default、primary、success、info、warning、danger", example = "default") + private String colorType; + + @Schema(description = "css 样式", example = "btn-visible") + private String cssClass; + + @Schema(description = "备注", example = "我是一个角色") + private String remark; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") private LocalDateTime createTime; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataSaveReqVO.java similarity index 81% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataBaseVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataSaveReqVO.java index f1aecc42c..4f35087bc 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataSaveReqVO.java @@ -1,5 +1,7 @@ package cn.iocoder.yudao.module.system.controller.admin.dict.vo.data; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.validation.InEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -7,12 +9,12 @@ import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; -/** - * 字典数据 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ +@Schema(description = "管理后台 - 字典数据创建/修改 Request VO") @Data -public class DictDataBaseVO { +public class DictDataSaveReqVO { + + @Schema(description = "字典数据编号", example = "1024") + private Long id; @Schema(description = "显示顺序不能为空", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @NotNull(message = "显示顺序不能为空") @@ -35,11 +37,12 @@ public class DictDataBaseVO { @Schema(description = "状态,见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @NotNull(message = "状态不能为空") -// @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") + @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") private Integer status; @Schema(description = "颜色类型,default、primary、success、info、warning、danger", example = "default") private String colorType; + @Schema(description = "css 样式", example = "btn-visible") private String cssClass; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataUpdateReqVO.java deleted file mode 100644 index 226029f81..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataUpdateReqVO.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.dict.vo.data; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 字典数据更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -public class DictDataUpdateReqVO extends DictDataBaseVO { - - @Schema(description = "字典数据编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "字典数据编号不能为空") - private Long id; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeCreateReqVO.java deleted file mode 100644 index 59e9ecc78..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeCreateReqVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.dict.vo.type; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; - -@Schema(description = "管理后台 - 字典类型创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -public class DictTypeCreateReqVO extends DictTypeBaseVO { - - @Schema(description = "字典类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "sys_common_sex") - @NotNull(message = "字典类型不能为空") - @Size(max = 100, message = "字典类型类型长度不能超过100个字符") - private String type; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeExcelVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeExcelVO.java deleted file mode 100644 index b7db46d0e..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeExcelVO.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.dict.vo.type; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import cn.iocoder.yudao.module.system.enums.DictTypeConstants; -import com.alibaba.excel.annotation.ExcelProperty; -import lombok.Data; - -/** - * 字典类型 Excel 导出响应 VO - */ -@Data -public class DictTypeExcelVO { - - @ExcelProperty("字典主键") - private Long id; - - @ExcelProperty("字典名称") - private String name; - - @ExcelProperty("字典类型") - private String type; - - @ExcelProperty(value = "状态", converter = DictConvert.class) - @DictFormat(DictTypeConstants.COMMON_STATUS) - private Integer status; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeExportReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeExportReqVO.java deleted file mode 100644 index 5a5147b69..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeExportReqVO.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.dict.vo.type; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 字典类型分页列表 Request VO") -@Data -public class DictTypeExportReqVO { - - @Schema(description = "字典类型名称,模糊匹配", example = "芋道") - private String name; - - @Schema(description = "字典类型,模糊匹配", example = "sys_common_sex") - private String type; - - @Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1") - private Integer status; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @Schema(description = "创建时间") - private LocalDateTime[] createTime; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeRespVO.java index 0dcba7007..6ddd47bcd 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeRespVO.java @@ -1,26 +1,40 @@ package cn.iocoder.yudao.module.system.controller.admin.dict.vo.type; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; import java.time.LocalDateTime; @Schema(description = "管理后台 - 字典类型信息 Response VO") @Data -@NoArgsConstructor -@AllArgsConstructor -@EqualsAndHashCode(callSuper = true) -public class DictTypeRespVO extends DictTypeBaseVO { +@ExcelIgnoreUnannotated +public class DictTypeRespVO { @Schema(description = "字典类型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("字典主键") private Long id; + @Schema(description = "字典名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "性别") + @ExcelProperty("字典名称") + private String name; + @Schema(description = "字典类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "sys_common_sex") + @ExcelProperty("字典类型") private String type; + @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "状态", converter = DictConvert.class) + @DictFormat(DictTypeConstants.COMMON_STATUS) + private Integer status; + + @Schema(description = "备注", example = "快乐的备注") + private String remark; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") private LocalDateTime createTime; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeSaveReqVO.java similarity index 64% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeBaseVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeSaveReqVO.java index 996a32364..c506c08f6 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeSaveReqVO.java @@ -7,18 +7,23 @@ import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; -/** - * 字典类型 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ +@Schema(description = "管理后台 - 字典类型创建/修改 Request VO") @Data -public class DictTypeBaseVO { +public class DictTypeSaveReqVO { + + @Schema(description = "字典类型编号", example = "1024") + private Long id; @Schema(description = "字典名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "性别") @NotBlank(message = "字典名称不能为空") @Size(max = 100, message = "字典类型名称长度不能超过100个字符") private String name; + @Schema(description = "字典类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "sys_common_sex") + @NotNull(message = "字典类型不能为空") + @Size(max = 100, message = "字典类型类型长度不能超过 100 个字符") + private String type; + @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @NotNull(message = "状态不能为空") private Integer status; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeSimpleRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeSimpleRespVO.java index 2d8133b75..f3e717dae 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeSimpleRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeSimpleRespVO.java @@ -1,14 +1,10 @@ package cn.iocoder.yudao.module.system.controller.admin.dict.vo.type; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; import lombok.Data; -import lombok.NoArgsConstructor; @Schema(description = "管理后台 - 字典类型精简信息 Response VO") @Data -@NoArgsConstructor -@AllArgsConstructor public class DictTypeSimpleRespVO { @Schema(description = "字典类型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeUpdateReqVO.java deleted file mode 100644 index 9209317ba..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/type/DictTypeUpdateReqVO.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.dict.vo.type; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 字典类型更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -public class DictTypeUpdateReqVO extends DictTypeBaseVO { - - @Schema(description = "字典类型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "字典类型编号不能为空") - private Long id; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java index 1f4f78c80..15976361e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java @@ -1,8 +1,8 @@ package cn.iocoder.yudao.module.system.controller.app.dict; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.app.dict.vo.AppDictDataRespVO; -import cn.iocoder.yudao.module.system.convert.dict.DictDataConvert; import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO; import cn.iocoder.yudao.module.system.service.dict.DictDataService; import io.swagger.v3.oas.annotations.Operation; @@ -33,7 +33,7 @@ public class AppDictDataController { @Parameter(name = "type", description = "字典类型", required = true, example = "common_status") public CommonResult> getDictDataListByType(@RequestParam("type") String type) { List list = dictDataService.getEnabledDictDataListByType(type); - return success(DictDataConvert.INSTANCE.convertList03(list)); + return success(BeanUtils.toBean(list, AppDictDataRespVO.class)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictDataConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictDataConvert.java deleted file mode 100644 index dbfad6678..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictDataConvert.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.dict; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.*; -import cn.iocoder.yudao.module.system.controller.app.dict.vo.AppDictDataRespVO; -import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper -public interface DictDataConvert { - - DictDataConvert INSTANCE = Mappers.getMapper(DictDataConvert.class); - - List convertList(List list); - - DictDataRespVO convert(DictDataDO bean); - - PageResult convertPage(PageResult page); - - DictDataDO convert(DictDataUpdateReqVO bean); - - DictDataDO convert(DictDataCreateReqVO bean); - - List convertList02(List bean); - - DictDataRespDTO convert02(DictDataDO bean); - - List convertList03(List list); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictTypeConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictTypeConvert.java deleted file mode 100644 index 392e3082e..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictTypeConvert.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.dict; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.*; -import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper -public interface DictTypeConvert { - - DictTypeConvert INSTANCE = Mappers.getMapper(DictTypeConvert.class); - - PageResult convertPage(PageResult bean); - - DictTypeRespVO convert(DictTypeDO bean); - - DictTypeDO convert(DictTypeCreateReqVO bean); - - DictTypeDO convert(DictTypeUpdateReqVO bean); - - List convertList(List list); - - List convertList02(List list); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java index f92c86298..fe00e55b4 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.dal.mysql.dict; 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.dict.vo.data.DictDataExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -41,13 +40,6 @@ public interface DictDataMapper extends BaseMapperX { .orderByDesc(Arrays.asList(DictDataDO::getDictType, DictDataDO::getSort))); } - default List selectList(DictDataExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .likeIfPresent(DictDataDO::getLabel, reqVO.getLabel()) - .eqIfPresent(DictDataDO::getDictType, reqVO.getDictType()) - .eqIfPresent(DictDataDO::getStatus, reqVO.getStatus())); - } - default List selectListByTypeAndStatus(String dictType, Integer status) { return selectList(new LambdaQueryWrapper() .eq(DictDataDO::getDictType, dictType) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictTypeMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictTypeMapper.java index 261f18cc4..52393a961 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictTypeMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictTypeMapper.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.dal.mysql.dict; 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.dict.vo.type.DictTypeExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypePageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO; import org.apache.ibatis.annotations.Mapper; @@ -11,7 +10,6 @@ import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Update; import java.time.LocalDateTime; -import java.util.List; @Mapper public interface DictTypeMapper extends BaseMapperX { @@ -25,14 +23,6 @@ public interface DictTypeMapper extends BaseMapperX { .orderByDesc(DictTypeDO::getId)); } - default List selectList(DictTypeExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .likeIfPresent(DictTypeDO::getName, reqVO.getName()) - .likeIfPresent(DictTypeDO::getType, reqVO.getType()) - .eqIfPresent(DictTypeDO::getStatus, reqVO.getStatus()) - .betweenIfPresent(DictTypeDO::getCreateTime, reqVO.getCreateTime())); - } - default DictTypeDO selectByType(String type) { return selectOne(DictTypeDO::getType, type); } @@ -41,8 +31,7 @@ public interface DictTypeMapper extends BaseMapperX { return selectOne(DictTypeDO::getName, name); } - int deleteById(@Param("id") Long id, @Param("deletedTime") LocalDateTime deletedTime); - @Update("UPDATE system_dict_type SET deleted = 1, deleted_time = #{deletedTime} WHERE id = #{id}") void updateToDelete(@Param("id") Long id, @Param("deletedTime") LocalDateTime deletedTime); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java index 3fc6a4071..a0abf106c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java @@ -1,10 +1,8 @@ package cn.iocoder.yudao.module.system.service.dict; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO; import java.util.Collection; @@ -20,17 +18,17 @@ public interface DictDataService { /** * 创建字典数据 * - * @param reqVO 字典数据信息 + * @param createReqVO 字典数据信息 * @return 字典数据编号 */ - Long createDictData(DictDataCreateReqVO reqVO); + Long createDictData(DictDataSaveReqVO createReqVO); /** * 更新字典数据 * - * @param reqVO 字典数据信息 + * @param updateReqVO 字典数据信息 */ - void updateDictData(DictDataUpdateReqVO reqVO); + void updateDictData(DictDataSaveReqVO updateReqVO); /** * 删除字典数据 @@ -49,18 +47,10 @@ public interface DictDataService { /** * 获得字典数据分页列表 * - * @param reqVO 分页请求 + * @param pageReqVO 分页请求 * @return 字典数据分页列表 */ - PageResult getDictDataPage(DictDataPageReqVO reqVO); - - /** - * 获得字典数据列表 - * - * @param reqVO 列表请求 - * @return 字典数据列表 - */ - List getDictDataList(DictDataExportReqVO reqVO); + PageResult getDictDataPage(DictDataPageReqVO pageReqVO); /** * 获得字典数据列表 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java index 8a49719fb..1391a8f1a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java @@ -4,11 +4,9 @@ import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; 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.dict.vo.data.DictDataCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataExportReqVO; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.dict.DictDataConvert; +import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO; import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO; import cn.iocoder.yudao.module.system.dal.mysql.dict.DictDataMapper; @@ -55,15 +53,8 @@ public class DictDataServiceImpl implements DictDataService { } @Override - public PageResult getDictDataPage(DictDataPageReqVO reqVO) { - return dictDataMapper.selectPage(reqVO); - } - - @Override - public List getDictDataList(DictDataExportReqVO reqVO) { - List list = dictDataMapper.selectList(reqVO); - list.sort(COMPARATOR_TYPE_AND_SORT); - return list; + public PageResult getDictDataPage(DictDataPageReqVO pageReqVO) { + return dictDataMapper.selectPage(pageReqVO); } @Override @@ -79,23 +70,29 @@ public class DictDataServiceImpl implements DictDataService { } @Override - public Long createDictData(DictDataCreateReqVO reqVO) { - // 校验正确性 - validateDictDataForCreateOrUpdate(null, reqVO.getValue(), reqVO.getDictType()); + public Long createDictData(DictDataSaveReqVO createReqVO) { + // 校验字典类型有效 + validateDictTypeExists(createReqVO.getDictType()); + // 校验字典数据的值的唯一性 + validateDictDataValueUnique(null, createReqVO.getDictType(), createReqVO.getValue()); // 插入字典类型 - DictDataDO dictData = DictDataConvert.INSTANCE.convert(reqVO); + DictDataDO dictData = BeanUtils.toBean(createReqVO, DictDataDO.class); dictDataMapper.insert(dictData); return dictData.getId(); } @Override - public void updateDictData(DictDataUpdateReqVO reqVO) { - // 校验正确性 - validateDictDataForCreateOrUpdate(reqVO.getId(), reqVO.getValue(), reqVO.getDictType()); + public void updateDictData(DictDataSaveReqVO updateReqVO) { + // 校验自己存在 + validateDictDataExists(updateReqVO.getId()); + // 校验字典类型有效 + validateDictTypeExists(updateReqVO.getDictType()); + // 校验字典数据的值的唯一性 + validateDictDataValueUnique(updateReqVO.getId(), updateReqVO.getDictType(), updateReqVO.getValue()); // 更新字典类型 - DictDataDO updateObj = DictDataConvert.INSTANCE.convert(reqVO); + DictDataDO updateObj = BeanUtils.toBean(updateReqVO, DictDataDO.class); dictDataMapper.updateById(updateObj); } @@ -113,15 +110,6 @@ public class DictDataServiceImpl implements DictDataService { return dictDataMapper.selectCountByDictType(dictType); } - private void validateDictDataForCreateOrUpdate(Long id, String value, String dictType) { - // 校验自己存在 - validateDictDataExists(id); - // 校验字典类型有效 - validateDictTypeExists(dictType); - // 校验字典数据的值的唯一性 - validateDictDataValueUnique(id, dictType, value); - } - @VisibleForTesting public void validateDictDataValueUnique(Long id, String dictType, String value) { DictDataDO dictData = dictDataMapper.selectByDictTypeAndValue(dictType, value); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictTypeService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictTypeService.java index 4b334b08b..40911891c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictTypeService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictTypeService.java @@ -1,10 +1,8 @@ package cn.iocoder.yudao.module.system.service.dict; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO; import java.util.List; @@ -19,17 +17,17 @@ public interface DictTypeService { /** * 创建字典类型 * - * @param reqVO 字典类型信息 + * @param createReqVO 字典类型信息 * @return 字典类型编号 */ - Long createDictType(DictTypeCreateReqVO reqVO); + Long createDictType(DictTypeSaveReqVO createReqVO); /** * 更新字典类型 * - * @param reqVO 字典类型信息 + * @param updateReqVO 字典类型信息 */ - void updateDictType(DictTypeUpdateReqVO reqVO); + void updateDictType(DictTypeSaveReqVO updateReqVO); /** * 删除字典类型 @@ -41,18 +39,10 @@ public interface DictTypeService { /** * 获得字典类型分页列表 * - * @param reqVO 分页请求 + * @param pageReqVO 分页请求 * @return 字典类型分页列表 */ - PageResult getDictTypePage(DictTypePageReqVO reqVO); - - /** - * 获得字典类型列表 - * - * @param reqVO 列表请求 - * @return 字典类型列表 - */ - List getDictTypeList(DictTypeExportReqVO reqVO); + PageResult getDictTypePage(DictTypePageReqVO pageReqVO); /** * 获得字典类型详情 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImpl.java index cc731affe..76c1de55e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImpl.java @@ -3,11 +3,9 @@ package cn.iocoder.yudao.module.system.service.dict; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeExportReqVO; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.dict.DictTypeConvert; +import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO; import cn.iocoder.yudao.module.system.dal.mysql.dict.DictTypeMapper; import com.google.common.annotations.VisibleForTesting; @@ -35,13 +33,8 @@ public class DictTypeServiceImpl implements DictTypeService { private DictTypeMapper dictTypeMapper; @Override - public PageResult getDictTypePage(DictTypePageReqVO reqVO) { - return dictTypeMapper.selectPage(reqVO); - } - - @Override - public List getDictTypeList(DictTypeExportReqVO reqVO) { - return dictTypeMapper.selectList(reqVO); + public PageResult getDictTypePage(DictTypePageReqVO pageReqVO) { + return dictTypeMapper.selectPage(pageReqVO); } @Override @@ -55,24 +48,30 @@ public class DictTypeServiceImpl implements DictTypeService { } @Override - public Long createDictType(DictTypeCreateReqVO reqVO) { - // 校验正确性 - validateDictTypeForCreateOrUpdate(null, reqVO.getName(), reqVO.getType()); + public Long createDictType(DictTypeSaveReqVO createReqVO) { + // 校验字典类型的名字的唯一性 + validateDictTypeNameUnique(null, createReqVO.getName()); + // 校验字典类型的类型的唯一性 + validateDictTypeUnique(null, createReqVO.getType()); // 插入字典类型 - DictTypeDO dictType = DictTypeConvert.INSTANCE.convert(reqVO) - .setDeletedTime(LocalDateTimeUtils.EMPTY); // 唯一索引,避免 null 值 + DictTypeDO dictType = BeanUtils.toBean(createReqVO, DictTypeDO.class); + dictType.setDeletedTime(LocalDateTimeUtils.EMPTY); // 唯一索引,避免 null 值 dictTypeMapper.insert(dictType); return dictType.getId(); } @Override - public void updateDictType(DictTypeUpdateReqVO reqVO) { - // 校验正确性 - validateDictTypeForCreateOrUpdate(reqVO.getId(), reqVO.getName(), null); + public void updateDictType(DictTypeSaveReqVO updateReqVO) { + // 校验自己存在 + validateDictTypeExists(updateReqVO.getId()); + // 校验字典类型的名字的唯一性 + validateDictTypeNameUnique(updateReqVO.getId(), updateReqVO.getName()); + // 校验字典类型的类型的唯一性 + validateDictTypeUnique(updateReqVO.getId(), updateReqVO.getType()); // 更新字典类型 - DictTypeDO updateObj = DictTypeConvert.INSTANCE.convert(reqVO); + DictTypeDO updateObj = BeanUtils.toBean(updateReqVO, DictTypeDO.class); dictTypeMapper.updateById(updateObj); } @@ -93,15 +92,6 @@ public class DictTypeServiceImpl implements DictTypeService { return dictTypeMapper.selectList(); } - private void validateDictTypeForCreateOrUpdate(Long id, String name, String type) { - // 校验自己存在 - validateDictTypeExists(id); - // 校验字典类型的名字的唯一性 - validateDictTypeNameUnique(id, name); - // 校验字典类型的类型的唯一性 - validateDictTypeUnique(id, type); - } - @VisibleForTesting void validateDictTypeNameUnique(Long id, String name) { DictTypeDO dictType = dictTypeMapper.selectByName(name); diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImplTest.java index bb962b0dd..983a70c52 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImplTest.java @@ -4,10 +4,8 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO; import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO; import cn.iocoder.yudao.module.system.dal.mysql.dict.DictDataMapper; @@ -91,34 +89,6 @@ public class DictDataServiceImplTest extends BaseDbUnitTest { assertPojoEquals(dbDictData, pageResult.getList().get(0)); } - @Test - public void testGetDictDataList_export() { - // mock 数据 - DictDataDO dbDictData = randomPojo(DictDataDO.class, o -> { // 等会查询到 - o.setLabel("芋艿"); - o.setDictType("yunai"); - o.setStatus(CommonStatusEnum.ENABLE.getStatus()); - }); - dictDataMapper.insert(dbDictData); - // 测试 label 不匹配 - dictDataMapper.insert(cloneIgnoreId(dbDictData, o -> o.setLabel("艿"))); - // 测试 dictType 不匹配 - dictDataMapper.insert(cloneIgnoreId(dbDictData, o -> o.setDictType("nai"))); - // 测试 status 不匹配 - dictDataMapper.insert(cloneIgnoreId(dbDictData, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); - // 准备参数 - DictDataExportReqVO reqVO = new DictDataExportReqVO(); - reqVO.setLabel("芋"); - reqVO.setDictType("yunai"); - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); - - // 调用 - List list = dictDataService.getDictDataList(reqVO); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbDictData, list.get(0)); - } - @Test public void testGetDictData() { // mock 数据 @@ -136,8 +106,9 @@ public class DictDataServiceImplTest extends BaseDbUnitTest { @Test public void testCreateDictData_success() { // 准备参数 - DictDataCreateReqVO reqVO = randomPojo(DictDataCreateReqVO.class, - o -> o.setStatus(randomCommonStatus())); + DictDataSaveReqVO reqVO = randomPojo(DictDataSaveReqVO.class, + o -> o.setStatus(randomCommonStatus())) + .setId(null); // 防止 id 被赋值 // mock 方法 when(dictTypeService.getDictType(eq(reqVO.getDictType()))).thenReturn(randomDictTypeDO(reqVO.getDictType())); @@ -147,7 +118,7 @@ public class DictDataServiceImplTest extends BaseDbUnitTest { assertNotNull(dictDataId); // 校验记录的属性是否正确 DictDataDO dictData = dictDataMapper.selectById(dictDataId); - assertPojoEquals(reqVO, dictData); + assertPojoEquals(reqVO, dictData, "id"); } @Test @@ -156,7 +127,7 @@ public class DictDataServiceImplTest extends BaseDbUnitTest { DictDataDO dbDictData = randomDictDataDO(); dictDataMapper.insert(dbDictData);// @Sql: 先插入出一条存在的数据 // 准备参数 - DictDataUpdateReqVO reqVO = randomPojo(DictDataUpdateReqVO.class, o -> { + DictDataSaveReqVO reqVO = randomPojo(DictDataSaveReqVO.class, o -> { o.setId(dbDictData.getId()); // 设置更新的 ID o.setStatus(randomCommonStatus()); }); diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImplTest.java index fc9387019..b9eb10a5f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImplTest.java @@ -4,10 +4,8 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO; import cn.iocoder.yudao.module.system.dal.mysql.dict.DictTypeMapper; import org.junit.jupiter.api.Test; @@ -74,38 +72,6 @@ public class DictTypeServiceImplTest extends BaseDbUnitTest { assertPojoEquals(dbDictType, pageResult.getList().get(0)); } - @Test - public void testGetDictTypeList_export() { - // mock 数据 - DictTypeDO dbDictType = randomPojo(DictTypeDO.class, o -> { // 等会查询到 - o.setName("yunai"); - o.setType("芋艿"); - o.setStatus(CommonStatusEnum.ENABLE.getStatus()); - o.setCreateTime(buildTime(2021, 1, 15)); - }); - dictTypeMapper.insert(dbDictType); - // 测试 name 不匹配 - dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setName("tudou"))); - // 测试 type 不匹配 - dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setType("土豆"))); - // 测试 status 不匹配 - dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); - // 测试 createTime 不匹配 - dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setCreateTime(buildTime(2021, 1, 1)))); - // 准备参数 - DictTypeExportReqVO reqVO = new DictTypeExportReqVO(); - reqVO.setName("nai"); - reqVO.setType("艿"); - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); - reqVO.setCreateTime(buildBetweenTime(2021, 1, 10, 2021, 1, 20)); - - // 调用 - List list = dictTypeService.getDictTypeList(reqVO); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbDictType, list.get(0)); - } - @Test public void testGetDictType_id() { // mock 数据 @@ -139,8 +105,9 @@ public class DictTypeServiceImplTest extends BaseDbUnitTest { @Test public void testCreateDictType_success() { // 准备参数 - DictTypeCreateReqVO reqVO = randomPojo(DictTypeCreateReqVO.class, - o -> o.setStatus(randomEle(CommonStatusEnum.values()).getStatus())); + DictTypeSaveReqVO reqVO = randomPojo(DictTypeSaveReqVO.class, + o -> o.setStatus(randomEle(CommonStatusEnum.values()).getStatus())) + .setId(null); // 避免 id 被赋值 // 调用 Long dictTypeId = dictTypeService.createDictType(reqVO); @@ -148,7 +115,7 @@ public class DictTypeServiceImplTest extends BaseDbUnitTest { assertNotNull(dictTypeId); // 校验记录的属性是否正确 DictTypeDO dictType = dictTypeMapper.selectById(dictTypeId); - assertPojoEquals(reqVO, dictType); + assertPojoEquals(reqVO, dictType, "id"); } @Test @@ -157,7 +124,7 @@ public class DictTypeServiceImplTest extends BaseDbUnitTest { DictTypeDO dbDictType = randomDictTypeDO(); dictTypeMapper.insert(dbDictType);// @Sql: 先插入出一条存在的数据 // 准备参数 - DictTypeUpdateReqVO reqVO = randomPojo(DictTypeUpdateReqVO.class, o -> { + DictTypeSaveReqVO reqVO = randomPojo(DictTypeSaveReqVO.class, o -> { o.setId(dbDictType.getId()); // 设置更新的 ID o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); }); From 8eb04d6805621db14280659932a0957fb241604b Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 2 Dec 2023 18:40:31 +0800 Subject: [PATCH 03/19] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20error?= =?UTF-8?q?Code=20=E6=A8=A1=E5=9D=97=E7=9A=84=20VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/errorcode/ErrorCodeController.java | 20 +++++---- .../errorcode/vo/ErrorCodeCreateReqVO.java | 14 ------- .../admin/errorcode/vo/ErrorCodeExcelVO.java | 40 ------------------ .../errorcode/vo/ErrorCodeExportReqVO.java | 31 -------------- .../admin/errorcode/vo/ErrorCodeRespVO.java | 36 +++++++++++++--- ...odeBaseVO.java => ErrorCodeSaveReqVO.java} | 10 ++--- .../errorcode/vo/ErrorCodeUpdateReqVO.java | 20 --------- .../convert/errorcode/ErrorCodeConvert.java | 42 ------------------- .../dal/mysql/errorcode/ErrorCodeMapper.java | 11 ----- .../service/errorcode/ErrorCodeService.java | 16 ++----- .../errorcode/ErrorCodeServiceImpl.java | 41 ++++++++---------- .../errorcode/ErrorCodeServiceTest.java | 30 +++---------- 12 files changed, 72 insertions(+), 239 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeCreateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeExcelVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeExportReqVO.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/{ErrorCodeBaseVO.java => ErrorCodeSaveReqVO.java} (80%) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeUpdateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/errorcode/ErrorCodeConvert.java diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/ErrorCodeController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/ErrorCodeController.java index 90879472b..79e167c26 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/ErrorCodeController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/ErrorCodeController.java @@ -1,10 +1,11 @@ package cn.iocoder.yudao.module.system.controller.admin.errorcode; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import cn.iocoder.yudao.module.system.convert.errorcode.ErrorCodeConvert; import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.*; import cn.iocoder.yudao.module.system.dal.dataobject.errorcode.ErrorCodeDO; import cn.iocoder.yudao.module.system.service.errorcode.ErrorCodeService; @@ -36,14 +37,14 @@ public class ErrorCodeController { @PostMapping("/create") @Operation(summary = "创建错误码") @PreAuthorize("@ss.hasPermission('system:error-code:create')") - public CommonResult createErrorCode(@Valid @RequestBody ErrorCodeCreateReqVO createReqVO) { + public CommonResult createErrorCode(@Valid @RequestBody ErrorCodeSaveReqVO createReqVO) { return success(errorCodeService.createErrorCode(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新错误码") @PreAuthorize("@ss.hasPermission('system:error-code:update')") - public CommonResult updateErrorCode(@Valid @RequestBody ErrorCodeUpdateReqVO updateReqVO) { + public CommonResult updateErrorCode(@Valid @RequestBody ErrorCodeSaveReqVO updateReqVO) { errorCodeService.updateErrorCode(updateReqVO); return success(true); } @@ -63,7 +64,7 @@ public class ErrorCodeController { @PreAuthorize("@ss.hasPermission('system:error-code:query')") public CommonResult getErrorCode(@RequestParam("id") Long id) { ErrorCodeDO errorCode = errorCodeService.getErrorCode(id); - return success(ErrorCodeConvert.INSTANCE.convert(errorCode)); + return success(BeanUtils.toBean(errorCode, ErrorCodeRespVO.class)); } @GetMapping("/page") @@ -71,19 +72,20 @@ public class ErrorCodeController { @PreAuthorize("@ss.hasPermission('system:error-code:query')") public CommonResult> getErrorCodePage(@Valid ErrorCodePageReqVO pageVO) { PageResult pageResult = errorCodeService.getErrorCodePage(pageVO); - return success(ErrorCodeConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, ErrorCodeRespVO.class)); } @GetMapping("/export-excel") @Operation(summary = "导出错误码 Excel") @PreAuthorize("@ss.hasPermission('system:error-code:export')") @OperateLog(type = EXPORT) - public void exportErrorCodeExcel(@Valid ErrorCodeExportReqVO exportReqVO, + public void exportErrorCodeExcel(@Valid ErrorCodePageReqVO exportReqVO, HttpServletResponse response) throws IOException { - List list = errorCodeService.getErrorCodeList(exportReqVO); + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = errorCodeService.getErrorCodePage(exportReqVO).getList(); // 导出 Excel - List datas = ErrorCodeConvert.INSTANCE.convertList02(list); - ExcelUtils.write(response, "错误码.xls", "数据", ErrorCodeExcelVO.class, datas); + ExcelUtils.write(response, "错误码.xls", "数据", ErrorCodeRespVO.class, + BeanUtils.toBean(list, ErrorCodeRespVO.class)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeCreateReqVO.java deleted file mode 100644 index 0f859dbd9..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeCreateReqVO.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.errorcode.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -@Schema(description = "管理后台 - 错误码创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class ErrorCodeCreateReqVO extends ErrorCodeBaseVO { - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeExcelVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeExcelVO.java deleted file mode 100644 index 8af519d25..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeExcelVO.java +++ /dev/null @@ -1,40 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.errorcode.vo; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import com.alibaba.excel.annotation.ExcelProperty; -import lombok.Data; - -import java.time.LocalDateTime; - -/** - * 错误码 Excel VO - * - * @author 芋道源码 - */ -@Data -public class ErrorCodeExcelVO { - - @ExcelProperty("错误码编号") - private Long id; - - @ExcelProperty(value = "错误码类型", converter = DictConvert.class) - @DictFormat("inf_error_code_type") // TODO 芋艿:得思考下杂解决枚举值 - private Integer type; - - @ExcelProperty("应用名") - private String applicationName; - - @ExcelProperty("错误码编码") - private Integer code; - - @ExcelProperty("错误码错误提示") - private String message; - - @ExcelProperty("备注") - private String memo; - - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeExportReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeExportReqVO.java deleted file mode 100644 index a89d7190c..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeExportReqVO.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.errorcode.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 错误码 Excel 导出 Request VO,参数和 InfErrorCodePageReqVO 是一致的") -@Data -public class ErrorCodeExportReqVO { - - @Schema(description = "错误码类型", example = "1") - private Integer type; - - @Schema(description = "应用名", example = "dashboard") - private String applicationName; - - @Schema(description = "错误码编码", example = "1234") - private Integer code; - - @Schema(description = "错误码错误提示", example = "帅气") - private String message; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @Schema(description = "创建时间") - private LocalDateTime[] createTime; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeRespVO.java index bd8e35fef..1bf13453f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeRespVO.java @@ -1,25 +1,51 @@ package cn.iocoder.yudao.module.system.controller.admin.errorcode.vo; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; +import javax.validation.constraints.NotNull; import java.time.LocalDateTime; @Schema(description = "管理后台 - 错误码 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class ErrorCodeRespVO extends ErrorCodeBaseVO { +@ExcelIgnoreUnannotated +public class ErrorCodeRespVO { @Schema(description = "错误码编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("错误码编号") private Long id; @Schema(description = "错误码类型,参见 ErrorCodeTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "错误码类型", converter = DictConvert.class) + @DictFormat(DictTypeConstants.ERROR_CODE_TYPE) private Integer type; + @Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "dashboard") + @NotNull(message = "应用名不能为空") + @ExcelProperty("应用名") + private String applicationName; + + @Schema(description = "错误码编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1234") + @NotNull(message = "错误码编码不能为空") + @ExcelProperty("错误码编码") + private Integer code; + + @Schema(description = "错误码错误提示", requiredMode = Schema.RequiredMode.REQUIRED, example = "帅气") + @NotNull(message = "错误码错误提示不能为空") + @ExcelProperty("错误码错误提示") + private String message; + + @Schema(description = "备注", example = "哈哈哈") + @ExcelProperty("备注") + private String memo; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") private LocalDateTime createTime; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeSaveReqVO.java similarity index 80% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeBaseVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeSaveReqVO.java index 3e222a070..d8b6b2125 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeSaveReqVO.java @@ -5,12 +5,12 @@ import lombok.Data; import javax.validation.constraints.NotNull; -/** -* 错误码 Base VO,提供给添加、修改、详细的子 VO 使用 -* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 -*/ +@Schema(description = "管理后台 - 错误码创建/修改 Request VO") @Data -public class ErrorCodeBaseVO { +public class ErrorCodeSaveReqVO { + + @Schema(description = "错误码编号", example = "1024") + private Long id; @Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "dashboard") @NotNull(message = "应用名不能为空") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeUpdateReqVO.java deleted file mode 100644 index 5b17591f0..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeUpdateReqVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.errorcode.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 错误码更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class ErrorCodeUpdateReqVO extends ErrorCodeBaseVO { - - @Schema(description = "错误码编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "错误码编号不能为空") - private Long id; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/errorcode/ErrorCodeConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/errorcode/ErrorCodeConvert.java deleted file mode 100644 index 436cde66d..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/errorcode/ErrorCodeConvert.java +++ /dev/null @@ -1,42 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.errorcode; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeAutoGenerateReqDTO; -import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeRespDTO; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeExcelVO; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeRespVO; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeUpdateReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.errorcode.ErrorCodeDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -/** - * 错误码 Convert - * - * @author 芋道源码 - */ -@Mapper -public interface ErrorCodeConvert { - - ErrorCodeConvert INSTANCE = Mappers.getMapper(ErrorCodeConvert.class); - - ErrorCodeDO convert(ErrorCodeCreateReqVO bean); - - ErrorCodeDO convert(ErrorCodeUpdateReqVO bean); - - ErrorCodeRespVO convert(ErrorCodeDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); - - List convertList02(List list); - - ErrorCodeDO convert(ErrorCodeAutoGenerateReqDTO bean); - - List convertList03(List list); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/errorcode/ErrorCodeMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/errorcode/ErrorCodeMapper.java index 93baced06..2e345e3ad 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/errorcode/ErrorCodeMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/errorcode/ErrorCodeMapper.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.dal.mysql.errorcode; 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.errorcode.vo.ErrorCodeExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodePageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.errorcode.ErrorCodeDO; import org.apache.ibatis.annotations.Mapper; @@ -25,16 +24,6 @@ public interface ErrorCodeMapper extends BaseMapperX { .orderByDesc(ErrorCodeDO::getCode)); } - default List selectList(ErrorCodeExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .eqIfPresent(ErrorCodeDO::getType, reqVO.getType()) - .likeIfPresent(ErrorCodeDO::getApplicationName, reqVO.getApplicationName()) - .eqIfPresent(ErrorCodeDO::getCode, reqVO.getCode()) - .likeIfPresent(ErrorCodeDO::getMessage, reqVO.getMessage()) - .betweenIfPresent(ErrorCodeDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(ErrorCodeDO::getCode)); - } - default List selectListByCodes(Collection codes) { return selectList(ErrorCodeDO::getCode, codes); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeService.java index e6a275612..b3894582d 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeService.java @@ -3,10 +3,8 @@ package cn.iocoder.yudao.module.system.service.errorcode; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeAutoGenerateReqDTO; import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeRespDTO; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.errorcode.ErrorCodeDO; import javax.validation.Valid; @@ -44,14 +42,14 @@ public interface ErrorCodeService { * @param createReqVO 创建信息 * @return 编号 */ - Long createErrorCode(@Valid ErrorCodeCreateReqVO createReqVO); + Long createErrorCode(@Valid ErrorCodeSaveReqVO createReqVO); /** * 更新错误码 * * @param updateReqVO 更新信息 */ - void updateErrorCode(@Valid ErrorCodeUpdateReqVO updateReqVO); + void updateErrorCode(@Valid ErrorCodeSaveReqVO updateReqVO); /** * 删除错误码 @@ -76,12 +74,4 @@ public interface ErrorCodeService { */ PageResult getErrorCodePage(ErrorCodePageReqVO pageReqVO); - /** - * 获得错误码列表, 用于 Excel 导出 - * - * @param exportReqVO 查询条件 - * @return 错误码列表 - */ - List getErrorCodeList(ErrorCodeExportReqVO exportReqVO); - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceImpl.java index ed0712a90..45dfb7c7d 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceImpl.java @@ -2,13 +2,11 @@ package cn.iocoder.yudao.module.system.service.errorcode; import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeAutoGenerateReqDTO; import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeRespDTO; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.errorcode.ErrorCodeConvert; +import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.errorcode.ErrorCodeDO; import cn.iocoder.yudao.module.system.dal.mysql.errorcode.ErrorCodeMapper; import cn.iocoder.yudao.module.system.enums.errorcode.ErrorCodeTypeEnum; @@ -43,12 +41,12 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { private ErrorCodeMapper errorCodeMapper; @Override - public Long createErrorCode(ErrorCodeCreateReqVO createReqVO) { + public Long createErrorCode(ErrorCodeSaveReqVO createReqVO) { // 校验 code 重复 validateCodeDuplicate(createReqVO.getCode(), null); // 插入 - ErrorCodeDO errorCode = ErrorCodeConvert.INSTANCE.convert(createReqVO) + ErrorCodeDO errorCode = BeanUtils.toBean(createReqVO, ErrorCodeDO.class) .setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType()); errorCodeMapper.insert(errorCode); // 返回 @@ -56,14 +54,14 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { } @Override - public void updateErrorCode(ErrorCodeUpdateReqVO updateReqVO) { + public void updateErrorCode(ErrorCodeSaveReqVO updateReqVO) { // 校验存在 validateErrorCodeExists(updateReqVO.getId()); // 校验 code 重复 validateCodeDuplicate(updateReqVO.getCode(), updateReqVO.getId()); // 更新 - ErrorCodeDO updateObj = ErrorCodeConvert.INSTANCE.convert(updateReqVO) + ErrorCodeDO updateObj = BeanUtils.toBean(updateReqVO, ErrorCodeDO.class) .setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType()); errorCodeMapper.updateById(updateObj); } @@ -116,11 +114,6 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { return errorCodeMapper.selectPage(pageReqVO); } - @Override - public List getErrorCodeList(ErrorCodeExportReqVO exportReqVO) { - return errorCodeMapper.selectList(exportReqVO); - } - @Override @Transactional public void autoGenerateErrorCodes(List autoGenerateDTOs) { @@ -134,40 +127,40 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { // 遍历 autoGenerateBOs 数组,逐个插入或更新。考虑到每次量级不大,就不走批量了 autoGenerateDTOs.forEach(autoGenerateDTO -> { - ErrorCodeDO errorCodeDO = errorCodeDOMap.get(autoGenerateDTO.getCode()); + ErrorCodeDO errorCode = errorCodeDOMap.get(autoGenerateDTO.getCode()); // 不存在,则进行新增 - if (errorCodeDO == null) { - errorCodeDO = ErrorCodeConvert.INSTANCE.convert(autoGenerateDTO) + if (errorCode == null) { + errorCode = BeanUtils.toBean(autoGenerateDTO, ErrorCodeDO.class) .setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType()); - errorCodeMapper.insert(errorCodeDO); + errorCodeMapper.insert(errorCode); return; } // 存在,则进行更新。更新有三个前置条件: // 条件 1. 只更新自动生成的错误码,即 Type 为 ErrorCodeTypeEnum.AUTO_GENERATION - if (!ErrorCodeTypeEnum.AUTO_GENERATION.getType().equals(errorCodeDO.getType())) { + if (!ErrorCodeTypeEnum.AUTO_GENERATION.getType().equals(errorCode.getType())) { return; } // 条件 2. 分组 applicationName 必须匹配,避免存在错误码冲突的情况 - if (!autoGenerateDTO.getApplicationName().equals(errorCodeDO.getApplicationName())) { + if (!autoGenerateDTO.getApplicationName().equals(errorCode.getApplicationName())) { log.error("[autoGenerateErrorCodes][自动创建({}/{}) 错误码失败,数据库中已经存在({}/{})]", autoGenerateDTO.getCode(), autoGenerateDTO.getApplicationName(), - errorCodeDO.getCode(), errorCodeDO.getApplicationName()); + errorCode.getCode(), errorCode.getApplicationName()); return; } // 条件 3. 错误提示语存在差异 - if (autoGenerateDTO.getMessage().equals(errorCodeDO.getMessage())) { + if (autoGenerateDTO.getMessage().equals(errorCode.getMessage())) { return; } // 最终匹配,进行更新 - errorCodeMapper.updateById(new ErrorCodeDO().setId(errorCodeDO.getId()).setMessage(autoGenerateDTO.getMessage())); + errorCodeMapper.updateById(new ErrorCodeDO().setId(errorCode.getId()).setMessage(autoGenerateDTO.getMessage())); }); } @Override public List getErrorCodeList(String applicationName, LocalDateTime minUpdateTime) { - List errorCodeDOs = errorCodeMapper.selectListByApplicationNameAndUpdateTimeGt( + List list = errorCodeMapper.selectListByApplicationNameAndUpdateTimeGt( applicationName, minUpdateTime); - return ErrorCodeConvert.INSTANCE.convertList03(errorCodeDOs); + return BeanUtils.toBean(list, ErrorCodeRespDTO.class); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceTest.java index cd5e01307..d35ee7b3a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceTest.java @@ -5,10 +5,8 @@ import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeAutoGenerateReqDTO; import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeRespDTO; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.errorcode.ErrorCodeDO; import cn.iocoder.yudao.module.system.dal.mysql.errorcode.ErrorCodeMapper; import cn.iocoder.yudao.module.system.enums.errorcode.ErrorCodeTypeEnum; @@ -44,7 +42,8 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { @Test public void testCreateErrorCode_success() { // 准备参数 - ErrorCodeCreateReqVO reqVO = randomPojo(ErrorCodeCreateReqVO.class); + ErrorCodeSaveReqVO reqVO = randomPojo(ErrorCodeSaveReqVO.class) + .setId(null); // 防止 id 被赋值 // 调用 Long errorCodeId = errorCodeService.createErrorCode(reqVO); @@ -52,7 +51,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { assertNotNull(errorCodeId); // 校验记录的属性是否正确 ErrorCodeDO errorCode = errorCodeMapper.selectById(errorCodeId); - assertPojoEquals(reqVO, errorCode); + assertPojoEquals(reqVO, errorCode, "id"); assertEquals(ErrorCodeTypeEnum.MANUAL_OPERATION.getType(), errorCode.getType()); } @@ -62,7 +61,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { ErrorCodeDO dbErrorCode = randomErrorCodeDO(); errorCodeMapper.insert(dbErrorCode);// @Sql: 先插入出一条存在的数据 // 准备参数 - ErrorCodeUpdateReqVO reqVO = randomPojo(ErrorCodeUpdateReqVO.class, o -> { + ErrorCodeSaveReqVO reqVO = randomPojo(ErrorCodeSaveReqVO.class, o -> { o.setId(dbErrorCode.getId()); // 设置更新的 ID }); @@ -133,25 +132,6 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { return dbErrorCode; } - @Test - public void testGetErrorCodeList_export() { - // mock 数据 - ErrorCodeDO dbErrorCode = initGetErrorCodePage(); - // 准备参数 - ErrorCodeExportReqVO reqVO = new ErrorCodeExportReqVO(); - reqVO.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType()); - reqVO.setApplicationName("tu"); - reqVO.setCode(1); - reqVO.setMessage("ma"); - reqVO.setCreateTime(buildBetweenTime(2020, 11, 1, 2020, 11, 30)); - - // 调用 - List list = errorCodeService.getErrorCodeList(reqVO); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbErrorCode, list.get(0)); - } - @Test public void testValidateCodeDuplicate_codeDuplicateForCreate() { // 准备参数 From 4225db217d180467f05912c02a058cac5efe1602 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 2 Dec 2023 19:25:25 +0800 Subject: [PATCH 04/19] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20login?= =?UTF-8?q?Log=20=E5=92=8C=20operateLog=20=E6=A8=A1=E5=9D=97=E7=9A=84=20VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/errorcode/vo/ErrorCodeRespVO.java | 3 - .../admin/logger/LoginLogController.java | 26 +++--- .../admin/logger/OperateLogController.java | 54 +++++------- .../logger/vo/loginlog/LoginLogBaseVO.java | 42 --------- .../logger/vo/loginlog/LoginLogExcelVO.java | 40 --------- .../vo/loginlog/LoginLogExportReqVO.java | 28 ------ .../logger/vo/loginlog/LoginLogRespVO.java | 41 +++++++-- .../vo/operatelog/OperateLogBaseVO.java | 85 ------------------- .../vo/operatelog/OperateLogExcelVO.java | 42 --------- .../vo/operatelog/OperateLogExportReqVO.java | 31 ------- .../vo/operatelog/OperateLogRespVO.java | 80 +++++++++++++++-- .../convert/logger/LoginLogConvert.java | 24 ------ .../convert/logger/OperateLogConvert.java | 31 ++----- .../dal/mysql/logger/LoginLogMapper.java | 17 ---- .../dal/mysql/logger/OperateLogMapper.java | 17 ---- .../service/logger/LoginLogService.java | 18 +--- .../service/logger/LoginLogServiceImpl.java | 15 +--- .../service/logger/OperateLogService.java | 15 +--- .../service/logger/OperateLogServiceImpl.java | 40 +++------ .../logger/LoginLogServiceImplTest.java | 34 -------- .../logger/OperateLogServiceImplTest.java | 51 +---------- 21 files changed, 176 insertions(+), 558 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/loginlog/LoginLogBaseVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/loginlog/LoginLogExcelVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/loginlog/LoginLogExportReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogBaseVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogExcelVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogExportReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/logger/LoginLogConvert.java diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeRespVO.java index 1bf13453f..67199c683 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeRespVO.java @@ -26,17 +26,14 @@ public class ErrorCodeRespVO { private Integer type; @Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "dashboard") - @NotNull(message = "应用名不能为空") @ExcelProperty("应用名") private String applicationName; @Schema(description = "错误码编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1234") - @NotNull(message = "错误码编码不能为空") @ExcelProperty("错误码编码") private Integer code; @Schema(description = "错误码错误提示", requiredMode = Schema.RequiredMode.REQUIRED, example = "帅气") - @NotNull(message = "错误码错误提示不能为空") @ExcelProperty("错误码错误提示") private String message; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/LoginLogController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/LoginLogController.java index f5262697a..70d586d88 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/LoginLogController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/LoginLogController.java @@ -1,18 +1,17 @@ package cn.iocoder.yudao.module.system.controller.admin.logger; -import cn.iocoder.yudao.module.system.dal.dataobject.logger.LoginLogDO; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogExcelVO; -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogRespVO; -import cn.iocoder.yudao.module.system.convert.logger.LoginLogConvert; +import cn.iocoder.yudao.module.system.dal.dataobject.logger.LoginLogDO; import cn.iocoder.yudao.module.system.service.logger.LoginLogService; -import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; @@ -25,6 +24,7 @@ import javax.validation.Valid; import java.io.IOException; import java.util.List; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; @Tag(name = "管理后台 - 登录日志") @@ -39,21 +39,21 @@ public class LoginLogController { @GetMapping("/page") @Operation(summary = "获得登录日志分页列表") @PreAuthorize("@ss.hasPermission('system:login-log:query')") - public CommonResult> getLoginLogPage(@Valid LoginLogPageReqVO reqVO) { - PageResult page = loginLogService.getLoginLogPage(reqVO); - return CommonResult.success(LoginLogConvert.INSTANCE.convertPage(page)); + public CommonResult> getLoginLogPage(@Valid LoginLogPageReqVO pageReqVO) { + PageResult pageResult = loginLogService.getLoginLogPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, LoginLogRespVO.class)); } @GetMapping("/export") @Operation(summary = "导出登录日志 Excel") @PreAuthorize("@ss.hasPermission('system:login-log:export')") @OperateLog(type = EXPORT) - public void exportLoginLog(HttpServletResponse response, @Valid LoginLogExportReqVO reqVO) throws IOException { - List list = loginLogService.getLoginLogList(reqVO); - // 拼接数据 - List data = LoginLogConvert.INSTANCE.convertList(list); + public void exportLoginLog(HttpServletResponse response, @Valid LoginLogPageReqVO exportReqVO) throws IOException { + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = loginLogService.getLoginLogPage(exportReqVO).getList(); // 输出 - ExcelUtils.write(response, "登录日志.xls", "数据列表", LoginLogExcelVO.class, data); + ExcelUtils.write(response, "登录日志.xls", "数据列表", LoginLogRespVO.class, + BeanUtils.toBean(list, LoginLogRespVO.class)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/OperateLogController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/OperateLogController.java index fc035f471..277aa0a75 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/OperateLogController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/OperateLogController.java @@ -1,22 +1,19 @@ package cn.iocoder.yudao.module.system.controller.admin.logger; -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExcelVO; -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExportReqVO; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogRespVO; import cn.iocoder.yudao.module.system.convert.logger.OperateLogConvert; import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; import cn.iocoder.yudao.module.system.service.logger.OperateLogService; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.framework.common.util.collection.MapUtils; -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.module.system.service.user.AdminUserService; -import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; @@ -27,12 +24,11 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Map; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; @Tag(name = "管理后台 - 操作日志") @@ -49,37 +45,27 @@ public class OperateLogController { @GetMapping("/page") @Operation(summary = "查看操作日志分页列表") @PreAuthorize("@ss.hasPermission('system:operate-log:query')") - public CommonResult> pageOperateLog(@Valid OperateLogPageReqVO reqVO) { - PageResult pageResult = operateLogService.getOperateLogPage(reqVO); - + public CommonResult> pageOperateLog(@Valid OperateLogPageReqVO pageReqVO) { + PageResult pageResult = operateLogService.getOperateLogPage(pageReqVO); // 获得拼接需要的数据 - Collection userIds = CollectionUtils.convertList(pageResult.getList(), OperateLogDO::getUserId); - Map userMap = userService.getUserMap(userIds); - // 拼接数据 - List list = new ArrayList<>(pageResult.getList().size()); - pageResult.getList().forEach(operateLog -> { - OperateLogRespVO respVO = OperateLogConvert.INSTANCE.convert(operateLog); - list.add(respVO); - // 拼接用户信息 - MapUtils.findAndThen(userMap, operateLog.getUserId(), user -> respVO.setUserNickname(user.getNickname())); - }); - return success(new PageResult<>(list, pageResult.getTotal())); + Map userMap = userService.getUserMap( + convertList(pageResult.getList(), OperateLogDO::getUserId)); + return success(new PageResult<>(OperateLogConvert.INSTANCE.convertList(pageResult.getList(), userMap), + pageResult.getTotal())); } @Operation(summary = "导出操作日志") @GetMapping("/export") @PreAuthorize("@ss.hasPermission('system:operate-log:export')") @OperateLog(type = EXPORT) - public void exportOperateLog(HttpServletResponse response, @Valid OperateLogExportReqVO reqVO) throws IOException { - List list = operateLogService.getOperateLogList(reqVO); - - // 获得拼接需要的数据 - Collection userIds = CollectionUtils.convertList(list, OperateLogDO::getUserId); - Map userMap = userService.getUserMap(userIds); - // 拼接数据 - List excelDataList = OperateLogConvert.INSTANCE.convertList(list, userMap); + public void exportOperateLog(HttpServletResponse response, @Valid OperateLogPageReqVO exportReqVO) throws IOException { + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = operateLogService.getOperateLogPage(exportReqVO).getList(); // 输出 - ExcelUtils.write(response, "操作日志.xls", "数据列表", OperateLogExcelVO.class, excelDataList); + Map userMap = userService.getUserMap( + convertList(list, OperateLogDO::getUserId)); + ExcelUtils.write(response, "操作日志.xls", "数据列表", OperateLogRespVO.class, + OperateLogConvert.INSTANCE.convertList(list, userMap)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/loginlog/LoginLogBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/loginlog/LoginLogBaseVO.java deleted file mode 100644 index 0a8736a80..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/loginlog/LoginLogBaseVO.java +++ /dev/null @@ -1,42 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; - -/** - * 登录日志 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ -@Data -public class LoginLogBaseVO { - - @Schema(description = "日志类型,参见 LoginLogTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "日志类型不能为空") - private Integer logType; - - @Schema(description = "链路追踪编号", example = "89aca178-a370-411c-ae02-3f0d672be4ab") - @NotEmpty(message = "链路追踪编号不能为空") - private String traceId; - - @Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao") - @NotBlank(message = "用户账号不能为空") - @Size(max = 30, message = "用户账号长度不能超过30个字符") - private String username; - - @Schema(description = "登录结果,参见 LoginResultEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "登录结果不能为空") - private Integer result; - - @Schema(description = "用户 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "127.0.0.1") - @NotEmpty(message = "用户 IP 不能为空") - private String userIp; - - @Schema(description = "浏览器 UserAgent", example = "Mozilla/5.0") - private String userAgent; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/loginlog/LoginLogExcelVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/loginlog/LoginLogExcelVO.java deleted file mode 100644 index 897fe4497..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/loginlog/LoginLogExcelVO.java +++ /dev/null @@ -1,40 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import cn.iocoder.yudao.module.system.enums.DictTypeConstants; -import com.alibaba.excel.annotation.ExcelProperty; -import lombok.Data; - -import java.time.LocalDateTime; - -/** - * 登录日志 Excel 导出响应 VO - */ -@Data -public class LoginLogExcelVO { - - @ExcelProperty("日志主键") - private Long id; - - @ExcelProperty("用户账号") - private String username; - - @ExcelProperty(value = "日志类型", converter = DictConvert.class) - @DictFormat(DictTypeConstants.LOGIN_TYPE) - private Integer logType; - - @ExcelProperty(value = "登录结果", converter = DictConvert.class) - @DictFormat(DictTypeConstants.LOGIN_RESULT) - private Integer result; - - @ExcelProperty("登录 IP") - private String userIp; - - @ExcelProperty("浏览器 UA") - private String userAgent; - - @ExcelProperty("登录时间") - private LocalDateTime createTime; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/loginlog/LoginLogExportReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/loginlog/LoginLogExportReqVO.java deleted file mode 100644 index d957771e0..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/loginlog/LoginLogExportReqVO.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 登录日志分页列表 Request VO") -@Data -public class LoginLogExportReqVO { - - @Schema(description = "用户 IP,模拟匹配", example = "127.0.0.1") - private String userIp; - - @Schema(description = "用户账号,模拟匹配", example = "芋道") - private String username; - - @Schema(description = "操作状态", example = "true") - private Boolean status; - - @Schema(description = "登录时间", example = "[2022-07-01 00:00:00,2022-07-01 23:59:59]") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] createTime; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/loginlog/LoginLogRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/loginlog/LoginLogRespVO.java index 0d69e7d3c..7b9cd165e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/loginlog/LoginLogRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/loginlog/LoginLogRespVO.java @@ -1,30 +1,57 @@ package cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; -import javax.validation.constraints.NotNull; import java.time.LocalDateTime; @Schema(description = "管理后台 - 登录日志 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class LoginLogRespVO extends LoginLogBaseVO { +@ExcelIgnoreUnannotated +public class LoginLogRespVO { @Schema(description = "日志编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("日志主键") private Long id; + @Schema(description = "日志类型,参见 LoginLogTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "日志类型", converter = DictConvert.class) + @DictFormat(DictTypeConstants.LOGIN_TYPE) + private Integer logType; + @Schema(description = "用户编号", example = "666") private Long userId; @Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") - @NotNull(message = "用户类型不能为空") private Integer userType; + @Schema(description = "链路追踪编号", example = "89aca178-a370-411c-ae02-3f0d672be4ab") + private String traceId; + + @Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao") + @ExcelProperty("用户账号") + private String username; + + @Schema(description = "登录结果,参见 LoginResultEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "登录结果", converter = DictConvert.class) + @DictFormat(DictTypeConstants.LOGIN_RESULT) + private Integer result; + + @Schema(description = "用户 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "127.0.0.1") + @ExcelProperty("登录 IP") + private String userIp; + + @Schema(description = "浏览器 UserAgent", example = "Mozilla/5.0") + @ExcelProperty("浏览器 UA") + private String userAgent; + @Schema(description = "登录时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("登录时间") private LocalDateTime createTime; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogBaseVO.java deleted file mode 100644 index c07cc8e1f..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogBaseVO.java +++ /dev/null @@ -1,85 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; -import java.time.LocalDateTime; -import java.util.Map; - -/** - * 操作日志 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ -@Data -public class OperateLogBaseVO { - - @Schema(description = "链路追踪编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "89aca178-a370-411c-ae02-3f0d672be4ab") - @NotEmpty(message = "链路追踪编号不能为空") - private String traceId; - - @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "用户编号不能为空") - private Long userId; - - @Schema(description = "操作模块", requiredMode = Schema.RequiredMode.REQUIRED, example = "订单") - @NotEmpty(message = "操作模块不能为空") - private String module; - - @Schema(description = "操作名", requiredMode = Schema.RequiredMode.REQUIRED, example = "创建订单") - @NotEmpty(message = "操作名") - private String name; - - @Schema(description = "操作分类,参见 OperateLogTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "操作分类不能为空") - private Integer type; - - @Schema(description = "操作明细", example = "修改编号为 1 的用户信息,将性别从男改成女,将姓名从芋道改成源码。") - private String content; - - @Schema(description = "拓展字段", example = "{'orderId': 1}") - private Map exts; - - @Schema(description = "请求方法名", requiredMode = Schema.RequiredMode.REQUIRED, example = "GET") - @NotEmpty(message = "请求方法名不能为空") - private String requestMethod; - - @Schema(description = "请求地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "/xxx/yyy") - @NotEmpty(message = "请求地址不能为空") - private String requestUrl; - - @Schema(description = "用户 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "127.0.0.1") - @NotEmpty(message = "用户 IP 不能为空") - private String userIp; - - @Schema(description = "浏览器 UserAgent", requiredMode = Schema.RequiredMode.REQUIRED, example = "Mozilla/5.0") - @NotEmpty(message = "浏览器 UserAgent 不能为空") - private String userAgent; - - @Schema(description = "Java 方法名", requiredMode = Schema.RequiredMode.REQUIRED, example = "cn.iocoder.yudao.adminserver.UserController.save(...)") - @NotEmpty(message = "Java 方法名不能为空") - private String javaMethod; - - @Schema(description = "Java 方法的参数") - private String javaMethodArgs; - - @Schema(description = "开始时间", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "开始时间不能为空") - private LocalDateTime startTime; - - @Schema(description = "执行时长,单位:毫秒", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "执行时长不能为空") - private Integer duration; - - @Schema(description = "结果码", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "结果码不能为空") - private Integer resultCode; - - @Schema(description = "结果提示") - private String resultMsg; - - @Schema(description = "结果数据") - private String resultData; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogExcelVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogExcelVO.java deleted file mode 100644 index 8285a9bf5..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogExcelVO.java +++ /dev/null @@ -1,42 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import cn.iocoder.yudao.module.system.enums.DictTypeConstants; -import com.alibaba.excel.annotation.ExcelProperty; -import lombok.Data; - -import java.time.LocalDateTime; - -/** - * 操作日志 Excel 导出响应 VO - */ -@Data -public class OperateLogExcelVO { - - @ExcelProperty("日志编号") - private Long id; - - @ExcelProperty("操作模块") - private String module; - - @ExcelProperty("操作名") - private String name; - - @ExcelProperty(value = "操作类型", converter = DictConvert.class) - @DictFormat(DictTypeConstants.OPERATE_TYPE) - private String type; - - @ExcelProperty("操作人") - private String userNickname; - - @ExcelProperty(value = "操作结果") // 成功 or 失败 - private String successStr; - - @ExcelProperty("操作日志") - private LocalDateTime startTime; - - @ExcelProperty("执行时长") - private Integer duration; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogExportReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogExportReqVO.java deleted file mode 100644 index b25953027..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogExportReqVO.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 操作日志分页列表 Request VO") -@Data -public class OperateLogExportReqVO { - - @Schema(description = "操作模块,模拟匹配", example = "订单") - private String module; - - @Schema(description = "用户昵称,模拟匹配", example = "芋道") - private String userNickname; - - @Schema(description = "操作分类,参见 OperateLogTypeEnum 枚举类", example = "1") - private Integer type; - - @Schema(description = "操作状态", example = "true") - private Boolean success; - - @Schema(description = "开始时间", example = "[2022-07-01 00:00:00,2022-07-01 23:59:59]") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] startTime; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogRespVO.java index 5ed6ae948..3de8d669e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogRespVO.java @@ -1,20 +1,90 @@ package cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; + +import javax.validation.constraints.NotEmpty; +import java.time.LocalDateTime; +import java.util.Map; @Schema(description = "管理后台 - 操作日志 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class OperateLogRespVO extends OperateLogBaseVO { +@ExcelIgnoreUnannotated +public class OperateLogRespVO { @Schema(description = "日志编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("日志编号") private Long id; + @Schema(description = "链路追踪编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "89aca178-a370-411c-ae02-3f0d672be4ab") + private String traceId; + + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Long userId; + @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") + @ExcelProperty("操作人") private String userNickname; + @Schema(description = "操作模块", requiredMode = Schema.RequiredMode.REQUIRED, example = "订单") + @ExcelProperty("操作模块") + private String module; + + @Schema(description = "操作名", requiredMode = Schema.RequiredMode.REQUIRED, example = "创建订单") + @ExcelProperty("操作名") + private String name; + + @Schema(description = "操作分类,参见 OperateLogTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "操作类型", converter = DictConvert.class) + @DictFormat(DictTypeConstants.OPERATE_TYPE) + private Integer type; + + @Schema(description = "操作明细", example = "修改编号为 1 的用户信息,将性别从男改成女,将姓名从芋道改成源码。") + private String content; + + @Schema(description = "拓展字段", example = "{'orderId': 1}") + private Map exts; + + @Schema(description = "请求方法名", requiredMode = Schema.RequiredMode.REQUIRED, example = "GET") + @NotEmpty(message = "请求方法名不能为空") + private String requestMethod; + + @Schema(description = "请求地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "/xxx/yyy") + private String requestUrl; + + @Schema(description = "用户 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "127.0.0.1") + private String userIp; + + @Schema(description = "浏览器 UserAgent", requiredMode = Schema.RequiredMode.REQUIRED, example = "Mozilla/5.0") + private String userAgent; + + @Schema(description = "Java 方法名", requiredMode = Schema.RequiredMode.REQUIRED, example = "cn.iocoder.yudao.adminserver.UserController.save(...)") + private String javaMethod; + + @Schema(description = "Java 方法的参数") + private String javaMethodArgs; + + @Schema(description = "开始时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("操作日志") + private LocalDateTime startTime; + + @Schema(description = "执行时长,单位:毫秒", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("执行时长") + private Integer duration; + + @Schema(description = "结果码", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty(value = "结果码") + private Integer resultCode; + + @Schema(description = "结果提示") + private String resultMsg; + + @Schema(description = "结果数据") + private String resultData; + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/logger/LoginLogConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/logger/LoginLogConvert.java deleted file mode 100644 index ea50d4b09..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/logger/LoginLogConvert.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.logger; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO; -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogExcelVO; -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogRespVO; -import cn.iocoder.yudao.module.system.dal.dataobject.logger.LoginLogDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper -public interface LoginLogConvert { - - LoginLogConvert INSTANCE = Mappers.getMapper(LoginLogConvert.class); - - PageResult convertPage(PageResult page); - - List convertList(List list); - - LoginLogDO convert(LoginLogCreateReqDTO bean); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/logger/OperateLogConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/logger/OperateLogConvert.java index e32ebd091..7b3aff8c0 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/logger/OperateLogConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/logger/OperateLogConvert.java @@ -1,41 +1,28 @@ package cn.iocoder.yudao.module.system.convert.logger; -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExcelVO; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogRespVO; import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.collection.MapUtils; -import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; - -import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.SUCCESS; @Mapper public interface OperateLogConvert { OperateLogConvert INSTANCE = Mappers.getMapper(OperateLogConvert.class); - OperateLogDO convert(OperateLogCreateReqDTO bean); - - PageResult convertPage(PageResult page); - - OperateLogRespVO convert(OperateLogDO bean); - - default List convertList(List list, Map userMap) { - return list.stream().map(operateLog -> { - OperateLogExcelVO excelVO = convert02(operateLog); - MapUtils.findAndThen(userMap, operateLog.getUserId(), user -> excelVO.setUserNickname(user.getNickname())); - excelVO.setSuccessStr(SUCCESS.getCode().equals(operateLog.getResultCode()) ? "成功" : "失败"); - return excelVO; - }).collect(Collectors.toList()); + default List convertList(List list, Map userMap) { + return CollectionUtils.convertList(list, log -> { + OperateLogRespVO logVO = BeanUtils.toBean(log, OperateLogRespVO.class); + MapUtils.findAndThen(userMap, log.getUserId(), user -> logVO.setUserNickname(user.getNickname())); + return logVO; + }); } - OperateLogExcelVO convert02(OperateLogDO bean); - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/logger/LoginLogMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/logger/LoginLogMapper.java index 1617fe075..0cb47ebe7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/logger/LoginLogMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/logger/LoginLogMapper.java @@ -3,14 +3,11 @@ package cn.iocoder.yudao.module.system.dal.mysql.logger; 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.logger.vo.loginlog.LoginLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.logger.LoginLogDO; import cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum; import org.apache.ibatis.annotations.Mapper; -import java.util.List; - @Mapper public interface LoginLogMapper extends BaseMapperX { @@ -28,18 +25,4 @@ public interface LoginLogMapper extends BaseMapperX { return selectPage(reqVO, query); } - default List selectList(LoginLogExportReqVO reqVO) { - LambdaQueryWrapperX query = new LambdaQueryWrapperX() - .likeIfPresent(LoginLogDO::getUserIp, reqVO.getUserIp()) - .likeIfPresent(LoginLogDO::getUsername, reqVO.getUsername()) - .betweenIfPresent(LoginLogDO::getCreateTime, reqVO.getCreateTime()); - if (Boolean.TRUE.equals(reqVO.getStatus())) { - query.eq(LoginLogDO::getResult, LoginResultEnum.SUCCESS.getResult()); - } else if (Boolean.FALSE.equals(reqVO.getStatus())) { - query.gt(LoginLogDO::getResult, LoginResultEnum.SUCCESS.getResult()); - } - query.orderByDesc(LoginLogDO::getId); // 降序 - return selectList(query); - } - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/logger/OperateLogMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/logger/OperateLogMapper.java index 86e53a510..0bed6b8cc 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/logger/OperateLogMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/logger/OperateLogMapper.java @@ -4,13 +4,11 @@ import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstant 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.logger.vo.operatelog.OperateLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO; import org.apache.ibatis.annotations.Mapper; import java.util.Collection; -import java.util.List; @Mapper public interface OperateLogMapper extends BaseMapperX { @@ -30,19 +28,4 @@ public interface OperateLogMapper extends BaseMapperX { return selectPage(reqVO, query); } - default List selectList(OperateLogExportReqVO reqVO, Collection userIds) { - LambdaQueryWrapperX query = new LambdaQueryWrapperX() - .likeIfPresent(OperateLogDO::getModule, reqVO.getModule()) - .inIfPresent(OperateLogDO::getUserId, userIds) - .eqIfPresent(OperateLogDO::getType, reqVO.getType()) - .betweenIfPresent(OperateLogDO::getStartTime, reqVO.getStartTime()); - if (Boolean.TRUE.equals(reqVO.getSuccess())) { - query.eq(OperateLogDO::getResultCode, GlobalErrorCodeConstants.SUCCESS.getCode()); - } else if (Boolean.FALSE.equals(reqVO.getSuccess())) { - query.gt(OperateLogDO::getResultCode, GlobalErrorCodeConstants.SUCCESS.getCode()); - } - query.orderByDesc(OperateLogDO::getId); // 降序 - return selectList(query); - } - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/LoginLogService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/LoginLogService.java index 38b4fe78e..64cd07b74 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/LoginLogService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/LoginLogService.java @@ -1,13 +1,11 @@ package cn.iocoder.yudao.module.system.service.logger; -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogExportReqVO; -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogPageReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.logger.LoginLogDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO; +import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogPageReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.logger.LoginLogDO; import javax.validation.Valid; -import java.util.List; /** * 登录日志 Service 接口 @@ -17,18 +15,10 @@ public interface LoginLogService { /** * 获得登录日志分页 * - * @param reqVO 分页条件 + * @param pageReqVO 分页条件 * @return 登录日志分页 */ - PageResult getLoginLogPage(LoginLogPageReqVO reqVO); - - /** - * 获得登录日志列表 - * - * @param reqVO 列表条件 - * @return 登录日志列表 - */ - List getLoginLogList(LoginLogExportReqVO reqVO); + PageResult getLoginLogPage(LoginLogPageReqVO pageReqVO); /** * 创建登录日志 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/LoginLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/LoginLogServiceImpl.java index 0b806f6da..e1de978c8 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/LoginLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/LoginLogServiceImpl.java @@ -1,17 +1,15 @@ package cn.iocoder.yudao.module.system.service.logger; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO; -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogPageReqVO; -import cn.iocoder.yudao.module.system.convert.logger.LoginLogConvert; import cn.iocoder.yudao.module.system.dal.dataobject.logger.LoginLogDO; import cn.iocoder.yudao.module.system.dal.mysql.logger.LoginLogMapper; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.util.List; /** * 登录日志 Service 实现 @@ -24,18 +22,13 @@ public class LoginLogServiceImpl implements LoginLogService { private LoginLogMapper loginLogMapper; @Override - public PageResult getLoginLogPage(LoginLogPageReqVO reqVO) { - return loginLogMapper.selectPage(reqVO); - } - - @Override - public List getLoginLogList(LoginLogExportReqVO reqVO) { - return loginLogMapper.selectList(reqVO); + public PageResult getLoginLogPage(LoginLogPageReqVO pageReqVO) { + return loginLogMapper.selectPage(pageReqVO); } @Override public void createLoginLog(LoginLogCreateReqDTO reqDTO) { - LoginLogDO loginLog = LoginLogConvert.INSTANCE.convert(reqDTO); + LoginLogDO loginLog = BeanUtils.toBean(reqDTO, LoginLogDO.class); loginLogMapper.insert(loginLog); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/OperateLogService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/OperateLogService.java index 434ecbc46..89e562c65 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/OperateLogService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/OperateLogService.java @@ -2,12 +2,9 @@ package cn.iocoder.yudao.module.system.service.logger; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO; -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO; -import java.util.List; - /** * 操作日志 Service 接口 * @@ -25,17 +22,9 @@ public interface OperateLogService { /** * 获得操作日志分页列表 * - * @param reqVO 分页条件 + * @param pageReqVO 分页条件 * @return 操作日志分页列表 */ - PageResult getOperateLogPage(OperateLogPageReqVO reqVO); - - /** - * 获得操作日志列表 - * - * @param reqVO 列表条件 - * @return 日志列表 - */ - List getOperateLogList(OperateLogExportReqVO reqVO); + PageResult getOperateLogPage(OperateLogPageReqVO pageReqVO); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/OperateLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/OperateLogServiceImpl.java index c899696ac..5890a7fb4 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/OperateLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/OperateLogServiceImpl.java @@ -3,11 +3,10 @@ package cn.iocoder.yudao.module.system.service.logger; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.string.StrUtils; import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO; -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO; -import cn.iocoder.yudao.module.system.convert.logger.OperateLogConvert; import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; import cn.iocoder.yudao.module.system.dal.mysql.logger.OperateLogMapper; @@ -18,13 +17,16 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.Collection; -import java.util.Collections; -import java.util.List; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO.JAVA_METHOD_ARGS_MAX_LENGTH; import static cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO.RESULT_MAX_LENGTH; +/** + * 操作日志 Service 实现类 + * + * @author 芋道源码 + */ @Service @Validated @Slf4j @@ -38,38 +40,24 @@ public class OperateLogServiceImpl implements OperateLogService { @Override public void createOperateLog(OperateLogCreateReqDTO createReqDTO) { - OperateLogDO logDO = OperateLogConvert.INSTANCE.convert(createReqDTO); - logDO.setJavaMethodArgs(StrUtils.maxLength(logDO.getJavaMethodArgs(), JAVA_METHOD_ARGS_MAX_LENGTH)); - logDO.setResultData(StrUtils.maxLength(logDO.getResultData(), RESULT_MAX_LENGTH)); - operateLogMapper.insert(logDO); + OperateLogDO log = BeanUtils.toBean(createReqDTO, OperateLogDO.class); + log.setJavaMethodArgs(StrUtils.maxLength(log.getJavaMethodArgs(), JAVA_METHOD_ARGS_MAX_LENGTH)); + log.setResultData(StrUtils.maxLength(log.getResultData(), RESULT_MAX_LENGTH)); + operateLogMapper.insert(log); } @Override - public PageResult getOperateLogPage(OperateLogPageReqVO reqVO) { + public PageResult getOperateLogPage(OperateLogPageReqVO pageReqVO) { // 处理基于用户昵称的查询 Collection userIds = null; - if (StrUtil.isNotEmpty(reqVO.getUserNickname())) { - userIds = convertSet(userService.getUserListByNickname(reqVO.getUserNickname()), AdminUserDO::getId); + if (StrUtil.isNotEmpty(pageReqVO.getUserNickname())) { + userIds = convertSet(userService.getUserListByNickname(pageReqVO.getUserNickname()), AdminUserDO::getId); if (CollUtil.isEmpty(userIds)) { return PageResult.empty(); } } // 查询分页 - return operateLogMapper.selectPage(reqVO, userIds); - } - - @Override - public List getOperateLogList(OperateLogExportReqVO reqVO) { - // 处理基于用户昵称的查询 - Collection userIds = null; - if (StrUtil.isNotEmpty(reqVO.getUserNickname())) { - userIds = convertSet(userService.getUserListByNickname(reqVO.getUserNickname()), AdminUserDO::getId); - if (CollUtil.isEmpty(userIds)) { - return Collections.emptyList(); - } - } - // 查询列表 - return operateLogMapper.selectList(reqVO, userIds); + return operateLogMapper.selectPage(pageReqVO, userIds); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/logger/LoginLogServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/logger/LoginLogServiceImplTest.java index 66eebc0bd..530c27408 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/logger/LoginLogServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/logger/LoginLogServiceImplTest.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.service.logger; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO; -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.logger.LoginLogDO; import cn.iocoder.yudao.module.system.dal.mysql.logger.LoginLogMapper; @@ -11,7 +10,6 @@ import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Import; import javax.annotation.Resource; -import java.util.List; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; @@ -64,38 +62,6 @@ public class LoginLogServiceImplTest extends BaseDbUnitTest { assertPojoEquals(loginLogDO, pageResult.getList().get(0)); } - @Test - public void testGetLoginLogList() { - // mock 数据 - LoginLogDO loginLogDO = randomPojo(LoginLogDO.class, o -> { - o.setUserIp("192.168.199.16"); - o.setUsername("wang"); - o.setResult(SUCCESS.getResult()); - o.setCreateTime(buildTime(2021, 3, 6)); - }); - loginLogMapper.insert(loginLogDO); - // 测试 status 不匹配 - loginLogMapper.insert(cloneIgnoreId(loginLogDO, o -> o.setResult(CAPTCHA_CODE_ERROR.getResult()))); - // 测试 ip 不匹配 - loginLogMapper.insert(cloneIgnoreId(loginLogDO, o -> o.setUserIp("192.168.128.18"))); - // 测试 username 不匹配 - loginLogMapper.insert(cloneIgnoreId(loginLogDO, o -> o.setUsername("yunai"))); - // 测试 createTime 不匹配 - loginLogMapper.insert(cloneIgnoreId(loginLogDO, o -> o.setCreateTime(buildTime(2021, 2, 6)))); - // 构造调用参数 - LoginLogExportReqVO reqVO = new LoginLogExportReqVO(); - reqVO.setUsername("wang"); - reqVO.setUserIp("192.168.199"); - reqVO.setStatus(true); - reqVO.setCreateTime(buildBetweenTime(2021, 3, 5, 2021, 3, 7)); - - // 调用service方法 - List list = loginLogService.getLoginLogList(reqVO); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(loginLogDO, list.get(0)); - } - @Test public void testCreateLoginLog() { LoginLogCreateReqDTO reqDTO = randomPojo(LoginLogCreateReqDTO.class); diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/logger/OperateLogServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/logger/OperateLogServiceImplTest.java index 14b007e25..ecc01d796 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/logger/OperateLogServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/logger/OperateLogServiceImplTest.java @@ -9,7 +9,6 @@ import cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.framework.test.core.util.RandomUtils; import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO; -import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; @@ -21,7 +20,6 @@ import org.springframework.context.annotation.Import; import javax.annotation.Resource; import java.util.Collections; -import java.util.List; import static cn.hutool.core.util.RandomUtil.randomEle; import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST; @@ -46,7 +44,7 @@ public class OperateLogServiceImplTest extends BaseDbUnitTest { private AdminUserService userService; @Test - public void testCreateOperateLogAsync() { + public void testCreateOperateLog() { OperateLogCreateReqDTO reqVO = RandomUtils.randomPojo(OperateLogCreateReqDTO.class, o -> o.setExts(MapUtil.builder("orderId", randomLongId()).build())); @@ -105,51 +103,4 @@ public class OperateLogServiceImplTest extends BaseDbUnitTest { assertPojoEquals(operateLogDO, pageResult.getList().get(0)); } - @Test - public void testGetOperateLogs() { - // mock(用户信息) - AdminUserDO user = RandomUtils.randomPojo(AdminUserDO.class, o -> { - o.setNickname("wang"); - o.setStatus(CommonStatusEnum.ENABLE.getStatus()); - }); - when(userService.getUserListByNickname("wang")).thenReturn(Collections.singletonList(user)); - Long userId = user.getId(); - - // 构造操作日志 - OperateLogDO operateLogDO = RandomUtils.randomPojo(OperateLogDO.class, o -> { - o.setUserId(userId); - o.setUserType(randomEle(UserTypeEnum.values()).getValue()); - o.setModule("order"); - o.setType(OperateTypeEnum.CREATE.getType()); - o.setStartTime(buildTime(2021, 3, 6)); - o.setResultCode(GlobalErrorCodeConstants.SUCCESS.getCode()); - o.setExts(MapUtil.builder("orderId", randomLongId()).build()); - }); - operateLogMapper.insert(operateLogDO); - // 测试 userId 不匹配 - operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setUserId(userId + 1))); - // 测试 module 不匹配 - operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setModule("user"))); - // 测试 type 不匹配 - operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setType(OperateTypeEnum.IMPORT.getType()))); - // 测试 createTime 不匹配 - operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setStartTime(buildTime(2021, 2, 6)))); - // 测试 resultCode 不匹配 - operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setResultCode(BAD_REQUEST.getCode()))); - - // 构造调用参数 - OperateLogExportReqVO reqVO = new OperateLogExportReqVO(); - reqVO.setUserNickname("wang"); - reqVO.setModule("order"); - reqVO.setType(OperateTypeEnum.CREATE.getType()); - reqVO.setStartTime(buildBetweenTime(2021, 3, 5, 2021, 3, 7)); - reqVO.setSuccess(true); - - // 调用 service 方法 - List list = operateLogServiceImpl.getOperateLogList(reqVO); - // 断言,只查到了一条符合条件的 - assertEquals(1, list.size()); - assertPojoEquals(operateLogDO, list.get(0)); - } - } From b77b6322e1f46e44a633f24c948ce788e64c39db Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 2 Dec 2023 19:54:58 +0800 Subject: [PATCH 05/19] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20mail?= =?UTF-8?q?=20=E6=A8=A1=E5=9D=97=E7=9A=84=20VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/dict/DictDataController.java | 2 +- .../admin/mail/MailAccountController.java | 23 +++--- .../admin/mail/MailLogController.java | 8 +- .../admin/mail/MailTemplateController.java | 16 ++-- .../vo/account/MailAccountCreateReqVO.java | 14 ---- .../mail/vo/account/MailAccountRespVO.java | 26 +++++-- ...tBaseVO.java => MailAccountSaveReqVO.java} | 10 +-- .../vo/account/MailAccountUpdateReqVO.java | 20 ----- .../admin/mail/vo/log/MailLogBaseVO.java | 75 ------------------- .../admin/mail/vo/log/MailLogRespVO.java | 56 +++++++++++++- .../vo/template/MailTemplateCreateReqVO.java | 14 ---- .../mail/vo/template/MailTemplateRespVO.java | 32 ++++++-- ...BaseVO.java => MailTemplateSaveReqVO.java} | 10 +-- .../vo/template/MailTemplateUpdateReqVO.java | 20 ----- .../convert/mail/MailAccountConvert.java | 14 ---- .../system/convert/mail/MailLogConvert.java | 18 ----- .../convert/mail/MailTemplateConvert.java | 26 ------- .../service/mail/MailAccountService.java | 7 +- .../service/mail/MailAccountServiceImpl.java | 16 ++-- .../service/mail/MailLogServiceImpl.java | 1 - .../service/mail/MailTemplateService.java | 9 +-- .../service/mail/MailTemplateServiceImpl.java | 15 ++-- .../mail/MailAccountServiceImplTest.java | 14 ++-- .../mail/MailTemplateServiceImplTest.java | 14 ++-- 24 files changed, 169 insertions(+), 291 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/{MailAccountBaseVO.java => MailAccountSaveReqVO.java} (87%) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java delete mode 100755 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogBaseVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateCreateReqVO.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/{MailTemplateBaseVO.java => MailTemplateSaveReqVO.java} (88%) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateUpdateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailLogConvert.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/DictDataController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/DictDataController.java index 4075e49df..a2b8d6f56 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/DictDataController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/DictDataController.java @@ -62,7 +62,7 @@ public class DictDataController { return success(true); } - @GetMapping("/list-all-simple") + @GetMapping(value = {"/list-all-simple", "simple-list"}) @Operation(summary = "获得全部字典数据列表", description = "一般用于管理后台缓存字典数据在本地") // 无需添加权限认证,因为前端全局都需要 public CommonResult> getSimpleDictDataList() { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java index 718e4b4fb..e01b29bb5 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java @@ -3,8 +3,11 @@ package cn.iocoder.yudao.module.system.controller.admin.mail; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.*; -import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountRespVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountSaveReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountSimpleRespVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.service.mail.MailAccountService; import io.swagger.v3.oas.annotations.Operation; @@ -30,14 +33,14 @@ public class MailAccountController { @PostMapping("/create") @Operation(summary = "创建邮箱账号") @PreAuthorize("@ss.hasPermission('system:mail-account:create')") - public CommonResult createMailAccount(@Valid @RequestBody MailAccountCreateReqVO createReqVO) { + public CommonResult createMailAccount(@Valid @RequestBody MailAccountSaveReqVO createReqVO) { return success(mailAccountService.createMailAccount(createReqVO)); } @PutMapping("/update") @Operation(summary = "修改邮箱账号") @PreAuthorize("@ss.hasPermission('system:mail-account:update')") - public CommonResult updateMailAccount(@Valid @RequestBody MailAccountUpdateReqVO updateReqVO) { + public CommonResult updateMailAccount(@Valid @RequestBody MailAccountSaveReqVO updateReqVO) { mailAccountService.updateMailAccount(updateReqVO); return success(true); } @@ -56,23 +59,23 @@ public class MailAccountController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('system:mail-account:get')") public CommonResult getMailAccount(@RequestParam("id") Long id) { - MailAccountDO mailAccountDO = mailAccountService.getMailAccount(id); - return success(MailAccountConvert.INSTANCE.convert(mailAccountDO)); + MailAccountDO account = mailAccountService.getMailAccount(id); + return success(BeanUtils.toBean(account, MailAccountRespVO.class)); } @GetMapping("/page") @Operation(summary = "获得邮箱账号分页") @PreAuthorize("@ss.hasPermission('system:mail-account:query')") - public CommonResult> getMailAccountPage(@Valid MailAccountPageReqVO pageReqVO) { + public CommonResult> getMailAccountPage(@Valid MailAccountPageReqVO pageReqVO) { PageResult pageResult = mailAccountService.getMailAccountPage(pageReqVO); - return success(MailAccountConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, MailAccountRespVO.class)); } - @GetMapping("/list-all-simple") + @GetMapping({"/list-all-simple", "simple-list"}) @Operation(summary = "获得邮箱账号精简列表") public CommonResult> getSimpleMailAccountList() { List list = mailAccountService.getMailAccountList(); - return success(MailAccountConvert.INSTANCE.convertList02(list)); + return success(BeanUtils.toBean(list, MailAccountSimpleRespVO.class)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailLogController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailLogController.java index 1347f6ac6..c2669ec52 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailLogController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailLogController.java @@ -2,9 +2,9 @@ package cn.iocoder.yudao.module.system.controller.admin.mail; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogRespVO; -import cn.iocoder.yudao.module.system.convert.mail.MailLogConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO; import cn.iocoder.yudao.module.system.service.mail.MailLogService; import io.swagger.v3.oas.annotations.Operation; @@ -34,7 +34,7 @@ public class MailLogController { @PreAuthorize("@ss.hasPermission('system:mail-log:query')") public CommonResult> getMailLogPage(@Valid MailLogPageReqVO pageVO) { PageResult pageResult = mailLogService.getMailLogPage(pageVO); - return success(MailLogConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, MailLogRespVO.class)); } @GetMapping("/get") @@ -42,8 +42,8 @@ public class MailLogController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('system:mail-log:query')") public CommonResult getMailTemplate(@RequestParam("id") Long id) { - MailLogDO mailLogDO = mailLogService.getMailLog(id); - return success(MailLogConvert.INSTANCE.convert(mailLogDO)); + MailLogDO log = mailLogService.getMailLog(id); + return success(BeanUtils.toBean(log, MailLogRespVO.class)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java index d41732278..3a171ee62 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java @@ -2,8 +2,8 @@ package cn.iocoder.yudao.module.system.controller.admin.mail; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.*; -import cn.iocoder.yudao.module.system.convert.mail.MailTemplateConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.service.mail.MailSendService; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; @@ -33,14 +33,14 @@ public class MailTemplateController { @PostMapping("/create") @Operation(summary = "创建邮件模版") @PreAuthorize("@ss.hasPermission('system:mail-template:create')") - public CommonResult createMailTemplate(@Valid @RequestBody MailTemplateCreateReqVO createReqVO){ + public CommonResult createMailTemplate(@Valid @RequestBody MailTemplateSaveReqVO createReqVO){ return success(mailTempleService.createMailTemplate(createReqVO)); } @PutMapping("/update") @Operation(summary = "修改邮件模版") @PreAuthorize("@ss.hasPermission('system:mail-template:update')") - public CommonResult updateMailTemplate(@Valid @RequestBody MailTemplateUpdateReqVO updateReqVO){ + public CommonResult updateMailTemplate(@Valid @RequestBody MailTemplateSaveReqVO updateReqVO){ mailTempleService.updateMailTemplate(updateReqVO); return success(true); } @@ -59,8 +59,8 @@ public class MailTemplateController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('system:mail-template:get')") public CommonResult getMailTemplate(@RequestParam("id") Long id) { - MailTemplateDO mailTemplateDO = mailTempleService.getMailTemplate(id); - return success(MailTemplateConvert.INSTANCE.convert(mailTemplateDO)); + MailTemplateDO template = mailTempleService.getMailTemplate(id); + return success(BeanUtils.toBean(template, MailTemplateRespVO.class)); } @GetMapping("/page") @@ -68,14 +68,14 @@ public class MailTemplateController { @PreAuthorize("@ss.hasPermission('system:mail-template:query')") public CommonResult> getMailTemplatePage(@Valid MailTemplatePageReqVO pageReqVO) { PageResult pageResult = mailTempleService.getMailTemplatePage(pageReqVO); - return success(MailTemplateConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, MailTemplateRespVO.class)); } - @GetMapping("/list-all-simple") + @GetMapping({"/list-all-simple", "simple-list"}) @Operation(summary = "获得邮件模版精简列表") public CommonResult> getSimpleTemplateList() { List list = mailTempleService.getMailTemplateList(); - return success(MailTemplateConvert.INSTANCE.convertList02(list)); + return success(BeanUtils.toBean(list, MailTemplateSimpleRespVO.class)); } @PostMapping("/send-mail") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java deleted file mode 100644 index 6776ad9f7..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountCreateReqVO.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -@Schema(description = "管理后台 - 邮箱账号创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class MailAccountCreateReqVO extends MailAccountBaseVO { - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountRespVO.java index dcc42f408..c1dc376df 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountRespVO.java @@ -2,22 +2,34 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; -import javax.validation.constraints.NotNull; import java.time.LocalDateTime; @Schema(description = "管理后台 - 邮箱账号 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class MailAccountRespVO extends MailAccountBaseVO { +public class MailAccountRespVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "编号不能为空") private Long id; + @Schema(description = "邮箱", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudaoyuanma@123.com") + private String mail; + + @Schema(description = "用户名", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao") + private String username; + + @Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456") + private String password; + + @Schema(description = "SMTP 服务器域名", requiredMode = Schema.RequiredMode.REQUIRED, example = "www.iocoder.cn") + private String host; + + @Schema(description = "SMTP 服务器端口", requiredMode = Schema.RequiredMode.REQUIRED, example = "80") + private Integer port; + + @Schema(description = "是否开启 ssl", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") + private Boolean sslEnable; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountSaveReqVO.java similarity index 87% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountSaveReqVO.java index 799342e58..83a7647eb 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountSaveReqVO.java @@ -6,12 +6,12 @@ import lombok.Data; import javax.validation.constraints.Email; import javax.validation.constraints.NotNull; -/** - * 邮箱账号 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ +@Schema(description = "管理后台 - 邮箱账号创建/修改 Request VO") @Data -public class MailAccountBaseVO { +public class MailAccountSaveReqVO { + + @Schema(description = "编号", example = "1024") + private Long id; @Schema(description = "邮箱", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudaoyuanma@123.com") @NotNull(message = "邮箱不能为空") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java deleted file mode 100644 index e961cc70a..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/account/MailAccountUpdateReqVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.mail.vo.account; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 邮箱账号修改 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class MailAccountUpdateReqVO extends MailAccountBaseVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "编号不能为空") - private Long id; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogBaseVO.java deleted file mode 100755 index 7ba58b70f..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogBaseVO.java +++ /dev/null @@ -1,75 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.mail.vo.log; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import javax.validation.constraints.NotNull; -import java.time.LocalDateTime; -import java.util.Map; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -/** - * 邮件日志 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ -@Data -public class MailLogBaseVO { - - @Schema(description = "用户编号", example = "30883") - private Long userId; - - @Schema(description = "用户类型,参见 UserTypeEnum 枚举", example = "2") - private Byte userType; - - @Schema(description = "接收邮箱地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "76854@qq.com") - @NotNull(message = "接收邮箱地址不能为空") - private String toMail; - - @Schema(description = "邮箱账号编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "18107") - @NotNull(message = "邮箱账号编号不能为空") - private Long accountId; - - @Schema(description = "发送邮箱地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "85757@qq.com") - @NotNull(message = "发送邮箱地址不能为空") - private String fromMail; - - @Schema(description = "模板编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "5678") - @NotNull(message = "模板编号不能为空") - private Long templateId; - - @Schema(description = "模板编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "test_01") - @NotNull(message = "模板编码不能为空") - private String templateCode; - - @Schema(description = "模版发送人名称", example = "李四") - private String templateNickname; - - @Schema(description = "邮件标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试标题") - @NotNull(message = "邮件标题不能为空") - private String templateTitle; - - @Schema(description = "邮件内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试内容") - @NotNull(message = "邮件内容不能为空") - private String templateContent; - - @Schema(description = "邮件参数", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "邮件参数不能为空") - private Map templateParams; - - @Schema(description = "发送状态,参见 MailSendStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "发送状态不能为空") - private Byte sendStatus; - - @Schema(description = "发送时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime sendTime; - - @Schema(description = "发送返回的消息 ID", example = "28568") - private String sendMessageId; - - @Schema(description = "发送异常") - private String sendException; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java index 25d8498fe..49edfffef 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/log/MailLogRespVO.java @@ -1,18 +1,66 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.log; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + import java.time.LocalDateTime; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; @Schema(description = "管理后台 - 邮件日志 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class MailLogRespVO extends MailLogBaseVO { +public class MailLogRespVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31020") private Long id; + @Schema(description = "用户编号", example = "30883") + private Long userId; + + @Schema(description = "用户类型,参见 UserTypeEnum 枚举", example = "2") + private Byte userType; + + @Schema(description = "接收邮箱地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "76854@qq.com") + private String toMail; + + @Schema(description = "邮箱账号编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "18107") + private Long accountId; + + @Schema(description = "发送邮箱地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "85757@qq.com") + private String fromMail; + + @Schema(description = "模板编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "5678") + private Long templateId; + + @Schema(description = "模板编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "test_01") + private String templateCode; + + @Schema(description = "模版发送人名称", example = "李四") + private String templateNickname; + + @Schema(description = "邮件标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试标题") + private String templateTitle; + + @Schema(description = "邮件内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试内容") + private String templateContent; + + @Schema(description = "邮件参数", requiredMode = Schema.RequiredMode.REQUIRED) + private Map templateParams; + + @Schema(description = "发送状态,参见 MailSendStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Byte sendStatus; + + @Schema(description = "发送时间") + private LocalDateTime sendTime; + + @Schema(description = "发送返回的消息 ID", example = "28568") + private String sendMessageId; + + @Schema(description = "发送异常") + private String sendException; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateCreateReqVO.java deleted file mode 100644 index b8b47e3b2..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateCreateReqVO.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -@Schema(description = "管理后台 - 邮件模版创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class MailTemplateCreateReqVO extends MailTemplateBaseVO { - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java index c003b0059..8485f25ea 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateRespVO.java @@ -2,24 +2,46 @@ package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; import java.time.LocalDateTime; import java.util.List; @Schema(description = "管理后台 - 邮件末班 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class MailTemplateRespVO extends MailTemplateBaseVO { +public class MailTemplateRespVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Long id; + @Schema(description = "模版名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试名字") + private String name; + + @Schema(description = "模版编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "test") + private String code; + + @Schema(description = "发送的邮箱账号编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Long accountId; + + @Schema(description = "发送人名称", example = "芋头") + private String nickname; + + @Schema(description = "标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "注册成功") + private String title; + + @Schema(description = "内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "你好,注册成功啦") + private String content; + @Schema(description = "参数数组", example = "name,code") private List params; + @Schema(description = "状态,参见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer status; + + @Schema(description = "备注", example = "奥特曼") + private String remark; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateSaveReqVO.java similarity index 88% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateSaveReqVO.java index eae1640aa..de316973c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateSaveReqVO.java @@ -6,12 +6,12 @@ import lombok.Data; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; -/** - * 邮件模版 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ +@Schema(description = "管理后台 - 邮件模版创建/修改 Request VO") @Data -public class MailTemplateBaseVO { +public class MailTemplateSaveReqVO { + + @Schema(description = "编号", example = "1024") + private Long id; @Schema(description = "模版名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试名字") @NotNull(message = "名称不能为空") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateUpdateReqVO.java deleted file mode 100644 index bc99db508..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/template/MailTemplateUpdateReqVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.mail.vo.template; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 邮件模版修改 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class MailTemplateUpdateReqVO extends MailTemplateBaseVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "编号不能为空") - private Long id; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java index ffd150135..5d20ac13d 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailAccountConvert.java @@ -2,29 +2,15 @@ package cn.iocoder.yudao.module.system.convert.mail; import cn.hutool.core.util.StrUtil; import cn.hutool.extra.mail.MailAccount; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.*; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; -import java.util.List; - @Mapper public interface MailAccountConvert { MailAccountConvert INSTANCE = Mappers.getMapper(MailAccountConvert.class); - MailAccountDO convert(MailAccountCreateReqVO bean); - - MailAccountDO convert(MailAccountUpdateReqVO bean); - - MailAccountRespVO convert(MailAccountDO bean); - - PageResult convertPage(PageResult pageResult); - - List convertList02(List list); - default MailAccount convert(MailAccountDO account, String nickname) { String from = StrUtil.isNotEmpty(nickname) ? nickname + " <" + account.getMail() + ">" : account.getMail(); return new MailAccount().setFrom(from).setAuth(true) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailLogConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailLogConvert.java deleted file mode 100644 index c5599e355..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailLogConvert.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.mail; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogRespVO; -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailLogDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -@Mapper -public interface MailLogConvert { - - MailLogConvert INSTANCE = Mappers.getMapper(MailLogConvert.class); - - PageResult convertPage(PageResult pageResult); - - MailLogRespVO convert(MailLogDO bean); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java deleted file mode 100644 index 4430ffb05..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/mail/MailTemplateConvert.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.mail; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.*; -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper -public interface MailTemplateConvert { - - MailTemplateConvert INSTANCE = Mappers.getMapper(MailTemplateConvert.class); - - MailTemplateDO convert(MailTemplateUpdateReqVO bean); - - MailTemplateDO convert(MailTemplateCreateReqVO bean); - - MailTemplateRespVO convert(MailTemplateDO bean); - - PageResult convertPage(PageResult pageResult); - - List convertList02(List list); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java index 62e97a829..72d62568c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java @@ -1,9 +1,8 @@ package cn.iocoder.yudao.module.system.service.mail; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import javax.validation.Valid; @@ -23,14 +22,14 @@ public interface MailAccountService { * @param createReqVO 邮箱账号信息 * @return 编号 */ - Long createMailAccount(@Valid MailAccountCreateReqVO createReqVO); + Long createMailAccount(@Valid MailAccountSaveReqVO createReqVO); /** * 修改邮箱账号 * * @param updateReqVO 邮箱账号信息 */ - void updateMailAccount(@Valid MailAccountUpdateReqVO updateReqVO); + void updateMailAccount(@Valid MailAccountSaveReqVO updateReqVO); /** * 删除邮箱账号 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountServiceImpl.java index 94b02dbab..73cd9d3a1 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountServiceImpl.java @@ -1,10 +1,9 @@ package cn.iocoder.yudao.module.system.service.mail; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; @@ -39,21 +38,20 @@ public class MailAccountServiceImpl implements MailAccountService { private MailTemplateService mailTemplateService; @Override - public Long createMailAccount(MailAccountCreateReqVO createReqVO) { - // 插入 - MailAccountDO account = MailAccountConvert.INSTANCE.convert(createReqVO); + public Long createMailAccount(MailAccountSaveReqVO createReqVO) { + MailAccountDO account = BeanUtils.toBean(createReqVO, MailAccountDO.class); mailAccountMapper.insert(account); return account.getId(); } @Override @CacheEvict(value = RedisKeyConstants.MAIL_ACCOUNT, key = "#updateReqVO.id") - public void updateMailAccount(MailAccountUpdateReqVO updateReqVO) { + public void updateMailAccount(MailAccountSaveReqVO updateReqVO) { // 校验是否存在 validateMailAccountExists(updateReqVO.getId()); // 更新 - MailAccountDO updateObj = MailAccountConvert.INSTANCE.convert(updateReqVO); + MailAccountDO updateObj = BeanUtils.toBean(updateReqVO, MailAccountDO.class); mailAccountMapper.updateById(updateObj); } @@ -63,7 +61,7 @@ public class MailAccountServiceImpl implements MailAccountService { // 校验是否存在账号 validateMailAccountExists(id); // 校验是否存在关联模版 - if (mailTemplateService.countByAccountId(id) > 0) { + if (mailTemplateService.getMailTemplateCountByAccountId(id) > 0) { throw exception(MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogServiceImpl.java index 3e7cdc48b..292acab07 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailLogServiceImpl.java @@ -12,7 +12,6 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.time.LocalDateTime; -import java.util.Date; import java.util.Map; import java.util.Objects; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index 69e02c810..0f5a49f1d 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -1,9 +1,8 @@ package cn.iocoder.yudao.module.system.service.mail; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import javax.validation.Valid; @@ -24,14 +23,14 @@ public interface MailTemplateService { * @param createReqVO 邮件信息 * @return 编号 */ - Long createMailTemplate(@Valid MailTemplateCreateReqVO createReqVO); + Long createMailTemplate(@Valid MailTemplateSaveReqVO createReqVO); /** * 邮件模版修改 * * @param updateReqVO 邮件信息 */ - void updateMailTemplate(@Valid MailTemplateUpdateReqVO updateReqVO); + void updateMailTemplate(@Valid MailTemplateSaveReqVO updateReqVO); /** * 邮件模版删除 @@ -86,6 +85,6 @@ public interface MailTemplateService { * @param accountId 账号编号 * @return 数量 */ - long countByAccountId(Long accountId); + long getMailTemplateCountByAccountId(Long accountId); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateServiceImpl.java index 6d17c2b59..530d588a3 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateServiceImpl.java @@ -4,10 +4,9 @@ import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ReUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.mail.MailTemplateConvert; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; @@ -48,12 +47,12 @@ public class MailTemplateServiceImpl implements MailTemplateService { private MailTemplateMapper mailTemplateMapper; @Override - public Long createMailTemplate(MailTemplateCreateReqVO createReqVO) { + public Long createMailTemplate(MailTemplateSaveReqVO createReqVO) { // 校验 code 是否唯一 validateCodeUnique(null, createReqVO.getCode()); // 插入 - MailTemplateDO template = MailTemplateConvert.INSTANCE.convert(createReqVO) + MailTemplateDO template = BeanUtils.toBean(createReqVO, MailTemplateDO.class) .setParams(parseTemplateContentParams(createReqVO.getContent())); mailTemplateMapper.insert(template); return template.getId(); @@ -62,14 +61,14 @@ public class MailTemplateServiceImpl implements MailTemplateService { @Override @CacheEvict(cacheNames = RedisKeyConstants.NOTIFY_TEMPLATE, allEntries = true) // allEntries 清空所有缓存,因为可能修改到 code 字段,不好清理 - public void updateMailTemplate(@Valid MailTemplateUpdateReqVO updateReqVO) { + public void updateMailTemplate(@Valid MailTemplateSaveReqVO updateReqVO) { // 校验是否存在 validateMailTemplateExists(updateReqVO.getId()); // 校验 code 是否唯一 validateCodeUnique(updateReqVO.getId(),updateReqVO.getCode()); // 更新 - MailTemplateDO updateObj = MailTemplateConvert.INSTANCE.convert(updateReqVO) + MailTemplateDO updateObj = BeanUtils.toBean(updateReqVO, MailTemplateDO.class) .setParams(parseTemplateContentParams(updateReqVO.getContent())); mailTemplateMapper.updateById(updateObj); } @@ -132,7 +131,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { } @Override - public long countByAccountId(Long accountId) { + public long getMailTemplateCountByAccountId(Long accountId) { return mailTemplateMapper.selectCountByAccountId(accountId); } diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/mail/MailAccountServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/mail/MailAccountServiceImplTest.java index ea2725e25..6e1bf0d05 100755 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/mail/MailAccountServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/mail/MailAccountServiceImplTest.java @@ -2,9 +2,8 @@ package cn.iocoder.yudao.module.system.service.mail; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import org.junit.jupiter.api.Test; @@ -43,7 +42,8 @@ public class MailAccountServiceImplTest extends BaseDbUnitTest { @Test public void testCreateMailAccount_success() { // 准备参数 - MailAccountCreateReqVO reqVO = randomPojo(MailAccountCreateReqVO.class, o -> o.setMail(randomEmail())); + MailAccountSaveReqVO reqVO = randomPojo(MailAccountSaveReqVO.class, o -> o.setMail(randomEmail())) + .setId(null); // 防止 id 被赋值 // 调用 Long mailAccountId = mailAccountService.createMailAccount(reqVO); @@ -51,7 +51,7 @@ public class MailAccountServiceImplTest extends BaseDbUnitTest { assertNotNull(mailAccountId); // 校验记录的属性是否正确 MailAccountDO mailAccount = mailAccountMapper.selectById(mailAccountId); - assertPojoEquals(reqVO, mailAccount); + assertPojoEquals(reqVO, mailAccount, "id"); } @Test @@ -60,7 +60,7 @@ public class MailAccountServiceImplTest extends BaseDbUnitTest { MailAccountDO dbMailAccount = randomPojo(MailAccountDO.class); mailAccountMapper.insert(dbMailAccount);// @Sql: 先插入出一条存在的数据 // 准备参数 - MailAccountUpdateReqVO reqVO = randomPojo(MailAccountUpdateReqVO.class, o -> { + MailAccountSaveReqVO reqVO = randomPojo(MailAccountSaveReqVO.class, o -> { o.setId(dbMailAccount.getId()); // 设置更新的 ID o.setMail(randomEmail()); }); @@ -75,7 +75,7 @@ public class MailAccountServiceImplTest extends BaseDbUnitTest { @Test public void testUpdateMailAccount_notExists() { // 准备参数 - MailAccountUpdateReqVO reqVO = randomPojo(MailAccountUpdateReqVO.class); + MailAccountSaveReqVO reqVO = randomPojo(MailAccountSaveReqVO.class); // 调用, 并断言异常 assertServiceException(() -> mailAccountService.updateMailAccount(reqVO), MAIL_ACCOUNT_NOT_EXISTS); @@ -89,7 +89,7 @@ public class MailAccountServiceImplTest extends BaseDbUnitTest { // 准备参数 Long id = dbMailAccount.getId(); // mock 方法(无关联模版) - when(mailTemplateService.countByAccountId(eq(id))).thenReturn(0L); + when(mailTemplateService.getMailTemplateCountByAccountId(eq(id))).thenReturn(0L); // 调用 mailAccountService.deleteMailAccount(id); diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateServiceImplTest.java index 8776595ea..7f76570bb 100755 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateServiceImplTest.java @@ -3,9 +3,8 @@ package cn.iocoder.yudao.module.system.service.mail; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateSaveReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateUpdateReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import org.junit.jupiter.api.Test; @@ -43,7 +42,8 @@ public class MailTemplateServiceImplTest extends BaseDbUnitTest { @Test public void testCreateMailTemplate_success() { // 准备参数 - MailTemplateCreateReqVO reqVO = randomPojo(MailTemplateCreateReqVO.class); + MailTemplateSaveReqVO reqVO = randomPojo(MailTemplateSaveReqVO.class) + .setId(null); // 防止 id 被赋值 // 调用 Long mailTemplateId = mailTemplateService.createMailTemplate(reqVO); @@ -51,7 +51,7 @@ public class MailTemplateServiceImplTest extends BaseDbUnitTest { assertNotNull(mailTemplateId); // 校验记录的属性是否正确 MailTemplateDO mailTemplate = mailTemplateMapper.selectById(mailTemplateId); - assertPojoEquals(reqVO, mailTemplate); + assertPojoEquals(reqVO, mailTemplate, "id"); } @Test @@ -60,7 +60,7 @@ public class MailTemplateServiceImplTest extends BaseDbUnitTest { MailTemplateDO dbMailTemplate = randomPojo(MailTemplateDO.class); mailTemplateMapper.insert(dbMailTemplate);// @Sql: 先插入出一条存在的数据 // 准备参数 - MailTemplateUpdateReqVO reqVO = randomPojo(MailTemplateUpdateReqVO.class, o -> { + MailTemplateSaveReqVO reqVO = randomPojo(MailTemplateSaveReqVO.class, o -> { o.setId(dbMailTemplate.getId()); // 设置更新的 ID }); @@ -74,7 +74,7 @@ public class MailTemplateServiceImplTest extends BaseDbUnitTest { @Test public void testUpdateMailTemplate_notExists() { // 准备参数 - MailTemplateUpdateReqVO reqVO = randomPojo(MailTemplateUpdateReqVO.class); + MailTemplateSaveReqVO reqVO = randomPojo(MailTemplateSaveReqVO.class); // 调用, 并断言异常 assertServiceException(() -> mailTemplateService.updateMailTemplate(reqVO), MAIL_TEMPLATE_NOT_EXISTS); @@ -207,7 +207,7 @@ public class MailTemplateServiceImplTest extends BaseDbUnitTest { Long accountId = dbMailTemplate.getAccountId(); // 调用 - long count = mailTemplateService.countByAccountId(accountId); + long count = mailTemplateService.getMailTemplateCountByAccountId(accountId); // 断言 assertEquals(1, count); } From 5eb5472dec6314e5aaaf1a5361b153ebd16bcaf2 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 2 Dec 2023 20:07:54 +0800 Subject: [PATCH 06/19] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20notic?= =?UTF-8?q?e=20=E6=A8=A1=E5=9D=97=E7=9A=84=20VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/notice/NoticeController.java | 25 ++++++++-------- .../admin/notice/vo/NoticeCreateReqVO.java | 11 ------- .../admin/notice/vo/NoticeRespVO.java | 16 ++++++++-- ...NoticeBaseVO.java => NoticeSaveReqVO.java} | 11 +++---- .../admin/notice/vo/NoticeUpdateReqVO.java | 18 ------------ .../system/convert/notice/NoticeConvert.java | 24 --------------- .../system/service/notice/NoticeService.java | 29 +++++++++---------- .../service/notice/NoticeServiceImpl.java | 15 +++++----- .../service/notice/NoticeServiceImplTest.java | 10 +++---- 9 files changed, 58 insertions(+), 101 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeCreateReqVO.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/{NoticeBaseVO.java => NoticeSaveReqVO.java} (77%) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeUpdateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notice/NoticeConvert.java diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/NoticeController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/NoticeController.java index 5a566702f..138f2d9ae 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/NoticeController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/NoticeController.java @@ -4,17 +4,16 @@ import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.infra.api.websocket.WebSocketSenderApi; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO; import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeRespVO; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.notice.NoticeConvert; +import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; import cn.iocoder.yudao.module.system.service.notice.NoticeService; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -39,16 +38,16 @@ public class NoticeController { @PostMapping("/create") @Operation(summary = "创建通知公告") @PreAuthorize("@ss.hasPermission('system:notice:create')") - public CommonResult createNotice(@Valid @RequestBody NoticeCreateReqVO reqVO) { - Long noticeId = noticeService.createNotice(reqVO); + public CommonResult createNotice(@Valid @RequestBody NoticeSaveReqVO createReqVO) { + Long noticeId = noticeService.createNotice(createReqVO); return success(noticeId); } @PutMapping("/update") @Operation(summary = "修改通知公告") @PreAuthorize("@ss.hasPermission('system:notice:update')") - public CommonResult updateNotice(@Valid @RequestBody NoticeUpdateReqVO reqVO) { - noticeService.updateNotice(reqVO); + public CommonResult updateNotice(@Valid @RequestBody NoticeSaveReqVO updateReqVO) { + noticeService.updateNotice(updateReqVO); return success(true); } @@ -64,8 +63,9 @@ public class NoticeController { @GetMapping("/page") @Operation(summary = "获取通知公告列表") @PreAuthorize("@ss.hasPermission('system:notice:query')") - public CommonResult> getNoticePage(@Validated NoticePageReqVO reqVO) { - return success(NoticeConvert.INSTANCE.convertPage(noticeService.getNoticePage(reqVO))); + public CommonResult> getNoticePage(@Validated NoticePageReqVO pageReqVO) { + PageResult pageResult = noticeService.getNoticePage(pageReqVO); + return success(BeanUtils.toBean(pageResult, NoticeRespVO.class)); } @GetMapping("/get") @@ -73,7 +73,8 @@ public class NoticeController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('system:notice:query')") public CommonResult getNotice(@RequestParam("id") Long id) { - return success(NoticeConvert.INSTANCE.convert(noticeService.getNotice(id))); + NoticeDO notice = noticeService.getNotice(id); + return success(BeanUtils.toBean(notice, NoticeRespVO.class)); } @PostMapping("/push") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeCreateReqVO.java deleted file mode 100644 index 211f4f0cf..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeCreateReqVO.java +++ /dev/null @@ -1,11 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.notice.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Schema(description = "管理后台 - 通知公告创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -public class NoticeCreateReqVO extends NoticeBaseVO { -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeRespVO.java index 621c1d301..543f5881e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeRespVO.java @@ -2,18 +2,28 @@ package cn.iocoder.yudao.module.system.controller.admin.notice.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; import java.time.LocalDateTime; @Schema(description = "管理后台 - 通知公告信息 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -public class NoticeRespVO extends NoticeBaseVO { +public class NoticeRespVO { @Schema(description = "通知公告序号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Long id; + @Schema(description = "公告标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "小博主") + private String title; + + @Schema(description = "公告类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "小博主") + private Integer type; + + @Schema(description = "公告内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "半生编码") + private String content; + + @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer status; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") private LocalDateTime createTime; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeSaveReqVO.java similarity index 77% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeBaseVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeSaveReqVO.java index efac4df73..4d7e6c872 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeSaveReqVO.java @@ -7,12 +7,13 @@ import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; -/** - * 通知公告 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ +@Schema(description = "管理后台 - 通知公告创建/修改 Request VO") @Data -public class NoticeBaseVO { +public class NoticeSaveReqVO { + + @Schema(description = "岗位公告编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @NotNull(message = "岗位公告编号不能为空") + private Long id; @Schema(description = "公告标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "小博主") @NotBlank(message = "公告标题不能为空") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeUpdateReqVO.java deleted file mode 100644 index 695bd2863..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeUpdateReqVO.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.notice.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 岗位公告更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -public class NoticeUpdateReqVO extends NoticeBaseVO { - - @Schema(description = "岗位公告编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "岗位公告编号不能为空") - private Long id; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notice/NoticeConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notice/NoticeConvert.java deleted file mode 100644 index ad2bedec7..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notice/NoticeConvert.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.notice; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeRespVO; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -@Mapper -public interface NoticeConvert { - - NoticeConvert INSTANCE = Mappers.getMapper(NoticeConvert.class); - - PageResult convertPage(PageResult page); - - NoticeRespVO convert(NoticeDO bean); - - NoticeDO convert(NoticeUpdateReqVO bean); - - NoticeDO convert(NoticeCreateReqVO bean); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeService.java index 432fe876e..c935c49b2 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeService.java @@ -1,9 +1,8 @@ package cn.iocoder.yudao.module.system.service.notice; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; /** @@ -12,29 +11,29 @@ import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; public interface NoticeService { /** - * 创建岗位公告公告 + * 创建通知公告 * - * @param reqVO 岗位公告公告信息 - * @return 岗位公告公告编号 + * @param createReqVO 通知公告 + * @return 编号 */ - Long createNotice(NoticeCreateReqVO reqVO); + Long createNotice(NoticeSaveReqVO createReqVO); /** - * 更新岗位公告公告 + * 更新通知公告 * - * @param reqVO 岗位公告公告信息 + * @param reqVO 通知公告 */ - void updateNotice(NoticeUpdateReqVO reqVO); + void updateNotice(NoticeSaveReqVO reqVO); /** - * 删除岗位公告公告信息 + * 删除通知公告 * - * @param id 岗位公告公告编号 + * @param id 编号 */ void deleteNotice(Long id); /** - * 获得岗位公告公告分页列表 + * 获得通知公告分页列表 * * @param reqVO 分页条件 * @return 部门分页列表 @@ -42,10 +41,10 @@ public interface NoticeService { PageResult getNoticePage(NoticePageReqVO reqVO); /** - * 获得岗位公告公告信息 + * 获得通知公告 * - * @param id 岗位公告公告编号 - * @return 岗位公告公告信息 + * @param id 编号 + * @return 通知公告 */ NoticeDO getNotice(Long id); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImpl.java index 1930e64c1..f0204c3cf 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImpl.java @@ -1,10 +1,9 @@ package cn.iocoder.yudao.module.system.service.notice; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.notice.NoticeConvert; +import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; import cn.iocoder.yudao.module.system.dal.mysql.notice.NoticeMapper; import com.google.common.annotations.VisibleForTesting; @@ -27,18 +26,18 @@ public class NoticeServiceImpl implements NoticeService { private NoticeMapper noticeMapper; @Override - public Long createNotice(NoticeCreateReqVO reqVO) { - NoticeDO notice = NoticeConvert.INSTANCE.convert(reqVO); + public Long createNotice(NoticeSaveReqVO createReqVO) { + NoticeDO notice = BeanUtils.toBean(createReqVO, NoticeDO.class); noticeMapper.insert(notice); return notice.getId(); } @Override - public void updateNotice(NoticeUpdateReqVO reqVO) { + public void updateNotice(NoticeSaveReqVO updateReqVO) { // 校验是否存在 - validateNoticeExists(reqVO.getId()); + validateNoticeExists(updateReqVO.getId()); // 更新通知公告 - NoticeDO updateObj = NoticeConvert.INSTANCE.convert(reqVO); + NoticeDO updateObj = BeanUtils.toBean(updateReqVO, NoticeDO.class); noticeMapper.updateById(updateObj); } diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImplTest.java index b4727096a..dfde83538 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImplTest.java @@ -3,9 +3,8 @@ package cn.iocoder.yudao.module.system.service.notice; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; import cn.iocoder.yudao.module.system.dal.mysql.notice.NoticeMapper; import org.junit.jupiter.api.Test; @@ -72,14 +71,15 @@ class NoticeServiceImplTest extends BaseDbUnitTest { @Test public void testCreateNotice_success() { // 准备参数 - NoticeCreateReqVO reqVO = randomPojo(NoticeCreateReqVO.class); + NoticeSaveReqVO reqVO = randomPojo(NoticeSaveReqVO.class) + .setId(null); // 避免 id 被赋值 // 调用 Long noticeId = noticeService.createNotice(reqVO); // 校验插入属性是否正确 assertNotNull(noticeId); NoticeDO notice = noticeMapper.selectById(noticeId); - assertPojoEquals(reqVO, notice); + assertPojoEquals(reqVO, notice, "id"); } @Test @@ -89,7 +89,7 @@ class NoticeServiceImplTest extends BaseDbUnitTest { noticeMapper.insert(dbNoticeDO); // 准备更新参数 - NoticeUpdateReqVO reqVO = randomPojo(NoticeUpdateReqVO.class, o -> o.setId(dbNoticeDO.getId())); + NoticeSaveReqVO reqVO = randomPojo(NoticeSaveReqVO.class, o -> o.setId(dbNoticeDO.getId())); // 更新 noticeService.updateNotice(reqVO); From 9aed06af5d8de23657f60c701e6a1a51e8743b33 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 2 Dec 2023 20:25:10 +0800 Subject: [PATCH 07/19] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20notif?= =?UTF-8?q?y=20=E6=A8=A1=E5=9D=97=E7=9A=84=20VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/notify/NotifyMessageController.java | 15 ++--- .../notify/NotifyTemplateController.java | 12 ++-- .../vo/message/NotifyMessageBaseVO.java | 60 ------------------- .../vo/message/NotifyMessageRespVO.java | 37 ++++++++++-- .../template/NotifyTemplateCreateReqVO.java | 11 ---- .../vo/template/NotifyTemplateRespVO.java | 29 +++++++-- ...seVO.java => NotifyTemplateSaveReqVO.java} | 12 ++-- .../vo/template/NotifyTemplateSendReqVO.java | 1 + .../template/NotifyTemplateUpdateReqVO.java | 17 ------ .../convert/notify/NotifyMessageConvert.java | 27 --------- .../convert/notify/NotifyTemplateConvert.java | 35 ----------- .../notify/NotifyMessageServiceImpl.java | 2 - .../service/notify/NotifyTemplateService.java | 7 +-- .../notify/NotifyTemplateServiceImpl.java | 14 ++--- .../notify/NotifyTemplateServiceImplTest.java | 14 ++--- 15 files changed, 94 insertions(+), 199 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateCreateReqVO.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/{NotifyTemplateBaseVO.java => NotifyTemplateSaveReqVO.java} (87%) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateUpdateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyTemplateConvert.java diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java index c3e5249e8..93394ddbb 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java @@ -3,10 +3,10 @@ package cn.iocoder.yudao.module.system.controller.admin.notify; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageMyPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO; -import cn.iocoder.yudao.module.system.convert.notify.NotifyMessageConvert; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; import cn.iocoder.yudao.module.system.service.notify.NotifyMessageService; import io.swagger.v3.oas.annotations.Operation; @@ -39,8 +39,8 @@ public class NotifyMessageController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('system:notify-message:query')") public CommonResult getNotifyMessage(@RequestParam("id") Long id) { - NotifyMessageDO notifyMessage = notifyMessageService.getNotifyMessage(id); - return success(NotifyMessageConvert.INSTANCE.convert(notifyMessage)); + NotifyMessageDO message = notifyMessageService.getNotifyMessage(id); + return success(BeanUtils.toBean(message, NotifyMessageRespVO.class)); } @GetMapping("/page") @@ -48,7 +48,7 @@ public class NotifyMessageController { @PreAuthorize("@ss.hasPermission('system:notify-message:query')") public CommonResult> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) { PageResult pageResult = notifyMessageService.getNotifyMessagePage(pageVO); - return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, NotifyMessageRespVO.class)); } // ========== 查看自己的站内信 ========== @@ -58,7 +58,7 @@ public class NotifyMessageController { public CommonResult> getMyMyNotifyMessagePage(@Valid NotifyMessageMyPageReqVO pageVO) { PageResult pageResult = notifyMessageService.getMyMyNotifyMessagePage(pageVO, getLoginUserId(), UserTypeEnum.ADMIN.getValue()); - return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, NotifyMessageRespVO.class)); } @PutMapping("/update-read") @@ -83,13 +83,14 @@ public class NotifyMessageController { @RequestParam(name = "size", defaultValue = "10") Integer size) { List list = notifyMessageService.getUnreadNotifyMessageList( getLoginUserId(), UserTypeEnum.ADMIN.getValue(), size); - return success(NotifyMessageConvert.INSTANCE.convertList(list)); + return success(BeanUtils.toBean(list, NotifyMessageRespVO.class)); } @GetMapping("/get-unread-count") @Operation(summary = "获得当前用户的未读站内信数量") public CommonResult getUnreadNotifyMessageCount() { - return success(notifyMessageService.getUnreadNotifyMessageCount(getLoginUserId(), UserTypeEnum.ADMIN.getValue())); + return success(notifyMessageService.getUnreadNotifyMessageCount( + getLoginUserId(), UserTypeEnum.ADMIN.getValue())); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java index b5152e25b..81c5d3a83 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java @@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.system.controller.admin.notify; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.*; -import cn.iocoder.yudao.module.system.convert.notify.NotifyTemplateConvert; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; import cn.iocoder.yudao.module.system.service.notify.NotifySendService; import cn.iocoder.yudao.module.system.service.notify.NotifyTemplateService; @@ -35,14 +35,14 @@ public class NotifyTemplateController { @PostMapping("/create") @Operation(summary = "创建站内信模版") @PreAuthorize("@ss.hasPermission('system:notify-template:create')") - public CommonResult createNotifyTemplate(@Valid @RequestBody NotifyTemplateCreateReqVO createReqVO) { + public CommonResult createNotifyTemplate(@Valid @RequestBody NotifyTemplateSaveReqVO createReqVO) { return success(notifyTemplateService.createNotifyTemplate(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新站内信模版") @PreAuthorize("@ss.hasPermission('system:notify-template:update')") - public CommonResult updateNotifyTemplate(@Valid @RequestBody NotifyTemplateUpdateReqVO updateReqVO) { + public CommonResult updateNotifyTemplate(@Valid @RequestBody NotifyTemplateSaveReqVO updateReqVO) { notifyTemplateService.updateNotifyTemplate(updateReqVO); return success(true); } @@ -61,8 +61,8 @@ public class NotifyTemplateController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('system:notify-template:query')") public CommonResult getNotifyTemplate(@RequestParam("id") Long id) { - NotifyTemplateDO notifyTemplate = notifyTemplateService.getNotifyTemplate(id); - return success(NotifyTemplateConvert.INSTANCE.convert(notifyTemplate)); + NotifyTemplateDO template = notifyTemplateService.getNotifyTemplate(id); + return success(BeanUtils.toBean(template, NotifyTemplateRespVO.class)); } @GetMapping("/page") @@ -70,7 +70,7 @@ public class NotifyTemplateController { @PreAuthorize("@ss.hasPermission('system:notify-template:query')") public CommonResult> getNotifyTemplatePage(@Valid NotifyTemplatePageReqVO pageVO) { PageResult pageResult = notifyTemplateService.getNotifyTemplatePage(pageVO); - return success(NotifyTemplateConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, NotifyTemplateRespVO.class)); } @PostMapping("/send-notify") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java deleted file mode 100644 index 95fa77cc5..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java +++ /dev/null @@ -1,60 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.notify.vo.message; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import javax.validation.constraints.NotNull; -import java.time.LocalDateTime; -import java.util.Map; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -/** - * 站内信消息 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ -@Data -public class NotifyMessageBaseVO { - - @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "25025") - @NotNull(message = "用户编号不能为空") - private Long userId; - - @Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "用户类型不能为空") - private Byte userType; - - @Schema(description = "模版编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13013") - @NotNull(message = "模版编号不能为空") - private Long templateId; - - @Schema(description = "模板编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "test_01") - @NotNull(message = "模板编码不能为空") - private String templateCode; - - @Schema(description = "模版发送人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") - @NotNull(message = "模版发送人名称不能为空") - private String templateNickname; - - @Schema(description = "模版内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试内容") - @NotNull(message = "模版内容不能为空") - private String templateContent; - - @Schema(description = "模版类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") - @NotNull(message = "模版类型不能为空") - private Integer templateType; - - @Schema(description = "模版参数", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "模版参数不能为空") - private Map templateParams; - - @Schema(description = "是否已读", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") - @NotNull(message = "是否已读不能为空") - private Boolean readStatus; - - @Schema(description = "阅读时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime readTime; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageRespVO.java index 9da05e151..774ed2a34 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageRespVO.java @@ -2,20 +2,47 @@ package cn.iocoder.yudao.module.system.controller.admin.notify.vo.message; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; import java.time.LocalDateTime; +import java.util.Map; @Schema(description = "管理后台 - 站内信 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class NotifyMessageRespVO extends NotifyMessageBaseVO { +public class NotifyMessageRespVO { @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Long id; + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "25025") + private Long userId; + + @Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Byte userType; + + @Schema(description = "模版编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13013") + private Long templateId; + + @Schema(description = "模板编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "test_01") + private String templateCode; + + @Schema(description = "模版发送人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") + private String templateNickname; + + @Schema(description = "模版内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试内容") + private String templateContent; + + @Schema(description = "模版类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + private Integer templateType; + + @Schema(description = "模版参数", requiredMode = Schema.RequiredMode.REQUIRED) + private Map templateParams; + + @Schema(description = "是否已读", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") + private Boolean readStatus; + + @Schema(description = "阅读时间") + private LocalDateTime readTime; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateCreateReqVO.java deleted file mode 100644 index eb080a7bf..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateCreateReqVO.java +++ /dev/null @@ -1,11 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; - -@Schema(description = "管理后台 - 站内信模版创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class NotifyTemplateCreateReqVO extends NotifyTemplateBaseVO { -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateRespVO.java index 38e2210ec..8d362b800 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateRespVO.java @@ -1,23 +1,42 @@ package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; +import lombok.Data; import java.time.LocalDateTime; -import java.util.*; +import java.util.List; @Schema(description = "管理后台 - 站内信模版 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class NotifyTemplateRespVO extends NotifyTemplateBaseVO { +public class NotifyTemplateRespVO { @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Long id; + @Schema(description = "模版名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试模版") + private String name; + + @Schema(description = "模版编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "SEND_TEST") + private String code; + + @Schema(description = "模版类型,对应 system_notify_template_type 字典", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer type; + + @Schema(description = "发送人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "土豆") + private String nickname; + + @Schema(description = "模版内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是模版内容") + private String content; + @Schema(description = "参数数组", example = "name,code") private List params; + @Schema(description = "状态,参见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer status; + + @Schema(description = "备注", example = "我是备注") + private String remark; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSaveReqVO.java similarity index 87% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateBaseVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSaveReqVO.java index 72b995ad1..ca7501825 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSaveReqVO.java @@ -3,17 +3,17 @@ package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.validation.InEnum; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; +import lombok.*; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; -/** - * 站内信模版 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ +@Schema(description = "管理后台 - 站内信模版创建/修改 Request VO") @Data -public class NotifyTemplateBaseVO { +public class NotifyTemplateSaveReqVO { + + @Schema(description = "ID", example = "1024") + private Long id; @Schema(description = "模版名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试模版") @NotEmpty(message = "模版名称不能为空") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSendReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSendReqVO.java index 6a47e8ba9..43b5691b6 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSendReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSendReqVO.java @@ -25,4 +25,5 @@ public class NotifyTemplateSendReqVO { @Schema(description = "模板参数") private Map templateParams; + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateUpdateReqVO.java deleted file mode 100644 index 17927a1e2..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateUpdateReqVO.java +++ /dev/null @@ -1,17 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; -import javax.validation.constraints.*; - -@Schema(description = "管理后台 - 站内信模版更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class NotifyTemplateUpdateReqVO extends NotifyTemplateBaseVO { - - @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "ID 不能为空") - private Long id; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java deleted file mode 100644 index d594bf56e..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java +++ /dev/null @@ -1,27 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.notify; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO; -import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -/** - * 站内信 Convert - * - * @author xrcoder - */ -@Mapper -public interface NotifyMessageConvert { - - NotifyMessageConvert INSTANCE = Mappers.getMapper(NotifyMessageConvert.class); - - NotifyMessageRespVO convert(NotifyMessageDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyTemplateConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyTemplateConvert.java deleted file mode 100644 index d6bfa86fc..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyTemplateConvert.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.notify; - -import java.util.*; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; - -import cn.iocoder.yudao.framework.common.util.date.DateUtils; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateRespVO; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateUpdateReqVO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; -import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; - -/** - * 站内信模版 Convert - * - * @author xrcoder - */ -@Mapper(uses = DateUtils.class) -public interface NotifyTemplateConvert { - - NotifyTemplateConvert INSTANCE = Mappers.getMapper(NotifyTemplateConvert.class); - - NotifyTemplateDO convert(NotifyTemplateCreateReqVO bean); - - NotifyTemplateDO convert(NotifyTemplateUpdateReqVO bean); - - NotifyTemplateRespVO convert(NotifyTemplateDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java index 3abcebcf9..1ac4c0488 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java @@ -14,8 +14,6 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; - /** * 站内信 Service 实现类 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java index 2657e0dd9..76e1554ad 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java @@ -1,9 +1,8 @@ package cn.iocoder.yudao.module.system.service.notify; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplatePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; import javax.validation.Valid; @@ -22,14 +21,14 @@ public interface NotifyTemplateService { * @param createReqVO 创建信息 * @return 编号 */ - Long createNotifyTemplate(@Valid NotifyTemplateCreateReqVO createReqVO); + Long createNotifyTemplate(@Valid NotifyTemplateSaveReqVO createReqVO); /** * 更新站内信模版 * * @param updateReqVO 更新信息 */ - void updateNotifyTemplate(@Valid NotifyTemplateUpdateReqVO updateReqVO); + void updateNotifyTemplate(@Valid NotifyTemplateSaveReqVO updateReqVO); /** * 删除站内信模版 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java index c28e42d7c..cd8e9076f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java @@ -3,10 +3,9 @@ package cn.iocoder.yudao.module.system.service.notify; import cn.hutool.core.util.ReUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateCreateReqVO; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplatePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.notify.NotifyTemplateConvert; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyTemplateMapper; import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; @@ -45,12 +44,12 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService { private NotifyTemplateMapper notifyTemplateMapper; @Override - public Long createNotifyTemplate(NotifyTemplateCreateReqVO createReqVO) { + public Long createNotifyTemplate(NotifyTemplateSaveReqVO createReqVO) { // 校验站内信编码是否重复 validateNotifyTemplateCodeDuplicate(null, createReqVO.getCode()); // 插入 - NotifyTemplateDO notifyTemplate = NotifyTemplateConvert.INSTANCE.convert(createReqVO); + NotifyTemplateDO notifyTemplate = BeanUtils.toBean(createReqVO, NotifyTemplateDO.class); notifyTemplate.setParams(parseTemplateContentParams(notifyTemplate.getContent())); notifyTemplateMapper.insert(notifyTemplate); return notifyTemplate.getId(); @@ -59,14 +58,14 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService { @Override @CacheEvict(cacheNames = RedisKeyConstants.NOTIFY_TEMPLATE, allEntries = true) // allEntries 清空所有缓存,因为可能修改到 code 字段,不好清理 - public void updateNotifyTemplate(NotifyTemplateUpdateReqVO updateReqVO) { + public void updateNotifyTemplate(NotifyTemplateSaveReqVO updateReqVO) { // 校验存在 validateNotifyTemplateExists(updateReqVO.getId()); // 校验站内信编码是否重复 validateNotifyTemplateCodeDuplicate(updateReqVO.getId(), updateReqVO.getCode()); // 更新 - NotifyTemplateDO updateObj = NotifyTemplateConvert.INSTANCE.convert(updateReqVO); + NotifyTemplateDO updateObj = BeanUtils.toBean(updateReqVO, NotifyTemplateDO.class); updateObj.setParams(parseTemplateContentParams(updateObj.getContent())); notifyTemplateMapper.updateById(updateObj); } @@ -135,4 +134,5 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService { public String formatNotifyTemplateContent(String content, Map params) { return StrUtil.format(content, params); } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImplTest.java index 04c410fb7..d49f48cce 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImplTest.java @@ -3,9 +3,8 @@ package cn.iocoder.yudao.module.system.service.notify; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplatePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyTemplateMapper; import org.junit.jupiter.api.Test; @@ -41,8 +40,9 @@ public class NotifyTemplateServiceImplTest extends BaseDbUnitTest { @Test public void testCreateNotifyTemplate_success() { // 准备参数 - NotifyTemplateCreateReqVO reqVO = randomPojo(NotifyTemplateCreateReqVO.class, - o -> o.setStatus(randomCommonStatus())); + NotifyTemplateSaveReqVO reqVO = randomPojo(NotifyTemplateSaveReqVO.class, + o -> o.setStatus(randomCommonStatus())) + .setId(null); // 防止 id 被赋值 // 调用 Long notifyTemplateId = notifyTemplateService.createNotifyTemplate(reqVO); @@ -50,7 +50,7 @@ public class NotifyTemplateServiceImplTest extends BaseDbUnitTest { assertNotNull(notifyTemplateId); // 校验记录的属性是否正确 NotifyTemplateDO notifyTemplate = notifyTemplateMapper.selectById(notifyTemplateId); - assertPojoEquals(reqVO, notifyTemplate); + assertPojoEquals(reqVO, notifyTemplate, "id"); } @Test @@ -59,7 +59,7 @@ public class NotifyTemplateServiceImplTest extends BaseDbUnitTest { NotifyTemplateDO dbNotifyTemplate = randomPojo(NotifyTemplateDO.class); notifyTemplateMapper.insert(dbNotifyTemplate);// @Sql: 先插入出一条存在的数据 // 准备参数 - NotifyTemplateUpdateReqVO reqVO = randomPojo(NotifyTemplateUpdateReqVO.class, o -> { + NotifyTemplateSaveReqVO reqVO = randomPojo(NotifyTemplateSaveReqVO.class, o -> { o.setId(dbNotifyTemplate.getId()); // 设置更新的 ID o.setStatus(randomCommonStatus()); }); @@ -74,7 +74,7 @@ public class NotifyTemplateServiceImplTest extends BaseDbUnitTest { @Test public void testUpdateNotifyTemplate_notExists() { // 准备参数 - NotifyTemplateUpdateReqVO reqVO = randomPojo(NotifyTemplateUpdateReqVO.class); + NotifyTemplateSaveReqVO reqVO = randomPojo(NotifyTemplateSaveReqVO.class); // 调用, 并断言异常 assertServiceException(() -> notifyTemplateService.updateNotifyTemplate(reqVO), NOTIFY_TEMPLATE_NOT_EXISTS); From 73d53dbaad60c25e5002206a658c51cd5e268606 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 2 Dec 2023 20:48:51 +0800 Subject: [PATCH 08/19] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20oauth?= =?UTF-8?q?2=20=E6=A8=A1=E5=9D=97=E7=9A=84=20VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/api/oauth2/OAuth2TokenApiImpl.java | 11 ++-- .../admin/oauth2/OAuth2ClientController.java | 19 ++++--- .../admin/oauth2/OAuth2TokenController.java | 8 +-- .../admin/oauth2/OAuth2UserController.java | 13 ++--- .../vo/client/OAuth2ClientCreateReqVO.java | 12 ----- .../oauth2/vo/client/OAuth2ClientRespVO.java | 52 +++++++++++++++++-- ...BaseVO.java => OAuth2ClientSaveReqVO.java} | 15 +++--- .../vo/client/OAuth2ClientUpdateReqVO.java | 20 ------- .../convert/auth/OAuth2ClientConvert.java | 33 ------------ .../convert/auth/OAuth2TokenConvert.java | 22 -------- .../convert/oauth2/OAuth2OpenConvert.java | 7 ++- .../convert/oauth2/OAuth2UserConvert.java | 25 --------- .../service/oauth2/OAuth2ClientService.java | 7 ++- .../oauth2/OAuth2ClientServiceImpl.java | 17 +++--- .../oauth2/OAuth2ClientServiceImplTest.java | 14 ++--- 15 files changed, 101 insertions(+), 174 deletions(-) delete mode 100755 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientCreateReqVO.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/{OAuth2ClientBaseVO.java => OAuth2ClientSaveReqVO.java} (91%) delete mode 100755 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientUpdateReqVO.java delete mode 100755 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/auth/OAuth2ClientConvert.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/auth/OAuth2TokenConvert.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/oauth2/OAuth2UserConvert.java diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/oauth2/OAuth2TokenApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/oauth2/OAuth2TokenApiImpl.java index efe4cd5c3..be7eba3d6 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/oauth2/OAuth2TokenApiImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/oauth2/OAuth2TokenApiImpl.java @@ -1,9 +1,9 @@ package cn.iocoder.yudao.module.system.api.oauth2; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenCheckRespDTO; import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenCreateReqDTO; import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenRespDTO; -import cn.iocoder.yudao.module.system.convert.auth.OAuth2TokenConvert; import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO; import cn.iocoder.yudao.module.system.service.oauth2.OAuth2TokenService; import org.springframework.stereotype.Service; @@ -25,24 +25,25 @@ public class OAuth2TokenApiImpl implements OAuth2TokenApi { public OAuth2AccessTokenRespDTO createAccessToken(OAuth2AccessTokenCreateReqDTO reqDTO) { OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.createAccessToken( reqDTO.getUserId(), reqDTO.getUserType(), reqDTO.getClientId(), reqDTO.getScopes()); - return OAuth2TokenConvert.INSTANCE.convert2(accessTokenDO); + return BeanUtils.toBean(accessTokenDO, OAuth2AccessTokenRespDTO.class); } @Override public OAuth2AccessTokenCheckRespDTO checkAccessToken(String accessToken) { - return OAuth2TokenConvert.INSTANCE.convert(oauth2TokenService.checkAccessToken(accessToken)); + OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.checkAccessToken(accessToken); + return BeanUtils.toBean(accessTokenDO, OAuth2AccessTokenCheckRespDTO.class); } @Override public OAuth2AccessTokenRespDTO removeAccessToken(String accessToken) { OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.removeAccessToken(accessToken); - return OAuth2TokenConvert.INSTANCE.convert2(accessTokenDO); + return BeanUtils.toBean(accessTokenDO, OAuth2AccessTokenRespDTO.class); } @Override public OAuth2AccessTokenRespDTO refreshAccessToken(String refreshToken, String clientId) { OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.refreshAccessToken(refreshToken, clientId); - return OAuth2TokenConvert.INSTANCE.convert2(accessTokenDO); + return BeanUtils.toBean(accessTokenDO, OAuth2AccessTokenRespDTO.class); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/OAuth2ClientController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/OAuth2ClientController.java index 358f94678..7aa9bb97a 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/OAuth2ClientController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/OAuth2ClientController.java @@ -2,16 +2,15 @@ package cn.iocoder.yudao.module.system.controller.admin.oauth2; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientCreateReqVO; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientRespVO; -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.auth.OAuth2ClientConvert; +import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO; import cn.iocoder.yudao.module.system.service.oauth2.OAuth2ClientService; -import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -33,14 +32,14 @@ public class OAuth2ClientController { @PostMapping("/create") @Operation(summary = "创建 OAuth2 客户端") @PreAuthorize("@ss.hasPermission('system:oauth2-client:create')") - public CommonResult createOAuth2Client(@Valid @RequestBody OAuth2ClientCreateReqVO createReqVO) { + public CommonResult createOAuth2Client(@Valid @RequestBody OAuth2ClientSaveReqVO createReqVO) { return success(oAuth2ClientService.createOAuth2Client(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新 OAuth2 客户端") @PreAuthorize("@ss.hasPermission('system:oauth2-client:update')") - public CommonResult updateOAuth2Client(@Valid @RequestBody OAuth2ClientUpdateReqVO updateReqVO) { + public CommonResult updateOAuth2Client(@Valid @RequestBody OAuth2ClientSaveReqVO updateReqVO) { oAuth2ClientService.updateOAuth2Client(updateReqVO); return success(true); } @@ -59,16 +58,16 @@ public class OAuth2ClientController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('system:oauth2-client:query')") public CommonResult getOAuth2Client(@RequestParam("id") Long id) { - OAuth2ClientDO oAuth2Client = oAuth2ClientService.getOAuth2Client(id); - return success(OAuth2ClientConvert.INSTANCE.convert(oAuth2Client)); + OAuth2ClientDO client = oAuth2ClientService.getOAuth2Client(id); + return success(BeanUtils.toBean(client, OAuth2ClientRespVO.class)); } @GetMapping("/page") - @Operation(summary = "获得OAuth2 客户端分页") + @Operation(summary = "获得 OAuth2 客户端分页") @PreAuthorize("@ss.hasPermission('system:oauth2-client:query')") public CommonResult> getOAuth2ClientPage(@Valid OAuth2ClientPageReqVO pageVO) { PageResult pageResult = oAuth2ClientService.getOAuth2ClientPage(pageVO); - return success(OAuth2ClientConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, OAuth2ClientRespVO.class)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/OAuth2TokenController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/OAuth2TokenController.java index d1e0364dc..62827b1b9 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/OAuth2TokenController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/OAuth2TokenController.java @@ -2,16 +2,16 @@ package cn.iocoder.yudao.module.system.controller.admin.oauth2; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.token.OAuth2AccessTokenPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.token.OAuth2AccessTokenRespVO; -import cn.iocoder.yudao.module.system.convert.auth.OAuth2TokenConvert; import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO; import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum; import cn.iocoder.yudao.module.system.service.auth.AdminAuthService; import cn.iocoder.yudao.module.system.service.oauth2.OAuth2TokenService; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; @@ -35,7 +35,7 @@ public class OAuth2TokenController { @PreAuthorize("@ss.hasPermission('system:oauth2-token:page')") public CommonResult> getAccessTokenPage(@Valid OAuth2AccessTokenPageReqVO reqVO) { PageResult pageResult = oauth2TokenService.getAccessTokenPage(reqVO); - return success(OAuth2TokenConvert.INSTANCE.convert(pageResult)); + return success(BeanUtils.toBean(pageResult, OAuth2AccessTokenRespVO.class)); } @DeleteMapping("/delete") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/OAuth2UserController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/OAuth2UserController.java index b56d71484..7236299aa 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/OAuth2UserController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/OAuth2UserController.java @@ -2,17 +2,18 @@ package cn.iocoder.yudao.module.system.controller.admin.oauth2; import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.user.OAuth2UserInfoRespVO; import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.user.OAuth2UserUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.oauth2.OAuth2UserConvert; +import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; import cn.iocoder.yudao.module.system.service.dept.DeptService; import cn.iocoder.yudao.module.system.service.dept.PostService; import cn.iocoder.yudao.module.system.service.user.AdminUserService; -import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; @@ -53,16 +54,16 @@ public class OAuth2UserController { public CommonResult getUserInfo() { // 获得用户基本信息 AdminUserDO user = userService.getUser(getLoginUserId()); - OAuth2UserInfoRespVO resp = OAuth2UserConvert.INSTANCE.convert(user); + OAuth2UserInfoRespVO resp = BeanUtils.toBean(user, OAuth2UserInfoRespVO.class); // 获得部门信息 if (user.getDeptId() != null) { DeptDO dept = deptService.getDept(user.getDeptId()); - resp.setDept(OAuth2UserConvert.INSTANCE.convert(dept)); + resp.setDept(BeanUtils.toBean(dept, OAuth2UserInfoRespVO.Dept.class)); } // 获得岗位信息 if (CollUtil.isNotEmpty(user.getPostIds())) { List posts = postService.getPostList(user.getPostIds()); - resp.setPosts(OAuth2UserConvert.INSTANCE.convertList(posts)); + resp.setPosts(BeanUtils.toBean(posts, OAuth2UserInfoRespVO.Post.class)); } return success(resp); } @@ -73,7 +74,7 @@ public class OAuth2UserController { public CommonResult updateUserInfo(@Valid @RequestBody OAuth2UserUpdateReqVO reqVO) { // 这里将 UserProfileUpdateReqVO =》UserProfileUpdateReqVO 对象,实现接口的复用。 // 主要是,AdminUserService 没有自己的 BO 对象,所以复用只能这么做 - userService.updateUserProfile(getLoginUserId(), OAuth2UserConvert.INSTANCE.convert(reqVO)); + userService.updateUserProfile(getLoginUserId(), BeanUtils.toBean(reqVO, UserProfileUpdateReqVO.class)); return success(true); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientCreateReqVO.java deleted file mode 100755 index b7b8ffc38..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientCreateReqVO.java +++ /dev/null @@ -1,12 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; - -@Schema(description = "管理后台 - OAuth2 客户端创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class OAuth2ClientCreateReqVO extends OAuth2ClientBaseVO { - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientRespVO.java index 7a106fd97..acd26c7b0 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientRespVO.java @@ -2,20 +2,62 @@ package cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; import java.time.LocalDateTime; +import java.util.List; @Schema(description = "管理后台 - OAuth2 客户端 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class OAuth2ClientRespVO extends OAuth2ClientBaseVO { +public class OAuth2ClientRespVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Long id; + @Schema(description = "客户端编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "tudou") + private String clientId; + + @Schema(description = "客户端密钥", requiredMode = Schema.RequiredMode.REQUIRED, example = "fan") + private String secret; + + @Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "土豆") + private String name; + + @Schema(description = "应用图标", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png") + private String logo; + + @Schema(description = "应用描述", example = "我是一个应用") + private String description; + + @Schema(description = "状态,参见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer status; + + @Schema(description = "访问令牌的有效期", requiredMode = Schema.RequiredMode.REQUIRED, example = "8640") + private Integer accessTokenValiditySeconds; + + @Schema(description = "刷新令牌的有效期", requiredMode = Schema.RequiredMode.REQUIRED, example = "8640000") + private Integer refreshTokenValiditySeconds; + + @Schema(description = "可重定向的 URI 地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn") + private List redirectUris; + + @Schema(description = "授权类型,参见 OAuth2GrantTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "password") + private List authorizedGrantTypes; + + @Schema(description = "授权范围", example = "user_info") + private List scopes; + + @Schema(description = "自动通过的授权范围", example = "user_info") + private List autoApproveScopes; + + @Schema(description = "权限", example = "system:user:query") + private List authorities; + + @Schema(description = "资源", example = "1024") + private List resourceIds; + + @Schema(description = "附加信息", example = "{yunai: true}") + private String additionalInformation; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientSaveReqVO.java similarity index 91% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientBaseVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientSaveReqVO.java index d9f661d5e..b9199b822 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientSaveReqVO.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; +import lombok.*; import org.hibernate.validator.constraints.URL; import javax.validation.constraints.AssertTrue; @@ -11,12 +11,12 @@ import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import java.util.List; -/** -* OAuth2 客户端 Base VO,提供给添加、修改、详细的子 VO 使用 -* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 -*/ +@Schema(description = "管理后台 - OAuth2 客户端创建/修改 Request VO") @Data -public class OAuth2ClientBaseVO { +public class OAuth2ClientSaveReqVO { + + @Schema(description = "编号", example = "1024") + private Long id; @Schema(description = "客户端编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "tudou") @NotNull(message = "客户端编号不能为空") @@ -52,8 +52,7 @@ public class OAuth2ClientBaseVO { @Schema(description = "可重定向的 URI 地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn") @NotNull(message = "可重定向的 URI 地址不能为空") - private List<@NotEmpty(message = "重定向的 URI 不能为空") - @URL(message = "重定向的 URI 格式不正确") String> redirectUris; + private List<@NotEmpty(message = "重定向的 URI 不能为空") @URL(message = "重定向的 URI 格式不正确") String> redirectUris; @Schema(description = "授权类型,参见 OAuth2GrantTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "password") @NotNull(message = "授权类型不能为空") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientUpdateReqVO.java deleted file mode 100755 index 8f7d9a095..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/vo/client/OAuth2ClientUpdateReqVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - OAuth2 客户端更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class OAuth2ClientUpdateReqVO extends OAuth2ClientBaseVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "编号不能为空") - private Long id; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/auth/OAuth2ClientConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/auth/OAuth2ClientConvert.java deleted file mode 100755 index 87f408aac..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/auth/OAuth2ClientConvert.java +++ /dev/null @@ -1,33 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.auth; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientRespVO; -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientUpdateReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -/** - * OAuth2 客户端 Convert - * - * @author 芋道源码 - */ -@Mapper -public interface OAuth2ClientConvert { - - OAuth2ClientConvert INSTANCE = Mappers.getMapper(OAuth2ClientConvert.class); - - OAuth2ClientDO convert(OAuth2ClientCreateReqVO bean); - - OAuth2ClientDO convert(OAuth2ClientUpdateReqVO bean); - - OAuth2ClientRespVO convert(OAuth2ClientDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/auth/OAuth2TokenConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/auth/OAuth2TokenConvert.java deleted file mode 100644 index 17c62f0dd..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/auth/OAuth2TokenConvert.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.auth; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenCheckRespDTO; -import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenRespDTO; -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.token.OAuth2AccessTokenRespVO; -import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -@Mapper -public interface OAuth2TokenConvert { - - OAuth2TokenConvert INSTANCE = Mappers.getMapper(OAuth2TokenConvert.class); - - OAuth2AccessTokenCheckRespDTO convert(OAuth2AccessTokenDO bean); - - PageResult convert(PageResult page); - - OAuth2AccessTokenRespDTO convert2(OAuth2AccessTokenDO bean); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/oauth2/OAuth2OpenConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/oauth2/OAuth2OpenConvert.java index 3426e5c8f..24c953754 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/oauth2/OAuth2OpenConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/oauth2/OAuth2OpenConvert.java @@ -4,6 +4,7 @@ import cn.hutool.core.date.LocalDateTimeUtil; import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.open.OAuth2OpenAccessTokenRespVO; import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.open.OAuth2OpenAuthorizeInfoRespVO; @@ -25,21 +26,19 @@ public interface OAuth2OpenConvert { OAuth2OpenConvert INSTANCE = Mappers.getMapper(OAuth2OpenConvert.class); default OAuth2OpenAccessTokenRespVO convert(OAuth2AccessTokenDO bean) { - OAuth2OpenAccessTokenRespVO respVO = convert0(bean); + OAuth2OpenAccessTokenRespVO respVO = BeanUtils.toBean(bean, OAuth2OpenAccessTokenRespVO.class); respVO.setTokenType(SecurityFrameworkUtils.AUTHORIZATION_BEARER.toLowerCase()); respVO.setExpiresIn(OAuth2Utils.getExpiresIn(bean.getExpiresTime())); respVO.setScope(OAuth2Utils.buildScopeStr(bean.getScopes())); return respVO; } - OAuth2OpenAccessTokenRespVO convert0(OAuth2AccessTokenDO bean); default OAuth2OpenCheckTokenRespVO convert2(OAuth2AccessTokenDO bean) { - OAuth2OpenCheckTokenRespVO respVO = convert3(bean); + OAuth2OpenCheckTokenRespVO respVO = BeanUtils.toBean(bean, OAuth2OpenCheckTokenRespVO.class); respVO.setExp(LocalDateTimeUtil.toEpochMilli(bean.getExpiresTime()) / 1000L); respVO.setUserType(UserTypeEnum.ADMIN.getValue()); return respVO; } - OAuth2OpenCheckTokenRespVO convert3(OAuth2AccessTokenDO bean); default OAuth2OpenAuthorizeInfoRespVO convert(OAuth2ClientDO client, List approves) { // 构建 scopes diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/oauth2/OAuth2UserConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/oauth2/OAuth2UserConvert.java deleted file mode 100644 index b2610565a..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/oauth2/OAuth2UserConvert.java +++ /dev/null @@ -1,25 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.oauth2; - -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.user.OAuth2UserInfoRespVO; -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.user.OAuth2UserUpdateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; -import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; -import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper -public interface OAuth2UserConvert { - - OAuth2UserConvert INSTANCE = Mappers.getMapper(OAuth2UserConvert.class); - - OAuth2UserInfoRespVO convert(AdminUserDO bean); - OAuth2UserInfoRespVO.Dept convert(DeptDO dept); - List convertList(List list); - - UserProfileUpdateReqVO convert(OAuth2UserUpdateReqVO bean); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientService.java index de826c261..10735537f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientService.java @@ -1,9 +1,8 @@ package cn.iocoder.yudao.module.system.service.oauth2; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO; import javax.validation.Valid; @@ -24,14 +23,14 @@ public interface OAuth2ClientService { * @param createReqVO 创建信息 * @return 编号 */ - Long createOAuth2Client(@Valid OAuth2ClientCreateReqVO createReqVO); + Long createOAuth2Client(@Valid OAuth2ClientSaveReqVO createReqVO); /** * 更新 OAuth2 客户端 * * @param updateReqVO 更新信息 */ - void updateOAuth2Client(@Valid OAuth2ClientUpdateReqVO updateReqVO); + void updateOAuth2Client(@Valid OAuth2ClientSaveReqVO updateReqVO); /** * 删除 OAuth2 客户端 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImpl.java index f1f102499..66392b131 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImpl.java @@ -6,11 +6,10 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.string.StrUtils; -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.auth.OAuth2ClientConvert; +import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO; import cn.iocoder.yudao.module.system.dal.mysql.oauth2.OAuth2ClientMapper; import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; @@ -41,25 +40,25 @@ public class OAuth2ClientServiceImpl implements OAuth2ClientService { private OAuth2ClientMapper oauth2ClientMapper; @Override - public Long createOAuth2Client(OAuth2ClientCreateReqVO createReqVO) { + public Long createOAuth2Client(OAuth2ClientSaveReqVO createReqVO) { validateClientIdExists(null, createReqVO.getClientId()); // 插入 - OAuth2ClientDO oauth2Client = OAuth2ClientConvert.INSTANCE.convert(createReqVO); - oauth2ClientMapper.insert(oauth2Client); - return oauth2Client.getId(); + OAuth2ClientDO client = BeanUtils.toBean(createReqVO, OAuth2ClientDO.class); + oauth2ClientMapper.insert(client); + return client.getId(); } @Override @CacheEvict(cacheNames = RedisKeyConstants.OAUTH_CLIENT, allEntries = true) // allEntries 清空所有缓存,因为可能修改到 clientId 字段,不好清理 - public void updateOAuth2Client(OAuth2ClientUpdateReqVO updateReqVO) { + public void updateOAuth2Client(OAuth2ClientSaveReqVO updateReqVO) { // 校验存在 validateOAuth2ClientExists(updateReqVO.getId()); // 校验 Client 未被占用 validateClientIdExists(updateReqVO.getId(), updateReqVO.getClientId()); // 更新 - OAuth2ClientDO updateObj = OAuth2ClientConvert.INSTANCE.convert(updateReqVO); + OAuth2ClientDO updateObj = BeanUtils.toBean(updateReqVO, OAuth2ClientDO.class); oauth2ClientMapper.updateById(updateObj); } diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImplTest.java index 25b31220c..3d4e436ab 100755 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImplTest.java @@ -4,9 +4,8 @@ import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO; import cn.iocoder.yudao.module.system.dal.mysql.oauth2.OAuth2ClientMapper; import org.junit.jupiter.api.Test; @@ -42,8 +41,9 @@ public class OAuth2ClientServiceImplTest extends BaseDbUnitTest { @Test public void testCreateOAuth2Client_success() { // 准备参数 - OAuth2ClientCreateReqVO reqVO = randomPojo(OAuth2ClientCreateReqVO.class, - o -> o.setLogo(randomString())); + OAuth2ClientSaveReqVO reqVO = randomPojo(OAuth2ClientSaveReqVO.class, + o -> o.setLogo(randomString())) + .setId(null); // 防止 id 被赋值 // 调用 Long oauth2ClientId = oauth2ClientService.createOAuth2Client(reqVO); @@ -51,7 +51,7 @@ public class OAuth2ClientServiceImplTest extends BaseDbUnitTest { assertNotNull(oauth2ClientId); // 校验记录的属性是否正确 OAuth2ClientDO oAuth2Client = oauth2ClientMapper.selectById(oauth2ClientId); - assertPojoEquals(reqVO, oAuth2Client); + assertPojoEquals(reqVO, oAuth2Client, "id"); } @Test @@ -60,7 +60,7 @@ public class OAuth2ClientServiceImplTest extends BaseDbUnitTest { OAuth2ClientDO dbOAuth2Client = randomPojo(OAuth2ClientDO.class); oauth2ClientMapper.insert(dbOAuth2Client);// @Sql: 先插入出一条存在的数据 // 准备参数 - OAuth2ClientUpdateReqVO reqVO = randomPojo(OAuth2ClientUpdateReqVO.class, o -> { + OAuth2ClientSaveReqVO reqVO = randomPojo(OAuth2ClientSaveReqVO.class, o -> { o.setId(dbOAuth2Client.getId()); // 设置更新的 ID o.setLogo(randomString()); }); @@ -75,7 +75,7 @@ public class OAuth2ClientServiceImplTest extends BaseDbUnitTest { @Test public void testUpdateOAuth2Client_notExists() { // 准备参数 - OAuth2ClientUpdateReqVO reqVO = randomPojo(OAuth2ClientUpdateReqVO.class); + OAuth2ClientSaveReqVO reqVO = randomPojo(OAuth2ClientSaveReqVO.class); // 调用, 并断言异常 assertServiceException(() -> oauth2ClientService.updateOAuth2Client(reqVO), OAUTH2_CLIENT_NOT_EXISTS); From 2dd835893a6a5e14305d521606808d1ac287e784 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 2 Dec 2023 21:47:03 +0800 Subject: [PATCH 09/19] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20permi?= =?UTF-8?q?ssion=20=E6=A8=A1=E5=9D=97=E7=9A=84=20VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OperateLogFrameworkServiceImpl.java | 2 +- .../enums/permission/DataScopeEnum.java | 12 +++- .../admin/permission/MenuController.java | 34 ++++++------ .../admin/permission/RoleController.java | 38 +++++++------ .../permission/vo/menu/MenuCreateReqVO.java | 10 ---- .../admin/permission/vo/menu/MenuRespVO.java | 55 +++++++++++++++++-- .../menu/{MenuBaseVO.java => MenuSaveVO.java} | 10 ++-- .../permission/vo/menu/MenuSimpleRespVO.java | 2 - .../permission/vo/menu/MenuUpdateReqVO.java | 17 ------ .../PermissionAssignRoleDataScopeReqVO.java | 4 +- .../permission/vo/role/RoleCreateReqVO.java | 12 ---- .../admin/permission/vo/role/RoleExcelVO.java | 34 ------------ .../permission/vo/role/RoleExportReqVO.java | 28 ---------- .../admin/permission/vo/role/RoleRespVO.java | 42 ++++++++++---- .../{RoleBaseVO.java => RoleSaveReqVO.java} | 10 ++-- .../permission/vo/role/RoleSimpleRespVO.java | 2 - .../permission/vo/role/RoleUpdateReqVO.java | 18 ------ .../convert/permission/MenuConvert.java | 28 ---------- .../convert/permission/RoleConvert.java | 28 ---------- .../dal/mysql/permission/RoleMapper.java | 9 --- .../service/permission/MenuService.java | 11 ++-- .../service/permission/MenuServiceImpl.java | 31 +++++------ .../service/permission/RoleService.java | 20 ++----- .../service/permission/RoleServiceImpl.java | 27 ++++----- .../service/tenant/TenantServiceImpl.java | 4 +- .../permission/MenuServiceImplTest.java | 16 +++--- .../permission/RoleServiceImplTest.java | 41 ++------------ 27 files changed, 193 insertions(+), 352 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuCreateReqVO.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/{MenuBaseVO.java => MenuSaveVO.java} (92%) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuUpdateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleCreateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleExcelVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleExportReqVO.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/{RoleBaseVO.java => RoleSaveReqVO.java} (84%) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleUpdateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/permission/MenuConvert.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/permission/RoleConvert.java diff --git a/yudao-framework/yudao-spring-boot-starter-biz-operatelog/src/main/java/cn/iocoder/yudao/framework/operatelog/core/service/OperateLogFrameworkServiceImpl.java b/yudao-framework/yudao-spring-boot-starter-biz-operatelog/src/main/java/cn/iocoder/yudao/framework/operatelog/core/service/OperateLogFrameworkServiceImpl.java index a636c4bdf..495193f7c 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-operatelog/src/main/java/cn/iocoder/yudao/framework/operatelog/core/service/OperateLogFrameworkServiceImpl.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-operatelog/src/main/java/cn/iocoder/yudao/framework/operatelog/core/service/OperateLogFrameworkServiceImpl.java @@ -21,7 +21,7 @@ public class OperateLogFrameworkServiceImpl implements OperateLogFrameworkServic @Override @Async public void createOperateLog(OperateLog operateLog) { - OperateLogCreateReqDTO reqDTO = BeanUtil.copyProperties(operateLog, OperateLogCreateReqDTO.class); + OperateLogCreateReqDTO reqDTO = BeanUtil.toBean(operateLog, OperateLogCreateReqDTO.class); operateLogApi.createOperateLog(reqDTO); } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/permission/DataScopeEnum.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/permission/DataScopeEnum.java index 7146b98ef..6b06b06d6 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/permission/DataScopeEnum.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/permission/DataScopeEnum.java @@ -1,8 +1,11 @@ package cn.iocoder.yudao.module.system.enums.permission; +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; import lombok.AllArgsConstructor; import lombok.Getter; +import java.util.Arrays; + /** * 数据范围枚举类 * @@ -12,7 +15,7 @@ import lombok.Getter; */ @Getter @AllArgsConstructor -public enum DataScopeEnum { +public enum DataScopeEnum implements IntArrayValuable { ALL(1), // 全部数据权限 @@ -27,4 +30,11 @@ public enum DataScopeEnum { */ private final Integer scope; + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(DataScopeEnum::getScope).toArray(); + + @Override + public int[] array() { + return ARRAYS; + } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/MenuController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/MenuController.java index 4b007ff72..46a14254c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/MenuController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/MenuController.java @@ -2,13 +2,16 @@ package cn.iocoder.yudao.module.system.controller.admin.permission; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.*; -import cn.iocoder.yudao.module.system.convert.permission.MenuConvert; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuListReqVO; +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuRespVO; +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuSaveVO; +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuSimpleRespVO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; import cn.iocoder.yudao.module.system.service.permission.MenuService; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -32,16 +35,16 @@ public class MenuController { @PostMapping("/create") @Operation(summary = "创建菜单") @PreAuthorize("@ss.hasPermission('system:menu:create')") - public CommonResult createMenu(@Valid @RequestBody MenuCreateReqVO reqVO) { - Long menuId = menuService.createMenu(reqVO); + public CommonResult createMenu(@Valid @RequestBody MenuSaveVO createReqVO) { + Long menuId = menuService.createMenu(createReqVO); return success(menuId); } @PutMapping("/update") @Operation(summary = "修改菜单") @PreAuthorize("@ss.hasPermission('system:menu:update')") - public CommonResult updateMenu(@Valid @RequestBody MenuUpdateReqVO reqVO) { - menuService.updateMenu(reqVO); + public CommonResult updateMenu(@Valid @RequestBody MenuSaveVO updateReqVO) { + menuService.updateMenu(updateReqVO); return success(true); } @@ -60,20 +63,17 @@ public class MenuController { public CommonResult> getMenuList(MenuListReqVO reqVO) { List list = menuService.getMenuList(reqVO); list.sort(Comparator.comparing(MenuDO::getSort)); - return success(MenuConvert.INSTANCE.convertList(list)); + return success(BeanUtils.toBean(list, MenuRespVO.class)); } - @GetMapping("/list-all-simple") + @GetMapping({"/list-all-simple", "simple-list"}) @Operation(summary = "获取菜单精简信息列表", description = "只包含被开启的菜单,用于【角色分配菜单】功能的选项。" + "在多租户的场景下,会只返回租户所在套餐有的菜单") public CommonResult> getSimpleMenuList() { - // 获得菜单列表,只要开启状态的 - MenuListReqVO reqVO = new MenuListReqVO(); - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); - List list = menuService.getMenuListByTenant(reqVO); - // 排序后,返回给前端 + List list = menuService.getMenuListByTenant( + new MenuListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus())); list.sort(Comparator.comparing(MenuDO::getSort)); - return success(MenuConvert.INSTANCE.convertList02(list)); + return success(BeanUtils.toBean(list, MenuSimpleRespVO.class)); } @GetMapping("/get") @@ -81,7 +81,7 @@ public class MenuController { @PreAuthorize("@ss.hasPermission('system:menu:query')") public CommonResult getMenu(Long id) { MenuDO menu = menuService.getMenu(id); - return success(MenuConvert.INSTANCE.convert(menu)); + return success(BeanUtils.toBean(menu, MenuRespVO.class)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/RoleController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/RoleController.java index 2df1e74b0..baf09237c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/RoleController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/RoleController.java @@ -2,16 +2,17 @@ package cn.iocoder.yudao.module.system.controller.admin.permission; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.*; -import cn.iocoder.yudao.module.system.convert.permission.RoleConvert; import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; import cn.iocoder.yudao.module.system.service.permission.RoleService; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -39,15 +40,15 @@ public class RoleController { @PostMapping("/create") @Operation(summary = "创建角色") @PreAuthorize("@ss.hasPermission('system:role:create')") - public CommonResult createRole(@Valid @RequestBody RoleCreateReqVO reqVO) { - return success(roleService.createRole(reqVO, null)); + public CommonResult createRole(@Valid @RequestBody RoleSaveReqVO createReqVO) { + return success(roleService.createRole(createReqVO, null)); } @PutMapping("/update") @Operation(summary = "修改角色") @PreAuthorize("@ss.hasPermission('system:role:update')") - public CommonResult updateRole(@Valid @RequestBody RoleUpdateReqVO reqVO) { - roleService.updateRole(reqVO); + public CommonResult updateRole(@Valid @RequestBody RoleSaveReqVO updateReqVO) { + roleService.updateRole(updateReqVO); return success(true); } @@ -73,34 +74,35 @@ public class RoleController { @PreAuthorize("@ss.hasPermission('system:role:query')") public CommonResult getRole(@RequestParam("id") Long id) { RoleDO role = roleService.getRole(id); - return success(RoleConvert.INSTANCE.convert(role)); + return success(BeanUtils.toBean(role, RoleRespVO.class)); } @GetMapping("/page") @Operation(summary = "获得角色分页") @PreAuthorize("@ss.hasPermission('system:role:query')") - public CommonResult> getRolePage(RolePageReqVO reqVO) { - return success(roleService.getRolePage(reqVO)); + public CommonResult> getRolePage(RolePageReqVO pageReqVO) { + PageResult pageResult = roleService.getRolePage(pageReqVO); + return success(BeanUtils.toBean(pageResult, RoleRespVO.class)); } @GetMapping("/list-all-simple") @Operation(summary = "获取角色精简信息列表", description = "只包含被开启的角色,主要用于前端的下拉选项") public CommonResult> getSimpleRoleList() { - // 获得角色列表,只要开启状态的 List list = roleService.getRoleListByStatus(singleton(CommonStatusEnum.ENABLE.getStatus())); - // 排序后,返回给前端 list.sort(Comparator.comparing(RoleDO::getSort)); - return success(RoleConvert.INSTANCE.convertList02(list)); + return success(BeanUtils.toBean(list, RoleSimpleRespVO.class)); } - @GetMapping("/export") + @GetMapping("/export-excel") + @Operation(summary = "导出角色 Excel") @OperateLog(type = EXPORT) @PreAuthorize("@ss.hasPermission('system:role:export')") - public void export(HttpServletResponse response, @Validated RoleExportReqVO reqVO) throws IOException { - List list = roleService.getRoleList(reqVO); - List data = RoleConvert.INSTANCE.convertList03(list); + public void export(HttpServletResponse response, @Validated RolePageReqVO exportReqVO) throws IOException { + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = roleService.getRolePage(exportReqVO).getList(); // 输出 - ExcelUtils.write(response, "角色数据.xls", "角色列表", RoleExcelVO.class, data); + ExcelUtils.write(response, "角色数据.xls", "数据", RoleRespVO.class, + BeanUtils.toBean(list, RoleRespVO.class)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuCreateReqVO.java deleted file mode 100644 index 56721b7fe..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuCreateReqVO.java +++ /dev/null @@ -1,10 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; - -@Schema(description = "管理后台 - 菜单创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -public class MenuCreateReqVO extends MenuBaseVO { -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuRespVO.java index 6cd9bd174..4be8e1b2f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuRespVO.java @@ -6,21 +6,66 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; import java.time.LocalDateTime; @Schema(description = "管理后台 - 菜单信息 Response VO") @Data -@NoArgsConstructor -@AllArgsConstructor -@EqualsAndHashCode(callSuper = true) -public class MenuRespVO extends MenuBaseVO { +public class MenuRespVO { @Schema(description = "菜单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Long id; - @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @Schema(description = "菜单名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") + @NotBlank(message = "菜单名称不能为空") + @Size(max = 50, message = "菜单名称长度不能超过50个字符") + private String name; + + @Schema(description = "权限标识,仅菜单类型为按钮时,才需要传递", example = "sys:menu:add") + @Size(max = 100) + private String permission; + + @Schema(description = "类型,参见 MenuTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @NotNull(message = "菜单类型不能为空") + private Integer type; + + @Schema(description = "显示顺序不能为空", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @NotNull(message = "显示顺序不能为空") + private Integer sort; + + @Schema(description = "父菜单 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @NotNull(message = "父菜单 ID 不能为空") + private Long parentId; + + @Schema(description = "路由地址,仅菜单类型为菜单或者目录时,才需要传", example = "post") + @Size(max = 200, message = "路由地址不能超过200个字符") + private String path; + + @Schema(description = "菜单图标,仅菜单类型为菜单或者目录时,才需要传", example = "/menu/list") + private String icon; + + @Schema(description = "组件路径,仅菜单类型为菜单时,才需要传", example = "system/post/index") + @Size(max = 200, message = "组件路径不能超过255个字符") + private String component; + + @Schema(description = "组件名", example = "SystemUser") + private String componentName; + + @Schema(description = "状态,见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @NotNull(message = "状态不能为空") private Integer status; + @Schema(description = "是否可见", example = "false") + private Boolean visible; + + @Schema(description = "是否缓存", example = "false") + private Boolean keepAlive; + + @Schema(description = "是否总是显示", example = "false") + private Boolean alwaysShow; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") private LocalDateTime createTime; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuSaveVO.java similarity index 92% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuBaseVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuSaveVO.java index 29e6c36ea..8b91af1b8 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuSaveVO.java @@ -7,12 +7,12 @@ import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; -/** - * 菜单 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ +@Schema(description = "管理后台 - 菜单创建/修改 Request VO") @Data -public class MenuBaseVO { +public class MenuSaveVO { + + @Schema(description = "菜单编号", example = "1024") + private Long id; @Schema(description = "菜单名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") @NotBlank(message = "菜单名称不能为空") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuSimpleRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuSimpleRespVO.java index 19770dd80..20f110e86 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuSimpleRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuSimpleRespVO.java @@ -9,8 +9,6 @@ import javax.validation.constraints.NotNull; @Schema(description = "管理后台 - 菜单精简信息 Response VO") @Data -@NoArgsConstructor -@AllArgsConstructor public class MenuSimpleRespVO { @Schema(description = "菜单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuUpdateReqVO.java deleted file mode 100644 index a931f16e4..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuUpdateReqVO.java +++ /dev/null @@ -1,17 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 菜单更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -public class MenuUpdateReqVO extends MenuBaseVO { - - @Schema(description = "菜单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "菜单编号不能为空") - private Long id; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/permission/PermissionAssignRoleDataScopeReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/permission/PermissionAssignRoleDataScopeReqVO.java index 2957898e8..f70426d31 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/permission/PermissionAssignRoleDataScopeReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/permission/PermissionAssignRoleDataScopeReqVO.java @@ -1,5 +1,7 @@ package cn.iocoder.yudao.module.system.controller.admin.permission.vo.permission; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import cn.iocoder.yudao.module.system.enums.permission.DataScopeEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -17,7 +19,7 @@ public class PermissionAssignRoleDataScopeReqVO { @Schema(description = "数据范围,参见 DataScopeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @NotNull(message = "数据范围不能为空") -// TODO 这里要多一个枚举校验 + @InEnum(value = DataScopeEnum.class, message = "数据范围必须是 {value}") private Integer dataScope; @Schema(description = "部门编号列表,只有范围类型为 DEPT_CUSTOM 时,该字段才需要", example = "1,3,5") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleCreateReqVO.java deleted file mode 100644 index ab4523f15..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleCreateReqVO.java +++ /dev/null @@ -1,12 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.permission.vo.role; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Schema(description = "管理后台 - 角色创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -public class RoleCreateReqVO extends RoleBaseVO { - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleExcelVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleExcelVO.java deleted file mode 100644 index d22cf9bf2..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleExcelVO.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.permission.vo.role; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import cn.iocoder.yudao.module.system.enums.DictTypeConstants; -import com.alibaba.excel.annotation.ExcelProperty; -import lombok.Data; - -/** - * 角色 Excel 导出响应 VO - */ -@Data -public class RoleExcelVO { - - @ExcelProperty("角色序号") - private Long id; - - @ExcelProperty("角色名称") - private String name; - - @ExcelProperty("角色标志") - private String code; - - @ExcelProperty("角色排序") - private Integer sort; - - @ExcelProperty("数据范围") - private Integer dataScope; - - @ExcelProperty(value = "角色状态", converter = DictConvert.class) - @DictFormat(DictTypeConstants.COMMON_STATUS) - private String status; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleExportReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleExportReqVO.java deleted file mode 100644 index 40ff75197..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleExportReqVO.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.permission.vo.role; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 角色分页 Request VO") -@Data -public class RoleExportReqVO { - - @Schema(description = "角色名称,模糊匹配", example = "芋道") - private String name; - - @Schema(description = "角色标识,模糊匹配", example = "yudao") - private String code; - - @Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1") - private Integer status; - - @Schema(description = "开始时间", example = "[2022-07-01 00:00:00,2022-07-01 23:59:59]") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] createTime; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleRespVO.java index 7eeb1493c..2e15ee4f7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleRespVO.java @@ -1,36 +1,56 @@ package cn.iocoder.yudao.module.system.controller.admin.permission.vo.role; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; +import javax.validation.constraints.NotBlank; import java.time.LocalDateTime; import java.util.Set; @Schema(description = "管理后台 - 角色信息 Response VO") @Data -@NoArgsConstructor -@AllArgsConstructor -@EqualsAndHashCode(callSuper = true) -public class RoleRespVO extends RoleBaseVO { +@ExcelIgnoreUnannotated +public class RoleRespVO { @Schema(description = "角色编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty("角色序号") private Long id; - @Schema(description = "数据范围,参见 DataScopeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - private Integer dataScope; + @Schema(description = "角色名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "管理员") + @ExcelProperty("角色名称") + private String name; - @Schema(description = "数据范围(指定部门数组)", example = "1") - private Set dataScopeDeptIds; + @NotBlank(message = "角色标志不能为空") + @ExcelProperty("角色标志") + private String code; + + @Schema(description = "显示顺序不能为空", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("角色排序") + private Integer sort; @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "角色状态", converter = DictConvert.class) + @DictFormat(DictTypeConstants.COMMON_STATUS) private Integer status; @Schema(description = "角色类型,参见 RoleTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") private Integer type; + @Schema(description = "备注", example = "我是一个角色") + private String remark; + + @Schema(description = "数据范围,参见 DataScopeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty("数据范围") + private Integer dataScope; + + @Schema(description = "数据范围(指定部门数组)", example = "1") + private Set dataScopeDeptIds; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") private LocalDateTime createTime; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleSaveReqVO.java similarity index 84% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleBaseVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleSaveReqVO.java index f03ac05e1..5a59b5f4c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleSaveReqVO.java @@ -7,12 +7,12 @@ import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; -/** - * 角色 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ +@Schema(description = "管理后台 - 角色创建 Request VO") @Data -public class RoleBaseVO { +public class RoleSaveReqVO { + + @Schema(description = "角色编号", example = "1") + private Long id; @Schema(description = "角色名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "管理员") @NotBlank(message = "角色名称不能为空") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleSimpleRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleSimpleRespVO.java index bd177148e..1e9a9dffa 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleSimpleRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleSimpleRespVO.java @@ -7,8 +7,6 @@ import lombok.NoArgsConstructor; @Schema(description = "管理后台 - 角色精简信息 Response VO") @Data -@NoArgsConstructor -@AllArgsConstructor public class RoleSimpleRespVO { @Schema(description = "角色编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleUpdateReqVO.java deleted file mode 100644 index 713989c19..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleUpdateReqVO.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.permission.vo.role; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 角色更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -public class RoleUpdateReqVO extends RoleBaseVO { - - @Schema(description = "角色编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "角色编号不能为空") - private Long id; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/permission/MenuConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/permission/MenuConvert.java deleted file mode 100644 index 0fb3505cc..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/permission/MenuConvert.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.permission; - -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuRespVO; -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuSimpleRespVO; -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuUpdateReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper -public interface MenuConvert { - - MenuConvert INSTANCE = Mappers.getMapper(MenuConvert.class); - - List convertList(List list); - - MenuDO convert(MenuCreateReqVO bean); - - MenuDO convert(MenuUpdateReqVO bean); - - MenuRespVO convert(MenuDO bean); - - List convertList02(List list); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/permission/RoleConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/permission/RoleConvert.java deleted file mode 100644 index 73475ee4d..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/permission/RoleConvert.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.permission; - -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.*; -import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; -import cn.iocoder.yudao.module.system.service.permission.bo.RoleCreateReqBO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper -public interface RoleConvert { - - RoleConvert INSTANCE = Mappers.getMapper(RoleConvert.class); - - RoleDO convert(RoleUpdateReqVO bean); - - RoleRespVO convert(RoleDO bean); - - RoleDO convert(RoleCreateReqVO bean); - - List convertList02(List list); - - List convertList03(List list); - - RoleDO convert(RoleCreateReqBO bean); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/RoleMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/RoleMapper.java index 55e853273..f6d86d1a1 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/RoleMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/RoleMapper.java @@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; 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.permission.vo.role.RoleExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RolePageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; import org.apache.ibatis.annotations.Mapper; @@ -25,14 +24,6 @@ public interface RoleMapper extends BaseMapperX { .orderByDesc(RoleDO::getId)); } - default List selectList(RoleExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .likeIfPresent(RoleDO::getName, reqVO.getName()) - .likeIfPresent(RoleDO::getCode, reqVO.getCode()) - .eqIfPresent(RoleDO::getStatus, reqVO.getStatus()) - .betweenIfPresent(BaseDO::getCreateTime, reqVO.getCreateTime())); - } - default RoleDO selectByName(String name) { return selectOne(RoleDO::getName, name); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuService.java index e627ba1f4..adc2b3151 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuService.java @@ -1,8 +1,7 @@ package cn.iocoder.yudao.module.system.service.permission; -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuCreateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuSaveVO; import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuListReqVO; -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuUpdateReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; import java.util.Collection; @@ -18,17 +17,17 @@ public interface MenuService { /** * 创建菜单 * - * @param reqVO 菜单信息 + * @param createReqVO 菜单信息 * @return 创建出来的菜单编号 */ - Long createMenu(MenuCreateReqVO reqVO); + Long createMenu(MenuSaveVO createReqVO); /** * 更新菜单 * - * @param reqVO 菜单信息 + * @param updateReqVO 菜单信息 */ - void updateMenu(MenuUpdateReqVO reqVO); + void updateMenu(MenuSaveVO updateReqVO); /** * 删除菜单 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java index f06fd3474..594094135 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java @@ -1,10 +1,9 @@ package cn.iocoder.yudao.module.system.service.permission; import cn.hutool.core.collection.CollUtil; -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuCreateReqVO; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuSaveVO; import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuListReqVO; -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.permission.MenuConvert; import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; import cn.iocoder.yudao.module.system.dal.mysql.permission.MenuMapper; import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; @@ -45,16 +44,16 @@ public class MenuServiceImpl implements MenuService { private TenantService tenantService; @Override - @CacheEvict(value = RedisKeyConstants.PERMISSION_MENU_ID_LIST, key = "#reqVO.permission", - condition = "#reqVO.permission != null") - public Long createMenu(MenuCreateReqVO reqVO) { + @CacheEvict(value = RedisKeyConstants.PERMISSION_MENU_ID_LIST, key = "#createReqVO.permission", + condition = "#createReqVO.permission != null") + public Long createMenu(MenuSaveVO createReqVO) { // 校验父菜单存在 - validateParentMenu(reqVO.getParentId(), null); + validateParentMenu(createReqVO.getParentId(), null); // 校验菜单(自己) - validateMenu(reqVO.getParentId(), reqVO.getName(), null); + validateMenu(createReqVO.getParentId(), createReqVO.getName(), null); // 插入数据库 - MenuDO menu = MenuConvert.INSTANCE.convert(reqVO); + MenuDO menu = BeanUtils.toBean(createReqVO, MenuDO.class); initMenuProperty(menu); menuMapper.insert(menu); // 返回 @@ -64,20 +63,20 @@ public class MenuServiceImpl implements MenuService { @Override @CacheEvict(value = RedisKeyConstants.PERMISSION_MENU_ID_LIST, allEntries = true) // allEntries 清空所有缓存,因为 permission 如果变更,涉及到新老两个 permission。直接清理,简单有效 - public void updateMenu(MenuUpdateReqVO reqVO) { + public void updateMenu(MenuSaveVO updateReqVO) { // 校验更新的菜单是否存在 - if (menuMapper.selectById(reqVO.getId()) == null) { + if (menuMapper.selectById(updateReqVO.getId()) == null) { throw exception(MENU_NOT_EXISTS); } // 校验父菜单存在 - validateParentMenu(reqVO.getParentId(), reqVO.getId()); + validateParentMenu(updateReqVO.getParentId(), updateReqVO.getId()); // 校验菜单(自己) - validateMenu(reqVO.getParentId(), reqVO.getName(), reqVO.getId()); + validateMenu(updateReqVO.getParentId(), updateReqVO.getName(), updateReqVO.getId()); // 更新到数据库 - MenuDO updateObject = MenuConvert.INSTANCE.convert(reqVO); - initMenuProperty(updateObject); - menuMapper.updateById(updateObject); + MenuDO updateObj = BeanUtils.toBean(updateReqVO, MenuDO.class); + initMenuProperty(updateObj); + menuMapper.updateById(updateObj); } @Override diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleService.java index d837d1e8b..a97eb796d 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleService.java @@ -1,10 +1,8 @@ package cn.iocoder.yudao.module.system.service.permission; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RolePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; import javax.validation.Valid; @@ -22,18 +20,18 @@ public interface RoleService { /** * 创建角色 * - * @param reqVO 创建角色信息 + * @param createReqVO 创建角色信息 * @param type 角色类型 * @return 角色编号 */ - Long createRole(@Valid RoleCreateReqVO reqVO, Integer type); + Long createRole(@Valid RoleSaveReqVO createReqVO, Integer type); /** * 更新角色 * - * @param reqVO 更新角色信息 + * @param updateReqVO 更新角色信息 */ - void updateRole(@Valid RoleUpdateReqVO reqVO); + void updateRole(@Valid RoleSaveReqVO updateReqVO); /** * 删除角色 @@ -114,14 +112,6 @@ public interface RoleService { */ PageResult getRolePage(RolePageReqVO reqVO); - /** - * 获得角色列表 - * - * @param reqVO 列表查询 - * @return 角色列表 - */ - List getRoleList(RoleExportReqVO reqVO); - /** * 判断角色编号数组中,是否有管理员 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImpl.java index c8ae9f343..aa170d36e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImpl.java @@ -6,11 +6,9 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleExportReqVO; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RolePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.permission.RoleConvert; +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; import cn.iocoder.yudao.module.system.dal.mysql.permission.RoleMapper; import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; @@ -50,11 +48,11 @@ public class RoleServiceImpl implements RoleService { @Override @Transactional(rollbackFor = Exception.class) - public Long createRole(RoleCreateReqVO reqVO, Integer type) { + public Long createRole(RoleSaveReqVO createReqVO, Integer type) { // 校验角色 - validateRoleDuplicate(reqVO.getName(), reqVO.getCode(), null); + validateRoleDuplicate(createReqVO.getName(), createReqVO.getCode(), null); // 插入到数据库 - RoleDO role = RoleConvert.INSTANCE.convert(reqVO); + RoleDO role = BeanUtils.toBean(createReqVO, RoleDO.class); role.setType(ObjectUtil.defaultIfNull(type, RoleTypeEnum.CUSTOM.getType())); role.setStatus(CommonStatusEnum.ENABLE.getStatus()); role.setDataScope(DataScopeEnum.ALL.getScope()); // 默认可查看所有数据。原因是,可能一些项目不需要项目权限 @@ -64,15 +62,15 @@ public class RoleServiceImpl implements RoleService { } @Override - @CacheEvict(value = RedisKeyConstants.ROLE, key = "#reqVO.id") - public void updateRole(RoleUpdateReqVO reqVO) { + @CacheEvict(value = RedisKeyConstants.ROLE, key = "#updateReqVO.id") + public void updateRole(RoleSaveReqVO updateReqVO) { // 校验是否可以更新 - validateRoleForUpdate(reqVO.getId()); + validateRoleForUpdate(updateReqVO.getId()); // 校验角色的唯一字段是否重复 - validateRoleDuplicate(reqVO.getName(), reqVO.getCode(), reqVO.getId()); + validateRoleDuplicate(updateReqVO.getName(), updateReqVO.getCode(), updateReqVO.getId()); // 更新到数据库 - RoleDO updateObj = RoleConvert.INSTANCE.convert(reqVO); + RoleDO updateObj = BeanUtils.toBean(updateReqVO, RoleDO.class); roleMapper.updateById(updateObj); } @@ -208,11 +206,6 @@ public class RoleServiceImpl implements RoleService { return roleMapper.selectPage(reqVO); } - @Override - public List getRoleList(RoleExportReqVO reqVO) { - return roleMapper.selectList(reqVO); - } - @Override public boolean hasAnySuperAdmin(Collection ids) { if (CollectionUtil.isEmpty(ids)) { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java index 1df71f606..1f4fce034 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java @@ -11,7 +11,7 @@ import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.framework.tenant.config.TenantProperties; import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleCreateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleSaveReqVO; 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; @@ -130,7 +130,7 @@ public class TenantServiceImpl implements TenantService { private Long createRole(TenantPackageDO tenantPackage) { // 创建角色 - RoleCreateReqVO reqVO = new RoleCreateReqVO(); + RoleSaveReqVO reqVO = new RoleSaveReqVO(); reqVO.setName(RoleCodeEnum.TENANT_ADMIN.getName()).setCode(RoleCodeEnum.TENANT_ADMIN.getCode()) .setSort(0).setRemark("系统自动生成"); Long roleId = roleService.createRole(reqVO, RoleTypeEnum.SYSTEM.getType()); diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImplTest.java index a0c17b3fb..3a95fd30f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImplTest.java @@ -2,9 +2,8 @@ package cn.iocoder.yudao.module.system.service.permission; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuListReqVO; -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuSaveVO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; import cn.iocoder.yudao.module.system.dal.mysql.permission.MenuMapper; import cn.iocoder.yudao.module.system.enums.permission.MenuTypeEnum; @@ -14,7 +13,8 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; import javax.annotation.Resource; -import java.util.*; +import java.util.List; +import java.util.Set; import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet; import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; @@ -51,16 +51,16 @@ public class MenuServiceImplTest extends BaseDbUnitTest { menuMapper.insert(menuDO); Long parentId = menuDO.getId(); // 准备参数 - MenuCreateReqVO reqVO = randomPojo(MenuCreateReqVO.class, o -> { + MenuSaveVO reqVO = randomPojo(MenuSaveVO.class, o -> { o.setParentId(parentId); o.setName("testSonName"); o.setType(MenuTypeEnum.MENU.getType()); - }); + }).setId(null); // 防止 id 被赋值 Long menuId = menuService.createMenu(reqVO); // 校验记录的属性是否正确 MenuDO dbMenu = menuMapper.selectById(menuId); - assertPojoEquals(reqVO, dbMenu); + assertPojoEquals(reqVO, dbMenu, "id"); } @Test @@ -69,7 +69,7 @@ public class MenuServiceImplTest extends BaseDbUnitTest { MenuDO sonMenuDO = createParentAndSonMenu(); Long sonId = sonMenuDO.getId(); // 准备参数 - MenuUpdateReqVO reqVO = randomPojo(MenuUpdateReqVO.class, o -> { + MenuSaveVO reqVO = randomPojo(MenuSaveVO.class, o -> { o.setId(sonId); o.setName("testSonName"); // 修改名字 o.setParentId(sonMenuDO.getParentId()); @@ -86,7 +86,7 @@ public class MenuServiceImplTest extends BaseDbUnitTest { @Test public void testUpdateMenu_sonIdNotExist() { // 准备参数 - MenuUpdateReqVO reqVO = randomPojo(MenuUpdateReqVO.class); + MenuSaveVO reqVO = randomPojo(MenuSaveVO.class); // 调用,并断言异常 assertServiceException(() -> menuService.updateMenu(reqVO), MENU_NOT_EXISTS); } diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImplTest.java index 5c7e96398..6b590e161 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImplTest.java @@ -4,10 +4,8 @@ import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RolePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; import cn.iocoder.yudao.module.system.dal.mysql.permission.RoleMapper; import cn.iocoder.yudao.module.system.enums.permission.DataScopeEnum; @@ -52,13 +50,14 @@ public class RoleServiceImplTest extends BaseDbUnitTest { @Test public void testCreateRole() { // 准备参数 - RoleCreateReqVO reqVO = randomPojo(RoleCreateReqVO.class); + RoleSaveReqVO reqVO = randomPojo(RoleSaveReqVO.class) + .setId(null); // 防止 id 被赋值 // 调用 Long roleId = roleService.createRole(reqVO, null); // 断言 RoleDO roleDO = roleMapper.selectById(roleId); - assertPojoEquals(reqVO, roleDO); + assertPojoEquals(reqVO, roleDO, "id"); assertEquals(RoleTypeEnum.CUSTOM.getType(), roleDO.getType()); assertEquals(CommonStatusEnum.ENABLE.getStatus(), roleDO.getStatus()); assertEquals(DataScopeEnum.ALL.getScope(), roleDO.getDataScope()); @@ -71,7 +70,7 @@ public class RoleServiceImplTest extends BaseDbUnitTest { roleMapper.insert(roleDO); // 准备参数 Long id = roleDO.getId(); - RoleUpdateReqVO reqVO = randomPojo(RoleUpdateReqVO.class, o -> o.setId(id)); + RoleSaveReqVO reqVO = randomPojo(RoleSaveReqVO.class, o -> o.setId(id)); // 调用 roleService.updateRole(reqVO); @@ -256,36 +255,6 @@ public class RoleServiceImplTest extends BaseDbUnitTest { } } - @Test - public void testGetRoleList() { - // mock 数据 - RoleDO dbRole = randomPojo(RoleDO.class, o -> { // 等会查询到 - o.setName("土豆"); - o.setCode("tudou"); - o.setStatus(CommonStatusEnum.ENABLE.getStatus()); - o.setCreateTime(buildTime(2022, 2, 8)); - }); - roleMapper.insert(dbRole); - // 测试 name 不匹配 - roleMapper.insert(cloneIgnoreId(dbRole, o -> o.setName("红薯"))); - // 测试 code 不匹配 - roleMapper.insert(cloneIgnoreId(dbRole, o -> o.setCode("hong"))); - // 测试 createTime 不匹配 - roleMapper.insert(cloneIgnoreId(dbRole, o -> o.setCreateTime(buildTime(2022, 2, 16)))); - // 准备参数 - RoleExportReqVO reqVO = new RoleExportReqVO(); - reqVO.setName("土豆"); - reqVO.setCode("tu"); - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); - reqVO.setCreateTime(buildBetweenTime(2022, 2, 1, 2022, 2, 12)); - - // 调用 - List list = roleService.getRoleList(reqVO); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbRole, list.get(0)); - } - @Test public void testGetRolePage() { // mock 数据 From 8b67111733a7222038dc11cc45885d965dbcde41 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 2 Dec 2023 21:59:08 +0800 Subject: [PATCH 10/19] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20sensi?= =?UTF-8?q?tiveWord=20=E6=A8=A1=E5=9D=97=E7=9A=84=20VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SensitiveWordController.java | 28 ++++++------ .../vo/SensitiveWordCreateReqVO.java | 14 ------ .../vo/SensitiveWordExcelVO.java | 40 ----------------- .../vo/SensitiveWordExportReqVO.java | 28 ------------ .../sensitiveword/vo/SensitiveWordRespVO.java | 29 +++++++++++-- ...rdBaseVO.java => SensitiveWordSaveVO.java} | 10 ++--- .../vo/SensitiveWordUpdateReqVO.java | 20 --------- .../sensitiveword/SensitiveWordConvert.java | 36 ---------------- .../sensitiveword/SensitiveWordMapper.java | 12 ------ .../sensitiveword/SensitiveWordService.java | 16 ++----- .../SensitiveWordServiceImpl.java | 19 +++----- .../SensitiveWordServiceImplTest.java | 43 +++---------------- 12 files changed, 62 insertions(+), 233 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordCreateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordExcelVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordExportReqVO.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/{SensitiveWordBaseVO.java => SensitiveWordSaveVO.java} (80%) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordUpdateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/sensitiveword/SensitiveWordConvert.java diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/SensitiveWordController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/SensitiveWordController.java index ab0a129df..f2231d897 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/SensitiveWordController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/SensitiveWordController.java @@ -1,16 +1,19 @@ package cn.iocoder.yudao.module.system.controller.admin.sensitiveword; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.*; -import cn.iocoder.yudao.module.system.convert.sensitiveword.SensitiveWordConvert; +import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordRespVO; +import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordSaveVO; import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; import cn.iocoder.yudao.module.system.service.sensitiveword.SensitiveWordService; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -37,14 +40,14 @@ public class SensitiveWordController { @PostMapping("/create") @Operation(summary = "创建敏感词") @PreAuthorize("@ss.hasPermission('system:sensitive-word:create')") - public CommonResult createSensitiveWord(@Valid @RequestBody SensitiveWordCreateReqVO createReqVO) { + public CommonResult createSensitiveWord(@Valid @RequestBody SensitiveWordSaveVO createReqVO) { return success(sensitiveWordService.createSensitiveWord(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新敏感词") @PreAuthorize("@ss.hasPermission('system:sensitive-word:update')") - public CommonResult updateSensitiveWord(@Valid @RequestBody SensitiveWordUpdateReqVO updateReqVO) { + public CommonResult updateSensitiveWord(@Valid @RequestBody SensitiveWordSaveVO updateReqVO) { sensitiveWordService.updateSensitiveWord(updateReqVO); return success(true); } @@ -64,7 +67,7 @@ public class SensitiveWordController { @PreAuthorize("@ss.hasPermission('system:sensitive-word:query')") public CommonResult getSensitiveWord(@RequestParam("id") Long id) { SensitiveWordDO sensitiveWord = sensitiveWordService.getSensitiveWord(id); - return success(SensitiveWordConvert.INSTANCE.convert(sensitiveWord)); + return success(BeanUtils.toBean(sensitiveWord, SensitiveWordRespVO.class)); } @GetMapping("/page") @@ -72,19 +75,20 @@ public class SensitiveWordController { @PreAuthorize("@ss.hasPermission('system:sensitive-word:query')") public CommonResult> getSensitiveWordPage(@Valid SensitiveWordPageReqVO pageVO) { PageResult pageResult = sensitiveWordService.getSensitiveWordPage(pageVO); - return success(SensitiveWordConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, SensitiveWordRespVO.class)); } @GetMapping("/export-excel") @Operation(summary = "导出敏感词 Excel") @PreAuthorize("@ss.hasPermission('system:sensitive-word:export')") @OperateLog(type = EXPORT) - public void exportSensitiveWordExcel(@Valid SensitiveWordExportReqVO exportReqVO, + public void exportSensitiveWordExcel(@Valid SensitiveWordPageReqVO exportReqVO, HttpServletResponse response) throws IOException { - List list = sensitiveWordService.getSensitiveWordList(exportReqVO); + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = sensitiveWordService.getSensitiveWordPage(exportReqVO).getList(); // 导出 Excel - List datas = SensitiveWordConvert.INSTANCE.convertList02(list); - ExcelUtils.write(response, "敏感词.xls", "数据", SensitiveWordExcelVO.class, datas); + ExcelUtils.write(response, "敏感词.xls", "数据", SensitiveWordRespVO.class, + BeanUtils.toBean(list, SensitiveWordRespVO.class)); } @GetMapping("/get-tags") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordCreateReqVO.java deleted file mode 100644 index 2e2e89df5..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordCreateReqVO.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -@Schema(description = "管理后台 - 敏感词创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class SensitiveWordCreateReqVO extends SensitiveWordBaseVO { - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordExcelVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordExcelVO.java deleted file mode 100644 index 29409cbe3..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordExcelVO.java +++ /dev/null @@ -1,40 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import cn.iocoder.yudao.framework.excel.core.convert.JsonConvert; -import cn.iocoder.yudao.module.system.enums.DictTypeConstants; -import com.alibaba.excel.annotation.ExcelProperty; -import lombok.Data; - -import java.time.LocalDateTime; -import java.util.List; - -/** - * 敏感词 Excel VO - * - * @author 永不言败 - */ -@Data -public class SensitiveWordExcelVO { - - @ExcelProperty("编号") - private Long id; - - @ExcelProperty("敏感词") - private String name; - - @ExcelProperty(value = "标签", converter = JsonConvert.class) - private List tags; - - @ExcelProperty(value = "状态", converter = DictConvert.class) - @DictFormat(DictTypeConstants.COMMON_STATUS) - private Integer status; - - @ExcelProperty("描述") - private String description; - - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordExportReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordExportReqVO.java deleted file mode 100644 index 6ea8614ab..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordExportReqVO.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 敏感词 Excel 导出 Request VO,参数和 SensitiveWordPageReqVO 是一致的") -@Data -public class SensitiveWordExportReqVO { - - @Schema(description = "敏感词", example = "敏感词") - private String name; - - @Schema(description = "标签", example = "短信,评论") - private String tag; - - @Schema(description = "状态,参见 CommonStatusEnum 枚举类", example = "1") - private Integer status; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @Schema(description = "创建时间") - private LocalDateTime[] createTime; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordRespVO.java index 750d733cf..43d041ecc 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordRespVO.java @@ -1,22 +1,45 @@ package cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import cn.iocoder.yudao.framework.excel.core.convert.JsonConvert; +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; +import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; import java.time.LocalDateTime; +import java.util.List; @Schema(description = "管理后台 - 敏感词 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class SensitiveWordRespVO extends SensitiveWordBaseVO { +public class SensitiveWordRespVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty("编号") private Long id; + @Schema(description = "敏感词", requiredMode = Schema.RequiredMode.REQUIRED, example = "敏感词") + @ExcelProperty("敏感词") + private String name; + + @Schema(description = "标签", requiredMode = Schema.RequiredMode.REQUIRED, example = "短信,评论") + @ExcelProperty(value = "标签", converter = JsonConvert.class) + private List tags; + + @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "状态", converter = DictConvert.class) + @DictFormat(DictTypeConstants.COMMON_STATUS) + private Integer status; + + @Schema(description = "描述", example = "污言秽语") + @ExcelProperty("描述") + private String description; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") private LocalDateTime createTime; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordSaveVO.java similarity index 80% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordBaseVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordSaveVO.java index b2ae46d17..c7b2fbd89 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordSaveVO.java @@ -6,12 +6,12 @@ import lombok.Data; import javax.validation.constraints.NotNull; import java.util.List; -/** - * 敏感词 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ +@Schema(description = "管理后台 - 敏感词创建/修改 Request VO") @Data -public class SensitiveWordBaseVO { +public class SensitiveWordSaveVO { + + @Schema(description = "编号", example = "1") + private Long id; @Schema(description = "敏感词", requiredMode = Schema.RequiredMode.REQUIRED, example = "敏感词") @NotNull(message = "敏感词不能为空") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordUpdateReqVO.java deleted file mode 100644 index 7c8100383..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordUpdateReqVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 敏感词更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class SensitiveWordUpdateReqVO extends SensitiveWordBaseVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "编号不能为空") - private Long id; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/sensitiveword/SensitiveWordConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/sensitiveword/SensitiveWordConvert.java deleted file mode 100644 index fde03dbf3..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/sensitiveword/SensitiveWordConvert.java +++ /dev/null @@ -1,36 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.sensitiveword; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordExcelVO; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordRespVO; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordUpdateReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -/** - * 敏感词 Convert - * - * @author 永不言败 - */ -@Mapper -public interface SensitiveWordConvert { - - SensitiveWordConvert INSTANCE = Mappers.getMapper(SensitiveWordConvert.class); - - SensitiveWordDO convert(SensitiveWordCreateReqVO bean); - - SensitiveWordDO convert(SensitiveWordUpdateReqVO bean); - - SensitiveWordRespVO convert(SensitiveWordDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); - - List convertList02(List list); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sensitiveword/SensitiveWordMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sensitiveword/SensitiveWordMapper.java index 646e8f2b3..f4bf8cc69 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sensitiveword/SensitiveWordMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sensitiveword/SensitiveWordMapper.java @@ -3,14 +3,12 @@ package cn.iocoder.yudao.module.system.dal.mysql.sensitiveword; 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.sensitiveword.vo.SensitiveWordExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select; import java.time.LocalDateTime; -import java.util.List; /** * 敏感词 Mapper @@ -28,16 +26,6 @@ public interface SensitiveWordMapper extends BaseMapperX { .betweenIfPresent(SensitiveWordDO::getCreateTime, reqVO.getCreateTime()) .orderByDesc(SensitiveWordDO::getId)); } - - default List selectList(SensitiveWordExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .likeIfPresent(SensitiveWordDO::getName, reqVO.getName()) - .likeIfPresent(SensitiveWordDO::getTags, reqVO.getTag()) - .eqIfPresent(SensitiveWordDO::getStatus, reqVO.getStatus()) - .betweenIfPresent(SensitiveWordDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(SensitiveWordDO::getId)); - } - default SensitiveWordDO selectByName(String name) { return selectOne(SensitiveWordDO::getName, name); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordService.java index e84e81f6d..4f0363274 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordService.java @@ -1,10 +1,8 @@ package cn.iocoder.yudao.module.system.service.sensitiveword; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordSaveVO; import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; import javax.validation.Valid; @@ -24,14 +22,14 @@ public interface SensitiveWordService { * @param createReqVO 创建信息 * @return 编号 */ - Long createSensitiveWord(@Valid SensitiveWordCreateReqVO createReqVO); + Long createSensitiveWord(@Valid SensitiveWordSaveVO createReqVO); /** * 更新敏感词 * * @param updateReqVO 更新信息 */ - void updateSensitiveWord(@Valid SensitiveWordUpdateReqVO updateReqVO); + void updateSensitiveWord(@Valid SensitiveWordSaveVO updateReqVO); /** * 删除敏感词 @@ -63,14 +61,6 @@ public interface SensitiveWordService { */ PageResult getSensitiveWordPage(SensitiveWordPageReqVO pageReqVO); - /** - * 获得敏感词列表, 用于 Excel 导出 - * - * @param exportReqVO 查询条件 - * @return 敏感词列表 - */ - List getSensitiveWordList(SensitiveWordExportReqVO exportReqVO); - /** * 获得所有敏感词的标签数组 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImpl.java index 991708c36..08ee30958 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImpl.java @@ -4,11 +4,9 @@ import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; 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.sensitiveword.vo.SensitiveWordCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordExportReqVO; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.sensitiveword.SensitiveWordConvert; +import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordSaveVO; import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; import cn.iocoder.yudao.module.system.dal.mysql.sensitiveword.SensitiveWordMapper; import cn.iocoder.yudao.module.system.util.collection.SimpleTrie; @@ -141,12 +139,12 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { } @Override - public Long createSensitiveWord(SensitiveWordCreateReqVO createReqVO) { + public Long createSensitiveWord(SensitiveWordSaveVO createReqVO) { // 校验唯一性 validateSensitiveWordNameUnique(null, createReqVO.getName()); // 插入 - SensitiveWordDO sensitiveWord = SensitiveWordConvert.INSTANCE.convert(createReqVO); + SensitiveWordDO sensitiveWord = BeanUtils.toBean(createReqVO, SensitiveWordDO.class); sensitiveWordMapper.insert(sensitiveWord); // 刷新缓存 @@ -155,13 +153,13 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { } @Override - public void updateSensitiveWord(SensitiveWordUpdateReqVO updateReqVO) { + public void updateSensitiveWord(SensitiveWordSaveVO updateReqVO) { // 校验唯一性 validateSensitiveWordExists(updateReqVO.getId()); validateSensitiveWordNameUnique(updateReqVO.getId(), updateReqVO.getName()); // 更新 - SensitiveWordDO updateObj = SensitiveWordConvert.INSTANCE.convert(updateReqVO); + SensitiveWordDO updateObj = BeanUtils.toBean(updateReqVO, SensitiveWordDO.class); sensitiveWordMapper.updateById(updateObj); // 刷新缓存 @@ -214,11 +212,6 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { return sensitiveWordMapper.selectPage(pageReqVO); } - @Override - public List getSensitiveWordList(SensitiveWordExportReqVO exportReqVO) { - return sensitiveWordMapper.selectList(exportReqVO); - } - @Override public Set getSensitiveWordTagSet() { return sensitiveWordTagsCache; diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImplTest.java index 47f1ea923..cc7b11d50 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImplTest.java @@ -4,10 +4,8 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.SetUtils; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordSaveVO; import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; import cn.iocoder.yudao.module.system.dal.mysql.sensitiveword.SensitiveWordMapper; import org.junit.jupiter.api.BeforeEach; @@ -83,7 +81,8 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { @Test public void testCreateSensitiveWord_success() { // 准备参数 - SensitiveWordCreateReqVO reqVO = randomPojo(SensitiveWordCreateReqVO.class); + SensitiveWordSaveVO reqVO = randomPojo(SensitiveWordSaveVO.class) + .setId(null); // 防止 id 被赋值 // 调用 Long sensitiveWordId = sensitiveWordService.createSensitiveWord(reqVO); @@ -91,7 +90,7 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { assertNotNull(sensitiveWordId); // 校验记录的属性是否正确 SensitiveWordDO sensitiveWord = sensitiveWordMapper.selectById(sensitiveWordId); - assertPojoEquals(reqVO, sensitiveWord); + assertPojoEquals(reqVO, sensitiveWord, "id"); } @Test @@ -100,7 +99,7 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { SensitiveWordDO dbSensitiveWord = randomPojo(SensitiveWordDO.class); sensitiveWordMapper.insert(dbSensitiveWord);// @Sql: 先插入出一条存在的数据 // 准备参数 - SensitiveWordUpdateReqVO reqVO = randomPojo(SensitiveWordUpdateReqVO.class, o -> { + SensitiveWordSaveVO reqVO = randomPojo(SensitiveWordSaveVO.class, o -> { o.setId(dbSensitiveWord.getId()); // 设置更新的 ID }); @@ -114,7 +113,7 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { @Test public void testUpdateSensitiveWord_notExists() { // 准备参数 - SensitiveWordUpdateReqVO reqVO = randomPojo(SensitiveWordUpdateReqVO.class); + SensitiveWordSaveVO reqVO = randomPojo(SensitiveWordSaveVO.class); // 调用, 并断言异常 assertServiceException(() -> sensitiveWordService.updateSensitiveWord(reqVO), SENSITIVE_WORD_NOT_EXISTS); @@ -204,36 +203,6 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { assertPojoEquals(dbSensitiveWord, pageResult.getList().get(0)); } - @Test - public void testGetSensitiveWordList_export() { - // mock 数据 - SensitiveWordDO dbSensitiveWord = randomPojo(SensitiveWordDO.class, o -> { // 等会查询到 - o.setName("笨蛋"); - o.setTags(Arrays.asList("论坛", "蔬菜")); - o.setStatus(CommonStatusEnum.ENABLE.getStatus()); - o.setCreateTime(buildTime(2022, 2, 8)); - }); - sensitiveWordMapper.insert(dbSensitiveWord); - // 测试 name 不匹配 - sensitiveWordMapper.insert(cloneIgnoreId(dbSensitiveWord, o -> o.setName("傻瓜"))); - // 测试 tags 不匹配 - sensitiveWordMapper.insert(cloneIgnoreId(dbSensitiveWord, o -> o.setTags(Arrays.asList("短信", "日用品")))); - // 测试 createTime 不匹配 - sensitiveWordMapper.insert(cloneIgnoreId(dbSensitiveWord, o -> o.setCreateTime(buildTime(2022, 2, 16)))); - // 准备参数 - SensitiveWordExportReqVO reqVO = new SensitiveWordExportReqVO(); - reqVO.setName("笨"); - reqVO.setTag("论坛"); - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); - reqVO.setCreateTime(buildBetweenTime(2022, 2, 1, 2022, 2, 12)); - - // 调用 - List list = sensitiveWordService.getSensitiveWordList(reqVO); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbSensitiveWord, list.get(0)); - } - @Test public void testValidateText_noTag() { testInitLocalCache(); From e61ecb63dd103ab9ebcb352b5b35882a51a3c1e6 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 2 Dec 2023 22:39:23 +0800 Subject: [PATCH 11/19] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20sms?= =?UTF-8?q?=20=E6=A8=A1=E5=9D=97=E7=9A=84=20VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/permission/RoleController.java | 2 +- .../admin/sms/SmsChannelController.java | 30 +++--- .../admin/sms/SmsLogController.java | 30 +++--- .../admin/sms/SmsTemplateController.java | 22 +++-- .../sms/vo/channel/SmsChannelCreateReqVO.java | 20 ---- .../sms/vo/channel/SmsChannelRespVO.java | 30 +++++- ...elBaseVO.java => SmsChannelSaveReqVO.java} | 15 ++- .../vo/channel/SmsChannelSimpleRespVO.java | 4 - .../sms/vo/channel/SmsChannelUpdateReqVO.java | 20 ---- .../admin/sms/vo/log/SmsLogExcelVO.java | 94 ------------------- .../admin/sms/vo/log/SmsLogExportReqVO.java | 38 -------- .../admin/sms/vo/log/SmsLogRespVO.java | 34 +++++++ .../vo/template/SmsTemplateCreateReqVO.java | 13 --- .../sms/vo/template/SmsTemplateExcelVO.java | 55 ----------- .../vo/template/SmsTemplateExportReqVO.java | 37 -------- .../sms/vo/template/SmsTemplateRespVO.java | 54 +++++++++-- ...eBaseVO.java => SmsTemplateSaveReqVO.java} | 11 ++- .../vo/template/SmsTemplateUpdateReqVO.java | 20 ---- .../system/convert/sms/SmsChannelConvert.java | 39 -------- .../system/convert/sms/SmsLogConvert.java | 30 ------ .../convert/sms/SmsTemplateConvert.java | 31 ------ .../system/dal/mysql/sms/SmsLogMapper.java | 15 --- .../dal/mysql/sms/SmsTemplateMapper.java | 15 --- .../system/service/sms/SmsChannelService.java | 7 +- .../service/sms/SmsChannelServiceImpl.java | 19 ++-- .../system/service/sms/SmsLogService.java | 12 +-- .../system/service/sms/SmsLogServiceImpl.java | 7 -- .../service/sms/SmsTemplateService.java | 24 ++--- .../service/sms/SmsTemplateServiceImpl.java | 21 ++--- .../service/sms/SmsChannelServiceTest.java | 20 ++-- .../service/sms/SmsLogServiceImplTest.java | 46 --------- .../sms/SmsTemplateServiceImplTest.java | 58 ++---------- 32 files changed, 208 insertions(+), 665 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelCreateReqVO.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/{SmsChannelBaseVO.java => SmsChannelSaveReqVO.java} (74%) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelUpdateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/log/SmsLogExcelVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/log/SmsLogExportReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateCreateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateExcelVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateExportReqVO.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/{SmsTemplateBaseVO.java => SmsTemplateSaveReqVO.java} (89%) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateUpdateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/sms/SmsChannelConvert.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/sms/SmsLogConvert.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/sms/SmsTemplateConvert.java diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/RoleController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/RoleController.java index baf09237c..14437a6fc 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/RoleController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/RoleController.java @@ -85,7 +85,7 @@ public class RoleController { return success(BeanUtils.toBean(pageResult, RoleRespVO.class)); } - @GetMapping("/list-all-simple") + @GetMapping({"/list-all-simple", "/simple-list"}) @Operation(summary = "获取角色精简信息列表", description = "只包含被开启的角色,主要用于前端的下拉选项") public CommonResult> getSimpleRoleList() { List list = roleService.getRoleListByStatus(singleton(CommonStatusEnum.ENABLE.getStatus())); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/SmsChannelController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/SmsChannelController.java index b6512a601..79ff7b80d 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/SmsChannelController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/SmsChannelController.java @@ -1,14 +1,17 @@ package cn.iocoder.yudao.module.system.controller.admin.sms; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.*; -import cn.iocoder.yudao.module.system.convert.sms.SmsChannelConvert; -import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; -import cn.iocoder.yudao.module.system.service.sms.SmsChannelService; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelPageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelRespVO; +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelSaveReqVO; +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelSimpleRespVO; +import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; +import cn.iocoder.yudao.module.system.service.sms.SmsChannelService; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; @@ -30,14 +33,14 @@ public class SmsChannelController { @PostMapping("/create") @Operation(summary = "创建短信渠道") @PreAuthorize("@ss.hasPermission('system:sms-channel:create')") - public CommonResult createSmsChannel(@Valid @RequestBody SmsChannelCreateReqVO createReqVO) { + public CommonResult createSmsChannel(@Valid @RequestBody SmsChannelSaveReqVO createReqVO) { return success(smsChannelService.createSmsChannel(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新短信渠道") @PreAuthorize("@ss.hasPermission('system:sms-channel:update')") - public CommonResult updateSmsChannel(@Valid @RequestBody SmsChannelUpdateReqVO updateReqVO) { + public CommonResult updateSmsChannel(@Valid @RequestBody SmsChannelSaveReqVO updateReqVO) { smsChannelService.updateSmsChannel(updateReqVO); return success(true); } @@ -56,8 +59,8 @@ public class SmsChannelController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('system:sms-channel:query')") public CommonResult getSmsChannel(@RequestParam("id") Long id) { - SmsChannelDO smsChannel = smsChannelService.getSmsChannel(id); - return success(SmsChannelConvert.INSTANCE.convert(smsChannel)); + SmsChannelDO channel = smsChannelService.getSmsChannel(id); + return success(BeanUtils.toBean(channel, SmsChannelRespVO.class)); } @GetMapping("/page") @@ -65,16 +68,15 @@ public class SmsChannelController { @PreAuthorize("@ss.hasPermission('system:sms-channel:query')") public CommonResult> getSmsChannelPage(@Valid SmsChannelPageReqVO pageVO) { PageResult pageResult = smsChannelService.getSmsChannelPage(pageVO); - return success(SmsChannelConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, SmsChannelRespVO.class)); } - @GetMapping("/list-all-simple") + @GetMapping({"/list-all-simple", "/simple-list"}) @Operation(summary = "获得短信渠道精简列表", description = "包含被禁用的短信渠道") public CommonResult> getSimpleSmsChannelList() { List list = smsChannelService.getSmsChannelList(); - // 排序后,返回给前端 list.sort(Comparator.comparing(SmsChannelDO::getId)); - return success(SmsChannelConvert.INSTANCE.convertList03(list)); + return success(BeanUtils.toBean(list, SmsChannelSimpleRespVO.class)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/SmsLogController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/SmsLogController.java index 27b957bd6..fda06b8de 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/SmsLogController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/SmsLogController.java @@ -1,18 +1,17 @@ package cn.iocoder.yudao.module.system.controller.admin.sms; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.log.SmsLogExcelVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.log.SmsLogExportReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.log.SmsLogPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.log.SmsLogRespVO; -import cn.iocoder.yudao.module.system.convert.sms.SmsLogConvert; -import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsLogDO; -import cn.iocoder.yudao.module.system.service.sms.SmsLogService; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import io.swagger.v3.oas.annotations.tags.Tag; +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.log.SmsLogPageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.log.SmsLogRespVO; +import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsLogDO; +import cn.iocoder.yudao.module.system.service.sms.SmsLogService; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; @@ -40,21 +39,22 @@ public class SmsLogController { @GetMapping("/page") @Operation(summary = "获得短信日志分页") @PreAuthorize("@ss.hasPermission('system:sms-log:query')") - public CommonResult> getSmsLogPage(@Valid SmsLogPageReqVO pageVO) { - PageResult pageResult = smsLogService.getSmsLogPage(pageVO); - return success(SmsLogConvert.INSTANCE.convertPage(pageResult)); + public CommonResult> getSmsLogPage(@Valid SmsLogPageReqVO pageReqVO) { + PageResult pageResult = smsLogService.getSmsLogPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, SmsLogRespVO.class)); } @GetMapping("/export-excel") @Operation(summary = "导出短信日志 Excel") @PreAuthorize("@ss.hasPermission('system:sms-log:export')") @OperateLog(type = EXPORT) - public void exportSmsLogExcel(@Valid SmsLogExportReqVO exportReqVO, + public void exportSmsLogExcel(@Valid SmsLogPageReqVO exportReqVO, HttpServletResponse response) throws IOException { - List list = smsLogService.getSmsLogList(exportReqVO); + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = smsLogService.getSmsLogPage(exportReqVO).getList(); // 导出 Excel - List datas = SmsLogConvert.INSTANCE.convertList02(list); - ExcelUtils.write(response, "短信日志.xls", "数据", SmsLogExcelVO.class, datas); + ExcelUtils.write(response, "短信日志.xls", "数据", SmsLogRespVO.class, + BeanUtils.toBean(list, SmsLogRespVO.class)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/SmsTemplateController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/SmsTemplateController.java index 173d8f643..7fe345f29 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/SmsTemplateController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/SmsTemplateController.java @@ -1,7 +1,8 @@ package cn.iocoder.yudao.module.system.controller.admin.sms; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.*; -import cn.iocoder.yudao.module.system.convert.sms.SmsTemplateConvert; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import cn.iocoder.yudao.module.system.service.sms.SmsTemplateService; import cn.iocoder.yudao.module.system.service.sms.SmsSendService; @@ -37,14 +38,14 @@ public class SmsTemplateController { @PostMapping("/create") @Operation(summary = "创建短信模板") @PreAuthorize("@ss.hasPermission('system:sms-template:create')") - public CommonResult createSmsTemplate(@Valid @RequestBody SmsTemplateCreateReqVO createReqVO) { + public CommonResult createSmsTemplate(@Valid @RequestBody SmsTemplateSaveReqVO createReqVO) { return success(smsTemplateService.createSmsTemplate(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新短信模板") @PreAuthorize("@ss.hasPermission('system:sms-template:update')") - public CommonResult updateSmsTemplate(@Valid @RequestBody SmsTemplateUpdateReqVO updateReqVO) { + public CommonResult updateSmsTemplate(@Valid @RequestBody SmsTemplateSaveReqVO updateReqVO) { smsTemplateService.updateSmsTemplate(updateReqVO); return success(true); } @@ -63,8 +64,8 @@ public class SmsTemplateController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('system:sms-template:query')") public CommonResult getSmsTemplate(@RequestParam("id") Long id) { - SmsTemplateDO smsTemplate = smsTemplateService.getSmsTemplate(id); - return success(SmsTemplateConvert.INSTANCE.convert(smsTemplate)); + SmsTemplateDO template = smsTemplateService.getSmsTemplate(id); + return success(BeanUtils.toBean(template, SmsTemplateRespVO.class)); } @GetMapping("/page") @@ -72,19 +73,20 @@ public class SmsTemplateController { @PreAuthorize("@ss.hasPermission('system:sms-template:query')") public CommonResult> getSmsTemplatePage(@Valid SmsTemplatePageReqVO pageVO) { PageResult pageResult = smsTemplateService.getSmsTemplatePage(pageVO); - return success(SmsTemplateConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, SmsTemplateRespVO.class)); } @GetMapping("/export-excel") @Operation(summary = "导出短信模板 Excel") @PreAuthorize("@ss.hasPermission('system:sms-template:export')") @OperateLog(type = EXPORT) - public void exportSmsTemplateExcel(@Valid SmsTemplateExportReqVO exportReqVO, + public void exportSmsTemplateExcel(@Valid SmsTemplatePageReqVO exportReqVO, HttpServletResponse response) throws IOException { - List list = smsTemplateService.getSmsTemplateList(exportReqVO); + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = smsTemplateService.getSmsTemplatePage(exportReqVO).getList(); // 导出 Excel - List datas = SmsTemplateConvert.INSTANCE.convertList02(list); - ExcelUtils.write(response, "短信模板.xls", "数据", SmsTemplateExcelVO.class, datas); + ExcelUtils.write(response, "短信模板.xls", "数据", SmsTemplateRespVO.class, + BeanUtils.toBean(list, SmsTemplateRespVO.class)); } @PostMapping("/send-sms") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelCreateReqVO.java deleted file mode 100644 index 7e052de57..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelCreateReqVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 短信渠道创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class SmsChannelCreateReqVO extends SmsChannelBaseVO { - - @Schema(description = "渠道编码,参见 SmsChannelEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "YUN_PIAN") - @NotNull(message = "渠道编码不能为空") - private String code; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelRespVO.java index 040f5bc24..70b709e2c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelRespVO.java @@ -2,23 +2,43 @@ package cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; +import org.hibernate.validator.constraints.URL; +import javax.validation.constraints.NotNull; import java.time.LocalDateTime; @Schema(description = "管理后台 - 短信渠道 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class SmsChannelRespVO extends SmsChannelBaseVO { +public class SmsChannelRespVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Long id; + @Schema(description = "短信签名", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码") + @NotNull(message = "短信签名不能为空") + private String signature; + @Schema(description = "渠道编码,参见 SmsChannelEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "YUN_PIAN") private String code; + @Schema(description = "启用状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @NotNull(message = "启用状态不能为空") + private Integer status; + + @Schema(description = "备注", example = "好吃!") + private String remark; + + @Schema(description = "短信 API 的账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao") + @NotNull(message = "短信 API 的账号不能为空") + private String apiKey; + + @Schema(description = "短信 API 的密钥", example = "yuanma") + private String apiSecret; + + @Schema(description = "短信发送回调 URL", example = "https://www.iocoder.cn") + @URL(message = "回调 URL 格式不正确") + private String callbackUrl; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelSaveReqVO.java similarity index 74% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelBaseVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelSaveReqVO.java index 56f503998..47cde1ee2 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelSaveReqVO.java @@ -1,21 +1,26 @@ package cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel; + import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import org.hibernate.validator.constraints.URL; import javax.validation.constraints.NotNull; -/** -* 短信渠道 Base VO,提供给添加、修改、详细的子 VO 使用 -* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 -*/ +@Schema(description = "管理后台 - 短信渠道创建/修改 Request VO") @Data -public class SmsChannelBaseVO { +public class SmsChannelSaveReqVO { + + @Schema(description = "编号", example = "1024") + private Long id; @Schema(description = "短信签名", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码") @NotNull(message = "短信签名不能为空") private String signature; + @Schema(description = "渠道编码,参见 SmsChannelEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "YUN_PIAN") + @NotNull(message = "渠道编码不能为空") + private String code; + @Schema(description = "启用状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @NotNull(message = "启用状态不能为空") private Integer status; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelSimpleRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelSimpleRespVO.java index 560a39e91..350297ce3 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelSimpleRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelSimpleRespVO.java @@ -3,18 +3,14 @@ package cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import javax.validation.constraints.NotNull; - @Schema(description = "管理后台 - 短信渠道精简 Response VO") @Data public class SmsChannelSimpleRespVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "编号不能为空") private Long id; @Schema(description = "短信签名", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码") - @NotNull(message = "短信签名不能为空") private String signature; @Schema(description = "渠道编码,参见 SmsChannelEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "YUN_PIAN") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelUpdateReqVO.java deleted file mode 100644 index 594854705..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/channel/SmsChannelUpdateReqVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 短信渠道更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class SmsChannelUpdateReqVO extends SmsChannelBaseVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "编号不能为空") - private Long id; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/log/SmsLogExcelVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/log/SmsLogExcelVO.java deleted file mode 100644 index 3027a1213..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/log/SmsLogExcelVO.java +++ /dev/null @@ -1,94 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.sms.vo.log; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import cn.iocoder.yudao.framework.excel.core.convert.JsonConvert; -import cn.iocoder.yudao.module.system.enums.DictTypeConstants; -import com.alibaba.excel.annotation.ExcelProperty; -import lombok.Data; - -import java.time.LocalDateTime; -import java.util.Map; - -/** - * 短信日志 Excel VO - * - * @author 芋道源码 - */ -@Data -public class SmsLogExcelVO { - - @ExcelProperty("编号") - private Long id; - - @ExcelProperty("短信渠道编号") - private Long channelId; - - @ExcelProperty("短信渠道编码") - private String channelCode; - - @ExcelProperty("模板编号") - private Long templateId; - - @ExcelProperty("模板编码") - private String templateCode; - - @ExcelProperty(value = "短信类型", converter = DictConvert.class) - @DictFormat(DictTypeConstants.SMS_TEMPLATE_TYPE) - private Integer templateType; - - @ExcelProperty("短信内容") - private String templateContent; - - @ExcelProperty(value = "短信参数", converter = JsonConvert.class) - private Map templateParams; - - @ExcelProperty("短信 API 的模板编号") - private String apiTemplateId; - - @ExcelProperty("手机号") - private String mobile; - - @ExcelProperty("用户编号") - private Long userId; - - @ExcelProperty(value = "用户类型", converter = DictConvert.class) - @DictFormat(DictTypeConstants.USER_TYPE) - private Integer userType; - - @ExcelProperty(value = "发送状态", converter = DictConvert.class) - @DictFormat(DictTypeConstants.SMS_SEND_STATUS) - private Integer sendStatus; - - @ExcelProperty("发送时间") - private LocalDateTime sendTime; - - @ExcelProperty("短信 API 发送结果的编码") - private String apiSendCode; - - @ExcelProperty("短信 API 发送失败的提示") - private String apiSendMsg; - - @ExcelProperty("短信 API 发送返回的唯一请求 ID") - private String apiRequestId; - - @ExcelProperty("短信 API 发送返回的序号") - private String apiSerialNo; - - @ExcelProperty(value = "接收状态", converter = DictConvert.class) - @DictFormat(DictTypeConstants.SMS_RECEIVE_STATUS) - private Integer receiveStatus; - - @ExcelProperty("接收时间") - private LocalDateTime receiveTime; - - @ExcelProperty("API 接收结果的编码") - private String apiReceiveCode; - - @ExcelProperty("API 接收结果的说明") - private String apiReceiveMsg; - - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/log/SmsLogExportReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/log/SmsLogExportReqVO.java deleted file mode 100644 index a96aeb8ef..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/log/SmsLogExportReqVO.java +++ /dev/null @@ -1,38 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.sms.vo.log; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 短信日志 Excel 导出 Request VO,参数和 SmsLogPageReqVO 是一致的") -@Data -public class SmsLogExportReqVO { - - @Schema(description = "短信渠道编号", example = "10") - private Long channelId; - - @Schema(description = "模板编号", example = "20") - private Long templateId; - - @Schema(description = "手机号", example = "15601691300") - private String mobile; - - @Schema(description = "发送状态", example = "1") - private Integer sendStatus; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @Schema(description = "开始发送时间") - private LocalDateTime[] sendTime; - - @Schema(description = "接收状态", example = "0") - private Integer receiveStatus; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @Schema(description = "开始接收时间") - private LocalDateTime[] receiveTime; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/log/SmsLogRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/log/SmsLogRespVO.java index 71b4b39fa..77409ed91 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/log/SmsLogRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/log/SmsLogRespVO.java @@ -1,5 +1,11 @@ package cn.iocoder.yudao.module.system.controller.admin.sms.vo.log; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import cn.iocoder.yudao.framework.excel.core.convert.JsonConvert; +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -8,75 +14,103 @@ import java.util.Map; @Schema(description = "管理后台 - 短信日志 Response VO") @Data +@ExcelIgnoreUnannotated public class SmsLogRespVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("编号") private Long id; @Schema(description = "短信渠道编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") + @ExcelProperty("短信渠道编号") private Long channelId; @Schema(description = "短信渠道编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "ALIYUN") + @ExcelProperty("短信渠道编码") private String channelCode; @Schema(description = "模板编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20") + @ExcelProperty("模板编号") private Long templateId; @Schema(description = "模板编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "test-01") + @ExcelProperty("模板编码") private String templateCode; @Schema(description = "短信类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "短信类型", converter = DictConvert.class) + @DictFormat(DictTypeConstants.SMS_TEMPLATE_TYPE) private Integer templateType; @Schema(description = "短信内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "你好,你的验证码是 1024") + @ExcelProperty("短信内容") private String templateContent; @Schema(description = "短信参数", requiredMode = Schema.RequiredMode.REQUIRED, example = "name,code") + @ExcelProperty(value = "短信参数", converter = JsonConvert.class) private Map templateParams; @Schema(description = "短信 API 的模板编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "SMS_207945135") + @ExcelProperty("短信 API 的模板编号") private String apiTemplateId; @Schema(description = "手机号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15601691300") + @ExcelProperty("手机号") private String mobile; @Schema(description = "用户编号", example = "10") + @ExcelProperty("用户编号") private Long userId; @Schema(description = "用户类型", example = "1") + @ExcelProperty(value = "用户类型", converter = DictConvert.class) + @DictFormat(DictTypeConstants.USER_TYPE) private Integer userType; @Schema(description = "发送状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "发送状态", converter = DictConvert.class) + @DictFormat(DictTypeConstants.SMS_SEND_STATUS) private Integer sendStatus; @Schema(description = "发送时间") + @ExcelProperty("发送时间") private LocalDateTime sendTime; @Schema(description = "短信 API 发送结果的编码", example = "SUCCESS") + @ExcelProperty("短信 API 发送结果的编码") private String apiSendCode; @Schema(description = "短信 API 发送失败的提示", example = "成功") + @ExcelProperty("短信 API 发送失败的提示") private String apiSendMsg; @Schema(description = "短信 API 发送返回的唯一请求 ID", example = "3837C6D3-B96F-428C-BBB2-86135D4B5B99") + @ExcelProperty("短信 API 发送返回的唯一请求 ID") private String apiRequestId; @Schema(description = "短信 API 发送返回的序号", example = "62923244790") + @ExcelProperty("短信 API 发送返回的序号") private String apiSerialNo; @Schema(description = "接收状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") + @ExcelProperty(value = "接收状态", converter = DictConvert.class) + @DictFormat(DictTypeConstants.SMS_RECEIVE_STATUS) private Integer receiveStatus; @Schema(description = "接收时间") + @ExcelProperty("接收时间") private LocalDateTime receiveTime; @Schema(description = "API 接收结果的编码", example = "DELIVRD") + @ExcelProperty("API 接收结果的编码") private String apiReceiveCode; @Schema(description = "API 接收结果的说明", example = "用户接收成功") + @ExcelProperty("API 接收结果的说明") private String apiReceiveMsg; @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") private LocalDateTime createTime; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateCreateReqVO.java deleted file mode 100644 index 737a16a45..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateCreateReqVO.java +++ /dev/null @@ -1,13 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.sms.vo.template; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -@Schema(description = "管理后台 - 短信模板创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class SmsTemplateCreateReqVO extends SmsTemplateBaseVO { - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateExcelVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateExcelVO.java deleted file mode 100644 index f4f34bd1d..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateExcelVO.java +++ /dev/null @@ -1,55 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.sms.vo.template; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import cn.iocoder.yudao.module.system.enums.DictTypeConstants; -import com.alibaba.excel.annotation.ExcelProperty; -import lombok.Data; - -import java.time.LocalDateTime; - -/** - * 短信模板 Excel VO - * - * @author 芋道源码 - */ -@Data -public class SmsTemplateExcelVO { - - @ExcelProperty("编号") - private Long id; - - @ExcelProperty(value = "短信签名", converter = DictConvert.class) - @DictFormat(DictTypeConstants.SMS_TEMPLATE_TYPE) - private Integer type; - - @ExcelProperty(value = "开启状态", converter = DictConvert.class) - @DictFormat(DictTypeConstants.COMMON_STATUS) - private Integer status; - - @ExcelProperty("模板编码") - private String code; - - @ExcelProperty("模板名称") - private String name; - - @ExcelProperty("模板内容") - private String content; - - @ExcelProperty("备注") - private String remark; - - @ExcelProperty("短信 API 的模板编号") - private String apiTemplateId; - - @ExcelProperty("短信渠道编号") - private Long channelId; - - @ExcelProperty(value = "短信渠道编码", converter = DictConvert.class) - @DictFormat(DictTypeConstants.SMS_CHANNEL_CODE) - private String channelCode; - - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateExportReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateExportReqVO.java deleted file mode 100644 index 973a9a4e8..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateExportReqVO.java +++ /dev/null @@ -1,37 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.sms.vo.template; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 短信模板 Excel 导出 Request VO,参数和 SmsTemplatePageReqVO 是一致的") -@Data -public class SmsTemplateExportReqVO { - - @Schema(description = "短信签名", example = "1") - private Integer type; - - @Schema(description = "开启状态", example = "1") - private Integer status; - - @Schema(description = "模板编码,模糊匹配", example = "test_01") - private String code; - - @Schema(description = "模板内容,模糊匹配", example = "你好,{name}。你长的太{like}啦!") - private String content; - - @Schema(description = "短信 API 的模板编号,模糊匹配", example = "4383920") - private String apiTemplateId; - - @Schema(description = "短信渠道编号", example = "10") - private Long channelId; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @Schema(description = "创建时间") - private LocalDateTime[] createTime; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateRespVO.java index 3139d20dc..6b8aecaaa 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateRespVO.java @@ -1,29 +1,69 @@ package cn.iocoder.yudao.module.system.controller.admin.sms.vo.template; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; import java.time.LocalDateTime; import java.util.List; @Schema(description = "管理后台 - 短信模板 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class SmsTemplateRespVO extends SmsTemplateBaseVO { +@ExcelIgnoreUnannotated +public class SmsTemplateRespVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("编号") private Long id; - @Schema(description = "短信渠道编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "ALIYUN") - private String channelCode; + @Schema(description = "短信类型,参见 SmsTemplateTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "短信签名", converter = DictConvert.class) + @DictFormat(DictTypeConstants.SMS_TEMPLATE_TYPE) + private Integer type; + + @Schema(description = "开启状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "开启状态", converter = DictConvert.class) + @DictFormat(DictTypeConstants.COMMON_STATUS) + private Integer status; + + @Schema(description = "模板编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "test_01") + @ExcelProperty("模板编码") + private String code; + + @Schema(description = "模板名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao") + @ExcelProperty("模板名称") + private String name; + + @Schema(description = "模板内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "你好,{name}。你长的太{like}啦!") + @ExcelProperty("模板内容") + private String content; @Schema(description = "参数数组", example = "name,code") private List params; + @Schema(description = "备注", example = "哈哈哈") + @ExcelProperty("备注") + private String remark; + + @Schema(description = "短信 API 的模板编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "4383920") + @ExcelProperty("短信 API 的模板编号") + private String apiTemplateId; + + @Schema(description = "短信渠道编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") + @ExcelProperty("短信渠道编号") + private Long channelId; + + @Schema(description = "短信渠道编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "ALIYUN") + @ExcelProperty(value = "短信渠道编码", converter = DictConvert.class) + @DictFormat(DictTypeConstants.SMS_CHANNEL_CODE) + private String channelCode; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") private LocalDateTime createTime; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateSaveReqVO.java similarity index 89% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateBaseVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateSaveReqVO.java index d5bc304e5..7199bf39c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateSaveReqVO.java @@ -1,15 +1,16 @@ package cn.iocoder.yudao.module.system.controller.admin.sms.vo.template; + import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import javax.validation.constraints.NotNull; -/** -* 短信模板 Base VO,提供给添加、修改、详细的子 VO 使用 -* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 -*/ +@Schema(description = "管理后台 - 短信模板创建/修改 Request VO") @Data -public class SmsTemplateBaseVO { +public class SmsTemplateSaveReqVO { + + @Schema(description = "编号", example = "1024") + private Long id; @Schema(description = "短信类型,参见 SmsTemplateTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @NotNull(message = "短信类型不能为空") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateUpdateReqVO.java deleted file mode 100644 index d347f6950..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/template/SmsTemplateUpdateReqVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.sms.vo.template; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 短信模板更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class SmsTemplateUpdateReqVO extends SmsTemplateBaseVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "编号不能为空") - private Long id; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/sms/SmsChannelConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/sms/SmsChannelConvert.java deleted file mode 100644 index 10252c870..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/sms/SmsChannelConvert.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.sms; - -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelRespVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelSimpleRespVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelUpdateReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.sms.core.property.SmsChannelProperties; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -/** - * 短信渠道 Convert - * - * @author 芋道源码 - */ -@Mapper -public interface SmsChannelConvert { - - SmsChannelConvert INSTANCE = Mappers.getMapper(SmsChannelConvert.class); - - SmsChannelDO convert(SmsChannelCreateReqVO bean); - - SmsChannelDO convert(SmsChannelUpdateReqVO bean); - - SmsChannelRespVO convert(SmsChannelDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); - - List convertList03(List list); - - SmsChannelProperties convert02(SmsChannelDO channel); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/sms/SmsLogConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/sms/SmsLogConvert.java deleted file mode 100644 index 40efe60a1..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/sms/SmsLogConvert.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.sms; - -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.log.SmsLogExcelVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.log.SmsLogRespVO; -import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsLogDO; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -/** - * 短信日志 Convert - * - * @author 芋道源码 - */ -@Mapper -public interface SmsLogConvert { - - SmsLogConvert INSTANCE = Mappers.getMapper(SmsLogConvert.class); - - SmsLogRespVO convert(SmsLogDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); - - List convertList02(List list); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/sms/SmsTemplateConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/sms/SmsTemplateConvert.java deleted file mode 100644 index b0fb02b8f..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/sms/SmsTemplateConvert.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.sms; - -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateExcelVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateRespVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateUpdateReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper -public interface SmsTemplateConvert { - - SmsTemplateConvert INSTANCE = Mappers.getMapper(SmsTemplateConvert.class); - - SmsTemplateDO convert(SmsTemplateCreateReqVO bean); - - SmsTemplateDO convert(SmsTemplateUpdateReqVO bean); - - SmsTemplateRespVO convert(SmsTemplateDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); - - List convertList02(List list); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsLogMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsLogMapper.java index 8ebd34fcf..f2388711a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsLogMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsLogMapper.java @@ -3,13 +3,10 @@ package cn.iocoder.yudao.module.system.dal.mysql.sms; 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.sms.vo.log.SmsLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.sms.vo.log.SmsLogPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsLogDO; import org.apache.ibatis.annotations.Mapper; -import java.util.List; - @Mapper public interface SmsLogMapper extends BaseMapperX { @@ -25,16 +22,4 @@ public interface SmsLogMapper extends BaseMapperX { .orderByDesc(SmsLogDO::getId)); } - default List selectList(SmsLogExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .eqIfPresent(SmsLogDO::getChannelId, reqVO.getChannelId()) - .eqIfPresent(SmsLogDO::getTemplateId, reqVO.getTemplateId()) - .likeIfPresent(SmsLogDO::getMobile, reqVO.getMobile()) - .eqIfPresent(SmsLogDO::getSendStatus, reqVO.getSendStatus()) - .betweenIfPresent(SmsLogDO::getSendTime, reqVO.getSendTime()) - .eqIfPresent(SmsLogDO::getReceiveStatus, reqVO.getReceiveStatus()) - .betweenIfPresent(SmsLogDO::getReceiveTime, reqVO.getReceiveTime()) - .orderByDesc(SmsLogDO::getId)); - } - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsTemplateMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsTemplateMapper.java index ee6f54fef..a9a1ebb99 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsTemplateMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsTemplateMapper.java @@ -3,13 +3,10 @@ package cn.iocoder.yudao.module.system.dal.mysql.sms; 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.sms.vo.template.SmsTemplateExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplatePageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import org.apache.ibatis.annotations.Mapper; -import java.util.List; - @Mapper public interface SmsTemplateMapper extends BaseMapperX { @@ -29,18 +26,6 @@ public interface SmsTemplateMapper extends BaseMapperX { .orderByDesc(SmsTemplateDO::getId)); } - default List selectList(SmsTemplateExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .eqIfPresent(SmsTemplateDO::getType, reqVO.getType()) - .eqIfPresent(SmsTemplateDO::getStatus, reqVO.getStatus()) - .likeIfPresent(SmsTemplateDO::getCode, reqVO.getCode()) - .likeIfPresent(SmsTemplateDO::getContent, reqVO.getContent()) - .likeIfPresent(SmsTemplateDO::getApiTemplateId, reqVO.getApiTemplateId()) - .eqIfPresent(SmsTemplateDO::getChannelId, reqVO.getChannelId()) - .betweenIfPresent(SmsTemplateDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(SmsTemplateDO::getId)); - } - default Long selectCountByChannelId(Long channelId) { return selectCount(SmsTemplateDO::getChannelId, channelId); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelService.java index 34540d6ed..c820630da 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelService.java @@ -2,9 +2,8 @@ package cn.iocoder.yudao.module.system.service.sms; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.sms.core.client.SmsClient; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; import javax.validation.Valid; @@ -24,14 +23,14 @@ public interface SmsChannelService { * @param createReqVO 创建信息 * @return 编号 */ - Long createSmsChannel(@Valid SmsChannelCreateReqVO createReqVO); + Long createSmsChannel(@Valid SmsChannelSaveReqVO createReqVO); /** * 更新短信渠道 * * @param updateReqVO 更新信息 */ - void updateSmsChannel(@Valid SmsChannelUpdateReqVO updateReqVO); + void updateSmsChannel(@Valid SmsChannelSaveReqVO updateReqVO); /** * 删除短信渠道 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceImpl.java index 1c6670547..0187bbee9 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceImpl.java @@ -2,13 +2,12 @@ package cn.iocoder.yudao.module.system.service.sms; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.sms.core.client.SmsClient; import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; import cn.iocoder.yudao.framework.sms.core.property.SmsChannelProperties; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.sms.SmsChannelConvert; +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; import cn.iocoder.yudao.module.system.dal.mysql.sms.SmsChannelMapper; import com.google.common.cache.CacheLoader; @@ -47,7 +46,7 @@ public class SmsChannelServiceImpl implements SmsChannelService { // 查询,然后尝试刷新 SmsChannelDO channel = smsChannelMapper.selectById(id); if (channel != null) { - SmsChannelProperties properties = SmsChannelConvert.INSTANCE.convert02(channel); + SmsChannelProperties properties = BeanUtils.toBean(channel, SmsChannelProperties.class); smsClientFactory.createOrUpdateSmsClient(properties); } return smsClientFactory.getSmsClient(id); @@ -67,7 +66,7 @@ public class SmsChannelServiceImpl implements SmsChannelService { // 查询,然后尝试刷新 SmsChannelDO channel = smsChannelMapper.selectByCode(code); if (channel != null) { - SmsChannelProperties properties = SmsChannelConvert.INSTANCE.convert02(channel); + SmsChannelProperties properties = BeanUtils.toBean(channel, SmsChannelProperties.class); smsClientFactory.createOrUpdateSmsClient(properties); } return smsClientFactory.getSmsClient(code); @@ -85,18 +84,18 @@ public class SmsChannelServiceImpl implements SmsChannelService { private SmsTemplateService smsTemplateService; @Override - public Long createSmsChannel(SmsChannelCreateReqVO createReqVO) { - SmsChannelDO channel = SmsChannelConvert.INSTANCE.convert(createReqVO); + public Long createSmsChannel(SmsChannelSaveReqVO createReqVO) { + SmsChannelDO channel = BeanUtils.toBean(createReqVO, SmsChannelDO.class); smsChannelMapper.insert(channel); return channel.getId(); } @Override - public void updateSmsChannel(SmsChannelUpdateReqVO updateReqVO) { + public void updateSmsChannel(SmsChannelSaveReqVO updateReqVO) { // 校验存在 SmsChannelDO channel = validateSmsChannelExists(updateReqVO.getId()); // 更新 - SmsChannelDO updateObj = SmsChannelConvert.INSTANCE.convert(updateReqVO); + SmsChannelDO updateObj = BeanUtils.toBean(updateReqVO, SmsChannelDO.class); smsChannelMapper.updateById(updateObj); // 清空缓存 @@ -108,7 +107,7 @@ public class SmsChannelServiceImpl implements SmsChannelService { // 校验存在 SmsChannelDO channel = validateSmsChannelExists(id); // 校验是否有在使用该账号的模版 - if (smsTemplateService.countByChannelId(id) > 0) { + if (smsTemplateService.getSmsTemplateCountByChannelId(id) > 0) { throw exception(SMS_CHANNEL_HAS_CHILDREN); } // 删除 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsLogService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsLogService.java index a9a147b7a..0c86c0f07 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsLogService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsLogService.java @@ -1,13 +1,11 @@ package cn.iocoder.yudao.module.system.service.sms; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.log.SmsLogExportReqVO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.sms.vo.log.SmsLogPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsLogDO; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import java.time.LocalDateTime; -import java.util.List; import java.util.Map; /** @@ -67,12 +65,4 @@ public interface SmsLogService { */ PageResult getSmsLogPage(SmsLogPageReqVO pageReqVO); - /** - * 获得短信日志列表, 用于 Excel 导出 - * - * @param exportReqVO 查询条件 - * @return 短信日志列表 - */ - List getSmsLogList(SmsLogExportReqVO exportReqVO); - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsLogServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsLogServiceImpl.java index 150526b2f..c79b94123 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsLogServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsLogServiceImpl.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.system.service.sms; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.log.SmsLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.sms.vo.log.SmsLogPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsLogDO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; @@ -13,7 +12,6 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.time.LocalDateTime; -import java.util.List; import java.util.Map; import java.util.Objects; @@ -78,9 +76,4 @@ public class SmsLogServiceImpl implements SmsLogService { return smsLogMapper.selectPage(pageReqVO); } - @Override - public List getSmsLogList(SmsLogExportReqVO exportReqVO) { - return smsLogMapper.selectList(exportReqVO); - } - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateService.java index f3f886f55..9d6ac3a1e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateService.java @@ -1,14 +1,11 @@ package cn.iocoder.yudao.module.system.service.sms; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateExportReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplatePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateUpdateReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplatePageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateSaveReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import javax.validation.Valid; -import java.util.List; import java.util.Map; /** @@ -25,14 +22,14 @@ public interface SmsTemplateService { * @param createReqVO 创建信息 * @return 编号 */ - Long createSmsTemplate(@Valid SmsTemplateCreateReqVO createReqVO); + Long createSmsTemplate(@Valid SmsTemplateSaveReqVO createReqVO); /** * 更新短信模板 * * @param updateReqVO 更新信息 */ - void updateSmsTemplate(@Valid SmsTemplateUpdateReqVO updateReqVO); + void updateSmsTemplate(@Valid SmsTemplateSaveReqVO updateReqVO); /** * 删除短信模板 @@ -65,22 +62,13 @@ public interface SmsTemplateService { */ PageResult getSmsTemplatePage(SmsTemplatePageReqVO pageReqVO); - /** - * 获得短信模板列表, 用于 Excel 导出 - * - * @param exportReqVO 查询条件 - * @return 短信模板分页 - */ - List getSmsTemplateList(SmsTemplateExportReqVO exportReqVO); - /** * 获得指定短信渠道下的短信模板数量 * * @param channelId 短信渠道编号 * @return 数量 */ - Long countByChannelId(Long channelId); - + Long getSmsTemplateCountByChannelId(Long channelId); /** * 格式化短信内容 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImpl.java index 876d09556..219710f27 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImpl.java @@ -6,14 +6,12 @@ import cn.hutool.core.util.ReUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.sms.core.client.SmsClient; import cn.iocoder.yudao.framework.sms.core.client.dto.SmsTemplateRespDTO; import cn.iocoder.yudao.framework.sms.core.enums.SmsTemplateAuditStatusEnum; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplatePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.sms.SmsTemplateConvert; +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.sms.SmsTemplateMapper; @@ -55,7 +53,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { private SmsChannelService smsChannelService; @Override - public Long createSmsTemplate(SmsTemplateCreateReqVO createReqVO) { + public Long createSmsTemplate(SmsTemplateSaveReqVO createReqVO) { // 校验短信渠道 SmsChannelDO channelDO = validateSmsChannel(createReqVO.getChannelId()); // 校验短信编码是否重复 @@ -64,7 +62,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { validateApiTemplate(createReqVO.getChannelId(), createReqVO.getApiTemplateId()); // 插入 - SmsTemplateDO template = SmsTemplateConvert.INSTANCE.convert(createReqVO); + SmsTemplateDO template = BeanUtils.toBean(createReqVO, SmsTemplateDO.class); template.setParams(parseTemplateContentParams(template.getContent())); template.setChannelCode(channelDO.getCode()); smsTemplateMapper.insert(template); @@ -75,7 +73,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { @Override @CacheEvict(cacheNames = RedisKeyConstants.SMS_TEMPLATE, allEntries = true) // allEntries 清空所有缓存,因为可能修改到 code 字段,不好清理 - public void updateSmsTemplate(SmsTemplateUpdateReqVO updateReqVO) { + public void updateSmsTemplate(SmsTemplateSaveReqVO updateReqVO) { // 校验存在 validateSmsTemplateExists(updateReqVO.getId()); // 校验短信渠道 @@ -86,7 +84,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { validateApiTemplate(updateReqVO.getChannelId(), updateReqVO.getApiTemplateId()); // 更新 - SmsTemplateDO updateObj = SmsTemplateConvert.INSTANCE.convert(updateReqVO); + SmsTemplateDO updateObj = BeanUtils.toBean(updateReqVO, SmsTemplateDO.class); updateObj.setParams(parseTemplateContentParams(updateObj.getContent())); updateObj.setChannelCode(channelDO.getCode()); smsTemplateMapper.updateById(updateObj); @@ -126,12 +124,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { } @Override - public List getSmsTemplateList(SmsTemplateExportReqVO exportReqVO) { - return smsTemplateMapper.selectList(exportReqVO); - } - - @Override - public Long countByChannelId(Long channelId) { + public Long getSmsTemplateCountByChannelId(Long channelId) { return smsTemplateMapper.selectCountByChannelId(channelId); } diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceTest.java index 62f26e8ba..551f39f04 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceTest.java @@ -2,14 +2,13 @@ package cn.iocoder.yudao.module.system.service.sms; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.sms.core.client.SmsClient; import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; import cn.iocoder.yudao.framework.sms.core.property.SmsChannelProperties; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.sms.SmsChannelConvert; +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; import cn.iocoder.yudao.module.system.dal.mysql.sms.SmsChannelMapper; import org.junit.jupiter.api.Test; @@ -48,7 +47,8 @@ public class SmsChannelServiceTest extends BaseDbUnitTest { @Test public void testCreateSmsChannel_success() { // 准备参数 - SmsChannelCreateReqVO reqVO = randomPojo(SmsChannelCreateReqVO.class, o -> o.setStatus(randomCommonStatus())); + SmsChannelSaveReqVO reqVO = randomPojo(SmsChannelSaveReqVO.class, o -> o.setStatus(randomCommonStatus())) + .setId(null); // 防止 id 被赋值 // 调用 Long smsChannelId = smsChannelService.createSmsChannel(reqVO); @@ -56,7 +56,7 @@ public class SmsChannelServiceTest extends BaseDbUnitTest { assertNotNull(smsChannelId); // 校验记录的属性是否正确 SmsChannelDO smsChannel = smsChannelMapper.selectById(smsChannelId); - assertPojoEquals(reqVO, smsChannel); + assertPojoEquals(reqVO, smsChannel, "id"); // 断言 cache assertNull(smsChannelService.getIdClientCache().getIfPresent(smsChannel.getId())); assertNull(smsChannelService.getCodeClientCache().getIfPresent(smsChannel.getCode())); @@ -68,7 +68,7 @@ public class SmsChannelServiceTest extends BaseDbUnitTest { SmsChannelDO dbSmsChannel = randomPojo(SmsChannelDO.class); smsChannelMapper.insert(dbSmsChannel);// @Sql: 先插入出一条存在的数据 // 准备参数 - SmsChannelUpdateReqVO reqVO = randomPojo(SmsChannelUpdateReqVO.class, o -> { + SmsChannelSaveReqVO reqVO = randomPojo(SmsChannelSaveReqVO.class, o -> { o.setId(dbSmsChannel.getId()); // 设置更新的 ID o.setStatus(randomCommonStatus()); o.setCallbackUrl(randomString()); @@ -87,7 +87,7 @@ public class SmsChannelServiceTest extends BaseDbUnitTest { @Test public void testUpdateSmsChannel_notExists() { // 准备参数 - SmsChannelUpdateReqVO reqVO = randomPojo(SmsChannelUpdateReqVO.class); + SmsChannelSaveReqVO reqVO = randomPojo(SmsChannelSaveReqVO.class); // 调用, 并断言异常 assertServiceException(() -> smsChannelService.updateSmsChannel(reqVO), SMS_CHANNEL_NOT_EXISTS); @@ -127,7 +127,7 @@ public class SmsChannelServiceTest extends BaseDbUnitTest { // 准备参数 Long id = dbSmsChannel.getId(); // mock 方法 - when(smsTemplateService.countByChannelId(eq(id))).thenReturn(10L); + when(smsTemplateService.getSmsTemplateCountByChannelId(eq(id))).thenReturn(10L); // 调用, 并断言异常 assertServiceException(() -> smsChannelService.deleteSmsChannel(id), SMS_CHANNEL_HAS_CHILDREN); @@ -207,7 +207,7 @@ public class SmsChannelServiceTest extends BaseDbUnitTest { // 断言 assertSame(client, mockClient); verify(smsClientFactory).createOrUpdateSmsClient(argThat(arg -> { - SmsChannelProperties properties = SmsChannelConvert.INSTANCE.convert02(channel); + SmsChannelProperties properties = BeanUtils.toBean(channel, SmsChannelProperties.class); return properties.equals(arg); })); } @@ -228,7 +228,7 @@ public class SmsChannelServiceTest extends BaseDbUnitTest { // 断言 assertSame(client, mockClient); verify(smsClientFactory).createOrUpdateSmsClient(argThat(arg -> { - SmsChannelProperties properties = SmsChannelConvert.INSTANCE.convert02(channel); + SmsChannelProperties properties = BeanUtils.toBean(channel, SmsChannelProperties.class); return properties.equals(arg); })); } diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsLogServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsLogServiceImplTest.java index 1535f2c23..eed34b988 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsLogServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsLogServiceImplTest.java @@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.log.SmsLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.sms.vo.log.SmsLogPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsLogDO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; @@ -18,7 +17,6 @@ import org.springframework.context.annotation.Import; import javax.annotation.Resource; import java.time.LocalDateTime; -import java.util.List; import java.util.Map; import java.util.function.Consumer; @@ -86,50 +84,6 @@ public class SmsLogServiceImplTest extends BaseDbUnitTest { assertPojoEquals(dbSmsLog, pageResult.getList().get(0)); } - @Test - public void testGetSmsLogList() { - // mock 数据 - SmsLogDO dbSmsLog = randomSmsLogDO(o -> { // 等会查询到 - o.setChannelId(1L); - o.setTemplateId(10L); - o.setMobile("15601691300"); - o.setSendStatus(SmsSendStatusEnum.INIT.getStatus()); - o.setSendTime(buildTime(2020, 11, 11)); - o.setReceiveStatus(SmsReceiveStatusEnum.INIT.getStatus()); - o.setReceiveTime(buildTime(2021, 11, 11)); - }); - smsLogMapper.insert(dbSmsLog); - // 测试 channelId 不匹配 - smsLogMapper.insert(cloneIgnoreId(dbSmsLog, o -> o.setChannelId(2L))); - // 测试 templateId 不匹配 - smsLogMapper.insert(cloneIgnoreId(dbSmsLog, o -> o.setTemplateId(20L))); - // 测试 mobile 不匹配 - smsLogMapper.insert(cloneIgnoreId(dbSmsLog, o -> o.setMobile("18818260999"))); - // 测试 sendStatus 不匹配 - smsLogMapper.insert(cloneIgnoreId(dbSmsLog, o -> o.setSendStatus(SmsSendStatusEnum.IGNORE.getStatus()))); - // 测试 sendTime 不匹配 - smsLogMapper.insert(cloneIgnoreId(dbSmsLog, o -> o.setSendTime(buildTime(2020, 12, 12)))); - // 测试 receiveStatus 不匹配 - smsLogMapper.insert(cloneIgnoreId(dbSmsLog, o -> o.setReceiveStatus(SmsReceiveStatusEnum.SUCCESS.getStatus()))); - // 测试 receiveTime 不匹配 - smsLogMapper.insert(cloneIgnoreId(dbSmsLog, o -> o.setReceiveTime(buildTime(2021, 12, 12)))); - // 准备参数 - SmsLogExportReqVO reqVO = new SmsLogExportReqVO(); - reqVO.setChannelId(1L); - reqVO.setTemplateId(10L); - reqVO.setMobile("156"); - reqVO.setSendStatus(SmsSendStatusEnum.INIT.getStatus()); - reqVO.setSendTime(buildBetweenTime(2020, 11, 1, 2020, 11, 30)); - reqVO.setReceiveStatus(SmsReceiveStatusEnum.INIT.getStatus()); - reqVO.setReceiveTime(buildBetweenTime(2021, 11, 1, 2021, 11, 30)); - - // 调用 - List list = smsLogService.getSmsLogList(reqVO); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbSmsLog, list.get(0)); - } - @Test public void testCreateSmsLog() { // 准备参数 diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImplTest.java index b5d538d48..ecd894719 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImplTest.java @@ -8,10 +8,8 @@ import cn.iocoder.yudao.framework.sms.core.client.SmsClient; import cn.iocoder.yudao.framework.sms.core.client.dto.SmsTemplateRespDTO; import cn.iocoder.yudao.framework.sms.core.enums.SmsTemplateAuditStatusEnum; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateExportReqVO; +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateSaveReqVO; import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplatePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateUpdateReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.sms.SmsTemplateMapper; @@ -66,11 +64,11 @@ public class SmsTemplateServiceImplTest extends BaseDbUnitTest { @SuppressWarnings("unchecked") public void testCreateSmsTemplate_success() throws Throwable { // 准备参数 - SmsTemplateCreateReqVO reqVO = randomPojo(SmsTemplateCreateReqVO.class, o -> { + SmsTemplateSaveReqVO reqVO = randomPojo(SmsTemplateSaveReqVO.class, o -> { o.setContent("正在进行登录操作{operation},您的验证码是{code}"); o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); // 保证 status 的范围 o.setType(randomEle(SmsTemplateTypeEnum.values()).getType()); // 保证 type 的 范围 - }); + }).setId(null); // 防止 id 被赋值 // mock Channel 的方法 SmsChannelDO channelDO = randomPojo(SmsChannelDO.class, o -> { o.setId(reqVO.getChannelId()); @@ -88,7 +86,7 @@ public class SmsTemplateServiceImplTest extends BaseDbUnitTest { assertNotNull(smsTemplateId); // 校验记录的属性是否正确 SmsTemplateDO smsTemplate = smsTemplateMapper.selectById(smsTemplateId); - assertPojoEquals(reqVO, smsTemplate); + assertPojoEquals(reqVO, smsTemplate, "id"); assertEquals(Lists.newArrayList("operation", "code"), smsTemplate.getParams()); assertEquals(channelDO.getCode(), smsTemplate.getChannelCode()); } @@ -100,7 +98,7 @@ public class SmsTemplateServiceImplTest extends BaseDbUnitTest { SmsTemplateDO dbSmsTemplate = randomSmsTemplateDO(); smsTemplateMapper.insert(dbSmsTemplate);// @Sql: 先插入出一条存在的数据 // 准备参数 - SmsTemplateUpdateReqVO reqVO = randomPojo(SmsTemplateUpdateReqVO.class, o -> { + SmsTemplateSaveReqVO reqVO = randomPojo(SmsTemplateSaveReqVO.class, o -> { o.setId(dbSmsTemplate.getId()); // 设置更新的 ID o.setContent("正在进行登录操作{operation},您的验证码是{code}"); o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); // 保证 status 的范围 @@ -129,7 +127,7 @@ public class SmsTemplateServiceImplTest extends BaseDbUnitTest { @Test public void testUpdateSmsTemplate_notExists() { // 准备参数 - SmsTemplateUpdateReqVO reqVO = randomPojo(SmsTemplateUpdateReqVO.class); + SmsTemplateSaveReqVO reqVO = randomPojo(SmsTemplateSaveReqVO.class); // 调用, 并断言异常 assertServiceException(() -> smsTemplateService.updateSmsTemplate(reqVO), SMS_TEMPLATE_NOT_EXISTS); @@ -203,50 +201,6 @@ public class SmsTemplateServiceImplTest extends BaseDbUnitTest { assertPojoEquals(dbSmsTemplate, pageResult.getList().get(0)); } - @Test - public void testGetSmsTemplateList() { - // mock 数据 - SmsTemplateDO dbSmsTemplate = randomPojo(SmsTemplateDO.class, o -> { // 等会查询到 - o.setType(SmsTemplateTypeEnum.PROMOTION.getType()); - o.setStatus(CommonStatusEnum.ENABLE.getStatus()); - o.setCode("tudou"); - o.setContent("芋道源码"); - o.setApiTemplateId("yunai"); - o.setChannelId(1L); - o.setCreateTime(buildTime(2021, 11, 11)); - }); - smsTemplateMapper.insert(dbSmsTemplate); - // 测试 type 不匹配 - smsTemplateMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsTemplate, o -> o.setType(SmsTemplateTypeEnum.VERIFICATION_CODE.getType()))); - // 测试 status 不匹配 - smsTemplateMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsTemplate, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); - // 测试 code 不匹配 - smsTemplateMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsTemplate, o -> o.setCode("yuanma"))); - // 测试 content 不匹配 - smsTemplateMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsTemplate, o -> o.setContent("源码"))); - // 测试 apiTemplateId 不匹配 - smsTemplateMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsTemplate, o -> o.setApiTemplateId("nai"))); - // 测试 channelId 不匹配 - smsTemplateMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsTemplate, o -> o.setChannelId(2L))); - // 测试 createTime 不匹配 - smsTemplateMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsTemplate, o -> o.setCreateTime(buildTime(2021, 12, 12)))); - // 准备参数 - SmsTemplateExportReqVO reqVO = new SmsTemplateExportReqVO(); - reqVO.setType(SmsTemplateTypeEnum.PROMOTION.getType()); - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); - reqVO.setCode("tu"); - reqVO.setContent("芋道"); - reqVO.setApiTemplateId("yu"); - reqVO.setChannelId(1L); - reqVO.setCreateTime(buildBetweenTime(2021, 11, 1, 2021, 12, 1)); - - // 调用 - List list = smsTemplateService.getSmsTemplateList(reqVO); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbSmsTemplate, list.get(0)); - } - @Test public void testValidateSmsChannel_success() { // 准备参数 From 5bb8fdca7ef8a9d9303a58e7d40a822e446ff59b Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 2 Dec 2023 23:01:15 +0800 Subject: [PATCH 12/19] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20socia?= =?UTF-8?q?l=20=E6=A8=A1=E5=9D=97=E7=9A=84=20VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/social/SocialClientApiImpl.java | 6 +-- .../admin/socail/SocialClientController.java | 15 +++---- .../admin/socail/SocialUserController.java | 12 ++--- .../vo/client/SocialClientCreateReqVO.java | 14 ------ .../socail/vo/client/SocialClientRespVO.java | 27 ++++++++--- ...BaseVO.java => SocialClientSaveReqVO.java} | 20 ++++----- .../vo/client/SocialClientUpdateReqVO.java | 20 --------- .../socail/vo/user/SocialUserBaseVO.java | 45 ------------------- .../vo/{ => user}/SocialUserBindReqVO.java | 2 +- .../socail/vo/user/SocialUserRespVO.java | 33 +++++++++++--- .../vo/{ => user}/SocialUserUnbindReqVO.java | 2 +- .../convert/social/SocialClientConvert.java | 38 ---------------- .../convert/social/SocialUserConvert.java | 19 +------- .../dal/mysql/social/SocialClientMapper.java | 2 +- .../service/social/SocialClientService.java | 7 ++- .../social/SocialClientServiceImpl.java | 18 ++++---- .../social/SocialClientServiceImplTest.java | 12 ++--- 17 files changed, 97 insertions(+), 195 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientCreateReqVO.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/{SocialClientBaseVO.java => SocialClientSaveReqVO.java} (80%) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientUpdateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserBaseVO.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/{ => user}/SocialUserBindReqVO.java (99%) rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/{ => user}/SocialUserUnbindReqVO.java (99%) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/social/SocialClientConvert.java diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApiImpl.java index 6f83530e4..e05251f61 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApiImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApiImpl.java @@ -1,9 +1,9 @@ package cn.iocoder.yudao.module.system.api.social; import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO; import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO; -import cn.iocoder.yudao.module.system.convert.social.SocialClientConvert; import cn.iocoder.yudao.module.system.service.social.SocialClientService; import me.chanjar.weixin.common.bean.WxJsapiSignature; import org.springframework.stereotype.Service; @@ -31,13 +31,13 @@ public class SocialClientApiImpl implements SocialClientApi { @Override public SocialWxJsapiSignatureRespDTO createWxMpJsapiSignature(Integer userType, String url) { WxJsapiSignature signature = socialClientService.createWxMpJsapiSignature(userType, url); - return SocialClientConvert.INSTANCE.convert(signature); + return BeanUtils.toBean(signature, SocialWxJsapiSignatureRespDTO.class); } @Override public SocialWxPhoneNumberInfoRespDTO getWxMaPhoneNumberInfo(Integer userType, String phoneCode) { WxMaPhoneNumberInfo info = socialClientService.getWxMaPhoneNumberInfo(userType, phoneCode); - return SocialClientConvert.INSTANCE.convert(info); + return BeanUtils.toBean(info, SocialWxPhoneNumberInfoRespDTO.class); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialClientController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialClientController.java index 893523630..c9b5f4da7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialClientController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialClientController.java @@ -2,11 +2,10 @@ package cn.iocoder.yudao.module.system.controller.admin.socail; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientCreateReqVO; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientRespVO; -import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.social.SocialClientConvert; +import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO; import cn.iocoder.yudao.module.system.service.social.SocialClientService; import io.swagger.v3.oas.annotations.Operation; @@ -33,14 +32,14 @@ public class SocialClientController { @PostMapping("/create") @Operation(summary = "创建社交客户端") @PreAuthorize("@ss.hasPermission('system:social-client:create')") - public CommonResult createSocialClient(@Valid @RequestBody SocialClientCreateReqVO createReqVO) { + public CommonResult createSocialClient(@Valid @RequestBody SocialClientSaveReqVO createReqVO) { return success(socialClientService.createSocialClient(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新社交客户端") @PreAuthorize("@ss.hasPermission('system:social-client:update')") - public CommonResult updateSocialClient(@Valid @RequestBody SocialClientUpdateReqVO updateReqVO) { + public CommonResult updateSocialClient(@Valid @RequestBody SocialClientSaveReqVO updateReqVO) { socialClientService.updateSocialClient(updateReqVO); return success(true); } @@ -59,8 +58,8 @@ public class SocialClientController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('system:social-client:query')") public CommonResult getSocialClient(@RequestParam("id") Long id) { - SocialClientDO socialClient = socialClientService.getSocialClient(id); - return success(SocialClientConvert.INSTANCE.convert(socialClient)); + SocialClientDO client = socialClientService.getSocialClient(id); + return success(BeanUtils.toBean(client, SocialClientRespVO.class)); } @GetMapping("/page") @@ -68,7 +67,7 @@ public class SocialClientController { @PreAuthorize("@ss.hasPermission('system:social-client:query')") public CommonResult> getSocialClientPage(@Valid SocialClientPageReqVO pageVO) { PageResult pageResult = socialClientService.getSocialClientPage(pageVO); - return success(SocialClientConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, SocialClientRespVO.class)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialUserController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialUserController.java index 08b45147e..eb2792e6d 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialUserController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialUserController.java @@ -3,8 +3,9 @@ package cn.iocoder.yudao.module.system.controller.admin.socail; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserBindReqVO; -import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserUnbindReqVO; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserBindReqVO; +import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserUnbindReqVO; import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserRespVO; import cn.iocoder.yudao.module.system.convert.social.SocialUserConvert; @@ -35,7 +36,8 @@ public class SocialUserController { @PostMapping("/bind") @Operation(summary = "社交绑定,使用 code 授权码") public CommonResult socialBind(@RequestBody @Valid SocialUserBindReqVO reqVO) { - socialUserService.bindSocialUser(SocialUserConvert.INSTANCE.convert(getLoginUserId(), UserTypeEnum.ADMIN.getValue(), reqVO)); + socialUserService.bindSocialUser(SocialUserConvert.INSTANCE.convert( + getLoginUserId(), UserTypeEnum.ADMIN.getValue(), reqVO)); return CommonResult.success(true); } @@ -54,7 +56,7 @@ public class SocialUserController { @PreAuthorize("@ss.hasPermission('system:social-user:query')") public CommonResult getSocialUser(@RequestParam("id") Long id) { SocialUserDO socialUser = socialUserService.getSocialUser(id); - return success(SocialUserConvert.INSTANCE.convert(socialUser)); + return success(BeanUtils.toBean(socialUser, SocialUserRespVO.class)); } @GetMapping("/page") @@ -62,7 +64,7 @@ public class SocialUserController { @PreAuthorize("@ss.hasPermission('system:social-user:query')") public CommonResult> getSocialUserPage(@Valid SocialUserPageReqVO pageVO) { PageResult pageResult = socialUserService.getSocialUserPage(pageVO); - return success(SocialUserConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, SocialUserRespVO.class)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientCreateReqVO.java deleted file mode 100644 index 8bd98c41d..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientCreateReqVO.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.socail.vo.client; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -@Schema(description = "管理后台 - 社交客户端创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class SocialClientCreateReqVO extends SocialClientBaseVO { - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientRespVO.java index 4512a67b5..900f363d1 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientRespVO.java @@ -2,20 +2,37 @@ package cn.iocoder.yudao.module.system.controller.admin.socail.vo.client; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; import java.time.LocalDateTime; @Schema(description = "管理后台 - 社交客户端 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class SocialClientRespVO extends SocialClientBaseVO { +public class SocialClientRespVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27162") private Long id; + @Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao商城") + private String name; + + @Schema(description = "社交平台的类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "31") + private Integer socialType; + + @Schema(description = "用户类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + private Integer userType; + + @Schema(description = "客户端编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "wwd411c69a39ad2e54") + private String clientId; + + @Schema(description = "客户端密钥", requiredMode = Schema.RequiredMode.REQUIRED, example = "peter") + private String clientSecret; + + @Schema(description = "授权方的网页应用编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000045") + private String agentId; + + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer status; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientSaveReqVO.java similarity index 80% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientBaseVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientSaveReqVO.java index 86d980ee0..be89153e8 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientSaveReqVO.java @@ -13,12 +13,12 @@ import javax.validation.constraints.AssertTrue; import javax.validation.constraints.NotNull; import java.util.Objects; -/** - * 社交客户端 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ +@Schema(description = "管理后台 - 社交客户端创建/修改 Request VO") @Data -public class SocialClientBaseVO { +public class SocialClientSaveReqVO { + + @Schema(description = "编号", example = "27162") + private Long id; @Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao商城") @NotNull(message = "应用名不能为空") @@ -38,7 +38,7 @@ public class SocialClientBaseVO { @NotNull(message = "客户端编号不能为空") private String clientId; - @Schema(description = "客户端密钥", requiredMode = Schema.RequiredMode.REQUIRED, example = "1wTb7hYxnpT2TUbIeHGXGo7T0odav1ic10mLdyyATOw") + @Schema(description = "客户端密钥", requiredMode = Schema.RequiredMode.REQUIRED, example = "peter") @NotNull(message = "客户端密钥不能为空") private String clientSecret; @@ -50,16 +50,12 @@ public class SocialClientBaseVO { @InEnum(CommonStatusEnum.class) private Integer status; - @SuppressWarnings("RedundantIfStatement") @AssertTrue(message = "agentId 不能为空") @JsonIgnore public boolean isAgentIdValid() { // 如果是企业微信,必须填写 agentId 属性 - if (Objects.equals(socialType, SocialTypeEnum.WECHAT_ENTERPRISE.getType()) - && StrUtil.isEmpty(agentId)) { - return false; - } - return true; + return !Objects.equals(socialType, SocialTypeEnum.WECHAT_ENTERPRISE.getType()) + || !StrUtil.isEmpty(agentId); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientUpdateReqVO.java deleted file mode 100644 index 963bf4b09..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientUpdateReqVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.socail.vo.client; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 社交客户端更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class SocialClientUpdateReqVO extends SocialClientBaseVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27162") - @NotNull(message = "编号不能为空") - private Long id; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserBaseVO.java deleted file mode 100644 index e763d0570..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserBaseVO.java +++ /dev/null @@ -1,45 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.socail.vo.user; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import javax.validation.constraints.NotNull; - -/** - * 社交用户 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ -@Data -public class SocialUserBaseVO { - - @Schema(description = "社交平台的类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "30") - @NotNull(message = "社交平台的类型不能为空") - private Integer type; - - @Schema(description = "社交 openid", requiredMode = Schema.RequiredMode.REQUIRED, example = "666") - @NotNull(message = "社交 openid不能为空") - private String openid; - - @Schema(description = "社交 token", requiredMode = Schema.RequiredMode.REQUIRED, example = "666") - private String token; - - @Schema(description = "原始 Token 数据,一般是 JSON 格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}") - private String rawTokenInfo; - - @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") - @NotNull(message = "用户昵称不能为空") - private String nickname; - - @Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png") - private String avatar; - - @Schema(description = "原始用户数据,一般是 JSON 格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}") - private String rawUserInfo; - - @Schema(description = "最后一次的认证 code", requiredMode = Schema.RequiredMode.REQUIRED, example = "666666") - private String code; - - @Schema(description = "最后一次的认证 state", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456") - private String state; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/SocialUserBindReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserBindReqVO.java similarity index 99% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/SocialUserBindReqVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserBindReqVO.java index 9958d6441..9ba416849 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/SocialUserBindReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserBindReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.system.controller.admin.socail.vo; +package cn.iocoder.yudao.module.system.controller.admin.socail.vo.user; import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; import cn.iocoder.yudao.framework.common.validation.InEnum; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserRespVO.java index fdffa0872..fd377037d 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserRespVO.java @@ -2,20 +2,43 @@ package cn.iocoder.yudao.module.system.controller.admin.socail.vo.user; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; import java.time.LocalDateTime; @Schema(description = "管理后台 - 社交用户 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class SocialUserRespVO extends SocialUserBaseVO { +public class SocialUserRespVO { @Schema(description = "主键(自增策略)", requiredMode = Schema.RequiredMode.REQUIRED, example = "14569") private Long id; + @Schema(description = "社交平台的类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "30") + private Integer type; + + @Schema(description = "社交 openid", requiredMode = Schema.RequiredMode.REQUIRED, example = "666") + private String openid; + + @Schema(description = "社交 token", requiredMode = Schema.RequiredMode.REQUIRED, example = "666") + private String token; + + @Schema(description = "原始 Token 数据,一般是 JSON 格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}") + private String rawTokenInfo; + + @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") + private String nickname; + + @Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png") + private String avatar; + + @Schema(description = "原始用户数据,一般是 JSON 格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}") + private String rawUserInfo; + + @Schema(description = "最后一次的认证 code", requiredMode = Schema.RequiredMode.REQUIRED, example = "666666") + private String code; + + @Schema(description = "最后一次的认证 state", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456") + private String state; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/SocialUserUnbindReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserUnbindReqVO.java similarity index 99% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/SocialUserUnbindReqVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserUnbindReqVO.java index 10f6244cd..10f07fcdc 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/SocialUserUnbindReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserUnbindReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.system.controller.admin.socail.vo; +package cn.iocoder.yudao.module.system.controller.admin.socail.vo.user; import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/social/SocialClientConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/social/SocialClientConvert.java deleted file mode 100644 index af227aa19..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/social/SocialClientConvert.java +++ /dev/null @@ -1,38 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.social; - -import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO; -import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO; -import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientRespVO; -import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientUpdateReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO; -import me.chanjar.weixin.common.bean.WxJsapiSignature; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper -public interface SocialClientConvert { - - SocialClientConvert INSTANCE = Mappers.getMapper(SocialClientConvert.class); - - SocialWxJsapiSignatureRespDTO convert(WxJsapiSignature bean); - - SocialWxPhoneNumberInfoRespDTO convert(WxMaPhoneNumberInfo bean); - - SocialClientDO convert(SocialClientCreateReqVO bean); - - SocialClientDO convert(SocialClientUpdateReqVO bean); - - SocialClientRespVO convert(SocialClientDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); - - - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/social/SocialUserConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/social/SocialUserConvert.java index c2e8a272e..9e679a242 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/social/SocialUserConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/social/SocialUserConvert.java @@ -1,32 +1,17 @@ package cn.iocoder.yudao.module.system.convert.social; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; -import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO; -import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserBindReqVO; -import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserUnbindReqVO; -import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserRespVO; -import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; +import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserBindReqVO; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; -import java.util.List; - @Mapper public interface SocialUserConvert { SocialUserConvert INSTANCE = Mappers.getMapper(SocialUserConvert.class); - @Mapping(target = "socialType", source = "reqVO.type") + @Mapping(source = "reqVO.type", target = "socialType") SocialUserBindReqDTO convert(Long userId, Integer userType, SocialUserBindReqVO reqVO); - SocialUserUnbindReqDTO convert(Long userId, Integer userType, SocialUserUnbindReqVO reqVO); - - SocialUserRespVO convert(SocialUserDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/social/SocialClientMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/social/SocialClientMapper.java index 717a26142..4ebe226bf 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/social/SocialClientMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/social/SocialClientMapper.java @@ -20,7 +20,7 @@ public interface SocialClientMapper extends BaseMapperX { .likeIfPresent(SocialClientDO::getName, reqVO.getName()) .eqIfPresent(SocialClientDO::getSocialType, reqVO.getSocialType()) .eqIfPresent(SocialClientDO::getUserType, reqVO.getUserType()) - .eqIfPresent(SocialClientDO::getClientId, reqVO.getClientId()) + .likeIfPresent(SocialClientDO::getClientId, reqVO.getClientId()) .eqIfPresent(SocialClientDO::getStatus, reqVO.getStatus()) .orderByDesc(SocialClientDO::getId)); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java index 35e9d5962..dba86c699 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java @@ -2,9 +2,8 @@ package cn.iocoder.yudao.module.system.service.social; import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO; import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; import com.xingyuv.jushauth.model.AuthUser; @@ -70,14 +69,14 @@ public interface SocialClientService { * @param createReqVO 创建信息 * @return 编号 */ - Long createSocialClient(@Valid SocialClientCreateReqVO createReqVO); + Long createSocialClient(@Valid SocialClientSaveReqVO createReqVO); /** * 更新社交客户端 * * @param updateReqVO 更新信息 */ - void updateSocialClient(@Valid SocialClientUpdateReqVO updateReqVO); + void updateSocialClient(@Valid SocialClientSaveReqVO updateReqVO); /** * 删除社交客户端 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java index 29184bee7..e13f08529 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java @@ -12,10 +12,9 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.cache.CacheUtils; import cn.iocoder.yudao.framework.common.util.http.HttpUtils; -import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientCreateReqVO; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.social.SocialClientConvert; +import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO; import cn.iocoder.yudao.module.system.dal.mysql.social.SocialClientMapper; import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; @@ -267,26 +266,25 @@ public class SocialClientServiceImpl implements SocialClientService { // =================== 客户端管理 =================== @Override - public Long createSocialClient(SocialClientCreateReqVO createReqVO) { + public Long createSocialClient(SocialClientSaveReqVO createReqVO) { // 校验重复 validateSocialClientUnique(null, createReqVO.getUserType(), createReqVO.getSocialType()); // 插入 - SocialClientDO socialClient = SocialClientConvert.INSTANCE.convert(createReqVO); - socialClientMapper.insert(socialClient); - // 返回 - return socialClient.getId(); + SocialClientDO client = BeanUtils.toBean(createReqVO, SocialClientDO.class); + socialClientMapper.insert(client); + return client.getId(); } @Override - public void updateSocialClient(SocialClientUpdateReqVO updateReqVO) { + public void updateSocialClient(SocialClientSaveReqVO updateReqVO) { // 校验存在 validateSocialClientExists(updateReqVO.getId()); // 校验重复 validateSocialClientUnique(updateReqVO.getId(), updateReqVO.getUserType(), updateReqVO.getSocialType()); // 更新 - SocialClientDO updateObj = SocialClientConvert.INSTANCE.convert(updateReqVO); + SocialClientDO updateObj = BeanUtils.toBean(updateReqVO, SocialClientDO.class); socialClientMapper.updateById(updateObj); } diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImplTest.java index a54ee1133..601255b8b 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImplTest.java @@ -2,9 +2,8 @@ package cn.iocoder.yudao.module.system.service.social; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO; import cn.iocoder.yudao.module.system.dal.mysql.social.SocialClientMapper; import org.junit.jupiter.api.Disabled; @@ -40,7 +39,8 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest { @Test public void testCreateSocialClient_success() { // 准备参数 - SocialClientCreateReqVO reqVO = randomPojo(SocialClientCreateReqVO.class); + SocialClientSaveReqVO reqVO = randomPojo(SocialClientSaveReqVO.class) + .setId(null); // 防止 id 被赋值 // 调用 Long socialClientId = socialClientService.createSocialClient(reqVO); @@ -48,7 +48,7 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest { assertNotNull(socialClientId); // 校验记录的属性是否正确 SocialClientDO socialClient = socialClientMapper.selectById(socialClientId); - assertPojoEquals(reqVO, socialClient); + assertPojoEquals(reqVO, socialClient, "id"); } @Test @@ -57,7 +57,7 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest { SocialClientDO dbSocialClient = randomPojo(SocialClientDO.class); socialClientMapper.insert(dbSocialClient);// @Sql: 先插入出一条存在的数据 // 准备参数 - SocialClientUpdateReqVO reqVO = randomPojo(SocialClientUpdateReqVO.class, o -> { + SocialClientSaveReqVO reqVO = randomPojo(SocialClientSaveReqVO.class, o -> { o.setId(dbSocialClient.getId()); // 设置更新的 ID }); @@ -71,7 +71,7 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest { @Test public void testUpdateSocialClient_notExists() { // 准备参数 - SocialClientUpdateReqVO reqVO = randomPojo(SocialClientUpdateReqVO.class); + SocialClientSaveReqVO reqVO = randomPojo(SocialClientSaveReqVO.class); // 调用, 并断言异常 assertServiceException(() -> socialClientService.updateSocialClient(reqVO), SOCIAL_CLIENT_NOT_EXISTS); From d4cf945af710c67659dd9778aa59c0136f5eb43a Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 2 Dec 2023 23:42:57 +0800 Subject: [PATCH 13/19] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20tenan?= =?UTF-8?q?t=20=E6=A8=A1=E5=9D=97=E7=9A=84=20VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/tenant/TenantController.java | 31 ++++++----- .../admin/tenant/TenantPackageController.java | 15 +++--- .../vo/packages/TenantPackageCreateReqVO.java | 14 ----- .../vo/packages/TenantPackageRespVO.java | 19 +++++-- ...aseVO.java => TenantPackageSaveReqVO.java} | 16 +++--- .../vo/packages/TenantPackageUpdateReqVO.java | 17 ------ .../tenant/vo/tenant/TenantCreateReqVO.java | 29 ----------- .../admin/tenant/vo/tenant/TenantExcelVO.java | 39 -------------- .../tenant/vo/tenant/TenantExportReqVO.java | 31 ----------- .../admin/tenant/vo/tenant/TenantRespVO.java | 43 +++++++++++++-- ...TenantBaseVO.java => TenantSaveReqVO.java} | 38 +++++++++++--- .../tenant/vo/tenant/TenantSimpleRespVO.java | 6 +-- .../tenant/vo/tenant/TenantUpdateReqVO.java | 17 ------ .../system/convert/tenant/TenantConvert.java | 22 +------- .../convert/tenant/TenantPackageConvert.java | 37 ------------- .../system/dal/mysql/tenant/TenantMapper.java | 11 ---- .../service/tenant/TenantPackageService.java | 7 ++- .../tenant/TenantPackageServiceImpl.java | 13 +++-- .../system/service/tenant/TenantService.java | 16 ++---- .../service/tenant/TenantServiceImpl.java | 24 ++++----- .../tenant/TenantPackageServiceImplTest.java | 21 ++++---- .../service/tenant/TenantServiceImplTest.java | 52 +++---------------- 22 files changed, 161 insertions(+), 357 deletions(-) delete mode 100755 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageCreateReqVO.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/{TenantPackageBaseVO.java => TenantPackageSaveReqVO.java} (62%) delete mode 100755 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageUpdateReqVO.java delete mode 100755 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantCreateReqVO.java delete mode 100755 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantExcelVO.java delete mode 100755 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantExportReqVO.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/{TenantBaseVO.java => TenantSaveReqVO.java} (51%) mode change 100755 => 100644 delete mode 100755 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantUpdateReqVO.java delete mode 100755 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/tenant/TenantPackageConvert.java diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/TenantController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/TenantController.java index 06589ec9a..ea815313e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/TenantController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/TenantController.java @@ -1,16 +1,20 @@ package cn.iocoder.yudao.module.system.controller.admin.tenant; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -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.controller.admin.tenant.vo.tenant.TenantPageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantRespVO; +import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantSaveReqVO; +import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantSimpleRespVO; import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; import cn.iocoder.yudao.module.system.service.tenant.TenantService; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; @@ -47,20 +51,20 @@ public class TenantController { @Parameter(name = "website", description = "域名", required = true, example = "www.iocoder.cn") public CommonResult getTenantByWebsite(@RequestParam("website") String website) { TenantDO tenant = tenantService.getTenantByWebsite(website); - return success(TenantConvert.INSTANCE.convert03(tenant)); + return success(BeanUtils.toBean(tenant, TenantSimpleRespVO.class)); } @PostMapping("/create") @Operation(summary = "创建租户") @PreAuthorize("@ss.hasPermission('system:tenant:create')") - public CommonResult createTenant(@Valid @RequestBody TenantCreateReqVO createReqVO) { + public CommonResult createTenant(@Valid @RequestBody TenantSaveReqVO createReqVO) { return success(tenantService.createTenant(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新租户") @PreAuthorize("@ss.hasPermission('system:tenant:update')") - public CommonResult updateTenant(@Valid @RequestBody TenantUpdateReqVO updateReqVO) { + public CommonResult updateTenant(@Valid @RequestBody TenantSaveReqVO updateReqVO) { tenantService.updateTenant(updateReqVO); return success(true); } @@ -80,7 +84,7 @@ public class TenantController { @PreAuthorize("@ss.hasPermission('system:tenant:query')") public CommonResult getTenant(@RequestParam("id") Long id) { TenantDO tenant = tenantService.getTenant(id); - return success(TenantConvert.INSTANCE.convert(tenant)); + return success(BeanUtils.toBean(tenant, TenantRespVO.class)); } @GetMapping("/page") @@ -88,19 +92,20 @@ public class TenantController { @PreAuthorize("@ss.hasPermission('system:tenant:query')") public CommonResult> getTenantPage(@Valid TenantPageReqVO pageVO) { PageResult pageResult = tenantService.getTenantPage(pageVO); - return success(TenantConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, TenantRespVO.class)); } @GetMapping("/export-excel") @Operation(summary = "导出租户 Excel") @PreAuthorize("@ss.hasPermission('system:tenant:export')") @OperateLog(type = EXPORT) - public void exportTenantExcel(@Valid TenantExportReqVO exportReqVO, + public void exportTenantExcel(@Valid TenantPageReqVO exportReqVO, HttpServletResponse response) throws IOException { - List list = tenantService.getTenantList(exportReqVO); + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = tenantService.getTenantPage(exportReqVO).getList(); // 导出 Excel - List datas = TenantConvert.INSTANCE.convertList02(list); - ExcelUtils.write(response, "租户.xls", "数据", TenantExcelVO.class, datas); + ExcelUtils.write(response, "租户.xls", "数据", TenantRespVO.class, + BeanUtils.toBean(list, TenantRespVO.class)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/TenantPackageController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/TenantPackageController.java index ec4782388..f523d5196 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/TenantPackageController.java +++ b/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; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.*; -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.v3.oas.annotations.tags.Tag; @@ -32,14 +32,14 @@ public class TenantPackageController { @PostMapping("/create") @Operation(summary = "创建租户套餐") @PreAuthorize("@ss.hasPermission('system:tenant-package:create')") - public CommonResult createTenantPackage(@Valid @RequestBody TenantPackageCreateReqVO createReqVO) { + public CommonResult createTenantPackage(@Valid @RequestBody TenantPackageSaveReqVO createReqVO) { return success(tenantPackageService.createTenantPackage(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新租户套餐") @PreAuthorize("@ss.hasPermission('system:tenant-package:update')") - public CommonResult updateTenantPackage(@Valid @RequestBody TenantPackageUpdateReqVO updateReqVO) { + public CommonResult updateTenantPackage(@Valid @RequestBody TenantPackageSaveReqVO updateReqVO) { tenantPackageService.updateTenantPackage(updateReqVO); return success(true); } @@ -59,7 +59,7 @@ public class TenantPackageController { @PreAuthorize("@ss.hasPermission('system:tenant-package:query')") public CommonResult getTenantPackage(@RequestParam("id") Long id) { TenantPackageDO tenantPackage = tenantPackageService.getTenantPackage(id); - return success(TenantPackageConvert.INSTANCE.convert(tenantPackage)); + return success(BeanUtils.toBean(tenantPackage, TenantPackageRespVO.class)); } @GetMapping("/page") @@ -67,15 +67,14 @@ public class TenantPackageController { @PreAuthorize("@ss.hasPermission('system:tenant-package:query')") public CommonResult> getTenantPackagePage(@Valid TenantPackagePageReqVO pageVO) { PageResult pageResult = tenantPackageService.getTenantPackagePage(pageVO); - return success(TenantPackageConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, TenantPackageRespVO.class)); } - @GetMapping("/get-simple-list") + @GetMapping({"/get-simple-list", "simple-list"}) @Operation(summary = "获取租户套餐精简信息列表", description = "只包含被开启的租户套餐,主要用于前端的下拉选项") public CommonResult> getTenantPackageList() { - // 获得角色列表,只要开启状态的 List list = tenantPackageService.getTenantPackageListByStatus(CommonStatusEnum.ENABLE.getStatus()); - return success(TenantPackageConvert.INSTANCE.convertList02(list)); + return success(BeanUtils.toBean(list, TenantPackageSimpleRespVO.class)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageCreateReqVO.java deleted file mode 100755 index 255971447..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageCreateReqVO.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -@Schema(description = "管理后台 - 租户套餐创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class TenantPackageCreateReqVO extends TenantPackageBaseVO { - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageRespVO.java index 29b985df6..16ffd817a 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageRespVO.java +++ b/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; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; import java.time.LocalDateTime; +import java.util.Set; @Schema(description = "管理后台 - 租户套餐 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class TenantPackageRespVO extends TenantPackageBaseVO { +public class TenantPackageRespVO { @Schema(description = "套餐编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Long id; + @Schema(description = "套餐名", requiredMode = Schema.RequiredMode.REQUIRED, example = "VIP") + private String name; + + @Schema(description = "状态,参见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer status; + + @Schema(description = "备注", example = "好") + private String remark; + + @Schema(description = "关联的菜单编号", requiredMode = Schema.RequiredMode.REQUIRED) + private Set menuIds; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageSaveReqVO.java similarity index 62% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageBaseVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageSaveReqVO.java index fdf316a9b..3faed3a3d 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageSaveReqVO.java @@ -1,24 +1,28 @@ package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.validation.InEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import java.util.Set; -/** - * 租户套餐 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ +@Schema(description = "管理后台 - 租户套餐创建/修改 Request VO") @Data -public class TenantPackageBaseVO { +public class TenantPackageSaveReqVO { + + @Schema(description = "套餐编号", example = "1024") + private Long id; @Schema(description = "套餐名", requiredMode = Schema.RequiredMode.REQUIRED, example = "VIP") - @NotNull(message = "套餐名不能为空") + @NotEmpty(message = "套餐名不能为空") private String name; @Schema(description = "状态,参见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @NotNull(message = "状态不能为空") + @InEnum(value = CommonStatusEnum.class, message = "状态必须是 {value}") private Integer status; @Schema(description = "备注", example = "好") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageUpdateReqVO.java deleted file mode 100755 index 0d7e74c25..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/packages/TenantPackageUpdateReqVO.java +++ /dev/null @@ -1,17 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; -import javax.validation.constraints.*; - -@Schema(description = "管理后台 - 租户套餐更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class TenantPackageUpdateReqVO extends TenantPackageBaseVO { - - @Schema(description = "套餐编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "套餐编号不能为空") - private Long id; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantCreateReqVO.java deleted file mode 100755 index b45ac59ba..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantCreateReqVO.java +++ /dev/null @@ -1,29 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; -import org.hibernate.validator.constraints.Length; - -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.Pattern; -import javax.validation.constraints.Size; - -@Schema(description = "管理后台 - 租户创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class TenantCreateReqVO extends TenantBaseVO { - - @Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao") - @NotBlank(message = "用户账号不能为空") - @Pattern(regexp = "^[a-zA-Z0-9]{4,30}$", message = "用户账号由 数字、字母 组成") - @Size(min = 4, max = 30, message = "用户账号长度为 4-30 个字符") - private String username; - - @Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456") - @NotEmpty(message = "密码不能为空") - @Length(min = 4, max = 16, message = "密码长度为 4-16 位") - private String password; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantExcelVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantExcelVO.java deleted file mode 100755 index 7ea57714d..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantExcelVO.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant; - -import cn.iocoder.yudao.module.system.enums.DictTypeConstants; -import lombok.*; -import java.time.LocalDateTime; - -import com.alibaba.excel.annotation.ExcelProperty; -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; - - -/** - * 租户 Excel VO - * - * @author 芋道源码 - */ -@Data -public class TenantExcelVO { - - @ExcelProperty("租户编号") - private Long id; - - @ExcelProperty("租户名") - private String name; - - @ExcelProperty("联系人") - private String contactName; - - @ExcelProperty("联系手机") - private String contactMobile; - - @ExcelProperty(value = "状态", converter = DictConvert.class) - @DictFormat(DictTypeConstants.COMMON_STATUS) - private Integer status; - - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantExportReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantExportReqVO.java deleted file mode 100755 index c5c5a0660..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantExportReqVO.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 租户 Excel 导出 Request VO,参数和 TenantPageReqVO 是一致的") -@Data -public class TenantExportReqVO { - - @Schema(description = "租户名", example = "芋道") - private String name; - - @Schema(description = "联系人", example = "芋艿") - private String contactName; - - @Schema(description = "联系手机", example = "15601691300") - private String contactMobile; - - @Schema(description = "租户状态(0正常 1停用)", example = "1") - private Integer status; - - @Schema(description = "创建时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] createTime; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantRespVO.java index 13754d669..5a444b521 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantRespVO.java @@ -1,20 +1,55 @@ package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; +import lombok.Data; import java.time.LocalDateTime; @Schema(description = "管理后台 - 租户 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class TenantRespVO extends TenantBaseVO { +@ExcelIgnoreUnannotated +public class TenantRespVO { @Schema(description = "租户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("租户编号") private Long id; + @Schema(description = "租户名", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") + @ExcelProperty("租户名") + private String name; + + @Schema(description = "联系人", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") + @ExcelProperty("联系人") + private String contactName; + + @Schema(description = "联系手机", example = "15601691300") + @ExcelProperty("联系手机") + private String contactMobile; + + @Schema(description = "租户状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "状态", converter = DictConvert.class) + @DictFormat(DictTypeConstants.COMMON_STATUS) + private Integer status; + + @Schema(description = "绑定域名", example = "https://www.iocoder.cn") + private String website; + + @Schema(description = "租户套餐编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Long packageId; + + @Schema(description = "过期时间", requiredMode = Schema.RequiredMode.REQUIRED) + private LocalDateTime expireTime; + + @Schema(description = "账号数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer accountCount; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") private LocalDateTime createTime; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantSaveReqVO.java old mode 100755 new mode 100644 similarity index 51% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantBaseVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantSaveReqVO.java index 73c1dcf50..117d365ff --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantSaveReqVO.java @@ -1,17 +1,23 @@ package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant; +import cn.hutool.core.util.ObjectUtil; +import com.fasterxml.jackson.annotation.JsonIgnore; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; +import lombok.Data; +import org.hibernate.validator.constraints.Length; -import javax.validation.constraints.*; +import javax.validation.constraints.AssertTrue; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Pattern; +import javax.validation.constraints.Size; import java.time.LocalDateTime; -/** - * 租户 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ +@Schema(description = "管理后台 - 租户创建/修改 Request VO") @Data -public class TenantBaseVO { +public class TenantSaveReqVO { + + @Schema(description = "租户编号", example = "1024") + private Long id; @Schema(description = "租户名", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") @NotNull(message = "租户名不能为空") @@ -43,4 +49,22 @@ public class TenantBaseVO { @NotNull(message = "账号数量不能为空") private Integer accountCount; + // ========== 仅【创建】时,需要传递的字段 ========== + + @Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao") + @Pattern(regexp = "^[a-zA-Z0-9]{4,30}$", message = "用户账号由 数字、字母 组成") + @Size(min = 4, max = 30, message = "用户账号长度为 4-30 个字符") + private String username; + + @Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456") + @Length(min = 4, max = 16, message = "密码长度为 4-16 位") + private String password; + + @AssertTrue(message = "用户账号、密码不能为空") + @JsonIgnore + public boolean isUsernameValid() { + return id != null // 修改时,不需要传递 + || (ObjectUtil.isAllNotEmpty(username, password)); // 新增时,必须都传递 username、password + } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantSimpleRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantSimpleRespVO.java index 8bc74194e..49752278d 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantSimpleRespVO.java +++ b/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; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; @Schema(description = "管理后台 - 租户精简 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class TenantSimpleRespVO extends TenantBaseVO { +public class TenantSimpleRespVO { @Schema(description = "租户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Long id; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantUpdateReqVO.java deleted file mode 100755 index 6555bcec0..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/vo/tenant/TenantUpdateReqVO.java +++ /dev/null @@ -1,17 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; -import javax.validation.constraints.*; - -@Schema(description = "管理后台 - 租户更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class TenantUpdateReqVO extends TenantBaseVO { - - @Schema(description = "租户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "租户编号不能为空") - private Long id; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/tenant/TenantConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/tenant/TenantConvert.java index b9e35cd10..eeb30fcf8 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/tenant/TenantConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/tenant/TenantConvert.java @@ -1,14 +1,10 @@ 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.tenant.*; +import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantSaveReqVO; import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserCreateReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; -import java.util.List; - /** * 租户 Convert * @@ -19,21 +15,7 @@ public interface TenantConvert { TenantConvert INSTANCE = Mappers.getMapper(TenantConvert.class); - TenantDO convert(TenantCreateReqVO bean); - - TenantDO convert(TenantUpdateReqVO bean); - - TenantRespVO convert(TenantDO bean); - - TenantSimpleRespVO convert03(TenantDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); - - List convertList02(List list); - - default UserCreateReqVO convert02(TenantCreateReqVO bean) { + default UserCreateReqVO convert02(TenantSaveReqVO bean) { UserCreateReqVO reqVO = new UserCreateReqVO(); reqVO.setUsername(bean.getUsername()); reqVO.setPassword(bean.getPassword()); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/tenant/TenantPackageConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/tenant/TenantPackageConvert.java deleted file mode 100755 index ff8c7e4ae..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/tenant/TenantPackageConvert.java +++ /dev/null @@ -1,37 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.tenant; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleSimpleRespVO; -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.TenantPackageSimpleRespVO; -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 convertList(List list); - - PageResult convertPage(PageResult page); - - List convertList02(List list); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenant/TenantMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenant/TenantMapper.java index 5ac719d2e..aaca0160a 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenant/TenantMapper.java +++ b/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; 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.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 org.apache.ibatis.annotations.Mapper; @@ -28,16 +27,6 @@ public interface TenantMapper extends BaseMapperX { .orderByDesc(TenantDO::getId)); } - default List selectList(TenantExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .likeIfPresent(TenantDO::getName, reqVO.getName()) - .likeIfPresent(TenantDO::getContactName, reqVO.getContactName()) - .likeIfPresent(TenantDO::getContactMobile, reqVO.getContactMobile()) - .eqIfPresent(TenantDO::getStatus, reqVO.getStatus()) - .betweenIfPresent(TenantDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(TenantDO::getId)); - } - default TenantDO selectByName(String name) { return selectOne(TenantDO::getName, name); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageService.java index c58426a2b..1abe4feeb 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageService.java @@ -1,9 +1,8 @@ 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.controller.admin.tenant.vo.packages.TenantPackageSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO; import javax.validation.Valid; @@ -22,14 +21,14 @@ public interface TenantPackageService { * @param createReqVO 创建信息 * @return 编号 */ - Long createTenantPackage(@Valid TenantPackageCreateReqVO createReqVO); + Long createTenantPackage(@Valid TenantPackageSaveReqVO createReqVO); /** * 更新租户套餐 * * @param updateReqVO 更新信息 */ - void updateTenantPackage(@Valid TenantPackageUpdateReqVO updateReqVO); + void updateTenantPackage(@Valid TenantPackageSaveReqVO updateReqVO); /** * 删除租户套餐 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageServiceImpl.java index 8a65ab1f0..3fd76a154 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageServiceImpl.java +++ b/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; import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.TenantPackageCreateReqVO; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 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.controller.admin.tenant.vo.packages.TenantPackageSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO; import cn.iocoder.yudao.module.system.dal.mysql.tenant.TenantPackageMapper; @@ -38,9 +37,9 @@ public class TenantPackageServiceImpl implements TenantPackageService { private TenantService tenantService; @Override - public Long createTenantPackage(TenantPackageCreateReqVO createReqVO) { + public Long createTenantPackage(TenantPackageSaveReqVO createReqVO) { // 插入 - TenantPackageDO tenantPackage = TenantPackageConvert.INSTANCE.convert(createReqVO); + TenantPackageDO tenantPackage = BeanUtils.toBean(createReqVO, TenantPackageDO.class); tenantPackageMapper.insert(tenantPackage); // 返回 return tenantPackage.getId(); @@ -48,11 +47,11 @@ public class TenantPackageServiceImpl implements TenantPackageService { @Override @DSTransactional // 多数据源,使用 @DSTransactional 保证本地事务,以及数据源的切换 - public void updateTenantPackage(TenantPackageUpdateReqVO updateReqVO) { + public void updateTenantPackage(TenantPackageSaveReqVO updateReqVO) { // 校验存在 TenantPackageDO tenantPackage = validateTenantPackageExists(updateReqVO.getId()); // 更新 - TenantPackageDO updateObj = TenantPackageConvert.INSTANCE.convert(updateReqVO); + TenantPackageDO updateObj = BeanUtils.toBean(updateReqVO, TenantPackageDO.class); tenantPackageMapper.updateById(updateObj); // 如果菜单发生变化,则修改每个租户的菜单 if (!CollUtil.isEqualList(tenantPackage.getMenuIds(), updateReqVO.getMenuIds())) { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantService.java index 4c24bb33c..c7e879b8e 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantService.java +++ b/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; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; -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.controller.admin.tenant.vo.tenant.TenantSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; import cn.iocoder.yudao.module.system.service.tenant.handler.TenantInfoHandler; import cn.iocoder.yudao.module.system.service.tenant.handler.TenantMenuHandler; @@ -27,14 +25,14 @@ public interface TenantService { * @param createReqVO 创建信息 * @return 编号 */ - Long createTenant(@Valid TenantCreateReqVO createReqVO); + Long createTenant(@Valid TenantSaveReqVO createReqVO); /** * 更新租户 * * @param updateReqVO 更新信息 */ - void updateTenant(@Valid TenantUpdateReqVO updateReqVO); + void updateTenant(@Valid TenantSaveReqVO updateReqVO); /** * 更新租户的角色菜单 @@ -67,14 +65,6 @@ public interface TenantService { */ PageResult getTenantPage(TenantPageReqVO pageReqVO); - /** - * 获得租户列表, 用于 Excel 导出 - * - * @param exportReqVO 查询条件 - * @return 租户列表 - */ - List getTenantList(TenantExportReqVO exportReqVO); - /** * 获得名字对应的租户 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java index 1f4fce034..b4bdf1036 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java +++ b/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; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.date.DateUtils; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.tenant.config.TenantProperties; import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleSaveReqVO; -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.controller.admin.tenant.vo.tenant.TenantSaveReqVO; import cn.iocoder.yudao.module.system.convert.tenant.TenantConvert; import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; @@ -97,7 +96,7 @@ public class TenantServiceImpl implements TenantService { @Override @DSTransactional // 多数据源,使用 @DSTransactional 保证本地事务,以及数据源的切换 - public Long createTenant(TenantCreateReqVO createReqVO) { + public Long createTenant(TenantSaveReqVO createReqVO) { // 校验租户名称是否重复 validTenantNameDuplicate(createReqVO.getName(), null); // 校验租户域名是否重复 @@ -106,9 +105,9 @@ public class TenantServiceImpl implements TenantService { TenantPackageDO tenantPackage = tenantPackageService.validTenantPackage(createReqVO.getPackageId()); // 创建租户 - TenantDO tenant = TenantConvert.INSTANCE.convert(createReqVO); + TenantDO tenant = BeanUtils.toBean(createReqVO, TenantDO.class); tenantMapper.insert(tenant); - + // 创建租户的管理员 TenantUtils.execute(tenant.getId(), () -> { // 创建角色 Long roleId = createRole(tenantPackage); @@ -120,7 +119,7 @@ public class TenantServiceImpl implements TenantService { return tenant.getId(); } - private Long createUser(Long roleId, TenantCreateReqVO createReqVO) { + private Long createUser(Long roleId, TenantSaveReqVO createReqVO) { // 创建用户 Long userId = userService.createUser(TenantConvert.INSTANCE.convert02(createReqVO)); // 分配角色 @@ -140,8 +139,8 @@ public class TenantServiceImpl implements TenantService { } @Override - @DSTransactional - public void updateTenant(TenantUpdateReqVO updateReqVO) { + @DSTransactional // 多数据源,使用 @DSTransactional 保证本地事务,以及数据源的切换 + public void updateTenant(TenantSaveReqVO updateReqVO) { // 校验存在 TenantDO tenant = validateUpdateTenant(updateReqVO.getId()); // 校验租户名称是否重复 @@ -152,7 +151,7 @@ public class TenantServiceImpl implements TenantService { TenantPackageDO tenantPackage = tenantPackageService.validTenantPackage(updateReqVO.getPackageId()); // 更新租户 - TenantDO updateObj = TenantConvert.INSTANCE.convert(updateReqVO); + TenantDO updateObj = BeanUtils.toBean(updateReqVO, TenantDO.class); tenantMapper.updateById(updateObj); // 如果套餐发生变化,则修改其角色的权限 if (ObjectUtil.notEqual(tenant.getPackageId(), updateReqVO.getPackageId())) { @@ -246,11 +245,6 @@ public class TenantServiceImpl implements TenantService { return tenantMapper.selectPage(pageReqVO); } - @Override - public List getTenantList(TenantExportReqVO exportReqVO) { - return tenantMapper.selectList(exportReqVO); - } - @Override public TenantDO getTenantByName(String name) { return tenantMapper.selectByName(name); diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageServiceImplTest.java index 9f80a1014..ab4784b97 100755 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageServiceImplTest.java +++ b/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; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -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.controller.admin.tenant.vo.packages.TenantPackageSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO; import cn.iocoder.yudao.module.system.dal.mysql.tenant.TenantPackageMapper; @@ -14,7 +13,6 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; import javax.annotation.Resource; - import java.util.List; 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 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.framework.test.core.util.RandomUtils.*; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; import static java.util.Arrays.asList; import static org.junit.jupiter.api.Assertions.*; @@ -51,7 +48,9 @@ public class TenantPackageServiceImplTest extends BaseDbUnitTest { @Test public void testCreateTenantPackage_success() { // 准备参数 - TenantPackageCreateReqVO reqVO = randomPojo(TenantPackageCreateReqVO.class); + TenantPackageSaveReqVO reqVO = randomPojo(TenantPackageSaveReqVO.class, + o -> o.setStatus(randomCommonStatus())) + .setId(null); // 防止 id 被赋值 // 调用 Long tenantPackageId = tenantPackageService.createTenantPackage(reqVO); @@ -59,17 +58,19 @@ public class TenantPackageServiceImplTest extends BaseDbUnitTest { assertNotNull(tenantPackageId); // 校验记录的属性是否正确 TenantPackageDO tenantPackage = tenantPackageMapper.selectById(tenantPackageId); - assertPojoEquals(reqVO, tenantPackage); + assertPojoEquals(reqVO, tenantPackage, "id"); } @Test public void testUpdateTenantPackage_success() { // mock 数据 - TenantPackageDO dbTenantPackage = randomPojo(TenantPackageDO.class); + TenantPackageDO dbTenantPackage = randomPojo(TenantPackageDO.class, + o -> o.setStatus(randomCommonStatus())); tenantPackageMapper.insert(dbTenantPackage);// @Sql: 先插入出一条存在的数据 // 准备参数 - TenantPackageUpdateReqVO reqVO = randomPojo(TenantPackageUpdateReqVO.class, o -> { + TenantPackageSaveReqVO reqVO = randomPojo(TenantPackageSaveReqVO.class, o -> { o.setId(dbTenantPackage.getId()); // 设置更新的 ID + o.setStatus(randomCommonStatus()); }); // mock 方法 Long tenantId01 = randomLongId(); @@ -91,7 +92,7 @@ public class TenantPackageServiceImplTest extends BaseDbUnitTest { @Test public void testUpdateTenantPackage_notExists() { // 准备参数 - TenantPackageUpdateReqVO reqVO = randomPojo(TenantPackageUpdateReqVO.class); + TenantPackageSaveReqVO reqVO = randomPojo(TenantPackageSaveReqVO.class); // 调用, 并断言异常 assertServiceException(() -> tenantPackageService.updateTenantPackage(reqVO), TENANT_PACKAGE_NOT_EXISTS); diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImplTest.java index 78e5435c8..62e7808c8 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImplTest.java +++ b/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; import cn.iocoder.yudao.framework.tenant.config.TenantProperties; import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -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.controller.admin.tenant.vo.tenant.TenantSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; @@ -152,7 +150,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { }))).thenReturn(300L); // 准备参数 - TenantCreateReqVO reqVO = randomPojo(TenantCreateReqVO.class, o -> { + TenantSaveReqVO reqVO = randomPojo(TenantSaveReqVO.class, o -> { o.setContactName("芋道"); o.setContactMobile("15601691300"); o.setPackageId(100L); @@ -160,7 +158,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { o.setWebsite("https://www.iocoder.cn"); o.setUsername("yunai"); o.setPassword("yuanma"); - }); + }).setId(null); // 设置为 null,方便后面校验 // 调用 Long tenantId = tenantService.createTenant(reqVO); @@ -168,7 +166,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { assertNotNull(tenantId); // 校验记录的属性是否正确 TenantDO tenant = tenantMapper.selectById(tenantId); - assertPojoEquals(reqVO, tenant); + assertPojoEquals(reqVO, tenant, "id"); assertEquals(300L, tenant.getContactUserId()); // verify 分配权限 verify(permissionService).assignRoleMenu(eq(200L), same(tenantPackage.getMenuIds())); @@ -182,7 +180,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { TenantDO dbTenant = randomPojo(TenantDO.class, o -> o.setStatus(randomCommonStatus())); tenantMapper.insert(dbTenant);// @Sql: 先插入出一条存在的数据 // 准备参数 - TenantUpdateReqVO reqVO = randomPojo(TenantUpdateReqVO.class, o -> { + TenantSaveReqVO reqVO = randomPojo(TenantSaveReqVO.class, o -> { o.setId(dbTenant.getId()); // 设置更新的 ID o.setStatus(randomCommonStatus()); o.setWebsite(randomString()); @@ -214,7 +212,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { @Test public void testUpdateTenant_notExists() { // 准备参数 - TenantUpdateReqVO reqVO = randomPojo(TenantUpdateReqVO.class); + TenantSaveReqVO reqVO = randomPojo(TenantSaveReqVO.class); // 调用, 并断言异常 assertServiceException(() -> tenantService.updateTenant(reqVO), TENANT_NOT_EXISTS); @@ -226,7 +224,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { TenantDO dbTenant = randomPojo(TenantDO.class, o -> o.setPackageId(PACKAGE_ID_SYSTEM)); tenantMapper.insert(dbTenant);// @Sql: 先插入出一条存在的数据 // 准备参数 - TenantUpdateReqVO reqVO = randomPojo(TenantUpdateReqVO.class, o -> { + TenantSaveReqVO reqVO = randomPojo(TenantSaveReqVO.class, o -> { o.setId(dbTenant.getId()); // 设置更新的 ID }); @@ -321,42 +319,6 @@ public class TenantServiceImplTest extends BaseDbUnitTest { assertPojoEquals(dbTenant, pageResult.getList().get(0)); } - @Test - public void testGetTenantList() { - // mock 数据 - TenantDO dbTenant = randomPojo(TenantDO.class, o -> { // 等会查询到 - o.setName("芋道源码"); - o.setContactName("芋艿"); - o.setContactMobile("15601691300"); - o.setStatus(CommonStatusEnum.ENABLE.getStatus()); - o.setCreateTime(buildTime(2020, 12, 12)); - }); - tenantMapper.insert(dbTenant); - // 测试 name 不匹配 - tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setName(randomString()))); - // 测试 contactName 不匹配 - tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setContactName(randomString()))); - // 测试 contactMobile 不匹配 - tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setContactMobile(randomString()))); - // 测试 status 不匹配 - tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); - // 测试 createTime 不匹配 - tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setCreateTime(buildTime(2021, 12, 12)))); - // 准备参数 - TenantExportReqVO reqVO = new TenantExportReqVO(); - reqVO.setName("芋道"); - reqVO.setContactName("艿"); - reqVO.setContactMobile("1560"); - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); - reqVO.setCreateTime(buildBetweenTime(2020, 12, 1, 2020, 12, 24)); - - // 调用 - List list = tenantService.getTenantList(reqVO); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbTenant, list.get(0)); - } - @Test public void testGetTenantByName() { // mock 数据 From 42dc4b6194bbc3ea7090e868604c631e9dd16fc0 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 3 Dec 2023 01:02:59 +0800 Subject: [PATCH 14/19] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20user?= =?UTF-8?q?=20=E6=A8=A1=E5=9D=97=E7=9A=84=20VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/api/user/AdminUserApiImpl.java | 10 +- .../controller/admin/user/UserController.java | 120 ++++++------------ .../admin/user/UserProfileController.java | 20 +-- .../user/vo/profile/UserProfileRespVO.java | 76 ++++------- .../admin/user/vo/user/UserCreateReqVO.java | 20 --- .../admin/user/vo/user/UserExcelVO.java | 52 -------- .../admin/user/vo/user/UserExportReqVO.java | 35 ----- .../user/vo/user/UserPageItemRespVO.java | 33 ----- .../admin/user/vo/user/UserRespVO.java | 56 +++++++- .../{UserBaseVO.java => UserSaveReqVO.java} | 32 +++-- .../admin/user/vo/user/UserSimpleRespVO.java | 5 + .../admin/user/vo/user/UserUpdateReqVO.java | 18 --- .../system/convert/tenant/TenantConvert.java | 6 +- .../system/convert/user/UserConvert.java | 67 +++++----- .../dal/mysql/user/AdminUserMapper.java | 10 -- .../system/service/user/AdminUserService.java | 22 +--- .../service/user/AdminUserServiceImpl.java | 53 +++----- .../user/AdminUserServiceImplTest.java | 34 +---- 18 files changed, 219 insertions(+), 450 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserCreateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserExcelVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserExportReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserPageItemRespVO.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/{UserBaseVO.java => UserSaveReqVO.java} (62%) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserUpdateReqVO.java diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApiImpl.java index adbc694da..172680022 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApiImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApiImpl.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.system.api.user; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; -import cn.iocoder.yudao.module.system.convert.user.UserConvert; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; import cn.iocoder.yudao.module.system.service.user.AdminUserService; import org.springframework.stereotype.Service; @@ -24,25 +24,25 @@ public class AdminUserApiImpl implements AdminUserApi { @Override public AdminUserRespDTO getUser(Long id) { AdminUserDO user = userService.getUser(id); - return UserConvert.INSTANCE.convert4(user); + return BeanUtils.toBean(user, AdminUserRespDTO.class); } @Override public List getUserList(Collection ids) { List users = userService.getUserList(ids); - return UserConvert.INSTANCE.convertList4(users); + return BeanUtils.toBean(users, AdminUserRespDTO.class); } @Override public List getUserListByDeptIds(Collection deptIds) { List users = userService.getUserListByDeptIds(deptIds); - return UserConvert.INSTANCE.convertList4(users); + return BeanUtils.toBean(users, AdminUserRespDTO.class); } @Override public List getUserListByPostIds(Collection postIds) { List users = userService.getUserListByPostIds(postIds); - return UserConvert.INSTANCE.convertList4(users); + return BeanUtils.toBean(users, AdminUserRespDTO.class); } @Override diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserController.java index f8c817db5..358affb3e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserController.java @@ -1,23 +1,23 @@ package cn.iocoder.yudao.module.system.controller.admin.user; import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.*; import cn.iocoder.yudao.module.system.convert.user.UserConvert; import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; +import cn.iocoder.yudao.module.system.enums.common.SexEnum; import cn.iocoder.yudao.module.system.service.dept.DeptService; import cn.iocoder.yudao.module.system.service.user.AdminUserService; -import cn.iocoder.yudao.module.system.enums.common.SexEnum; -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.collection.MapUtils; -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; -import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -27,11 +27,12 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.IOException; -import java.util.*; +import java.util.Arrays; +import java.util.List; +import java.util.Map; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; @Tag(name = "管理后台 - 用户") @@ -48,7 +49,7 @@ public class UserController { @PostMapping("/create") @Operation(summary = "新增用户") @PreAuthorize("@ss.hasPermission('system:user:create')") - public CommonResult createUser(@Valid @RequestBody UserCreateReqVO reqVO) { + public CommonResult createUser(@Valid @RequestBody UserSaveReqVO reqVO) { Long id = userService.createUser(reqVO); return success(id); } @@ -56,7 +57,7 @@ public class UserController { @PutMapping("update") @Operation(summary = "修改用户") @PreAuthorize("@ss.hasPermission('system:user:update')") - public CommonResult updateUser(@Valid @RequestBody UserUpdateReqVO reqVO) { + public CommonResult updateUser(@Valid @RequestBody UserSaveReqVO reqVO) { userService.updateUser(reqVO); return success(true); } @@ -89,56 +90,27 @@ public class UserController { @GetMapping("/page") @Operation(summary = "获得用户分页列表") @PreAuthorize("@ss.hasPermission('system:user:list')") - public CommonResult> getUserPage(@Valid UserPageReqVO reqVO) { + public CommonResult> getUserPage(@Valid UserPageReqVO pageReqVO) { // 获得用户分页列表 - PageResult pageResult = userService.getUserPage(reqVO); + PageResult pageResult = userService.getUserPage(pageReqVO); if (CollUtil.isEmpty(pageResult.getList())) { - return success(new PageResult<>(pageResult.getTotal())); // 返回空 + return success(new PageResult<>(pageResult.getTotal())); } - - // 获得拼接需要的数据 - Collection deptIds = convertList(pageResult.getList(), AdminUserDO::getDeptId); - Map deptMap = deptService.getDeptMap(deptIds); - // 拼接结果返回 - List userList = new ArrayList<>(pageResult.getList().size()); - pageResult.getList().forEach(user -> { - UserPageItemRespVO respVO = UserConvert.INSTANCE.convert(user); - respVO.setDept(UserConvert.INSTANCE.convert(deptMap.get(user.getDeptId()))); - userList.add(respVO); - }); - return success(new PageResult<>(userList, pageResult.getTotal())); + // 拼接数据 + Map deptMap = deptService.getDeptMap( + convertList(pageResult.getList(), AdminUserDO::getDeptId)); + return success(new PageResult<>(UserConvert.INSTANCE.convertList(pageResult.getList(), deptMap), + pageResult.getTotal())); } - // TODO @芋艿:看看这里怎么统一调整下;客户的选择组件; - @GetMapping("/all") - @Operation(summary = "查询所有用户列表") - public CommonResult> getAllUser() { - // 获得用户分页列表 - List pageResult = userService.getUserList(); - if (CollUtil.isEmpty(pageResult)) { - return success(Collections.emptyList()); // 返回空 - } - - // 获得拼接需要的数据 - Collection deptIds = convertList(pageResult, AdminUserDO::getDeptId); - Map deptMap = deptService.getDeptMap(deptIds); - // 拼接结果返回 - List userList = new ArrayList<>(pageResult.size()); - pageResult.forEach(user -> { - UserPageItemRespVO respVO = UserConvert.INSTANCE.convert(user); - respVO.setDept(UserConvert.INSTANCE.convert(deptMap.get(user.getDeptId()))); - userList.add(respVO); - }); - return success(userList); - } - - @GetMapping("/list-all-simple") + @GetMapping({"/list-all-simple", "/simple-list"}) @Operation(summary = "获取用户精简信息列表", description = "只包含被开启的用户,主要用于前端的下拉选项") public CommonResult> getSimpleUserList() { - // 获用户列表,只要开启状态的 List list = userService.getUserListByStatus(CommonStatusEnum.ENABLE.getStatus()); - // 排序后,返回给前端 - return success(UserConvert.INSTANCE.convertList04(list)); + // 拼接数据 + Map deptMap = deptService.getDeptMap( + convertList(list, AdminUserDO::getDeptId)); + return success(UserConvert.INSTANCE.convertSimpleList(list, deptMap)); } @GetMapping("/get") @@ -147,41 +119,24 @@ public class UserController { @PreAuthorize("@ss.hasPermission('system:user:query')") public CommonResult getUser(@RequestParam("id") Long id) { AdminUserDO user = userService.getUser(id); - // 获得部门数据 + // 拼接数据 DeptDO dept = deptService.getDept(user.getDeptId()); - return success(UserConvert.INSTANCE.convert(user).setDept(UserConvert.INSTANCE.convert(dept))); + return success(UserConvert.INSTANCE.convert(user, dept)); } @GetMapping("/export") @Operation(summary = "导出用户") @PreAuthorize("@ss.hasPermission('system:user:export')") @OperateLog(type = EXPORT) - public void exportUserList(@Validated UserExportReqVO reqVO, + public void exportUserList(@Validated UserPageReqVO exportReqVO, HttpServletResponse response) throws IOException { - // 获得用户列表 - List users = userService.getUserList(reqVO); - - // 获得拼接需要的数据 - Collection deptIds = convertList(users, AdminUserDO::getDeptId); - Map deptMap = deptService.getDeptMap(deptIds); - Map deptLeaderUserMap = userService.getUserMap( - convertSet(deptMap.values(), DeptDO::getLeaderUserId)); - // 拼接数据 - List excelUsers = new ArrayList<>(users.size()); - users.forEach(user -> { - UserExcelVO excelVO = UserConvert.INSTANCE.convert02(user); - // 设置部门 - MapUtils.findAndThen(deptMap, user.getDeptId(), dept -> { - excelVO.setDeptName(dept.getName()); - // 设置部门负责人的名字 - MapUtils.findAndThen(deptLeaderUserMap, dept.getLeaderUserId(), - deptLeaderUser -> excelVO.setDeptLeaderNickname(deptLeaderUser.getNickname())); - }); - excelUsers.add(excelVO); - }); - - // 输出 - ExcelUtils.write(response, "用户数据.xls", "用户列表", UserExcelVO.class, excelUsers); + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = userService.getUserPage(exportReqVO).getList(); + // 输出 Excel + Map deptMap = deptService.getDeptMap( + convertList(list, AdminUserDO::getDeptId)); + ExcelUtils.write(response, "用户数据.xls", "数据", UserRespVO.class, + UserConvert.INSTANCE.convertList(list, deptMap)); } @GetMapping("/get-import-template") @@ -194,7 +149,6 @@ public class UserController { UserImportExcelVO.builder().username("yuanma").deptId(2L).email("yuanma@iocoder.cn").mobile("15601701300") .nickname("源码").status(CommonStatusEnum.DISABLE.getStatus()).sex(SexEnum.FEMALE.getSex()).build() ); - // 输出 ExcelUtils.write(response, "用户导入模板.xls", "用户列表", UserImportExcelVO.class, list); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserProfileController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserProfileController.java index d9fc4a635..5fc4cacde 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserProfileController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserProfileController.java @@ -58,27 +58,18 @@ public class UserProfileController { @GetMapping("/get") @Operation(summary = "获得登录用户信息") @DataPermission(enable = false) // 关闭数据权限,避免只查看自己时,查询不到部门。 - public CommonResult profile() { + public CommonResult getUserProfile() { // 获得用户基本信息 AdminUserDO user = userService.getUser(getLoginUserId()); - UserProfileRespVO resp = UserConvert.INSTANCE.convert03(user); // 获得用户角色 List userRoles = roleService.getRoleListFromCache(permissionService.getUserRoleIdListByUserId(user.getId())); - resp.setRoles(UserConvert.INSTANCE.convertList(userRoles)); // 获得部门信息 - if (user.getDeptId() != null) { - DeptDO dept = deptService.getDept(user.getDeptId()); - resp.setDept(UserConvert.INSTANCE.convert02(dept)); - } + DeptDO dept = user.getDeptId() != null ? deptService.getDept(user.getDeptId()) : null; // 获得岗位信息 - if (CollUtil.isNotEmpty(user.getPostIds())) { - List posts = postService.getPostList(user.getPostIds()); - resp.setPosts(UserConvert.INSTANCE.convertList02(posts)); - } + List posts = CollUtil.isNotEmpty(user.getPostIds()) ? postService.getPostList(user.getPostIds()) : null; // 获得社交用户信息 List socialUsers = socialService.getSocialUserList(user.getId(), UserTypeEnum.ADMIN.getValue()); - resp.setSocialUsers(UserConvert.INSTANCE.convertList03(socialUsers)); - return success(resp); + return success(UserConvert.INSTANCE.convert(user, userRoles, dept, posts, socialUsers)); } @PutMapping("/update") @@ -95,7 +86,8 @@ public class UserProfileController { return success(true); } - @RequestMapping(value = "/update-avatar", method = {RequestMethod.POST, RequestMethod.PUT}) // 解决 uni-app 不支持 Put 上传文件的问题 + @RequestMapping(value = "/update-avatar", + method = {RequestMethod.POST, RequestMethod.PUT}) // 解决 uni-app 不支持 Put 上传文件的问题 @Operation(summary = "上传用户个人头像") public CommonResult updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws Exception { if (file.isEmpty()) { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/profile/UserProfileRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/profile/UserProfileRespVO.java index 6abf1fb65..4f7c71ecd 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/profile/UserProfileRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/profile/UserProfileRespVO.java @@ -1,28 +1,38 @@ package cn.iocoder.yudao.module.system.controller.admin.user.vo.profile; -import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserBaseVO; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSimpleRespVO; +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleSimpleRespVO; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; import java.time.LocalDateTime; import java.util.List; - @Data -@EqualsAndHashCode(callSuper = true) -@NoArgsConstructor -@AllArgsConstructor @Schema(description = "管理后台 - 用户个人中心信息 Response VO") -public class UserProfileRespVO extends UserBaseVO { +public class UserProfileRespVO { @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") private Long id; - @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - private Integer status; + @Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao") + private String username; + + @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") + private String nickname; + + @Schema(description = "用户邮箱", example = "yudao@iocoder.cn") + private String email; + + @Schema(description = "手机号码", example = "15601691300") + private String mobile; + + @Schema(description = "用户性别,参见 SexEnum 枚举类", example = "1") + private Integer sex; + + @Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png") + private String avatar; @Schema(description = "最后登录 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "192.168.1.1") private String loginIp; @@ -36,58 +46,20 @@ public class UserProfileRespVO extends UserBaseVO { /** * 所属角色 */ - private List roles; - + private List roles; /** * 所在部门 */ - private Dept dept; - + private DeptSimpleRespVO dept; /** * 所属岗位数组 */ - private List posts; + private List posts; /** * 社交用户数组 */ private List socialUsers; - @Schema(description = "角色") - @Data - public static class Role { - - @Schema(description = "角色编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - private Long id; - - @Schema(description = "角色名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "普通角色") - private String name; - - } - - @Schema(description = "部门") - @Data - public static class Dept { - - @Schema(description = "部门编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - private Long id; - - @Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "研发部") - private String name; - - } - - @Schema(description = "岗位") - @Data - public static class Post { - - @Schema(description = "岗位编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - private Long id; - - @Schema(description = "岗位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "开发") - private String name; - - } - @Schema(description = "社交用户") @Data public static class SocialUser { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserCreateReqVO.java deleted file mode 100644 index 8b84685f1..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserCreateReqVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.user.vo.user; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import org.hibernate.validator.constraints.Length; - -import javax.validation.constraints.NotEmpty; - -@Schema(description = "管理后台 - 用户创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -public class UserCreateReqVO extends UserBaseVO { - - @Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456") - @NotEmpty(message = "密码不能为空") - @Length(min = 4, max = 16, message = "密码长度为 4-16 位") - private String password; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserExcelVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserExcelVO.java deleted file mode 100644 index 16899c263..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserExcelVO.java +++ /dev/null @@ -1,52 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.user.vo.user; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import cn.iocoder.yudao.module.system.enums.DictTypeConstants; -import com.alibaba.excel.annotation.ExcelProperty; -import lombok.Data; - -import java.time.LocalDateTime; - -/** - * 用户 Excel 导出 VO - */ -@Data -public class UserExcelVO { - - @ExcelProperty("用户编号") - private Long id; - - @ExcelProperty("用户名称") - private String username; - - @ExcelProperty("用户昵称") - private String nickname; - - @ExcelProperty("用户邮箱") - private String email; - - @ExcelProperty("手机号码") - private String mobile; - - @ExcelProperty(value = "用户性别", converter = DictConvert.class) - @DictFormat(DictTypeConstants.USER_SEX) - private Integer sex; - - @ExcelProperty(value = "帐号状态", converter = DictConvert.class) - @DictFormat(DictTypeConstants.COMMON_STATUS) - private Integer status; - - @ExcelProperty("最后登录IP") - private String loginIp; - - @ExcelProperty("最后登录时间") - private LocalDateTime loginDate; - - @ExcelProperty("部门名称") - private String deptName; - - @ExcelProperty("部门负责人") - private String deptLeaderNickname; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserExportReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserExportReqVO.java deleted file mode 100644 index f74771121..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserExportReqVO.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.user.vo.user; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 用户导出 Request VO,参数和 UserPageReqVO 是一致的") -@Data -@NoArgsConstructor -@AllArgsConstructor -public class UserExportReqVO { - - @Schema(description = "用户账号,模糊匹配", example = "yudao") - private String username; - - @Schema(description = "手机号码,模糊匹配", example = "yudao") - private String mobile; - - @Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1") - private Integer status; - - @Schema(description = "创建时间", example = "[2022-07-01 00:00:00,2022-07-01 23:59:59]") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] createTime; - - @Schema(description = "部门编号,同时筛选子部门", example = "1024") - private Long deptId; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserPageItemRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserPageItemRespVO.java deleted file mode 100644 index 3c01ca9bb..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserPageItemRespVO.java +++ /dev/null @@ -1,33 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.user.vo.user; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -@Schema(description = "管理后台 - 用户分页时的信息 Response VO,相比用户基本信息来说,会多部门信息") -@Data -@NoArgsConstructor -@AllArgsConstructor -@EqualsAndHashCode(callSuper = true) -public class UserPageItemRespVO extends UserRespVO { - - /** - * 所在部门 - */ - private Dept dept; - - @Schema(description = "部门") - @Data - public static class Dept { - - @Schema(description = "部门编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - private Long id; - - @Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "研发部") - private String name; - - } - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserRespVO.java index f07b5679f..2837318f9 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserRespVO.java @@ -1,28 +1,72 @@ package cn.iocoder.yudao.module.system.controller.admin.user.vo.user; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; +import lombok.Data; import java.time.LocalDateTime; - +import java.util.Set; @Schema(description = "管理后台 - 用户信息 Response VO") @Data -@NoArgsConstructor -@AllArgsConstructor -@EqualsAndHashCode(callSuper = true) -public class UserRespVO extends UserBaseVO { +@ExcelIgnoreUnannotated +public class UserRespVO{ @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty("用户编号") private Long id; + @Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao") + @ExcelProperty("用户名称") + private String username; + + @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") + @ExcelProperty("用户昵称") + private String nickname; + + @Schema(description = "备注", example = "我是一个用户") + private String remark; + + @Schema(description = "部门ID", example = "我是一个用户") + private Long deptId; + @Schema(description = "部门名称", example = "IT 部") + @ExcelProperty("部门名称") + private String deptName; + + @Schema(description = "岗位编号数组", example = "1") + private Set postIds; + + @Schema(description = "用户邮箱", example = "yudao@iocoder.cn") + @ExcelProperty("用户邮箱") + private String email; + + @Schema(description = "手机号码", example = "15601691300") + @ExcelProperty("手机号码") + private String mobile; + + @Schema(description = "用户性别,参见 SexEnum 枚举类", example = "1") + @ExcelProperty(value = "用户性别", converter = DictConvert.class) + @DictFormat(DictTypeConstants.USER_SEX) + private Integer sex; + + @Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png") + private String avatar; + @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "帐号状态", converter = DictConvert.class) + @DictFormat(DictTypeConstants.COMMON_STATUS) private Integer status; @Schema(description = "最后登录 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "192.168.1.1") + @ExcelProperty("最后登录IP") private String loginIp; @Schema(description = "最后登录时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") + @ExcelProperty("最后登录时间") private LocalDateTime loginDate; @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserSaveReqVO.java similarity index 62% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserBaseVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserSaveReqVO.java index 5008cb2d0..4ab2eddd2 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserSaveReqVO.java @@ -1,21 +1,22 @@ package cn.iocoder.yudao.module.system.controller.admin.user.vo.user; +import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.validation.Mobile; +import com.fasterxml.jackson.annotation.JsonIgnore; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import org.hibernate.validator.constraints.Length; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Pattern; -import javax.validation.constraints.Size; +import javax.validation.constraints.*; import java.util.Set; -/** - * 用户 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ +@Schema(description = "管理后台 - 用户创建/修改 Request VO") @Data -public class UserBaseVO { +public class UserSaveReqVO { + + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @NotNull(message = "用户编号不能为空") + private Long id; @Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao") @NotBlank(message = "用户账号不能为空") @@ -51,4 +52,17 @@ public class UserBaseVO { @Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png") private String avatar; + // ========== 仅【创建】时,需要传递的字段 ========== + + @Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456") + @Length(min = 4, max = 16, message = "密码长度为 4-16 位") + private String password; + + @AssertTrue(message = "密码不能为空") + @JsonIgnore + public boolean isPasswordValid() { + return id != null // 修改时,不需要传递 + || (ObjectUtil.isAllNotEmpty(password)); // 新增时,必须都传递 password + } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserSimpleRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserSimpleRespVO.java index f021d7213..6dac2869d 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserSimpleRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserSimpleRespVO.java @@ -17,4 +17,9 @@ public class UserSimpleRespVO { @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") private String nickname; + @Schema(description = "部门ID", example = "我是一个用户") + private Long deptId; + @Schema(description = "部门名称", example = "IT 部") + private String deptName; + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserUpdateReqVO.java deleted file mode 100644 index 2267c506f..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserUpdateReqVO.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.user.vo.user; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 用户更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -public class UserUpdateReqVO extends UserBaseVO { - - @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "用户编号不能为空") - private Long id; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/tenant/TenantConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/tenant/TenantConvert.java index eeb30fcf8..669954d7e 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/tenant/TenantConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/tenant/TenantConvert.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.system.convert.tenant; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantSaveReqVO; -import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserCreateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -15,8 +15,8 @@ public interface TenantConvert { TenantConvert INSTANCE = Mappers.getMapper(TenantConvert.class); - default UserCreateReqVO convert02(TenantSaveReqVO bean) { - UserCreateReqVO reqVO = new UserCreateReqVO(); + default UserSaveReqVO convert02(TenantSaveReqVO bean) { + UserSaveReqVO reqVO = new UserSaveReqVO(); reqVO.setUsername(bean.getUsername()); reqVO.setPassword(bean.getPassword()); reqVO.setNickname(bean.getContactName()).setMobile(bean.getContactMobile()); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/user/UserConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/user/UserConvert.java index 9a2aac3c5..b58be2195 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/user/UserConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/user/UserConvert.java @@ -1,10 +1,14 @@ package cn.iocoder.yudao.module.system.convert.user; -import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSimpleRespVO; +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleSimpleRespVO; import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileRespVO; -import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO; -import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.*; +import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserRespVO; +import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSimpleRespVO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; @@ -14,42 +18,41 @@ import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; import java.util.List; +import java.util.Map; @Mapper public interface UserConvert { UserConvert INSTANCE = Mappers.getMapper(UserConvert.class); - UserPageItemRespVO convert(AdminUserDO bean); + default List convertList(List list, Map deptMap) { + return CollectionUtils.convertList(list, user -> convert(user, deptMap.get(user.getDeptId()))); + } - UserPageItemRespVO.Dept convert(DeptDO bean); + default UserRespVO convert(AdminUserDO user, DeptDO dept) { + UserRespVO userVO = BeanUtils.toBean(user, UserRespVO.class); + if (dept != null) { + userVO.setDeptName(dept.getName()); + } + return userVO; + } - AdminUserDO convert(UserCreateReqVO bean); + default List convertSimpleList(List list, Map deptMap) { + return CollectionUtils.convertList(list, user -> { + UserSimpleRespVO userVO = BeanUtils.toBean(user, UserSimpleRespVO.class); + MapUtils.findAndThen(deptMap, user.getDeptId(), dept -> userVO.setDeptName(dept.getName())); + return userVO; + }); + } - AdminUserDO convert(UserUpdateReqVO bean); - - UserExcelVO convert02(AdminUserDO bean); - - AdminUserDO convert(UserImportExcelVO bean); - - UserProfileRespVO convert03(AdminUserDO bean); - - List convertList(List list); - - UserProfileRespVO.Dept convert02(DeptDO bean); - - AdminUserDO convert(UserProfileUpdateReqVO bean); - - AdminUserDO convert(UserProfileUpdatePasswordReqVO bean); - - List convertList02(List list); - - List convertList03(List list); - - List convertList04(List list); - - AdminUserRespDTO convert4(AdminUserDO bean); - - List convertList4(List users); + default UserProfileRespVO convert(AdminUserDO user, List userRoles, + DeptDO dept, List posts, List socialUsers) { + UserProfileRespVO userVO = BeanUtils.toBean(user, UserProfileRespVO.class); + userVO.setRoles(BeanUtils.toBean(userRoles, RoleSimpleRespVO.class)); + userVO.setDept(BeanUtils.toBean(dept, DeptSimpleRespVO.class)); + userVO.setPosts(BeanUtils.toBean(posts, PostSimpleRespVO.class)); + userVO.setSocialUsers(BeanUtils.toBean(socialUsers, UserProfileRespVO.SocialUser.class)); + return userVO; + } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/user/AdminUserMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/user/AdminUserMapper.java index 4e0827210..75bf3fa47 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/user/AdminUserMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/user/AdminUserMapper.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.dal.mysql.user; 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.user.vo.user.UserExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; import org.apache.ibatis.annotations.Mapper; @@ -36,15 +35,6 @@ public interface AdminUserMapper extends BaseMapperX { .orderByDesc(AdminUserDO::getId)); } - default List selectList(UserExportReqVO reqVO, Collection deptIds) { - return selectList(new LambdaQueryWrapperX() - .likeIfPresent(AdminUserDO::getUsername, reqVO.getUsername()) - .likeIfPresent(AdminUserDO::getMobile, reqVO.getMobile()) - .eqIfPresent(AdminUserDO::getStatus, reqVO.getStatus()) - .betweenIfPresent(AdminUserDO::getCreateTime, reqVO.getCreateTime()) - .inIfPresent(AdminUserDO::getDeptId, deptIds)); - } - default List selectListByNickname(String nickname) { return selectList(new LambdaQueryWrapperX().like(AdminUserDO::getNickname, nickname)); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java index 569969d51..e715a6968 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java @@ -22,17 +22,17 @@ public interface AdminUserService { /** * 创建用户 * - * @param reqVO 用户信息 + * @param createReqVO 用户信息 * @return 用户编号 */ - Long createUser(@Valid UserCreateReqVO reqVO); + Long createUser(@Valid UserSaveReqVO createReqVO); /** * 修改用户 * - * @param reqVO 用户信息 + * @param updateReqVO 用户信息 */ - void updateUser(@Valid UserUpdateReqVO reqVO); + void updateUser(@Valid UserSaveReqVO updateReqVO); /** * 更新用户的最后登陆信息 @@ -167,14 +167,6 @@ public interface AdminUserService { return CollectionUtils.convertMap(getUserList(ids), AdminUserDO::getId); } - /** - * 获得用户列表 - * - * @param reqVO 列表请求 - * @return 用户列表 - */ - List getUserList(UserExportReqVO reqVO); - /** * 获得用户列表,基于昵称模糊匹配 * @@ -209,10 +201,4 @@ public interface AdminUserService { */ boolean isPasswordMatch(String rawPassword, String encodedPassword); - /** - * 获取所有用户列表 - * - * @return 用户列表 - */ - List getUserList(); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java index 88bb8ea1e..5f438708c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java @@ -8,12 +8,15 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils; import cn.iocoder.yudao.module.infra.api.file.FileApi; import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO; import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.*; -import cn.iocoder.yudao.module.system.convert.user.UserConvert; +import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserImportExcelVO; +import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserImportRespVO; +import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.UserPostDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; @@ -76,7 +79,7 @@ public class AdminUserServiceImpl implements AdminUserService { @Override @Transactional(rollbackFor = Exception.class) - public Long createUser(UserCreateReqVO reqVO) { + public Long createUser(UserSaveReqVO createReqVO) { // 校验账户配合 tenantService.handleTenantInfo(tenant -> { long count = userMapper.selectCount(); @@ -85,12 +88,12 @@ public class AdminUserServiceImpl implements AdminUserService { } }); // 校验正确性 - validateUserForCreateOrUpdate(null, reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), - reqVO.getDeptId(), reqVO.getPostIds()); + validateUserForCreateOrUpdate(null, createReqVO.getUsername(), + createReqVO.getMobile(), createReqVO.getEmail(), createReqVO.getDeptId(), createReqVO.getPostIds()); // 插入用户 - AdminUserDO user = UserConvert.INSTANCE.convert(reqVO); + AdminUserDO user = BeanUtils.toBean(createReqVO, AdminUserDO.class); user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启 - user.setPassword(encodePassword(reqVO.getPassword())); // 加密密码 + user.setPassword(encodePassword(createReqVO.getPassword())); // 加密密码 userMapper.insert(user); // 插入关联岗位 if (CollectionUtil.isNotEmpty(user.getPostIds())) { @@ -102,18 +105,19 @@ public class AdminUserServiceImpl implements AdminUserService { @Override @Transactional(rollbackFor = Exception.class) - public void updateUser(UserUpdateReqVO reqVO) { + public void updateUser(UserSaveReqVO updateReqVO) { + updateReqVO.setPassword(null); // 特殊:此处不更新密码 // 校验正确性 - validateUserForCreateOrUpdate(reqVO.getId(), reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), - reqVO.getDeptId(), reqVO.getPostIds()); + validateUserForCreateOrUpdate(updateReqVO.getId(), updateReqVO.getUsername(), + updateReqVO.getMobile(), updateReqVO.getEmail(), updateReqVO.getDeptId(), updateReqVO.getPostIds()); // 更新用户 - AdminUserDO updateObj = UserConvert.INSTANCE.convert(reqVO); + AdminUserDO updateObj = BeanUtils.toBean(updateReqVO, AdminUserDO.class); userMapper.updateById(updateObj); // 更新岗位 - updateUserPost(reqVO, updateObj); + updateUserPost(updateReqVO, updateObj); } - private void updateUserPost(UserUpdateReqVO reqVO, AdminUserDO updateObj) { + private void updateUserPost(UserSaveReqVO reqVO, AdminUserDO updateObj) { Long userId = reqVO.getId(); Set dbPostIds = convertSet(userPostMapper.selectListByUserId(userId), UserPostDO::getPostId); // 计算新增和删除的岗位编号 @@ -142,7 +146,7 @@ public class AdminUserServiceImpl implements AdminUserService { validateEmailUnique(id, reqVO.getEmail()); validateMobileUnique(id, reqVO.getMobile()); // 执行更新 - userMapper.updateById(UserConvert.INSTANCE.convert(reqVO).setId(id)); + userMapper.updateById(BeanUtils.toBean(reqVO, AdminUserDO.class).setId(id)); } @Override @@ -156,7 +160,7 @@ public class AdminUserServiceImpl implements AdminUserService { } @Override - public String updateUserAvatar(Long id, InputStream avatarFile) throws Exception { + public String updateUserAvatar(Long id, InputStream avatarFile) { validateUserExists(id); // 存储文件 String avatar = fileApi.createFile(IoUtil.readBytes(avatarFile)); @@ -271,11 +275,6 @@ public class AdminUserServiceImpl implements AdminUserService { }); } - @Override - public List getUserList(UserExportReqVO reqVO) { - return userMapper.selectList(reqVO, getDeptCondition(reqVO.getDeptId())); - } - @Override public List getUserListByNickname(String nickname) { return userMapper.selectListByNickname(nickname); @@ -415,7 +414,7 @@ public class AdminUserServiceImpl implements AdminUserService { // 判断如果不存在,在进行插入 AdminUserDO existUser = userMapper.selectByUsername(importUser.getUsername()); if (existUser == null) { - userMapper.insert(UserConvert.INSTANCE.convert(importUser) + userMapper.insert(BeanUtils.toBean(importUser, AdminUserDO.class) .setPassword(encodePassword(userInitPassword)).setPostIds(new HashSet<>())); // 设置默认密码及空岗位编号数组 respVO.getCreateUsernames().add(importUser.getUsername()); return; @@ -425,7 +424,7 @@ public class AdminUserServiceImpl implements AdminUserService { respVO.getFailureUsernames().put(importUser.getUsername(), USER_USERNAME_EXISTS.getMsg()); return; } - AdminUserDO updateUser = UserConvert.INSTANCE.convert(importUser); + AdminUserDO updateUser = BeanUtils.toBean(importUser, AdminUserDO.class); updateUser.setId(existUser.getId()); userMapper.updateById(updateUser); respVO.getUpdateUsernames().add(importUser.getUsername()); @@ -443,16 +442,6 @@ public class AdminUserServiceImpl implements AdminUserService { return passwordEncoder.matches(rawPassword, encodedPassword); } - /** - * 获取所有用户列表 - * - * @return 用户列表 - */ - @Override - public List getUserList() { - return userMapper.selectList(); - } - /** * 对密码进行加密 * diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImplTest.java index acc4357cc..03897a83f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImplTest.java @@ -80,11 +80,11 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest { @Test public void testCreatUser_success() { // 准备参数 - UserCreateReqVO reqVO = randomPojo(UserCreateReqVO.class, o -> { + UserSaveReqVO reqVO = randomPojo(UserSaveReqVO.class, o -> { o.setSex(RandomUtil.randomEle(SexEnum.values()).getSex()); o.setMobile(randomString()); o.setPostIds(asSet(1L, 2L)); - }); + }).setId(null); // 避免 id 被赋值 // mock 账户额度充足 TenantDO tenant = randomPojo(TenantDO.class, o -> o.setAccountCount(1)); doNothing().when(tenantService).handleTenantInfo(argThat(handler -> { @@ -111,7 +111,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest { Long userId = userService.createUser(reqVO); // 断言 AdminUserDO user = userMapper.selectById(userId); - assertPojoEquals(reqVO, user, "password"); + assertPojoEquals(reqVO, user, "password", "id"); assertEquals("yudaoyuanma", user.getPassword()); assertEquals(CommonStatusEnum.ENABLE.getStatus(), user.getStatus()); // 断言关联岗位 @@ -123,7 +123,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest { @Test public void testCreatUser_max() { // 准备参数 - UserCreateReqVO reqVO = randomPojo(UserCreateReqVO.class); + UserSaveReqVO reqVO = randomPojo(UserSaveReqVO.class); // mock 账户额度不足 TenantDO tenant = randomPojo(TenantDO.class, o -> o.setAccountCount(-1)); doNothing().when(tenantService).handleTenantInfo(argThat(handler -> { @@ -143,7 +143,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest { userPostMapper.insert(new UserPostDO().setUserId(dbUser.getId()).setPostId(1L)); userPostMapper.insert(new UserPostDO().setUserId(dbUser.getId()).setPostId(2L)); // 准备参数 - UserUpdateReqVO reqVO = randomPojo(UserUpdateReqVO.class, o -> { + UserSaveReqVO reqVO = randomPojo(UserSaveReqVO.class, o -> { o.setId(dbUser.getId()); o.setSex(RandomUtil.randomEle(SexEnum.values()).getSex()); o.setMobile(randomString()); @@ -167,7 +167,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest { userService.updateUser(reqVO); // 断言 AdminUserDO user = userMapper.selectById(reqVO.getId()); - assertPojoEquals(reqVO, user); + assertPojoEquals(reqVO, user, "password"); // 断言关联岗位 List userPosts = userPostMapper.selectListByUserId(user.getId()); assertEquals(2L, userPosts.get(0).getPostId()); @@ -355,28 +355,6 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest { assertPojoEquals(dbUser, pageResult.getList().get(0)); } - @Test - public void testGetUserList_export() { - // mock 数据 - AdminUserDO dbUser = initGetUserPageData(); - // 准备参数 - UserExportReqVO reqVO = new UserExportReqVO(); - reqVO.setUsername("tu"); - reqVO.setMobile("1560"); - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); - reqVO.setCreateTime(buildBetweenTime(2020, 12, 1, 2020, 12, 24)); - reqVO.setDeptId(1L); // 其中,1L 是 2L 的父部门 - // mock 方法 - List deptList = newArrayList(randomPojo(DeptDO.class, o -> o.setId(2L))); - when(deptService.getChildDeptList(eq(reqVO.getDeptId()))).thenReturn(deptList); - - // 调用 - List list = userService.getUserList(reqVO); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbUser, list.get(0)); - } - /** * 初始化 getUserPage 方法的测试数据 */ From 645e6f3cc8ff97b911a0b25763f6248f9b96c06a Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 3 Dec 2023 09:57:34 +0800 Subject: [PATCH 15/19] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20confi?= =?UTF-8?q?g=20=E6=A8=A1=E5=9D=97=E7=9A=84=20VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/config/ConfigController.java | 23 +++++----- .../admin/config/vo/ConfigCreateReqVO.java | 20 -------- .../admin/config/vo/ConfigExcelVO.java | 46 ------------------- .../admin/config/vo/ConfigExportReqVO.java | 28 ----------- .../admin/config/vo/ConfigRespVO.java | 40 +++++++++++++--- ...ConfigBaseVO.java => ConfigSaveReqVO.java} | 21 +++++---- .../admin/config/vo/ConfigUpdateReqVO.java | 20 -------- .../infra/convert/config/ConfigConvert.java | 13 ++---- .../infra/dal/mysql/config/ConfigMapper.java | 11 ----- .../infra/service/config/ConfigService.java | 22 ++------- .../service/config/ConfigServiceImpl.java | 44 ++++++------------ .../service/config/ConfigServiceImplTest.java | 44 ++---------------- 12 files changed, 87 insertions(+), 245 deletions(-) delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigCreateReqVO.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigExcelVO.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigExportReqVO.java rename yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/{ConfigBaseVO.java => ConfigSaveReqVO.java} (63%) delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigUpdateReqVO.java diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/ConfigController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/ConfigController.java index f9a6a8e9e..bbfea5ecd 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/ConfigController.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/ConfigController.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.infra.controller.admin.config; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; @@ -38,15 +39,15 @@ public class ConfigController { @PostMapping("/create") @Operation(summary = "创建参数配置") @PreAuthorize("@ss.hasPermission('infra:config:create')") - public CommonResult createConfig(@Valid @RequestBody ConfigCreateReqVO reqVO) { - return success(configService.createConfig(reqVO)); + public CommonResult createConfig(@Valid @RequestBody ConfigSaveReqVO createReqVO) { + return success(configService.createConfig(createReqVO)); } @PutMapping("/update") @Operation(summary = "修改参数配置") @PreAuthorize("@ss.hasPermission('infra:config:update')") - public CommonResult updateConfig(@Valid @RequestBody ConfigUpdateReqVO reqVO) { - configService.updateConfig(reqVO); + public CommonResult updateConfig(@Valid @RequestBody ConfigSaveReqVO updateReqVO) { + configService.updateConfig(updateReqVO); return success(true); } @@ -84,8 +85,8 @@ public class ConfigController { @GetMapping("/page") @Operation(summary = "获取参数配置分页") @PreAuthorize("@ss.hasPermission('infra:config:query')") - public CommonResult> getConfigPage(@Valid ConfigPageReqVO reqVO) { - PageResult page = configService.getConfigPage(reqVO); + public CommonResult> getConfigPage(@Valid ConfigPageReqVO pageReqVO) { + PageResult page = configService.getConfigPage(pageReqVO); return success(ConfigConvert.INSTANCE.convertPage(page)); } @@ -93,13 +94,13 @@ public class ConfigController { @Operation(summary = "导出参数配置") @PreAuthorize("@ss.hasPermission('infra:config:export')") @OperateLog(type = EXPORT) - public void exportConfig(@Valid ConfigExportReqVO reqVO, + public void exportConfig(@Valid ConfigPageReqVO exportReqVO, HttpServletResponse response) throws IOException { - List list = configService.getConfigList(reqVO); - // 拼接数据 - List datas = ConfigConvert.INSTANCE.convertList(list); + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = configService.getConfigPage(exportReqVO).getList(); // 输出 - ExcelUtils.write(response, "参数配置.xls", "数据", ConfigExcelVO.class, datas); + ExcelUtils.write(response, "参数配置.xls", "数据", ConfigRespVO.class, + ConfigConvert.INSTANCE.convertList(list)); } } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigCreateReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigCreateReqVO.java deleted file mode 100644 index ebbdf67fc..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigCreateReqVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.config.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Size; - -@Schema(description = "管理后台 - 参数配置创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -public class ConfigCreateReqVO extends ConfigBaseVO { - - @Schema(description = "参数键名", requiredMode = Schema.RequiredMode.REQUIRED, example = "yunai.db.username") - @NotBlank(message = "参数键名长度不能为空") - @Size(max = 100, message = "参数键名长度不能超过100个字符") - private String key; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigExcelVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigExcelVO.java deleted file mode 100644 index 12611032a..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigExcelVO.java +++ /dev/null @@ -1,46 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.config.vo; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; -import com.alibaba.excel.annotation.ExcelProperty; -import lombok.Data; - -import java.time.LocalDateTime; - -/** - * 参数配置 Excel 导出响应 VO - */ -@Data -public class ConfigExcelVO { - - @ExcelProperty("参数配置序号") - private Long id; - - @ExcelProperty("参数键名") - private String configKey; - - @ExcelProperty("参数分类") - private String category; - - @ExcelProperty("参数名称") - private String name; - - @ExcelProperty("参数键值") - private String value; - - @ExcelProperty(value = "参数类型", converter = DictConvert.class) - @DictFormat(DictTypeConstants.CONFIG_TYPE) - private Integer type; - - @ExcelProperty(value = "是否可见", converter = DictConvert.class) - @DictFormat(DictTypeConstants.BOOLEAN_STRING) - private Boolean visible; - - @ExcelProperty("备注") - private String remark; - - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigExportReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigExportReqVO.java deleted file mode 100644 index 78d289a5b..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigExportReqVO.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.config.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 参数配置导出 Request VO") -@Data -public class ConfigExportReqVO { - - @Schema(description = "参数名称", example = "模糊匹配") - private String name; - - @Schema(description = "参数键名,模糊匹配", example = "yunai.db.username") - private String key; - - @Schema(description = "参数类型,参见 SysConfigTypeEnum 枚举", example = "1") - private Integer type; - - @Schema(description = "创建时间", example = "[2022-07-01 00:00:00,2022-07-01 23:59:59]") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] createTime; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigRespVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigRespVO.java index 8c3d51e7e..b4f642f69 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigRespVO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigRespVO.java @@ -1,30 +1,56 @@ package cn.iocoder.yudao.module.infra.controller.admin.config.vo; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Size; import java.time.LocalDateTime; @Schema(description = "管理后台 - 参数配置信息 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -public class ConfigRespVO extends ConfigBaseVO { +@ExcelIgnoreUnannotated +public class ConfigRespVO { @Schema(description = "参数配置序号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("参数配置序号") private Long id; + @Schema(description = "参数分类", requiredMode = Schema.RequiredMode.REQUIRED, example = "biz") + @ExcelProperty("参数分类") + private String category; + + @Schema(description = "参数名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "数据库名") + @ExcelProperty("参数名称") + private String name; + @Schema(description = "参数键名", requiredMode = Schema.RequiredMode.REQUIRED, example = "yunai.db.username") - @NotBlank(message = "参数键名长度不能为空") - @Size(max = 100, message = "参数键名长度不能超过100个字符") + @ExcelProperty("参数键名") private String key; + @Schema(description = "参数键值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("参数键值") + private String value; + @Schema(description = "参数类型,参见 SysConfigTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "参数类型", converter = DictConvert.class) + @DictFormat(DictTypeConstants.CONFIG_TYPE) private Integer type; + @Schema(description = "是否可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") + @ExcelProperty(value = "是否可见", converter = DictConvert.class) + @DictFormat(DictTypeConstants.BOOLEAN_STRING) + private Boolean visible; + + @Schema(description = "备注", example = "备注一下很帅气!") + @ExcelProperty("备注") + private String remark; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") + @ExcelProperty("创建时间") private LocalDateTime createTime; } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigBaseVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigSaveReqVO.java similarity index 63% rename from yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigBaseVO.java rename to yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigSaveReqVO.java index acd3beee6..59aaa4848 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigBaseVO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigSaveReqVO.java @@ -8,26 +8,31 @@ import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; -/** - * 参数配置 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ +@Schema(description = "管理后台 - 参数配置创建/修改 Request VO") @Data -public class ConfigBaseVO { +public class ConfigSaveReqVO { + + @Schema(description = "参数配置序号", example = "1024") + private Long id; @Schema(description = "参数分组", requiredMode = Schema.RequiredMode.REQUIRED, example = "biz") @NotEmpty(message = "参数分组不能为空") - @Size(max = 50, message = "参数名称不能超过50个字符") + @Size(max = 50, message = "参数名称不能超过 50 个字符") private String category; @Schema(description = "参数名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "数据库名") @NotBlank(message = "参数名称不能为空") - @Size(max = 100, message = "参数名称不能超过100个字符") + @Size(max = 100, message = "参数名称不能超过 100 个字符") private String name; + @Schema(description = "参数键名", requiredMode = Schema.RequiredMode.REQUIRED, example = "yunai.db.username") + @NotBlank(message = "参数键名长度不能为空") + @Size(max = 100, message = "参数键名长度不能超过 100 个字符") + private String key; + @Schema(description = "参数键值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @NotBlank(message = "参数键值不能为空") - @Size(max = 500, message = "参数键值长度不能超过500个字符") + @Size(max = 500, message = "参数键值长度不能超过 500 个字符") private String value; @Schema(description = "是否可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigUpdateReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigUpdateReqVO.java deleted file mode 100644 index b2497b1cd..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigUpdateReqVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.config.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 参数配置创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class ConfigUpdateReqVO extends ConfigBaseVO { - - @Schema(description = "参数配置序号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "参数配置编号不能为空") - private Long id; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/config/ConfigConvert.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/config/ConfigConvert.java index 94bcc0eae..92094b0a9 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/config/ConfigConvert.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/config/ConfigConvert.java @@ -1,10 +1,8 @@ package cn.iocoder.yudao.module.infra.convert.config; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigCreateReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigExcelVO; import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigRespVO; -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigUpdateReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; import org.mapstruct.Mapper; import org.mapstruct.Mapping; @@ -19,15 +17,12 @@ public interface ConfigConvert { PageResult convertPage(PageResult page); + List convertList(List list); + @Mapping(source = "configKey", target = "key") ConfigRespVO convert(ConfigDO bean); @Mapping(source = "key", target = "configKey") - ConfigDO convert(ConfigCreateReqVO bean); - - ConfigDO convert(ConfigUpdateReqVO bean); - - @Mapping(source = "configKey", target = "key") - List convertList(List list); + ConfigDO convert(ConfigSaveReqVO bean); } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/config/ConfigMapper.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/config/ConfigMapper.java index 49eea5517..466403c6e 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/config/ConfigMapper.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/config/ConfigMapper.java @@ -3,13 +3,10 @@ package cn.iocoder.yudao.module.infra.dal.mysql.config; 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.infra.controller.admin.config.vo.ConfigExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigPageReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; import org.apache.ibatis.annotations.Mapper; -import java.util.List; - @Mapper public interface ConfigMapper extends BaseMapperX { @@ -25,12 +22,4 @@ public interface ConfigMapper extends BaseMapperX { .betweenIfPresent(ConfigDO::getCreateTime, reqVO.getCreateTime())); } - default List selectList(ConfigExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .likeIfPresent(ConfigDO::getName, reqVO.getName()) - .likeIfPresent(ConfigDO::getConfigKey, reqVO.getKey()) - .eqIfPresent(ConfigDO::getType, reqVO.getType()) - .betweenIfPresent(ConfigDO::getCreateTime, reqVO.getCreateTime())); - } - } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/config/ConfigService.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/config/ConfigService.java index abd82e54a..a6979023f 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/config/ConfigService.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/config/ConfigService.java @@ -1,14 +1,11 @@ package cn.iocoder.yudao.module.infra.service.config; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigCreateReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigPageReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigUpdateReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; import javax.validation.Valid; -import java.util.List; /** * 参数配置 Service 接口 @@ -20,17 +17,17 @@ public interface ConfigService { /** * 创建参数配置 * - * @param reqVO 创建信息 + * @param createReqVO 创建信息 * @return 配置编号 */ - Long createConfig(@Valid ConfigCreateReqVO reqVO); + Long createConfig(@Valid ConfigSaveReqVO createReqVO); /** * 更新参数配置 * - * @param reqVO 更新信息 + * @param updateReqVO 更新信息 */ - void updateConfig(@Valid ConfigUpdateReqVO reqVO); + void updateConfig(@Valid ConfigSaveReqVO updateReqVO); /** * 删除参数配置 @@ -63,13 +60,4 @@ public interface ConfigService { */ PageResult getConfigPage(@Valid ConfigPageReqVO reqVO); - /** - * 获得参数配置列表 - * - * @param reqVO 列表 - * @return 列表 - */ - List getConfigList(@Valid ConfigExportReqVO reqVO); - - } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceImpl.java index 51c912be7..6d14ad9fc 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceImpl.java @@ -1,11 +1,8 @@ package cn.iocoder.yudao.module.infra.service.config; -import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigCreateReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigPageReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigUpdateReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigSaveReqVO; import cn.iocoder.yudao.module.infra.convert.config.ConfigConvert; import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; import cn.iocoder.yudao.module.infra.dal.mysql.config.ConfigMapper; @@ -16,7 +13,6 @@ import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; @@ -33,22 +29,26 @@ public class ConfigServiceImpl implements ConfigService { private ConfigMapper configMapper; @Override - public Long createConfig(ConfigCreateReqVO reqVO) { - // 校验正确性 - validateConfigForCreateOrUpdate(null, reqVO.getKey()); + public Long createConfig(ConfigSaveReqVO createReqVO) { + // 校验参数配置 key 的唯一性 + validateConfigKeyUnique(null, createReqVO.getKey()); + // 插入参数配置 - ConfigDO config = ConfigConvert.INSTANCE.convert(reqVO); + ConfigDO config = ConfigConvert.INSTANCE.convert(createReqVO); config.setType(ConfigTypeEnum.CUSTOM.getType()); configMapper.insert(config); return config.getId(); } @Override - public void updateConfig(ConfigUpdateReqVO reqVO) { - // 校验正确性 - validateConfigForCreateOrUpdate(reqVO.getId(), null); // 不允许更新 key + public void updateConfig(ConfigSaveReqVO updateReqVO) { + // 校验自己存在 + validateConfigExists(updateReqVO.getId()); + // 校验参数配置 key 的唯一性 + validateConfigKeyUnique(updateReqVO.getId(), updateReqVO.getKey()); + // 更新参数配置 - ConfigDO updateObj = ConfigConvert.INSTANCE.convert(reqVO); + ConfigDO updateObj = ConfigConvert.INSTANCE.convert(updateReqVO); configMapper.updateById(updateObj); } @@ -75,22 +75,8 @@ public class ConfigServiceImpl implements ConfigService { } @Override - public PageResult getConfigPage(ConfigPageReqVO reqVO) { - return configMapper.selectPage(reqVO); - } - - @Override - public List getConfigList(ConfigExportReqVO reqVO) { - return configMapper.selectList(reqVO); - } - - private void validateConfigForCreateOrUpdate(Long id, String key) { - // 校验自己存在 - validateConfigExists(id); - // 校验参数配置 key 的唯一性 - if (StrUtil.isNotEmpty(key)) { - validateConfigKeyUnique(id, key); - } + public PageResult getConfigPage(ConfigPageReqVO pageReqVO) { + return configMapper.selectPage(pageReqVO); } @VisibleForTesting diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceImplTest.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceImplTest.java index 428b20522..1c1f1f3e8 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceImplTest.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceImplTest.java @@ -4,10 +4,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.framework.test.core.util.RandomUtils; -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigCreateReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigPageReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigUpdateReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; import cn.iocoder.yudao.module.infra.dal.mysql.config.ConfigMapper; import cn.iocoder.yudao.module.infra.enums.config.ConfigTypeEnum; @@ -15,7 +13,6 @@ import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Import; import javax.annotation.Resource; -import java.util.List; import java.util.function.Consumer; import static cn.hutool.core.util.RandomUtil.randomEle; @@ -40,7 +37,8 @@ public class ConfigServiceImplTest extends BaseDbUnitTest { @Test public void testCreateConfig_success() { // 准备参数 - ConfigCreateReqVO reqVO = randomPojo(ConfigCreateReqVO.class); + ConfigSaveReqVO reqVO = randomPojo(ConfigSaveReqVO.class) + .setId(null); // 防止 id 被赋值,导致唯一性校验失败 // 调用 Long configId = configService.createConfig(reqVO); @@ -48,7 +46,7 @@ public class ConfigServiceImplTest extends BaseDbUnitTest { assertNotNull(configId); // 校验记录的属性是否正确 ConfigDO config = configMapper.selectById(configId); - assertPojoEquals(reqVO, config); + assertPojoEquals(reqVO, config, "id"); assertEquals(ConfigTypeEnum.CUSTOM.getType(), config.getType()); } @@ -58,7 +56,7 @@ public class ConfigServiceImplTest extends BaseDbUnitTest { ConfigDO dbConfig = randomConfigDO(); configMapper.insert(dbConfig);// @Sql: 先插入出一条存在的数据 // 准备参数 - ConfigUpdateReqVO reqVO = randomPojo(ConfigUpdateReqVO.class, o -> { + ConfigSaveReqVO reqVO = randomPojo(ConfigSaveReqVO.class, o -> { o.setId(dbConfig.getId()); // 设置更新的 ID }); @@ -178,38 +176,6 @@ public class ConfigServiceImplTest extends BaseDbUnitTest { assertPojoEquals(dbConfig, pageResult.getList().get(0)); } - @Test - public void testGetConfigList() { - // mock 数据 - ConfigDO dbConfig = randomConfigDO(o -> { // 等会查询到 - o.setName("芋艿"); - o.setConfigKey("yunai"); - o.setType(ConfigTypeEnum.SYSTEM.getType()); - o.setCreateTime(buildTime(2021, 2, 1)); - }); - configMapper.insert(dbConfig); - // 测试 name 不匹配 - configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setName("土豆"))); - // 测试 key 不匹配 - configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setConfigKey("tudou"))); - // 测试 type 不匹配 - configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setType(ConfigTypeEnum.CUSTOM.getType()))); - // 测试 createTime 不匹配 - configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1)))); - // 准备参数 - ConfigExportReqVO reqVO = new ConfigExportReqVO(); - reqVO.setName("艿"); - reqVO.setKey("nai"); - reqVO.setType(ConfigTypeEnum.SYSTEM.getType()); - reqVO.setCreateTime(buildBetweenTime(2021, 1, 15, 2021, 2, 15)); - - // 调用 - List list = configService.getConfigList(reqVO); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbConfig, list.get(0)); - } - @Test public void testGetConfig() { // mock 数据 From fc3bb430c39a477d5cd007009b397d1fcd77fb0a Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 3 Dec 2023 10:06:56 +0800 Subject: [PATCH 16/19] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20dataS?= =?UTF-8?q?ourceConfig=20=E6=A8=A1=E5=9D=97=E7=9A=84=20VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/db/DataSourceConfigController.java | 19 ++++++------ .../db/vo/DataSourceConfigCreateReqVO.java | 17 ----------- .../admin/db/vo/DataSourceConfigRespVO.java | 15 +++++++--- ...VO.java => DataSourceConfigSaveReqVO.java} | 15 ++++++---- .../db/vo/DataSourceConfigUpdateReqVO.java | 21 ------------- .../convert/db/DataSourceConfigConvert.java | 30 ------------------- .../service/db/DataSourceConfigService.java | 7 ++--- .../db/DataSourceConfigServiceImpl.java | 19 ++++++------ .../db/DataSourceConfigServiceImplTest.java | 12 ++++---- 9 files changed, 48 insertions(+), 107 deletions(-) delete mode 100755 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/vo/DataSourceConfigCreateReqVO.java rename yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/vo/{DataSourceConfigBaseVO.java => DataSourceConfigSaveReqVO.java} (66%) delete mode 100755 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/vo/DataSourceConfigUpdateReqVO.java delete mode 100755 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/db/DataSourceConfigConvert.java diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/DataSourceConfigController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/DataSourceConfigController.java index 366f382d7..85a12279e 100755 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/DataSourceConfigController.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/DataSourceConfigController.java @@ -1,15 +1,14 @@ package cn.iocoder.yudao.module.infra.controller.admin.db; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigCreateReqVO; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigRespVO; -import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigUpdateReqVO; -import cn.iocoder.yudao.module.infra.convert.db.DataSourceConfigConvert; +import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.db.DataSourceConfigDO; import cn.iocoder.yudao.module.infra.service.db.DataSourceConfigService; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -32,14 +31,14 @@ public class DataSourceConfigController { @PostMapping("/create") @Operation(summary = "创建数据源配置") @PreAuthorize("@ss.hasPermission('infra:data-source-config:create')") - public CommonResult createDataSourceConfig(@Valid @RequestBody DataSourceConfigCreateReqVO createReqVO) { + public CommonResult createDataSourceConfig(@Valid @RequestBody DataSourceConfigSaveReqVO createReqVO) { return success(dataSourceConfigService.createDataSourceConfig(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新数据源配置") @PreAuthorize("@ss.hasPermission('infra:data-source-config:update')") - public CommonResult updateDataSourceConfig(@Valid @RequestBody DataSourceConfigUpdateReqVO updateReqVO) { + public CommonResult updateDataSourceConfig(@Valid @RequestBody DataSourceConfigSaveReqVO updateReqVO) { dataSourceConfigService.updateDataSourceConfig(updateReqVO); return success(true); } @@ -58,8 +57,8 @@ public class DataSourceConfigController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('infra:data-source-config:query')") public CommonResult getDataSourceConfig(@RequestParam("id") Long id) { - DataSourceConfigDO dataSourceConfig = dataSourceConfigService.getDataSourceConfig(id); - return success(DataSourceConfigConvert.INSTANCE.convert(dataSourceConfig)); + DataSourceConfigDO config = dataSourceConfigService.getDataSourceConfig(id); + return success(BeanUtils.toBean(config, DataSourceConfigRespVO.class)); } @GetMapping("/list") @@ -67,7 +66,7 @@ public class DataSourceConfigController { @PreAuthorize("@ss.hasPermission('infra:data-source-config:query')") public CommonResult> getDataSourceConfigList() { List list = dataSourceConfigService.getDataSourceConfigList(); - return success(DataSourceConfigConvert.INSTANCE.convertList(list)); + return success(BeanUtils.toBean(list, DataSourceConfigRespVO.class)); } } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/vo/DataSourceConfigCreateReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/vo/DataSourceConfigCreateReqVO.java deleted file mode 100755 index 598bda81b..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/vo/DataSourceConfigCreateReqVO.java +++ /dev/null @@ -1,17 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.db.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; -import javax.validation.constraints.*; - -@Schema(description = "管理后台 - 数据源配置创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class DataSourceConfigCreateReqVO extends DataSourceConfigBaseVO { - - @Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456") - @NotNull(message = "密码不能为空") - private String password; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/vo/DataSourceConfigRespVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/vo/DataSourceConfigRespVO.java index 77ecef56c..f97952873 100755 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/vo/DataSourceConfigRespVO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/vo/DataSourceConfigRespVO.java @@ -1,19 +1,26 @@ package cn.iocoder.yudao.module.infra.controller.admin.db.vo; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; +import lombok.Data; import java.time.LocalDateTime; @Schema(description = "管理后台 - 数据源配置 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class DataSourceConfigRespVO extends DataSourceConfigBaseVO { +public class DataSourceConfigRespVO { @Schema(description = "主键编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Integer id; + @Schema(description = "数据源名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "test") + private String name; + + @Schema(description = "数据源连接", requiredMode = Schema.RequiredMode.REQUIRED, example = "jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro") + private String url; + + @Schema(description = "用户名", requiredMode = Schema.RequiredMode.REQUIRED, example = "root") + private String username; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/vo/DataSourceConfigBaseVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/vo/DataSourceConfigSaveReqVO.java similarity index 66% rename from yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/vo/DataSourceConfigBaseVO.java rename to yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/vo/DataSourceConfigSaveReqVO.java index 800227e3c..54d231f6b 100755 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/vo/DataSourceConfigBaseVO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/vo/DataSourceConfigSaveReqVO.java @@ -1,14 +1,15 @@ package cn.iocoder.yudao.module.infra.controller.admin.db.vo; + import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; import javax.validation.constraints.*; -/** -* 数据源配置 Base VO,提供给添加、修改、详细的子 VO 使用 -* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 -*/ +@Schema(description = "管理后台 - 数据源配置创建/修改 Request VO") @Data -public class DataSourceConfigBaseVO { +public class DataSourceConfigSaveReqVO { + + @Schema(description = "主键编号", example = "1024") + private Long id; @Schema(description = "数据源名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "test") @NotNull(message = "数据源名称不能为空") @@ -22,4 +23,8 @@ public class DataSourceConfigBaseVO { @NotNull(message = "用户名不能为空") private String username; + @Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456") + @NotNull(message = "密码不能为空") + private String password; + } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/vo/DataSourceConfigUpdateReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/vo/DataSourceConfigUpdateReqVO.java deleted file mode 100755 index 5cc31eab6..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/vo/DataSourceConfigUpdateReqVO.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.db.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; -import javax.validation.constraints.*; - -@Schema(description = "管理后台 - 数据源配置更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class DataSourceConfigUpdateReqVO extends DataSourceConfigBaseVO { - - @Schema(description = "主键编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "主键编号不能为空") - private Long id; - - @Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456") - @NotNull(message = "密码不能为空") - private String password; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/db/DataSourceConfigConvert.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/db/DataSourceConfigConvert.java deleted file mode 100755 index d81d85cee..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/db/DataSourceConfigConvert.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.infra.convert.db; - -import java.util.*; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; - -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; -import cn.iocoder.yudao.module.infra.controller.admin.db.vo.*; -import cn.iocoder.yudao.module.infra.dal.dataobject.db.DataSourceConfigDO; - -/** - * 数据源配置 Convert - * - * @author 芋道源码 - */ -@Mapper -public interface DataSourceConfigConvert { - - DataSourceConfigConvert INSTANCE = Mappers.getMapper(DataSourceConfigConvert.class); - - DataSourceConfigDO convert(DataSourceConfigCreateReqVO bean); - - DataSourceConfigDO convert(DataSourceConfigUpdateReqVO bean); - - DataSourceConfigRespVO convert(DataSourceConfigDO bean); - - List convertList(List list); - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigService.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigService.java index 002d00944..2838f44d7 100755 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigService.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigService.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.infra.service.db; -import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigCreateReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigUpdateReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.db.DataSourceConfigDO; import javax.validation.Valid; @@ -20,14 +19,14 @@ public interface DataSourceConfigService { * @param createReqVO 创建信息 * @return 编号 */ - Long createDataSourceConfig(@Valid DataSourceConfigCreateReqVO createReqVO); + Long createDataSourceConfig(@Valid DataSourceConfigSaveReqVO createReqVO); /** * 更新数据源配置 * * @param updateReqVO 更新信息 */ - void updateDataSourceConfig(@Valid DataSourceConfigUpdateReqVO updateReqVO); + void updateDataSourceConfig(@Valid DataSourceConfigSaveReqVO updateReqVO); /** * 删除数据源配置 diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigServiceImpl.java index e4365c205..006fb738f 100755 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigServiceImpl.java @@ -1,9 +1,8 @@ package cn.iocoder.yudao.module.infra.service.db; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.mybatis.core.util.JdbcUtils; -import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigCreateReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigUpdateReqVO; -import cn.iocoder.yudao.module.infra.convert.db.DataSourceConfigConvert; +import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.db.DataSourceConfigDO; import cn.iocoder.yudao.module.infra.dal.mysql.db.DataSourceConfigMapper; import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; @@ -35,21 +34,21 @@ public class DataSourceConfigServiceImpl implements DataSourceConfigService { private DynamicDataSourceProperties dynamicDataSourceProperties; @Override - public Long createDataSourceConfig(DataSourceConfigCreateReqVO createReqVO) { - DataSourceConfigDO dataSourceConfig = DataSourceConfigConvert.INSTANCE.convert(createReqVO); - validateConnectionOK(dataSourceConfig); + public Long createDataSourceConfig(DataSourceConfigSaveReqVO createReqVO) { + DataSourceConfigDO config = BeanUtils.toBean(createReqVO, DataSourceConfigDO.class); + validateConnectionOK(config); // 插入 - dataSourceConfigMapper.insert(dataSourceConfig); + dataSourceConfigMapper.insert(config); // 返回 - return dataSourceConfig.getId(); + return config.getId(); } @Override - public void updateDataSourceConfig(DataSourceConfigUpdateReqVO updateReqVO) { + public void updateDataSourceConfig(DataSourceConfigSaveReqVO updateReqVO) { // 校验存在 validateDataSourceConfigExists(updateReqVO.getId()); - DataSourceConfigDO updateObj = DataSourceConfigConvert.INSTANCE.convert(updateReqVO); + DataSourceConfigDO updateObj = BeanUtils.toBean(updateReqVO, DataSourceConfigDO.class); validateConnectionOK(updateObj); // 更新 diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigServiceImplTest.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigServiceImplTest.java index b5ef46c46..d5bc5c5a6 100755 --- a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigServiceImplTest.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigServiceImplTest.java @@ -6,8 +6,7 @@ import cn.hutool.crypto.symmetric.AES; import cn.iocoder.yudao.framework.mybatis.core.type.EncryptTypeHandler; import cn.iocoder.yudao.framework.mybatis.core.util.JdbcUtils; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigCreateReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigUpdateReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.db.DataSourceConfigDO; import cn.iocoder.yudao.module.infra.dal.mysql.db.DataSourceConfigMapper; import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; @@ -70,7 +69,8 @@ public class DataSourceConfigServiceImplTest extends BaseDbUnitTest { public void testCreateDataSourceConfig_success() { try (MockedStatic databaseUtilsMock = mockStatic(JdbcUtils.class)) { // 准备参数 - DataSourceConfigCreateReqVO reqVO = randomPojo(DataSourceConfigCreateReqVO.class); + DataSourceConfigSaveReqVO reqVO = randomPojo(DataSourceConfigSaveReqVO.class) + .setId(null); // 避免 id 被设置 // mock 方法 databaseUtilsMock.when(() -> JdbcUtils.isConnectionOK(eq(reqVO.getUrl()), eq(reqVO.getUsername()), eq(reqVO.getPassword()))).thenReturn(true); @@ -81,7 +81,7 @@ public class DataSourceConfigServiceImplTest extends BaseDbUnitTest { assertNotNull(dataSourceConfigId); // 校验记录的属性是否正确 DataSourceConfigDO dataSourceConfig = dataSourceConfigMapper.selectById(dataSourceConfigId); - assertPojoEquals(reqVO, dataSourceConfig); + assertPojoEquals(reqVO, dataSourceConfig, "id"); } } @@ -92,7 +92,7 @@ public class DataSourceConfigServiceImplTest extends BaseDbUnitTest { DataSourceConfigDO dbDataSourceConfig = randomPojo(DataSourceConfigDO.class); dataSourceConfigMapper.insert(dbDataSourceConfig);// @Sql: 先插入出一条存在的数据 // 准备参数 - DataSourceConfigUpdateReqVO reqVO = randomPojo(DataSourceConfigUpdateReqVO.class, o -> { + DataSourceConfigSaveReqVO reqVO = randomPojo(DataSourceConfigSaveReqVO.class, o -> { o.setId(dbDataSourceConfig.getId()); // 设置更新的 ID }); // mock 方法 @@ -110,7 +110,7 @@ public class DataSourceConfigServiceImplTest extends BaseDbUnitTest { @Test public void testUpdateDataSourceConfig_notExists() { // 准备参数 - DataSourceConfigUpdateReqVO reqVO = randomPojo(DataSourceConfigUpdateReqVO.class); + DataSourceConfigSaveReqVO reqVO = randomPojo(DataSourceConfigSaveReqVO.class); // 调用, 并断言异常 assertServiceException(() -> dataSourceConfigService.updateDataSourceConfig(reqVO), DATA_SOURCE_CONFIG_NOT_EXISTS); From 35d171b1d97e5ea9b10d0f86737091e1752bae78 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 3 Dec 2023 10:33:43 +0800 Subject: [PATCH 17/19] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20file?= =?UTF-8?q?=20=E6=A8=A1=E5=9D=97=E7=9A=84=20VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/file/FileConfigController.java | 19 +++-- .../controller/admin/file/FileController.java | 8 +- .../file/vo/config/FileConfigBaseVO.java | 22 ------ .../file/vo/config/FileConfigPageReqVO.java | 2 +- .../file/vo/config/FileConfigRespVO.java | 15 ++-- ...ateReqVO.java => FileConfigSaveReqVO.java} | 18 +++-- .../file/vo/config/FileConfigUpdateReqVO.java | 25 ------- .../infra/convert/file/FileConfigConvert.java | 18 +---- .../infra/convert/file/FileConvert.java | 18 ----- .../infra/service/file/FileConfigService.java | 7 +- .../service/file/FileConfigServiceImpl.java | 12 +-- .../file/FileConfigServiceImplTest.java | 73 ++++++++++--------- 12 files changed, 81 insertions(+), 156 deletions(-) delete mode 100755 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigBaseVO.java rename yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/{FileConfigCreateReqVO.java => FileConfigSaveReqVO.java} (58%) mode change 100755 => 100644 delete mode 100755 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigUpdateReqVO.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/file/FileConvert.java diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileConfigController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileConfigController.java index 1fbae0931..eb51f08c3 100755 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileConfigController.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileConfigController.java @@ -2,16 +2,15 @@ package cn.iocoder.yudao.module.infra.controller.admin.file; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigCreateReqVO; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigPageReqVO; import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigRespVO; -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigUpdateReqVO; -import cn.iocoder.yudao.module.infra.convert.file.FileConfigConvert; +import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileConfigDO; import cn.iocoder.yudao.module.infra.service.file.FileConfigService; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -33,14 +32,14 @@ public class FileConfigController { @PostMapping("/create") @Operation(summary = "创建文件配置") @PreAuthorize("@ss.hasPermission('infra:file-config:create')") - public CommonResult createFileConfig(@Valid @RequestBody FileConfigCreateReqVO createReqVO) { + public CommonResult createFileConfig(@Valid @RequestBody FileConfigSaveReqVO createReqVO) { return success(fileConfigService.createFileConfig(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新文件配置") @PreAuthorize("@ss.hasPermission('infra:file-config:update')") - public CommonResult updateFileConfig(@Valid @RequestBody FileConfigUpdateReqVO updateReqVO) { + public CommonResult updateFileConfig(@Valid @RequestBody FileConfigSaveReqVO updateReqVO) { fileConfigService.updateFileConfig(updateReqVO); return success(true); } @@ -67,8 +66,8 @@ public class FileConfigController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('infra:file-config:query')") public CommonResult getFileConfig(@RequestParam("id") Long id) { - FileConfigDO fileConfig = fileConfigService.getFileConfig(id); - return success(FileConfigConvert.INSTANCE.convert(fileConfig)); + FileConfigDO config = fileConfigService.getFileConfig(id); + return success(BeanUtils.toBean(config, FileConfigRespVO.class)); } @GetMapping("/page") @@ -76,7 +75,7 @@ public class FileConfigController { @PreAuthorize("@ss.hasPermission('infra:file-config:query')") public CommonResult> getFileConfigPage(@Valid FileConfigPageReqVO pageVO) { PageResult pageResult = fileConfigService.getFileConfigPage(pageVO); - return success(FileConfigConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, FileConfigRespVO.class)); } @GetMapping("/test") diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java index acb9360b5..d31125316 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java @@ -4,17 +4,17 @@ import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO; import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileRespVO; import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileUploadReqVO; -import cn.iocoder.yudao.module.infra.convert.file.FileConvert; import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO; import cn.iocoder.yudao.module.infra.service.file.FileService; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.security.access.prepost.PreAuthorize; @@ -86,7 +86,7 @@ public class FileController { @PreAuthorize("@ss.hasPermission('infra:file:query')") public CommonResult> getFilePage(@Valid FilePageReqVO pageVO) { PageResult pageResult = fileService.getFilePage(pageVO); - return success(FileConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, FileRespVO.class)); } } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigBaseVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigBaseVO.java deleted file mode 100755 index eccbd4bb1..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigBaseVO.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.file.vo.config; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import javax.validation.constraints.NotNull; - -/** -* 文件配置 Base VO,提供给添加、修改、详细的子 VO 使用 -* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 -*/ -@Data -public class FileConfigBaseVO { - - @Schema(description = "配置名", requiredMode = Schema.RequiredMode.REQUIRED, example = "S3 - 阿里云") - @NotNull(message = "配置名不能为空") - private String name; - - @Schema(description = "备注", example = "我是备注") - private String remark; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigPageReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigPageReqVO.java index f2314a469..481fa2af5 100755 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigPageReqVO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigPageReqVO.java @@ -27,4 +27,4 @@ public class FileConfigPageReqVO extends PageParam { @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime[] createTime; -} +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigRespVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigRespVO.java index c64556728..e3bb6fe88 100755 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigRespVO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigRespVO.java @@ -3,32 +3,31 @@ package cn.iocoder.yudao.module.infra.controller.admin.file.vo.config; import cn.iocoder.yudao.framework.file.core.client.FileClientConfig; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; -import javax.validation.constraints.NotNull; import java.time.LocalDateTime; @Schema(description = "管理后台 - 文件配置 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class FileConfigRespVO extends FileConfigBaseVO { +public class FileConfigRespVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") private Long id; + @Schema(description = "配置名", requiredMode = Schema.RequiredMode.REQUIRED, example = "S3 - 阿里云") + private String name; + @Schema(description = "存储器,参见 FileStorageEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "存储器不能为空") private Integer storage; @Schema(description = "是否为主配置", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") - @NotNull(message = "是否为主配置不能为空") private Boolean master; @Schema(description = "存储配置", requiredMode = Schema.RequiredMode.REQUIRED) private FileClientConfig config; + @Schema(description = "备注", example = "我是备注") + private String remark; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigCreateReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigSaveReqVO.java old mode 100755 new mode 100644 similarity index 58% rename from yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigCreateReqVO.java rename to yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigSaveReqVO.java index 496e32237..b346ee60a --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigCreateReqVO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigSaveReqVO.java @@ -2,17 +2,20 @@ package cn.iocoder.yudao.module.infra.controller.admin.file.vo.config; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; import javax.validation.constraints.NotNull; import java.util.Map; -@Schema(description = "管理后台 - 文件配置创建 Request VO") +@Schema(description = "管理后台 - 文件配置创建/修改 Request VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class FileConfigCreateReqVO extends FileConfigBaseVO { +public class FileConfigSaveReqVO { + + @Schema(description = "编号", example = "1") + private Long id; + + @Schema(description = "配置名", requiredMode = Schema.RequiredMode.REQUIRED, example = "S3 - 阿里云") + @NotNull(message = "配置名不能为空") + private String name; @Schema(description = "存储器,参见 FileStorageEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @NotNull(message = "存储器不能为空") @@ -22,4 +25,7 @@ public class FileConfigCreateReqVO extends FileConfigBaseVO { @NotNull(message = "存储配置不能为空") private Map config; + @Schema(description = "备注", example = "我是备注") + private String remark; + } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigUpdateReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigUpdateReqVO.java deleted file mode 100755 index ba599d424..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigUpdateReqVO.java +++ /dev/null @@ -1,25 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.file.vo.config; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import javax.validation.constraints.NotNull; -import java.util.Map; - -@Schema(description = "管理后台 - 文件配置更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class FileConfigUpdateReqVO extends FileConfigBaseVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "编号不能为空") - private Long id; - - @Schema(description = "存储配置,配置是动态参数,所以使用 Map 接收", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "存储配置不能为空") - private Map config; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/file/FileConfigConvert.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/file/FileConfigConvert.java index 442368302..7df2b57e6 100755 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/file/FileConfigConvert.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/file/FileConfigConvert.java @@ -1,16 +1,11 @@ package cn.iocoder.yudao.module.infra.convert.file; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigCreateReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigRespVO; -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigUpdateReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileConfigDO; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; -import java.util.List; - /** * 文件配置 Convert * @@ -22,15 +17,6 @@ public interface FileConfigConvert { FileConfigConvert INSTANCE = Mappers.getMapper(FileConfigConvert.class); @Mapping(target = "config", ignore = true) - FileConfigDO convert(FileConfigCreateReqVO bean); - - @Mapping(target = "config", ignore = true) - FileConfigDO convert(FileConfigUpdateReqVO bean); - - FileConfigRespVO convert(FileConfigDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); + FileConfigDO convert(FileConfigSaveReqVO bean); } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/file/FileConvert.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/file/FileConvert.java deleted file mode 100644 index ee7e5186b..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/file/FileConvert.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.module.infra.convert.file; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileRespVO; -import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -@Mapper -public interface FileConvert { - - FileConvert INSTANCE = Mappers.getMapper(FileConvert.class); - - FileRespVO convert(FileDO bean); - - PageResult convertPage(PageResult page); - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigService.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigService.java index 1b279391a..e43088098 100755 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigService.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigService.java @@ -2,9 +2,8 @@ package cn.iocoder.yudao.module.infra.service.file; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.file.core.client.FileClient; -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigCreateReqVO; import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigPageReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigUpdateReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileConfigDO; import javax.validation.Valid; @@ -22,14 +21,14 @@ public interface FileConfigService { * @param createReqVO 创建信息 * @return 编号 */ - Long createFileConfig(@Valid FileConfigCreateReqVO createReqVO); + Long createFileConfig(@Valid FileConfigSaveReqVO createReqVO); /** * 更新文件配置 * * @param updateReqVO 更新信息 */ - void updateFileConfig(@Valid FileConfigUpdateReqVO updateReqVO); + void updateFileConfig(@Valid FileConfigSaveReqVO updateReqVO); /** * 更新文件配置为 Master diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.java index 4b54efc2f..94ec1d9b9 100755 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.java @@ -4,14 +4,14 @@ import cn.hutool.core.io.resource.ResourceUtil; import cn.hutool.core.util.IdUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils; import cn.iocoder.yudao.framework.file.core.client.FileClient; import cn.iocoder.yudao.framework.file.core.client.FileClientConfig; import cn.iocoder.yudao.framework.file.core.client.FileClientFactory; import cn.iocoder.yudao.framework.file.core.enums.FileStorageEnum; -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigCreateReqVO; import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigPageReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigUpdateReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigSaveReqVO; import cn.iocoder.yudao.module.infra.convert.file.FileConfigConvert; import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileConfigDO; import cn.iocoder.yudao.module.infra.dal.mysql.file.FileConfigMapper; @@ -63,7 +63,7 @@ public class FileConfigServiceImpl implements FileConfigService { return fileClientFactory.getFileClient(null == config ? id : config.getId()); } - }); + }); @Resource private FileClientFactory fileClientFactory; @@ -75,7 +75,7 @@ public class FileConfigServiceImpl implements FileConfigService { private Validator validator; @Override - public Long createFileConfig(FileConfigCreateReqVO createReqVO) { + public Long createFileConfig(FileConfigSaveReqVO createReqVO) { FileConfigDO fileConfig = FileConfigConvert.INSTANCE.convert(createReqVO) .setConfig(parseClientConfig(createReqVO.getStorage(), createReqVO.getConfig())) .setMaster(false); // 默认非 master @@ -84,7 +84,7 @@ public class FileConfigServiceImpl implements FileConfigService { } @Override - public void updateFileConfig(FileConfigUpdateReqVO updateReqVO) { + public void updateFileConfig(FileConfigSaveReqVO updateReqVO) { // 校验存在 FileConfigDO config = validateFileConfigExists(updateReqVO.getId()); // 更新 @@ -126,7 +126,7 @@ public class FileConfigServiceImpl implements FileConfigService { // 校验存在 FileConfigDO config = validateFileConfigExists(id); if (Boolean.TRUE.equals(config.getMaster())) { - throw exception(FILE_CONFIG_DELETE_FAIL_MASTER); + throw exception(FILE_CONFIG_DELETE_FAIL_MASTER); } // 删除 fileConfigMapper.deleteById(id); diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImplTest.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImplTest.java index 999c8ee28..cef3da5ee 100755 --- a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImplTest.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImplTest.java @@ -11,9 +11,8 @@ import cn.iocoder.yudao.framework.file.core.client.local.LocalFileClient; import cn.iocoder.yudao.framework.file.core.client.local.LocalFileClientConfig; import cn.iocoder.yudao.framework.file.core.enums.FileStorageEnum; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigCreateReqVO; import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigPageReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigUpdateReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileConfigDO; import cn.iocoder.yudao.module.infra.dal.mysql.file.FileConfigMapper; import lombok.Data; @@ -41,10 +40,10 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; /** -* {@link FileConfigServiceImpl} 的单元测试类 -* -* @author 芋道源码 -*/ + * {@link FileConfigServiceImpl} 的单元测试类 + * + * @author 芋道源码 + */ @Import(FileConfigServiceImpl.class) public class FileConfigServiceImplTest extends BaseDbUnitTest { @@ -64,8 +63,9 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest { // 准备参数 Map config = MapUtil.builder().put("basePath", "/yunai") .put("domain", "https://www.iocoder.cn").build(); - FileConfigCreateReqVO reqVO = randomPojo(FileConfigCreateReqVO.class, - o -> o.setStorage(FileStorageEnum.LOCAL.getStorage()).setConfig(config)); + FileConfigSaveReqVO reqVO = randomPojo(FileConfigSaveReqVO.class, + o -> o.setStorage(FileStorageEnum.LOCAL.getStorage()).setConfig(config)) + .setId(null); // 避免 id 被赋值 // 调用 Long fileConfigId = fileConfigService.createFileConfig(reqVO); @@ -73,7 +73,7 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest { assertNotNull(fileConfigId); // 校验记录的属性是否正确 FileConfigDO fileConfig = fileConfigMapper.selectById(fileConfigId); - assertPojoEquals(reqVO, fileConfig, "config"); + assertPojoEquals(reqVO, fileConfig, "id", "config"); assertFalse(fileConfig.getMaster()); assertEquals("/yunai", ((LocalFileClientConfig) fileConfig.getConfig()).getBasePath()); assertEquals("https://www.iocoder.cn", ((LocalFileClientConfig) fileConfig.getConfig()).getDomain()); @@ -88,8 +88,9 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest { .setConfig(new LocalFileClientConfig().setBasePath("/yunai").setDomain("https://www.iocoder.cn"))); fileConfigMapper.insert(dbFileConfig);// @Sql: 先插入出一条存在的数据 // 准备参数 - FileConfigUpdateReqVO reqVO = randomPojo(FileConfigUpdateReqVO.class, o -> { + FileConfigSaveReqVO reqVO = randomPojo(FileConfigSaveReqVO.class, o -> { o.setId(dbFileConfig.getId()); // 设置更新的 ID + o.setStorage(FileStorageEnum.LOCAL.getStorage()); Map config = MapUtil.builder().put("basePath", "/yunai2") .put("domain", "https://doc.iocoder.cn").build(); o.setConfig(config); @@ -109,7 +110,7 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest { @Test public void testUpdateFileConfig_notExists() { // 准备参数 - FileConfigUpdateReqVO reqVO = randomPojo(FileConfigUpdateReqVO.class); + FileConfigSaveReqVO reqVO = randomPojo(FileConfigSaveReqVO.class); // 调用, 并断言异常 assertServiceException(() -> fileConfigService.updateFileConfig(reqVO), FILE_CONFIG_NOT_EXISTS); @@ -148,8 +149,8 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest { // 调用 fileConfigService.deleteFileConfig(id); - // 校验数据不存在了 - assertNull(fileConfigMapper.selectById(id)); + // 校验数据不存在了 + assertNull(fileConfigMapper.selectById(id)); // 验证 cache assertNull(fileConfigService.getClientCache().getIfPresent(id)); } @@ -177,30 +178,30 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest { @Test public void testGetFileConfigPage() { - // mock 数据 - FileConfigDO dbFileConfig = randomFileConfigDO().setName("芋道源码") - .setStorage(FileStorageEnum.LOCAL.getStorage()); - dbFileConfig.setCreateTime(LocalDateTimeUtil.parse("2020-01-23", DatePattern.NORM_DATE_PATTERN));// 等会查询到 - fileConfigMapper.insert(dbFileConfig); - // 测试 name 不匹配 - fileConfigMapper.insert(cloneIgnoreId(dbFileConfig, o -> o.setName("源码"))); - // 测试 storage 不匹配 - fileConfigMapper.insert(cloneIgnoreId(dbFileConfig, o -> o.setStorage(FileStorageEnum.DB.getStorage()))); - // 测试 createTime 不匹配 - fileConfigMapper.insert(cloneIgnoreId(dbFileConfig, o -> o.setCreateTime(LocalDateTimeUtil.parse("2020-11-23", DatePattern.NORM_DATE_PATTERN)))); - // 准备参数 - FileConfigPageReqVO reqVO = new FileConfigPageReqVO(); - reqVO.setName("芋道"); - reqVO.setStorage(FileStorageEnum.LOCAL.getStorage()); - reqVO.setCreateTime((new LocalDateTime[]{buildTime(2020, 1, 1), - buildTime(2020, 1, 24)})); + // mock 数据 + FileConfigDO dbFileConfig = randomFileConfigDO().setName("芋道源码") + .setStorage(FileStorageEnum.LOCAL.getStorage()); + dbFileConfig.setCreateTime(LocalDateTimeUtil.parse("2020-01-23", DatePattern.NORM_DATE_PATTERN));// 等会查询到 + fileConfigMapper.insert(dbFileConfig); + // 测试 name 不匹配 + fileConfigMapper.insert(cloneIgnoreId(dbFileConfig, o -> o.setName("源码"))); + // 测试 storage 不匹配 + fileConfigMapper.insert(cloneIgnoreId(dbFileConfig, o -> o.setStorage(FileStorageEnum.DB.getStorage()))); + // 测试 createTime 不匹配 + fileConfigMapper.insert(cloneIgnoreId(dbFileConfig, o -> o.setCreateTime(LocalDateTimeUtil.parse("2020-11-23", DatePattern.NORM_DATE_PATTERN)))); + // 准备参数 + FileConfigPageReqVO reqVO = new FileConfigPageReqVO(); + reqVO.setName("芋道"); + reqVO.setStorage(FileStorageEnum.LOCAL.getStorage()); + reqVO.setCreateTime((new LocalDateTime[]{buildTime(2020, 1, 1), + buildTime(2020, 1, 24)})); - // 调用 - PageResult pageResult = fileConfigService.getFileConfigPage(reqVO); - // 断言 - assertEquals(1, pageResult.getTotal()); - assertEquals(1, pageResult.getList().size()); - assertPojoEquals(dbFileConfig, pageResult.getList().get(0)); + // 调用 + PageResult pageResult = fileConfigService.getFileConfigPage(reqVO); + // 断言 + assertEquals(1, pageResult.getTotal()); + assertEquals(1, pageResult.getList().size()); + assertPojoEquals(dbFileConfig, pageResult.getList().get(0)); } @Test From e541fe63246e140b9e3c1e309ec7f7d6540f191b Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 3 Dec 2023 18:11:45 +0800 Subject: [PATCH 18/19] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20job?= =?UTF-8?q?=20=E6=A8=A1=E5=9D=97=E7=9A=84=20VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/job/JobController.java | 43 +++++------- .../admin/job/JobLogController.java | 35 ++++------ .../admin/job/vo/job/JobCreateReqVO.java | 20 ------ .../admin/job/vo/job/JobExcelVO.java | 56 --------------- .../admin/job/vo/job/JobExportReqVO.java | 19 ----- .../admin/job/vo/job/JobRespVO.java | 41 +++++++++-- .../job/{JobBaseVO.java => JobSaveReqVO.java} | 19 +++-- .../admin/job/vo/job/JobUpdateReqVO.java | 20 ------ .../admin/job/vo/log/JobLogBaseVO.java | 53 -------------- .../admin/job/vo/log/JobLogExcelVO.java | 53 -------------- .../admin/job/vo/log/JobLogExportReqVO.java | 32 --------- .../admin/job/vo/log/JobLogRespVO.java | 51 ++++++++++++-- .../module/infra/convert/job/JobConvert.java | 36 ---------- .../infra/convert/job/JobLogConvert.java | 30 -------- .../infra/dal/mysql/job/JobLogMapper.java | 13 ---- .../module/infra/dal/mysql/job/JobMapper.java | 15 +--- .../infra/service/job/JobLogService.java | 20 ------ .../infra/service/job/JobLogServiceImpl.java | 22 ++---- .../module/infra/service/job/JobService.java | 16 +---- .../infra/service/job/JobServiceImpl.java | 21 ++---- .../service/job/JobLogServiceImplTest.java | 57 --------------- .../infra/service/job/JobServiceImplTest.java | 70 +++---------------- 22 files changed, 151 insertions(+), 591 deletions(-) delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobCreateReqVO.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobExcelVO.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobExportReqVO.java rename yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/{JobBaseVO.java => JobSaveReqVO.java} (65%) delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobUpdateReqVO.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogBaseVO.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogExcelVO.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogExportReqVO.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/job/JobConvert.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/job/JobLogConvert.java diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobController.java index 2574db968..8261ecd65 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobController.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobController.java @@ -1,18 +1,21 @@ package cn.iocoder.yudao.module.infra.controller.admin.job; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.framework.quartz.core.util.CronUtils; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.*; -import cn.iocoder.yudao.module.infra.convert.job.JobConvert; +import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobPageReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobRespVO; +import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobDO; import cn.iocoder.yudao.module.infra.service.job.JobService; -import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; -import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; import org.quartz.SchedulerException; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; @@ -23,7 +26,6 @@ import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.IOException; import java.time.LocalDateTime; -import java.util.Collection; import java.util.Collections; import java.util.List; @@ -42,7 +44,7 @@ public class JobController { @PostMapping("/create") @Operation(summary = "创建定时任务") @PreAuthorize("@ss.hasPermission('infra:job:create')") - public CommonResult createJob(@Valid @RequestBody JobCreateReqVO createReqVO) + public CommonResult createJob(@Valid @RequestBody JobSaveReqVO createReqVO) throws SchedulerException { return success(jobService.createJob(createReqVO)); } @@ -50,7 +52,7 @@ public class JobController { @PutMapping("/update") @Operation(summary = "更新定时任务") @PreAuthorize("@ss.hasPermission('infra:job:update')") - public CommonResult updateJob(@Valid @RequestBody JobUpdateReqVO updateReqVO) + public CommonResult updateJob(@Valid @RequestBody JobSaveReqVO updateReqVO) throws SchedulerException { jobService.updateJob(updateReqVO); return success(true); @@ -94,16 +96,7 @@ public class JobController { @PreAuthorize("@ss.hasPermission('infra:job:query')") public CommonResult getJob(@RequestParam("id") Long id) { JobDO job = jobService.getJob(id); - return success(JobConvert.INSTANCE.convert(job)); - } - - @GetMapping("/list") - @Operation(summary = "获得定时任务列表") - @Parameter(name = "ids", description = "编号列表", required = true) - @PreAuthorize("@ss.hasPermission('infra:job:query')") - public CommonResult> getJobList(@RequestParam("ids") Collection ids) { - List list = jobService.getJobList(ids); - return success(JobConvert.INSTANCE.convertList(list)); + return success(BeanUtils.toBean(job, JobRespVO.class)); } @GetMapping("/page") @@ -111,19 +104,20 @@ public class JobController { @PreAuthorize("@ss.hasPermission('infra:job:query')") public CommonResult> getJobPage(@Valid JobPageReqVO pageVO) { PageResult pageResult = jobService.getJobPage(pageVO); - return success(JobConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, JobRespVO.class)); } @GetMapping("/export-excel") @Operation(summary = "导出定时任务 Excel") @PreAuthorize("@ss.hasPermission('infra:job:export')") @OperateLog(type = EXPORT) - public void exportJobExcel(@Valid JobExportReqVO exportReqVO, + public void exportJobExcel(@Valid JobPageReqVO exportReqVO, HttpServletResponse response) throws IOException { - List list = jobService.getJobList(exportReqVO); + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = jobService.getJobPage(exportReqVO).getList(); // 导出 Excel - List datas = JobConvert.INSTANCE.convertList02(list); - ExcelUtils.write(response, "定时任务.xls", "数据", JobExcelVO.class, datas); + ExcelUtils.write(response, "定时任务.xls", "数据", JobRespVO.class, + BeanUtils.toBean(list, JobRespVO.class)); } @GetMapping("/get_next_times") @@ -133,8 +127,9 @@ public class JobController { @Parameter(name = "count", description = "数量", example = "5") }) @PreAuthorize("@ss.hasPermission('infra:job:query')") - public CommonResult> getJobNextTimes(@RequestParam("id") Long id, - @RequestParam(value = "count", required = false, defaultValue = "5") Integer count) { + public CommonResult> getJobNextTimes( + @RequestParam("id") Long id, + @RequestParam(value = "count", required = false, defaultValue = "5") Integer count) { JobDO job = jobService.getJob(id); if (job == null) { return success(Collections.emptyList()); diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobLogController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobLogController.java index 1441f9cf6..5797ff6e5 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobLogController.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobLogController.java @@ -1,20 +1,18 @@ package cn.iocoder.yudao.module.infra.controller.admin.job; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import cn.iocoder.yudao.framework.operatelog.core.util.OperateLogUtils; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogExcelVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogPageReqVO; import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogRespVO; -import cn.iocoder.yudao.module.infra.convert.job.JobLogConvert; import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobLogDO; import cn.iocoder.yudao.module.infra.service.job.JobLogService; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; @@ -26,7 +24,6 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.IOException; -import java.util.Collection; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -47,16 +44,7 @@ public class JobLogController { @PreAuthorize("@ss.hasPermission('infra:job:query')") public CommonResult getJobLog(@RequestParam("id") Long id) { JobLogDO jobLog = jobLogService.getJobLog(id); - return success(JobLogConvert.INSTANCE.convert(jobLog)); - } - - @GetMapping("/list") - @Operation(summary = "获得定时任务日志列表") - @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") - @PreAuthorize("@ss.hasPermission('infra:job:query')") - public CommonResult> getJobLogList(@RequestParam("ids") Collection ids) { - List list = jobLogService.getJobLogList(ids); - return success(JobLogConvert.INSTANCE.convertList(list)); + return success(BeanUtils.toBean(jobLog, JobLogRespVO.class)); } @GetMapping("/page") @@ -64,19 +52,20 @@ public class JobLogController { @PreAuthorize("@ss.hasPermission('infra:job:query')") public CommonResult> getJobLogPage(@Valid JobLogPageReqVO pageVO) { PageResult pageResult = jobLogService.getJobLogPage(pageVO); - return success(JobLogConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, JobLogRespVO.class)); } @GetMapping("/export-excel") @Operation(summary = "导出定时任务日志 Excel") @PreAuthorize("@ss.hasPermission('infra:job:export')") @OperateLog(type = EXPORT) - public void exportJobLogExcel(@Valid JobLogExportReqVO exportReqVO, + public void exportJobLogExcel(@Valid JobLogPageReqVO exportReqVO, HttpServletResponse response) throws IOException { - List list = jobLogService.getJobLogList(exportReqVO); + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = jobLogService.getJobLogPage(exportReqVO).getList(); // 导出 Excel - List datas = JobLogConvert.INSTANCE.convertList02(list); - ExcelUtils.write(response, "任务日志.xls", "数据", JobLogExcelVO.class, datas); + ExcelUtils.write(response, "任务日志.xls", "数据", JobLogRespVO.class, + BeanUtils.toBean(list, JobLogRespVO.class)); } -} +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobCreateReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobCreateReqVO.java deleted file mode 100644 index be9914532..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobCreateReqVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.job.vo.job; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 定时任务创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class JobCreateReqVO extends JobBaseVO { - - @Schema(description = "处理器的名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "sysUserSessionTimeoutJob") - @NotNull(message = "处理器的名字不能为空") - private String handlerName; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobExcelVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobExcelVO.java deleted file mode 100644 index 55811ecec..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobExcelVO.java +++ /dev/null @@ -1,56 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.job.vo.job; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; -import com.alibaba.excel.annotation.ExcelProperty; -import lombok.Data; - -import java.time.LocalDateTime; - -/** - * 定时任务 Excel VO - * - * @author 芋道源码 - */ -@Data -public class JobExcelVO { - - @ExcelProperty("任务编号") - private Long id; - - @ExcelProperty("任务名称") - private String name; - - @ExcelProperty(value = "任务状态", converter = DictConvert.class) - @DictFormat(DictTypeConstants.JOB_STATUS) - private Integer status; - - @ExcelProperty("处理器的名字") - private String handlerName; - - @ExcelProperty("处理器的参数") - private String handlerParam; - - @ExcelProperty("CRON 表达式") - private String cronExpression; - - @ExcelProperty("最后一次执行的开始时间") - private LocalDateTime executeBeginTime; - - @ExcelProperty("最后一次执行的结束时间") - private LocalDateTime executeEndTime; - - @ExcelProperty("上一次触发时间") - private LocalDateTime firePrevTime; - - @ExcelProperty("下一次触发时间") - private LocalDateTime fireNextTime; - - @ExcelProperty("监控超时时间") - private Integer monitorTimeout; - - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobExportReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobExportReqVO.java deleted file mode 100644 index 49b7e83d3..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobExportReqVO.java +++ /dev/null @@ -1,19 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.job.vo.job; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -@Schema(description = "管理后台 - 定时任务 Excel 导出 Request VO-参数和 JobPageReqVO 是一致的") -@Data -public class JobExportReqVO { - - @Schema(description = "任务名称-模糊匹配", example = "测试任务") - private String name; - - @Schema(description = "任务状态-参见 JobStatusEnum 枚举", example = "1") - private Integer status; - - @Schema(description = "处理器的名字-模糊匹配", example = "UserSessionTimeoutJob") - private String handlerName; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobRespVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobRespVO.java index b0e18a796..25683f89c 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobRespVO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobRespVO.java @@ -1,30 +1,59 @@ package cn.iocoder.yudao.module.infra.controller.admin.job.vo.job; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; import javax.validation.constraints.NotNull; import java.time.LocalDateTime; @Schema(description = "管理后台 - 定时任务 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class JobRespVO extends JobBaseVO { +@ExcelIgnoreUnannotated +public class JobRespVO { @Schema(description = "任务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("任务编号") private Long id; + @Schema(description = "任务名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试任务") + @ExcelProperty("任务名称") + private String name; + @Schema(description = "任务状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "任务状态", converter = DictConvert.class) + @DictFormat(DictTypeConstants.JOB_STATUS) private Integer status; @Schema(description = "处理器的名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "sysUserSessionTimeoutJob") - @NotNull(message = "处理器的名字不能为空") + @ExcelProperty("处理器的名字") private String handlerName; + @Schema(description = "处理器的参数", example = "yudao") + @ExcelProperty("处理器的参数") + private String handlerParam; + + @Schema(description = "CRON 表达式", requiredMode = Schema.RequiredMode.REQUIRED, example = "0/10 * * * * ? *") + @ExcelProperty("CRON 表达式") + private String cronExpression; + + @Schema(description = "重试次数", requiredMode = Schema.RequiredMode.REQUIRED, example = "3") + @NotNull(message = "重试次数不能为空") + private Integer retryCount; + + @Schema(description = "重试间隔", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") + private Integer retryInterval; + + @Schema(description = "监控超时时间", example = "1000") + @ExcelProperty("监控超时时间") + private Integer monitorTimeout; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") private LocalDateTime createTime; } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobBaseVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobSaveReqVO.java similarity index 65% rename from yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobBaseVO.java rename to yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobSaveReqVO.java index 9d14846b2..0fb986e63 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobBaseVO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobSaveReqVO.java @@ -3,24 +3,29 @@ package cn.iocoder.yudao.module.infra.controller.admin.job.vo.job; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; -/** -* 定时任务 Base VO,提供给添加、修改、详细的子 VO 使用 -* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 -*/ +@Schema(description = "管理后台 - 定时任务创建/修改 Request VO") @Data -public class JobBaseVO { +public class JobSaveReqVO { + + @Schema(description = "任务编号", example = "1024") + private Long id; @Schema(description = "任务名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试任务") - @NotNull(message = "任务名称不能为空") + @NotEmpty(message = "任务名称不能为空") private String name; + @Schema(description = "处理器的名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "sysUserSessionTimeoutJob") + @NotEmpty(message = "处理器的名字不能为空") + private String handlerName; + @Schema(description = "处理器的参数", example = "yudao") private String handlerParam; @Schema(description = "CRON 表达式", requiredMode = Schema.RequiredMode.REQUIRED, example = "0/10 * * * * ? *") - @NotNull(message = "CRON 表达式不能为空") + @NotEmpty(message = "CRON 表达式不能为空") private String cronExpression; @Schema(description = "重试次数", requiredMode = Schema.RequiredMode.REQUIRED, example = "3") diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobUpdateReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobUpdateReqVO.java deleted file mode 100644 index df1435669..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobUpdateReqVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.job.vo.job; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 定时任务更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class JobUpdateReqVO extends JobBaseVO { - - @Schema(description = "任务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "任务编号不能为空") - private Long id; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogBaseVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogBaseVO.java deleted file mode 100644 index 5a74d38db..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogBaseVO.java +++ /dev/null @@ -1,53 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.job.vo.log; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import javax.validation.constraints.NotNull; -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -/** -* 定时任务日志 Base VO,提供给添加、修改、详细的子 VO 使用 -* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 -*/ -@Data -public class JobLogBaseVO { - - @Schema(description = "任务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "任务编号不能为空") - private Long jobId; - - @Schema(description = "处理器的名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "sysUserSessionTimeoutJob") - @NotNull(message = "处理器的名字不能为空") - private String handlerName; - - @Schema(description = "处理器的参数", example = "yudao") - private String handlerParam; - - @Schema(description = "第几次执行", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "第几次执行不能为空") - private Integer executeIndex; - - @Schema(description = "开始执行时间", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "开始执行时间不能为空") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime beginTime; - - @Schema(description = "结束执行时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime endTime; - - @Schema(description = "执行时长", example = "123") - private Integer duration; - - @Schema(description = "任务状态,参见 JobLogStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "任务状态不能为空") - private Integer status; - - @Schema(description = "结果数据", example = "执行成功") - private String result; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogExcelVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogExcelVO.java deleted file mode 100644 index e8619d42a..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogExcelVO.java +++ /dev/null @@ -1,53 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.job.vo.log; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; -import com.alibaba.excel.annotation.ExcelProperty; -import lombok.Data; - -import java.time.LocalDateTime; - -/** - * 定时任务 Excel VO - * - * @author 芋艿 - */ -@Data -public class JobLogExcelVO { - - @ExcelProperty("日志编号") - private Long id; - - @ExcelProperty("任务编号") - private Long jobId; - - @ExcelProperty("处理器的名字") - private String handlerName; - - @ExcelProperty("处理器的参数") - private String handlerParam; - - @ExcelProperty("第几次执行") - private Integer executeIndex; - - @ExcelProperty("开始执行时间") - private LocalDateTime beginTime; - - @ExcelProperty("结束执行时间") - private LocalDateTime endTime; - - @ExcelProperty("执行时长") - private Integer duration; - - @ExcelProperty(value = "任务状态", converter = DictConvert.class) - @DictFormat(DictTypeConstants.JOB_STATUS) - private Integer status; - - @ExcelProperty("结果数据") - private String result; - - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogExportReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogExportReqVO.java deleted file mode 100644 index 3156e2bc3..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogExportReqVO.java +++ /dev/null @@ -1,32 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.job.vo.log; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 定时任务 Excel 导出 Request VO,参数和 JobLogPageReqVO 是一致的") -@Data -public class JobLogExportReqVO { - - @Schema(description = "任务编号", example = "10") - private Long jobId; - - @Schema(description = "处理器的名字,模糊匹配") - private String handlerName; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @Schema(description = "开始执行时间") - private LocalDateTime beginTime; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @Schema(description = "结束执行时间") - private LocalDateTime endTime; - - @Schema(description = "任务状态,参见 JobLogStatusEnum 枚举") - private Integer status; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogRespVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogRespVO.java index 4da31956a..543339d69 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogRespVO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogRespVO.java @@ -1,22 +1,63 @@ package cn.iocoder.yudao.module.infra.controller.admin.job.vo.log; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; import java.time.LocalDateTime; @Schema(description = "管理后台 - 定时任务日志 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class JobLogRespVO extends JobLogBaseVO { +@ExcelIgnoreUnannotated +public class JobLogRespVO { @Schema(description = "日志编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("日志编号") private Long id; + @Schema(description = "任务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("任务编号") + private Long jobId; + + @Schema(description = "处理器的名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "sysUserSessionTimeoutJob") + @ExcelProperty("处理器的名字") + private String handlerName; + + @Schema(description = "处理器的参数", example = "yudao") + @ExcelProperty("处理器的参数") + private String handlerParam; + + @Schema(description = "第几次执行", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty("第几次执行") + private Integer executeIndex; + + @Schema(description = "开始执行时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("开始执行时间") + private LocalDateTime beginTime; + + @Schema(description = "结束执行时间") + @ExcelProperty("结束执行时间") + private LocalDateTime endTime; + + @Schema(description = "执行时长", example = "123") + @ExcelProperty("执行时长") + private Integer duration; + + @Schema(description = "任务状态,参见 JobLogStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "任务状态", converter = DictConvert.class) + @DictFormat(DictTypeConstants.JOB_STATUS) + private Integer status; + + @Schema(description = "结果数据", example = "执行成功") + @ExcelProperty("结果数据") + private String result; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") private LocalDateTime createTime; } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/job/JobConvert.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/job/JobConvert.java deleted file mode 100644 index 2c7aa0297..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/job/JobConvert.java +++ /dev/null @@ -1,36 +0,0 @@ -package cn.iocoder.yudao.module.infra.convert.job; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobCreateReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobExcelVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobRespVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobUpdateReqVO; -import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -/** - * 定时任务 Convert - * - * @author 芋道源码 - */ -@Mapper -public interface JobConvert { - - JobConvert INSTANCE = Mappers.getMapper(JobConvert.class); - - JobDO convert(JobCreateReqVO bean); - - JobDO convert(JobUpdateReqVO bean); - - JobRespVO convert(JobDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); - - List convertList02(List list); - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/job/JobLogConvert.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/job/JobLogConvert.java deleted file mode 100644 index 3f32c526d..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/job/JobLogConvert.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.infra.convert.job; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogExcelVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogRespVO; -import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobLogDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -/** - * 定时任务日志 Convert - * - * @author 芋艿 - */ -@Mapper -public interface JobLogConvert { - - JobLogConvert INSTANCE = Mappers.getMapper(JobLogConvert.class); - - JobLogRespVO convert(JobLogDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); - - List convertList02(List list); - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/job/JobLogMapper.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/job/JobLogMapper.java index 31280685b..58ac6daf1 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/job/JobLogMapper.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/job/JobLogMapper.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.infra.dal.mysql.job; 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.infra.controller.admin.job.vo.log.JobLogExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogPageReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobLogDO; import org.apache.ibatis.annotations.Delete; @@ -11,7 +10,6 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.time.LocalDateTime; -import java.util.List; /** * 任务日志 Mapper @@ -32,17 +30,6 @@ public interface JobLogMapper extends BaseMapperX { ); } - default List selectList(JobLogExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .eqIfPresent(JobLogDO::getJobId, reqVO.getJobId()) - .likeIfPresent(JobLogDO::getHandlerName, reqVO.getHandlerName()) - .geIfPresent(JobLogDO::getBeginTime, reqVO.getBeginTime()) - .leIfPresent(JobLogDO::getEndTime, reqVO.getEndTime()) - .eqIfPresent(JobLogDO::getStatus, reqVO.getStatus()) - .orderByDesc(JobLogDO::getId) // ID 倒序 - ); - } - /** * 物理删除指定时间之前的日志 * diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/job/JobMapper.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/job/JobMapper.java index 883906a01..c585dbb14 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/job/JobMapper.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/job/JobMapper.java @@ -1,15 +1,12 @@ package cn.iocoder.yudao.module.infra.dal.mysql.job; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobExportReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobPageReqVO; -import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobDO; 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.infra.controller.admin.job.vo.job.JobPageReqVO; +import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobDO; import org.apache.ibatis.annotations.Mapper; -import java.util.List; - /** * 定时任务 Mapper * @@ -30,12 +27,4 @@ public interface JobMapper extends BaseMapperX { ); } - default List selectList(JobExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .likeIfPresent(JobDO::getName, reqVO.getName()) - .eqIfPresent(JobDO::getStatus, reqVO.getStatus()) - .likeIfPresent(JobDO::getHandlerName, reqVO.getHandlerName()) - ); - } - } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobLogService.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobLogService.java index 87be870b4..f1e7e7c67 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobLogService.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobLogService.java @@ -2,13 +2,9 @@ package cn.iocoder.yudao.module.infra.service.job; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.quartz.core.service.JobLogFrameworkService; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogPageReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobLogDO; -import java.util.Collection; -import java.util.List; - /** * Job 日志 Service 接口 * @@ -24,14 +20,6 @@ public interface JobLogService extends JobLogFrameworkService { */ JobLogDO getJobLog(Long id); - /** - * 获得定时任务列表 - * - * @param ids 编号 - * @return 定时任务列表 - */ - List getJobLogList(Collection ids); - /** * 获得定时任务分页 * @@ -40,14 +28,6 @@ public interface JobLogService extends JobLogFrameworkService { */ PageResult getJobLogPage(JobLogPageReqVO pageReqVO); - /** - * 获得定时任务列表, 用于 Excel 导出 - * - * @param exportReqVO 查询条件 - * @return 定时任务分页 - */ - List getJobLogList(JobLogExportReqVO exportReqVO); - /** * 清理 exceedDay 天前的任务日志 * diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobLogServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobLogServiceImpl.java index cab33079d..868fd1bb2 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobLogServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobLogServiceImpl.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.infra.service.job; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogPageReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobLogDO; import cn.iocoder.yudao.module.infra.dal.mysql.job.JobLogMapper; @@ -13,8 +12,6 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.time.LocalDateTime; -import java.util.Collection; -import java.util.List; /** * Job 日志 Service 实现类 @@ -30,8 +27,10 @@ public class JobLogServiceImpl implements JobLogService { private JobLogMapper jobLogMapper; @Override - public Long createJobLog(Long jobId, LocalDateTime beginTime, String jobHandlerName, String jobHandlerParam, Integer executeIndex) { - JobLogDO log = JobLogDO.builder().jobId(jobId).handlerName(jobHandlerName).handlerParam(jobHandlerParam).executeIndex(executeIndex) + public Long createJobLog(Long jobId, LocalDateTime beginTime, + String jobHandlerName, String jobHandlerParam, Integer executeIndex) { + JobLogDO log = JobLogDO.builder().jobId(jobId).handlerName(jobHandlerName) + .handlerParam(jobHandlerParam).executeIndex(executeIndex) .beginTime(beginTime).status(JobLogStatusEnum.RUNNING.getStatus()).build(); jobLogMapper.insert(log); return log.getId(); @@ -42,7 +41,8 @@ public class JobLogServiceImpl implements JobLogService { public void updateJobLogResultAsync(Long logId, LocalDateTime endTime, Integer duration, boolean success, String result) { try { JobLogDO updateObj = JobLogDO.builder().id(logId).endTime(endTime).duration(duration) - .status(success ? JobLogStatusEnum.SUCCESS.getStatus() : JobLogStatusEnum.FAILURE.getStatus()).result(result).build(); + .status(success ? JobLogStatusEnum.SUCCESS.getStatus() : JobLogStatusEnum.FAILURE.getStatus()) + .result(result).build(); jobLogMapper.updateById(updateObj); } catch (Exception ex) { log.error("[updateJobLogResultAsync][logId({}) endTime({}) duration({}) success({}) result({})]", @@ -72,19 +72,9 @@ public class JobLogServiceImpl implements JobLogService { return jobLogMapper.selectById(id); } - @Override - public List getJobLogList(Collection ids) { - return jobLogMapper.selectBatchIds(ids); - } - @Override public PageResult getJobLogPage(JobLogPageReqVO pageReqVO) { return jobLogMapper.selectPage(pageReqVO); } - @Override - public List getJobLogList(JobLogExportReqVO exportReqVO) { - return jobLogMapper.selectList(exportReqVO); - } - } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobService.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobService.java index bd5dd646d..81a9de9ba 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobService.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobService.java @@ -1,10 +1,8 @@ package cn.iocoder.yudao.module.infra.service.job; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobCreateReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobPageReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobUpdateReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobDO; import org.quartz.SchedulerException; @@ -25,14 +23,14 @@ public interface JobService { * @param createReqVO 创建信息 * @return 编号 */ - Long createJob(@Valid JobCreateReqVO createReqVO) throws SchedulerException; + Long createJob(@Valid JobSaveReqVO createReqVO) throws SchedulerException; /** * 更新定时任务 * * @param updateReqVO 更新信息 */ - void updateJob(@Valid JobUpdateReqVO updateReqVO) throws SchedulerException; + void updateJob(@Valid JobSaveReqVO updateReqVO) throws SchedulerException; /** * 更新定时任务的状态 @@ -80,12 +78,4 @@ public interface JobService { */ PageResult getJobPage(JobPageReqVO pageReqVO); - /** - * 获得定时任务列表, 用于 Excel 导出 - * - * @param exportReqVO 查询条件 - * @return 定时任务分页 - */ - List getJobList(JobExportReqVO exportReqVO); - } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImpl.java index 498d816b8..40fe98273 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImpl.java @@ -1,13 +1,11 @@ package cn.iocoder.yudao.module.infra.service.job; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.quartz.core.scheduler.SchedulerManager; import cn.iocoder.yudao.framework.quartz.core.util.CronUtils; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobCreateReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobPageReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobUpdateReqVO; -import cn.iocoder.yudao.module.infra.convert.job.JobConvert; +import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobDO; import cn.iocoder.yudao.module.infra.dal.mysql.job.JobMapper; import cn.iocoder.yudao.module.infra.enums.job.JobStatusEnum; @@ -21,8 +19,8 @@ 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.infra.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.containsAny; +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; /** * 定时任务 Service 实现类 @@ -41,14 +39,14 @@ public class JobServiceImpl implements JobService { @Override @Transactional(rollbackFor = Exception.class) - public Long createJob(JobCreateReqVO createReqVO) throws SchedulerException { + public Long createJob(JobSaveReqVO createReqVO) throws SchedulerException { validateCronExpression(createReqVO.getCronExpression()); // 校验唯一性 if (jobMapper.selectByHandlerName(createReqVO.getHandlerName()) != null) { throw exception(JOB_HANDLER_EXISTS); } // 插入 - JobDO job = JobConvert.INSTANCE.convert(createReqVO); + JobDO job = BeanUtils.toBean(createReqVO, JobDO.class); job.setStatus(JobStatusEnum.INIT.getStatus()); fillJobMonitorTimeoutEmpty(job); jobMapper.insert(job); @@ -66,7 +64,7 @@ public class JobServiceImpl implements JobService { @Override @Transactional(rollbackFor = Exception.class) - public void updateJob(JobUpdateReqVO updateReqVO) throws SchedulerException { + public void updateJob(JobSaveReqVO updateReqVO) throws SchedulerException { validateCronExpression(updateReqVO.getCronExpression()); // 校验存在 JobDO job = validateJobExists(updateReqVO.getId()); @@ -75,7 +73,7 @@ public class JobServiceImpl implements JobService { throw exception(JOB_UPDATE_ONLY_NORMAL_STATUS); } // 更新 - JobDO updateObj = JobConvert.INSTANCE.convert(updateReqVO); + JobDO updateObj = BeanUtils.toBean(updateReqVO, JobDO.class); fillJobMonitorTimeoutEmpty(updateObj); jobMapper.updateById(updateObj); @@ -159,11 +157,6 @@ public class JobServiceImpl implements JobService { return jobMapper.selectPage(pageReqVO); } - @Override - public List getJobList(JobExportReqVO exportReqVO) { - return jobMapper.selectList(exportReqVO); - } - private static void fillJobMonitorTimeoutEmpty(JobDO job) { if (job.getMonitorTimeout() == null) { job.setMonitorTimeout(0); diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/job/JobLogServiceImplTest.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/job/JobLogServiceImplTest.java index efba0c0cf..9061297ec 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/job/JobLogServiceImplTest.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/job/JobLogServiceImplTest.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.infra.service.job; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogPageReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobLogDO; import cn.iocoder.yudao.module.infra.dal.mysql.job.JobLogMapper; @@ -12,14 +11,11 @@ import org.springframework.context.annotation.Import; import javax.annotation.Resource; import java.time.LocalDateTime; -import java.util.Collection; -import java.util.List; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; 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.RandomUtils.*; -import static java.util.Collections.singleton; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -110,23 +106,6 @@ public class JobLogServiceImplTest extends BaseDbUnitTest { assertPojoEquals(dbJobLog, jobLog); } - @Test - public void testGetJobLogList() { - // mock 数据 - JobLogDO dbJobLog = randomPojo(JobLogDO.class, o -> o.setExecuteIndex(1)); - jobLogMapper.insert(dbJobLog); - // 测试 handlerName 不匹配 - jobLogMapper.insert(cloneIgnoreId(dbJobLog, o -> {})); - // 准备参数 - Collection ids = singleton(dbJobLog.getId()); - - // 调用 - List list = jobLogService.getJobLogList(ids); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbJobLog, list.get(0)); - } - @Test public void testGetJobPage() { // mock 数据 @@ -164,40 +143,4 @@ public class JobLogServiceImplTest extends BaseDbUnitTest { assertPojoEquals(dbJobLog, pageResult.getList().get(0)); } - @Test - public void testGetJobList_export() { - // mock 数据 - JobLogDO dbJobLog = randomPojo(JobLogDO.class, o -> { - o.setExecuteIndex(1); - o.setHandlerName("handlerName 单元测试"); - o.setStatus(JobLogStatusEnum.SUCCESS.getStatus()); - o.setBeginTime(buildTime(2021, 1, 8)); - o.setEndTime(buildTime(2021, 1, 8)); - }); - jobLogMapper.insert(dbJobLog); - // 测试 jobId 不匹配 - jobLogMapper.insert(cloneIgnoreId(dbJobLog, o -> o.setJobId(randomLongId()))); - // 测试 handlerName 不匹配 - jobLogMapper.insert(cloneIgnoreId(dbJobLog, o -> o.setHandlerName(randomString()))); - // 测试 beginTime 不匹配 - jobLogMapper.insert(cloneIgnoreId(dbJobLog, o -> o.setBeginTime(buildTime(2021, 1, 7)))); - // 测试 endTime 不匹配 - jobLogMapper.insert(cloneIgnoreId(dbJobLog, o -> o.setEndTime(buildTime(2021, 1, 9)))); - // 测试 status 不匹配 - jobLogMapper.insert(cloneIgnoreId(dbJobLog, o -> o.setStatus(JobLogStatusEnum.FAILURE.getStatus()))); - // 准备参数 - JobLogExportReqVO reqVo = new JobLogExportReqVO(); - reqVo.setJobId(dbJobLog.getJobId()); - reqVo.setHandlerName("单元"); - reqVo.setBeginTime(dbJobLog.getBeginTime()); - reqVo.setEndTime(dbJobLog.getEndTime()); - reqVo.setStatus(JobLogStatusEnum.SUCCESS.getStatus()); - - // 调用 - List list = jobLogService.getJobLogList(reqVo); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbJobLog, list.get(0)); - } - } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImplTest.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImplTest.java index f10c40365..fe673fec2 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImplTest.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImplTest.java @@ -3,10 +3,8 @@ package cn.iocoder.yudao.module.infra.service.job; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.quartz.core.scheduler.SchedulerManager; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobCreateReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobPageReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobUpdateReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobDO; import cn.iocoder.yudao.module.infra.dal.mysql.job.JobMapper; import cn.iocoder.yudao.module.infra.enums.job.JobStatusEnum; @@ -16,17 +14,13 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; import javax.annotation.Resource; -import java.util.Collection; -import java.util.List; -import static cn.hutool.core.util.RandomUtil.randomEle; 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.randomPojo; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString; import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; -import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; @@ -44,7 +38,7 @@ public class JobServiceImplTest extends BaseDbUnitTest { @Test public void testCreateJob_cronExpressionValid() { // 准备参数。Cron 表达式为 String 类型,默认随机字符串。 - JobCreateReqVO reqVO = randomPojo(JobCreateReqVO.class); + JobSaveReqVO reqVO = randomPojo(JobSaveReqVO.class); // 调用,并断言异常 assertServiceException(() -> jobService.createJob(reqVO), JOB_CRON_EXPRESSION_VALID); @@ -53,7 +47,7 @@ public class JobServiceImplTest extends BaseDbUnitTest { @Test public void testCreateJob_jobHandlerExists() throws SchedulerException { // 准备参数 指定 Cron 表达式 - JobCreateReqVO reqVO = randomPojo(JobCreateReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *")); + JobSaveReqVO reqVO = randomPojo(JobSaveReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *")); // 调用 jobService.createJob(reqVO); @@ -64,7 +58,8 @@ public class JobServiceImplTest extends BaseDbUnitTest { @Test public void testCreateJob_success() throws SchedulerException { // 准备参数 指定 Cron 表达式 - JobCreateReqVO reqVO = randomPojo(JobCreateReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *")); + JobSaveReqVO reqVO = randomPojo(JobSaveReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *")) + .setId(null); // 调用 Long jobId = jobService.createJob(reqVO); @@ -72,7 +67,7 @@ public class JobServiceImplTest extends BaseDbUnitTest { assertNotNull(jobId); // 校验记录的属性是否正确 JobDO job = jobMapper.selectById(jobId); - assertPojoEquals(reqVO, job); + assertPojoEquals(reqVO, job, "id"); assertEquals(JobStatusEnum.NORMAL.getStatus(), job.getStatus()); // 校验调用 verify(schedulerManager).addJob(eq(job.getId()), eq(job.getHandlerName()), eq(job.getHandlerParam()), @@ -82,7 +77,7 @@ public class JobServiceImplTest extends BaseDbUnitTest { @Test public void testUpdateJob_jobNotExists(){ // 准备参数 - JobUpdateReqVO reqVO = randomPojo(JobUpdateReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *")); + JobSaveReqVO reqVO = randomPojo(JobSaveReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *")); // 调用,并断言异常 assertServiceException(() -> jobService.updateJob(reqVO), JOB_NOT_EXISTS); @@ -94,7 +89,7 @@ public class JobServiceImplTest extends BaseDbUnitTest { JobDO job = randomPojo(JobDO.class, o -> o.setStatus(JobStatusEnum.INIT.getStatus())); jobMapper.insert(job); // 准备参数 - JobUpdateReqVO updateReqVO = randomPojo(JobUpdateReqVO.class, o -> { + JobSaveReqVO updateReqVO = randomPojo(JobSaveReqVO.class, o -> { o.setId(job.getId()); o.setCronExpression("0 0/1 * * * ? *"); }); @@ -110,7 +105,7 @@ public class JobServiceImplTest extends BaseDbUnitTest { JobDO job = randomPojo(JobDO.class, o -> o.setStatus(JobStatusEnum.NORMAL.getStatus())); jobMapper.insert(job); // 准备参数 - JobUpdateReqVO updateReqVO = randomPojo(JobUpdateReqVO.class, o -> { + JobSaveReqVO updateReqVO = randomPojo(JobSaveReqVO.class, o -> { o.setId(job.getId()); o.setCronExpression("0 0/1 * * * ? *"); }); @@ -200,25 +195,6 @@ public class JobServiceImplTest extends BaseDbUnitTest { verify(schedulerManager).deleteJob(eq(job.getHandlerName())); } - @Test - public void testGetJobList() { - // mock 数据 - JobDO dbJob = randomPojo(JobDO.class, o -> { - o.setStatus(randomEle(JobStatusEnum.values()).getStatus()); // 保证 status 的范围 - }); - jobMapper.insert(dbJob); - // 测试 id 不匹配 - jobMapper.insert(cloneIgnoreId(dbJob, o -> {})); - - // 准备参数 - Collection ids = singletonList(dbJob.getId()); - // 调用 - List list = jobService.getJobList(ids); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbJob, list.get(0)); - } - @Test public void testGetJobPage() { // mock 数据 @@ -248,34 +224,6 @@ public class JobServiceImplTest extends BaseDbUnitTest { assertPojoEquals(dbJob, pageResult.getList().get(0)); } - @Test - public void testGetJobList_export() { - // mock 数据 - JobDO dbJob = randomPojo(JobDO.class, o -> { - o.setName("定时任务测试"); - o.setHandlerName("handlerName 单元测试"); - o.setStatus(JobStatusEnum.INIT.getStatus()); - }); - jobMapper.insert(dbJob); - // 测试 name 不匹配 - jobMapper.insert(cloneIgnoreId(dbJob, o -> o.setName("土豆"))); - // 测试 status 不匹配 - jobMapper.insert(cloneIgnoreId(dbJob, o -> o.setStatus(JobStatusEnum.NORMAL.getStatus()))); - // 测试 handlerName 不匹配 - jobMapper.insert(cloneIgnoreId(dbJob, o -> o.setHandlerName(randomString()))); - // 准备参数 - JobExportReqVO reqVo = new JobExportReqVO(); - reqVo.setName("定时"); - reqVo.setStatus(JobStatusEnum.INIT.getStatus()); - reqVo.setHandlerName("单元"); - - // 调用 - List list = jobService.getJobList(reqVo); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbJob, list.get(0)); - } - @Test public void testGetJob() { // mock 数据 From 30fef09eee81577d83afac42e6229dd7188ad5dc Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 3 Dec 2023 18:32:47 +0800 Subject: [PATCH 19/19] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20error?= =?UTF-8?q?Log=20=E5=92=8C=20accessLog=20=E6=A8=A1=E5=9D=97=E7=9A=84=20VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatis/core/mapper/BaseMapperX.java | 2 +- .../admin/logger/ApiAccessLogController.java | 22 ++--- .../admin/logger/ApiErrorLogController.java | 24 ++--- .../vo/apiaccesslog/ApiAccessLogBaseVO.java | 75 -------------- .../vo/apiaccesslog/ApiAccessLogExcelVO.java | 65 ------------ .../apiaccesslog/ApiAccessLogExportReqVO.java | 37 ------- .../vo/apiaccesslog/ApiAccessLogRespVO.java | 70 ++++++++++++- .../vo/apierrorlog/ApiErrorLogBaseVO.java | 95 ------------------ .../vo/apierrorlog/ApiErrorLogExcelVO.java | 90 ----------------- .../apierrorlog/ApiErrorLogExportReqVO.java | 34 ------- .../vo/apierrorlog/ApiErrorLogRespVO.java | 98 +++++++++++++++++-- .../convert/logger/ApiAccessLogConvert.java | 33 ------- .../convert/logger/ApiErrorLogConvert.java | 31 ------ .../dal/mysql/logger/ApiAccessLogMapper.java | 15 --- .../dal/mysql/logger/ApiErrorLogMapper.java | 14 --- .../service/logger/ApiAccessLogService.java | 11 --- .../logger/ApiAccessLogServiceImpl.java | 11 +-- .../service/logger/ApiErrorLogService.java | 11 --- .../logger/ApiErrorLogServiceImpl.java | 14 +-- .../logger/ApiAccessLogServiceImplTest.java | 45 --------- .../logger/ApiErrorLogServiceImplTest.java | 42 -------- 21 files changed, 185 insertions(+), 654 deletions(-) delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apiaccesslog/ApiAccessLogBaseVO.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apiaccesslog/ApiAccessLogExcelVO.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apiaccesslog/ApiAccessLogExportReqVO.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apierrorlog/ApiErrorLogBaseVO.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apierrorlog/ApiErrorLogExcelVO.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apierrorlog/ApiErrorLogExportReqVO.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/logger/ApiAccessLogConvert.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/logger/ApiErrorLogConvert.java diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java index 6a76024d5..023611bbc 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java @@ -28,7 +28,7 @@ public interface BaseMapperX extends MPJBaseMapper { default PageResult selectPage(PageParam pageParam, @Param("ew") Wrapper queryWrapper) { // 特殊:不分页,直接查询全部 - if (PageParam.PAGE_SIZE_NONE.equals(pageParam.getPageNo())) { + if (PageParam.PAGE_SIZE_NONE.equals(pageParam.getPageSize())) { List list = selectList(queryWrapper); return new PageResult<>(list, (long) list.size()); } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/ApiAccessLogController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/ApiAccessLogController.java index 641e1c23b..0d027633e 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/ApiAccessLogController.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/ApiAccessLogController.java @@ -1,18 +1,17 @@ package cn.iocoder.yudao.module.infra.controller.admin.logger; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogExcelVO; -import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO; import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogRespVO; -import cn.iocoder.yudao.module.infra.convert.logger.ApiAccessLogConvert; import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiAccessLogDO; import cn.iocoder.yudao.module.infra.service.logger.ApiAccessLogService; -import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; @@ -40,21 +39,22 @@ public class ApiAccessLogController { @GetMapping("/page") @Operation(summary = "获得API 访问日志分页") @PreAuthorize("@ss.hasPermission('infra:api-access-log:query')") - public CommonResult> getApiAccessLogPage(@Valid ApiAccessLogPageReqVO pageVO) { - PageResult pageResult = apiAccessLogService.getApiAccessLogPage(pageVO); - return success(ApiAccessLogConvert.INSTANCE.convertPage(pageResult)); + public CommonResult> getApiAccessLogPage(@Valid ApiAccessLogPageReqVO pageReqVO) { + PageResult pageResult = apiAccessLogService.getApiAccessLogPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, ApiAccessLogRespVO.class)); } @GetMapping("/export-excel") @Operation(summary = "导出API 访问日志 Excel") @PreAuthorize("@ss.hasPermission('infra:api-access-log:export')") @OperateLog(type = EXPORT) - public void exportApiAccessLogExcel(@Valid ApiAccessLogExportReqVO exportReqVO, + public void exportApiAccessLogExcel(@Valid ApiAccessLogPageReqVO exportReqVO, HttpServletResponse response) throws IOException { - List list = apiAccessLogService.getApiAccessLogList(exportReqVO); + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = apiAccessLogService.getApiAccessLogPage(exportReqVO).getList(); // 导出 Excel - List datas = ApiAccessLogConvert.INSTANCE.convertList02(list); - ExcelUtils.write(response, "API 访问日志.xls", "数据", ApiAccessLogExcelVO.class, datas); + ExcelUtils.write(response, "API 访问日志.xls", "数据", ApiAccessLogRespVO.class, + BeanUtils.toBean(list, ApiAccessLogRespVO.class)); } } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/ApiErrorLogController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/ApiErrorLogController.java index 191bd94d0..ecb0c45d5 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/ApiErrorLogController.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/ApiErrorLogController.java @@ -1,20 +1,19 @@ package cn.iocoder.yudao.module.infra.controller.admin.logger; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogExcelVO; -import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogPageReqVO; import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogRespVO; -import cn.iocoder.yudao.module.infra.convert.logger.ApiErrorLogConvert; import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiErrorLogDO; import cn.iocoder.yudao.module.infra.service.logger.ApiErrorLogService; -import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; -import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -54,21 +53,22 @@ public class ApiErrorLogController { @GetMapping("/page") @Operation(summary = "获得 API 错误日志分页") @PreAuthorize("@ss.hasPermission('infra:api-error-log:query')") - public CommonResult> getApiErrorLogPage(@Valid ApiErrorLogPageReqVO pageVO) { - PageResult pageResult = apiErrorLogService.getApiErrorLogPage(pageVO); - return success(ApiErrorLogConvert.INSTANCE.convertPage(pageResult)); + public CommonResult> getApiErrorLogPage(@Valid ApiErrorLogPageReqVO pageReqVO) { + PageResult pageResult = apiErrorLogService.getApiErrorLogPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, ApiErrorLogRespVO.class)); } @GetMapping("/export-excel") @Operation(summary = "导出 API 错误日志 Excel") @PreAuthorize("@ss.hasPermission('infra:api-error-log:export')") @OperateLog(type = EXPORT) - public void exportApiErrorLogExcel(@Valid ApiErrorLogExportReqVO exportReqVO, + public void exportApiErrorLogExcel(@Valid ApiErrorLogPageReqVO exportReqVO, HttpServletResponse response) throws IOException { - List list = apiErrorLogService.getApiErrorLogList(exportReqVO); + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = apiErrorLogService.getApiErrorLogPage(exportReqVO).getList(); // 导出 Excel - List datas = ApiErrorLogConvert.INSTANCE.convertList02(list); - ExcelUtils.write(response, "API 错误日志.xls", "数据", ApiErrorLogExcelVO.class, datas); + ExcelUtils.write(response, "API 错误日志.xls", "数据", ApiErrorLogRespVO.class, + BeanUtils.toBean(list, ApiErrorLogRespVO.class)); } } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apiaccesslog/ApiAccessLogBaseVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apiaccesslog/ApiAccessLogBaseVO.java deleted file mode 100644 index daa3e72b7..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apiaccesslog/ApiAccessLogBaseVO.java +++ /dev/null @@ -1,75 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import javax.validation.constraints.NotNull; -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -/** -* API 访问日志 Base VO,提供给添加、修改、详细的子 VO 使用 -* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 -*/ -@Data -public class ApiAccessLogBaseVO { - - @Schema(description = "链路追踪编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "66600cb6-7852-11eb-9439-0242ac130002") - @NotNull(message = "链路追踪编号不能为空") - private String traceId; - - @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "666") - @NotNull(message = "用户编号不能为空") - private Long userId; - - @Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") - @NotNull(message = "用户类型不能为空") - private Integer userType; - - @Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "dashboard") - @NotNull(message = "应用名不能为空") - private String applicationName; - - @Schema(description = "请求方法名", requiredMode = Schema.RequiredMode.REQUIRED, example = "GET") - @NotNull(message = "请求方法名不能为空") - private String requestMethod; - - @Schema(description = "请求地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "/xxx/yyy") - @NotNull(message = "请求地址不能为空") - private String requestUrl; - - @Schema(description = "请求参数") - private String requestParams; - - @Schema(description = "用户 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "127.0.0.1") - @NotNull(message = "用户 IP不能为空") - private String userIp; - - @Schema(description = "浏览器 UA", requiredMode = Schema.RequiredMode.REQUIRED, example = "Mozilla/5.0") - @NotNull(message = "浏览器 UA不能为空") - private String userAgent; - - @Schema(description = "开始请求时间", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "开始请求时间不能为空") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime beginTime; - - @Schema(description = "结束请求时间", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "结束请求时间不能为空") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime endTime; - - @Schema(description = "执行时长", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") - @NotNull(message = "执行时长不能为空") - private Integer duration; - - @Schema(description = "结果码", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") - @NotNull(message = "结果码不能为空") - private Integer resultCode; - - @Schema(description = "结果提示", example = "芋道源码,牛逼!") - private String resultMsg; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apiaccesslog/ApiAccessLogExcelVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apiaccesslog/ApiAccessLogExcelVO.java deleted file mode 100644 index 21447743d..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apiaccesslog/ApiAccessLogExcelVO.java +++ /dev/null @@ -1,65 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import cn.iocoder.yudao.module.system.enums.DictTypeConstants; -import com.alibaba.excel.annotation.ExcelProperty; -import lombok.Data; - -import java.time.LocalDateTime; - -/** - * API 访问日志 Excel VO - * - * @author 芋道源码 - */ -@Data -public class ApiAccessLogExcelVO { - - @ExcelProperty("日志主键") - private Long id; - - @ExcelProperty("链路追踪编号") - private String traceId; - - @ExcelProperty("用户编号") - private Long userId; - - @ExcelProperty(value = "用户类型", converter = DictConvert.class) - @DictFormat(DictTypeConstants.USER_TYPE) - private Integer userType; - - @ExcelProperty("应用名") - private String applicationName; - - @ExcelProperty("请求方法名") - private String requestMethod; - - @ExcelProperty("请求地址") - private String requestUrl; - - @ExcelProperty("请求参数") - private String requestParams; - - @ExcelProperty("用户 IP") - private String userIp; - - @ExcelProperty("浏览器 UA") - private String userAgent; - - @ExcelProperty("开始请求时间") - private LocalDateTime beginTime; - - @ExcelProperty("结束请求时间") - private LocalDateTime endTime; - - @ExcelProperty("执行时长") - private Integer duration; - - @ExcelProperty("结果码") - private Integer resultCode; - - @ExcelProperty("结果提示") - private String resultMsg; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apiaccesslog/ApiAccessLogExportReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apiaccesslog/ApiAccessLogExportReqVO.java deleted file mode 100644 index 8010e3586..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apiaccesslog/ApiAccessLogExportReqVO.java +++ /dev/null @@ -1,37 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - API 访问日志 Excel 导出 Request VO,参数和 ApiAccessLogPageReqVO 是一致的") -@Data -public class ApiAccessLogExportReqVO { - - @Schema(description = "用户编号", example = "666") - private Long userId; - - @Schema(description = "用户类型", example = "2") - private Integer userType; - - @Schema(description = "应用名", example = "dashboard") - private String applicationName; - - @Schema(description = "请求地址,模糊匹配", example = "/xxx/yyy") - private String requestUrl; - - @Schema(description = "开始时间", example = "[2022-07-01 00:00:00, 2022-07-01 23:59:59]") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] beginTime; - - @Schema(description = "执行时长,大于等于,单位:毫秒", example = "100") - private Integer duration; - - @Schema(description = "结果码", example = "0") - private Integer resultCode; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apiaccesslog/ApiAccessLogRespVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apiaccesslog/ApiAccessLogRespVO.java index 4a6ec8ae5..5e3f3c976 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apiaccesslog/ApiAccessLogRespVO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apiaccesslog/ApiAccessLogRespVO.java @@ -1,21 +1,81 @@ package cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; import java.time.LocalDateTime; @Schema(description = "管理后台 - API 访问日志 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class ApiAccessLogRespVO extends ApiAccessLogBaseVO { +@ExcelIgnoreUnannotated +public class ApiAccessLogRespVO { @Schema(description = "日志主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("日志主键") private Long id; + @Schema(description = "链路追踪编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "66600cb6-7852-11eb-9439-0242ac130002") + @ExcelProperty("链路追踪编号") + private String traceId; + + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "666") + @ExcelProperty("用户编号") + private Long userId; + + @Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + @ExcelProperty(value = "用户类型", converter = DictConvert.class) + @DictFormat(DictTypeConstants.USER_TYPE) + private Integer userType; + + @Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "dashboard") + @ExcelProperty("应用名") + private String applicationName; + + @Schema(description = "请求方法名", requiredMode = Schema.RequiredMode.REQUIRED, example = "GET") + @ExcelProperty("请求方法名") + private String requestMethod; + + @Schema(description = "请求地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "/xxx/yyy") + @ExcelProperty("请求地址") + private String requestUrl; + + @Schema(description = "请求参数") + @ExcelProperty("请求参数") + private String requestParams; + + @Schema(description = "用户 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "127.0.0.1") + @ExcelProperty("用户 IP") + private String userIp; + + @Schema(description = "浏览器 UA", requiredMode = Schema.RequiredMode.REQUIRED, example = "Mozilla/5.0") + @ExcelProperty("浏览器 UA") + private String userAgent; + + @Schema(description = "开始请求时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("开始请求时间") + private LocalDateTime beginTime; + + @Schema(description = "结束请求时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("结束请求时间") + private LocalDateTime endTime; + + @Schema(description = "执行时长", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") + @ExcelProperty("执行时长") + private Integer duration; + + @Schema(description = "结果码", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") + @ExcelProperty("结果码") + private Integer resultCode; + + @Schema(description = "结果提示", example = "芋道源码,牛逼!") + @ExcelProperty("结果提示") + private String resultMsg; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apierrorlog/ApiErrorLogBaseVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apierrorlog/ApiErrorLogBaseVO.java deleted file mode 100644 index 92fd9751d..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apierrorlog/ApiErrorLogBaseVO.java +++ /dev/null @@ -1,95 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import javax.validation.constraints.NotNull; -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -/** -* API 错误日志 Base VO,提供给添加、修改、详细的子 VO 使用 -* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 -*/ -@Data -public class ApiErrorLogBaseVO { - - @Schema(description = "链路追踪编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "66600cb6-7852-11eb-9439-0242ac130002") - @NotNull(message = "链路追踪编号不能为空") - private String traceId; - - @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "666") - @NotNull(message = "用户编号不能为空") - private Integer userId; - - @Schema(description = "用户类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "用户类型不能为空") - private Integer userType; - - @Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "dashboard") - @NotNull(message = "应用名不能为空") - private String applicationName; - - @Schema(description = "请求方法名", requiredMode = Schema.RequiredMode.REQUIRED, example = "GET") - @NotNull(message = "请求方法名不能为空") - private String requestMethod; - - @Schema(description = "请求地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "/xx/yy") - @NotNull(message = "请求地址不能为空") - private String requestUrl; - - @Schema(description = "请求参数", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "请求参数不能为空") - private String requestParams; - - @Schema(description = "用户 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "127.0.0.1") - @NotNull(message = "用户 IP不能为空") - private String userIp; - - @Schema(description = "浏览器 UA", requiredMode = Schema.RequiredMode.REQUIRED, example = "Mozilla/5.0") - @NotNull(message = "浏览器 UA不能为空") - private String userAgent; - - @Schema(description = "异常发生时间", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "异常发生时间不能为空") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime exceptionTime; - - @Schema(description = "异常名", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "异常名不能为空") - private String exceptionName; - - @Schema(description = "异常导致的消息", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "异常导致的消息不能为空") - private String exceptionMessage; - - @Schema(description = "异常导致的根消息", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "异常导致的根消息不能为空") - private String exceptionRootCauseMessage; - - @Schema(description = "异常的栈轨迹", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "异常的栈轨迹不能为空") - private String exceptionStackTrace; - - @Schema(description = "异常发生的类全名", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "异常发生的类全名不能为空") - private String exceptionClassName; - - @Schema(description = "异常发生的类文件", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "异常发生的类文件不能为空") - private String exceptionFileName; - - @Schema(description = "异常发生的方法名", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "异常发生的方法名不能为空") - private String exceptionMethodName; - - @Schema(description = "异常发生的方法所在行", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "异常发生的方法所在行不能为空") - private Integer exceptionLineNumber; - - @Schema(description = "处理状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") - @NotNull(message = "处理状态不能为空") - private Integer processStatus; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apierrorlog/ApiErrorLogExcelVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apierrorlog/ApiErrorLogExcelVO.java deleted file mode 100644 index 08f10894f..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apierrorlog/ApiErrorLogExcelVO.java +++ /dev/null @@ -1,90 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; -import com.alibaba.excel.annotation.ExcelProperty; -import lombok.Data; - -import java.time.LocalDateTime; - -/** - * API 错误日志 Excel VO - * - * @author 芋道源码 - */ -@Data -public class ApiErrorLogExcelVO { - - @ExcelProperty("编号") - private Integer id; - - @ExcelProperty("链路追踪编号") - private String traceId; - - @ExcelProperty("用户编号") - private Integer userId; - - @ExcelProperty(value = "用户类型", converter = DictConvert.class) - @DictFormat(cn.iocoder.yudao.module.system.enums.DictTypeConstants.USER_TYPE) - private Integer userType; - - @ExcelProperty("应用名") - private String applicationName; - - @ExcelProperty("请求方法名") - private String requestMethod; - - @ExcelProperty("请求地址") - private String requestUrl; - - @ExcelProperty("请求参数") - private String requestParams; - - @ExcelProperty("用户 IP") - private String userIp; - - @ExcelProperty("浏览器 UA") - private String userAgent; - - @ExcelProperty("异常发生时间") - private LocalDateTime exceptionTime; - - @ExcelProperty("异常名") - private String exceptionName; - - @ExcelProperty("异常导致的消息") - private String exceptionMessage; - - @ExcelProperty("异常导致的根消息") - private String exceptionRootCauseMessage; - - @ExcelProperty("异常的栈轨迹") - private String exceptionStackTrace; - - @ExcelProperty("异常发生的类全名") - private String exceptionClassName; - - @ExcelProperty("异常发生的类文件") - private String exceptionFileName; - - @ExcelProperty("异常发生的方法名") - private String exceptionMethodName; - - @ExcelProperty("异常发生的方法所在行") - private Integer exceptionLineNumber; - - @ExcelProperty("创建时间") - private LocalDateTime createTime; - - @ExcelProperty(value = "处理状态", converter = DictConvert.class) - @DictFormat(DictTypeConstants.API_ERROR_LOG_PROCESS_STATUS) - private Integer processStatus; - - @ExcelProperty("处理时间") - private LocalDateTime processTime; - - @ExcelProperty("处理用户编号") - private Integer processUserId; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apierrorlog/ApiErrorLogExportReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apierrorlog/ApiErrorLogExportReqVO.java deleted file mode 100644 index 792f2d7c0..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apierrorlog/ApiErrorLogExportReqVO.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - API 错误日志 Excel 导出 Request VO,参数和 ApiErrorLogPageReqVO 是一致的") -@Data -public class ApiErrorLogExportReqVO { - - @Schema(description = "用户编号", example = "666") - private Long userId; - - @Schema(description = "用户类型", example = "1") - private Integer userType; - - @Schema(description = "应用名", example = "dashboard") - private String applicationName; - - @Schema(description = "请求地址", example = "/xx/yy") - private String requestUrl; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @Schema(description = "异常发生时间") - private LocalDateTime[] exceptionTime; - - @Schema(description = "处理状态", example = "0") - private Integer processStatus; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apierrorlog/ApiErrorLogRespVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apierrorlog/ApiErrorLogRespVO.java index 5b2c8f8c3..53f52f02c 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apierrorlog/ApiErrorLogRespVO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/logger/vo/apierrorlog/ApiErrorLogRespVO.java @@ -1,28 +1,112 @@ package cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; import java.time.LocalDateTime; @Schema(description = "管理后台 - API 错误日志 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class ApiErrorLogRespVO extends ApiErrorLogBaseVO { +@ExcelIgnoreUnannotated +public class ApiErrorLogRespVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("编号") private Integer id; - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - private LocalDateTime createTime; + @Schema(description = "链路追踪编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "66600cb6-7852-11eb-9439-0242ac130002") + @ExcelProperty("链路追踪编号") + private String traceId; + + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "666") + @ExcelProperty("用户编号") + private Integer userId; + + @Schema(description = "用户类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "用户类型", converter = DictConvert.class) + @DictFormat(cn.iocoder.yudao.module.system.enums.DictTypeConstants.USER_TYPE) + private Integer userType; + + @Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "dashboard") + @ExcelProperty("应用名") + private String applicationName; + + @Schema(description = "请求方法名", requiredMode = Schema.RequiredMode.REQUIRED, example = "GET") + @ExcelProperty("请求方法名") + private String requestMethod; + + @Schema(description = "请求地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "/xx/yy") + @ExcelProperty("请求地址") + private String requestUrl; + + @Schema(description = "请求参数", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("请求参数") + private String requestParams; + + @Schema(description = "用户 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "127.0.0.1") + @ExcelProperty("用户 IP") + private String userIp; + + @Schema(description = "浏览器 UA", requiredMode = Schema.RequiredMode.REQUIRED, example = "Mozilla/5.0") + @ExcelProperty("浏览器 UA") + private String userAgent; + + @Schema(description = "异常发生时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("异常发生时间") + private LocalDateTime exceptionTime; + + @Schema(description = "异常名", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("异常名") + private String exceptionName; + + @Schema(description = "异常导致的消息", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("异常导致的消息") + private String exceptionMessage; + + @Schema(description = "异常导致的根消息", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("异常导致的根消息") + private String exceptionRootCauseMessage; + + @Schema(description = "异常的栈轨迹", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("异常的栈轨迹") + private String exceptionStackTrace; + + @Schema(description = "异常发生的类全名", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("异常发生的类全名") + private String exceptionClassName; + + @Schema(description = "异常发生的类文件", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("异常发生的类文件") + private String exceptionFileName; + + @Schema(description = "异常发生的方法名", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("异常发生的方法名") + private String exceptionMethodName; + + @Schema(description = "异常发生的方法所在行", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("异常发生的方法所在行") + private Integer exceptionLineNumber; + + @Schema(description = "处理状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") + @ExcelProperty(value = "处理状态", converter = DictConvert.class) + @DictFormat(DictTypeConstants.API_ERROR_LOG_PROCESS_STATUS) + private Integer processStatus; @Schema(description = "处理时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("处理时间") private LocalDateTime processTime; @Schema(description = "处理用户编号", example = "233") + @ExcelProperty("处理用户编号") private Integer processUserId; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; + } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/logger/ApiAccessLogConvert.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/logger/ApiAccessLogConvert.java deleted file mode 100644 index f3a80e8c0..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/logger/ApiAccessLogConvert.java +++ /dev/null @@ -1,33 +0,0 @@ -package cn.iocoder.yudao.module.infra.convert.logger; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO; -import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogExcelVO; -import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogRespVO; -import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiAccessLogDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -/** - * API 访问日志 Convert - * - * @author 芋道源码 - */ -@Mapper -public interface ApiAccessLogConvert { - - ApiAccessLogConvert INSTANCE = Mappers.getMapper(ApiAccessLogConvert.class); - - ApiAccessLogRespVO convert(ApiAccessLogDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); - - List convertList02(List list); - - ApiAccessLogDO convert(ApiAccessLogCreateReqDTO bean); - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/logger/ApiErrorLogConvert.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/logger/ApiErrorLogConvert.java deleted file mode 100644 index 778e171c7..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/logger/ApiErrorLogConvert.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.iocoder.yudao.module.infra.convert.logger; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO; -import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogExcelVO; -import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogRespVO; -import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiErrorLogDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -/** - * API 错误日志 Convert - * - * @author 芋道源码 - */ -@Mapper -public interface ApiErrorLogConvert { - - ApiErrorLogConvert INSTANCE = Mappers.getMapper(ApiErrorLogConvert.class); - - ApiErrorLogRespVO convert(ApiErrorLogDO bean); - - PageResult convertPage(PageResult page); - - List convertList02(List list); - - ApiErrorLogDO convert(ApiErrorLogCreateReqDTO bean); - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/logger/ApiAccessLogMapper.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/logger/ApiAccessLogMapper.java index 77c479817..dce30829f 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/logger/ApiAccessLogMapper.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/logger/ApiAccessLogMapper.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.infra.dal.mysql.logger; 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.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiAccessLogDO; import org.apache.ibatis.annotations.Delete; @@ -11,7 +10,6 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.time.LocalDateTime; -import java.util.List; /** * API 访问日志 Mapper @@ -34,19 +32,6 @@ public interface ApiAccessLogMapper extends BaseMapperX { ); } - default List selectList(ApiAccessLogExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .eqIfPresent(ApiAccessLogDO::getUserId, reqVO.getUserId()) - .eqIfPresent(ApiAccessLogDO::getUserType, reqVO.getUserType()) - .eqIfPresent(ApiAccessLogDO::getApplicationName, reqVO.getApplicationName()) - .likeIfPresent(ApiAccessLogDO::getRequestUrl, reqVO.getRequestUrl()) - .betweenIfPresent(ApiAccessLogDO::getBeginTime, reqVO.getBeginTime()) - .geIfPresent(ApiAccessLogDO::getDuration, reqVO.getDuration()) - .eqIfPresent(ApiAccessLogDO::getResultCode, reqVO.getResultCode()) - .orderByDesc(ApiAccessLogDO::getId) - ); - } - /** * 物理删除指定时间之前的日志 * diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/logger/ApiErrorLogMapper.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/logger/ApiErrorLogMapper.java index 4a9432ef4..b597d7929 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/logger/ApiErrorLogMapper.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/logger/ApiErrorLogMapper.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.infra.dal.mysql.logger; 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.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogPageReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiErrorLogDO; import org.apache.ibatis.annotations.Delete; @@ -11,7 +10,6 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.time.LocalDateTime; -import java.util.List; /** * API 错误日志 Mapper @@ -33,18 +31,6 @@ public interface ApiErrorLogMapper extends BaseMapperX { ); } - default List selectList(ApiErrorLogExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .eqIfPresent(ApiErrorLogDO::getUserId, reqVO.getUserId()) - .eqIfPresent(ApiErrorLogDO::getUserType, reqVO.getUserType()) - .eqIfPresent(ApiErrorLogDO::getApplicationName, reqVO.getApplicationName()) - .likeIfPresent(ApiErrorLogDO::getRequestUrl, reqVO.getRequestUrl()) - .betweenIfPresent(ApiErrorLogDO::getExceptionTime, reqVO.getExceptionTime()) - .eqIfPresent(ApiErrorLogDO::getProcessStatus, reqVO.getProcessStatus()) - .orderByDesc(ApiErrorLogDO::getId) - ); - } - /** * 物理删除指定时间之前的日志 * diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogService.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogService.java index 3f2a005e1..fd4e841af 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogService.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogService.java @@ -2,12 +2,9 @@ package cn.iocoder.yudao.module.infra.service.logger; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO; -import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiAccessLogDO; -import java.util.List; - /** * API 访问日志 Service 接口 * @@ -30,14 +27,6 @@ public interface ApiAccessLogService { */ PageResult getApiAccessLogPage(ApiAccessLogPageReqVO pageReqVO); - /** - * 获得 API 访问日志列表, 用于 Excel 导出 - * - * @param exportReqVO 查询条件 - * @return API 访问日志分页 - */ - List getApiAccessLogList(ApiAccessLogExportReqVO exportReqVO); - /** * 清理 exceedDay 天前的访问日志 * diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogServiceImpl.java index 12655542a..2d9c05c31 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogServiceImpl.java @@ -1,10 +1,9 @@ package cn.iocoder.yudao.module.infra.service.logger; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO; -import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO; -import cn.iocoder.yudao.module.infra.convert.logger.ApiAccessLogConvert; import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiAccessLogDO; import cn.iocoder.yudao.module.infra.dal.mysql.logger.ApiAccessLogMapper; import lombok.extern.slf4j.Slf4j; @@ -13,7 +12,6 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.time.LocalDateTime; -import java.util.List; /** * API 访问日志 Service 实现类 @@ -30,7 +28,7 @@ public class ApiAccessLogServiceImpl implements ApiAccessLogService { @Override public void createApiAccessLog(ApiAccessLogCreateReqDTO createDTO) { - ApiAccessLogDO apiAccessLog = ApiAccessLogConvert.INSTANCE.convert(createDTO); + ApiAccessLogDO apiAccessLog = BeanUtils.toBean(createDTO, ApiAccessLogDO.class); apiAccessLogMapper.insert(apiAccessLog); } @@ -39,11 +37,6 @@ public class ApiAccessLogServiceImpl implements ApiAccessLogService { return apiAccessLogMapper.selectPage(pageReqVO); } - @Override - public List getApiAccessLogList(ApiAccessLogExportReqVO exportReqVO) { - return apiAccessLogMapper.selectList(exportReqVO); - } - @Override @SuppressWarnings("DuplicatedCode") public Integer cleanAccessLog(Integer exceedDay, Integer deleteLimit) { diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogService.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogService.java index 04c1efd39..82eb3c4c0 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogService.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogService.java @@ -2,12 +2,9 @@ package cn.iocoder.yudao.module.infra.service.logger; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO; -import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogPageReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiErrorLogDO; -import java.util.List; - /** * API 错误日志 Service 接口 * @@ -30,14 +27,6 @@ public interface ApiErrorLogService { */ PageResult getApiErrorLogPage(ApiErrorLogPageReqVO pageReqVO); - /** - * 获得 API 错误日志列表, 用于 Excel 导出 - * - * @param exportReqVO 查询条件 - * @return API 错误日志分页 - */ - List getApiErrorLogList(ApiErrorLogExportReqVO exportReqVO); - /** * 更新 API 错误日志已处理 * diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogServiceImpl.java index 14a0141ef..29d742d19 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogServiceImpl.java @@ -1,10 +1,9 @@ package cn.iocoder.yudao.module.infra.service.logger; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO; -import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogPageReqVO; -import cn.iocoder.yudao.module.infra.convert.logger.ApiErrorLogConvert; import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiErrorLogDO; import cn.iocoder.yudao.module.infra.dal.mysql.logger.ApiErrorLogMapper; import cn.iocoder.yudao.module.infra.enums.logger.ApiErrorLogProcessStatusEnum; @@ -14,11 +13,9 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.time.LocalDateTime; -import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.API_ERROR_LOG_NOT_FOUND; -import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.API_ERROR_LOG_PROCESSED; +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; /** * API 错误日志 Service 实现类 @@ -35,7 +32,7 @@ public class ApiErrorLogServiceImpl implements ApiErrorLogService { @Override public void createApiErrorLog(ApiErrorLogCreateReqDTO createDTO) { - ApiErrorLogDO apiErrorLog = ApiErrorLogConvert.INSTANCE.convert(createDTO) + ApiErrorLogDO apiErrorLog = BeanUtils.toBean(createDTO, ApiErrorLogDO.class) .setProcessStatus(ApiErrorLogProcessStatusEnum.INIT.getStatus()); apiErrorLogMapper.insert(apiErrorLog); } @@ -45,11 +42,6 @@ public class ApiErrorLogServiceImpl implements ApiErrorLogService { return apiErrorLogMapper.selectPage(pageReqVO); } - @Override - public List getApiErrorLogList(ApiErrorLogExportReqVO exportReqVO) { - return apiErrorLogMapper.selectList(exportReqVO); - } - @Override public void updateApiErrorLogProcess(Long id, Integer processStatus, Long processUserId) { ApiErrorLogDO errorLog = apiErrorLogMapper.selectById(id); diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogServiceImplTest.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogServiceImplTest.java index 8ff2dd9bf..dc9b3d907 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogServiceImplTest.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogServiceImplTest.java @@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstant import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO; -import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiAccessLogDO; import cn.iocoder.yudao.module.infra.dal.mysql.logger.ApiAccessLogMapper; @@ -13,7 +12,6 @@ import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Import; import javax.annotation.Resource; -import java.util.List; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; @@ -75,49 +73,6 @@ public class ApiAccessLogServiceImplTest extends BaseDbUnitTest { assertPojoEquals(apiAccessLogDO, pageResult.getList().get(0)); } - @Test - public void testGetApiAccessLogList() { - ApiAccessLogDO apiAccessLogDO = randomPojo(ApiAccessLogDO.class, o -> { - o.setUserId(2233L); - o.setUserType(UserTypeEnum.ADMIN.getValue()); - o.setApplicationName("yudao-test"); - o.setRequestUrl("foo"); - o.setBeginTime(buildTime(2021, 3, 13)); - o.setDuration(1000); - o.setResultCode(GlobalErrorCodeConstants.SUCCESS.getCode()); - }); - apiAccessLogMapper.insert(apiAccessLogDO); - // 测试 userId 不匹配 - apiAccessLogMapper.insert(cloneIgnoreId(apiAccessLogDO, o -> o.setUserId(3344L))); - // 测试 userType 不匹配 - apiAccessLogMapper.insert(cloneIgnoreId(apiAccessLogDO, o -> o.setUserType(UserTypeEnum.MEMBER.getValue()))); - // 测试 applicationName 不匹配 - apiAccessLogMapper.insert(cloneIgnoreId(apiAccessLogDO, o -> o.setApplicationName("test"))); - // 测试 requestUrl 不匹配 - apiAccessLogMapper.insert(cloneIgnoreId(apiAccessLogDO, o -> o.setRequestUrl("bar"))); - // 测试 beginTime 不匹配:构造一个早期时间 2021-02-06 00:00:00 - apiAccessLogMapper.insert(cloneIgnoreId(apiAccessLogDO, o -> o.setBeginTime(buildTime(2021, 2, 6)))); - // 测试 duration 不匹配 - apiAccessLogMapper.insert(cloneIgnoreId(apiAccessLogDO, o -> o.setDuration(100))); - // 测试 resultCode 不匹配 - apiAccessLogMapper.insert(cloneIgnoreId(apiAccessLogDO, o -> o.setResultCode(2))); - // 准备参数 - ApiAccessLogExportReqVO reqVO = new ApiAccessLogExportReqVO(); - reqVO.setUserId(2233L); - reqVO.setUserType(UserTypeEnum.ADMIN.getValue()); - reqVO.setApplicationName("yudao-test"); - reqVO.setRequestUrl("foo"); - reqVO.setBeginTime(buildBetweenTime(2021, 3, 13, 2021, 3, 13)); - reqVO.setDuration(1000); - reqVO.setResultCode(GlobalErrorCodeConstants.SUCCESS.getCode()); - - // 调用 - List list = apiAccessLogService.getApiAccessLogList(reqVO); - // 断言,只查到了一条符合条件的 - assertEquals(1, list.size()); - assertPojoEquals(apiAccessLogDO, list.get(0)); - } - @Test public void testCreateApiAccessLog() { // 准备参数 diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogServiceImplTest.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogServiceImplTest.java index 86e55f5d1..dab21bfff 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogServiceImplTest.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogServiceImplTest.java @@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO; -import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogPageReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiErrorLogDO; import cn.iocoder.yudao.module.infra.dal.mysql.logger.ApiErrorLogMapper; @@ -13,7 +12,6 @@ import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Import; import javax.annotation.Resource; -import java.util.List; import static cn.hutool.core.util.RandomUtil.randomEle; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; @@ -78,46 +76,6 @@ public class ApiErrorLogServiceImplTest extends BaseDbUnitTest { assertPojoEquals(apiErrorLogDO, pageResult.getList().get(0)); } - @Test - public void testGetApiErrorLogList() { - // mock 数据 - ApiErrorLogDO apiErrorLogDO = randomPojo(ApiErrorLogDO.class, o -> { - o.setUserId(2233L); - o.setUserType(UserTypeEnum.ADMIN.getValue()); - o.setApplicationName("yudao-test"); - o.setRequestUrl("foo"); - o.setExceptionTime(buildTime(2021, 3, 13)); - o.setProcessStatus(ApiErrorLogProcessStatusEnum.INIT.getStatus()); - }); - apiErrorLogMapper.insert(apiErrorLogDO); - // 测试 userId 不匹配 - apiErrorLogMapper.insert(cloneIgnoreId(apiErrorLogDO, o -> o.setUserId(3344L))); - // 测试 userType 不匹配 - apiErrorLogMapper.insert(cloneIgnoreId(apiErrorLogDO, logDO -> logDO.setUserType(UserTypeEnum.MEMBER.getValue()))); - // 测试 applicationName 不匹配 - apiErrorLogMapper.insert(cloneIgnoreId(apiErrorLogDO, logDO -> logDO.setApplicationName("test"))); - // 测试 requestUrl 不匹配 - apiErrorLogMapper.insert(cloneIgnoreId(apiErrorLogDO, logDO -> logDO.setRequestUrl("bar"))); - // 测试 exceptionTime 不匹配:构造一个早期时间 2021-02-06 00:00:00 - apiErrorLogMapper.insert(cloneIgnoreId(apiErrorLogDO, logDO -> logDO.setExceptionTime(buildTime(2021, 2, 6)))); - // 测试 progressStatus 不匹配 - apiErrorLogMapper.insert(cloneIgnoreId(apiErrorLogDO, logDO -> logDO.setProcessStatus(ApiErrorLogProcessStatusEnum.DONE.getStatus()))); - // 准备参数 - ApiErrorLogExportReqVO reqVO = new ApiErrorLogExportReqVO(); - reqVO.setUserId(2233L); - reqVO.setUserType(UserTypeEnum.ADMIN.getValue()); - reqVO.setApplicationName("yudao-test"); - reqVO.setRequestUrl("foo"); - reqVO.setExceptionTime(buildBetweenTime(2021, 3, 1, 2021, 3, 31)); - reqVO.setProcessStatus(ApiErrorLogProcessStatusEnum.INIT.getStatus()); - - // 调用 - List list = apiErrorLogService.getApiErrorLogList(reqVO); - // 断言,只查到了一条符合条件的 - assertEquals(1, list.size()); - assertPojoEquals(apiErrorLogDO, list.get(0)); - } - @Test public void testCreateApiErrorLog() { // 准备参数