|
@@ -2,11 +2,8 @@ package com.persagy.apm.alarmservice.group.alarmrecord.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.persagy.apm.alarmservice.group.alarmrecord.enums.*;
|
|
|
import com.persagy.apm.alarmservice.project.alarmcondition.model.vo.AlarmConditionStrItem;
|
|
|
-import com.persagy.apm.alarmservice.group.alarmrecord.enums.EnumAlarmLevel;
|
|
|
-import com.persagy.apm.alarmservice.group.alarmrecord.enums.EnumAlarmState;
|
|
|
-import com.persagy.apm.alarmservice.group.alarmrecord.enums.EnumAlarmTreatMode;
|
|
|
-import com.persagy.apm.alarmservice.group.alarmrecord.enums.EnumAlarmTreatState;
|
|
|
import com.persagy.apm.alarmservice.group.alarmrecord.model.vo.AlarmRecordItemVO;
|
|
|
import com.persagy.apm.alarmservice.group.alarmrecord.model.vo.AlarmRecordListItem;
|
|
|
import com.persagy.apm.alarmservice.group.management.model.equip.vo.EquipItem;
|
|
@@ -21,11 +18,19 @@ import com.persagy.apm.energyalarmstarter.alarmdata.service.AlarmItemServiceImpl
|
|
|
import com.persagy.apm.energyalarmstarter.alarmdata.service.AlarmRecordServiceImpl;
|
|
|
import com.persagy.apm.energyalarmstarter.alarmdata.utils.DateUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.assertj.core.util.Lists;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
@@ -348,4 +353,178 @@ public class AlarmRecordWrapper {
|
|
|
return alarmRecordService.queryCount(queryAlarmRecordDTO);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查看报警记录详情
|
|
|
+ *
|
|
|
+ * @param recordIdList 报警记录id列表
|
|
|
+ * @return 报警记录详情列表
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/9/21 3:54 下午
|
|
|
+ */
|
|
|
+ public List<AlarmRecordItem> getAlarmRecordList(List<String> recordIdList) throws Exception {
|
|
|
+ if (CollectionUtils.isEmpty(recordIdList) || recordIdList.size() == 0){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ QueryAlarmRecordDTO queryAlarmRecordDTO = new QueryAlarmRecordDTO();
|
|
|
+ queryAlarmRecordDTO.setId(recordIdList);
|
|
|
+ DmpResult<List<AlarmRecordItem>> result = alarmRecordService.query(queryAlarmRecordDTO);
|
|
|
+ if (result == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return result.getData();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造EXCEl文件
|
|
|
+ * @param enumAlarmListType 报警列表类型
|
|
|
+ * @param alarmRecordItemVOList 数据列表
|
|
|
+ */
|
|
|
+ public void initExcel(EnumAlarmListType enumAlarmListType, List<AlarmRecordItemVO> alarmRecordItemVOList){
|
|
|
+ try {
|
|
|
+ //创建Workbook
|
|
|
+ XSSFWorkbook wb = new XSSFWorkbook();
|
|
|
+ XSSFSheet overViewSheet = wb.createSheet();
|
|
|
+ wb.setSheetName(0,enumAlarmListType.getDesc());//设置sheet页标题
|
|
|
+ handleExcelTitle(enumAlarmListType,overViewSheet,wb);// 处理表头
|
|
|
+ //能耗概览Sheet数据填充
|
|
|
+ fillDataTable(enumAlarmListType,overViewSheet,alarmRecordItemVOList);
|
|
|
+ //本地自测
|
|
|
+ String time = DateUtils.date2Str(new Date(),DateUtils.SDFSECOND);
|
|
|
+ String excelName =enumAlarmListType.getDesc()+"-"+time+".xlsx";
|
|
|
+
|
|
|
+// 本地测试
|
|
|
+// FileOutputStream out = new FileOutputStream("D:\\exl\\"+excelName);
|
|
|
+// wb.write(out);
|
|
|
+// out.flush();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 填充 excel文件数据行
|
|
|
+ * @param enumAlarmListType 报警列表类型
|
|
|
+ * @param sheet 文件sheet
|
|
|
+ * @param alarmRecordItemVOList 数据列表
|
|
|
+ */
|
|
|
+ public void fillDataTable(EnumAlarmListType enumAlarmListType,XSSFSheet sheet,List<AlarmRecordItemVO> alarmRecordItemVOList) {
|
|
|
+ try {
|
|
|
+ for (int i = 0; i < alarmRecordItemVOList.size(); i++) {
|
|
|
+ AlarmRecordItemVO alarmRecordItemVO = alarmRecordItemVOList.get(i);
|
|
|
+ XSSFRow row = sheet.createRow(i+1);
|
|
|
+ String groupName = "";//分组名称
|
|
|
+ if (null != alarmRecordItemVO.getGroup() && null != alarmRecordItemVO.getGroup().getName()){
|
|
|
+ groupName = alarmRecordItemVO.getGroup().getName();
|
|
|
+ }
|
|
|
+ Cell cell = row.createCell(0);cell.setCellValue(groupName);
|
|
|
+ String objName = "";//对象名称
|
|
|
+ if (null != alarmRecordItemVO.getObj() && null != alarmRecordItemVO.getObj().getName()){
|
|
|
+ objName = alarmRecordItemVO.getObj().getName();
|
|
|
+ }
|
|
|
+ cell = row.createCell(1);cell.setCellValue(objName);
|
|
|
+ String itemName = "";//报警类型
|
|
|
+ if (null != alarmRecordItemVO.getAlarmItem() && null != alarmRecordItemVO.getAlarmItem().getName()){
|
|
|
+ itemName = alarmRecordItemVO.getAlarmItem().getName();
|
|
|
+ }
|
|
|
+ cell = row.createCell(2);cell.setCellValue(itemName);
|
|
|
+ String levelName = "";//报警级别
|
|
|
+ if (null != alarmRecordItemVO.getAlarmLevel() && null != alarmRecordItemVO.getAlarmLevel().getName()){
|
|
|
+ levelName = alarmRecordItemVO.getAlarmLevel().getName();
|
|
|
+ }
|
|
|
+ String stateName = "";//报警状态
|
|
|
+ if (null != alarmRecordItemVO.getAlarmState() && null != alarmRecordItemVO.getAlarmState().getName()){
|
|
|
+ stateName = alarmRecordItemVO.getAlarmState().getName();
|
|
|
+ }
|
|
|
+ String treatStateName = "";//报警处理状态
|
|
|
+ if (null != alarmRecordItemVO.getAlarmTreatState() && null != alarmRecordItemVO.getAlarmTreatState().getName()){
|
|
|
+ treatStateName = alarmRecordItemVO.getAlarmTreatState().getName();
|
|
|
+ }
|
|
|
+ String triggerTime = "";
|
|
|
+ if (null != alarmRecordItemVO.getTriggerTime()){
|
|
|
+ triggerTime = DateUtils.date2Str(alarmRecordItemVO.getTriggerTime(),DateUtils.SDF_SECOND);
|
|
|
+ }
|
|
|
+ String treatEndTime = "";
|
|
|
+ if (null != alarmRecordItemVO.getTreatEndTime()){
|
|
|
+ treatEndTime = DateUtils.date2Str(alarmRecordItemVO.getTreatEndTime(),DateUtils.SDF_SECOND);
|
|
|
+ }
|
|
|
+ String ignoreTime = "";
|
|
|
+ if (null != alarmRecordItemVO.getIgnoreTime()){
|
|
|
+ ignoreTime = DateUtils.date2Str(alarmRecordItemVO.getIgnoreTime(),DateUtils.SDF_SECOND);
|
|
|
+ }
|
|
|
+ String duration = "";
|
|
|
+ if (null != alarmRecordItemVO.getDuration()){
|
|
|
+ duration = alarmRecordItemVO.getDuration();
|
|
|
+ }
|
|
|
+ cell = row.createCell(3);cell.setCellValue(triggerTime);
|
|
|
+ if (EnumAlarmListType.CURRENT.getType().equals(enumAlarmListType.getType())){
|
|
|
+ cell = row.createCell(4);cell.setCellValue(duration);
|
|
|
+ cell = row.createCell(5);cell.setCellValue(levelName);
|
|
|
+ cell = row.createCell(6);cell.setCellValue(stateName);
|
|
|
+ cell = row.createCell(7);cell.setCellValue(treatStateName);
|
|
|
+ }else if (EnumAlarmListType.HISTORY.getType().equals(enumAlarmListType.getType())){
|
|
|
+ cell = row.createCell(4);cell.setCellValue(treatEndTime);
|
|
|
+ cell = row.createCell(5);cell.setCellValue(duration);
|
|
|
+ cell = row.createCell(6);cell.setCellValue(levelName);
|
|
|
+ cell = row.createCell(7);cell.setCellValue(stateName);
|
|
|
+ cell = row.createCell(8);cell.setCellValue(treatStateName);
|
|
|
+ }else if (EnumAlarmListType.IGNORE.getType().equals(enumAlarmListType.getType())){
|
|
|
+ cell = row.createCell(4);cell.setCellValue(ignoreTime);
|
|
|
+ cell = row.createCell(5);cell.setCellValue(duration);
|
|
|
+ cell = row.createCell(6);cell.setCellValue(levelName);
|
|
|
+ cell = row.createCell(7);cell.setCellValue(stateName);
|
|
|
+ cell = row.createCell(8);cell.setCellValue(treatStateName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理文件标题行
|
|
|
+ * @param enumAlarmListType 报警列表类型
|
|
|
+ * @param sheet 文件sheet
|
|
|
+ * @param wb 文件wb
|
|
|
+ */
|
|
|
+ public void handleExcelTitle(EnumAlarmListType enumAlarmListType,XSSFSheet sheet, XSSFWorkbook wb){
|
|
|
+ XSSFCellStyle cellStyle = wb.createCellStyle();
|
|
|
+ cellStyle.setWrapText(true);
|
|
|
+ //设置行宽
|
|
|
+ sheet.setColumnWidth(0, 5000);sheet.setColumnWidth(1, 5000);
|
|
|
+ sheet.setColumnWidth(2, 7000);sheet.setColumnWidth(3, 5000);
|
|
|
+ //行
|
|
|
+ XSSFRow Row1 = sheet.createRow(0);
|
|
|
+ Cell cell = Row1.createCell(0);cell.setCellStyle(cellStyle);cell.setCellValue("分组名称");
|
|
|
+ cell = Row1.createCell(1);cell.setCellStyle(cellStyle);cell.setCellValue("报警对象");
|
|
|
+ cell = Row1.createCell(2);cell.setCellStyle(cellStyle);cell.setCellValue("报警类型");
|
|
|
+ cell = Row1.createCell(3);cell.setCellStyle(cellStyle);cell.setCellValue("报警开始时间");
|
|
|
+ if (EnumAlarmListType.CURRENT.getType().equals(enumAlarmListType.getType())){
|
|
|
+ sheet.setColumnWidth(4, 3500);sheet.setColumnWidth(5, 3000);
|
|
|
+ sheet.setColumnWidth(6, 3000);sheet.setColumnWidth(7, 5000);
|
|
|
+ cell = Row1.createCell(4);cell.setCellStyle(cellStyle);cell.setCellValue("报警持续时长(h)");
|
|
|
+ cell = Row1.createCell(5);cell.setCellStyle(cellStyle);cell.setCellValue("报警等级");
|
|
|
+ cell = Row1.createCell(6);cell.setCellStyle(cellStyle);cell.setCellValue("报警状态");
|
|
|
+ cell = Row1.createCell(7);cell.setCellStyle(cellStyle);cell.setCellValue("报警处理状态");
|
|
|
+ }else if (EnumAlarmListType.HISTORY.getType().equals(enumAlarmListType.getType())){
|
|
|
+ sheet.setColumnWidth(4, 5000);sheet.setColumnWidth(5, 3500);
|
|
|
+ sheet.setColumnWidth(6, 3000);sheet.setColumnWidth(7, 3000);
|
|
|
+ sheet.setColumnWidth(8, 5000);
|
|
|
+ cell = Row1.createCell(4);cell.setCellStyle(cellStyle);cell.setCellValue("处理完成时间");
|
|
|
+ cell = Row1.createCell(5);cell.setCellStyle(cellStyle);cell.setCellValue("异常持续时长(h)");
|
|
|
+ cell = Row1.createCell(6);cell.setCellStyle(cellStyle);cell.setCellValue("报警等级");
|
|
|
+ cell = Row1.createCell(7);cell.setCellStyle(cellStyle);cell.setCellValue("报警状态");
|
|
|
+ cell = Row1.createCell(8);cell.setCellStyle(cellStyle);cell.setCellValue("报警处理状态");
|
|
|
+ }else if (EnumAlarmListType.IGNORE.getType().equals(enumAlarmListType.getType())){
|
|
|
+ sheet.setColumnWidth(4, 5000);sheet.setColumnWidth(5, 3500);
|
|
|
+ sheet.setColumnWidth(6, 3000);sheet.setColumnWidth(7, 3000);
|
|
|
+ sheet.setColumnWidth(8, 5000);
|
|
|
+ cell = Row1.createCell(4);cell.setCellStyle(cellStyle);cell.setCellValue("忽略时间");
|
|
|
+ cell = Row1.createCell(5);cell.setCellStyle(cellStyle);cell.setCellValue("异常持续时长(h)");
|
|
|
+ cell = Row1.createCell(6);cell.setCellStyle(cellStyle);cell.setCellValue("报警等级");
|
|
|
+ cell = Row1.createCell(7);cell.setCellStyle(cellStyle);cell.setCellValue("报警状态");
|
|
|
+ cell = Row1.createCell(8);cell.setCellStyle(cellStyle);cell.setCellValue("报警处理状态");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|