feat: 图片模块调整

master
yang 2025-01-20 14:30:26 +08:00
parent dc2b5c9daa
commit 5f4404ae1d
20 changed files with 424 additions and 296 deletions

View File

@ -2,8 +2,10 @@ package com.mcwl.web.controller.communityCenter;
import com.mcwl.common.core.controller.BaseController; import com.mcwl.common.core.controller.BaseController;
import com.mcwl.common.core.domain.AjaxResult; 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.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.PublishComment;
import com.mcwl.communityCenter.service.PublishCommentService; import com.mcwl.communityCenter.service.PublishCommentService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -43,39 +45,37 @@ public class PublishCommentController extends BaseController {
/** /**
* *
* *
* @param publishComment * @param commentDetailRes
* @return * @return
*/ */
@ApiOperation(value = "获取评论") @ApiOperation(value = "获取评论详情")
@GetMapping("/comment/{Id}") @PostMapping("/detail")
public List<PublicModelCommentVo> getComment(@RequestBody PublishComment publishComment) { public AjaxResult getComment(@RequestBody @Valid CommentDetailRes commentDetailRes) {
return publishCommentService.getComment(publishComment); return publishCommentService.getComment(commentDetailRes);
} }
/** // /**
* // * 点赞或取消点赞评论
* // * @param commentDetailRes 评论请求参数
* @param userId ID // * @return 更新后的点赞数
* @param commentId ID // */
* @return // @ApiOperation(value = "点赞或取消点赞评论")
*/ // @PostMapping("/like")
@ApiOperation(value = "点赞或取消点赞评论") // public AjaxResult like(@RequestBody @Valid CommentDetailRes commentDetailRes) {
@PostMapping("/{commentId}/like") //
public ResponseEntity<Integer> toggleLike(@PathVariable Long commentId, @RequestParam Long userId) { // return publishCommentService.like(commentDetailRes);
int updatedLikes = publishCommentService.toggleLike(userId, commentId); // }
return ResponseEntity.ok(updatedLikes);
}
@ApiOperation(value = "删除评论") @ApiOperation(value = "删除评论")
@DeleteMapping("/{id}") @PostMapping("/delete")
public ResponseEntity<String> delete(@PathVariable Long id) { public AjaxResult delete(@RequestBody @Valid CommentDelRes commentDelRes) {
publishCommentService.removeById(id);
return ResponseEntity.ok("删除成功"); return publishCommentService.removeCommentById(commentDelRes);
} }
} }

View File

@ -16,7 +16,7 @@ import javax.validation.constraints.NotNull;
import java.util.List; import java.util.List;
/** /**
* *
*/ */
@Api(tags = "图片评论") @Api(tags = "图片评论")
@RestController @RestController
@ -37,7 +37,7 @@ public class ModelImageCommentController {
@ApiOperation(value = "图片评论发布") @ApiOperation(value = "图片评论发布")
@PostMapping("/comment") @PostMapping("/comment")
public AjaxResult comment(@RequestBody ModelImageCommentRes modelImageCommentRes) { public AjaxResult comment(@RequestBody ModelImageCommentRes modelImageCommentRes) {
modelImageService.comment(modelImageCommentRes); modelImageCommentService.comment(modelImageCommentRes);
return AjaxResult.success(); return AjaxResult.success();
} }
@ -68,7 +68,7 @@ public class ModelImageCommentController {
@ApiOperation(value = "获取图片评论") @ApiOperation(value = "获取图片评论")
@GetMapping("/comment/{imageId}") @GetMapping("/comment/{imageId}")
public AjaxResult getComment(@PathVariable @NotNull(message = "图片id不能为空") Long 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); return AjaxResult.success(modelImageCommentVoList);
} }

View File

