Browse Source

增加下载整个报警记录列表接口

lixing 3 years ago
parent
commit
20da3b033e

+ 57 - 5
src/main/java/com/persagy/apm/alarmservice/group/alarmrecord/controller/AlarmRecordController.java

@@ -283,6 +283,40 @@ public class AlarmRecordController {
         return ResultHelper.single(alarmRecordItemVO);
     }
 
+    @ApiOperation(value = "下载全部记录")
+    @PostMapping("/download_all")
+    public void downloadAllAlarmRecord(
+            @Valid @RequestBody DownloadAllAlarmRecordDTO downloadAllAlarmRecordDTO,
+            HttpServletResponse response, HttpServletRequest request) throws Exception {
+        String listType = downloadAllAlarmRecordDTO.getListType();
+        PageQueryAlarmRecordDTO pageQueryAlarmRecordDTO = ConvertAlarmRecordTool.INSTANCE.convert2PageQueryAlarmRecordDTO(downloadAllAlarmRecordDTO);
+        // 去掉分页条件
+        pageQueryAlarmRecordDTO.setSize(Integer.MAX_VALUE);
+        CommonResult<PageList<AlarmRecordListItem>> result = null;
+        if (listType.equals(EnumAlarmListType.CURRENT.getType())) {
+            result = queryCurrentAlarmRecord(pageQueryAlarmRecordDTO);
+        }
+        if (listType.equals(EnumAlarmListType.HISTORY.getType())) {
+            result = queryHistoryAlarmRecord(pageQueryAlarmRecordDTO);
+        }
+        if (listType.equals(EnumAlarmListType.IGNORE.getType())) {
+            result = queryIgnoredAlarmRecord(pageQueryAlarmRecordDTO);
+        }
+
+        List<AlarmRecordListItem> alarmRecordItemList = new ArrayList<>();
+        if (result != null) {
+            alarmRecordItemList = result.getContent().getRecords();
+        }
+
+        List<AlarmRecordItemVO> alarmRecordItemVOList = ConvertAlarmRecordTool.INSTANCE.
+                convert2AlarmRecordItemVOList(alarmRecordItemList);
+        EnumAlarmListType enumAlarmListType = EnumAlarmListType.getByType(listType);
+        if (enumAlarmListType == null) {
+            throw new IllegalArgumentException("列表类型传值错误");
+        }
+        downloadRecordList(response, enumAlarmListType, alarmRecordItemVOList);
+    }
+
     @ApiOperation(value = "下载")
     @PostMapping("/download")
     public void downloadAlarmRecord(
@@ -298,7 +332,27 @@ public class AlarmRecordController {
         }
         // 获取报警详情列表
         List<AlarmRecordItem> alarmRecordItemList = alarmRecordWrapper.getAlarmRecordList(recordIdList);
+        List<AlarmRecordItemVO> alarmRecordItemVOList = new ArrayList<>();
+        if (!CollectionUtils.isEmpty(alarmRecordItemList)) {
+            for (AlarmRecordItem alarmRecord : alarmRecordItemList) {
+                alarmRecordItemVOList.add(alarmRecordWrapper.convert2AlarmRecordItemVO(alarmRecord));
+            }
+        }
+        downloadRecordList(response, enumAlarmListType, alarmRecordItemVOList);
+    }
 
