Commit 8b67111733a7222038dc11cc45885d965dbcde41
1 parent
2dd83589
🔧 简化 sensitiveWord 模块的 VO
Showing
12 changed files
with
62 additions
and
233 deletions
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/SensitiveWordController.java
| 1 | package cn.iocoder.yudao.module.system.controller.admin.sensitiveword; | 1 | package cn.iocoder.yudao.module.system.controller.admin.sensitiveword; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 5 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 7 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 6 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | 8 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.*; | ||
| 8 | -import cn.iocoder.yudao.module.system.convert.sensitiveword.SensitiveWordConvert; | 9 | +import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; |
| 10 | +import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordRespVO; | ||
| 11 | +import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordSaveVO; | ||
| 9 | import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; | 12 | import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; |
| 10 | import cn.iocoder.yudao.module.system.service.sensitiveword.SensitiveWordService; | 13 | import cn.iocoder.yudao.module.system.service.sensitiveword.SensitiveWordService; |
| 11 | -import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 12 | -import io.swagger.v3.oas.annotations.Parameter; | ||
| 13 | import io.swagger.v3.oas.annotations.Operation; | 14 | import io.swagger.v3.oas.annotations.Operation; |
| 15 | +import io.swagger.v3.oas.annotations.Parameter; | ||
| 16 | +import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 14 | import org.springframework.security.access.prepost.PreAuthorize; | 17 | import org.springframework.security.access.prepost.PreAuthorize; |
| 15 | import org.springframework.validation.annotation.Validated; | 18 | import org.springframework.validation.annotation.Validated; |
| 16 | import org.springframework.web.bind.annotation.*; | 19 | import org.springframework.web.bind.annotation.*; |
| @@ -37,14 +40,14 @@ public class SensitiveWordController { | @@ -37,14 +40,14 @@ public class SensitiveWordController { | ||
| 37 | @PostMapping("/create") | 40 | @PostMapping("/create") |
| 38 | @Operation(summary = "创建敏感词") | 41 | @Operation(summary = "创建敏感词") |
| 39 | @PreAuthorize("@ss.hasPermission('system:sensitive-word:create')") | 42 | @PreAuthorize("@ss.hasPermission('system:sensitive-word:create')") |
| 40 | - public CommonResult<Long> createSensitiveWord(@Valid @RequestBody SensitiveWordCreateReqVO createReqVO) { | 43 | + public CommonResult<Long> createSensitiveWord(@Valid @RequestBody SensitiveWordSaveVO createReqVO) { |
| 41 | return success(sensitiveWordService.createSensitiveWord(createReqVO)); | 44 | return success(sensitiveWordService.createSensitiveWord(createReqVO)); |
| 42 | } | 45 | } |
| 43 | 46 | ||
| 44 | @PutMapping("/update") | 47 | @PutMapping("/update") |
| 45 | @Operation(summary = "更新敏感词") | 48 | @Operation(summary = "更新敏感词") |
| 46 | @PreAuthorize("@ss.hasPermission('system:sensitive-word:update')") | 49 | @PreAuthorize("@ss.hasPermission('system:sensitive-word:update')") |
| 47 | - public CommonResult<Boolean> updateSensitiveWord(@Valid @RequestBody SensitiveWordUpdateReqVO updateReqVO) { | 50 | + public CommonResult<Boolean> updateSensitiveWord(@Valid @RequestBody SensitiveWordSaveVO updateReqVO) { |
| 48 | sensitiveWordService.updateSensitiveWord(updateReqVO); | 51 | sensitiveWordService.updateSensitiveWord(updateReqVO); |
| 49 | return success(true); | 52 | return success(true); |
| 50 | } | 53 | } |
| @@ -64,7 +67,7 @@ public class SensitiveWordController { | @@ -64,7 +67,7 @@ public class SensitiveWordController { | ||
| 64 | @PreAuthorize("@ss.hasPermission('system:sensitive-word:query')") | 67 | @PreAuthorize("@ss.hasPermission('system:sensitive-word:query')") |
| 65 | public CommonResult<SensitiveWordRespVO> getSensitiveWord(@RequestParam("id") Long id) { | 68 | public CommonResult<SensitiveWordRespVO> getSensitiveWord(@RequestParam("id") Long id) { |
| 66 | SensitiveWordDO sensitiveWord = sensitiveWordService.getSensitiveWord(id); | 69 | SensitiveWordDO sensitiveWord = sensitiveWordService.getSensitiveWord(id); |
| 67 | - return success(SensitiveWordConvert.INSTANCE.convert(sensitiveWord)); | 70 | + return success(BeanUtils.toBean(sensitiveWord, SensitiveWordRespVO.class)); |
| 68 | } | 71 | } |
| 69 | 72 | ||
| 70 | @GetMapping("/page") | 73 | @GetMapping("/page") |
| @@ -72,19 +75,20 @@ public class SensitiveWordController { | @@ -72,19 +75,20 @@ public class SensitiveWordController { | ||
| 72 | @PreAuthorize("@ss.hasPermission('system:sensitive-word:query')") | 75 | @PreAuthorize("@ss.hasPermission('system:sensitive-word:query')") |
| 73 | public CommonResult<PageResult<SensitiveWordRespVO>> getSensitiveWordPage(@Valid SensitiveWordPageReqVO pageVO) { | 76 | public CommonResult<PageResult<SensitiveWordRespVO>> getSensitiveWordPage(@Valid SensitiveWordPageReqVO pageVO) { |
| 74 | PageResult<SensitiveWordDO> pageResult = sensitiveWordService.getSensitiveWordPage(pageVO); | 77 | PageResult<SensitiveWordDO> pageResult = sensitiveWordService.getSensitiveWordPage(pageVO); |
| 75 | - return success(SensitiveWordConvert.INSTANCE.convertPage(pageResult)); | 78 | + return success(BeanUtils.toBean(pageResult, SensitiveWordRespVO.class)); |
| 76 | } | 79 | } |
| 77 | 80 | ||
| 78 | @GetMapping("/export-excel") | 81 | @GetMapping("/export-excel") |
| 79 | @Operation(summary = "导出敏感词 Excel") | 82 | @Operation(summary = "导出敏感词 Excel") |
| 80 | @PreAuthorize("@ss.hasPermission('system:sensitive-word:export')") | 83 | @PreAuthorize("@ss.hasPermission('system:sensitive-word:export')") |
| 81 | @OperateLog(type = EXPORT) | 84 | @OperateLog(type = EXPORT) |
| 82 | - public void exportSensitiveWordExcel(@Valid SensitiveWordExportReqVO exportReqVO, | 85 | + public void exportSensitiveWordExcel(@Valid SensitiveWordPageReqVO exportReqVO, |
| 83 | HttpServletResponse response) throws IOException { | 86 | HttpServletResponse response) throws IOException { |
| 84 | - List<SensitiveWordDO> list = sensitiveWordService.getSensitiveWordList(exportReqVO); | 87 | + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
| 88 | + List<SensitiveWordDO> list = sensitiveWordService.getSensitiveWordPage(exportReqVO).getList(); | ||
| 85 | // 导出 Excel | 89 | // 导出 Excel |
| 86 | - List<SensitiveWordExcelVO> datas = SensitiveWordConvert.INSTANCE.convertList02(list); | ||
| 87 | - ExcelUtils.write(response, "敏感词.xls", "数据", SensitiveWordExcelVO.class, datas); | 90 | + ExcelUtils.write(response, "敏感词.xls", "数据", SensitiveWordRespVO.class, |
| 91 | + BeanUtils.toBean(list, SensitiveWordRespVO.class)); | ||
| 88 | } | 92 | } |
| 89 | 93 | ||
| 90 | @GetMapping("/get-tags") | 94 | @GetMapping("/get-tags") |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordCreateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo; | ||
| 2 | - | ||
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | -import lombok.Data; | ||
| 5 | -import lombok.EqualsAndHashCode; | ||
| 6 | -import lombok.ToString; | ||
| 7 | - | ||
| 8 | -@Schema(description = "管理后台 - 敏感词创建 Request VO") | ||
| 9 | -@Data | ||
| 10 | -@EqualsAndHashCode(callSuper = true) | ||
| 11 | -@ToString(callSuper = true) | ||
| 12 | -public class SensitiveWordCreateReqVO extends SensitiveWordBaseVO { | ||
| 13 | - | ||
| 14 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordExcelVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | ||
| 4 | -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | ||
| 5 | -import cn.iocoder.yudao.framework.excel.core.convert.JsonConvert; | ||
| 6 | -import cn.iocoder.yudao.module.system.enums.DictTypeConstants; | ||
| 7 | -import com.alibaba.excel.annotation.ExcelProperty; | ||
| 8 | -import lombok.Data; | ||
| 9 | - | ||
| 10 | -import java.time.LocalDateTime; | ||
| 11 | -import java.util.List; | ||
| 12 | - | ||
| 13 | -/** | ||
| 14 | - * 敏感词 Excel VO | ||
| 15 | - * | ||
| 16 | - * @author 永不言败 | ||
| 17 | - */ | ||
| 18 | -@Data | ||
| 19 | -public class SensitiveWordExcelVO { | ||
| 20 | - | ||
| 21 | - @ExcelProperty("编号") | ||
| 22 | - private Long id; | ||
| 23 | - | ||
| 24 | - @ExcelProperty("敏感词") | ||
| 25 | - private String name; | ||
| 26 | - | ||
| 27 | - @ExcelProperty(value = "标签", converter = JsonConvert.class) | ||
| 28 | - private List<String> tags; | ||
| 29 | - | ||
| 30 | - @ExcelProperty(value = "状态", converter = DictConvert.class) | ||
| 31 | - @DictFormat(DictTypeConstants.COMMON_STATUS) | ||
| 32 | - private Integer status; | ||
| 33 | - | ||
| 34 | - @ExcelProperty("描述") | ||
| 35 | - private String description; | ||
| 36 | - | ||
| 37 | - @ExcelProperty("创建时间") | ||
| 38 | - private LocalDateTime createTime; | ||
| 39 | - | ||
| 40 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordExportReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo; | ||
| 2 | - | ||
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | -import lombok.Data; | ||
| 5 | -import org.springframework.format.annotation.DateTimeFormat; | ||
| 6 | - | ||
| 7 | -import java.time.LocalDateTime; | ||
| 8 | - | ||
| 9 | -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ||
| 10 | - | ||
| 11 | -@Schema(description = "管理后台 - 敏感词 Excel 导出 Request VO,参数和 SensitiveWordPageReqVO 是一致的") | ||
| 12 | -@Data | ||
| 13 | -public class SensitiveWordExportReqVO { | ||
| 14 | - | ||
| 15 | - @Schema(description = "敏感词", example = "敏感词") | ||
| 16 | - private String name; | ||
| 17 | - | ||
| 18 | - @Schema(description = "标签", example = "短信,评论") | ||
| 19 | - private String tag; | ||
| 20 | - | ||
| 21 | - @Schema(description = "状态,参见 CommonStatusEnum 枚举类", example = "1") | ||
| 22 | - private Integer status; | ||
| 23 | - | ||
| 24 | - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 25 | - @Schema(description = "创建时间") | ||
| 26 | - private LocalDateTime[] createTime; | ||
| 27 | - | ||
| 28 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordRespVO.java
| 1 | package cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo; | 1 | package cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | ||
| 4 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | ||
| 5 | +import cn.iocoder.yudao.framework.excel.core.convert.JsonConvert; | ||
| 6 | +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; | ||
| 7 | +import com.alibaba.excel.annotation.ExcelProperty; | ||
| 3 | import io.swagger.v3.oas.annotations.media.Schema; | 8 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | import lombok.Data; | 9 | import lombok.Data; |
| 5 | import lombok.EqualsAndHashCode; | 10 | import lombok.EqualsAndHashCode; |
| 6 | import lombok.ToString; | 11 | import lombok.ToString; |
| 7 | 12 | ||
| 8 | import java.time.LocalDateTime; | 13 | import java.time.LocalDateTime; |
| 14 | +import java.util.List; | ||
| 9 | 15 | ||
| 10 | @Schema(description = "管理后台 - 敏感词 Response VO") | 16 | @Schema(description = "管理后台 - 敏感词 Response VO") |
| 11 | @Data | 17 | @Data |
| 12 | -@EqualsAndHashCode(callSuper = true) | ||
| 13 | -@ToString(callSuper = true) | ||
| 14 | -public class SensitiveWordRespVO extends SensitiveWordBaseVO { | 18 | +public class SensitiveWordRespVO { |
| 15 | 19 | ||
| 16 | @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | 20 | @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 21 | + @ExcelProperty("编号") | ||
| 17 | private Long id; | 22 | private Long id; |
| 18 | 23 | ||
| 24 | + @Schema(description = "敏感词", requiredMode = Schema.RequiredMode.REQUIRED, example = "敏感词") | ||
| 25 | + @ExcelProperty("敏感词") | ||
| 26 | + private String name; | ||
| 27 | + | ||
| 28 | + @Schema(description = "标签", requiredMode = Schema.RequiredMode.REQUIRED, example = "短信,评论") | ||
| 29 | + @ExcelProperty(value = "标签", converter = JsonConvert.class) | ||
| 30 | + private List<String> tags; | ||
| 31 | + | ||
| 32 | + @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 33 | + @ExcelProperty(value = "状态", converter = DictConvert.class) | ||
| 34 | + @DictFormat(DictTypeConstants.COMMON_STATUS) | ||
| 35 | + private Integer status; | ||
| 36 | + | ||
| 37 | + @Schema(description = "描述", example = "污言秽语") | ||
| 38 | + @ExcelProperty("描述") | ||
| 39 | + private String description; | ||
| 40 | + | ||
| 19 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | 41 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) |
| 42 | + @ExcelProperty("创建时间") | ||
| 20 | private LocalDateTime createTime; | 43 | private LocalDateTime createTime; |
| 21 | 44 | ||
| 22 | } | 45 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordBaseVO.java renamed to 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; | @@ -6,12 +6,12 @@ import lombok.Data; | ||
| 6 | import javax.validation.constraints.NotNull; | 6 | import javax.validation.constraints.NotNull; |
| 7 | import java.util.List; | 7 | import java.util.List; |
| 8 | 8 | ||
| 9 | -/** | ||
| 10 | - * 敏感词 Base VO,提供给添加、修改、详细的子 VO 使用 | ||
| 11 | - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | ||
| 12 | - */ | 9 | +@Schema(description = "管理后台 - 敏感词创建/修改 Request VO") |
| 13 | @Data | 10 | @Data |
| 14 | -public class SensitiveWordBaseVO { | 11 | +public class SensitiveWordSaveVO { |
| 12 | + | ||
| 13 | + @Schema(description = "编号", example = "1") | ||
| 14 | + private Long id; | ||
| 15 | 15 | ||
| 16 | @Schema(description = "敏感词", requiredMode = Schema.RequiredMode.REQUIRED, example = "敏感词") | 16 | @Schema(description = "敏感词", requiredMode = Schema.RequiredMode.REQUIRED, example = "敏感词") |
| 17 | @NotNull(message = "敏感词不能为空") | 17 | @NotNull(message = "敏感词不能为空") |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/vo/SensitiveWordUpdateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo; | ||
| 2 | - | ||
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | -import lombok.Data; | ||
| 5 | -import lombok.EqualsAndHashCode; | ||
| 6 | -import lombok.ToString; | ||
| 7 | - | ||
| 8 | -import javax.validation.constraints.NotNull; | ||
| 9 | - | ||
| 10 | -@Schema(description = "管理后台 - 敏感词更新 Request VO") | ||
| 11 | -@Data | ||
| 12 | -@EqualsAndHashCode(callSuper = true) | ||
| 13 | -@ToString(callSuper = true) | ||
| 14 | -public class SensitiveWordUpdateReqVO extends SensitiveWordBaseVO { | ||
| 15 | - | ||
| 16 | - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 17 | - @NotNull(message = "编号不能为空") | ||
| 18 | - private Long id; | ||
| 19 | - | ||
| 20 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/sensitiveword/SensitiveWordConvert.java deleted
| 1 | -package cn.iocoder.yudao.module.system.convert.sensitiveword; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordCreateReqVO; | ||
| 5 | -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordExcelVO; | ||
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordRespVO; | ||
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordUpdateReqVO; | ||
| 8 | -import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; | ||
| 9 | -import org.mapstruct.Mapper; | ||
| 10 | -import org.mapstruct.factory.Mappers; | ||
| 11 | - | ||
| 12 | -import java.util.List; | ||
| 13 | - | ||
| 14 | -/** | ||
| 15 | - * 敏感词 Convert | ||
| 16 | - * | ||
| 17 | - * @author 永不言败 | ||
| 18 | - */ | ||
| 19 | -@Mapper | ||
| 20 | -public interface SensitiveWordConvert { | ||
| 21 | - | ||
| 22 | - SensitiveWordConvert INSTANCE = Mappers.getMapper(SensitiveWordConvert.class); | ||
| 23 | - | ||
| 24 | - SensitiveWordDO convert(SensitiveWordCreateReqVO bean); | ||
| 25 | - | ||
| 26 | - SensitiveWordDO convert(SensitiveWordUpdateReqVO bean); | ||
| 27 | - | ||
| 28 | - SensitiveWordRespVO convert(SensitiveWordDO bean); | ||
| 29 | - | ||
| 30 | - List<SensitiveWordRespVO> convertList(List<SensitiveWordDO> list); | ||
| 31 | - | ||
| 32 | - PageResult<SensitiveWordRespVO> convertPage(PageResult<SensitiveWordDO> page); | ||
| 33 | - | ||
| 34 | - List<SensitiveWordExcelVO> convertList02(List<SensitiveWordDO> list); | ||
| 35 | - | ||
| 36 | -} |
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; | @@ -3,14 +3,12 @@ package cn.iocoder.yudao.module.system.dal.mysql.sensitiveword; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordExportReqVO; | ||
| 7 | import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; | 6 | import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; |
| 8 | import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; | 7 | import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; |
| 9 | import org.apache.ibatis.annotations.Mapper; | 8 | import org.apache.ibatis.annotations.Mapper; |
| 10 | import org.apache.ibatis.annotations.Select; | 9 | import org.apache.ibatis.annotations.Select; |
| 11 | 10 | ||
| 12 | import java.time.LocalDateTime; | 11 | import java.time.LocalDateTime; |
| 13 | -import java.util.List; | ||
| 14 | 12 | ||
| 15 | /** | 13 | /** |
| 16 | * 敏感词 Mapper | 14 | * 敏感词 Mapper |
| @@ -28,16 +26,6 @@ public interface SensitiveWordMapper extends BaseMapperX<SensitiveWordDO> { | @@ -28,16 +26,6 @@ public interface SensitiveWordMapper extends BaseMapperX<SensitiveWordDO> { | ||
| 28 | .betweenIfPresent(SensitiveWordDO::getCreateTime, reqVO.getCreateTime()) | 26 | .betweenIfPresent(SensitiveWordDO::getCreateTime, reqVO.getCreateTime()) |
| 29 | .orderByDesc(SensitiveWordDO::getId)); | 27 | .orderByDesc(SensitiveWordDO::getId)); |
| 30 | } | 28 | } |
| 31 | - | ||
| 32 | - default List<SensitiveWordDO> selectList(SensitiveWordExportReqVO reqVO) { | ||
| 33 | - return selectList(new LambdaQueryWrapperX<SensitiveWordDO>() | ||
| 34 | - .likeIfPresent(SensitiveWordDO::getName, reqVO.getName()) | ||
| 35 | - .likeIfPresent(SensitiveWordDO::getTags, reqVO.getTag()) | ||
| 36 | - .eqIfPresent(SensitiveWordDO::getStatus, reqVO.getStatus()) | ||
| 37 | - .betweenIfPresent(SensitiveWordDO::getCreateTime, reqVO.getCreateTime()) | ||
| 38 | - .orderByDesc(SensitiveWordDO::getId)); | ||
| 39 | - } | ||
| 40 | - | ||
| 41 | default SensitiveWordDO selectByName(String name) { | 29 | default SensitiveWordDO selectByName(String name) { |
| 42 | return selectOne(SensitiveWordDO::getName, name); | 30 | return selectOne(SensitiveWordDO::getName, name); |
| 43 | } | 31 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordService.java
| 1 | package cn.iocoder.yudao.module.system.service.sensitiveword; | 1 | package cn.iocoder.yudao.module.system.service.sensitiveword; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordCreateReqVO; | ||
| 5 | -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordExportReqVO; | ||
| 6 | import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; | 4 | import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordUpdateReqVO; | 5 | +import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordSaveVO; |
| 8 | import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; | 6 | import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; |
| 9 | 7 | ||
| 10 | import javax.validation.Valid; | 8 | import javax.validation.Valid; |
| @@ -24,14 +22,14 @@ public interface SensitiveWordService { | @@ -24,14 +22,14 @@ public interface SensitiveWordService { | ||
| 24 | * @param createReqVO 创建信息 | 22 | * @param createReqVO 创建信息 |
| 25 | * @return 编号 | 23 | * @return 编号 |
| 26 | */ | 24 | */ |
| 27 | - Long createSensitiveWord(@Valid SensitiveWordCreateReqVO createReqVO); | 25 | + Long createSensitiveWord(@Valid SensitiveWordSaveVO createReqVO); |
| 28 | 26 | ||
| 29 | /** | 27 | /** |
| 30 | * 更新敏感词 | 28 | * 更新敏感词 |
| 31 | * | 29 | * |
| 32 | * @param updateReqVO 更新信息 | 30 | * @param updateReqVO 更新信息 |
| 33 | */ | 31 | */ |
| 34 | - void updateSensitiveWord(@Valid SensitiveWordUpdateReqVO updateReqVO); | 32 | + void updateSensitiveWord(@Valid SensitiveWordSaveVO updateReqVO); |
| 35 | 33 | ||
| 36 | /** | 34 | /** |
| 37 | * 删除敏感词 | 35 | * 删除敏感词 |
| @@ -64,14 +62,6 @@ public interface SensitiveWordService { | @@ -64,14 +62,6 @@ public interface SensitiveWordService { | ||
| 64 | PageResult<SensitiveWordDO> getSensitiveWordPage(SensitiveWordPageReqVO pageReqVO); | 62 | PageResult<SensitiveWordDO> getSensitiveWordPage(SensitiveWordPageReqVO pageReqVO); |
| 65 | 63 | ||
| 66 | /** | 64 | /** |
| 67 | - * 获得敏感词列表, 用于 Excel 导出 | ||
| 68 | - * | ||
| 69 | - * @param exportReqVO 查询条件 | ||
| 70 | - * @return 敏感词列表 | ||
| 71 | - */ | ||
| 72 | - List<SensitiveWordDO> getSensitiveWordList(SensitiveWordExportReqVO exportReqVO); | ||
| 73 | - | ||
| 74 | - /** | ||
| 75 | * 获得所有敏感词的标签数组 | 65 | * 获得所有敏感词的标签数组 |
| 76 | * | 66 | * |
| 77 | * @return 标签数组 | 67 | * @return 标签数组 |
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; | @@ -4,11 +4,9 @@ import cn.hutool.core.collection.CollUtil; | ||
| 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 6 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordCreateReqVO; | ||
| 8 | -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordExportReqVO; | 7 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 9 | import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; | 8 | import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; |
| 10 | -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordUpdateReqVO; | ||
| 11 | -import cn.iocoder.yudao.module.system.convert.sensitiveword.SensitiveWordConvert; | 9 | +import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordSaveVO; |
| 12 | import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; | 10 | import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; |
| 13 | import cn.iocoder.yudao.module.system.dal.mysql.sensitiveword.SensitiveWordMapper; | 11 | import cn.iocoder.yudao.module.system.dal.mysql.sensitiveword.SensitiveWordMapper; |
| 14 | import cn.iocoder.yudao.module.system.util.collection.SimpleTrie; | 12 | import cn.iocoder.yudao.module.system.util.collection.SimpleTrie; |
| @@ -141,12 +139,12 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { | @@ -141,12 +139,12 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { | ||
| 141 | } | 139 | } |
| 142 | 140 | ||
| 143 | @Override | 141 | @Override |
| 144 | - public Long createSensitiveWord(SensitiveWordCreateReqVO createReqVO) { | 142 | + public Long createSensitiveWord(SensitiveWordSaveVO createReqVO) { |
| 145 | // 校验唯一性 | 143 | // 校验唯一性 |
| 146 | validateSensitiveWordNameUnique(null, createReqVO.getName()); | 144 | validateSensitiveWordNameUnique(null, createReqVO.getName()); |
| 147 | 145 | ||
| 148 | // 插入 | 146 | // 插入 |
| 149 | - SensitiveWordDO sensitiveWord = SensitiveWordConvert.INSTANCE.convert(createReqVO); | 147 | + SensitiveWordDO sensitiveWord = BeanUtils.toBean(createReqVO, SensitiveWordDO.class); |
| 150 | sensitiveWordMapper.insert(sensitiveWord); | 148 | sensitiveWordMapper.insert(sensitiveWord); |
| 151 | 149 | ||
| 152 | // 刷新缓存 | 150 | // 刷新缓存 |
| @@ -155,13 +153,13 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { | @@ -155,13 +153,13 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { | ||
| 155 | } | 153 | } |
| 156 | 154 | ||
| 157 | @Override | 155 | @Override |
| 158 | - public void updateSensitiveWord(SensitiveWordUpdateReqVO updateReqVO) { | 156 | + public void updateSensitiveWord(SensitiveWordSaveVO updateReqVO) { |
| 159 | // 校验唯一性 | 157 | // 校验唯一性 |
| 160 | validateSensitiveWordExists(updateReqVO.getId()); | 158 | validateSensitiveWordExists(updateReqVO.getId()); |
| 161 | validateSensitiveWordNameUnique(updateReqVO.getId(), updateReqVO.getName()); | 159 | validateSensitiveWordNameUnique(updateReqVO.getId(), updateReqVO.getName()); |
| 162 | 160 | ||
| 163 | // 更新 | 161 | // 更新 |
| 164 | - SensitiveWordDO updateObj = SensitiveWordConvert.INSTANCE.convert(updateReqVO); | 162 | + SensitiveWordDO updateObj = BeanUtils.toBean(updateReqVO, SensitiveWordDO.class); |
| 165 | sensitiveWordMapper.updateById(updateObj); | 163 | sensitiveWordMapper.updateById(updateObj); |
| 166 | 164 | ||
| 167 | // 刷新缓存 | 165 | // 刷新缓存 |
| @@ -215,11 +213,6 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { | @@ -215,11 +213,6 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { | ||
| 215 | } | 213 | } |
| 216 | 214 | ||
| 217 | @Override | 215 | @Override |
| 218 | - public List<SensitiveWordDO> getSensitiveWordList(SensitiveWordExportReqVO exportReqVO) { | ||
| 219 | - return sensitiveWordMapper.selectList(exportReqVO); | ||
| 220 | - } | ||
| 221 | - | ||
| 222 | - @Override | ||
| 223 | public Set<String> getSensitiveWordTagSet() { | 216 | public Set<String> getSensitiveWordTagSet() { |
| 224 | return sensitiveWordTagsCache; | 217 | return sensitiveWordTagsCache; |
| 225 | } | 218 | } |
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; | @@ -4,10 +4,8 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.common.util.collection.SetUtils; | 5 | import cn.iocoder.yudao.framework.common.util.collection.SetUtils; |
| 6 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | 6 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordCreateReqVO; | ||
| 8 | -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordExportReqVO; | ||
| 9 | import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; | 7 | import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO; |
| 10 | -import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordUpdateReqVO; | 8 | +import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordSaveVO; |
| 11 | import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; | 9 | import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO; |
| 12 | import cn.iocoder.yudao.module.system.dal.mysql.sensitiveword.SensitiveWordMapper; | 10 | import cn.iocoder.yudao.module.system.dal.mysql.sensitiveword.SensitiveWordMapper; |
| 13 | import org.junit.jupiter.api.BeforeEach; | 11 | import org.junit.jupiter.api.BeforeEach; |
| @@ -83,7 +81,8 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { | @@ -83,7 +81,8 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { | ||
| 83 | @Test | 81 | @Test |
| 84 | public void testCreateSensitiveWord_success() { | 82 | public void testCreateSensitiveWord_success() { |
| 85 | // 准备参数 | 83 | // 准备参数 |
| 86 | - SensitiveWordCreateReqVO reqVO = randomPojo(SensitiveWordCreateReqVO.class); | 84 | + SensitiveWordSaveVO reqVO = randomPojo(SensitiveWordSaveVO.class) |
| 85 | + .setId(null); // 防止 id 被赋值 | ||
| 87 | 86 | ||
| 88 | // 调用 | 87 | // 调用 |
| 89 | Long sensitiveWordId = sensitiveWordService.createSensitiveWord(reqVO); | 88 | Long sensitiveWordId = sensitiveWordService.createSensitiveWord(reqVO); |
| @@ -91,7 +90,7 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { | @@ -91,7 +90,7 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { | ||
| 91 | assertNotNull(sensitiveWordId); | 90 | assertNotNull(sensitiveWordId); |
| 92 | // 校验记录的属性是否正确 | 91 | // 校验记录的属性是否正确 |
| 93 | SensitiveWordDO sensitiveWord = sensitiveWordMapper.selectById(sensitiveWordId); | 92 | SensitiveWordDO sensitiveWord = sensitiveWordMapper.selectById(sensitiveWordId); |
| 94 | - assertPojoEquals(reqVO, sensitiveWord); | 93 | + assertPojoEquals(reqVO, sensitiveWord, "id"); |
| 95 | } | 94 | } |
| 96 | 95 | ||
| 97 | @Test | 96 | @Test |
| @@ -100,7 +99,7 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { | @@ -100,7 +99,7 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { | ||
| 100 | SensitiveWordDO dbSensitiveWord = randomPojo(SensitiveWordDO.class); | 99 | SensitiveWordDO dbSensitiveWord = randomPojo(SensitiveWordDO.class); |
| 101 | sensitiveWordMapper.insert(dbSensitiveWord);// @Sql: 先插入出一条存在的数据 | 100 | sensitiveWordMapper.insert(dbSensitiveWord);// @Sql: 先插入出一条存在的数据 |
| 102 | // 准备参数 | 101 | // 准备参数 |
| 103 | - SensitiveWordUpdateReqVO reqVO = randomPojo(SensitiveWordUpdateReqVO.class, o -> { | 102 | + SensitiveWordSaveVO reqVO = randomPojo(SensitiveWordSaveVO.class, o -> { |
| 104 | o.setId(dbSensitiveWord.getId()); // 设置更新的 ID | 103 | o.setId(dbSensitiveWord.getId()); // 设置更新的 ID |
| 105 | }); | 104 | }); |
| 106 | 105 | ||
| @@ -114,7 +113,7 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { | @@ -114,7 +113,7 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { | ||
| 114 | @Test | 113 | @Test |
| 115 | public void testUpdateSensitiveWord_notExists() { | 114 | public void testUpdateSensitiveWord_notExists() { |
| 116 | // 准备参数 | 115 | // 准备参数 |
| 117 | - SensitiveWordUpdateReqVO reqVO = randomPojo(SensitiveWordUpdateReqVO.class); | 116 | + SensitiveWordSaveVO reqVO = randomPojo(SensitiveWordSaveVO.class); |
| 118 | 117 | ||
| 119 | // 调用, 并断言异常 | 118 | // 调用, 并断言异常 |
| 120 | assertServiceException(() -> sensitiveWordService.updateSensitiveWord(reqVO), SENSITIVE_WORD_NOT_EXISTS); | 119 | assertServiceException(() -> sensitiveWordService.updateSensitiveWord(reqVO), SENSITIVE_WORD_NOT_EXISTS); |
| @@ -205,36 +204,6 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { | @@ -205,36 +204,6 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest { | ||
| 205 | } | 204 | } |
| 206 | 205 | ||
| 207 | @Test | 206 | @Test |
| 208 | - public void testGetSensitiveWordList_export() { | ||
| 209 | - // mock 数据 | ||
| 210 | - SensitiveWordDO dbSensitiveWord = randomPojo(SensitiveWordDO.class, o -> { // 等会查询到 | ||
| 211 | - o.setName("笨蛋"); | ||
| 212 | - o.setTags(Arrays.asList("论坛", "蔬菜")); | ||
| 213 | - o.setStatus(CommonStatusEnum.ENABLE.getStatus()); | ||
| 214 | - o.setCreateTime(buildTime(2022, 2, 8)); | ||
| 215 | - }); | ||
| 216 | - sensitiveWordMapper.insert(dbSensitiveWord); | ||
| 217 | - // 测试 name 不匹配 | ||
| 218 | - sensitiveWordMapper.insert(cloneIgnoreId(dbSensitiveWord, o -> o.setName("傻瓜"))); | ||
| 219 | - // 测试 tags 不匹配 | ||
| 220 | - sensitiveWordMapper.insert(cloneIgnoreId(dbSensitiveWord, o -> o.setTags(Arrays.asList("短信", "日用品")))); | ||
| 221 | - // 测试 createTime 不匹配 | ||
| 222 | - sensitiveWordMapper.insert(cloneIgnoreId(dbSensitiveWord, o -> o.setCreateTime(buildTime(2022, 2, 16)))); | ||
| 223 | - // 准备参数 | ||
| 224 | - SensitiveWordExportReqVO reqVO = new SensitiveWordExportReqVO(); | ||
| 225 | - reqVO.setName("笨"); | ||
| 226 | - reqVO.setTag("论坛"); | ||
| 227 | - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | ||
| 228 | - reqVO.setCreateTime(buildBetweenTime(2022, 2, 1, 2022, 2, 12)); | ||
| 229 | - | ||
| 230 | - // 调用 | ||
| 231 | - List<SensitiveWordDO> list = sensitiveWordService.getSensitiveWordList(reqVO); | ||
| 232 | - // 断言 | ||
| 233 | - assertEquals(1, list.size()); | ||
| 234 | - assertPojoEquals(dbSensitiveWord, list.get(0)); | ||
| 235 | - } | ||
| 236 | - | ||
| 237 | - @Test | ||
| 238 | public void testValidateText_noTag() { | 207 | public void testValidateText_noTag() { |
| 239 | testInitLocalCache(); | 208 | testInitLocalCache(); |
| 240 | // 准备参数 | 209 | // 准备参数 |