From 39ffdf5754b4ebca682bd3c925f7a500e8a1bbda Mon Sep 17 00:00:00 2001
From: aix <vip_xiaobin810@163.com>
Date: Thu, 08 Aug 2024 16:56:36 +0800
Subject: [PATCH] 国土调查云身份凭证token
---
src/main/java/com/dji/sample/territory/service/impl/TbFjServiceImpl.java | 112 ++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 73 insertions(+), 39 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..4ccc300 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,43 +1,40 @@
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.dao.IMarkMapper;
+import com.dji.sample.media.model.*;
+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.pojo.TerritoryConfigPojo;
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 org.bouncycastle.crypto.params.ECPrivateKeyParameters;
+import com.dji.sample.territory.utils.*;
import org.springframework.beans.factory.annotation.Autowired;
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.math.BigDecimal;
import java.math.RoundingMode;
import java.net.HttpURLConnection;
import java.net.URL;
-import java.text.SimpleDateFormat;
+import java.nio.file.Files;
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;
-import static com.dji.sample.territory.utils.CoordinateSystemUtil.*;
-import static com.dji.sample.territory.utils.SM2SignUtil.getSM2PrivateKey;
-import static com.dji.sample.territory.utils.SM2SignUtil.signWithSM2;
+import static com.dji.sample.media.service.impl.FileServiceImpl.uploadFile;
+import static com.dji.sample.territory.utils.SM3.sm3;
@Service
@DS("sqlite-ret")
@@ -46,7 +43,12 @@
private ITbFjMapper tbFjMapper;
@Autowired
private PatchesConfigPojo patchesConfigPojo;
-
+ @Autowired
+ private TerritoryConfigPojo territoryConfigPojo;
+ @Autowired
+ private MinioPojo pojo;
+ @Autowired
+ private IMarkMapper markMapper;
/**
* 按照地块编号所对应的信息和音视频文件存入sqlite数据库
*
@@ -72,7 +74,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);
}
}
@@ -102,11 +104,14 @@
JSONObject shootPosition = jsonObject.getJSONObject("shootPosition");
Double lat = shootPosition.getDouble("lat");
Double lng = shootPosition.getDouble("lng");
+ PositionDTO position=new PositionDTO();
+ position.setLat(lat);
+ position.setLng(lng);
// 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";
@@ -120,26 +125,33 @@
String head = "http://dev.jxpskj.com:9000/cloud-bucket";
String url = head + key;
File file = downloadFile(url);
- String fjhxz = HashUtil.SM3Hash(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);
+ byte[] bytesArray = Files.readAllBytes(file1.toPath());
+ fjhxz= sm3(bytesArray);
FJ = fileToByteArray(file1);
+ saveMarkFile(lotInfo.getWorkspaceId(),mediaFile,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);
+ StringBuffer buffer=SM3.addStringBuffer(fjhxz,pssj,truncateToSevenDecimalPlaces(lng),truncateToSevenDecimalPlaces(lat),(int)pitch,(int)psjd,pshgj,psry,zsdm);
+ String jyms= SM3.addJym(buffer);
TbFjEntity.TbFjEntityBuilder builder = TbFjEntity.builder();
if (lotInfo != null) {
builder.bsm(bsm)
@@ -151,16 +163,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(jyms)
.url(url)
.pstz(pstz)
.fjyskd(width)
@@ -170,6 +183,7 @@
// else {
//// throw new IllegalArgumentException("未匹配到相关地块");
// }
+ file.delete();
return builder.build();
}
@@ -181,18 +195,24 @@
*/
public static File downloadFile(String fileUrl) {
File downloadedFile = null;
+
try {
URL url = new URL(fileUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
- downloadedFile = new File(File.createTempFile("temp", ".jpeg").toURI());
- InputStream inputStream = connection.getInputStream();
- OutputStream outputStream = new FileOutputStream(downloadedFile);
- byte[] buffer = new byte[1024];
- int bytesRead;
- while ((bytesRead = inputStream.read(buffer)) != -1) {
- outputStream.write(buffer, 0, bytesRead);
+ // 创建临时文件
+ File tempFile = File.createTempFile("temp", ".jpeg");
+ downloadedFile = tempFile;
+
+ // 使用 try-with-resources 确保流被关闭
+ try (InputStream inputStream = connection.getInputStream();
+ OutputStream outputStream = new FileOutputStream(downloadedFile)) {
+ byte[] buffer = new byte[1024];
+ int bytesRead;
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
+ outputStream.write(buffer, 0, bytesRead);
+ }
}
} catch (IOException e) {
e.printStackTrace();
@@ -215,6 +235,22 @@
fis.close();
return data;
}
+ public void saveMarkFile(String workspaceId, MediaFileEntity file,File file1) {
+ try {
+ MediaFileMarkEntity mediaFileMarkEntity= new MediaFileMarkEntity();
+ mediaFileMarkEntity.setWorkspaceId(workspaceId);
+ mediaFileMarkEntity.setIsadd(0);
+ mediaFileMarkEntity.setIsOriginal(false);
+ mediaFileMarkEntity.setFileId(UUID.randomUUID().toString());
+ mediaFileMarkEntity.setObjectKey("/mark" + file.getFilePath()+ "/" + file.getFileName());
+ mediaFileMarkEntity.setFileName("mark" + file.getFileName());
+ mediaFileMarkEntity.setFilePath("mark" + file.getFilePath());
+ uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), mediaFileMarkEntity.getObjectKey(), file1, "image/jpeg");
+ markMapper.insert(mediaFileMarkEntity);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
public static String convertTimestampToDateTime(long timestamp) {
// 将时间戳转换为 Instant 对象
@@ -229,23 +265,21 @@
}
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