fix:优化航线管理航线上传逻辑

This commit is contained in:
高大 2026-01-24 17:18:08 +08:00
parent 5acb3656d3
commit 4d4b85dd7f
2 changed files with 21 additions and 32 deletions

View File

@ -22,7 +22,7 @@ public class WayPointUitls {
* @return
*/
public static byte[] kmz2waypoint(KmlInfo kmlInfo) {
public static String kmz2waypoint(KmlInfo kmlInfo) {
//准备一个waypoint文件的标头文本
StringBuilder waypointBuilder = new StringBuilder("QGC WPL 110\n");
// 重置全局id计数器
@ -102,7 +102,7 @@ public class WayPointUitls {
waypointBuilder.append(formatWaypointLine(point, i)).append("\n");
}
return waypointBuilder.toString().getBytes();
return waypointBuilder.toString();
}

View File

@ -21,8 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
@ -65,7 +63,7 @@ public class AirlineFileServiceImpl implements IAirlineFileService {
public AirlineFileDTO parseAndUplload(MultipartFile file) {
KmlInfo kmlInfo = new KmlInfo();
try (ArchiveInputStream archiveInputStream = new ZipArchiveInputStream(file.getInputStream()); ByteArrayOutputStream out = new ByteArrayOutputStream()) {
try (ArchiveInputStream archiveInputStream = new ZipArchiveInputStream(file.getInputStream());) {
ArchiveEntry entry;
while (!Objects.isNull(entry = archiveInputStream.getNextEntry())) {
String name = entry.getName();
@ -79,14 +77,11 @@ public class AirlineFileServiceImpl implements IAirlineFileService {
throw new BaseException("kmz文件内容缺失");
}
String globalHeight = kmlInfo.getDocument().getFolder().getGlobalHeight();
out.write(WayPointUitls.kmz2waypoint(kmlInfo));
R<String> fileUrl = remoteFileService.uploadFileByStream(UUID.randomUUID().toString(), "waypoints", out);
R<String> fileUrl = remoteFileService.uploadFileByData(UUID.randomUUID().toString(), "waypoints", WayPointUitls.kmz2waypoint(kmlInfo));
AirlineFileDTO dto = new AirlineFileDTO();
dto.setFileUrl(fileUrl.getData());
dto.setAirVendor("");
dto.setAirType("");
return dto;
} catch (IOException e) {
@ -109,19 +104,15 @@ public class AirlineFileServiceImpl implements IAirlineFileService {
StringBuilder waypointBuilder = new StringBuilder("QGC WPL 110\n");
List<AirLinePointVO> LineDto = airlineFile.getLinePointDtoList();
// 新建字节输出流,Freemarker操作此输出流写入生成的业务文件.
try (ByteArrayOutputStream out = new ByteArrayOutputStream();) {
if (LineDto != null && !LineDto.isEmpty()) {
for (int i = 0; i < LineDto.size(); i++) {
AirLinePointVO point = LineDto.get(i);
waypointBuilder.append(WayPointUitls.formatWaypointLine(point, i)).append("\n");
}
// 生成文件
out.write(waypointBuilder.toString().getBytes());
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
// 上传文件
R<String> fileUrl = remoteFileService.uploadFileByStream(UUID.randomUUID().toString(), "waypoints", out);
out.close();
in.close();
R<String> fileUrl = remoteFileService.uploadFileByData(UUID.randomUUID().toString(), "waypoints", waypointBuilder.toString());
//保存航线文件数据
airlineFile.setFileUrl(fileUrl.getData());
airlineFile.setSource("airport");
@ -131,8 +122,6 @@ public class AirlineFileServiceImpl implements IAirlineFileService {
return AirlineFileServiceConvert.toDTO(result);
}
return null;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}