Commit f040f118 authored by 刘基明's avatar 刘基明

文本查重

parent 4ff6e293
......@@ -209,16 +209,16 @@ public class ThemeManager {
// 校验参数
checkAttachment(req.getContent());
// 文本查重
if (themeTextCheckService.checkDuplicate(ConvertUtil.convertThemeText(JsonUtil.toJson(req.getContent())))) {
return CommonResp.error(ErrorCodeConstant.THEME_TEXT_DUPLICATE.getCode(),ErrorCodeConstant.THEME_TEXT_DUPLICATE.getMsg());
}
// 保存主题表
ThemeEntity themeEntity = new ThemeEntity();
BeanUtils.copyProperties(req, themeEntity);
themeEntity.setAuthorId(userId);
// 文本查重
if (themeTextCheckService.checkDuplicate(ConvertUtil.convert(themeEntity).getTextContent())) {
throw new BizException("圈子里已存在相似内容,请勿重复发布");
}
// 腾讯云敏感词校验
checkContent(req);
themeEntity.setContent(JsonUtil.toJson(req.getContent()));
......
......@@ -49,6 +49,9 @@ public class ThemeTextCheckService {
}
public boolean checkDuplicate(String content) {
if (content.length()<15){
return false;
}
content = content.replaceAll("[,。!? ]", "。");
String[] split = content.split("。");
List<String> list = new ArrayList<>();
......
......@@ -71,6 +71,20 @@ public class ConvertUtil {
return themeEntities.stream().map(ConvertUtil::themeEntityToQo).collect(Collectors.toList());
}
// 抽取文本内容
public static String convertThemeText(String content) {
List<ThemeContentQo> themeContentQos = JsonUtil.toBean(content, new TypeReference<List<ThemeContentQo>>() {
});
StringBuilder sb = new StringBuilder();
themeContentQos.stream().filter(q -> RelTypeEnum.TEXT.type.equals(q.getType())).forEach(q -> {
sb.append(q.getValue());
});
return sb.toString();
}
public static ESThemeQo convert(ThemeEntity entity) {
ESThemeQo qo = new ESThemeQo();
BeanUtils.copyProperties(entity, qo);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment