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 * @return
*/ */
public static byte[] kmz2waypoint(KmlInfo kmlInfo) { public static String kmz2waypoint(KmlInfo kmlInfo) {
//准备一个waypoint文件的标头文本 //准备一个waypoint文件的标头文本
StringBuilder waypointBuilder = new StringBuilder("QGC WPL 110\n"); StringBuilder waypointBuilder = new StringBuilder("QGC WPL 110\n");
// 重置全局id计数器 // 重置全局id计数器
@ -102,7 +102,7 @@ public class WayPointUitls {
waypointBuilder.append(formatWaypointLine(point, i)).append("\n"); 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.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -65,7 +63,7 @@ public class AirlineFileServiceImpl implements IAirlineFileService {
public AirlineFileDTO parseAndUplload(MultipartFile file) { public AirlineFileDTO parseAndUplload(MultipartFile file) {
KmlInfo kmlInfo = new KmlInfo(); KmlInfo kmlInfo = new KmlInfo();
try (ArchiveInputStream archiveInputStream = new ZipArchiveInputStream(file.getInputStream()); ByteArrayOutputStream out = new ByteArrayOutputStream()) { try (ArchiveInputStream archiveInputStream = new ZipArchiveInputStream(file.getInputStream());) {
ArchiveEntry entry; ArchiveEntry entry;
while (!Objects.isNull(entry = archiveInputStream.getNextEntry())) { while (!Objects.isNull(entry = archiveInputStream.getNextEntry())) {
String name = entry.getName(); String name = entry.getName();
@ -79,14 +77,11 @@ public class AirlineFileServiceImpl implements IAirlineFileService {
throw new BaseException("kmz文件内容缺失"); throw new BaseException("kmz文件内容缺失");
} }
String globalHeight = kmlInfo.getDocument().getFolder().getGlobalHeight(); String globalHeight = kmlInfo.getDocument().getFolder().getGlobalHeight();
out.write(WayPointUitls.kmz2waypoint(kmlInfo)); R<String> fileUrl = remoteFileService.uploadFileByData(UUID.randomUUID().toString(), "waypoints", WayPointUitls.kmz2waypoint(kmlInfo));
R<String> fileUrl = remoteFileService.uploadFileByStream(UUID.randomUUID().toString(), "waypoints", out);
AirlineFileDTO dto = new AirlineFileDTO(); AirlineFileDTO dto = new AirlineFileDTO();
dto.setFileUrl(fileUrl.getData()); dto.setFileUrl(fileUrl.getData());
dto.setAirVendor(""); dto.setAirVendor("");
dto.setAirType(""); dto.setAirType("");
return dto; return dto;
} catch (IOException e) { } catch (IOException e) {
@ -109,30 +104,24 @@ public class AirlineFileServiceImpl implements IAirlineFileService {
StringBuilder waypointBuilder = new StringBuilder("QGC WPL 110\n"); StringBuilder waypointBuilder = new StringBuilder("QGC WPL 110\n");
List<AirLinePointVO> LineDto = airlineFile.getLinePointDtoList(); List<AirLinePointVO> LineDto = airlineFile.getLinePointDtoList();
// 新建字节输出流,Freemarker操作此输出流写入生成的业务文件. // 新建字节输出流,Freemarker操作此输出流写入生成的业务文件.
try (ByteArrayOutputStream out = new ByteArrayOutputStream();) { if (LineDto != null && !LineDto.isEmpty()) {
if (LineDto != null && !LineDto.isEmpty()) { for (int i = 0; i < LineDto.size(); i++) {
for (int i = 0; i < LineDto.size(); i++) { AirLinePointVO point = LineDto.get(i);
AirLinePointVO point = LineDto.get(i); waypointBuilder.append(WayPointUitls.formatWaypointLine(point, i)).append("\n");
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();
//保存航线文件数据
airlineFile.setFileUrl(fileUrl.getData());
airlineFile.setSource("airport");
airlineFile.setStatus(airlineFile.getStatus() == null ? 1 : airlineFile.getStatus());
AirlineFile model = AirlineFileServiceConvert.toModel(airlineFile);
AirlineFile result = iAirlineFileDomain.save(model);
return AirlineFileServiceConvert.toDTO(result);
} }
return null;
} catch (Exception e) { // 上传文件
throw new RuntimeException(e); R<String> fileUrl = remoteFileService.uploadFileByData(UUID.randomUUID().toString(), "waypoints", waypointBuilder.toString());
//保存航线文件数据
airlineFile.setFileUrl(fileUrl.getData());
airlineFile.setSource("airport");
airlineFile.setStatus(airlineFile.getStatus() == null ? 1 : airlineFile.getStatus());
AirlineFile model = AirlineFileServiceConvert.toModel(airlineFile);
AirlineFile result = iAirlineFileDomain.save(model);
return AirlineFileServiceConvert.toDTO(result);
} }
return null;
} }
} }