feiyu02
2025-07-23 344d9006faa27ea65e3eaf5e8f9173aad2266038
src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/ThirdPartyServiceImpl.kt
@@ -1,12 +1,18 @@
package com.flightfeather.uav.lightshare.service.impl
import com.flightfeather.uav.biz.datafetch.ShenXinDataFetch
import com.flightfeather.uav.biz.sourcetrace.SourceTraceController
import com.flightfeather.uav.common.exception.BizException
import com.flightfeather.uav.domain.repository.MissionRep
import com.flightfeather.uav.domain.repository.RealTimeDataRep
import com.flightfeather.uav.domain.repository.SceneInfoRep
import com.flightfeather.uav.domain.repository.SourceTraceRep
import com.flightfeather.uav.lightshare.eunm.ThirdPartyLabel
import com.flightfeather.uav.lightshare.service.ThirdPartyService
import com.flightfeather.uav.socket.eunm.UWDeviceType
import org.springframework.stereotype.Service
import java.time.LocalDateTime
import java.util.concurrent.ConcurrentHashMap
/**
 *
@@ -14,7 +20,17 @@
 * @author feiyu02
 */
@Service
class ThirdPartyServiceImpl(private val shenXinDataFetch: ShenXinDataFetch) : ThirdPartyService {
class ThirdPartyServiceImpl(
    private val shenXinDataFetch: ShenXinDataFetch,
    private val sceneInfoRep: SceneInfoRep,
    private val sourceTraceRep: SourceTraceRep,
    private val missionRep: MissionRep,
    private val realTimeDataRep: RealTimeDataRep,
) : ThirdPartyService {
    // 实时走航污染溯源处理器
    private val sourceTraceMap = ConcurrentHashMap<String?, SourceTraceController>()
    private val historySourceTraceTask = ConcurrentHashMap<String, Boolean>()
    override fun fetchMissionData(label: String, missionCode: String): Boolean {
        when (label) {
@@ -31,10 +47,39 @@
    ): Boolean {
        when (label) {
            ThirdPartyLabel.ShenXin.value -> {
                shenXinDataFetch.fetchLatestData(type, deviceCode, startTime, endTime)
                val data = shenXinDataFetch.fetchLatestData(type, deviceCode, startTime, endTime)
                getSourceTraceCtrl(deviceCode)?.addDataList(data)
                return true
            }
            else -> throw BizException("第三方接口标识不存在")
        }
    }
    override fun sourceTrace(label: String, missionCode: String): Boolean {
        when (label) {
            ThirdPartyLabel.ShenXin.value -> {
                if (!historySourceTraceTask.containsKey(missionCode)) {
                    historySourceTraceTask[missionCode] = false
                }
                if (historySourceTraceTask[missionCode] != true) {
                    historySourceTraceTask[missionCode] = true
                    val stc = SourceTraceController(sceneInfoRep, sourceTraceRep)
                    val mission = missionRep.findOne(missionCode) ?: throw BizException("走航任务不存在")
                    val data = realTimeDataRep.fetchData(mission)
                    stc.addDataList(data)
                }
                return true
            }
            else -> throw BizException("第三方接口标识不存在")
        }
    }
    private fun getSourceTraceCtrl(key: String): SourceTraceController? {
        // 每台设备有各自单独的异常数据处理器
        if (!sourceTraceMap.containsKey(key)) {
            sourceTraceMap[key] = SourceTraceController(sceneInfoRep, sourceTraceRep)
        }
        // 将走航数据传入异常处理器
        return sourceTraceMap[key]
    }
}