|
|
@@ -5,23 +5,24 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import shop.alien.config.properties.RiskControlProperties;
|
|
|
import shop.alien.entity.second.LifeUserLog;
|
|
|
+import shop.alien.entity.second.SecondRiskControlRecord;
|
|
|
import shop.alien.entity.store.LifeUser;
|
|
|
import shop.alien.entity.store.vo.LifeUserVo;
|
|
|
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.mapper.second.SecondRiskControlRecordMapper;
|
|
|
import shop.alien.util.common.JwtUtil;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -37,10 +38,14 @@ public class LifeUserService extends ServiceImpl<LifeUserMapper, LifeUser> {
|
|
|
|
|
|
private final BaseRedisService baseRedisService;
|
|
|
|
|
|
- private final SecondServiceFeign secondServiceFeign;
|
|
|
+ private final SecondServiceFeign alienSecondFeign;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RiskControlProperties riskControlProperties;
|
|
|
+
|
|
|
+ private final SecondRiskControlRecordMapper secondRiskControlRecordMapper;
|
|
|
+
|
|
|
|
|
|
- @Value("${risk-control.account-abnormal.reg-count24h:4}")
|
|
|
- private Integer regCount24h;
|
|
|
|
|
|
@Value("${jwt.expiration-time}")
|
|
|
private String effectiveTime;
|
|
|
@@ -88,10 +93,10 @@ public class LifeUserService extends ServiceImpl<LifeUserMapper, LifeUser> {
|
|
|
userVo.setToken(JwtUtil.createJWT("user_" + phoneNum, lifeUser.getUserName(), JSONObject.toJSONString(tokenMap), effectiveTimeIntLong));
|
|
|
// userVo.setToken(JWTUtils.createToken(tokenMap));
|
|
|
baseRedisService.setString("user_" + phoneNum, userVo.getToken());
|
|
|
+
|
|
|
// 二手平台登录log,同一个macip登录多账号记录
|
|
|
addLifeUserLogInfo(user2, macIp);
|
|
|
- // 第一次登录,添加用户基础积分
|
|
|
- secondServiceFeign.createPointsRecord(user2.getId(), 300, 1);
|
|
|
+
|
|
|
return userVo;
|
|
|
} else {
|
|
|
return null;
|
|
|
@@ -108,8 +113,10 @@ public class LifeUserService extends ServiceImpl<LifeUserMapper, LifeUser> {
|
|
|
String token = JwtUtil.createJWT("user_" + phoneNum, user.getUserName(), JSONObject.toJSONString(tokenMap), effectiveTimeIntLong);
|
|
|
userVo.setToken(token);
|
|
|
baseRedisService.setString("user_" + phoneNum, token);
|
|
|
+
|
|
|
// 二手平台登录log,同一个macip登录多账号记录
|
|
|
addLifeUserLogInfo(user, macIp);
|
|
|
+
|
|
|
return userVo;
|
|
|
}
|
|
|
}
|
|
|
@@ -131,21 +138,38 @@ public class LifeUserService extends ServiceImpl<LifeUserMapper, LifeUser> {
|
|
|
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);
|
|
|
-
|
|
|
- if (lsit.size() > regCount24h) {
|
|
|
- String detailInfo = lsit.stream()
|
|
|
- .map(row -> row.getUserId().toString())
|
|
|
- .collect(Collectors.joining(","));
|
|
|
- secondServiceFeign.recordRiskControlData(null, 2, "账号异常", macIp, detailInfo);
|
|
|
+ int count = lifeUserLogMapper.insert(lifeUserLog);
|
|
|
+ if (count > 0) {
|
|
|
+ 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);
|
|
|
+
|
|
|
+ if (lsit.size() > riskControlProperties.getAccountAbnormal().getRegCount24h() && !isViolation(startDate, endDate, macIp, user.getId())) {
|
|
|
+ String detailInfo = lsit.stream()
|
|
|
+ .map(row -> row.getUserId().toString())
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+ alienSecondFeign.recordRiskControlData(user.getId(), 2, "账号异常", macIp, detailInfo);
|
|
|
+ }
|
|
|
}
|
|
|
+ // 第一次登录,添加用户基础积分
|
|
|
+ alienSecondFeign.createPointsRecord(user.getId(), 300, 1);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("用户登录log存放异常:{}");
|
|
|
+ log.error("用户登录log存放异常:{}", e);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ public boolean isViolation(String startDate, String endDate, String macIp, Integer userId) {
|
|
|
+ List<SecondRiskControlRecord> list = secondRiskControlRecordMapper.selectByBusinessId(startDate, endDate, macIp);
|
|
|
+ for (SecondRiskControlRecord record : list) {
|
|
|
+ // 将数组转换为包含整数的列表
|
|
|
+ List<Integer> userIdList = Arrays.stream(record.getDetailInfo().split(","))
|
|
|
+ .map(Integer::parseInt)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (userIdList.contains(userId)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|