Commit 2424ac75 authored by liwei's avatar liwei

修改了评论功能

parent 6cb8abef
......@@ -346,7 +346,7 @@ CREATE TABLE `opm_article_comment` (
`article_id` bigint NULL DEFAULT NULL COMMENT '动态ID',
`content` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '评论内容',
`like_count` int NULL DEFAULT NULL COMMENT '点赞数',
`reply_count` int NULL DEFAULT NULL COMMENT '回复数',
`comment_count` int NULL DEFAULT NULL COMMENT '评论数',
`parent_id` bigint NULL DEFAULT NULL COMMENT '父级id',
`exam_status` varchar(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '审核状态,1已审核,0未审核',
PRIMARY KEY (`business_id`) USING BTREE
......@@ -63,7 +63,7 @@ public class AppOpmArticleController extends CyPaginationController<OpmArticle>
@Operation(summary="查询单一opmArticle管理", description="查询单一opmArticle管理")
@Parameters({@Parameter(name = "businessId", description = "businessId", required = true)})
@GetMapping("/open/opmArticle/detail/{businessId:\\w+}")
public CyResult detail(@PathVariable String businessId) {
public CyResult detail(@PathVariable Integer businessId) {
return CyResultGenUtil.builder(new CyPersistModel(1),
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
......
......@@ -7,6 +7,7 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import jakarta.servlet.http.HttpServletResponse;
import org.rcisoft.business.opmArticle.entity.ArticleCommentDTO;
import org.rcisoft.business.opmArticle.entity.LikeDTO;
import org.rcisoft.business.opmArticle.entity.OpmArticle;
import org.rcisoft.business.opmArticle.service.OpmArticleService;
......@@ -24,6 +25,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.persistence.criteria.CriteriaBuilder;
import javax.validation.Valid;
import java.util.List;
......@@ -97,7 +99,7 @@ public class OpmArticleController extends CyPaginationController<OpmArticle> {
@Operation(summary="查询单一opmArticle管理", description="查询单一opmArticle管理")
@Parameters({@Parameter(name = "businessId", description = "businessId", required = true)})
@GetMapping("/detail/{businessId:\\w+}")
public CyResult detail(@PathVariable String businessId) {
public CyResult detail(@PathVariable Integer businessId) {
return CyResultGenUtil.builder(new CyPersistModel(1),
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
......@@ -168,14 +170,14 @@ public class OpmArticleController extends CyPaginationController<OpmArticle> {
}
@PreAuthorize("@cyPerm.hasPerm('cms:opmArticle:add')")
@CyOpeLogAnno(title = "system-opmArticle管理管理-新增opmArticle管理", businessType = CyLogTypeEnum.INSERT)
@Operation(summary="添加opmArticle管理", description="添加opmArticle管理")
@CyOpeLogAnno(title = "system-opmArticle管理管理-新增评论", businessType = CyLogTypeEnum.INSERT)
@Operation(summary="添加动态评论", description="添加动态评论")
@PostMapping(value = "/comment")
public CyResult comment(@Valid @RequestBody OpmArticle opmArticle, BindingResult bindingResult) {
CyPersistModel data = opmArticleServiceImpl.addComment(opmArticle);
public CyResult comment(@Valid @RequestBody ArticleCommentDTO dto, BindingResult bindingResult) {
CyPersistModel data = opmArticleServiceImpl.addComment(dto);
return CyResultGenUtil.builder(data,
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
opmArticle);
dto);
}
}
......@@ -3,12 +3,14 @@ package org.rcisoft.business.opmArticle.dao;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.rcisoft.business.opmArticle.entity.ArticleCommentDTO;
import org.rcisoft.business.opmArticle.entity.ArticleCommentVO;
import org.rcisoft.business.opmArticle.entity.LikeDTO;
import org.rcisoft.business.opmArticle.entity.OpmArticle;
import org.rcisoft.core.mapper.CyBaseMapper;
import org.rcisoft.core.model.CyPageInfo;
import javax.persistence.criteria.CriteriaBuilder;
import java.util.List;
......@@ -28,10 +30,15 @@ public interface OpmArticleRepository extends CyBaseMapper<OpmArticle> {
IPage<OpmArticle> queryOpmArticlePaged(CyPageInfo cyPageInfo, @Param("entity") OpmArticle opmArticle);
OpmArticle selectByIdWithUrl(@Param("articleId") String articleId,@Param("loginUserId") String loginUserId);
OpmArticle selectArticleDetail(@Param("articleId") Integer articleId, @Param("loginUserId") String loginUserId);
List<ArticleCommentVO> SelectArticleComment(Integer businessId);
//查询评论
List<ArticleCommentVO> selectArticleComment(@Param("articleId") Integer articleId);
//查询评论下的子评论
List<ArticleCommentVO> selectArticleChildrenComment(@Param("articleId") Integer articleId, @Param("parentId") Integer parentId);
//删除评论
int deleteComment(OpmArticle opmArticle);
//添加点赞记录
......@@ -46,10 +53,13 @@ public interface OpmArticleRepository extends CyBaseMapper<OpmArticle> {
//点赞数-1
int reduceLikeCount(Integer articleId);
//评论数+1
int addCommentCount(Integer articleId);
//动态表评论数+1
int addArticleCommentCount(Integer articleId);
//评论表评论数+1
int addCommentCount(Integer commentId);
//添加动态评论
int addComment(@Param("entity") OpmArticle opmArticle);
int addComment(@Param("entity") ArticleCommentDTO dto);
}
package org.rcisoft.business.opmArticle.entity;
import lombok.Data;
import java.util.Date;
@Data
public class ArticleCommentDTO {
//动态ID
private Integer articleId;
//评论内容
private String commentContent;
//被评论人ID
private Integer commentedUserId;
//父级ID
private Integer parentId;
//创建时间
private Date createDate;
//修改时间
private Date updateDate;
//创建人
private Integer createBy;
//修改人
private Integer updateBy;
}
......@@ -8,7 +8,6 @@ import java.util.List;
@Data
public class ArticleCommentVO {
/**
* 业务Id
*/
......@@ -55,9 +54,29 @@ public class ArticleCommentVO {
private Integer likeCount;
/**
* 回复数
* 评论数
*/
private Integer commentCount;
/**
* 被评论会员号
*/
private String commentedMemCode;
/**
* 被评论人昵称
*/
private String commentedMemNickName;
/**
* 评论人ID
*/
private Integer userId;
/**
* 被评论人ID
*/
private Integer replyCount;
private Integer commentedUserId;
/**
* 子评论
......
......@@ -2,6 +2,7 @@ package org.rcisoft.business.opmArticle.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.rcisoft.business.cmsBanner.entity.CmsBanner;
import org.rcisoft.business.opmArticle.entity.ArticleCommentDTO;
import org.rcisoft.business.opmArticle.entity.LikeDTO;
import org.rcisoft.business.opmArticle.entity.OpmArticle;
import org.rcisoft.core.model.CyPageInfo;
......@@ -47,7 +48,7 @@ public interface OpmArticleService {
* @param id
* @return
*/
OpmArticle findById(String id);
OpmArticle findById(Integer id);
/**
* 分页查询 opmArticle管理
......@@ -88,9 +89,9 @@ public interface OpmArticleService {
/**
* 添加评论
* @param opmArticle
* @param dto
* @return
*/
CyPersistModel addComment(OpmArticle opmArticle);
CyPersistModel addComment(ArticleCommentDTO dto);
}
......@@ -10,6 +10,7 @@ import org.apache.commons.lang3.StringUtils;
import org.rcisoft.baidu.censor.dto.CensorResult;
import org.rcisoft.baidu.censor.service.ContentCensorService;
import org.rcisoft.business.opmArticle.dao.OpmArticleRepository;
import org.rcisoft.business.opmArticle.entity.ArticleCommentDTO;
import org.rcisoft.business.opmArticle.entity.ArticleCommentVO;
import org.rcisoft.business.opmArticle.entity.LikeDTO;
import org.rcisoft.business.opmArticle.entity.OpmArticle;
......@@ -136,14 +137,15 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
* @return
*/
@Override
public OpmArticle findById(String articleId){
public OpmArticle findById(Integer articleId){
String loginUserId = CyUserUtil.getAuthenBusinessId();
//根据动态id 查询动态详情
OpmArticle opmArticle = baseMapper.selectByIdWithUrl(articleId,loginUserId);
OpmArticle opmArticle = baseMapper.selectArticleDetail(articleId,loginUserId);
//查询该动态的评论
List<ArticleCommentVO> list = baseMapper.SelectArticleComment(opmArticle.getBusinessId());
List<ArticleCommentVO> list = baseMapper.selectArticleComment(opmArticle.getBusinessId());
list.forEach(item -> {
List<ArticleCommentVO> childrenCommentList = new ArrayList<>();
//查询该条评论下的子评论
List<ArticleCommentVO> childrenCommentList = baseMapper.selectArticleChildrenComment(opmArticle.getBusinessId(),item.getBusinessId());
item.setChildrenCommentList(childrenCommentList);
});
opmArticle.setArticleCommentVOList(list);
......@@ -241,19 +243,23 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
/**
* 添加评论
* @param opmArticle
* @param dto
* @return
*/
@Override
public CyPersistModel addComment(OpmArticle opmArticle) {
opmArticle.setUserId(CyUserUtil.getAuthenBusinessId());
opmArticle.setCreateDate(new Date());
opmArticle.setUpdateDate(new Date());
opmArticle.setCreateBy(CyUserUtil.getAuthenBusinessId());
opmArticle.setUpdateBy(CyUserUtil.getAuthenBusinessId());
int line = baseMapper.addComment(opmArticle);
public CyPersistModel addComment(ArticleCommentDTO dto) {
dto.setCommentedUserId(Integer.valueOf(CyUserUtil.getAuthenBusinessId()));
dto.setCreateDate(new Date());
dto.setUpdateDate(new Date());
dto.setCreateBy(Integer.valueOf(CyUserUtil.getAuthenBusinessId()));
dto.setUpdateBy(Integer.valueOf(CyUserUtil.getAuthenBusinessId()));
int line = baseMapper.addComment(dto);
//修改主表的评论数
baseMapper.addCommentCount(opmArticle.getArticleId());
baseMapper.addArticleCommentCount(dto.getArticleId());
//修改子表的评论数 给父级评论数+1
if (dto.getParentId() != null){
baseMapper.addCommentCount(dto.getParentId());
}
return new CyPersistModel(line);
}
}
......@@ -27,11 +27,16 @@
SET like_count = like_count - 1
WHERE business_id = #{articleId};
</update>
<update id="addCommentCount">
<update id="addArticleCommentCount">
UPDATE opm_article
SET comment_count = comment_count + 1
WHERE business_id = #{articleId};
</update>
<update id="addCommentCount">
UPDATE opm_article_comment
SET comment_count = comment_count + 1
WHERE business_id = #{commentId};
</update>
<select id="queryOpmArticle" resultMap="BaseResultMap">
select opa.*,sot.topic_name as topic,mi.mem_code as memCode
from opm_article opa
......@@ -173,7 +178,7 @@
ORDER BY
opa.create_date DESC
</select>
<select id="selectByIdWithUrl" resultType="org.rcisoft.business.opmArticle.entity.OpmArticle">
<select id="selectArticleDetail" resultType="org.rcisoft.business.opmArticle.entity.OpmArticle">
SELECT
opa.*,
mi.mem_code AS memCode,
......@@ -217,13 +222,15 @@
ORDER BY
opa.create_date DESC
</select>
<select id="SelectArticleComment" resultType="org.rcisoft.business.opmArticle.entity.ArticleCommentVO">
<select id="selectArticleComment" resultType="org.rcisoft.business.opmArticle.entity.ArticleCommentVO">
SELECT opc.business_id,
opc.content,
opc.parent_id,
opc.create_date,
opc.like_count,
opc.reply_count,
opc.comment_count,
opc.create_by AS userId,
opc.user_id AS commentedUserId,
mi.mem_code as memCode,
mi.mem_nick_name as memNickName,
mi.avatar as avatarId,
......@@ -231,9 +238,35 @@
FROM opm_article_comment opc
LEFT JOIN mem_info mi ON mi.user_id = opc.create_by
left join oss_info oi on oi.business_id = mi.avatar
WHERE 1 = 1
AND opc.del_flag = '0'
AND opc.parent_id is null
AND opc.article_id = #{articleId}
</select>
<select id="selectArticleChildrenComment" resultType="org.rcisoft.business.opmArticle.entity.ArticleCommentVO">
SELECT
opc.business_id,
opc.content,
opc.parent_id,
opc.create_date,
opc.like_count,
opc.comment_count,
opc.create_by AS userId,
opc.user_id AS commentedUserId,
mi.mem_code as memCode,
mi.mem_nick_name as memNickName,
mi2.mem_code as commentedMemCode,
mi2.mem_nick_name as commentedMemNickName,
mi.avatar as avatarId,
oi.url as avatarUrl
FROM opm_article_comment opc
LEFT JOIN mem_info mi ON mi.user_id = opc.create_by
LEFT JOIN oss_info oi on oi.business_id = mi.avatar
LEFT JOIN mem_info mi2 ON mi2.user_id = opc.user_id
WHERE 1 = 1
AND opc.del_flag = '0'
AND opc.article_id = #{articleId}
and opc.parent_id = #{parentId}
</select>
<delete id="deleteComment">
update opm_article_comment set del_flag = '1' where business_id = #{businessId}
......@@ -254,7 +287,7 @@
VALUES
(
#{entity.createBy}, #{entity.createDate},#{entity.updateBy},#{entity.updateDate},
#{entity.commentContent},#{entity.parentId},#{entity.articleId},#{entity.userId}
#{entity.commentContent},#{entity.parentId},#{entity.articleId},#{entity.commentedUserId}
)
</insert>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment