123
This commit is contained in:
@@ -1,32 +1,107 @@
|
||||
package com.ruoyi.cai.mq.handle;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ruoyi.cai.domain.User;
|
||||
import com.ruoyi.cai.domain.UserInfo;
|
||||
import com.ruoyi.cai.dto.commom.IdDTO;
|
||||
import com.ruoyi.cai.enums.GenderEnum;
|
||||
import com.ruoyi.cai.manager.LockManager;
|
||||
import com.ruoyi.cai.mapper.UserFollowMapper;
|
||||
import com.ruoyi.cai.mq.dto.CommonConsumerEnum;
|
||||
import com.ruoyi.cai.mq.handle.dto.LoginNotifyDTO;
|
||||
import com.ruoyi.cai.mq.handle.dto.RankNotifyDTO;
|
||||
import com.ruoyi.cai.rank.RankManager;
|
||||
import com.ruoyi.cai.notice.YunxinHttpService;
|
||||
import com.ruoyi.cai.service.UserInfoService;
|
||||
import com.ruoyi.cai.service.UserService;
|
||||
import com.ruoyi.common.utils.ip.AddressUtils;
|
||||
import com.ruoyi.framework.OnlineUserTodayCache;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.redisson.api.RBucket;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class LoginNotifyHandle implements IHandle {
|
||||
|
||||
@Autowired
|
||||
private OnlineUserTodayCache onlineUserTodayCache;
|
||||
@Autowired
|
||||
private UserInfoService userInfoService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
@Override
|
||||
public void run(String message) {
|
||||
LoginNotifyDTO loginNotify = JSON.parseObject(message, LoginNotifyDTO.class);
|
||||
boolean todayFirstLogin = onlineUserTodayCache.addOnlineUserId(loginNotify.getUserId());
|
||||
boolean todayFirstLogin = onlineUserTodayCache.addOnlineUserId(loginNotify.getUserId(),loginNotify.getHappenTime());
|
||||
if(todayFirstLogin){
|
||||
this.updateUserInfoSB(loginNotify.getUserId(),loginNotify.getClientIP(),loginNotify.getImei());
|
||||
}
|
||||
// 上线通知
|
||||
|
||||
|
||||
|
||||
String loginNoticeFansLock = LockManager.getLoginNoticeFansLock(loginNotify.getUserId());
|
||||
RBucket<String> bucket = redissonClient.getBucket(loginNoticeFansLock);
|
||||
boolean boo = bucket.setIfAbsent("cai", Duration.ofMinutes(60));
|
||||
if(boo){
|
||||
sendOnlineNotice(loginNotify.getUserId());
|
||||
}
|
||||
}
|
||||
|
||||
@Resource
|
||||
private UserFollowMapper userFollowMapper;
|
||||
@Autowired
|
||||
private YunxinHttpService yunxinHttpService;
|
||||
|
||||
private void sendOnlineNotice(Long userId){
|
||||
log.info("发送在线通知调试打印");
|
||||
User user = userService.getById(userId);
|
||||
// 男的上线,并且没有开启隐身模式 则通知女主播舔狗上线了
|
||||
if(GenderEnum.MAN.getCode().equals(user.getGender()) && !user.getNoGreet().equals(1)){
|
||||
// 获取他的女粉丝
|
||||
Page<IdDTO> page = new Page<>(1,500);
|
||||
int current = 0;
|
||||
while (true){
|
||||
current++;
|
||||
page.setCurrent(current);
|
||||
Page<IdDTO> userIdPage = userFollowMapper.pageFanUserIdByGender(page, userId,GenderEnum.WOMEN.getCode());
|
||||
if(userIdPage.getRecords().isEmpty()){
|
||||
break;
|
||||
}
|
||||
List<Long> userIds = userIdPage.getRecords().stream().map(IdDTO::getId).collect(Collectors.toList());
|
||||
yunxinHttpService.sendOnlineAttentionNotice(userIds, user);
|
||||
if(userIdPage.getRecords().size() < 500){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateUserInfoSB(Long userId, String ip,String imei) {
|
||||
String address = AddressUtils.getRealAddressByIP(ip);
|
||||
UserInfo userInfo = userInfoService.getById(userId);
|
||||
UserInfo update = new UserInfo();
|
||||
update.setUserId(userId);
|
||||
update.setLoginCount(userInfo.getLoginCount()==null?0:userInfo.getLoginCount()+1);
|
||||
update.setLastLoginIp(ip);
|
||||
update.setLastLoginTime(LocalDateTime.now());
|
||||
update.setLastLocation(address);
|
||||
if(StringUtils.isNotBlank(imei)){
|
||||
update.setImei(imei);
|
||||
}
|
||||
userInfoService.updateById(update);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CommonConsumerEnum getType() {
|
||||
return CommonConsumerEnum.LOGIN;
|
||||
|
||||
@@ -35,7 +35,7 @@ public class WindowGiftNotifyHandle implements IHandle{
|
||||
Gift gift = windowGift.getGift();
|
||||
Set<Long> userIds = onlineUserTodayCache.getAllOnlineToday();
|
||||
List<Long> userIdList = new ArrayList<>(userIds);
|
||||
List<List<Long>> lists = Lists.partition(userIdList, 300);
|
||||
List<List<Long>> lists = Lists.partition(userIdList, 500);
|
||||
for (List<Long> list : lists) {
|
||||
SendGiftWindowsAmountNoticeData data = new SendGiftWindowsAmountNoticeData();
|
||||
data.setId(fromUser.getId());
|
||||
|
||||
@@ -9,6 +9,8 @@ import java.time.LocalDateTime;
|
||||
@Data
|
||||
public class LoginNotifyDTO extends CommonDTO {
|
||||
private Long userId;
|
||||
private String clientIP;
|
||||
private String imei;
|
||||
|
||||
private LocalDateTime happenTime;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user