在线不卡日本ⅴ一区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;}

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

    相關(guān)推薦

    聯(lián)系我們

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