Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
8fc74636
Commit
8fc74636
authored
Apr 18, 2024
by
caotao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
健康指数日月年问题修改。
parent
b3d8ddb0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
906 additions
and
121 deletions
+906
-121
IdxBizFanWarningRuleSetMapper.java
...dule/jxiop/biz/mapper2/IdxBizFanWarningRuleSetMapper.java
+6
-0
IdxBizPvWarningRuleSetMapper.java
...odule/jxiop/biz/mapper2/IdxBizPvWarningRuleSetMapper.java
+8
-0
HealthStatusIndicatorServiceImpl.java
...op/biz/service/impl/HealthStatusIndicatorServiceImpl.java
+892
-121
No files found.
amos-boot-system-jxiop/amos-boot-module-jxiop-analyse-biz/src/main/java/com/yeejoin/amos/boot/module/jxiop/biz/mapper2/IdxBizFanWarningRuleSetMapper.java
View file @
8fc74636
...
@@ -26,6 +26,12 @@ public interface IdxBizFanWarningRuleSetMapper extends BaseMapper<IdxBizFanWarni
...
@@ -26,6 +26,12 @@ public interface IdxBizFanWarningRuleSetMapper extends BaseMapper<IdxBizFanWarni
Integer
getMaxWaringCycleOfMinutesByGatewayId
(
String
gatewayId
);
Integer
getMaxWaringCycleOfMinutesByGatewayId
(
String
gatewayId
);
@Select
(
"SELECT MAX(WARNING_CYCLE) FROM idx_biz_fan_warning_rule_set WHERE ANALYSIS_TYPE = '按小时'"
)
@Select
(
"SELECT MAX(WARNING_CYCLE) FROM idx_biz_fan_warning_rule_set WHERE ANALYSIS_TYPE = '按小时'"
)
Integer
getMaxWaringCycleOfHour
();
Integer
getMaxWaringCycleOfHour
();
@Select
(
"SELECT MAX(WARNING_CYCLE) FROM idx_biz_fan_warning_rule_set WHERE ANALYSIS_TYPE = '按小时' and GATEWAY_ID = #{gatewayId}"
)
Integer
getMaxWaringCycleOfHourByGatewayId
(
String
gatewayId
);
@Select
(
"SELECT MAX(WARNING_CYCLE) FROM idx_biz_fan_warning_rule_set WHERE ANALYSIS_TYPE = '按天'"
)
@Select
(
"SELECT MAX(WARNING_CYCLE) FROM idx_biz_fan_warning_rule_set WHERE ANALYSIS_TYPE = '按天'"
)
Integer
getMaxWaringCycleOfDay
();
Integer
getMaxWaringCycleOfDay
();
@Select
(
"SELECT MAX(WARNING_CYCLE) FROM idx_biz_fan_warning_rule_set WHERE ANALYSIS_TYPE = '按天' and GATEWAY_ID = #{gatewayId}"
)
Integer
getMaxWaringCycleOfDayByGatewayId
(
String
gatewayId
);
@Select
(
"SELECT GATEWAY_ID FROM idx_biz_pv_warning_rule_set GROUP BY GATEWAY_ID"
)
List
<
String
>
getGatewayIds
();
}
}
amos-boot-system-jxiop/amos-boot-module-jxiop-analyse-biz/src/main/java/com/yeejoin/amos/boot/module/jxiop/biz/mapper2/IdxBizPvWarningRuleSetMapper.java
View file @
8fc74636
...
@@ -6,6 +6,8 @@ import io.swagger.models.auth.In;
...
@@ -6,6 +6,8 @@ import io.swagger.models.auth.In;
import
javafx.beans.binding.DoubleExpression
;
import
javafx.beans.binding.DoubleExpression
;
import
org.apache.ibatis.annotations.Select
;
import
org.apache.ibatis.annotations.Select
;
import
java.util.List
;
/**
/**
* Mapper 接口
* Mapper 接口
*
*
...
@@ -20,6 +22,12 @@ public interface IdxBizPvWarningRuleSetMapper extends BaseMapper<IdxBizPvWarning
...
@@ -20,6 +22,12 @@ public interface IdxBizPvWarningRuleSetMapper extends BaseMapper<IdxBizPvWarning
Integer
getMaxWaringCycleOfMinutesByGatewayId
(
String
gateWayId
);
Integer
getMaxWaringCycleOfMinutesByGatewayId
(
String
gateWayId
);
@Select
(
"SELECT MAX(WARNING_CYCLE) FROM idx_biz_pv_warning_rule_set WHERE ANALYSIS_TYPE = '按小时'"
)
@Select
(
"SELECT MAX(WARNING_CYCLE) FROM idx_biz_pv_warning_rule_set WHERE ANALYSIS_TYPE = '按小时'"
)
Integer
getMaxWaringCycleOfHour
();
Integer
getMaxWaringCycleOfHour
();
@Select
(
"SELECT MAX(WARNING_CYCLE) FROM idx_biz_pv_warning_rule_set WHERE ANALYSIS_TYPE = '按小时' and GATEWAY_ID = #{gateWayId}"
)
Integer
getMaxWaringCycleOfHourByGatewayId
(
String
gateWayId
);
@Select
(
"SELECT MAX(WARNING_CYCLE) FROM idx_biz_pv_warning_rule_set WHERE ANALYSIS_TYPE = '按天'"
)
@Select
(
"SELECT MAX(WARNING_CYCLE) FROM idx_biz_pv_warning_rule_set WHERE ANALYSIS_TYPE = '按天'"
)
Integer
getMaxWaringCycleOfDay
();
Integer
getMaxWaringCycleOfDay
();
@Select
(
"SELECT MAX(WARNING_CYCLE) FROM idx_biz_pv_warning_rule_set WHERE ANALYSIS_TYPE = '按天 and GATEWAY_ID = #{gateWayId}'"
)
Integer
getMaxWaringCycleOfDayByGatewayId
(
String
gateWayId
);
@Select
(
"SELECT GATEWAY_ID FROM idx_biz_pv_warning_rule_set GROUP BY GATEWAY_ID"
)
List
<
String
>
getGatewayIds
();
}
}
amos-boot-system-jxiop/amos-boot-module-jxiop-analyse-biz/src/main/java/com/yeejoin/amos/boot/module/jxiop/biz/service/impl/HealthStatusIndicatorServiceImpl.java
View file @
8fc74636
...
@@ -899,6 +899,197 @@ public class HealthStatusIndicatorServiceImpl {
...
@@ -899,6 +899,197 @@ public class HealthStatusIndicatorServiceImpl {
fetchDataPv
(
tdPvWarningRecordList
,
stationMap
);
fetchDataPv
(
tdPvWarningRecordList
,
stationMap
);
}
}
// @Scheduled(cron = "0 0 0/1 * * ?")
// @Scheduled(cron = "0 0/5 * * * ?")
@Async
(
"async"
)
public
void
healthWarningHourGFNew
()
{
if
(!
openHealth
)
{
return
;
}
Date
time
=
new
Date
();
// Date date = DateUtils.dateAddHours(time, -13);
// 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");
List
<
String
>
gateWayIds
=
idxBizPvWarningRuleSetMapper
.
getGatewayIds
();
gateWayIds
.
forEach
(
gateWayId
->
{
new
Thread
(()
->
{
Integer
maxWaringCycle
=
idxBizPvWarningRuleSetMapper
.
getMaxWaringCycleOfHourByGatewayId
(
gateWayId
)
+
AnalyseOffset
;
String
format
=
DateUtil
.
format
(
time
,
"yyyy-MM-dd HH:mm:00"
);
Date
date
=
DateUtil
.
offsetHour
(
time
,
-
8
);
date
=
DateUtil
.
offsetHour
(
date
,
0
-
maxWaringCycle
);
LambdaQueryWrapper
<
PvHealthIndexHour
>
wrapper
=
new
LambdaQueryWrapper
<>();
//wrapper.ne(PvHealthIndexHour::getHealthLevel,"安全");
wrapper
.
eq
(
PvHealthIndexHour:
:
getGatewayId
,
gateWayId
);
wrapper
.
eq
(
PvHealthIndexHour:
:
getAnalysisObjType
,
"测点"
);
wrapper
.
ge
(
PvHealthIndexHour:
:
getTs
,
date
);
Date
dateMax
=
DateUtil
.
offsetHour
(
time
,
-
8
);
wrapper
.
le
(
PvHealthIndexHour:
:
getTs
,
dateMax
);
wrapper
.
orderByAsc
(
PvHealthIndexHour:
:
getTs
);
List
<
PvHealthIndexHour
>
healthIndices
=
pvHealthIndexHourMapper
.
selectList
(
wrapper
);
List
<
String
>
collect
=
healthIndices
.
stream
().
map
(
PvHealthIndexHour:
:
getAnalysisObjSeq
).
collect
(
Collectors
.
toList
());
if
(
null
==
healthIndices
)
{
return
;
}
LambdaQueryWrapper
<
IdxBizPvWarningRuleSet
>
queryWrapper
=
new
LambdaQueryWrapper
<>();
queryWrapper
.
eq
(
IdxBizPvWarningRuleSet:
:
getAnalysisType
,
WarningPeriodEnum
.
HOUR
.
getName
());
queryWrapper
.
in
(
IdxBizPvWarningRuleSet:
:
getAnalysisPointId
,
collect
);
List
<
IdxBizPvWarningRuleSet
>
idxBizPvWarningRules
=
idxBizPvWarningRuleSetMapper
.
selectList
(
queryWrapper
);
Map
<
String
,
Map
<
String
,
List
<
PvHealthIndexHour
>>>
gateWayMaps
=
healthIndices
.
stream
().
collect
(
Collectors
.
groupingBy
(
PvHealthIndexHour:
:
getGatewayId
,
Collectors
.
groupingBy
(
PvHealthIndexHour:
:
getIndexAddress
)));
List
<
IdxBizPvWarningRecord
>
idxBizPvWarningRecordList
=
new
ArrayList
<>();
List
<
PvWarningRecord
>
tdPvWarningRecordList
=
new
ArrayList
<>();
HashMap
<
String
,
StationBasic
>
stationMap
=
new
HashMap
<>();
// for (String gateWayId : gateWayMaps.keySet()) {
LambdaQueryWrapper
<
StationBasic
>
basicLambdaQueryWrapper
=
new
LambdaQueryWrapper
<>();
basicLambdaQueryWrapper
.
eq
(
StationBasic:
:
getFanGatewayId
,
gateWayId
);
basicLambdaQueryWrapper
.
last
(
"limit 1"
);
StationBasic
stationBasic
=
stationBasicMapper
.
selectOne
(
basicLambdaQueryWrapper
);
stationMap
.
put
(
gateWayId
,
stationBasic
);
Map
<
String
,
List
<
PvHealthIndexHour
>>
healthDataMaps
=
gateWayMaps
.
get
(
gateWayId
);
for
(
String
address
:
healthDataMaps
.
keySet
())
{
List
<
PvHealthIndexHour
>
idxBizPvHealthIndices
=
healthDataMaps
.
get
(
address
);
List
<
IdxBizPvWarningRuleSet
>
idxBizPvWarningRuleSets
=
idxBizPvWarningRules
.
stream
().
filter
(
t
->
t
.
getAnalysisPointId
().
equals
(
idxBizPvHealthIndices
.
get
(
0
).
getAnalysisObjSeq
())).
collect
(
Collectors
.
toList
());
if
(
ObjectUtils
.
isEmpty
(
idxBizPvWarningRuleSets
))
{
continue
;
}
Double
healthValueWarn
=
0.0
;
Double
healthValueRisk
=
0.0
;
Double
healthValueNotice
=
0.0
;
int
healthValueWarnCount
=
0
;
int
healthValueRiskCount
=
0
;
int
healthValueNoticeCount
=
0
;
int
healthValueMinCount
=
0
;
int
riskNum
=
0
;
int
warnNum
=
0
;
int
noticeNum
=
0
;
for
(
IdxBizPvWarningRuleSet
e
:
idxBizPvWarningRuleSets
)
{
switch
(
e
.
getWarningName
())
{
case
"警告"
:
healthValueWarn
=
Double
.
parseDouble
(
e
.
getWarningIf
().
substring
(
2
));
healthValueWarnCount
=
Integer
.
parseInt
(
e
.
getWarningCycle
());
break
;
case
"危险"
:
healthValueRisk
=
Double
.
parseDouble
(
e
.
getWarningIf
().
substring
(
2
));
healthValueRiskCount
=
Integer
.
parseInt
(
e
.
getWarningCycle
());
break
;
case
"注意"
:
healthValueNotice
=
Double
.
parseDouble
(
e
.
getWarningIf
().
substring
(
2
));
healthValueNoticeCount
=
Integer
.
parseInt
(
e
.
getWarningCycle
());
break
;
}
}
List
<
Double
>
healthIndex
=
idxBizPvHealthIndices
.
stream
().
map
(
PvHealthIndexHour:
:
getHealthIndex
).
collect
(
Collectors
.
toList
());
// Double finalHealthValueRisk = healthValueRisk;
// long riskNum = healthIndex.subList(healthIndex.size()>healthValueRiskCount? (int) (healthIndex.size() - healthValueRiskCount) :0,healthIndex.size()).stream().filter(e -> e <= finalHealthValueRisk).count();
// Double finalHealthValueWarn = healthValueWarn;
// long warnNum = healthIndex.subList(healthIndex.size()>healthValueWarnCount? (int) (healthIndex.size() - healthValueWarnCount) :0,healthIndex.size()).stream().filter(e -> e <= finalHealthValueWarn).count();
// Double finalHealthValueNotice = healthValueNotice;
// long noticeNum = healthIndex.subList(healthIndex.size()>healthValueNoticeCount? (int) (healthIndex.size() - healthValueNoticeCount) :0,healthIndex.size()).stream().filter(e -> e <= finalHealthValueNotice).count();
Double
finalHealthValueRisk
=
healthValueRisk
;
if
(
healthIndex
.
size
()
>=
healthValueRiskCount
)
{
List
<
Double
>
healthIndexList
=
healthIndex
.
subList
(
healthIndex
.
size
()
-
healthValueRiskCount
,
healthIndex
.
size
());
riskNum
=
(
int
)
healthIndexList
.
stream
().
filter
(
e
->
e
<=
finalHealthValueRisk
).
count
();
}
Double
finalHealthValueWarn
=
healthValueWarn
;
if
(
healthIndex
.
size
()
>=
healthValueWarnCount
)
{
List
<
Double
>
healthIndexList
=
healthIndex
.
subList
(
healthIndex
.
size
()
-
healthValueWarnCount
,
healthIndex
.
size
());
warnNum
=
(
int
)
healthIndexList
.
stream
().
filter
(
e
->
e
<=
finalHealthValueWarn
).
count
();
}
Double
finalHealthValueNotice
=
healthValueNotice
;
if
(
healthIndex
.
size
()
>=
healthValueNoticeCount
)
{
List
<
Double
>
healthIndexList
=
healthIndex
.
subList
(
healthIndex
.
size
()
-
healthValueNoticeCount
,
healthIndex
.
size
());
noticeNum
=
(
int
)
healthIndexList
.
stream
().
filter
(
e
->
e
<=
finalHealthValueNotice
).
count
();
}
String
level
=
""
;
String
content
=
""
;
String
num
=
""
;
if
(
noticeNum
==
healthValueNoticeCount
)
{
level
=
"注意"
;
num
=
""
+
healthValueNotice
;
content
=
healthValueNoticeCount
+
"小时"
;
}
if
(
warnNum
==
healthValueWarnCount
)
{
level
=
"警告"
;
num
=
""
+
healthValueWarn
;
content
=
healthValueWarnCount
+
"小时"
;
}
if
(
riskNum
==
healthValueRiskCount
)
{
level
=
"危险"
;
num
=
""
+
healthValueRisk
;
content
=
healthValueRiskCount
+
"小时"
;
}
//库里若已存在该测点预警 不生成重复的 若新生预警等级高于历史 则生成
LambdaQueryWrapper
<
PvWarningRecord
>
query
=
new
LambdaQueryWrapper
<>();
query
.
eq
(
PvWarningRecord:
:
getAnalysisPointId
,
idxBizPvHealthIndices
.
get
(
0
).
getAnalysisObjSeq
());
query
.
eq
(
PvWarningRecord:
:
getStatus
,
"0"
);
query
.
isNull
(
PvWarningRecord:
:
getDisposotionDate
);
query
.
orderByDesc
(
PvWarningRecord:
:
getRecDate
);
List
<
PvWarningRecord
>
idxBizPvWarningRecords
=
pvWaringRecordMapper
.
selectList
(
query
);
int
flag
=
ObjectUtils
.
isEmpty
(
idxBizPvWarningRecords
)
||
WarningNameEnum
.
getCode
(
level
)
>
WarningNameEnum
.
getCode
(
idxBizPvWarningRecords
.
get
(
0
).
getWarningName
())
?
0
:
1
;
Boolean
timeFlag
=
format
.
equals
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getRecDate
());
if
(!
level
.
equals
(
""
)
&&
flag
==
0
&&
timeFlag
)
{
IdxBizPvWarningRecord
idxBizPvWarningRecord
=
new
IdxBizPvWarningRecord
();
idxBizPvWarningRecord
.
setKks
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getKks
());
idxBizPvWarningRecord
.
setArae
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getArea
());
idxBizPvWarningRecord
.
setStation
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getStation
());
idxBizPvWarningRecord
.
setSubarray
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getSubarray
());
idxBizPvWarningRecord
.
setGatewayId
(
gateWayId
);
idxBizPvWarningRecord
.
setIndexAddress
(
address
);
idxBizPvWarningRecord
.
setEquipmentName
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getEquipmentName
());
idxBizPvWarningRecord
.
setAnalysisPointId
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getAnalysisObjSeq
());
idxBizPvWarningRecord
.
setDisposotionState
(
"待确认"
);
idxBizPvWarningRecord
.
setStatus
(
"0"
);
idxBizPvWarningRecord
.
setWarningName
(
level
);
idxBizPvWarningRecord
.
setCONTENT
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getPointName
()
+
"连续"
+
content
+
"健康指数≤"
+
num
);
idxBizPvWarningRecord
.
setRecDate
(
time
);
idxBizPvWarningRecord
.
setWarningPeriod
(
WarningPeriodEnum
.
HOUR
.
getName
());
idxBizPvWarningRecord
.
setManufacturer
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getManufacturer
());
idxBizPvWarningRecord
.
setPointName
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getPointName
());
idxBizPvWarningRecord
.
setHealthIndexSeq
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getHealthIndex
().
toString
());
idxBizPvWarningRecord
.
setHealthLevel
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getHealthLevel
());
idxBizPvWarningRecordList
.
add
(
idxBizPvWarningRecord
);
//idxBizPvWarningRecordMapper.insert(idxBizPvWarningRecord);
long
currentTimeMillis
=
System
.
currentTimeMillis
();
long
nanoTime
=
System
.
nanoTime
();
long
timestamp
=
currentTimeMillis
*
1000000
+
nanoTime
%
1000000
;
PvWarningRecord
pvWarningRecord
=
new
PvWarningRecord
();
BeanUtils
.
copyProperties
(
idxBizPvWarningRecord
,
pvWarningRecord
,
"disposotionDate"
,
"recDate"
,
"CONTENT"
);
pvWarningRecord
.
setContent
(
idxBizPvWarningRecord
.
getCONTENT
());
pvWarningRecord
.
setRecDate
(
format
);
pvWarningRecord
.
setTs
(
timestamp
);
pvWarningRecord
.
setHealthIndex
(
String
.
format
(
CommonConstans
.
Onedecimalplaces
,
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getHealthIndex
()));
pvWarningRecord
.
setOrgCode
(
idxBizPvHealthIndices
.
get
(
0
).
getOrgCode
());
tdPvWarningRecordList
.
add
(
pvWarningRecord
);
}
}
// }
// idxBizPvWarningRecordService.saveBatch(idxBizPvWarningRecordList);
if
(
CollUtil
.
isNotEmpty
(
tdPvWarningRecordList
))
{
// tdengine插入
log
.
info
(
"==================光伏按小时产生预警数据成功"
,
JSON
.
toJSONString
(
tdPvWarningRecordList
));
pvWaringRecordMapper
.
saveBatchWarningRecords
(
tdPvWarningRecordList
);
}
// 触发风险模型生成预警处置模块的预警记录
fetchDataPv
(
tdPvWarningRecordList
,
stationMap
);
}).
start
();
});
}
/***
/***
* 每三天取一次最大粒度内的指数异常数据
* 每三天取一次最大粒度内的指数异常数据
* 判断三天内数据是否符合预警规则 符合则报警并在redis中缓存 同一级别的预警记录下次不生成
* 判断三天内数据是否符合预警规则 符合则报警并在redis中缓存 同一级别的预警记录下次不生成
...
@@ -1090,6 +1281,198 @@ public class HealthStatusIndicatorServiceImpl {
...
@@ -1090,6 +1281,198 @@ public class HealthStatusIndicatorServiceImpl {
fetchDataPv
(
tdPvWarningRecordList
,
stationMap
);
fetchDataPv
(
tdPvWarningRecordList
,
stationMap
);
}
}
// @Scheduled(cron = "0 0 0 0/1 * ? ")
@Async
(
"async"
)
public
void
healthWarningDayGFNew
()
{
if
(!
openHealth
)
{
return
;
}
// Calendar calendar = Calendar.getInstance();
Date
time
=
new
Date
();
//三天 + 8小时
// Date date = DateUtils.dateAddHours(time, -80);
// calendar.set(Calendar.DAY_OF_MONTH,calendar.get(Calendar.DAY_OF_MONTH)-3);
// SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
List
<
String
>
gateWayIds
=
idxBizPvWarningRuleSetMapper
.
getGatewayIds
();
gateWayIds
.
forEach
(
gateWayId
->
{
new
Thread
(()
->
{
Integer
maxWaringCycle
=
idxBizPvWarningRuleSetMapper
.
getMaxWaringCycleOfDayByGatewayId
(
gateWayId
)
+
AnalyseOffset
;
String
format
=
DateUtil
.
format
(
time
,
"yyyy-MM-dd HH:mm:00"
);
Date
date
=
DateUtil
.
offsetHour
(
time
,
-
8
);
date
=
DateUtil
.
offsetDay
(
date
,
0
-
maxWaringCycle
);
LambdaQueryWrapper
<
PvHealthIndexDay
>
wrapper
=
new
LambdaQueryWrapper
<>();
//wrapper.ne(PvHealthIndexDay::getHealthLevel, "安全");
wrapper
.
eq
(
PvHealthIndexDay:
:
getAnalysisObjType
,
"测点"
);
wrapper
.
eq
(
PvHealthIndexDay:
:
getGatewayId
,
gateWayId
);
wrapper
.
ge
(
PvHealthIndexDay:
:
getTs
,
date
);
Date
dateMax
=
DateUtil
.
offsetHour
(
time
,
-
8
);
wrapper
.
le
(
PvHealthIndexDay:
:
getTs
,
dateMax
);
wrapper
.
orderByAsc
(
PvHealthIndexDay:
:
getTs
);
List
<
PvHealthIndexDay
>
healthIndices
=
pvHealthIndexDayMapper
.
selectList
(
wrapper
);
if
(
null
==
healthIndices
)
{
return
;
}
List
<
String
>
collect
=
healthIndices
.
stream
().
map
(
PvHealthIndexDay:
:
getAnalysisObjSeq
).
collect
(
Collectors
.
toList
());
LambdaQueryWrapper
<
IdxBizPvWarningRuleSet
>
queryWrapper
=
new
LambdaQueryWrapper
<>();
queryWrapper
.
eq
(
IdxBizPvWarningRuleSet:
:
getAnalysisType
,
WarningPeriodEnum
.
DAY
.
getName
());
queryWrapper
.
in
(
IdxBizPvWarningRuleSet:
:
getAnalysisPointId
,
collect
);
List
<
IdxBizPvWarningRuleSet
>
idxBizPvWarningRules
=
idxBizPvWarningRuleSetMapper
.
selectList
(
queryWrapper
);
Map
<
String
,
Map
<
String
,
List
<
PvHealthIndexDay
>>>
gateWayMaps
=
healthIndices
.
stream
().
collect
(
Collectors
.
groupingBy
(
PvHealthIndexDay:
:
getGatewayId
,
Collectors
.
groupingBy
(
PvHealthIndexDay:
:
getIndexAddress
)));
List
<
IdxBizPvWarningRecord
>
idxBizPvWarningRecordList
=
new
ArrayList
<>();
List
<
PvWarningRecord
>
tdPvWarningRecordList
=
new
ArrayList
<>();
HashMap
<
String
,
StationBasic
>
stationMap
=
new
HashMap
<>();
// for (String gateWayId : gateWayMaps.keySet()) {
LambdaQueryWrapper
<
StationBasic
>
basicLambdaQueryWrapper
=
new
LambdaQueryWrapper
<>();
basicLambdaQueryWrapper
.
eq
(
StationBasic:
:
getFanGatewayId
,
gateWayId
);
basicLambdaQueryWrapper
.
last
(
"limit 1"
);
StationBasic
stationBasic
=
stationBasicMapper
.
selectOne
(
basicLambdaQueryWrapper
);
stationMap
.
put
(
gateWayId
,
stationBasic
);
Map
<
String
,
List
<
PvHealthIndexDay
>>
healthDataMaps
=
gateWayMaps
.
get
(
gateWayId
);
for
(
String
address
:
healthDataMaps
.
keySet
())
{
List
<
PvHealthIndexDay
>
idxBizPvHealthIndices
=
healthDataMaps
.
get
(
address
);
List
<
IdxBizPvWarningRuleSet
>
idxBizPvWarningRuleSets
=
idxBizPvWarningRules
.
stream
().
filter
(
t
->
t
.
getAnalysisPointId
().
equals
(
idxBizPvHealthIndices
.
get
(
0
).
getAnalysisObjSeq
())).
collect
(
Collectors
.
toList
());
if
(
ObjectUtils
.
isEmpty
(
idxBizPvWarningRuleSets
))
{
continue
;
}
Double
healthValueWarn
=
0.0
;
Double
healthValueRisk
=
0.0
;
Double
healthValueNotice
=
0.0
;
int
healthValueWarnCount
=
0
;
int
healthValueRiskCount
=
0
;
int
healthValueNoticeCount
=
0
;
int
healthValueMinCount
=
0
;
int
riskNum
=
0
;
int
warnNum
=
0
;
int
noticeNum
=
0
;
for
(
IdxBizPvWarningRuleSet
e
:
idxBizPvWarningRuleSets
)
{
switch
(
e
.
getWarningName
())
{
case
"警告"
:
healthValueWarn
=
Double
.
parseDouble
(
e
.
getWarningIf
().
substring
(
2
));
healthValueWarnCount
=
Integer
.
parseInt
(
e
.
getWarningCycle
());
break
;
case
"危险"
:
healthValueRisk
=
Double
.
parseDouble
(
e
.
getWarningIf
().
substring
(
2
));
healthValueRiskCount
=
Integer
.
parseInt
(
e
.
getWarningCycle
());
break
;
case
"注意"
:
healthValueNotice
=
Double
.
parseDouble
(
e
.
getWarningIf
().
substring
(
2
));
healthValueNoticeCount
=
Integer
.
parseInt
(
e
.
getWarningCycle
());
break
;
}
}
List
<
Double
>
healthIndex
=
idxBizPvHealthIndices
.
stream
().
map
(
PvHealthIndexDay:
:
getHealthIndex
).
collect
(
Collectors
.
toList
());
// Double finalHealthValueRisk = healthValueRisk;
// long riskNum = healthIndex.subList(healthIndex.size()>healthValueRiskCount? (int) (healthIndex.size() - healthValueRiskCount) :0,healthIndex.size()).stream().filter(e -> e <= finalHealthValueRisk).count();
// Double finalHealthValueWarn = healthValueWarn;
// long warnNum = healthIndex.subList(healthIndex.size()>healthValueWarnCount? (int) (healthIndex.size() - healthValueWarnCount) :0,healthIndex.size()).stream().filter(e -> e <= finalHealthValueWarn).count();
// Double finalHealthValueNotice = healthValueNotice;
// long noticeNum = healthIndex.subList(healthIndex.size()>healthValueNoticeCount? (int) (healthIndex.size() - healthValueNoticeCount) :0,healthIndex.size()).stream().filter(e -> e <= finalHealthValueNotice).count();
Double
finalHealthValueRisk
=
healthValueRisk
;
if
(
healthIndex
.
size
()
>=
healthValueRiskCount
)
{
List
<
Double
>
healthIndexList
=
healthIndex
.
subList
(
healthIndex
.
size
()
-
healthValueRiskCount
,
healthIndex
.
size
());
riskNum
=
(
int
)
healthIndexList
.
stream
().
filter
(
e
->
e
<=
finalHealthValueRisk
).
count
();
}
Double
finalHealthValueWarn
=
healthValueWarn
;
if
(
healthIndex
.
size
()
>=
healthValueWarnCount
)
{
List
<
Double
>
healthIndexList
=
healthIndex
.
subList
(
healthIndex
.
size
()
-
healthValueWarnCount
,
healthIndex
.
size
());
warnNum
=
(
int
)
healthIndexList
.
stream
().
filter
(
e
->
e
<=
finalHealthValueWarn
).
count
();
}
Double
finalHealthValueNotice
=
healthValueNotice
;
if
(
healthIndex
.
size
()
>=
healthValueNoticeCount
)
{
List
<
Double
>
healthIndexList
=
healthIndex
.
subList
(
healthIndex
.
size
()
-
healthValueNoticeCount
,
healthIndex
.
size
());
noticeNum
=
(
int
)
healthIndexList
.
stream
().
filter
(
e
->
e
<=
finalHealthValueNotice
).
count
();
}
String
level
=
""
;
String
content
=
""
;
String
num
=
""
;
if
(
noticeNum
==
healthValueNoticeCount
)
{
// redisUtils.set(gateWayId+"_"+address+"_health_notice_day","notice");
level
=
"注意"
;
num
=
""
+
healthValueNotice
;
content
=
healthValueNoticeCount
+
"天"
;
}
if
(
warnNum
==
healthValueWarnCount
)
{
// redisUtils.set(gateWayId+"_"+address+"_health_warn_day","warn");
level
=
"警告"
;
num
=
""
+
healthValueWarn
;
content
=
healthValueWarnCount
+
"天"
;
}
if
(
riskNum
==
healthValueRiskCount
)
{
// redisUtils.set(gateWayId+"_"+address+"_health_risk_day","risk");
level
=
"危险"
;
num
=
""
+
healthValueRisk
;
content
=
healthValueRiskCount
+
"天"
;
}
//库里若已存在该测点预警 不生成重复的 若新生预警等级高于历史 则生成
LambdaQueryWrapper
<
PvWarningRecord
>
query
=
new
LambdaQueryWrapper
<>();
query
.
eq
(
PvWarningRecord:
:
getAnalysisPointId
,
idxBizPvHealthIndices
.
get
(
0
).
getAnalysisObjSeq
());
query
.
eq
(
PvWarningRecord:
:
getStatus
,
"0"
);
query
.
isNull
(
PvWarningRecord:
:
getDisposotionDate
);
query
.
orderByDesc
(
PvWarningRecord:
:
getTs
);
List
<
PvWarningRecord
>
idxBizPvWarningRecords
=
pvWaringRecordMapper
.
selectList
(
query
);
int
flag
=
ObjectUtils
.
isEmpty
(
idxBizPvWarningRecords
)
||
WarningNameEnum
.
getCode
(
level
)
>
WarningNameEnum
.
getCode
(
idxBizPvWarningRecords
.
get
(
0
).
getWarningName
())
?
0
:
1
;
Boolean
timeFlag
=
format
.
equals
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getRecDate
());
if
(!
level
.
equals
(
""
)
&&
flag
==
0
&&
timeFlag
)
{
IdxBizPvWarningRecord
idxBizPvWarningRecord
=
new
IdxBizPvWarningRecord
();
idxBizPvWarningRecord
.
setKks
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getKks
());
idxBizPvWarningRecord
.
setArae
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getArea
());
idxBizPvWarningRecord
.
setStation
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getStation
());
idxBizPvWarningRecord
.
setSubarray
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getSubarray
());
idxBizPvWarningRecord
.
setGatewayId
(
gateWayId
);
idxBizPvWarningRecord
.
setIndexAddress
(
address
);
idxBizPvWarningRecord
.
setEquipmentName
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getEquipmentName
());
idxBizPvWarningRecord
.
setAnalysisPointId
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getAnalysisObjSeq
());
idxBizPvWarningRecord
.
setDisposotionState
(
"待确认"
);
idxBizPvWarningRecord
.
setStatus
(
"0"
);
idxBizPvWarningRecord
.
setWarningName
(
level
);
idxBizPvWarningRecord
.
setCONTENT
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getPointName
()
+
"连续"
+
content
+
"健康指数≤"
+
num
);
idxBizPvWarningRecord
.
setRecDate
(
time
);
idxBizPvWarningRecord
.
setWarningPeriod
(
WarningPeriodEnum
.
DAY
.
getName
());
idxBizPvWarningRecord
.
setManufacturer
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getManufacturer
());
idxBizPvWarningRecord
.
setPointName
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getPointName
());
idxBizPvWarningRecord
.
setHealthIndexSeq
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getHealthIndex
().
toString
());
idxBizPvWarningRecord
.
setHealthLevel
(
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getHealthLevel
());
idxBizPvWarningRecordList
.
add
(
idxBizPvWarningRecord
);
//idxBizPvWarningRecordMapper.insert(idxBizPvWarningRecord);
long
currentTimeMillis
=
System
.
currentTimeMillis
();
long
nanoTime
=
System
.
nanoTime
();
long
timestamp
=
currentTimeMillis
*
1000000
+
nanoTime
%
1000000
;
PvWarningRecord
pvWarningRecord
=
new
PvWarningRecord
();
BeanUtils
.
copyProperties
(
idxBizPvWarningRecord
,
pvWarningRecord
,
"disposotionDate"
,
"recDate"
,
"CONTENT"
);
pvWarningRecord
.
setContent
(
idxBizPvWarningRecord
.
getCONTENT
());
pvWarningRecord
.
setRecDate
(
format
);
pvWarningRecord
.
setTs
(
timestamp
);
pvWarningRecord
.
setHealthIndex
(
String
.
format
(
CommonConstans
.
Onedecimalplaces
,
idxBizPvHealthIndices
.
get
(
idxBizPvHealthIndices
.
size
()
-
1
).
getHealthIndex
()));
pvWarningRecord
.
setOrgCode
(
idxBizPvHealthIndices
.
get
(
0
).
getOrgCode
());
tdPvWarningRecordList
.
add
(
pvWarningRecord
);
}
}
// }
// idxBizPvWarningRecordService.saveBatch(idxBizPvWarningRecordList);
if
(
CollUtil
.
isNotEmpty
(
tdPvWarningRecordList
))
{
log
.
info
(
"==================光伏按天产生预警数据成功"
,
JSON
.
toJSONString
(
tdPvWarningRecordList
));
// tdengine插入
pvWaringRecordMapper
.
saveBatchWarningRecords
(
tdPvWarningRecordList
);
}
// 触发风险模型生成预警处置模块的预警记录
fetchDataPv
(
tdPvWarningRecordList
,
stationMap
);
}).
start
();
});
}
// @Scheduled(cron = "0 0 */1 * * ?")
// @Scheduled(cron = "0 0 */1 * * ?")
@Async
(
"async"
)
@Async
(
"async"
)
//@PostConstruct
//@PostConstruct
...
@@ -1349,146 +1732,146 @@ public class HealthStatusIndicatorServiceImpl {
...
@@ -1349,146 +1732,146 @@ public class HealthStatusIndicatorServiceImpl {
HashMap
<
String
,
StationBasic
>
stationMap
=
new
HashMap
<>();
HashMap
<
String
,
StationBasic
>
stationMap
=
new
HashMap
<>();
// for (String gateWayId : gateWayMaps.keySet()) {
// for (String gateWayId : gateWayMaps.keySet()) {
LambdaQueryWrapper
<
StationBasic
>
basicLambdaQueryWrapper
=
new
LambdaQueryWrapper
<>();
LambdaQueryWrapper
<
StationBasic
>
basicLambdaQueryWrapper
=
new
LambdaQueryWrapper
<>();
basicLambdaQueryWrapper
.
eq
(
StationBasic:
:
getFanGatewayId
,
gatewayId
);
basicLambdaQueryWrapper
.
eq
(
StationBasic:
:
getFanGatewayId
,
gatewayId
);
basicLambdaQueryWrapper
.
last
(
"limit 1"
);
basicLambdaQueryWrapper
.
last
(
"limit 1"
);
StationBasic
stationBasic
=
stationBasicMapper
.
selectOne
(
basicLambdaQueryWrapper
);
StationBasic
stationBasic
=
stationBasicMapper
.
selectOne
(
basicLambdaQueryWrapper
);
stationMap
.
put
(
gatewayId
,
stationBasic
);
stationMap
.
put
(
gatewayId
,
stationBasic
);
Map
<
String
,
List
<
FanHealthIndexMoment
>>
healthDataMaps
=
gateWayMaps
.
get
(
gatewayId
);
Map
<
String
,
List
<
FanHealthIndexMoment
>>
healthDataMaps
=
gateWayMaps
.
get
(
gatewayId
);
for
(
String
address
:
healthDataMaps
.
keySet
())
{
for
(
String
address
:
healthDataMaps
.
keySet
())
{
//获取指定测点的健康指数列表
//获取指定测点的健康指数列表
List
<
FanHealthIndexMoment
>
idxBizFanHealthIndices
=
healthDataMaps
.
get
(
address
);
List
<
FanHealthIndexMoment
>
idxBizFanHealthIndices
=
healthDataMaps
.
get
(
address
);
List
<
IdxBizFanWarningRuleSet
>
idxBizPvWarningRuleSets
=
idxBizPvWarningRules
.
stream
().
filter
(
t
->
t
.
getAnalysisPointId
().
equals
(
idxBizFanHealthIndices
.
get
(
0
).
getAnalysisObjSeq
())).
collect
(
Collectors
.
toList
());
if
(
ObjectUtils
.
isEmpty
(
idxBizPvWarningRuleSets
))
{
List
<
IdxBizFanWarningRuleSet
>
idxBizPvWarningRuleSets
=
idxBizPvWarningRules
.
stream
().
filter
(
t
->
t
.
getAnalysisPointId
().
equals
(
idxBizFanHealthIndices
.
get
(
0
).
getAnalysisObjSeq
())).
collect
(
Collectors
.
toList
());
continue
;
}
Double
healthValueWarn
=
0.0
;
if
(
ObjectUtils
.
isEmpty
(
idxBizPvWarningRuleSets
))
{
Double
healthValueRisk
=
0.0
;
continue
;
Double
healthValueNotice
=
0.0
;
}
int
healthValueWarnCount
=
0
;
Double
healthValueWarn
=
0.0
;
int
healthValueRiskCount
=
0
;
Double
healthValueRisk
=
0.0
;
int
healthValueNoticeCount
=
0
;
Double
healthValueNotice
=
0.0
;
int
healthValueMinCount
=
0
;
int
riskNum
=
0
;
int
warnNum
=
0
;
int
noticeNum
=
0
;
int
healthValueWarnCount
=
0
;
int
healthValueRiskCount
=
0
;
int
healthValueNoticeCount
=
0
;
int
healthValueMinCount
=
0
;
int
riskNum
=
0
;
int
warnNum
=
0
;
int
noticeNum
=
0
;
for
(
IdxBizFanWarningRuleSet
e
:
idxBizPvWarningRuleSets
)
{
switch
(
e
.
getWarningName
())
{
case
"警告"
:
healthValueWarn
=
Double
.
parseDouble
(
e
.
getWarningIf
().
substring
(
2
));
healthValueWarnCount
=
Integer
.
parseInt
(
e
.
getWarningCycle
());
break
;
case
"危险"
:
healthValueRisk
=
Double
.
parseDouble
(
e
.
getWarningIf
().
substring
(
2
));
healthValueRiskCount
=
Integer
.
parseInt
(
e
.
getWarningCycle
());
break
;
case
"注意"
:
healthValueNotice
=
Double
.
parseDouble
(
e
.
getWarningIf
().
substring
(
2
));
healthValueNoticeCount
=
Integer
.
parseInt
(
e
.
getWarningCycle
());
break
;
}
for
(
IdxBizFanWarningRuleSet
e
:
idxBizPvWarningRuleSets
)
{
switch
(
e
.
getWarningName
())
{
case
"警告"
:
healthValueWarn
=
Double
.
parseDouble
(
e
.
getWarningIf
().
substring
(
2
));
healthValueWarnCount
=
Integer
.
parseInt
(
e
.
getWarningCycle
());
break
;
case
"危险"
:
healthValueRisk
=
Double
.
parseDouble
(
e
.
getWarningIf
().
substring
(
2
));
healthValueRiskCount
=
Integer
.
parseInt
(
e
.
getWarningCycle
());
break
;
case
"注意"
:
healthValueNotice
=
Double
.
parseDouble
(
e
.
getWarningIf
().
substring
(
2
));
healthValueNoticeCount
=
Integer
.
parseInt
(
e
.
getWarningCycle
());
break
;
}
}
}
//获取指定测点的健康指数列表
List
<
Double
>
healthIndex
=
idxBizFanHealthIndices
.
stream
().
map
(
FanHealthIndexMoment:
:
getHealthIndex
).
collect
(
Collectors
.
toList
());
//获取指定测点的健康指数列表
List
<
Double
>
healthIndex
=
idxBizFanHealthIndices
.
stream
().
map
(
FanHealthIndexMoment:
:
getHealthIndex
).
collect
(
Collectors
.
toList
());
// Double finalHealthValueRisk = healthValueRisk;
// Double finalHealthValueRisk = healthValueRisk;
// long riskNum = healthIndex.subList(healthIndex.size()>healthValueRiskCount? (int) (healthIndex.size() - healthValueRiskCount) :0,healthIndex.size()).stream().filter(e -> e <= finalHealthValueRisk).count();
// long riskNum = healthIndex.subList(healthIndex.size()>healthValueRiskCount? (int) (healthIndex.size() - healthValueRiskCount) :0,healthIndex.size()).stream().filter(e -> e <= finalHealthValueRisk).count();
// Double finalHealthValueWarn = healthValueWarn;
// Double finalHealthValueWarn = healthValueWarn;
// long warnNum = healthIndex.subList(healthIndex.size()>healthValueWarnCount? (int) (healthIndex.size() - healthValueWarnCount) :0,healthIndex.size()).stream().filter(e -> e <= finalHealthValueWarn).count();
// long warnNum = healthIndex.subList(healthIndex.size()>healthValueWarnCount? (int) (healthIndex.size() - healthValueWarnCount) :0,healthIndex.size()).stream().filter(e -> e <= finalHealthValueWarn).count();
// Double finalHealthValueNotice = healthValueNotice;
// Double finalHealthValueNotice = healthValueNotice;
// long noticeNum = healthIndex.subList(healthIndex.size()>healthValueNoticeCount? (int) (healthIndex.size() - healthValueNoticeCount) :0,healthIndex.size()).stream().filter(e -> e <= finalHealthValueNotice).count();
// long noticeNum = healthIndex.subList(healthIndex.size()>healthValueNoticeCount? (int) (healthIndex.size() - healthValueNoticeCount) :0,healthIndex.size()).stream().filter(e -> e <= finalHealthValueNotice).count();
Double
finalHealthValueRisk
=
healthValueRisk
;
Double
finalHealthValueRisk
=
healthValueRisk
;
if
(
healthIndex
.
size
()
>=
healthValueRiskCount
)
{
if
(
healthIndex
.
size
()
>=
healthValueRiskCount
)
{
List
<
Double
>
healthIndexList
=
healthIndex
.
subList
(
healthIndex
.
size
()
-
healthValueRiskCount
,
healthIndex
.
size
());
List
<
Double
>
healthIndexList
=
healthIndex
.
subList
(
healthIndex
.
size
()
-
healthValueRiskCount
,
healthIndex
.
size
());
riskNum
=
(
int
)
healthIndexList
.
stream
().
filter
(
e
->
e
<=
finalHealthValueRisk
).
count
();
riskNum
=
(
int
)
healthIndexList
.
stream
().
filter
(
e
->
e
<=
finalHealthValueRisk
).
count
();
}
}
Double
finalHealthValueWarn
=
healthValueWarn
;
Double
finalHealthValueWarn
=
healthValueWarn
;
if
(
healthIndex
.
size
()
>=
healthValueWarnCount
)
{
if
(
healthIndex
.
size
()
>=
healthValueWarnCount
)
{
List
<
Double
>
healthIndexList
=
healthIndex
.
subList
(
healthIndex
.
size
()
-
healthValueWarnCount
,
healthIndex
.
size
());
List
<
Double
>
healthIndexList
=
healthIndex
.
subList
(
healthIndex
.
size
()
-
healthValueWarnCount
,
healthIndex
.
size
());
warnNum
=
(
int
)
healthIndexList
.
stream
().
filter
(
e
->
e
<=
finalHealthValueWarn
).
count
();
warnNum
=
(
int
)
healthIndexList
.
stream
().
filter
(
e
->
e
<=
finalHealthValueWarn
).
count
();
}
}
Double
finalHealthValueNotice
=
healthValueNotice
;
Double
finalHealthValueNotice
=
healthValueNotice
;
if
(
healthIndex
.
size
()
>=
healthValueNoticeCount
)
{
if
(
healthIndex
.
size
()
>=
healthValueNoticeCount
)
{
List
<
Double
>
healthIndexList
=
healthIndex
.
subList
(
healthIndex
.
size
()
-
healthValueNoticeCount
,
healthIndex
.
size
());
List
<
Double
>
healthIndexList
=
healthIndex
.
subList
(
healthIndex
.
size
()
-
healthValueNoticeCount
,
healthIndex
.
size
());
noticeNum
=
(
int
)
healthIndexList
.
stream
().
filter
(
e
->
e
<=
finalHealthValueNotice
).
count
();
noticeNum
=
(
int
)
healthIndexList
.
stream
().
filter
(
e
->
e
<=
finalHealthValueNotice
).
count
();
}
}
String
level
=
""
;
String
level
=
""
;
String
content
=
""
;
String
content
=
""
;
String
num
=
""
;
String
num
=
""
;
if
(
noticeNum
==
healthValueNoticeCount
)
{
if
(
noticeNum
==
healthValueNoticeCount
)
{
// redisUtils.set(gateWayId+"_"+address+"_health_notice_day","notice");
// redisUtils.set(gateWayId+"_"+address+"_health_notice_day","notice");
level
=
"注意"
;
level
=
"注意"
;
num
=
""
+
healthValueNotice
;
num
=
""
+
healthValueNotice
;
content
=
healthValueNoticeCount
*
10
+
"分钟"
;
content
=
healthValueNoticeCount
*
10
+
"分钟"
;
}
}
if
(
warnNum
==
healthValueWarnCount
)
{
if
(
warnNum
==
healthValueWarnCount
)
{
// redisUtils.set(gateWayId+"_"+address+"_health_warn_day","warn");
// redisUtils.set(gateWayId+"_"+address+"_health_warn_day","warn");
level
=
"警告"
;
level
=
"警告"
;
num
=
""
+
healthValueWarn
;
num
=
""
+
healthValueWarn
;
content
=
healthValueWarnCount
*
10
+
"分钟"
;
content
=
healthValueWarnCount
*
10
+
"分钟"
;
}
}
if
(
riskNum
==
healthValueRiskCount
)
{
if
(
riskNum
==
healthValueRiskCount
)
{
// redisUtils.set(gateWayId+"_"+address+"_health_risk_day","risk");
// redisUtils.set(gateWayId+"_"+address+"_health_risk_day","risk");
level
=
"危险"
;
level
=
"危险"
;
num
=
""
+
healthValueRisk
;
num
=
""
+
healthValueRisk
;
content
=
healthValueRiskCount
*
10
+
"分钟"
;
content
=
healthValueRiskCount
*
10
+
"分钟"
;
}
}
//库里若已存在该测点预警 不生成重复的 若新生预警等级高于历史 则生成
//库里若已存在该测点预警 不生成重复的 若新生预警等级高于历史 则生成
LambdaQueryWrapper
<
FanWarningRecord
>
query
=
new
LambdaQueryWrapper
<>();
LambdaQueryWrapper
<
FanWarningRecord
>
query
=
new
LambdaQueryWrapper
<>();
query
.
eq
(
FanWarningRecord:
:
getAnalysisPointId
,
idxBizFanHealthIndices
.
get
(
0
).
getAnalysisObjSeq
());
query
.
eq
(
FanWarningRecord:
:
getAnalysisPointId
,
idxBizFanHealthIndices
.
get
(
0
).
getAnalysisObjSeq
());
query
.
eq
(
FanWarningRecord:
:
getStatus
,
"0"
);
query
.
eq
(
FanWarningRecord:
:
getStatus
,
"0"
);
query
.
isNull
(
FanWarningRecord:
:
getDisposotionDate
);
query
.
isNull
(
FanWarningRecord:
:
getDisposotionDate
);
query
.
orderByDesc
(
FanWarningRecord:
:
getTs
);
query
.
orderByDesc
(
FanWarningRecord:
:
getTs
);
List
<
FanWarningRecord
>
idxBizFanWarningRecords
=
fanWaringRecordMapper
.
selectList
(
query
);
List
<
FanWarningRecord
>
idxBizFanWarningRecords
=
fanWaringRecordMapper
.
selectList
(
query
);
int
flag
=
ObjectUtils
.
isEmpty
(
idxBizFanWarningRecords
)
||
WarningNameEnum
.
getCode
(
level
)
>
WarningNameEnum
.
getCode
(
idxBizFanWarningRecords
.
get
(
0
).
getWarningName
())
?
0
:
1
;
int
flag
=
ObjectUtils
.
isEmpty
(
idxBizFanWarningRecords
)
||
WarningNameEnum
.
getCode
(
level
)
>
WarningNameEnum
.
getCode
(
idxBizFanWarningRecords
.
get
(
0
).
getWarningName
())
?
0
:
1
;
Boolean
timeFlag
=
format
.
equals
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getRecDate
());
Boolean
timeFlag
=
format
.
equals
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getRecDate
());
if
(!
level
.
equals
(
""
)
&&
flag
==
0
&&
timeFlag
)
{
if
(!
level
.
equals
(
""
)
&&
flag
==
0
&&
timeFlag
)
{
IdxBizFanWarningRecord
idxBizFanWarningRecord
=
new
IdxBizFanWarningRecord
();
IdxBizFanWarningRecord
idxBizFanWarningRecord
=
new
IdxBizFanWarningRecord
();
idxBizFanWarningRecord
.
setKks
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getKks
());
idxBizFanWarningRecord
.
setKks
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getKks
());
idxBizFanWarningRecord
.
setArae
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getArea
());
idxBizFanWarningRecord
.
setArae
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getArea
());
idxBizFanWarningRecord
.
setStation
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getStation
());
idxBizFanWarningRecord
.
setStation
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getStation
());
idxBizFanWarningRecord
.
setSubSystem
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getSubSystem
());
idxBizFanWarningRecord
.
setSubSystem
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getSubSystem
());
idxBizFanWarningRecord
.
setGatewayId
(
gatewayId
);
idxBizFanWarningRecord
.
setGatewayId
(
gatewayId
);
idxBizFanWarningRecord
.
setIndexAddress
(
address
);
idxBizFanWarningRecord
.
setIndexAddress
(
address
);
idxBizFanWarningRecord
.
setEquipmentName
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getEquipmentName
());
idxBizFanWarningRecord
.
setEquipmentName
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getEquipmentName
());
idxBizFanWarningRecord
.
setAnalysisPointId
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getAnalysisObjSeq
());
idxBizFanWarningRecord
.
setAnalysisPointId
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getAnalysisObjSeq
());
idxBizFanWarningRecord
.
setDisposotionState
(
"待确认"
);
idxBizFanWarningRecord
.
setDisposotionState
(
"待确认"
);
idxBizFanWarningRecord
.
setStatus
(
"0"
);
idxBizFanWarningRecord
.
setStatus
(
"0"
);
idxBizFanWarningRecord
.
setWarningName
(
level
);
idxBizFanWarningRecord
.
setWarningName
(
level
);
idxBizFanWarningRecord
.
setCONTENT
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getPointName
()
+
"连续"
+
content
+
"健康指数≤"
+
num
);
idxBizFanWarningRecord
.
setCONTENT
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getPointName
()
+
"连续"
+
content
+
"健康指数≤"
+
num
);
idxBizFanWarningRecord
.
setRecDate
(
time
);
idxBizFanWarningRecord
.
setRecDate
(
time
);
idxBizFanWarningRecord
.
setWarningPeriod
(
WarningPeriodEnum
.
MINUTES
.
getName
());
idxBizFanWarningRecord
.
setWarningPeriod
(
WarningPeriodEnum
.
MINUTES
.
getName
());
idxBizFanWarningRecord
.
setNumber
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getNumber
());
idxBizFanWarningRecord
.
setNumber
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getNumber
());
idxBizFanWarningRecord
.
setPointName
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getPointName
());
idxBizFanWarningRecord
.
setPointName
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getPointName
());
idxBizFanWarningRecord
.
setHealthIndexSeq
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getHealthIndex
().
toString
());
idxBizFanWarningRecord
.
setHealthIndexSeq
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getHealthIndex
().
toString
());
idxBizFanWarningRecord
.
setHealthLevel
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getHealthLevel
());
idxBizFanWarningRecord
.
setHealthLevel
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getHealthLevel
());
idxBizFanWarningRecordList
.
add
(
idxBizFanWarningRecord
);
idxBizFanWarningRecordList
.
add
(
idxBizFanWarningRecord
);
//idxBizFanWarningRecordMapper.insert(idxBizFanWarningRecord);
//idxBizFanWarningRecordMapper.insert(idxBizFanWarningRecord);
long
currentTimeMillis
=
System
.
currentTimeMillis
();
long
currentTimeMillis
=
System
.
currentTimeMillis
();
long
nanoTime
=
System
.
nanoTime
();
long
nanoTime
=
System
.
nanoTime
();
long
timestamp
=
currentTimeMillis
*
1000000
+
nanoTime
%
1000000
;
long
timestamp
=
currentTimeMillis
*
1000000
+
nanoTime
%
1000000
;
FanWarningRecord
fanWarningRecord
=
new
FanWarningRecord
();
FanWarningRecord
fanWarningRecord
=
new
FanWarningRecord
();
BeanUtils
.
copyProperties
(
idxBizFanWarningRecord
,
fanWarningRecord
,
"disposotionDate"
,
"recDate"
,
"CONTENT"
);
BeanUtils
.
copyProperties
(
idxBizFanWarningRecord
,
fanWarningRecord
,
"disposotionDate"
,
"recDate"
,
"CONTENT"
);
fanWarningRecord
.
setContent
(
idxBizFanWarningRecord
.
getCONTENT
());
fanWarningRecord
.
setContent
(
idxBizFanWarningRecord
.
getCONTENT
());
fanWarningRecord
.
setRecDate
(
format
);
fanWarningRecord
.
setRecDate
(
format
);
fanWarningRecord
.
setTs
(
timestamp
);
fanWarningRecord
.
setTs
(
timestamp
);
fanWarningRecord
.
setHealthIndex
(
String
.
format
(
CommonConstans
.
Onedecimalplaces
,
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getHealthIndex
()));
fanWarningRecord
.
setHealthIndex
(
String
.
format
(
CommonConstans
.
Onedecimalplaces
,
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getHealthIndex
()));
fanWarningRecord
.
setOrgCode
(
idxBizFanHealthIndices
.
get
(
0
).
getOrgCode
());
fanWarningRecord
.
setOrgCode
(
idxBizFanHealthIndices
.
get
(
0
).
getOrgCode
());
tdFanWarningRecordList
.
add
(
fanWarningRecord
);
tdFanWarningRecordList
.
add
(
fanWarningRecord
);
}
}
}
}
// }
// }
// idxBizFanWarningRecordService.saveBatch(idxBizFanWarningRecordList);
// idxBizFanWarningRecordService.saveBatch(idxBizFanWarningRecordList);
...
@@ -1692,6 +2075,198 @@ public class HealthStatusIndicatorServiceImpl {
...
@@ -1692,6 +2075,198 @@ public class HealthStatusIndicatorServiceImpl {
fetchDataFan
(
tdFanWarningRecordList
,
stationMap
);
fetchDataFan
(
tdFanWarningRecordList
,
stationMap
);
}
}
// @Scheduled(cron = "0 0 0/1 * * ?")
@Async
(
"async"
)
public
void
healthWarningHourNew
()
{
if
(!
openHealth
)
{
return
;
}
Date
time
=
new
Date
();
String
format
=
DateUtil
.
format
(
time
,
"yyyy-MM-dd HH:00:00"
);
// Date date = DateUtils.dateAddHours(time, -13);
// 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");
List
<
String
>
gateWayIds
=
idxBizFanWarningRuleSetMapper
.
getGatewayIds
();
gateWayIds
.
forEach
(
gateWayId
->
{
new
Thread
(()
->
{
Integer
maxWaringCycle
=
idxBizFanWarningRuleSetMapper
.
getMaxWaringCycleOfHourByGatewayId
(
gateWayId
);
Date
date
=
DateUtil
.
offsetHour
(
time
,
-
8
);
date
=
DateUtil
.
offsetHour
(
date
,
0
-
(
maxWaringCycle
));
LambdaQueryWrapper
<
FanHealthIndexHour
>
wrapper
=
new
LambdaQueryWrapper
<>();
wrapper
.
eq
(
FanHealthIndexHour:
:
getAnalysisObjType
,
"测点"
);
wrapper
.
eq
(
FanHealthIndexHour:
:
getGatewayId
,
gateWayId
);
//wrapper.ne(FanHealthIndexHour::getHealthLevel, "安全");
wrapper
.
ge
(
FanHealthIndexHour:
:
getTs
,
date
);
Date
dateMax
=
DateUtil
.
offsetHour
(
time
,
-
8
);
wrapper
.
le
(
FanHealthIndexHour:
:
getTs
,
dateMax
);
wrapper
.
orderByAsc
(
FanHealthIndexHour:
:
getTs
);
List
<
FanHealthIndexHour
>
healthIndices
=
fanHealthIndexHourMapper
.
selectList
(
wrapper
);
if
(
ObjectUtils
.
isEmpty
(
healthIndices
))
{
return
;
}
List
<
String
>
collect
=
healthIndices
.
stream
().
map
(
FanHealthIndexHour:
:
getAnalysisObjSeq
).
collect
(
Collectors
.
toList
());
LambdaQueryWrapper
<
IdxBizFanWarningRuleSet
>
queryWrapper
=
new
LambdaQueryWrapper
<>();
queryWrapper
.
eq
(
IdxBizFanWarningRuleSet:
:
getAnalysisType
,
WarningPeriodEnum
.
HOUR
.
getName
());
queryWrapper
.
in
(
IdxBizFanWarningRuleSet:
:
getAnalysisPointId
,
collect
);
List
<
IdxBizFanWarningRuleSet
>
idxBizPvWarningRules
=
idxBizFanWarningRuleSetMapper
.
selectList
(
queryWrapper
);
Map
<
String
,
Map
<
String
,
List
<
FanHealthIndexHour
>>>
gateWayMaps
=
healthIndices
.
stream
().
collect
(
Collectors
.
groupingBy
(
FanHealthIndexHour:
:
getGatewayId
,
Collectors
.
groupingBy
(
FanHealthIndexHour:
:
getIndexAddress
)));
List
<
IdxBizFanWarningRecord
>
idxBizFanWarningRecordList
=
new
ArrayList
<>();
List
<
FanWarningRecord
>
tdFanWarningRecordList
=
new
ArrayList
<>();
HashMap
<
String
,
StationBasic
>
stationMap
=
new
HashMap
<>();
// for (String gateWayId : gateWayMaps.keySet()) {
LambdaQueryWrapper
<
StationBasic
>
basicLambdaQueryWrapper
=
new
LambdaQueryWrapper
<>();
basicLambdaQueryWrapper
.
eq
(
StationBasic:
:
getFanGatewayId
,
gateWayId
);
basicLambdaQueryWrapper
.
last
(
"limit 1"
);
StationBasic
stationBasic
=
stationBasicMapper
.
selectOne
(
basicLambdaQueryWrapper
);
stationMap
.
put
(
gateWayId
,
stationBasic
);
Map
<
String
,
List
<
FanHealthIndexHour
>>
healthDataMaps
=
gateWayMaps
.
get
(
gateWayId
);
for
(
String
address
:
healthDataMaps
.
keySet
())
{
List
<
FanHealthIndexHour
>
idxBizFanHealthIndices
=
healthDataMaps
.
get
(
address
);
List
<
IdxBizFanWarningRuleSet
>
idxBizPvWarningRuleSets
=
idxBizPvWarningRules
.
stream
().
filter
(
t
->
t
.
getAnalysisPointId
().
equals
(
idxBizFanHealthIndices
.
get
(
0
).
getAnalysisObjSeq
())).
collect
(
Collectors
.
toList
());
if
(
ObjectUtils
.
isEmpty
(
idxBizPvWarningRuleSets
))
{
continue
;
}
Double
healthValueWarn
=
0.0
;
Double
healthValueRisk
=
0.0
;
Double
healthValueNotice
=
0.0
;
// long healthValueNoticeCount = 0;
// long healthValueRiskCount = 0;
// long healthValueWarnCount = 0;
int
healthValueWarnCount
=
0
;
int
healthValueRiskCount
=
0
;
int
healthValueNoticeCount
=
0
;
int
healthValueMinCount
=
0
;
int
riskNum
=
0
;
int
warnNum
=
0
;
int
noticeNum
=
0
;
for
(
IdxBizFanWarningRuleSet
e
:
idxBizPvWarningRuleSets
)
{
switch
(
e
.
getWarningName
())
{
case
"警告"
:
healthValueWarn
=
Double
.
parseDouble
(
e
.
getWarningIf
().
substring
(
2
));
healthValueWarnCount
=
Integer
.
parseInt
(
e
.
getWarningCycle
());
break
;
case
"危险"
:
healthValueRisk
=
Double
.
parseDouble
(
e
.
getWarningIf
().
substring
(
2
));
healthValueRiskCount
=
Integer
.
parseInt
(
e
.
getWarningCycle
());
break
;
case
"注意"
:
healthValueNotice
=
Double
.
parseDouble
(
e
.
getWarningIf
().
substring
(
2
));
healthValueNoticeCount
=
Integer
.
parseInt
(
e
.
getWarningCycle
());
break
;
}
}
List
<
Double
>
healthIndex
=
idxBizFanHealthIndices
.
stream
().
map
(
FanHealthIndexHour:
:
getHealthIndex
).
collect
(
Collectors
.
toList
());
// Double finalHealthValueRisk = healthValueRisk;
// long riskNum = healthIndex.subList(healthIndex.size()>healthValueRiskCount? (int) (healthIndex.size() - healthValueRiskCount) :0,healthIndex.size()).stream().filter(e -> e <= finalHealthValueRisk).count();
// Double finalHealthValueWarn = healthValueWarn;
// long warnNum = healthIndex.subList(healthIndex.size()>healthValueWarnCount? (int) (healthIndex.size() - healthValueWarnCount) :0,healthIndex.size()).stream().filter(e -> e <= finalHealthValueWarn).count();
// Double finalHealthValueNotice = healthValueNotice;
// long noticeNum = healthIndex.subList(healthIndex.size()>healthValueNoticeCount? (int) (healthIndex.size() - healthValueNoticeCount) :0,healthIndex.size()).stream().filter(e -> e <= finalHealthValueNotice).count();
Double
finalHealthValueRisk
=
healthValueRisk
;
if
(
healthIndex
.
size
()
>=
healthValueRiskCount
)
{
List
<
Double
>
healthIndexList
=
healthIndex
.
subList
(
healthIndex
.
size
()
-
healthValueRiskCount
,
healthIndex
.
size
());
riskNum
=
(
int
)
healthIndexList
.
stream
().
filter
(
e
->
e
<=
finalHealthValueRisk
).
count
();
}
Double
finalHealthValueWarn
=
healthValueWarn
;
if
(
healthIndex
.
size
()
>=
healthValueWarnCount
)
{
List
<
Double
>
healthIndexList
=
healthIndex
.
subList
(
healthIndex
.
size
()
-
healthValueWarnCount
,
healthIndex
.
size
());
warnNum
=
(
int
)
healthIndexList
.
stream
().
filter
(
e
->
e
<=
finalHealthValueWarn
).
count
();
}
Double
finalHealthValueNotice
=
healthValueNotice
;
if
(
healthIndex
.
size
()
>=
healthValueNoticeCount
)
{
List
<
Double
>
healthIndexList
=
healthIndex
.
subList
(
healthIndex
.
size
()
-
healthValueNoticeCount
,
healthIndex
.
size
());
noticeNum
=
(
int
)
healthIndexList
.
stream
().
filter
(
e
->
e
<=
finalHealthValueNotice
).
count
();
}
String
level
=
""
;
String
content
=
""
;
String
num
=
""
;
if
(
noticeNum
==
healthValueNoticeCount
)
{
level
=
"注意"
;
num
=
""
+
healthValueNotice
;
content
=
healthValueNoticeCount
+
"小时"
;
}
if
(
warnNum
==
healthValueWarnCount
)
{
level
=
"警告"
;
num
=
""
+
healthValueWarn
;
content
=
healthValueWarnCount
+
"小时"
;
}
if
(
riskNum
==
healthValueRiskCount
)
{
level
=
"危险"
;
num
=
""
+
healthValueRisk
;
content
=
healthValueRiskCount
+
"小时"
;
}
LambdaQueryWrapper
<
FanWarningRecord
>
query
=
new
LambdaQueryWrapper
<>();
query
.
eq
(
FanWarningRecord:
:
getAnalysisPointId
,
idxBizFanHealthIndices
.
get
(
0
).
getAnalysisObjSeq
());
query
.
eq
(
FanWarningRecord:
:
getStatus
,
"0"
);
query
.
isNull
(
FanWarningRecord:
:
getDisposotionDate
);
query
.
orderByDesc
(
FanWarningRecord:
:
getTs
);
List
<
FanWarningRecord
>
idxBizFanWarningRecords
=
fanWaringRecordMapper
.
selectList
(
query
);
int
flag
=
ObjectUtils
.
isEmpty
(
idxBizFanWarningRecords
)
||
WarningNameEnum
.
getCode
(
level
)
>
WarningNameEnum
.
getCode
(
idxBizFanWarningRecords
.
get
(
0
).
getWarningName
())
?
0
:
1
;
Boolean
timeFlag
=
format
.
equals
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getRecDate
());
if
(!
level
.
equals
(
""
)
&&
flag
==
0
&&
timeFlag
)
{
IdxBizFanWarningRecord
idxBizFanWarningRecord
=
new
IdxBizFanWarningRecord
();
idxBizFanWarningRecord
.
setKks
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getKks
());
idxBizFanWarningRecord
.
setArae
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getArea
());
idxBizFanWarningRecord
.
setStation
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getStation
());
idxBizFanWarningRecord
.
setSubSystem
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getSubSystem
());
idxBizFanWarningRecord
.
setGatewayId
(
gateWayId
);
idxBizFanWarningRecord
.
setIndexAddress
(
address
);
idxBizFanWarningRecord
.
setEquipmentName
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getEquipmentName
());
idxBizFanWarningRecord
.
setAnalysisPointId
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getAnalysisObjSeq
());
idxBizFanWarningRecord
.
setDisposotionState
(
"待确认"
);
idxBizFanWarningRecord
.
setStatus
(
"0"
);
idxBizFanWarningRecord
.
setWarningName
(
level
);
idxBizFanWarningRecord
.
setCONTENT
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getPointName
()
+
"连续"
+
content
+
"健康指数≤"
+
num
);
idxBizFanWarningRecord
.
setRecDate
(
time
);
idxBizFanWarningRecord
.
setWarningPeriod
(
WarningPeriodEnum
.
HOUR
.
getName
());
idxBizFanWarningRecord
.
setNumber
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getNumber
());
idxBizFanWarningRecord
.
setHealthIndexSeq
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getHealthIndex
().
toString
());
idxBizFanWarningRecord
.
setHealthLevel
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getHealthLevel
());
idxBizFanWarningRecord
.
setPointName
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getPointName
());
idxBizFanWarningRecordList
.
add
(
idxBizFanWarningRecord
);
long
currentTimeMillis
=
System
.
currentTimeMillis
();
long
nanoTime
=
System
.
nanoTime
();
long
timestamp
=
currentTimeMillis
*
1000000
+
nanoTime
%
1000000
;
FanWarningRecord
fanWarningRecord
=
new
FanWarningRecord
();
BeanUtils
.
copyProperties
(
idxBizFanWarningRecord
,
fanWarningRecord
,
"disposotionDate"
,
"recDate"
,
"CONTENT"
);
fanWarningRecord
.
setContent
(
idxBizFanWarningRecord
.
getCONTENT
());
fanWarningRecord
.
setRecDate
(
format
);
fanWarningRecord
.
setTs
(
timestamp
);
fanWarningRecord
.
setHealthIndex
(
String
.
format
(
CommonConstans
.
Onedecimalplaces
,
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getHealthIndex
()));
fanWarningRecord
.
setOrgCode
(
idxBizFanHealthIndices
.
get
(
0
).
getOrgCode
());
tdFanWarningRecordList
.
add
(
fanWarningRecord
);
}
}
// }
// idxBizFanWarningRecordService.saveBatch(idxBizFanWarningRecordList);
if
(
CollUtil
.
isNotEmpty
(
tdFanWarningRecordList
))
{
// tdengine插入
fanWaringRecordMapper
.
saveBatchWarningRecords
(
tdFanWarningRecordList
);
}
// 触发风险模型生成预警处置模块的预警记录
fetchDataFan
(
tdFanWarningRecordList
,
stationMap
);
}).
start
();
});
}
/***
/***
* 每三天取一次最大粒度内的指数异常数据
* 每三天取一次最大粒度内的指数异常数据
* 判断三天内数据是否符合预警规则 符合则报警并在redis中缓存 同一级别的预警记录下次不生成
* 判断三天内数据是否符合预警规则 符合则报警并在redis中缓存 同一级别的预警记录下次不生成
...
@@ -1890,6 +2465,202 @@ public class HealthStatusIndicatorServiceImpl {
...
@@ -1890,6 +2465,202 @@ public class HealthStatusIndicatorServiceImpl {
fetchDataFan
(
tdFanWarningRecordList
,
stationMap
);
fetchDataFan
(
tdFanWarningRecordList
,
stationMap
);
}
}
// @Scheduled(cron = "0 0 0 0/1 * ? ")
@Async
(
"async"
)
public
void
healthWarningDayNew
()
{
if
(!
openHealth
)
{
return
;
}
Date
time
=
new
Date
();
String
format
=
DateUtil
.
format
(
time
,
"yyyy-MM-dd 00:00:00"
);
//三天 + 8小时
// Date date = DateUtils.dateAddHours(time, -80);
// Calendar calendar = Calendar.getInstance();
// calendar.set(Calendar.DAY_OF_MONTH,calendar.get(Calendar.DAY_OF_MONTH)-3);
// SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
List
<
String
>
gatewayIds
=
idxBizFanWarningRuleSetMapper
.
getGatewayIds
();
gatewayIds
.
stream
().
forEach
(
gatewayId
->{
Integer
maxWaringCycle
=
idxBizFanWarningRuleSetMapper
.
getMaxWaringCycleOfDayByGatewayId
(
gatewayId
);
Date
date
=
DateUtil
.
offsetHour
(
time
,
-
8
);
date
=
DateUtil
.
offsetDay
(
date
,
0
-
(
maxWaringCycle
));
LambdaQueryWrapper
<
FanHealthIndexDay
>
wrapper
=
new
LambdaQueryWrapper
<>();
// wrapper.ne(FanHealthIndexDay::getHealthLevel,"安全");
wrapper
.
ge
(
FanHealthIndexDay:
:
getRecDate
,
date
);
wrapper
.
eq
(
FanHealthIndexDay:
:
getAnalysisObjType
,
"测点"
);
Date
dateMax
=
DateUtil
.
offsetHour
(
time
,
-
8
);
wrapper
.
le
(
FanHealthIndexDay:
:
getRecDate
,
dateMax
);
wrapper
.
orderByAsc
(
FanHealthIndexDay:
:
getTs
);
List
<
FanHealthIndexDay
>
healthIndices
=
fanHealthIndexDayMapper
.
selectList
(
wrapper
);
if
(
ObjectUtils
.
isEmpty
(
healthIndices
))
{
return
;
}
List
<
String
>
collect
=
healthIndices
.
stream
().
map
(
FanHealthIndexDay:
:
getAnalysisObjSeq
).
collect
(
Collectors
.
toList
());
LambdaQueryWrapper
<
IdxBizFanWarningRuleSet
>
queryWrapper
=
new
LambdaQueryWrapper
<>();
queryWrapper
.
eq
(
IdxBizFanWarningRuleSet:
:
getAnalysisType
,
WarningPeriodEnum
.
DAY
.
getName
());
queryWrapper
.
in
(
IdxBizFanWarningRuleSet:
:
getAnalysisPointId
,
collect
);
List
<
IdxBizFanWarningRuleSet
>
idxBizPvWarningRules
=
idxBizFanWarningRuleSetMapper
.
selectList
(
queryWrapper
);
Map
<
String
,
Map
<
String
,
List
<
FanHealthIndexDay
>>>
gateWayMaps
=
healthIndices
.
stream
().
collect
(
Collectors
.
groupingBy
(
FanHealthIndexDay:
:
getGatewayId
,
Collectors
.
groupingBy
(
FanHealthIndexDay:
:
getIndexAddress
)));
List
<
IdxBizFanWarningRecord
>
idxBizFanWarningRecordList
=
new
ArrayList
<>();
List
<
FanWarningRecord
>
tdFanWarningRecordList
=
new
ArrayList
<>();
HashMap
<
String
,
StationBasic
>
stationMap
=
new
HashMap
<>();
// for (String gateWayId : gateWayMaps.keySet()) {
LambdaQueryWrapper
<
StationBasic
>
basicLambdaQueryWrapper
=
new
LambdaQueryWrapper
<>();
basicLambdaQueryWrapper
.
eq
(
StationBasic:
:
getFanGatewayId
,
gatewayId
);
basicLambdaQueryWrapper
.
last
(
"limit 1"
);
StationBasic
stationBasic
=
stationBasicMapper
.
selectOne
(
basicLambdaQueryWrapper
);
stationMap
.
put
(
gatewayId
,
stationBasic
);
Map
<
String
,
List
<
FanHealthIndexDay
>>
healthDataMaps
=
gateWayMaps
.
get
(
gatewayId
);
for
(
String
address
:
healthDataMaps
.
keySet
())
{
List
<
FanHealthIndexDay
>
idxBizFanHealthIndices
=
healthDataMaps
.
get
(
address
);
List
<
IdxBizFanWarningRuleSet
>
idxBizPvWarningRuleSets
=
idxBizPvWarningRules
.
stream
().
filter
(
t
->
t
.
getAnalysisPointId
().
equals
(
idxBizFanHealthIndices
.
get
(
0
).
getAnalysisObjSeq
())).
collect
(
Collectors
.
toList
());
if
(
ObjectUtils
.
isEmpty
(
idxBizPvWarningRuleSets
))
{
continue
;
}
Double
healthValueWarn
=
0.0
;
Double
healthValueRisk
=
0.0
;
Double
healthValueNotice
=
0.0
;
// long healthValueNoticeCount = 0;
// long healthValueWarnCount = 0;
// long healthValueRiskCount = 0;
int
healthValueWarnCount
=
0
;
int
healthValueRiskCount
=
0
;
int
healthValueNoticeCount
=
0
;
int
healthValueMinCount
=
0
;
int
riskNum
=
0
;
int
warnNum
=
0
;
int
noticeNum
=
0
;
for
(
IdxBizFanWarningRuleSet
e
:
idxBizPvWarningRuleSets
)
{
switch
(
e
.
getWarningName
())
{
case
"警告"
:
healthValueWarn
=
Double
.
parseDouble
(
e
.
getWarningIf
().
substring
(
2
));
healthValueWarnCount
=
Integer
.
parseInt
(
e
.
getWarningCycle
());
break
;
case
"危险"
:
healthValueRisk
=
Double
.
parseDouble
(
e
.
getWarningIf
().
substring
(
2
));
healthValueRiskCount
=
Integer
.
parseInt
(
e
.
getWarningCycle
());
break
;
case
"注意"
:
healthValueNotice
=
Double
.
parseDouble
(
e
.
getWarningIf
().
substring
(
2
));
healthValueNoticeCount
=
Integer
.
parseInt
(
e
.
getWarningCycle
());
break
;
}
}
List
<
Double
>
healthIndex
=
idxBizFanHealthIndices
.
stream
().
map
(
FanHealthIndexDay:
:
getHealthIndex
).
collect
(
Collectors
.
toList
());
// Double finalHealthValueRisk = healthValueRisk;
// long riskNum = healthIndex.subList(healthIndex.size()>healthValueRiskCount? (int) (healthIndex.size() - healthValueRiskCount) :0,healthIndex.size()).stream().filter(e -> e <= finalHealthValueRisk).count();
// Double finalHealthValueWarn = healthValueWarn;
// long warnNum = healthIndex.subList(healthIndex.size()>healthValueWarnCount? (int) (healthIndex.size() - healthValueWarnCount) :0,healthIndex.size()).stream().filter(e -> e <= finalHealthValueWarn).count();
// Double finalHealthValueNotice = healthValueNotice;
// long noticeNum = healthIndex.subList(healthIndex.size()>healthValueNoticeCount? (int) (healthIndex.size() - healthValueNoticeCount) :0,healthIndex.size()).stream().filter(e -> e <= finalHealthValueNotice).count();
Double
finalHealthValueRisk
=
healthValueRisk
;
if
(
healthIndex
.
size
()
>=
healthValueRiskCount
)
{
List
<
Double
>
healthIndexList
=
healthIndex
.
subList
(
healthIndex
.
size
()
-
healthValueRiskCount
,
healthIndex
.
size
());
riskNum
=
(
int
)
healthIndexList
.
stream
().
filter
(
e
->
e
<=
finalHealthValueRisk
).
count
();
}
Double
finalHealthValueWarn
=
healthValueWarn
;
if
(
healthIndex
.
size
()
>=
healthValueWarnCount
)
{
List
<
Double
>
healthIndexList
=
healthIndex
.
subList
(
healthIndex
.
size
()
-
healthValueWarnCount
,
healthIndex
.
size
());
warnNum
=
(
int
)
healthIndexList
.
stream
().
filter
(
e
->
e
<=
finalHealthValueWarn
).
count
();
}
Double
finalHealthValueNotice
=
healthValueNotice
;
if
(
healthIndex
.
size
()
>=
healthValueNoticeCount
)
{
List
<
Double
>
healthIndexList
=
healthIndex
.
subList
(
healthIndex
.
size
()
-
healthValueNoticeCount
,
healthIndex
.
size
());
noticeNum
=
(
int
)
healthIndexList
.
stream
().
filter
(
e
->
e
<=
finalHealthValueNotice
).
count
();
}
String
level
=
""
;
String
content
=
""
;
String
num
=
""
;
if
(
noticeNum
==
healthValueNoticeCount
)
{
// redisUtils.set(gateWayId+"_"+address+"_health_notice_day","notice");
level
=
"注意"
;
num
=
""
+
healthValueNotice
;
content
=
healthValueNoticeCount
+
"天"
;
}
if
(
warnNum
==
healthValueWarnCount
)
{
// redisUtils.set(gateWayId+"_"+address+"_health_warn_day","warn");
level
=
"警告"
;
num
=
""
+
healthValueWarn
;
content
=
healthValueWarnCount
+
"天"
;
}
if
(
riskNum
==
healthValueRiskCount
)
{
// redisUtils.set(gateWayId+"_"+address+"_health_risk_day","risk");
level
=
"危险"
;
num
=
""
+
healthValueRisk
;
content
=
healthValueRiskCount
+
"天"
;
}
LambdaQueryWrapper
<
FanWarningRecord
>
query
=
new
LambdaQueryWrapper
<>();
query
.
eq
(
FanWarningRecord:
:
getAnalysisPointId
,
idxBizFanHealthIndices
.
get
(
0
).
getAnalysisObjSeq
());
query
.
eq
(
FanWarningRecord:
:
getStatus
,
"0"
);
query
.
isNull
(
FanWarningRecord:
:
getDisposotionDate
);
query
.
orderByDesc
(
FanWarningRecord:
:
getTs
);
List
<
FanWarningRecord
>
idxBizFanWarningRecords
=
fanWaringRecordMapper
.
selectList
(
query
);
int
flag
=
ObjectUtils
.
isEmpty
(
idxBizFanWarningRecords
)
||
WarningNameEnum
.
getCode
(
level
)
>
WarningNameEnum
.
getCode
(
idxBizFanWarningRecords
.
get
(
0
).
getWarningName
())
?
0
:
1
;
Boolean
timeFlag
=
format
.
equals
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getRecDate
());
if
(!
level
.
equals
(
""
)
&&
flag
==
0
&&
timeFlag
)
{
IdxBizFanWarningRecord
idxBizFanWarningRecord
=
new
IdxBizFanWarningRecord
();
idxBizFanWarningRecord
.
setKks
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getKks
());
idxBizFanWarningRecord
.
setArae
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getArea
());
idxBizFanWarningRecord
.
setStation
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getStation
());
idxBizFanWarningRecord
.
setSubSystem
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getSubSystem
());
idxBizFanWarningRecord
.
setGatewayId
(
gatewayId
);
idxBizFanWarningRecord
.
setIndexAddress
(
address
);
idxBizFanWarningRecord
.
setEquipmentName
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getEquipmentName
());
idxBizFanWarningRecord
.
setAnalysisPointId
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getAnalysisObjSeq
());
idxBizFanWarningRecord
.
setDisposotionState
(
"待确认"
);
idxBizFanWarningRecord
.
setStatus
(
"0"
);
idxBizFanWarningRecord
.
setWarningName
(
level
);
idxBizFanWarningRecord
.
setCONTENT
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getPointName
()
+
"连续"
+
content
+
"健康指数≤"
+
num
);
idxBizFanWarningRecord
.
setRecDate
(
time
);
idxBizFanWarningRecord
.
setWarningPeriod
(
WarningPeriodEnum
.
DAY
.
getName
());
idxBizFanWarningRecord
.
setNumber
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getNumber
());
idxBizFanWarningRecord
.
setHealthIndexSeq
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getHealthIndex
().
toString
());
idxBizFanWarningRecord
.
setHealthLevel
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getHealthLevel
());
idxBizFanWarningRecord
.
setPointName
(
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getPointName
());
idxBizFanWarningRecordList
.
add
(
idxBizFanWarningRecord
);
long
currentTimeMillis
=
System
.
currentTimeMillis
();
long
nanoTime
=
System
.
nanoTime
();
long
timestamp
=
currentTimeMillis
*
1000000
+
nanoTime
%
1000000
;
FanWarningRecord
fanWarningRecord
=
new
FanWarningRecord
();
BeanUtils
.
copyProperties
(
idxBizFanWarningRecord
,
fanWarningRecord
,
"disposotionDate"
,
"recDate"
,
"CONTENT"
);
fanWarningRecord
.
setContent
(
idxBizFanWarningRecord
.
getCONTENT
());
fanWarningRecord
.
setRecDate
(
format
);
fanWarningRecord
.
setTs
(
timestamp
);
fanWarningRecord
.
setHealthIndex
(
String
.
format
(
CommonConstans
.
Onedecimalplaces
,
idxBizFanHealthIndices
.
get
(
idxBizFanHealthIndices
.
size
()
-
1
).
getHealthIndex
()));
fanWarningRecord
.
setOrgCode
(
idxBizFanHealthIndices
.
get
(
0
).
getOrgCode
());
tdFanWarningRecordList
.
add
(
fanWarningRecord
);
}
}
// }
// idxBizFanWarningRecordService.saveBatch(idxBizFanWarningRecordList);
if
(
CollUtil
.
isNotEmpty
(
tdFanWarningRecordList
))
{
// tdengine插入
fanWaringRecordMapper
.
saveBatchWarningRecords
(
tdFanWarningRecordList
);
}
// 触发风险模型生成预警处置模块的预警记录
fetchDataFan
(
tdFanWarningRecordList
,
stationMap
);
});
}
public
String
getJumpUrlByInfo
(
String
sbbm
,
List
<
JumpConfig
>
jumpConfigs
)
{
public
String
getJumpUrlByInfo
(
String
sbbm
,
List
<
JumpConfig
>
jumpConfigs
)
{
Map
<
String
,
String
>
collect
=
jumpConfigs
.
stream
().
collect
(
Collectors
.
toMap
(
JumpConfig:
:
getType
,
JumpConfig:
:
getUrl
));
Map
<
String
,
String
>
collect
=
jumpConfigs
.
stream
().
collect
(
Collectors
.
toMap
(
JumpConfig:
:
getType
,
JumpConfig:
:
getUrl
));
if
(
StrUtil
.
isEmpty
(
sbbm
))
{
if
(
StrUtil
.
isEmpty
(
sbbm
))
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment