From 0d02d968ba0626009dfddfccda2ded84a118a88c Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Wed, 17 Jul 2024 10:49:45 +0800
Subject: [PATCH] 新增临时文件自动删除定时器,增加巡河喊话,修改水印文件上传方式
---
src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java | 103 +++++++++++++++++-----------------
src/main/java/com/dji/sample/speak/service/serviceImpl/SpeakVoiceServiceImpl.java | 9 +-
src/main/java/com/dji/sample/speak/service/SpeakVoiceService.java | 2
src/main/java/com/dji/sample/patches/utils/TimerUtil.java | 19 ++++++
src/main/java/com/dji/sample/speak/controller/SpeakVoiceController.java | 4
src/main/java/com/dji/sample/patches/controller/PatchesController.java | 2
6 files changed, 78 insertions(+), 61 deletions(-)
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 27fdcb0..ab36fe7 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
@@ -115,65 +115,64 @@
return mapper.insert(fileEntity);
}
- public void saveMarkFile(String workspaceId, FileUploadDTO file) throws IOException, FontFormatException, ImageProcessingException {
- String endpoint = pojo.getEndpoint();
- String accessKey = pojo.getAccessKey();
- String secretKey = pojo.getSecretKey();
- String bucketName = pojo.getBucket();
- String url = pojo.getEndpoint() + "/" + pojo.getBucket() + file.getObjectKey();
- File file1 = TbFjServiceImpl.downloadFile(url);
- File nailFile = new File(ImgZipUtil.compressImage(file1, 50).toURI());
- MediaFileNailEntity nailEntity = this.fileUploadConvertToNailEntity(file);
- nailEntity.setIsOriginal(false);
- nailEntity.setWorkspaceId(workspaceId);
- nailEntity.setFileName("nail" + file.getName());
- nailEntity.setObjectKey("/nail" + file.getPath() + "/" + file.getName());
- nailEntity.setFilePath("nail" + file.getPath());
- String nailName = nailEntity.getObjectKey();
- nailEntity.setFileId(UUID.randomUUID().toString());
- uploadFile(endpoint, accessKey, secretKey, bucketName, nailName, nailFile, "image/jpeg");
- nailMapper.insert(nailEntity);
- try {
- boolean contains = file.getName().contains("~");
- if (contains) {
- String name = TimerUtil.getDkbh(file.getName());
- List<LotInfo> lotInfos = patchesMapper.selectList(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getDkbh, name));
- if (!lotInfos.isEmpty()) {
- LambdaUpdateWrapper<LotInfo> updateWrapper = new LambdaUpdateWrapper<>();
- updateWrapper.eq(LotInfo::getDkbh, name)
- .eq(LotInfo::getInvestigate, 0)
- .set(LotInfo::getInvestigate, 1);
- patchesMapper.update(null, updateWrapper);
+ public void saveMarkFile(String workspaceId, FileUploadDTO file) throws IOException {
+ boolean endsWith = file.getObjectKey().endsWith(".mp4");
+ if (endsWith) {
+ MediaFileNailEntity nailEntity = this.fileUploadConvertToNailEntity((file));
+ nailEntity.setWorkspaceId(workspaceId);
+ nailEntity.setFileId(UUID.randomUUID().toString());
+ nailMapper.insert(nailEntity);
+ } else {
+ String endpoint = pojo.getEndpoint();
+ String accessKey = pojo.getAccessKey();
+ String secretKey = pojo.getSecretKey();
+ String bucketName = pojo.getBucket();
+ String url = pojo.getEndpoint() + "/" + pojo.getBucket() + file.getObjectKey();
+ File file1 = TbFjServiceImpl.downloadFile(url);
+ File nailFile = new File(ImgZipUtil.compressImage(file1, 50).toURI());
+ MediaFileNailEntity nailEntity = this.fileUploadConvertToNailEntity(file);
+ nailEntity.setIsOriginal(false);
+ nailEntity.setWorkspaceId(workspaceId);
+ nailEntity.setFileName("nail" + file.getName());
+ nailEntity.setObjectKey("/nail" + file.getPath() + "/" + file.getName());
+ nailEntity.setFilePath("nail" + file.getPath());
+ String nailName = nailEntity.getObjectKey();
+ nailEntity.setFileId(UUID.randomUUID().toString());
+ uploadFile(endpoint, accessKey, secretKey, bucketName, nailName, nailFile, "image/jpeg");
+ nailMapper.insert(nailEntity);
+ try {
+ if (file.getName().contains("~")) {
+ String name = TimerUtil.getDkbh(file.getName());
+ List<LotInfo> lotInfos = patchesMapper.selectList(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getDkbh, name));
+ if (!lotInfos.isEmpty()) {
+ LambdaUpdateWrapper<LotInfo> updateWrapper = new LambdaUpdateWrapper<>();
+ updateWrapper.eq(LotInfo::getDkbh, name)
+ .eq(LotInfo::getInvestigate, 0)
+ .set(LotInfo::getInvestigate, 1);
+ patchesMapper.update(null, updateWrapper);
+ }
}
-
- boolean endsWith = file.getObjectKey().endsWith(".mp4");
- if (endsWith) {
MediaFileMarkEntity mediaFileMarkEntity = this.fileUploadConvertToMarkEntity(file);
+ long timestamp = convertToTimestamp(file.getMetadata().getCreatedTime());
+ File markFile = new File(WaterMarkUtil.addWatermark(file1, timestamp, file.getMetadata().getShootPosition().getLat(),
+ file.getMetadata().getShootPosition().getLng(), file.getMetadata().getGimbalYawDegree()).toURI());
+ Object data = ImgUtil.getInfo(file1);
+ mediaFileMarkEntity.setDronedata(data);
mediaFileMarkEntity.setWorkspaceId(workspaceId);
+ mediaFileMarkEntity.setIsadd(0);
+ mediaFileMarkEntity.setIsOriginal(false);
mediaFileMarkEntity.setFileId(UUID.randomUUID().toString());
+ mediaFileMarkEntity.setObjectKey("/mark" + file.getPath() + "/" + file.getName());
+ mediaFileMarkEntity.setFileName("mark" + file.getName());
+ mediaFileMarkEntity.setFilePath("mark" + file.getPath());
+ String objectName = mediaFileMarkEntity.getObjectKey(); // 例如 "folder/file.txt"
+ uploadFile(endpoint, accessKey, secretKey, bucketName, objectName, markFile, "image/jpeg");
markMapper.insert(mediaFileMarkEntity);
- }
- MediaFileMarkEntity mediaFileMarkEntity = this.fileUploadConvertToMarkEntity(file);
- long timestamp = convertToTimestamp(file.getMetadata().getCreatedTime());
- File markFile = new File(WaterMarkUtil.addWatermark(file1, timestamp, file.getMetadata().getShootPosition().getLat(),
- file.getMetadata().getShootPosition().getLng(), file.getMetadata().getGimbalYawDegree()).toURI());
- Object data = ImgUtil.getInfo(file1);
- mediaFileMarkEntity.setDronedata(data);
- mediaFileMarkEntity.setWorkspaceId(workspaceId);
- mediaFileMarkEntity.setIsadd(0);
- mediaFileMarkEntity.setIsOriginal(false);
- mediaFileMarkEntity.setFileId(UUID.randomUUID().toString());
- mediaFileMarkEntity.setObjectKey("/mark" + file.getPath() + "/" + file.getName());
- mediaFileMarkEntity.setFileName("mark" + file.getName());
- mediaFileMarkEntity.setFilePath("mark" + file.getPath());
- String objectName = mediaFileMarkEntity.getObjectKey(); // 例如 "folder/file.txt"
- uploadFile(endpoint, accessKey, secretKey, bucketName, objectName, markFile, "image/jpeg");
- markMapper.insert(mediaFileMarkEntity);
+ } catch (Exception e) {
+ e.printStackTrace();
}
- } catch (Exception e) {
- e.printStackTrace();
}
- }
+ }
@Override
public Object mediaInfo(String filename) {
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 58b4bd1..da5a457 100644
--- a/src/main/java/com/dji/sample/patches/controller/PatchesController.java
+++ b/src/main/java/com/dji/sample/patches/controller/PatchesController.java
@@ -165,7 +165,7 @@
@GetMapping("/useMyTask")
public ResponseResult useMyTask() throws Exception {
try {
- timerUtil.myTask();
+ TimerUtil.mytask10();
// timerUtil.myTask2();
// timerUtil.myTask3();
// timerUtil.mytask4();
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 afa660b..3ba0976 100644
--- a/src/main/java/com/dji/sample/patches/utils/TimerUtil.java
+++ b/src/main/java/com/dji/sample/patches/utils/TimerUtil.java
@@ -218,6 +218,24 @@
String times = convertTimestampToFormattedString(time);
sendPostWithParameters("定时任务4:30", "c3a7b125-bc0b-49d4-96ed-80743200ab80", times, lists1, listOfLists);
}
+ @Scheduled(cron = "0 0 6 * * ?")
+ public static void mytask10() {
+ File directory = new File("/tmp");
+ String[] partialFileNames = {"temp", "mark"}; // 要匹配的部分文件名
+ if (directory.isDirectory()) {
+ File[] files = directory.listFiles();
+ if (files != null) {
+ for (File file : files) {
+ for (String partialFileName : partialFileNames) {
+ if (file.isFile() && file.getName().contains(partialFileName)) {
+ file.delete();
+ break; // 跳出内层循环,以免重复删除同一个文件
+ }
+ }
+ }
+ }
+ }
+ }
/**
* 完成对未推送的图斑数据进行整合发送
*
@@ -272,6 +290,7 @@
return convert(new File(destKMZFile));
}
+
/**
* 将航线上传Oss
*
diff --git a/src/main/java/com/dji/sample/speak/controller/SpeakVoiceController.java b/src/main/java/com/dji/sample/speak/controller/SpeakVoiceController.java
index 2a764a3..a3b93d8 100644
--- a/src/main/java/com/dji/sample/speak/controller/SpeakVoiceController.java
+++ b/src/main/java/com/dji/sample/speak/controller/SpeakVoiceController.java
@@ -57,8 +57,8 @@
}
@PostMapping("/putVoice")
- public ResponseResult putVoice(int id) {
- return ResponseResult.success(voiceServicel.awayRiver(id));
+ public ResponseResult putVoice() {
+ return ResponseResult.success(voiceServicel.awayRiver());
}
@GetMapping("/selectVoice")
diff --git a/src/main/java/com/dji/sample/speak/service/SpeakVoiceService.java b/src/main/java/com/dji/sample/speak/service/SpeakVoiceService.java
index 9d96eda..5ba41e6 100644
--- a/src/main/java/com/dji/sample/speak/service/SpeakVoiceService.java
+++ b/src/main/java/com/dji/sample/speak/service/SpeakVoiceService.java
@@ -26,7 +26,7 @@
int setVoiceVolume(SpeakVolumeDto dto,String sn);
- int awayRiver (int id);
+ int awayRiver ();
PaginationData<SpeakVoiceEntity> getVoices(Integer pages,Integer page_size);
}
diff --git a/src/main/java/com/dji/sample/speak/service/serviceImpl/SpeakVoiceServiceImpl.java b/src/main/java/com/dji/sample/speak/service/serviceImpl/SpeakVoiceServiceImpl.java
index e642faa..cfe43a8 100644
--- a/src/main/java/com/dji/sample/speak/service/serviceImpl/SpeakVoiceServiceImpl.java
+++ b/src/main/java/com/dji/sample/speak/service/serviceImpl/SpeakVoiceServiceImpl.java
@@ -89,14 +89,13 @@
}
@Override
- public int awayRiver(int id) {
- SpeakVoiceEntity voiceEntity=voiceMapper.selectById(id);
+ public int awayRiver() {
SpeakVoiceStartDto dto = new SpeakVoiceStartDto();
SpeakVoiceFileDto fileDto = new SpeakVoiceFileDto();
- fileDto.setUrl(voiceEntity.getUrl());
- fileDto.setMd5(voiceEntity.getMd5());
+ fileDto.setUrl("http://dev.jxpskj.com:9000/cloud-bucket/请远离河道07151604");
+ fileDto.setMd5("d2b448dcba09071834d02f082dc5386f");
fileDto.setFormat(FormatEnum.PCM);
- fileDto.setName(voiceEntity.getName());
+ fileDto.setName("河道危险");
dto.setPsdk_index(2);
dto.setFile(fileDto);
return messageSenderService.publishServicesTopic("4TADKCM0010016", VoiceEnums.SPEAKER_AUDIO_PLAY_START.getMethod(), dto).getResult();
--
Gitblit v1.9.3