123333
This commit is contained in:
@@ -3,6 +3,7 @@ package com.ruoyi.web.controller.sensitive;
|
|||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
|
||||||
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.annotation.Log;
|
||||||
import com.ruoyi.common.annotation.RepeatSubmit;
|
import com.ruoyi.common.annotation.RepeatSubmit;
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
@@ -13,15 +14,21 @@ import com.ruoyi.common.core.validate.AddGroup;
|
|||||||
import com.ruoyi.common.core.validate.EditGroup;
|
import com.ruoyi.common.core.validate.EditGroup;
|
||||||
import com.ruoyi.common.enums.BusinessType;
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
|
import com.ruoyi.sensitive.cache.LastUpdateTimeCache;
|
||||||
import com.ruoyi.sensitive.domain.Word;
|
import com.ruoyi.sensitive.domain.Word;
|
||||||
|
import com.ruoyi.sensitive.dto.SensitiveConfig;
|
||||||
|
import com.ruoyi.sensitive.dto.WordTestResp;
|
||||||
|
import com.ruoyi.sensitive.service.SensitiveWordManager;
|
||||||
import com.ruoyi.sensitive.service.WordService;
|
import com.ruoyi.sensitive.service.WordService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -38,6 +45,30 @@ import java.util.List;
|
|||||||
public class WordController extends BaseController {
|
public class WordController extends BaseController {
|
||||||
|
|
||||||
private final WordService wordService;
|
private final WordService wordService;
|
||||||
|
@Autowired
|
||||||
|
private SensitiveWordBs sensitiveWordBs;
|
||||||
|
@Autowired
|
||||||
|
private LastUpdateTimeCache cache;
|
||||||
|
@Autowired
|
||||||
|
private SensitiveWordManager sensitiveWordManager;
|
||||||
|
|
||||||
|
@PostMapping("/updateSensitiveConfig")
|
||||||
|
public R<Void> updateSensitiveConfig(@RequestBody SensitiveConfig sensitiveConfig){
|
||||||
|
sensitiveWordManager.updateSensitiveConfig(sensitiveConfig);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/getSensitiveConfig")
|
||||||
|
public R<SensitiveConfig> getSensitiveConfig(){
|
||||||
|
return R.ok(sensitiveWordManager.getSensitiveConfig());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/lastRefresh")
|
||||||
|
public R<LocalDateTime> lastRefresh() {
|
||||||
|
LocalDateTime time = cache.getRefreshTime();
|
||||||
|
return R.ok(time);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询敏感词列表
|
* 查询敏感词列表
|
||||||
@@ -106,4 +137,19 @@ public class WordController extends BaseController {
|
|||||||
@PathVariable Integer[] ids) {
|
@PathVariable Integer[] ids) {
|
||||||
return toAjax(wordService.removeWordBatchByIds(Arrays.asList(ids)));
|
return toAjax(wordService.removeWordBatchByIds(Arrays.asList(ids)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Log(title = "刷新敏感词", businessType = BusinessType.OTHER)
|
||||||
|
@GetMapping("/refresh")
|
||||||
|
public R<Void> refresh() {
|
||||||
|
sensitiveWordBs.init();
|
||||||
|
cache.setRefreshTime();
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/test")
|
||||||
|
public R<WordTestResp> test(@RequestBody Word word) {
|
||||||
|
return R.ok(sensitiveWordManager.test(word.getWord()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,10 @@
|
|||||||
<artifactId>IJPay-AliPay</artifactId>
|
<artifactId>IJPay-AliPay</artifactId>
|
||||||
<version>${ijapy.version}</version>
|
<version>${ijapy.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-sensitive-word</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.aliyun</groupId>
|
<groupId>com.aliyun</groupId>
|
||||||
<artifactId>aliyun-java-sdk-core</artifactId>
|
<artifactId>aliyun-java-sdk-core</artifactId>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.ruoyi.cai.domain;
|
package com.ruoyi.cai.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -22,7 +23,7 @@ public class UserChatFilter implements Serializable {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@TableId(value = "id")
|
@TableId(value = "id",type = IdType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.ruoyi.cai.manager;
|
|||||||
import cn.hutool.core.lang.UUID;
|
import cn.hutool.core.lang.UUID;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
|
||||||
import com.ruoyi.cai.domain.Account;
|
import com.ruoyi.cai.domain.Account;
|
||||||
import com.ruoyi.cai.domain.User;
|
import com.ruoyi.cai.domain.User;
|
||||||
import com.ruoyi.cai.domain.UserChatRecord;
|
import com.ruoyi.cai.domain.UserChatRecord;
|
||||||
@@ -52,6 +53,10 @@ public class ImService {
|
|||||||
private AmqpProducer amqpProducer;
|
private AmqpProducer amqpProducer;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysOssService sysOssService;
|
private ISysOssService sysOssService;
|
||||||
|
@Autowired
|
||||||
|
private SensitiveWordBs sensitiveWordBs;
|
||||||
|
@Autowired
|
||||||
|
private UserChatFilterService userChatFilterService;
|
||||||
|
|
||||||
public ImResp sendMessage(Long fromUserId, ImMessageDTO message) {
|
public ImResp sendMessage(Long fromUserId, ImMessageDTO message) {
|
||||||
ChatTypeEnum typeEnum = ChatTypeEnum.getByType(message.getType());
|
ChatTypeEnum typeEnum = ChatTypeEnum.getByType(message.getType());
|
||||||
@@ -129,15 +134,21 @@ public class ImService {
|
|||||||
if (fromUser.getIsAnchor().equals(0) && toUser.getIsAnchor().equals(0)) {
|
if (fromUser.getIsAnchor().equals(0) && toUser.getIsAnchor().equals(0)) {
|
||||||
throw new ServiceException("目前只能和女神私信!");
|
throw new ServiceException("目前只能和女神私信!");
|
||||||
}
|
}
|
||||||
|
int filter = 0;
|
||||||
|
String content = message.getContent();
|
||||||
// 正则判断违规数据替换
|
// 正则判断违规数据替换
|
||||||
if(typeEnum == ChatTypeEnum.MESSAGE){
|
if(typeEnum == ChatTypeEnum.MESSAGE){
|
||||||
|
boolean contains = sensitiveWordBs.contains(message.getContent());
|
||||||
|
if(contains){
|
||||||
|
filter = 1;
|
||||||
|
content = sensitiveWordBs.replace(message.getContent());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(fromUser.getIsAnchor().equals(1)){ // 女神发消息不要钱
|
if(fromUser.getIsAnchor().equals(1)){ // 女神发消息不要钱
|
||||||
Account account = accountService.getByUserId(fromUserId);
|
Account account = accountService.getByUserId(fromUserId);
|
||||||
ImResp resp = new ImResp();
|
ImResp resp = new ImResp();
|
||||||
resp.setCoin(account.getCoin()+ account.getIncomeCoin());
|
resp.setCoin(account.getCoin()+ account.getIncomeCoin());
|
||||||
resp.setContent(message.getContent());
|
resp.setContent(content);
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
// 判断VIP获取价格
|
// 判断VIP获取价格
|
||||||
@@ -150,15 +161,21 @@ public class ImService {
|
|||||||
// 存储聊天记录
|
// 存储聊天记录
|
||||||
Account account = accountService.getByUserId(fromUserId);
|
Account account = accountService.getByUserId(fromUserId);
|
||||||
UserChatRecord record = userChatRecordService.saveRecord(fromUser, toUser, traceId, message);
|
UserChatRecord record = userChatRecordService.saveRecord(fromUser, toUser, traceId, message);
|
||||||
|
if(filter == 1){
|
||||||
|
userChatFilterService.saveFilter(fromUser, toUser, content);
|
||||||
|
}
|
||||||
ImResp resp = new ImResp();
|
ImResp resp = new ImResp();
|
||||||
resp.setCut(imPrice > 0);
|
resp.setCut(imPrice > 0);
|
||||||
resp.setCutCoin(imPrice);
|
resp.setCutCoin(imPrice);
|
||||||
resp.setCoin(account.getCoin()+ account.getIncomeCoin());
|
resp.setCoin(account.getCoin()+ account.getIncomeCoin());
|
||||||
resp.setRecordId(record.getId());
|
resp.setRecordId(record.getId());
|
||||||
resp.setContent(message.getContent());
|
resp.setFilter(filter);
|
||||||
|
resp.setContent(content);
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Long getByImPrice(Long userId){
|
private Long getByImPrice(Long userId){
|
||||||
UserMemberTypeEnum userMemberType = userMemberService.checkUserIsMember(userId);
|
UserMemberTypeEnum userMemberType = userMemberService.checkUserIsMember(userId);
|
||||||
if(userMemberType == null){
|
if(userMemberType == null){
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.ruoyi.cai.service;
|
package com.ruoyi.cai.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.ruoyi.cai.domain.User;
|
||||||
import com.ruoyi.cai.domain.UserChatFilter;
|
import com.ruoyi.cai.domain.UserChatFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -11,4 +12,5 @@ import com.ruoyi.cai.domain.UserChatFilter;
|
|||||||
*/
|
*/
|
||||||
public interface UserChatFilterService extends IService<UserChatFilter> {
|
public interface UserChatFilterService extends IService<UserChatFilter> {
|
||||||
|
|
||||||
|
void saveFilter(User fromUser, User toUser, String content);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.ruoyi.cai.service.impl;
|
package com.ruoyi.cai.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.ruoyi.cai.domain.User;
|
||||||
import com.ruoyi.cai.domain.UserChatFilter;
|
import com.ruoyi.cai.domain.UserChatFilter;
|
||||||
import com.ruoyi.cai.mapper.UserChatFilterMapper;
|
import com.ruoyi.cai.mapper.UserChatFilterMapper;
|
||||||
import com.ruoyi.cai.service.UserChatFilterService;
|
import com.ruoyi.cai.service.UserChatFilterService;
|
||||||
@@ -14,4 +15,12 @@ import org.springframework.stereotype.Service;
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class UserChatFilterServiceImpl extends ServiceImpl<UserChatFilterMapper,UserChatFilter> implements UserChatFilterService {
|
public class UserChatFilterServiceImpl extends ServiceImpl<UserChatFilterMapper,UserChatFilter> implements UserChatFilterService {
|
||||||
|
@Override
|
||||||
|
public void saveFilter(User fromUser, User toUser, String content) {
|
||||||
|
UserChatFilter chatFilter = new UserChatFilter();
|
||||||
|
chatFilter.setFromUid(fromUser.getId());
|
||||||
|
chatFilter.setToUid(toUser.getId());
|
||||||
|
chatFilter.setContent(content);
|
||||||
|
this.save(chatFilter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,54 @@
|
|||||||
package com.ruoyi.sensitive.cache;
|
package com.ruoyi.sensitive.cache;
|
||||||
|
|
||||||
|
import com.ruoyi.common.constant.DateConstant;
|
||||||
import org.redisson.api.RBucket;
|
import org.redisson.api.RBucket;
|
||||||
import org.redisson.api.RedissonClient;
|
import org.redisson.api.RedissonClient;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class LastUpdateTimeCache {
|
public class LastUpdateTimeCache {
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedissonClient redissonClient;
|
private RedissonClient redissonClient;
|
||||||
private String getKey(){
|
private String getKey(){
|
||||||
return "sensitive-lastRefreshTime";
|
return "sensitive-lastUpdateTime";
|
||||||
}
|
|
||||||
public LocalDateTime getTime(){
|
|
||||||
String key = getKey();
|
|
||||||
RBucket<LocalDateTime> bucket = redissonClient.getBucket(key);
|
|
||||||
return bucket.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTime(){
|
private String getRefreshKey(){
|
||||||
|
return "sensitive-lastRefreshTime";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRefreshTime(){
|
||||||
|
String key = getRefreshKey();
|
||||||
|
RBucket<LocalDateTime> bucket = redissonClient.getBucket(key);
|
||||||
|
bucket.set(LocalDateTime.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getRefreshTime(){
|
||||||
|
String key = getRefreshKey();
|
||||||
|
RBucket<String> bucket = redissonClient.getBucket(key);
|
||||||
|
String s = bucket.get();
|
||||||
|
if(s == null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return LocalDateTime.parse(s, DateTimeFormatter.ofPattern(DateConstant.PATTERN_DATETIME));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public LocalDateTime getUpdateTime(){
|
||||||
|
String key = getKey();
|
||||||
|
RBucket<String> bucket = redissonClient.getBucket(key);
|
||||||
|
String s = bucket.get();
|
||||||
|
if(s == null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return LocalDateTime.parse(s, DateTimeFormatter.ofPattern(DateConstant.PATTERN_DATETIME));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdateTime(){
|
||||||
String key = getKey();
|
String key = getKey();
|
||||||
RBucket<LocalDateTime> bucket = redissonClient.getBucket(key);
|
RBucket<LocalDateTime> bucket = redissonClient.getBucket(key);
|
||||||
bucket.set(LocalDateTime.now());
|
bucket.set(LocalDateTime.now());
|
||||||
|
|||||||
28
ruoyi-sensitive-word/src/main/java/com/ruoyi/sensitive/cache/SensitiveWordConfigCache.java
vendored
Normal file
28
ruoyi-sensitive-word/src/main/java/com/ruoyi/sensitive/cache/SensitiveWordConfigCache.java
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package com.ruoyi.sensitive.cache;
|
||||||
|
|
||||||
|
import com.ruoyi.sensitive.dto.SensitiveConfig;
|
||||||
|
import org.redisson.api.RBucket;
|
||||||
|
import org.redisson.api.RedissonClient;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class SensitiveWordConfigCache {
|
||||||
|
@Autowired
|
||||||
|
private RedissonClient redissonClient;
|
||||||
|
private String getKey(){
|
||||||
|
return "sensitive-config";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConfig(SensitiveConfig config){
|
||||||
|
String key = getKey();
|
||||||
|
RBucket<SensitiveConfig> bucket = redissonClient.getBucket(key);
|
||||||
|
bucket.set(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SensitiveConfig getConfig(){
|
||||||
|
String key = getKey();
|
||||||
|
RBucket<SensitiveConfig> bucket = redissonClient.getBucket(key);
|
||||||
|
return bucket.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,19 +18,17 @@ public class MySensitiveWordScheduleRefresh {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SensitiveWordBs sensitiveWordBs;
|
private SensitiveWordBs sensitiveWordBs;
|
||||||
@Autowired
|
@Autowired
|
||||||
private LastUpdateTimeCache lastUpdateTimeCache;
|
private LastUpdateTimeCache cache;
|
||||||
|
|
||||||
@Scheduled(fixedDelay = 20,timeUnit = TimeUnit.SECONDS)
|
@Scheduled(fixedDelay = 20,timeUnit = TimeUnit.SECONDS)
|
||||||
public void job(){
|
public void job(){
|
||||||
try {
|
try {
|
||||||
log.info("MySensitiveWordScheduleRefresh start");
|
LocalDateTime time = cache.getUpdateTime();
|
||||||
LocalDateTime time = lastUpdateTimeCache.getTime();
|
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
if(time == null || time.isBefore(now)){
|
if(time == null || time.isBefore(now)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
refresh();
|
refresh();
|
||||||
log.info("MySensitiveWordScheduleRefresh end");
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("MySensitiveWordScheduleRefresh meet ex", e);
|
log.error("MySensitiveWordScheduleRefresh meet ex", e);
|
||||||
}
|
}
|
||||||
@@ -42,6 +40,7 @@ public class MySensitiveWordScheduleRefresh {
|
|||||||
|
|
||||||
private void refresh() {
|
private void refresh() {
|
||||||
sensitiveWordBs.init();
|
sensitiveWordBs.init();
|
||||||
|
cache.setRefreshTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.ruoyi.sensitive.config;
|
|||||||
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
|
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
|
||||||
import com.github.houbb.sensitive.word.support.allow.WordAllows;
|
import com.github.houbb.sensitive.word.support.allow.WordAllows;
|
||||||
import com.github.houbb.sensitive.word.support.deny.WordDenys;
|
import com.github.houbb.sensitive.word.support.deny.WordDenys;
|
||||||
|
import com.ruoyi.sensitive.cache.SensitiveWordConfigCache;
|
||||||
|
import com.ruoyi.sensitive.dto.SensitiveConfig;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -19,6 +21,8 @@ public class SensitiveWordConfig {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MyDdWordDeny myDdWordDeny;
|
private MyDdWordDeny myDdWordDeny;
|
||||||
|
@Autowired
|
||||||
|
private SensitiveWordConfigCache sensitiveWordConfigCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化引导类
|
* 初始化引导类
|
||||||
@@ -27,11 +31,25 @@ public class SensitiveWordConfig {
|
|||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public SensitiveWordBs sensitiveWordBs() {
|
public SensitiveWordBs sensitiveWordBs() {
|
||||||
|
SensitiveConfig sensitiveConfig = sensitiveWordConfigCache.getConfig();
|
||||||
|
if(sensitiveConfig == null){
|
||||||
|
sensitiveConfig = new SensitiveConfig();
|
||||||
|
}
|
||||||
return SensitiveWordBs.newInstance()
|
return SensitiveWordBs.newInstance()
|
||||||
.wordAllow(WordAllows.chains(WordAllows.defaults(), myDdWordAllow))
|
.wordAllow(WordAllows.chains(WordAllows.defaults(), myDdWordAllow))
|
||||||
.wordDeny(WordDenys.chains(WordDenys.defaults(), myDdWordDeny))
|
.wordDeny(WordDenys.chains(WordDenys.defaults(), myDdWordDeny))
|
||||||
.ignoreRepeat(false)
|
|
||||||
// 各种其他配置
|
// 各种其他配置
|
||||||
|
.ignoreCase(sensitiveConfig.isIgnoreCase())
|
||||||
|
.ignoreWidth(sensitiveConfig.isIgnoreWidth())
|
||||||
|
.ignoreNumStyle(sensitiveConfig.isIgnoreNumStyle())
|
||||||
|
.ignoreChineseStyle(sensitiveConfig.isIgnoreChineseStyle())
|
||||||
|
.ignoreEnglishStyle(sensitiveConfig.isIgnoreEnglishStyle())
|
||||||
|
.ignoreRepeat(sensitiveConfig.isIgnoreRepeat())
|
||||||
|
.enableNumCheck(sensitiveConfig.isEnableNumCheck())
|
||||||
|
.enableEmailCheck(sensitiveConfig.isEnableEmailCheck())
|
||||||
|
.enableUrlCheck(sensitiveConfig.isEnableUrlCheck())
|
||||||
|
.enableWordCheck(sensitiveConfig.isEnableWordCheck())
|
||||||
|
.numCheckLen(sensitiveConfig.getNumCheckLen())
|
||||||
.init();
|
.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package com.ruoyi.sensitive.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SensitiveConfig {
|
||||||
|
/**
|
||||||
|
* 是否忽略大小写
|
||||||
|
*/
|
||||||
|
private boolean ignoreCase = true;
|
||||||
|
/**
|
||||||
|
* 是否忽略全角、半角
|
||||||
|
*/
|
||||||
|
private boolean ignoreWidth = true;
|
||||||
|
/**
|
||||||
|
* 是否忽略数字样式
|
||||||
|
*/
|
||||||
|
private boolean ignoreNumStyle = true;
|
||||||
|
/**
|
||||||
|
* 是否忽略中文样式
|
||||||
|
*/
|
||||||
|
private boolean ignoreChineseStyle = true;
|
||||||
|
/**
|
||||||
|
* 是否忽略英文样式
|
||||||
|
*/
|
||||||
|
private boolean ignoreEnglishStyle = true;
|
||||||
|
/**
|
||||||
|
* 是否忽略重复
|
||||||
|
*/
|
||||||
|
private boolean ignoreRepeat = false;
|
||||||
|
|
||||||
|
// 开启校验
|
||||||
|
/**
|
||||||
|
* 启用数字检测
|
||||||
|
*/
|
||||||
|
private boolean enableNumCheck = true;
|
||||||
|
/**
|
||||||
|
* 启用邮箱检测
|
||||||
|
*/
|
||||||
|
private boolean enableEmailCheck = true;
|
||||||
|
/**
|
||||||
|
* 启用 URL 检测
|
||||||
|
*/
|
||||||
|
private boolean enableUrlCheck = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单词校验
|
||||||
|
* @since 0.4.0
|
||||||
|
*/
|
||||||
|
private boolean enableWordCheck = true;
|
||||||
|
|
||||||
|
// 额外配置
|
||||||
|
/**
|
||||||
|
* 检测数字时的长度
|
||||||
|
*/
|
||||||
|
private int numCheckLen = 8;
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.ruoyi.sensitive.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class WordTestResp {
|
||||||
|
private String sourceText;
|
||||||
|
private String targetText;
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.ruoyi.sensitive.service;
|
||||||
|
|
||||||
|
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
|
||||||
|
import com.ruoyi.sensitive.cache.SensitiveWordConfigCache;
|
||||||
|
import com.ruoyi.sensitive.dto.SensitiveConfig;
|
||||||
|
import com.ruoyi.sensitive.dto.WordTestResp;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class SensitiveWordManager {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SensitiveWordBs sensitiveWordBs;
|
||||||
|
@Autowired
|
||||||
|
private SensitiveWordConfigCache sensitiveWordConfigCache;
|
||||||
|
|
||||||
|
public WordTestResp test(String text) {
|
||||||
|
String results = sensitiveWordBs.replace(text);
|
||||||
|
WordTestResp wordTestResp = new WordTestResp();
|
||||||
|
wordTestResp.setSourceText(text);
|
||||||
|
wordTestResp.setTargetText(results);
|
||||||
|
return wordTestResp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateSensitiveConfig(SensitiveConfig sensitiveConfig) {
|
||||||
|
sensitiveWordBs
|
||||||
|
.ignoreCase(sensitiveConfig.isIgnoreCase())
|
||||||
|
.ignoreWidth(sensitiveConfig.isIgnoreWidth())
|
||||||
|
.ignoreNumStyle(sensitiveConfig.isIgnoreNumStyle())
|
||||||
|
.ignoreChineseStyle(sensitiveConfig.isIgnoreChineseStyle())
|
||||||
|
.ignoreEnglishStyle(sensitiveConfig.isIgnoreEnglishStyle())
|
||||||
|
.ignoreRepeat(sensitiveConfig.isIgnoreRepeat())
|
||||||
|
.enableNumCheck(sensitiveConfig.isEnableNumCheck())
|
||||||
|
.enableEmailCheck(sensitiveConfig.isEnableEmailCheck())
|
||||||
|
.enableUrlCheck(sensitiveConfig.isEnableUrlCheck())
|
||||||
|
.enableWordCheck(sensitiveConfig.isEnableWordCheck())
|
||||||
|
.numCheckLen(sensitiveConfig.getNumCheckLen())
|
||||||
|
.init();
|
||||||
|
sensitiveWordConfigCache.setConfig(sensitiveConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SensitiveConfig getSensitiveConfig(){
|
||||||
|
return sensitiveWordConfigCache.getConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.ruoyi.sensitive.service.impl;
|
package com.ruoyi.sensitive.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
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.cache.LastUpdateTimeCache;
|
||||||
import com.ruoyi.sensitive.domain.Word;
|
import com.ruoyi.sensitive.domain.Word;
|
||||||
import com.ruoyi.sensitive.mapper.WordMapper;
|
import com.ruoyi.sensitive.mapper.WordMapper;
|
||||||
@@ -26,21 +25,21 @@ public class WordServiceImpl extends ServiceImpl<WordMapper,Word> implements Wor
|
|||||||
@Override
|
@Override
|
||||||
public boolean removeWordBatchByIds(List<Integer> asList) {
|
public boolean removeWordBatchByIds(List<Integer> asList) {
|
||||||
boolean re = this.removeBatchByIds(asList);
|
boolean re = this.removeBatchByIds(asList);
|
||||||
lastUpdateTimeCache.setTime();
|
lastUpdateTimeCache.setUpdateTime();
|
||||||
return re;
|
return re;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateWordById(Word bo) {
|
public boolean updateWordById(Word bo) {
|
||||||
boolean re = this.updateById(bo);
|
boolean re = this.updateById(bo);
|
||||||
lastUpdateTimeCache.setTime();
|
lastUpdateTimeCache.setUpdateTime();
|
||||||
return re;
|
return re;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean saveWord(Word bo) {
|
public boolean saveWord(Word bo) {
|
||||||
boolean re = this.save(bo);
|
boolean re = this.save(bo);
|
||||||
lastUpdateTimeCache.setTime();
|
lastUpdateTimeCache.setUpdateTime();
|
||||||
return re;
|
return re;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user