123333
This commit is contained in:
8
pom.xml
8
pom.xml
@@ -316,6 +316,13 @@
|
||||
<artifactId>ruoyi-cai</artifactId>
|
||||
<version>${ruoyi-vue-plus.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- demo模块 -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-sensitive-word</artifactId>
|
||||
<version>${ruoyi-vue-plus.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
@@ -331,6 +338,7 @@
|
||||
<module>ruoyi-cai</module>
|
||||
<module>ruoyi-yunxin</module>
|
||||
<module>ruoyi-websocket-boot</module>
|
||||
<module>ruoyi-sensitive-word</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
|
||||
@@ -88,6 +88,11 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-sensitive-word</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- skywalking 整合 logback -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.apache.skywalking</groupId>-->
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.ruoyi.web.controller.sensitive;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.annotation.RepeatSubmit;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.PageQuery;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.core.validate.AddGroup;
|
||||
import com.ruoyi.common.core.validate.EditGroup;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.sensitive.domain.Word;
|
||||
import com.ruoyi.sensitive.service.WordService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 敏感词
|
||||
*
|
||||
* @author 77
|
||||
* @date 2024-02-19
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/sensitive/word")
|
||||
public class WordController extends BaseController {
|
||||
|
||||
private final WordService wordService;
|
||||
|
||||
/**
|
||||
* 查询敏感词列表
|
||||
*/
|
||||
@SaCheckPermission("sensitive:word:list")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<Word> list(Word bo, PageQuery pageQuery) {
|
||||
Page<Word> page = wordService.page(pageQuery.build(), Wrappers.lambdaQuery(bo));
|
||||
return TableDataInfo.build(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出敏感词列表
|
||||
*/
|
||||
@SaCheckPermission("sensitive:word:export")
|
||||
@Log(title = "敏感词", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(Word bo, HttpServletResponse response) {
|
||||
List<Word> list = wordService.list(Wrappers.lambdaQuery(bo));
|
||||
ExcelUtil.exportExcel(list, "敏感词", Word.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取敏感词详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@SaCheckPermission("sensitive:word:query")
|
||||
@GetMapping("/{id}")
|
||||
public R<Word> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Integer id) {
|
||||
return R.ok(wordService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增敏感词
|
||||
*/
|
||||
@SaCheckPermission("sensitive:word:add")
|
||||
@Log(title = "敏感词", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit()
|
||||
@PostMapping()
|
||||
public R<Void> add(@Validated(AddGroup.class) @RequestBody Word bo) {
|
||||
return toAjax(wordService.saveWord(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改敏感词
|
||||
*/
|
||||
@SaCheckPermission("sensitive:word:edit")
|
||||
@Log(title = "敏感词", businessType = BusinessType.UPDATE)
|
||||
@RepeatSubmit()
|
||||
@PutMapping()
|
||||
public R<Void> edit(@Validated(EditGroup.class) @RequestBody Word bo) {
|
||||
return toAjax(wordService.updateWordById(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除敏感词
|
||||
*
|
||||
* @param ids 主键串
|
||||
*/
|
||||
@SaCheckPermission("sensitive:word:remove")
|
||||
@Log(title = "敏感词", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable Integer[] ids) {
|
||||
return toAjax(wordService.removeWordBatchByIds(Arrays.asList(ids)));
|
||||
}
|
||||
}
|
||||
32
ruoyi-sensitive-word/pom.xml
Normal file
32
ruoyi-sensitive-word/pom.xml
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-vue-plus</artifactId>
|
||||
<version>4.8.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ruoyi-sensitive-word</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.houbb</groupId>
|
||||
<artifactId>sensitive-word</artifactId>
|
||||
<version>0.12.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
28
ruoyi-sensitive-word/src/main/java/com/ruoyi/sensitive/cache/LastUpdateTimeCache.java
vendored
Normal file
28
ruoyi-sensitive-word/src/main/java/com/ruoyi/sensitive/cache/LastUpdateTimeCache.java
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
package com.ruoyi.sensitive.cache;
|
||||
|
||||
import org.redisson.api.RBucket;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Component
|
||||
public class LastUpdateTimeCache {
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
private String getKey(){
|
||||
return "sensitive-lastRefreshTime";
|
||||
}
|
||||
public LocalDateTime getTime(){
|
||||
String key = getKey();
|
||||
RBucket<LocalDateTime> bucket = redissonClient.getBucket(key);
|
||||
return bucket.get();
|
||||
}
|
||||
|
||||
public void setTime(){
|
||||
String key = getKey();
|
||||
RBucket<LocalDateTime> bucket = redissonClient.getBucket(key);
|
||||
bucket.set(LocalDateTime.now());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.ruoyi.sensitive.config;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.github.houbb.heaven.support.handler.IHandler;
|
||||
import com.github.houbb.heaven.util.util.CollectionUtil;
|
||||
import com.github.houbb.sensitive.word.api.IWordAllow;
|
||||
import com.ruoyi.sensitive.domain.Word;
|
||||
import com.ruoyi.sensitive.service.WordService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author binbin.hou
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@Component
|
||||
public class MyDdWordAllow implements IWordAllow {
|
||||
|
||||
@Autowired
|
||||
private WordService wordService;
|
||||
|
||||
@Override
|
||||
public List<String> allow() {
|
||||
List<Word> wordList = wordService.list(Wrappers.lambdaQuery(Word.class)
|
||||
.select(Word::getWord)
|
||||
.eq(Word::getEnableStatus,1)
|
||||
.eq(Word::getType, 1));
|
||||
return CollectionUtil.toList(wordList, new IHandler<Word, String>() {
|
||||
@Override
|
||||
public String handle(Word word) {
|
||||
return word.getWord();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.ruoyi.sensitive.config;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.github.houbb.heaven.support.handler.IHandler;
|
||||
import com.github.houbb.heaven.util.util.CollectionUtil;
|
||||
import com.github.houbb.sensitive.word.api.IWordDeny;
|
||||
import com.ruoyi.sensitive.domain.Word;
|
||||
import com.ruoyi.sensitive.service.WordService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author binbin.hou
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@Component
|
||||
public class MyDdWordDeny implements IWordDeny {
|
||||
|
||||
@Autowired
|
||||
private WordService wordService;
|
||||
|
||||
@Override
|
||||
public List<String> deny() {
|
||||
List<Word> wordList = wordService.list(Wrappers.lambdaQuery(Word.class)
|
||||
.select(Word::getWord)
|
||||
.eq(Word::getEnableStatus,1)
|
||||
.eq(Word::getType, 2));
|
||||
|
||||
return CollectionUtil.toList(wordList, new IHandler<Word, String>() {
|
||||
@Override
|
||||
public String handle(Word word) {
|
||||
return word.getWord();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.ruoyi.sensitive.config;
|
||||
|
||||
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
|
||||
import com.ruoyi.sensitive.cache.LastUpdateTimeCache;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MySensitiveWordScheduleRefresh {
|
||||
|
||||
@Autowired
|
||||
private SensitiveWordBs sensitiveWordBs;
|
||||
@Autowired
|
||||
private LastUpdateTimeCache lastUpdateTimeCache;
|
||||
|
||||
@Scheduled(fixedDelay = 20,timeUnit = TimeUnit.SECONDS)
|
||||
public void job(){
|
||||
try {
|
||||
log.info("MySensitiveWordScheduleRefresh start");
|
||||
LocalDateTime time = lastUpdateTimeCache.getTime();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
if(time == null || time.isBefore(now)){
|
||||
return;
|
||||
}
|
||||
refresh();
|
||||
log.info("MySensitiveWordScheduleRefresh end");
|
||||
} catch (Exception e) {
|
||||
log.error("MySensitiveWordScheduleRefresh meet ex", e);
|
||||
}
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
sensitiveWordBs.init();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.ruoyi.sensitive.config;
|
||||
|
||||
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
|
||||
import com.github.houbb.sensitive.word.support.allow.WordAllows;
|
||||
import com.github.houbb.sensitive.word.support.deny.WordDenys;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author binbin.hou
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@Configuration
|
||||
public class SensitiveWordConfig {
|
||||
|
||||
@Autowired
|
||||
private MyDdWordAllow myDdWordAllow;
|
||||
|
||||
@Autowired
|
||||
private MyDdWordDeny myDdWordDeny;
|
||||
|
||||
/**
|
||||
* 初始化引导类
|
||||
* @return 初始化引导类
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Bean
|
||||
public SensitiveWordBs sensitiveWordBs() {
|
||||
return SensitiveWordBs.newInstance()
|
||||
.wordAllow(WordAllows.chains(WordAllows.defaults(), myDdWordAllow))
|
||||
.wordDeny(WordDenys.chains(WordDenys.defaults(), myDdWordDeny))
|
||||
.ignoreRepeat(false)
|
||||
// 各种其他配置
|
||||
.init();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.ruoyi.sensitive.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 敏感词对象 cai_word
|
||||
*
|
||||
* @author 77
|
||||
* @date 2024-02-19
|
||||
*/
|
||||
@Data
|
||||
@TableName("cai_word")
|
||||
public class Word implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* 应用自增主键
|
||||
*/
|
||||
@TableId(value = "id")
|
||||
private Integer id;
|
||||
/**
|
||||
* 单词
|
||||
*/
|
||||
private String word;
|
||||
/**
|
||||
* 1-白名单 2-黑名单
|
||||
*/
|
||||
private Integer type;
|
||||
/**
|
||||
* 启用状态
|
||||
*/
|
||||
private Integer enableStatus;
|
||||
/**
|
||||
* 配置描述
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 操作员名称
|
||||
*/
|
||||
private String operatorId;
|
||||
|
||||
private LocalDateTime updateTime;
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.ruoyi.sensitive.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.ruoyi.sensitive.domain.Word;
|
||||
|
||||
/**
|
||||
* 敏感词Mapper接口
|
||||
*
|
||||
* @author 77
|
||||
* @date 2024-02-19
|
||||
*/
|
||||
public interface WordMapper extends BaseMapper<Word> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.ruoyi.sensitive.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.ruoyi.sensitive.domain.Word;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 敏感词Service接口
|
||||
*
|
||||
* @author 77
|
||||
* @date 2024-02-19
|
||||
*/
|
||||
public interface WordService extends IService<Word> {
|
||||
|
||||
boolean removeWordBatchByIds(List<Integer> asList);
|
||||
|
||||
boolean updateWordById(Word bo);
|
||||
|
||||
boolean saveWord(Word bo);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.ruoyi.sensitive.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.houbb.sensitive.word.support.allow.WordAllows;
|
||||
import com.ruoyi.sensitive.cache.LastUpdateTimeCache;
|
||||
import com.ruoyi.sensitive.domain.Word;
|
||||
import com.ruoyi.sensitive.mapper.WordMapper;
|
||||
import com.ruoyi.sensitive.service.WordService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 敏感词Service业务层处理
|
||||
*
|
||||
* @author 77
|
||||
* @date 2024-02-19
|
||||
*/
|
||||
@Service
|
||||
public class WordServiceImpl extends ServiceImpl<WordMapper,Word> implements WordService {
|
||||
|
||||
@Autowired
|
||||
private LastUpdateTimeCache lastUpdateTimeCache;
|
||||
|
||||
@Override
|
||||
public boolean removeWordBatchByIds(List<Integer> asList) {
|
||||
boolean re = this.removeBatchByIds(asList);
|
||||
lastUpdateTimeCache.setTime();
|
||||
return re;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateWordById(Word bo) {
|
||||
boolean re = this.updateById(bo);
|
||||
lastUpdateTimeCache.setTime();
|
||||
return re;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveWord(Word bo) {
|
||||
boolean re = this.save(bo);
|
||||
lastUpdateTimeCache.setTime();
|
||||
return re;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.sensitive.mapper.WordMapper">
|
||||
|
||||
<resultMap type="com.ruoyi.sensitive.domain.Word" id="WordResult">
|
||||
<result property="id" column="id"/>
|
||||
<result property="word" column="word"/>
|
||||
<result property="type" column="type"/>
|
||||
<result property="enableStatus" column="enable_status"/>
|
||||
<result property="remark" column="remark"/>
|
||||
<result property="operatorId" column="operator_id"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
</resultMap>
|
||||
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user