diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/enums/IdCardTypeEnum.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/enums/IdCardTypeEnum.java new file mode 100644 index 0000000000..7ca7f04641 --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/enums/IdCardTypeEnum.java @@ -0,0 +1,27 @@ +package com.epmet.commons.tools.enums; + +/** + * 唯一整件类型 + */ +public enum IdCardTypeEnum { + + OTHERS("0", "其他"), + SFZH("1", "身份证号"), + PASSPORT("2", "护照"); + + private String type; + private String name; + + IdCardTypeEnum(String type, String name) { + this.type = type; + this.name = name; + } + + public String getType() { + return type; + } + + public String getName() { + return name; + } +} diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/entity/IcResiUserEntity.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/entity/IcResiUserEntity.java index f787399b23..d7849f5592 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/entity/IcResiUserEntity.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/entity/IcResiUserEntity.java @@ -96,10 +96,15 @@ public class IcResiUserEntity extends BaseEpmetEntity { private String gender; /** - * 身份证号 + * 证件号 */ private String idCard; + /** + * 证件类型。1:身份证号;2:护照 + */ + private String idCardType; + /** * 出生日期 */ diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserImportServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserImportServiceImpl.java index 7f8921443f..adc9a94eb4 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserImportServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserImportServiceImpl.java @@ -18,6 +18,7 @@ import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.dto.result.OptionResultDTO; import com.epmet.commons.tools.enums.IcResiUserSubStatusEnum; +import com.epmet.commons.tools.enums.IdCardTypeEnum; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.exception.ExceptionUtils; @@ -98,6 +99,11 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res */ private final Pattern PATTERN_18_ID = Pattern.compile("^\\d{6}(?\\d{4})(?0[1-9]|1[0-2])(?[0-2][0-9]|3[0-1])\\d{2}(?\\d)[0-9a-xA-X]$"); + /** + * 9位护照 + */ + private final Pattern PATTERN_9_PASSPORT = Pattern.compile("^\\w{2}\\d{7}|\\w{1}\\d{8}$"); + /** * 日期解析,不含时间 */ @@ -623,14 +629,10 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res if (StringUtils.isBlank(idCard)) { log.debug("【居民信息导入】specifiedCheck身份证号为空的:{},{}", mobile, name); - String errorMsg = "身份证号不能为空"; + String errorMsg = "证件号不能为空"; throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), errorMsg, errorMsg); } - if (idCard.length() != 18 && idCard.length() != 15) { - errors.add("身份证号长度错误"); - } - if (StringUtils.isNotBlank(mobile) && mobile.length() > 15) { errors.add("手机号长度错误"); } @@ -642,12 +644,13 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res } // ================== 数据补充 =================== - String year; - String month; - String day; - String sex; + String year = null, month = null, day = null, sex = null; + + // 证件类型,默认是1身份证号 + String idCardType = IdCardTypeEnum.SFZH.getType(); if (idCard.length() == 15) { + // 身份证 Matcher matcher = PATTERN_15_ID.matcher(idCard); if (matcher.matches()) { year = "19".concat(matcher.group("year")); @@ -655,10 +658,11 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res day = matcher.group("day"); sex = matcher.group("sex"); } else { - String s = "身份证号解析错误"; + String s = "证件号解析错误"; throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), s, s); } } else if (idCard.length() == 18) { + // 身份证 Matcher matcher = PATTERN_18_ID.matcher(idCard); if (matcher.matches()) { year = matcher.group("year"); @@ -666,28 +670,40 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res day = matcher.group("day"); sex = matcher.group("sex"); } else { - String s = "身份证号解析错误"; + String s = "证件号解析错误"; throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), s, s); } + } else if (idCard.length() == 9) { + // 护照 + Matcher matcher = PATTERN_9_PASSPORT.matcher(idCard); + if (matcher.matches()) { + idCardType = IdCardTypeEnum.PASSPORT.getType(); + } } else { - String s = "身份证号位数错误"; + String s = "证件号解析错误"; throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), s, s); } - // 出生日期 & 年龄 - LocalDate birthday = null; - try { - birthday = LocalDate.of(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day)); - } catch (DateTimeException e) { - throw new EpmetException("身份证号中日期信息错误"); - } - int age = Period.between(birthday, LocalDate.now()).getYears(); + // 存储证件类型 + columnAndValues.put("ID_CARD_TYPE", idCardType); - // 性别 & 生日 & 老年人 - Boolean isMale = (Integer.parseInt(sex) % 2) == 1; - columnAndValues.put("BIRTHDAY", String.join("-", Arrays.asList(year, month,day))); - columnAndValues.put("GENDER", isMale ? "1" : "2"); - columnAndValues.put("IS_OLD_PEOPLE", age >= 60 ? "1" : "0"); + if (idCardType.equals(IdCardTypeEnum.SFZH.getType())) { + //只有证件类型是身份证号才做相关解析 + // 出生日期 & 年龄 + LocalDate birthday = null; + try { + birthday = LocalDate.of(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day)); + } catch (DateTimeException e) { + throw new EpmetException("身份证号中日期信息错误"); + } + int age = Period.between(birthday, LocalDate.now()).getYears(); + + // 性别 & 生日 & 老年人 + Boolean isMale = (Integer.parseInt(sex) % 2) == 1; + columnAndValues.put("BIRTHDAY", String.join("-", Arrays.asList(year, month, day))); + columnAndValues.put("GENDER", isMale ? "1" : "2"); + columnAndValues.put("IS_OLD_PEOPLE", age >= 60 ? "1" : "0"); + } } /**