|
@@ -0,0 +1,60 @@
|
|
|
+package com.fdkankan.ucenter.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.fdkankan.common.util.JwtUtil;
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
+import com.fdkankan.ucenter.entity.LoginLog;
|
|
|
+import com.fdkankan.ucenter.mapper.ILoginLogMapper;
|
|
|
+import com.fdkankan.ucenter.service.ILoginLogService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fdkankan.ucenter.util.DateUserUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2022-09-28
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class LoginLogServiceImpl extends ServiceImpl<ILoginLogMapper, LoginLog> implements ILoginLogService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RedisUtil redisUtil;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addLog(String clientIP, String token) {
|
|
|
+ try {
|
|
|
+ String tokenKey = "ucenter:active:token:"+ token;
|
|
|
+ if(redisUtil.hasKey(tokenKey)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String username = JwtUtil.getUsername(token);
|
|
|
+ String userNameKey = "ucenter:active:userName:"+ username;
|
|
|
+ if(redisUtil.hasKey(userNameKey)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<LoginLog> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.between(LoginLog::getCreateTime, DateUserUtil.getZeroDate(),DateUserUtil.getLastDate());
|
|
|
+ LoginLog one = this.getOne(wrapper);
|
|
|
+ if(one == null){
|
|
|
+ one = new LoginLog();
|
|
|
+ one.setUserName(username);
|
|
|
+ one.setIp(clientIP);
|
|
|
+ this.save(one);
|
|
|
+ Long exTime = DateUserUtil.getLastNowTime();
|
|
|
+ if(exTime >10){
|
|
|
+ redisUtil.set("ucenter:active:userName:"+ username,"1",exTime -10);
|
|
|
+ redisUtil.set("ucenter:active:token:"+ token,"1",exTime -10);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|