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