朋友圈 喜欢功能 接口API

朋友圈 喜欢功能接口

/** 朋友圈 喜欢功能接口* *//** * 喜欢 * * @param userId * @param publishId * @return */Boolean loveComment(Long userId, String publishId);/** * 取消喜欢 * * @param userId * @param publishId * @return */Boolean disLoveComment(Long userId, String publishId);/** * 查询喜欢数 * * @param publishId * @return */Long queryLoveCount(String publishId);/** * 查询 户是否喜欢该动态 * * @param userId * @param publishId * @return */Boolean queryUserIsLove(Long userId, String publishId);

朋友圈 喜欢功能接口 实现类

/** 朋友圈 喜欢功能* */@Overridepublic Boolean loveComment(Long userId, String publishId) { //查询该 户是否已经喜欢 if (this.queryUserIsLove(userId, publishId)) { return false; } //喜欢 boolean result = this.saveComment(userId, publishId, CommentType.LOVE, null); if (!result) { return false; } //喜欢成功后,修改Redis中的总的喜欢数 String redisKey = this.getCommentRedisKeyPrefix(publishId); String hashKey = CommentType.LOVE.toString(); this.redisTemplate.opsForHash().increment(redisKey, hashKey, 1); //标记 户已经喜欢 hashKey = this.getCommentUserLoveRedisKey(userId); this.redisTemplate.opsForHash().put(redisKey, hashKey, “1”); return true;}private String getCommentUserLoveRedisKey(Long userId) { return COMMENT_USER_LOVE_REDIS_KEY_PREFIX + userId;}@Overridepublic Boolean disLoveComment(Long userId, String publishId) { if (!this.queryUserIsLove(userId, publishId)) { //如果 户没有喜欢,就直接返回 return false; } boolean result = this.removeComment(userId, publishId, CommentType.LOVE); if (!result) { //删除失败 return false; } //删除redis中的记录 String redisKey = this.getCommentRedisKeyPrefix(publishId); String hashKey = this.getCommentUserLoveRedisKey(userId); this.redisTemplate.opsForHash().delete(redisKey, hashKey); this.redisTemplate.opsForHash().increment(redisKey, CommentType.LOVE.toString(), -1); return true;}@Overridepublic Long queryLoveCount(String publishId) { // 先从redis中命中,如果命中的话就返回,没有命中就查询Mongodb String redisKey = this.getCommentRedisKeyPrefix(publishId); String hashKey = CommentType.LOVE.toString(); Object value = this.redisTemplate.opsForHash().get(redisKey, hashKey); if (ObjectUtil.isNotEmpty(value)) { return Convert.toLong(value); } //查询count Long count = this.queryCommentCount(publishId, CommentType.LOVE); //存储到redis中 this.redisTemplate.opsForHash().put(redisKey, hashKey, String.valueOf(count)); return count;}@Overridepublic Boolean queryUserIsLove(Long userId, String publishId) { String redisKey = this.getCommentRedisKeyPrefix(publishId); String hashKey = this.getCommentUserLoveRedisKey(userId); Object value = this.redisTemplate.opsForHash().get(redisKey, hashKey); if (ObjectUtil.isNotEmpty(value)) { return StrUtil.equals(Convert.toStr(value), “1”); } //查询mongodb Query query = Query.query(Criteria.where(“publishId”) .is(new ObjectId(publishId)) .and(“userId”).is(userId) .and(“commentType”).is(CommentType.LOVE.getType())); long count = this.mongoTemplate.count(query, Comment.class); if (count == 0) { return false; } //标记 户已经喜欢 this.redisTemplate.opsForHash().put(redisKey, hashKey, “1”); return true;}

郑重声明:本文内容及图片均整理自互联网,不代表本站立场,版权归原作者所有,如有侵权请联系管理员(admin#wlmqw.com)删除。
(0)
用户投稿
上一篇 2022年6月13日
下一篇 2022年6月13日

相关推荐

  • 有种“氧气美女”叫左小青,她曾是体操冠军,退役后进入娱乐圈

    在娱乐圈当中有很多被大家熟悉的明星也都不是科班出身的,就像赵丽颖也是其中一个,从当初的一个普通女生,现成为影视圈中当中的一线小花。而除了赵丽颖,还有一些是跨行业的明星艺人,比如王嘉…

    2022年5月12日
  • 很哇塞的宝藏短句

    1. 走时满身月,归时满天星。 2.所有的温柔都源于你的强大。 3. 愿有人知你冷暖,懂你悲欢。 4. 多年后若能重逢,道别来无恙。 5. 愿你以渺小启程,以伟大结尾。 6. 种自…

    2022年5月18日
  • 最新的日常美好生活文案,发朋友圈人人点赞

    一、恰到好处的喜欢最舒服,懂分寸的关系最迷人。 二、我活在世上,无非想要明白些道理,遇见些有趣的事,倘能如我愿,我的一生就算成功。 三、别活的跟支烟似的,无聊时让人点起你,抽完了又…

    2022年8月2日
  • 女生开什么车合适?10-20万左右好看又显气质!

    说实话大部分女生在对汽车、机械没什么感觉,开车手感、路感都比大部分男人差。女生开车,最好选一款小车、好开的车很重要。开车或是停车时,闹笑话是小事,安全才是大事! 女生选车第一要素是…

    2022年8月15日
  • 新居之约陈曦开的什么车 这家境一天换一辆座驾都行

    《新居之约》中的陈曦除了是一名设计师,也是一名富二代。就她这家境,一天换一辆车开都没问题,而且还得是豪车。杨光最开始和陈曦产生交集,也是和车有关。陈曦开的是什么车?关注十目影娱,一…

    2022年5月13日
  • 哪个牌子的电视盒子好用?测评博主盘点2022电视盒子排行榜

    电视盒子发展至今已有数年的时间,近几年不仅出现了更多的电视盒子品牌,功能也五花八门,有投屏的、有打游戏的、有上网课的、有健身运动的,甚至现在还有儿童故事机的了!这无疑就加大了大家选…

    2022年6月29日
  • 很是精辟地说说

    世界最廉价的东西是什么? 大概就是付出吧。 一颗一贫如洗的真心 和一事无成的温柔。 世上唯一不能复制的是时间, 唯一不能重演的是人生, 该怎么走, 过什么样的生活 全凭自己的选择和…

    2022年8月12日
  • 为什么不少开过SUV车主都换回了轿车?

    因为轿车便宜呗。为什么很多开过sUV的车主再也不想开轿车了?因为SUV开着更舒服呗。所以你这个问题问的就是有毛病的。 说反了 我还是喜欢suv,钓鱼时经常翻山越岭,轿车通过性太差!…

    2022年7月25日
  • 现在什么专业前景比较好?

    俗话说“男怕入错行,女怕嫁错郎”这是非常有道理的。因此,大学选专业看前景。笔者提出未来几年吃香的职业,人才缺口的专业及最新职业,仅供你参考。 图片来源于网络 从当前及未来几年情况来…

    2022年6月18日
  • 那些暗示一直在等你的句子

    时间为媒,余生为聘,以你之名,冠我之姓,吾之爱汝,愿执子之手,与子偕老,始于初见,止于终老。 “浮生一梦何处醉,不敢忘是与君缘!” 每一个决定转身的人都在风里站了很久 时间告诉我们…

    2022年6月27日

联系我们

联系邮箱:admin#wlmqw.com
工作时间:周一至周五,10:30-18:30,节假日休息