Browse Source

收费站统计分析table导出

develop
lau572 5 months ago
parent
commit
18b49aee1c
  1. 297
      zc-business/src/main/java/com/zc/business/controller/DcTrafficIncidentsController.java
  2. 74
      zc-business/src/main/java/com/zc/business/domain/export/SelectTollStationAnalysis.java

297
zc-business/src/main/java/com/zc/business/controller/DcTrafficIncidentsController.java

@ -6,14 +6,20 @@ import com.zc.business.domain.DcEventListQuery;
import com.zc.business.domain.export.*;
import com.zc.business.enums.UniversalEnum;
import com.zc.business.service.IDcTrafficIncidentsService;
import com.zc.common.core.httpclient.exception.HttpException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
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.*;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -255,6 +261,297 @@ public class DcTrafficIncidentsController {
return trafficIncidentsService.selectTollStationAnalysis(searchType,facilityIdList,controlType,startTime,endTime);
}
@ApiOperation(value="导出收费站统计分析table",tags = {"ECharts导出"})
@GetMapping("/exportSelectTollStationAnalysis")
public void exportSelectTollStationAnalysis(HttpServletResponse response,
@ApiParam(value="查询条件(1:站点,2:原因)", name="searchType", required=true) @RequestParam ("searchType") String searchType,
@ApiParam(value="站点id", name="facilityId", required=false) @RequestParam (name="facilityId",required = false) String[] facilityIdList,
@ApiParam(value="类型(1:封闭,2:限行)", name="controlType", required=false) @RequestParam (name="controlType",required = false) String controlType,
@ApiParam(value="开始时间", name="startTime", required=true) @RequestParam ("startTime") String startTime,
@ApiParam(value="结束时间", name="endTime", required=true) @RequestParam ("endTime") String endTime) throws IOException, HttpException {
AjaxResult ajaxResult = trafficIncidentsService.selectTollStationAnalysis(searchType,facilityIdList,controlType,startTime,endTime);
if ("1".equals(searchType)){
List<SelectTollStationAnalysis> list = new ArrayList<>();
if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) {
List<Map<String,Object>> data = (List<Map<String,Object>>) ajaxResult.get("data");
Integer closeTotal = 0;
Integer restrictionTotal = 0;
Integer total = 0;
for (Map<String, Object> datum : data) {
SelectTollStationAnalysis selectTollStationAnalysis = new SelectTollStationAnalysis();
Integer facilityClose = Integer.parseInt(datum.get("facilityClose").toString());
Integer facilityRestriction = Integer.parseInt(datum.get("facilityRestriction").toString());
Integer sum = facilityClose + facilityRestriction;
selectTollStationAnalysis.setFacilityName(datum.get("facilityName").toString());
selectTollStationAnalysis.setFacilityClose(facilityClose.toString());
selectTollStationAnalysis.setFacilityRestriction(facilityRestriction.toString());
selectTollStationAnalysis.setSum(sum.toString());
list.add(selectTollStationAnalysis);
closeTotal += facilityClose;
restrictionTotal += facilityRestriction;
total += sum;
}
SelectTollStationAnalysis selectTollStationAnalysis = new SelectTollStationAnalysis();
selectTollStationAnalysis.setFacilityName("合计");
selectTollStationAnalysis.setFacilityClose(closeTotal.toString());
selectTollStationAnalysis.setFacilityRestriction(restrictionTotal.toString());
selectTollStationAnalysis.setSum(total.toString());
list.add(selectTollStationAnalysis);
}
ExcelUtil<SelectTollStationAnalysis> util = new ExcelUtil<>(SelectTollStationAnalysis.class);
util.exportExcel(response, list, "收费站统计分析列表");
} else {
XSSFWorkbook workbook = new XSSFWorkbook(); // 创建工作簿
Sheet sheet = workbook.createSheet(UniversalEnum.THE_WHOLE_SECTION_TWO_WAY_REAL_TIME_TRAFFIC_FLOW.getValue()); // 创建工作表
// 创建数据行样式
CellStyle dataStyle = workbook.createCellStyle();
dataStyle.setAlignment(HorizontalAlignment.CENTER);
dataStyle.setVerticalAlignment(VerticalAlignment.CENTER);
dataStyle.setBorderRight(BorderStyle.THIN);
dataStyle.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
dataStyle.setBorderLeft(BorderStyle.THIN);
dataStyle.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
dataStyle.setBorderTop(BorderStyle.THIN);
dataStyle.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
dataStyle.setBorderBottom(BorderStyle.THIN);
dataStyle.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
Font dataFont = workbook.createFont();
dataFont.setFontName(UniversalEnum.ARIAL.getValue());
dataFont.setFontHeightInPoints((short) UniversalEnum.TEN.getNumber());
dataStyle.setFont(dataFont);
// 创建表头样式
CellStyle headerStyle = workbook.createCellStyle();
headerStyle.cloneStyleFrom(dataStyle);
headerStyle.setAlignment(HorizontalAlignment.CENTER);
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
headerStyle.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
headerStyle.setBorderRight(BorderStyle.THIN);
headerStyle.setRightBorderColor(IndexedColors.WHITE.getIndex());
headerStyle.setBorderLeft(BorderStyle.THIN);
headerStyle.setLeftBorderColor(IndexedColors.WHITE.getIndex());
headerStyle.setBorderTop(BorderStyle.THIN);
headerStyle.setTopBorderColor(IndexedColors.WHITE.getIndex());
headerStyle.setBorderBottom(BorderStyle.THIN);
headerStyle.setBottomBorderColor(IndexedColors.WHITE.getIndex());
Font headerFont = workbook.createFont();
headerFont.setFontName(UniversalEnum.ARIAL.getValue());
headerFont.setFontHeightInPoints((short) UniversalEnum.TEN.getNumber());
headerFont.setBold(true);
headerFont.setColor(IndexedColors.WHITE.getIndex());
headerStyle.setFont(headerFont);
// 添加第一层级表头
Row row = sheet.createRow(UniversalEnum.ZERO.getNumber());
String[] row1 = new String[]{};
if ("2".equals(controlType)){
row1 = new String[]{"限行原因","","限行站次","","","","","限行时长","","","",""};
} else {
row1 = new String[]{"封闭原因","","封闭站次","","","","","封闭时长","","","",""};
}
for (int i = 0; i < row1.length; i++) {
Cell cell = row.createCell(i);
cell.setCellValue(row1[i]);
cell.setCellStyle(headerStyle);
}
// 添加第二层级表头(与第一层级对齐)
String[] row2 = new String[]{"","","目标时段","","去年同期时段","","同比(%)","目标时段","","去年同期时段","","同比(%)"};
Row subHeaderRow1 = sheet.createRow(UniversalEnum.ONE.getNumber());
for (int i = 0; i < row2.length; i++) {
Cell cell = subHeaderRow1.createCell(i);
cell.setCellValue(row2[i]);
cell.setCellStyle(headerStyle);
}
// 添加第三层级表头
String[] row3 = new String[]{"","","站次","占比(%)","站次","占比(%)","","站次","占比(%)","站次","占比(%)",""};
Row subHeaderRow2 = sheet.createRow(UniversalEnum.TWO.getNumber());
for (int i = 0; i < row3.length; i++) {
Cell cell = subHeaderRow2.createCell(i);
cell.setCellValue(row3[i]);
cell.setCellStyle(headerStyle);
}
//合并表头单元格,参数依次为起始行,结束行,起始列,结束列 (从0开始)
sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ZERO.getNumber(), UniversalEnum.TWO.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.ONE.getNumber()));
sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ZERO.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.TWO.getNumber(), UniversalEnum.SIX.getNumber()));
sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ZERO.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.SEVEN.getNumber(), UniversalEnum.ELEVEN.getNumber()));
sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ONE.getNumber(), UniversalEnum.ONE.getNumber(), UniversalEnum.TWO.getNumber(), UniversalEnum.THREE.getNumber()));
sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ONE.getNumber(), UniversalEnum.ONE.getNumber(), UniversalEnum.FOUR.getNumber(), UniversalEnum.FIVE.getNumber()));
sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ONE.getNumber(), UniversalEnum.TWO.getNumber(), UniversalEnum.SIX.getNumber(), UniversalEnum.SIX.getNumber()));
sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ONE.getNumber(), UniversalEnum.ONE.getNumber(), UniversalEnum.SEVEN.getNumber(), UniversalEnum.EIGHT.getNumber()));
sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ONE.getNumber(), UniversalEnum.ONE.getNumber(), UniversalEnum.NINE.getNumber(), UniversalEnum.TEN.getNumber()));
sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ONE.getNumber(), UniversalEnum.TWO.getNumber(), UniversalEnum.ELEVEN.getNumber(), UniversalEnum.ELEVEN.getNumber()));
if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) {
List<Map<String, Object>> data = (List<Map<String, Object>>) ajaxResult.get("data");
//行号
int rowIndex = 3;
//先塞入恶劣天气类型数据
for (int i = 2; i < 9; i++) {
Map<String, Object> map = data.get(i);
Row subHeaderRow = sheet.createRow(rowIndex);
Cell cell = subHeaderRow.createCell(UniversalEnum.ZERO.getNumber());
cell.setCellValue(map.get("controlCauseName").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.ONE.getNumber());
cell.setCellValue(map.get("causeTypeName").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.TWO.getNumber());
cell.setCellValue(map.get("num").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.THREE.getNumber());
cell.setCellValue(map.get("numRatio").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.FOUR.getNumber());
cell.setCellValue(map.get("lastYearNum").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.FIVE.getNumber());
cell.setCellValue(map.get("lastYearNumRatio").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.SIX.getNumber());
cell.setCellValue(map.get("yearNumRatio").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.SEVEN.getNumber());
cell.setCellValue(map.get("minuteTime").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.EIGHT.getNumber());
cell.setCellValue(map.get("timeRatio").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.NINE.getNumber());
cell.setCellValue(map.get("lastYearTime").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.TEN.getNumber());
cell.setCellValue(map.get("lastYearTimeRatio").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.ELEVEN.getNumber());
cell.setCellValue(map.get("yearTimeRatio").toString());
cell.setCellStyle(dataStyle);
rowIndex++;
}
//再塞入车流量大、交通事故
for (int i = 0; i < 2; i++) {
Map<String, Object> map = data.get(i);
Row subHeaderRow = sheet.createRow(rowIndex);
Cell cell = subHeaderRow.createCell(UniversalEnum.ZERO.getNumber());
cell.setCellValue(map.get("controlCauseName").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.ONE.getNumber());
cell.setCellValue(map.get("causeTypeName").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.TWO.getNumber());
cell.setCellValue(map.get("num").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.THREE.getNumber());
cell.setCellValue(map.get("numRatio").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.FOUR.getNumber());
cell.setCellValue(map.get("lastYearNum").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.FIVE.getNumber());
cell.setCellValue(map.get("lastYearNumRatio").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.SIX.getNumber());
cell.setCellValue(map.get("yearNumRatio").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.SEVEN.getNumber());
cell.setCellValue(map.get("minuteTime").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.EIGHT.getNumber());
cell.setCellValue(map.get("timeRatio").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.NINE.getNumber());
cell.setCellValue(map.get("lastYearTime").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.TEN.getNumber());
cell.setCellValue(map.get("lastYearTimeRatio").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.ELEVEN.getNumber());
cell.setCellValue(map.get("yearTimeRatio").toString());
cell.setCellStyle(dataStyle);
rowIndex++;
}
//最后塞入施工、警备任务、其他
for (int i = 9; i < 12; i++) {
Map<String, Object> map = data.get(i);
Row subHeaderRow = sheet.createRow(rowIndex);
Cell cell = subHeaderRow.createCell(UniversalEnum.ZERO.getNumber());
cell.setCellValue(map.get("controlCauseName").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.ONE.getNumber());
cell.setCellValue(map.get("causeTypeName").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.TWO.getNumber());
cell.setCellValue(map.get("num").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.THREE.getNumber());
cell.setCellValue(map.get("numRatio").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.FOUR.getNumber());
cell.setCellValue(map.get("lastYearNum").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.FIVE.getNumber());
cell.setCellValue(map.get("lastYearNumRatio").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.SIX.getNumber());
cell.setCellValue(map.get("yearNumRatio").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.SEVEN.getNumber());
cell.setCellValue(map.get("minuteTime").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.EIGHT.getNumber());
cell.setCellValue(map.get("timeRatio").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.NINE.getNumber());
cell.setCellValue(map.get("lastYearTime").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.TEN.getNumber());
cell.setCellValue(map.get("lastYearTimeRatio").toString());
cell.setCellStyle(dataStyle);
cell = subHeaderRow.createCell(UniversalEnum.ELEVEN.getNumber());
cell.setCellValue(map.get("yearTimeRatio").toString());
cell.setCellStyle(dataStyle);
rowIndex++;
}
//合并数据单元格,参数依次为起始行,结束行,起始列,结束列 (从0开始)
sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.THREE.getNumber(), UniversalEnum.NINE.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.ZERO.getNumber()));
sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.TEN.getNumber(), UniversalEnum.TEN.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.ONE.getNumber()));
sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.ELEVEN.getNumber(), UniversalEnum.ELEVEN.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.ONE.getNumber()));
sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.TWELVE.getNumber(), UniversalEnum.TWELVE.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.ONE.getNumber()));
sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.THIRTEEN.getNumber(), UniversalEnum.THIRTEEN.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.ONE.getNumber()));
sheet.addMergedRegion(new CellRangeAddress(UniversalEnum.FOURTEEN.getNumber(), UniversalEnum.FOURTEEN.getNumber(), UniversalEnum.ZERO.getNumber(), UniversalEnum.ONE.getNumber()));
}
response.setContentType(UniversalEnum.DERIVE_THE_TWO_WAY_REAL_TIME_TRAFFIC_FLOW_OF_THE_WHOLE_SECTION.getValue());
response.setCharacterEncoding(UniversalEnum.LOWERCASE_UTF_8.getValue());
String fileName = "收费站统计分析列表.xlsx";
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
// 写入文件
try (ServletOutputStream outputStream = response.getOutputStream()){
workbook.write(outputStream);
} finally {
workbook.close();
}
}
}
/**
* @Description 路网管控-事件管控分析-收费站统计分析echarts(当月)
*

74
zc-business/src/main/java/com/zc/business/domain/export/SelectTollStationAnalysis.java

@ -0,0 +1,74 @@
package com.zc.business.domain.export;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* 导出收费站统计分析table对象
*
* @author ruoyi
* @date 2024-01-13
*/
public class SelectTollStationAnalysis extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 收费站名称 */
@Excel(name = "收费站名称")
private String facilityName;
/** 封闭 */
@Excel(name = "封闭")
private String facilityClose;
/** 限行 */
@Excel(name = "限行")
private String facilityRestriction;
/** 合计 */
@Excel(name = "合计")
private String sum;
public String getFacilityName() {
return facilityName;
}
public void setFacilityName(String facilityName) {
this.facilityName = facilityName;
}
public String getFacilityClose() {
return facilityClose;
}
public void setFacilityClose(String facilityClose) {
this.facilityClose = facilityClose;
}
public String getFacilityRestriction() {
return facilityRestriction;
}
public void setFacilityRestriction(String facilityRestriction) {
this.facilityRestriction = facilityRestriction;
}
public String getSum() {
return sum;
}
public void setSum(String sum) {
this.sum = sum;
}
@Override
public String toString() {
return new ToStringBuilder(this)
.append("facilityName", facilityName)
.append("facilityClose", facilityClose)
.append("facilityRestriction", facilityRestriction)
.append("sum", sum)
.toString();
}
}
Loading…
Cancel
Save