jiangping
2025-06-09 5ecb8706b917aa86f43e44a412e86e3e50b636c0
server/service/src/main/java/com/doumee/core/utils/Constants.java
@@ -321,22 +321,34 @@
    }
    public static int calculateAge(String idCard,Date dateDate) {
        if (idCard == null || idCard.length() != 18) {
            throw new IllegalArgumentException("身份证号码必须是18位");
        try{
            Integer happenYear = Integer.valueOf(DateUtil.dateToString(dateDate,"yyyy"));
            Integer birthYear = Integer.valueOf(idCard.substring(6,10));
            return happenYear - birthYear;
        }catch (Exception e){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"年龄信息错误");
        }
        // 提取出生日期
        String birthDateStr = idCard.substring(6, 14); // 例如:19900101
        LocalDate birthDate = LocalDate.parse(birthDateStr);
        Instant instant = dateDate.toInstant();
        // 获取当前日期
        LocalDate currentDate = instant.atZone(ZoneId.systemDefault()).toLocalDate(); // 转换为 LocalDate
        // 计算年龄
        Period period = Period.between(birthDate, currentDate);
        int age = period.getYears(); // 直接获取年份差即为年龄
        return age;
//        if (idCard == null || idCard.length() != 18) {
//            throw new IllegalArgumentException("身份证号码必须是18位");
//        }
//
//        // 提取出生日期
//        String birthDateStr = idCard.substring(6, 14); // 例如:19900101
//        LocalDate birthDate = LocalDate.parse(birthDateStr);
//        Instant instant = dateDate.toInstant();
//        // 获取当前日期
//        LocalDate currentDate = instant.atZone(ZoneId.systemDefault()).toLocalDate(); // 转换为 LocalDate
//
//        // 计算年龄
//        Period period = Period.between(birthDate, currentDate);
//        int age = period.getYears(); // 直接获取年份差即为年龄
//        return age;
    }
@@ -2166,7 +2178,6 @@
            }
            return null;
        }
        // 普通方法
        public static SettleClaimsLogParentStatus getAll(int index) {