|
@@ -23,9 +23,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
import java.time.temporal.ChronoUnit;
|
|
|
-import java.util.Arrays;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Optional;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
@@ -205,48 +203,56 @@ public class IdentityAuthService {
|
|
|
try {
|
|
try {
|
|
|
List<IdentityAuth> list = identityAuthRepo.findByStatusAndAutoValidated(AuthStatus.PENDING, false);
|
|
List<IdentityAuth> list = identityAuthRepo.findByStatusAndAutoValidated(AuthStatus.PENDING, false);
|
|
|
list.parallelStream().forEach(identityAuth -> {
|
|
list.parallelStream().forEach(identityAuth -> {
|
|
|
- log.info("实名 {}", identityAuth.getRealName());
|
|
|
|
|
- boolean success = false;
|
|
|
|
|
- String reason = null;
|
|
|
|
|
- User user = userRepo.findById(identityAuth.getUserId()).orElseThrow(new BusinessException("用户不存在"));
|
|
|
|
|
- if (user.getAuthStatus() == AuthStatus.SUCCESS) {
|
|
|
|
|
- audit(identityAuth.getId(), AuthStatus.SUCCESS, null);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- if (!Pattern.matches("[1-9]{1}[0-9]{5}(19|20)[0-9]{2}((0[1-9]{1})|(1[0-2]{1}))((0[1-9]{1})|([1-2]{1}[0-9]{1}|(3[0-1]{1})))[0-9]{3}[0-9x]{1}", identityAuth.getIdNo()
|
|
|
|
|
- .toLowerCase())) {
|
|
|
|
|
- audit(identityAuth.getId(), AuthStatus.FAIL, "身份证格式错误");
|
|
|
|
|
- return;
|
|
|
|
|
- } else {
|
|
|
|
|
- LocalDate birth = DateTimeUtils.toLocalDate(identityAuth.getIdNo().substring(6, 14), "yyyyMMdd");
|
|
|
|
|
- long age = ChronoUnit.YEARS.between(birth, LocalDate.now());
|
|
|
|
|
- if (age < 18) {
|
|
|
|
|
- audit(identityAuth.getId(), AuthStatus.FAIL, "未满18岁");
|
|
|
|
|
- return;
|
|
|
|
|
- } else if (age > 60) {
|
|
|
|
|
- audit(identityAuth.getId(), AuthStatus.FAIL, "超过60岁");
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ Map<String, Object> map = auth(identityAuth);
|
|
|
|
|
+ audit(identityAuth.getId(), (AuthStatus) map.get("status"), (String) map.get("reason"));
|
|
|
|
|
+ });
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("批量自动实名出错", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ public Map<String, Object> auth(IdentityAuth identityAuth) {
|
|
|
|
|
+ log.info("实名 {}", identityAuth.getRealName());
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
|
+ String reason = null;
|
|
|
|
|
+ User user = userRepo.findById(identityAuth.getUserId()).orElseThrow(new BusinessException("用户不存在"));
|
|
|
|
|
+ if (user.getAuthStatus() == AuthStatus.SUCCESS) {
|
|
|
|
|
+ result.put("status", AuthStatus.SUCCESS);
|
|
|
|
|
+ } else if (!Pattern.matches("[1-9]{1}[0-9]{5}(19|20)[0-9]{2}((0[1-9]{1})|(1[0-2]{1}))((0[1-9]{1})|([1-2]{1}[0-9]{1}|(3[0-1]{1})))[0-9]{3}[0-9x]{1}", identityAuth.getIdNo()
|
|
|
|
|
+ .toLowerCase())) {
|
|
|
|
|
+ result.put("status", AuthStatus.FAIL);
|
|
|
|
|
+ result.put("reason", "身份证格式错误");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ LocalDate birth = DateTimeUtils.toLocalDate(identityAuth.getIdNo().substring(6, 14), "yyyyMMdd");
|
|
|
|
|
+ long age = ChronoUnit.YEARS.between(birth, LocalDate.now());
|
|
|
|
|
+ if (age < 18) {
|
|
|
|
|
+ result.put("status", AuthStatus.FAIL);
|
|
|
|
|
+ result.put("reason", "未满18岁");
|
|
|
|
|
+ } else if (age > 60) {
|
|
|
|
|
+ result.put("status", AuthStatus.FAIL);
|
|
|
|
|
+ result.put("reason", "超过60岁");
|
|
|
|
|
+ } else {
|
|
|
int count = identityAuthRepo.countByIdNoAndStatus(identityAuth.getIdNo(), AuthStatus.SUCCESS);
|
|
int count = identityAuthRepo.countByIdNoAndStatus(identityAuth.getIdNo(), AuthStatus.SUCCESS);
|
|
|
|
|
|
|
|
if (count >= 3) {
|
|
if (count >= 3) {
|
|
|
- success = false;
|
|
|
|
|
- reason = "同一身份证注册超过3个";
|
|
|
|
|
|
|
+ result.put("status", AuthStatus.PENDING);
|
|
|
|
|
+ result.put("reason", "同一身份证注册超过3个");
|
|
|
} else {
|
|
} else {
|
|
|
try {
|
|
try {
|
|
|
validate(identityAuth.getRealName(), user.getPhone(), identityAuth.getIdNo());
|
|
validate(identityAuth.getRealName(), user.getPhone(), identityAuth.getIdNo());
|
|
|
- success = true;
|
|
|
|
|
|
|
+ result.put("status", AuthStatus.SUCCESS);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("自动实名出错", e);
|
|
log.error("自动实名出错", e);
|
|
|
- reason = e.getMessage();
|
|
|
|
|
|
|
+ if ("不匹配".equals(e.getMessage())) {
|
|
|
|
|
+ result.put("status", AuthStatus.FAIL);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ result.put("status", AuthStatus.PENDING);
|
|
|
|
|
+ }
|
|
|
|
|
+ result.put("reason", e.getMessage());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- audit(identityAuth.getId(), success ? AuthStatus.SUCCESS : AuthStatus.PENDING, reason);
|
|
|
|
|
- });
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("批量自动实名出错", e);
|
|
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|