在线不卡日本ⅴ一区v二区_精品一区二区中文字幕_天堂v在线视频_亚洲五月天婷婷中文网站

  • <menu id="lky3g"></menu>
  • <style id="lky3g"></style>
    <pre id="lky3g"><tt id="lky3g"></tt></pre>

    朋友圈 喜歡功能 接口API

    朋友圈 喜歡功能接口

    /** 朋友圈 喜歡功能接口* *//** * 喜歡 * * @param userId * @param publishId * @return */Boolean loveComment(Long userId, String publishId);/** * 取消喜歡 * * @param userId * @param publishId * @return */Boolean disLoveComment(Long userId, String publishId);/** * 查詢喜歡數(shù) * * @param publishId * @return */Long queryLoveCount(String publishId);/** * 查詢 戶是否喜歡該動態(tài) * * @param userId * @param publishId * @return */Boolean queryUserIsLove(Long userId, String publishId);

    朋友圈 喜歡功能接口 實現(xiàn)類

    /** 朋友圈 喜歡功能* */@Overridepublic Boolean loveComment(Long userId, String publishId) { //查詢該 戶是否已經(jīng)喜歡 if (this.queryUserIsLove(userId, publishId)) { return false; } //喜歡 boolean result = this.saveComment(userId, publishId, CommentType.LOVE, null); if (!result) { return false; } //喜歡成功后,修改Redis中的總的喜歡數(shù) String redisKey = this.getCommentRedisKeyPrefix(publishId); String hashKey = CommentType.LOVE.toString(); this.redisTemplate.opsForHash().increment(redisKey, hashKey, 1); //標記 戶已經(jīng)喜歡 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; } //標記 戶已經(jīng)喜歡 this.redisTemplate.opsForHash().put(redisKey, hashKey, “1”); return true;}

    鄭重聲明:本文內容及圖片均整理自互聯(lián)網(wǎng),不代表本站立場,版權歸原作者所有,如有侵權請聯(lián)系管理員(admin#wlmqw.com)刪除。
    (0)
    用戶投稿
    上一篇 2022年6月13日 15:28
    下一篇 2022年6月13日 15:28

    相關推薦

    • Spring Boot面試題(總結最全面的面試題?。。。?

      什么是 Spring Boot? Spring Boot 是 Spring 開源組織下的子項目,是 Spring 組件一站式解決方案,主要是簡化了使用 Spring 的難度,簡省了…

      2022年6月27日
    • 蔡依林因立場被央視刪除動態(tài)后,《北京歡迎你》再刪除蔡依林鏡頭

      前幾日,不少明星紛紛轉發(fā)“堅持一個中國”的動態(tài),包括一些港臺藝人,然而田馥甄、炎亞綸因為言論不當被網(wǎng)友紛紛吐槽與抵制,蔡依林也被扒出此前多次言論不當,目前田馥甄的音樂作品在某平臺已…

      2022年8月10日
    • 人到中年最無奈的短句 成年人壓抑心累的文案短句

      .我一直以為愛情是一場考試,只要我努力一點,再努力一點,就能拿到滿意的成績,后來我才知道,這個世界上幾乎所有的東西,都能通過努力得到,偏偏愛不可以。 2.生命里總有那么個人,驚艷了…

      2022年7月26日
    • 這些來自對岸的明星到底有多愛國

      這些明星有多愛國?不僅公開講話不怕冒犯灣灣媒體,還放棄了美國綠卡想念祖國,周杰倫代言國貨。今天我將帶大家看看這些10名灣灣藝術家是多么愛國! 當我在影視劇中看到他時,我知道他是全劇…

      2022年8月12日
    • RTX 3050獨顯加持的銳龍本!ThinkBook 16p NX是否值得選?

      聯(lián)想最近推出了一大波銳龍平臺的產品,其中16英寸的代表就有ThinkBook 16+、ThinkBook 16p和ThinkBook 16p NX。它們之間的差異很大,ThinkB…

      2022年6月27日
    • 689頁27萬字智慧冷庫農產品冷鏈物流大數(shù)據(jù)信息化系統(tǒng)集成方案

      總體布局 整個場地的道路系統(tǒng)由一個環(huán)行道路和貫穿南北的中軸路組成,各功能分區(qū)的主要道路7米寬,可保證雙向大型貨車的通行。地塊內由北向南依次為辦公區(qū)、市場交易區(qū)、冷庫區(qū)。 6.3.2…

      2022年7月9日
    • 作家為什么喜歡熬夜

      之前不懂為什么作家喜歡熬夜寫作 雖然我不是作家 但是體驗過幾次晚上寫作之后 覺得此時環(huán)境很安靜 此時是與心靈在對話 也或許夜晚的自己褪下面具 是最真實的自己 面對自己的真實靈魂有講…

      2022年6月30日
    • “朋友圈走心文案短句”

      這回憶太長 長過漫長的海岸線 這相愛又太短 短到自作多情 “真正想送你東西的人 不會問你要不要 有人問你要不要的時候 最好拒絕” “無論我們最后生疏到什么樣子 曾經(jīng)對你的好都是真的…

      2022年8月6日
    • ThinkBook Plus 17:雙屏筆記本有什么獨特之處?

      全新的ThinkBook Plus 17終于上市啦!作為一臺輕薄商務本,它與眾不同,創(chuàng)新性的將 17.3 英寸超寬主顯示屏和 8 英寸觸摸屏組合在一起,實現(xiàn)雙屏聯(lián)動。憑借新穎的設計…

      2022年8月2日
    • 39歲王心凌曬臺北的家:全屋雖不奢華,但滿滿的都是舒適和精致感

      導語:39歲王心凌曬出臺北的家:全屋雖不豪華,但卻沒有絲毫俗氣,喜歡! 生命中,總是有一些遇見,既驚艷了時光,又溫柔了歲月。 《浪姐3》的舞臺,讓人們再一次回味青春,感受到了曾經(jīng)的…

      2022年8月31日

    聯(lián)系我們

    聯(lián)系郵箱:admin#wlmqw.com
    工作時間:周一至周五,10:30-18:30,節(jié)假日休息