|
@@ -1,8 +1,6 @@
|
|
|
package org.springblade.business.controller;
|
|
|
|
|
|
-import com.aspose.cells.PageSetup;
|
|
|
-import com.aspose.cells.PaperSizeType;
|
|
|
-import com.aspose.cells.PdfSaveOptions;
|
|
|
+import com.aspose.cells.*;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
@@ -11,6 +9,9 @@ import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
import org.apache.poi.xssf.usermodel.*;
|
|
|
import org.springblade.business.dto.TrialSummaryMonthlyEditDTO;
|
|
@@ -30,10 +31,7 @@ import org.springframework.mock.web.MockMultipartFile;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import javax.servlet.ServletOutputStream;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
|
-import java.net.URLDecoder;
|
|
|
import java.util.*;
|
|
|
import java.util.List;
|
|
|
import java.util.function.Function;
|
|
@@ -207,7 +205,7 @@ public class TrialSummaryMonthlyController {
|
|
|
@PostMapping("/monthly/download")
|
|
|
@ApiOperationSupport(order = 3)
|
|
|
@ApiOperation(value = "月报汇总下载", notes = "传入TrialSummaryMonthlyPageDTO")
|
|
|
- public void monthlyDownload(@RequestBody TrialSummaryMonthlyPageDTO dto, HttpServletResponse response) {
|
|
|
+ public R<Object> monthlyDownload(@RequestBody TrialSummaryMonthlyPageDTO dto) {
|
|
|
List<Map<String, Object>> records = monthlyPage(dto).getData().getRecords();
|
|
|
try (Workbook workbook = new XSSFWorkbook()) {
|
|
|
Sheet sheet = workbook.createSheet("Sheet1");
|
|
@@ -278,24 +276,21 @@ public class TrialSummaryMonthlyController {
|
|
|
sheet.setColumnWidth(3, 5000);
|
|
|
sheet.setColumnWidth(4, 5000);
|
|
|
|
|
|
- try (ServletOutputStream outputStream = response.getOutputStream();
|
|
|
- ByteArrayOutputStream byteArrayOutputStreamResult = new ByteArrayOutputStream()) {
|
|
|
- String fileName = dto.getStartTime() + "~" + dto.getEndTime() + ".xlsx";
|
|
|
- String decodedFileName = URLDecoder.decode(fileName, "UTF-8");
|
|
|
- response.setHeader("Content-Disposition", "attachment; filename=\"" + decodedFileName + "\"");
|
|
|
- response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
- workbook.write(byteArrayOutputStreamResult);
|
|
|
- byte[] excelBytesResult = byteArrayOutputStreamResult.toByteArray();
|
|
|
- outputStream.write(excelBytesResult);
|
|
|
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
+ workbook.write(byteArrayOutputStream);
|
|
|
+ byte[] excelBytes = byteArrayOutputStream.toByteArray();
|
|
|
+ ByteArrayResource resource = new ByteArrayResource(excelBytes);
|
|
|
+ MockMultipartFile multipartFile = new MockMultipartFile("file", SnowFlakeUtil.getId() + ".xlsx", "application/vnd.ms-excel", resource.getInputStream());
|
|
|
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } finally {
|
|
|
- workbook.close();
|
|
|
+ BladeFile bladeFile = newIOSSClient.uploadFileByInputStream(multipartFile);
|
|
|
+ if (bladeFile != null) {
|
|
|
+ return R.data(bladeFile.getLink());
|
|
|
}
|
|
|
+
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
+ return R.fail("操作失败");
|
|
|
}
|
|
|
|
|
|
private void setCellValueWithNullCheck(Cell cell, String defaultValue, Object value) {
|
|
@@ -310,7 +305,12 @@ public class TrialSummaryMonthlyController {
|
|
|
@ApiOperationSupport(order = 4)
|
|
|
@ApiOperation(value = "月报汇总打印", notes = "传入TrialSummaryMonthlyPageDTO")
|
|
|
public R<Object> monthlyPrint(@RequestBody TrialSummaryMonthlyPageDTO dto) {
|
|
|
- List<Map<String, Object>> records = monthlyPage(dto).getData().getRecords();
|
|
|
+ IPage<Map<String, Object>> data = monthlyPage(dto).getData();
|
|
|
+ long size = data.getSize();
|
|
|
+ List<Map<String, Object>> records = data.getRecords();
|
|
|
+ if (records.size() <= 0) {
|
|
|
+ return R.data(null);
|
|
|
+ }
|
|
|
try (Workbook workbook = new XSSFWorkbook()) {
|
|
|
Sheet sheet = workbook.createSheet("Sheet1");
|
|
|
Row titleRow_1 = sheet.createRow(0);
|
|
@@ -352,24 +352,49 @@ public class TrialSummaryMonthlyController {
|
|
|
setCellValueWithNullCheck(titleRow_2.createCell(3), "不合格数", "");
|
|
|
setCellValueWithNullCheck(titleRow_2.createCell(4), "备注", "");
|
|
|
|
|
|
+ if (records.size() < size) {
|
|
|
+ int a = (int) size - records.size();
|
|
|
+ for (long i = 0; i < a; i++) {
|
|
|
+ records.add(new HashMap<>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
int rowNum = 2;
|
|
|
for (Map<String, Object> record : records) {
|
|
|
Row currentMonthRow = sheet.createRow(rowNum);
|
|
|
sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum + 1, 0, 0));
|
|
|
- setCellValueWithNullCheck(currentMonthRow.createCell(0), "", record.get("trialProjectName"));
|
|
|
-
|
|
|
- Map<String, Object> currentMonth = (Map<String, Object>) record.get("currentMonth");
|
|
|
- setCellValueWithNullCheck(currentMonthRow.createCell(1), "本月", "");
|
|
|
- setCellValueWithNullCheck(currentMonthRow.createCell(2), "", currentMonth.get("qualifiedTotal"));
|
|
|
- setCellValueWithNullCheck(currentMonthRow.createCell(3), "", currentMonth.get("unQualifiedTotal"));
|
|
|
- setCellValueWithNullCheck(currentMonthRow.createCell(4), "", currentMonth.get("remarks"));
|
|
|
|
|
|
- Map<String, Object> totalMonth = (Map<String, Object>) record.get("totalMonth");
|
|
|
- Row totalMonthRow = sheet.createRow(++rowNum);
|
|
|
- setCellValueWithNullCheck(totalMonthRow.createCell(1), "累计", "");
|
|
|
- setCellValueWithNullCheck(totalMonthRow.createCell(2), "", totalMonth.get("qualifiedTotal"));
|
|
|
- setCellValueWithNullCheck(totalMonthRow.createCell(3), "", totalMonth.get("unQualifiedTotal"));
|
|
|
- setCellValueWithNullCheck(totalMonthRow.createCell(4), "", totalMonth.get("remarks"));
|
|
|
+ if (ObjectUtil.isNotEmpty(record)) {
|
|
|
+ setCellValueWithNullCheck(currentMonthRow.createCell(0), "", record.get("trialProjectName"));
|
|
|
+
|
|
|
+ Map<String, Object> currentMonth = (Map<String, Object>) record.get("currentMonth");
|
|
|
+ setCellValueWithNullCheck(currentMonthRow.createCell(1), "本月", "");
|
|
|
+ setCellValueWithNullCheck(currentMonthRow.createCell(2), "", currentMonth.get("qualifiedTotal"));
|
|
|
+ setCellValueWithNullCheck(currentMonthRow.createCell(3), "", currentMonth.get("unQualifiedTotal"));
|
|
|
+ setCellValueWithNullCheck(currentMonthRow.createCell(4), "", currentMonth.get("remarks"));
|
|
|
+
|
|
|
+ Map<String, Object> totalMonth = (Map<String, Object>) record.get("totalMonth");
|
|
|
+ Row totalMonthRow = sheet.createRow(++rowNum);
|
|
|
+ setCellValueWithNullCheck(totalMonthRow.createCell(1), "累计", "");
|
|
|
+ setCellValueWithNullCheck(totalMonthRow.createCell(2), "", totalMonth.get("qualifiedTotal"));
|
|
|
+ setCellValueWithNullCheck(totalMonthRow.createCell(3), "", totalMonth.get("unQualifiedTotal"));
|
|
|
+ setCellValueWithNullCheck(totalMonthRow.createCell(4), "", totalMonth.get("remarks"));
|
|
|
+
|
|
|
+ } else {
|
|
|
+ /*打印空行*/
|
|
|
+ setCellValueWithNullCheck(currentMonthRow.createCell(0), "", "");
|
|
|
+
|
|
|
+ setCellValueWithNullCheck(currentMonthRow.createCell(1), "", "");
|
|
|
+ setCellValueWithNullCheck(currentMonthRow.createCell(2), "", "");
|
|
|
+ setCellValueWithNullCheck(currentMonthRow.createCell(3), "", "");
|
|
|
+ setCellValueWithNullCheck(currentMonthRow.createCell(4), "", "");
|
|
|
+
|
|
|
+ Row totalMonthRow = sheet.createRow(++rowNum);
|
|
|
+ setCellValueWithNullCheck(totalMonthRow.createCell(1), "", "");
|
|
|
+ setCellValueWithNullCheck(totalMonthRow.createCell(2), "", "");
|
|
|
+ setCellValueWithNullCheck(totalMonthRow.createCell(3), "", "");
|
|
|
+ setCellValueWithNullCheck(totalMonthRow.createCell(4), "", "");
|
|
|
+ }
|
|
|
|
|
|
rowNum++;
|
|
|
}
|