From 89ff8790559c8c08166accc9107d58a7d1c679b2 Mon Sep 17 00:00:00 2001 From: yang <2119157836@qq.com> Date: Thu, 13 Feb 2025 10:37:15 +0800 Subject: [PATCH] =?UTF-8?q?refactor(resource):=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E5=92=8C=E7=82=B9=E8=B5=9E=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resource/ModelCommentController.java | 8 +++-- .../resource/ModelImageCommentController.java | 6 ++-- .../resource/WorkFlowCommentController.java | 13 +++---- .../mapper/ModelCommentLikeMapper.java | 1 + .../mapper/ModelImageCommentLikeMapper.java | 2 +- .../mapper/WorkFlowCommentLikeMapper.java | 1 + .../resource/service/ModelCommentService.java | 4 +-- .../service/WorkFlowCommentService.java | 4 +-- .../impl/ModelCommentLikeServiceImpl.java | 8 +++-- .../service/impl/ModelCommentServiceImpl.java | 30 ++++++++++------ .../ModelImageCommentLikeServiceImpl.java | 8 +++-- .../impl/ModelImageCommentServiceImpl.java | 26 +++++++++----- .../impl/ModelImageLikeServiceImpl.java | 6 +++- .../service/impl/ModelLikeServiceImpl.java | 4 ++- .../impl/WorkFlowCommentLikeServiceImpl.java | 8 +++-- .../impl/WorkFlowCommentServiceImpl.java | 34 +++++++++++-------- .../service/impl/WorkFlowLikeServiceImpl.java | 6 ++-- .../resource/ModelCommentLikeMapper.xml | 9 ++++- .../resource/ModelImageCommentLikeMapper.xml | 6 ++-- .../resource/WorkFlowCommentLikeMapper.xml | 5 +++ .../mapper/resource/WorkFlowLikeMapper.xml | 10 ++---- 21 files changed, 125 insertions(+), 74 deletions(-) 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 634b26d..2a7c441 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 @@ -76,7 +76,7 @@ public class ModelCommentController { @ApiParam(value = "评论id", required = true) Long commentId) { modelCommentLikeService.like(commentId); - return AjaxResult.error(); + return AjaxResult.success(); } @@ -86,11 +86,13 @@ public class ModelCommentController { @ApiOperation(value = "获取模型评论") @GetMapping("/comment") @Valid - public AjaxResult getComment(@NotNull(message = "模型id不能为空") + public AjaxResult getComment(@Valid + @NotNull(message = "模型id不能为空") @ApiParam(value = "模型id", required = true) Long modelId, + @Valid @NotNull(message = "排序方式不能为空") - @ApiParam(value = "排序方式", required = true) + @ApiParam(value = "排序方式 0最热 1最新", required = true) Integer sortType) { List modelCommentList = modelCommentService.getComment(modelId, sortType); return AjaxResult.success(modelCommentList); 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 97822bf..e77f4ec 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 @@ -75,11 +75,13 @@ public class ModelImageCommentController { @ApiOperation(value = "获取图片评论") @GetMapping("/comment") @Valid - public AjaxResult getComment(@NotNull(message = "图片id不能为空") + public AjaxResult getComment(@Valid + @NotNull(message = "图片id不能为空") @ApiParam(value = "评论id", required = true) Long imageId, + @Valid @NotNull(message = "排序方式不能为空") - @ApiParam(value = "排序方式", required = true) + @ApiParam(value = "排序方式 0最热 1最新", required = true) Integer sortType) { List modelImageCommentVoList = modelImageCommentService.getComment(imageId, sortType); return AjaxResult.success(modelImageCommentVoList); 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 cf66009..326edc7 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 @@ -75,7 +75,7 @@ public class WorkFlowCommentController { @ApiParam(value = "评论id", required = true) Long commentId) { workFlowCommentLikeService.like(commentId); - return AjaxResult.error(); + return AjaxResult.success(); } @@ -84,12 +84,13 @@ public class WorkFlowCommentController { */ @ApiOperation(value = "获取工作流评论") @GetMapping("/comment") - @Valid - public AjaxResult getComment(@NotNull(message = "模型id不能为空") + public AjaxResult getComment(@Valid + @NotNull(message = "模型id不能为空") @ApiParam(value = "模型id", required = true) Long commentId, + @Valid @NotNull(message = "排序方式不能为空") - @ApiParam(value = "排序方式", required = true) + @ApiParam(value = "排序方式 0最热 1最新", required = true) Integer sortType) { List modelCommentList = workFlowCommentService.getComment(commentId, sortType); return AjaxResult.success(modelCommentList); @@ -117,8 +118,8 @@ public class WorkFlowCommentController { public AjaxResult getCommentCount(@Valid @NotNull(message = "工作流id不能为空") @ApiParam(value = "工作流id", required = true) - Long imageId) { - Integer commentCount = workFlowCommentService.getCommentCount(imageId); + Long workFlowId) { + Integer commentCount = workFlowCommentService.getCommentCount(workFlowId); return AjaxResult.success(commentCount); } diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelCommentLikeMapper.java b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelCommentLikeMapper.java index 79e3836..8e4ba67 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelCommentLikeMapper.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelCommentLikeMapper.java @@ -17,4 +17,5 @@ import org.apache.ibatis.annotations.Param; public interface ModelCommentLikeMapper extends BaseMapper { ModelCommentLike getLikeComment(@Param("userId") Long userId, @Param("commentId") Long commentId); + void updateDelFlagById(ModelCommentLike modelCommentLike); } diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelImageCommentLikeMapper.java b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelImageCommentLikeMapper.java index 95ce900..55c1098 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelImageCommentLikeMapper.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelImageCommentLikeMapper.java @@ -10,5 +10,5 @@ import org.apache.ibatis.annotations.Param; public interface ModelImageCommentLikeMapper extends BaseMapper { ModelImageCommentLike getLikeImageComment(@Param("userId") Long userId, @Param("commentId") Long commentId); - void updateDelFlagById(@Param("userId") Long userId, @Param("commentId") Long commentId); + void updateDelFlagById(ModelImageCommentLike modelImageCommentLike); } diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/WorkFlowCommentLikeMapper.java b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/WorkFlowCommentLikeMapper.java index 29f06fb..7558662 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/WorkFlowCommentLikeMapper.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/WorkFlowCommentLikeMapper.java @@ -17,4 +17,5 @@ import org.apache.ibatis.annotations.Param; public interface WorkFlowCommentLikeMapper extends BaseMapper { WorkFlowCommentLike getLikeComment(@Param("userId") Long userId, @Param("commentId") Long commentId); + void updateDelFlagById(WorkFlowCommentLike workFlowCommentLike); } 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 a9c4e9e..2f0ef71 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 @@ -20,10 +20,10 @@ public interface ModelCommentService extends IService { /** * 获取评论 - * @param imageId 图片id + * @param modelId 模型id * @return 评论区 */ - List getComment(Long imageId, Integer sortType); + List getComment(Long modelId, Integer sortType); /** * 获取评论数量 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 7e83cd1..265f1ad 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 @@ -23,10 +23,10 @@ public interface WorkFlowCommentService extends IService { /** * 获取评论 * - * @param imageId 图片id + * @param workFLowId 工作流id * @return 评论区 */ - List getComment(Long imageId, Integer sortType); + List getComment(Long workFLowId, Integer sortType); /** diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelCommentLikeServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelCommentLikeServiceImpl.java index f4b6deb..7a2386b 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelCommentLikeServiceImpl.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelCommentLikeServiceImpl.java @@ -43,14 +43,16 @@ public class ModelCommentLikeServiceImpl extends ServiceImpl getComment(Long imageId, Integer sortType) { + public List getComment(Long modelId, Integer sortType) { // 1. 查询所有父评论 - List parentComments = baseMapper.selectList( - new LambdaQueryWrapper() - .eq(ModelComment::getModelId, imageId) - .isNull(ModelComment::getParentId) - .orderByDesc(sortType != 1, ModelComment::getLikeNum) - .orderByAsc(ModelComment::getCreateTime) - ); + LambdaQueryWrapper lqw = new LambdaQueryWrapper() + .eq(ModelComment::getModelId, modelId) + .isNull(ModelComment::getParentId); + if (sortType == 0) { + // 按点赞数降序,创建时间升序 + lqw.orderByAsc(ModelComment::getLikeNum) + .orderByAsc(ModelComment::getCreateTime); + } else { + lqw.orderByDesc(ModelComment::getCreateTime); + } + List parentComments = baseMapper.selectList(lqw); // 无评论直接返回空列表 if (parentComments.isEmpty()) { @@ -124,8 +129,11 @@ public class ModelCommentServiceImpl extends ServiceImpl childCommentList = baseMapper.selectList(new LambdaQueryWrapper() - .in(ModelComment::getParentId, parentIds)); + List childCommentList = new ArrayList<>(); + if (!parentIds.isEmpty()) { + childCommentList = baseMapper.selectList(new LambdaQueryWrapper() + .in(ModelComment::getParentId, parentIds)); + } return parentIds.size() + childCommentList.size(); diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageCommentLikeServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageCommentLikeServiceImpl.java index 80a3f4e..871fe99 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageCommentLikeServiceImpl.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageCommentLikeServiceImpl.java @@ -39,12 +39,16 @@ public class ModelImageCommentLikeServiceImpl extends ServiceImpl 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) - ); + LambdaQueryWrapper lqw = new LambdaQueryWrapper() + .eq(ModelImageComment::getModelImageId, imageId) + .isNull(ModelImageComment::getParentId); + if (sortType == 0) { + // 按点赞数降序,创建时间升序 + lqw.orderByAsc(ModelImageComment::getLikeNum) + .orderByAsc(ModelImageComment::getCreateTime); + } else { + lqw.orderByDesc(ModelImageComment::getCreateTime); + } + List parentComments = baseMapper.selectList(lqw); // 无评论直接返回空列表 if (parentComments.isEmpty()) { @@ -111,8 +116,11 @@ public class ModelImageCommentServiceImpl extends ServiceImpl childCommentList = baseMapper.selectList(new LambdaQueryWrapper() - .in(ModelImageComment::getParentId, parentIds)); + List childCommentList = new ArrayList<>(); + if (!parentIds.isEmpty()) { + childCommentList = baseMapper.selectList(new LambdaQueryWrapper() + .in(ModelImageComment::getParentId, parentIds)); + } return parentIds.size() + childCommentList.size(); diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageLikeServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageLikeServiceImpl.java index 33419cc..d939e69 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageLikeServiceImpl.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageLikeServiceImpl.java @@ -49,8 +49,12 @@ public class ModelImageLikeServiceImpl extends ServiceImpl getComment(Long imageId, Integer sortType) { + public List getComment(Long workFLowId, Integer sortType) { // 查询所有父评论 - List parentComments = baseMapper.selectList( - new LambdaQueryWrapper() - .eq(WorkFlowComment::getWorkFlowId, imageId) - .isNull(WorkFlowComment::getParentId) - .orderByDesc(sortType != 1, WorkFlowComment::getLikeNum) - .orderByAsc(WorkFlowComment::getCreateTime) - ); + LambdaQueryWrapper lqw = new LambdaQueryWrapper() + .eq(WorkFlowComment::getWorkFlowId, workFLowId) + .isNull(WorkFlowComment::getParentId); + if (sortType == 0) { + // 按点赞数降序,创建时间升序 + lqw.orderByAsc(WorkFlowComment::getLikeNum) + .orderByAsc(WorkFlowComment::getCreateTime); + } else { + lqw.orderByDesc(WorkFlowComment::getCreateTime); + } + List parentComments = baseMapper.selectList(lqw); // 无评论直接返回空列表 if (parentComments.isEmpty()) { @@ -116,8 +120,11 @@ public class WorkFlowCommentServiceImpl extends ServiceImpl childCommentList = baseMapper.selectList(new LambdaQueryWrapper() - .in(WorkFlowComment::getParentId, parentIds)); + List childCommentList = new ArrayList<>(); + if (!parentIds.isEmpty()) { + childCommentList = baseMapper.selectList(new LambdaQueryWrapper() + .in(WorkFlowComment::getParentId, parentIds)); + } return parentIds.size() + childCommentList.size(); @@ -189,9 +196,9 @@ public class WorkFlowCommentServiceImpl extends ServiceImpl buildCommentTree(List parentComments, - List childComments, - Map userMap, - Map likeStatusMap) { + List childComments, + Map userMap, + Map likeStatusMap) { Map> childMap = new HashMap<>(); for (WorkFlowComment child : childComments) { childMap.computeIfAbsent(child.getParentId(), k -> new ArrayList<>()).add(child); @@ -246,5 +253,4 @@ public class WorkFlowCommentServiceImpl extends ServiceImpl + + update model_comment_like + set del_flag = #{delFlag} + where user_id = #{userId} and model_comment_id = #{modelCommentId} + diff --git a/mcwl-resource/src/main/resources/mapper/resource/ModelImageCommentLikeMapper.xml b/mcwl-resource/src/main/resources/mapper/resource/ModelImageCommentLikeMapper.xml index b6498aa..cf9acc0 100644 --- a/mcwl-resource/src/main/resources/mapper/resource/ModelImageCommentLikeMapper.xml +++ b/mcwl-resource/src/main/resources/mapper/resource/ModelImageCommentLikeMapper.xml @@ -30,9 +30,9 @@ from model_image_comment_like - update model_image_comment_like - set del_flag = !del_flag - where user_id = #{userId} and model_image_comment_id = #{commentId} + UPDATE model_image_comment_like + SET del_flag = #{delFlag} + WHERE user_id = #{userId} and model_image_comment_id = #{modelImageCommentId} diff --git a/mcwl-resource/src/main/resources/mapper/resource/WorkFlowCommentLikeMapper.xml b/mcwl-resource/src/main/resources/mapper/resource/WorkFlowCommentLikeMapper.xml index a3bc305..7881818 100644 --- a/mcwl-resource/src/main/resources/mapper/resource/WorkFlowCommentLikeMapper.xml +++ b/mcwl-resource/src/main/resources/mapper/resource/WorkFlowCommentLikeMapper.xml @@ -3,6 +3,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + + update work_flow_comment_like + set del_flag = #{delFlag} + where user_id = #{userId} and work_flow_comment_id = #{workFlowCommentId} +