From d2a37de5073f0311c5e85834828fb6cdc8b199eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B5=E9=A3=9E=E5=AE=87?= <2684146481@qq.com> Date: Tue, 1 Aug 2023 10:17:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E9=80=9A=E8=AE=AF=E5=91=8A?= =?UTF-8?q?=E8=AD=A6=E7=9A=84=E6=9C=80=E5=90=8E=E4=B8=80=E5=B0=8F=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E8=BF=90=E8=A1=8C=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CentralMonitorController.java | 23 +++- .../config/service/CentralMonitorService.java | 13 +++ .../service/impl/CentralMonitorServiceImpl.java | 116 +++++++++++++++------ 3 files changed, 115 insertions(+), 37 deletions(-) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java index 0989365..f9a3356 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java @@ -4,15 +4,14 @@ import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzims.operational.config.service.CentralMonitorService; import com.hnac.hzims.operational.station.service.IRealMonitorService; import com.hnac.hzims.operational.main.vo.RealStationVo; +import com.hnac.hzinfo.datasearch.PointData; +import com.hnac.hzinfo.sdk.core.response.HzPage; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; import org.springblade.core.boot.ctrl.BladeController; import org.springblade.core.tool.api.R; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -45,4 +44,20 @@ public class CentralMonitorController extends BladeController { realMonitorService.realTimeData(""); return R.success("true"); } + + + /** + * 查询通讯告警的最后一小时的运行数据 + * @param page + * @param size + * @param roleId + * @return + */ + @GetMapping("/selectCommunication/{page}/{size}") + public R selectCommunication(@PathVariable Integer page, + @PathVariable Integer size, + String roleId){ + HzPage result = monitorService.selectOriginalDataByRealIds(page, size, roleId); + return R.data(result); + } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/CentralMonitorService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/CentralMonitorService.java index 040e7c9..cceb159 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/CentralMonitorService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/CentralMonitorService.java @@ -2,6 +2,8 @@ package com.hnac.hzims.operational.config.service; import com.hnac.hzims.operational.main.vo.RealStationVo; +import com.hnac.hzinfo.datasearch.PointData; +import com.hnac.hzinfo.sdk.core.response.HzPage; import java.util.List; @@ -15,4 +17,15 @@ public interface CentralMonitorService{ * @return */ List getStationMonitor(); + + + /** + * 查询通讯告警的最后一小时的运行数据 + * @param page 当前页 + * @param size 每页记录数 + * @param roleId + * @return + */ + HzPage selectOriginalDataByRealIds(Integer page, Integer size, String roleId); + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java index 2124c9c..8d0afa6 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java @@ -5,6 +5,12 @@ import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.service.IStationService; import com.hnac.hzims.operational.main.vo.RealStationVo; +import com.hnac.hzinfo.datasearch.PointData; +import com.hnac.hzinfo.datasearch.history.IHistoryDataSearchClient; +import com.hnac.hzinfo.datasearch.history.OriginalDataQuery; +import com.hnac.hzinfo.sdk.core.response.HzPage; +import com.hnac.hzinfo.sdk.core.response.Result; +import lombok.Getter; import lombok.RequiredArgsConstructor; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.CollectionUtil; @@ -15,7 +21,13 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; +import java.text.SimpleDateFormat; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.Collections; +import java.util.Date; import java.util.List; import java.util.stream.Collectors; @@ -24,37 +36,75 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class CentralMonitorServiceImpl implements CentralMonitorService { - private final IStationService stationService; - private final ISysClient sysClient; - private final RedisTemplate redisTemplate; - - @Value("${hzims.operation.monitor.station}") - public String moniter_station_key; - - /** - * 获取站点监控数据 - * @return - */ - @Override - public List getStationMonitor() { - // 根据用户权限获取机构 - R> R = sysClient.getDeptByCurrentUser(); - if (!R.isSuccess() || CollectionUtil.isEmpty(R.getData())) { - return null; - } - List deptIdList = R.getData().stream().map(Dept::getId).collect(Collectors.toList()); - List list = stationService.getStationType(null, Collections.singletonList(HomePageConstant.HYDROPOWER),deptIdList); - if(CollectionUtil.isEmpty(list)){ - return null; - } - List codeList = list.stream().map(StationEntity::getCode).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(codeList)){ - return null; - } - List result = (List) redisTemplate.opsForValue().get(moniter_station_key); - if(StringUtil.isEmpty(result)){ - return null; - } - return result.stream().filter(o->codeList.contains(o.getStationCode())).collect(Collectors.toList()); - } + private final IStationService stationService; + private final ISysClient sysClient; + private final RedisTemplate redisTemplate; + private final IHistoryDataSearchClient historyDataSearchClient; + + @Value("${hzims.operation.monitor.station}") + public String moniter_station_key; + + /** + * 获取站点监控数据 + * + * @return + */ + @Override + public List getStationMonitor() { + // 根据用户权限获取机构 + R> R = sysClient.getDeptByCurrentUser(); + if (!R.isSuccess() || CollectionUtil.isEmpty(R.getData())) { + return null; + } + List deptIdList = R.getData().stream().map(Dept::getId).collect(Collectors.toList()); + List list = stationService.getStationType(null, Collections.singletonList(HomePageConstant.HYDROPOWER), deptIdList); + if (CollectionUtil.isEmpty(list)) { + return null; + } + List codeList = list.stream().map(StationEntity::getCode).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(codeList)) { + return null; + } + List result = (List) redisTemplate.opsForValue().get(moniter_station_key); + if (StringUtil.isEmpty(result)) { + return null; + } + return result.stream().filter(o -> codeList.contains(o.getStationCode())).collect(Collectors.toList()); + } + + /** + * 查询通讯告警的最后一小时的运行数据 + * + * @param page 当前页 + * @param size 每页记录数 + * @param roleId + * @return + */ + @Override + public HzPage selectOriginalDataByRealIds(Integer page, Integer size, String roleId) { + OriginalDataQuery originalDataQuery = new OriginalDataQuery(); + originalDataQuery.setRealId(roleId); + originalDataQuery.setLimit(size); + LocalDateTime startTime = LocalDateTime.now(); + LocalDateTime endTime = startTime.minusHours(1); + originalDataQuery.setBeginTime(this.getOriginalDate(startTime)); + originalDataQuery.setEndTime(this.getOriginalDate(endTime)); + Result> originalDataByRealIds = historyDataSearchClient.getOriginalDataByRealIds(originalDataQuery); + if (!originalDataByRealIds.isSuccess()) { + throw new IllegalArgumentException("数据不存在"); + } + return originalDataByRealIds.getData(); + } + + + /** + * LocalDateTime 转 date + * @param localDateTime + * @return + */ + public static Date getOriginalDate(LocalDateTime localDateTime) { + Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant(); + return Date.from(instant); + } + }