diff --git a/src/main/java/com/ruoyi/airline/domain/uitl/WayPointUitls.java b/src/main/java/com/ruoyi/airline/domain/uitl/WayPointUitls.java index 8cfb2f8..7e7c066 100644 --- a/src/main/java/com/ruoyi/airline/domain/uitl/WayPointUitls.java +++ b/src/main/java/com/ruoyi/airline/domain/uitl/WayPointUitls.java @@ -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(); } diff --git a/src/main/java/com/ruoyi/airline/service/impl/AirlineFileServiceImpl.java b/src/main/java/com/ruoyi/airline/service/impl/AirlineFileServiceImpl.java index ea61b7e..3cb49b7 100644 --- a/src/main/java/com/ruoyi/airline/service/impl/AirlineFileServiceImpl.java +++ b/src/main/java/com/ruoyi/airline/service/impl/AirlineFileServiceImpl.java @@ -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 fileUrl = remoteFileService.uploadFileByStream(UUID.randomUUID().toString(), "waypoints", out); + R 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,30 +104,24 @@ public class AirlineFileServiceImpl implements IAirlineFileService { StringBuilder waypointBuilder = new StringBuilder("QGC WPL 110\n"); List 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 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); + 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"); } - return null; - } catch (Exception e) { - throw new RuntimeException(e); + + // 上传文件 + R 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; + } } \ No newline at end of file