|
@@ -47,6 +47,8 @@ public class LifeUserService extends ServiceImpl<LifeUserGatewayMapper, LifeUser
|
|
|
|
|
|
|
|
private final SecondRiskControlRecordMapper secondRiskControlRecordMapper;
|
|
private final SecondRiskControlRecordMapper secondRiskControlRecordMapper;
|
|
|
|
|
|
|
|
|
|
+ private final LifeUserLogTransactionService lifeUserLogTransactionService;
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RiskControlProperties riskControlProperties;
|
|
private RiskControlProperties riskControlProperties;
|
|
|
|
|
|
|
@@ -135,6 +137,7 @@ public class LifeUserService extends ServiceImpl<LifeUserGatewayMapper, LifeUser
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 用户登录log存放(加入mac地址)
|
|
* 用户登录log存放(加入mac地址)
|
|
|
|
|
+ * 记录用户登录信息并进行风控检查
|
|
|
*/
|
|
*/
|
|
|
@Transactional
|
|
@Transactional
|
|
|
public void addLifeUserLogInfo(LifeUser user, String macIp) {
|
|
public void addLifeUserLogInfo(LifeUser user, String macIp) {
|
|
@@ -144,12 +147,13 @@ public class LifeUserService extends ServiceImpl<LifeUserGatewayMapper, LifeUser
|
|
|
lifeUserLog.setUserName(user.getUserName());
|
|
lifeUserLog.setUserName(user.getUserName());
|
|
|
lifeUserLog.setMacIp(macIp);
|
|
lifeUserLog.setMacIp(macIp);
|
|
|
lifeUserLog.setCreatedTime(new Date());
|
|
lifeUserLog.setCreatedTime(new Date());
|
|
|
- int count = lifeUserLogMapper.insert(lifeUserLog);
|
|
|
|
|
|
|
+ // 通过独立服务类调用,确保事务代理生效,插入操作立即提交
|
|
|
|
|
+ int count = lifeUserLogTransactionService.insertLifeUserLog(lifeUserLog);
|
|
|
if (count > 0) {
|
|
if (count > 0) {
|
|
|
String startDate = LocalDateTime.now().minusHours(24L).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
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"));
|
|
String endDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
- // 使用一个新的事务来查询,确保能看到刚才插入的数据
|
|
|
|
|
- List<LifeUserLog> lsit = getLifeUserLogByDateInNewTransaction(startDate, endDate, macIp);
|
|
|
|
|
|
|
+ // 通过独立服务类查询,确保能看到刚才插入并提交的数据
|
|
|
|
|
+ List<LifeUserLog> lsit = lifeUserLogTransactionService.getLifeUserLogByDate(startDate, endDate, macIp);
|
|
|
|
|
|
|
|
if (lsit.size() > riskControlProperties.getAccountAbnormal().getRegCount24h() && !isViolation(startDate, endDate, macIp, user.getId())) {
|
|
if (lsit.size() > riskControlProperties.getAccountAbnormal().getRegCount24h() && !isViolation(startDate, endDate, macIp, user.getId())) {
|
|
|
String detailInfo = lsit.stream()
|
|
String detailInfo = lsit.stream()
|
|
@@ -166,11 +170,16 @@ public class LifeUserService extends ServiceImpl<LifeUserGatewayMapper, LifeUser
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @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) {
|
|
public boolean isViolation(String startDate, String endDate, String macIp, Integer userId) {
|
|
|
List<SecondRiskControlRecord> list = secondRiskControlRecordMapper.selectByBusinessId(startDate, endDate, macIp);
|
|
List<SecondRiskControlRecord> list = secondRiskControlRecordMapper.selectByBusinessId(startDate, endDate, macIp);
|
|
|
for (SecondRiskControlRecord record : list) {
|
|
for (SecondRiskControlRecord record : list) {
|