Commit cba395e6 authored by chenzhao's avatar chenzhao

修改代码

parent c2ea1be8
...@@ -114,4 +114,7 @@ public class IdxBizFanPointVarCentralValueDto { ...@@ -114,4 +114,7 @@ public class IdxBizFanPointVarCentralValueDto {
@TableField("PROCESS_POINT2_ID") @TableField("PROCESS_POINT2_ID")
private Double processPoint2Id; private Double processPoint2Id;
@ApiModelProperty(value = "预警内容")
@TableField("CONTENT")
private String CONTENT;
} }
...@@ -8,6 +8,7 @@ import lombok.EqualsAndHashCode; ...@@ -8,6 +8,7 @@ import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Date;
/** /**
* *
...@@ -39,7 +40,7 @@ public class IdxBizFanPointVarCentralValue{ ...@@ -39,7 +40,7 @@ public class IdxBizFanPointVarCentralValue{
* *
*/ */
@TableField("REC_DATE") @TableField("REC_DATE")
private LocalDateTime recDate; private Date recDate;
/** /**
* *
...@@ -81,7 +82,7 @@ public class IdxBizFanPointVarCentralValue{ ...@@ -81,7 +82,7 @@ public class IdxBizFanPointVarCentralValue{
* *
*/ */
@TableField("ANALYSIS_POINT_ID") @TableField("ANALYSIS_POINT_ID")
private Integer analysisPointId; private String analysisPointId;
/** /**
* 片区 * 片区
...@@ -171,6 +172,6 @@ public class IdxBizFanPointVarCentralValue{ ...@@ -171,6 +172,6 @@ public class IdxBizFanPointVarCentralValue{
* 工况变量2ID * 工况变量2ID
*/ */
@TableField("PROCESS_POINT2_ID") @TableField("PROCESS_POINT2_ID")
private Double processPoint2Id; private String processPoint2Id;
} }
...@@ -125,4 +125,9 @@ public class IdxBizFanWarningRecord{ ...@@ -125,4 +125,9 @@ public class IdxBizFanWarningRecord{
@TableField("EQUIPMENT_NAME") @TableField("EQUIPMENT_NAME")
private String equipmentName; private String equipmentName;
/**
* 预警内容
* */
@TableField("CONTENT")
private String CONTENT;
} }
package com.yeejoin.amos.boot.module.jxiop.biz.mapper2; package com.yeejoin.amos.boot.module.jxiop.biz.mapper2;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; 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 com.yeejoin.amos.boot.module.jxiop.biz.entity.IdxBizFanPointProcessVariableClassification;
import java.util.List; import java.util.List;
...@@ -12,7 +13,7 @@ import java.util.List; ...@@ -12,7 +13,7 @@ import java.util.List;
* @date 2023-08-15 * @date 2023-08-15
*/ */
public interface IdxBizFanPointProcessVariableClassificationMapper extends BaseMapper<IdxBizFanPointProcessVariableClassification> { public interface IdxBizFanPointProcessVariableClassificationMapper extends BaseMapper<IdxBizFanPointProcessVariableClassification> {
List<IdxBizFanPointProcessVariableClassification> getInfluxDBData(); List<IdxBizFanPointProcessVariableClassificationDto> getInfluxDBData();
List<String> gateWayIdListFan(); List<String> gateWayIdListFan();
} }
...@@ -2,15 +2,27 @@ package com.yeejoin.amos.boot.module.jxiop.biz.service.impl; ...@@ -2,15 +2,27 @@ package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON; 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.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.entity.*;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.*; import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.*;
import com.yeejoin.amos.component.influxdb.InfluxdbUtil; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; 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.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -48,6 +60,11 @@ public class CommonServiceImpl { ...@@ -48,6 +60,11 @@ public class CommonServiceImpl {
@Value("${gkzxzjs.key:input 2}") @Value("${gkzxzjs.key:input 2}")
String gkzxzjskey2; String gkzxzjskey2;
//----------------健康指数值计算相关请求属性配置------------------------
@Value("${gkzxzjs.url:8804dc58-508b-4e73-8346-5aa8d808746f}")
String jkzsjsurl;
// {"tableName": "idx_biz_fan_point_process_variable_classification"} 风机工况变量划分 // {"tableName": "idx_biz_fan_point_process_variable_classification"} 风机工况变量划分
// {"tableName": "idx_biz_pv_point_process_variable_classification"} 光伏工况变量画分 // {"tableName": "idx_biz_pv_point_process_variable_classification"} 光伏工况变量画分
// {"tableName": "idx_biz_fan_point_var_correlation"} 风机相关性 // {"tableName": "idx_biz_fan_point_var_correlation"} 风机相关性
...@@ -63,6 +80,13 @@ public class CommonServiceImpl { ...@@ -63,6 +80,13 @@ public class CommonServiceImpl {
@Autowired @Autowired
private InfluxdbUtil influxdbUtil; private InfluxdbUtil influxdbUtil;
@Autowired
private ElasticsearchRestTemplate elasticsearchTemplate;
@Autowired
IdxBizFanPointVarCentralValueMapper idxBizFanPointVarCentralValueMapper;
/** /**
* @return * @return
...@@ -638,4 +662,96 @@ public class CommonServiceImpl { ...@@ -638,4 +662,96 @@ public class CommonServiceImpl {
SimpleDateFormat dateFormat = new SimpleDateFormat(FORMAT_UTC); SimpleDateFormat dateFormat = new SimpleDateFormat(FORMAT_UTC);
return dateFormat.format(timeStr); 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);
}
}
}
} }
...@@ -80,3 +80,11 @@ spring.elasticsearch.rest.connection-timeout=30000 ...@@ -80,3 +80,11 @@ spring.elasticsearch.rest.connection-timeout=30000
spring.elasticsearch.rest.username=elastic spring.elasticsearch.rest.username=elastic
spring.elasticsearch.rest.password=123456 spring.elasticsearch.rest.password=123456
spring.elasticsearch.rest.read-timeout=30000 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