xuhy
2025-11-15 dec2234ff37237d6ffd7bb936c9756cff8a8e674
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
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.THelpNeedsExport;
import com.ruoyi.system.export.TMicroWishExport;
import com.ruoyi.system.model.TAppUser;
import com.ruoyi.system.model.THelpNeeds;
import com.ruoyi.system.model.THelpNeeds;
import com.ruoyi.system.query.AssistedDiningListQuery;
import com.ruoyi.system.query.HelpNeedsListQuery;
import com.ruoyi.system.query.TCourseOrderQuery;
import com.ruoyi.system.service.THelpNeedsService;
import com.ruoyi.system.service.THelpNeedsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
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.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 助需管理 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-11-06
 */
@RestController
@RequestMapping("/t-help-needs")
@Api(tags = "助需管理")
public class THelpNeedsController {
    @Autowired
    private THelpNeedsService helpNeedsService;
    @ApiOperation(value = "助需管理分页列表")
    @PostMapping(value = "/pageList")
    public R<PageInfo<THelpNeeds>> pageList(@RequestBody HelpNeedsListQuery query) {
        return R.ok(helpNeedsService.pageList(query));
    }
 
    @ApiOperation(value = "添加")
    @Transactional
    @Log(title = "助需管理-添加", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public R<Boolean> save(@RequestBody THelpNeeds dto) {
        helpNeedsService.save(dto);
        return R.ok();
    }
    @ApiOperation(value = "修改")
    @Log(title = "助需管理-修改", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public R<Boolean> edit(@RequestBody THelpNeeds dto) {
        helpNeedsService.updateById(dto);
        return R.ok();
    }
    @Log(title = "助需管理-删除", businessType = BusinessType.DELETE)
    @ApiOperation(value = "助需管理-删除")
    @DeleteMapping(value = "/deleteById")
    public R<Boolean> deleteById(@RequestParam String id) {
        return R.ok(helpNeedsService.removeById(id));
    }
 
    /**
     * 批量删除助需管理
     */
    @Log(title = "助需管理-批量删除", businessType = BusinessType.DELETE)
    @ApiOperation(value = "助需管理-批量删除")
    @DeleteMapping(value = "/deleteByIds")
    public R<Boolean> deleteByIds(@RequestBody List<String> ids) {
        return R.ok(helpNeedsService.removeByIds(ids));
    }
    @ApiOperation(value = "查看详情")
    @GetMapping(value = "/detail")
    public R<THelpNeeds> detail(String id) {
        return R.ok(helpNeedsService.getById( id));
    }
 
    @Log(title = "助需管理-助需记录导出", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "助需记录导出")
    @PostMapping("/exportHelpNeeds")
    public void exportHelpNeeds(@RequestBody HelpNeedsListQuery query){
        List<THelpNeedsExport> helpNeedsExports = helpNeedsService.exportHelpNeeds(query);
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), THelpNeedsExport.class, helpNeedsExports);
        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();
            }
        }
    }
}