| | |
| | | return if (res.isEmpty()) null else res[0] |
| | | } |
| | | |
| | | val stMsgCache = mutableMapOf<String, List<BaseExceptionResult?>>() |
| | | fun fetchList( |
| | | deviceCode: String, |
| | | startTime: Date, |
| | | endTime: Date, |
| | | msgType: MsgType? = null, |
| | | minPer: Double? = 0.5, |
| | | ): List<BaseExceptionResult?> { |
| | | var res = sourceTraceMsgBlobMapper.selectWithBlob(deviceCode, startTime, endTime) |
| | | if (msgType !== null) { |
| | | res = res.filter { it?.msgType == msgType.value } |
| | | var stMsgList = listOf<BaseExceptionResult?>() |
| | | val key = "${deviceCode}_${startTime.time}_${endTime.time}_${msgType?.value}" |
| | | if (stMsgCache.containsKey(key)) { |
| | | stMsgList = stMsgCache[key]!! |
| | | } |
| | | if (stMsgList.isEmpty()) { |
| | | var res = sourceTraceMsgBlobMapper.selectWithBlob(deviceCode, startTime, endTime) |
| | | if (msgType !== null) { |
| | | res = res.filter { it?.msgType == msgType.value } |
| | | } |
| | | |
| | | return res.map { stm -> |
| | | when (stm?.msgType) { |
| | | MsgType.PolClue.value, |
| | | MsgType.DataChange.value, |
| | | -> { |
| | | GsonUtils.gson.fromJson(stm.blobContent, PollutedClue::class.java) |
| | | stMsgList = res.map { stm -> |
| | | when (stm?.msgType) { |
| | | MsgType.PolClue.value, |
| | | MsgType.DataChange.value, |
| | | -> { |
| | | GsonUtils.gson.fromJson(stm.blobContent, PollutedClue::class.java) |
| | | } |
| | | |
| | | MsgType.AnaResult.value -> { |
| | | GsonUtils.gson.fromJson(stm.blobContent, AnalysisResult::class.java) |
| | | } |
| | | |
| | | else -> null |
| | | } |
| | | |
| | | MsgType.AnaResult.value -> { |
| | | GsonUtils.gson.fromJson(stm.blobContent, AnalysisResult::class.java) |
| | | } |
| | | stMsgCache[key] = stMsgList |
| | | } |
| | | // 筛选出异常数据PollutedClue中异常百分比大于minPer的 |
| | | return stMsgList.filter { |
| | | if (it is PollutedClue) { |
| | | var valid = false |
| | | (it as PollutedClue?)?.pollutedData?.statisticMap?.entries?.forEach {sta-> |
| | | if (!valid) valid = (sta.value.avgPer?:.0) > minPer!! |
| | | } |
| | | |
| | | else -> null |
| | | valid |
| | | } else { |
| | | true |
| | | } |
| | | } |
| | | } |
| | |
| | | .andGreaterThanOrEqualTo("startTime", mission.startTime) |
| | | .andLessThanOrEqualTo("endTime", mission.endTime) |
| | | }).map { it?.id } |
| | | if (idList.isEmpty()) return 0 |
| | | sourceTraceMsgMapper.deleteByExample(Example(SourceTraceMsg::class.java).apply { |
| | | createCriteria().andIn("id", idList) |
| | | }) |