diff --git a/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java b/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java index 9b0b85d..61c4db4 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java +++ b/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java @@ -247,7 +247,7 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService { QueryWrapper wrapper = buildQueryWrapper(bo); if (ObjectUtil.isEmpty(wrapper)){ - return new TableDataInfo<>(); + return TableDataInfo.build(); } Page page = this.baseMapper.pageBusinessAlert(pageQuery.build(), wrapper, ptPrefix); @@ -282,7 +282,7 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService { QueryWrapper wrapper = buildQueryWrapper(bo); if (ObjectUtil.isEmpty(wrapper)){ - return new TableDataInfo<>(); + return TableDataInfo.build(); } wrapper.in("t.flowStatus", BusinessStatusEnum.CANCEL.getStatus()); @@ -319,7 +319,7 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService { QueryWrapper wrapper = buildQueryWrapper(bo); if (ObjectUtil.isEmpty(wrapper)){ - return new TableDataInfo<>(); + return TableDataInfo.build(); } wrapper.eq("t.handle_type",BusinessStatusEnum.FINISH.getStatus()); @@ -356,7 +356,7 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService { QueryWrapper wrapper = buildQueryWrapper(bo); if (ObjectUtil.isEmpty(wrapper)){ - return new TableDataInfo<>(); + return TableDataInfo.build(); } wrapper.eq("t.node_type", 1); @@ -401,7 +401,7 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService { QueryWrapper wrapper = buildQueryWrapper(bo); if (ObjectUtil.isEmpty(wrapper)){ - return new TableDataInfo<>(); + return TableDataInfo.build(); } String tableWorkflow = ptPrefix.getTableWorkflow(); // eg: "dk_workflow" diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/DeviceFlightRecordsServiceImpl.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/DeviceFlightRecordsServiceImpl.java index d441791..61caff5 100644 --- a/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/DeviceFlightRecordsServiceImpl.java +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/DeviceFlightRecordsServiceImpl.java @@ -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().eq(DeviceFlightRecordsEntity::getDeviceSn,deviceFlightRecords.getDeviceSn())); + DeviceFlightRecordsEntity deviceFlightRecordsEntities = this.baseMapper.selectOne(new LambdaQueryWrapper().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 deviceFlightRecordsEntities = this.baseMapper.selectList(new LambdaQueryWrapper<>()); - int flyCount = deviceFlightRecordsEntities.stream() - .map(DeviceFlightRecordsEntity::getFlyCount) - .reduce(0, Integer::sum); + int flyCount = Optional.ofNullable(deviceFlightRecordsEntities) + .map(list -> list.stream() + .map(DeviceFlightRecordsEntity::getFlyCount) + .reduce(0, Integer::sum)) + .orElse(0); - int flyAccTime = deviceFlightRecordsEntities.stream() - .map(DeviceFlightRecordsEntity::getFlyAccTime) - .reduce(0, Integer::sum); +// int flyAccTime = deviceFlightRecordsEntities.stream() +// .map(DeviceFlightRecordsEntity::getFlyAccTime) +// .reduce(0, Integer::sum); + int flyAccTime = Optional.ofNullable(deviceFlightRecordsEntities) + .map(list -> list.stream() + .map(DeviceFlightRecordsEntity::getFlyAccTime) + .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; }