Merge branch 'feature/my-invitation' into preview

# Conflicts:
#	mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageServiceImpl.java
feature/my-invitation
yang 2025-01-11 15:34:59 +08:00
commit 8c844faca5
12 changed files with 236 additions and 16 deletions

View File

@ -5,10 +5,12 @@ import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.common.utils.SecurityUtils; import com.mcwl.common.utils.SecurityUtils;
import com.mcwl.common.utils.oss.OssUtil; import com.mcwl.common.utils.oss.OssUtil;
import com.mcwl.resource.domain.ModelImage; import com.mcwl.resource.domain.ModelImage;
import com.mcwl.resource.domain.ModelImageComment;
import com.mcwl.resource.domain.ModelImageCommentLike; import com.mcwl.resource.domain.ModelImageCommentLike;
import com.mcwl.resource.domain.ModelImageLike; import com.mcwl.resource.domain.ModelImageLike;
import com.mcwl.resource.domain.dto.ModelImageCommentRes; import com.mcwl.resource.domain.dto.ModelImageCommentRes;
import com.mcwl.resource.domain.dto.ModelImageRes; 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.ModelImageCommentLikeService;
import com.mcwl.resource.service.ModelImageLikeService; import com.mcwl.resource.service.ModelImageLikeService;
import com.mcwl.resource.service.ModelImageService; import com.mcwl.resource.service.ModelImageService;
@ -16,9 +18,14 @@ import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.validation.constraints.NotNull;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Objects; import java.util.Objects;
/**
*
*/
@RestController @RestController
@RequestMapping("/modelImage") @RequestMapping("/modelImage")
@RequiredArgsConstructor @RequiredArgsConstructor
@ -76,10 +83,17 @@ public class ModelImageController {
@GetMapping("/commentLike/{commentId}") @GetMapping("/commentLike/{commentId}")
public AjaxResult commentLike(@PathVariable Long commentId) { public AjaxResult commentLike(@PathVariable Long commentId) {
modelImageCommentLikeService.like(commentId); modelImageCommentLikeService.like(commentId);
return AjaxResult.error(); return AjaxResult.success();
}
/**
*
*/
@GetMapping("/comment/{imageId}")
public AjaxResult getComment(@PathVariable @NotNull(message = "图片id不能为空") Long imageId) {
List<ModelImageCommentVo> modelImageCommentVoList = modelImageService.getComment(imageId);
return AjaxResult.success(modelImageCommentVoList);
} }
} }

View File

@ -27,6 +27,11 @@
<artifactId>mcwl-common</artifactId> <artifactId>mcwl-common</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.mcwl</groupId>
<artifactId>mcwl-system</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.baomidou</groupId> <groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId> <artifactId>mybatis-plus-boot-starter</artifactId>

View File

@ -28,6 +28,10 @@ public class ModelImage extends BaseEntity {
*/ */
@TableId @TableId
private Long id; private Long id;
/**
* ID
*/
private Long userId;
/** /**
* 8 * 8
*/ */

View File

@ -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<ModelImageCommentVo> 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;
}

View File

@ -4,8 +4,11 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mcwl.resource.domain.ModelImageComment; import com.mcwl.resource.domain.ModelImageComment;
import com.mcwl.resource.domain.ModelImageCommentLike; import com.mcwl.resource.domain.ModelImageCommentLike;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper @Mapper
public interface ModelImageCommentLikeMapper extends BaseMapper<ModelImageCommentLike> { public interface ModelImageCommentLikeMapper extends BaseMapper<ModelImageCommentLike> {
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);
} }

View File

@ -4,8 +4,11 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mcwl.resource.domain.ModelImage; import com.mcwl.resource.domain.ModelImage;
import com.mcwl.resource.domain.ModelImageLike; import com.mcwl.resource.domain.ModelImageLike;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper @Mapper
public interface ModelImageLikeMapper extends BaseMapper<ModelImageLike> { public interface ModelImageLikeMapper extends BaseMapper<ModelImageLike> {
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);
} }

View File

