zhaowenyu
2025-11-05 9f3cd3d14b2025c79296ff6cbc49d7efe3302ec5
ard-route/src/main/java/com/ard/route/service/impl/UavRouteServiceImpl.java
@@ -13,6 +13,7 @@
import com.ard.route.domain.kml.*;
import com.ard.route.domain.route.ArdRouteInformation;
import com.ard.route.domain.vo.KmzInfoVO;
import com.ard.route.domain.vo.KmzResultVo;
import com.ard.route.enums.kml.ExitOnRCLostEnums;
import com.ard.route.service.IArdRouteInformationService;
import com.ard.route.util.FileUtils;
@@ -38,32 +39,20 @@
import java.util.zip.ZipOutputStream;
import static com.ard.route.util.RouteFileUtils.*;
import static com.ard.route.util.ToolUtils.extractFilePath;
import static com.ard.route.util.ToolUtils.getFileNameWithoutExtension;
import static com.ard.route.util.ToolUtils.*;
/**
 * Author:songjian
 * Author:xia
 * Date: 2024/12/22 10:36
 **/
@Service
public class UavRouteServiceImpl implements UavRouteService {
    private Boolean isLocal = false;
    private String localFilePath = "KmzFile/kmz/";
    private String kmzPath = "kmz";
    @Resource
    private OssServiceContext ossService;
    @Resource
    private IArdRouteInformationService ardRouteInformationService;
    /**
     * XML 头部
     */
    private static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    /**
     * 编辑kmz文件
@@ -149,7 +138,7 @@
     * 生成kmz文件(带航点)
     */
    @Override
    public String buildKmz(UavRouteReq uavRouteReq, String fileName) {
    public KmzResultVo buildKmz(UavRouteReq uavRouteReq, String fileName) {
        KmlParams kmlParams = new KmlParams();
        BeanUtils.copyProperties(uavRouteReq, kmlParams);
        kmlParams.setRoutePointList(BeanUtil.copyToList(uavRouteReq.getRoutePointList(), RoutePointInfo.class));
@@ -163,7 +152,7 @@
     * @param kmlParams 参数对象
     * @return 本地文件路径
     */
    public String buildKmz(String fileName, KmlParams kmlParams) {
    public KmzResultVo buildKmz(String fileName, KmlParams kmlParams) {
        KmlInfo kmlInfo = buildKml(kmlParams);
        KmlInfo wpmlInfo = buildWpml(kmlParams);
        return buildKmz(fileName, kmlInfo, wpmlInfo);
@@ -177,13 +166,16 @@
     * @param wpmlInfo wpml 文件信息
     * @return 本地文件路径
     */
    public String buildKmz(String fileName, KmlInfo kmlInfo, KmlInfo wpmlInfo) {
    public KmzResultVo buildKmz(String fileName, KmlInfo kmlInfo, KmlInfo wpmlInfo) {
        XStream xStream = new XStream(new DomDriver());
        xStream.processAnnotations(KmlInfo.class);
        xStream.addImplicitCollection(KmlActionGroup.class, "action");
        xStream.addImplicitCollection(KmlPlacemark.class, "actionGroup");
        String kml = XML_HEADER + xStream.toXML(kmlInfo);
        String wpml = XML_HEADER + xStream.toXML(wpmlInfo);
        KmzResultVo result = new KmzResultVo();
        // 判断本地生成kmz文件
        if (isLocal) {
@@ -198,7 +190,8 @@
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            return localFilePath + fileName + ".kmz";
            result.setUpPath(localFilePath + fileName + ".kmz");
            return result;
        }else {
            try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
                 ZipOutputStream zipOutputStream = new ZipOutputStream(baos)) {
@@ -222,16 +215,11 @@
                        new ByteArrayInputStream(baos.toByteArray())
                );
                String kmzFilePath = ossService.upload(kmzPath,multipartFile);
                // KMZ信息管理
                ArdRouteInformation ardRouteInformation = new ArdRouteInformation();
                ardRouteInformation.setFileName(fileName);
                ardRouteInformation.setFileNameNew(getFileNameWithoutExtension(kmzFilePath));
                ardRouteInformation.setMinioUpPath(extractFilePath(kmzFilePath));
                ardRouteInformation.setUpPath(kmzFilePath);
                ardRouteInformation.setUpFileSize(fileSize);
                ardRouteInformation.setCreateBy(SecurityUtils.getUsername());
                ardRouteInformationService.insertArdRouteInformation(ardRouteInformation);
                return kmzFilePath;
                result.setFileNameNew(getFileNameWithoutExtension(kmzFilePath));
                result.setMinioUpPath(extractFilePath(kmzFilePath));
                result.setUpPath(kmzFilePath);
                result.setUpFileSize(fileSize);
                return result;
            } catch (Exception e) {
                throw new RuntimeException("KMZ文件生成或上传失败", e);
            }
@@ -242,7 +230,7 @@
     * 解析kmz文件
     */
    @Override
    public KmzInfoVO parseKmz(String fileUrl) throws IOException {
    public KmzInfoVO parseKmz(String fileUrl){
        KmzInfoVO kmzInfoVO = new KmzInfoVO();
        try (InputStream inputStream = ossService.getObject(kmzPath,fileUrl);
             ArchiveInputStream archiveInputStream = new ZipArchiveInputStream(inputStream)){
@@ -260,23 +248,5 @@
            e.printStackTrace();
        }
        return null;
//        File file = FileUtils.downloadUrlToTempFile(fileUrl);
//        try (ArchiveInputStream archiveInputStream = new ZipArchiveInputStream(FileUtil.getInputStream(file))) {
//            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 kmzInfoVO;
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return null;
    }
}