Commit 1b942caf authored by liwei's avatar liwei

修改了点赞接口

parent 76188298
...@@ -155,21 +155,9 @@ public class OpmArticleController extends CyPaginationController<OpmArticle> { ...@@ -155,21 +155,9 @@ public class OpmArticleController extends CyPaginationController<OpmArticle> {
/** /**
* 点赞增加点赞数 * 点赞增加点赞数
*/ */
@PostMapping("/likeAdd/{articleId:\\w+}") @PostMapping("/likeAdd")
public CyResult likeAdd(@PathVariable String articleId) { public CyResult likeAdd(String articleId,String praiseType) {
CyPersistModel data = opmArticleServiceImpl.likeAdd(articleId); CyPersistModel data = opmArticleServiceImpl.likeAdd(articleId,praiseType);
return CyResultGenUtil.builder(data,
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
articleId);
}
/**
* 删除点赞中间表
*/
@PostMapping("/likeDelete/{articleId:\\w+}")
public CyResult likeDelete(@PathVariable String articleId) {
CyPersistModel data = opmArticleServiceImpl.likeDelete(articleId);
return CyResultGenUtil.builder(data, return CyResultGenUtil.builder(data,
CyMessCons.MESSAGE_ALERT_SUCCESS, CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR, CyMessCons.MESSAGE_ALERT_ERROR,
......
...@@ -37,9 +37,16 @@ public interface OpmArticleRepository extends CyBaseMapper<OpmArticle> { ...@@ -37,9 +37,16 @@ public interface OpmArticleRepository extends CyBaseMapper<OpmArticle> {
List<String> SelectPathList(Integer businessId); List<String> SelectPathList(Integer businessId);
//添加点赞记录
int likeAdd(@Param("entity") LikeDTO likeDTO); int likeAdd(@Param("entity") LikeDTO likeDTO);
int likeDelete(@Param("entity") LikeDTO likeDTO); //删除点赞记录
int likeDelete(@Param("userId") String userId,@Param("articleId") String articleId);
//点赞数+1
int addLikeCount(String articleId);
//点赞数-1
int reduceLikeCount(String articleId);
} }
...@@ -84,14 +84,6 @@ public interface OpmArticleService { ...@@ -84,14 +84,6 @@ public interface OpmArticleService {
* @param articleId * @param articleId
* @return * @return
*/ */
CyPersistModel likeAdd(String articleId); CyPersistModel likeAdd(String articleId,String praiseType);
/**
* 删除点赞中间表
* @param articleId
* @return
*/
CyPersistModel likeDelete(String articleId);
} }
...@@ -9,6 +9,7 @@ import org.rcisoft.business.opmArticle.entity.ArticleCommentDTO; ...@@ -9,6 +9,7 @@ import org.rcisoft.business.opmArticle.entity.ArticleCommentDTO;
import org.rcisoft.business.opmArticle.entity.LikeDTO; import org.rcisoft.business.opmArticle.entity.LikeDTO;
import org.rcisoft.business.opmArticle.entity.OpmArticle; import org.rcisoft.business.opmArticle.entity.OpmArticle;
import org.rcisoft.business.opmArticle.service.OpmArticleService; import org.rcisoft.business.opmArticle.service.OpmArticleService;
import org.rcisoft.core.exception.CyServiceException;
import org.rcisoft.core.model.CyPageInfo; import org.rcisoft.core.model.CyPageInfo;
import org.rcisoft.core.model.CyPersistModel; import org.rcisoft.core.model.CyPersistModel;
import org.rcisoft.core.util.CyUserUtil; import org.rcisoft.core.util.CyUserUtil;
...@@ -156,29 +157,27 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm ...@@ -156,29 +157,27 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
*/ */
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT) @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
@Override @Override
public CyPersistModel likeAdd(String articleId){ public CyPersistModel likeAdd(String articleId,String praiseType){
//增加操作 int line = 0;
LikeDTO likeDTO = new LikeDTO(); if (praiseType.equals("praise")){
likeDTO.setUserId(CyUserUtil.getAuthenBusinessId()); //点赞
likeDTO.setArticleId(articleId); //向点赞表增加一条数据
int line = baseMapper.likeAdd(likeDTO); LikeDTO likeDTO = new LikeDTO();
return new CyPersistModel(line); likeDTO.setUserId(CyUserUtil.getAuthenBusinessId());
} likeDTO.setArticleId(articleId);
//增加主表该动态的点赞数
baseMapper.addLikeCount(articleId);
/** line = baseMapper.likeAdd(likeDTO);
* 删除点赞中间表 } else if (praiseType.equals("cancel")){
* @param articleId //取消点赞
* @return //删除点赞表中的数据
*/ String userId = CyUserUtil.getAuthenBusinessId();
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT) baseMapper.likeDelete(userId,articleId);
@Override //修改主表中该动态的点赞数
public CyPersistModel likeDelete(String articleId){ line = baseMapper.reduceLikeCount(articleId);
//删除操作 } else {
LikeDTO likeDTO = new LikeDTO(); throw new CyServiceException("点赞失败,请稍后再试");
likeDTO.setUserId(CyUserUtil.getAuthenBusinessId()); }
likeDTO.setArticleId(articleId);
int line = baseMapper.likeDelete(likeDTO);
return new CyPersistModel(line); return new CyPersistModel(line);
} }
......
...@@ -17,6 +17,16 @@ ...@@ -17,6 +17,16 @@
<result column="exam_status" jdbcType="VARCHAR" property="examStatus"/> <result column="exam_status" jdbcType="VARCHAR" property="examStatus"/>
<result column="is_article" jdbcType="VARCHAR" property="isArticle"/> <result column="is_article" jdbcType="VARCHAR" property="isArticle"/>
</resultMap> </resultMap>
<update id="addLikeCount">
UPDATE opm_article
SET like_count = like_count + 1
WHERE business_id = #{articleId};
</update>
<update id="reduceLikeCount">
UPDATE opm_article
SET like_count = like_count - 1
WHERE business_id = #{articleId};
</update>
<!--<cache type="${corePackag!}.util.RedisCache"/>--> <!--<cache type="${corePackag!}.util.RedisCache"/>-->
<select id="queryOpmArticle" resultMap="BaseResultMap"> <select id="queryOpmArticle" resultMap="BaseResultMap">
...@@ -109,7 +119,7 @@ ...@@ -109,7 +119,7 @@
opm_article.del_flag = '0' opm_article.del_flag = '0'
) AS pic_ids ON opa.business_id = pic_ids.business_id ) AS pic_ids ON opa.business_id = pic_ids.business_id
LEFT JOIN oss_info pic_urls ON pic_ids.picture_id = pic_urls.business_id LEFT JOIN oss_info pic_urls ON pic_ids.picture_id = pic_urls.business_id
left join opm_user_like opl on opl.business_id = opa.business_id and opl.user_id = #{entity.userId} left join opm_user_like opl on opl.article_id = opa.business_id and opl.user_id = #{entity.userId}
WHERE WHERE
opa.del_flag = '0' opa.del_flag = '0'
<if test="entity.flag !=null and entity.flag != '' "> <if test="entity.flag !=null and entity.flag != '' ">
...@@ -199,8 +209,8 @@ ...@@ -199,8 +209,8 @@
update opm_article_comment set del_flag = '1' where business_id = #{businessId} update opm_article_comment set del_flag = '1' where business_id = #{businessId}
and del_flag = '0' and del_flag = '0'
</delete> </delete>
<delete id="likeDelete" parameterType="org.rcisoft.business.opmArticle.entity.LikeDTO"> <delete id="likeDelete" parameterType="org.rcisoft.business.opmArticle.entity.OpmArticle">
delete from opm_user_like where user_id = #{entity.userId} and article_id = #{entity.articleId} delete from opm_user_like where user_id = #{userId} and article_id = #{articleId}
</delete> </delete>
<insert id="likeAdd" parameterType="org.rcisoft.business.opmArticle.entity.OpmArticle"> <insert id="likeAdd" parameterType="org.rcisoft.business.opmArticle.entity.OpmArticle">
insert into opm_user_like (user_id, article_id,create_date) insert into opm_user_like (user_id, article_id,create_date)
......
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