@ -13,7 +13,7 @@ import lombok.EqualsAndHashCode;
@ApiModel(description = "评论区评论") @ApiModel(description = "评论区评论")
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@TableName("cc_publish_comment") @TableName("cc_comment")
public class PublishComment extends BaseEntity { public class PublishComment extends BaseEntity {
/** /**
* id * id

View File

@ -19,7 +19,7 @@ import lombok.EqualsAndHashCode;
@ApiModel(description = "评论点赞") @ApiModel(description = "评论点赞")
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@TableName("cc_publish_comment_like") @TableName("cc_comment_like")
public class PublishCommentLike extends BaseEntity { public class PublishCommentLike extends BaseEntity {
/** /**

View File

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

View File

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

View File

@ -12,10 +12,6 @@ import javax.validation.constraints.NotNull;
@ApiModel(value = "查看详情请求参数") @ApiModel(value = "查看详情请求参数")
public class QuestionDetailRes { public class QuestionDetailRes {
@NotNull(message = "问题id不能为空")
@ApiModelProperty(value = "问题id", required = true)
private Long questionId;
@NotNull(message = "租户不能为空") @NotNull(message = "租户不能为空")
@ApiModelProperty(value = "租户id", required = true) @ApiModelProperty(value = "租户id", required = true)
private Long tenantId; private Long tenantId;
@ -24,4 +20,8 @@ public class QuestionDetailRes {
@ApiModelProperty(value = "社区id", required = true) @ApiModelProperty(value = "社区id", required = true)
private Long communityId; private Long communityId;
@NotNull(message = "问题id不能为空")
@ApiModelProperty(value = "问题id", required = true)
private Long questionId;
} }

View File

@ -22,7 +22,10 @@ import java.util.List;
@AllArgsConstructor @AllArgsConstructor
@Data @Data
@ApiModel(description = "评论区评论") @ApiModel(description = "评论区评论")
public class PublicModelCommentVo { public class CommentVo {
@ApiModelProperty(value = "评论id")
private Long id;
/** /**
* id * id
@ -42,23 +45,12 @@ public class PublicModelCommentVo {
@ApiModelProperty(value = "用户头像") @ApiModelProperty(value = "用户头像")
private String userAvatar; private String userAvatar;
/**
* id
*/
@ApiModelProperty(value = "评论id")
private Long commentId;
/** /**
* *
*/ */
@ApiModelProperty(value = "评论内容") @ApiModelProperty(value = "评论内容")
private String content; private String content;
/**
*
*/
@ApiModelProperty(value = "子评论")
private List<PublicModelCommentVo> contentList = new ArrayList<>();
/** /**
* *

View File

@ -31,6 +31,9 @@ public class CustomTenantHandler implements TenantLineHandler {
tables.add("cc_question"); tables.add("cc_question");
// 发布评论表 // 发布评论表
tables.add("cc_publish_comment"); tables.add("cc_publish_comment");
// 输出表名
log.info("多租户表:{}", tables);
} }

View File

@ -29,4 +29,14 @@ public interface InviteMapper extends BaseMapper<Invite> {
*/ */
@InterceptorIgnore(tenantLine = "true") @InterceptorIgnore(tenantLine = "true")
Invite isInvite(@Param("tenantId") Long tenantId,@Param("communityId") Long communityId,@Param("userId") Long userId); Invite isInvite(@Param("tenantId") Long tenantId,@Param("communityId") Long communityId,@Param("userId") Long userId);
/**
* ididid
* @param tenantId id
* @param communityId id
* @param inviteeUserId id
* @return
*/
@InterceptorIgnore(tenantLine = "true")
Invite selectByTenantIdAndCommunityIdAndInviteeUserId(Long tenantId, Long communityId, Long inviteeUserId);
} }

View File

@ -6,6 +6,8 @@ import com.mcwl.communityCenter.domain.PublishComment;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* @AuthorChenYan * @AuthorChenYan
* @Projectmcwl-ai * @Projectmcwl-ai
@ -17,4 +19,32 @@ import org.apache.ibatis.annotations.Param;
@Mapper @Mapper
public interface PublishCommentMapper extends BaseMapper<PublishComment> { 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);
} }

View File

@ -2,10 +2,14 @@ package com.mcwl.communityCenter.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.mcwl.common.core.domain.AjaxResult; 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.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.PublishComment;
import org.springframework.http.ResponseEntity;
import javax.validation.Valid;
import java.util.List; import java.util.List;
/** /**
@ -19,14 +23,13 @@ import java.util.List;
public interface PublishCommentService extends IService<PublishComment> { public interface PublishCommentService extends IService<PublishComment> {
/** /**
* *
* @param userId ID * @param commentDetailRes
* @param commentId ID * @return
* @return
*/ */
int toggleLike(Long userId, Long commentId); AjaxResult getComment(CommentDetailRes commentDetailRes);
List<PublicModelCommentVo> getComment(PublishComment publishComment);
AjaxResult addComment(CommentRes commentRes); AjaxResult addComment(CommentRes commentRes);
AjaxResult removeCommentById(CommentDelRes commentDelRes);
} }

View File

