🔧 简化 sensitiveWord 模块的 VO
This commit is contained in:
parent
df2bcb267d
commit
5c50b5ff13
@ -1,16 +1,19 @@
|
|||||||
package cn.iocoder.yudao.module.system.controller.admin.sensitiveword;
|
package cn.iocoder.yudao.module.system.controller.admin.sensitiveword;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
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.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.excel.core.util.ExcelUtils;
|
||||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
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.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO;
|
||||||
import cn.iocoder.yudao.module.system.convert.sensitiveword.SensitiveWordConvert;
|
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.dal.dataobject.sensitiveword.SensitiveWordDO;
|
||||||
import cn.iocoder.yudao.module.system.service.sensitiveword.SensitiveWordService;
|
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.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.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@ -37,14 +40,14 @@ public class SensitiveWordController {
|
|||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@Operation(summary = "创建敏感词")
|
@Operation(summary = "创建敏感词")
|
||||||
@PreAuthorize("@ss.hasPermission('system:sensitive-word:create')")
|
@PreAuthorize("@ss.hasPermission('system:sensitive-word:create')")
|
||||||
public CommonResult<Long> createSensitiveWord(@Valid @RequestBody SensitiveWordCreateReqVO createReqVO) {
|
public CommonResult<Long> createSensitiveWord(@Valid @RequestBody SensitiveWordSaveVO createReqVO) {
|
||||||
return success(sensitiveWordService.createSensitiveWord(createReqVO));
|
return success(sensitiveWordService.createSensitiveWord(createReqVO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/update")
|
@PutMapping("/update")
|
||||||
@Operation(summary = "更新敏感词")
|
@Operation(summary = "更新敏感词")
|
||||||
@PreAuthorize("@ss.hasPermission('system:sensitive-word:update')")
|
@PreAuthorize("@ss.hasPermission('system:sensitive-word:update')")
|
||||||
public CommonResult<Boolean> updateSensitiveWord(@Valid @RequestBody SensitiveWordUpdateReqVO updateReqVO) {
|
public CommonResult<Boolean> updateSensitiveWord(@Valid @RequestBody SensitiveWordSaveVO updateReqVO) {
|
||||||
sensitiveWordService.updateSensitiveWord(updateReqVO);
|
sensitiveWordService.updateSensitiveWord(updateReqVO);
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
@ -64,7 +67,7 @@ public class SensitiveWordController {
|
|||||||
@PreAuthorize("@ss.hasPermission('system:sensitive-word:query')")
|
@PreAuthorize("@ss.hasPermission('system:sensitive-word:query')")
|
||||||
public CommonResult<SensitiveWordRespVO> getSensitiveWord(@RequestParam("id") Long id) {
|
public CommonResult<SensitiveWordRespVO> getSensitiveWord(@RequestParam("id") Long id) {
|
||||||
SensitiveWordDO sensitiveWord = sensitiveWordService.getSensitiveWord(id);
|
SensitiveWordDO sensitiveWord = sensitiveWordService.getSensitiveWord(id);
|
||||||
return success(SensitiveWordConvert.INSTANCE.convert(sensitiveWord));
|
return success(BeanUtils.toBean(sensitiveWord, SensitiveWordRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
@ -72,19 +75,20 @@ public class SensitiveWordController {
|
|||||||
@PreAuthorize("@ss.hasPermission('system:sensitive-word:query')")
|
@PreAuthorize("@ss.hasPermission('system:sensitive-word:query')")
|
||||||
public CommonResult<PageResult<SensitiveWordRespVO>> getSensitiveWordPage(@Valid SensitiveWordPageReqVO pageVO) {
|
public CommonResult<PageResult<SensitiveWordRespVO>> getSensitiveWordPage(@Valid SensitiveWordPageReqVO pageVO) {
|
||||||
PageResult<SensitiveWordDO> pageResult = sensitiveWordService.getSensitiveWordPage(pageVO);
|
PageResult<SensitiveWordDO> pageResult = sensitiveWordService.getSensitiveWordPage(pageVO);
|
||||||
return success(SensitiveWordConvert.INSTANCE.convertPage(pageResult));
|
return success(BeanUtils.toBean(pageResult, SensitiveWordRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/export-excel")
|
@GetMapping("/export-excel")
|
||||||
@Operation(summary = "导出敏感词 Excel")
|
@Operation(summary = "导出敏感词 Excel")
|
||||||
@PreAuthorize("@ss.hasPermission('system:sensitive-word:export')")
|
@PreAuthorize("@ss.hasPermission('system:sensitive-word:export')")
|
||||||
@OperateLog(type = EXPORT)
|
@OperateLog(type = EXPORT)
|
||||||
public void exportSensitiveWordExcel(@Valid SensitiveWordExportReqVO exportReqVO,
|
public void exportSensitiveWordExcel(@Valid SensitiveWordPageReqVO exportReqVO,
|
||||||
HttpServletResponse response) throws IOException {
|
HttpServletResponse response) throws IOException {
|
||||||
List<SensitiveWordDO> list = sensitiveWordService.getSensitiveWordList(exportReqVO);
|
exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||||
|
List<SensitiveWordDO> list = sensitiveWordService.getSensitiveWordPage(exportReqVO).getList();
|
||||||
// 导出 Excel
|
// 导出 Excel
|
||||||
List<SensitiveWordExcelVO> datas = SensitiveWordConvert.INSTANCE.convertList02(list);
|
ExcelUtils.write(response, "敏感词.xls", "数据", SensitiveWordRespVO.class,
|
||||||
ExcelUtils.write(response, "敏感词.xls", "数据", SensitiveWordExcelVO.class, datas);
|
BeanUtils.toBean(list, SensitiveWordRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/get-tags")
|
@GetMapping("/get-tags")
|
||||||
|
@ -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 {
|
|
||||||
|
|
||||||
}
|
|
@ -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<String> tags;
|
|
||||||
|
|
||||||
@ExcelProperty(value = "状态", converter = DictConvert.class)
|
|
||||||
@DictFormat(DictTypeConstants.COMMON_STATUS)
|
|
||||||
private Integer status;
|
|
||||||
|
|
||||||
@ExcelProperty("描述")
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
@ExcelProperty("创建时间")
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
|
|
||||||
}
|
|
@ -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;
|
|
||||||
|
|
||||||
}
|
|
@ -1,22 +1,43 @@
|
|||||||
package cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo;
|
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 io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.ToString;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Schema(description = "管理后台 - 敏感词 Response VO")
|
@Schema(description = "管理后台 - 敏感词 Response VO")
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
public class SensitiveWordRespVO {
|
||||||
@ToString(callSuper = true)
|
|
||||||
public class SensitiveWordRespVO extends SensitiveWordBaseVO {
|
|
||||||
|
|
||||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
@ExcelProperty("编号")
|
||||||
private Long id;
|
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<String> 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)
|
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("创建时间")
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,12 @@ import lombok.Data;
|
|||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
@Schema(description = "管理后台 - 敏感词创建/修改 Request VO")
|
||||||
* 敏感词 Base VO,提供给添加、修改、详细的子 VO 使用
|
|
||||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
|
||||||
*/
|
|
||||||
@Data
|
@Data
|
||||||
public class SensitiveWordBaseVO {
|
public class SensitiveWordSaveVO {
|
||||||
|
|
||||||
|
@Schema(description = "编号", example = "1")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "敏感词", requiredMode = Schema.RequiredMode.REQUIRED, example = "敏感词")
|
@Schema(description = "敏感词", requiredMode = Schema.RequiredMode.REQUIRED, example = "敏感词")
|
||||||
@NotNull(message = "敏感词不能为空")
|
@NotNull(message = "敏感词不能为空")
|
@ -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;
|
|
||||||
|
|
||||||
}
|
|
@ -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<SensitiveWordRespVO> convertList(List<SensitiveWordDO> list);
|
|
||||||
|
|
||||||
PageResult<SensitiveWordRespVO> convertPage(PageResult<SensitiveWordDO> page);
|
|
||||||
|
|
||||||
List<SensitiveWordExcelVO> convertList02(List<SensitiveWordDO> list);
|
|
||||||
|
|
||||||
}
|
|
@ -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.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
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.controller.admin.sensitiveword.vo.SensitiveWordPageReqVO;
|
||||||
import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO;
|
import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 敏感词 Mapper
|
* 敏感词 Mapper
|
||||||
@ -29,15 +27,6 @@ public interface SensitiveWordMapper extends BaseMapperX<SensitiveWordDO> {
|
|||||||
.orderByDesc(SensitiveWordDO::getId));
|
.orderByDesc(SensitiveWordDO::getId));
|
||||||
}
|
}
|
||||||
|
|
||||||
default List<SensitiveWordDO> selectList(SensitiveWordExportReqVO reqVO) {
|
|
||||||
return selectList(new LambdaQueryWrapperX<SensitiveWordDO>()
|
|
||||||
.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) {
|
default SensitiveWordDO selectByName(String name) {
|
||||||
return selectOne(SensitiveWordDO::getName, name);
|
return selectOne(SensitiveWordDO::getName, name);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
package cn.iocoder.yudao.module.system.service.sensitiveword;
|
package cn.iocoder.yudao.module.system.service.sensitiveword;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
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.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.dataobject.sensitiveword.SensitiveWordDO;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
@ -24,14 +22,14 @@ public interface SensitiveWordService {
|
|||||||
* @param createReqVO 创建信息
|
* @param createReqVO 创建信息
|
||||||
* @return 编号
|
* @return 编号
|
||||||
*/
|
*/
|
||||||
Long createSensitiveWord(@Valid SensitiveWordCreateReqVO createReqVO);
|
Long createSensitiveWord(@Valid SensitiveWordSaveVO createReqVO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新敏感词
|
* 更新敏感词
|
||||||
*
|
*
|
||||||
* @param updateReqVO 更新信息
|
* @param updateReqVO 更新信息
|
||||||
*/
|
*/
|
||||||
void updateSensitiveWord(@Valid SensitiveWordUpdateReqVO updateReqVO);
|
void updateSensitiveWord(@Valid SensitiveWordSaveVO updateReqVO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除敏感词
|
* 删除敏感词
|
||||||
@ -63,14 +61,6 @@ public interface SensitiveWordService {
|
|||||||
*/
|
*/
|
||||||
PageResult<SensitiveWordDO> getSensitiveWordPage(SensitiveWordPageReqVO pageReqVO);
|
PageResult<SensitiveWordDO> getSensitiveWordPage(SensitiveWordPageReqVO pageReqVO);
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得敏感词列表, 用于 Excel 导出
|
|
||||||
*
|
|
||||||
* @param exportReqVO 查询条件
|
|
||||||
* @return 敏感词列表
|
|
||||||
*/
|
|
||||||
List<SensitiveWordDO> getSensitiveWordList(SensitiveWordExportReqVO exportReqVO);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得所有敏感词的标签数组
|
* 获得所有敏感词的标签数组
|
||||||
*
|
*
|
||||||
|
@ -4,11 +4,9 @@ import cn.hutool.core.collection.CollUtil;
|
|||||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
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.CollectionUtils;
|
||||||
import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.SensitiveWordCreateReqVO;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
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.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.convert.sensitiveword.SensitiveWordConvert;
|
|
||||||
import cn.iocoder.yudao.module.system.dal.dataobject.sensitiveword.SensitiveWordDO;
|
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.dal.mysql.sensitiveword.SensitiveWordMapper;
|
||||||
import cn.iocoder.yudao.module.system.util.collection.SimpleTrie;
|
import cn.iocoder.yudao.module.system.util.collection.SimpleTrie;
|
||||||
@ -141,12 +139,12 @@ public class SensitiveWordServiceImpl implements SensitiveWordService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long createSensitiveWord(SensitiveWordCreateReqVO createReqVO) {
|
public Long createSensitiveWord(SensitiveWordSaveVO createReqVO) {
|
||||||
// 校验唯一性
|
// 校验唯一性
|
||||||
validateSensitiveWordNameUnique(null, createReqVO.getName());
|
validateSensitiveWordNameUnique(null, createReqVO.getName());
|
||||||
|
|
||||||
// 插入
|
// 插入
|
||||||
SensitiveWordDO sensitiveWord = SensitiveWordConvert.INSTANCE.convert(createReqVO);
|
SensitiveWordDO sensitiveWord = BeanUtils.toBean(createReqVO, SensitiveWordDO.class);
|
||||||
sensitiveWordMapper.insert(sensitiveWord);
|
sensitiveWordMapper.insert(sensitiveWord);
|
||||||
|
|
||||||
// 刷新缓存
|
// 刷新缓存
|
||||||
@ -155,13 +153,13 @@ public class SensitiveWordServiceImpl implements SensitiveWordService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateSensitiveWord(SensitiveWordUpdateReqVO updateReqVO) {
|
public void updateSensitiveWord(SensitiveWordSaveVO updateReqVO) {
|
||||||
// 校验唯一性
|
// 校验唯一性
|
||||||
validateSensitiveWordExists(updateReqVO.getId());
|
validateSensitiveWordExists(updateReqVO.getId());
|
||||||
validateSensitiveWordNameUnique(updateReqVO.getId(), updateReqVO.getName());
|
validateSensitiveWordNameUnique(updateReqVO.getId(), updateReqVO.getName());
|
||||||
|
|
||||||
// 更新
|
// 更新
|
||||||
SensitiveWordDO updateObj = SensitiveWordConvert.INSTANCE.convert(updateReqVO);
|
SensitiveWordDO updateObj = BeanUtils.toBean(updateReqVO, SensitiveWordDO.class);
|
||||||
sensitiveWordMapper.updateById(updateObj);
|
sensitiveWordMapper.updateById(updateObj);
|
||||||
|
|
||||||
// 刷新缓存
|
// 刷新缓存
|
||||||
@ -214,11 +212,6 @@ public class SensitiveWordServiceImpl implements SensitiveWordService {
|
|||||||
return sensitiveWordMapper.selectPage(pageReqVO);
|
return sensitiveWordMapper.selectPage(pageReqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<SensitiveWordDO> getSensitiveWordList(SensitiveWordExportReqVO exportReqVO) {
|
|
||||||
return sensitiveWordMapper.selectList(exportReqVO);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getSensitiveWordTagSet() {
|
public Set<String> getSensitiveWordTagSet() {
|
||||||
return sensitiveWordTagsCache;
|
return sensitiveWordTagsCache;
|
||||||
|
@ -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.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.collection.SetUtils;
|
import cn.iocoder.yudao.framework.common.util.collection.SetUtils;
|
||||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
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.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.dataobject.sensitiveword.SensitiveWordDO;
|
||||||
import cn.iocoder.yudao.module.system.dal.mysql.sensitiveword.SensitiveWordMapper;
|
import cn.iocoder.yudao.module.system.dal.mysql.sensitiveword.SensitiveWordMapper;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
@ -83,7 +81,8 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testCreateSensitiveWord_success() {
|
public void testCreateSensitiveWord_success() {
|
||||||
// 准备参数
|
// 准备参数
|
||||||
SensitiveWordCreateReqVO reqVO = randomPojo(SensitiveWordCreateReqVO.class);
|
SensitiveWordSaveVO reqVO = randomPojo(SensitiveWordSaveVO.class)
|
||||||
|
.setId(null); // 防止 id 被赋值
|
||||||
|
|
||||||
// 调用
|
// 调用
|
||||||
Long sensitiveWordId = sensitiveWordService.createSensitiveWord(reqVO);
|
Long sensitiveWordId = sensitiveWordService.createSensitiveWord(reqVO);
|
||||||
@ -91,7 +90,7 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest {
|
|||||||
assertNotNull(sensitiveWordId);
|
assertNotNull(sensitiveWordId);
|
||||||
// 校验记录的属性是否正确
|
// 校验记录的属性是否正确
|
||||||
SensitiveWordDO sensitiveWord = sensitiveWordMapper.selectById(sensitiveWordId);
|
SensitiveWordDO sensitiveWord = sensitiveWordMapper.selectById(sensitiveWordId);
|
||||||
assertPojoEquals(reqVO, sensitiveWord);
|
assertPojoEquals(reqVO, sensitiveWord, "id");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -100,7 +99,7 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest {
|
|||||||
SensitiveWordDO dbSensitiveWord = randomPojo(SensitiveWordDO.class);
|
SensitiveWordDO dbSensitiveWord = randomPojo(SensitiveWordDO.class);
|
||||||
sensitiveWordMapper.insert(dbSensitiveWord);// @Sql: 先插入出一条存在的数据
|
sensitiveWordMapper.insert(dbSensitiveWord);// @Sql: 先插入出一条存在的数据
|
||||||
// 准备参数
|
// 准备参数
|
||||||
SensitiveWordUpdateReqVO reqVO = randomPojo(SensitiveWordUpdateReqVO.class, o -> {
|
SensitiveWordSaveVO reqVO = randomPojo(SensitiveWordSaveVO.class, o -> {
|
||||||
o.setId(dbSensitiveWord.getId()); // 设置更新的 ID
|
o.setId(dbSensitiveWord.getId()); // 设置更新的 ID
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -114,7 +113,7 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUpdateSensitiveWord_notExists() {
|
public void testUpdateSensitiveWord_notExists() {
|
||||||
// 准备参数
|
// 准备参数
|
||||||
SensitiveWordUpdateReqVO reqVO = randomPojo(SensitiveWordUpdateReqVO.class);
|
SensitiveWordSaveVO reqVO = randomPojo(SensitiveWordSaveVO.class);
|
||||||
|
|
||||||
// 调用, 并断言异常
|
// 调用, 并断言异常
|
||||||
assertServiceException(() -> sensitiveWordService.updateSensitiveWord(reqVO), SENSITIVE_WORD_NOT_EXISTS);
|
assertServiceException(() -> sensitiveWordService.updateSensitiveWord(reqVO), SENSITIVE_WORD_NOT_EXISTS);
|
||||||
@ -204,36 +203,6 @@ public class SensitiveWordServiceImplTest extends BaseDbUnitTest {
|
|||||||
assertPojoEquals(dbSensitiveWord, pageResult.getList().get(0));
|
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<SensitiveWordDO> list = sensitiveWordService.getSensitiveWordList(reqVO);
|
|
||||||
// 断言
|
|
||||||
assertEquals(1, list.size());
|
|
||||||
assertPojoEquals(dbSensitiveWord, list.get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidateText_noTag() {
|
public void testValidateText_noTag() {
|
||||||
testInitLocalCache();
|
testInitLocalCache();
|
||||||
|
Loading…
Reference in New Issue
Block a user