|
|
@@ -145,6 +145,7 @@ public class LifeUserService extends ServiceImpl<LifeUserGatewayMapper, LifeUser
|
|
|
|
|
|
/**
|
|
|
* 用户登录log存放(加入mac地址)
|
|
|
+ * 记录用户登录信息并进行风控检查
|
|
|
*/
|
|
|
@Transactional
|
|
|
public void addLifeUserLogInfo(LifeUser user, String macIp) {
|
|
|
@@ -154,11 +155,12 @@ public class LifeUserService extends ServiceImpl<LifeUserGatewayMapper, LifeUser
|
|
|
lifeUserLog.setUserName(user.getUserName());
|
|
|
lifeUserLog.setMacIp(macIp);
|
|
|
lifeUserLog.setCreatedTime(new Date());
|
|
|
- int count = lifeUserLogMapper.insert(lifeUserLog);
|
|
|
+ // 将插入操作放到新事务中,确保立即提交
|
|
|
+ int count = insertLifeUserLogInNewTransaction(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 = getLifeUserLogByDateInNewTransaction(startDate, endDate, macIp);
|
|
|
|
|
|
if (lsit.size() > riskControlProperties.getAccountAbnormal().getRegCount24h() && !isViolation(startDate, endDate, macIp, user.getId())) {
|
|
|
@@ -176,11 +178,42 @@ public class LifeUserService extends ServiceImpl<LifeUserGatewayMapper, LifeUser
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 在新事务中插入用户登录日志
|
|
|
+ * 使用 REQUIRES_NEW 确保插入操作立即提交,便于后续查询
|
|
|
+ *
|
|
|
+ * @param lifeUserLog 用户登录日志对象
|
|
|
+ * @return int 插入成功的记录数
|
|
|
+ */
|
|
|
+ @Transactional(propagation = Propagation.REQUIRES_NEW)
|
|
|
+ public int insertLifeUserLogInNewTransaction(LifeUserLog lifeUserLog) {
|
|
|
+ return lifeUserLogMapper.insert(lifeUserLog);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 在新事务中查询指定时间段内的用户登录日志
|
|
|
+ * 使用 REQUIRES_NEW 确保能读取到已提交的最新数据
|
|
|
+ *
|
|
|
+ * @param startDate 开始时间
|
|
|
+ * @param endDate 结束时间
|
|
|
+ * @param macIp MAC地址/IP
|
|
|
+ * @return List<LifeUserLog> 用户登录日志列表
|
|
|
+ */
|
|
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
|
|
public List<LifeUserLog> getLifeUserLogByDateInNewTransaction(String startDate, String endDate, String macIp) {
|
|
|
return lifeUserLogMapper.getLifeUserLogByDate(startDate, endDate, macIp);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 判断是否已存在违规记录
|
|
|
+ * 检查指定时间段内是否已经记录过该用户的风控信息
|
|
|
+ *
|
|
|
+ * @param startDate 开始时间
|
|
|
+ * @param endDate 结束时间
|
|
|
+ * @param macIp MAC地址/IP
|
|
|
+ * @param userId 用户ID
|
|
|
+ * @return boolean true-已存在违规记录,false-不存在
|
|
|
+ */
|
|
|
public boolean isViolation(String startDate, String endDate, String macIp, Integer userId) {
|
|
|
List<SecondRiskControlRecord> list = secondRiskControlRecordMapper.selectByBusinessId(startDate, endDate, macIp);
|
|
|
for (SecondRiskControlRecord record : list) {
|