【新增】上传飞行记录接口
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package com.corewing.app.dto.api;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class uploadReplaySessionRequest {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private Long startTime;
|
||||
private Long endTime;
|
||||
private Long duration; // 持续时间(秒)
|
||||
private Long dataCount; // 数据点数量
|
||||
private Date createdAt;
|
||||
private Date updatedAt;
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -2,11 +2,10 @@ package com.corewing.app.modules.app;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.corewing.app.common.Result;
|
||||
import com.corewing.app.dto.api.uploadReplaySessionRequest;
|
||||
import com.corewing.app.entity.ReplaySession;
|
||||
import com.corewing.app.service.ReplaySessionService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
@@ -18,9 +17,23 @@ public class AppReplaySessionController {
|
||||
@Resource
|
||||
private ReplaySessionService replaySessionService;
|
||||
|
||||
/**
|
||||
* 获取飞行记录
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getReplayList")
|
||||
public Result<List<ReplaySession>> getReplayList() {
|
||||
return Result.success(replaySessionService.getReplayList(StpUtil.getLoginId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传飞行记录
|
||||
* @param uploadReplaySessionRequests
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/uploadReplaySession")
|
||||
public Result<Boolean> uploadReplaySession(@RequestBody List<uploadReplaySessionRequest> uploadReplaySessionRequests) {
|
||||
return Result.isBool(replaySessionService.uploadReplaySession(uploadReplaySessionRequests));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.corewing.app.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.corewing.app.dto.api.uploadReplaySessionRequest;
|
||||
import com.corewing.app.entity.ReplaySession;
|
||||
|
||||
import java.util.List;
|
||||
@@ -8,4 +9,6 @@ import java.util.List;
|
||||
|
||||
public interface ReplaySessionService extends IService<ReplaySession> {
|
||||
List<ReplaySession> getReplayList(Object loginId);
|
||||
|
||||
boolean uploadReplaySession(List<uploadReplaySessionRequest> uploadReplaySessionRequests);
|
||||
}
|
||||
|
||||
@@ -2,19 +2,54 @@ package com.corewing.app.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
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.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 org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ReplaySession> getReplayList(Object loginId) {
|
||||
LambdaQueryWrapper<ReplaySession> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(ReplaySession::getUserId, loginId);
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public boolean uploadReplaySession(List<uploadReplaySessionRequest> uploadReplaySessionRequests) {
|
||||
uploadReplaySessionRequests.forEach(replaySessionRequest -> {
|
||||
ReplaySession replaySession = new ReplaySession();
|
||||
replaySession.setId(replaySessionRequest.getId());
|
||||
replaySession.setName(replaySessionRequest.getName());
|
||||
replaySession.setDuration(replaySessionRequest.getDuration());
|
||||
replaySession.setStartTime(replaySessionRequest.getStartTime());
|
||||
replaySession.setEndTime(replaySessionRequest.getEndTime());
|
||||
replaySession.setDescription(replaySessionRequest.getDescription());
|
||||
replaySession.setDataCount(replaySessionRequest.getDataCount());
|
||||
replaySession.setCreatedAt(replaySessionRequest.getCreatedAt());
|
||||
replaySession.setUpdatedAt(replaySessionRequest.getUpdatedAt());
|
||||
saveOrUpdate(replaySession);
|
||||
String json = gson.toJson(replaySessionRequest.getTrajectoryDataList());
|
||||
System.out.println(json);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user