diff --git a/dk-modules/business/src/main/java/org/dromara/business/feign/FeignDeviceGroup.java b/dk-modules/business/src/main/java/org/dromara/business/feign/FeignDeviceGroup.java index 4a36405..21924a8 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/feign/FeignDeviceGroup.java +++ b/dk-modules/business/src/main/java/org/dromara/business/feign/FeignDeviceGroup.java @@ -6,6 +6,7 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import java.util.List; +import java.util.Map; @FeignClient(name = "gateway",path = "sample") public interface FeignDeviceGroup { @@ -17,4 +18,8 @@ public interface FeignDeviceGroup { @GetMapping("/manage/api/v1/device/group/feign/device") public List listDevice(@RequestParam("userId") Long userId); + + + @GetMapping("/device/flight/count") + public Map getDevices(); } diff --git a/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertStatisticsServiceImpl.java b/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertStatisticsServiceImpl.java index 6ed5233..d4276b3 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertStatisticsServiceImpl.java +++ b/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertStatisticsServiceImpl.java @@ -186,57 +186,58 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist //----------------------------------------------获取飞行总架次、总时长---------------------------------------------- //获取飞行总架次、总时长 //获取机场信息根据当前登录人 - List deviceSnList = ObjectUtil.isNotEmpty(feignDeviceGroup.listDevice(LoginHelper.getUserId()))?feignDeviceGroup.listDevice(LoginHelper.getUserId()):ListUtil.empty(); +// List deviceSnList = ObjectUtil.isNotEmpty(feignDeviceGroup.listDevice(LoginHelper.getUserId()))?feignDeviceGroup.listDevice(LoginHelper.getUserId()):ListUtil.empty(); //过滤redis中用户所拥有的设备 - Map countMap = Optional.ofNullable(RedisUtils.getCacheMap(FLY_COUNT)) - .map(map -> map.entrySet().stream() - .filter(entry -> deviceSnList.contains(entry.getKey())) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))) - .orElse(new HashMap<>()); - - int flyCount; - - if (ObjectUtil.isNotEmpty(countMap)){ - flyCount = countMap.values().stream() - .filter(Objects::nonNull) - .mapToInt(value -> { - if (value instanceof Number) { - return ((Number) value).intValue(); - } - return 0; - }) - .sum(); - } else { - flyCount = 0; - } +// Map countMap = Optional.ofNullable(RedisUtils.getCacheMap(FLY_COUNT)) +// .map(map -> map.entrySet().stream() +// .filter(entry -> deviceSnList.contains(entry.getKey())) +// .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))) +// .orElse(new HashMap<>()); + +// int flyCount; +// +// if (ObjectUtil.isNotEmpty(countMap)){ +// flyCount = countMap.values().stream() +// .filter(Objects::nonNull) +// .mapToInt(value -> { +// if (value instanceof Number) { +// return ((Number) value).intValue(); +// } +// return 0; +// }) +// .sum(); +// } else { +// flyCount = 0; +// } //过滤redis中用户所拥有的设备 - Map accTimeMap = Optional.ofNullable(RedisUtils.getCacheMap(FLY_ACC_TIME)) - .map(map -> map.entrySet().stream() - .filter(entry -> deviceSnList.contains(entry.getKey())) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))) - .orElse(new HashMap<>()); - - - double flyAccTime; - - if (ObjectUtil.isNotEmpty(accTimeMap)) { - flyAccTime = accTimeMap.values().stream() - .filter(Objects::nonNull) - .mapToDouble(value -> { - if (value instanceof Number) { - return ((Number) value).doubleValue(); - } - return 0.0; - }) - .sum(); - } else { - flyAccTime = 0.0; - } +// Map accTimeMap = Optional.ofNullable(RedisUtils.getCacheMap(FLY_ACC_TIME)) +// .map(map -> map.entrySet().stream() +// .filter(entry -> deviceSnList.contains(entry.getKey())) +// .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))) +// .orElse(new HashMap<>()); +// +// +// double flyAccTime; +// +// if (ObjectUtil.isNotEmpty(accTimeMap)) { +// flyAccTime = accTimeMap.values().stream() +// .filter(Objects::nonNull) +// .mapToDouble(value -> { +// if (value instanceof Number) { +// return ((Number) value).doubleValue(); +// } +// return 0.0; +// }) +// .sum(); +// } else { +// flyAccTime = 0.0; +// } //----------------------------------------------获取飞行总架次、总时长---------------------------------------------- + Map devices = feignDeviceGroup.getDevices(); Map panel = baseMapper.countPanelAlert(businessAlertBo); @@ -245,8 +246,8 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist ObjectUtil.isEmpty(panel.get("total"))?0:panel.get("total"), ObjectUtil.isEmpty(panel.get("finishCount"))?0:panel.get("finishCount"), ObjectUtil.isEmpty(panel.get("cancelCount"))?0:panel.get("cancelCount"), - flyCount, - flyAccTime); + ObjectUtil.isEmpty(devices.get("flyCount"))?0:devices.get("flyCount"), + ObjectUtil.isEmpty(devices.get("flyAccTime"))?0:devices.get("flyAccTime")); } @Override diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/controller/DeviceFlightRecordsController.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/controller/DeviceFlightRecordsController.java new file mode 100644 index 0000000..44c721a --- /dev/null +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/controller/DeviceFlightRecordsController.java @@ -0,0 +1,28 @@ +package org.dromara.sample.manage.controller; + +import lombok.extern.slf4j.Slf4j; +import org.dromara.sample.manage.service.IDeviceFlightRecordsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@Slf4j +@RequestMapping("/device/flight") +public class DeviceFlightRecordsController { + + @Autowired + private IDeviceFlightRecordsService deviceFlightRecordsService; + + @GetMapping("/count") + public Map getDevices() { + log.info("----------------------------开始调用feign接口查询项目组----------------------------"); + Map deviceFlightCount = deviceFlightRecordsService.getDeviceFlightCount(); + log.info("----------------------------调用feign接口查询项目组结束----------------------------"); + return deviceFlightCount; + } + +} diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/mapper/DeviceFlightRecordsMapper.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/mapper/DeviceFlightRecordsMapper.java new file mode 100644 index 0000000..5db879e --- /dev/null +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/mapper/DeviceFlightRecordsMapper.java @@ -0,0 +1,7 @@ +package org.dromara.sample.manage.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.dromara.sample.manage.model.entity.DeviceFlightRecordsEntity; + +public interface DeviceFlightRecordsMapper extends BaseMapper { +} diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/model/entity/DeviceFlightRecordsEntity.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/model/entity/DeviceFlightRecordsEntity.java new file mode 100644 index 0000000..34d15f8 --- /dev/null +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/model/entity/DeviceFlightRecordsEntity.java @@ -0,0 +1,46 @@ +package org.dromara.sample.manage.model.entity; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@TableName(value = "device_flight_records") +public class DeviceFlightRecordsEntity { + + + @TableId(type = IdType.AUTO) + private Long id; + + /** + * 机场sn + */ + private String deviceSn; + + /** + * 飞行总架次 + */ + private Integer flyCount; + + /** + * 飞行总时长 + */ + private Integer flyAccTime; + + /** + * 创建时间 + */ + private Date createTime; + + +} diff --git a/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/IDeviceFlightRecordsService.java b/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/IDeviceFlightRecordsService.java new file mode 100644 index 0000000..71012f0 --- /dev/null +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/IDeviceFlightRecordsService.java @@ -0,0 +1,15 @@ +package org.dromara.sample.manage.service; + +import org.dromara.sample.manage.model.entity.DeviceFlightRecordsEntity; + +import java.util.List; +import java.util.Map; + +public interface IDeviceFlightRecordsService { + + + void saveDeviceFlight(List deviceFlightRecords); + + Map getDeviceFlightCount(); + +} 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 new file mode 100644 index 0000000..9f08d95 --- /dev/null +++ b/dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/DeviceFlightRecordsServiceImpl.java @@ -0,0 +1,59 @@ +package org.dromara.sample.manage.service.impl; + +import cn.hutool.core.util.ObjectUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.dromara.sample.manage.mapper.DeviceFlightRecordsMapper; +import org.dromara.sample.manage.model.entity.DeviceFlightRecordsEntity; +import org.dromara.sample.manage.service.IDeviceFlightRecordsService; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +@Service +public class DeviceFlightRecordsServiceImpl extends ServiceImpl implements IDeviceFlightRecordsService { + + + @Override + public void saveDeviceFlight(List deviceFlightRecords) { + + deviceFlightRecords.forEach(deviceFlightRecord -> { + //查询之前的数据 + DeviceFlightRecordsEntity deviceFlightRecordsEntities = this.baseMapper.selectOne(new LambdaQueryWrapper().eq(DeviceFlightRecordsEntity::getDeviceSn,deviceFlightRecord.getDeviceSn())); + + if (ObjectUtil.isNotEmpty(deviceFlightRecordsEntities)) { + deviceFlightRecordsEntities.setFlyCount(deviceFlightRecordsEntities.getFlyCount() + deviceFlightRecord.getFlyCount()); + deviceFlightRecordsEntities.setFlyAccTime(deviceFlightRecordsEntities.getFlyAccTime() + deviceFlightRecord.getFlyAccTime()); + + this.updateById(deviceFlightRecordsEntities); + }else { + this.save(deviceFlightRecord); + } + }); + } + + @Override + public Map getDeviceFlightCount() { + Map resultMap = new HashMap<>(); + + List deviceFlightRecordsEntities = this.baseMapper.selectList(new LambdaQueryWrapper<>()); + + int flyCount = deviceFlightRecordsEntities.stream() + .map(DeviceFlightRecordsEntity::getFlyCount) + .reduce(0, Integer::sum); + + + int flyAccTime = deviceFlightRecordsEntities.stream() + .map(DeviceFlightRecordsEntity::getFlyAccTime) + .reduce(0, Integer::sum); + + + resultMap.put("flyCount",flyCount); + resultMap.put("flyAccTime",flyAccTime); + + return resultMap; + } +} diff --git a/dk-modules/sample/src/main/resources/mapper/DeviceFlightRecordsMapper.xml b/dk-modules/sample/src/main/resources/mapper/DeviceFlightRecordsMapper.xml new file mode 100644 index 0000000..0b77503 --- /dev/null +++ b/dk-modules/sample/src/main/resources/mapper/DeviceFlightRecordsMapper.xml @@ -0,0 +1,8 @@ + + + + + +