feat: 图片模块调整
parent
dc2b5c9daa
commit
5f4404ae1d
|
@ -2,8 +2,10 @@ package com.mcwl.web.controller.communityCenter;
|
|||
|
||||
import com.mcwl.common.core.controller.BaseController;
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.communityCenter.domain.dto.CommentDelRes;
|
||||
import com.mcwl.communityCenter.domain.dto.CommentDetailRes;
|
||||
import com.mcwl.communityCenter.domain.dto.CommentRes;
|
||||
import com.mcwl.communityCenter.domain.vo.PublicModelCommentVo;
|
||||
import com.mcwl.communityCenter.domain.vo.CommentVo;
|
||||
import com.mcwl.communityCenter.domain.PublishComment;
|
||||
import com.mcwl.communityCenter.service.PublishCommentService;
|
||||
import io.swagger.annotations.Api;
|
||||
|
@ -43,39 +45,37 @@ public class PublishCommentController extends BaseController {
|
|||
|
||||
|
||||
/**
|
||||
* 获取评论
|
||||
* 获取评论详情
|
||||
*
|
||||
* @param publishComment
|
||||
* @return
|
||||
* @param commentDetailRes 评论详情请求参数
|
||||
* @return 评论详情
|
||||
*/
|
||||
@ApiOperation(value = "获取评论")
|
||||
@GetMapping("/comment/{Id}")
|
||||
public List<PublicModelCommentVo> getComment(@RequestBody PublishComment publishComment) {
|
||||
@ApiOperation(value = "获取评论详情")
|
||||
@PostMapping("/detail")
|
||||
public AjaxResult getComment(@RequestBody @Valid CommentDetailRes commentDetailRes) {
|
||||
|
||||
return publishCommentService.getComment(publishComment);
|
||||
return publishCommentService.getComment(commentDetailRes);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 点赞或取消点赞评论
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param commentId 评论ID
|
||||
* @return 更新后的点赞数
|
||||
*/
|
||||
@ApiOperation(value = "点赞或取消点赞评论")
|
||||
@PostMapping("/{commentId}/like")
|
||||
public ResponseEntity<Integer> toggleLike(@PathVariable Long commentId, @RequestParam Long userId) {
|
||||
int updatedLikes = publishCommentService.toggleLike(userId, commentId);
|
||||
return ResponseEntity.ok(updatedLikes);
|
||||
}
|
||||
// /**
|
||||
// * 点赞或取消点赞评论
|
||||
// * @param commentDetailRes 评论请求参数
|
||||
// * @return 更新后的点赞数
|
||||
// */
|
||||
// @ApiOperation(value = "点赞或取消点赞评论")
|
||||
// @PostMapping("/like")
|
||||
// public AjaxResult like(@RequestBody @Valid CommentDetailRes commentDetailRes) {
|
||||
//
|
||||
// return publishCommentService.like(commentDetailRes);
|
||||
// }
|
||||
|
||||
|
||||
@ApiOperation(value = "删除评论")
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<String> delete(@PathVariable Long id) {
|
||||
publishCommentService.removeById(id);
|
||||
return ResponseEntity.ok("删除成功");
|
||||
@PostMapping("/delete")
|
||||
public AjaxResult delete(@RequestBody @Valid CommentDelRes commentDelRes) {
|
||||
|
||||
return publishCommentService.removeCommentById(commentDelRes);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import javax.validation.constraints.NotNull;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 图片
|
||||
* 图片评论
|
||||
*/
|
||||
@Api(tags = "图片评论")
|
||||
@RestController
|
||||
|
@ -37,7 +37,7 @@ public class ModelImageCommentController {
|
|||
@ApiOperation(value = "图片评论发布")
|
||||
@PostMapping("/comment")
|
||||
public AjaxResult comment(@RequestBody ModelImageCommentRes modelImageCommentRes) {
|
||||
modelImageService.comment(modelImageCommentRes);
|
||||
modelImageCommentService.comment(modelImageCommentRes);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ public class ModelImageCommentController {
|
|||
@ApiOperation(value = "获取图片评论")
|
||||
@GetMapping("/comment/{imageId}")
|
||||
public AjaxResult getComment(@PathVariable @NotNull(message = "图片id不能为空") Long imageId) {
|
||||
List<ModelImageCommentVo> modelImageCommentVoList = modelImageService.getComment(imageId);
|
||||
List<ModelImageCommentVo> modelImageCommentVoList = modelImageCommentService.getComment(imageId);
|
||||
return AjaxResult.success(modelImageCommentVoList);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import lombok.EqualsAndHashCode;
|
|||
@ApiModel(description = "评论区评论")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("cc_publish_comment")
|
||||
@TableName("cc_comment")
|
||||
public class PublishComment extends BaseEntity {
|
||||
/**
|
||||
* id
|
||||
|
|
|
@ -19,7 +19,7 @@ import lombok.EqualsAndHashCode;
|
|||
@ApiModel(description = "评论点赞")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("cc_publish_comment_like")
|
||||
@TableName("cc_comment_like")
|
||||
public class PublishCommentLike extends BaseEntity {
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package com.mcwl.communityCenter.domain.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 评论删除请求参数
|
||||
*/
|
||||
@Data
|
||||
@ApiModel(value = "评论删除请求参数")
|
||||
public class CommentDelRes {
|
||||
|
||||
/**
|
||||
* 评论id
|
||||
*/
|
||||
@ApiModelProperty(value = "评论id", required = true)
|
||||
@NotNull(message = "评论id不能为空")
|
||||
private Long id;
|
||||
/**
|
||||
* 租户id
|
||||
*/
|
||||
@ApiModelProperty(value = "租户id", required = true)
|
||||
@NotNull(message = "租户id不能为空")
|
||||
private Long tenantId;
|
||||
/**
|
||||
* 社区id
|
||||
*/
|
||||
@ApiModelProperty(value = "社区id", required = true)
|
||||
@NotNull(message = "社区id不能为空")
|
||||
private Long communityId;
|
||||
/**
|
||||
* 运营id
|
||||
*/
|
||||
@ApiModelProperty(value = "运营id", required = true)
|
||||
@NotNull(message = "运营id不能为空")
|
||||
private Long operatorId;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.mcwl.communityCenter.domain.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 评论请求参数
|
||||
*/
|
||||
@Data
|
||||
@ApiModel(value = "评论请求参数")
|
||||
public class CommentDetailRes {
|
||||
|
||||
|
||||
/**
|
||||
* 租户id
|
||||
*/
|
||||
@ApiModelProperty(value = "租户id", required = true)
|
||||
@NotNull(message = "租户id不能为空")
|
||||
private Long tenantId;
|
||||
/**
|
||||
* 社区id
|
||||
*/
|
||||
@ApiModelProperty(value = "社区id", required = true)
|
||||
@NotNull(message = "社区id不能为空")
|
||||
private Long communityId;
|
||||
/**
|
||||
* 运营id
|
||||
*/
|
||||
@ApiModelProperty(value = "运营id", required = true)
|
||||
@NotNull(message = "运营id不能为空")
|
||||
private Long operatorId;
|
||||
|
||||
|
||||
}
|
|
@ -12,10 +12,6 @@ import javax.validation.constraints.NotNull;
|
|||
@ApiModel(value = "查看详情请求参数")
|
||||
public class QuestionDetailRes {
|
||||
|
||||
@NotNull(message = "问题id不能为空")
|
||||
@ApiModelProperty(value = "问题id", required = true)
|
||||
private Long questionId;
|
||||
|
||||
@NotNull(message = "租户不能为空")
|
||||
@ApiModelProperty(value = "租户id", required = true)
|
||||
private Long tenantId;
|
||||
|
@ -24,4 +20,8 @@ public class QuestionDetailRes {
|
|||
@ApiModelProperty(value = "社区id", required = true)
|
||||
private Long communityId;
|
||||
|
||||
@NotNull(message = "问题id不能为空")
|
||||
@ApiModelProperty(value = "问题id", required = true)
|
||||
private Long questionId;
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,10 @@ import java.util.List;
|
|||
@AllArgsConstructor
|
||||
@Data
|
||||
@ApiModel(description = "评论区评论")
|
||||
public class PublicModelCommentVo {
|
||||
public class CommentVo {
|
||||
|
||||
@ApiModelProperty(value = "评论id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
|
@ -42,23 +45,12 @@ public class PublicModelCommentVo {
|
|||
@ApiModelProperty(value = "用户头像")
|
||||
private String userAvatar;
|
||||
|
||||
/**
|
||||
* 评论id
|
||||
*/
|
||||
@ApiModelProperty(value = "评论id")
|
||||
private Long commentId;
|
||||
|
||||
/**
|
||||
* 评论内容
|
||||
*/
|
||||
@ApiModelProperty(value = "评论内容")
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 子评论
|
||||
*/
|
||||
@ApiModelProperty(value = "子评论")
|
||||
private List<PublicModelCommentVo> contentList = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 评论点赞数
|
|
@ -31,6 +31,9 @@ public class CustomTenantHandler implements TenantLineHandler {
|
|||
tables.add("cc_question");
|
||||
// 发布评论表
|
||||
tables.add("cc_publish_comment");
|
||||
|
||||
// 输出表名
|
||||
log.info("多租户表:{}", tables);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -29,4 +29,14 @@ public interface InviteMapper extends BaseMapper<Invite> {
|
|||
*/
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
Invite isInvite(@Param("tenantId") Long tenantId,@Param("communityId") Long communityId,@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 根据租户id、社区id和被邀请人id查询邀请记录
|
||||
* @param tenantId 租户id
|
||||
* @param communityId 社区id
|
||||
* @param inviteeUserId 被邀请人id
|
||||
* @return 邀请记录
|
||||
*/
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
Invite selectByTenantIdAndCommunityIdAndInviteeUserId(Long tenantId, Long communityId, Long inviteeUserId);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ import com.mcwl.communityCenter.domain.PublishComment;
|
|||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:ChenYan
|
||||
* @Project:mcwl-ai
|
||||
|
@ -17,4 +19,32 @@ import org.apache.ibatis.annotations.Param;
|
|||
@Mapper
|
||||
public interface PublishCommentMapper extends BaseMapper<PublishComment> {
|
||||
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
List<PublishComment> selectByTenantIdAndCommunityIdAndOperatorId(@Param("tenantId")
|
||||
Long tenantId,
|
||||
@Param("communityId")
|
||||
Long communityId,
|
||||
@Param("operatorId")
|
||||
Long operatorId);
|
||||
|
||||
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
PublishComment selectByIdAndTenantIdAndCommunityIdAndOperatorId(@Param("id")
|
||||
Long id,
|
||||
@Param("tenantId")
|
||||
Long tenantId,
|
||||
@Param("communityId")
|
||||
Long communityId,
|
||||
@Param("operatorId")
|
||||
Long operatorId);
|
||||
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
Integer deleteByIdAndTenantIdAndCommunityIdAndOperatorId(@Param("id")
|
||||
Long id,
|
||||
@Param("tenantId")
|
||||
Long tenantId,
|
||||
@Param("communityId")
|
||||
Long communityId,
|
||||
@Param("operatorId")
|
||||
Long operatorId);
|
||||
}
|
||||
|
|
|
@ -2,10 +2,14 @@ package com.mcwl.communityCenter.service;
|
|||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.communityCenter.domain.dto.CommentDelRes;
|
||||
import com.mcwl.communityCenter.domain.dto.CommentDetailRes;
|
||||
import com.mcwl.communityCenter.domain.dto.CommentRes;
|
||||
import com.mcwl.communityCenter.domain.vo.PublicModelCommentVo;
|
||||
import com.mcwl.communityCenter.domain.vo.CommentVo;
|
||||
import com.mcwl.communityCenter.domain.PublishComment;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -19,14 +23,13 @@ import java.util.List;
|
|||
|
||||
public interface PublishCommentService extends IService<PublishComment> {
|
||||
/**
|
||||
* 点赞或取消点赞评论
|
||||
* @param userId 用户ID
|
||||
* @param commentId 评论ID
|
||||
* @return 更新后的点赞数
|
||||
* 获取评论详情
|
||||
* @param commentDetailRes 评论详情参数
|
||||
* @return 评论详情
|
||||
*/
|
||||
int toggleLike(Long userId, Long commentId);
|
||||
|
||||
List<PublicModelCommentVo> getComment(PublishComment publishComment);
|
||||
AjaxResult getComment(CommentDetailRes commentDetailRes);
|
||||
|
||||
AjaxResult addComment(CommentRes commentRes);
|
||||
|
||||
AjaxResult removeCommentById(CommentDelRes commentDelRes);
|
||||
}
|
||||
|
|
|
@ -7,8 +7,10 @@ import com.mcwl.common.core.domain.AjaxResult;
|
|||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.communityCenter.domain.Publish;
|
||||
import com.mcwl.communityCenter.domain.dto.CommentDelRes;
|
||||
import com.mcwl.communityCenter.domain.dto.CommentDetailRes;
|
||||
import com.mcwl.communityCenter.domain.dto.CommentRes;
|
||||
import com.mcwl.communityCenter.domain.vo.PublicModelCommentVo;
|
||||
import com.mcwl.communityCenter.domain.vo.CommentVo;
|
||||
import com.mcwl.communityCenter.domain.PublishComment;
|
||||
import com.mcwl.communityCenter.domain.PublishCommentLike;
|
||||
import com.mcwl.communityCenter.mapper.PublishCommentLikeMapper;
|
||||
|
@ -17,7 +19,7 @@ import com.mcwl.communityCenter.mapper.PublishMapper;
|
|||
import com.mcwl.communityCenter.service.PublishCommentService;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -48,67 +50,26 @@ public class PublishCommentServiceImpl extends ServiceImpl<PublishCommentMapper,
|
|||
|
||||
private final PublishMapper publishMapper;
|
||||
|
||||
/**
|
||||
* 点赞或取消点赞评论
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param commentId 评论ID
|
||||
* @return 更新后的点赞数
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int toggleLike(Long userId, Long commentId) {
|
||||
// 检查评论是否存在
|
||||
PublishComment comment = this.getById(commentId);
|
||||
if (comment == null) {
|
||||
throw new RuntimeException("Comment not found");
|
||||
public AjaxResult getComment(CommentDetailRes commentDetailRes) {
|
||||
Long tenantId = commentDetailRes.getTenantId();
|
||||
Long communityId = commentDetailRes.getCommunityId();
|
||||
Long operatorId = commentDetailRes.getOperatorId();
|
||||
|
||||
// 查询评论
|
||||
List<PublishComment> publishComment = publishCommentMapper
|
||||
.selectByTenantIdAndCommunityIdAndOperatorId(tenantId, communityId, operatorId);
|
||||
|
||||
List<CommentVo> commentVoList = BeanUtil.copyToList(publishComment, CommentVo.class);
|
||||
|
||||
for (CommentVo commentVo : commentVoList) {
|
||||
Long userId = commentVo.getUserId();
|
||||
SysUser sysUser = sysUserService.selectUserById(userId);
|
||||
commentVo.setUserName(sysUser.getUserName());
|
||||
commentVo.setUserAvatar(sysUser.getAvatar());
|
||||
}
|
||||
|
||||
// 检查用户是否已经点赞
|
||||
PublishCommentLike like = likeMapper.selectOne(
|
||||
new LambdaQueryWrapper<PublishCommentLike>()
|
||||
.eq(PublishCommentLike::getUserId, userId)
|
||||
.eq(PublishCommentLike::getPublishCommentId, commentId));
|
||||
|
||||
if (like == null) { // 如果没有找到点赞记录,则进行点赞
|
||||
like = new PublishCommentLike();
|
||||
like.setUserId(userId);
|
||||
like.setCommunityId(1L); // 假设有一个默认的社区ID
|
||||
like.setPublishCommentId(commentId);
|
||||
likeMapper.insert(like);
|
||||
|
||||
// 更新评论的点赞数
|
||||
comment.setLikeNum(comment.getLikeNum() == null ? 1 : comment.getLikeNum() + 1);
|
||||
} else { // 如果找到了点赞记录,则取消点赞
|
||||
likeMapper.deleteById(like.getId());
|
||||
|
||||
// 更新评论的点赞数
|
||||
comment.setLikeNum(Math.max(0, comment.getLikeNum() - 1));
|
||||
}
|
||||
|
||||
// 保存更新后的评论信息
|
||||
this.updateById(comment);
|
||||
|
||||
return comment.getLikeNum();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PublicModelCommentVo> getComment(PublishComment publishComment) {
|
||||
List<PublicModelCommentVo> CommentVoList = new ArrayList<>();
|
||||
|
||||
// 查询所有父评论
|
||||
LambdaQueryWrapper<PublishComment> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.eq(PublishComment::getTenantId, publishComment.getTenantId())
|
||||
.isNull(PublishComment::getParentId)
|
||||
.orderByDesc(PublishComment::getCreateTime);
|
||||
// 添加父评论
|
||||
List<PublishComment> modelCommentList = publishCommentMapper.selectList(lqw);
|
||||
for (PublishComment Comment : modelCommentList) {
|
||||
PublicModelCommentVo CommentVo = getModelCommentVo(Comment);
|
||||
CommentVoList.add(CommentVo);
|
||||
}
|
||||
|
||||
return CommentVoList;
|
||||
return AjaxResult.success(commentVoList);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -133,67 +94,22 @@ public class PublishCommentServiceImpl extends ServiceImpl<PublishCommentMapper,
|
|||
return AjaxResult.success("评论成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public AjaxResult removeCommentById(CommentDelRes commentDelRes) {
|
||||
Long id = commentDelRes.getId();
|
||||
Long tenantId = commentDelRes.getTenantId();
|
||||
Long communityId = commentDelRes.getCommunityId();
|
||||
Long operatorId = commentDelRes.getOperatorId();
|
||||
|
||||
/**
|
||||
* 构建CommentVo对象
|
||||
*
|
||||
* @param Comment 父评论对象
|
||||
* @return CommentVo对象
|
||||
*/
|
||||
@NotNull
|
||||
private PublicModelCommentVo getModelCommentVo(PublishComment Comment) {
|
||||
Long userId = Comment.getUserId();
|
||||
SysUser sysUser = sysUserService.selectUserById(userId);
|
||||
PublishComment publishComment = publishCommentMapper.selectByIdAndTenantIdAndCommunityIdAndOperatorId(id, tenantId, communityId, operatorId);
|
||||
|
||||
// 构建CommentVo对象
|
||||
PublicModelCommentVo CommentVo = new PublicModelCommentVo();
|
||||
CommentVo.setUserId(userId);
|
||||
CommentVo.setUserName(sysUser.getUserName());
|
||||
CommentVo.setUserAvatar(sysUser.getAvatar());
|
||||
CommentVo.setCommentId(Comment.getId());
|
||||
CommentVo.setContent(Comment.getContent());
|
||||
// 查询子评论
|
||||
CommentVo.setContentList(getContentList(Comment.getId()));
|
||||
CommentVo.setLikeNum(Comment.getLikeNum());
|
||||
CommentVo.setCreateTime(Comment.getCreateTime());
|
||||
return CommentVo;
|
||||
if (Objects.isNull(publishComment)) {
|
||||
return AjaxResult.error("删除失败,该评论不存在");
|
||||
}
|
||||
|
||||
publishCommentMapper.deleteByIdAndTenantIdAndCommunityIdAndOperatorId(id, tenantId, communityId, operatorId);
|
||||
|
||||
/**
|
||||
* 递归查询子评论
|
||||
*
|
||||
* @param CommentId 父评论id
|
||||
* @return List<ModelCommentVo>
|
||||
*/
|
||||
private List<PublicModelCommentVo> getContentList(Long CommentId) {
|
||||
List<PublicModelCommentVo> CommentVoList = new ArrayList<>();
|
||||
if (Objects.isNull(CommentId)) {
|
||||
return CommentVoList;
|
||||
return AjaxResult.success("删除成功");
|
||||
}
|
||||
|
||||
// 查询子评论
|
||||
LambdaQueryWrapper<PublishComment> lqw = new LambdaQueryWrapper<PublishComment>()
|
||||
.eq(PublishComment::getParentId, CommentId)
|
||||
.orderByDesc(PublishComment::getCreateTime);
|
||||
|
||||
List<PublishComment> CommentList = publishCommentMapper.selectList(lqw);
|
||||
|
||||
for (PublishComment Comment : CommentList) {
|
||||
Long userId = Comment.getUserId();
|
||||
SysUser sysUser = sysUserService.selectUserById(userId);
|
||||
PublicModelCommentVo CommentVo = new PublicModelCommentVo();
|
||||
CommentVo.setUserId(userId);
|
||||
CommentVo.setUserName(sysUser.getUserName());
|
||||
CommentVo.setUserAvatar(sysUser.getAvatar());
|
||||
CommentVo.setCommentId(Comment.getId());
|
||||
CommentVo.setContent(Comment.getContent());
|
||||
CommentVo.setLikeNum(Comment.getLikeNum());
|
||||
CommentVo.setCreateTime(Comment.getCreateTime());
|
||||
|
||||
|
||||
CommentVoList.add(CommentVo);
|
||||
}
|
||||
return CommentVoList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.mcwl.common.utils.StringUtils;
|
|||
import com.mcwl.communityCenter.constant.StatusConstant;
|
||||
import com.mcwl.communityCenter.domain.Community;
|
||||
import com.mcwl.communityCenter.domain.CommunityAdvice;
|
||||
import com.mcwl.communityCenter.domain.Invite;
|
||||
import com.mcwl.communityCenter.domain.Question;
|
||||
import com.mcwl.communityCenter.domain.dto.QuestionDetailRes;
|
||||
import com.mcwl.communityCenter.domain.dto.QuestionPageRes;
|
||||
|
@ -22,6 +23,7 @@ import com.mcwl.communityCenter.domain.dto.QuestionRes;
|
|||
import com.mcwl.communityCenter.domain.vo.QuestionVo;
|
||||
import com.mcwl.communityCenter.mapper.CommunityAdviceMapper;
|
||||
import com.mcwl.communityCenter.mapper.CommunityMapper;
|
||||
import com.mcwl.communityCenter.mapper.InviteMapper;
|
||||
import com.mcwl.communityCenter.mapper.QuestionMapper;
|
||||
import com.mcwl.communityCenter.service.CommunityService;
|
||||
import com.mcwl.communityCenter.service.QuestionService;
|
||||
|
@ -46,6 +48,8 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|||
|
||||
private final ISysUserService sysUserService;
|
||||
|
||||
private final InviteMapper inviteMapper;
|
||||
|
||||
/**
|
||||
* 添加问题
|
||||
*
|
||||
|
@ -70,7 +74,11 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|||
return AjaxResult.error("您不能提问自己的问题");
|
||||
}
|
||||
|
||||
//TODO 再加个判断,提问人(userId)是否在社区中
|
||||
//提问人(userId)是否在社区中
|
||||
Invite invite = inviteMapper.selectByTenantIdAndCommunityIdAndInviteeUserId(tenantId, communityId, userId);
|
||||
if (Objects.isNull(invite)) {
|
||||
return AjaxResult.error("您不是该社区成员,不能提问");
|
||||
}
|
||||
|
||||
Question question = new Question();
|
||||
BeanUtil.copyProperties(questionRes, question);
|
||||
|
|
|
@ -19,4 +19,13 @@
|
|||
and invitee_user_id = #{userId}
|
||||
and del_flag = '0'
|
||||
</select>
|
||||
<select id="selectByTenantIdAndCommunityIdAndInviteeUserId"
|
||||
resultType="com.mcwl.communityCenter.domain.Invite">
|
||||
select id, tenant_id, community_id, invitee_user_id, type, fee_type, create_by, create_time, update_by, update_time, del_flag, remark
|
||||
from cc_invite
|
||||
where tenant_id = #{tenantId}
|
||||
and community_id = #{communityId}
|
||||
and invitee_user_id = #{inviteeUserId}
|
||||
and del_flag = '0'
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,55 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.mcwl.communityCenter.mapper.PublishCommentMapper">
|
||||
<update id="deleteByIdAndTenantIdAndCommunityIdAndOperatorId">
|
||||
update cc_comment set del_flag = '2'
|
||||
where id = #{id}
|
||||
and tenant_id = #{tenantId}
|
||||
and community_id = #{communityId}
|
||||
and operator_id = #{operatorId}
|
||||
and type = 0
|
||||
</update>
|
||||
|
||||
<select id="selectByTenantIdAndCommunityIdAndOperatorId"
|
||||
resultType="com.mcwl.communityCenter.domain.PublishComment">
|
||||
select id,
|
||||
tenant_id,
|
||||
community_id,
|
||||
operator_id,
|
||||
user_id,
|
||||
content,
|
||||
parent_id,
|
||||
type,
|
||||
like_num,
|
||||
create_time
|
||||
from cc_comment
|
||||
where tenant_id = #{tenantId}
|
||||
and community_id = #{communityId}
|
||||
and operator_id = #{operatorId}
|
||||
and type = 0
|
||||
and del_flag = '0'
|
||||
order by create_time
|
||||
</select>
|
||||
<select id="selectByIdAndTenantIdAndCommunityIdAndOperatorId"
|
||||
resultType="com.mcwl.communityCenter.domain.PublishComment">
|
||||
select id,
|
||||
tenant_id,
|
||||
community_id,
|
||||
operator_id,
|
||||
user_id,
|
||||
content,
|
||||
parent_id,
|
||||
type,
|
||||
like_num,
|
||||
create_time
|
||||
from cc_comment
|
||||
where id = #{id}
|
||||
and tenant_id = #{tenantId}
|
||||
and community_id = #{communityId}
|
||||
and operator_id = #{operatorId}
|
||||
and type = 0
|
||||
and del_flag = '0'
|
||||
</select>
|
||||
</mapper>
|
|
@ -3,7 +3,27 @@ package com.mcwl.resource.service;
|
|||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.mcwl.resource.domain.ModelImage;
|
||||
import com.mcwl.resource.domain.ModelImageComment;
|
||||
import com.mcwl.resource.domain.dto.ModelImageCommentRes;
|
||||
import com.mcwl.resource.domain.vo.ModelImageCommentVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface ModelImageCommentService extends IService<ModelImageComment> {
|
||||
|
||||
|
||||
/**
|
||||
* 评论
|
||||
* @param modelImageCommentRes 评论对象
|
||||
*/
|
||||
void comment(ModelImageCommentRes modelImageCommentRes);
|
||||
|
||||
/**
|
||||
* 获取评论
|
||||
* @param imageId 图片id
|
||||
* @return 评论区
|
||||
*/
|
||||
List<ModelImageCommentVo> getComment(Long imageId);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -31,19 +31,6 @@ public interface ModelImageService extends IService<ModelImage> {
|
|||
*/
|
||||
void publish(ModelImageRes modelImageRes);
|
||||
|
||||
/**
|
||||
* 评论
|
||||
* @param modelImageCommentRes 评论对象
|
||||
*/
|
||||
void comment(ModelImageCommentRes modelImageCommentRes);
|
||||
|
||||
/**
|
||||
* 获取评论
|
||||
* @param imageId 图片id
|
||||
* @return 评论区
|
||||
*/
|
||||
List<ModelImageCommentVo> getComment(Long imageId);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param imagePageRes 分页参数
|
||||
|
|
|
@ -1,15 +1,141 @@
|
|||
package com.mcwl.resource.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
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.vo.ModelImageCommentVo;
|
||||
import com.mcwl.resource.mapper.ModelImageCommentMapper;
|
||||
import com.mcwl.resource.mapper.ModelImageMapper;
|
||||
import com.mcwl.resource.service.ModelImageCommentService;
|
||||
import com.mcwl.resource.service.ModelImageService;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ModelImageCommentServiceImpl extends ServiceImpl<ModelImageCommentMapper, ModelImageComment> implements ModelImageCommentService {
|
||||
|
||||
private final ISysUserService sysUserService;
|
||||
|
||||
@Override
|
||||
public void comment(ModelImageCommentRes modelImageCommentRes) {
|
||||
Long parentId = modelImageCommentRes.getParentId();
|
||||
|
||||
if (Objects.nonNull(parentId)) {
|
||||
ModelImageComment mic = baseMapper.selectById(parentId);
|
||||
if (Objects.isNull(mic)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ModelImageComment modelImageComment = new ModelImageComment();
|
||||
BeanUtil.copyProperties(modelImageCommentRes, modelImageComment);
|
||||
modelImageComment.setUserId(SecurityUtils.getUserId());
|
||||
baseMapper.insert(modelImageComment);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评论
|
||||
*
|
||||
* @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 = baseMapper.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 = baseMapper.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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -47,27 +47,7 @@ public class ModelImageServiceImpl extends ServiceImpl<ModelImageMapper, ModelIm
|
|||
|
||||
private final ISysDictDataService sysDictDataService;
|
||||
|
||||
@Override
|
||||
public void comment(ModelImageCommentRes modelImageCommentRes) {
|
||||
Long parentId = modelImageCommentRes.getParentId();
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateById(ModelImageRes modelImageRes) {
|
||||
|
@ -76,8 +56,6 @@ public class ModelImageServiceImpl extends ServiceImpl<ModelImageMapper, ModelIm
|
|||
}
|
||||
ModelImage modelImage = new ModelImage();
|
||||
BeanUtil.copyProperties(modelImageRes, modelImage);
|
||||
modelImage.setUpdateBy(SecurityUtils.getUsername());
|
||||
modelImage.setUpdateTime(new Date());
|
||||
modelImageMapper.updateById(modelImage);
|
||||
}
|
||||
|
||||
|
@ -87,10 +65,6 @@ public class ModelImageServiceImpl extends ServiceImpl<ModelImageMapper, ModelIm
|
|||
ModelImage modelImage = new ModelImage();
|
||||
BeanUtil.copyProperties(modelImageRes, modelImage);
|
||||
modelImage.setUserId(SecurityUtils.getUserId());
|
||||
modelImage.setCreateBy(SecurityUtils.getUsername());
|
||||
modelImage.setCreateTime(new Date());
|
||||
modelImage.setUpdateBy(SecurityUtils.getUsername());
|
||||
modelImage.setUpdateTime(new Date());
|
||||
modelImage.setStatus(3);
|
||||
modelImageMapper.insert(modelImage);
|
||||
|
||||
|
@ -98,31 +72,7 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -176,31 +126,6 @@ public class ModelImageServiceImpl extends ServiceImpl<ModelImageMapper, ModelIm
|
|||
return rspData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelImageVo getDetail(Long imageId) {
|
||||
|
||||
|
@ -229,42 +154,6 @@ public class ModelImageServiceImpl extends ServiceImpl<ModelImageMapper, ModelIm
|
|||
return modelImageVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归查询子评论
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue