当前位置:网站首页>抖音实战~取关博主
抖音实战~取关博主
2022-06-28 03:40:00 【gblfy】


文章目录
一、需求分析
1. 取关流程图

2. 取关流程简述
- 1.前端携带用户ID和短视频发布者ID请求后端取关接口
- 2.判断我们是否朋友关系
- 2.1.非朋友关系,删除自己的关注关联表记录
- 2.2.朋友关系,抹除双方的朋友关系,设置非朋友状态,更新数据库
- 3.我关注总量-1(redis)
- 4.博主粉丝量-1(redis)
- 5.删除我和短视频博主的关系(redis)
二、源码实战
2.1. 取关~前端
// 取消关注
cancelFollow(vlogerId) {
var me = this;
var userId = getApp().getUserInfoSession().id;
var serverUrl = app.globalData.serverUrl;
uni.request({
method: "POST",
header: {
headerUserId: userId,
headerUserToken: app.getUserSessionToken()
},
url: serverUrl + "/fans/cancel?myId=" + userId + "&vlogerId=" + vlogerId,
success(result) {
if (result.data.status == 200) {
me.reFreshList(vlogerId, false);
} else {
uni.showToast({
title: result.data.msg,
icon: "none",
duration: 3000
});
}
}
});
},
2.2. 取关~后端
/**
* 取关
*
* @param myId 我的用户ID
* @param vlogerId 视频发布者ID
* @return
*/
@PostMapping("cancel")
public GraceJSONResult cancel(@RequestParam String myId,
@RequestParam String vlogerId) {
// 删除业务的执行
fansService.doCancel(myId, vlogerId);
// 博主的粉丝-1,我的关注-1
//我的关注总数
redis.decrement(REDIS_MY_FOLLOWS_COUNTS + ":" + myId, 1);
// 博主的粉丝总数
redis.decrement(REDIS_MY_FANS_COUNTS + ":" + vlogerId, 1);
// 我和博主的关联关系,依赖redis,不要存储数据库,避免db的性能瓶颈
redis.del(REDIS_FANS_AND_VLOGGER_RELATIONSHIP + ":" + myId + ":" + vlogerId);
return GraceJSONResult.ok();
}
/** * 取关 * * @param myId 我的用户ID * @param vlogerId 视频发布者ID * @return */
@Transactional
@Override
public void doCancel(String myId, String vlogerId) {
// 判断我们是否朋友关系,如果是,则需要取消双方的关系
Fans fan = queryFansRelationship(myId, vlogerId);
if (fan != null && fan.getIsFanFriendOfMine() == YesOrNo.YES.type) {
// 抹除双方的朋友关系,自己的关系删除即可
Fans pendingFan = queryFansRelationship(vlogerId, myId);
pendingFan.setIsFanFriendOfMine(YesOrNo.NO.type);
fansMapper.updateByPrimaryKeySelective(pendingFan);
}
// 删除自己的关注关联表记录
fansMapper.delete(fan);
}
三、5217取关实战
3.1. 取关前资料分析
尾号~0009
关注:1
粉丝:2
尾号~5217
关注:3
粉丝:2



3.2. 账号5217取关
尾号~0009
关注:1
粉丝:1 ->由2变成了1
尾号~5217
关注:2 ->由3变成了2
粉丝:2
我关注的那一条数据删除了,博主和我不是朋友关系了
四、账号0009取关实战
4.1. 账号0009取关
尾号~0009
关注:0 由1变成了0
粉丝:1
尾号~5217
关注:2 ->由3变成了2
粉丝:1 ->由2变成了1

4.2. 数据变化
0009账号关注的信息也删除了
边栏推荐
- Arrangement of basic electrical knowledge (I)
- 电学基础知识整理(二)
- Market competitiveness of robot programming education
- Reading notes of top performance version 2 (II) -- Performance observation tool
- The operating mechanism of spectrogram in audio Science
- 加法器—笔记
- 2022年6月对自己近况的一次总结
- 黑体辐射初探
- 仅用递归函数和栈操作逆序一个栈
- 光的粒子说(光电效应/康普顿效应)
猜你喜欢

Lingge leangoo agile Kanban tool adds the functions of exporting card documents and pasting shared brain map nodes

Iso8191 test is mentioned in as 3744.1. Are the two tests the same?

02 MongoDB数据类型、重要概念以及shell常用指令

How to write a software test report? Here comes the third party performance report template

《性能之巅第2版》阅读笔记(二)--CPU监测

错排兼排列组合公式

开关电源—Buck电路原理及其仿真

Detailed explanation of KVM common commands

English grammar_ Adjective / adverb Level 3 - Comparative_ Useful Expressions

Pycharm setting pseudo sublime color scheme
随机推荐
MSc 307 (88) (2010 FTPC code) Part 9 bedding test
欧洲家具EN 597-1 跟EN 597-2两个阻燃标准一样吗?
PostgreSQL 实现批量更新、删除、插入
ELK 搭建日志分析系统 + Zipkin服务链路追踪整合
How to write anti shake throttling for small programs?
僅用遞歸函數和棧操作逆序一個棧
光的粒子说(光电效应/康普顿效应)
02 MongoDB数据类型、重要概念以及shell常用指令
Iso8191 test is mentioned in as 3744.1. Are the two tests the same?
Are the two flame retardant standards of European furniture en 597-1 and en 597-2 the same?
MSC 307(88) (2010 FTPC Code)第2部分烟气和毒性测试
内卷、躺平与中年危机的相关思考
English grammar_ Adjective / adverb Level 3 - Comparative
歐洲家具EN 597-1 跟EN 597-2兩個阻燃標准一樣嗎?
How to learn a programming language systematically| Dark horse programmer
English notes - cause and effect
《性能之巅第2版》阅读笔记(二)--CPU监测
Backtracking maze problem
由两个栈组成的队列
MSC 307(88) (2010 FTPC Code) Part 5低播焰测试