Merge branch 'feature/community-center' into preview

master
yang 2025-01-19 20:01:04 +08:00
commit dc2b5c9daa
15 changed files with 239 additions and 147 deletions

View File

@ -0,0 +1,81 @@
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.CommentRes;
import com.mcwl.communityCenter.domain.vo.PublicModelCommentVo;
import com.mcwl.communityCenter.domain.PublishComment;
import com.mcwl.communityCenter.service.PublishCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
/**
*
*/
@Api(tags = "社群评论")
@RequestMapping("publishComment")
@RestController
@RequiredArgsConstructor
public class PublishCommentController extends BaseController {
private final PublishCommentService publishCommentService;
/**
*
*
* @param commentRes
* @return
*/
@ApiOperation(value = "添加评论")
@PostMapping("/save")
public AjaxResult save(@RequestBody @Valid CommentRes commentRes) {
return publishCommentService.addComment(commentRes);
}
/**
*
*
* @param publishComment
* @return
*/
@ApiOperation(value = "获取评论")
@GetMapping("/comment/{Id}")
public List<PublicModelCommentVo> getComment(@RequestBody PublishComment publishComment) {
return publishCommentService.getComment(publishComment);
}
/**
*
*
* @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);
}
@ApiOperation(value = "删除评论")
@DeleteMapping("/{id}")
public ResponseEntity<String> delete(@PathVariable Long id) {
publishCommentService.removeById(id);
return ResponseEntity.ok("删除成功");
}
}

View File

@ -1,7 +1,7 @@
package com.mcwl.web.controller.communityCenter;
import com.mcwl.common.core.controller.BaseController;
import com.mcwl.communityCenter.service.PublishCommissionLikeService;
import com.mcwl.communityCenter.service.PublishCommentLikeService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
@ -18,10 +18,10 @@ import org.springframework.web.bind.annotation.RestController;
@Api(tags = "社群评论区点赞")
@RestController
@RequestMapping("PublishCommissionLike")
public class PublishCommissionLikeController extends BaseController {
public class PublishCommentLikeController extends BaseController {
@Autowired
private PublishCommissionLikeService publishCommissionLikeService;
private PublishCommentLikeService publishCommentLikeService;

View File

@ -1,79 +0,0 @@
package com.mcwl.web.controller.communityCenter;
import com.mcwl.common.core.controller.BaseController;
import com.mcwl.communityCenter.domain.PublicModelCommentVo;
import com.mcwl.communityCenter.domain.PublishCommission;
import com.mcwl.communityCenter.service.PublishCommissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @AuthorChenYan
* @Projectmcwl-ai
* @Packagecom.mcwl.web.controller.communityCenter
* @FilenamePublishCommissionController
* @Description TODO
* @Date2025/1/17 14:21
*/
@Api(tags = "社群评论")
@RequestMapping("PublishCommission")
@RestController
public class PublishCommissionController extends BaseController {
@Autowired
private PublishCommissionService publishCommissionService;
/**
*
* @param publishCommission
* @return
*/
@ApiOperation(value = "获取评论")
@GetMapping("/comment/{Id}")
public List<PublicModelCommentVo> getComment(@RequestBody PublishCommission publishCommission) {
return publishCommissionService.getComment(publishCommission);
}
/**
*
* @param publishCommission
* @return
*/
@ApiOperation(value = "添加评论")
@PostMapping("/save")
public ResponseEntity<String> save(@RequestBody PublishCommission publishCommission) {
publishCommissionService.save(publishCommission);
return ResponseEntity.ok("评论成功");
}
/**
*
* @param userId ID
* @param commentId ID
* @return
*/
@ApiOperation(value = "点赞或取消点赞评论")
@PostMapping("/{commentId}/like")
public ResponseEntity<Integer> toggleLike(@PathVariable Long commentId, @RequestParam Long userId) {
int updatedLikes = publishCommissionService.toggleLike(userId, commentId);
return ResponseEntity.ok(updatedLikes);
}
@ApiOperation(value = "删除评论")
@DeleteMapping("/{id}")
public ResponseEntity<String> delete(@PathVariable Long id) {
publishCommissionService.removeById(id);
return ResponseEntity.ok("删除成功");
}
}

View File

@ -9,18 +9,12 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @AuthorChenYan
* @Projectmcwl-ai
* @Packagecom.mcwl.web.controller.communityCenter
* @FilenamePublishCommission
* @Description TODO
* @Date2025/1/17 14:11
*/
@ApiModel(description = "评论区评论")
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("cc_publish_commission")
public class PublishCommission extends BaseEntity {
@TableName("cc_publish_comment")
public class PublishComment extends BaseEntity {
/**
* id
*/
@ -32,6 +26,16 @@ public class PublishCommission extends BaseEntity {
*/
@ApiModelProperty(value = "租户id")
private Long tenantId;
/**
* id
*/
@ApiModelProperty(value = "社区id")
private Long communityId;
/**
* id
*/
@ApiModelProperty(value = "运营id")
private Long operatorId;
/**
* id
*/
@ -52,11 +56,12 @@ public class PublishCommission extends BaseEntity {
*/
@ApiModelProperty(value = "点赞数")
private Integer likeNum;
/**
* 0 2
* 0 1
*/
@ApiModelProperty(value = "删除标志0代表存在 2代表删除")
private String delFlag;
@ApiModelProperty(value = "评论类型 0发布 1提问")
private Integer type;
}

View File

@ -19,8 +19,8 @@ import lombok.EqualsAndHashCode;
@ApiModel(description = "评论点赞")
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("cc_publish_commission_like")
public class PublishCommissionLike extends BaseEntity {
@TableName("cc_publish_comment_like")
public class PublishCommentLike extends BaseEntity {
/**
* id
@ -42,5 +42,5 @@ public class PublishCommissionLike extends BaseEntity {
* id
*/
@ApiModelProperty(value = "评论id")
private Long publishCommissionId;
private Long publishCommentId;
}

View File

@ -0,0 +1,44 @@
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 CommentRes {
/**
* 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;
/**
*
*/
@ApiModelProperty(value = "内容", required = true)
@NotBlank(message = "内容不能为空")
private String content;
}

View File

@ -12,7 +12,6 @@ import javax.validation.constraints.NotNull;
*
*/
@Data
@TableName("cc_community")
@ApiModel(value = "社区请求参数")
public class CommunityRes {

View File

@ -1,4 +1,4 @@
package com.mcwl.communityCenter.domain;
package com.mcwl.communityCenter.domain.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;

View File

@ -29,6 +29,8 @@ public class CustomTenantHandler implements TenantLineHandler {
tables.add("cc_publish");
// 提问表
tables.add("cc_question");
// 发布评论表
tables.add("cc_publish_comment");
}

View File

@ -1,7 +1,7 @@
package com.mcwl.communityCenter.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mcwl.communityCenter.domain.PublishCommissionLike;
import com.mcwl.communityCenter.domain.PublishCommentLike;
import org.apache.ibatis.annotations.Mapper;
/**
@ -13,5 +13,5 @@ import org.apache.ibatis.annotations.Mapper;
* @Date2025/1/17 14:26
*/
@Mapper
public interface PublishCommissionLikeMapper extends BaseMapper<PublishCommissionLike> {
public interface PublishCommentLikeMapper extends BaseMapper<PublishCommentLike> {
}

View File

@ -1,8 +1,10 @@
package com.mcwl.communityCenter.mapper;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mcwl.communityCenter.domain.PublishCommission;
import com.mcwl.communityCenter.domain.PublishComment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* @AuthorChenYan
@ -13,5 +15,6 @@ import org.apache.ibatis.annotations.Mapper;
* @Date2025/1/17 14:29
*/
@Mapper
public interface PublishCommissionMapper extends BaseMapper<PublishCommission> {
public interface PublishCommentMapper extends BaseMapper<PublishComment> {
}

View File

@ -1,7 +1,7 @@
package com.mcwl.communityCenter.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.mcwl.communityCenter.domain.PublishCommissionLike;
import com.mcwl.communityCenter.domain.PublishCommentLike;
import org.springframework.stereotype.Service;
/**
@ -13,6 +13,6 @@ import org.springframework.stereotype.Service;
* @Date2025/1/17 14:23
*/
@Service
public interface PublishCommissionLikeService extends IService<PublishCommissionLike> {
public interface PublishCommentLikeService extends IService<PublishCommentLike> {
}

View File

@ -1,8 +1,10 @@
package com.mcwl.communityCenter.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.mcwl.communityCenter.domain.PublicModelCommentVo;
import com.mcwl.communityCenter.domain.PublishCommission;
import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.communityCenter.domain.dto.CommentRes;
import com.mcwl.communityCenter.domain.vo.PublicModelCommentVo;
import com.mcwl.communityCenter.domain.PublishComment;
import java.util.List;
@ -15,7 +17,7 @@ import java.util.List;
* @Date2025/1/17 14:27
*/
public interface PublishCommissionService extends IService<PublishCommission> {
public interface PublishCommentService extends IService<PublishComment> {
/**
*
* @param userId ID
@ -24,6 +26,7 @@ public interface PublishCommissionService extends IService<PublishCommission> {
*/
int toggleLike(Long userId, Long commentId);
List<PublicModelCommentVo> getComment(PublishCommission publishCommission);
List<PublicModelCommentVo> getComment(PublishComment publishComment);
AjaxResult addComment(CommentRes commentRes);
}

View File

@ -1,9 +1,9 @@
package com.mcwl.communityCenter.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mcwl.communityCenter.domain.PublishCommissionLike;
import com.mcwl.communityCenter.mapper.PublishCommissionLikeMapper;
import com.mcwl.communityCenter.service.PublishCommissionLikeService;
import com.mcwl.communityCenter.domain.PublishCommentLike;
import com.mcwl.communityCenter.mapper.PublishCommentLikeMapper;
import com.mcwl.communityCenter.service.PublishCommentLikeService;
import org.springframework.stereotype.Service;
/**
@ -15,5 +15,5 @@ import org.springframework.stereotype.Service;
* @Date2025/1/17 14:25
*/
@Service
public class PublishCommissionLikeServiceImpl extends ServiceImpl<PublishCommissionLikeMapper, PublishCommissionLike>implements PublishCommissionLikeService {
public class PublishCommentLikeServiceImpl extends ServiceImpl<PublishCommentLikeMapper, PublishCommentLike>implements PublishCommentLikeService {
}

View File

@ -1,15 +1,22 @@
package com.mcwl.communityCenter.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.AjaxResult;
import com.mcwl.common.core.domain.entity.SysUser;
import com.mcwl.communityCenter.domain.PublicModelCommentVo;
import com.mcwl.communityCenter.domain.PublishCommission;
import com.mcwl.communityCenter.domain.PublishCommissionLike;
import com.mcwl.communityCenter.mapper.PublishCommissionLikeMapper;
import com.mcwl.communityCenter.mapper.PublishCommissionMapper;
import com.mcwl.communityCenter.service.PublishCommissionService;
import com.mcwl.common.utils.SecurityUtils;
import com.mcwl.communityCenter.domain.Publish;
import com.mcwl.communityCenter.domain.dto.CommentRes;
import com.mcwl.communityCenter.domain.vo.PublicModelCommentVo;
import com.mcwl.communityCenter.domain.PublishComment;
import com.mcwl.communityCenter.domain.PublishCommentLike;
import com.mcwl.communityCenter.mapper.PublishCommentLikeMapper;
import com.mcwl.communityCenter.mapper.PublishCommentMapper;
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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -19,7 +26,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
/**
*
*
* @AuthorChenYan
* @Projectmcwl-ai
* @Packagecom.mcwl.communityCenter.service.impl
@ -28,17 +37,20 @@ import java.util.Objects;
* @Date2025/1/17 14:28
*/
@Service
public class PublishCommissionServiceImpl extends ServiceImpl<PublishCommissionMapper, PublishCommission> implements PublishCommissionService {
@Autowired
private PublishCommissionMapper publishCommentMapper;
@Autowired
private PublishCommissionLikeMapper likeMapper;
@RequiredArgsConstructor
public class PublishCommentServiceImpl extends ServiceImpl<PublishCommentMapper, PublishComment> implements PublishCommentService {
@Autowired
private ISysUserService sysUserService;
private final PublishCommentMapper publishCommentMapper;
private final PublishCommentLikeMapper likeMapper;
private final ISysUserService sysUserService;
private final PublishMapper publishMapper;
/**
*
*
* @param userId ID
* @param commentId ID
* @return
@ -47,22 +59,22 @@ public class PublishCommissionServiceImpl extends ServiceImpl<PublishCommissionM
@Transactional
public int toggleLike(Long userId, Long commentId) {
// 检查评论是否存在
PublishCommission comment = this.getById(commentId);
PublishComment comment = this.getById(commentId);
if (comment == null) {
throw new RuntimeException("Comment not found");
}
// 检查用户是否已经点赞
PublishCommissionLike like = likeMapper.selectOne(
new LambdaQueryWrapper<PublishCommissionLike>()
.eq(PublishCommissionLike::getUserId, userId)
.eq(PublishCommissionLike::getPublishCommissionId, commentId));
PublishCommentLike like = likeMapper.selectOne(
new LambdaQueryWrapper<PublishCommentLike>()
.eq(PublishCommentLike::getUserId, userId)
.eq(PublishCommentLike::getPublishCommentId, commentId));
if (like == null) { // 如果没有找到点赞记录,则进行点赞
like = new PublishCommissionLike();
like = new PublishCommentLike();
like.setUserId(userId);
like.setCommunityId(1L); // 假设有一个默认的社区ID
like.setPublishCommissionId(commentId);
like.setPublishCommentId(commentId);
likeMapper.insert(like);
// 更新评论的点赞数
@ -81,17 +93,17 @@ public class PublishCommissionServiceImpl extends ServiceImpl<PublishCommissionM
}
@Override
public List<PublicModelCommentVo> getComment(PublishCommission publishCommission) {
public List<PublicModelCommentVo> getComment(PublishComment publishComment) {
List<PublicModelCommentVo> CommentVoList = new ArrayList<>();
// 查询所有父评论
LambdaQueryWrapper<PublishCommission> lqw = new LambdaQueryWrapper<>();
lqw.eq(PublishCommission::getTenantId, publishCommission.getTenantId())
.isNull(PublishCommission::getParentId)
.orderByDesc(PublishCommission::getCreateTime);
LambdaQueryWrapper<PublishComment> lqw = new LambdaQueryWrapper<>();
lqw.eq(PublishComment::getTenantId, publishComment.getTenantId())
.isNull(PublishComment::getParentId)
.orderByDesc(PublishComment::getCreateTime);
// 添加父评论
List<PublishCommission> modelCommentList = publishCommentMapper.selectList(lqw);
for (PublishCommission Comment : modelCommentList) {
List<PublishComment> modelCommentList = publishCommentMapper.selectList(lqw);
for (PublishComment Comment : modelCommentList) {
PublicModelCommentVo CommentVo = getModelCommentVo(Comment);
CommentVoList.add(CommentVo);
}
@ -99,6 +111,28 @@ public class PublishCommissionServiceImpl extends ServiceImpl<PublishCommissionM
return CommentVoList;
}
@Override
public AjaxResult addComment(CommentRes commentRes) {
Long tenantId = commentRes.getTenantId();
Long communityId = commentRes.getCommunityId();
Long operatorId = commentRes.getOperatorId();
Publish publish = publishMapper.selectByIdAndTenantIdAndCommunityId(operatorId, tenantId, communityId);
if (Objects.isNull(publish)) {
return AjaxResult.error("评论失败,该内容不存在");
}
PublishComment publishComment = new PublishComment();
BeanUtil.copyProperties(commentRes, publishComment);
publishComment.setOperatorId(operatorId);
publishComment.setUserId(SecurityUtils.getUserId());
publishComment.setType(0);
publishCommentMapper.insert(publishComment);
return AjaxResult.success("评论成功");
}
/**
* CommentVo
@ -107,7 +141,7 @@ public class PublishCommissionServiceImpl extends ServiceImpl<PublishCommissionM
* @return CommentVo
*/
@NotNull
private PublicModelCommentVo getModelCommentVo(PublishCommission Comment) {
private PublicModelCommentVo getModelCommentVo(PublishComment Comment) {
Long userId = Comment.getUserId();
SysUser sysUser = sysUserService.selectUserById(userId);
@ -139,13 +173,13 @@ public class PublishCommissionServiceImpl extends ServiceImpl<PublishCommissionM
}
// 查询子评论
LambdaQueryWrapper<PublishCommission> lqw = new LambdaQueryWrapper<PublishCommission>()
.eq(PublishCommission::getParentId, CommentId)
.orderByDesc(PublishCommission::getCreateTime);
LambdaQueryWrapper<PublishComment> lqw = new LambdaQueryWrapper<PublishComment>()
.eq(PublishComment::getParentId, CommentId)
.orderByDesc(PublishComment::getCreateTime);
List<PublishCommission> CommentList = publishCommentMapper.selectList(lqw);
List<PublishComment> CommentList = publishCommentMapper.selectList(lqw);
for (PublishCommission Comment : CommentList) {
for (PublishComment Comment : CommentList) {
Long userId = Comment.getUserId();
SysUser sysUser = sysUserService.selectUserById(userId);
PublicModelCommentVo CommentVo = new PublicModelCommentVo();