Commit cba395e6 authored by chenzhao's avatar chenzhao

修改代码

parent c2ea1be8
......@@ -114,4 +114,7 @@ public class IdxBizFanPointVarCentralValueDto {
@TableField("PROCESS_POINT2_ID")
private Double processPoint2Id;
@ApiModelProperty(value = "预警内容")
@TableField("CONTENT")
private String CONTENT;
}
......@@ -8,6 +8,7 @@ import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.time.LocalDateTime;
import java.util.Date;
/**
*
......@@ -39,7 +40,7 @@ public class IdxBizFanPointVarCentralValue{
*
*/
@TableField("REC_DATE")
private LocalDateTime recDate;
private Date recDate;
/**
*
......@@ -81,7 +82,7 @@ public class IdxBizFanPointVarCentralValue{
*
*/
@TableField("ANALYSIS_POINT_ID")
private Integer analysisPointId;
private String analysisPointId;
/**
* 片区
......@@ -171,6 +172,6 @@ public class IdxBizFanPointVarCentralValue{
* 工况变量2ID
*/
@TableField("PROCESS_POINT2_ID")
private Double processPoint2Id;
private String processPoint2Id;
}
......@@ -125,4 +125,9 @@ public class IdxBizFanWarningRecord{
@TableField("EQUIPMENT_NAME")
private String equipmentName;
/**
* 预警内容
* */
@TableField("CONTENT")
private String CONTENT;
}
package com.yeejoin.amos.boot.module.jxiop.biz.mapper2;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.IdxBizFanPointProcessVariableClassificationDto;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.IdxBizFanPointProcessVariableClassification;
import java.util.List;
......@@ -12,7 +13,7 @@ import java.util.List;
* @date 2023-08-15
*/
public interface IdxBizFanPointProcessVariableClassificationMapper extends BaseMapper<IdxBizFanPointProcessVariableClassification> {
List<IdxBizFanPointProcessVariableClassification> getInfluxDBData();
List<IdxBizFanPointProcessVariableClassificationDto> getInfluxDBData();
List<String> gateWayIdListFan();
}
......@@ -2,15 +2,27 @@ package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESEquipments;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.IdxBizFanPointProcessVariableClassificationDto;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.*;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.*;
import com.yeejoin.amos.component.influxdb.InfluxdbUtil;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
......@@ -48,6 +60,11 @@ public class CommonServiceImpl {
@Value("${gkzxzjs.key:input 2}")
String gkzxzjskey2;
//----------------健康指数值计算相关请求属性配置------------------------
@Value("${gkzxzjs.url:8804dc58-508b-4e73-8346-5aa8d808746f}")
String jkzsjsurl;
// {"tableName": "idx_biz_fan_point_process_variable_classification"} 风机工况变量划分
// {"tableName": "idx_biz_pv_point_process_variable_classification"} 光伏工况变量画分
// {"tableName": "idx_biz_fan_point_var_correlation"} 风机相关性
......@@ -63,6 +80,13 @@ public class CommonServiceImpl {
@Autowired
private InfluxdbUtil influxdbUtil;
@Autowired
private ElasticsearchRestTemplate elasticsearchTemplate;
@Autowired
IdxBizFanPointVarCentralValueMapper idxBizFanPointVarCentralValueMapper;
/**
* @return
......@@ -638,4 +662,96 @@ public class CommonServiceImpl {
SimpleDateFormat dateFormat = new SimpleDateFormat(FORMAT_UTC);
return dateFormat.format(timeStr);
}
@Scheduled(cron = "0/10 * * * * ?")
private void healthWarningMinute() {
List<IdxBizFanPointProcessVariableClassificationDto> data = idxBizFanPointProcessVariableClassificationMapper.getInfluxDBData();
Map<String, List<IdxBizFanPointProcessVariableClassificationDto>> maps = data.stream().collect(Collectors.groupingBy(IdxBizFanPointProcessVariableClassificationDto::getGatewayId));
BoolQueryBuilder boolMustAll = QueryBuilders.boolQuery();
List<QueryBuilder> should = boolMustAll.should();
for (String s : maps.keySet()) {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
List<String> address = maps.get(s).stream().map(IdxBizFanPointProcessVariableClassificationDto::getIndexAddress).collect(Collectors.toList());
boolQueryBuilder.must(QueryBuilders.termsQuery("address.keyword", address)).must(QueryBuilders.matchQuery("gatewayId.keyword", s));
should.add(boolQueryBuilder);
}
// 创建查询构造器
NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder()
//过滤条件
.withQuery(boolMustAll);
List<ESEquipments> equipments = new LinkedList<>();
long totle = 0;
try {
SearchHits<ESEquipments> searchHits = elasticsearchTemplate.search(queryBuilder.build(), ESEquipments.class);
for (SearchHit searchHit : searchHits.getSearchHits()) {
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(searchHit.getContent());
ESEquipments eSAlertCalled = JSONObject.toJavaObject(jsonObject, ESEquipments.class);
equipments.add(eSAlertCalled);
}
totle = searchHits.getTotalHits();
} catch (Exception e) {
// TODO: handle exception
}
for (IdxBizFanPointProcessVariableClassificationDto datum : data) {
for (ESEquipments equipment : equipments) {
if (equipment.getAddress().equals(datum.getIndexAddress()) && equipment.getGatewayId().equals(datum.getGatewayId())){
datum.setCurrentValue(equipment.getValueDouble());
}
}
}
LambdaQueryWrapper<IdxBizFanPointVarCentralValue> wrapper = new LambdaQueryWrapper<>();
List<IdxBizFanPointVarCentralValue> idxBizUhefs = idxBizFanPointVarCentralValueMapper.selectList(wrapper);
List< Map<String, Object>> datas = new ArrayList<>();
for (IdxBizFanPointVarCentralValue idxBizUhef : idxBizUhefs) {
double value1 = 0.00;
double value2 = 0.00;
double value3 = 0.00;
double value4 = 0.00;
for (IdxBizFanPointProcessVariableClassificationDto datum : data) {
if (idxBizUhef.getProcessPoint1Id().equals(datum.getSequenceNbr())){
value1 = datum.getCurrentValue();
}
if (idxBizUhef.getProcessPoint2Id().equals(datum.getSequenceNbr())) {
value2 = datum.getCurrentValue();
}
if (idxBizUhef.getProcessPoint3Id().equals(datum.getSequenceNbr())) {
value3 = datum.getCurrentValue();
}
if (idxBizUhef.getAnalysisPointId().equals(datum.getSequenceNbr())) {
value4 = datum.getCurrentValue();
}
}
if (idxBizUhef.getProcess1Min() < value1 && value1 < idxBizUhef.getProcess1Max() &&
idxBizUhef.getProcess2Min() < value2 && value2 < idxBizUhef.getPorcess2Max() &&
idxBizUhef.getProcess3Min() < value3 && value3 < idxBizUhef.getProcess3Max()){
Map<String, Object> map = new HashMap<>();
map.put("analysVariable",value4);
map.put("stdDev",idxBizUhef.getAnalysisStdDev());
map.put("centerValue",idxBizUhef.getAnalysisCenterValue());
map.put("analysVariableId",idxBizUhef.getAnalysisPointId());
datas.add(map);
}
}
if (!datas.isEmpty()) {
logger.info("------------------------------------------开始调用健康指数计算算法开始----------------------------------------");
HashMap<String, Object> realParams = new HashMap<>();
realParams.put(gkzxzjskey1, datas);
String response = HttpUtil.createPost(baseUrl + jkzsjsurl).body(JSON.toJSONString(realParams)).execute().body();
try {
logger.info("--------------------repsonse: "+response);
TimeUnit.SECONDS.sleep(sleepTime);
logger.info("------------------------------------------调用健康指数计算算法结束----------------------------------------");
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESEquipments;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.IdxBizUhefDto;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.IdxBizUxfvDto;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.IdxBizFanHealthIndex;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.IdxBizPldo;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.IdxBizUhef;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.IdxBizUxfv;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.IdxBizPldoMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.IdxBizUhefMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.IdxBizUxfvMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.utils.InfluxDButils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.*;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
public class HealthStatusIndicatorServiceImpl {
@Autowired
private IdxBizUhefMapper idxBizUhefMapper;
@Autowired
private IdxBizUxfvMapper idxBizUxfvMapper;
@Autowired
private IdxBizPldoMapper idxBizPldoMapper;
@Autowired
private InfluxDButils influxDButils;
@Autowired
private ElasticsearchRestTemplate elasticsearchTemplate;
@Value("${healthValue_Warn}")
Double healthValueWarn;
@Value("${healthValue_Risk}")
Double healthValueRisk;
@Value("${healthValue_Notice}")
Double healthValueNotice;
@Scheduled(cron = "0/10 * * * * ? ")
private void mother() {
List<IdxBizUxfvDto> data = idxBizUxfvMapper.getInfluxDBData();
@Value("${healthValue_DayCount}")
long healthValueDayCount;
@Value("${healthValue_HourCount}")
long healthValueHourCount;
@Value("${healthValue_MinCount}")
long healthValueMinCount;
Map<String, List<IdxBizUxfvDto>> maps = data.stream().collect(Collectors.groupingBy(IdxBizUxfvDto::getGatewayId));
BoolQueryBuilder boolMustAll = QueryBuilders.boolQuery();
@Autowired
private RedisUtils redisUtils;
@Autowired
IdxBizFanHealthIndexMapper idxBizFanHealthIndexMapper;
List<QueryBuilder> should = boolMustAll.should();
for (String s : maps.keySet()) {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
List<String> address = maps.get(s).stream().map(IdxBizUxfvDto::getIndexAddress).collect(Collectors.toList());
boolQueryBuilder.must(QueryBuilders.termsQuery("address.keyword", address)).must(QueryBuilders.matchQuery("gatewayId.keyword", s));
should.add(boolQueryBuilder);
}
@Autowired
IdxBizFanWarningRecordMapper idxBizFanWarningRecordMapper;
/***
* 每一小时获取一次最大粒度内的指数异常数据
* 判断一小时内数据是否符合预警规则 符合则报警并在redis中缓存 同一级别的预警记录下次不生成
*
*/
@Scheduled(cron = "0 0 */1 * * ?")
private void healthWarningMinute() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY,calendar.get(Calendar.HOUR_OF_DAY)-1);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
LambdaQueryWrapper<IdxBizFanHealthIndex> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(IdxBizFanHealthIndex::getAnalysisType,"按时刻");
wrapper.le(IdxBizFanHealthIndex::getHealthIndex,healthValueNotice);
wrapper.ge(IdxBizFanHealthIndex::getRecDate,df.format(calendar.getTime()));
wrapper.orderByDesc(IdxBizFanHealthIndex::getRecDate);
List<IdxBizFanHealthIndex> healthIndices = idxBizFanHealthIndexMapper.selectList(wrapper);
Map<Integer, Map<String, List<IdxBizFanHealthIndex>>> gateWayMaps = healthIndices.stream().collect(Collectors.groupingBy(IdxBizFanHealthIndex::getGatewayId, Collectors.groupingBy(IdxBizFanHealthIndex::getIndexAddress)));
for (Integer gateWayId : gateWayMaps.keySet()) {
Map<String, List<IdxBizFanHealthIndex>> healthDataMaps = gateWayMaps.get(gateWayId);
for (String address : healthDataMaps.keySet()) {
List<IdxBizFanHealthIndex> idxBizFanHealthIndices = healthDataMaps.get(address);
List<Double> healthIndex = idxBizFanHealthIndices.stream().map(IdxBizFanHealthIndex::getHealthIndex).collect(Collectors.toList());
long riskNum = healthIndex.stream().filter(e -> e <= healthValueRisk).count();
long warnNum = healthIndex.stream().filter(e -> e <= healthValueWarn).count();
long noticeNum = healthIndex.stream().filter(e -> e <= healthValueNotice).count();
String level = "";
String content = "";
String num = "";
content = healthValueMinCount + "分钟";
if (riskNum >= healthValueMinCount && !redisUtils.hasKey(gateWayId+"_"+address+"_health_risk_minute")){
redisUtils.set(gateWayId+"_"+address+"_health_risk_minute","risk");
level ="危险";
num = ""+healthValueRisk;
}else if (warnNum >= healthValueMinCount && !redisUtils.hasKey(gateWayId+"_"+address+"_health_warn_minute") ){
redisUtils.set(gateWayId+"_"+address+"_health_warn_minute","warn");
level ="警告";
num = ""+healthValueWarn;
}else if (noticeNum >= healthValueMinCount && !redisUtils.hasKey(gateWayId+"_"+address+"_health_notice_minute")){
redisUtils.set(gateWayId+"_"+address+"_health_notice_minute","notice");
level ="注意";
num = ""+healthValueNotice;
}
// 创建查询构造器
NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder()
//过滤条件
.withQuery(boolMustAll);
List<ESEquipments> equipments = new LinkedList<>();
long totle = 0;
try {
SearchHits<ESEquipments> searchHits = elasticsearchTemplate.search(queryBuilder.build(), ESEquipments.class);
for (SearchHit searchHit : searchHits.getSearchHits()) {
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(searchHit.getContent());
ESEquipments eSAlertCalled = JSONObject.toJavaObject(jsonObject, ESEquipments.class);
equipments.add(eSAlertCalled);
if (!level.equals("")){
IdxBizFanWarningRecord idxBizFanWarningRecord = new IdxBizFanWarningRecord();
idxBizFanWarningRecord.setRecord(idxBizFanHealthIndices.get(0).getRecord());
idxBizFanWarningRecord.setArae(idxBizFanHealthIndices.get(0).getArae());
idxBizFanWarningRecord.setStation(idxBizFanHealthIndices.get(0).getStation());
idxBizFanWarningRecord.setSubSystem(idxBizFanHealthIndices.get(0).getSubSystem());
idxBizFanWarningRecord.setGatewayId(gateWayId);
idxBizFanWarningRecord.setIndexAddress(address);
idxBizFanWarningRecord.setEquipmentName(idxBizFanHealthIndices.get(0).getEquipmentName());
idxBizFanWarningRecord.setAnalysisPointId(idxBizFanHealthIndices.get(0).getAnalysisObjSeq());
idxBizFanWarningRecord.setDisposotionState("未处置");
idxBizFanWarningRecord.setStatus("0");
idxBizFanWarningRecord.setWarningName(level);
idxBizFanWarningRecord.setCONTENT("连续"+content+"健康指数<"+num );
}
}
totle = searchHits.getTotalHits();
} catch (Exception e) {
// TODO: handle exception
}
}
/***
* 每五小时获取一次最大粒度内的指数异常数据
* 判断五小时内数据是否符合预警规则 符合则报警并在redis中缓存 同一级别的预警记录下次不生成
*
*/
@Scheduled(cron = "0 0 */5 * * ?")
private void healthWarningHour() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY,calendar.get(Calendar.HOUR_OF_DAY)-5);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
LambdaQueryWrapper<IdxBizFanHealthIndex> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(IdxBizFanHealthIndex::getAnalysisType,"按小时");
wrapper.le(IdxBizFanHealthIndex::getHealthIndex,healthValueNotice);
wrapper.ge(IdxBizFanHealthIndex::getRecDate,df.format(calendar.getTime()));
wrapper.orderByDesc(IdxBizFanHealthIndex::getRecDate);
List<IdxBizFanHealthIndex> healthIndices = idxBizFanHealthIndexMapper.selectList(wrapper);
Map<Integer, Map<String, List<IdxBizFanHealthIndex>>> gateWayMaps = healthIndices.stream().collect(Collectors.groupingBy(IdxBizFanHealthIndex::getGatewayId, Collectors.groupingBy(IdxBizFanHealthIndex::getIndexAddress)));
for (Integer gateWayId : gateWayMaps.keySet()) {
Map<String, List<IdxBizFanHealthIndex>> healthDataMaps = gateWayMaps.get(gateWayId);
for (String address : healthDataMaps.keySet()) {
List<IdxBizFanHealthIndex> idxBizFanHealthIndices = healthDataMaps.get(address);
List<Double> healthIndex = idxBizFanHealthIndices.stream().map(IdxBizFanHealthIndex::getHealthIndex).collect(Collectors.toList());
long riskNum = healthIndex.stream().filter(e -> e <= healthValueRisk).count();
long warnNum = healthIndex.stream().filter(e -> e <= healthValueWarn).count();
long noticeNum = healthIndex.stream().filter(e -> e <= healthValueNotice).count();
String level = "";
String content = "";
String num = "";
content = healthValueHourCount + "小时";
if (riskNum >= healthValueHourCount && !redisUtils.hasKey(gateWayId+"_"+address+"_health_risk_hour")){
redisUtils.set(gateWayId+"_"+address+"_health_risk_hour","risk");
level ="危险";
num = ""+healthValueRisk;
}else if (warnNum >= healthValueHourCount && !redisUtils.hasKey(gateWayId+"_"+address+"_health_risk_hour") ){
redisUtils.set(gateWayId+"_"+address+"_health_warn_hour","warn");
level ="警告";
num = ""+healthValueWarn;
}else if (noticeNum >= healthValueHourCount && !redisUtils.hasKey(gateWayId+"_"+address+"_health_notice_hour")){
redisUtils.set(gateWayId+"_"+address+"_health_notice_hour","notice");
level ="注意";
num = ""+healthValueNotice;
for (IdxBizUxfvDto datum : data) {
for (ESEquipments equipment : equipments) {
if (equipment.getAddress().equals(datum.getIndexAddress()) && equipment.getGatewayId().equals(datum.getGatewayId())){
datum.setCurrentValue(equipment.getValueDouble());
}
}
}
LambdaQueryWrapper<IdxBizUhef> wrapper = new LambdaQueryWrapper<>();
List<IdxBizUhef> idxBizUhefs = idxBizUhefMapper.selectList(wrapper);
List< Map<String, Object>> datas = new ArrayList<>();
for (IdxBizUhef idxBizUhef : idxBizUhefs) {
double value1 = 0.00;
double value2 = 0.00;
double value3 = 0.00;
double value4 = 0.00;
for (IdxBizUxfvDto datum : data) {
if (idxBizUhef.getPointOneId().equals(datum.getSequenceNbr())){
value1 = datum.getCurrentValue();
}
if (idxBizUhef.getPointTwoId().equals(datum.getSequenceNbr())) {
value2 = datum.getCurrentValue();
}
if (idxBizUhef.getPointThreeId().equals(datum.getSequenceNbr())) {
value3 = datum.getCurrentValue();
if (!level.equals("")){
IdxBizFanWarningRecord idxBizFanWarningRecord = new IdxBizFanWarningRecord();
idxBizFanWarningRecord.setRecord(idxBizFanHealthIndices.get(0).getRecord());
idxBizFanWarningRecord.setArae(idxBizFanHealthIndices.get(0).getArae());
idxBizFanWarningRecord.setStation(idxBizFanHealthIndices.get(0).getStation());
idxBizFanWarningRecord.setSubSystem(idxBizFanHealthIndices.get(0).getSubSystem());
idxBizFanWarningRecord.setGatewayId(gateWayId);
idxBizFanWarningRecord.setIndexAddress(address);
idxBizFanWarningRecord.setEquipmentName(idxBizFanHealthIndices.get(0).getEquipmentName());
idxBizFanWarningRecord.setAnalysisPointId(idxBizFanHealthIndices.get(0).getAnalysisObjSeq());
idxBizFanWarningRecord.setDisposotionState("未处置");
idxBizFanWarningRecord.setStatus("0");
idxBizFanWarningRecord.setWarningName(level);
idxBizFanWarningRecord.setCONTENT("连续"+content+"健康指数<"+num );
}
if (idxBizUhef.getAnalysisPointId().equals(datum.getSequenceNbr())) {
value4 = datum.getCurrentValue();
}
}
if (idxBizUhef.getProcess1Min() < value1 && value1 < idxBizUhef.getProcess1Max() &&
idxBizUhef.getProcess2Min() < value2 && value2 < idxBizUhef.getProcess2Max() &&
idxBizUhef.getProcess3Min() < value3 && value3 < idxBizUhef.getProcess3Max()){
Map<String, Object> map = new HashMap<>();
map.put("analysVariable",value4);
map.put("stdDev",idxBizUhef.getAnalysisStdDev());
map.put("centerValue",idxBizUhef.getAnalysisCenterValue());
map.put("analysVariableId",idxBizUhef.getAnalysisPointId());
datas.add(map);
//算法接口 获取健康指数
double healthExponent = 0.00;
LambdaQueryWrapper<IdxBizPldo> healthQerry = new LambdaQueryWrapper<>();
healthQerry.ge(IdxBizPldo::getGroupLowerLimit,healthExponent);
healthQerry.le(IdxBizPldo::getGroupUpperLimit,healthExponent);
healthQerry.eq(IdxBizPldo::getAnalysisObjType,"设备");
IdxBizPldo idxBizPldo = idxBizPldoMapper.selectOne(healthQerry);
}
}
IdxBizFanHealthIndex idxBizFanHealthIndex = new IdxBizFanHealthIndex();
/***
* 每三天取一次最大粒度内的指数异常数据
* 判断三天内数据是否符合预警规则 符合则报警并在redis中缓存 同一级别的预警记录下次不生成
*
*/
@Scheduled(cron = "0 0 0 */3 * ? ")
private void healthWarningDay() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH,calendar.get(Calendar.DAY_OF_MONTH)-3);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
LambdaQueryWrapper<IdxBizFanHealthIndex> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(IdxBizFanHealthIndex::getAnalysisType,"按天");
wrapper.le(IdxBizFanHealthIndex::getHealthIndex,healthValueNotice);
wrapper.ge(IdxBizFanHealthIndex::getRecDate,df.format(calendar.getTime()));
wrapper.orderByDesc(IdxBizFanHealthIndex::getRecDate);
List<IdxBizFanHealthIndex> healthIndices = idxBizFanHealthIndexMapper.selectList(wrapper);
Map<Integer, Map<String, List<IdxBizFanHealthIndex>>> gateWayMaps = healthIndices.stream().collect(Collectors.groupingBy(IdxBizFanHealthIndex::getGatewayId, Collectors.groupingBy(IdxBizFanHealthIndex::getIndexAddress)));
for (Integer gateWayId : gateWayMaps.keySet()) {
Map<String, List<IdxBizFanHealthIndex>> healthDataMaps = gateWayMaps.get(gateWayId);
for (String address : healthDataMaps.keySet()) {
List<IdxBizFanHealthIndex> idxBizFanHealthIndices = healthDataMaps.get(address);
List<Double> healthIndex = idxBizFanHealthIndices.stream().map(IdxBizFanHealthIndex::getHealthIndex).collect(Collectors.toList());
long riskNum = healthIndex.stream().filter(e -> e <= healthValueRisk).count();
long warnNum = healthIndex.stream().filter(e -> e <= healthValueWarn).count();
long noticeNum = healthIndex.stream().filter(e -> e <= healthValueNotice).count();
String level = "";
String content = "";
String num = "";
content = healthValueDayCount + "天";
if (riskNum >= healthValueDayCount && !redisUtils.hasKey(gateWayId+"_"+address+"_health_risk_day")){
redisUtils.set(gateWayId+"_"+address+"_health_risk_day","risk");
level ="危险";
num = ""+healthValueRisk;
}else if (warnNum >= healthValueDayCount && !redisUtils.hasKey(gateWayId+"_"+address+"_health_warn_day") ){
redisUtils.set(gateWayId+"_"+address+"_health_warn_day","warn");
level ="警告";
num = ""+healthValueWarn;
}else if (noticeNum >= healthValueDayCount && !redisUtils.hasKey(gateWayId+"_"+address+"_health_notice_day")){
redisUtils.set(gateWayId+"_"+address+"_health_notice_day","notice");
level ="注意";
num = ""+healthValueNotice;
}
if (!level.equals("")){
IdxBizFanWarningRecord idxBizFanWarningRecord = new IdxBizFanWarningRecord();
idxBizFanWarningRecord.setRecord(idxBizFanHealthIndices.get(0).getRecord());
idxBizFanWarningRecord.setArae(idxBizFanHealthIndices.get(0).getArae());
idxBizFanWarningRecord.setStation(idxBizFanHealthIndices.get(0).getStation());
idxBizFanWarningRecord.setSubSystem(idxBizFanHealthIndices.get(0).getSubSystem());
idxBizFanWarningRecord.setGatewayId(gateWayId);
idxBizFanWarningRecord.setIndexAddress(address);
idxBizFanWarningRecord.setEquipmentName(idxBizFanHealthIndices.get(0).getEquipmentName());
idxBizFanWarningRecord.setAnalysisPointId(idxBizFanHealthIndices.get(0).getAnalysisObjSeq());
idxBizFanWarningRecord.setDisposotionState("未处置");
idxBizFanWarningRecord.setStatus("0");
idxBizFanWarningRecord.setWarningName(level);
idxBizFanWarningRecord.setCONTENT("连续"+content+"健康指数<"+num );
idxBizFanWarningRecordMapper.insert(idxBizFanWarningRecord);
}
}
}
// TODO: data
}
}
......@@ -80,3 +80,11 @@ spring.elasticsearch.rest.connection-timeout=30000
spring.elasticsearch.rest.username=elastic
spring.elasticsearch.rest.password=123456
spring.elasticsearch.rest.read-timeout=30000
healthValue_Warn=39
healthValue_Risk=59
healthValue_Notice=79
healthValue_DayCount=3
healthValue_HourCount=6
healthValue_MinCount=5
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment