diff --git a/airpower-core/pom.xml b/airpower-core/pom.xml index 095cb6d0420c712071e2b1b84748cd9931135786..550c1eb4addf7c44bac483b73f4da9a1e65eeae6 100644 --- a/airpower-core/pom.xml +++ b/airpower-core/pom.xml @@ -5,10 +5,10 @@ cn.hamm airpower - 2.2.1 + 2.2.2 airpower-core - 2.2.1 + 2.2.2 airpower-core AirPower is a fast backend development tool based on SpringBoot3 and JPA. It's the core of AirPower. diff --git a/airpower-core/src/main/java/cn/hamm/airpower/root/RootService.java b/airpower-core/src/main/java/cn/hamm/airpower/root/RootService.java index d7bc2788ff002f178ccaca70b8cbb88779664411..dc9f61e1316e7c07560a3917236c7beca35d1cc7 100644 --- a/airpower-core/src/main/java/cn/hamm/airpower/root/RootService.java +++ b/airpower-core/src/main/java/cn/hamm/airpower/root/RootService.java @@ -1119,10 +1119,13 @@ public class RootService, R extends RootRepository> { break; case LIKE: if (!isEqual) { + // 如果是模糊匹配 predicateList.add( builder.like(root.get(field.getName()), fieldValue + Constant.PERCENT) ); + break; } + // 如果不是模糊匹配,走到default分支 default: // 强匹配 predicate = builder.equal(root.get(field.getName()), fieldValue); diff --git a/airpower-core/src/main/java/cn/hamm/airpower/util/ValidateUtil.java b/airpower-core/src/main/java/cn/hamm/airpower/util/ValidateUtil.java index f786d65598b8cc4ea6c3cb7d70ada2fd0872f317..8434d0de15892da86be9e0995aad24e2bcc950b7 100644 --- a/airpower-core/src/main/java/cn/hamm/airpower/util/ValidateUtil.java +++ b/airpower-core/src/main/java/cn/hamm/airpower/util/ValidateUtil.java @@ -3,6 +3,7 @@ package cn.hamm.airpower.util; import cn.hamm.airpower.config.Constant; import cn.hamm.airpower.config.PatternConstant; import cn.hamm.airpower.enums.ServiceError; +import cn.hamm.airpower.exception.ServiceException; import cn.hamm.airpower.root.RootModel; import jakarta.validation.ConstraintViolation; import jakarta.validation.Validation; @@ -28,7 +29,7 @@ public class ValidateUtil { */ private final Validator validator; - ValidateUtil() { + public ValidateUtil() { // 初始化验证器工厂 try (ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory()) { // 创建验证器实例 @@ -160,6 +161,43 @@ public class ValidateUtil { return validRegex(value, PatternConstant.NATURAL_INTEGER); } + /** + *

是否是有效二代身份证号

+ * + * @param idCard 身份证号 + * @return 验证结果 + */ + public final boolean isChina2Identity(String idCard) { + // 一代身份证长度 + final int idLength = 15; + // 二代身份证长度 + final int id2Length = 18; + // 二代身份证求余数 + final int id2Mod = 11; + // 系数 + final int[] factor = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}; + // 尾数 + final char[] flags = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'}; + + if (Objects.isNull(idCard)) { + return false; + } + if (idCard.length() != id2Length && idCard.length() != idLength) { + return false; + } + if (idCard.length() == id2Length) { + // 校验二代身份证 + int sum = 0; + for (int i = 0; i < idCard.length() - 1; i++) { + sum += Integer.parseInt(String.valueOf(idCard.charAt(i))) * factor[i]; + } + + // 求和后取余数11,得到的余数与校验码进行匹配,匹配成功,说明通过验证。 + return flags[sum % id2Mod] == idCard.charAt(idCard.length() - 1); + } + throw new ServiceException("暂不支持一代身份证校验"); + } + /** *

正则校验

* diff --git a/pom.xml b/pom.xml index 7336c4b3e3906f6635a74252a6b91c161bd68cc1..9d0ccf1eeb5eb6452d299432f7eae6293071755e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,11 +4,11 @@ 4.0.0 cn.hamm airpower - 2.2.1 + 2.2.2 airpower AirPower is a fast backend development tool based on SpringBoot3 and JPA. - 2.2.1 + 2.2.2 UTF-8 UTF-8 UTF-8