Browse Source

查询通讯告警的最后一小时的运行数据

zhongwei
段飞宇 1 year ago
parent
commit
d2a37de507
  1. 23
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java
  2. 13
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/CentralMonitorService.java
  3. 116
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java

23
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<PointData> result = monitorService.selectOriginalDataByRealIds(page, size, roleId);
return R.data(result);
}
}

13
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<RealStationVo> getStationMonitor();
/**
* 查询通讯告警的最后一小时的运行数据
* @param page 当前页
* @param size 每页记录数
* @param roleId
* @return
*/
HzPage<PointData> selectOriginalDataByRealIds(Integer page, Integer size, String roleId);
}

116
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<RealStationVo> getStationMonitor() {
// 根据用户权限获取机构
R<List<Dept>> R = sysClient.getDeptByCurrentUser();
if (!R.isSuccess() || CollectionUtil.isEmpty(R.getData())) {
return null;
}
List<Long> deptIdList = R.getData().stream().map(Dept::getId).collect(Collectors.toList());
List<StationEntity> list = stationService.getStationType(null, Collections.singletonList(HomePageConstant.HYDROPOWER),deptIdList);
if(CollectionUtil.isEmpty(list)){
return null;
}
List<String> codeList = list.stream().map(StationEntity::getCode).collect(Collectors.toList());
if(CollectionUtil.isEmpty(codeList)){
return null;
}
List<RealStationVo> result = (List<RealStationVo>) 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<RealStationVo> getStationMonitor() {
// 根据用户权限获取机构
R<List<Dept>> R = sysClient.getDeptByCurrentUser();
if (!R.isSuccess() || CollectionUtil.isEmpty(R.getData())) {
return null;
}
List<Long> deptIdList = R.getData().stream().map(Dept::getId).collect(Collectors.toList());
List<StationEntity> list = stationService.getStationType(null, Collections.singletonList(HomePageConstant.HYDROPOWER), deptIdList);
if (CollectionUtil.isEmpty(list)) {
return null;
}
List<String> codeList = list.stream().map(StationEntity::getCode).collect(Collectors.toList());
if (CollectionUtil.isEmpty(codeList)) {
return null;
}
List<RealStationVo> result = (List<RealStationVo>) 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<PointData> 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<HzPage<PointData>> 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);
}
}

Loading…
Cancel
Save