|
|
@@ -2,6 +2,7 @@ package shop.alien.store.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
@@ -45,6 +46,8 @@ public class CommonCommentServiceImpl extends ServiceImpl<CommonCommentMapper, C
|
|
|
private final StoreUserMapper storeUserMapper;
|
|
|
private final LifeUserViolationMapper lifeUserViolationMapper;
|
|
|
private final LifeUserMapper lifeUserMapper;
|
|
|
+ @Autowired
|
|
|
+ private LifeFansMapper lifeFansMapper;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -68,6 +71,8 @@ public class CommonCommentServiceImpl extends ServiceImpl<CommonCommentMapper, C
|
|
|
if ("high".equals(textCheckResult.getRiskLevel())) {
|
|
|
return 2; // 文本内容异常(包含敏感词)
|
|
|
}
|
|
|
+ // 2.审核通过,设置评价状态为已审核
|
|
|
+ commonComment.setAuditStatus(1);
|
|
|
return this.save(commonComment) ? 0 : 1;
|
|
|
} catch (Exception e) {
|
|
|
log.error("新增评论失败", e);
|
|
|
@@ -102,7 +107,8 @@ public class CommonCommentServiceImpl extends ServiceImpl<CommonCommentMapper, C
|
|
|
commentWrapper.eq("cc.source_type", CommentSourceTypeEnum.DYNAMIC_COMMENT.getType());
|
|
|
}
|
|
|
commentWrapper.eq("cc.source_id", sourceId)
|
|
|
- .eq("cc.parent_id", 0);
|
|
|
+ .eq("cc.parent_id", 0)
|
|
|
+ .eq("cc.delete_flag", CommonConstant.DELETE_FLAG_UNDELETE);
|
|
|
Page<CommonCommentVo> page = null;
|
|
|
if( null != pageNum && null != pageSize){
|
|
|
page = new Page<>(pageNum, pageSize);
|
|
|
@@ -151,6 +157,7 @@ public class CommonCommentServiceImpl extends ServiceImpl<CommonCommentMapper, C
|
|
|
QueryWrapper<CommonComment> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq(null != sourceId, "source_id", sourceId);
|
|
|
queryWrapper.eq(null != sourceType, "source_type", sourceType);
|
|
|
+ queryWrapper.eq("delete_flag", CommonConstant.DELETE_FLAG_UNDELETE);
|
|
|
//通过当前登录人id和类型 查询举报业务id 不包含已举报的
|
|
|
List<LifeUserViolation> lifeUserViolations = new ArrayList<>();
|
|
|
if(sourceType == CommentSourceTypeEnum.DYNAMIC_COMMENT.getType() ){
|
|
|
@@ -189,9 +196,73 @@ public class CommonCommentServiceImpl extends ServiceImpl<CommonCommentMapper, C
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public boolean deleteComment(Long commentId) {
|
|
|
+ if (commentId == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 首先获取要删除的评论
|
|
|
+ CommonComment comment = this.getById(commentId);
|
|
|
+ if (comment == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if(comment.getParentId() == 0){
|
|
|
+ // 获取所有子评论(包括子评论的子评论)
|
|
|
+ List<CommonCommentVo> allChildComments = getChildCommentsRecursively(commentId, null, null);
|
|
|
+
|
|
|
+ // 准备要删除的评论ID列表,包含父评论和所有子评论
|
|
|
+ List<Long> commentIdsToDelete = new ArrayList<>();
|
|
|
+ commentIdsToDelete.add(commentId); // 添加父评论ID
|
|
|
+
|
|
|
+ // 收集所有子评论的ID
|
|
|
+ for (CommonCommentVo child : allChildComments) {
|
|
|
+ commentIdsToDelete.add(child.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量更新所有相关评论的删除标志
|
|
|
+ if (!commentIdsToDelete.isEmpty()) {
|
|
|
+ UpdateWrapper<CommonComment> wrapper = new UpdateWrapper<>();
|
|
|
+ wrapper.in("id", commentIdsToDelete)
|
|
|
+ .set("delete_flag", CommonConstant.DELETE_FLAG_DELETED); // 直接设置数据库字段
|
|
|
+
|
|
|
+ boolean result = this.update(wrapper);
|
|
|
+
|
|
|
+ if (result) {
|
|
|
+ log.info("成功删除评论及其子评论,评论ID列表:{}", commentIdsToDelete);
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ log.error("删除评论失败,评论ID列表:{}", commentIdsToDelete);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 只有父评论,没有子评论的情况
|
|
|
+ UpdateWrapper<CommonComment> wrapper = new UpdateWrapper<>();
|
|
|
+ wrapper.eq("id", commentId)
|
|
|
+ .set("delete_flag", CommonConstant.DELETE_FLAG_DELETED);
|
|
|
+
|
|
|
+ boolean result = this.update(wrapper);
|
|
|
+ if (result) {
|
|
|
+ log.info("成功删除评论,评论ID:{}", commentId);
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ log.error("删除评论失败,评论ID:{}", commentId);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("删除评论时发生异常,评论ID:{}", commentId, e);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private void getOtherDataWithSourceType(Integer sourceId, Integer sourceType, String userId, Map<String, Object> map) {
|
|
|
if ( sourceType == CommentSourceTypeEnum.DYNAMIC_COMMENT.getType() ) {
|
|
|
- // 计算分析数和喜欢数
|
|
|
+ // 1.计算分析数和喜欢数
|
|
|
LifeUserDynamics lifeUserDynamics = lifeUserDynamicsMapper.selectOne(new QueryWrapper<LifeUserDynamics>().eq("id", sourceId));
|
|
|
if(null != lifeUserDynamics){
|
|
|
map.put("likeCount",lifeUserDynamics.getDianzanCount());
|
|
|
@@ -200,10 +271,10 @@ public class CommonCommentServiceImpl extends ServiceImpl<CommonCommentMapper, C
|
|
|
map.put("likeCount",0);
|
|
|
map.put("transferCount",0);
|
|
|
}
|
|
|
- // 查询商家头像 TODO -> 动态发布的时候id不应该用Store_phone的格式,来不及重构动态的位置,后续等有缘人吧
|
|
|
+ // 2.查询商家头像 TODO -> 动态发布的时候id不应该用Store_phone的格式,来不及重构动态的位置,后续等有缘人吧
|
|
|
StoreUser storeUser = storeUserMapper.selectOne(new QueryWrapper<StoreUser>().eq("phone", lifeUserDynamics.getPhoneId().split("_")[1]));
|
|
|
map.put("userImage",storeUser.getHeadImg()!= null?storeUser.getHeadImg():"");
|
|
|
- // 查询当前用户是否喜欢
|
|
|
+ // 3.查询当前用户是否喜欢
|
|
|
LifeLikeRecord lifeLikeRecord = lifeLikeRecordMapper.selectOne(new QueryWrapper<LifeLikeRecord>()
|
|
|
.eq("type", CommonConstant.LIKE_TYPE_DYNAMICS)
|
|
|
.eq("dianzan_id", userId)
|
|
|
@@ -214,6 +285,17 @@ public class CommonCommentServiceImpl extends ServiceImpl<CommonCommentMapper, C
|
|
|
} else {
|
|
|
map.put("isLike",0);
|
|
|
}
|
|
|
+ // 4.查询当前登录人是否关注了动态发布者
|
|
|
+ LifeUser lifeUser = lifeUserMapper.selectById(userId);
|
|
|
+ LifeFans lifeFans = lifeFansMapper.selectOne(new QueryWrapper<LifeFans>().eq("followed_id", lifeUserDynamics.getPhoneId())
|
|
|
+ .eq("fans_id", "user_".concat(lifeUser.getUserPhone()))
|
|
|
+ .eq("fans_type", 1)
|
|
|
+ .last("limit 1"));
|
|
|
+ if(null != lifeFans){
|
|
|
+ map.put("isFans",1);
|
|
|
+ } else {
|
|
|
+ map.put("isFans",0);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|