+    /**
+     * 下载报警记录列表
+     *
+     * @param response            response对象
+     * @param enumAlarmListType   列表类型
+     * @param alarmRecordItemList 要下载的列表
+     * @author lixing
+     * @version V1.0 2021/10/19 7:22 下午
+     */
+    private void downloadRecordList(
+            HttpServletResponse response, EnumAlarmListType enumAlarmListType,
+            List<AlarmRecordItemVO> alarmRecordItemVOList) throws Exception {
         // 创建Workbook
         XSSFWorkbook wb = new XSSFWorkbook();
         XSSFSheet overViewSheet = wb.createSheet();
@@ -307,11 +361,7 @@ public class AlarmRecordController {
         // 处理表头
         alarmRecordWrapper.handleExcelTitle(enumAlarmListType, overViewSheet, wb);
 
-        if (!CollectionUtils.isEmpty(alarmRecordItemList) && alarmRecordItemList.size() > 0) {
-            List<AlarmRecordItemVO> alarmRecordItemVOList = new ArrayList<>();
-            for (AlarmRecordItem alarmRecord : alarmRecordItemList) {
-                alarmRecordItemVOList.add(alarmRecordWrapper.convert2AlarmRecordItemVO(alarmRecord));
-            }
+        if (!CollectionUtils.isEmpty(alarmRecordItemVOList)) {
             // 能耗概览Sheet数据填充
             alarmRecordWrapper.fillDataTable(enumAlarmListType, overViewSheet, alarmRecordItemVOList);
         }
@@ -334,5 +384,7 @@ public class AlarmRecordController {
             e.printStackTrace();
         }
     }
+
+
 }
 

+ 9 - 0
src/main/java/com/persagy/apm/alarmservice/group/alarmrecord/model/ConvertAlarmRecordTool.java

@@ -1,6 +1,9 @@
 package com.persagy.apm.alarmservice.group.alarmrecord.model;
 
+import com.persagy.apm.alarmservice.group.alarmrecord.model.dto.DownloadAllAlarmRecordDTO;
 import com.persagy.apm.alarmservice.group.alarmrecord.model.dto.PageQueryAlarmRecordDTO;
+import com.persagy.apm.alarmservice.group.alarmrecord.model.vo.AlarmRecordItemVO;
+import com.persagy.apm.alarmservice.group.alarmrecord.model.vo.AlarmRecordListItem;
 import com.persagy.apm.common.model.dto.Sort;
 import com.persagy.apm.energyalarmstarter.alarmdata.model.dto.alarmrecord.QueryAlarmRecordDTO;
 import com.persagy.apm.energyalarmstarter.alarmdata.model.dto.common.OrderDTO;
@@ -33,4 +36,10 @@ public interface ConvertAlarmRecordTool {
     OrderDTO convert2OrderDTO(Sort sort);
 
     List<OrderDTO> convert2OrderDTOList(List<Sort> sortList);
+
+    PageQueryAlarmRecordDTO convert2PageQueryAlarmRecordDTO(DownloadAllAlarmRecordDTO downloadAllAlarmRecordDTO);
+
+    AlarmRecordItemVO convert2AlarmRecordItemVO(AlarmRecordListItem alarmRecordListItem);
+
+    List<AlarmRecordItemVO> convert2AlarmRecordItemVOList(List<AlarmRecordListItem> alarmRecordListItemList);
 }

+ 44 - 0
src/main/java/com/persagy/apm/alarmservice/group/alarmrecord/model/dto/DownloadAllAlarmRecordDTO.java

@@ -0,0 +1,44 @@
+package com.persagy.apm.alarmservice.group.alarmrecord.model.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 下载列表中所有报警记录DTO
+ *
+ * @author lixing
+ * @version V1.0 2021/9/11 2:31 下午
+ **/
+@Data
+@ApiModel
+public class DownloadAllAlarmRecordDTO {
+    @ApiModelProperty(value = "列表类型", required = true,
+            notes = "com.persagy.apm.alarmservice.group.alarmrecord.enums.EnumAlarmListType")
+    private String listType;
+    @ApiModelProperty(value = "报警开始时间")
+    private Date triggerStartTime;
+    @ApiModelProperty(value = "报警结束时间")
+    private Date triggerEndTime;
+    @ApiModelProperty(value = "分组id")
+    private List<String> groupId;
+    @ApiModelProperty(value = "报警类型编码")
+    private List<String> alarmItemCode;
+    @ApiModelProperty(value = "报警状态")
+    private List<String> alarmState;
+    @ApiModelProperty(value = "报警对象名称(模糊查询)")
+    private String objName;
+    @ApiModelProperty(value = "报警等级")
+    private List<String> alarmLevel;
+    @ApiModelProperty(value = "报警处理状态")
+    private List<String> alarmTreatState;
+    @ApiModelProperty(value = "报警处理方式")
+    private List<String> alarmTreatMode;
+    @ApiModelProperty(value = "报警系统")
+    private List<String> category;
+    @ApiModelProperty(value = "项目id")
+    private List<String> projectIds;
+}