From 6ad595014ddd8578ead23116b3f9cb00f828627a Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Thu, 16 May 2024 16:27:43 +0800
Subject: [PATCH] db对接格式修改,定时器异步、水印调整

---
 src/main/java/com/dji/sample/territory/service/impl/TbFjServiceImpl.java |   59 ++++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 46 insertions(+), 13 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 5a7aa60..2647b25 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
@@ -8,6 +8,7 @@
 import com.dji.sample.territory.dao.ITbFjMapper;
 import com.dji.sample.territory.model.entity.TbFjEntity;
 import com.dji.sample.territory.service.ITbFJService;
+import com.dji.sample.territory.utils.HashUtil;
 import com.dji.sample.territory.utils.Sm3Util;
 import com.dji.sample.territory.utils.VideoZipUtil;
 import com.dji.sample.territory.utils.WaterMarkUtil;
@@ -16,10 +17,19 @@
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.imageio.ImageIO;
+import javax.xml.crypto.Data;
+import java.awt.image.BufferedImage;
 import java.io.*;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.UUID;
 
@@ -58,6 +68,11 @@
         return count;
     }
 
+    public void   insertOneData(MediaFileEntity mediaFile, LotInfo lotInfo) throws Exception {
+        TbFjEntity tbFj = dbConvertToEntity(mediaFile, lotInfo);
+        tbFjMapper.insert(tbFj);
+    }
+
     @Override
     public void deleteData() {
         tbFjMapper.delete(null);
@@ -79,32 +94,36 @@
         Double absoluteAltitude = jsonObject.getDouble("absoluteAltitude");
         Double relativeAltitude = jsonObject.getDouble("relativeAltitude");
         Double gimbalYawDegree = jsonObject.getDouble("gimbalYawDegree");
+        Long sj =jsonObject.getLong("createdTime");
         JSONObject shootPosition = jsonObject.getJSONObject("shootPosition");
         Double lat = shootPosition.getDouble("lat");
         Double lng = shootPosition.getDouble("lng");
-        double[] coordinates = extractCoordinates(pointWGStoCGCS(lng, lat));
-        double x = Double.parseDouble(((formatCoordinate(coordinates[1]))));
-        double y = Double.parseDouble(((formatCoordinate(coordinates[0]))));
+//        double[] coordinates = extractCoordinates(pointWGStoCGCS(lng, lat));
+//        double x = Double.parseDouble(((formatCoordinate(coordinates[1]))));
+//        double y = Double.parseDouble(((formatCoordinate(coordinates[0]))));
         //本地数据库没有的数据在FJ表非空用0
         int psjd = 0;
-        String fjhxz = "0";
         int pshgj = 0;
-        String psry = "0";
+        String psry = "中图智绘无人机";
         String zsdm = "23C8CCC61E3042FBA6A658F319337B1A";
         String dklx = "0";
-        String xzqdm = "0";
         int fjlx = 1;
-        Long pssj = mediaFile.getCreateTime();
+        String pstz="Y";
+        String pssj=convertTimestampToDateTime(sj);
         String bsm = UUID.randomUUID().toString();
         String fjmc = mediaFile.getFileName();
         String key = mediaFile.getObjectKey();
         String head = "http://dev.jxpskj.com:9000/cloud-bucket";
         String url = head + key;
         File file = downloadFile(url);
+        String fjhxz = HashUtil.SM3Hash(file);
+        BufferedImage image = ImageIO.read(file);
+        int width = image.getWidth();
+        int height = image.getHeight();
         //对应图片和视频文件进行不同处理
         boolean endsWith = key.endsWith(".mp4");
         if (!endsWith) {
-            file1 = WaterMarkUtil.addWatermark(file, patchesConfigPojo.getUnzip(), pssj, lat, lng,gimbalYawDegree);
+            file1 = WaterMarkUtil.addWatermark(file, patchesConfigPojo.getUnzip(), sj, lat, lng,gimbalYawDegree);
             FJ = fileToByteArray(file1);
         } else {
             file1 = VideoZipUtil.compressVideo(file, 800000, 128000, 1280, 720);
@@ -120,18 +139,18 @@
         TbFjEntity.TbFjEntityBuilder builder = TbFjEntity.builder();
         if (lotInfo != null) {
             builder.bsm(bsm)
-                    .dkbsm(lotInfo.getDkbh())
-                    .xzqdm(xzqdm)
+                    .dkbsm(lotInfo.getBsm())
+                    .xzqdm(lotInfo.getXzqdm())
                     .dklx(dklx)
                     .xdgd(relativeAltitude)
                     .jdgd(absoluteAltitude)
-                    .Latitude(x)
-                    .longitude(y)
+                    .Latitude(lat)
+                    .longitude(lng)
                     .fj(FJ)
                     .fjmc(fjmc)
                     .fjlx(fjlx)
                     .psfyj(gimbalYawDegree)
-                    .pssj(String.valueOf(pssj))
+                    .pssj(pssj)
                     .psjd(psjd)
                     .fjhxz(fjhxz)
                     .pshgj(pshgj)
@@ -139,6 +158,9 @@
                     .psry(psry)
                     .jym(signatureHex)
                     .url(url)
+                    .pstz(pstz)
+                    .fjyskd(width)
+                    .fjysgd(height)
                     .build();
         }
 //        else {
@@ -189,4 +211,15 @@
         fis.close();
         return data;
     }
+    public static String convertTimestampToDateTime(long timestamp) {
+        // 将时间戳转换为 Instant 对象
+        Instant instant = Instant.ofEpochMilli(timestamp);
+
+        // 将 Instant 对象转换为 LocalDateTime 对象
+        LocalDateTime dateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
+
+        // 格式化日期时间
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        return dateTime.format(formatter);
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3