From 9ed0b1847912221197697791d69e01ccae17f5b9 Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期二, 27 八月 2024 17:36:11 +0800 Subject: [PATCH] 1. 新增NO监测因子 2. 新增第三方数据接口数据获取相关模块 --- src/main/kotlin/com/flightfeather/uav/domain/repository/RealTimeDataRep.kt | 145 +++++++++++++++++++++++++++++++++--------------- 1 files changed, 99 insertions(+), 46 deletions(-) diff --git a/src/main/kotlin/com/flightfeather/uav/domain/repository/RealTimeDataRep.kt b/src/main/kotlin/com/flightfeather/uav/domain/repository/RealTimeDataRep.kt index b41950d..718bdd4 100644 --- a/src/main/kotlin/com/flightfeather/uav/domain/repository/RealTimeDataRep.kt +++ b/src/main/kotlin/com/flightfeather/uav/domain/repository/RealTimeDataRep.kt @@ -1,5 +1,6 @@ package com.flightfeather.uav.domain.repository +import com.flightfeather.uav.common.exception.BizException import com.flightfeather.uav.domain.entity.* import com.flightfeather.uav.domain.mapper.RealTimeDataGridMapper import com.flightfeather.uav.domain.mapper.RealTimeDataGridMinMapper @@ -9,6 +10,8 @@ import com.github.pagehelper.PageHelper import org.springframework.stereotype.Repository import tk.mybatis.mapper.entity.Example +import java.time.LocalDateTime +import java.time.ZoneId import java.util.* /** @@ -22,56 +25,106 @@ 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 { - // 褰撹姹傛帴鍙d笉浼犻�掕捣濮嬫椂闂达紝榛樿鑾峰彇鏈�鏂扮殑鏁版嵁 - if (sTime == null && eTime == null) { - desc() - } - } - } + private val delegate = RealTimeDataRepDelegate(realTimeDataVehicleMapper, realTimeDataUavMapper, + realTimeDataGridMapper, realTimeDataGridMinMapper) fun fetchData( - deviceCode: String, - sTime: Date?, - eTime: Date?, - type: Int? = 0, + deviceType: UWDeviceType?, deviceCode: String, sTime: Date? = null, eTime: Date? = null, type: Int? = 0, + page: Int? = null, perPage: Int? = null, ): 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) - }) - } - } - else -> Unit + if (page != null && perPage != null) { + var pageInfo = PageHelper.startPage<BaseRealTimeData>(page, perPage) } - return result + return delegate.selectByDeviceType(deviceType, type) { example -> + example.createCriteria().apply { + andEqualTo("deviceCode", deviceCode) + sTime?.let { andGreaterThanOrEqualTo("dataTime", it) } + eTime?.let { andLessThanOrEqualTo("dataTime", it) } + } + example.orderBy("dataTime").apply { + // 褰撹姹傛帴鍙d笉浼犻�掕捣濮嬫椂闂达紝榛樿鑾峰彇鏈�鏂扮殑鏁版嵁 + if (sTime == null && eTime == null) { + desc() + } + } + } + + +// var result = listOf<BaseRealTimeData>() +// when (deviceType) { +// 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) +// }) +// } +// } +// else -> Unit +// } +// return result } - fun fetchData(mission: Mission) = fetchData(mission.deviceCode, mission.startTime, mission.endTime) + fun fetchData(mission: Mission) = + fetchData(UWDeviceType.fromValue(mission.deviceType), mission.deviceCode, mission.startTime, mission.endTime) + + + fun saveData(deviceType: UWDeviceType?, data: List<BaseRealTimeData>, type: Int? = 0): Int { + return delegate.insertByDeviceType(deviceType, type, data) +// return when (deviceType) { +// UWDeviceType.UAV -> realTimeDataUavMapper.insertList(data as List<RealTimeDataUav>) +// UWDeviceType.VEHICLE -> realTimeDataVehicleMapper.insertList(data as List<RealTimeDataVehicle>) +// UWDeviceType.GRID -> realTimeDataGridMapper.insertList(data as List<RealTimeDataGrid>) +// UWDeviceType.BOAT -> 0 +// else -> 0 +// } + } + + fun deleteData(mission: Mission, type: Int? = 0): Int { + if (mission.deviceCode == null || mission.startTime == null || mission.endTime == null) { + throw BizException("瑕佸垹闄ょ殑璧拌埅浠诲姟缂哄け璁惧缂栧彿鎴栭噰鏍锋椂闂磋寖鍥达紝鏃犳硶鍒犻櫎瀵瑰簲鐩戞祴鏁版嵁") + } + return deleteData(UWDeviceType.fromValue(mission.deviceType), + mission.deviceCode, + mission.startTime, + mission.endTime, type) + } + + fun deleteData(deviceType: UWDeviceType?, deviceCode: String, sTime: Date?, eTime: Date?, type: Int? = 0): Int { + return delegate.deleteByDeviceType(deviceType, type) { + it.createCriteria().apply { + andEqualTo("deviceCode", deviceCode) + andGreaterThanOrEqualTo("dataTime", sTime) + andLessThanOrEqualTo("dataTime", eTime) + } + } + } + + fun deleteData( + deviceType: UWDeviceType?, deviceCode: String, sTime: LocalDateTime?, eTime: LocalDateTime?, type: Int? = 0, + ): Int = deleteData(deviceType, deviceCode, + Date.from(sTime?.atZone(ZoneId.systemDefault())?.toInstant()), + Date.from(eTime?.atZone(ZoneId.systemDefault())?.toInstant()), + type + ) + + fun deleteData(deviceType: UWDeviceType?, data: List<BaseRealTimeData>, type: Int? = 0) { + delegate.deleteByDeviceType(deviceType, type, data) + } } \ No newline at end of file -- Gitblit v1.9.3