From 28714a4d141162eda766272c75bc2728024fe666 Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Fri, 19 Apr 2024 17:18:05 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/ht-dev' into ht-dev

---
 src/main/java/com/dji/sample/territory/service/impl/TbFjServiceImpl.java |   35 ++++++++++++++++++++++++++---------
 1 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/dji/sample/territory/service/impl/TbFjServiceImpl.java b/src/main/java/com/dji/sample/territory/service/impl/TbFjServiceImpl.java
index 6e85ecb..27724eb 100644
--- a/src/main/java/com/dji/sample/territory/service/impl/TbFjServiceImpl.java
+++ b/src/main/java/com/dji/sample/territory/service/impl/TbFjServiceImpl.java
@@ -20,7 +20,7 @@
 import java.util.UUID;
 
 @Service
-@DS("sqlite")
+@DS("sqlite-ret")
 public class TbFjServiceImpl implements ITbFJService {
     @Autowired
     private ITbFjMapper mapper;
@@ -55,7 +55,7 @@
      * @return
      * @throws IOException
      */
-    private TbFjEntity dbConvertToEntity(MediaFileEntity mediaFile, LotInfo lotInfo) {
+    private TbFjEntity dbConvertToEntity(MediaFileEntity mediaFile, LotInfo lotInfo) throws IOException {
         String jsonString = JSONObject.toJSONString(mediaFile.getMetadata());
         JSONObject jsonObject = JSONObject.parseObject(jsonString);
         Double absoluteAltitude = jsonObject.getDouble("absoluteAltitude");
@@ -78,7 +78,9 @@
         String key = mediaFile.getObjectKey();
         String head = "http://dev.jxpskj.com:9000/cloud-bucket";
         String url = head + key;
-        byte[] FJ = downloadFileAsBytes(url);
+        File file =downloadFile(url);
+        File file1=WaterMark.addWatermark(file,patchesConfigPojo.getUnzip(),pssj,lat,lng);
+        byte[] FJ = fileToByteArray(file1);
         TbFjEntity.TbFjEntityBuilder builder = TbFjEntity.builder();
         if (lotInfo != null) {
             builder.bsm(bsm)
@@ -89,7 +91,7 @@
                     .jdgd(absoluteAltitude)
                     .Latitude(lat)
                     .longitude(lng)
-                    .fj(FJ)
+//                    .fj(FJ)
                     .fjmc(fjmc)
                     .fjlx(1)
                     .psfyj(gimbalYawDegree)
@@ -100,6 +102,7 @@
                     .zsdm(zsdm)
                     .psry(psry)
                     .jym(jym)
+                    .url(url)
                     .build();
         } else {
             throw new IllegalArgumentException("未匹配到相关地块");
@@ -113,15 +116,19 @@
      * @param fileUrl
      * @return
      */
-    public static byte[] downloadFileAsBytes(String fileUrl) {
-        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+    public  File downloadFile(String fileUrl) {
 
+        File downloadedFile = null;
+        String localFilePath =  patchesConfigPojo.getUnzip()+ "tmp.jpg";
         try {
             URL url = new URL(fileUrl);
             HttpURLConnection connection = (HttpURLConnection) url.openConnection();
             connection.setRequestMethod("GET");
 
-            try (InputStream inputStream = connection.getInputStream()) {
+            downloadedFile = new File(localFilePath);
+
+            try (InputStream inputStream = connection.getInputStream();
+                 OutputStream outputStream = new FileOutputStream(downloadedFile)) {
                 byte[] buffer = new byte[1024];
                 int bytesRead;
                 while ((bytesRead = inputStream.read(buffer)) != -1) {
@@ -129,11 +136,21 @@
                 }
             }
 
+            System.out.println("File downloaded and saved at: " + downloadedFile.getAbsolutePath());
+
         } catch (IOException e) {
             e.printStackTrace();
         }
 
-        return outputStream.toByteArray();
+        return downloadedFile;
     }
 
-}
+    public static byte[] fileToByteArray(File file) throws IOException {
+        FileInputStream fis = new FileInputStream(file);
+        byte[] data = new byte[(int) file.length()];
+        fis.read(data);
+        fis.close();
+        return data;
+    }
+
+}
\ No newline at end of file

--
Gitblit v1.9.3