zss
2025-01-13 8d85246f061e3da623c7b9eb4e323ee724b4de0b
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
package com.yuanchu.mom.controller;
 
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuanchu.mom.annotation.ValueAuth;
import com.yuanchu.mom.annotation.ValueClassify;
import com.yuanchu.mom.dto.IncidentReportAddDto;
import com.yuanchu.mom.excel.IncidentReportExport;
import com.yuanchu.mom.service.IncidentReportService;
import com.yuanchu.mom.vo.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
 
/**
 * <p>
 * 设备验收添加验收字段表 前端控制器
 * </p>
 *
 * @author 江苏鵷雏网络科技有限公司
 * @since 2024-09-19 03:54:49
 */
@RestController
@RequestMapping("/incident-report")
public class IncidentReportController {
    @Autowired
    private IncidentReportService incidentReportService;
 
    @PostMapping("saveIncidentReportData")
    public Result saveIncidentReportData(@RequestBody IncidentReportAddDto incidentReportAddDto) {
        incidentReportService.saveIncidentReportData(incidentReportAddDto);
        return Result.success();
    }
 
    @GetMapping("/getShowIncidentReport")
    public Result getShowIncidentReport(@RequestParam("id") Integer id) {
        return Result.success(incidentReportService.getShowIncidentReport(id));
    }
 
    @DeleteMapping("/deleteIncidentReport")
    public Result deleteIncidentReport(@RequestParam("id") Integer id) {
        incidentReportService.deleteIncidentReport(id);
        return Result.success();
    }
 
    @GetMapping("/incidentReportPage")
    public Result incidentReportPage(@RequestParam("deviceId") Integer deviceId, Page page, String processNumber){
        return Result.success(incidentReportService.getByDeviceId(deviceId, page, processNumber));
    }
 
    @DeleteMapping("deleteIncidentReportAll")
    public Result deleteIncidentReport(Integer sparePartsId, Integer fileId, Integer installId, Integer acceptanceCheckId) {
        incidentReportService.deleteIncidentReportAll(sparePartsId, fileId, installId, acceptanceCheckId);
        return Result.success();
    }
 
    @GetMapping("/incidentReportExport")
    public Result incidentReportPage(@RequestParam("deviceId") Integer deviceId, HttpServletResponse response) throws IOException {
        List<IncidentReportExport> list = incidentReportService.incidentReportExport(deviceId);
        response.setHeader("requestType", "excel");
        response.setHeader("Access-Control-Expose-Headers", "requestType");
        // 设置单元格样式
        // 保存到第一个sheet中
        EasyExcel.write(response.getOutputStream())
                .head(IncidentReportExport.class)
                .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) // 自适应列宽
                .sheet()
                .doWrite(list);
        return Result.success();
    }
 
    @ValueClassify("设备验收")
    @ApiOperation(value = "设备验收导出")
    @GetMapping("/acceptanceCertificateExport")
    @ValueAuth
    public void acceptanceCertificateExport(@RequestParam("deviceId") Integer deviceId, @RequestParam("processNumber") String processNumber, HttpServletResponse response) throws Exception {
        incidentReportService.acceptanceCertificateExport(deviceId, processNumber, response);
    }
}