From 28f661933ffdeb1f65ecee52f8f4b7a3b373da9b Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Mon, 03 Jun 2024 18:29:52 +0800
Subject: [PATCH] 完善图斑功能,完善水印,增加图片的角度信息
---
src/main/java/com/dji/sample/territory/service/impl/TbFjServiceImpl.java | 78 +++++++++++++++++++++++++++++---------
1 files changed, 59 insertions(+), 19 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 1622950..afc83aa 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
@@ -1,8 +1,10 @@
package com.dji.sample.territory.service.impl;
+import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.dji.sample.media.model.MediaFileEntity;
+import com.dji.sample.media.util.ImgUtil;
import com.dji.sample.patches.config.pojo.PatchesConfigPojo;
import com.dji.sample.patches.model.entity.LotInfo;
import com.dji.sample.territory.dao.ITbFjMapper;
@@ -21,6 +23,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 +72,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,28 +100,38 @@
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;
+ double psjd = WaterMarkUtil.convertAngle(gimbalYawDegree);
int pshgj = 0;
String psry = "中图智绘无人机";
String zsdm = "23C8CCC61E3042FBA6A658F319337B1A";
String dklx = "0";
int fjlx = 1;
- String pstz="Y";
- Long sj = mediaFile.getCreateTime();
- String pssj=convertTimestampToDateTime(sj);
+ 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);
+// JSONObject jsonObjects = JSONObject.parseObject(ImgUtil.getInfo(file));
+ JSONObject jsons = (JSONObject) (ImgUtil.getInfo(file));
+ String str = jsons.toJSONString();
+ String newstr = str.replace("+", "");
+ JSONObject json = JSON.parseObject(newstr);
+ Double pitch = json.getDouble("GimbalPitchDegree");
+ String focal = json.getString("FocalLength");
+ String numberPart = focal.replaceAll("[^\\d]", "");
+ int psjj = Integer.parseInt(numberPart);
+ json.getString("GimbalYawDegree");
String fjhxz = HashUtil.SM3Hash(file);
BufferedImage image = ImageIO.read(file);
int width = image.getWidth();
@@ -123,13 +139,13 @@
//对应图片和视频文件进行不同处理
boolean endsWith = key.endsWith(".mp4");
if (!endsWith) {
- file1 = WaterMarkUtil.addWatermark(file, patchesConfigPojo.getUnzip(), sj, lat, lng,gimbalYawDegree);
+ file1 = WaterMarkUtil.addWatermark(file, 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+","+y+","+x+","+gimbalYawDegree+","+psjd+","+pshgj+","+psry+","+zsdm);
+ String sm3 = Sm3Util.calculateSM3Hash(fjhxz + "," + pssj + "," + lng + "," + lat + "," + gimbalYawDegree + "," + psjd + "," + pshgj + "," + psry + "," + zsdm);
byte[] hash = sm3.getBytes(); // 注意:使用SM3或其他哈希算法来计算数据的哈希值
// 加载私钥
@@ -142,16 +158,17 @@
.dkbsm(lotInfo.getBsm())
.xzqdm(lotInfo.getXzqdm())
.dklx(dklx)
- .xdgd(relativeAltitude)
- .jdgd(absoluteAltitude)
- .Latitude(x)
- .longitude(y)
+ .xdgd(truncateToTwoDecimalPlaces(relativeAltitude))
+ .jdgd(truncateToTwoDecimalPlaces(absoluteAltitude))
+ .Latitude(truncateToSevenDecimalPlaces(lat))
+ .longitude(truncateToSevenDecimalPlaces(lng))
.fj(FJ)
+ .psjj(psjj)
.fjmc(fjmc)
.fjlx(fjlx)
- .psfyj(gimbalYawDegree)
+ .psfyj(pitch)
.pssj(pssj)
- .psjd(psjd)
+ .psjd((int) psjd)
.fjhxz(fjhxz)
.pshgj(pshgj)
.zsdm(zsdm)
@@ -175,7 +192,7 @@
* @param fileUrl
* @return
*/
- public File downloadFile(String fileUrl) {
+ public static File downloadFile(String fileUrl) {
File downloadedFile = null;
try {
URL url = new URL(fileUrl);
@@ -211,6 +228,7 @@
fis.close();
return data;
}
+
public static String convertTimestampToDateTime(long timestamp) {
// 将时间戳转换为 Instant 对象
Instant instant = Instant.ofEpochMilli(timestamp);
@@ -222,4 +240,26 @@
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