|
|
@@ -121,6 +121,10 @@ public class ForumPostInfoServiceImpl extends ServiceImpl<ForumPostInfoMapper, F
|
|
|
} else if (forumPostInfoPageParam.getSortOrder() == 1) {
|
|
|
queryWrapper.lambda().orderByDesc(ForumPostInfo::getViewCount);
|
|
|
}
|
|
|
+ // 置顶的优先
|
|
|
+ queryWrapper.lambda().orderByDesc(ForumPostInfo::getIsTop);
|
|
|
+ // 帖子状态 0正常
|
|
|
+ queryWrapper.lambda().eq(ForumPostInfo::getPostStatus, 0);
|
|
|
Page<ForumPostInfo> page = this.page(CommonPageRequest.defaultPage(), queryWrapper);
|
|
|
if (page.getRecords().size() > 0) {
|
|
|
for (ForumPostInfo forumPostInfo : page.getRecords()) {
|
|
|
@@ -163,7 +167,8 @@ public class ForumPostInfoServiceImpl extends ServiceImpl<ForumPostInfoMapper, F
|
|
|
SaBaseLoginUser loginUser = StpLoginUserUtil.getLoginUser();
|
|
|
forumPostInfo.setUserId(loginUser.getId());
|
|
|
// 过滤敏感词
|
|
|
- filterSensitiveWords(forumPostInfoAddParam, loginUser, uuid);
|
|
|
+ String postContent = filterSensitiveWords(forumPostInfoAddParam.getPostContent(), loginUser, uuid);
|
|
|
+ forumPostInfo.setPostContent(postContent);
|
|
|
// 存储基础表
|
|
|
this.save(forumPostInfo);
|
|
|
// 区分出是普通帖子、还是技术支持帖子、内容纠错帖子 0普通帖子 1技术支持 2内容纠错
|
|
|
@@ -192,35 +197,55 @@ public class ForumPostInfoServiceImpl extends ServiceImpl<ForumPostInfoMapper, F
|
|
|
/**
|
|
|
* 过滤发帖中的敏感词
|
|
|
*
|
|
|
- * @param forumPostInfoAddParam 帖子信息编辑参数
|
|
|
+ * @param postContent 帖子内容
|
|
|
*/
|
|
|
- public void filterSensitiveWords(ForumPostInfoAddParam forumPostInfoAddParam, SaBaseLoginUser loginUser, String uuid) {
|
|
|
+ public String filterSensitiveWords(String postContent, SaBaseLoginUser loginUser, String uuid) {
|
|
|
List<ForumSensitivity> forumSensitivities = forumSensitivityMapper.selectList(new QueryWrapper<>());
|
|
|
if (forumSensitivities.size() > 0) {
|
|
|
// 过滤敏感词
|
|
|
for (ForumSensitivity forumSensitivity : forumSensitivities) {
|
|
|
// 过滤逻辑
|
|
|
- if (forumPostInfoAddParam.getPostContent().contains(forumSensitivity.getSensitivityWord())) {
|
|
|
+ if (postContent.contains(forumSensitivity.getSensitivityWord())) {
|
|
|
// 替换句子中敏感词为*号
|
|
|
- forumPostInfoAddParam.setPostContent(forumPostInfoAddParam.getPostContent().replace(forumSensitivity.getSensitivityWord(), "******"));
|
|
|
+ postContent = postContent.replace(forumSensitivity.getSensitivityWord(), "******");
|
|
|
+ // 记录敏感词命中情况
|
|
|
+ ForumSensitivityRecord forumSensitivityRecord = new ForumSensitivityRecord();
|
|
|
+ forumSensitivityRecord.setSensitivityWord(forumSensitivity.getSensitivityWord()); // 敏感词
|
|
|
+ forumSensitivityRecord.setUserId(loginUser.getId()); // 用户id
|
|
|
+ forumSensitivityRecord.setRecordType(0); // 发帖子类型
|
|
|
+ forumSensitivityRecord.setPostId(uuid); // 帖子id
|
|
|
+ forumSensitivityRecordMapper.insert(forumSensitivityRecord);
|
|
|
}
|
|
|
- // 记录敏感词命中情况
|
|
|
- ForumSensitivityRecord forumSensitivityRecord = new ForumSensitivityRecord();
|
|
|
- forumSensitivityRecord.setSensitivityWord(forumSensitivity.getSensitivityWord()); // 敏感词
|
|
|
- forumSensitivityRecord.setUserId(loginUser.getId()); // 用户id
|
|
|
- forumSensitivityRecord.setRecordType(0); // 发帖子类型
|
|
|
- forumSensitivityRecord.setPostId(uuid); // 帖子id
|
|
|
- forumSensitivityRecordMapper.insert(forumSensitivityRecord);
|
|
|
}
|
|
|
}
|
|
|
+ return postContent;
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public void edit(ForumPostInfoEditParam forumPostInfoEditParam) {
|
|
|
+ public CommonResult<String> edit(ForumPostInfoEditParam forumPostInfoEditParam) {
|
|
|
+ SaBaseLoginUser loginUser = StpLoginUserUtil.getLoginUser();
|
|
|
+ // 首先判断帖子是否存在
|
|
|
+ ForumPostInfo dataPost = this.queryEntity(forumPostInfoEditParam.getPostId());
|
|
|
+ if (ObjectUtil.isNull(dataPost)) {
|
|
|
+ return CommonResult.error("帖子不存在");
|
|
|
+ }
|
|
|
+ // 判断帖子是否为自己的
|
|
|
+ if (!dataPost.getUserId().equals(loginUser.getId())) {
|
|
|
+ return CommonResult.error("帖子不是自己的,无法编辑");
|
|
|
+ }
|
|
|
+ // 过滤敏感词
|
|
|
+ String postContent = filterSensitiveWords(forumPostInfoEditParam.getPostContent(), loginUser, forumPostInfoEditParam.getPostId());
|
|
|
+ forumPostInfoEditParam.setPostContent(postContent);
|
|
|
+ // 更新帖子信息
|
|
|
ForumPostInfo forumPostInfo = this.queryEntity(forumPostInfoEditParam.getPostId());
|
|
|
BeanUtil.copyProperties(forumPostInfoEditParam, forumPostInfo);
|
|
|
- this.updateById(forumPostInfo);
|
|
|
+ boolean b = this.updateById(forumPostInfo);
|
|
|
+ if (!b) {
|
|
|
+ return CommonResult.error("帖子更新失败");
|
|
|
+ } else {
|
|
|
+ return CommonResult.ok();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@@ -296,4 +321,36 @@ public class ForumPostInfoServiceImpl extends ServiceImpl<ForumPostInfoMapper, F
|
|
|
return forumPostInfo;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public CommonResult<String> top(com.alibaba.fastjson.JSONObject jsonObject) {
|
|
|
+ // 取出字段
|
|
|
+ String postId = jsonObject.getString("postId");
|
|
|
+ Integer isTop = jsonObject.getInteger("isTop");
|
|
|
+ // 更新帖子信息
|
|
|
+ ForumPostInfo forumPostInfo = this.queryEntity(postId);
|
|
|
+ forumPostInfo.setIsTop(isTop);
|
|
|
+ boolean b = this.updateById(forumPostInfo);
|
|
|
+ if (!b) {
|
|
|
+ return CommonResult.error("帖子置顶失败");
|
|
|
+ } else {
|
|
|
+ return CommonResult.ok();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResult<String> close(com.alibaba.fastjson.JSONObject jsonObject) {
|
|
|
+ // 取出字段
|
|
|
+ String postId = jsonObject.getString("postId");
|
|
|
+ Integer postStatus = jsonObject.getInteger("postStatus");
|
|
|
+ // 更新帖子信息
|
|
|
+ ForumPostInfo forumPostInfo = this.queryEntity(postId);
|
|
|
+ forumPostInfo.setPostStatus(postStatus);
|
|
|
+ boolean b = this.updateById(forumPostInfo);
|
|
|
+ if (!b) {
|
|
|
+ return CommonResult.error();
|
|
|
+ } else {
|
|
|
+ return CommonResult.ok();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|