diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/ModelCommentController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/ModelCommentController.java index d04269c..634b26d 100644 --- a/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/ModelCommentController.java +++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/ModelCommentController.java @@ -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 @@ -31,12 +33,11 @@ import java.util.List; public class ModelCommentController { @Autowired - private ModelLikeService modelLikeService; + private ModelLikeService modelLikeService; @Autowired - private ModelCommentService modelCommentService; + private ModelCommentService modelCommentService; @Autowired - private ModelCommentLikeService modelCommentLikeService; - + private ModelCommentLikeService modelCommentLikeService; /** @@ -45,7 +46,10 @@ public class ModelCommentController { @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 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 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); + } } diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/ModelImageCommentController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/ModelImageCommentController.java index 760794a..97822bf 100644 --- a/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/ModelImageCommentController.java +++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/ModelImageCommentController.java @@ -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 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 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); + } + } diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/WorkFlowCommentController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/WorkFlowCommentController.java index ce05862..cf66009 100644 --- a/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/WorkFlowCommentController.java +++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/WorkFlowCommentController.java @@ -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 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 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); + } } diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/ModelCommentService.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/ModelCommentService.java index dff6065..a9c4e9e 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/ModelCommentService.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/ModelCommentService.java @@ -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 { * @param imageId 图片id * @return 评论区 */ - List getComment(Long imageId); + List getComment(Long imageId, Integer sortType); + /** + * 获取评论数量 + * @param modelId 模型id + * @return 评论数量 + */ + Integer getCommentCount(Long modelId); } diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/ModelImageCommentService.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/ModelImageCommentService.java index 969bec5..0263292 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/ModelImageCommentService.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/ModelImageCommentService.java @@ -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 { * @param imageId 图片id * @return 评论区 */ - List getComment(Long imageId); + List getComment(Long imageId, Integer sortType); + /** + * 获取评论数量 + * @param imageId 图片id + * @return 评论数量 + */ + Integer getCommentCount(Long imageId); } diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/ModelImageService.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/ModelImageService.java index ebe80ab..46224c0 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/ModelImageService.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/ModelImageService.java @@ -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 { diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/WorkFlowCommentService.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/WorkFlowCommentService.java index b99cc6f..7e83cd1 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/WorkFlowCommentService.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/WorkFlowCommentService.java @@ -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 { /** * 获取评论 + * * @param imageId 图片id * @return 评论区 */ - List getComment(Long imageId); + List getComment(Long imageId, Integer sortType); + + /** + * 获取评论数量 + * + * @param workFlowId 工作流id + * @return 评论数量 + */ + Integer getCommentCount(Long workFlowId); } diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelCommentServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelCommentServiceImpl.java index afd854a..7db4c3c 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelCommentServiceImpl.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelCommentServiceImpl.java @@ -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 getComment(Long imageId) { + public List getComment(Long imageId, Integer sortType) { // 1. 查询所有父评论 List parentComments = baseMapper.selectList( new LambdaQueryWrapper() .eq(ModelComment::getModelId, imageId) .isNull(ModelComment::getParentId) + .orderByDesc(sortType != 1, ModelComment::getLikeNum) .orderByAsc(ModelComment::getCreateTime) ); @@ -108,6 +104,33 @@ public class ModelCommentServiceImpl extends ServiceImpl modelCommentList = baseMapper.selectList( + new LambdaQueryWrapper() + .eq(ModelComment::getModelId, modelId)); + + // 获取所有父评论的ID + List parentIds = modelCommentList.stream() + .map(ModelComment::getId) + .collect(Collectors.toList()); + + // 获取所有子评论 + List childCommentList = baseMapper.selectList(new LambdaQueryWrapper() + .in(ModelComment::getParentId, parentIds)); + + + return parentIds.size() + childCommentList.size(); + } + /** * 收集所有评论ID(父+子) */ diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageCommentServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageCommentServiceImpl.java index 75200d3..b5cc67d 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageCommentServiceImpl.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageCommentServiceImpl.java @@ -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 getComment(Long imageId) { + public List getComment(Long imageId, Integer sortType) { // 1. 查询所有父评论 List parentComments = baseMapper.selectList( new LambdaQueryWrapper() .eq(ModelImageComment::getModelImageId, imageId) .isNull(ModelImageComment::getParentId) + .orderByDesc(sortType != 1, ModelImageComment::getLikeNum) .orderByAsc(ModelImageComment::getCreateTime) ); @@ -99,6 +97,28 @@ public class ModelImageCommentServiceImpl extends ServiceImpl modelImageCommentList = baseMapper.selectList( + new LambdaQueryWrapper() + .eq(ModelImageComment::getModelImageId, imageId)); + + // 获取所有父评论的ID + List parentIds = modelImageCommentList.stream() + .map(ModelImageComment::getId) + .collect(Collectors.toList()); + + // 获取所有子评论 + List childCommentList = baseMapper.selectList(new LambdaQueryWrapper() + .in(ModelImageComment::getParentId, parentIds)); + + + return parentIds.size() + childCommentList.size(); + } + + /** * 收集所有评论ID(父+子) */ diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageServiceImpl.java index 4f1169f..5a330a3 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageServiceImpl.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageServiceImpl.java @@ -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; diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowCommentServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowCommentServiceImpl.java index c58ea3f..bdcd705 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowCommentServiceImpl.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/WorkFlowCommentServiceImpl.java @@ -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 getComment(Long imageId) { + public List getComment(Long imageId, Integer sortType) { // 查询所有父评论 List parentComments = baseMapper.selectList( new LambdaQueryWrapper() .eq(WorkFlowComment::getWorkFlowId, imageId) .isNull(WorkFlowComment::getParentId) + .orderByDesc(sortType != 1, WorkFlowComment::getLikeNum) .orderByAsc(WorkFlowComment::getCreateTime) ); @@ -104,6 +103,25 @@ public class WorkFlowCommentServiceImpl extends ServiceImpl modelCommentList = baseMapper.selectList( + new LambdaQueryWrapper() + .eq(WorkFlowComment::getWorkFlowId, workFlowId)); + + // 获取所有父评论的ID + List parentIds = modelCommentList.stream() + .map(WorkFlowComment::getId) + .collect(Collectors.toList()); + + // 获取所有子评论 + List childCommentList = baseMapper.selectList(new LambdaQueryWrapper() + .in(WorkFlowComment::getParentId, parentIds)); + + + return parentIds.size() + childCommentList.size(); + } /** * 收集所有评论ID(父+子)