Commit 7079dee7 authored by chenzhao's avatar chenzhao

增加光伏预警

parent 3556bf18
...@@ -69,13 +69,13 @@ public class IdxBizFanWarningRecord{ ...@@ -69,13 +69,13 @@ public class IdxBizFanWarningRecord{
* *
*/ */
@TableField("HEALTH_INDEX_SEQ") @TableField("HEALTH_INDEX_SEQ")
private Integer healthIndexSeq; private String healthIndexSeq;
/** /**
* *
*/ */
@TableField("ANALYSIS_POINT_ID") @TableField("ANALYSIS_POINT_ID")
private Integer analysisPointId; private String analysisPointId;
/** /**
* 预警等级 * 预警等级
......
...@@ -75,7 +75,7 @@ public class IdxBizPvWarningRecord{ ...@@ -75,7 +75,7 @@ public class IdxBizPvWarningRecord{
* *
*/ */
@TableField("ANALYSIS_POINT_ID") @TableField("ANALYSIS_POINT_ID")
private Integer analysisPointId; private String analysisPointId;
/** /**
* 预警等级 * 预警等级
...@@ -117,7 +117,7 @@ public class IdxBizPvWarningRecord{ ...@@ -117,7 +117,7 @@ public class IdxBizPvWarningRecord{
* 网关ID * 网关ID
*/ */
@TableField("GATEWAY_ID") @TableField("GATEWAY_ID")
private Integer gatewayId; private String gatewayId;
/** /**
* 点表地址 * 点表地址
...@@ -131,4 +131,9 @@ public class IdxBizPvWarningRecord{ ...@@ -131,4 +131,9 @@ public class IdxBizPvWarningRecord{
@TableField("EQUIPMENT_NAME") @TableField("EQUIPMENT_NAME")
private String equipmentName; private String equipmentName;
/**
* 预警内容
* */
@TableField("CONTENT")
private String CONTENT;
} }
...@@ -44,6 +44,217 @@ public class HealthStatusIndicatorServiceImpl { ...@@ -44,6 +44,217 @@ public class HealthStatusIndicatorServiceImpl {
* *
*/ */
@Autowired
IdxBizPvHealthIndexMapper idxBizPvHealthIndexMapper;
@Autowired
IdxBizPvWarningRecordMapper idxBizPvWarningRecordMapper;
/***
* 每一小时获取一次最大粒度内的指数异常数据
* 判断一小时内数据是否符合预警规则 符合则报警并在redis中缓存 同一级别的预警记录下次不生成
*
*/
@Scheduled(cron = "0 0 */1 * * ?")
private void healthWarningMinuteGF() {
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<IdxBizPvHealthIndex> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(IdxBizPvHealthIndex::getAnalysisType,"按时刻");
wrapper.le(IdxBizPvHealthIndex::getHealthIndex,healthValueNotice);
wrapper.ge(IdxBizPvHealthIndex::getRecDate,df.format(calendar.getTime()));
wrapper.orderByDesc(IdxBizPvHealthIndex::getRecDate);
List<IdxBizPvHealthIndex> healthIndices = idxBizPvHealthIndexMapper.selectList(wrapper);
Map<String, Map<String, List<IdxBizPvHealthIndex>>> gateWayMaps = healthIndices.stream().collect(Collectors.groupingBy(IdxBizPvHealthIndex::getGatewayId, Collectors.groupingBy(IdxBizPvHealthIndex::getIndexAddress)));
for (String gateWayId : gateWayMaps.keySet()) {
Map<String, List<IdxBizPvHealthIndex>> healthDataMaps = gateWayMaps.get(gateWayId);
for (String address : healthDataMaps.keySet()) {
List<IdxBizPvHealthIndex> idxBizPvHealthIndices = healthDataMaps.get(address);
List<Double> healthIndex = idxBizPvHealthIndices.stream().map(IdxBizPvHealthIndex::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;
}
if (!level.equals("")){
IdxBizPvWarningRecord idxBizPvWarningRecord = new IdxBizPvWarningRecord();
idxBizPvWarningRecord.setRecord(idxBizPvHealthIndices.get(0).getRecord());
idxBizPvWarningRecord.setArae(idxBizPvHealthIndices.get(0).getArae());
idxBizPvWarningRecord.setStation(idxBizPvHealthIndices.get(0).getStation());
idxBizPvWarningRecord.setSubarray(idxBizPvHealthIndices.get(0).getSubarray());
idxBizPvWarningRecord.setGatewayId(gateWayId);
idxBizPvWarningRecord.setIndexAddress(address);
idxBizPvWarningRecord.setEquipmentName(idxBizPvHealthIndices.get(0).getEquipmentName());
idxBizPvWarningRecord.setAnalysisPointId(idxBizPvHealthIndices.get(0).getAnalysisObjSeq());
idxBizPvWarningRecord.setDisposotionState("未处置");
idxBizPvWarningRecord.setStatus("0");
idxBizPvWarningRecord.setWarningName(level);
idxBizPvWarningRecord.setCONTENT("连续"+content+"健康指数<"+num );
}
}
}
}
/***
* 每五小时获取一次最大粒度内的指数异常数据
* 判断五小时内数据是否符合预警规则 符合则报警并在redis中缓存 同一级别的预警记录下次不生成
*
*/
@Scheduled(cron = "0 0 */5 * * ?")
private void healthWarningHourGF() {
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<IdxBizPvHealthIndex> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(IdxBizPvHealthIndex::getAnalysisType,"按小时");
wrapper.le(IdxBizPvHealthIndex::getHealthIndex,healthValueNotice);
wrapper.ge(IdxBizPvHealthIndex::getRecDate,df.format(calendar.getTime()));
wrapper.orderByDesc(IdxBizPvHealthIndex::getRecDate);
List<IdxBizPvHealthIndex> healthIndices = idxBizPvHealthIndexMapper.selectList(wrapper);
Map<String, Map<String, List<IdxBizPvHealthIndex>>> gateWayMaps = healthIndices.stream().collect(Collectors.groupingBy(IdxBizPvHealthIndex::getGatewayId, Collectors.groupingBy(IdxBizPvHealthIndex::getIndexAddress)));
for (String gateWayId : gateWayMaps.keySet()) {
Map<String, List<IdxBizPvHealthIndex>> healthDataMaps = gateWayMaps.get(gateWayId);
for (String address : healthDataMaps.keySet()) {
List<IdxBizPvHealthIndex> idxBizPvHealthIndices = healthDataMaps.get(address);
List<Double> healthIndex = idxBizPvHealthIndices.stream().map(IdxBizPvHealthIndex::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;
}
if (!level.equals("")){
IdxBizPvWarningRecord idxBizPvWarningRecord = new IdxBizPvWarningRecord();
idxBizPvWarningRecord.setRecord(idxBizPvHealthIndices.get(0).getRecord());
idxBizPvWarningRecord.setArae(idxBizPvHealthIndices.get(0).getArae());
idxBizPvWarningRecord.setStation(idxBizPvHealthIndices.get(0).getStation());
idxBizPvWarningRecord.setSubarray(idxBizPvHealthIndices.get(0).getSubarray());
idxBizPvWarningRecord.setGatewayId(gateWayId);
idxBizPvWarningRecord.setIndexAddress(address);
idxBizPvWarningRecord.setEquipmentName(idxBizPvHealthIndices.get(0).getEquipmentName());
idxBizPvWarningRecord.setAnalysisPointId(idxBizPvHealthIndices.get(0).getAnalysisObjSeq());
idxBizPvWarningRecord.setDisposotionState("未处置");
idxBizPvWarningRecord.setStatus("0");
idxBizPvWarningRecord.setWarningName(level);
idxBizPvWarningRecord.setCONTENT("连续"+content+"健康指数<"+num );
}
}
}
}
/***
* 每三天取一次最大粒度内的指数异常数据
* 判断三天内数据是否符合预警规则 符合则报警并在redis中缓存 同一级别的预警记录下次不生成
*
*/
@Scheduled(cron = "0 0 0 */3 * ? ")
private void healthWarningDayGF() {
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<IdxBizPvHealthIndex> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(IdxBizPvHealthIndex::getAnalysisType,"按天");
wrapper.le(IdxBizPvHealthIndex::getHealthIndex,healthValueNotice);
wrapper.ge(IdxBizPvHealthIndex::getRecDate,df.format(calendar.getTime()));
wrapper.orderByDesc(IdxBizPvHealthIndex::getRecDate);
List<IdxBizPvHealthIndex> healthIndices = idxBizPvHealthIndexMapper.selectList(wrapper);
Map<String, Map<String, List<IdxBizPvHealthIndex>>> gateWayMaps = healthIndices.stream().collect(Collectors.groupingBy(IdxBizPvHealthIndex::getGatewayId, Collectors.groupingBy(IdxBizPvHealthIndex::getIndexAddress)));
for (String gateWayId : gateWayMaps.keySet()) {
Map<String, List<IdxBizPvHealthIndex>> healthDataMaps = gateWayMaps.get(gateWayId);
for (String address : healthDataMaps.keySet()) {
List<IdxBizPvHealthIndex> idxBizPvHealthIndices = healthDataMaps.get(address);
List<Double> healthIndex = idxBizPvHealthIndices.stream().map(IdxBizPvHealthIndex::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("")){
IdxBizPvWarningRecord idxBizPvWarningRecord = new IdxBizPvWarningRecord();
idxBizPvWarningRecord.setRecord(idxBizPvHealthIndices.get(0).getRecord());
idxBizPvWarningRecord.setArae(idxBizPvHealthIndices.get(0).getArae());
idxBizPvWarningRecord.setStation(idxBizPvHealthIndices.get(0).getStation());
idxBizPvWarningRecord.setSubarray(idxBizPvHealthIndices.get(0).getSubarray());
idxBizPvWarningRecord.setGatewayId(gateWayId);
idxBizPvWarningRecord.setIndexAddress(address);
idxBizPvWarningRecord.setEquipmentName(idxBizPvHealthIndices.get(0).getEquipmentName());
idxBizPvWarningRecord.setAnalysisPointId(idxBizPvHealthIndices.get(0).getAnalysisObjSeq());
idxBizPvWarningRecord.setDisposotionState("未处置");
idxBizPvWarningRecord.setStatus("0");
idxBizPvWarningRecord.setWarningName(level);
idxBizPvWarningRecord.setCONTENT("连续"+content+"健康指数<"+num );
idxBizPvWarningRecordMapper.insert(idxBizPvWarningRecord);
}
}
}
}
@Scheduled(cron = "0 0 */1 * * ?") @Scheduled(cron = "0 0 */1 * * ?")
private void healthWarningMinute() { private void healthWarningMinute() {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
......
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