From 50ddc52925236912dc6329e04da8c27d24992268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E9=9B=AA=E4=BC=9F?= Date: Wed, 11 Sep 2024 11:03:56 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=91=E6=B5=8B=E5=B9=B3=E5=8F=B0=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E9=A6=96=E9=A1=B5=E7=9A=84=E6=8A=A5=E8=AD=A6=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=AF=BC=E5=87=BA=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=B1=9E=E6=80=A7=EF=BC=8C=E5=A4=9Asheet=E5=AF=BC?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HwMonitorPlatformController.java | 58 +++++++++++++++++-- .../business/domain/VO/AlarmInfoExportVo.java | 54 ++++++++--------- .../ruoyi/business/domain/VO/HwDeviceVo.java | 3 +- .../business/mapper/HwAlarmInfoMapper.java | 11 ++++ .../business/service/IHwAlarmInfoService.java | 7 +++ .../service/impl/HwAlarmInfoServiceImpl.java | 15 +++-- 6 files changed, 113 insertions(+), 35 deletions(-) diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorPlatformController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorPlatformController.java index c6883b1..9898c44 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorPlatformController.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorPlatformController.java @@ -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 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 alarmInfoExportVos = hwAlarmInfoService.selectAlarmInfoExport(startTime,endTime); - ExcelUtil util = new ExcelUtil(AlarmInfoExportVo.class); - util.exportExcel(response,alarmInfoExportVos,"报警数据导出"); + public void AlarmInfosExport(HttpServletResponse response,Date startTime,Date endTime) throws IOException, NoSuchFieldException, IllegalAccessException { + List list1 = hwAlarmInfoService.selectUnitId(); + HashMap> map = new HashMap<>(); + for (Long unitId : list1) { + List list2 = hwAlarmInfoService.selectAlarmInfoExport1(unitId,startTime,endTime); + List attributes = hwMonitorUnitAttributeService.selectAttributes(unitId); + + List excelMap = new ArrayList(); + LinkedHashMap attributeMap = new LinkedHashMap(); + for (HwMonitorUnitAttribute attribute : attributes) { + attributeMap.put(attribute.getAttributeName(),attribute.getAttributeValue()); + } + for (AlarmInfoExportVo alarmInfo : list2) { + LinkedHashMap voMap = new LinkedHashMap<>(); + Class 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 alarmInfoExportVos = hwAlarmInfoService.selectAlarmInfoExport(startTime,endTime); +// ExcelUtil util = new ExcelUtil(AlarmInfoExportVo.class); +// util.exportExcel(response,alarmInfoExportVos,"报警数据导出"); } /** * 导入excel,同一个租户重复导入时会覆盖之前的excel diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/AlarmInfoExportVo.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/AlarmInfoExportVo.java index b0f8605..701ff24 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/AlarmInfoExportVo.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/AlarmInfoExportVo.java @@ -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() { diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/HwDeviceVo.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/HwDeviceVo.java index 39f4e54..5617a57 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/HwDeviceVo.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/HwDeviceVo.java @@ -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; diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwAlarmInfoMapper.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwAlarmInfoMapper.java index e130897..190821f 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwAlarmInfoMapper.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwAlarmInfoMapper.java @@ -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 selectAlarmInfoExport1(@Param("monitorUnitId")Long monitorUnitId,@Param("startTime") Date startTime, @Param("endTime") Date endTime); + + List selectUnitId(); + + } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwAlarmInfoService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwAlarmInfoService.java index c5398c6..f33ec90 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwAlarmInfoService.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwAlarmInfoService.java @@ -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 selectAlarmInfoExport(Date startTime, Date endTime); + List selectAlarmInfoExport1(Long monitorUnitId,Date startTime, Date endTime); + + List selectUnitId(); + } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmInfoServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmInfoServiceImpl.java index 7089ffd..bb13a37 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmInfoServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmInfoServiceImpl.java @@ -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 selectAlarmInfoExport(Date startTime, Date endTime) { return hwAlarmInfoMapper.selectAlarmInfoExport(startTime,endTime); } + + @Override + public List selectAlarmInfoExport1(Long monitorUnitId,Date startTime, Date endTime) { + return hwAlarmInfoMapper.selectAlarmInfoExport1(monitorUnitId,startTime,endTime); + } + + @Override + public List selectUnitId() { + return hwAlarmInfoMapper.selectUnitId(); + } }