xuhy
2025-11-12 30bd0425caaee2e105aac054bcdf94e9a58a2d3b
年龄修改
4个文件已修改
62 ■■■■■ 已修改文件
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TOldsterController.java 4 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TOldsterWarningController.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TOldsterServiceImpl.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TOldsterWarningServiceImpl.java 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TOldsterController.java
@@ -176,10 +176,6 @@
                result.append("第"+i+"行:[", "老人姓名"+"]不能为空");
                continue;
            }
            if (oldsterImport.getOldsterAge()==null){
                result.append("第"+i+"行:[", "老人年龄"+"]不能为空");
                continue;
            }
            if (!StringUtils.hasLength(oldsterImport.getOldsterSexStr())){
                result.append("第"+i+"行:[", "老人性别"+"]不能为空");
                continue;
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TOldsterWarningController.java
@@ -34,6 +34,8 @@
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;
@@ -80,7 +82,6 @@
        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());
@@ -90,6 +91,16 @@
            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);
    }
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;
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TOldsterWarningServiceImpl.java
@@ -15,6 +15,8 @@
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;
@@ -33,6 +35,22 @@
    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;
    }
@@ -40,6 +58,18 @@
    @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;
    }
}