xiexiang 2 lat temu
rodzic
commit
120fe19abb

+ 68 - 0
RMS/src/main/java/cn/cslg/report/service/business/ExportArgumentsScenariosService.java

@@ -0,0 +1,68 @@
+package cn.cslg.report.service.business;
+
+import cn.cslg.report.common.model.dto.invalidReReport.InvalidReasonDTO;
+import cn.cslg.report.common.model.vo.invalidReReport.ExportInvalidReasonVO;
+import cn.cslg.report.service.business.InvalidReReport.InvalidReasonService;
+import cn.hutool.core.collection.CollUtil;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.stereotype.Service;
+
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * 导出无效理由实现类
+ * @Author xiexiang
+ * @Date 2023/7/24
+ */
+@Service
+@Slf4j
+@RequiredArgsConstructor(onConstructor_ = {@Lazy})
+public class ExportArgumentsScenariosService {
+    private final InvalidReasonService invalidReasonService;
+
+    public void ExportToExcel(Integer reportId, String filePath) throws IOException {
+        List<ExportInvalidReasonVO> exportInvalidReasonVOS = invalidReasonService.exportInvalidReason(reportId);
+        try (FileOutputStream fileOut = new FileOutputStream(filePath)){
+            Workbook workbook = new XSSFWorkbook();
+            Sheet sheet = workbook.createSheet("无效理由");
+            //创建标题行
+            Row headerRow = sheet.createRow(0);
+            String[] headers = {"序号","无效理由","涉及内容","相关证据","陈述意见"};
+            for(int i = 0; i < headers.length; i++){
+                Cell cell = headerRow.createCell(i);
+                cell.setCellValue(headers[i]);
+            }
+            //字体
+            Font headerFont = workbook.createFont();
+            headerFont.setBold(true);
+            CellStyle headerCellStyle = workbook.createCellStyle();
+            headerCellStyle.setFont(headerFont);
+            int rowNum = 0;
+            //填充数据
+            for(ExportInvalidReasonVO exportInvalidReasonVO : exportInvalidReasonVOS){
+                Row row = sheet.createRow(rowNum++);
+                row.createCell(0).setCellValue(exportInvalidReasonVO.getInvalidName());
+                row.createCell(1).setCellValue(exportInvalidReasonVO.getContent());
+                row.createCell(2).setCellValue(exportInvalidReasonVO.getProofStr());
+                row.createCell(3).setCellValue(exportInvalidReasonVO.getArgumentStr());
+            }
+            //自动调整列宽
+            for(int i = 0; i < headers.length; i++){
+                sheet.autoSizeColumn(i);
+            }
+            workbook.write(fileOut);
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        }
+    }
+}