feiyu02
2025-09-30 94fee0b511279679b43e210878d3d36e5a14384b
src/main/kotlin/com/flightfeather/uav/biz/datafetch/ShenXinDataFetch.kt
@@ -2,6 +2,7 @@
import com.flightfeather.uav.common.exception.BizException
import com.flightfeather.uav.common.net.ShenXinService
import com.flightfeather.uav.domain.entity.BaseRealTimeData
import com.flightfeather.uav.domain.entity.Mission
import com.flightfeather.uav.domain.repository.MissionRep
import com.flightfeather.uav.domain.repository.RealTimeDataRep
@@ -25,16 +26,17 @@
    private val deviceStatusMap = ConcurrentHashMap<String, Boolean>()
    // 走航任务是否正在获取数据
    private val missionStatusMap = ConcurrentHashMap<String, Boolean>()
    /**
     * 获取最新的数据
     * @param deviceType 设备类型
     * @param code 设备编号
     */
    private fun fetchLatestData(deviceType: UWDeviceType, code: String) {
    private fun fetchLatestData(deviceType: UWDeviceType, code: String): List<BaseRealTimeData> {
        if (deviceStatusMap.containsKey(code)) {
            // 设备正在获取实时数据,则直接返回,放弃本次请求
            if (deviceStatusMap[code] == true) {
                return
                return emptyList()
            }
            // 否则开始获取数据,修改状态为true
            else {
@@ -57,6 +59,7 @@
            if (data.isNotEmpty()) {
                realTimeDataRep.saveData(deviceType, data)
            }
            return data
        } finally {
            // 设备完成数据获取后,修改状态为false
            deviceStatusMap[code] = false
@@ -66,13 +69,15 @@
    /**
     * 获取给定时间范围内的数据
     */
    fun fetchLatestData(deviceType: UWDeviceType, code: String, sTime: LocalDateTime?, eTime: LocalDateTime?) {
    fun fetchLatestData(deviceType: UWDeviceType, code: String, sTime: LocalDateTime?, eTime: LocalDateTime?)
            : List<BaseRealTimeData> {
        if (sTime != null && eTime != null) {
            val data = ShenXinService.fetchData(code, sTime, eTime)
            realTimeDataRep.deleteData(deviceType, code, sTime, eTime)
            realTimeDataRep.saveData(deviceType, data)
            return data
        } else if (sTime == null && eTime == null) {
            fetchLatestData(deviceType, code)
            return fetchLatestData(deviceType, code)
        } else {
            throw BizException("开始和结束时间需要都省略或者都填写")
        }