|
@@ -2,19 +2,24 @@ package com.ozs.service.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.ozs.common.utils.StringUtils;
|
|
|
import com.ozs.service.entity.MsgAlarm;
|
|
|
+import com.ozs.service.entity.vo.AlarmStatisticResVo;
|
|
|
import com.ozs.service.entity.vo.AlarmStatisticVo;
|
|
|
import com.ozs.service.mapper.MsgAlarmMapper;
|
|
|
import com.ozs.service.service.MsgAlarmService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.apache.poi.hssf.usermodel.*;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -54,4 +59,92 @@ public class MsgAlarmServiceImpl extends ServiceImpl<MsgAlarmMapper, MsgAlarm> i
|
|
|
List<AlarmStatisticVo> list = msgAlarmMapper.listMonth(railwayCode, startMonth, endMonth, alarmType, userId);
|
|
|
return list;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void exportExcel(HttpServletResponse response, AlarmStatisticResVo alarmStatisticResVo, String userId) throws Exception {
|
|
|
+ // 第一步,创建一个webbook,对应一个Excel文件
|
|
|
+ HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
+ // 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet
|
|
|
+ HSSFSheet sheet = wb.createSheet("报警数据详情");
|
|
|
+ // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
|
|
|
+ HSSFRow row = sheet.createRow(0);
|
|
|
+ // 第四步,创建单元格,并设置值表头 设置表头居中
|
|
|
+ HSSFCellStyle style = wb.createCellStyle();
|
|
|
+ //单元格边框
|
|
|
+ //style.setAlignment(BorderStyle.THIN); // 创建一个居中格式
|
|
|
+ style.setBorderBottom(BorderStyle.THIN); //下边框
|
|
|
+ style.setBorderLeft(BorderStyle.THIN);//左边框
|
|
|
+ style.setBorderTop(BorderStyle.THIN);//上边框
|
|
|
+ style.setBorderRight(BorderStyle.THIN);//右边框
|
|
|
+ //设置单元格字体大小
|
|
|
+ HSSFFont font = wb.createFont();
|
|
|
+ font.setFontName("宋体");
|
|
|
+ font.setFontHeightInPoints((short) 11);//设置字体大小
|
|
|
+ //font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
|
|
|
+ style.setFont(font);//选择需要用到的字体格式
|
|
|
+
|
|
|
+ HSSFCell cell = row.createCell(0);
|
|
|
+ cell.setCellValue("线路");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+ cell = row.createCell(1);
|
|
|
+ cell.setCellValue("时间");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+ cell = row.createCell(2);
|
|
|
+ cell.setCellValue("行别");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+ cell = row.createCell(3);
|
|
|
+ cell.setCellValue("报警类型");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+ cell = row.createCell(4);
|
|
|
+ cell.setCellValue("里程位置");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+ cell = row.createCell(5);
|
|
|
+ cell.setCellValue("里程起始范围km");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+ cell = row.createCell(6);
|
|
|
+ cell.setCellValue("里程结束范围km");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ //调取数据
|
|
|
+ List<AlarmStatisticVo> list = msgAlarmMapper.list(alarmStatisticResVo.getRailwayCode(), alarmStatisticResVo.getStartMonth(),
|
|
|
+ alarmStatisticResVo.getEndMonth(), alarmStatisticResVo.getAlarmType(), userId);
|
|
|
+ //将数据写入表格
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ HSSFCell cel = row.createCell(i + 1);
|
|
|
+ AlarmStatisticVo vo = list.get(i);
|
|
|
+ // 第四步,创建单元格,并设置值
|
|
|
+ if (StringUtils.isNotEmpty(vo.getBaseCameraManagement().getRailwayCode())) {
|
|
|
+ cel.setCellValue(vo.getBaseCameraManagement().getRailwayCode());
|
|
|
+ }
|
|
|
+ if (vo.getAlarmTime() != null) {
|
|
|
+ cel.setCellValue(vo.getAlarmTime());
|
|
|
+ }
|
|
|
+ if (vo.getLineDir() != null) {
|
|
|
+ cel.setCellValue(vo.getLineDir());
|
|
|
+ }
|
|
|
+ if (vo.getAlarmType() != null) {
|
|
|
+ cel.setCellValue(vo.getAlarmType());
|
|
|
+ }
|
|
|
+ if (vo.getBaseCameraManagement().getInstallMile() != null) {
|
|
|
+ cel.setCellValue(vo.getBaseCameraManagement().getInstallMile());
|
|
|
+ }
|
|
|
+ if (vo.getBaseCameraManagement().getBeginMile() != null) {
|
|
|
+ cel.setCellValue(vo.getBaseCameraManagement().getBeginMile());
|
|
|
+ }
|
|
|
+ if (vo.getBaseCameraManagement().getEndMile() != null) {
|
|
|
+ cel.setCellValue(vo.getBaseCameraManagement().getEndMile());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //第六步,输出Excel文件
|
|
|
+ OutputStream output = response.getOutputStream();
|
|
|
+ response.reset();
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+ //设置文件头:最后一个参数是设置下载文件名
|
|
|
+ long filename = System.currentTimeMillis();
|
|
|
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
|
|
|
+ String fileName = "报警数据详情";
|
|
|
+ response.setHeader("Content-disposition", "attachment; filename=" + fileName + ".xlsx");
|
|
|
+ wb.write(output);
|
|
|
+ output.close();
|
|
|
+ }
|
|
|
}
|