Browse Source

号码验证座机+手机

dev
zxc 4 years ago
parent
commit
9eb3eb0d65
  1. 2
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java
  2. 19
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/validator/PhoneValidatorUtils.java
  3. 43
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java

2
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社区自组织名称已存在"), COMMUNITY_SELF_ORGANIZATION_LIST_REPART_ERROR(8530, "%s社区自组织名称已存在"),
MATTER_NAME_EXISTS_APPOINTMENT_ERROR(8532, "存在重复预约事项"), MATTER_NAME_EXISTS_APPOINTMENT_ERROR(8532, "存在重复预约事项"),
CHECK_PHONE_ERROR(8533, "号码不合法"),
// 该错误不会提示给前端,只是后端传输错误信息用。 // 该错误不会提示给前端,只是后端传输错误信息用。
ACCESS_SQL_FILTER_MISSION_ARGS(8701, "缺少生成权限过滤SQL所需参数"), ACCESS_SQL_FILTER_MISSION_ARGS(8701, "缺少生成权限过滤SQL所需参数"),
OPER_ADD_CUSTOMER_ROOT_AGENCY_ERROR(8702, "添加客户根级组织失败"), OPER_ADD_CUSTOMER_ROOT_AGENCY_ERROR(8702, "添加客户根级组织失败"),

19
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 { 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}))"; 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 手机号 * @param tel 手机号
@ -24,8 +30,19 @@ public class PhoneValidatorUtils {
return Pattern.matches(REGEX_MOBILE, tel); 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) { public static void main(String[] args) {
System.out.println(isMobile("19353198889")); System.out.println(isTel("2887438"));
} }
} }

