Commit 14d2571e authored by 罗林杰's avatar 罗林杰

修改评论点赞

parent fbe63088
...@@ -78,6 +78,21 @@ public class AppOpmArticleController extends CyPaginationController<OpmArticle> ...@@ -78,6 +78,21 @@ public class AppOpmArticleController extends CyPaginationController<OpmArticle>
articleId); articleId);
} }
/**
* 评论-点赞
*/
@PreAuthorize("@cyPerm.hasPerm('app:article:like')")
@CyOpeLogAnno(title = "system-动态管理-评论点赞", businessType = CyLogTypeEnum.QUERY)
@Operation(summary="评论点赞", description="评论点赞")
@PostMapping("/opmArticle/likeComment")
public CyResult likeCommentAdd(Integer articleId, String praiseType) {
CyPersistModel data = opmArticleServiceImpl.likeCommentAdd(articleId,praiseType);
return CyResultGenUtil.builder(data,
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
articleId);
}
@PreAuthorize("@cyPerm.hasPerm('app:article:detail')") @PreAuthorize("@cyPerm.hasPerm('app:article:detail')")
@CyOpeLogAnno(title = "system-opmArticle管理管理-查询opmArticle管理", businessType = CyLogTypeEnum.QUERY) @CyOpeLogAnno(title = "system-opmArticle管理管理-查询opmArticle管理", businessType = CyLogTypeEnum.QUERY)
@Operation(summary="查询单一opmArticle管理", description="查询单一opmArticle管理") @Operation(summary="查询单一opmArticle管理", description="查询单一opmArticle管理")
......
...@@ -33,10 +33,10 @@ public interface OpmArticleRepository extends CyBaseMapper<OpmArticle> { ...@@ -33,10 +33,10 @@ public interface OpmArticleRepository extends CyBaseMapper<OpmArticle> {
OpmArticle selectArticleDetail(@Param("articleId") Integer articleId, @Param("loginUserId") String loginUserId); OpmArticle selectArticleDetail(@Param("articleId") Integer articleId, @Param("loginUserId") String loginUserId);
//查询评论 //查询评论
List<ArticleCommentVO> selectArticleComment(@Param("articleId") Integer articleId); List<ArticleCommentVO> selectArticleComment(@Param("articleId") Integer articleId, @Param("loginUserId") String loginUserId);
//查询评论下的子评论 //查询评论下的子评论
List<ArticleCommentVO> selectArticleChildrenComment(@Param("articleId") Integer articleId, @Param("parentId") Integer parentId); List<ArticleCommentVO> selectArticleChildrenComment(@Param("articleId") Integer articleId, @Param("parentId") Integer parentId, @Param("loginUserId") String loginUserId);
//删除评论 //删除评论
int deleteComment(OpmArticle opmArticle); int deleteComment(OpmArticle opmArticle);
...@@ -47,12 +47,18 @@ public interface OpmArticleRepository extends CyBaseMapper<OpmArticle> { ...@@ -47,12 +47,18 @@ public interface OpmArticleRepository extends CyBaseMapper<OpmArticle> {
//删除点赞记录 //删除点赞记录
int likeDelete(@Param("userId") String userId,@Param("articleId") Integer articleId); int likeDelete(@Param("userId") String userId,@Param("articleId") Integer articleId);
//点赞数+1 //动态点赞数+1
int addLikeCount(Integer articleId); int addLikeCount(Integer articleId);
//点赞数-1 //评论点赞数+1
int addCommentLikeCount(Integer articleId);
//动态点赞数-1
int reduceLikeCount(Integer articleId); int reduceLikeCount(Integer articleId);
//评论点赞数-1
int reduceCommentLikeCount(Integer articleId);
//动态表评论数+1 //动态表评论数+1
int addArticleCommentCount(Integer articleId); int addArticleCommentCount(Integer articleId);
......
package org.rcisoft.business.opmArticle.entity; package org.rcisoft.business.opmArticle.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
...@@ -82,4 +83,9 @@ public class ArticleCommentVO { ...@@ -82,4 +83,9 @@ public class ArticleCommentVO {
* 子评论 * 子评论
*/ */
private List<ArticleCommentVO> childrenCommentList; private List<ArticleCommentVO> childrenCommentList;
/**
* 是否点赞
*/
private String isLike;
} }
...@@ -87,6 +87,13 @@ public interface OpmArticleService { ...@@ -87,6 +87,13 @@ public interface OpmArticleService {
*/ */
CyPersistModel likeAdd(Integer articleId,String praiseType); CyPersistModel likeAdd(Integer articleId,String praiseType);
/**
* 评论增加点赞数
* @param articleId
* @return
*/
CyPersistModel likeCommentAdd(Integer articleId,String praiseType);
/** /**
* 添加评论 * 添加评论
* @param dto * @param dto
......
...@@ -145,10 +145,10 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm ...@@ -145,10 +145,10 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
//根据动态id 查询动态详情 //根据动态id 查询动态详情
OpmArticle opmArticle = baseMapper.selectArticleDetail(articleId,loginUserId); OpmArticle opmArticle = baseMapper.selectArticleDetail(articleId,loginUserId);
//查询该动态的评论 //查询该动态的评论
List<ArticleCommentVO> list = baseMapper.selectArticleComment(opmArticle.getBusinessId()); List<ArticleCommentVO> list = baseMapper.selectArticleComment(opmArticle.getBusinessId(),loginUserId);
list.forEach(item -> { list.forEach(item -> {
//查询该条评论下的子评论 //查询该条评论下的子评论
List<ArticleCommentVO> childrenCommentList = baseMapper.selectArticleChildrenComment(opmArticle.getBusinessId(),item.getBusinessId()); List<ArticleCommentVO> childrenCommentList = baseMapper.selectArticleChildrenComment(opmArticle.getBusinessId(),item.getBusinessId(),loginUserId);
item.setChildrenCommentList(childrenCommentList); item.setChildrenCommentList(childrenCommentList);
}); });
opmArticle.setArticleCommentVOList(list); opmArticle.setArticleCommentVOList(list);
...@@ -253,6 +253,37 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm ...@@ -253,6 +253,37 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
return new CyPersistModel(line); return new CyPersistModel(line);
} }
/**
* 评论增加点赞数
* @param articleId
* @return
*/
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
@Override
public CyPersistModel likeCommentAdd(Integer articleId,String praiseType){
int line = 0;
if (praiseType.equals("praise")){
//点赞
//向点赞表增加一条数据
LikeDTO likeDTO = new LikeDTO();
likeDTO.setUserId(CyUserUtil.getAuthenBusinessId());
likeDTO.setArticleId(articleId);
//增加主表该动态的点赞数
baseMapper.addCommentLikeCount(articleId);
line = baseMapper.likeAdd(likeDTO);
} else if (praiseType.equals("cancel")){
//取消点赞
//删除点赞表中的数据
String userId = CyUserUtil.getAuthenBusinessId();
baseMapper.likeDelete(userId,articleId);
//修改主表中该动态的点赞数
line = baseMapper.reduceCommentLikeCount(articleId);
} else {
throw new CyServiceException("点赞失败,请稍后再试");
}
return new CyPersistModel(line);
}
/** /**
* 添加评论 * 添加评论
* @param dto * @param dto
......
...@@ -37,6 +37,16 @@ ...@@ -37,6 +37,16 @@
SET comment_count = comment_count + 1 SET comment_count = comment_count + 1
WHERE business_id = #{commentId}; WHERE business_id = #{commentId};
</update> </update>
<update id="reduceCommentLikeCount" parameterType="java.lang.Integer">
UPDATE opm_article_comment
SET like_count = like_count - 1
WHERE business_id = #{articleId};
</update>
<update id="addCommentLikeCount" parameterType="java.lang.Integer">
UPDATE opm_article_comment
SET like_count = like_count + 1
WHERE business_id = #{articleId};
</update>
<select id="queryOpmArticle" resultMap="BaseResultMap"> <select id="queryOpmArticle" resultMap="BaseResultMap">
select opa.*,sot.topic_name as topic,mi.mem_code as memCode select opa.*,sot.topic_name as topic,mi.mem_code as memCode
from opm_article opa from opm_article opa
...@@ -241,10 +251,14 @@ ...@@ -241,10 +251,14 @@
mi.mem_code as memCode, mi.mem_code as memCode,
mi.mem_nick_name as memNickName, mi.mem_nick_name as memNickName,
mi.avatar as avatarId, mi.avatar as avatarId,
oi.url as avatarUrl oi.url as avatarUrl,
CASE
WHEN oal.business_id IS NOT NULL THEN 1 ELSE 0
END AS isLike
FROM opm_article_comment opc FROM opm_article_comment opc
LEFT JOIN mem_info mi ON mi.user_id = opc.create_by 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 oss_info oi on oi.business_id = mi.avatar
LEFT JOIN opm_article_like oal on oal.article_id = opc.business_id and oal.user_id = #{loginUserId}
WHERE 1 = 1 WHERE 1 = 1
AND opc.del_flag = '0' AND opc.del_flag = '0'
AND opc.parent_id is null AND opc.parent_id is null
...@@ -265,11 +279,15 @@ ...@@ -265,11 +279,15 @@
mi2.mem_code as commentedMemCode, mi2.mem_code as commentedMemCode,
mi2.mem_nick_name as commentedMemNickName, mi2.mem_nick_name as commentedMemNickName,
mi.avatar as avatarId, mi.avatar as avatarId,
oi.url as avatarUrl oi.url as avatarUrl,
CASE
WHEN oal.business_id IS NOT NULL THEN 1 ELSE 0
END AS isLike
FROM opm_article_comment opc FROM opm_article_comment opc
LEFT JOIN mem_info mi ON mi.user_id = opc.create_by 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 oss_info oi on oi.business_id = mi.avatar
LEFT JOIN mem_info mi2 ON mi2.user_id = opc.user_id LEFT JOIN mem_info mi2 ON mi2.user_id = opc.user_id
LEFT JOIN opm_article_like oal on oal.article_id = opc.business_id and oal.user_id = #{loginUserId}
WHERE 1 = 1 WHERE 1 = 1
AND opc.del_flag = '0' AND opc.del_flag = '0'
AND opc.article_id = #{articleId} AND opc.article_id = #{articleId}
......
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