commit
c9d3913544
File diff suppressed because one or more lines are too long
@ -0,0 +1,30 @@
|
||||
package cn.iocoder.yudao.module.system.api.sensitiveword;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 敏感词 API 接口
|
||||
*
|
||||
* @author 永不言败
|
||||
*/
|
||||
public interface SensitiveWordApi {
|
||||
|
||||
/**
|
||||
* 获得文本所包含的不合法的敏感词数组
|
||||
*
|
||||
* @param text 文本
|
||||
* @param tags 标签数组
|
||||
* @return 不合法的敏感词数组
|
||||
*/
|
||||
List<String> validateText(String text, List<String> tags);
|
||||
|
||||
/**
|
||||
* 判断文本是否包含敏感词
|
||||
*
|
||||
* @param text 文本
|
||||
* @param tags 表述数组
|
||||
* @return 是否包含
|
||||
*/
|
||||
boolean isTextValid(String text, List<String> tags);
|
||||
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package cn.iocoder.yudao.module.system.api.sensitiveword;
|
||||
|
||||
import cn.iocoder.yudao.module.system.service.sensitiveword.SensitiveWordService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 敏感词 API 实现类
|
||||
*
|
||||
* @author 永不言败
|
||||
*/
|
||||
@Service
|
||||
public class SensitiveWordApiImpl implements SensitiveWordApi {
|
||||
|
||||
@Resource
|
||||
private SensitiveWordService sensitiveWordService;
|
||||
|
||||
@Override
|
||||
public List<String> validateText(String text, List<String> tags) {
|
||||
return sensitiveWordService.validateText(text, tags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTextValid(String text, List<String> tags) {
|
||||
return sensitiveWordService.isTextValid(text, tags);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
### 请求 /system/sensitive-word/validate-text 接口 => 成功
|
||||
GET {{baseUrl}}/system/sensitive-word/validate-text?text=XXX&tags=短信&tags=蔬菜
|
||||
Authorization: Bearer {{token}}
|
||||
tenant-id: {{adminTenentId}}
|
||||
@ -0,0 +1,104 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.sensitiveword;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo.*;
|
||||
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.service.sensitiveword.SensitiveWordService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Api(tags = "管理后台 - 敏感词")
|
||||
@RestController
|
||||
@RequestMapping("/system/sensitive-word")
|
||||
@Validated
|
||||
public class SensitiveWordController {
|
||||
|
||||
@Resource
|
||||
private SensitiveWordService sensitiveWordService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@ApiOperation("创建敏感词")
|
||||
@PreAuthorize("@ss.hasPermission('system:sensitive-word:create')")
|
||||
public CommonResult<Long> createSensitiveWord(@Valid @RequestBody SensitiveWordCreateReqVO createReqVO) {
|
||||
return success(sensitiveWordService.createSensitiveWord(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@ApiOperation("更新敏感词")
|
||||
@PreAuthorize("@ss.hasPermission('system:sensitive-word:update')")
|
||||
public CommonResult<Boolean> updateSensitiveWord(@Valid @RequestBody SensitiveWordUpdateReqVO updateReqVO) {
|
||||
sensitiveWordService.updateSensitiveWord(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperation("删除敏感词")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
|
||||
@PreAuthorize("@ss.hasPermission('system:sensitive-word:delete')")
|
||||
public CommonResult<Boolean> deleteSensitiveWord(@RequestParam("id") Long id) {
|
||||
sensitiveWordService.deleteSensitiveWord(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获得敏感词")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@PreAuthorize("@ss.hasPermission('system:sensitive-word:query')")
|
||||
public CommonResult<SensitiveWordRespVO> getSensitiveWord(@RequestParam("id") Long id) {
|
||||
SensitiveWordDO sensitiveWord = sensitiveWordService.getSensitiveWord(id);
|
||||
return success(SensitiveWordConvert.INSTANCE.convert(sensitiveWord));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得敏感词分页")
|
||||
@PreAuthorize("@ss.hasPermission('system:sensitive-word:query')")
|
||||
public CommonResult<PageResult<SensitiveWordRespVO>> getSensitiveWordPage(@Valid SensitiveWordPageReqVO pageVO) {
|
||||
PageResult<SensitiveWordDO> pageResult = sensitiveWordService.getSensitiveWordPage(pageVO);
|
||||
return success(SensitiveWordConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@ApiOperation("导出敏感词 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('system:sensitive-word:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportSensitiveWordExcel(@Valid SensitiveWordExportReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<SensitiveWordDO> list = sensitiveWordService.getSensitiveWordList(exportReqVO);
|
||||
// 导出 Excel
|
||||
List<SensitiveWordExcelVO> datas = SensitiveWordConvert.INSTANCE.convertList02(list);
|
||||
ExcelUtils.write(response, "敏感词.xls", "数据", SensitiveWordExcelVO.class, datas);
|
||||
}
|
||||
|
||||
@GetMapping("/get-tags")
|
||||
@ApiOperation("获取所有敏感词的标签数组")
|
||||
@PreAuthorize("@ss.hasPermission('system:sensitive-word:query')")
|
||||
public CommonResult<Set<String>> getSensitiveWordTags() throws IOException {
|
||||
return success(sensitiveWordService.getSensitiveWordTags());
|
||||
}
|
||||
|
||||
@GetMapping("/validate-text")
|
||||
@ApiOperation("获得文本所包含的不合法的敏感词数组")
|
||||
public CommonResult<List<String>> validateText(@RequestParam("text") String text,
|
||||
@RequestParam(value = "tags", required = false) List<String> tags) {
|
||||
return success(sensitiveWordService.validateText(text, tags));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
@ApiModel("管理后台 - 敏感词创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class SensitiveWordCreateReqVO extends SensitiveWordBaseVO {
|
||||
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ApiModel("管理后台 - 敏感词 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class SensitiveWordRespVO extends SensitiveWordBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "编号", required = true, example = "1")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "创建时间", required = true)
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.sensitiveword.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@ApiModel("管理后台 - 敏感词更新 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class SensitiveWordUpdateReqVO extends SensitiveWordBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "编号", required = true, example = "1")
|
||||
@NotNull(message = "编号不能为空")
|
||||
private Long id;
|
||||
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
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);
|
||||
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
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.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 敏感词 Mapper
|
||||
*
|
||||
* @author 永不言败
|
||||
*/
|
||||
@Mapper
|
||||
public interface SensitiveWordMapper extends BaseMapperX<SensitiveWordDO> {
|
||||
|
||||
default PageResult<SensitiveWordDO> selectPage(SensitiveWordPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<SensitiveWordDO>()
|
||||
.likeIfPresent(SensitiveWordDO::getName, reqVO.getName())
|
||||
.likeIfPresent(SensitiveWordDO::getTags, reqVO.getTag())
|
||||
.eqIfPresent(SensitiveWordDO::getStatus, reqVO.getStatus())
|
||||
.betweenIfPresent(SensitiveWordDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
|
||||
.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.getBeginCreateTime(), reqVO.getEndCreateTime())
|
||||
.orderByDesc(SensitiveWordDO::getId));
|
||||
}
|
||||
|
||||
default SensitiveWordDO selectByName(String name) {
|
||||
return selectOne(SensitiveWordDO::getName, name);
|
||||
}
|
||||
|
||||
@Select("SELECT id FROM system_sensitive_word WHERE update_time > #{maxUpdateTime} LIMIT 1")
|
||||
SensitiveWordDO selectExistsByUpdateTimeAfter(Date maxUpdateTime);
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package cn.iocoder.yudao.module.system.mq.consumer.sensitiveword;
|
||||
|
||||
import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessageListener;
|
||||
import cn.iocoder.yudao.module.system.mq.message.sensitiveword.SensitiveWordRefreshMessage;
|
||||
import cn.iocoder.yudao.module.system.service.sensitiveword.SensitiveWordService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 针对 {@link SensitiveWordRefreshMessage} 的消费者
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SensitiveWordRefreshConsumer extends AbstractChannelMessageListener<SensitiveWordRefreshMessage> {
|
||||
|
||||
@Resource
|
||||
private SensitiveWordService sensitiveWordService;
|
||||
|
||||
@Override
|
||||
public void onMessage(SensitiveWordRefreshMessage message) {
|
||||
log.info("[onMessage][收到 SensitiveWord 刷新消息]");
|
||||
sensitiveWordService.initLocalCache();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package cn.iocoder.yudao.module.system.mq.message.sensitiveword;
|
||||
|
||||
import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessage;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 敏感词的刷新 Message
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SensitiveWordRefreshMessage extends AbstractChannelMessage {
|
||||
|
||||
@Override
|
||||
public String getChannel() {
|
||||
return "system.sensitive-word.refresh";
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package cn.iocoder.yudao.module.system.mq.producer.sensitiveword;
|
||||
|
||||
import cn.iocoder.yudao.framework.mq.core.RedisMQTemplate;
|
||||
import cn.iocoder.yudao.module.system.mq.message.sensitiveword.SensitiveWordRefreshMessage;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 敏感词相关的 Producer
|
||||
*/
|
||||
@Component
|
||||
public class SensitiveWordProducer {
|
||||
|
||||
@Resource
|
||||
private RedisMQTemplate redisMQTemplate;
|
||||
|
||||
/**
|
||||
* 发送 {@link SensitiveWordRefreshMessage} 消息
|
||||
*/
|
||||
public void sendSensitiveWordRefreshMessage() {
|
||||
SensitiveWordRefreshMessage message = new SensitiveWordRefreshMessage();
|
||||
redisMQTemplate.send(message);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,104 @@
|
||||
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.dal.dataobject.sensitiveword.SensitiveWordDO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 敏感词 Service 接口
|
||||
*
|
||||
* @author 永不言败
|
||||
*/
|
||||
public interface SensitiveWordService {
|
||||
|
||||
/**
|
||||
* 初始化本地缓存
|
||||
*/
|
||||
void initLocalCache();
|
||||
|
||||
/**
|
||||
* 创建敏感词
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createSensitiveWord(@Valid SensitiveWordCreateReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新敏感词
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateSensitiveWord(@Valid SensitiveWordUpdateReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除敏感词
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteSensitiveWord(Long id);
|
||||
|
||||
/**
|
||||
* 获得敏感词
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 敏感词
|
||||
*/
|
||||
SensitiveWordDO getSensitiveWord(Long id);
|
||||
|
||||
/**
|
||||
* 获得敏感词列表
|
||||
*
|
||||
* @return 敏感词列表
|
||||
*/
|
||||
List<SensitiveWordDO> getSensitiveWordList();
|
||||
|
||||
/**
|
||||
* 获得敏感词分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 敏感词分页
|
||||
*/
|
||||
PageResult<SensitiveWordDO> getSensitiveWordPage(SensitiveWordPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得敏感词列表, 用于 Excel 导出
|
||||
*
|
||||
* @param exportReqVO 查询条件
|
||||
* @return 敏感词列表
|
||||
*/
|
||||
List<SensitiveWordDO> getSensitiveWordList(SensitiveWordExportReqVO exportReqVO);
|
||||
|
||||
/**
|
||||
* 获得所有敏感词的标签数组
|
||||
*
|
||||
* @return 标签数组
|
||||
*/
|
||||
Set<String> getSensitiveWordTags();
|
||||
|
||||
/**
|
||||
* 获得文本所包含的不合法的敏感词数组
|
||||
*
|
||||
* @param text 文本
|
||||
* @param tags 标签数组
|
||||
* @return 不合法的敏感词数组
|
||||
*/
|
||||
List<String> validateText(String text, List<String> tags);
|
||||
|
||||
/**
|
||||
* 判断文本是否包含敏感词
|
||||
*
|
||||
* @param text 文本
|
||||
* @param tags 表述数组
|
||||
* @return 是否包含
|
||||
*/
|
||||
boolean isTextValid(String text, List<String> tags);
|
||||
|
||||
}
|
||||
@ -0,0 +1,246 @@
|
||||
package cn.iocoder.yudao.module.system.service.sensitiveword;
|
||||
|
||||
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.common.util.date.DateUtils;
|
||||
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.dal.dataobject.sensitiveword.SensitiveWordDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.sensitiveword.SensitiveWordMapper;
|
||||
import cn.iocoder.yudao.module.system.mq.producer.sensitiveword.SensitiveWordProducer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.max;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SENSITIVE_WORD_NOT_EXISTS;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* {@link SensitiveWordServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 永不言败
|
||||
*/
|
||||
@Import(SensitiveWordServiceImpl.class)
|
||||
public class SensitiveWordServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private SensitiveWordServiceImpl sensitiveWordService;
|
||||
|
||||
@Resource
|
||||
private SensitiveWordMapper sensitiveWordMapper;
|
||||
|
||||
@MockBean
|
||||
private SensitiveWordProducer sensitiveWordProducer;
|
||||
|
||||
@Test
|
||||
public void testInitLocalCache() {
|
||||
SensitiveWordDO wordDO1 = randomPojo(SensitiveWordDO.class, o -> o.setName("傻瓜")
|
||||
.setTags(singletonList("论坛")).setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
sensitiveWordMapper.insert(wordDO1);
|
||||
SensitiveWordDO wordDO2 = randomPojo(SensitiveWordDO.class, o -> o.setName("笨蛋")
|
||||
.setTags(singletonList("蔬菜")).setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
sensitiveWordMapper.insert(wordDO2);
|
||||
|
||||
// 调用
|
||||
sensitiveWordService.initLocalCache();
|
||||
// 断言 maxUpdateTime 缓存
|
||||
assertEquals(max(wordDO1.getUpdateTime(), wordDO2.getUpdateTime()), sensitiveWordService.getMaxUpdateTime());
|
||||
// 断言 sensitiveWordTagsCache 缓存
|
||||
assertEquals(SetUtils.asSet("论坛", "蔬菜"), sensitiveWordService.getSensitiveWordTags());
|
||||
// 断言 tagSensitiveWordTries 缓存
|
||||
assertNotNull(sensitiveWordService.getDefaultSensitiveWordTrie());
|
||||
assertEquals(2, sensitiveWordService.getTagSensitiveWordTries().size());
|
||||
assertNotNull(sensitiveWordService.getTagSensitiveWordTries().get("论坛"));
|
||||
assertNotNull(sensitiveWordService.getTagSensitiveWordTries().get("蔬菜"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateSensitiveWord_success() {
|
||||
// 准备参数
|
||||
SensitiveWordCreateReqVO reqVO = randomPojo(SensitiveWordCreateReqVO.class);
|
||||
|
||||
// 调用
|
||||
Long sensitiveWordId = sensitiveWordService.createSensitiveWord(reqVO);
|
||||
// 断言
|
||||
assertNotNull(sensitiveWordId);
|
||||
// 校验记录的属性是否正确
|
||||
SensitiveWordDO sensitiveWord = sensitiveWordMapper.selectById(sensitiveWordId);
|
||||
assertPojoEquals(reqVO, sensitiveWord);
|
||||
verify(sensitiveWordProducer).sendSensitiveWordRefreshMessage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateSensitiveWord_success() {
|
||||
// mock 数据
|
||||
SensitiveWordDO dbSensitiveWord = randomPojo(SensitiveWordDO.class);
|
||||
sensitiveWordMapper.insert(dbSensitiveWord);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
SensitiveWordUpdateReqVO reqVO = randomPojo(SensitiveWordUpdateReqVO.class, o -> {
|
||||
o.setId(dbSensitiveWord.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
sensitiveWordService.updateSensitiveWord(reqVO);
|
||||
// 校验是否更新正确
|
||||
SensitiveWordDO sensitiveWord = sensitiveWordMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, sensitiveWord);
|
||||
verify(sensitiveWordProducer).sendSensitiveWordRefreshMessage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateSensitiveWord_notExists() {
|
||||
// 准备参数
|
||||
SensitiveWordUpdateReqVO reqVO = randomPojo(SensitiveWordUpdateReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> sensitiveWordService.updateSensitiveWord(reqVO), SENSITIVE_WORD_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteSensitiveWord_success() {
|
||||
// mock 数据
|
||||
SensitiveWordDO dbSensitiveWord = randomPojo(SensitiveWordDO.class);
|
||||
sensitiveWordMapper.insert(dbSensitiveWord);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbSensitiveWord.getId();
|
||||
|
||||
// 调用
|
||||
sensitiveWordService.deleteSensitiveWord(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(sensitiveWordMapper.selectById(id));
|
||||
verify(sensitiveWordProducer).sendSensitiveWordRefreshMessage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteSensitiveWord_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> sensitiveWordService.deleteSensitiveWord(id), SENSITIVE_WORD_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSensitiveWordPage() {
|
||||
// mock 数据
|
||||
SensitiveWordDO dbSensitiveWord = randomPojo(SensitiveWordDO.class, o -> { // 等会查询到
|
||||
o.setName("笨蛋");
|
||||
o.setTags(Arrays.asList("论坛", "蔬菜"));
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setCreateTime(DateUtils.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(DateUtils.buildTime(2022, 2, 16))));
|
||||
// 准备参数
|
||||
SensitiveWordPageReqVO reqVO = new SensitiveWordPageReqVO();
|
||||
reqVO.setName("笨");
|
||||
reqVO.setTag("论坛");
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
reqVO.setBeginCreateTime(DateUtils.buildTime(2022, 2, 1));
|
||||
reqVO.setEndCreateTime(DateUtils.buildTime(2022, 2, 12));
|
||||
|
||||
// 调用
|
||||
PageResult<SensitiveWordDO> pageResult = sensitiveWordService.getSensitiveWordPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbSensitiveWord, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSensitiveWordList() {
|
||||
// mock 数据
|
||||
SensitiveWordDO dbSensitiveWord = randomPojo(SensitiveWordDO.class, o -> { // 等会查询到
|
||||
o.setName("笨蛋");
|
||||
o.setTags(Arrays.asList("论坛", "蔬菜"));
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setCreateTime(DateUtils.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(DateUtils.buildTime(2022, 2, 16))));
|
||||
// 准备参数
|
||||
SensitiveWordExportReqVO reqVO = new SensitiveWordExportReqVO();
|
||||
reqVO.setName("笨");
|
||||
reqVO.setTag("论坛");
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
reqVO.setBeginCreateTime(DateUtils.buildTime(2022, 2, 1));
|
||||
reqVO.setEndCreateTime(DateUtils.buildTime(2022, 2, 12));
|
||||
|
||||
// 调用
|
||||
List<SensitiveWordDO> list = sensitiveWordService.getSensitiveWordList(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbSensitiveWord, list.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateText_noTag() {
|
||||
testInitLocalCache();
|
||||
// 准备参数
|
||||
String text = "你是傻瓜,你是笨蛋";
|
||||
|
||||
// 调用
|
||||
List<String> result = sensitiveWordService.validateText(text, null);
|
||||
// 断言
|
||||
assertEquals(Arrays.asList("傻瓜", "笨蛋"), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateText_hasTag() {
|
||||
testInitLocalCache();
|
||||
// 准备参数
|
||||
String text = "你是傻瓜,你是笨蛋";
|
||||
|
||||
// 调用
|
||||
List<String> result = sensitiveWordService.validateText(text, singletonList("论坛"));
|
||||
// 断言
|
||||
assertEquals(singletonList("傻瓜"), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsTestValid_noTag() {
|
||||
testInitLocalCache();
|
||||
// 准备参数
|
||||
String text = "你是傻瓜,你是笨蛋";
|
||||
|
||||
// 调用,断言
|
||||
assertFalse(sensitiveWordService.isTextValid(text, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsTestValid_hasTag() {
|
||||
testInitLocalCache();
|
||||
// 准备参数
|
||||
String text = "你是傻瓜,你是笨蛋";
|
||||
|
||||
// 调用,断言
|
||||
assertFalse(sensitiveWordService.isTextValid(text, singletonList("论坛")));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
import request from '@/utils/request'
|
||||
import qs from 'qs'
|
||||
|
||||
// 创建敏感词
|
||||
export function createSensitiveWord(data) {
|
||||
return request({
|
||||
url: '/system/sensitive-word/create',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 更新敏感词
|
||||
export function updateSensitiveWord(data) {
|
||||
return request({
|
||||
url: '/system/sensitive-word/update',
|
||||
method: 'put',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 删除敏感词
|
||||
export function deleteSensitiveWord(id) {
|
||||
return request({
|
||||
url: '/system/sensitive-word/delete?id=' + id,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
|
||||
// 获得敏感词
|
||||
export function getSensitiveWord(id) {
|
||||
return request({
|
||||
url: '/system/sensitive-word/get?id=' + id,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 获得敏感词分页
|
||||
export function getSensitiveWordPage(query) {
|
||||
return request({
|
||||
url: '/system/sensitive-word/page',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
// 导出敏感词 Excel
|
||||
export function exportSensitiveWordExcel(query) {
|
||||
return request({
|
||||
url: '/system/sensitive-word/export-excel',
|
||||
method: 'get',
|
||||
params: query,
|
||||
responseType: 'blob'
|
||||
})
|
||||
}
|
||||
|
||||
// 获取所有敏感词的标签数组
|
||||
export function getSensitiveWordTags(){
|
||||
return request({
|
||||
url: '/system/sensitive-word/get-tags',
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 获得文本所包含的不合法的敏感词数组
|
||||
export function validateText(query) {
|
||||
return request({
|
||||
url: '/system/sensitive-word/validate-text?' + qs.stringify(query, {arrayFormat: 'repeat'}),
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,326 @@
|
||||
<template>
|
||||
<div class="app-container">
|
||||
<!-- 搜索工作栏 -->
|
||||
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
|
||||
<el-form-item label="敏感词" prop="name">
|
||||
<el-input v-model="queryParams.name" placeholder="请输入敏感词" clearable @keyup.enter.native="handleQuery"/>
|
||||
</el-form-item>
|
||||
<el-form-item label="标签" prop="tag">
|
||||
<el-select v-model="queryParams.tag" placeholder="请选择标签" clearable @keyup.enter.native="handleQuery">
|
||||
<el-option v-for="tag in tags" :key="tag" :label="tag" :value="tag"/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-select v-model="queryParams.status" placeholder="请选择启用状态" clearable>
|
||||
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)"
|
||||
:key="dict.value" :label="dict.label" :value="dict.value"/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="创建时间">
|
||||
<el-date-picker v-model="dateRangeCreateTime" size="small" style="width: 240px" value-format="yyyy-MM-dd"
|
||||
type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<!-- 操作工具栏 -->
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
|
||||
v-hasPermi="['system:sensitive-word:create']">新增</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
|
||||
:loading="exportLoading" v-hasPermi="['system:sensitive-word:export']">导出</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button type="success" plain icon="el-icon-document-checked" size="mini" @click="handleTest">测试</el-button>
|
||||
</el-col>
|
||||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList" />
|
||||
</el-row>
|
||||
|
||||
<!-- 列表 -->
|
||||
<el-table v-loading="loading" :data="list">
|
||||
<el-table-column label="编号" align="center" prop="id"/>
|
||||
<el-table-column label="敏感词" align="center" prop="name"/>
|
||||
<el-table-column label="状态" align="center" prop="status">
|
||||
<template slot-scope="scope">
|
||||
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="描述" align="center" prop="description"/>
|
||||
<el-table-column label="标签" align="center" prop="tags">
|
||||
</el-table-column>
|
||||
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
|
||||
<template slot-scope="scope">
|
||||
<el-tag :disable-transitions="true" v-for="(tag, index) in scope.row.tags" :index="index">
|
||||
{{ tag }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<template slot-scope="scope">
|
||||
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
|
||||
v-hasPermi="['system:sensitive-word:update']">修改
|
||||
</el-button>
|
||||
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
|
||||
v-hasPermi="['system:sensitive-word:delete']">删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<!-- 分页组件 -->
|
||||
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
|
||||
@pagination="getList"/>
|
||||
|
||||
<!-- 对话框(添加 / 修改) -->
|
||||
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
||||
<el-form-item label="敏感词" prop="name">
|
||||
<el-input v-model="form.name" placeholder="请输入敏感词"/>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-radio-group v-model="form.status">
|
||||
<el-radio v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)"
|
||||
:key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="description">
|
||||
<el-input v-model="form.description" type="textarea" placeholder="请输入内容" />
|
||||
</el-form-item>
|
||||
<el-form-item label="标签" prop="tags">
|
||||
<el-select v-model="form.tags" multiple filterable allow-create placeholder="请选择文章标签" style="width: 380px" >
|
||||
<el-option v-for="tag in tags" :key="tag" :label="tag" :value="tag"/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 对话框(测试敏感词) -->
|
||||
<el-dialog title="检测敏感词" :visible.sync="testOpen" width="500px" append-to-body>
|
||||
<el-form ref="testForm" :model="testForm" :rules="testRules" label-width="80px">
|
||||
<el-form-item label="文本" prop="text">
|
||||
<el-input type="textarea" v-model="testForm.text" placeholder="请输入测试文本"/>
|
||||
</el-form-item>
|
||||
<el-form-item label="标签" prop="tags">
|
||||
<el-select v-model="testForm.tags" multiple placeholder="请选择标签" style="width: 380px" >
|
||||
<el-option v-for="tag in tags" :key="tag" :label="tag" :value="tag"/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="submitTestForm">检 测</el-button>
|
||||
<el-button @click="cancelTest">取 消</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { createSensitiveWord, updateSensitiveWord, deleteSensitiveWord, getSensitiveWord, getSensitiveWordPage,
|
||||
exportSensitiveWordExcel, validateText, getSensitiveWordTags} from "@/api/system/sensitiveWord";
|
||||
import {CommonStatusEnum} from "@/utils/constants";
|
||||
|
||||
export default {
|
||||
name: "SensitiveWord",
|
||||
data() {
|
||||
return {
|
||||
// 遮罩层
|
||||
loading: true,
|
||||
// 导出遮罩层
|
||||
exportLoading: false,
|
||||
// 显示搜索条件
|
||||
showSearch: true,
|
||||
// 总条数
|
||||
total: 0,
|
||||
// 敏感词列表
|
||||
list: [],
|
||||
// 弹出层标题
|
||||
title: "",
|
||||
// 是否显示弹出层
|
||||
open: false,
|
||||
testOpen: false,
|
||||
dateRangeCreateTime: [],
|
||||
tags: [],
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
name: null,
|
||||
tag: null,
|
||||
},
|
||||
// 表单参数
|
||||
form: {},
|
||||
// 表单参数
|
||||
testForm: {},
|
||||
// 表单校验
|
||||
rules: {
|
||||
name: [{required: true, message: "敏感词不能为空", trigger: "blur"}],
|
||||
tags: [{required: true, message: "标签不能为空", trigger: "blur"}]
|
||||
},
|
||||
testRules: {
|
||||
text: [{required: true, message: "测试文本不能为空", trigger: 'blur'}],
|
||||
}
|
||||
};
|
||||
},
|
||||
created() {
|
||||
this.getTags();
|
||||
this.getList();
|
||||
},
|
||||
methods: {
|
||||
/** 初始化标签select*/
|
||||
getTags(){
|
||||
getSensitiveWordTags().then(response => {
|
||||
this.tags = response.data;
|
||||
});
|
||||
},
|
||||
/** 查询列表 */
|
||||
getList() {
|
||||
this.loading = true;
|
||||
// 处理查询参数
|
||||
let params = {...this.queryParams};
|
||||
this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
|
||||
// 执行查询
|
||||
getSensitiveWordPage(params).then(response => {
|
||||
this.list = response.data.list;
|
||||
this.total = response.data.total;
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
/** 取消按钮 */
|
||||
cancel() {
|
||||
this.open = false;
|
||||
this.reset();
|
||||
},
|
||||
/** 取消按钮 */
|
||||
cancelTest() {
|
||||
this.resetTest();
|
||||
},
|
||||
/** 表单重置 */
|
||||
reset() {
|
||||
this.form = {
|
||||
id: undefined,
|
||||
name: undefined,
|
||||
description: undefined,
|
||||
tags: undefined,
|
||||
status: CommonStatusEnum.ENABLE
|
||||
};
|
||||
this.resetForm("form");
|
||||
},
|
||||
/** 表单重置 */
|
||||
resetTest() {
|
||||
this.testForm = {
|
||||
text: undefined,
|
||||
tags: undefined
|
||||
};
|
||||
this.resetForm("testForm");
|
||||
},
|
||||
/** 搜索按钮操作 */
|
||||
handleQuery() {
|
||||
this.queryParams.pageNo = 1;
|
||||
this.getList();
|
||||
},
|
||||
/** 重置按钮操作 */
|
||||
resetQuery() {
|
||||
this.dateRangeCreateTime = [];
|
||||
this.resetForm("queryForm");
|
||||
this.handleQuery();
|
||||
},
|
||||
/** 新增按钮操作 */
|
||||
handleAdd() {
|
||||
this.reset();
|
||||
this.open = true;
|
||||
this.title = "添加敏感词";
|
||||
},
|
||||
/** 测试敏感词按钮操作 */
|
||||
handleTest() {
|
||||
this.resetTest();
|
||||
this.testOpen = true;
|
||||
this.titleTest = "检测文本是否含有敏感词";
|
||||
},
|
||||
/** 修改按钮操作 */
|
||||
handleUpdate(row) {
|
||||
this.reset();
|
||||
const id = row.id;
|
||||
getSensitiveWord(id).then(response => {
|
||||
this.form = response.data;
|
||||
this.open = true;
|
||||
this.title = "修改敏感词";
|
||||
});
|
||||
},
|
||||
/** 提交按钮 */
|
||||
submitForm() {
|
||||
this.$refs["form"].validate(valid => {
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
// 修改的提交
|
||||
if (this.form.id != null) {
|
||||
updateSensitiveWord(this.form).then(response => {
|
||||
this.$modal.msgSuccess("修改成功");
|
||||
this.open = false;
|
||||
this.getList();
|
||||
}).catch(err => {});
|
||||
return;
|
||||
}
|
||||
// 添加的提交
|
||||
createSensitiveWord(this.form).then(response => {
|
||||
this.$modal.msgSuccess("新增成功");
|
||||
this.open = false;
|
||||
this.getList();
|
||||
}).catch(err => {});
|
||||
});
|
||||
},
|
||||
/** 测试文本2提交按钮 */
|
||||
submitTestForm() {
|
||||
this.$refs["testForm"].validate(valid => {
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
validateText(this.testForm).then(response => {
|
||||
if (response.data.length === 0) {
|
||||
this.$modal.msgSuccess("不包含敏感词!");
|
||||
return;
|
||||
}
|
||||
this.$modal.msgWarning("包含敏感词:" + response.data.join(', '));
|
||||
})
|
||||
});
|
||||
},
|
||||
/** 删除按钮操作 */
|
||||
handleDelete(row) {
|
||||
const id = row.id;
|
||||
this.$modal.confirm('是否确认删除敏感词编号为"' + id + '"的数据项?').then(function () {
|
||||
return deleteSensitiveWord(id);
|
||||
}).then(() => {
|
||||
this.getList();
|
||||
this.$modal.msgSuccess("删除成功");
|
||||
}).catch(() => {
|
||||
});
|
||||
},
|
||||
/** 导出按钮操作 */
|
||||
handleExport() {
|
||||
// 处理查询参数
|
||||
let params = {...this.queryParams};
|
||||
params.pageNo = undefined;
|
||||
params.pageSize = undefined;
|
||||
this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
|
||||
// 执行导出
|
||||
this.$modal.confirm('是否确认导出所有敏感词数据项?').then(() => {
|
||||
this.exportLoading = true;
|
||||
return exportSensitiveWordExcel(params);
|
||||
}).then(response => {
|
||||
this.$download.excel(response, '${table.classComment}.xls');
|
||||
this.exportLoading = false;
|
||||
}).catch(() => {
|
||||
});
|
||||
},
|
||||
}
|
||||
};
|
||||
</script>
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue