From 8d9a2d656e4ae007590c622e5f7c228adacdca49 Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Fri, 14 Jun 2024 10:11:36 +0800
Subject: [PATCH] 统一风格

---
 src/main/java/com/dji/sample/territory/service/impl/TbDkjbxxServiceImpl.java |   59 +++++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 43 insertions(+), 16 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 679665a..135d1e5 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
@@ -9,12 +9,14 @@
 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;
 import com.dji.sample.territory.dao.ITbFjMapper;
 import com.dji.sample.territory.model.entity.TbDkjbxxEntity;
 import com.dji.sample.territory.model.entity.TbFjEntity;
+import com.dji.sample.territory.model.entity.param.UploadUrlParam;
 import com.dji.sample.territory.pojo.TerritoryConfigPojo;
 import com.dji.sample.territory.service.ITbDkjbxxService;
 import org.locationtech.jts.geom.Coordinate;
@@ -28,9 +30,11 @@
 import java.io.*;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.net.URLConnection;
 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;
@@ -48,6 +52,8 @@
 public class TbDkjbxxServiceImpl extends ServiceImpl<ITbDkjbxxMapper, TbDkjbxxEntity> implements ITbDkjbxxService {
     @Autowired
     private ITbDkjbxxMapper iTbDkjbxxMapper;
+    @Autowired
+    private TbFjServiceImpl tbFjService;
     @Autowired
     private PatchesConfigPojo patchesConfigPojo;
     @Autowired
@@ -71,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) {
@@ -112,6 +118,38 @@
         return convert(new File(destKMZFile));
     }
 
+    @Override
+    public ResponseResult uploadUrl(String url,String taskName) {
+        if (url.isEmpty()) {
+            throw new IllegalArgumentException("上传文件为空");
+        }
+        String saveFilePath = territoryConfigPojo.getResource(); // 要保存文件的本地路径
+
+        try {
+            downloadFile(url, saveFilePath);
+            System.out.println("文件下载完成");
+        } catch (IOException e) {
+            System.out.println("下载文件时发生错误:" + e.getMessage());
+        }
+        TimerUtil util=new TimerUtil();
+        util.dbSave(territoryConfigPojo.getResource(),territoryConfigPojo.getResourcesave(),taskName);
+        return ResponseResult.success();
+    }
+    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);
+            }
+        }
+    }
+
     /**
      * 将TbDkjbxxEntity类型的列表转换为LotInfo类型的列表。
      *
@@ -121,25 +159,14 @@
     private List<LotInfo> dbConvertToEntity(List<TbDkjbxxEntity> list) {
         List<LotInfo> infos = new ArrayList<>();
         for (TbDkjbxxEntity file : list) {
-            double[] coordinates = extractCoordinates(pointCGCStoWGS(file.getXzb(), file.getYzb()));
             // 使用Builder模式构建LotInfo对象
             LotInfo.LotInfoBuilder builder = LotInfo.builder();
             if (file != null) {
                 // 从TbDkjbxxEntity实体中提取信息,构建LotInfo对象
-                builder.bsm(file.getBsm())
-                        .bz(file.getBz())
-                        .dkmj(file.getDkmj())
-                        .dkmc(file.getDkmc())
-                        .dkbh(file.getDkbh())
-                        .xmc(file.getXmc())
-                        .xzb(coordinates[0])
-                        .sfbhzdk(file.getSfbhzdk())
-                        .sjlx(file.getSjlx())
-                        .dkfw(poylonCGCStoWGS(file.getDkfw()))
-                        .xzqdm(file.getXzqdm())
-                        .yzb(coordinates[1])
-                        .kzxx(file.getKzxx())
-                        .dklx(file.getDklx())
+                builder.bsm(file.getFId())
+                        .dkbh(file.getFTbbh())
+                        .dkfw(file.getFShape())
+                        .xzqdm(file.getFXzqdm())
                         .build();
                 // 将构建好的LotInfo对象添加到infos列表中
                 infos.add(builder.build());

--
Gitblit v1.9.3