[fix]修改点赞逻辑和视频上传
This commit is contained in:
parent
d60ed900bc
commit
485834b2cd
@ -18,6 +18,7 @@ import com.wzj.soopin.member.domain.vo.AccountBillVO;
|
||||
import com.wzj.soopin.member.domain.vo.MemberAccountVO;
|
||||
import com.wzj.soopin.member.domain.vo.MemberBankVO;
|
||||
import com.wzj.soopin.member.domain.vo.MemberVO;
|
||||
import com.wzj.soopin.member.service.IFansService;
|
||||
import com.wzj.soopin.member.service.IMemberAccountService;
|
||||
import com.wzj.soopin.member.service.IMemberBankService;
|
||||
import com.wzj.soopin.member.service.IMemberService;
|
||||
@ -86,6 +87,8 @@ public class AppMemberController {
|
||||
|
||||
private final WxAuthService wxAuthService;
|
||||
|
||||
private final IFansService fansService;
|
||||
|
||||
@Operation(summary = "获取会员账户信息详细信息")
|
||||
@GetMapping(value = "/info")
|
||||
public R<MemberVO> getInfo(Long memberId) {
|
||||
@ -239,4 +242,30 @@ public class AppMemberController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Operation(summary = "用户注销")
|
||||
@Log(title = "用户注销 ", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/follow")
|
||||
public R follow(@RequestParam Long vloggerId) {
|
||||
LoginUser loginUser= LoginHelper.getLoginUser();
|
||||
if (loginUser == null) {
|
||||
throw new ServiceException("用户未登录");
|
||||
}
|
||||
fansService.doFollow(loginUser.getUserId(), vloggerId);
|
||||
return R.ok();
|
||||
}
|
||||
@Operation(summary = "用户注销")
|
||||
@Log(title = "用户注销 ", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/cancel")
|
||||
public R cancelFollow(@RequestParam Long vloggerId) {
|
||||
LoginUser loginUser= LoginHelper.getLoginUser();
|
||||
if (loginUser == null) {
|
||||
throw new ServiceException("用户未登录");
|
||||
}
|
||||
fansService.doCancel(loginUser.getUserId(), vloggerId);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ rocketmq:
|
||||
# 消费者组 (系统模块)
|
||||
group: wzj_prod
|
||||
# 是否启动消费者
|
||||
enabled: true
|
||||
enabled: false
|
||||
--- # mail 邮件发送
|
||||
mail:
|
||||
enabled: false
|
||||
|
@ -60,8 +60,8 @@ public interface GlobalConstants {
|
||||
/**
|
||||
* 我喜欢的视频 redis key
|
||||
*/
|
||||
String GLOBAL_VLOG_LIKED= "global:vlog:member:";
|
||||
String GLOBAL_VLOG_MY_LIKED_LIST= "global:vlog:myliked:list";
|
||||
String GLOBAL_VLOG_DOILIKE = "global:vlog:doilike:";
|
||||
String GLOBAL_VLOG_MY_LIKED_LIST= "global:vlog:myliked:list:";
|
||||
/**
|
||||
* 我喜欢的视频数量 redis key
|
||||
*/
|
||||
|
@ -47,6 +47,21 @@ public class RocketMQConfig {
|
||||
*/
|
||||
public static final String TOPIC_VLOG_MSG = "TOPIC_VLOG_MSG";
|
||||
|
||||
/**
|
||||
* 视频上传主题
|
||||
*/
|
||||
public static final String TOPIC_VLOG_UPLOAD = "TOPIC_VLOG_UPLOAD";
|
||||
|
||||
/**
|
||||
* 视频上传主题
|
||||
*/
|
||||
public static final String GROUP_VLOG_UPLOAD = "GROUP_VLOG_UPLOAD";
|
||||
|
||||
/**
|
||||
* 视频上传主题
|
||||
*/
|
||||
public static final String TAG_VLOG_UPLOAD = "VLOG_UPLOAD";
|
||||
|
||||
/**
|
||||
* 视频上传消费者组
|
||||
*/
|
||||
|
@ -119,10 +119,14 @@ public class UserRocketMQConsumerManager {
|
||||
// 拉取所有队列的消息
|
||||
for (MessageQueue mq : mqs) {
|
||||
PullResult result = pullSingleQueueMessage(userId, context.consumer, mq , batchSize-current);
|
||||
Double offset = getUserQueueOffset(userId, mq);
|
||||
if(offset!=null&&offset>=result.getMaxOffset()){
|
||||
redisCache.zSetAdd(GlobalConstants.GLOBAL_OFFSET+userId,mq.getQueueId()+"",result.getNextBeginOffset());
|
||||
}
|
||||
|
||||
if (result.getPullStatus() == PullStatus.FOUND) {
|
||||
allMessages.addAll(result.getMsgFoundList());
|
||||
// 更新用户的偏移量
|
||||
updateUserOffset(userId, mq, result.getNextBeginOffset());
|
||||
redisCache.zSetAdd(GlobalConstants.GLOBAL_OFFSET+userId,mq.getQueueId()+"",result.getNextBeginOffset());
|
||||
current+=result.getMsgFoundList().size();
|
||||
if(current==batchSize){
|
||||
@ -178,6 +182,7 @@ public class UserRocketMQConsumerManager {
|
||||
* 更新用户在指定队列的消费偏移量
|
||||
*/
|
||||
private void updateUserOffset(String userId, MessageQueue mq, long offset) {
|
||||
redisCache.zSetAdd(GlobalConstants.GLOBAL_OFFSET+userId,mq.getQueueId()+"",offset);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -35,9 +35,9 @@ import java.nio.file.Path;
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@RocketMQMessageListener(
|
||||
topic = RocketMQConfig.TOPIC_VLOG_MSG,
|
||||
consumerGroup = RocketMQConfig.GROUP_VLOG_MSG,
|
||||
selectorExpression = RocketMQConfig.TAG_VLOG_MSG
|
||||
topic = RocketMQConfig.TOPIC_VLOG_UPLOAD,
|
||||
consumerGroup = RocketMQConfig.GROUP_VLOG_UPLOAD,
|
||||
selectorExpression = RocketMQConfig.TAG_VLOG_UPLOAD
|
||||
)
|
||||
public class VlogUploadMessageConsumer implements RocketMQListener<MessageExt> {
|
||||
private final QcCloud qcCloud;
|
||||
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.wzj.soopin.content.domain.po.MyLikedVlog;
|
||||
import com.wzj.soopin.content.mapper.MyLikedVlogMapper;
|
||||
import com.wzj.soopin.content.service.IMyLikeVlogService;
|
||||
import com.wzj.soopin.member.domain.po.Fans;
|
||||
import org.dromara.common.core.constant.GlobalConstants;
|
||||
import org.dromara.common.redis.utils.RedisUtils;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@ -19,7 +20,6 @@ public class MyLikeVlogServiceImpl extends ServiceImpl<MyLikedVlogMapper, MyLike
|
||||
|
||||
|
||||
@Override
|
||||
@Cacheable(cacheNames = GlobalConstants.GLOBAL_VLOG_LIKED, key = "#vlogId + '_' + #memberId")
|
||||
public boolean like(String vlogId, Long vloggerId,Long memberId) {
|
||||
MyLikedVlog myLikedVlog = new MyLikedVlog();
|
||||
myLikedVlog.setMemberId(memberId);
|
||||
@ -28,8 +28,6 @@ public class MyLikeVlogServiceImpl extends ServiceImpl<MyLikedVlogMapper, MyLike
|
||||
return this.save(myLikedVlog);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(cacheNames = GlobalConstants.GLOBAL_VLOG_LIKED, key = "#vlogId + '_' + #memberId")
|
||||
public boolean unLike(String vlogId, Long memberId) {
|
||||
return this.remove(new LambdaQueryWrapper<MyLikedVlog>()
|
||||
.eq(MyLikedVlog::getMemberId, memberId.toString())
|
||||
@ -56,9 +54,11 @@ public class MyLikeVlogServiceImpl extends ServiceImpl<MyLikedVlogMapper, MyLike
|
||||
}
|
||||
|
||||
|
||||
@Cacheable(cacheNames = GlobalConstants.GLOBAL_VLOG_DOILIKE, key = "#memberId + '_' + #vlogId")
|
||||
public boolean doILikeVlog(String vlogId, Long memberId) {
|
||||
Boolean doILike = RedisUtils.getCacheMapValue(GlobalConstants.GLOBAL_VLOG_LIKED, vlogId + "_" + memberId);
|
||||
return doILike != null && doILike;
|
||||
return this.baseMapper.selectCount(new LambdaQueryWrapper<MyLikedVlog>()
|
||||
.eq(MyLikedVlog::getMemberId, memberId.toString())
|
||||
.eq(MyLikedVlog::getVlogId, vlogId.toString())) > 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -83,6 +83,7 @@ public class VlogPullServiceImpl implements IVlogPullService {
|
||||
//发出事件
|
||||
//先临时取10条数据
|
||||
Page<IndexVlogVO> indexVlogVOPage = vlogService.getIndexVlogList(null, page);
|
||||
Collections.shuffle(indexVlogVOPage.getRecords());
|
||||
//标记已读
|
||||
if(loginUser!=null){
|
||||
saveMyReadVlog(indexVlogVOPage.getRecords(), loginUser.getUserId());
|
||||
|
@ -90,6 +90,8 @@ public class VlogPushServiceImpl implements IVlogPushService {
|
||||
if(CollectionUtils.isEmpty(vlogPage.getRecords())){
|
||||
return false;
|
||||
}
|
||||
// 4. 使用 Collections.shuffle 打乱 List 的顺序
|
||||
Collections.shuffle(vlogPage.getRecords());
|
||||
vlogPage.getRecords().stream().forEach(vlogId -> {
|
||||
//将数据发送的mq的热点数据队列
|
||||
MQMessage message = MQMessage.builder()
|
||||
|
@ -136,11 +136,11 @@ public class VlogServiceImpl extends ServiceImpl<VlogMapper, Vlog> implements Vl
|
||||
.messageType(MQMessageType.VLOG.name())
|
||||
.data(vlog.getId())
|
||||
.source("app")
|
||||
.topic("VLOG_UPLOAD_TOPIC")
|
||||
.tag("upload")
|
||||
.topic(RocketMQConfig.TOPIC_VLOG_UPLOAD)
|
||||
.tag(RocketMQConfig.TAG_VLOG_UPLOAD)
|
||||
.sendTime(LocalDateTime.now())
|
||||
.build();
|
||||
MqUtil.sendMessage(RocketMQConfig.TOPIC_VLOG_MSG + ":" + RocketMQConfig.TAG_VLOG_MSG, message);
|
||||
MqUtil.sendMessage(RocketMQConfig.TOPIC_VLOG_UPLOAD + ":" + RocketMQConfig.TAG_VLOG_UPLOAD, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -309,6 +309,7 @@ public class VlogServiceImpl extends ServiceImpl<VlogMapper, Vlog> implements Vl
|
||||
RedisUtils.delCacheMapValue(GlobalConstants.GLOBAL_VLOG_MY_LIKED_LIST, userId);
|
||||
RedisUtils.delCacheMapValue(GlobalConstants.GLOBAL_VLOG_LIKED_COUNT, vlogId);
|
||||
RedisUtils.delCacheMapValue(GlobalConstants.GLOBAL_VLOG_ALL_LIKED_COUNT, vloggerId);
|
||||
RedisUtils.delCacheMapValue(GlobalConstants.GLOBAL_VLOG_DOILIKE, userId + "_" + vlogId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.protobuf.ServiceException;
|
||||
import com.wzj.soopin.member.domain.po.Fans;
|
||||
import com.wzj.soopin.member.domain.po.Member;
|
||||
import com.wzj.soopin.member.domain.vo.FansVO;
|
||||
@ -45,9 +46,20 @@ public class FansServiceImpl extends ServiceImpl<FansMapper, Fans> implements IF
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
@Cacheable(value = GlobalConstants.GLOBAL_MEMBER_DOIFOLLOW, key = "#vloggerId" + "-" + "#myId")
|
||||
public boolean doFollow(Long myId, Long vloggerId) {
|
||||
// 幂等性校验:已存在则不再插入
|
||||
Member member = memberMapper.selectById(myId);
|
||||
if (member == null) {
|
||||
log.error("用户不存在");
|
||||
return false;
|
||||
}
|
||||
|
||||
Member vlogger = memberMapper.selectById(vloggerId);
|
||||
if (vlogger == null) {
|
||||
log.error("视频主不存在");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Fans existing = queryFansRelationship(myId, vloggerId);
|
||||
if (existing != null) {
|
||||
@ -67,7 +79,7 @@ public class FansServiceImpl extends ServiceImpl<FansMapper, Fans> implements IF
|
||||
vloger.setBothFriend(YesOrNo.YES.type);
|
||||
baseMapper.updateById(vloger);
|
||||
} else {
|
||||
fans.setFriendFlag(YesOrNo.YES.type);
|
||||
fans.setFriendFlag(YesOrNo.NO.type);
|
||||
}
|
||||
baseMapper.insert(fans);
|
||||
|
||||
@ -110,7 +122,6 @@ public class FansServiceImpl extends ServiceImpl<FansMapper, Fans> implements IF
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
@CacheEvict(value = GlobalConstants.GLOBAL_MEMBER_DOIFOLLOW, key = "#vloggerId" + "-" + "#myId")
|
||||
public boolean doCancel(Long myId, Long vloggerId) {
|
||||
// 判断我们是否朋友关系,如果是,则需要取消双方的关系
|
||||
Fans fan = queryFansRelationship(myId, vloggerId);
|
||||
@ -138,15 +149,9 @@ public class FansServiceImpl extends ServiceImpl<FansMapper, Fans> implements IF
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(cacheNames = GlobalConstants.GLOBAL_MEMBER_DOIFOLLOW, key = "#myId" + "-" + "#vloggerId")
|
||||
public boolean queryDoIFollowVloger(Long myId, Long vloggerId) {
|
||||
|
||||
Boolean result = RedisUtils.getCacheMapValue(GlobalConstants.GLOBAL_MEMBER_DOIFOLLOW, vloggerId + "-" + myId);
|
||||
if (result == null) {
|
||||
result = baseMapper.selectCount(new LambdaQueryWrapper<Fans>().eq(Fans::getFanId, myId).eq(Fans::getVloggerId, vloggerId)) > 0;
|
||||
RedisUtils.setCacheMapValue(GlobalConstants.GLOBAL_MEMBER_DOIFOLLOW, vloggerId + "-" + myId, result);
|
||||
}
|
||||
|
||||
return result != null ? result : false;
|
||||
return baseMapper.selectCount(new LambdaQueryWrapper<Fans>().eq(Fans::getFanId, myId).eq(Fans::getVloggerId, vloggerId)) > 0;
|
||||
}
|
||||
|
||||
|
||||
@ -175,6 +180,7 @@ public class FansServiceImpl extends ServiceImpl<FansMapper, Fans> implements IF
|
||||
RedisUtils.delCacheMapValue(GlobalConstants.GLOBAL_MEMBER_FANS_COUNT, vloggerId + "");
|
||||
RedisUtils.delCacheMapValue(GlobalConstants.GLOBAL_MEMBER_FOLLOW_COUNT, userId + "");
|
||||
RedisUtils.delCacheMapValue(GlobalConstants.GLOBAL_MEMBER_FRIENDS_COUNT, userId + "");
|
||||
RedisUtils.delCacheMapValue(GlobalConstants.GLOBAL_MEMBER_DOIFOLLOW, userId + "-" + vloggerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -319,6 +319,8 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper,Member> implemen
|
||||
|
||||
for (MemberVO memberVO : records) {
|
||||
memberVO.setDoIFollowVloger(fansService.queryDoIFollowVloger(tokenUser.getUserId(), memberVO.getId()));
|
||||
memberVO.setFansCount(fansService.myFansCount(memberVO.getId()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user