feiyu02
2025-08-14 b10c22af595bd995e56946bff63b8f2f984b13e8
src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedSource.kt
@@ -45,41 +45,44 @@
        // 按照区域检索内部污染源信息
        var result = mutableListOf<SceneInfo>()
        // 1. 首先按照四至范围从数据库初步筛选污染源,此处的区域坐标已转换为火星坐标系
        val polygonTmp = pollutedArea.polygon!!
        val fb = MapUtil.calFourBoundaries(polygonTmp)
        val sceneList = sceneInfoRep.findByCoordinateRange(fb)
        // 2. 再精确判断是否在反向溯源区域多边形内部
        sceneList.forEach {
            val point = it!!.longitude.toDouble() to it.latitude.toDouble()
            if (MapUtil.isPointInPolygon(point, polygonTmp)) {
                result.add(it)
            }
        }
        val polygonTmp = pollutedArea.polygon
        this.sceneList = emptyList()
        val closePolygonTmp = pollutedArea.closePolygon!!
        val closeFb = MapUtil.calFourBoundaries(closePolygonTmp)
        val closeSceneList = sceneInfoRep.findByCoordinateRange(closeFb)
        // 2. 再精确判断是否在反向溯源区域多边形内部
        closeSceneList.forEach {
            val point = it!!.longitude.toDouble() to it.latitude.toDouble()
            if (MapUtil.isPointInPolygon(point, closePolygonTmp)) {
                result.add(it)
            }
        }
        // 根据污染因子的量级,计算主要的污染场景类型,筛选结果
        val mainSceneType = calSceneType(pollutedData)
        if (mainSceneType != null) {
//            this.conclusion = mainSceneType.first
            result = result.filter {
                val r = mainSceneType.second.find { s->
                    s.value == it.typeId.toInt()
        if (polygonTmp != null) {
            val fb = MapUtil.calFourBoundaries(polygonTmp)
            val sceneList = sceneInfoRep.findByCoordinateRange(fb)
            // 2. 再精确判断是否在反向溯源区域多边形内部
            sceneList.forEach {
                val point = it!!.longitude.toDouble() to it.latitude.toDouble()
                if (MapUtil.isPointInPolygon(point, polygonTmp)) {
                    result.add(it)
                }
                r != null
            }.toMutableList()
        }
            }
        this.sceneList = findClosestStation(sceneInfoRep, result)
            val closePolygonTmp = pollutedArea.closePolygon!!
            val closeFb = MapUtil.calFourBoundaries(closePolygonTmp)
            val closeSceneList = sceneInfoRep.findByCoordinateRange(closeFb)
            // 2. 再精确判断是否在反向溯源区域多边形内部
            closeSceneList.forEach {
                val point = it!!.longitude.toDouble() to it.latitude.toDouble()
                if (MapUtil.isPointInPolygon(point, closePolygonTmp)) {
                    result.add(it)
                }
            }
            // 根据污染因子的量级,计算主要的污染场景类型,筛选结果
            val mainSceneType = calSceneType(pollutedData)
            if (mainSceneType != null) {
//            this.conclusion = mainSceneType.first
                result = result.filter {
                    val r = mainSceneType.second.find { s ->
                        s.value == it.typeId.toInt()
                    }
                    r != null
                }.toMutableList()
            }
            this.sceneList = findClosestStation(sceneInfoRep, result)
        }
        val txt = summaryTxt(pollutedData, this.sceneList!!)
        this.conclusion = txt
@@ -97,17 +100,17 @@
                // 氮氧化合物,一般由于机动车尾气,同步计算CO
                FactorType.NO2 -> {
                    val coAvg = round(pollutedData.dataList.map { it.co!! }.average()) / 1000
                     "氮氧化合物偏高,CO的量级为${coAvg}mg/m³,一般由于机动车尾气造成,污染源以汽修、加油站为主" to
                    "氮氧化合物偏高,CO的量级为${coAvg}mg/m³,一般由于机动车尾气造成,污染源以汽修、加油站为主" to
                            listOf(SceneType.TYPE6, SceneType.TYPE10, SceneType.TYPE17)
                }
                FactorType.CO ->  null
                FactorType.CO -> null
                FactorType.H2S ->  null
                FactorType.H2S -> null
                FactorType.SO2 ->  null
                FactorType.SO2 -> null
                FactorType.O3 ->  null
                FactorType.O3 -> null
                // a) pm2.5、pm10特别高,两者在各情况下同步展示,pm2.5占pm10的比重变化,比重越高,越有可能是餐饮
                // b) pm10特别高、pm2.5较高,大颗粒扬尘污染,只展示pm10,pm2.5占pm10的比重变化,工地为主
                FactorType.PM25,
@@ -121,7 +124,7 @@
                    }.average()
                    val str =
                        "PM2.5量级为${pm25Avg}μg/m³,PM10量级为${pm10Avg}μg/m³,PM2.5占PM10的比重为${round(percentageAvg * 100)}%"
                     if (percentageAvg > 0.666) {
                    if (percentageAvg > 0.666) {
                        "${str},比重较大,污染源以餐饮为主,工地次之" to
                                listOf(
                                    SceneType.TYPE1,
@@ -156,11 +159,11 @@
                    val pm25Avg = round(pollutedData.dataList.map { it.pm25!! }.average() * 10) / 10
                    val coAvg = round(pollutedData.dataList.map { it.co!! }.average()) / 1000
                    val o3Avg = round(pollutedData.dataList.map { it.o3!! }.average() * 10) / 10
                     "VOC偏高,同时PM2.5量级为${pm25Avg}μg/m³,CO量级为${coAvg}mg/m³,O3量级为${o3Avg}μg/m³,污染源以汽修、加油站为主" to
                    "VOC偏高,同时PM2.5量级为${pm25Avg}μg/m³,CO量级为${coAvg}mg/m³,O3量级为${o3Avg}μg/m³,污染源以汽修、加油站为主" to
                            listOf(SceneType.TYPE6, SceneType.TYPE17, SceneType.TYPE12)
                }
                else ->  null
                else -> null
            }
            des = res?.first
            res?.second?.let { sceneTypes.addAll(it) }
@@ -212,7 +215,7 @@
        val et = DateUtil.instance.getTime(pollutedData.endTime)
        var txt =
            "在${st}至${et}之间,出现${pollutedData.exception}"
        pollutedData.statisticMap.entries.forEach {s ->
        pollutedData.statisticMap.entries.forEach { s ->
            txt += ",${s.key.des}最低值为${s.value.min}μg/m³,最高值为${s.value.max}μg/m³,均值为${s.value.avg}μg/m³"
        }
        if (sceneList.isEmpty()) {