From 4d1c72b10afcb0c4e7ba3b6caddd29b191ae5870 Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Mon, 20 May 2024 16:22:46 +0800
Subject: [PATCH] 水印调整

---
 src/main/java/com/dji/sample/territory/service/impl/TbFjServiceImpl.java |   50 ++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 38 insertions(+), 12 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 2647b25..175763a 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
@@ -21,6 +21,8 @@
 import javax.xml.crypto.Data;
 import java.awt.image.BufferedImage;
 import java.io.*;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.text.SimpleDateFormat;
@@ -68,9 +70,11 @@
         return count;
     }
 
-    public void   insertOneData(MediaFileEntity mediaFile, LotInfo lotInfo) throws Exception {
+    public void insertOneData(MediaFileEntity mediaFile, LotInfo lotInfo) throws Exception {
         TbFjEntity tbFj = dbConvertToEntity(mediaFile, lotInfo);
-        tbFjMapper.insert(tbFj);
+        if (tbFj.getFjysgd()==3000){
+            tbFjMapper.insert(tbFj);
+        }
     }
 
     @Override
@@ -94,7 +98,7 @@
         Double absoluteAltitude = jsonObject.getDouble("absoluteAltitude");
         Double relativeAltitude = jsonObject.getDouble("relativeAltitude");
         Double gimbalYawDegree = jsonObject.getDouble("gimbalYawDegree");
-        Long sj =jsonObject.getLong("createdTime");
+        Long sj = jsonObject.getLong("createdTime");
         JSONObject shootPosition = jsonObject.getJSONObject("shootPosition");
         Double lat = shootPosition.getDouble("lat");
         Double lng = shootPosition.getDouble("lng");
@@ -108,8 +112,8 @@
         String zsdm = "23C8CCC61E3042FBA6A658F319337B1A";
         String dklx = "0";
         int fjlx = 1;
-        String pstz="Y";
-        String pssj=convertTimestampToDateTime(sj);
+        String pstz = "Y";
+        String pssj = convertTimestampToDateTime(sj);
         String bsm = UUID.randomUUID().toString();
         String fjmc = mediaFile.getFileName();
         String key = mediaFile.getObjectKey();
@@ -123,13 +127,13 @@
         //对应图片和视频文件进行不同处理
         boolean endsWith = key.endsWith(".mp4");
         if (!endsWith) {
-            file1 = WaterMarkUtil.addWatermark(file, patchesConfigPojo.getUnzip(), sj, 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);
             FJ = fileToByteArray(file1);
         }
-        String sm3 = Sm3Util.calculateSM3Hash(fjhxz+","+pssj+","+lng+","+lat+","+gimbalYawDegree+","+psjd+","+pshgj+","+psry+","+zsdm);
+        String sm3 = Sm3Util.calculateSM3Hash(fjhxz + "," + pssj + "," + lng + "," + lat + "," + gimbalYawDegree + "," + psjd + "," + pshgj + "," + psry + "," + zsdm);
 
         byte[] hash = sm3.getBytes(); // 注意:使用SM3或其他哈希算法来计算数据的哈希值
         // 加载私钥
@@ -142,10 +146,10 @@
                     .dkbsm(lotInfo.getBsm())
                     .xzqdm(lotInfo.getXzqdm())
                     .dklx(dklx)
-                    .xdgd(relativeAltitude)
-                    .jdgd(absoluteAltitude)
-                    .Latitude(lat)
-                    .longitude(lng)
+                    .xdgd(truncateToTwoDecimalPlaces(relativeAltitude))
+                    .jdgd(truncateToTwoDecimalPlaces(absoluteAltitude))
+                    .Latitude(truncateToSevenDecimalPlaces(lat))
+                    .longitude(truncateToSevenDecimalPlaces(lng))
                     .fj(FJ)
                     .fjmc(fjmc)
                     .fjlx(fjlx)
@@ -211,6 +215,7 @@
         fis.close();
         return data;
     }
+
     public static String convertTimestampToDateTime(long timestamp) {
         // 将时间戳转换为 Instant 对象
         Instant instant = Instant.ofEpochMilli(timestamp);
@@ -222,4 +227,25 @@
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         return dateTime.format(formatter);
     }
-}
\ No newline at end of file
+
+    public static Double truncateToTwoDecimalPlaces(Double value) {
+        if (value == null) {
+            return null;  // 处理null值情况
+        }
+        BigDecimal bd = new BigDecimal(value).setScale(2, RoundingMode.DOWN);
+        return bd.doubleValue();
+    }
+    public static Double truncateToSevenDecimalPlaces(Double value) {
+        if (value == null) {
+            return null;  // 处理null值情况
+        }
+        BigDecimal bd = new BigDecimal(value).setScale(7, RoundingMode.DOWN);
+        return bd.doubleValue();
+
+    }
+
+    public static void main(String[] args) {
+        System.out.println(truncateToSevenDecimalPlaces(152.00666565));
+        System.out.println(truncateToTwoDecimalPlaces(12.006));
+    }
+}

--
Gitblit v1.9.3