diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java index 0f70c9ecbd..8363ccb87a 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java @@ -165,6 +165,8 @@ public enum EpmetErrorCode { COMMUNITY_SELF_ORGANIZATION_LIST_REPART_ERROR(8530, "%s社区自组织名称已存在"), MATTER_NAME_EXISTS_APPOINTMENT_ERROR(8532, "存在重复预约事项"), + CHECK_PHONE_ERROR(8533, "号码不合法"), + // 该错误不会提示给前端,只是后端传输错误信息用。 ACCESS_SQL_FILTER_MISSION_ARGS(8701, "缺少生成权限过滤SQL所需参数"), OPER_ADD_CUSTOMER_ROOT_AGENCY_ERROR(8702, "添加客户根级组织失败"), diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/validator/PhoneValidatorUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/validator/PhoneValidatorUtils.java index d1a35124af..9f97a3f5c1 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/validator/PhoneValidatorUtils.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/validator/PhoneValidatorUtils.java @@ -12,6 +12,12 @@ import java.util.regex.Pattern; public class PhoneValidatorUtils { private static final String REGEX_MOBILE ="((\\+86|0086)?\\s*)((134[0-8]\\d{7})|(((13([0-3]|[5-9]))|(14[5-9])|15([0-3]|[5-9])|(16(2|[5-7]))|17([0-3]|[5-8])|18[0-9]|19([0-9]))\\d{8})|(14(0|1|4)0\\d{7})|(1740([0-5]|[6-9]|[10-12])\\d{7}))"; + /** + * 正则:固定电话号码,可带区号,然后至少6,8位数字 + */ + private static final String REGEX_TEL = "^(\\d{3,4}-)?\\d{6,8}$"; + private static final Pattern PATTERN_REGEX_TEL = Pattern.compile(REGEX_TEL); + /** * 判断是否是手机号 * @param tel 手机号 @@ -24,8 +30,19 @@ public class PhoneValidatorUtils { return Pattern.matches(REGEX_MOBILE, tel); } + /** + * 验证固定电话号码 + */ + public static boolean isTel( String str) { + return isMatch(PATTERN_REGEX_TEL, str); + } + + public static boolean isMatch(Pattern pattern, String str) { + return StringUtils.isNotEmpty(str) && pattern.matcher(str).matches(); + } + public static void main(String[] args) { - System.out.println(isMobile("19353198889")); + System.out.println(isTel("2887438")); } } diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java index cde9814019..afa9210488 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java @@ -11,6 +11,7 @@ import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.redis.common.CustomerOrgRedis; @@ -20,6 +21,7 @@ import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.DateUtils; import com.epmet.commons.tools.utils.ExcelPoiUtils; +import com.epmet.commons.tools.validator.PhoneValidatorUtils; import com.epmet.constant.IcCommunitySelfOrganizationConstant; import com.epmet.dao.IcCommunitySelfOrganizationDao; import com.epmet.dto.IcCommunitySelfOrganizationDTO; @@ -131,6 +133,11 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl l = new LambdaQueryWrapper<>(); l.eq(IcCommunitySelfOrganizationEntity::getOrganizationName,formDTO.getOrganizationName()) .eq(IcCommunitySelfOrganizationEntity::getCustomerId,customerId) @@ -163,6 +170,14 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl { + boolean m = PhoneValidatorUtils.isMobile(p.getPersonPhone()); + boolean t = PhoneValidatorUtils.isTel(p.getPersonPhone()); + if (!m && !t){ + throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode()); + } + }); List persons = ConvertUtils.sourceToTarget(formDTO.getOrganizationPersonnel(), IcCommunitySelfOrganizationPersonnelEntity.class); Map> groupPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone)); List phones = new ArrayList<>(); @@ -199,6 +214,11 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl l = new LambdaQueryWrapper<>(); l.eq(IcCommunitySelfOrganizationEntity::getOrganizationName,formDTO.getOrganizationName()) .eq(IcCommunitySelfOrganizationEntity::getCustomerId,tokenDto.getCustomerId()) @@ -214,6 +234,13 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl { + boolean mobile = PhoneValidatorUtils.isMobile(p.getPersonPhone()); + boolean tel = PhoneValidatorUtils.isTel(p.getPersonPhone()); + if (!mobile && !tel){ + throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode()); + } + }); List persons = ConvertUtils.sourceToTarget(formDTO.getOrganizationPersonnel(), IcCommunitySelfOrganizationPersonnelEntity.class); Map> groupPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone)); List phones = new ArrayList<>(); @@ -335,7 +362,16 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl testExcelImportResult = ExcelPoiUtils.importExcelMore(file, 0, 2, ImportCommunitySelfOrganization.class); List list = testExcelImportResult.getList(); + if (CollectionUtils.isNotEmpty(list)){ + // 号码校验 + list.forEach(p -> { + boolean m = PhoneValidatorUtils.isMobile(p.getPrincipalPhone()); + boolean t = PhoneValidatorUtils.isTel(p.getPrincipalPhone()); + if (!m && !t){ + throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode()); + } + }); String customerId = tokenDto.getCustomerId(); List existsNames = baseDao.selectOrgByOrgName(list.stream().map(ImportCommunitySelfOrganization::getOrganizationName).collect(Collectors.toList()), customerId); Map> groupByName = list.stream().collect(Collectors.groupingBy(ImportCommunitySelfOrganization::getOrganizationName)); @@ -372,6 +408,13 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl { + boolean m = PhoneValidatorUtils.isMobile(p.getPersonPhone()); + boolean t = PhoneValidatorUtils.isTel(p.getPersonPhone()); + if (!m && !t){ + throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode()); + } + }); List persons = ConvertUtils.sourceToTarget(l.getPersons(), IcCommunitySelfOrganizationPersonnelEntity.class); Map> groupByPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone)); List phones = new ArrayList<>();