|
|
@ -35,22 +35,39 @@ public class OcrVo { |
|
|
|
String idCardName = "姓名"; |
|
|
|
String idCardSex = "性别"; |
|
|
|
String idCardNo = "公民身份号码"; |
|
|
|
words.forEach(wordNode ->{ |
|
|
|
String nation = "民族"; |
|
|
|
for (int i = 0; i < words.size(); i++) { |
|
|
|
BaiDuVo.GeneralWord wordNode = words.get(i); |
|
|
|
String word = wordNode.getWords(); |
|
|
|
if (word.startsWith(idCardName)) { |
|
|
|
this.name = word.substring(idCardName.length()); |
|
|
|
this.name = word.length() != idCardName.length() ? |
|
|
|
word.substring(idCardName.length()) : |
|
|
|
i + 1 < words.size() ? words.get(i + 1).getWords() : null; |
|
|
|
} else if (word.startsWith(idCardSex)) { |
|
|
|
int sexIndex = 2; |
|
|
|
if (word.length() > sexIndex) { |
|
|
|
String sexWord = word.substring(sexIndex,sexIndex +1); |
|
|
|
this.sex = "女".equals(sexWord) ? (byte)0 : (byte)1; |
|
|
|
} else { |
|
|
|
String sexWord = i + 1 < words.size() ? words.get(i + 1).getWords() : null; |
|
|
|
this.sex = "女".equals(sexWord) ? (byte)0 : "男".equals(sexWord) ? (byte)1 : null; |
|
|
|
} |
|
|
|
|
|
|
|
int nationIndex = 5; |
|
|
|
if (word.length() > nationIndex) { |
|
|
|
this.nation = word.substring(nationIndex); |
|
|
|
} |
|
|
|
|
|
|
|
} else if (word.contains(nation)) { |
|
|
|
int nationIndex = word.indexOf(nation) + nation.length() + 1; |
|
|
|
if (nationIndex < word.length() ) { |
|
|
|
this.nation = word.substring(nationIndex); |
|
|
|
} else { |
|
|
|
this.nation = i + 1 < words.size() ? words.get(i + 1).getWords() : null; |
|
|
|
} |
|
|
|
} else if (word.startsWith(idCardNo)) { |
|
|
|
this.idCardNo = word.substring(6); |
|
|
|
this.age = IdcardUtil.getAgeByIdCard(this.idCardNo); |
|
|
|
int idCardIndex = 6; |
|
|
|
int idCardMinLength = 15; |
|
|
|
if (word.length() > idCardIndex) { |
|
|
@ -60,7 +77,16 @@ public class OcrVo { |
|
|
|
this.age = IdcardUtil.getAgeByIdCard(this.idCardNo); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
if (StrUtil.isEmpty(this.idCardNo)) { |
|
|
|
String lastWord = words.get(words.size() - 1).getWords(); |
|
|
|
this.idCardNo = lastWord.replaceAll("\\D", ""); |
|
|
|
int idCardMinLength = 15; |
|
|
|
if (StrUtil.isNotBlank(this.idCardNo) && this.idCardNo.length() >= idCardMinLength) { |
|
|
|
this.age = IdcardUtil.getAgeByIdCard(this.idCardNo); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|