From aa94ef4e1f060b184e6ea9fb37254b376a1eb60e Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期二, 14 十一月 2023 10:49:06 +0800 Subject: [PATCH] 1. 新增风险值的自动运行逻辑; --- src/main/java/com/flightfeather/monitor/analysis/dust/risk/DustRiskMonthAnalysis.kt | 20 ++++++++++++-------- 1 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/flightfeather/monitor/analysis/dust/risk/DustRiskMonthAnalysis.kt b/src/main/java/com/flightfeather/monitor/analysis/dust/risk/DustRiskMonthAnalysis.kt index 4ba6551..e2efa14 100644 --- a/src/main/java/com/flightfeather/monitor/analysis/dust/risk/DustRiskMonthAnalysis.kt +++ b/src/main/java/com/flightfeather/monitor/analysis/dust/risk/DustRiskMonthAnalysis.kt @@ -1,6 +1,9 @@ package com.flightfeather.monitor.analysis.dust.risk import com.flightfeather.monitor.domain.ds1.entity.* +import java.time.LocalDate +import java.time.ZoneId +import java.util.* class DustRiskMonthAnalysis(val config: DustExceptionSetting) { @@ -17,8 +20,12 @@ /** * 姣忚疆娆$殑鍒濆鍖� */ - fun roundInit() { - resultList.add(RiskValue()) + fun roundInit(mnCode: String, date: LocalDate) { + resultList.add(RiskValue().apply { + this.mnCode = mnCode + lst = Date.from(date.withDayOfMonth(1).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()) + type = "month" + }) } /** @@ -34,7 +41,6 @@ riskExceedRate(res, list) riskExceptionRepetitionRate(res, list) riskExceptionType(res, list) - onDone(res) } fun riskOnlineRate(riskValue: RiskValue, list: List<RiskValue?>) { @@ -57,16 +63,14 @@ riskValue.exceptionTypeAggregation = avg(list) { it.exceptionTypeAggregation } } - fun onDone(riskValue: RiskValue) { - riskValue.type = "month" - } - private fun avg(list: List<RiskValue?>, onNext: (value: RiskValue) -> Double): Double { + private fun avg(list: List<RiskValue?>, onNext: (value: RiskValue) -> Double?): Double { var total = .0 var count = 0 list.forEach { if (it == null) return@forEach - total += onNext(it) + val a = onNext(it) ?: return@forEach + total += a count++ } return if (count == 0) .0 else total / count -- Gitblit v1.9.3