package com.ard.route.util;
|
|
import com.ard.route.domain.djuav.ActionGroupReq;
|
import com.ard.route.domain.djuav.PointActionReq;
|
import com.ard.route.domain.djuav.RoutePointReq;
|
import com.ard.route.domain.djuav.UavRouteReq;
|
import com.ard.route.domain.djuav.kml.*;
|
import com.ard.route.domain.route.ArdRouteInfo;
|
import com.ard.route.domain.vo.KmzInfoVo;
|
import com.ard.work.domain.dto.state.PointData;
|
import com.ard.work.domain.dto.wayline.PlanLineData;
|
import com.ard.work.domain.dto.wayline.PointAction;
|
import com.ard.work.domain.dto.wayline.WayLineUploadDTO;
|
import org.apache.commons.compress.archivers.ArchiveEntry;
|
import org.apache.commons.compress.archivers.ArchiveInputStream;
|
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import java.io.InputStream;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Objects;
|
|
import static com.ard.route.util.ToolUtils.getDoublePoint;
|
|
public class UavRouteReqUtils {
|
|
// 将文件转换成 UavRouteReq 实体
|
public static UavRouteReq fileConversionEntity(MultipartFile file){
|
KmzInfoVo kmzInfoVO = new KmzInfoVo();
|
try (InputStream inputStream = file.getInputStream();
|
ArchiveInputStream archiveInputStream = new ZipArchiveInputStream(inputStream)){
|
ArchiveEntry entry;
|
while (!Objects.isNull(entry = archiveInputStream.getNextEntry())) {
|
String name = entry.getName();
|
if (name.toLowerCase().endsWith(".kml")) {
|
kmzInfoVO.setKmlInfo(RouteFileUtils.parseKml(archiveInputStream));
|
} else if (name.toLowerCase().endsWith(".wpml")) {
|
kmzInfoVO.setWpmlInfo(RouteFileUtils.parseKml(archiveInputStream));
|
}
|
}
|
return kmzInfoVoToUavRouteReq(kmzInfoVO);
|
}catch (Exception e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
|
public static UavRouteReq kmzInfoVoToUavRouteReq(KmzInfoVo vo) {
|
UavRouteReq uavRouteReq = new UavRouteReq();
|
if (vo.getKmlInfo().getDocument().getFolder().getTemplateType() != null){
|
uavRouteReq.setTemplateType(vo.getKmlInfo().getDocument().getFolder().getTemplateType());
|
}
|
KmlDroneInfo droneInfo = vo.getKmlInfo().getDocument().getKmlMissionConfig().getDroneInfo();
|
uavRouteReq.setDroneType(Integer.valueOf(droneInfo.getDroneEnumValue()));
|
// 机场1:M30/M30T 依赖 droneSubEnumValue 区分(0-67-0 / 0-67-1),导入 KMZ 时需一并保留
|
if (droneInfo.getDroneSubEnumValue() != null && !droneInfo.getDroneSubEnumValue().isEmpty()) {
|
uavRouteReq.setSubDroneType(Integer.valueOf(droneInfo.getDroneSubEnumValue()));
|
}
|
uavRouteReq.setImageFormat(vo.getKmlInfo().getDocument().getFolder().getPayloadParam().getImageFormat());
|
uavRouteReq.setGlobalHeight(Double.valueOf(vo.getKmlInfo().getDocument().getFolder().getGlobalHeight()));
|
uavRouteReq.setAutoFlightSpeed(Double.valueOf(vo.getKmlInfo().getDocument().getFolder().getAutoFlightSpeed()));
|
uavRouteReq.setTakeOffRefPoint(vo.getKmlInfo().getDocument().getKmlMissionConfig().getTakeOffRefPoint());
|
uavRouteReq.setRoutePointList(routePointList(vo.getKmlInfo().getDocument().getFolder().getPlacemarkList()));
|
return uavRouteReq;
|
}
|
|
public static List<RoutePointReq> routePointList(List<KmlPlacemark> placemarkList) {
|
List<RoutePointReq> routePointList = new ArrayList<>();
|
for (KmlPlacemark kmlPlacemark : placemarkList) {
|
RoutePointReq routePointReq = new RoutePointReq();
|
routePointReq.setRoutePointIndex(Integer.valueOf(kmlPlacemark.getIndex()));
|
routePointReq.setLongitude(getDoublePoint(kmlPlacemark.getKmlPoint().getCoordinates(),"lon"));
|
routePointReq.setLatitude(getDoublePoint(kmlPlacemark.getKmlPoint().getCoordinates(),"lat"));
|
routePointReq.setHeight(Double.valueOf(kmlPlacemark.getHeight()));
|
if (kmlPlacemark.getWaypointSpeed() != null) {
|
routePointReq.setSpeed(Double.valueOf(kmlPlacemark.getWaypointSpeed()));
|
}
|
if (kmlPlacemark.getActionGroup() != null) {
|
routePointReq.setActionGroupList(actionGroupList(kmlPlacemark.getActionGroup()));
|
}
|
routePointList.add(routePointReq);
|
}
|
return routePointList;
|
}
|
|
public static List<ActionGroupReq> actionGroupList(List<KmlActionGroup> actionGroup) {
|
List<ActionGroupReq> actionGroupList = new ArrayList<>();
|
for (KmlActionGroup kmlActionGroup : actionGroup) {
|
ActionGroupReq actionGroupReq = new ActionGroupReq();
|
List<PointActionReq> actions = new ArrayList<>();
|
//for (KmlAction kmlAction : kmlActionGroup.getAction()) {
|
for (int i=0 ; i < kmlActionGroup.getAction().size() ; i++) {
|
PointActionReq pointActionReq = actions(kmlActionGroup.getAction().get(i),i);
|
actions.add(pointActionReq);
|
}
|
actionGroupReq.setActions(actions);
|
actionGroupList.add(actionGroupReq);
|
}
|
return actionGroupList;
|
}
|
|
public static PointActionReq actions(KmlAction kmlAction,Integer actionIndex){
|
PointActionReq pointActionReq = new PointActionReq();
|
pointActionReq.setActionIndex(actionIndex);
|
if ("takePhoto".equals(kmlAction.getActionActuatorFunc())) { // 照相
|
pointActionReq.setTakePhotoType(0);
|
pointActionReq.setFileSuffix(kmlAction.getActionActuatorFuncParam().getFileSuffix());
|
pointActionReq.setImageFormat("");
|
pointActionReq.setUseGlobalImageFormat(Integer.valueOf(kmlAction.getActionActuatorFuncParam().getUseGlobalPayloadLensIndex()));
|
}
|
if ("startRecord".equals(kmlAction.getActionActuatorFunc())) { // 开始录像
|
pointActionReq.setPanoShotSubMode(kmlAction.getActionActuatorFuncParam().getFileSuffix());
|
pointActionReq.setStartRecord(true);
|
}
|
if ("stopRecord".equals(kmlAction.getActionActuatorFunc())) { // 停止录像
|
pointActionReq.setStopRecord(true);
|
}
|
if ("gimbalRotate".equals(kmlAction.getActionActuatorFunc())) { // 云台偏航俯仰
|
if ("1".equals(kmlAction.getActionActuatorFuncParam().getGimbalPitchRotateEnable())) { // 云台俯仰角
|
pointActionReq.setGimbalPitchRotateAngle(Double.valueOf(kmlAction.getActionActuatorFuncParam().getGimbalPitchRotateAngle()));
|
}
|
if ("1".equals(kmlAction.getActionActuatorFuncParam().getGimbalYawRotateEnable())){ // 云台偏航角
|
pointActionReq.setGimbalYawRotateAngle(Double.valueOf(kmlAction.getActionActuatorFuncParam().getGimbalYawRotateAngle()));
|
}
|
}
|
if ("zoom".equals(kmlAction.getActionActuatorFunc())) { // 变焦
|
pointActionReq.setZoom(Double.valueOf(kmlAction.getActionActuatorFuncParam().getFocalLength()));
|
}
|
if ("hover".equals(kmlAction.getActionActuatorFunc())) { // 悬停
|
pointActionReq.setHoverTime(Integer.valueOf(kmlAction.getActionActuatorFuncParam().getHoverTime()));
|
}
|
if ("rotateYaw".equals(kmlAction.getActionActuatorFunc())) { // 飞行器偏航
|
pointActionReq.setAircraftHeading(Double.valueOf(kmlAction.getActionActuatorFuncParam().getAircraftHeading()));
|
}
|
return pointActionReq;
|
}
|
|
/**
|
* ArdRouteInfo实体转换,WayLineUploadDTO
|
*/
|
public static WayLineUploadDTO buildWayLineUploadDTO(ArdRouteInfo ardRouteInfo){
|
WayLineUploadDTO wayLineUploadDTO = new WayLineUploadDTO();
|
String finishAction = ardRouteInfo.getUavRouteReq().getFinishAction(); //1
|
Double autoFlightSpeed = ardRouteInfo.getUavRouteReq().getAutoFlightSpeed(); //15
|
Double globalTransitionalSpeed = ardRouteInfo.getUavRouteReq().getGlobalTransitionalSpeed(); //8
|
String exitOnRcLostAction = ardRouteInfo.getUavRouteReq().getExitOnRcLostAction(); //0
|
|
PlanLineData planLineData = new PlanLineData();
|
if (finishAction != null){
|
planLineData.setLoseAction(0);
|
}
|
if (autoFlightSpeed != null){
|
planLineData.setAutoSpeed(8);
|
}
|
planLineData.setMaxSpeed(15);
|
// if (globalTransitionalSpeed != null){
|
// planLineData.setMaxSpeed(15);
|
// }
|
if (exitOnRcLostAction != null){
|
planLineData.setFinishedAction(1);
|
}
|
planLineData.setHomeHeight(50);
|
planLineData.setInterests(new ArrayList<>());
|
planLineData.setIsSaveEnergyMode(0);
|
planLineData.setPoints(buildPointDataList(ardRouteInfo.getUavRouteReq()));
|
|
wayLineUploadDTO.setWayLineData(planLineData);
|
return wayLineUploadDTO;
|
}
|
|
public static List<PointData> buildPointDataList(UavRouteReq uavRouteReq){
|
List<PointData> pointDataList = new ArrayList<>();
|
for (RoutePointReq routePointReq : uavRouteReq.getRoutePointList()) {
|
PointData pointData = new PointData();
|
|
Integer routePointIndex = routePointReq.getRoutePointIndex();
|
if (routePointIndex != null){
|
pointData.setGroupIndex(routePointIndex);
|
}
|
Double height = routePointReq.getHeight();
|
if (height != null){
|
pointData.setHeight(height.floatValue());
|
}
|
Double longitude = routePointReq.getLongitude();
|
if (longitude != null){
|
pointData.setLng(longitude.floatValue());
|
}
|
Double latitude = routePointReq.getLatitude();
|
if (latitude != null){
|
pointData.setLat(latitude.floatValue());
|
}
|
Double speed = routePointReq.getSpeed();
|
if (speed != null){
|
pointData.setSpeed(speed.floatValue());
|
}
|
pointData.setDampingDistance(0);
|
pointData.setFlightPathMode(1);
|
pointData.setHeading(0);
|
pointData.setHeadingMode(0);
|
pointData.setInterestIndex(-1);
|
pointData.setSafeGohomeFlag(0);
|
pointData.setActions(buildPointActionList(routePointReq.getActionGroupList()));
|
pointDataList.add(pointData);
|
|
}
|
return pointDataList;
|
}
|
|
public static List<PointAction> buildPointActionList(List<ActionGroupReq> actionGroupList){
|
List<PointAction> pointActionList = new ArrayList<>();
|
for (ActionGroupReq actionGroupReq : actionGroupList) {
|
for (PointActionReq action : actionGroupReq.getActions()) {
|
PointAction pointAction = typeProcessing(action);
|
pointActionList.add(pointAction);
|
}
|
}
|
return pointActionList;
|
}
|
|
public static PointAction typeProcessing(PointActionReq pointActionReq){
|
PointAction pointAction = new PointAction();
|
|
if (pointActionReq.getZoom() != null){
|
pointAction.setType(1);
|
pointAction.setParam(pointActionReq.getZoom().floatValue());
|
pointAction.setSpeakInfo("");
|
pointAction.setWaitTime(2);
|
}
|
|
if (pointActionReq.getTakePhotoType() != null){
|
pointAction.setType(2);
|
pointAction.setParam(1);
|
pointAction.setSpeakInfo("");
|
pointAction.setWaitTime(2);
|
}
|
|
if (pointActionReq.getStartRecord() != null){
|
pointAction.setType(3);
|
pointAction.setParam(1);
|
pointAction.setSpeakInfo("");
|
pointAction.setWaitTime(2);
|
}
|
|
if (pointActionReq.getStopRecord() != null){
|
pointAction.setType(4);
|
pointAction.setParam(1);
|
pointAction.setSpeakInfo("");
|
pointAction.setWaitTime(2);
|
}
|
|
if (pointActionReq.getAircraftHeading() != null){
|
pointAction.setType(5);
|
pointAction.setParam(pointActionReq.getAircraftHeading().floatValue());
|
pointAction.setSpeakInfo("");
|
pointAction.setWaitTime(2);
|
}
|
|
if (pointActionReq.getGimbalPitchRotateAngle() != null){
|
pointAction.setType(6);
|
pointAction.setParam(pointActionReq.getGimbalPitchRotateAngle().floatValue());
|
pointAction.setSpeakInfo("");
|
pointAction.setWaitTime(2);
|
}
|
|
if (pointActionReq.getGimbalYawRotateAngle() != null){
|
pointAction.setType(7);
|
pointAction.setParam(pointActionReq.getGimbalYawRotateAngle().floatValue());
|
pointAction.setSpeakInfo("");
|
pointAction.setWaitTime(2);
|
}
|
|
if (pointActionReq.getHoverTime() != null){
|
pointAction.setType(9);
|
pointAction.setParam(pointActionReq.getHoverTime().floatValue());
|
pointAction.setSpeakInfo("");
|
pointAction.setWaitTime(2);
|
}
|
|
return pointAction;
|
|
}
|
|
}
|