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; /** *

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

* * @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 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); } }