From 38d72198bfcced01ed9513b978163e5cd1d84625 Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期一, 21 七月 2025 15:31:41 +0800 Subject: [PATCH] 2025.7.21 1. 修改动态溯源异常判断逻辑 --- src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt | 209 +++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 149 insertions(+), 60 deletions(-) diff --git a/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt b/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt index 0336e02..36fdfa1 100644 --- a/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt +++ b/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt @@ -5,14 +5,20 @@ import com.flightfeather.uav.domain.entity.BaseRealTimeData import com.flightfeather.uav.lightshare.eunm.ExceptionStatusType import com.flightfeather.uav.socket.eunm.FactorType +import org.springframework.beans.BeanUtils import java.time.Duration /** * 杩炵画绫诲瀷鐨勫紓甯稿垎鏋愬熀绫�,閫傜敤浜庡綋鍓嶆暟鎹笌鐩搁偦鏁版嵁涔嬮棿鏈夊叧鑱斿叧绯荤殑鎯呭喌 */ abstract class BaseExceptionContinuous<T : ExceptionTag, V : BaseAnalysisConfig, Y : BaseExceptionResult>( - config: V, private val tagClz: Class<T> + config: V, private val tagClz: Class<T>, ) : BaseExceptionAnalysis<V, Y>(config) { + + enum class JudgeMethod(val des: String) { + M1("鍦ㄤ竴瀹氱殑绌洪棿鍜屾椂闂磋寖鍥村唴锛屾暟鎹疮璁″嚭鐜癗娆″紓甯稿悗锛岃涓鸿寮傚父鎴愮珛"), + M2("瑕佹眰鏁版嵁涓嶉棿鏂繛缁嚭鐜癗娆″紓甯稿悗锛岃涓鸿寮傚父鎴愮珛"), + } companion object { // 璁板綍寮傚父鏁版嵁娈垫椂锛屽垎鍒悜璧峰鍓嶅拰鏈熬鍚庨澶栬褰曠殑鏁版嵁涓暟鍋忕Щ閲� @@ -27,11 +33,25 @@ // 鏈熬鏁版嵁瀵硅薄 protected var lastData: BaseRealTimeData? = null - // 鏈�鏂扮殑涓�缁勫紓甯革紝鏍规嵁璁惧畾鍙傛暟锛屽皢鐩稿叧鑱旂殑鍥犲瓙浜х敓鐨勫紓甯稿悎骞� - protected val latestExceptionResult = mutableListOf<BaseExceptionResult>() + // 鏈�鏂扮殑涓�缁勫紓甯革紝璁板綍鍗曞洜瀛愬紓甯� + protected val latestExceptions = mutableListOf<Pair<FactorFilter.SelectedFactor, T>>() - // 鏈�鏂扮殑涓�缁勫悎骞跺紓甯� - protected val latestCombinedResult = mutableListOf<List<BaseExceptionResult>>() + /** + * 鏈�鏂扮殑涓�缁勫悎骞跺紓甯革紝鏍规嵁閰嶇疆鍙傛暟浠嶽latestExceptions]鍗曞洜瀛愬紓甯镐腑锛屽悎骞跺紓甯� + */ + protected val latestCombinedExc = mutableListOf<List<Pair<FactorFilter.SelectedFactor, T>>>() + + /** + * 寮傚父缁撴灉 + */ + protected val result = mutableListOf<Y>() + + /** + * 涓嶉�傜敤浜庢寮傚父绫诲瀷鐨勭洃娴嬪洜瀛� + */ + open var excludedFactor: List<FactorType> = emptyList() + + abstract var judgeMethod: JudgeMethod /** * 绔嬪嵆鍒ゆ柇锛氬綋鍑虹幇寮傚父鏃讹紝缂撳瓨寮傚父鏁版嵁鐨勫悓鏃讹紝绔嬪嵆瀵瑰凡鏈夊紓甯歌繘琛屽垽鏂槸鍚︽弧瓒冲紓甯哥粨鏋滆姹� @@ -90,7 +110,7 @@ * @return */ open fun needCut(tag: T, hasException: Boolean?, data: BaseRealTimeData): Boolean { - // 榛樿鍒ゆ柇鏉′欢涓� 褰撳紓甯镐笉鍐嶉噸澶嶅嚭鐜版椂锛屽舰鎴愬紓甯哥粨鏋� + // 榛樿鍒ゆ柇鏉′欢涓� 褰撳紓甯镐笉鍐嶉噸澶嶅嚭鐜版椂 return tag.exceptionExisted && hasException == false } @@ -108,9 +128,10 @@ val hasException = judge(lastData, data) config.factorFilter.selectedList.forEach { s -> val f = s.main - tagMap[f]?.let { - it.addHistoryData(data) + // 鎺掗櫎姝ゅ紓甯哥被鍨嬩笉閫傜敤鐨勭洃娴嬪洜瀛� + if (excludedFactor.contains(f)) return@forEach + tagMap[f]?.let { it.eIndex++ // 璧峰鏁版嵁 it.endData = data @@ -118,40 +139,84 @@ it.refreshWithNextException(data) } - // 瀵逛簬寮傚父鐨勭敓鎴愬垎鍒墽琛屽悗缃垽鏂�佸拰绔嬪嵆鍒ゆ柇 - // 1. 鍚庣疆鍒ゆ柇锛氬綋鐩搁偦鏁版嵁鏃堕棿涓嶈繛缁椂锛屾垨鑰呮弧瓒宠嚜瀹氫箟鏉′欢鏃讹紝瀵逛箣鍓嶅凡鏈夌殑寮傚父杩涜璁板綍锛屽舰鎴愬紓甯哥粨鏋� -// if (afterExcCheck(isContinue, it, hasException[f])) { -// // 鏁版嵁涓嶈繛缁椂鎴栬�呮弧瓒充富鍔ㄦ埅鏂潯浠舵椂锛岃褰曞紓甯告儏鍐� -// recordException(s, it, data) -// } - // 2. 绔嬪嵆鍒ゆ柇锛氬綋鍑虹幇寮傚父鏃讹紝缂撳瓨寮傚父鏁版嵁鐨勫悓鏃讹紝绔嬪嵆瀵瑰凡鏈夊紓甯歌繘琛屽垽鏂槸鍚︽弧瓒冲紓甯哥粨鏋滆姹� - if (hasException[f] == true) { - -// afterExcCheck(isContinue, it, hasException[f]) - if (needCut(it, hasException[f], data)) { - it.refreshWithNextException(data) - } - // 鏈夊紓甯稿嚭鐜版椂锛岃褰曞紓甯告暟鎹� - it.addExceptionData(data) - // 褰撶珛鍗冲垽鏂�氳繃鏃讹紝褰㈡垚寮傚父缁撴灉 - if (immeExcCheck(it, f)) { - recordException(s, it, data) - } + // 鎸夌収涓嶅悓鐨勬柟寮忚繘琛屽紓甯稿垽鏂� + when (judgeMethod) { + JudgeMethod.M1 -> judgeMethod1(hasException, f, it, data, s) + JudgeMethod.M2 -> judgeMethod2(isContinue, hasException, f, it, data, s) } - // 3. 鏁版嵁姝e父锛屾棤浠讳綍寮傚父鏃禿 - // TODO("2025.6.3锛氬叾浠栧瓙绫荤殑姝ゅ鍒锋柊閫昏緫寰呭畬鎴愨��) -// else { -// it.refreshWithNextException(data) -// } + + it.addHistoryData(data) } } lastData = data mergeExceptionResult() + clearExceptions(data) } override fun onDone() { checkResult(exceptionStatus = ExceptionStatusType.Ended) + } + + /** + * 鏁版嵁寮傚父鍒ゆ柇鏂瑰紡涓� + * 鍦ㄤ竴瀹氱殑绌洪棿鍜屾椂闂磋寖鍥村唴锛屾暟鎹疮璁″嚭鐜癗娆″紓甯稿悗锛岃涓鸿寮傚父鎴愮珛 + */ + private fun judgeMethod1( + hasException: MutableMap<FactorType, Boolean>, + f: FactorType, + tag: T, + data: BaseRealTimeData, + s: FactorFilter.SelectedFactor, + ) { + // 鍑虹幇寮傚父 + if (hasException[f] == true) { + // 鍒ゆ柇鏁版嵁鍦ㄧ┖闂村拰鏃堕棿鍙樺寲涓婃槸鍚﹁秴鍑洪檺瀹氳寖鍥达紝鑻ヨ秴鍑哄垯鍒犻櫎閬楃暀鐨勫紓甯歌褰曪紝鍒锋柊璧峰鐐规暟鎹� + if (needCut(tag, hasException[f], data)) { + tag.refreshWithNextException(data) + } + // 璁板綍寮傚父鏁版嵁 + tag.addExceptionData(data) + // 褰撶珛鍗冲垽鏂�氳繃鏃讹紝褰㈡垚寮傚父缁撴灉 + if (immeExcCheck(tag, f)) { + recordException(s, tag, data) + } + } + // 鏁版嵁姝e父锛屽苟涓旀病鏈夊巻鍙插紓甯告暟鎹椂锛屽埛鏂拌捣濮嬬偣鏁版嵁 + else if (!tag.exceptionExisted) { + tag.refreshWithNextException(data) + } + } + + /** + * 鏁版嵁寮傚父鍒ゆ柇鏂瑰紡浜� + * 瑕佹眰鏁版嵁涓嶉棿鏂繛缁嚭鐜癗娆″紓甯稿悗锛岃涓鸿寮傚父鎴愮珛 + */ + private fun judgeMethod2( + isContinue: Boolean, + hasException: MutableMap<FactorType, Boolean>, + f: FactorType, + tag: T, + data: BaseRealTimeData, + s: FactorFilter.SelectedFactor, + ) { + // 褰撶浉閭绘暟鎹椂闂翠笉杩炵画鏃讹紝鍒锋柊璧峰鐐规暟鎹紝绉婚櫎鍘嗗彶寮傚父璁板綍 + if (!isContinue) { + tag.refreshWithNextException(data) + } + // 鍑虹幇寮傚父 + else if (hasException[f] == true) { + // 鏈夊紓甯稿嚭鐜版椂锛岃褰曞紓甯告暟鎹� + tag.addExceptionData(data) + // 褰撶珛鍗冲垽鏂�氳繃鏃讹紝褰㈡垚寮傚父缁撴灉 + if (immeExcCheck(tag, f)) { + recordException(s, tag, data) + } + } + // 鏁版嵁姝e父锛屽埛鏂拌捣濮嬬偣鏁版嵁锛岀Щ闄ゅ巻鍙插紓甯歌褰� + else { + tag.refreshWithNextException(data) + } } /** @@ -160,7 +225,7 @@ */ fun recordException(factor: FactorFilter.SelectedFactor, tag: T, data: BaseRealTimeData) { checkResult(factor, ExceptionStatusType.Ended) - tag.refreshWithNextException(data) +// tag.refreshWithNextException(data) } /** @@ -168,7 +233,7 @@ */ open fun checkResult( factor: FactorFilter.SelectedFactor? = null, - exceptionStatus: ExceptionStatusType = ExceptionStatusType.InProgress + exceptionStatus: ExceptionStatusType = ExceptionStatusType.InProgress, ) { val tag = tagMap[factor?.main] if (factor != null && tag != null) { @@ -191,23 +256,24 @@ open fun onNewException(tag: T, factor: FactorFilter.SelectedFactor, exceptionStatus: ExceptionStatusType) { if (tag.startData == null) return // val ex = newResult(tag.startData!!, tag.endData, factor, tag.exceptionData) - val ex = newResult(tag, factor) - .apply { status = exceptionStatus.value } - // 寮傚父宸插垱寤烘椂锛屾洿鏂板紓甯镐俊鎭� - if (tag.exceptionCreated) { - // 灏嗘渶鏂扮殑寮傚父鐨刧uid璧嬪�肩粰ex - val lastEx = tag.exceptionResult.last() - ex.guid = lastEx.guid - tag.exceptionResult.removeLast() - tag.exceptionResult.add(ex) - } - // 寮傚父鏈垱寤烘椂锛屾柊寤哄紓甯镐俊鎭� - else { - tag.exceptionResult.add(ex) - tag.exceptionCreated = true - } - - latestExceptionResult.add(ex) +// val ex = newResult(tag, factor) +// .apply { status = exceptionStatus.value } +// // 寮傚父宸插垱寤烘椂锛屾洿鏂板紓甯镐俊鎭� +// if (tag.exceptionCreated) { +// // 灏嗘渶鏂扮殑寮傚父鐨刧uid璧嬪�肩粰ex +// val lastEx = tag.exceptionResult.last() +// ex.guid = lastEx.guid +// tag.exceptionResult.removeLast() +// tag.exceptionResult.add(ex) +// } +// // 寮傚父鏈垱寤烘椂锛屾柊寤哄紓甯镐俊鎭� +// else { +// tag.exceptionResult.add(ex) +// tag.exceptionCreated = true +// } +// val tagClone = tagClz.newInstance() +// BeanUtils.copyProperties(tag, tagClone) + latestExceptions.add(factor to tag) } /** @@ -215,13 +281,13 @@ */ open fun mergeExceptionResult() { // 閬嶅巻鎵�鏈夌殑鍥犲瓙缁勫悎 - config.combination?.forEach {c -> - val res = mutableListOf<BaseExceptionResult>() + config.factorFilter.combination.forEach { c -> + val res = mutableListOf<Pair<FactorFilter.SelectedFactor, T>>() var exist = true // 鏌ョ湅缁勫悎鍐呯殑鎵�鏈夊洜瀛愭槸鍚﹂兘鍚屾椂鍑虹幇寮傚父 - c.forEach { f-> - val r = latestExceptionResult.find { e-> - e.factorId == f.value + c.forEach { f -> + val r = latestExceptions.find { e -> + e.first.main == f } if (r != null) { res.add(r) @@ -232,18 +298,41 @@ // 濡傛灉缁勫悎鍐呯殑鎵�鏈夊洜瀛愰兘瀛樺湪寮傚父锛屽垯瀛樺偍涓哄悎骞跺紓甯� if (exist) { // 灏嗗悎骞跺紓甯镐粠鍗曚釜寮傚父闆嗗悎涓幓闄� - res.forEach { r-> - latestExceptionResult.removeIf { e-> e.factorId == r.factorId } + res.forEach { r -> + latestExceptions.removeIf { e -> e.first.main == r.first.main } } // 灏嗗悎骞跺紓甯稿瓨鍌� - latestCombinedResult.add(res) + latestCombinedExc.add(res) } } + // 瀛樺偍寮傚父缁撴灉 + latestExceptions.forEach { + result.add(newResult(listOf(it))) + } + latestCombinedExc.forEach { + result.add(newResult(it)) + } + } + + private fun clearExceptions(data: BaseRealTimeData) { + latestExceptions.forEach { + it.second.refreshWithNextException(data) + } + latestExceptions.clear() + latestCombinedExc.forEach { + it.forEach { e -> + e.second.refreshWithNextException(data) + } + } + latestCombinedExc.clear() + result.clear() } /** * 鐢熸垚涓�鏉″紓甯稿垎鏋愮粨鏋� */ - abstract fun newResult(tag:T, factor: FactorFilter.SelectedFactor): Y + abstract fun newResult(tag: T, factor: FactorFilter.SelectedFactor): Y + + abstract fun newResult(exceptions: List<Pair<FactorFilter.SelectedFactor, ExceptionTag>>): Y } \ No newline at end of file -- Gitblit v1.9.3