Browse Source

[feat]

1、增加飞行总架次总时长保存接口以及修改获取时长接口①
pull/4/head
杨威 2 months ago
parent
commit
e52025e9cf
  1. 5
      dk-modules/business/src/main/java/org/dromara/business/feign/FeignDeviceGroup.java
  2. 93
      dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertStatisticsServiceImpl.java
  3. 28
      dk-modules/sample/src/main/java/org/dromara/sample/manage/controller/DeviceFlightRecordsController.java
  4. 7
      dk-modules/sample/src/main/java/org/dromara/sample/manage/mapper/DeviceFlightRecordsMapper.java
  5. 46
      dk-modules/sample/src/main/java/org/dromara/sample/manage/model/entity/DeviceFlightRecordsEntity.java
  6. 15
      dk-modules/sample/src/main/java/org/dromara/sample/manage/service/IDeviceFlightRecordsService.java
  7. 59
      dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/DeviceFlightRecordsServiceImpl.java
  8. 8
      dk-modules/sample/src/main/resources/mapper/DeviceFlightRecordsMapper.xml

5
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<String> listDevice(@RequestParam("userId") Long userId);
@GetMapping("/device/flight/count")
public Map<String,Integer> getDevices();
}

93
dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertStatisticsServiceImpl.java

@ -186,57 +186,58 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist
//----------------------------------------------获取飞行总架次、总时长----------------------------------------------
//获取飞行总架次、总时长
//获取机场信息根据当前登录人
List<String> deviceSnList = ObjectUtil.isNotEmpty(feignDeviceGroup.listDevice(LoginHelper.getUserId()))?feignDeviceGroup.listDevice(LoginHelper.getUserId()):ListUtil.empty();
// List<String> deviceSnList = ObjectUtil.isNotEmpty(feignDeviceGroup.listDevice(LoginHelper.getUserId()))?feignDeviceGroup.listDevice(LoginHelper.getUserId()):ListUtil.empty();
//过滤redis中用户所拥有的设备
Map<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Integer> devices = feignDeviceGroup.getDevices();
Map<String, Object> 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

28
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<String,Integer> getDevices() {
log.info("----------------------------开始调用feign接口查询项目组----------------------------");
Map<String, Integer> deviceFlightCount = deviceFlightRecordsService.getDeviceFlightCount();
log.info("----------------------------调用feign接口查询项目组结束----------------------------");
return deviceFlightCount;
}
}

7
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<DeviceFlightRecordsEntity> {
}

46
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;
}

15
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<DeviceFlightRecordsEntity> deviceFlightRecords);
Map<String,Integer> getDeviceFlightCount();
}

59
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<DeviceFlightRecordsMapper,DeviceFlightRecordsEntity> implements IDeviceFlightRecordsService {
@Override
public void saveDeviceFlight(List<DeviceFlightRecordsEntity> deviceFlightRecords) {
deviceFlightRecords.forEach(deviceFlightRecord -> {
//查询之前的数据
DeviceFlightRecordsEntity deviceFlightRecordsEntities = this.baseMapper.selectOne(new LambdaQueryWrapper<DeviceFlightRecordsEntity>().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<String,Integer> getDeviceFlightCount() {
Map<String,Integer> resultMap = new HashMap<>();
List<DeviceFlightRecordsEntity> 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;
}
}

8
dk-modules/sample/src/main/resources/mapper/DeviceFlightRecordsMapper.xml

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.dromara.sample.manage.mapper.DeviceFlightRecordsMapper">
</mapper>
Loading…
Cancel
Save