xuhy
2025-11-17 2c35ada755cd899d07d06d98556d7de0f4705bf8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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;
 
/**
 * <p>
 * 老人预警 服务实现类
 * </p>
 *
 * @author xiaochen
 * @since 2025-11-06
 */
@Service
public class TOldsterWarningServiceImpl extends ServiceImpl<TOldsterWarningMapper, TOldsterWarning> implements TOldsterWarningService {
 
    @Override
    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;
    }
}