@ -7,8 +7,10 @@ import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.common.core.domain.entity.SysUser; import com.mcwl.common.core.domain.entity.SysUser;
import com.mcwl.common.utils.SecurityUtils; import com.mcwl.common.utils.SecurityUtils;
import com.mcwl.communityCenter.domain.Publish; 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.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.PublishComment;
import com.mcwl.communityCenter.domain.PublishCommentLike; import com.mcwl.communityCenter.domain.PublishCommentLike;
import com.mcwl.communityCenter.mapper.PublishCommentLikeMapper; 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.communityCenter.service.PublishCommentService;
import com.mcwl.system.service.ISysUserService; import com.mcwl.system.service.ISysUserService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -48,67 +50,26 @@ public class PublishCommentServiceImpl extends ServiceImpl<PublishCommentMapper,
private final PublishMapper publishMapper; private final PublishMapper publishMapper;
/**
*
*
* @param userId ID
* @param commentId ID
* @return
*/
@Override @Override
@Transactional public AjaxResult getComment(CommentDetailRes commentDetailRes) {
public int toggleLike(Long userId, Long commentId) { Long tenantId = commentDetailRes.getTenantId();
// 检查评论是否存在 Long communityId = commentDetailRes.getCommunityId();
PublishComment comment = this.getById(commentId); Long operatorId = commentDetailRes.getOperatorId();
if (comment == null) {
throw new RuntimeException("Comment not found"); // 查询评论
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());
} }
// 检查用户是否已经点赞 return AjaxResult.success(commentVoList);
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;
} }
@Override @Override
@ -133,67 +94,22 @@ public class PublishCommentServiceImpl extends ServiceImpl<PublishCommentMapper,
return AjaxResult.success("评论成功"); 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();
/** PublishComment publishComment = publishCommentMapper.selectByIdAndTenantIdAndCommunityIdAndOperatorId(id, tenantId, communityId, operatorId);
* CommentVo
*
* @param Comment
* @return CommentVo
*/
@NotNull
private PublicModelCommentVo getModelCommentVo(PublishComment Comment) {
Long userId = Comment.getUserId();
SysUser sysUser = sysUserService.selectUserById(userId);
// 构建CommentVo对象 if (Objects.isNull(publishComment)) {
PublicModelCommentVo CommentVo = new PublicModelCommentVo(); return AjaxResult.error("删除失败,该评论不存在");
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;
}
/**
*
*
* @param CommentId id
* @return List<ModelCommentVo>
*/
private List<PublicModelCommentVo> getContentList(Long CommentId) {
List<PublicModelCommentVo> CommentVoList = new ArrayList<>();
if (Objects.isNull(CommentId)) {
return CommentVoList;
} }
// 查询子评论 publishCommentMapper.deleteByIdAndTenantIdAndCommunityIdAndOperatorId(id, tenantId, communityId, operatorId);
LambdaQueryWrapper<PublishComment> lqw = new LambdaQueryWrapper<PublishComment>()
.eq(PublishComment::getParentId, CommentId)
.orderByDesc(PublishComment::getCreateTime);
List<PublishComment> CommentList = publishCommentMapper.selectList(lqw); return AjaxResult.success("删除成功");
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;
} }
} }

View File

