123
This commit is contained in:
@@ -217,21 +217,6 @@ public class CaiLoginManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void recordLoginInfo(User user, String ip,String imei) {
|
|
||||||
String address = AddressUtils.getRealAddressByIP(ip);
|
|
||||||
UserInfo userInfo = userInfoService.getById(user.getId());
|
|
||||||
UserInfo update = new UserInfo();
|
|
||||||
update.setUserId(user.getId());
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 退出登录
|
* 退出登录
|
||||||
@@ -262,9 +247,6 @@ public class CaiLoginManager {
|
|||||||
loginUser.setUserType(UserType.APP_USER.getUserType());
|
loginUser.setUserType(UserType.APP_USER.getUserType());
|
||||||
LoginHelper.login(loginUser);
|
LoginHelper.login(loginUser);
|
||||||
sysLoginService.recordLogininfor(loginUser.getUsername(), UserType.APP_USER.getUserType(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
|
sysLoginService.recordLogininfor(loginUser.getUsername(), UserType.APP_USER.getUserType(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
|
||||||
String clientIP = ServletUtils.getClientIP();
|
|
||||||
String imei = ServletUtils.getImei();
|
|
||||||
ExecutorConstant.COMMON_EXECUTOR.execute(() -> recordLoginInfo(user,clientIP,imei));
|
|
||||||
return StpUtil.getTokenValue();
|
return StpUtil.getTokenValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,14 +61,17 @@ public class MemberPrice implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 有效期(天)
|
* 有效期(天)
|
||||||
*/
|
*/
|
||||||
|
@Schema(description = "有效期(天)")
|
||||||
private Integer expires;
|
private Integer expires;
|
||||||
/**
|
/**
|
||||||
* 状态 0 可用 1不可用
|
* 状态 0 可用 1不可用
|
||||||
*/
|
*/
|
||||||
|
@Schema(hidden = true)
|
||||||
private Integer status;
|
private Integer status;
|
||||||
/**
|
/**
|
||||||
* 永久状态 0 不是 1是
|
* 永久状态 0 不是 1是
|
||||||
*/
|
*/
|
||||||
|
@Schema(description = "永久状态 0-不是 1-是")
|
||||||
private Integer longs;
|
private Integer longs;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public class MemberSkill implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 类型 0 普通 1 超级
|
* 类型 0 普通 1 超级
|
||||||
*/
|
*/
|
||||||
|
@Schema(description = "会员类型 0 普通 1 超级")
|
||||||
private Integer memberType;
|
private Integer memberType;
|
||||||
/**
|
/**
|
||||||
* 名称
|
* 名称
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.ruoyi.cai.dto.commom;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class IdDTO {
|
||||||
|
private Long id;
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ import com.ruoyi.cai.mq.handle.dto.LoginNotifyDTO;
|
|||||||
import com.ruoyi.cai.service.AnchorService;
|
import com.ruoyi.cai.service.AnchorService;
|
||||||
import com.ruoyi.common.core.domain.PageQuery;
|
import com.ruoyi.common.core.domain.PageQuery;
|
||||||
import com.ruoyi.common.helper.LoginHelper;
|
import com.ruoyi.common.helper.LoginHelper;
|
||||||
|
import com.ruoyi.common.utils.ServletUtils;
|
||||||
import org.redisson.api.RBucket;
|
import org.redisson.api.RBucket;
|
||||||
import org.redisson.api.RedissonClient;
|
import org.redisson.api.RedissonClient;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -117,6 +118,8 @@ public class HomeManager {
|
|||||||
if(userId != null){
|
if(userId != null){
|
||||||
LoginNotifyDTO loginUserDTO = new LoginNotifyDTO();
|
LoginNotifyDTO loginUserDTO = new LoginNotifyDTO();
|
||||||
loginUserDTO.setUserId(userId);
|
loginUserDTO.setUserId(userId);
|
||||||
|
loginUserDTO.setImei(ServletUtils.getImei());
|
||||||
|
loginUserDTO.setClientIP(ServletUtils.getClientIP());
|
||||||
amqpProducer.sendCommonMq(loginUserDTO);
|
amqpProducer.sendCommonMq(loginUserDTO);
|
||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ public class LockManager {
|
|||||||
public static final String LOCK_SEND_GUARD_REDIS = RedisHttpConstant.REDIS_P + "lock:sendGuard:%s";
|
public static final String LOCK_SEND_GUARD_REDIS = RedisHttpConstant.REDIS_P + "lock:sendGuard:%s";
|
||||||
public static final String LOCK_SEND_GIFT_REDIS = RedisHttpConstant.REDIS_P + "lock:sendGift:%s";
|
public static final String LOCK_SEND_GIFT_REDIS = RedisHttpConstant.REDIS_P + "lock:sendGift:%s";
|
||||||
public static final String LOCK_VIDEO_SETTLE_REDIS = RedisHttpConstant.REDIS_P + "lock:videoSettle:%s";
|
public static final String LOCK_VIDEO_SETTLE_REDIS = RedisHttpConstant.REDIS_P + "lock:videoSettle:%s";
|
||||||
|
public static final String LOCK_ONLINE_LOGIN_NOTICE_REDIS = RedisHttpConstant.REDIS_P + "lockHand:loginFansNotice:%s";
|
||||||
|
|
||||||
public static String getRegisterLockKey(String mobile){
|
public static String getRegisterLockKey(String mobile){
|
||||||
return String.format(LOCK_REGISTER_REDIS,mobile);
|
return String.format(LOCK_REGISTER_REDIS,mobile);
|
||||||
@@ -39,4 +40,8 @@ public class LockManager {
|
|||||||
public static String getSendGiftLock(Long userId){
|
public static String getSendGiftLock(Long userId){
|
||||||
return String.format(LOCK_SEND_GIFT_REDIS,userId);
|
return String.format(LOCK_SEND_GIFT_REDIS,userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getLoginNoticeFansLock(Long userId){
|
||||||
|
return String.format(LOCK_ONLINE_LOGIN_NOTICE_REDIS,userId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.ruoyi.cai.domain.UserFollow;
|
import com.ruoyi.cai.domain.UserFollow;
|
||||||
import com.ruoyi.cai.dto.app.query.StarQuery;
|
import com.ruoyi.cai.dto.app.query.StarQuery;
|
||||||
import com.ruoyi.cai.dto.app.vo.user.UserStarOrVisitorList;
|
import com.ruoyi.cai.dto.app.vo.user.UserStarOrVisitorList;
|
||||||
|
import com.ruoyi.cai.dto.commom.IdDTO;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,4 +26,6 @@ public interface UserFollowMapper extends BaseMapper<UserFollow> {
|
|||||||
* 查询我的粉丝 (关注我的人)
|
* 查询我的粉丝 (关注我的人)
|
||||||
*/
|
*/
|
||||||
Page<UserStarOrVisitorList> pageMyFansApp(@Param("build") Page<Object> build, @Param("query") StarQuery query);
|
Page<UserStarOrVisitorList> pageMyFansApp(@Param("build") Page<Object> build, @Param("query") StarQuery query);
|
||||||
|
|
||||||
|
Page<IdDTO> pageFanUserIdByGender(@Param("page") Page<IdDTO> page, @Param("userId") Long userId, @Param("gender") Integer gender);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +1,107 @@
|
|||||||
package com.ruoyi.cai.mq.handle;
|
package com.ruoyi.cai.mq.handle;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
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.dto.CommonConsumerEnum;
|
||||||
import com.ruoyi.cai.mq.handle.dto.LoginNotifyDTO;
|
import com.ruoyi.cai.mq.handle.dto.LoginNotifyDTO;
|
||||||
import com.ruoyi.cai.mq.handle.dto.RankNotifyDTO;
|
import com.ruoyi.cai.notice.YunxinHttpService;
|
||||||
import com.ruoyi.cai.rank.RankManager;
|
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 com.ruoyi.framework.OnlineUserTodayCache;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
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
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class LoginNotifyHandle implements IHandle {
|
public class LoginNotifyHandle implements IHandle {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private OnlineUserTodayCache onlineUserTodayCache;
|
private OnlineUserTodayCache onlineUserTodayCache;
|
||||||
|
@Autowired
|
||||||
|
private UserInfoService userInfoService;
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
@Autowired
|
||||||
|
private RedissonClient redissonClient;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(String message) {
|
public void run(String message) {
|
||||||
LoginNotifyDTO loginNotify = JSON.parseObject(message, LoginNotifyDTO.class);
|
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
|
@Override
|
||||||
public CommonConsumerEnum getType() {
|
public CommonConsumerEnum getType() {
|
||||||
return CommonConsumerEnum.LOGIN;
|
return CommonConsumerEnum.LOGIN;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class WindowGiftNotifyHandle implements IHandle{
|
|||||||
Gift gift = windowGift.getGift();
|
Gift gift = windowGift.getGift();
|
||||||
Set<Long> userIds = onlineUserTodayCache.getAllOnlineToday();
|
Set<Long> userIds = onlineUserTodayCache.getAllOnlineToday();
|
||||||
List<Long> userIdList = new ArrayList<>(userIds);
|
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) {
|
for (List<Long> list : lists) {
|
||||||
SendGiftWindowsAmountNoticeData data = new SendGiftWindowsAmountNoticeData();
|
SendGiftWindowsAmountNoticeData data = new SendGiftWindowsAmountNoticeData();
|
||||||
data.setId(fromUser.getId());
|
data.setId(fromUser.getId());
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import java.time.LocalDateTime;
|
|||||||
@Data
|
@Data
|
||||||
public class LoginNotifyDTO extends CommonDTO {
|
public class LoginNotifyDTO extends CommonDTO {
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
private String clientIP;
|
||||||
|
private String imei;
|
||||||
|
|
||||||
private LocalDateTime happenTime;
|
private LocalDateTime happenTime;
|
||||||
|
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ public class UserFollowServiceImpl extends ServiceImpl<UserFollowMapper, UserFol
|
|||||||
userFollow.setFollowUser(realStarUser);
|
userFollow.setFollowUser(realStarUser);
|
||||||
this.save(userFollow);
|
this.save(userFollow);
|
||||||
userCountService.star(fromUserId, realStarUser);
|
userCountService.star(fromUserId, realStarUser);
|
||||||
|
// 给你关注的人发消息
|
||||||
yunxinHttpService.followedSendMessage(realStarUser, user, LocalDateTime.now());
|
yunxinHttpService.followedSendMessage(realStarUser, user, LocalDateTime.now());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,6 +121,7 @@ public class UserFollowServiceImpl extends ServiceImpl<UserFollowMapper, UserFol
|
|||||||
userFollow.setFollowUser(starOrVisitorReq.getToUserId());
|
userFollow.setFollowUser(starOrVisitorReq.getToUserId());
|
||||||
this.save(userFollow);
|
this.save(userFollow);
|
||||||
userCountService.star(fromUserId, starOrVisitorReq.getToUserId());
|
userCountService.star(fromUserId, starOrVisitorReq.getToUserId());
|
||||||
|
// 给你关注的人发消息
|
||||||
yunxinHttpService.followedSendMessage(starOrVisitorReq.getToUserId(), user, LocalDateTime.now());
|
yunxinHttpService.followedSendMessage(starOrVisitorReq.getToUserId(), user, LocalDateTime.now());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
where t1.follow_user = #{query.userId}
|
where t1.follow_user = #{query.userId}
|
||||||
order by t1.create_time desc
|
order by t1.create_time desc
|
||||||
</select>
|
</select>
|
||||||
|
<select id="pageFanUserIdByGender" resultType="com.ruoyi.cai.dto.commom.IdDTO">
|
||||||
|
select t2.id
|
||||||
|
from cai_user_follow t1
|
||||||
|
join cai_user t2 on t1.user_id = t2.id
|
||||||
|
where t1.follow_user = #{userId} and t2.gender = #{gender}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -17,20 +18,20 @@ public class OnlineUserTodayCache {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RedissonClient redissonClient;
|
private RedissonClient redissonClient;
|
||||||
|
|
||||||
private String getKey(){
|
private String getKey(LocalDateTime dateTime){
|
||||||
String today = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
String today = dateTime.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
||||||
return String.format(CacheConstants.ONLINE_TODAY_TOKEN_KEY,today);
|
return String.format(CacheConstants.ONLINE_TODAY_TOKEN_KEY,today);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addOnlineUserId(Long userId){
|
public boolean addOnlineUserId(Long userId, LocalDateTime dateTime){
|
||||||
RSet<Long> set = redissonClient.getSet(getKey());
|
RSet<Long> set = redissonClient.getSet(getKey(dateTime));
|
||||||
boolean res = set.add(userId);
|
boolean res = set.add(userId);
|
||||||
set.expire(Duration.ofDays(1));
|
set.expire(Duration.ofDays(1));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Long> getAllOnlineToday(){
|
public Set<Long> getAllOnlineToday(){
|
||||||
RSet<Long> set = redissonClient.getSet(getKey());
|
RSet<Long> set = redissonClient.getSet(getKey(LocalDateTime.now()));
|
||||||
return set.readAll();
|
return set.readAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user