| | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.time.LocalDate; |
| | | import java.time.Period; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | |
| | | TOldster oldster = oldsterService.getById(oldsterWarning.getOldsterId()); |
| | | if(Objects.nonNull(oldster)){ |
| | | oldsterWarningVO.setOldsterName(oldster.getOldsterName()); |
| | | oldsterWarningVO.setOldsterAge(oldster.getOldsterAge()); |
| | | oldsterWarningVO.setOldsterSex(oldster.getOldsterSex()); |
| | | oldsterWarningVO.setContactPhone(oldster.getContactPhone()); |
| | | oldsterWarningVO.setGuardianName(oldster.getGuardianName()); |
| | |
| | | oldsterWarningVO.setIdCard(oldster.getIdCard()); |
| | | oldsterWarningVO.setBirthDate(oldster.getBirthDate()); |
| | | oldsterWarningVO.setOldsterType(oldster.getOldsterType()); |
| | | 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--; |
| | | } |
| | | oldsterWarningVO.setOldsterAge(years); |
| | | } |
| | | return R.ok(oldsterWarningVO); |
| | | } |