|
@@ -7,15 +7,22 @@ import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import shop.alien.entity.second.LifeUserLog;
|
|
|
import shop.alien.entity.store.LifeUser;
|
|
import shop.alien.entity.store.LifeUser;
|
|
|
import shop.alien.entity.store.vo.LifeUserVo;
|
|
import shop.alien.entity.store.vo.LifeUserVo;
|
|
|
import shop.alien.gateway.config.BaseRedisService;
|
|
import shop.alien.gateway.config.BaseRedisService;
|
|
|
|
|
+import shop.alien.gateway.feign.SecondServiceFeign;
|
|
|
|
|
+import shop.alien.gateway.mapper.LifeUserLogMapper;
|
|
|
import shop.alien.gateway.mapper.LifeUserMapper;
|
|
import shop.alien.gateway.mapper.LifeUserMapper;
|
|
|
import shop.alien.util.common.JwtUtil;
|
|
import shop.alien.util.common.JwtUtil;
|
|
|
|
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 用户
|
|
* 用户
|
|
@@ -26,12 +33,19 @@ public class LifeUserService extends ServiceImpl<LifeUserMapper, LifeUser> {
|
|
|
|
|
|
|
|
private final LifeUserMapper lifeUserMapper;
|
|
private final LifeUserMapper lifeUserMapper;
|
|
|
|
|
|
|
|
|
|
+ private final LifeUserLogMapper lifeUserLogMapper;
|
|
|
|
|
+
|
|
|
private final BaseRedisService baseRedisService;
|
|
private final BaseRedisService baseRedisService;
|
|
|
|
|
|
|
|
|
|
+ private final SecondServiceFeign secondServiceFeign;
|
|
|
|
|
+
|
|
|
|
|
+ @Value("${risk-control.account-abnormal.reg-count24h:4}")
|
|
|
|
|
+ private Integer regCount24h;
|
|
|
|
|
+
|
|
|
@Value("${jwt.expiration-time}")
|
|
@Value("${jwt.expiration-time}")
|
|
|
private String effectiveTime;
|
|
private String effectiveTime;
|
|
|
|
|
|
|
|
- public LifeUserVo userLogin(String phoneNum) {
|
|
|
|
|
|
|
+ public LifeUserVo userLogin(String phoneNum, String macIp) {
|
|
|
int effectiveTimeInt = Integer.parseInt(effectiveTime.substring(0, effectiveTime.length() - 1));
|
|
int effectiveTimeInt = Integer.parseInt(effectiveTime.substring(0, effectiveTime.length() - 1));
|
|
|
String effectiveTimeUnit = effectiveTime.substring(effectiveTime.length() - 1);
|
|
String effectiveTimeUnit = effectiveTime.substring(effectiveTime.length() - 1);
|
|
|
long effectiveTimeIntLong = 0L;
|
|
long effectiveTimeIntLong = 0L;
|
|
@@ -74,6 +88,8 @@ public class LifeUserService extends ServiceImpl<LifeUserMapper, LifeUser> {
|
|
|
userVo.setToken(JwtUtil.createJWT("user_" + phoneNum, lifeUser.getUserName(), JSONObject.toJSONString(tokenMap), effectiveTimeIntLong));
|
|
userVo.setToken(JwtUtil.createJWT("user_" + phoneNum, lifeUser.getUserName(), JSONObject.toJSONString(tokenMap), effectiveTimeIntLong));
|
|
|
// userVo.setToken(JWTUtils.createToken(tokenMap));
|
|
// userVo.setToken(JWTUtils.createToken(tokenMap));
|
|
|
baseRedisService.setString("user_" + phoneNum, userVo.getToken());
|
|
baseRedisService.setString("user_" + phoneNum, userVo.getToken());
|
|
|
|
|
+ // 二手平台登录log,同一个macip登录多账号记录
|
|
|
|
|
+ addLifeUserLogInfo(user2, macIp);
|
|
|
return userVo;
|
|
return userVo;
|
|
|
} else {
|
|
} else {
|
|
|
return null;
|
|
return null;
|
|
@@ -90,6 +106,8 @@ public class LifeUserService extends ServiceImpl<LifeUserMapper, LifeUser> {
|
|
|
String token = JwtUtil.createJWT("user_" + phoneNum, user.getUserName(), JSONObject.toJSONString(tokenMap), effectiveTimeIntLong);
|
|
String token = JwtUtil.createJWT("user_" + phoneNum, user.getUserName(), JSONObject.toJSONString(tokenMap), effectiveTimeIntLong);
|
|
|
userVo.setToken(token);
|
|
userVo.setToken(token);
|
|
|
baseRedisService.setString("user_" + phoneNum, token);
|
|
baseRedisService.setString("user_" + phoneNum, token);
|
|
|
|
|
+ // 二手平台登录log,同一个macip登录多账号记录
|
|
|
|
|
+ addLifeUserLogInfo(user, macIp);
|
|
|
return userVo;
|
|
return userVo;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -100,4 +118,36 @@ public class LifeUserService extends ServiceImpl<LifeUserMapper, LifeUser> {
|
|
|
return this.getOne(lambdaQueryWrapper);
|
|
return this.getOne(lambdaQueryWrapper);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 用户登录log存放(加入mac地址)
|
|
|
|
|
+ */
|
|
|
|
|
+ public void addLifeUserLogInfo(LifeUser user, String macIp) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ LifeUserLog lifeUserLog = new LifeUserLog();
|
|
|
|
|
+ lifeUserLog.setUserId(user.getId());
|
|
|
|
|
+ lifeUserLog.setUserName(user.getUserName());
|
|
|
|
|
+ lifeUserLog.setMacIp(macIp);
|
|
|
|
|
+ lifeUserLog.setCreatedTime(new Date());
|
|
|
|
|
+ lifeUserLogMapper.insert(lifeUserLog);
|
|
|
|
|
+
|
|
|
|
|
+ String startDate = LocalDateTime.now().minusHours(24L).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
+ String endDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
+ List<LifeUserLog> lsit = lifeUserLogMapper.getLifeUserLogByDate(startDate, endDate, macIp);
|
|
|
|
|
+
|
|
|
|
|
+ secondServiceFeign.recordRiskControlData(1, 2, "账号异常","1", "测试");
|
|
|
|
|
+
|
|
|
|
|
+ if (lsit.size() > regCount24h) {
|
|
|
|
|
+ String detailInfo = lsit.stream()
|
|
|
|
|
+ .map(row -> row.getUserId().toString())
|
|
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
|
|
+ secondServiceFeign.recordRiskControlData(null, 2, "账号异常", "1", detailInfo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ secondServiceFeign.createPointsRecord(user.getId(), 300, 1);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("用户登录log存放异常:{}");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|