| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.time.Period; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | |
| | | public PageInfo<TOldsterWarningVO> pageList(OldsterListQuery query) { |
| | | PageInfo<TOldsterWarningVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); |
| | | List<TOldsterWarningVO> list = this.baseMapper.pageList(query,pageInfo); |
| | | if(CollectionUtils.isEmpty(list)){ |
| | | return pageInfo; |
| | | } |
| | | |
| | | for (TOldsterWarningVO oldsterWarningVO : list) { |
| | | LocalDate birthDate = oldsterWarningVO.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); |
| | | } |
| | | pageInfo.setRecords(list); |
| | | return pageInfo; |
| | | } |
| | |
| | | @Override |
| | | public List<TOldsterWarningExport> exportOldsterWarning(OldsterListQuery query) { |
| | | List<TOldsterWarningExport> list = this.baseMapper.exportOldsterWarning(query); |
| | | for (TOldsterWarningExport oldsterWarningExport : list) { |
| | | LocalDate birthDate = oldsterWarningExport.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--; |
| | | } |
| | | oldsterWarningExport.setOldsterAge(years); |
| | | } |
| | | return list; |
| | | } |
| | | } |