feat(resource): 添加获取评论数量,增加排序
parent
570c7bb656
commit
dd16eb0106
|
@ -2,7 +2,6 @@ package com.mcwl.web.controller.resource;
|
|||
|
||||
import com.mcwl.common.annotation.RepeatSubmit;
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.resource.domain.ModelComment;
|
||||
import com.mcwl.resource.domain.dto.ModelCommentRes;
|
||||
import com.mcwl.resource.domain.vo.ModelCommentVo;
|
||||
import com.mcwl.resource.service.ModelCommentLikeService;
|
||||
|
@ -10,6 +9,7 @@ import com.mcwl.resource.service.ModelCommentService;
|
|||
import com.mcwl.resource.service.ModelLikeService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
@ -17,7 +17,9 @@ import javax.validation.Valid;
|
|||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**模型评论
|
||||
/**
|
||||
* 模型评论
|
||||
*
|
||||
* @Author:ChenYan
|
||||
* @Project:McWl
|
||||
* @Package:com.mcwl.web.controller.resource
|
||||
|
@ -38,14 +40,16 @@ public class ModelCommentController {
|
|||
private ModelCommentLikeService modelCommentLikeService;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 模型点赞/取消
|
||||
*/
|
||||
@ApiOperation(value = "模型点赞/取消")
|
||||
@RepeatSubmit
|
||||
@GetMapping("/modelLike")
|
||||
public AjaxResult like(@Valid @NotNull(message = "模型id不能为空") Long modelId) {
|
||||
public AjaxResult like(@Valid
|
||||
@NotNull(message = "模型id不能为空")
|
||||
@ApiParam(value = "模型id", required = true)
|
||||
Long modelId) {
|
||||
modelLikeService.like(modelId);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
@ -67,20 +71,28 @@ public class ModelCommentController {
|
|||
@ApiOperation(value = "模型评论点赞/取消")
|
||||
@RepeatSubmit
|
||||
@GetMapping("/commentLike")
|
||||
public AjaxResult commentLike(@Valid @NotNull(message = "评论id不能为空") Long commentId) {
|
||||
public AjaxResult commentLike(@Valid
|
||||
@NotNull(message = "评论id不能为空")
|
||||
@ApiParam(value = "评论id", required = true)
|
||||
Long commentId) {
|
||||
modelCommentLikeService.like(commentId);
|
||||
return AjaxResult.error();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取模型评论
|
||||
*/
|
||||
@ApiOperation(value = "获取模型评论")
|
||||
@GetMapping("/comment")
|
||||
public AjaxResult getComment(@Valid @NotNull(message = "模型id不能为空") Long modelId) {
|
||||
List<ModelCommentVo> modelCommentList = modelCommentService.getComment(modelId);
|
||||
@Valid
|
||||
public AjaxResult getComment(@NotNull(message = "模型id不能为空")
|
||||
@ApiParam(value = "模型id", required = true)
|
||||
Long modelId,
|
||||
@NotNull(message = "排序方式不能为空")
|
||||
@ApiParam(value = "排序方式", required = true)
|
||||
Integer sortType) {
|
||||
List<ModelCommentVo> modelCommentList = modelCommentService.getComment(modelId, sortType);
|
||||
return AjaxResult.success(modelCommentList);
|
||||
}
|
||||
|
||||
|
@ -90,10 +102,25 @@ public class ModelCommentController {
|
|||
*/
|
||||
@ApiOperation(value = "删除模型评论")
|
||||
@GetMapping("/commentDelete")
|
||||
public AjaxResult commentDelete(@Valid @NotNull(message = "评论id不能为空") Long commentId) {
|
||||
public AjaxResult commentDelete(@Valid
|
||||
@NotNull(message = "评论id不能为空")
|
||||
@ApiParam(value = "评论id", required = true)
|
||||
Long commentId) {
|
||||
modelCommentService.removeById(commentId);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模型评论数量
|
||||
*/
|
||||
@ApiOperation(value = "获取模型评论数量")
|
||||
@GetMapping("/commentCount")
|
||||
public AjaxResult getCommentCount(@Valid
|
||||
@NotNull(message = "模型id不能为空")
|
||||
@ApiParam(value = "模型id", required = true)
|
||||
Long modelId) {
|
||||
Integer commentCount = modelCommentService.getCommentCount(modelId);
|
||||
return AjaxResult.success(commentCount);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.mcwl.resource.service.ModelImageCommentService;
|
|||
import com.mcwl.resource.service.ModelImageService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
@ -48,7 +49,10 @@ public class ModelImageCommentController {
|
|||
@ApiOperation(value = "图片评论点赞/取消")
|
||||
@RepeatSubmit
|
||||
@GetMapping("/commentLike")
|
||||
public AjaxResult commentLike(@Valid @NotNull(message = "评论id不能为空") Long commentId) {
|
||||
public AjaxResult commentLike(@Valid
|
||||
@NotNull(message = "评论id不能为空")
|
||||
@ApiParam(value = "评论id", required = true)
|
||||
Long commentId) {
|
||||
modelImageCommentLikeService.like(commentId);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
@ -58,7 +62,9 @@ public class ModelImageCommentController {
|
|||
*/
|
||||
@ApiOperation(value = "删除图片评论")
|
||||
@GetMapping("/commentDelete")
|
||||
public AjaxResult commentDelete(@Valid @NotNull(message = "评论id不能为空") Long commentId) {
|
||||
public AjaxResult commentDelete(@Valid
|
||||
@NotNull(message = "评论id不能为空")
|
||||
@ApiParam(value = "评论id", required = true) Long commentId) {
|
||||
modelImageCommentService.removeById(commentId);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
@ -68,10 +74,29 @@ public class ModelImageCommentController {
|
|||
*/
|
||||
@ApiOperation(value = "获取图片评论")
|
||||
@GetMapping("/comment")
|
||||
public AjaxResult getComment(@Valid @NotNull(message = "图片id不能为空") Long imageId) {
|
||||
List<ModelImageCommentVo> modelImageCommentVoList = modelImageCommentService.getComment(imageId);
|
||||
@Valid
|
||||
public AjaxResult getComment(@NotNull(message = "图片id不能为空")
|
||||
@ApiParam(value = "评论id", required = true)
|
||||
Long imageId,
|
||||
@NotNull(message = "排序方式不能为空")
|
||||
@ApiParam(value = "排序方式", required = true)
|
||||
Integer sortType) {
|
||||
List<ModelImageCommentVo> modelImageCommentVoList = modelImageCommentService.getComment(imageId, sortType);
|
||||
return AjaxResult.success(modelImageCommentVoList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图片评论数量
|
||||
*/
|
||||
@ApiOperation(value = "获取图片评论数量")
|
||||
@GetMapping("/commentCount")
|
||||
public AjaxResult getCommentCount(@Valid
|
||||
@NotNull(message = "图片id不能为空")
|
||||
@ApiParam(value = "图片id", required = true)
|
||||
Long imageId) {
|
||||
Integer commentCount = modelImageCommentService.getCommentCount(imageId);
|
||||
return AjaxResult.success(commentCount);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.mcwl.web.controller.resource;
|
||||
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.resource.domain.WorkFlowComment;
|
||||
import com.mcwl.resource.domain.dto.WorkFlowCommentRes;
|
||||
import com.mcwl.resource.domain.vo.WorkFlowCommentVo;
|
||||
import com.mcwl.resource.service.WorkFlowCommentLikeService;
|
||||
|
@ -9,6 +8,7 @@ import com.mcwl.resource.service.WorkFlowCommentService;
|
|||
import com.mcwl.resource.service.WorkFlowLikeService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
@ -18,6 +18,7 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* 工作流评论
|
||||
*
|
||||
* @Author:ChenYan
|
||||
* @Project:McWl
|
||||
* @Package:com.mcwl.web.controller.resource
|
||||
|
@ -38,13 +39,15 @@ public class WorkFlowCommentController {
|
|||
private WorkFlowCommentLikeService workFlowCommentLikeService;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 工作流点赞/取消
|
||||
*/
|
||||
@ApiOperation(value = "工作流点赞/取消")
|
||||
@GetMapping("/like")
|
||||
public AjaxResult like(@Valid @NotNull(message = "模型id不能为空") Long workFlowId) {
|
||||
public AjaxResult like(@Valid
|
||||
@NotNull(message = "模型id不能为空")
|
||||
@ApiParam(value = "模型id", required = true)
|
||||
Long workFlowId) {
|
||||
workFlowLikeService.like(workFlowId);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
@ -55,7 +58,9 @@ public class WorkFlowCommentController {
|
|||
*/
|
||||
@ApiOperation(value = "工作流评论发布")
|
||||
@PostMapping("/comment")
|
||||
public AjaxResult comment(@RequestBody WorkFlowCommentRes workFlowCommentRes) {
|
||||
public AjaxResult comment(@Valid
|
||||
@RequestBody
|
||||
WorkFlowCommentRes workFlowCommentRes) {
|
||||
workFlowCommentService.comment(workFlowCommentRes);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
@ -65,20 +70,28 @@ public class WorkFlowCommentController {
|
|||
*/
|
||||
@ApiOperation(value = "工作流评论点赞/取消")
|
||||
@GetMapping("/commentLike")
|
||||
public AjaxResult commentLike(@Valid @NotNull(message = "评论id不能为空") Long commentId) {
|
||||
public AjaxResult commentLike(@Valid
|
||||
@NotNull(message = "评论id不能为空")
|
||||
@ApiParam(value = "评论id", required = true)
|
||||
Long commentId) {
|
||||
workFlowCommentLikeService.like(commentId);
|
||||
return AjaxResult.error();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取工作流评论
|
||||
*/
|
||||
@ApiOperation(value = "获取工作流评论")
|
||||
@GetMapping("/comment")
|
||||
public AjaxResult getComment(@Valid @NotNull(message = "模型id不能为空") Long commentId) {
|
||||
List<WorkFlowCommentVo> modelCommentList = workFlowCommentService.getComment(commentId);
|
||||
@Valid
|
||||
public AjaxResult getComment(@NotNull(message = "模型id不能为空")
|
||||
@ApiParam(value = "模型id", required = true)
|
||||
Long commentId,
|
||||
@NotNull(message = "排序方式不能为空")
|
||||
@ApiParam(value = "排序方式", required = true)
|
||||
Integer sortType) {
|
||||
List<WorkFlowCommentVo> modelCommentList = workFlowCommentService.getComment(commentId, sortType);
|
||||
return AjaxResult.success(modelCommentList);
|
||||
}
|
||||
|
||||
|
@ -88,10 +101,25 @@ public class WorkFlowCommentController {
|
|||
*/
|
||||
@ApiOperation(value = "删除工作流评论")
|
||||
@GetMapping("/commentDelete")
|
||||
public AjaxResult commentDelete(@Valid @NotNull(message = "评论id不能为空") Long commentId) {
|
||||
public AjaxResult commentDelete(@Valid
|
||||
@NotNull(message = "评论id不能为空")
|
||||
@ApiParam(value = "评论id", required = true)
|
||||
Long commentId) {
|
||||
workFlowCommentService.removeById(commentId);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取工作流评论数量
|
||||
*/
|
||||
@ApiOperation(value = "获取工作流评论数量")
|
||||
@GetMapping("/commentCount")
|
||||
public AjaxResult getCommentCount(@Valid
|
||||
@NotNull(message = "工作流id不能为空")
|
||||
@ApiParam(value = "工作流id", required = true)
|
||||
Long imageId) {
|
||||
Integer commentCount = workFlowCommentService.getCommentCount(imageId);
|
||||
return AjaxResult.success(commentCount);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||
import com.mcwl.resource.domain.ModelComment;
|
||||
import com.mcwl.resource.domain.dto.ModelCommentRes;
|
||||
import com.mcwl.resource.domain.vo.ModelCommentVo;
|
||||
import com.mcwl.resource.domain.vo.ModelImageCommentVo;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -25,6 +23,12 @@ public interface ModelCommentService extends IService<ModelComment> {
|
|||
* @param imageId 图片id
|
||||
* @return 评论区
|
||||
*/
|
||||
List<ModelCommentVo> getComment(Long imageId);
|
||||
List<ModelCommentVo> getComment(Long imageId, Integer sortType);
|
||||
|
||||
/**
|
||||
* 获取评论数量
|
||||
* @param modelId 模型id
|
||||
* @return 评论数量
|
||||
*/
|
||||
Integer getCommentCount(Long modelId);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.mcwl.resource.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.mcwl.resource.domain.ModelImage;
|
||||
import com.mcwl.resource.domain.ModelImageComment;
|
||||
import com.mcwl.resource.domain.dto.ModelImageCommentRes;
|
||||
import com.mcwl.resource.domain.vo.ModelImageCommentVo;
|
||||
|
@ -23,7 +22,13 @@ public interface ModelImageCommentService extends IService<ModelImageComment> {
|
|||
* @param imageId 图片id
|
||||
* @return 评论区
|
||||
*/
|
||||
List<ModelImageCommentVo> getComment(Long imageId);
|
||||
List<ModelImageCommentVo> getComment(Long imageId, Integer sortType);
|
||||
|
||||
|
||||
/**
|
||||
* 获取评论数量
|
||||
* @param imageId 图片id
|
||||
* @return 评论数量
|
||||
*/
|
||||
Integer getCommentCount(Long imageId);
|
||||
}
|
||||
|
|
|
@ -1,21 +1,13 @@
|
|||
package com.mcwl.resource.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.common.core.page.PageDomain;
|
||||
import com.mcwl.common.core.page.TableDataInfo;
|
||||
import com.mcwl.resource.domain.ModelImage;
|
||||
import com.mcwl.resource.domain.ModelProduct;
|
||||
import com.mcwl.resource.domain.dto.ModelImageCommentRes;
|
||||
import com.mcwl.resource.domain.dto.ModelImagePageRes;
|
||||
import com.mcwl.resource.domain.dto.ModelImageRes;
|
||||
import com.mcwl.resource.domain.vo.MallProductVo;
|
||||
import com.mcwl.resource.domain.vo.ModelImageCommentVo;
|
||||
import com.mcwl.resource.domain.vo.ModelImageVo;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface ModelImageService extends IService<ModelImage> {
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* 工作流评论 业务层
|
||||
*
|
||||
* @Author:ChenYan
|
||||
* @Project:McWl
|
||||
* @Package:com.mcwl.resource.service
|
||||
|
@ -21,9 +22,18 @@ public interface WorkFlowCommentService extends IService<WorkFlowComment> {
|
|||
|
||||
/**
|
||||
* 获取评论
|
||||
*
|
||||
* @param imageId 图片id
|
||||
* @return 评论区
|
||||
*/
|
||||
List<WorkFlowCommentVo> getComment(Long imageId);
|
||||
List<WorkFlowCommentVo> getComment(Long imageId, Integer sortType);
|
||||
|
||||
|
||||
/**
|
||||
* 获取评论数量
|
||||
*
|
||||
* @param workFlowId 工作流id
|
||||
* @return 评论数量
|
||||
*/
|
||||
Integer getCommentCount(Long workFlowId);
|
||||
}
|
||||
|
|
|
@ -7,13 +7,9 @@ import com.mcwl.common.core.domain.entity.SysUser;
|
|||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.resource.domain.ModelComment;
|
||||
import com.mcwl.resource.domain.ModelCommentLike;
|
||||
import com.mcwl.resource.domain.ModelImageComment;
|
||||
import com.mcwl.resource.domain.dto.ModelCommentRes;
|
||||
import com.mcwl.resource.domain.dto.ModelImageCommentRes;
|
||||
import com.mcwl.resource.domain.vo.ModelCommentVo;
|
||||
import com.mcwl.resource.domain.vo.ModelImageCommentVo;
|
||||
import com.mcwl.resource.mapper.ModelCommentMapper;
|
||||
import com.mcwl.resource.mapper.ModelImageCommentMapper;
|
||||
import com.mcwl.resource.mapper.ModelImageMapper;
|
||||
import com.mcwl.resource.service.ModelCommentLikeService;
|
||||
import com.mcwl.resource.service.ModelCommentService;
|
||||
|
@ -21,7 +17,6 @@ import com.mcwl.system.service.ISysUserService;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -68,13 +63,14 @@ public class ModelCommentServiceImpl extends ServiceImpl<ModelCommentMapper, Mod
|
|||
* @return 评论区
|
||||
*/
|
||||
@Override
|
||||
public List<ModelCommentVo> getComment(Long imageId) {
|
||||
public List<ModelCommentVo> getComment(Long imageId, Integer sortType) {
|
||||
|
||||
// 1. 查询所有父评论
|
||||
List<ModelComment> parentComments = baseMapper.selectList(
|
||||
new LambdaQueryWrapper<ModelComment>()
|
||||
.eq(ModelComment::getModelId, imageId)
|
||||
.isNull(ModelComment::getParentId)
|
||||
.orderByDesc(sortType != 1, ModelComment::getLikeNum)
|
||||
.orderByAsc(ModelComment::getCreateTime)
|
||||
);
|
||||
|
||||
|
@ -108,6 +104,33 @@ public class ModelCommentServiceImpl extends ServiceImpl<ModelCommentMapper, Mod
|
|||
return buildCommentTree(parentComments, childComments, userMap, likeStatusMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评论总数
|
||||
*
|
||||
* @param modelId 模型ID
|
||||
* @return 评论总数
|
||||
*/
|
||||
@Override
|
||||
public Integer getCommentCount(Long modelId) {
|
||||
|
||||
// 获取所模型父评论
|
||||
List<ModelComment> modelCommentList = baseMapper.selectList(
|
||||
new LambdaQueryWrapper<ModelComment>()
|
||||
.eq(ModelComment::getModelId, modelId));
|
||||
|
||||
// 获取所有父评论的ID
|
||||
List<Long> parentIds = modelCommentList.stream()
|
||||
.map(ModelComment::getId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 获取所有子评论
|
||||
List<ModelComment> childCommentList = baseMapper.selectList(new LambdaQueryWrapper<ModelComment>()
|
||||
.in(ModelComment::getParentId, parentIds));
|
||||
|
||||
|
||||
return parentIds.size() + childCommentList.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* 收集所有评论ID(父+子)
|
||||
*/
|
||||
|
|
|
@ -5,20 +5,17 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.resource.domain.*;
|
||||
import com.mcwl.resource.domain.ModelImageComment;
|
||||
import com.mcwl.resource.domain.ModelImageCommentLike;
|
||||
import com.mcwl.resource.domain.dto.ModelImageCommentRes;
|
||||
import com.mcwl.resource.domain.vo.ModelImageCommentVo;
|
||||
import com.mcwl.resource.domain.vo.WorkFlowCommentVo;
|
||||
import com.mcwl.resource.mapper.ModelImageCommentMapper;
|
||||
import com.mcwl.resource.mapper.ModelImageMapper;
|
||||
import com.mcwl.resource.service.ModelImageCommentLikeService;
|
||||
import com.mcwl.resource.service.ModelImageCommentService;
|
||||
import com.mcwl.resource.service.ModelImageService;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -59,12 +56,13 @@ public class ModelImageCommentServiceImpl extends ServiceImpl<ModelImageCommentM
|
|||
* @return 评论区
|
||||
*/
|
||||
@Override
|
||||
public List<ModelImageCommentVo> getComment(Long imageId) {
|
||||
public List<ModelImageCommentVo> getComment(Long imageId, Integer sortType) {
|
||||
// 1. 查询所有父评论
|
||||
List<ModelImageComment> parentComments = baseMapper.selectList(
|
||||
new LambdaQueryWrapper<ModelImageComment>()
|
||||
.eq(ModelImageComment::getModelImageId, imageId)
|
||||
.isNull(ModelImageComment::getParentId)
|
||||
.orderByDesc(sortType != 1, ModelImageComment::getLikeNum)
|
||||
.orderByAsc(ModelImageComment::getCreateTime)
|
||||
);
|
||||
|
||||
|
@ -99,6 +97,28 @@ public class ModelImageCommentServiceImpl extends ServiceImpl<ModelImageCommentM
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getCommentCount(Long imageId) {
|
||||
|
||||
// 获取所有图片父评论
|
||||
List<ModelImageComment> modelImageCommentList = baseMapper.selectList(
|
||||
new LambdaQueryWrapper<ModelImageComment>()
|
||||
.eq(ModelImageComment::getModelImageId, imageId));
|
||||
|
||||
// 获取所有父评论的ID
|
||||
List<Long> parentIds = modelImageCommentList.stream()
|
||||
.map(ModelImageComment::getId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 获取所有子评论
|
||||
List<ModelImageComment> childCommentList = baseMapper.selectList(new LambdaQueryWrapper<ModelImageComment>()
|
||||
.in(ModelImageComment::getParentId, parentIds));
|
||||
|
||||
|
||||
return parentIds.size() + childCommentList.size();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 收集所有评论ID(父+子)
|
||||
*/
|
||||
|
|
|
@ -7,7 +7,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mcwl.common.constant.DictConstants;
|
||||
import com.mcwl.common.constant.HttpStatus;
|
||||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.common.core.page.TableDataInfo;
|
||||
|
@ -21,7 +20,6 @@ import com.mcwl.resource.domain.vo.ModelImageVo;
|
|||
import com.mcwl.resource.mapper.ModelImageCommentMapper;
|
||||
import com.mcwl.resource.mapper.ModelImageMapper;
|
||||
import com.mcwl.resource.service.ModelImageService;
|
||||
import com.mcwl.system.init.DictInit;
|
||||
import com.mcwl.system.service.ISysDictDataService;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
|
|
@ -5,10 +5,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.resource.domain.*;
|
||||
import com.mcwl.resource.domain.WorkFlowComment;
|
||||
import com.mcwl.resource.domain.WorkFlowCommentLike;
|
||||
import com.mcwl.resource.domain.dto.WorkFlowCommentRes;
|
||||
import com.mcwl.resource.domain.vo.ModelCommentVo;
|
||||
import com.mcwl.resource.domain.vo.ModelImageCommentVo;
|
||||
import com.mcwl.resource.domain.vo.WorkFlowCommentVo;
|
||||
import com.mcwl.resource.mapper.WorkFlowCommentMapper;
|
||||
import com.mcwl.resource.service.WorkFlowCommentLikeService;
|
||||
|
@ -17,7 +16,6 @@ import com.mcwl.system.service.ISysUserService;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -63,13 +61,14 @@ public class WorkFlowCommentServiceImpl extends ServiceImpl<WorkFlowCommentMappe
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<WorkFlowCommentVo> getComment(Long imageId) {
|
||||
public List<WorkFlowCommentVo> getComment(Long imageId, Integer sortType) {
|
||||
|
||||
// 查询所有父评论
|
||||
List<WorkFlowComment> parentComments = baseMapper.selectList(
|
||||
new LambdaQueryWrapper<WorkFlowComment>()
|
||||
.eq(WorkFlowComment::getWorkFlowId, imageId)
|
||||
.isNull(WorkFlowComment::getParentId)
|
||||
.orderByDesc(sortType != 1, WorkFlowComment::getLikeNum)
|
||||
.orderByAsc(WorkFlowComment::getCreateTime)
|
||||
);
|
||||
|
||||
|
@ -104,6 +103,25 @@ public class WorkFlowCommentServiceImpl extends ServiceImpl<WorkFlowCommentMappe
|
|||
return buildCommentTree(parentComments, childComments, userMap, likeStatusMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getCommentCount(Long workFlowId) {
|
||||
// 获取所工作流父评论
|
||||
List<WorkFlowComment> modelCommentList = baseMapper.selectList(
|
||||
new LambdaQueryWrapper<WorkFlowComment>()
|
||||
.eq(WorkFlowComment::getWorkFlowId, workFlowId));
|
||||
|
||||
// 获取所有父评论的ID
|
||||
List<Long> parentIds = modelCommentList.stream()
|
||||
.map(WorkFlowComment::getId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 获取所有子评论
|
||||
List<WorkFlowComment> childCommentList = baseMapper.selectList(new LambdaQueryWrapper<WorkFlowComment>()
|
||||
.in(WorkFlowComment::getParentId, parentIds));
|
||||
|
||||
|
||||
return parentIds.size() + childCommentList.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* 收集所有评论ID(父+子)
|
||||
|
|
Loading…
Reference in New Issue