Browse Source

获取飞行数据信息代码提交

tags/v1.3.1
chengwang 1 year ago
parent
commit
9c987d671b
5 changed files with 416 additions and 16 deletions
  1. +2
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/FlightDataHl.java
  2. +299
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/response/TZHLAirportFlightDataResponse.java
  3. +108
    -10
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/service/fly/data/FlyDataService.java
  4. +3
    -2
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/task/FlyDataTask.java
  5. +4
    -3
      tuoheng-service/tuoheng-admin/src/test/java/com/tuoheng/admin/tzhl/TZHLGetAirportMsgServiceTest.java

+ 2
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/FlightDataHl.java View File

@@ -6,6 +6,7 @@ import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;

/**
@@ -17,7 +18,7 @@ import java.util.Date;
@Data
@Accessors(chain = true)
@TableName("th_flight_data_hl")
public class FlightDataHl {
public class FlightDataHl implements Serializable {

private static final long serialVersionUID = 1L;


+ 299
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/response/TZHLAirportFlightDataResponse.java View File

@@ -0,0 +1,299 @@
package com.tuoheng.admin.tzhl.response;

import lombok.Data;

/**
* @Author ChengWang
* @Date 2023/8/14
*/
@Data
public class TZHLAirportFlightDataResponse {

/**
* ID
*/
private Long id;

/**
* 租户ID
*/
private String tenantId;

/**
* 巡检任务ID
*/
private String inspectionId;

/**
* 飞行记录编号
*/
private Long recordId;

/**
* 飞行计划编号
*
*/
private Long attachRD;

/**
* 无人机ID
*
*/
private Long uavId;

/**
* 无人机ID
*/
private String uavNo;

/**
* 北京时间 精确到毫秒
*/
private Long time;

/**
* 海拔高度 米
*/
private String alt;

/**
* 经度
*/
private String lng;

/**
* 纬度
*/
private String lat;

/**
* 地速 米/秒
*/
private String spd;

/**
* 离地高度 实际为距离起飞点的相对高度
*
*/
private String ht;

/**
* 真航向 单位:度,取值范围:[0,360]
*
*/
private String head;

/**
* 俯仰角 单位: 度,取值范围:[-90,90]
*/
private String pit;

/**
* 横滚角 单位:度,取值范围:[-90,90] 向左为正,向右为负
*
*/
private String roll;

/**
* 电池容量 百分比
*/
private String bat;

/**
* 电池电压 伏特
*/
private String vol;

/**
* 燃油剩余量百分比,或燃油数量,升
*/
private String fuel;

/**
* 活动类型 1 land-降落/ 2 track-轨迹记录
*/
private Long act;

/**
* 飞行模式,READY: 准备起飞,TAKEOFF: 正在起飞,HOLD: 正在盘旋,MISSION:正在按航线飞行,RETURN_TO_LAUNCH:
* 返航 LAND:降落,OFFBOARD:外部接管中,FOLLOW_ME:跟随动态位置,UNKNOWN: 未知模式 0~8
*/
private Long mode;

/**
* 飞行模式(天枢传输的模式)
*/
private String flightMode;

/**
* 马达是否启动
*/
private String arm;

/**
* 是否起飞到空中
*/
private String air;

/**
* 当前绝对速度
*/
private String absp;

/**
* 环境温度 摄氏度
*/
private String temp;

/**
* 当前故障码
*/
private String tc;

/**
* 垂直速度
*/
private String velocityZ;

/**
* 剩余飞行时间
*/
private String remainingFlightTime;

/**
* 信号质量 4G_ 5G_
*/
private String moduleSignal;

/**
* 卫星数量
*/
private String satellite;

/**
* 查询用(提供外部接口)
*/
private Long deptId;

/**
* polit是否打开
*/
private String appConnected;

/**
* 遥控器是否连接
*/
private String groundConnected;

/**
* 飞机控制权
*/
private String controlDevice;

/**
* 遥控器档位
*/
private String rcControlPosition;

/**
* gps信号等级
*/
private String gps;

/**
* 下视激光测距
*/
private String ultrasonicHeight;

/**
* 混合气压计海拔高度
*/
private String altitudeFused;

/**
* gps混合84椭球高程
*/
private String latLonAltitude;

/**
* home点经纬度
*/
private String homeLocation;

/**
* 电池电量
*/
private String duration;

/**
* 1号电池电量
*/
private String battery1CapacityPercent;

/**
* 1号电池电压
*/
private String battery1Voltage;

/**
* 1号电池温度
*/
private String battery1Temperature;

/**
* 1号电池加热
*/
private String battery1HeatState;

/**
* 2号电池电量
*/
private String battery2CapacityPercent;

/**
* 2号电池电压
*/
private String battery2Voltage;

/**
* 2号电池温度
*/
private String battery2Temperature;

/**
* 2号电池加热
*/
private String battery2HeatState;

/**
* 云台俯仰
*/
private String gimbalPitch;

/**
* 云台偏航
*/
private String gimbalYaw;

/**
* 云台横滚
*/
private String gimbalRoll;

/**
* 焦距倍数
*/
private String zoomRatio;

/**
* 变焦镜头焦距
*/
private String focalLength;

/**
* 视频源(广角/变焦/红外)
*/
private String videoStreamSource;


}

