|
@ -10,6 +10,7 @@ import lombok.NoArgsConstructor; |
|
|
import java.time.DateTimeException; |
|
|
import java.time.DateTimeException; |
|
|
import java.time.LocalDate; |
|
|
import java.time.LocalDate; |
|
|
import java.time.Period; |
|
|
import java.time.Period; |
|
|
|
|
|
import java.util.Date; |
|
|
import java.util.regex.Matcher; |
|
|
import java.util.regex.Matcher; |
|
|
import java.util.regex.Pattern; |
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
@ -56,6 +57,7 @@ public class IdCardRegexUtils { |
|
|
private String birthdayDay; |
|
|
private String birthdayDay; |
|
|
private String sex; |
|
|
private String sex; |
|
|
private Integer age; |
|
|
private Integer age; |
|
|
|
|
|
private LocalDate birthday; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -122,17 +124,18 @@ public class IdCardRegexUtils { |
|
|
String month = matcher.group("month"); |
|
|
String month = matcher.group("month"); |
|
|
String day = matcher.group("day"); |
|
|
String day = matcher.group("day"); |
|
|
String sex = matcher.group("sex"); |
|
|
String sex = matcher.group("sex"); |
|
|
|
|
|
LocalDate birthday; |
|
|
|
|
|
|
|
|
// ------- 年龄Start----------
|
|
|
// ------- 年龄Start----------
|
|
|
Integer age; |
|
|
Integer age; |
|
|
try { |
|
|
try { |
|
|
LocalDate birthday = LocalDate.of(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day)); |
|
|
birthday = LocalDate.of(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day)); |
|
|
age = Period.between(birthday, LocalDate.now()).getYears(); |
|
|
age = Period.between(birthday, LocalDate.now()).getYears(); |
|
|
} catch (DateTimeException e) { |
|
|
} catch (DateTimeException e) { |
|
|
throw new EpmetException("身份证号解析年龄失败:" + ExceptionUtils.getErrorStackTrace(e)); |
|
|
throw new EpmetException("身份证号解析年龄失败:" + ExceptionUtils.getErrorStackTrace(e)); |
|
|
} |
|
|
} |
|
|
// ------- 年龄End----------
|
|
|
// ------- 年龄End----------
|
|
|
return new ParsedContent(year, month, day, sex, age); |
|
|
return new ParsedContent(year, month, day, sex, age, birthday); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 其他类型暂时不可解析
|
|
|
// 其他类型暂时不可解析
|
|
|