| | |
| | | package com.ruoyi.article.service.impl; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.article.domain.pojo.SensitiveWords; |
| | | import com.ruoyi.article.controller.management.dto.MgtSensitiveWordsDTO; |
| | | import com.ruoyi.article.controller.management.dto.MgtSensitiveWordsQuery; |
| | | import com.ruoyi.article.controller.management.vo.MgtSensitiveWordsVO; |
| | | import com.ruoyi.article.domain.SensitiveWords; |
| | | import com.ruoyi.article.listener.SensitiveWordsListener; |
| | | import com.ruoyi.article.mapper.SensitiveWordsMapper; |
| | | import com.ruoyi.article.service.ISensitiveWordsService; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.utils.page.BeanUtils; |
| | | import com.ruoyi.common.core.utils.page.CollUtils; |
| | | import com.ruoyi.common.core.utils.page.PageDTO; |
| | | import com.ruoyi.system.api.domain.dto.judgeSensitiveWordsDTO; |
| | | import com.ruoyi.system.api.domain.vo.judgeSensitiveWordsVO; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.regex.Pattern; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @since 2024-05-16 |
| | | */ |
| | | @Service |
| | | public class SensitiveWordsServiceImpl extends |
| | | ServiceImpl<SensitiveWordsMapper, SensitiveWords> implements ISensitiveWordsService { |
| | | public class SensitiveWordsServiceImpl extends ServiceImpl<SensitiveWordsMapper, SensitiveWords> implements ISensitiveWordsService { |
| | | |
| | | @Override |
| | | public List<SensitiveWords> getMemberArticleList() { |
| | | LambdaQueryWrapper<SensitiveWords> wrapper= Wrappers.lambdaQuery(); |
| | | wrapper.eq(SensitiveWords::getDelFlag,0); |
| | | return this.list(wrapper); |
| | | } |
| | | |
| | | @Override |
| | | public judgeSensitiveWordsVO judgeSensitiveWordsList(judgeSensitiveWordsDTO SensitiveWordsDTO) { |
| | | judgeSensitiveWordsVO SensitiveWordsVO = new judgeSensitiveWordsVO(); |
| | | LambdaQueryWrapper<SensitiveWords> wrapper= Wrappers.lambdaQuery(); |
| | | wrapper.eq(SensitiveWords::getDelFlag,0); |
| | | List<SensitiveWords> list = this.list(wrapper); |
| | | if (CollUtils.isNotEmpty(list)) { |
| | | List<String> sensitiveWords = new ArrayList<>(); |
| | | for (SensitiveWords l : list) { |
| | | sensitiveWords.add(l.getWord()); |
| | | } |
| | | Pattern pattern = Pattern.compile(String.join("|", sensitiveWords), |
| | | Pattern.CASE_INSENSITIVE); |
| | | boolean b = pattern.matcher(SensitiveWordsDTO.getText()).find(); |
| | | if (b) { |
| | | SensitiveWordsVO.setType(1); |
| | | } else { |
| | | SensitiveWordsVO.setType(2); |
| | | } |
| | | } else { |
| | | SensitiveWordsVO.setType(2); |
| | | } |
| | | return SensitiveWordsVO; |
| | | } |
| | | /** |
| | | * 获取敏感词列表的分页数据 |
| | | * |
| | | * @param query 管理后台-敏感词查询对象 |
| | | * @return PageDTO<MgtSensitiveWordsVO> |
| | | */ |
| | | @Override |
| | | public PageDTO<MgtSensitiveWordsVO> getSensitiveWordsPage(MgtSensitiveWordsQuery query) { |
| | | PageDTO<MgtSensitiveWordsVO> pageVO; |
| | | Page<SensitiveWords> page = this.lambdaQuery() |
| | | .like(StringUtils.isNotBlank(query.getWord()), SensitiveWords::getWord, |
| | | query.getWord()).orderByDesc(SensitiveWords::getCreateTime) |
| | | .page(new Page<>(query.getPageCurr(), query.getPageSize())); |
| | | if (StringUtils.isEmpty(page.getRecords())) { |
| | | pageVO = PageDTO.empty(page); |
| | | } else { |
| | | pageVO = PageDTO.of(page, MgtSensitiveWordsVO.class); |
| | | } |
| | | return pageVO; |
| | | } |
| | | |
| | | /** |
| | | * 添加敏感词 |
| | | * |
| | | * @param dto 敏感词数据传输对象 |
| | | */ |
| | | @Override |
| | | public void saveSensitiveWords(MgtSensitiveWordsDTO dto) { |
| | | this.save(BeanUtils.copyBean(dto, SensitiveWords.class)); |
| | | } |
| | | |
| | | /** |
| | | * 敏感词导入 |
| | | * |
| | | * @param file 导入文件 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public void importSensitiveWords(MultipartFile file) throws IOException { |
| | | EasyExcel.read(file.getInputStream(), MgtSensitiveWordsDTO.class, |
| | | new SensitiveWordsListener(this)).sheet().doRead(); |
| | | } |
| | | } |