feat(resource): 添加获取评论数量,增加排序

master
yang 2025-02-12 22:21:05 +08:00
parent 570c7bb656
commit dd16eb0106
11 changed files with 208 additions and 58 deletions

View File

@ -2,7 +2,6 @@ package com.mcwl.web.controller.resource;
import com.mcwl.common.annotation.RepeatSubmit; import com.mcwl.common.annotation.RepeatSubmit;
import com.mcwl.common.core.domain.AjaxResult; 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.dto.ModelCommentRes;
import com.mcwl.resource.domain.vo.ModelCommentVo; import com.mcwl.resource.domain.vo.ModelCommentVo;
import com.mcwl.resource.service.ModelCommentLikeService; import com.mcwl.resource.service.ModelCommentLikeService;
@ -10,6 +9,7 @@ import com.mcwl.resource.service.ModelCommentService;
import com.mcwl.resource.service.ModelLikeService; import com.mcwl.resource.service.ModelLikeService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -17,7 +17,9 @@ import javax.validation.Valid;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.List; import java.util.List;
/** /**
*
*
* @AuthorChenYan * @AuthorChenYan
* @ProjectMcWl * @ProjectMcWl
* @Packagecom.mcwl.web.controller.resource * @Packagecom.mcwl.web.controller.resource
@ -38,14 +40,16 @@ public class ModelCommentController {
private ModelCommentLikeService modelCommentLikeService; private ModelCommentLikeService modelCommentLikeService;
/** /**
* / * /
*/ */
@ApiOperation(value = "模型点赞/取消") @ApiOperation(value = "模型点赞/取消")
@RepeatSubmit @RepeatSubmit
@GetMapping("/modelLike") @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); modelLikeService.like(modelId);
return AjaxResult.success(); return AjaxResult.success();
} }
@ -67,20 +71,28 @@ public class ModelCommentController {
@ApiOperation(value = "模型评论点赞/取消") @ApiOperation(value = "模型评论点赞/取消")
@RepeatSubmit @RepeatSubmit
@GetMapping("/commentLike") @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); modelCommentLikeService.like(commentId);
return AjaxResult.error(); return AjaxResult.error();
} }
/** /**
* *
*/ */
@ApiOperation(value = "获取模型评论") @ApiOperation(value = "获取模型评论")
@GetMapping("/comment") @GetMapping("/comment")
public AjaxResult getComment(@Valid @NotNull(message = "模型id不能为空") Long modelId) { @Valid
List<ModelCommentVo> modelCommentList = modelCommentService.getComment(modelId); 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); return AjaxResult.success(modelCommentList);
} }
@ -90,10 +102,25 @@ public class ModelCommentController {
*/ */
@ApiOperation(value = "删除模型评论") @ApiOperation(value = "删除模型评论")
@GetMapping("/commentDelete") @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); modelCommentService.removeById(commentId);
return AjaxResult.success(); 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);
}
} }

View File

@ -9,6 +9,7 @@ import com.mcwl.resource.service.ModelImageCommentService;
import com.mcwl.resource.service.ModelImageService; import com.mcwl.resource.service.ModelImageService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -48,7 +49,10 @@ public class ModelImageCommentController {
@ApiOperation(value = "图片评论点赞/取消") @ApiOperation(value = "图片评论点赞/取消")
@RepeatSubmit @RepeatSubmit
@GetMapping("/commentLike") @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); modelImageCommentLikeService.like(commentId);
return AjaxResult.success(); return AjaxResult.success();
} }
@ -58,7 +62,9 @@ public class ModelImageCommentController {
*/ */
@ApiOperation(value = "删除图片评论") @ApiOperation(value = "删除图片评论")
@GetMapping("/commentDelete") @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); modelImageCommentService.removeById(commentId);
return AjaxResult.success(); return AjaxResult.success();
} }
@ -68,10 +74,29 @@ public class ModelImageCommentController {
*/ */
@ApiOperation(value = "获取图片评论") @ApiOperation(value = "获取图片评论")
@GetMapping("/comment") @GetMapping("/comment")
public AjaxResult getComment(@Valid @NotNull(message = "图片id不能为空") Long imageId) { @Valid
List<ModelImageCommentVo> modelImageCommentVoList = modelImageCommentService.getComment(imageId); 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); 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);
}
} }

View File

