From bc16d0f0fc46ca6cb7d9bfb8496ad8f20ffba677 Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Mon, 06 May 2024 14:53:52 +0800
Subject: [PATCH] 修改DB库相关问题
---
src/main/java/com/dji/sample/patches/service/ShpToDataSourceService.java | 2
src/main/java/com/dji/sample/territory/service/ITbDkjbxxService.java | 5 +
src/main/java/com/dji/sample/patches/model/entity/LotInfo.java | 3
src/main/java/com/dji/sample/territory/service/impl/TbDkjbxxServiceImpl.java | 54 +++++++++---
src/main/java/com/dji/sample/territory/controller/TbDkjbxxController.java | 18 ++++
src/main/java/com/dji/sample/territory/model/entity/param/UploadUrlParam.java | 18 ++++
src/main/java/com/dji/sample/patches/service/impl/ShpToDataSourceServiceImpl.java | 26 ++---
src/main/java/com/dji/sample/territory/service/impl/TbFjServiceImpl.java | 2
src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java | 1
src/main/java/com/dji/sample/territory/utils/CoordinateSystemUtil.java | 5 +
src/main/java/com/dji/sample/media/model/MediaFileEntity.java | 3
src/main/java/com/dji/sample/territory/model/entity/TbDkjbxxEntity.java | 31 +------
src/main/java/com/dji/sample/territory/utils/WaterMarkUtil.java | 67 ++++++++++++----
13 files changed, 159 insertions(+), 76 deletions(-)
diff --git a/src/main/java/com/dji/sample/media/model/MediaFileEntity.java b/src/main/java/com/dji/sample/media/model/MediaFileEntity.java
index 59cf0fb..df78a7a 100644
--- a/src/main/java/com/dji/sample/media/model/MediaFileEntity.java
+++ b/src/main/java/com/dji/sample/media/model/MediaFileEntity.java
@@ -76,5 +76,8 @@
@TableField(value = "metadata", typeHandler = FastjsonTypeHandler.class)
private Object metadata;
+ @TableField("isadd")
+ private Integer isadd;
+
}
diff --git a/src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java b/src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java
index c7a4fb8..f423170 100644
--- a/src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java
+++ b/src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java
@@ -162,6 +162,7 @@
if (file != null) {
builder.fileName(file.getName())
.filePath(file.getPath())
+ .isadd(0)
.fingerprint(file.getFingerprint())
.objectKey(file.getObjectKey())
.subFileType(file.getSubFileType())
diff --git a/src/main/java/com/dji/sample/patches/model/entity/LotInfo.java b/src/main/java/com/dji/sample/patches/model/entity/LotInfo.java
index 96eaa7d..f637dff 100644
--- a/src/main/java/com/dji/sample/patches/model/entity/LotInfo.java
+++ b/src/main/java/com/dji/sample/patches/model/entity/LotInfo.java
@@ -63,6 +63,9 @@
@TableField("sjlx")
private String sjlx;
+ @TableField("isplan")
+ private int isplan;
+
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Long createTime;
diff --git a/src/main/java/com/dji/sample/patches/service/ShpToDataSourceService.java b/src/main/java/com/dji/sample/patches/service/ShpToDataSourceService.java
index 50642bc..60b4567 100644
--- a/src/main/java/com/dji/sample/patches/service/ShpToDataSourceService.java
+++ b/src/main/java/com/dji/sample/patches/service/ShpToDataSourceService.java
@@ -32,4 +32,6 @@
* @param list 需要保存到数据库的TbDkjbxxEntity实体列表。
*/
void savaInMysql(List<TbDkjbxxEntity> list, String workspaceId);
+
+ List<LotInfo> getNoPlan();
}
diff --git a/src/main/java/com/dji/sample/patches/service/impl/ShpToDataSourceServiceImpl.java b/src/main/java/com/dji/sample/patches/service/impl/ShpToDataSourceServiceImpl.java
index 84868e4..5a13fba 100644
--- a/src/main/java/com/dji/sample/patches/service/impl/ShpToDataSourceServiceImpl.java
+++ b/src/main/java/com/dji/sample/patches/service/impl/ShpToDataSourceServiceImpl.java
@@ -1,5 +1,6 @@
package com.dji.sample.patches.service.impl;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dji.sample.patches.config.pojo.PatchesConfigPojo;
import com.dji.sample.patches.dao.ShpToDataSourceMapper;
import com.dji.sample.patches.model.entity.LotInfo;
@@ -90,6 +91,7 @@
}
}
+
/**
* 将SQlite数据库中DKJBXX对象转换为LotInfo对象。
*
@@ -97,26 +99,20 @@
* @return 返回一个构建好的LotInfo对象,包含从数据库实体中转换来的信息。
*/
private LotInfo dbConvertToEntity(TbDkjbxxEntity file, String workspaceId) {
- double[] coordinates = extractCoordinates(pointCGCStoWGS(file.getXzb(), file.getYzb()));
LotInfo.LotInfoBuilder builder = LotInfo.builder();
- builder.bsm(file.getBsm())
- .bz(file.getBz())
- .dkmj(file.getDkmj())
- .dkmc(file.getDkmc())
- .dkbh(file.getDkbh())
- .xmc(file.getXmc())
- .xzb(coordinates[0])
- .sfbhzdk(file.getSfbhzdk())
- .sjlx(file.getSjlx())
- .dkfw(poylonCGCStoWGS(file.getDkfw()))
- .xzqdm(file.getXzqdm())
- .yzb(coordinates[1])
- .kzxx(file.getKzxx())
- .dklx(file.getDklx())
+ builder.bsm(file.getFId())
+ .xzqdm(file.getFXzqdmsys())
+ .dkbh(file.getFTbbh())
+ .dkfw(file.getFShape())
.workspaceId(workspaceId)
+ .isplan(0)
.build();
return builder.build();
}
+
+ public List<LotInfo> getNoPlan(){
+ return shpToDataSourceMapper.selectList(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getIsplan,0));
+ }
}
diff --git a/src/main/java/com/dji/sample/territory/controller/TbDkjbxxController.java b/src/main/java/com/dji/sample/territory/controller/TbDkjbxxController.java
index 4e8c897..30f6619 100644
--- a/src/main/java/com/dji/sample/territory/controller/TbDkjbxxController.java
+++ b/src/main/java/com/dji/sample/territory/controller/TbDkjbxxController.java
@@ -17,11 +17,13 @@
import com.dji.sample.patches.xml.mode.XMLTemplateModel;
import com.dji.sample.patches.xml.utils.CreateWaylineFileUtils;
import com.dji.sample.territory.model.entity.TbDkjbxxEntity;
+import com.dji.sample.territory.model.entity.param.UploadUrlParam;
import com.dji.sample.territory.service.ITbDkjbxxService;
import com.dji.sample.territory.service.ITbFJService;
import com.dji.sample.wayline.model.entity.WaylineFileEntity;
import com.dji.sample.wayline.service.IWaylineFileService;
import lombok.extern.slf4j.Slf4j;
+import org.apache.ibatis.annotations.Param;
import org.locationtech.jts.geom.Coordinate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -70,9 +72,21 @@
* @return
*/
@PostMapping("/upload")
- public ResponseResult uploadFile(@RequestParam("file") MultipartFile file) {
+ public ResponseResult uploadFile(@RequestParam("file") MultipartFile file){
+ String workspaceId="4a574db8-4ad3-48f7-9f16-3edbcd8056e1";
tbDkjbxxService.uploadFile(file);
- return ResponseResult.success("文件上传成功");
+ List<TbDkjbxxEntity> list = tbDkjbxxService.list();
+ shpToDataSourceService.savaInMysql(list, workspaceId);
+ return ResponseResult.success("上传成功");
+ }
+
+ @PostMapping("/uploadUrl")
+ public ResponseResult uploadUrl( @RequestBody UploadUrlParam param){
+ tbDkjbxxService.uploadUrl(param.getDbUrl());
+ String workspaceId="4a574db8-4ad3-48f7-9f16-3edbcd8056e1";
+ List<TbDkjbxxEntity> list = tbDkjbxxService.list();
+ shpToDataSourceService.savaInMysql(list, workspaceId);
+ return ResponseResult.success("上传成功");
}
/**
diff --git a/src/main/java/com/dji/sample/territory/model/entity/TbDkjbxxEntity.java b/src/main/java/com/dji/sample/territory/model/entity/TbDkjbxxEntity.java
index 903ae38..0c7f2e3 100644
--- a/src/main/java/com/dji/sample/territory/model/entity/TbDkjbxxEntity.java
+++ b/src/main/java/com/dji/sample/territory/model/entity/TbDkjbxxEntity.java
@@ -18,35 +18,14 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
-@TableName(value = "DKJBXX")
+@TableName(value = "table_info")
public class TbDkjbxxEntity {
- @TableId(type = IdType.NONE)
- private String bsm;
+private String fXzqdmsys;
- private String dklx;
+private String fShape;
- private String xzqdm;
+private String fTbbh;
- private String xmc;
-
- private String dkbh;
-
- private String dkmc;
-
- private Double dkmj;
-
- private String sfbhzdk;
-
- private Double xzb;
-
- private Double yzb;
-
- private String bz;
-
- private String kzxx;
-
- private String dkfw;
-
- private String sjlx;
+private String fId;
}
\ No newline at end of file
diff --git a/src/main/java/com/dji/sample/territory/model/entity/param/UploadUrlParam.java b/src/main/java/com/dji/sample/territory/model/entity/param/UploadUrlParam.java
new file mode 100644
index 0000000..b227de7
--- /dev/null
+++ b/src/main/java/com/dji/sample/territory/model/entity/param/UploadUrlParam.java
@@ -0,0 +1,18 @@
+package com.dji.sample.territory.model.entity.param;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class UploadUrlParam {
+ private String dbUrl;
+
+ private String taskName;
+
+ private String count;
+}
diff --git a/src/main/java/com/dji/sample/territory/service/ITbDkjbxxService.java b/src/main/java/com/dji/sample/territory/service/ITbDkjbxxService.java
index 7686445..91ea028 100644
--- a/src/main/java/com/dji/sample/territory/service/ITbDkjbxxService.java
+++ b/src/main/java/com/dji/sample/territory/service/ITbDkjbxxService.java
@@ -6,6 +6,7 @@
import com.dji.sample.patches.model.entity.LotInfo;
import com.dji.sample.territory.model.entity.TbDkjbxxEntity;
import com.dji.sample.territory.model.entity.TbFjEntity;
+import com.dji.sample.territory.model.entity.param.UploadUrlParam;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
@@ -24,9 +25,11 @@
* @param file
* @return
*/
- ResponseResult<String> uploadFile(MultipartFile file);
+ ResponseResult uploadFile(MultipartFile file);
MultipartFile listFile(String workspaceId, String waylineName, double airportLat, double airportLon) throws IOException;
+ ResponseResult uploadUrl(String url);
+
}
diff --git a/src/main/java/com/dji/sample/territory/service/impl/TbDkjbxxServiceImpl.java b/src/main/java/com/dji/sample/territory/service/impl/TbDkjbxxServiceImpl.java
index a5be0c5..9adf2ed 100644
--- a/src/main/java/com/dji/sample/territory/service/impl/TbDkjbxxServiceImpl.java
+++ b/src/main/java/com/dji/sample/territory/service/impl/TbDkjbxxServiceImpl.java
@@ -14,6 +14,7 @@
import com.dji.sample.territory.dao.ITbFjMapper;
import com.dji.sample.territory.model.entity.TbDkjbxxEntity;
import com.dji.sample.territory.model.entity.TbFjEntity;
+import com.dji.sample.territory.model.entity.param.UploadUrlParam;
import com.dji.sample.territory.pojo.TerritoryConfigPojo;
import com.dji.sample.territory.service.ITbDkjbxxService;
import org.locationtech.jts.geom.Coordinate;
@@ -27,6 +28,7 @@
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
+import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@@ -47,6 +49,8 @@
public class TbDkjbxxServiceImpl extends ServiceImpl<ITbDkjbxxMapper, TbDkjbxxEntity> implements ITbDkjbxxService {
@Autowired
private ITbDkjbxxMapper iTbDkjbxxMapper;
+ @Autowired
+ private TbFjServiceImpl tbFjService;
@Autowired
private PatchesConfigPojo patchesConfigPojo;
@Autowired
@@ -111,6 +115,37 @@
return convert(new File(destKMZFile));
}
+ @Override
+ public ResponseResult uploadUrl(String url) {
+ if (url.isEmpty()) {
+ throw new IllegalArgumentException("上传文件为空");
+ }
+ downloadFile(url);
+ return ResponseResult.success();
+ }
+ public File downloadFile(String fileUrl) {
+ File downloadedFile = null;
+ try {
+ URL url = new URL(fileUrl);
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ InputStream inputStream = connection.getInputStream();
+ downloadedFile = new File(territoryConfigPojo.getPath());
+ OutputStream outputStream = new FileOutputStream(downloadedFile);
+ byte[] buffer = new byte[1024];
+ int bytesRead;
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
+ outputStream.write(buffer, 0, bytesRead);
+ }
+ inputStream.close();
+ outputStream.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ return downloadedFile;
+ }
+
/**
* 将TbDkjbxxEntity类型的列表转换为LotInfo类型的列表。
*
@@ -120,25 +155,14 @@
private List<LotInfo> dbConvertToEntity(List<TbDkjbxxEntity> list) {
List<LotInfo> infos = new ArrayList<>();
for (TbDkjbxxEntity file : list) {
- double[] coordinates = extractCoordinates(pointCGCStoWGS(file.getXzb(), file.getYzb()));
// 使用Builder模式构建LotInfo对象
LotInfo.LotInfoBuilder builder = LotInfo.builder();
if (file != null) {
// 从TbDkjbxxEntity实体中提取信息,构建LotInfo对象
- builder.bsm(file.getBsm())
- .bz(file.getBz())
- .dkmj(file.getDkmj())
- .dkmc(file.getDkmc())
- .dkbh(file.getDkbh())
- .xmc(file.getXmc())
- .xzb(coordinates[0])
- .sfbhzdk(file.getSfbhzdk())
- .sjlx(file.getSjlx())
- .dkfw(poylonCGCStoWGS(file.getDkfw()))
- .xzqdm(file.getXzqdm())
- .yzb(coordinates[1])
- .kzxx(file.getKzxx())
- .dklx(file.getDklx())
+ builder.bsm(file.getFId())
+ .dkbh(file.getFTbbh())
+ .dkfw(file.getFShape())
+ .xzqdm(file.getFXzqdmsys())
.build();
// 将构建好的LotInfo对象添加到infos列表中
infos.add(builder.build());
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 de85568..336f61a 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
@@ -96,7 +96,7 @@
//对应图片和视频文件进行不同处理
boolean endsWith = key.endsWith(".mp4");
if (!endsWith) {
- file1 = WaterMarkUtil.addWatermark(file, patchesConfigPojo.getUnzip(), pssj, lat, lng);
+ file1 = WaterMarkUtil.addWatermark(file, patchesConfigPojo.getUnzip(), pssj, lat, lng,gimbalYawDegree);
FJ = fileToByteArray(file1);
} else {
file1 = VideoZipUtil.compressVideo(file, 800000, 128000, 1280, 720);
diff --git a/src/main/java/com/dji/sample/territory/utils/CoordinateSystemUtil.java b/src/main/java/com/dji/sample/territory/utils/CoordinateSystemUtil.java
index eff1297..b714146 100644
--- a/src/main/java/com/dji/sample/territory/utils/CoordinateSystemUtil.java
+++ b/src/main/java/com/dji/sample/territory/utils/CoordinateSystemUtil.java
@@ -3,6 +3,7 @@
import org.geotools.geometry.jts.JTS;
import org.geotools.referencing.CRS;
import org.locationtech.jts.geom.Geometry;
+import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CRSAuthorityFactory;
@@ -60,12 +61,16 @@
Geometry geometry = reader.read(wkt);
geometry.setSRID(srid);
return geometry;
+ } catch (ParseException e) {
+ System.out.println("WKT解析错误: " + e.getMessage());
+ e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
+
public static Geometry coordinateTransform(Geometry sourceGeometry, int targetSrid) {
if (sourceGeometry == null || sourceGeometry.getSRID() == 0 || targetSrid == 0) {
return null;
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 359ab80..c91c4f8 100644
--- a/src/main/java/com/dji/sample/territory/utils/WaterMarkUtil.java
+++ b/src/main/java/com/dji/sample/territory/utils/WaterMarkUtil.java
@@ -23,7 +23,9 @@
* @return 添加水印并压缩后的图片文件。
* @throws IOException 如果读取或保存图片失败。
*/
- public static File addWatermark(File file, String path, Long pssj, Double lat, Double lng) throws IOException {
+ public static File addWatermark(File file, String path, Long pssj, Double lat, Double lng, Double angles) throws IOException {
+ String author="机巢";
+ String angel=angle(angles);
Long timestamp = pssj; // 例如:Unix 时间戳(以秒为单位)
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String sd = sdf.format(new Date(Long.parseLong(String.valueOf(timestamp))));
@@ -39,31 +41,26 @@
Graphics2D g2d = originalImage.createGraphics();
// 设置水印文字 "国土调查云"
- String watermarkText = "国土调查云";
-
- // 设置水印文字样式
- g2d.setColor(Color.WHITE); // 设置为白色
+ String watermarkText = "江西调查云";
float alpha = 0.5f; // 设置透明度为 0.5
AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
g2d.setComposite(alphaComposite);
+ g2d.setFont(new Font("宋体", Font.BOLD, 100)); // 使用宋体字体
+ FontMetrics fms = g2d.getFontMetrics();
+ int textHeights = fms.getHeight();
- g2d.setFont(new Font("宋体", Font.BOLD, 200)); // 使用宋体字体
-
- // 设置水印位置(左上角)
- int x1 = 400; // 左上角水印位置 x 坐标
- int y1 = 1200; // 左上角水印位置 y 坐标
-
+ // 设置水印位置(左居中)
+ int x1 = 100; // 左边距离图片左边缘的距离
+ int y1 = (originalImage.getHeight() - textHeights) / 2; // 垂直居中
// 旋转35度角
double angle = Math.toRadians(35);
AffineTransform at = AffineTransform.getRotateInstance(angle, x1, y1);
g2d.setTransform(at);
-
// 绘制左上角旋转水印文字
g2d.drawString(watermarkText, x1, y1);
- // 设置第一个水印完毕,恢复透明度为不透明状态(透明度为 1.0)
alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f);
g2d.setComposite(alphaComposite);
- String extraInfo = String.format("时间:%s\nlon:%.9f lat:%.6f", sd, lng, lat);
+ 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);
// 计算文本宽度和高度
@@ -95,8 +92,46 @@
throw new IllegalArgumentException("水印图片保存失败");
}
float compressionQuality = 0.5f; // 0.0 - 1.0, higher value means better quality
- File compressedImageFile = compressImageAndGetFile(originalImageFiles, compressionQuality);
- return compressedImageFile;
+ return compressImageAndGetFile(originalImageFiles, compressionQuality);
}
+ public static String angle(double angle) {
+ if (angle > 0 && angle < 45) {
+ return "北偏东";
+ }
+ if (angle > 45 && angle < 90) {
+ return "东偏北";
+ }
+ if (angle > 90 && angle < 135) {
+ return "东偏南";
+ }
+ if (angle > 135 && angle < 180) {
+ return "南偏东";
+ }
+ if (angle > -45 && angle < 0) {
+ return "北偏西";
+ }
+ if (angle > -90 && angle < -45) {
+ return "西偏北";
+ }
+ if (angle > -135 && angle < -90) {
+ return "西偏南";
+ }
+ if (angle > -180 && angle < -135) {
+ return "南偏西";
+ }
+ if (angle == 0) {
+ return "正北";
+ }
+ if (angle == 90) {
+ return "正东";
+ }
+ if (angle == 180|| angle == -180) {
+ return "正南";
+ }
+ if (angle == -90) {
+ return "正西";
+ }
+ return "未知";
+ }
}
\ No newline at end of file
--
Gitblit v1.9.3