feiyu02
2025-07-10 c5f380b69707a9a09fe988a2f4bd98e142bf64ae
src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedSource.kt
@@ -1,5 +1,6 @@
package com.flightfeather.uav.biz.sourcetrace.model
import com.flightfeather.uav.common.utils.DateUtil
import com.flightfeather.uav.common.utils.MapUtil
import com.flightfeather.uav.domain.entity.SceneInfo
import com.flightfeather.uav.domain.repository.SceneInfoRep
@@ -25,7 +26,7 @@
     */
    // 溯源企业
    var sceneList: List<SceneInfoVo?>? = null
    var sceneList: List<SceneInfoVo>? = null
    // 溯源推理结论
    var conclusion: String? = null
@@ -69,7 +70,7 @@
        // 根据污染因子的量级,计算主要的污染场景类型,筛选结果
        val mainSceneType = calSceneType(pollutedData)
        if (mainSceneType != null) {
            this.conclusion = mainSceneType.first
//            this.conclusion = mainSceneType.first
            result = result.filter {
                val r = mainSceneType.second.find { s->
                    s.value == it.typeId.toInt()
@@ -80,6 +81,8 @@
        this.sceneList = findClosestStation(sceneInfoRep, result)
        val txt = summaryTxt(pollutedData, this.sceneList!!)
        this.conclusion = txt
    }
    /**
@@ -114,7 +117,7 @@
                    it.pm25!! / it.pm10!!
                }.average()
                val str =
                    "PM2.5量级为${pm25Avg}μg/m³,PM10量级为${pm25Avg}μg/m³,PM2.5占PM10的比重为${round(percentageAvg * 100)}%"
                    "PM2.5量级为${pm25Avg}μg/m³,PM10量级为${pm10Avg}μg/m³,PM2.5占PM10的比重为${round(percentageAvg * 100)}%"
                return if (percentageAvg > 0.666) {
                    "${str},比重较大,污染源以餐饮为主,工地次之" to
                            listOf(SceneType.TYPE1, SceneType.TYPE2, SceneType.TYPE3, SceneType.TYPE14, SceneType.TYPE5)
@@ -176,4 +179,35 @@
            return@map vo
        }
    }
    private fun summaryTxt(pollutedData: PollutedData, sceneList: List<SceneInfoVo>): String {
//        pollutedData.exception
//        pollutedData.selectedFactor?.main
        val st = DateUtil.instance.getTime(pollutedData.startTime)
        val et = DateUtil.instance.getTime(pollutedData.endTime)
        var txt =
            "${pollutedData.selectedFactor?.main?.des}在${st}至${et}之间,出现${pollutedData.exception},最低值为${
                pollutedData
                    .min
            },最高值为${pollutedData.max}"
        if (sceneList.isEmpty()) {
            txt += (",可能存在隐藏风险源。")
        } else {
            txt += (",发现${sceneList.size}个风险源,包含")
            val sizeMap = mutableMapOf<String, Int>()
            sceneList.forEach {
                if (!sizeMap.containsKey(it.type)) {
                    sizeMap[it.type] = 0
                }
                sizeMap[it.type] = sizeMap[it.type]!! + 1
            }
            sizeMap.forEach { (t, u) ->
                txt += ("${u}个${t},")
            }
            txt = txt.replaceRange(txt.length - 1, txt.length, "。")
        }
        return txt
    }
}