@ -1,7 +1,6 @@
package com.mcwl.web.controller.resource; package com.mcwl.web.controller.resource;
import com.mcwl.common.core.domain.AjaxResult; 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.dto.WorkFlowCommentRes;
import com.mcwl.resource.domain.vo.WorkFlowCommentVo; import com.mcwl.resource.domain.vo.WorkFlowCommentVo;
import com.mcwl.resource.service.WorkFlowCommentLikeService; import com.mcwl.resource.service.WorkFlowCommentLikeService;
@ -9,6 +8,7 @@ import com.mcwl.resource.service.WorkFlowCommentService;
import com.mcwl.resource.service.WorkFlowLikeService; import com.mcwl.resource.service.WorkFlowLikeService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -18,6 +18,7 @@ import java.util.List;
/** /**
* *
*
* @AuthorChenYan * @AuthorChenYan
* @ProjectMcWl * @ProjectMcWl
* @Packagecom.mcwl.web.controller.resource * @Packagecom.mcwl.web.controller.resource
@ -38,13 +39,15 @@ public class WorkFlowCommentController {
private WorkFlowCommentLikeService workFlowCommentLikeService; private WorkFlowCommentLikeService workFlowCommentLikeService;
/** /**
* / * /
*/ */
@ApiOperation(value = "工作流点赞/取消") @ApiOperation(value = "工作流点赞/取消")
@GetMapping("/like") @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); workFlowLikeService.like(workFlowId);
return AjaxResult.success(); return AjaxResult.success();
} }
@ -55,7 +58,9 @@ public class WorkFlowCommentController {
*/ */
@ApiOperation(value = "工作流评论发布") @ApiOperation(value = "工作流评论发布")
@PostMapping("/comment") @PostMapping("/comment")
public AjaxResult comment(@RequestBody WorkFlowCommentRes workFlowCommentRes) { public AjaxResult comment(@Valid
@RequestBody
WorkFlowCommentRes workFlowCommentRes) {
workFlowCommentService.comment(workFlowCommentRes); workFlowCommentService.comment(workFlowCommentRes);
return AjaxResult.success(); return AjaxResult.success();
} }
@ -65,20 +70,28 @@ public class WorkFlowCommentController {
*/ */
@ApiOperation(value = "工作流评论点赞/取消") @ApiOperation(value = "工作流评论点赞/取消")
@GetMapping("/commentLike") @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); workFlowCommentLikeService.like(commentId);
return AjaxResult.error(); return AjaxResult.error();
} }
/** /**
* *
*/ */
@ApiOperation(value = "获取工作流评论") @ApiOperation(value = "获取工作流评论")
@GetMapping("/comment") @GetMapping("/comment")
public AjaxResult getComment(@Valid @NotNull(message = "模型id不能为空") Long commentId) { @Valid
List<WorkFlowCommentVo> modelCommentList = workFlowCommentService.getComment(commentId); 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); return AjaxResult.success(modelCommentList);
} }
@ -88,10 +101,25 @@ public class WorkFlowCommentController {
*/ */
@ApiOperation(value = "删除工作流评论") @ApiOperation(value = "删除工作流评论")
@GetMapping("/commentDelete") @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); workFlowCommentService.removeById(commentId);
return AjaxResult.success(); 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);
}
} }

View File

@ -4,9 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.mcwl.resource.domain.ModelComment; import com.mcwl.resource.domain.ModelComment;
import com.mcwl.resource.domain.dto.ModelCommentRes; import com.mcwl.resource.domain.dto.ModelCommentRes;
import com.mcwl.resource.domain.vo.ModelCommentVo; import com.mcwl.resource.domain.vo.ModelCommentVo;
import com.mcwl.resource.domain.vo.ModelImageCommentVo;
import javax.validation.constraints.NotNull;
import java.util.List; import java.util.List;
/** /**
@ -25,6 +23,12 @@ public interface ModelCommentService extends IService<ModelComment> {
* @param imageId id * @param imageId id
* @return * @return
*/ */
List<ModelCommentVo> getComment(Long imageId); List<ModelCommentVo> getComment(Long imageId, Integer sortType);
/**
*
* @param modelId id
* @return
*/
Integer getCommentCount(Long modelId);
} }

View File

