|
|
|
@ -1,20 +1,21 @@
|
|
|
|
|
package com.example.venue_reservation_service.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import com.example.venue_reservation_service.domain.SensitiveWord;
|
|
|
|
|
import com.example.venue_reservation_service.dto.PageDTO;
|
|
|
|
|
import com.example.venue_reservation_service.dto.SensitiveWordDTO;
|
|
|
|
|
import com.example.venue_reservation_service.dto.WordDTO;
|
|
|
|
|
import com.example.venue_reservation_service.mapper.SensitiveWordMapper;
|
|
|
|
|
import com.example.venue_reservation_service.service.SensitiveWordService;
|
|
|
|
|
import com.example.venue_reservation_service.vo.QueryVO;
|
|
|
|
|
import com.example.venue_reservation_service.vo.Result;
|
|
|
|
|
import jakarta.annotation.Resource;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 敏感词业务实现类
|
|
|
|
@ -29,9 +30,15 @@ public class SensitiveWordServiceImpl extends ServiceImpl<SensitiveWordMapper, S
|
|
|
|
|
* 分页查询敏感词列表
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Result getSensitiveWords(PageDTO dto) {
|
|
|
|
|
public Result getSensitiveWords(WordDTO dto) {
|
|
|
|
|
Page<SensitiveWord> page = new Page<>(dto.getCurrent(), dto.getSize());
|
|
|
|
|
page = page(page, null);
|
|
|
|
|
LambdaQueryWrapper<SensitiveWord> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
Integer level = dto.getLevel();
|
|
|
|
|
if(level != 0){
|
|
|
|
|
wrapper.eq(SensitiveWord::getLevel, level);
|
|
|
|
|
}
|
|
|
|
|
wrapper.orderByDesc(SensitiveWord::getUpdateTime);
|
|
|
|
|
page = page(page, wrapper);
|
|
|
|
|
QueryVO<SensitiveWord> vo = new QueryVO<>();
|
|
|
|
|
vo.setList(page.getRecords());
|
|
|
|
|
vo.setTotal(page.getTotal());
|
|
|
|
@ -42,39 +49,37 @@ public class SensitiveWordServiceImpl extends ServiceImpl<SensitiveWordMapper, S
|
|
|
|
|
* 添加敏感词
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Result addSensitiveWord(SensitiveWordDTO sensitiveWordDTO) {
|
|
|
|
|
public Result addSensitiveWord(SensitiveWordDTO dto) {
|
|
|
|
|
// 去空格后判断是否重复
|
|
|
|
|
String word = sensitiveWordDTO.getWord().trim();
|
|
|
|
|
String word = dto.getWord().trim();
|
|
|
|
|
if (count(new LambdaQueryWrapper<SensitiveWord>().eq(SensitiveWord::getWord, word)) > 0) {
|
|
|
|
|
return Result.fail().message("该敏感词已存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SensitiveWord sensitiveWord = new SensitiveWord();
|
|
|
|
|
SensitiveWord sensitiveWord = BeanUtil.copyProperties(dto, SensitiveWord.class);
|
|
|
|
|
sensitiveWord.setWord(word);
|
|
|
|
|
sensitiveWord.setLevel(sensitiveWordDTO.getLevel());
|
|
|
|
|
sensitiveWord.setStatus("0"); // 默认不启用
|
|
|
|
|
sensitiveWord.setStatus(0); // 默认不启用
|
|
|
|
|
sensitiveWord.setCreateTime(LocalDateTime.now());
|
|
|
|
|
sensitiveWord.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
save(sensitiveWord);
|
|
|
|
|
|
|
|
|
|
return Result.ok().message("添加成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改敏感词信息
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Result updateSensitiveWord(Integer id, SensitiveWordDTO sensitiveWordDTO) {
|
|
|
|
|
SensitiveWord sensitiveWord = getById(id);
|
|
|
|
|
if (sensitiveWord == null) {
|
|
|
|
|
return Result.fail().message("未找到对应敏感词");
|
|
|
|
|
public Result updateSensitiveWord(SensitiveWord word) {
|
|
|
|
|
if(Optional.ofNullable(word).isEmpty() || Optional.ofNullable(word.getId()).isEmpty()){
|
|
|
|
|
return Result.fail().message("敏感词记录不存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sensitiveWord.setWord(sensitiveWordDTO.getWord().trim());
|
|
|
|
|
sensitiveWord.setLevel(sensitiveWordDTO.getLevel());
|
|
|
|
|
|
|
|
|
|
updateById(sensitiveWord);
|
|
|
|
|
SensitiveWord origin = getById(word.getId());
|
|
|
|
|
if(!origin.getWord().equals(word.getWord())){
|
|
|
|
|
// 修改了敏感词内容
|
|
|
|
|
if (count(new LambdaQueryWrapper<SensitiveWord>().eq(SensitiveWord::getWord, word.getWord())) > 0) {
|
|
|
|
|
return Result.fail().message("该敏感词已存在");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
updateById(word);
|
|
|
|
|
return Result.ok().message("修改成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -83,15 +88,28 @@ public class SensitiveWordServiceImpl extends ServiceImpl<SensitiveWordMapper, S
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Result removeSensitiveWord(Integer id) {
|
|
|
|
|
if (!exists(id)) {
|
|
|
|
|
return Result.fail().message("未找到对应敏感词");
|
|
|
|
|
SensitiveWord word = getById(id);
|
|
|
|
|
if(Optional.ofNullable(word).isEmpty()){
|
|
|
|
|
return Result.fail().message("未查询到相关敏感词信息");
|
|
|
|
|
}
|
|
|
|
|
if (word.getStatus() == 1) {
|
|
|
|
|
return Result.fail().message("该敏感词已启用,请先进行禁用");
|
|
|
|
|
}
|
|
|
|
|
removeById(id);
|
|
|
|
|
return Result.ok().message("删除成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 辅助方法:检查是否存在
|
|
|
|
|
private boolean exists(Integer id) {
|
|
|
|
|
return count(new LambdaQueryWrapper<SensitiveWord>().eq(SensitiveWord::getId, id)) > 0;
|
|
|
|
|
@Override
|
|
|
|
|
public Result set(Integer id) {
|
|
|
|
|
SensitiveWord word = getById(id);
|
|
|
|
|
if(Optional.ofNullable(word).isEmpty()){
|
|
|
|
|
return Result.fail().message("未查询到相关敏感词信息");
|
|
|
|
|
}
|
|
|
|
|
Integer status = word.getStatus();
|
|
|
|
|
word.setStatus(status == 1 ? 0 : 1);
|
|
|
|
|
updateById(word);
|
|
|
|
|
return Result.ok().message("设置成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|