From 8b67111733a7222038dc11cc45885d965dbcde41 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 2 Dec 2023 21:59:08 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20sensitiveWo?= =?UTF-8?q?rd=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();