+ 108
- 10
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/service/fly/data/FlyDataService.java View File

@@ -1,14 +1,28 @@
package com.tuoheng.admin.tzhl.service.fly.data;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tuoheng.admin.entity.FlightData;
import com.tuoheng.admin.entity.FlightDataHl;
import com.tuoheng.admin.entity.Inspection;
import com.tuoheng.admin.enums.MarkEnum;
import com.tuoheng.admin.mapper.FlightDataHlMapper;
import com.tuoheng.admin.mapper.FlightDataMapper;
import com.tuoheng.admin.tzhl.constant.TZHLConstant;
import com.tuoheng.admin.tzhl.request.TZHLFlyDataRequest;
import com.tuoheng.admin.tzhl.response.TZHLAirportFlightDataResponse;
import com.tuoheng.admin.tzhl.response.TZHLFlyDataResponse;
import com.tuoheng.admin.tzhl.response.TZHLFlyLogResponse;
import com.tuoheng.admin.tzhl.service.CallTianYiPlatformService;
import com.tuoheng.admin.utils.CurrentUserUtil;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.RedisUtils;
import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpEntity;
@@ -17,6 +31,12 @@ import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.sql.Wrapper;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class FlyDataService {
@@ -28,28 +48,106 @@ public class FlyDataService {
@Qualifier("restTemplate")
private RestTemplate restTemplate;

@Autowired
private FlightDataHlMapper flightDataHlMapper;

@Autowired
private CallTianYiPlatformService callTianYiPlatformService;

public void getFlyData(Inspection inspection) {

String apiPath = TZHLConstant.TIAN_YI_API_FLIGHT_DATA;

TZHLFlyDataRequest request = new TZHLFlyDataRequest();
request.setRecordId(null);
request.setDeptId("");
request.setCreateTime(null);
JSONObject jsonObject = this.jsonObjectRequest(inspection);

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity httpEntity = new HttpEntity(request, headers);
String dataJson = callTianYiPlatformService.callPost(apiPath, jsonObject);

List<TZHLAirportFlightDataResponse> flightDataHlList = JSON.parseArray(dataJson, TZHLAirportFlightDataResponse.class);

String dataJson = callTianYiPlatformService.callGet(apiPath, null);
//查询到的数据 入库
this.addFlightDataHl(inspection,flightDataHlList);

TZHLFlyLogResponse flyDataResponse = JSON.parseObject(dataJson, TZHLFlyLogResponse.class);
}

/**
* 飞行数据入库
* @param inspection
* @param flightDataHlList
* @return
*/
private void addFlightDataHl(Inspection inspection, List<TZHLAirportFlightDataResponse> flightDataHlList) {
if(CollectionUtil.isNotEmpty(flightDataHlList) && flightDataHlList.size() != 0){

for (TZHLAirportFlightDataResponse responseData : flightDataHlList) {
FlightDataHl flightDataHl = new FlightDataHl();
BeanUtils.copyProperties(responseData,flightDataHl);
flightDataHl.setTenantId(inspection.getTenantId());
flightDataHl.setInspectionId(inspection.getId());

//将最新的一条数据存入缓存,并设置过期时间
redisUtils.set(String.valueOf(inspection.getId()),flightDataHl,10);
int count = flightDataHlMapper.insert(flightDataHl);
if(count<=0){
log.info("输入插入失败,responseData:{}",responseData);
throw new SecurityException("飞行数据插入失败");
}
}
}
return;
}

// TODO
private JSONObject jsonObjectRequest(Inspection inspection) {
JsonResult jsonResult = this.check(inspection);
if(jsonResult.getCode() != 0){
return null;
}
//根据任务获取对应的部门
String deptId = inspection.getDeptId();
Long recordId = inspection.getRecordId();

JSONObject jsonObject = new JSONObject();
jsonObject.put("recordId",recordId);
jsonObject.put("deptId",deptId);
//查飞行数据最新一条的生成时间
this.getCreateTime(inspection,jsonObject);

return jsonObject;
}

/**
* 获取最新的一条数据信息
* @param inspection
* @return
*/
private void getCreateTime(Inspection inspection,JSONObject jsonObject) {
String tenantId = CurrentUserUtil.getTenantId();

List<FlightDataHl> flightDataHl = flightDataHlMapper.selectList(new LambdaQueryWrapper<FlightDataHl>()
.eq(FlightDataHl::getMark, MarkEnum.VALID.getCode())
.eq(FlightDataHl::getTenantId, tenantId)
.eq(FlightDataHl::getInspectionId, inspection.getId())
.orderByDesc(FlightDataHl::getCreateTime)
.last("limit 1"));

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

if(ObjectUtil.isNotNull(flightDataHl.get(0))){
Date createTime = flightDataHl.get(0).getCreateTime();
String dateString = sdf.format(createTime);
jsonObject.put("createTime",dateString);
}else {
return;
}
}

private JsonResult check(Inspection inspection) {
if(StringUtils.isEmpty(inspection.getDeptId())){
return JsonResult.error("任务部门id为空");
}
if(null == inspection.getRecordId()){
return JsonResult.error("飞行记录id为空");
}
return JsonResult.success();
}



+ 3
- 2
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/task/FlyDataTask.java View File

@@ -47,12 +47,13 @@ public class FlyDataTask {
.eq(Inspection::getInspectionType, InspectionTypeEnum.AIRPORT.getCode())
//查询未执行任务
.eq(Inspection::getExecutionStatus, 1)
//任务飞行
.eq(Inspection::getStatus, InspectionStatusEnum.WAIT_FLIGHT.getCode()));
//任务飞行
.eq(Inspection::getStatus, InspectionStatusEnum.IN_FLIGHT.getCode()));
log.info("执行定时执行飞行任务:机场任务数" + inspectionList.size());
if (StringUtils.isEmpty(inspectionList)) {
return;
}
//遍历任务列表中正在执行的任务进行飞行数据入库
for (Inspection inspection : inspectionList) {
log.info("执行定时,获取飞行数据: inspectionId:{}", inspection.getId());


+ 4
- 3
tuoheng-service/tuoheng-admin/src/test/java/com/tuoheng/admin/tzhl/TZHLGetAirportMsgServiceTest.java View File

@@ -1,5 +1,6 @@
package com.tuoheng.admin.tzhl;

import com.tuoheng.admin.tzhl.response.TZHLAirportMsgResponse;
import com.tuoheng.admin.tzhl.service.airport.TZHLGetAirportMsgService;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
@@ -25,9 +26,9 @@ public class TZHLGetAirportMsgServiceTest {
public void testGetAirportListTest() {

String sn = "4TADKCC0010018";
JsonResult result = tzhlGetAirportMsgService.getAirportMsg(sn);
log.info("获取结果值为result:{}",result);
System.out.println("data" + result.getData());
TZHLAirportMsgResponse airportMsg = tzhlGetAirportMsgService.getAirportMsg(sn);
log.info("获取结果值为result:{}",airportMsg);
System.out.println("data" + airportMsg);
}

}

Loading…
Cancel
Save