Commit c57723b9 authored by liwei's avatar liwei

修改了评论点赞bug

parent d7281c19
......@@ -85,12 +85,12 @@ public class AppOpmArticleController extends CyPaginationController<OpmArticle>
@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);
public CyResult likeCommentAdd(Integer commentId,String praiseType) {
CyPersistModel data = opmArticleServiceImpl.likeCommentAdd(commentId,praiseType);
return CyResultGenUtil.builder(data,
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
articleId);
commentId);
}
@PreAuthorize("@cyPerm.hasPerm('app:article:detail')")
......
......@@ -45,19 +45,19 @@ public interface OpmArticleRepository extends CyBaseMapper<OpmArticle> {
int likeAdd(@Param("entity") LikeDTO likeDTO);
//删除点赞记录
int likeDelete(@Param("userId") String userId,@Param("articleId") Integer articleId);
int likeDelete(@Param("userId") String userId,@Param("commentId") Integer commentId);
//动态点赞数+1
int addLikeCount(Integer articleId);
//评论点赞数+1
int addCommentLikeCount(Integer articleId);
int addCommentLikeCount(Integer commentId);
//动态点赞数-1
int reduceLikeCount(Integer articleId);
//评论点赞数-1
int reduceCommentLikeCount(Integer articleId);
int reduceCommentLikeCount(Integer commentId);
//动态表评论数+1
int addArticleCommentCount(Integer articleId);
......
......@@ -80,12 +80,13 @@ public class ArticleCommentVO {
private Integer commentedUserId;
/**
* 子评论
* 是否点赞
*/
private List<ArticleCommentVO> childrenCommentList;
private String isLike;
/**
* 是否点赞
* 子评论
*/
private String isLike;
private List<ArticleCommentVO> childrenCommentList;
}
......@@ -5,10 +5,14 @@ import lombok.Data;
@Data
public class LikeDTO {
Integer businessId;
//用户id
String userId;
//动态id
Integer articleId;
//评论id
Integer commentId;
}
......@@ -89,10 +89,10 @@ public interface OpmArticleService {
/**
* 评论增加点赞数
* @param articleId
* @param commentId
* @return
*/
CyPersistModel likeCommentAdd(Integer articleId,String praiseType);
CyPersistModel likeCommentAdd(Integer commentId,String praiseType);
/**
* 添加评论
......
......@@ -259,29 +259,30 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
/**
* 评论增加点赞数
* @param articleId
* @param commentId
* @param praiseType 点赞类型 praise:点赞 cancel:取消点赞
* @return
*/
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
@Override
public CyPersistModel likeCommentAdd(Integer articleId,String praiseType){
public CyPersistModel likeCommentAdd(Integer commentId,String praiseType){
int line = 0;
if (praiseType.equals("praise")){
//点赞
//向点赞表增加一条数据
LikeDTO likeDTO = new LikeDTO();
likeDTO.setUserId(CyUserUtil.getAuthenBusinessId());
likeDTO.setArticleId(articleId);
likeDTO.setCommentId(commentId);
//增加主表该动态的点赞数
baseMapper.addCommentLikeCount(articleId);
baseMapper.addCommentLikeCount(commentId);
line = baseMapper.likeAdd(likeDTO);
} else if (praiseType.equals("cancel")){
//取消点赞
//删除点赞表中的数据
String userId = CyUserUtil.getAuthenBusinessId();
baseMapper.likeDelete(userId,articleId);
baseMapper.likeDelete(userId,commentId);
//修改主表中该动态的点赞数
line = baseMapper.reduceCommentLikeCount(articleId);
line = baseMapper.reduceCommentLikeCount(commentId);
} else {
throw new CyServiceException("点赞失败,请稍后再试");
}
......
......@@ -40,12 +40,12 @@
<update id="reduceCommentLikeCount" parameterType="java.lang.Integer">
UPDATE opm_article_comment
SET like_count = like_count - 1
WHERE business_id = #{articleId};
WHERE business_id = #{commentId};
</update>
<update id="addCommentLikeCount" parameterType="java.lang.Integer">
UPDATE opm_article_comment
SET like_count = like_count + 1
WHERE business_id = #{articleId};
WHERE business_id = #{commentId};
</update>
<select id="queryOpmArticle" resultMap="BaseResultMap">
select opa.*,sot.topic_name as topic,mi.mem_code as memCode
......@@ -258,7 +258,7 @@
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 opm_article_like oal on oal.article_id = opc.business_id and oal.user_id = #{loginUserId}
LEFT JOIN opm_article_like oal on oal.comment_id = opc.business_id and oal.user_id = #{loginUserId}
WHERE 1 = 1
AND opc.del_flag = '0'
AND opc.parent_id is null
......@@ -287,7 +287,7 @@
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
LEFT JOIN opm_article_like oal on oal.article_id = opc.business_id and oal.user_id = #{loginUserId}
LEFT JOIN opm_article_like oal on oal.comment_id = opc.business_id and oal.user_id = #{loginUserId}
WHERE 1 = 1
AND opc.del_flag = '0'
AND opc.article_id = #{articleId}
......@@ -298,11 +298,11 @@
and del_flag = '0'
</delete>
<delete id="likeDelete" parameterType="org.rcisoft.business.opmArticle.entity.OpmArticle">
delete from opm_article_like where user_id = #{userId} and article_id = #{articleId}
delete from opm_article_like where user_id = #{userId} and comment_id = #{commentId}
</delete>
<insert id="likeAdd" parameterType="org.rcisoft.business.opmArticle.entity.OpmArticle">
insert into opm_article_like (user_id, article_id,create_date)
values (#{entity.userId}, #{entity.articleId},now())
insert into opm_article_like (user_id, article_id,comment_id,create_date)
values (#{entity.userId}, #{entity.articleId},#{entity.commentId},now())
</insert>
<insert id="addComment">
INSERT INTO opm_article_comment
......
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