@ -1,7 +1,6 @@
package com.mcwl.resource.service; package com.mcwl.resource.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.mcwl.resource.domain.ModelImage;
import com.mcwl.resource.domain.ModelImageComment; import com.mcwl.resource.domain.ModelImageComment;
import com.mcwl.resource.domain.dto.ModelImageCommentRes; import com.mcwl.resource.domain.dto.ModelImageCommentRes;
import com.mcwl.resource.domain.vo.ModelImageCommentVo; import com.mcwl.resource.domain.vo.ModelImageCommentVo;
@ -23,7 +22,13 @@ public interface ModelImageCommentService extends IService<ModelImageComment> {
* @param imageId id * @param imageId id
* @return * @return
*/ */
List<ModelImageCommentVo> getComment(Long imageId); List<ModelImageCommentVo> getComment(Long imageId, Integer sortType);
/**
*
* @param imageId id
* @return
*/
Integer getCommentCount(Long imageId);
} }

View File

@ -1,21 +1,13 @@
package com.mcwl.resource.service; package com.mcwl.resource.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; 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.common.core.page.TableDataInfo;
import com.mcwl.resource.domain.ModelImage; 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.ModelImagePageRes;
import com.mcwl.resource.domain.dto.ModelImageRes; 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 com.mcwl.resource.domain.vo.ModelImageVo;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.List;
public interface ModelImageService extends IService<ModelImage> { public interface ModelImageService extends IService<ModelImage> {

View File

@ -9,6 +9,7 @@ import java.util.List;
/** /**
* *
*
* @AuthorChenYan * @AuthorChenYan
* @ProjectMcWl * @ProjectMcWl
* @Packagecom.mcwl.resource.service * @Packagecom.mcwl.resource.service
@ -21,9 +22,18 @@ public interface WorkFlowCommentService extends IService<WorkFlowComment> {
/** /**
* *
*
* @param imageId id * @param imageId id
* @return * @return
*/ */
List<WorkFlowCommentVo> getComment(Long imageId); List<WorkFlowCommentVo> getComment(Long imageId, Integer sortType);
/**
*
*
* @param workFlowId id
* @return
*/
Integer getCommentCount(Long workFlowId);
} }

View File

