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]
|
}
|
}
|