Browse Source

优化身份证和年龄的判断

lighter 2 năm trước cách đây
mục cha
commit
20fb843da9

+ 3 - 2
src/main/java/thyyxxk/webserver/service/inpatient/DismissService.java

@@ -194,8 +194,9 @@ public class DismissService {
         if (!IdCardUtil.isValidatedIdCard(param.getSocialNo())) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "身份证不合法!");
         }
-        int age = IdCardUtil.getAgeByIdCard(param.getSocialNo());
-        if (age < 16 || age > 60) {
+        Integer age = IdCardUtil.getAgeByIdCard(param.getSocialNo());
+        age = age == null ? param.getAge() : age;
+        if (null != age && (age < 16 || age > 60)) {
             if (param.getName().equals(param.getContactName()) ||
                     param.getContactRelation().equals("0")) {
                 return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "16岁以下或60岁以上的患者,联系人不能填写本人。");

+ 2 - 2
src/main/java/thyyxxk/webserver/service/inpatient/PatientService.java

@@ -252,8 +252,8 @@ public class PatientService {
         if (!IdCardUtil.isValidatedIdCard(patient.getSocialNo())) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "身份证不合法!");
         }
-        int age = IdCardUtil.getAgeByIdCard(patient.getSocialNo());
-        if (age < 16 || age > 60) {
+        Integer age = IdCardUtil.getAgeByIdCard(patient.getSocialNo());
+        if (null != age && (age < 16 || age > 60)) {
             if (patient.getName().equals(patient.getContactName()) ||
                     patient.getContactRelation().equals("0")) {
                 return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "16岁以下或60岁以上的患者,联系人不能填写本人。");

+ 7 - 1
src/main/java/thyyxxk/webserver/utils/IdCardUtil.java

@@ -34,6 +34,9 @@ public class IdCardUtil {
         if (StringUtil.isBlank(idCard)) {
             return false;
         }
+        if (idCard.startsWith("R")) {
+            return true;
+        }
         return isValidate18IdCard(idCard);
     }
 
@@ -194,7 +197,10 @@ public class IdCardUtil {
         return a;
     }
 
-    public static int getAgeByIdCard(String idCard) {
+    public static Integer getAgeByIdCard(String idCard) {
+        if (idCard.length() < 18) {
+            return null;
+        }
         String birthDay = idCard.substring(6, 14);
         String time = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
         String yearStr = time.split("-")[0];