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 ++++++++++++----
 src/main/java/com/dji/sample/patches/utils/TimerUtil.java                |   22 ++++--
 src/main/java/com/dji/sample/territory/utils/WaterMarkUtil.java          |   53 +++++++++++++----
 src/main/java/com/dji/sample/patches/controller/PatchesController.java   |   10 ++-
 4 files changed, 99 insertions(+), 36 deletions(-)

diff --git a/src/main/java/com/dji/sample/patches/controller/PatchesController.java b/src/main/java/com/dji/sample/patches/controller/PatchesController.java
index 6a10feb..5d4a6e4 100644
--- a/src/main/java/com/dji/sample/patches/controller/PatchesController.java
+++ b/src/main/java/com/dji/sample/patches/controller/PatchesController.java
@@ -76,9 +76,13 @@
     }
     @GetMapping("/useMyTask")
     public ResponseResult useMyTask() throws Exception {
-        timerUtil.myTask();
-        timerUtil.myTask2();
-        return ResponseResult.success();
+        try {
+//        timerUtil.myTask();
+            timerUtil.myTask2();
+            return ResponseResult.success();
+        }catch (Exception e){
+            throw new RuntimeException("db存储发送出现异常");
+        }
     }
     /**
      * 根据图斑的地块编号获取相对应音视频
diff --git a/src/main/java/com/dji/sample/patches/utils/TimerUtil.java b/src/main/java/com/dji/sample/patches/utils/TimerUtil.java
index a2a30a8..8aba2a2 100644
--- a/src/main/java/com/dji/sample/patches/utils/TimerUtil.java
+++ b/src/main/java/com/dji/sample/patches/utils/TimerUtil.java
@@ -90,7 +90,7 @@
      */
     @Scheduled(cron = "0 0 0 * * ?")
     public void myTask() throws Exception {
-        String taskId="";
+        String taskId = "";
         String workspaceId = "4a574db8-4ad3-48f7-9f16-3edbcd8056e1";
 //        获取未规划的图斑集合
         List<List<LotInfo>> lists = getNoPlan();
@@ -109,6 +109,7 @@
             backWayline(multipartFile, waylineName, workspaceId, backclaim().getUsername());
             //将为规划的图斑状态更新为已规划
             updatePatchesStatu(list);
+//            waylineJobService.publishFlightTask(JobParam("656c62f4-cb86-4911-930d-b38089829348"),backclaim());
         }
 
     }
@@ -145,11 +146,10 @@
                 //更新媒体文件的是否添加状态
                 updateMediaStatu(mediaFile);
             }
-            //存储db到服务器
-            dbSave(territoryConfigPojo.getResult(), territoryConfigPojo.getResultsave(), taskId);
             //发送请求给第三方接口
             sendPostWithFileAndParameter(territoryConfigPojo.getResult(), taskId);
-
+            //存储db到服务器
+            dbSave(territoryConfigPojo.getResult(), territoryConfigPojo.getResultsave(), taskId);
         }
     }
 
@@ -243,12 +243,13 @@
         long timestamp = System.currentTimeMillis();
         List<List<Long>> listOfLists = new ArrayList<>();
         List<Long> sublist = new ArrayList<>();
-        sublist.add(1715852375L); // 添加整数值
+        sublist.add(1715941980L); // 添加整数值
         listOfLists.add(sublist);
         List<Long> list = new ArrayList<>();
-        list.add(1715852375L);
+        list.add(1715941980L);
         CreateJobParam param = new CreateJobParam();
-        param.setName("云飞行调查"+timestamp);
+        param.setName("云飞行调查" + timestamp);
+        param.setExecuteStartTimeArr(listOfLists);
         param.setTaskType(TIMED);
         param.setOutOfControlAction(0);
         param.setRepFreType(3);
@@ -328,12 +329,16 @@
             HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
 
             // 发送请求
-                     restTemplate.exchange(
+            ResponseEntity<String> response =restTemplate.exchange(
                     "https://jxlandcloud.org.cn/landCloudWork/artifact/media/upload.action",
 //                  "http://localhost:6789/territory/tbdkjbxx/upload",
                     HttpMethod.POST,
                     requestEntity,
                     String.class);
+            System.out.println(response);
+            System.out.println(response);
+            System.out.println(response);
+            System.out.println(response);
         } catch (Exception e) {
             throw new IllegalArgumentException("db推送失败" + e.getMessage());
         }
@@ -411,4 +416,5 @@
         }
         return folder;
     }
+
 }
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));
+    }
+}
diff --git a/src/main/java/com/dji/sample/territory/utils/WaterMarkUtil.java b/src/main/java/com/dji/sample/territory/utils/WaterMarkUtil.java
index a952962..e64559a 100644
--- a/src/main/java/com/dji/sample/territory/utils/WaterMarkUtil.java
+++ b/src/main/java/com/dji/sample/territory/utils/WaterMarkUtil.java
@@ -23,8 +23,8 @@
      * @return 添加水印并压缩后的图片文件。
      * @throws IOException 如果读取或保存图片失败。
      */
