监测平台系统首页的报警信息导出添加自定义属性,多sheet导出

breach-zhy
马雪伟 2 months ago
parent d05e13f6c6
commit 50ddc52925

@ -1,5 +1,6 @@
package com.ruoyi.business.controller;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
@ -8,6 +9,8 @@ import com.ruoyi.business.domain.*;
import com.ruoyi.business.domain.VO.*;
import com.ruoyi.business.service.*;
import com.ruoyi.business.utils.ExcelUtils;
import com.ruoyi.business.utils.UnitExcelUtils;
import com.ruoyi.common.core.annotation.Excel;
import com.ruoyi.common.core.constant.HwDictConstants;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
@ -29,7 +32,11 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Field;
import java.sql.*;
import java.util.*;
import java.util.Date;
import java.util.stream.Collectors;
@RestController
@ -48,6 +55,7 @@ public class HwMonitorPlatformController extends BaseController {
private IHwElectronicFenceService hwElectronicFenceService;
@Autowired
private IHwAlarmInfoService hwAlarmInfoService;
@Autowired HwMonitorUnitAttributeService hwMonitorUnitAttributeService;
@Autowired
private IHwMonitorPlatformService hwMonitorPlatformService;
@ -444,6 +452,7 @@ public class HwMonitorPlatformController extends BaseController {
@GetMapping("/getDeviceByAreaId/{tenantId}")
public AjaxResult getDeviceByAreaId(@PathVariable("tenantId") Long tenantId){
List<HwMonitorUnit> deviceList = hwDeviceService.getDeviceByAreaId(tenantId);
return success(deviceList);
}
/**
@ -451,10 +460,51 @@ public class HwMonitorPlatformController extends BaseController {
* */
@PostMapping("/AlarmInfosExport")
@RequiresPermissions("business:monitor:alarm")
public void AlarmInfosExport(HttpServletResponse response,Date startTime,Date endTime) {
List<AlarmInfoExportVo> alarmInfoExportVos = hwAlarmInfoService.selectAlarmInfoExport(startTime,endTime);
ExcelUtil<AlarmInfoExportVo> util = new ExcelUtil<AlarmInfoExportVo>(AlarmInfoExportVo.class);
util.exportExcel(response,alarmInfoExportVos,"报警数据导出");
public void AlarmInfosExport(HttpServletResponse response,Date startTime,Date endTime) throws IOException, NoSuchFieldException, IllegalAccessException {
List<Long> list1 = hwAlarmInfoService.selectUnitId();
HashMap<Long, List<LinkedHashMap>> map = new HashMap<>();
for (Long unitId : list1) {
List<AlarmInfoExportVo> list2 = hwAlarmInfoService.selectAlarmInfoExport1(unitId,startTime,endTime);
List<HwMonitorUnitAttribute> attributes = hwMonitorUnitAttributeService.selectAttributes(unitId);
List<LinkedHashMap> excelMap = new ArrayList<LinkedHashMap>();
LinkedHashMap attributeMap = new LinkedHashMap();
for (HwMonitorUnitAttribute attribute : attributes) {
attributeMap.put(attribute.getAttributeName(),attribute.getAttributeValue());
}
for (AlarmInfoExportVo alarmInfo : list2) {
LinkedHashMap voMap = new LinkedHashMap<>();
Class<AlarmInfoExportVo> clazz = AlarmInfoExportVo.class;
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
Excel annotation = field.getAnnotation(Excel.class);
String name = annotation.name();
field.setAccessible(true);
if (field.getName().equals("alarmInfoId")){
Long alarmInfoId =(Long)field.get(alarmInfo);
voMap.put(name,alarmInfoId);
}else {
String value = null;
if (field.get(alarmInfo)!=null){
value = field.get(alarmInfo).toString();
}
voMap.put(name,value);
}
}
voMap.putAll(attributeMap);
excelMap.add(voMap);
}
if (CollectionUtil.isNotEmpty(excelMap)){
map.put(unitId,excelMap);
}
}
UnitExcelUtils unitExcelUtils = new UnitExcelUtils();
unitExcelUtils.exportAlarmInfos(response,map);
// List<AlarmInfoExportVo> alarmInfoExportVos = hwAlarmInfoService.selectAlarmInfoExport(startTime,endTime);
// ExcelUtil<AlarmInfoExportVo> util = new ExcelUtil<AlarmInfoExportVo>(AlarmInfoExportVo.class);
// util.exportExcel(response,alarmInfoExportVos,"报警数据导出");
}
/**
* excelexcel

@ -1,6 +1,7 @@
package com.ruoyi.business.domain.VO;
import com.ruoyi.common.core.annotation.Excel;
import lombok.Data;
import javax.validation.constraints.Email;
@ -10,6 +11,7 @@ import javax.validation.constraints.Email;
* @Author :
* @Date: 2024-06-14 09:52
*/
@Data
public class AlarmInfoExportVo {
@Excel(name = "报警id")
private Long alarmInfoId;
@ -27,13 +29,13 @@ public class AlarmInfoExportVo {
private String alarmTime;
@Excel(name = "ID")
private String monitor_unit_id;
private String monitorUnitId;
@Excel(name = "状态")
private String monitor_unit_status;
private String monitorUnitStatus;
@Excel(name = "类型")
private String monitor_unit_type_name;
private String monitorUnitTypeName;
@Excel(name = "报警区域")
private String areaName;
@ -86,29 +88,29 @@ public class AlarmInfoExportVo {
this.alarmTime = alarmTime;
}
public String getMonitor_unit_id() {
return monitor_unit_id;
}
public void setMonitor_unit_id(String monitor_unit_id) {
this.monitor_unit_id = monitor_unit_id;
}
public String getMonitor_unit_status() {
return monitor_unit_status;
}
public void setMonitor_unit_status(String monitor_unit_status) {
this.monitor_unit_status = monitor_unit_status;
}
public String getMonitor_unit_type_name() {
return monitor_unit_type_name;
}
public void setMonitor_unit_type_name(String monitor_unit_type_name) {
this.monitor_unit_type_name = monitor_unit_type_name;
}
// public String getMonitor_unit_id() {
// return monitor_unit_id;
// }
//
// public void setMonitor_unit_id(String monitor_unit_id) {
// this.monitor_unit_id = monitor_unit_id;
// }
//
// public String getMonitor_unit_status() {
// return monitor_unit_status;
// }
//
// public void setMonitor_unit_status(String monitor_unit_status) {
// this.monitor_unit_status = monitor_unit_status;
// }
//
// public String getMonitor_unit_type_name() {
// return monitor_unit_type_name;
// }
//
// public void setMonitor_unit_type_name(String monitor_unit_type_name) {
// this.monitor_unit_type_name = monitor_unit_type_name;
// }
@Override
public String toString() {

@ -1,6 +1,7 @@
package com.ruoyi.business.domain.VO;
import com.ruoyi.business.domain.HwDeviceModeFunction;
import com.ruoyi.common.core.web.domain.BaseEntity;
import lombok.Data;
import java.util.List;
@ -14,7 +15,7 @@ import java.util.Map;
* @Version :1.0
*/
@Data
public class HwDeviceVo {
public class HwDeviceVo extends BaseEntity {
private Long deviceId;

@ -1,11 +1,15 @@
package com.ruoyi.business.mapper;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.ruoyi.business.domain.HwAlarmInfo;
import com.ruoyi.business.domain.VO.AlarmInfoExportVo;
import com.ruoyi.business.domain.VO.AlarmInfoVo;
import com.ruoyi.business.domain.VO.AlarmTypeVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
@ -14,6 +18,7 @@ import org.apache.ibatis.annotations.Param;
* @author xins
* @date 2023-09-15
*/
@Mapper
public interface HwAlarmInfoMapper
{
/**
@ -88,4 +93,10 @@ public interface HwAlarmInfoMapper
*
* */
public int updateHwAlarmInfoAllByDevice(HwAlarmInfo hwAlarmInfo);
List<AlarmInfoExportVo> selectAlarmInfoExport1(@Param("monitorUnitId")Long monitorUnitId,@Param("startTime") Date startTime, @Param("endTime") Date endTime);
List<Long> selectUnitId();
}

@ -1,7 +1,10 @@
package com.ruoyi.business.service;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.ruoyi.business.domain.HwAlarmInfo;
import com.ruoyi.business.domain.VO.AlarmInfoExportVo;
import com.ruoyi.business.domain.VO.AlarmTypeVo;
@ -76,4 +79,8 @@ public interface IHwAlarmInfoService
* */
List<AlarmInfoExportVo> selectAlarmInfoExport(Date startTime, Date endTime);
List<AlarmInfoExportVo> selectAlarmInfoExport1(Long monitorUnitId,Date startTime, Date endTime);
List<Long> selectUnitId();
}

@ -1,9 +1,6 @@
package com.ruoyi.business.service.impl;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
import com.ruoyi.business.domain.HwAlarmType;
@ -156,4 +153,14 @@ public class HwAlarmInfoServiceImpl implements IHwAlarmInfoService {
public List<AlarmInfoExportVo> selectAlarmInfoExport(Date startTime, Date endTime) {
return hwAlarmInfoMapper.selectAlarmInfoExport(startTime,endTime);
}
@Override
public List<AlarmInfoExportVo> selectAlarmInfoExport1(Long monitorUnitId,Date startTime, Date endTime) {
return hwAlarmInfoMapper.selectAlarmInfoExport1(monitorUnitId,startTime,endTime);
}
@Override
public List<Long> selectUnitId() {
return hwAlarmInfoMapper.selectUnitId();
}
}

Loading…
Cancel
Save