43
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.constant.StrConstant;
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult;
import com.epmet.commons.tools.exception.EpmetErrorCode; 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.exception.RenException;
import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.redis.common.CustomerOrgRedis; 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.ConvertUtils;
import com.epmet.commons.tools.utils.DateUtils; import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.commons.tools.utils.ExcelPoiUtils; import com.epmet.commons.tools.utils.ExcelPoiUtils;
import com.epmet.commons.tools.validator.PhoneValidatorUtils;
import com.epmet.constant.IcCommunitySelfOrganizationConstant; import com.epmet.constant.IcCommunitySelfOrganizationConstant;
import com.epmet.dao.IcCommunitySelfOrganizationDao; import com.epmet.dao.IcCommunitySelfOrganizationDao;
import com.epmet.dto.IcCommunitySelfOrganizationDTO; import com.epmet.dto.IcCommunitySelfOrganizationDTO;
@ -131,6 +133,11 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo
@Override @Override
public void addCommunitySelfOrganization(TokenDto tokenDto, AddCommunitySelfOrganizationFormDTO formDTO) { public void addCommunitySelfOrganization(TokenDto tokenDto, AddCommunitySelfOrganizationFormDTO formDTO) {
String customerId = tokenDto.getCustomerId(); String customerId = tokenDto.getCustomerId();
boolean mobile = PhoneValidatorUtils.isMobile(formDTO.getPrincipalPhone());
boolean tel = PhoneValidatorUtils.isTel(formDTO.getPrincipalPhone());
if (!mobile && !tel){
throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode());
}
LambdaQueryWrapper<IcCommunitySelfOrganizationEntity> l = new LambdaQueryWrapper<>(); LambdaQueryWrapper<IcCommunitySelfOrganizationEntity> l = new LambdaQueryWrapper<>();
l.eq(IcCommunitySelfOrganizationEntity::getOrganizationName,formDTO.getOrganizationName()) l.eq(IcCommunitySelfOrganizationEntity::getOrganizationName,formDTO.getOrganizationName())
.eq(IcCommunitySelfOrganizationEntity::getCustomerId,customerId) .eq(IcCommunitySelfOrganizationEntity::getCustomerId,customerId)
@ -163,6 +170,14 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo
} }
baseDao.insert(orgEntity); baseDao.insert(orgEntity);
if(CollectionUtils.isNotEmpty(formDTO.getOrganizationPersonnel())){ if(CollectionUtils.isNotEmpty(formDTO.getOrganizationPersonnel())){
// 号码校验
formDTO.getOrganizationPersonnel().forEach(p -> {
boolean m = PhoneValidatorUtils.isMobile(p.getPersonPhone());
boolean t = PhoneValidatorUtils.isTel(p.getPersonPhone());
if (!m && !t){
throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode());
}
});
List<IcCommunitySelfOrganizationPersonnelEntity> persons = ConvertUtils.sourceToTarget(formDTO.getOrganizationPersonnel(), IcCommunitySelfOrganizationPersonnelEntity.class); List<IcCommunitySelfOrganizationPersonnelEntity> persons = ConvertUtils.sourceToTarget(formDTO.getOrganizationPersonnel(), IcCommunitySelfOrganizationPersonnelEntity.class);
Map<String, List<IcCommunitySelfOrganizationPersonnelEntity>> groupPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone)); Map<String, List<IcCommunitySelfOrganizationPersonnelEntity>> groupPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone));
List<String> phones = new ArrayList<>(); List<String> phones = new ArrayList<>();
@ -199,6 +214,11 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void editCommunitySelfOrganization(TokenDto tokenDto, EditCommunitySelfOrganizationFormDTO formDTO) { public void editCommunitySelfOrganization(TokenDto tokenDto, EditCommunitySelfOrganizationFormDTO formDTO) {
boolean m = PhoneValidatorUtils.isMobile(formDTO.getPrincipalPhone());
boolean t = PhoneValidatorUtils.isTel(formDTO.getPrincipalPhone());
if (!m && !t){
throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode());
}
LambdaQueryWrapper<IcCommunitySelfOrganizationEntity> l = new LambdaQueryWrapper<>(); LambdaQueryWrapper<IcCommunitySelfOrganizationEntity> l = new LambdaQueryWrapper<>();
l.eq(IcCommunitySelfOrganizationEntity::getOrganizationName,formDTO.getOrganizationName()) l.eq(IcCommunitySelfOrganizationEntity::getOrganizationName,formDTO.getOrganizationName())
.eq(IcCommunitySelfOrganizationEntity::getCustomerId,tokenDto.getCustomerId()) .eq(IcCommunitySelfOrganizationEntity::getCustomerId,tokenDto.getCustomerId())
@ -214,6 +234,13 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo
baseDao.updateCommunitySelfOrganization(e); baseDao.updateCommunitySelfOrganization(e);
personnelService.deleteByOrgId(formDTO.getOrgId()); personnelService.deleteByOrgId(formDTO.getOrgId());
if (CollectionUtils.isNotEmpty(formDTO.getOrganizationPersonnel())){ if (CollectionUtils.isNotEmpty(formDTO.getOrganizationPersonnel())){
formDTO.getOrganizationPersonnel().forEach(p -> {
boolean mobile = PhoneValidatorUtils.isMobile(p.getPersonPhone());
boolean tel = PhoneValidatorUtils.isTel(p.getPersonPhone());
if (!mobile && !tel){
throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode());
}
});
List<IcCommunitySelfOrganizationPersonnelEntity> persons = ConvertUtils.sourceToTarget(formDTO.getOrganizationPersonnel(), IcCommunitySelfOrganizationPersonnelEntity.class); List<IcCommunitySelfOrganizationPersonnelEntity> persons = ConvertUtils.sourceToTarget(formDTO.getOrganizationPersonnel(), IcCommunitySelfOrganizationPersonnelEntity.class);
Map<String, List<IcCommunitySelfOrganizationPersonnelEntity>> groupPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone)); Map<String, List<IcCommunitySelfOrganizationPersonnelEntity>> groupPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone));
List<String> phones = new ArrayList<>(); List<String> phones = new ArrayList<>();
@ -335,7 +362,16 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo
public void importCommunitySelfOrganization(TokenDto tokenDto, HttpServletResponse response, MultipartFile file) throws IOException { public void importCommunitySelfOrganization(TokenDto tokenDto, HttpServletResponse response, MultipartFile file) throws IOException {
ExcelImportResult<ImportCommunitySelfOrganization> testExcelImportResult = ExcelPoiUtils.importExcelMore(file, 0, 2, ImportCommunitySelfOrganization.class); ExcelImportResult<ImportCommunitySelfOrganization> testExcelImportResult = ExcelPoiUtils.importExcelMore(file, 0, 2, ImportCommunitySelfOrganization.class);
List<ImportCommunitySelfOrganization> list = testExcelImportResult.getList(); List<ImportCommunitySelfOrganization> list = testExcelImportResult.getList();
if (CollectionUtils.isNotEmpty(list)){ 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(); String customerId = tokenDto.getCustomerId();
List<String> existsNames = baseDao.selectOrgByOrgName(list.stream().map(ImportCommunitySelfOrganization::getOrganizationName).collect(Collectors.toList()), customerId); List<String> existsNames = baseDao.selectOrgByOrgName(list.stream().map(ImportCommunitySelfOrganization::getOrganizationName).collect(Collectors.toList()), customerId);
Map<String, List<ImportCommunitySelfOrganization>> groupByName = list.stream().collect(Collectors.groupingBy(ImportCommunitySelfOrganization::getOrganizationName)); Map<String, List<ImportCommunitySelfOrganization>> groupByName = list.stream().collect(Collectors.groupingBy(ImportCommunitySelfOrganization::getOrganizationName));
@ -372,6 +408,13 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo
e.setOrganizationCreatedTime(l.getOrganizationCreatedTime()); e.setOrganizationCreatedTime(l.getOrganizationCreatedTime());
baseDao.insert(e); baseDao.insert(e);
if (CollectionUtils.isNotEmpty(l.getPersons())){ if (CollectionUtils.isNotEmpty(l.getPersons())){
l.getPersons().forEach(p -> {
boolean m = PhoneValidatorUtils.isMobile(p.getPersonPhone());
boolean t = PhoneValidatorUtils.isTel(p.getPersonPhone());
if (!m && !t){
throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode());
}
});
List<IcCommunitySelfOrganizationPersonnelEntity> persons = ConvertUtils.sourceToTarget(l.getPersons(), IcCommunitySelfOrganizationPersonnelEntity.class); List<IcCommunitySelfOrganizationPersonnelEntity> persons = ConvertUtils.sourceToTarget(l.getPersons(), IcCommunitySelfOrganizationPersonnelEntity.class);
Map<String, List<IcCommunitySelfOrganizationPersonnelEntity>> groupByPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone)); Map<String, List<IcCommunitySelfOrganizationPersonnelEntity>> groupByPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone));
List<String> phones = new ArrayList<>(); List<String> phones = new ArrayList<>();

Loading…
Cancel
Save