@ -8,6 +8,9 @@ import com.mcwl.resource.domain.ModelProduct;
import com.mcwl.resource.domain.dto.ModelImageCommentRes; import com.mcwl.resource.domain.dto.ModelImageCommentRes;
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.MallProductVo;
import com.mcwl.resource.domain.vo.ModelImageCommentVo;
import java.util.List;
public interface ModelImageService extends IService<ModelImage> { public interface ModelImageService extends IService<ModelImage> {
@ -23,4 +26,11 @@ public interface ModelImageService extends IService<ModelImage> {
* @param modelImageCommentRes * @param modelImageCommentRes
*/ */
void comment(ModelImageCommentRes modelImageCommentRes); void comment(ModelImageCommentRes modelImageCommentRes);
/**
*
* @param imageId id
* @return
*/
List<ModelImageCommentVo> getComment(Long imageId);
} }

View File

@ -27,7 +27,7 @@ public class ModelImageCommentLikeServiceImpl extends ServiceImpl<ModelImageComm
@Override @Override
@Transactional @Transactional
public void like(Long commentId) { public void like(Long commentId) {
ModelImageComment modelImageComment = modelImageCommentMapper.selectById(commentId); ModelImageComment modelImageComment = modelImageCommentMapper.selectById(commentId);
if (Objects.isNull(modelImageComment)) { if (Objects.isNull(modelImageComment)) {
throw new ServiceException("该评论不存在"); throw new ServiceException("该评论不存在");
@ -36,14 +36,12 @@ public class ModelImageCommentLikeServiceImpl extends ServiceImpl<ModelImageComm
ModelImageCommentLike modelImageCommentLike = baseMapper.getLikeImageComment(userId, commentId); ModelImageCommentLike modelImageCommentLike = baseMapper.getLikeImageComment(userId, commentId);
if (Objects.nonNull(modelImageCommentLike)) { if (Objects.nonNull(modelImageCommentLike)) {
if (Objects.equals(modelImageCommentLike.getDelFlag(), "0")) { if (Objects.equals(modelImageCommentLike.getDelFlag(), "0")) {
modelImageCommentLike.setDelFlag("1");
modelImageComment.setLikeNum(modelImageComment.getLikeNum() - 1); modelImageComment.setLikeNum(modelImageComment.getLikeNum() - 1);
} else { } else {
modelImageCommentLike.setDelFlag("0");
modelImageComment.setLikeNum(modelImageComment.getLikeNum() + 1); modelImageComment.setLikeNum(modelImageComment.getLikeNum() + 1);
} }
// 更新点赞记录 // 更新点赞记录
baseMapper.updateById(modelImageCommentLike); baseMapper.updateDelFlagById(userId, commentId);
// 更新图片评论点赞数 // 更新图片评论点赞数
modelImageCommentMapper.updateById(modelImageComment); modelImageCommentMapper.updateById(modelImageComment);
return; return;

View File

@ -34,14 +34,12 @@ public class ModelImageLikeServiceImpl extends ServiceImpl<ModelImageLikeMapper,
ModelImageLike modelImageLike = baseMapper.getLikeImage(userId, imageId); ModelImageLike modelImageLike = baseMapper.getLikeImage(userId, imageId);
if (Objects.nonNull(modelImageLike)) { if (Objects.nonNull(modelImageLike)) {
if (Objects.equals(modelImageLike.getDelFlag(), "0")) { if (Objects.equals(modelImageLike.getDelFlag(), "0")) {
modelImageLike.setDelFlag("1");
modelImage.setLikeNum(modelImage.getLikeNum() - 1); modelImage.setLikeNum(modelImage.getLikeNum() - 1);
} else { } else {
modelImageLike.setDelFlag("0");
modelImage.setLikeNum(modelImage.getLikeNum() + 1); modelImage.setLikeNum(modelImage.getLikeNum() + 1);
} }
// 更新点赞记录 // 更新点赞记录
baseMapper.updateById(modelImageLike); baseMapper.updateDelFlagById(userId, imageId);
// 更新图片点赞数 // 更新图片点赞数
modelImageMapper.updateById(modelImage); modelImageMapper.updateById(modelImage);
return; return;

View File

@ -1,18 +1,30 @@
package com.mcwl.resource.service.impl; package com.mcwl.resource.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.core.domain.AjaxResult;
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.ModelImage; 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.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.mapper.MallProductLikeMapper;
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.service.ISysUserService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.Objects; import java.util.Objects;
@ -24,19 +36,24 @@ public class ModelImageServiceImpl extends ServiceImpl<ModelImageMapper, ModelIm
private final ModelImageMapper modelImageMapper; private final ModelImageMapper modelImageMapper;
private final ISysUserService sysUserService;
@Override @Override
public void comment(ModelImageCommentRes modelImageCommentRes) { public void comment(ModelImageCommentRes modelImageCommentRes) {
Long parentId = modelImageCommentRes.getParentId(); Long parentId = modelImageCommentRes.getParentId();
ModelImageComment mic = modelImageCommentMapper.selectById(parentId);
if (Objects.nonNull(parentId) && Objects.isNull(mic)) { if (Objects.nonNull(parentId)) {
return; ModelImageComment mic = modelImageCommentMapper.selectById(parentId);
if (Objects.isNull(mic)) {
return;
}
} }
ModelImageComment modelImageComment = new ModelImageComment(); ModelImageComment modelImageComment = new ModelImageComment();
BeanUtil.copyProperties(modelImageCommentRes, modelImageComment); BeanUtil.copyProperties(modelImageCommentRes, modelImageComment);
modelImageComment.setUserId(SecurityUtils.getUserId()); modelImageComment.setUserId(SecurityUtils.getUserId());
modelImageComment.setCreateBy(SecurityUtils.getUsername()); modelImageComment.setCreateBy(SecurityUtils.getUsername());
modelImageComment.setCreateTime(new Date());
modelImageComment.setUpdateBy(SecurityUtils.getUsername()); modelImageComment.setUpdateBy(SecurityUtils.getUsername());
modelImageComment.setUpdateTime(new Date()); modelImageComment.setUpdateTime(new Date());
modelImageCommentMapper.insert(modelImageComment); modelImageCommentMapper.insert(modelImageComment);
@ -48,6 +65,7 @@ public class ModelImageServiceImpl extends ServiceImpl<ModelImageMapper, ModelIm
ModelImage modelImage = new ModelImage(); ModelImage modelImage = new ModelImage();
BeanUtil.copyProperties(modelImageRes, modelImage); BeanUtil.copyProperties(modelImageRes, modelImage);
modelImage.setUserId(SecurityUtils.getUserId());
modelImage.setCreateBy(SecurityUtils.getUsername()); modelImage.setCreateBy(SecurityUtils.getUsername());
modelImage.setUpdateBy(SecurityUtils.getUsername()); modelImage.setUpdateBy(SecurityUtils.getUsername());
modelImage.setUpdateTime(new Date()); modelImage.setUpdateTime(new Date());
@ -56,4 +74,94 @@ public class ModelImageServiceImpl extends ServiceImpl<ModelImageMapper, ModelIm
} }
/**
*
* @param imageId id
* @return
*/
@Override
public List<ModelImageCommentVo> getComment(Long imageId) {
List<ModelImageCommentVo> modelImageCommentVoList = new ArrayList<>();
// 查询所有父评论
LambdaQueryWrapper<ModelImageComment> lqw = new LambdaQueryWrapper<>();
lqw.eq(ModelImageComment::getModelImageId, imageId)
.isNull(ModelImageComment::getParentId)
.orderByDesc(ModelImageComment::getCreateTime);
// 添加父评论
List<ModelImageComment> 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<ModelImageCommentVo>
*/
private List<ModelImageCommentVo> getContentList(Long modelImageCommentId) {
List<ModelImageCommentVo> modelImageCommentVoList = new ArrayList<>();
if (Objects.isNull(modelImageCommentId)) {
return modelImageCommentVoList;
}
// 查询子评论
LambdaQueryWrapper<ModelImageComment> lqw = new LambdaQueryWrapper<ModelImageComment>()
.eq(ModelImageComment::getParentId, modelImageCommentId)
.orderByDesc(ModelImageComment::getCreateTime);
List<ModelImageComment> 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;
}
} }

View File

@ -29,10 +29,16 @@
remark remark
from model_image_comment_like from model_image_comment_like
</sql> </sql>
<update id="updateDelFlagById">
update model_image_comment_like
set del_flag = !del_flag
where user_id = #{userId} and model_image_comment_id = #{commentId}
</update>
<select id="getLikeImageComment" resultMap="ModelImageCommentLikeResult"> <select id="getLikeImageComment" resultMap="ModelImageCommentLikeResult">
<include refid="selectModelImageCommentLikeVo"/> <include refid="selectModelImageCommentLikeVo"/>
where user_id = #{userId} where user_id = #{userId}
and model_image_comment_id = #{imageId} and model_image_comment_id = #{commentId}
</select> </select>
</mapper> </mapper>

View File

@ -29,6 +29,11 @@
remark remark
from model_image_like from model_image_like
</sql> </sql>
<update id="updateDelFlagById">
update model_image_like
set del_flag = !del_flag
where user_id = #{userId} and model_image_id = #{imageId}
</update>
<select id="getLikeImage" resultMap="ModelImageLikeResult"> <select id="getLikeImage" resultMap="ModelImageLikeResult">
<include refid="selectModelImageLikeVo"/> <include refid="selectModelImageLikeVo"/>