From 120e61102dd7a753d23e07bba94e712a49860a05 Mon Sep 17 00:00:00 2001 From: yang <2119157836@qq.com> Date: Sat, 11 Jan 2025 15:33:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(resource):=20=E6=B7=BB=E5=8A=A0=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E8=AF=84=E8=AE=BA=E5=8A=9F=E8=83=BD-=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20ModelImageCommentVo=20=E7=B1=BB=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E5=8C=BA=E8=AF=84=E8=AE=BA=20-=20=E5=9C=A8?= =?UTF-8?q?=20ModelImageService=20=E6=8E=A5=E5=8F=A3=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20getComment=20=E6=96=B9=E6=B3=95=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=20-=20=E5=9C=A8=20ModelImageServiceImpl=20?= =?UTF-8?q?=E4=B8=AD=E5=AE=9E=E7=8E=B0=20getComment=20=E6=96=B9=E6=B3=95?= =?UTF-8?q?=20-=20=E5=9C=A8=20ModelImageController=20=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20getComment=20=E6=8E=A5=E5=8F=A3=20-=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=20ModelImageLike=20=E5=92=8C=20ModelImageCommentLike?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resource/ModelImageController.java | 20 +++- mcwl-resource/pom.xml | 5 + .../com/mcwl/resource/domain/ModelImage.java | 4 + .../domain/vo/ModelImageCommentVo.java | 66 +++++++++++ .../mapper/ModelImageCommentLikeMapper.java | 5 +- .../resource/mapper/ModelImageLikeMapper.java | 5 +- .../resource/service/ModelImageService.java | 10 ++ .../ModelImageCommentLikeServiceImpl.java | 6 +- .../impl/ModelImageLikeServiceImpl.java | 4 +- .../service/impl/ModelImageServiceImpl.java | 109 +++++++++++++++++- .../resource/ModelImageCommentLikeMapper.xml | 8 +- .../mapper/resource/ModelImageLikeMapper.xml | 5 + 12 files changed, 231 insertions(+), 16 deletions(-) create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/domain/vo/ModelImageCommentVo.java diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/ModelImageController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/ModelImageController.java index 37d5f20..b422da5 100644 --- a/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/ModelImageController.java +++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/ModelImageController.java @@ -5,10 +5,12 @@ import com.mcwl.common.core.domain.AjaxResult; import com.mcwl.common.utils.SecurityUtils; import com.mcwl.common.utils.oss.OssUtil; import com.mcwl.resource.domain.ModelImage; +import com.mcwl.resource.domain.ModelImageComment; import com.mcwl.resource.domain.ModelImageCommentLike; import com.mcwl.resource.domain.ModelImageLike; import com.mcwl.resource.domain.dto.ModelImageCommentRes; import com.mcwl.resource.domain.dto.ModelImageRes; +import com.mcwl.resource.domain.vo.ModelImageCommentVo; import com.mcwl.resource.service.ModelImageCommentLikeService; import com.mcwl.resource.service.ModelImageLikeService; import com.mcwl.resource.service.ModelImageService; @@ -16,9 +18,14 @@ import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import javax.validation.constraints.NotNull; import java.util.Date; +import java.util.List; import java.util.Objects; +/** + * 图片 + */ @RestController @RequestMapping("/modelImage") @RequiredArgsConstructor @@ -76,10 +83,17 @@ public class ModelImageController { @GetMapping("/commentLike/{commentId}") public AjaxResult commentLike(@PathVariable Long commentId) { modelImageCommentLikeService.like(commentId); - return AjaxResult.error(); + return AjaxResult.success(); + } + + /** + * 获取图片评论 + */ + @GetMapping("/comment/{imageId}") + public AjaxResult getComment(@PathVariable @NotNull(message = "图片id不能为空") Long imageId) { + List modelImageCommentVoList = modelImageService.getComment(imageId); + return AjaxResult.success(modelImageCommentVoList); } - - } diff --git a/mcwl-resource/pom.xml b/mcwl-resource/pom.xml index e1df24a..07a454d 100644 --- a/mcwl-resource/pom.xml +++ b/mcwl-resource/pom.xml @@ -27,6 +27,11 @@ mcwl-common + + com.mcwl + mcwl-system + + com.baomidou mybatis-plus-boot-starter diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/domain/ModelImage.java b/mcwl-resource/src/main/java/com/mcwl/resource/domain/ModelImage.java index 037955b..747f4d2 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/domain/ModelImage.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/domain/ModelImage.java @@ -28,6 +28,10 @@ public class ModelImage extends BaseEntity { */ @TableId private Long id; + /** + * 用户ID + */ + private Long userId; /** * 图片地址(最多8张,切割) */ diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/domain/vo/ModelImageCommentVo.java b/mcwl-resource/src/main/java/com/mcwl/resource/domain/vo/ModelImageCommentVo.java new file mode 100644 index 0000000..2b860cb --- /dev/null +++ b/mcwl-resource/src/main/java/com/mcwl/resource/domain/vo/ModelImageCommentVo.java @@ -0,0 +1,66 @@ +package com.mcwl.resource.domain.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * 评论区评论 + */ + +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Data +public class ModelImageCommentVo { + + /** + * 用户id + */ + private Long userId; + + /** + * 用户名 + */ + private String userName; + + /** + * 用户头像 + */ + private String userAvatar; + + /** + * 评论id + */ + private Long commentId; + + /** + * 评论内容 + */ + private String content; + + /** + * 子评论 + */ + private List contentList = new ArrayList<>(); + + /** + * 评论点赞数 + */ + private Integer likeNum; + + /** + * 评论时间 + */ + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date createTime; + +} 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 e266230..95ce900 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 @@ -4,8 +4,11 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.mcwl.resource.domain.ModelImageComment; import com.mcwl.resource.domain.ModelImageCommentLike; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; @Mapper public interface ModelImageCommentLikeMapper extends BaseMapper { - ModelImageCommentLike getLikeImageComment(Long userId, Long commentId); + ModelImageCommentLike getLikeImageComment(@Param("userId") Long userId, @Param("commentId") Long commentId); + + void updateDelFlagById(@Param("userId") Long userId, @Param("commentId") Long commentId); } diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelImageLikeMapper.java b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelImageLikeMapper.java index 3c4bb13..3395100 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelImageLikeMapper.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelImageLikeMapper.java @@ -4,8 +4,11 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.mcwl.resource.domain.ModelImage; import com.mcwl.resource.domain.ModelImageLike; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; @Mapper public interface ModelImageLikeMapper extends BaseMapper { - ModelImageLike getLikeImage(Long userId, Long imageId); + ModelImageLike getLikeImage(@Param("userId") Long userId, @Param("imageId") Long imageId); + + void updateDelFlagById(@Param("userId") Long userId, @Param("imageId") 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 2e79d86..ad903b0 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 @@ -8,6 +8,9 @@ import com.mcwl.resource.domain.ModelProduct; import com.mcwl.resource.domain.dto.ModelImageCommentRes; import com.mcwl.resource.domain.dto.ModelImageRes; import com.mcwl.resource.domain.vo.MallProductVo; +import com.mcwl.resource.domain.vo.ModelImageCommentVo; + +import java.util.List; public interface ModelImageService extends IService { @@ -23,4 +26,11 @@ public interface ModelImageService extends IService { * @param modelImageCommentRes 评论对象 */ void comment(ModelImageCommentRes modelImageCommentRes); + + /** + * 获取评论 + * @param imageId 图片id + * @return 评论区 + */ + List getComment(Long imageId); } 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 1e7c014..cd9574e 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 @@ -27,7 +27,7 @@ public class ModelImageCommentLikeServiceImpl extends ServiceImpl getComment(Long imageId) { + + List modelImageCommentVoList = new ArrayList<>(); + + // 查询所有父评论 + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(ModelImageComment::getModelImageId, imageId) + .isNull(ModelImageComment::getParentId) + .orderByDesc(ModelImageComment::getCreateTime); + // 添加父评论 + List modelImageCommentList = modelImageCommentMapper.selectList(lqw); + for (ModelImageComment modelImageComment : modelImageCommentList) { + ModelImageCommentVo modelImageCommentVo = getModelImageCommentVo(modelImageComment); + modelImageCommentVoList.add(modelImageCommentVo); + } + + return modelImageCommentVoList; + } + + /** + * 构建ModelImageCommentVo对象 + * + * @param modelImageComment 父评论对象 + * @return ModelImageCommentVo对象 + */ + @NotNull + private ModelImageCommentVo getModelImageCommentVo(ModelImageComment modelImageComment) { + Long userId = modelImageComment.getUserId(); + SysUser sysUser = sysUserService.selectUserById(userId); + + // 构建ModelImageCommentVo对象 + ModelImageCommentVo modelImageCommentVo = new ModelImageCommentVo(); + modelImageCommentVo.setUserId(userId); + modelImageCommentVo.setUserName(sysUser.getUserName()); + modelImageCommentVo.setUserAvatar(sysUser.getAvatar()); + modelImageCommentVo.setCommentId(modelImageComment.getId()); + modelImageCommentVo.setContent(modelImageComment.getContent()); + // 查询子评论 + modelImageCommentVo.setContentList(getContentList(modelImageComment.getId())); + modelImageCommentVo.setLikeNum(modelImageComment.getLikeNum()); + modelImageCommentVo.setCreateTime(modelImageComment.getCreateTime()); + return modelImageCommentVo; + } + + /** + * 递归查询子评论 + * + * @param modelImageCommentId 父评论id + * @return List + */ + private List getContentList(Long modelImageCommentId) { + List modelImageCommentVoList = new ArrayList<>(); + if (Objects.isNull(modelImageCommentId)) { + return modelImageCommentVoList; + } + + // 查询子评论 + LambdaQueryWrapper lqw = new LambdaQueryWrapper() + .eq(ModelImageComment::getParentId, modelImageCommentId) + .orderByDesc(ModelImageComment::getCreateTime); + + List modelImageCommentList = modelImageCommentMapper.selectList(lqw); + + for (ModelImageComment modelImageComment : modelImageCommentList) { + Long userId = modelImageComment.getUserId(); + SysUser sysUser = sysUserService.selectUserById(userId); + ModelImageCommentVo modelImageCommentVo = new ModelImageCommentVo(); + modelImageCommentVo.setUserId(userId); + modelImageCommentVo.setUserName(sysUser.getUserName()); + modelImageCommentVo.setUserAvatar(sysUser.getAvatar()); + modelImageCommentVo.setCommentId(modelImageComment.getId()); + modelImageCommentVo.setContent(modelImageComment.getContent()); + modelImageCommentVo.setLikeNum(modelImageComment.getLikeNum()); + modelImageCommentVo.setCreateTime(modelImageComment.getCreateTime()); + + + modelImageCommentVoList.add(modelImageCommentVo); + } + return modelImageCommentVoList; + } + + } diff --git a/mcwl-resource/src/main/resources/mapper/resource/ModelImageCommentLikeMapper.xml b/mcwl-resource/src/main/resources/mapper/resource/ModelImageCommentLikeMapper.xml index 29ad01b..b6498aa 100644 --- a/mcwl-resource/src/main/resources/mapper/resource/ModelImageCommentLikeMapper.xml +++ b/mcwl-resource/src/main/resources/mapper/resource/ModelImageCommentLikeMapper.xml @@ -29,10 +29,16 @@ remark 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} + + diff --git a/mcwl-resource/src/main/resources/mapper/resource/ModelImageLikeMapper.xml b/mcwl-resource/src/main/resources/mapper/resource/ModelImageLikeMapper.xml index c960a63..2e4a2b5 100644 --- a/mcwl-resource/src/main/resources/mapper/resource/ModelImageLikeMapper.xml +++ b/mcwl-resource/src/main/resources/mapper/resource/ModelImageLikeMapper.xml @@ -29,6 +29,11 @@ remark from model_image_like + + update model_image_like + set del_flag = !del_flag + where user_id = #{userId} and model_image_id = #{imageId} +