package com.ruoyi.requier.controller; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.core.domain.Result; import com.ruoyi.requier.dto.IncidentReportAddDto; import com.ruoyi.requier.excel.IncidentReportExport; import com.ruoyi.requier.service.IncidentReportService; 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; /** *

* 设备验收添加验收字段表 前端控制器 *

* * @author 江苏鵷雏网络科技有限公司 * @since 2024-09-19 03:54:49 */ @RestController @RequestMapping("/incidentReport") 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 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(); } }