From 30bd0425caaee2e105aac054bcdf94e9a58a2d3b Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期三, 12 十一月 2025 17:20:36 +0800
Subject: [PATCH] 年龄修改
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TOldsterServiceImpl.java | 15 +++++++++++++--
1 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TOldsterServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TOldsterServiceImpl.java
index 3635f93..2361fec 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TOldsterServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TOldsterServiceImpl.java
@@ -12,6 +12,8 @@
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
+import java.time.LocalDate;
+import java.time.Period;
import java.util.List;
/**
@@ -34,8 +36,17 @@
}
for (TOldster oldster : list) {
- int age = IDCardAgeCalculator.calculateAge(oldster.getIdCard());
- oldster.setAge(age);
+ LocalDate birthDate = oldster.getBirthDate();
+ LocalDate currentDate = LocalDate.now();
+ // 使用Period类计算两个日期之间的年数差异
+ Period period = Period.between(birthDate, currentDate);
+ int years = period.getYears();
+ // 如果当前日期小于出生日期的下一个生日,则需要减去一年(因为我们还没有过生日)
+ if (currentDate.isBefore(birthDate.plusYears(years).plusMonths(1).minusDays(1))) {
+ years--;
+ }
+ oldster.setOldsterAge(years);
+ oldster.setAge(years);
}
pageInfo.setRecords( list);
return pageInfo;
--
Gitblit v1.7.1