|
|
@@ -8,17 +8,22 @@ import com.siwei.apply.domain.res.TrendStatisticsData;
|
|
|
import com.siwei.apply.domain.res.TrendStatisticsRes;
|
|
|
import com.siwei.apply.domain.res.TrendUseStatisticsData;
|
|
|
import com.siwei.apply.domain.vo.LandSupplyProjectVO;
|
|
|
+import com.siwei.apply.domain.vo.LandSupplyReportVO;
|
|
|
import com.siwei.apply.service.cadastre.impl.StorageServiceImpl;
|
|
|
import com.siwei.common.core.domain.R;
|
|
|
import com.siwei.common.core.web.controller.BaseController;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -193,6 +198,209 @@ public class StorageController extends BaseController {
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 收储进度报表导出
|
|
|
+ * @param response
|
|
|
+ * @param startYear
|
|
|
+ * @param endYear
|
|
|
+ */
|
|
|
+ @GetMapping("/progress/export")
|
|
|
+ public void exportPurposeReport(HttpServletResponse response, @RequestParam String startYear, @RequestParam String endYear) {
|
|
|
+ try {
|
|
|
+ LandStorageReportDTO res = storageServiceImpl.stroageProgress(startYear,endYear);
|
|
|
+ if (res == null || CollectionUtils.isEmpty(res.getDetails())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
+ Sheet sheet = workbook.createSheet("收储进度报表");
|
|
|
+
|
|
|
+ CellStyle titleStyle = workbook.createCellStyle();
|
|
|
+ titleStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ Font titleFont = workbook.createFont();
|
|
|
+ titleFont.setBold(true);
|
|
|
+ titleFont.setFontHeightInPoints((short) 14);
|
|
|
+ titleStyle.setFont(titleFont);
|
|
|
+ titleStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ titleStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ titleStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ titleStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+
|
|
|
+ CellStyle headerStyle = workbook.createCellStyle();
|
|
|
+ headerStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
|
|
|
+ headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
+ Font headerFont = workbook.createFont();
|
|
|
+ headerFont.setBold(true);
|
|
|
+ headerStyle.setFont(headerFont);
|
|
|
+ headerStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ headerStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ headerStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ headerStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+
|
|
|
+ CellStyle dataStyle = workbook.createCellStyle();
|
|
|
+ dataStyle.setAlignment(HorizontalAlignment.RIGHT);
|
|
|
+ dataStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ dataStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ dataStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ dataStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ dataStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+
|
|
|
+ CellStyle rateStyle = workbook.createCellStyle();
|
|
|
+ rateStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ rateStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ rateStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ rateStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ rateStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ rateStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+
|
|
|
+ int rowIndex = 0;
|
|
|
+
|
|
|
+ Row titleRow = sheet.createRow(rowIndex++);
|
|
|
+ Cell titleCell = titleRow.createCell(0);
|
|
|
+ titleCell.setCellValue(res.getTitle() != null ? res.getTitle() : "收储进度报表");
|
|
|
+ titleCell.setCellStyle(titleStyle);
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 13));
|
|
|
+ titleRow.setHeight((short) 600);
|
|
|
+
|
|
|
+ Row subTitleRow = sheet.createRow(rowIndex++);
|
|
|
+ Cell subTitleCell = subTitleRow.createCell(0);
|
|
|
+ subTitleCell.setCellValue("统计时间范围:" + (res.getStatTimeRange() != null ? res.getStatTimeRange() : startYear + " 至 " + endYear));
|
|
|
+ subTitleCell.setCellStyle(titleStyle);
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 13));
|
|
|
+
|
|
|
+ Row headerRow = sheet.createRow(rowIndex++);
|
|
|
+ String[] headers = {"用地类型", "收储进度", "计划面积", "计划数量", "计划成本", "计划收购", "计划征收", "计划其它",
|
|
|
+ "完成面积", "完成数量", "完成成本", "完成收购", "完成征收", "完成其它"};
|
|
|
+ for (int i = 0; i < headers.length; i++) {
|
|
|
+ Cell cell = headerRow.createCell(i);
|
|
|
+ cell.setCellValue(headers[i]);
|
|
|
+ cell.setCellStyle(headerStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ int detailColCount = headers.length - 1;
|
|
|
+ for (LandStorageReportDTO.DetailDTO detail : res.getDetails()) {
|
|
|
+ Row dataRow = sheet.createRow(rowIndex++);
|
|
|
+
|
|
|
+ Cell typeCell = dataRow.createCell(0);
|
|
|
+ typeCell.setCellValue(detail.getCategory() != null ? detail.getCategory() : "");
|
|
|
+ typeCell.setCellStyle(dataStyle);
|
|
|
+
|
|
|
+ Cell rateCell = dataRow.createCell(1);
|
|
|
+ rateCell.setCellValue(detail.getProgress() != null ? detail.getProgress() : "0%");
|
|
|
+ rateCell.setCellStyle(rateStyle);
|
|
|
+
|
|
|
+ int colIndex = 2;
|
|
|
+ if (detail.getPlan() != null) {
|
|
|
+ LandStorageReportDTO.PlanDTO plan = detail.getPlan();
|
|
|
+ dataRow.createCell(colIndex++).setCellValue(plan.getArea() != null ? plan.getArea() : 0.0);
|
|
|
+ dataRow.createCell(colIndex++).setCellValue(plan.getCount() != null ? plan.getCount() : 0);
|
|
|
+ dataRow.createCell(colIndex++).setCellValue(plan.getCost() != null ? plan.getCost() : 0.0f);
|
|
|
+ dataRow.createCell(colIndex++).setCellValue(plan.getMethod1() != null ? plan.getMethod1() : 0);
|
|
|
+ dataRow.createCell(colIndex++).setCellValue(plan.getMethod2() != null ? plan.getMethod2() : 0);
|
|
|
+ dataRow.createCell(colIndex++).setCellValue(plan.getOtherMethod() != null ? plan.getOtherMethod() : 0);
|
|
|
+ } else {
|
|
|
+ colIndex += 6;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (detail.getCompleted() != null) {
|
|
|
+ LandStorageReportDTO.CompletedDTO completed = detail.getCompleted();
|
|
|
+ dataRow.createCell(colIndex++).setCellValue(completed.getArea() != null ? completed.getArea() : 0.0);
|
|
|
+ dataRow.createCell(colIndex++).setCellValue(completed.getCount() != null ? completed.getCount() : 0);
|
|
|
+ dataRow.createCell(colIndex++).setCellValue(completed.getCost() != null ? completed.getCost() : 0.0f);
|
|
|
+ dataRow.createCell(colIndex++).setCellValue(completed.getMethod1() != null ? completed.getMethod1() : 0);
|
|
|
+ dataRow.createCell(colIndex++).setCellValue(completed.getMethod2() != null ? completed.getMethod2() : 0);
|
|
|
+ dataRow.createCell(colIndex++).setCellValue(completed.getOtherMethod() != null ? completed.getOtherMethod() : 0);
|
|
|
+ } else {
|
|
|
+ colIndex += 6;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i <= detailColCount; i++) {
|
|
|
+ if (dataRow.getCell(i) == null) {
|
|
|
+ dataRow.createCell(i).setCellStyle(dataStyle);
|
|
|
+ } else if (i == 1) {
|
|
|
+ continue;
|
|
|
+ } else {
|
|
|
+ dataRow.getCell(i).setCellStyle(dataStyle);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (res.getSummary() != null && res.getSummary().getTotal() != null) {
|
|
|
+ LandStorageReportDTO.TotalDTO total = res.getSummary().getTotal();
|
|
|
+ Row totalRow = sheet.createRow(rowIndex++);
|
|
|
+
|
|
|
+ Cell typeCell = totalRow.createCell(0);
|
|
|
+ typeCell.setCellValue("合计");
|
|
|
+ typeCell.setCellStyle(dataStyle);
|
|
|
+
|
|
|
+ Cell rateCell = totalRow.createCell(1);
|
|
|
+ rateCell.setCellValue(total.getProgress() != null ? total.getProgress() : "0%");
|
|
|
+ rateCell.setCellStyle(rateStyle);
|
|
|
+
|
|
|
+ int colIndex = 2;
|
|
|
+ if (total.getPlan() != null) {
|
|
|
+ LandStorageReportDTO.PlanDTO plan = total.getPlan();
|
|
|
+ totalRow.createCell(colIndex++).setCellValue(plan.getArea() != null ? plan.getArea() : 0.0);
|
|
|
+ totalRow.createCell(colIndex++).setCellValue(plan.getCount() != null ? plan.getCount() : 0);
|
|
|
+ totalRow.createCell(colIndex++).setCellValue(plan.getCost() != null ? plan.getCost() : 0.0f);
|
|
|
+ totalRow.createCell(colIndex++).setCellValue(plan.getMethod1() != null ? plan.getMethod1() : 0);
|
|
|
+ totalRow.createCell(colIndex++).setCellValue(plan.getMethod2() != null ? plan.getMethod2() : 0);
|
|
|
+ totalRow.createCell(colIndex++).setCellValue(plan.getOtherMethod() != null ? plan.getOtherMethod() : 0);
|
|
|
+ } else {
|
|
|
+ colIndex += 6;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (total.getCompleted() != null) {
|
|
|
+ LandStorageReportDTO.CompletedDTO completed = total.getCompleted();
|
|
|
+ totalRow.createCell(colIndex++).setCellValue(completed.getArea() != null ? completed.getArea() : 0.0);
|
|
|
+ totalRow.createCell(colIndex++).setCellValue(completed.getCount() != null ? completed.getCount() : 0);
|
|
|
+ totalRow.createCell(colIndex++).setCellValue(completed.getCost() != null ? completed.getCost() : 0.0f);
|
|
|
+ totalRow.createCell(colIndex++).setCellValue(completed.getMethod1() != null ? completed.getMethod1() : 0);
|
|
|
+ totalRow.createCell(colIndex++).setCellValue(completed.getMethod2() != null ? completed.getMethod2() : 0);
|
|
|
+ totalRow.createCell(colIndex++).setCellValue(completed.getOtherMethod() != null ? completed.getOtherMethod() : 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i <= detailColCount; i++) {
|
|
|
+ if (totalRow.getCell(i) == null) {
|
|
|
+ totalRow.createCell(i).setCellStyle(dataStyle);
|
|
|
+ } else if (i == 1) {
|
|
|
+ continue;
|
|
|
+ } else {
|
|
|
+ totalRow.getCell(i).setCellStyle(dataStyle);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i <= detailColCount; i++) {
|
|
|
+ sheet.autoSizeColumn(i);
|
|
|
+ }
|
|
|
+
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ String fileName = "收储进度分析报表.xlsx";
|
|
|
+ String encodedName = URLEncoder.encode(fileName, StandardCharsets.UTF_8).replace("+", "%20");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename*=UTF-8''" + encodedName);
|
|
|
+
|
|
|
+ workbook.write(response.getOutputStream());
|
|
|
+ workbook.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@GetMapping("/report/inOutDetails")
|
|
|
public R<LandStorageInOutReportDTO> getInOutDetails() {
|
|
|
try {
|
|
|
@@ -206,6 +414,189 @@ public class StorageController extends BaseController {
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 出入库报表导出
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ @GetMapping("/inout/export")
|
|
|
+ public void exportInoutReport(HttpServletResponse response) {
|
|
|
+ try {
|
|
|
+ LandStorageInOutReportDTO res = storageServiceImpl.inOutDetails();
|
|
|
+ if (res == null || CollectionUtils.isEmpty(res.getCategoryList())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
+ Sheet sheet = workbook.createSheet("收储出入库分析报表");
|
|
|
+
|
|
|
+ CellStyle titleStyle = workbook.createCellStyle();
|
|
|
+ titleStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ Font titleFont = workbook.createFont();
|
|
|
+ titleFont.setBold(true);
|
|
|
+ titleFont.setFontHeightInPoints((short) 14);
|
|
|
+ titleStyle.setFont(titleFont);
|
|
|
+ titleStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ titleStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ titleStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ titleStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+
|
|
|
+ CellStyle headerStyle = workbook.createCellStyle();
|
|
|
+ headerStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
|
|
|
+ headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
+ Font headerFont = workbook.createFont();
|
|
|
+ headerFont.setBold(true);
|
|
|
+ headerStyle.setFont(headerFont);
|
|
|
+ headerStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ headerStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ headerStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ headerStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+
|
|
|
+ CellStyle dataStyle = workbook.createCellStyle();
|
|
|
+ dataStyle.setAlignment(HorizontalAlignment.RIGHT);
|
|
|
+ dataStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ dataStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ dataStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ dataStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ dataStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+
|
|
|
+ CellStyle totalStyle = workbook.createCellStyle();
|
|
|
+ totalStyle.setAlignment(HorizontalAlignment.RIGHT);
|
|
|
+ totalStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ totalStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
|
|
|
+ totalStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
+ Font totalFont = workbook.createFont();
|
|
|
+ totalFont.setBold(true);
|
|
|
+ totalStyle.setFont(totalFont);
|
|
|
+ totalStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ totalStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ totalStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ totalStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+
|
|
|
+ List<String> years = java.util.Arrays.asList("all", "2021", "2022", "2023", "2024", "2025", "2026", "other");
|
|
|
+ List<LandStorageInOutReportDTO.CategoryDTO> dataList = res.getCategoryList();
|
|
|
+
|
|
|
+ int lastColIndex = years.size() * 2;
|
|
|
+
|
|
|
+ int rowIndex = 0;
|
|
|
+
|
|
|
+ Row titleRow = sheet.createRow(rowIndex++);
|
|
|
+ Cell titleCell = titleRow.createCell(0);
|
|
|
+ titleCell.setCellValue(res.getTitle() != null ? res.getTitle() : "收储出入库分析报表");
|
|
|
+ titleCell.setCellStyle(titleStyle);
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, lastColIndex));
|
|
|
+ titleRow.setHeight((short) 600);
|
|
|
+
|
|
|
+ Row headerRow1 = sheet.createRow(rowIndex++);
|
|
|
+ Row headerRow2 = sheet.createRow(rowIndex++);
|
|
|
+
|
|
|
+ Cell typeHeader = headerRow1.createCell(0);
|
|
|
+ typeHeader.setCellValue("用地类型");
|
|
|
+ typeHeader.setCellStyle(headerStyle);
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(1, 2, 0, 0));
|
|
|
+ headerRow2.createCell(0).setCellStyle(headerStyle);
|
|
|
+
|
|
|
+ int colIndex = 1;
|
|
|
+ String[] categoryNames = {"入库", "出库"};
|
|
|
+ for (int i = 0; i < categoryNames.length; i++) {
|
|
|
+ Cell categoryCell = headerRow1.createCell(colIndex);
|
|
|
+ categoryCell.setCellValue(categoryNames[i]);
|
|
|
+ categoryCell.setCellStyle(headerStyle);
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(1, 1, colIndex, colIndex + years.size() - 1));
|
|
|
+
|
|
|
+ for (int j = 0; j < years.size(); j++) {
|
|
|
+ Cell yearCell = headerRow2.createCell(colIndex + j);
|
|
|
+ yearCell.setCellValue(years.get(j));
|
|
|
+ yearCell.setCellStyle(headerStyle);
|
|
|
+ }
|
|
|
+ colIndex += years.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ for (LandStorageInOutReportDTO.CategoryDTO categoryData : dataList) {
|
|
|
+ Row dataRow = sheet.createRow(rowIndex++);
|
|
|
+
|
|
|
+ Cell typeCell = dataRow.createCell(0);
|
|
|
+ typeCell.setCellValue(categoryData.getCategory() != null ? categoryData.getCategory() : "");
|
|
|
+ typeCell.setCellStyle(headerStyle);
|
|
|
+
|
|
|
+ int dataColIndex = 1;
|
|
|
+ LandStorageInOutReportDTO.DetailDTO detail = categoryData.getDetail() != null
|
|
|
+ ? categoryData.getDetail()
|
|
|
+ : new LandStorageInOutReportDTO.DetailDTO();
|
|
|
+
|
|
|
+ List<LandStorageInOutReportDTO.ItemDTO> inItems = detail.getIn();
|
|
|
+ List<LandStorageInOutReportDTO.ItemDTO> outItems = detail.getOut();
|
|
|
+
|
|
|
+ for (String year : years) {
|
|
|
+ Cell cell = dataRow.createCell(dataColIndex++);
|
|
|
+ cell.setCellValue(getItemCount(inItems, year, 0L));
|
|
|
+ cell.setCellStyle(dataStyle);
|
|
|
+ }
|
|
|
+ for (String year : years) {
|
|
|
+ Cell cell = dataRow.createCell(dataColIndex++);
|
|
|
+ cell.setCellValue(getItemCount(outItems, year, 0L));
|
|
|
+ cell.setCellStyle(dataStyle);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Row totalRow = sheet.createRow(rowIndex++);
|
|
|
+ Cell totalLabelCell = totalRow.createCell(0);
|
|
|
+ totalLabelCell.setCellValue("合计");
|
|
|
+ totalLabelCell.setCellStyle(headerStyle);
|
|
|
+
|
|
|
+ int totalColIndex = 1;
|
|
|
+ LandStorageInOutReportDTO.DetailDTO totalDetail = (res.getSummary() != null && res.getSummary().getDetail() != null)
|
|
|
+ ? res.getSummary().getDetail()
|
|
|
+ : new LandStorageInOutReportDTO.DetailDTO();
|
|
|
+
|
|
|
+ List<LandStorageInOutReportDTO.ItemDTO> totalInItems = totalDetail.getIn();
|
|
|
+ List<LandStorageInOutReportDTO.ItemDTO> totalOutItems = totalDetail.getOut();
|
|
|
+
|
|
|
+ for (String year : years) {
|
|
|
+ Cell cell = totalRow.createCell(totalColIndex++);
|
|
|
+ cell.setCellValue(getItemCount(totalInItems, year, 0L));
|
|
|
+ cell.setCellStyle(totalStyle);
|
|
|
+ }
|
|
|
+ for (String year : years) {
|
|
|
+ Cell cell = totalRow.createCell(totalColIndex++);
|
|
|
+ cell.setCellValue(getItemCount(totalOutItems, year, 0L));
|
|
|
+ cell.setCellStyle(totalStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i <= lastColIndex; i++) {
|
|
|
+ sheet.autoSizeColumn(i);
|
|
|
+ }
|
|
|
+
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ String fileName = "出入库分析报表.xlsx";
|
|
|
+ String encodedName = URLEncoder.encode(fileName, StandardCharsets.UTF_8).replace("+", "%20");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename*=UTF-8''" + encodedName);
|
|
|
+
|
|
|
+ workbook.write(response.getOutputStream());
|
|
|
+ workbook.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static long getItemCount(List<LandStorageInOutReportDTO.ItemDTO> items, String year, long defaultValue) {
|
|
|
+ if (items == null) {
|
|
|
+ return defaultValue;
|
|
|
+ }
|
|
|
+ for (LandStorageInOutReportDTO.ItemDTO item : items) {
|
|
|
+ if (item != null && year != null && year.equals(item.getYear())) {
|
|
|
+ try {
|
|
|
+ return item.getCount() != null ? Long.parseLong(item.getCount()) : defaultValue;
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ return defaultValue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return defaultValue;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|