@ -14,6 +14,7 @@ import com.mcwl.common.utils.StringUtils;
import com.mcwl.communityCenter.constant.StatusConstant; import com.mcwl.communityCenter.constant.StatusConstant;
import com.mcwl.communityCenter.domain.Community; import com.mcwl.communityCenter.domain.Community;
import com.mcwl.communityCenter.domain.CommunityAdvice; import com.mcwl.communityCenter.domain.CommunityAdvice;
import com.mcwl.communityCenter.domain.Invite;
import com.mcwl.communityCenter.domain.Question; import com.mcwl.communityCenter.domain.Question;
import com.mcwl.communityCenter.domain.dto.QuestionDetailRes; import com.mcwl.communityCenter.domain.dto.QuestionDetailRes;
import com.mcwl.communityCenter.domain.dto.QuestionPageRes; 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.domain.vo.QuestionVo;
import com.mcwl.communityCenter.mapper.CommunityAdviceMapper; import com.mcwl.communityCenter.mapper.CommunityAdviceMapper;
import com.mcwl.communityCenter.mapper.CommunityMapper; import com.mcwl.communityCenter.mapper.CommunityMapper;
import com.mcwl.communityCenter.mapper.InviteMapper;
import com.mcwl.communityCenter.mapper.QuestionMapper; import com.mcwl.communityCenter.mapper.QuestionMapper;
import com.mcwl.communityCenter.service.CommunityService; import com.mcwl.communityCenter.service.CommunityService;
import com.mcwl.communityCenter.service.QuestionService; import com.mcwl.communityCenter.service.QuestionService;
@ -46,6 +48,8 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
private final ISysUserService sysUserService; private final ISysUserService sysUserService;
private final InviteMapper inviteMapper;
/** /**
* *
* *
@ -70,7 +74,11 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
return AjaxResult.error("您不能提问自己的问题"); return AjaxResult.error("您不能提问自己的问题");
} }
//TODO 再加个判断提问人userId是否在社区中 //提问人userId是否在社区中
Invite invite = inviteMapper.selectByTenantIdAndCommunityIdAndInviteeUserId(tenantId, communityId, userId);
if (Objects.isNull(invite)) {
return AjaxResult.error("您不是该社区成员,不能提问");
}
Question question = new Question(); Question question = new Question();
BeanUtil.copyProperties(questionRes, question); BeanUtil.copyProperties(questionRes, question);

View File

@ -19,4 +19,13 @@
and invitee_user_id = #{userId} and invitee_user_id = #{userId}
and del_flag = '0' and del_flag = '0'
</select> </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> </mapper>

View File

@ -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>

View File

@ -3,7 +3,27 @@ package com.mcwl.resource.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
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.vo.ModelImageCommentVo;
import java.util.List;
public interface ModelImageCommentService extends IService<ModelImageComment> { public interface ModelImageCommentService extends IService<ModelImageComment> {
/**
*
* @param modelImageCommentRes
*/
void comment(ModelImageCommentRes modelImageCommentRes);
/**
*
* @param imageId id
* @return
*/
List<ModelImageCommentVo> getComment(Long imageId);
} }

View File

@ -31,19 +31,6 @@ public interface ModelImageService extends IService<ModelImage> {
*/ */
void publish(ModelImageRes modelImageRes); void publish(ModelImageRes modelImageRes);
/**
*
* @param modelImageCommentRes
*/
void comment(ModelImageCommentRes modelImageCommentRes);
/**
*
* @param imageId id
* @return
*/
List<ModelImageCommentVo> getComment(Long imageId);
/** /**
* *
* @param imagePageRes * @param imagePageRes

View File

@ -1,15 +1,141 @@
package com.mcwl.resource.service.impl; 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.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.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.vo.ModelImageCommentVo;
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.ModelImageCommentService; import com.mcwl.resource.service.ModelImageCommentService;
import com.mcwl.resource.service.ModelImageService; import com.mcwl.resource.service.ModelImageService;
import com.mcwl.system.service.ISysUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Service @Service
@RequiredArgsConstructor
public class ModelImageCommentServiceImpl extends ServiceImpl<ModelImageCommentMapper, ModelImageComment> implements ModelImageCommentService { 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;
}
} }

View File

@ -47,27 +47,7 @@ public class ModelImageServiceImpl extends ServiceImpl<ModelImageMapper, ModelIm
private final ISysDictDataService sysDictDataService; 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 @Override
public void updateById(ModelImageRes modelImageRes) { public void updateById(ModelImageRes modelImageRes) {
@ -76,8 +56,6 @@ public class ModelImageServiceImpl extends ServiceImpl<ModelImageMapper, ModelIm
} }
ModelImage modelImage = new ModelImage(); ModelImage modelImage = new ModelImage();
BeanUtil.copyProperties(modelImageRes, modelImage); BeanUtil.copyProperties(modelImageRes, modelImage);
modelImage.setUpdateBy(SecurityUtils.getUsername());
modelImage.setUpdateTime(new Date());
modelImageMapper.updateById(modelImage); modelImageMapper.updateById(modelImage);
} }
@ -87,10 +65,6 @@ 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.setUserId(SecurityUtils.getUserId());
modelImage.setCreateBy(SecurityUtils.getUsername());
modelImage.setCreateTime(new Date());
modelImage.setUpdateBy(SecurityUtils.getUsername());
modelImage.setUpdateTime(new Date());
modelImage.setStatus(3); modelImage.setStatus(3);
modelImageMapper.insert(modelImage); 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; 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 @Override
public ModelImageVo getDetail(Long imageId) { public ModelImageVo getDetail(Long imageId) {
@ -229,42 +154,6 @@ public class ModelImageServiceImpl extends ServiceImpl<ModelImageMapper, ModelIm
return modelImageVo; 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;
}
} }