feiyu02
2024-07-02 bf3bf9ff25ac106b556b2427cc382c8fcca63bff
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
package com.flightfeather.uav.domain.repository
 
import com.flightfeather.uav.domain.entity.*
import com.flightfeather.uav.domain.mapper.RealTimeDataGridMapper
import com.flightfeather.uav.domain.mapper.RealTimeDataGridMinMapper
import com.flightfeather.uav.domain.mapper.RealTimeDataUavMapper
import com.flightfeather.uav.domain.mapper.RealTimeDataVehicleMapper
import com.flightfeather.uav.socket.eunm.UWDeviceType
import com.github.pagehelper.PageHelper
import org.springframework.stereotype.Repository
import tk.mybatis.mapper.entity.Example
import java.util.*
 
/**
 * 实时走航数据数据库相关操作
 */
@Repository
class RealTimeDataRep(
    private val realTimeDataVehicleMapper: RealTimeDataVehicleMapper,
    private val realTimeDataUavMapper: RealTimeDataUavMapper,
    private val realTimeDataGridMapper: RealTimeDataGridMapper,
    private val realTimeDataGridMinMapper: RealTimeDataGridMinMapper,
) {
 
    private fun getSecondDataExample(example: Example, deviceCode: String?, sTime: Date?, eTime: Date?) {
        example.createCriteria().apply {
            deviceCode?.let { andEqualTo("deviceCode", it) }
            sTime?.let { andGreaterThanOrEqualTo("dataTime", it) }
            eTime?.let { andLessThanOrEqualTo("dataTime", it) }
        }
        example.orderBy("dataTime").apply {
            // 当请求接口不传递起始时间,默认获取最新的数据
            if (sTime == null && eTime == null) {
                desc()
            }
        }
    }
 
    fun fetchData(
        deviceCode: String,
        sTime: Date?,
        eTime: Date?,
        type: Int? = 0,
    ): List<BaseRealTimeData> {
        var result = listOf<BaseRealTimeData>()
        when (UWDeviceType.getType(deviceCode)) {
            UWDeviceType.VEHICLE -> {
                result = realTimeDataVehicleMapper.selectByExample(Example(RealTimeDataVehicle::class.java).apply {
                    getSecondDataExample(this, deviceCode, sTime, eTime)
                })
            }
            UWDeviceType.UAV -> {
                result = realTimeDataUavMapper.selectByExample(Example(RealTimeDataUav::class.java).apply {
                    getSecondDataExample(this, deviceCode, sTime, eTime)
                })
            }
            UWDeviceType.GRID -> {
                // 网格化监测秒级值
                result = if (type == null || type == 0) {
                    realTimeDataGridMapper.selectByExample(Example(RealTimeDataGrid::class.java).apply {
                        getSecondDataExample(this, deviceCode, sTime, eTime)
                    })
                }
                // 网格化监测分钟值
                else {
                    realTimeDataGridMinMapper.selectByExample(Example(RealTimeDataGridMin::class.java).apply {
                        getSecondDataExample(this, deviceCode, sTime, eTime)
                    })
                }
            }
        }
        return result
    }
 
    fun fetchData(mission: Mission) = fetchData(mission.deviceCode, mission.startTime, mission.endTime)
}