【新增】飞行记录删除接口及数据同步
This commit is contained in:
47
src/main/java/com/corewing/app/dto/api/TrajectoryData.java
Normal file
47
src/main/java/com/corewing/app/dto/api/TrajectoryData.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package com.corewing.app.dto.api;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class TrajectoryData {
|
||||
private Long id;
|
||||
private Long session_id;
|
||||
private Long timestamp;
|
||||
|
||||
// 基础遥测数据
|
||||
private Long rc;
|
||||
private Long gps;
|
||||
private Long gps_status;
|
||||
private double voltage;
|
||||
private double cell_voltage;
|
||||
private Long consumption;
|
||||
private double current;
|
||||
private double speed;
|
||||
private double air_speed;
|
||||
private double v_speed;
|
||||
private double altitude;
|
||||
private double distance;
|
||||
private double range;
|
||||
private Long throttle;
|
||||
private Long wind_direction;
|
||||
private double wind_speed;
|
||||
private Long heading;
|
||||
private double roll;
|
||||
private double pitch;
|
||||
private double yaw;
|
||||
|
||||
// 扩展数据
|
||||
private double compass_heading;
|
||||
private double drone_lat;
|
||||
private double drone_lon;
|
||||
private double home_lat;
|
||||
private double home_lon;
|
||||
private String map_type;
|
||||
private Boolean show_trajectory;
|
||||
private String flight_mode;
|
||||
private Long vehicle_type;
|
||||
private Long autopilot_type;
|
||||
private Boolean is_armed;
|
||||
|
||||
private String sync_id;
|
||||
}
|
||||
@@ -11,57 +11,16 @@ public class uploadReplaySessionRequest {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private Long startTime;
|
||||
private Long endTime;
|
||||
private Long start_time;
|
||||
private Long end_time;
|
||||
private Long duration; // 持续时间(秒)
|
||||
private Long dataCount; // 数据点数量
|
||||
private Date createdAt;
|
||||
private Date updatedAt;
|
||||
|
||||
private Long data_count; // 数据点数量
|
||||
private Date created_at;
|
||||
private Date updated_at;
|
||||
private String sync_id;
|
||||
List<TrajectoryData> trajectoryDataList;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Data
|
||||
class TrajectoryData {
|
||||
private Long id;
|
||||
private Long sessionId;
|
||||
private Long timestamp;
|
||||
|
||||
// 基础遥测数据
|
||||
private Long rc;
|
||||
private Long gps;
|
||||
private Long gpsStatus;
|
||||
private double voltage;
|
||||
private double cellVoltage;
|
||||
private Long consumption;
|
||||
private double current;
|
||||
private double speed;
|
||||
private double airSpeed;
|
||||
private double vSpeed;
|
||||
private double altitude;
|
||||
private double distance;
|
||||
private double range;
|
||||
private Long throttle;
|
||||
private Long windDirection;
|
||||
private double windSpeed;
|
||||
private Long heading;
|
||||
private double roll;
|
||||
private double pitch;
|
||||
private double yaw;
|
||||
|
||||
// 扩展数据
|
||||
private double compassHeading;
|
||||
private double droneLat;
|
||||
private double droneLon;
|
||||
private double homeLat;
|
||||
private double homeLon;
|
||||
private String mapType;
|
||||
private Boolean showTrajectory;
|
||||
private String flightMode;
|
||||
private Long vehicleType;
|
||||
private Long autopilotType;
|
||||
private Boolean isArmed;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.corewing.app.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.corewing.app.dto.api.TrajectoryData;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@TableName("app_replay_session")
|
||||
@@ -14,9 +17,11 @@ public class ReplaySession {
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.INPUT)
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private String syncId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@@ -66,4 +71,10 @@ public class ReplaySession {
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updatedAt;
|
||||
|
||||
/**
|
||||
* 轨迹数据点
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
List<TrajectoryData> trajectoryDataList;
|
||||
}
|
||||
|
||||
@@ -36,4 +36,14 @@ public class AppReplaySessionController {
|
||||
return Result.isBool(replaySessionService.uploadReplaySession(uploadReplaySessionRequests));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据同步id删除数据
|
||||
* @param syncId
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping("/deleteReplaySession/{syncId}")
|
||||
public Result<Boolean> deleteReplaySession(@PathVariable String syncId) {
|
||||
return Result.isBool(replaySessionService.deleteReplaySession(syncId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,10 @@ import java.util.List;
|
||||
|
||||
|
||||
public interface ReplaySessionService extends IService<ReplaySession> {
|
||||
|
||||
List<ReplaySession> getReplayList(Object loginId);
|
||||
|
||||
boolean uploadReplaySession(List<uploadReplaySessionRequest> uploadReplaySessionRequests);
|
||||
|
||||
boolean deleteReplaySession(String syncId);
|
||||
}
|
||||
|
||||
@@ -1,55 +1,121 @@
|
||||
package com.corewing.app.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.corewing.app.dto.api.TrajectoryData;
|
||||
import com.corewing.app.dto.api.uploadReplaySessionRequest;
|
||||
import com.corewing.app.entity.ReplaySession;
|
||||
import com.corewing.app.mapper.ReplaySessionMapper;
|
||||
import com.corewing.app.service.ReplaySessionService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.corewing.app.util.OSSUploadUtil;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.codehaus.jettison.json.JSONArray;
|
||||
import org.codehaus.jettison.json.JSONObject;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ReplaySessionServiceImpl extends ServiceImpl<ReplaySessionMapper, ReplaySession> implements ReplaySessionService {
|
||||
private final Gson gson;
|
||||
|
||||
public ReplaySessionServiceImpl(Gson gson) {
|
||||
this.gson = gson;
|
||||
}
|
||||
@Resource
|
||||
private Gson gson;
|
||||
|
||||
/**
|
||||
* 获取飞行记录
|
||||
* @param loginId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<ReplaySession> getReplayList(Object loginId) {
|
||||
LambdaQueryWrapper<ReplaySession> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(ReplaySession::getUserId, loginId);
|
||||
return this.list(queryWrapper);
|
||||
// 去oss里面下载对应的json文件流,解析到文件里面
|
||||
List<ReplaySession> list = list(queryWrapper);
|
||||
list.forEach(m -> {
|
||||
try {
|
||||
InputStream inputStream = OSSUploadUtil.downloadFileToStream(m.getOssPath());
|
||||
List<TrajectoryData> dataList = new Gson().fromJson(
|
||||
new InputStreamReader(inputStream, StandardCharsets.UTF_8),
|
||||
new TypeToken<List<TrajectoryData>>() {}.getType() // 增加 .getType()
|
||||
);
|
||||
m.setTrajectoryDataList(dataList);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步飞行记录
|
||||
* @param uploadReplaySessionRequests
|
||||
* @return
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public boolean uploadReplaySession(List<uploadReplaySessionRequest> uploadReplaySessionRequests) {
|
||||
uploadReplaySessionRequests.forEach(replaySessionRequest -> {
|
||||
|
||||
// 校验是否重复
|
||||
LambdaQueryWrapper<ReplaySession> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(ReplaySession::getSyncId, replaySessionRequest.getSync_id());
|
||||
if (count(queryWrapper) > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
ReplaySession replaySession = new ReplaySession();
|
||||
replaySession.setId(replaySessionRequest.getId());
|
||||
replaySession.setSyncId(replaySessionRequest.getSync_id());
|
||||
replaySession.setName(replaySessionRequest.getName());
|
||||
replaySession.setDuration(replaySessionRequest.getDuration());
|
||||
replaySession.setStartTime(replaySessionRequest.getStartTime());
|
||||
replaySession.setEndTime(replaySessionRequest.getEndTime());
|
||||
replaySession.setStartTime(replaySessionRequest.getStart_time());
|
||||
replaySession.setEndTime(replaySessionRequest.getEnd_time());
|
||||
replaySession.setDescription(replaySessionRequest.getDescription());
|
||||
replaySession.setDataCount(replaySessionRequest.getDataCount());
|
||||
replaySession.setCreatedAt(replaySessionRequest.getCreatedAt());
|
||||
replaySession.setUpdatedAt(replaySessionRequest.getUpdatedAt());
|
||||
saveOrUpdate(replaySession);
|
||||
replaySession.setDataCount(replaySessionRequest.getData_count());
|
||||
replaySession.setCreatedAt(replaySessionRequest.getCreated_at());
|
||||
replaySession.setUpdatedAt(replaySessionRequest.getUpdated_at());
|
||||
replaySession.setUserId(Long.valueOf(StpUtil.getLoginId().toString()));
|
||||
|
||||
String json = gson.toJson(replaySessionRequest.getTrajectoryDataList());
|
||||
System.out.println(json);
|
||||
// 必须指定编码,避免平台默认编码问题
|
||||
InputStream inputStream = new ByteArrayInputStream(
|
||||
json.getBytes(StandardCharsets.UTF_8)
|
||||
);
|
||||
String ossPath = "trajectory/" + replaySessionRequest.getSync_id() + ".json";
|
||||
OSSUploadUtil.uploadFile(inputStream, ossPath);
|
||||
|
||||
replaySession.setOssPath(ossPath);
|
||||
save(replaySession);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据syncId删除数据
|
||||
* @param syncId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteReplaySession(String syncId) {
|
||||
LambdaQueryWrapper<ReplaySession> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(ReplaySession::getSyncId, syncId);
|
||||
ReplaySession replaySession = this.getOne(queryWrapper);
|
||||
if (replaySession == null) {
|
||||
return false;
|
||||
}
|
||||
OSSUploadUtil.deleteFile("trajectory/" + syncId + ".json");
|
||||
return removeById(replaySession.getId());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user