|
|
@ -9,9 +9,7 @@ import org.dromara.sample.manage.service.IDeviceFlightRecordsService; |
|
|
|
import org.springframework.scheduling.annotation.Async; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
@ -19,18 +17,30 @@ public class DeviceFlightRecordsServiceImpl extends ServiceImpl<DeviceFlightReco |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void saveDeviceFlight(DeviceFlightRecordsEntity deviceFlightRecords) { |
|
|
|
public void saveDeviceFlight(DeviceFlightRecordsEntity currentFlightRecord) { |
|
|
|
|
|
|
|
//查询之前的数据
|
|
|
|
DeviceFlightRecordsEntity deviceFlightRecordsEntities = this.baseMapper.selectOne(new LambdaQueryWrapper<DeviceFlightRecordsEntity>().eq(DeviceFlightRecordsEntity::getDeviceSn,deviceFlightRecords.getDeviceSn())); |
|
|
|
DeviceFlightRecordsEntity deviceFlightRecordsEntities = this.baseMapper.selectOne(new LambdaQueryWrapper<DeviceFlightRecordsEntity>().eq(DeviceFlightRecordsEntity::getDeviceSn,currentFlightRecord.getDeviceSn())); |
|
|
|
|
|
|
|
//不为空
|
|
|
|
if (ObjectUtil.isNotEmpty(deviceFlightRecordsEntities)) { |
|
|
|
deviceFlightRecordsEntities.setFlyCount(deviceFlightRecordsEntities.getFlyCount() + deviceFlightRecords.getFlyCount()); |
|
|
|
deviceFlightRecordsEntities.setFlyAccTime(deviceFlightRecordsEntities.getFlyAccTime() + deviceFlightRecords.getFlyAccTime()); |
|
|
|
//飞行总架次大于等于表中数据替换 否则累加
|
|
|
|
if (currentFlightRecord.getFlyCount() >= deviceFlightRecordsEntities.getFlyCount()){ |
|
|
|
deviceFlightRecordsEntities.setFlyCount(currentFlightRecord.getFlyCount()); |
|
|
|
}else { |
|
|
|
deviceFlightRecordsEntities.setFlyCount(deviceFlightRecordsEntities.getFlyCount() + currentFlightRecord.getFlyCount()); |
|
|
|
} |
|
|
|
|
|
|
|
//飞行总时长大于等于表中数据替换 否则累加
|
|
|
|
if (currentFlightRecord.getFlyAccTime() >= deviceFlightRecordsEntities.getFlyAccTime()){ |
|
|
|
deviceFlightRecordsEntities.setFlyAccTime(currentFlightRecord.getFlyAccTime()); |
|
|
|
}else { |
|
|
|
deviceFlightRecordsEntities.setFlyAccTime(deviceFlightRecordsEntities.getFlyAccTime() + currentFlightRecord.getFlyAccTime()); |
|
|
|
} |
|
|
|
|
|
|
|
this.updateById(deviceFlightRecordsEntities); |
|
|
|
}else { |
|
|
|
this.save(deviceFlightRecords); |
|
|
|
this.save(currentFlightRecord); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -40,18 +50,28 @@ public class DeviceFlightRecordsServiceImpl extends ServiceImpl<DeviceFlightReco |
|
|
|
|
|
|
|
List<DeviceFlightRecordsEntity> deviceFlightRecordsEntities = this.baseMapper.selectList(new LambdaQueryWrapper<>()); |
|
|
|
|
|
|
|
int flyCount = deviceFlightRecordsEntities.stream() |
|
|
|
int flyCount = Optional.ofNullable(deviceFlightRecordsEntities) |
|
|
|
.map(list -> list.stream() |
|
|
|
.map(DeviceFlightRecordsEntity::getFlyCount) |
|
|
|
.reduce(0, Integer::sum); |
|
|
|
.reduce(0, Integer::sum)) |
|
|
|
.orElse(0); |
|
|
|
|
|
|
|
|
|
|
|
// int flyAccTime = deviceFlightRecordsEntities.stream()
|
|
|
|
// .map(DeviceFlightRecordsEntity::getFlyAccTime)
|
|
|
|
// .reduce(0, Integer::sum);
|
|
|
|
|
|
|
|
int flyAccTime = deviceFlightRecordsEntities.stream() |
|
|
|
int flyAccTime = Optional.ofNullable(deviceFlightRecordsEntities) |
|
|
|
.map(list -> list.stream() |
|
|
|
.map(DeviceFlightRecordsEntity::getFlyAccTime) |
|
|
|
.reduce(0, Integer::sum); |
|
|
|
.reduce(0, Integer::sum)) |
|
|
|
.orElse(0); |
|
|
|
|
|
|
|
|
|
|
|
int flyAccTimeHour = (int) Math.round(flyAccTime / 3600.0); |
|
|
|
|
|
|
|
resultMap.put("flyCount",flyCount); |
|
|
|
resultMap.put("flyAccTime",flyAccTime); |
|
|
|
resultMap.put("flyAccTime",flyAccTimeHour); |
|
|
|
|
|
|
|
return resultMap; |
|
|
|
} |
|
|
|