Merge branch 'feature/my-invitation' into preview
# Conflicts: # mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageServiceImpl.javafeature/my-invitation
commit
8c844faca5
|
@ -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<ModelImageCommentVo> modelImageCommentVoList = modelImageService.getComment(imageId);
|
||||
return AjaxResult.success(modelImageCommentVoList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,11 @@
|
|||
<artifactId>mcwl-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mcwl</groupId>
|
||||
<artifactId>mcwl-system</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
|
|
|
@ -28,6 +28,10 @@ public class ModelImage extends BaseEntity {
|
|||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* 图片地址(最多8张,切割)
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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> {
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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> {
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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<ModelImage> {
|
||||
|
@ -23,4 +26,11 @@ public interface ModelImageService extends IService<ModelImage> {
|
|||
* @param modelImageCommentRes 评论对象
|
||||
*/
|
||||
void comment(ModelImageCommentRes modelImageCommentRes);
|
||||
|
||||
/**
|
||||
* 获取评论
|
||||
* @param imageId 图片id
|
||||
* @return 评论区
|
||||
*/
|
||||
List<ModelImageCommentVo> getComment(Long imageId);
|
||||
}
|
||||
|
|
|
@ -36,14 +36,12 @@ public class ModelImageCommentLikeServiceImpl extends ServiceImpl<ModelImageComm
|
|||
ModelImageCommentLike modelImageCommentLike = baseMapper.getLikeImageComment(userId, commentId);
|
||||
if (Objects.nonNull(modelImageCommentLike)) {
|
||||
if (Objects.equals(modelImageCommentLike.getDelFlag(), "0")) {
|
||||
modelImageCommentLike.setDelFlag("1");
|
||||
modelImageComment.setLikeNum(modelImageComment.getLikeNum() - 1);
|
||||
} else {
|
||||
modelImageCommentLike.setDelFlag("0");
|
||||
modelImageComment.setLikeNum(modelImageComment.getLikeNum() + 1);
|
||||
}
|
||||
// 更新点赞记录
|
||||
baseMapper.updateById(modelImageCommentLike);
|
||||
baseMapper.updateDelFlagById(userId, commentId);
|
||||
// 更新图片评论点赞数
|
||||
modelImageCommentMapper.updateById(modelImageComment);
|
||||
return;
|
||||
|
|
|
@ -34,14 +34,12 @@ public class ModelImageLikeServiceImpl extends ServiceImpl<ModelImageLikeMapper,
|
|||
ModelImageLike modelImageLike = baseMapper.getLikeImage(userId, imageId);
|
||||
if (Objects.nonNull(modelImageLike)) {
|
||||
if (Objects.equals(modelImageLike.getDelFlag(), "0")) {
|
||||
modelImageLike.setDelFlag("1");
|
||||
modelImage.setLikeNum(modelImage.getLikeNum() - 1);
|
||||
} else {
|
||||
modelImageLike.setDelFlag("0");
|
||||
modelImage.setLikeNum(modelImage.getLikeNum() + 1);
|
||||
}
|
||||
// 更新点赞记录
|
||||
baseMapper.updateById(modelImageLike);
|
||||
baseMapper.updateDelFlagById(userId, imageId);
|
||||
// 更新图片点赞数
|
||||
modelImageMapper.updateById(modelImage);
|
||||
return;
|
||||
|
|
|
@ -1,18 +1,30 @@
|
|||
package com.mcwl.resource.service.impl;
|
||||
|
||||
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.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.resource.domain.ModelImage;
|
||||
import com.mcwl.resource.domain.ModelImageComment;
|
||||
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 com.mcwl.resource.mapper.MallProductLikeMapper;
|
||||
import com.mcwl.resource.mapper.ModelImageCommentMapper;
|
||||
import com.mcwl.resource.mapper.ModelImageMapper;
|
||||
import com.mcwl.resource.service.ModelImageService;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
|
@ -24,19 +36,24 @@ public class ModelImageServiceImpl extends ServiceImpl<ModelImageMapper, ModelIm
|
|||
|
||||
private final ModelImageMapper modelImageMapper;
|
||||
|
||||
private final ISysUserService sysUserService;
|
||||
|
||||
@Override
|
||||
public void comment(ModelImageCommentRes modelImageCommentRes) {
|
||||
Long parentId = modelImageCommentRes.getParentId();
|
||||
ModelImageComment mic = modelImageCommentMapper.selectById(parentId);
|
||||
|
||||
if (Objects.nonNull(parentId) && Objects.isNull(mic)) {
|
||||
if (Objects.nonNull(parentId)) {
|
||||
ModelImageComment mic = modelImageCommentMapper.selectById(parentId);
|
||||
if (Objects.isNull(mic)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ModelImageComment modelImageComment = new ModelImageComment();
|
||||
BeanUtil.copyProperties(modelImageCommentRes, modelImageComment);
|
||||
modelImageComment.setUserId(SecurityUtils.getUserId());
|
||||
modelImageComment.setCreateBy(SecurityUtils.getUsername());
|
||||
modelImageComment.setCreateTime(new Date());
|
||||
modelImageComment.setUpdateBy(SecurityUtils.getUsername());
|
||||
modelImageComment.setUpdateTime(new Date());
|
||||
modelImageCommentMapper.insert(modelImageComment);
|
||||
|
@ -48,6 +65,7 @@ public class ModelImageServiceImpl extends ServiceImpl<ModelImageMapper, ModelIm
|
|||
|
||||
ModelImage modelImage = new ModelImage();
|
||||
BeanUtil.copyProperties(modelImageRes, modelImage);
|
||||
modelImage.setUserId(SecurityUtils.getUserId());
|
||||
modelImage.setCreateBy(SecurityUtils.getUsername());
|
||||
modelImage.setUpdateBy(SecurityUtils.getUsername());
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -29,10 +29,16 @@
|
|||
remark
|
||||
from model_image_comment_like
|
||||
</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">
|
||||
<include refid="selectModelImageCommentLikeVo"/>
|
||||
where user_id = #{userId}
|
||||
and model_image_comment_id = #{imageId}
|
||||
and model_image_comment_id = #{commentId}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -29,6 +29,11 @@
|
|||
remark
|
||||
from model_image_like
|
||||
</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">
|
||||
<include refid="selectModelImageLikeVo"/>
|
||||
|
|
Loading…
Reference in New Issue