From a0e7cf2d16dc23b1d6edf3b69678ab66ccacb54d Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Wed, 12 Jun 2024 15:51:14 +0800
Subject: [PATCH] 图斑生成航线,图片哈希值
---
src/main/java/com/dji/sample/territory/service/impl/TbFjServiceImpl.java | 47 +++++++++++++++++++++++++++--------------------
1 files changed, 27 insertions(+), 20 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 816a922..87426ca 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,17 +1,16 @@
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;
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;
+import com.dji.sample.territory.utils.*;
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -72,7 +71,7 @@
public void insertOneData(MediaFileEntity mediaFile, LotInfo lotInfo) throws Exception {
TbFjEntity tbFj = dbConvertToEntity(mediaFile, lotInfo);
- if (tbFj.getFjysgd()==3000){
+ if (tbFj.getFjysgd() == 3000) {
tbFjMapper.insert(tbFj);
}
}
@@ -106,7 +105,7 @@
// 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";
@@ -120,26 +119,32 @@
String head = "http://dev.jxpskj.com:9000/cloud-bucket";
String url = head + key;
File file = downloadFile(url);
- String fjhxz = HashUtil.SM3Hash(file);
+// 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");
BufferedImage image = ImageIO.read(file);
int width = image.getWidth();
int height = image.getHeight();
+ String fjhxz = null;
//对应图片和视频文件进行不同处理
boolean endsWith = key.endsWith(".mp4");
if (!endsWith) {
- file1 = WaterMarkUtil.addWatermark(file, sj, lat, lng, gimbalYawDegree);
+ file1 = WaterMarkUtil.addWatermark(file, sj, lat, lng, gimbalYawDegree);
+ fjhxz = String.valueOf(SM3HashExample.HaXi(new File(file1.toURI())));
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);
-
- byte[] hash = sm3.getBytes(); // 注意:使用SM3或其他哈希算法来计算数据的哈希值
- // 加载私钥
- ECPrivateKeyParameters sm2PrivateKey = getSM2PrivateKey();
- // 使用SM2私钥对哈希值进行签名
- String signatureHex = signWithSM2(hash, sm2PrivateKey);
+ String hxz = HashUtil.calculateHash((fjhxz + "," + pssj + "," + lng + "," + lat + "," + gimbalYawDegree + "," + psjd + "," + pshgj + "," + psry + "," + zsdm).getBytes());
+ String jym=SM2SignExamples.jym(hxz);
TbFjEntity.TbFjEntityBuilder builder = TbFjEntity.builder();
if (lotInfo != null) {
builder.bsm(bsm)
@@ -151,16 +156,17 @@
.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)
.psry(psry)
- .jym(signatureHex)
+ .jym(jym)
.url(url)
.pstz(pstz)
.fjyskd(width)
@@ -235,6 +241,7 @@
BigDecimal bd = new BigDecimal(value).setScale(2, RoundingMode.DOWN);
return bd.doubleValue();
}
+
public static Double truncateToSevenDecimalPlaces(Double value) {
if (value == null) {
return null; // 处理null值情况
@@ -245,7 +252,7 @@
}
public static void main(String[] args) {
- System.out.println(truncateToSevenDecimalPlaces(152.00666565));
- System.out.println(truncateToTwoDecimalPlaces(12.006));
+ String s= String.valueOf(SM3HashExample.HaXi(new File("src/main/resources/FJ_10.jpeg")));
+ System.out.println(s);
}
}
--
Gitblit v1.9.3