riku
2025-08-28 3bb4fb15c664d29d179083698fdad35a661b1d7f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
 
/**
 *
 * @date 2024/8/26
 * @author feiyu02
 */
@Service
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) {
            ThirdPartyLabel.ShenXin.value -> {
                shenXinDataFetch.fetchMissionData(missionCode)
                return true
            }
            else -> throw BizException("第三方接口标识不存在")
        }
    }
 
    override fun fetchLatestData(
        label: String, type: UWDeviceType, deviceCode: String, startTime: LocalDateTime?, endTime: LocalDateTime?,
    ): Boolean {
        when (label) {
            ThirdPartyLabel.ShenXin.value -> {
                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]
    }
}