-    public static File addWatermark(File file, String path, Long pssj, Double lat, Double lng, Double angles) throws IOException {
-        String author="中图智绘无人机";
+    public static File addWatermark(File file, String path, Long pssj, Double lat, Double lng, Double angles) throws IOException, FontFormatException {
+
         String angel=angle(angles);
         Long timestamp = pssj; // 例如:Unix 时间戳(以秒为单位)
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -42,7 +42,7 @@
 
         // 设置水印文字 "江西调查云"
         String watermarkText = "江西调查云";
-        float alpha = 0.7f; // 设置透明度为 0.7
+        float alpha = 0.8f; // 设置透明度为 0.7
         AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
         g2d.setComposite(alphaComposite);
         g2d.setFont(new Font("宋体", Font.BOLD, 150)); // 使用宋体字体
@@ -58,11 +58,17 @@
         g2d.setTransform(at);
         // 绘制左上角旋转水印文字
         g2d.drawString(watermarkText, x1, y1);
-        alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f);
+        alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f);
         g2d.setComposite(alphaComposite);
-        String extraInfo = String.format("%s\nlon:%.9f lat:%.6f\n%s 时间:%s", author,lng, lat,angel,sd);
-        g2d.setFont(new Font("宋体", Font.BOLD, 50)); // 使用宋体字体,更小的字号
-        g2d.setBackground(Color.black);
+        String extraInfo = String.format("Lon:%.9f Lat:%.6f\n%s 时间:%s", lng, lat,angel,sd);
+
+        File fontFile = new File("src/main/java/com/dji/sample/territory/utils/MiSans-Normal.ttf"); // 替换为你的字体文件路径
+        Font customFont = Font.createFont(Font.TRUETYPE_FONT, fontFile).deriveFont(36.00F);
+        // 注册字体
+        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+        ge.registerFont(customFont);
+        g2d.setFont(customFont);
+
         // 计算文本宽度和高度
         FontMetrics fm = g2d.getFontMetrics();
         int textWidth = fm.stringWidth(extraInfo);
@@ -71,10 +77,32 @@
         g2d.setTransform(new AffineTransform());
         // 设置文本位置(右下角)
         int x2 = originalImage.getWidth() - textWidth - 30; // 右对齐的 x 坐标
-        int y2 = originalImage.getHeight() - textHeight - 68; // 最底部位置 y 坐标
+        int y2 = originalImage.getHeight() - textHeight - 30; // 最底部位置 y 坐标
+
+
+        int rectX = originalImage.getWidth() - textWidth  +530;
+        int rectY = originalImage.getHeight() - textHeight -15;
+        // 绘制半透明黑色背景矩形
+        Color semiTransparentColor = new Color(0, 0, 0, 156); // 0-255 的 alpha 值,0 表示完全透明,255 表示完全不透明
+        g2d.setColor(semiTransparentColor);
+        g2d.fillRect(rectX, rectY, textWidth, textHeight-6);
+
+        int rectXs = originalImage.getWidth() - textWidth +450 ;
+        int rectYs = originalImage.getHeight() - textHeight  -62;
+        // 绘制半透明黑色背景矩形
+        g2d.setColor(semiTransparentColor);
+        g2d.fillRect(rectXs, rectYs, textWidth, textHeight-10);
+
+//            int rectXw = originalImage.getWidth() - textWidth  +1510 ;
+//            int rectYw = originalImage.getHeight() - textHeight -124;
+//
+//            // 绘制半透明黑色背景矩形
+//            g2d.setColor(semiTransparentColor);
+//            g2d.fillRect(rectXw, rectYw, textWidth, textHeight-6);
         // 绘制文本信息
         String[] lines = extraInfo.split("\n");
         for (String line : lines) {
+            g2d.setColor(Color.WHITE);
             // 计算每行文本的宽度
             int lineWidth = fm.stringWidth(line);
             // 将文本的起始位置设置为图像宽度减去文本的宽度
@@ -84,15 +112,14 @@
         // 释放 Graphics2D 对象
         g2d.dispose();
         // 保存添加水印后的图片
-        File outputFile = File.createTempFile("mark", ".jpg");
-        File originalImageFiles = new File(outputFile.toURI());
+        File outputFile = new File("src/main/copy.jpeg");
         try {
-            ImageIO.write(originalImage, "jpg", outputFile);
+            ImageIO.write(originalImage, "jpg", outputFile); // 将图像写入临时文件
         } catch (IOException e) {
             throw new IllegalArgumentException("水印图片保存失败");
         }
-        float compressionQuality = 0.5f; // 0.0 - 1.0, higher value means better quality
-        return compressImageAndGetFile(originalImageFiles, compressionQuality);
+
+        return outputFile; // 返回保存的文件对象
     }
 
     public static String angle(double angle) {

--
Gitblit v1.9.3