From 2db1aa88e8ab53096a936163d686b90d8e056a99 Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Wed, 21 Aug 2024 23:18:33 +0800
Subject: [PATCH] 国土对接返回信息加密

---
 src/main/java/com/dji/sample/territory/service/impl/TbDkjbxxServiceImpl.java |   69 +++++++++++++++++-----------------
 1 files changed, 34 insertions(+), 35 deletions(-)

diff --git a/src/main/java/com/dji/sample/territory/service/impl/TbDkjbxxServiceImpl.java b/src/main/java/com/dji/sample/territory/service/impl/TbDkjbxxServiceImpl.java
index 9adf2ed..3bfce17 100644
--- a/src/main/java/com/dji/sample/territory/service/impl/TbDkjbxxServiceImpl.java
+++ b/src/main/java/com/dji/sample/territory/service/impl/TbDkjbxxServiceImpl.java
@@ -8,6 +8,8 @@
 import com.dji.sample.patches.model.entity.LotInfo;
 import com.dji.sample.patches.utils.GeoToolsUtil;
 import com.dji.sample.patches.utils.MultipartFileTOFileUtil;
+import com.dji.sample.patches.utils.PointPO;
+import com.dji.sample.patches.utils.TimerUtil;
 import com.dji.sample.patches.xml.mode.XMLTemplateModel;
 import com.dji.sample.patches.xml.utils.CreateWaylineFileUtils;
 import com.dji.sample.territory.dao.ITbDkjbxxMapper;
@@ -32,6 +34,7 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
+import java.util.UUID;
 
 import static com.dji.sample.patches.utils.MultipartFileTOFileUtil.convert;
 import static com.dji.sample.patches.utils.ZipUtil.zipFolder;
@@ -74,7 +77,7 @@
             // 获取上传的文件输入流
             InputStream inputStream = file.getInputStream();
             // 创建输出流,将文件内容写入资源文件
-            OutputStream outputStream = new FileOutputStream(territoryConfigPojo.getPath());
+            OutputStream outputStream = new FileOutputStream(territoryConfigPojo.getResource());
             byte[] buffer = new byte[1024];
             int bytesRead;
             while ((bytesRead = inputStream.read(buffer)) != -1) {
@@ -89,22 +92,11 @@
         }
     }
 
-
-    /**
-     * 根据给定的工作空间ID、航线名称、机场纬度和经度,生成并返回一个包含航线文件的MultipartFile对象。
-     *
-     * @param workspaceId 工作空间ID,用于查询相关数据。
-     * @param waylineName 航线名称,用于命名生成的文件。
-     * @param airportLat  机场纬度,用于地理坐标转换和航迹点排序。
-     * @param airportLon  机场经度,用于地理坐标转换和航迹点排序。
-     * @return MultipartFile 对象,包含压缩后的航迹文件。
-     * @throws IOException 如果文件操作失败,则抛出IOException。
-     */
     @Transactional
     public MultipartFile listFile(String workspaceId, String waylineName, double airportLat, double airportLon) throws IOException {
         List<TbDkjbxxEntity> list = iTbDkjbxxMapper.selectList(null);
         List<LotInfo> info = dbConvertToEntity(list);
-        Coordinate[] coordinates = GeoToolsUtil.getRoutePointOrder(info, airportLat, airportLon);
+        List<PointPO> coordinates = GeoToolsUtil.getRoutePointOrder(info, airportLat, airportLon);
         // 创建XML模板模型
         XMLTemplateModel xmlModel = XMLTemplateModel.init(coordinates, info);
         CreateWaylineFileUtils.createWaylineFile(xmlModel, patchesConfigPojo.getTemplate(), patchesConfigPojo.getTargetTemplate(), patchesConfigPojo.getWaylines(), patchesConfigPojo.getTargetWaylines());
@@ -116,34 +108,41 @@
     }
 
     @Override
-    public ResponseResult uploadUrl(String url) {
+    public void uploadUrl(String url, String taskName) {
         if (url.isEmpty()) {
             throw new IllegalArgumentException("上传文件为空");
         }
-        downloadFile(url);
-        return ResponseResult.success();
-    }
-    public File downloadFile(String fileUrl) {
-        File downloadedFile = null;
+        String saveFilePath = territoryConfigPojo.getResource(); // 要保存文件的本地路径
         try {
-            URL url = new URL(fileUrl);
-            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-            connection.setRequestMethod("GET");
-            InputStream inputStream = connection.getInputStream();
-            downloadedFile = new File(territoryConfigPojo.getPath());
-            OutputStream outputStream = new FileOutputStream(downloadedFile);
-            byte[] buffer = new byte[1024];
-            int bytesRead;
-            while ((bytesRead = inputStream.read(buffer)) != -1) {
-                outputStream.write(buffer, 0, bytesRead);
-            }
-            inputStream.close();
-            outputStream.close();
+            downloadFile(url, saveFilePath);
         } catch (IOException e) {
-            e.printStackTrace();
+            throw new IllegalArgumentException("下载db文件发生错误" + e);
         }
+        TimerUtil util = new TimerUtil();
+        util.dbSave(territoryConfigPojo.getResource(), territoryConfigPojo.getResourcesave(), taskName);
 
-        return downloadedFile;
+    }
+
+    /**
+     * 根据地址下载文件
+     *
+     * @param fileUrl
+     * @param saveFilePath
+     * @throws IOException
+     */
+    public static void downloadFile(String fileUrl, String saveFilePath) throws IOException {
+        // 创建URL对象
+        URL url = new URL(fileUrl);
+
+        // 打开连接
+        try (BufferedInputStream in = new BufferedInputStream(url.openStream());
+             FileOutputStream fileOutputStream = new FileOutputStream(saveFilePath)) {
+            byte[] dataBuffer = new byte[1024];
+            int bytesRead;
+            while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
+                fileOutputStream.write(dataBuffer, 0, bytesRead);
+            }
+        }
     }
 
     /**
@@ -162,7 +161,7 @@
                 builder.bsm(file.getFId())
                         .dkbh(file.getFTbbh())
                         .dkfw(file.getFShape())
-                        .xzqdm(file.getFXzqdmsys())
+                        .xzqdm(file.getFXzqdm())
                         .build();
                 // 将构建好的LotInfo对象添加到infos列表中
                 infos.add(builder.build());

--
Gitblit v1.9.3