@ -7,13 +7,9 @@ import com.mcwl.common.core.domain.entity.SysUser;
import com.mcwl.common.utils.SecurityUtils; import com.mcwl.common.utils.SecurityUtils;
import com.mcwl.resource.domain.ModelComment; import com.mcwl.resource.domain.ModelComment;
import com.mcwl.resource.domain.ModelCommentLike; 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.ModelCommentRes;
import com.mcwl.resource.domain.dto.ModelImageCommentRes;
import com.mcwl.resource.domain.vo.ModelCommentVo; 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.ModelCommentMapper;
import com.mcwl.resource.mapper.ModelImageCommentMapper;
import com.mcwl.resource.mapper.ModelImageMapper; import com.mcwl.resource.mapper.ModelImageMapper;
import com.mcwl.resource.service.ModelCommentLikeService; import com.mcwl.resource.service.ModelCommentLikeService;
import com.mcwl.resource.service.ModelCommentService; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.validation.constraints.NotNull;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -68,13 +63,14 @@ public class ModelCommentServiceImpl extends ServiceImpl<ModelCommentMapper, Mod
* @return * @return
*/ */
@Override @Override
public List<ModelCommentVo> getComment(Long imageId) { public List<ModelCommentVo> getComment(Long imageId, Integer sortType) {
// 1. 查询所有父评论 // 1. 查询所有父评论
List<ModelComment> parentComments = baseMapper.selectList( List<ModelComment> parentComments = baseMapper.selectList(
new LambdaQueryWrapper<ModelComment>() new LambdaQueryWrapper<ModelComment>()
.eq(ModelComment::getModelId, imageId) .eq(ModelComment::getModelId, imageId)
.isNull(ModelComment::getParentId) .isNull(ModelComment::getParentId)
.orderByDesc(sortType != 1, ModelComment::getLikeNum)
.orderByAsc(ModelComment::getCreateTime) .orderByAsc(ModelComment::getCreateTime)
); );
@ -108,6 +104,33 @@ public class ModelCommentServiceImpl extends ServiceImpl<ModelCommentMapper, Mod
return buildCommentTree(parentComments, childComments, userMap, likeStatusMap); 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+ * ID+
*/ */

View File

@ -5,20 +5,17 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mcwl.common.core.domain.entity.SysUser; import com.mcwl.common.core.domain.entity.SysUser;
import com.mcwl.common.utils.SecurityUtils; 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.dto.ModelImageCommentRes;
import com.mcwl.resource.domain.vo.ModelImageCommentVo; 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.ModelImageCommentMapper;
import com.mcwl.resource.mapper.ModelImageMapper;
import com.mcwl.resource.service.ModelImageCommentLikeService; import com.mcwl.resource.service.ModelImageCommentLikeService;
import com.mcwl.resource.service.ModelImageCommentService; import com.mcwl.resource.service.ModelImageCommentService;
import com.mcwl.resource.service.ModelImageService;
import com.mcwl.system.service.ISysUserService; import com.mcwl.system.service.ISysUserService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.validation.constraints.NotNull;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -59,12 +56,13 @@ public class ModelImageCommentServiceImpl extends ServiceImpl<ModelImageCommentM
* @return * @return
*/ */
@Override @Override
public List<ModelImageCommentVo> getComment(Long imageId) { public List<ModelImageCommentVo> getComment(Long imageId, Integer sortType) {
// 1. 查询所有父评论 // 1. 查询所有父评论
List<ModelImageComment> parentComments = baseMapper.selectList( List<ModelImageComment> parentComments = baseMapper.selectList(
new LambdaQueryWrapper<ModelImageComment>() new LambdaQueryWrapper<ModelImageComment>()
.eq(ModelImageComment::getModelImageId, imageId) .eq(ModelImageComment::getModelImageId, imageId)
.isNull(ModelImageComment::getParentId) .isNull(ModelImageComment::getParentId)
.orderByDesc(sortType != 1, ModelImageComment::getLikeNum)
.orderByAsc(ModelImageComment::getCreateTime) .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+ * ID+
*/ */

View File

@ -7,7 +7,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem; import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mcwl.common.constant.DictConstants;
import com.mcwl.common.constant.HttpStatus; import com.mcwl.common.constant.HttpStatus;
import com.mcwl.common.core.domain.entity.SysUser; import com.mcwl.common.core.domain.entity.SysUser;
import com.mcwl.common.core.page.TableDataInfo; 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.ModelImageCommentMapper;
import com.mcwl.resource.mapper.ModelImageMapper; import com.mcwl.resource.mapper.ModelImageMapper;
import com.mcwl.resource.service.ModelImageService; import com.mcwl.resource.service.ModelImageService;
import com.mcwl.system.init.DictInit;
import com.mcwl.system.service.ISysDictDataService; import com.mcwl.system.service.ISysDictDataService;
import com.mcwl.system.service.ISysUserService; import com.mcwl.system.service.ISysUserService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;

View File

@ -5,10 +5,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mcwl.common.core.domain.entity.SysUser; import com.mcwl.common.core.domain.entity.SysUser;
import com.mcwl.common.utils.SecurityUtils; 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.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.domain.vo.WorkFlowCommentVo;
import com.mcwl.resource.mapper.WorkFlowCommentMapper; import com.mcwl.resource.mapper.WorkFlowCommentMapper;
import com.mcwl.resource.service.WorkFlowCommentLikeService; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.validation.constraints.NotNull;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -63,13 +61,14 @@ public class WorkFlowCommentServiceImpl extends ServiceImpl<WorkFlowCommentMappe
} }
@Override @Override
public List<WorkFlowCommentVo> getComment(Long imageId) { public List<WorkFlowCommentVo> getComment(Long imageId, Integer sortType) {
// 查询所有父评论 // 查询所有父评论
List<WorkFlowComment> parentComments = baseMapper.selectList( List<WorkFlowComment> parentComments = baseMapper.selectList(
new LambdaQueryWrapper<WorkFlowComment>() new LambdaQueryWrapper<WorkFlowComment>()
.eq(WorkFlowComment::getWorkFlowId, imageId) .eq(WorkFlowComment::getWorkFlowId, imageId)
.isNull(WorkFlowComment::getParentId) .isNull(WorkFlowComment::getParentId)
.orderByDesc(sortType != 1, WorkFlowComment::getLikeNum)
.orderByAsc(WorkFlowComment::getCreateTime) .orderByAsc(WorkFlowComment::getCreateTime)
); );
@ -104,6 +103,25 @@ public class WorkFlowCommentServiceImpl extends ServiceImpl<WorkFlowCommentMappe
return buildCommentTree(parentComments, childComments, userMap, likeStatusMap); 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+ * ID+