|
@@ -4,11 +4,15 @@ 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.AlarmStatisticDto;
|
|
|
+import com.ozs.service.entity.vo.AlarmStatisticMonthDto;
|
|
|
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 com.ozs.system.mapper.SysDictDataMapper;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.poi.hssf.usermodel.*;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -33,6 +37,8 @@ import java.util.*;
|
|
|
public class MsgAlarmServiceImpl extends ServiceImpl<MsgAlarmMapper, MsgAlarm> implements MsgAlarmService {
|
|
|
@Autowired
|
|
|
MsgAlarmMapper msgAlarmMapper;
|
|
|
+ @Autowired
|
|
|
+ SysDictDataMapper sysDictDataMapper;
|
|
|
|
|
|
public static IPage listToPage(List list, int pageNum, int pageSize) {
|
|
|
List pageList = new ArrayList<>();
|
|
@@ -61,171 +67,31 @@ public class MsgAlarmServiceImpl extends ServiceImpl<MsgAlarmMapper, MsgAlarm> i
|
|
|
}
|
|
|
|
|
|
@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(),
|
|
|
+ public List<AlarmStatisticDto> exportExcel(AlarmStatisticResVo alarmStatisticResVo, String userId) {
|
|
|
+ List<AlarmStatisticDto> listDto = msgAlarmMapper.listDto(alarmStatisticResVo.getRailwayCode(), alarmStatisticResVo.getStartMonth(),
|
|
|
alarmStatisticResVo.getEndMonth(), alarmStatisticResVo.getAlarmType(), userId);
|
|
|
- //将数据写入表格
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
- row = sheet.createRow(i + 1);
|
|
|
- AlarmStatisticVo vo = list.get(i);
|
|
|
- // 第四步,创建单元格,并设置值
|
|
|
- if (StringUtils.isNotEmpty(vo.getBaseCameraManagement().getRailwayCode())) {
|
|
|
- row.createCell(0).setCellValue(vo.getBaseCameraManagement().getRailwayCode());
|
|
|
- }
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- if (vo.getAlarmTime() != null) {
|
|
|
- String dateStr = sdf.format(vo.getAlarmTime());
|
|
|
- row.createCell(1).setCellValue(dateStr);
|
|
|
- }
|
|
|
- if (vo.getLineDir() != null) {
|
|
|
- row.createCell(2).setCellValue(vo.getLineDir());
|
|
|
- }
|
|
|
- if (vo.getAlarmType() != null) {
|
|
|
- row.createCell(3).setCellValue(vo.getAlarmType());
|
|
|
- }
|
|
|
- if (vo.getBaseCameraManagement().getInstallMile() != null) {
|
|
|
- row.createCell(4).setCellValue(vo.getBaseCameraManagement().getInstallMile());
|
|
|
- }
|
|
|
- if (vo.getBaseCameraManagement().getBeginMile() != null) {
|
|
|
- row.createCell(5).setCellValue(vo.getBaseCameraManagement().getBeginMile());
|
|
|
- }
|
|
|
- if (vo.getBaseCameraManagement().getEndMile() != null) {
|
|
|
- row.createCell(6).setCellValue(vo.getBaseCameraManagement().getEndMile());
|
|
|
- }
|
|
|
- }
|
|
|
- //第六步,输出Excel文件
|
|
|
- OutputStream output = response.getOutputStream();
|
|
|
- response.reset();
|
|
|
- response.setContentType("application/vnd.ms-excel");
|
|
|
+ listDto.forEach(l -> {
|
|
|
+ String alarmType = l.getAlarmType();
|
|
|
+ String alarmTypeValue = sysDictDataMapper.selectDictLabel("sys_alarm_type", alarmType);
|
|
|
+ l.setAlarmTypeValue(alarmTypeValue);
|
|
|
|
|
|
- //设置文件头:最后一个参数是设置下载文件名
|
|
|
- long filename = System.currentTimeMillis();
|
|
|
- SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
|
|
|
- String fileName = "报警数据详情";
|
|
|
- response.addHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
|
|
|
- wb.write(output);
|
|
|
- output.close();
|
|
|
+ String lineDir = l.getLineDir();
|
|
|
+ String lineDirValue = sysDictDataMapper.selectDictLabel("sys_line_dir", lineDir);
|
|
|
+ l.setLineDirValue(lineDirValue);
|
|
|
+ });
|
|
|
+ return listDto;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void exportExcelMonth(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);
|
|
|
-
|
|
|
- //调取数据
|
|
|
- List<AlarmStatisticVo> list = msgAlarmMapper.listMonth(alarmStatisticResVo.getRailwayCode(), alarmStatisticResVo.getStartMonth(),
|
|
|
+ public List<AlarmStatisticMonthDto> exportExcelMonth(AlarmStatisticResVo alarmStatisticResVo, String userId) throws Exception {
|
|
|
+ List<AlarmStatisticMonthDto> listDto = msgAlarmMapper.listDtoMonth(alarmStatisticResVo.getRailwayCode(), alarmStatisticResVo.getStartMonth(),
|
|
|
alarmStatisticResVo.getEndMonth(), alarmStatisticResVo.getAlarmType(), userId);
|
|
|
- //将数据写入表格
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
- row = sheet.createRow(i + 1);
|
|
|
- AlarmStatisticVo vo = list.get(i);
|
|
|
- // 第四步,创建单元格,并设置值
|
|
|
- if (StringUtils.isNotEmpty(vo.getBaseCameraManagement().getRailwayCode())) {
|
|
|
- row.createCell(0).setCellValue(vo.getBaseCameraManagement().getRailwayCode());
|
|
|
- }
|
|
|
- if (vo.getAlarmType() != null) {
|
|
|
- row.createCell(1).setCellValue(vo.getAlarmType());
|
|
|
- }
|
|
|
- if (vo.getMonthsta() != null) {
|
|
|
- row.createCell(2).setCellValue(vo.getMonthsta());
|
|
|
- }
|
|
|
- if (vo.getFrequency() != null) {
|
|
|
- row.createCell(3).setCellValue(vo.getFrequency());
|
|
|
- }
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- if (vo.getAlarmTime() != null) {
|
|
|
- String dateStr = sdf.format(vo.getAlarmTime());
|
|
|
- row.createCell(4).setCellValue(dateStr);
|
|
|
- }
|
|
|
- }
|
|
|
- //第六步,输出Excel文件
|
|
|
- OutputStream output = response.getOutputStream();
|
|
|
- response.reset();
|
|
|
- response.setContentType("application/vnd.ms-excel");
|
|
|
- //设置文件头:最后一个参数是设置下载文件名
|
|
|
- long filename = System.currentTimeMillis();
|
|
|
- SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
|
|
|
- String fileName = "报警月统计数据";
|
|
|
- response.addHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
|
|
|
- wb.write(output);
|
|
|
- output.close();
|
|
|
+ listDto.forEach(l -> {
|
|
|
+ String alarmType = l.getAlarmType();
|
|
|
+ String alarmTypeValue = sysDictDataMapper.selectDictLabel("sys_alarm_type", alarmType);
|
|
|
+ l.setAlarmTypeValue(alarmTypeValue);
|
|
|
+ });
|
|
|
+ return listDto;
|
|
|
}
|
|
|
+
|
|
|
}
|