package com.ruoyi.system.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.basic.PageInfo; import com.ruoyi.system.export.TOldsterWarningExport; import com.ruoyi.system.mapper.TOldsterWarningMapper; import com.ruoyi.system.model.TAdvertisement; import com.ruoyi.system.model.TOldster; import com.ruoyi.system.model.TOldsterWarning; import com.ruoyi.system.query.OldsterListQuery; import com.ruoyi.system.query.TCourseOrderQuery; import com.ruoyi.system.service.TOldsterWarningService; import com.ruoyi.system.utils.util.IDCardAgeCalculator; import com.ruoyi.system.vo.TOldsterWarningVO; 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; /** *

* 老人预警 服务实现类 *

* * @author xiaochen * @since 2025-11-06 */ @Service public class TOldsterWarningServiceImpl extends ServiceImpl implements TOldsterWarningService { @Override public PageInfo pageList(OldsterListQuery query) { PageInfo pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); List 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 exportOldsterWarning(OldsterListQuery query) { List 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; } }