xuhy
2025-12-29 5cc91e1b876a2a4509d68ce15e63802f2713ead8
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package com.ruoyi.web.controller.api;
 
 
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.WebUtils;
import com.ruoyi.system.export.TCourseOrderExport;
import com.ruoyi.system.export.TOldsterWarningExport;
import com.ruoyi.system.export.TRefundOrderExport;
import com.ruoyi.system.model.TOldster;
import com.ruoyi.system.model.TOldsterWarning;
import com.ruoyi.system.model.TPartyBuilding;
import com.ruoyi.system.query.OldsterListQuery;
import com.ruoyi.system.query.TCourseOrderQuery;
import com.ruoyi.system.query.TPartyBuildingQuery;
import com.ruoyi.system.service.TOldsterService;
import com.ruoyi.system.service.TOldsterWarningService;
import com.ruoyi.system.service.TPartyBuildingService;
import com.ruoyi.system.vo.TOldsterWarningVO;
import com.ruoyi.system.vo.TPartyBuildingVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.ServletOutputStream;
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;
 
/**
 * <p>
 * 老人预警 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-11-06
 */
@Api(tags = "老人预警管理")
@RestController
@RequestMapping("/t-oldster-warning")
public class TOldsterWarningController {
 
    private final TOldsterWarningService oldsterWarningService;
    private final TOldsterService oldsterService;
    @Autowired
    public TOldsterWarningController(TOldsterWarningService oldsterWarningService, TOldsterService oldsterService) {
        this.oldsterWarningService = oldsterWarningService;
        this.oldsterService = oldsterService;
    }
 
    /**
     * 获取老人预警管理列表
     */
    @ApiOperation(value = "获取老人预警管理分页列表")
    @PostMapping(value = "/pageList")
    public R<PageInfo<TOldsterWarningVO>> pageList(@RequestBody OldsterListQuery query) {
        return R.ok(oldsterWarningService.pageList(query));
    }
 
    /**
     * 查看老人预警管理详情
     */
    @ApiOperation(value = "查看老人预警管理详情")
    @GetMapping(value = "/getDetailById")
    public R<TOldsterWarningVO> getDetailById(@RequestParam String id) {
        TOldsterWarning oldsterWarning = oldsterWarningService.getById(id);
        TOldsterWarningVO oldsterWarningVO = new TOldsterWarningVO();
        BeanUtils.copyProperties(oldsterWarning, oldsterWarningVO);
        // 查询老人信息
        TOldster oldster = oldsterService.getById(oldsterWarning.getOldsterId());
        if(Objects.nonNull(oldster)){
            oldsterWarningVO.setOldsterName(oldster.getOldsterName());
            oldsterWarningVO.setOldsterSex(oldster.getOldsterSex());
            oldsterWarningVO.setContactPhone(oldster.getContactPhone());
            oldsterWarningVO.setGuardianName(oldster.getGuardianName());
            oldsterWarningVO.setGuardianPhone(oldster.getGuardianPhone());
            oldsterWarningVO.setAddress(oldster.getAddress());
            oldsterWarningVO.setPassportPhoto(oldster.getPassportPhoto());
            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);
    }
    /**
     * 删除老人预警信息
     */
    @Log(title = "老人预警信息-删除", businessType = BusinessType.DELETE)
    @ApiOperation(value = "老人预警信息-删除")
    @DeleteMapping(value = "/deleteById")
    public R<Boolean> deleteById(@RequestParam String id) {
        return R.ok(oldsterWarningService.removeById(id));
    }
    @Log(title = "老人预警管理-老人预警记录导出", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "老人预警记录导出")
    @PostMapping("/exportOldsterWarning")
    public void exportOldsterWarning(@RequestBody OldsterListQuery query){
        List<TOldsterWarningExport> oldsterWarningExports = oldsterWarningService.exportOldsterWarning(query);
        for (TOldsterWarningExport oldsterWarningExport : oldsterWarningExports) {
            if(Objects.nonNull(oldsterWarningExport.getWarningTime())){
                oldsterWarningExport.setWarningTimeStr(DateUtils.localDateTimeToString(oldsterWarningExport.getWarningTime()));
            }
        }
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TOldsterWarningExport.class, oldsterWarningExports);
        HttpServletResponse response = WebUtils.response();
        assert response != null;
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        ServletOutputStream outputStream = null;
        try {
            String fileName = URLEncoder.encode("老人预警记录导出.xls", "utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setHeader("Pragma", "no-cache");
            response.setHeader("Cache-Control", "no-cache");
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
 
}