敏感词删除
This commit is contained in:
@@ -283,6 +283,19 @@ public class RedisService {
|
|||||||
return redisTemplate.opsForSet().members(key);
|
return redisTemplate.opsForSet().members(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 判断Set中是否存在指定元素
|
||||||
|
* @param key String 键
|
||||||
|
* @param value Object 元素
|
||||||
|
* @return boolean 是否存在
|
||||||
|
* @author yslg
|
||||||
|
* @since 2025-12-18
|
||||||
|
*/
|
||||||
|
public boolean sIsMember(String key, Object value) {
|
||||||
|
Boolean result = redisTemplate.opsForSet().isMember(key, value);
|
||||||
|
return result != null && result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 获取Set集合大小(等价于Redis的SCARD)
|
* @description 获取Set集合大小(等价于Redis的SCARD)
|
||||||
* @param key String 键
|
* @param key String 键
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class SensitiveServiceImpl implements SensitiveService{
|
|||||||
|
|
||||||
// 第一次检查:Redis中是否已存在
|
// 第一次检查:Redis中是否已存在
|
||||||
String redisKey = "allow".equals(type) ? SensitiveRedisContants.SENSITIVE_WORD_ALLOW : SensitiveRedisContants.SENSITIVE_WORD_DENY;
|
String redisKey = "allow".equals(type) ? SensitiveRedisContants.SENSITIVE_WORD_ALLOW : SensitiveRedisContants.SENSITIVE_WORD_DENY;
|
||||||
if (redisService.sMembers(redisKey).contains(word)) {
|
if (redisService.sIsMember(redisKey, word)) {
|
||||||
resultDomain.fail("敏感词已存在");
|
resultDomain.fail("敏感词已存在");
|
||||||
return resultDomain;
|
return resultDomain;
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ public class SensitiveServiceImpl implements SensitiveService{
|
|||||||
// 加锁
|
// 加锁
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
// 第二次检查:再次确认Redis中是否已存在
|
// 第二次检查:再次确认Redis中是否已存在
|
||||||
if (redisService.sMembers(redisKey).contains(word)) {
|
if (redisService.sIsMember(redisKey, word)) {
|
||||||
resultDomain.fail("敏感词已存在");
|
resultDomain.fail("敏感词已存在");
|
||||||
return resultDomain;
|
return resultDomain;
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,7 @@ public class SensitiveServiceImpl implements SensitiveService{
|
|||||||
String targetRedisKey = "allow".equals(newType) ? SensitiveRedisContants.SENSITIVE_WORD_ALLOW : SensitiveRedisContants.SENSITIVE_WORD_DENY;
|
String targetRedisKey = "allow".equals(newType) ? SensitiveRedisContants.SENSITIVE_WORD_ALLOW : SensitiveRedisContants.SENSITIVE_WORD_DENY;
|
||||||
|
|
||||||
// 检查目标类型中是否已存在该词
|
// 检查目标类型中是否已存在该词
|
||||||
if (redisService.sMembers(targetRedisKey).contains(word)) {
|
if (redisService.sIsMember(targetRedisKey, word)) {
|
||||||
resultDomain.fail("该敏感词在目标类型中已存在");
|
resultDomain.fail("该敏感词在目标类型中已存在");
|
||||||
return resultDomain;
|
return resultDomain;
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ public class SensitiveServiceImpl implements SensitiveService{
|
|||||||
// 加锁
|
// 加锁
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
// 再次检查
|
// 再次检查
|
||||||
if (redisService.sMembers(targetRedisKey).contains(word)) {
|
if (redisService.sIsMember(targetRedisKey, word)) {
|
||||||
resultDomain.fail("该敏感词在目标类型中已存在");
|
resultDomain.fail("该敏感词在目标类型中已存在");
|
||||||
return resultDomain;
|
return resultDomain;
|
||||||
}
|
}
|
||||||
@@ -117,7 +117,7 @@ public class SensitiveServiceImpl implements SensitiveService{
|
|||||||
|
|
||||||
// 第一次检查:Redis中是否存在
|
// 第一次检查:Redis中是否存在
|
||||||
String redisKey = "allow".equals(type) ? SensitiveRedisContants.SENSITIVE_WORD_ALLOW : SensitiveRedisContants.SENSITIVE_WORD_DENY;
|
String redisKey = "allow".equals(type) ? SensitiveRedisContants.SENSITIVE_WORD_ALLOW : SensitiveRedisContants.SENSITIVE_WORD_DENY;
|
||||||
if (!redisService.sMembers(redisKey).contains(word)) {
|
if (!redisService.sIsMember(redisKey, word)) {
|
||||||
resultDomain.fail("敏感词不存在");
|
resultDomain.fail("敏感词不存在");
|
||||||
return resultDomain;
|
return resultDomain;
|
||||||
}
|
}
|
||||||
@@ -125,7 +125,7 @@ public class SensitiveServiceImpl implements SensitiveService{
|
|||||||
// 加锁
|
// 加锁
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
// 第二次检查:再次确认Redis中是否存在
|
// 第二次检查:再次确认Redis中是否存在
|
||||||
if (!redisService.sMembers(redisKey).contains(word)) {
|
if (!redisService.sIsMember(redisKey, word)) {
|
||||||
resultDomain.fail("敏感词不存在");
|
resultDomain.fail("敏感词不存在");
|
||||||
return resultDomain;
|
return resultDomain;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class DynamicAllowWord implements IWordAllow {
|
|||||||
List<String> list = new ArrayList<>(members.size());
|
List<String> list = new ArrayList<>(members.size());
|
||||||
for (Object o : members) {
|
for (Object o : members) {
|
||||||
if (o != null) {
|
if (o != null) {
|
||||||
list.add(String.valueOf(o));
|
list.add(o.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class DynamicDenyWord implements IWordDeny {
|
|||||||
List<String> list = new ArrayList<>(members.size());
|
List<String> list = new ArrayList<>(members.size());
|
||||||
for (Object o : members) {
|
for (Object o : members) {
|
||||||
if (o != null) {
|
if (o != null) {
|
||||||
list.add(String.valueOf(o));
|
list.add(o.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export const sensitiveApi = {
|
|||||||
* @returns Promise<ResultDomain<boolean>>
|
* @returns Promise<ResultDomain<boolean>>
|
||||||
*/
|
*/
|
||||||
async deleteSensitiveWord(sensitiveWord: SensitiveWord): Promise<ResultDomain<boolean>> {
|
async deleteSensitiveWord(sensitiveWord: SensitiveWord): Promise<ResultDomain<boolean>> {
|
||||||
const response = await api.delete<boolean>(`/sensitive`, { data: sensitiveWord });
|
const response = await api.delete<boolean>(`/sensitive`, sensitiveWord);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user