123
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
package com.ruoyi.cai.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("cai_login_min_log")
|
||||||
|
public class LoginMinLog implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID=1L;
|
||||||
|
|
||||||
|
@TableId(value = "id",type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
private LocalDate loginDate;
|
||||||
|
private Long userId;
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.ruoyi.cai.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.ruoyi.cai.domain.LoginMinLog;
|
||||||
|
|
||||||
|
public interface LoginMinLogMapper extends BaseMapper<LoginMinLog> {
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ import com.ruoyi.cai.mapper.UserFollowMapper;
|
|||||||
import com.ruoyi.cai.mq.CommonConsumerEnum;
|
import com.ruoyi.cai.mq.CommonConsumerEnum;
|
||||||
import com.ruoyi.cai.mq.handle.dto.LoginNotifyDTO;
|
import com.ruoyi.cai.mq.handle.dto.LoginNotifyDTO;
|
||||||
import com.ruoyi.cai.notice.YunxinHttpService;
|
import com.ruoyi.cai.notice.YunxinHttpService;
|
||||||
|
import com.ruoyi.cai.service.LoginMinLogService;
|
||||||
import com.ruoyi.cai.service.UserInfoService;
|
import com.ruoyi.cai.service.UserInfoService;
|
||||||
import com.ruoyi.cai.service.UserService;
|
import com.ruoyi.cai.service.UserService;
|
||||||
import com.ruoyi.common.utils.ip.AddressUtils;
|
import com.ruoyi.common.utils.ip.AddressUtils;
|
||||||
@@ -40,6 +41,8 @@ public class LoginNotifyHandle implements IHandle {
|
|||||||
private UserService userService;
|
private UserService userService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedissonClient redissonClient;
|
private RedissonClient redissonClient;
|
||||||
|
@Autowired
|
||||||
|
private LoginMinLogService loginMinLogService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(String message) {
|
public void run(String message) {
|
||||||
@@ -52,6 +55,11 @@ public class LoginNotifyHandle implements IHandle {
|
|||||||
this.updateUserInfoSB(loginNotify.getUserId(),loginNotify.getClientIP(),loginNotify.getImei());
|
this.updateUserInfoSB(loginNotify.getUserId(),loginNotify.getClientIP(),loginNotify.getImei());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
loginMinLogService.saveData(loginNotify);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.getMessage(),e);
|
||||||
|
}
|
||||||
// 上线通知
|
// 上线通知
|
||||||
String loginNoticeFansLock = LockManager.getLoginNoticeFansLock(loginNotify.getUserId());
|
String loginNoticeFansLock = LockManager.getLoginNoticeFansLock(loginNotify.getUserId());
|
||||||
RBucket<String> bucket = redissonClient.getBucket(loginNoticeFansLock);
|
RBucket<String> bucket = redissonClient.getBucket(loginNoticeFansLock);
|
||||||
@@ -59,6 +67,7 @@ public class LoginNotifyHandle implements IHandle {
|
|||||||
if(boo){
|
if(boo){
|
||||||
sendOnlineNotice(loginNotify.getUserId());
|
sendOnlineNotice(loginNotify.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.ruoyi.cai.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.ruoyi.cai.domain.LoginMinLog;
|
||||||
|
import com.ruoyi.cai.mq.handle.dto.LoginNotifyDTO;
|
||||||
|
|
||||||
|
public interface LoginMinLogService extends IService<LoginMinLog> {
|
||||||
|
void saveData(LoginNotifyDTO loginNotify);
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.ruoyi.cai.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.ruoyi.cai.domain.LoginMinLog;
|
||||||
|
import com.ruoyi.cai.mapper.LoginMinLogMapper;
|
||||||
|
import com.ruoyi.cai.mq.handle.dto.LoginNotifyDTO;
|
||||||
|
import com.ruoyi.cai.util.IdLockManager;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class LoginMinLogServiceImpl extends ServiceImpl<LoginMinLogMapper, LoginMinLog> implements LoginMinLogService {
|
||||||
|
@Override
|
||||||
|
public void saveData(LoginNotifyDTO loginNotify) {
|
||||||
|
LocalDate now = loginNotify.getHappenTime().toLocalDate();
|
||||||
|
boolean exists = this.exists(Wrappers.lambdaQuery(LoginMinLog.class)
|
||||||
|
.eq(LoginMinLog::getLoginDate, now)
|
||||||
|
.eq(LoginMinLog::getUserId, loginNotify.getUserId()));
|
||||||
|
if(exists){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String lockKey = String.format("loginMinLog:%s", loginNotify.getUserId());
|
||||||
|
IdLockManager.executeWithLock(lockKey, () -> {
|
||||||
|
boolean existsF = this.exists(Wrappers.lambdaQuery(LoginMinLog.class)
|
||||||
|
.eq(LoginMinLog::getLoginDate, now)
|
||||||
|
.eq(LoginMinLog::getUserId, loginNotify.getUserId()));
|
||||||
|
if(existsF){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LoginMinLog log = new LoginMinLog();
|
||||||
|
log.setLoginDate(now);
|
||||||
|
log.setUserId(loginNotify.getUserId());
|
||||||
|
this.save(log);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user