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-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/processor/MaskProcessor.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/processor/MaskProcessor.java index 1ce0a85c54..24bce5bff3 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/processor/MaskProcessor.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/processor/MaskProcessor.java @@ -2,8 +2,10 @@ package com.epmet.commons.tools.processor; import cn.hutool.core.util.StrUtil; import com.epmet.commons.tools.annotation.MaskResponse; +import com.epmet.commons.tools.enums.IdCardTypeEnum; import com.epmet.commons.tools.exception.ExceptionUtils; import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.utils.IdCardRegexUtils; import com.epmet.commons.tools.utils.Result; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -13,6 +15,7 @@ import java.lang.reflect.Field; import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.regex.Pattern; /** * desc:脱敏处理器 @@ -136,21 +139,34 @@ public class MaskProcessor { } /** + * 唯一整件号打码,可能是身份证号或者是护照号 * 将明文字符串打码变为掩码。保留前6,后面打码 * @param originString * @return */ private String maskIdCard(String originString) { - int clearTextLength = 12; - // 仅将6位之后的全都打码 - int length = originString.length(); - if (length <= clearTextLength) { + + IdCardRegexUtils regexUtil = IdCardRegexUtils.parse(originString); + if (regexUtil == null) { + // 不匹配任何类型,不码 return originString; } - String maskStr = StrUtil.repeatByLength("*", length - clearTextLength); - - return originString.replaceAll("^(\\d{10})\\d+([a-zA-Z0-9]{2})$", new StringBuilder("$1").append(maskStr).append("$2").toString()); + if (regexUtil.getTypeEnum() == IdCardTypeEnum.SFZH) { + // 身份证号 + // 仅将6位之后的全都打码 + int maskedTextLength = 12; + int length = originString.length(); + String maskStr = StrUtil.repeatByLength("*", length - maskedTextLength); + return originString.replaceAll("^(\\d{10})\\d+([a-zA-Z0-9]{2})$", new StringBuilder("$1").append(maskStr).append("$2").toString()); + } else if (regexUtil.getTypeEnum() == IdCardTypeEnum.PASSPORT) { + // 护照,前两位,后两位为明文,其他* + String maskStr = StrUtil.repeatByLength("*", originString.length() - 4); + return originString.replaceAll("^([a-zA-Z0-9]{2})\\d+(\\d{2})$", new StringBuilder("$1").append(maskStr).append("$2").toString()); + } else { + // 其他情况,不码 + return originString; + } } /** diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/IdCardRegexUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/IdCardRegexUtils.java new file mode 100644 index 0000000000..d44e9bb3fb --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/IdCardRegexUtils.java @@ -0,0 +1,133 @@ +package com.epmet.commons.tools.utils; + +import com.epmet.commons.tools.enums.IdCardTypeEnum; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * 唯一整件正则工具 + */ +public class IdCardRegexUtils { + + /** + * 15位身份证号的正则表达式 + */ + private static final Pattern PATTERN_15_ID = Pattern.compile("^\\d{6}(?\\d{2})(?0[1-9]|1[0-2])(?[0-2][0-9]|3[0-1])\\d{2}(?\\d)$"); + /** + * 18位身份证号的正则表达式 + */ + private static 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 static final Pattern PATTERN_9_PASSPORT = Pattern.compile("^[a-zA-Z]{2}\\d{7}$|^[a-zA-Z]{1}\\d{8}$"); + + private String inputText; + + private Matcher matcher; + + private IdCardTypeEnum idCardType; + + private IdCardRegexUtils(IdCardTypeEnum idCardType, Matcher matcher, String inputText) { + this.idCardType = idCardType; + this.matcher = matcher; + this.inputText = inputText; + } + + /** + * 正则解析结果 + */ + @Data + @AllArgsConstructor + @NoArgsConstructor + public static class ParsedContent { + private String birthdayYear; + private String birthdayMonth; + private String birthdayDay; + private String sex; + } + + /** + * desc:校验输入的证件号是否合法 + * @param input + * @return + */ + public static boolean validateIdCard(String input){ + IdCardRegexUtils parse = IdCardRegexUtils.parse(input); + return parse != null; + } + + /** + * 解析正则 + * @param input + * @return + */ + public static IdCardRegexUtils parse(String input) { + if (input == null || input.trim().length() == 0) { + return null; + } + + if (input.length() == 15) { + Matcher matcher = PATTERN_15_ID.matcher(input); + if (matcher.matches()) { + return new IdCardRegexUtils(IdCardTypeEnum.SFZH, matcher, input); + } + } + + if (input.length() == 18) { + Matcher matcher = PATTERN_18_ID.matcher(input); + if (matcher.matches()) { + return new IdCardRegexUtils(IdCardTypeEnum.SFZH, matcher, input); + } + } + + if (input.length() == 9) { + Matcher matcher = PATTERN_9_PASSPORT.matcher(input); + if (matcher.matches()) { + return new IdCardRegexUtils(IdCardTypeEnum.PASSPORT, matcher, input); + } + } + return null; + } + + /** + * 获取解析结果 + * @return + */ + public ParsedContent getParsedResult() { + if (matcher == null || idCardType == null) { + return null; + } + + if (IdCardTypeEnum.SFZH == idCardType) { + //是身份证号,可以解析 + String year; + if (inputText.length() == 15) { + // 15位身份证号,years前需要拼上19 + year = "19".concat(matcher.group("year")); + } else { + year = matcher.group("year"); + } + String month = matcher.group("month"); + String day = matcher.group("day"); + String sex = matcher.group("sex"); + return new ParsedContent(year, month, day, sex); + } + + // 其他类型暂时不可解析 + return null; + } + + /** + * 获取类型枚举 + * @return + */ + public IdCardTypeEnum getTypeEnum() { + return idCardType; + } +} diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/resi/ResiVolunteerAuthenticateFormDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/resi/ResiVolunteerAuthenticateFormDTO.java index 877abcb74c..2169dda0d8 100644 --- a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/resi/ResiVolunteerAuthenticateFormDTO.java +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/resi/ResiVolunteerAuthenticateFormDTO.java @@ -59,7 +59,7 @@ public class ResiVolunteerAuthenticateFormDTO implements Serializable { /** * 身份证号码 */ - @NotBlank(message = "身份证号码不能为空", groups = {AddUserShowGroup.class }) + @NotBlank(message = "证件号能为空", groups = {AddUserShowGroup.class }) private String idNum; /** diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/ResiVolunteerController.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/ResiVolunteerController.java index b54acc67ec..22e724e5a1 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/ResiVolunteerController.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/ResiVolunteerController.java @@ -22,6 +22,7 @@ import com.epmet.commons.tools.dto.form.mq.MqBaseFormDTO; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.commons.tools.utils.IdCardRegexUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.constant.SystemMessageType; @@ -38,6 +39,7 @@ import com.epmet.dto.result.resi.ResiVolunteerInfoResultDTO; import com.epmet.feign.EpmetMessageOpenFeignClient; import com.epmet.send.SendMqMsgUtil; import com.epmet.service.VolunteerInfoService; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -72,6 +74,12 @@ public class ResiVolunteerController { formDTO.setUserId(tokenDto.getUserId()); formDTO.setCustomerId(tokenDto.getCustomerId()); ValidatorUtils.validateEntity(formDTO, ResiVolunteerAuthenticateFormDTO.AddUserShowGroup.class, ResiVolunteerAuthenticateFormDTO.AddUserInternalGroup.class); + if (StringUtils.isNotBlank(formDTO.getIdNum())){ + boolean b = IdCardRegexUtils.validateIdCard(formDTO.getIdNum()); + if (!b){ + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"请输入正确的证件号","请输入正确的证件号"); + } + } volunteerInfoService.authenticate(formDTO); //发送志愿者人员消息变动 diff --git a/epmet-module/gov-grid/gov-grid-client/src/main/java/com/epmet/dto/form/SaveOrUpdateParyMemberFormDTO.java b/epmet-module/gov-grid/gov-grid-client/src/main/java/com/epmet/dto/form/SaveOrUpdateParyMemberFormDTO.java index 3414805602..74dce9f16f 100644 --- a/epmet-module/gov-grid/gov-grid-client/src/main/java/com/epmet/dto/form/SaveOrUpdateParyMemberFormDTO.java +++ b/epmet-module/gov-grid/gov-grid-client/src/main/java/com/epmet/dto/form/SaveOrUpdateParyMemberFormDTO.java @@ -31,7 +31,7 @@ public class SaveOrUpdateParyMemberFormDTO implements Serializable { @NotBlank(message = "姓名不能为空", groups = {AddUserShowGroup.class}) private String name; - @NotBlank(message = "身份证不能为空", groups = {AddUserShowGroup.class}) + @NotBlank(message = "证件号不能为空", groups = {AddUserShowGroup.class}) private String idCard; @NotBlank(message = "手机号不能为空", groups = {AddUserShowGroup.class}) diff --git a/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/mine/controller/PersonalCenterController.java b/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/mine/controller/PersonalCenterController.java index 48ea31f06b..8666aca88c 100644 --- a/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/mine/controller/PersonalCenterController.java +++ b/epmet-module/resi-mine/resi-mine-server/src/main/java/com/epmet/modules/mine/controller/PersonalCenterController.java @@ -1,7 +1,10 @@ package com.epmet.modules.mine.controller; import com.epmet.commons.tools.annotation.LoginUser; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.commons.tools.utils.IdCardRegexUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.dto.form.EditInfoFormDTO; @@ -10,6 +13,7 @@ import com.epmet.dto.form.SendCodeFormDTO; import com.epmet.modules.mine.service.PersonalCenterService; import com.epmet.resi.mine.dto.result.InitInfoResultDTO; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -55,6 +59,12 @@ public class PersonalCenterController { formDTO.setUserId(tokenDto.getUserId()); formDTO.setCustomerId(tokenDto.getCustomerId()); ValidatorUtils.validateEntity(formDTO,EditInfoFormDTO.AddUserShowGroup.class,EditInfoFormDTO.AddUserInternalGroup.class); + if (StringUtils.isNotBlank(formDTO.getIdNum())){ + boolean b = IdCardRegexUtils.validateIdCard(formDTO.getIdNum()); + if (!b){ + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"请输入正确的证件号","请输入正确的证件号"); + } + } personalCenterService.editInfo(tokenDto, formDTO); return new Result(); } diff --git a/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/service/impl/PartyMemberConfirmServiceImpl.java b/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/service/impl/PartyMemberConfirmServiceImpl.java index 74b9ba9844..961197076d 100644 --- a/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/service/impl/PartyMemberConfirmServiceImpl.java +++ b/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/service/impl/PartyMemberConfirmServiceImpl.java @@ -10,6 +10,7 @@ import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.redis.common.CustomerOrgRedis; import com.epmet.commons.tools.redis.common.bean.GridInfoCache; import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.utils.IdCardRegexUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.constant.*; import com.epmet.dto.*; @@ -167,6 +168,14 @@ public class PartyMemberConfirmServiceImpl implements PartyMemberConfirmService @Transactional(rollbackFor = Exception.class) public Result submit(PartymemberInfoDTO partyMemberInfoDTO) { log.info("submit param:{}",JSON.toJSONString(partyMemberInfoDTO)); + + // 证件类型判断----start---- + IdCardRegexUtils regex = IdCardRegexUtils.parse(partyMemberInfoDTO.getIdCard()); + if (regex == null) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "证件号解析错误", "证件号解析错误"); + } + // 证件类型判断----end---- + Result result = new Result(); //校验手机验证码是否正常 diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/IcFollowUpRecordDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/IcFollowUpRecordDTO.java index aba428a576..89950e63c0 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/IcFollowUpRecordDTO.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/IcFollowUpRecordDTO.java @@ -67,7 +67,7 @@ public class IcFollowUpRecordDTO implements Serializable { */ @ColumnWidth(25) @ExcelProperty("身份证号") - @NotBlank(message = "身份证号不能为空", groups = {AddUserRequired.class}) + @NotBlank(message = "证件号不能为空", groups = {AddUserRequired.class}) private String idCard; /** diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/AddIcVaccineFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/AddIcVaccineFormDTO.java index 482ef97839..cca2734f9c 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/AddIcVaccineFormDTO.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/AddIcVaccineFormDTO.java @@ -56,7 +56,7 @@ public class AddIcVaccineFormDTO implements Serializable { /** * 身份证号 */ - @NotBlank(message = "身份证号不能为空", groups = Vaccine.class) + @NotBlank(message = "证件号不能为空", groups = Vaccine.class) private String idCard; /** * 接种时间 diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/EditInfoFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/EditInfoFormDTO.java index 7917113509..6ef7eb715e 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/EditInfoFormDTO.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/EditInfoFormDTO.java @@ -47,7 +47,7 @@ public class EditInfoFormDTO implements Serializable { private String name; //@NotBlank(message = "身份证号不能为空") - @Length(max=18,message = "身份证号不能超过18位",groups = AddUserShowGroup.class) + @Length(max=18,message = "证件号不能超过18位",groups = AddUserShowGroup.class) //别的小程序不统一升级,没办法限制必填。 private String idNum; diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/IcMoveInAddEditFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/IcMoveInAddEditFormDTO.java index bcb62d6b45..083658ffda 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/IcMoveInAddEditFormDTO.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/IcMoveInAddEditFormDTO.java @@ -71,8 +71,8 @@ public class IcMoveInAddEditFormDTO implements Serializable { /** * 身份证号 */ - @NotBlank(message = "身份证号不能为空", groups = {AddGroup.class}) - @Length(min = 15, max = 18, message = "身份证号位数不正确", groups = AddGroup.class) + @NotBlank(message = "证件号不能为空", groups = {AddGroup.class}) + @Length(min = 9, max = 18, message = "证件号位数不正确", groups = AddGroup.class) private String idCard; /** * 性别(1男2女0未知) diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/IcNoticeFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/IcNoticeFormDTO.java index 09919051b9..7cc5c08b82 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/IcNoticeFormDTO.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/IcNoticeFormDTO.java @@ -17,6 +17,6 @@ public class IcNoticeFormDTO extends PageFormDTO implements Serializable { private static final long serialVersionUID = 7392894573654015338L; private String customerId; private String noticeId; - @NotBlank(message = "身份证号不能为空", groups = DefaultGroup.class) + @NotBlank(message = "证件号不能为空", groups = DefaultGroup.class) private String idCard; } diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/IcTripReportFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/IcTripReportFormDTO.java index d9a7f4d565..5c7a53e335 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/IcTripReportFormDTO.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/IcTripReportFormDTO.java @@ -57,7 +57,7 @@ public class IcTripReportFormDTO implements Serializable { /** * 身份证号 */ - @NotBlank(message = "身份证号不能为空", groups = {ResiUserRequired.class,PcAddRequired.class,PcUpdateRequired.class}) + @NotBlank(message = "证件号能为空", groups = {ResiUserRequired.class,PcAddRequired.class,PcUpdateRequired.class}) private String idCard; /** diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/InfoSubmitFromDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/InfoSubmitFromDTO.java index c99a96878c..3ce4110f4c 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/InfoSubmitFromDTO.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/InfoSubmitFromDTO.java @@ -57,7 +57,7 @@ public class InfoSubmitFromDTO implements Serializable { private String name; //@NotBlank(message = "身份证号不能为空") - @Length(max=18,message = "身份证号不能超过18位") + @Length(max=18,message = "证件号不能超过18位") //别的小程序不统一升级,没办法限制必填。 private String idNum; diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/PageFollowUpFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/PageFollowUpFormDTO.java index ab4a416d9e..1a1de84a5e 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/PageFollowUpFormDTO.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/PageFollowUpFormDTO.java @@ -12,10 +12,10 @@ public class PageFollowUpFormDTO extends PageFormDTO { /** * 身份证号 */ - @NotBlank(message = "身份证号不能为空", groups = {AddUserShowGroup.class}) + @NotBlank(message = "证件号不能为空", groups = {AddUserShowGroup.class}) private String idCard; - @NotBlank(message = "身份证号不能为空", groups = {AddUserShowGroup.class}) + @NotBlank(message = "证件号不能为空", groups = {AddUserShowGroup.class}) private String name; /** diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/CollectListMemberExcelResultDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/CollectListMemberExcelResultDTO.java index 89742845fa..f94a7dc803 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/CollectListMemberExcelResultDTO.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/CollectListMemberExcelResultDTO.java @@ -24,7 +24,7 @@ public class CollectListMemberExcelResultDTO implements Serializable { /** * 成员身份证 */ - @Excel(name = "成员身份证号", width = 30) + @Excel(name = "成员证件号", width = 30) private String memberIdNum; /** diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiCollectController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiCollectController.java index cca091439f..d508f670e8 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiCollectController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiCollectController.java @@ -4,15 +4,19 @@ import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.annotation.MaskResponse; import com.epmet.commons.tools.aop.NoRepeatSubmit; import com.epmet.commons.tools.constant.StrConstant; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.ExcelUtils; +import com.epmet.commons.tools.utils.IdCardRegexUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.dto.form.*; import com.epmet.dto.result.*; import com.epmet.service.IcResiCollectService; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -180,6 +184,18 @@ public class IcResiCollectController { //效验数据 ValidatorUtils.validateEntity(formDTO); formDTO.setOrigin("internal");//固定为内部 + + // 证件类型判断----start---- + for (IcResiCollectMemFormDTO member : formDTO.getMemberList()) { + if (StringUtils.isNotBlank(member.getIdNum())) { + IdCardRegexUtils regex = IdCardRegexUtils.parse(member.getIdNum()); + if (regex == null) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "证件号解析错误", "证件号解析错误"); + } + } + } + // 证件类型判断----end---- + return icResiCollectService.saveCollectInfo(formDTO); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiCollectVisitorController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiCollectVisitorController.java index 2019de84d1..1c46fb5f52 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiCollectVisitorController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiCollectVisitorController.java @@ -2,9 +2,12 @@ package com.epmet.controller; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.aop.NoRepeatSubmit; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.ExcelUtils; +import com.epmet.commons.tools.utils.IdCardRegexUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.AssertUtils; import com.epmet.commons.tools.validator.ValidatorUtils; @@ -115,6 +118,12 @@ public class IcResiCollectVisitorController { public Result saveInfo(@RequestBody SaveCollectVisitorFormDTO dto) { //效验数据 ValidatorUtils.validateEntity(dto); + // 证件类型判断----start---- + IdCardRegexUtils regex = IdCardRegexUtils.parse(dto.getIdCard()); + if (regex == null) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "证件号解析错误", "证件号解析错误"); + } + // 证件类型判断----end---- return icResiCollectVisitorService.saveInfo(dto); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java index 7604ebc5c7..7ac26844dd 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java @@ -307,12 +307,30 @@ public class IcResiUserController implements ResultDataResolver { */ @PostMapping("rent/updateimage") public Result updateImage(@LoginUser TokenDto tokenDto, @RequestBody RentTenantFormDTO formDTO) { + + // 身份证号验证 + if (StringUtils.isNotBlank(formDTO.getUser().getIdCard())) { + checkIdCard(formDTO.getUser().getIdCard()); + } + + if (StringUtils.isNotBlank(formDTO.getIdCard())) { + checkIdCard(formDTO.getIdCard()); + } + String resiUserId = icResiUserService.updateImage(tokenDto, formDTO); //推送MQ事件 editResiMq(formDTO.getCustomerId(), resiUserId); return new Result(); } + private void checkIdCard(String idCard) { + // 证件类型判断----start---- + IdCardRegexUtils regex = IdCardRegexUtils.parse(idCard); + if (regex == null) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "证件号解析错误", "证件号解析错误"); + } + } + private void editResiMq(String customerId, String userId) { //推送MQ事件 IcResiUserAddMQMsg mqMsg = new IcResiUserAddMQMsg(); diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcTripReportRecordController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcTripReportRecordController.java index 6e1aff48ff..cfc1313c69 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcTripReportRecordController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcTripReportRecordController.java @@ -33,6 +33,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.web.bind.annotation.*; @@ -159,6 +160,12 @@ public class IcTripReportRecordController implements ResultDataResolver { formDTO.setUserId(tokenDto.getUserId()); formDTO.setUserType(IcResiUserConstant.USER_TYPE_RESI); ValidatorUtils.validateEntity(formDTO,IcTripReportFormDTO.ResiUserRequired.class,IcTripReportFormDTO.ResiUserInternalGroup.class); + if (StringUtils.isNotBlank(formDTO.getIdCard())){ + boolean b = IdCardRegexUtils.validateIdCard(formDTO.getIdCard()); + if (!b){ + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"请输入正确的证件号","请输入正确的证件号"); + } + } return new Result().ok(icTripReportRecordService.resiSave(formDTO)); } 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/excel/ChangeDeathExcel.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/ChangeDeathExcel.java index a198ceee2d..5ad2165e88 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/ChangeDeathExcel.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/ChangeDeathExcel.java @@ -23,7 +23,7 @@ public class ChangeDeathExcel { @Excel(name = "姓名") private String name; - @Excel(name = "身份证") + @Excel(name = "证件号") private String idCard; @Excel(name = "手机号") diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/ChangeRelocationExcel.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/ChangeRelocationExcel.java index 1823d569e2..3b875fd0cd 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/ChangeRelocationExcel.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/ChangeRelocationExcel.java @@ -32,7 +32,7 @@ public class ChangeRelocationExcel { @Excel(name = "手机号") private String mobile; - @Excel(name = "身份证号") + @Excel(name = "证件号") private String idCard; @Excel(name = "性别") diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/ChangeWelfareExcel.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/ChangeWelfareExcel.java index 99437aa726..acb7705b2f 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/ChangeWelfareExcel.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/ChangeWelfareExcel.java @@ -24,7 +24,7 @@ public class ChangeWelfareExcel { @Excel(name = "姓名") private String name; - @Excel(name = "身份证") + @Excel(name = "证件号") private String idCard; @Excel(name = "手机号") diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcBirthRecordServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcBirthRecordServiceImpl.java index 163d15c563..37a65965d7 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcBirthRecordServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcBirthRecordServiceImpl.java @@ -7,12 +7,15 @@ import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.enums.GenderEnum; import com.epmet.commons.tools.enums.IcResiUserSubStatusEnum; +import com.epmet.commons.tools.enums.IdCardTypeEnum; import com.epmet.commons.tools.enums.RelationshipEnum; +import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.redis.common.CustomerStaffRedis; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.utils.IdCardRegexUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.dao.IcBirthRecordDao; import com.epmet.dao.IcResiUserDao; @@ -144,6 +147,15 @@ public class IcBirthRecordServiceImpl extends BaseServiceImpl controlGroup1 = Arrays.asList("input", "textarea", "datepicker", "daterange"); public static final List controlGroup2 = Arrays.asList("select", "radio", "cascader"); - /** - * 15位身份证号的正则表达式 - */ - private final Pattern PATTERN_15_ID = Pattern.compile("^\\d{6}(?\\d{2})(?0[1-9]|1[0-2])(?[0-2][0-9]|3[0-1])\\d{2}(?\\d)$"); - /** - * 18位身份证号的正则表达式 - */ - 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]$"); - /** * 日期解析,不含时间 */ @@ -233,7 +225,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res private String tableName; - @Excel(name = "身份证号", width = 40) + @Excel(name = "证件号", width = 40) private String idCard; @Excel(name = "姓名", width = 25) @@ -623,14 +615,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,52 +630,48 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res } // ================== 数据补充 =================== - String year; - String month; - String day; - String sex; + IdCardRegexUtils regexUtilInstance = IdCardRegexUtils.parse(idCard); + if (regexUtilInstance == null) { + String s = "请输入正确的证件号"; + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), s, s); + } - if (idCard.length() == 15) { - Matcher matcher = PATTERN_15_ID.matcher(idCard); - if (matcher.matches()) { - year = "19".concat(matcher.group("year")); - month = matcher.group("month"); - day = matcher.group("day"); - sex = matcher.group("sex"); - } else { - 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"); - month = matcher.group("month"); - day = matcher.group("day"); - sex = matcher.group("sex"); - } else { - String s = "身份证号解析错误"; - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), s, s); - } - } else { - String s = "身份证号位数错误"; + IdCardTypeEnum idCardType = regexUtilInstance.getTypeEnum(); + + if (idCardType == null || IdCardTypeEnum.OTHERS == idCardType) { + 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("身份证号中日期信息错误"); + IdCardRegexUtils.ParsedContent parsedResult = regexUtilInstance.getParsedResult(); + String year = null, month = null, day = null, sex = null; + if (parsedResult != null) { + year = parsedResult.getBirthdayYear(); + month = parsedResult.getBirthdayMonth(); + day = parsedResult.getBirthdayDay(); + sex = parsedResult.getSex(); } - 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"); + // 存储证件类型 + columnAndValues.put("ID_CARD_TYPE", idCardType.getType()); + + if (idCardType == IdCardTypeEnum.SFZH) { + //只有证件类型是身份证号才做相关解析 + // 出生日期 & 年龄 + 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"); + } } /** diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java index d8f57e4e81..0f55cab634 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java @@ -258,7 +258,7 @@ public class IcResiUserServiceImpl extends BaseServiceImpl entityList = baseDao.selectList(wrapper); if (CollectionUtils.isNotEmpty(entityList)) { - String errorMsg = "修改居民信息失败,身份证号已存在!"; + String errorMsg = "修改居民信息失败,证件号已存在!"; throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), errorMsg, errorMsg); } } @@ -620,6 +630,17 @@ public class IcResiUserServiceImpl extends BaseServiceImpl