提交 b5b8ce74 编写于 作者:  Peijun.zhao's avatar Peijun.zhao

add idNo check

上级 e28aefc5
流水线 #36067 已失败 于阶段
......@@ -166,12 +166,18 @@ public class CircleAccountServiceImpl implements CircleAccountService {
if(!diyAcctInitReq.getCode().equals("618")){
return null;
}
logger.info("createDiyAccount:{}", JSONObject.toJSONString(diyAcctInitReq));
List<Integer> savedIds = new ArrayList<>();
Map<Integer,DiyAcctInit> idCardMap = new HashMap<>();
try {
if (CollectionUtils.isNotEmpty(diyAcctInitReq.getDiyAcctInitList())) {
for (DiyAcctInit acctInit : diyAcctInitReq.getDiyAcctInitList()) {
if(!checkIdNum(acctInit.getCard())){
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "身份证号格式错误:" + acctInit.getCard());
}
String encryMobile = EncryptUtils.encryptContent(acctInit.getDecryMobile(), EncryptConstants.ENCRYPT_TYPE_MOBILE);
Account dbAcct = accountMapper.getByMobilePhone(encryMobile); //获取医生表账号信息
if (null == dbAcct) {
......@@ -300,4 +306,40 @@ public class CircleAccountServiceImpl implements CircleAccountService {
return map;
}
public static boolean checkIdNum(String cellValue) {
// 身份证校验
String regularExpression = "(^[1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$)|" +
"(^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}$)";
boolean matches = cellValue.matches(regularExpression);
if (matches) {
if (cellValue.length() == 18) {
try {
char[] charArray = cellValue.toCharArray();
//前十七位加权因子
int[] idCardWi = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
//这是除以11后,可能产生的11位余数对应的验证码
String[] idCardY = {"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"};
int sum = 0;
for (int i = 0; i < idCardWi.length; i++) {
int current = Integer.parseInt(String.valueOf(charArray[i]));
int count = current * idCardWi[i];
sum += count;
}
char idCardLast = charArray[17];
int idCardMod = sum % 11;
if (idCardY[idCardMod].toUpperCase().equals(String.valueOf(idCardLast).toUpperCase())) {
matches = true;
} else {
System.out.println("身份证最后一位:" + String.valueOf(idCardLast).toUpperCase() +
"错误,正确的应该是:" + idCardY[idCardMod].toUpperCase());
matches = false;
}
} catch (Exception e) {
logger.error("checkIdNum", e);
}
}
}
return matches;
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册