src/main/java/com/dji/sample/control/model/enums/RemoteDebugMethodEnum.java
@@ -51,7 +51,7 @@ CHARGE_CLOSE("charge_close", true, null), BATTERY_MAINTENANCE_SWITCH("battery_maintenance_switch", true, AlarmState.class), ALARM_STATE_SWITCH("alarm_state_switch", true, AlarmState.class), BATTERY_STORE_MODE_SWITCH("battery_store_mode_switch", true, BatteryStoreMode.class), src/main/java/com/dji/sample/media/controller/FileController.java
@@ -8,6 +8,7 @@ import com.dji.sample.media.model.MediaFileEntity; import com.dji.sample.media.model.MediaFileQueryParam; import com.dji.sample.media.service.IFileService; import com.dji.sample.media.util.ImageDownloaderAndCompressor; import com.drew.imaging.ImageProcessingException; import org.apache.ibatis.annotations.Update; import org.springframework.beans.factory.annotation.Autowired; @@ -15,14 +16,18 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponseWrapper; import java.awt.*; import java.io.File; import java.io.IOException; import java.net.URL; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; import static com.dji.sample.component.AuthInterceptor.TOKEN_CLAIM; import static com.dji.sample.media.util.ImageDownloaderAndCompressor.*; /** * @author sean @@ -65,15 +70,15 @@ @RequestParam(name = "page_size", defaultValue = "10") int pageSize, @PathVariable(name = "workspace_id") String workspaceId ) { return ResponseResult.success(fileService.getPhotoByJobId(page,pageSize,workspaceId, jobId)); return ResponseResult.success(fileService.getPhotoByJobId(page, pageSize, workspaceId, jobId)); } @GetMapping("/{workspace_id}/getJobIds") public ResponseResult getJobIds(@PathVariable(name = "workspace_id") String workspaceId, @RequestParam(defaultValue = "1") int page, @RequestParam(name = "page_size", defaultValue = "10") int pageSize ) { return ResponseResult.success(fileService.getJobId(page,pageSize,workspaceId)); ) { return ResponseResult.success(fileService.getJobId(page, pageSize, workspaceId)); } @PutMapping("/examine") @@ -165,4 +170,10 @@ e.printStackTrace(); } } } @GetMapping("/download-images") public void downloadImages(@RequestParam String jobId, HttpServletResponse response) { fileService.downloadImages(jobId,response); } } src/main/java/com/dji/sample/media/dao/IFileMapper.java
@@ -8,6 +8,7 @@ import com.dji.sample.media.model.MediaJobDTO; import com.dji.sample.media.model.param.SearchMediaParam; import com.dji.sample.wayline.model.dto.WaylineJobDTO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; /** @@ -15,6 +16,7 @@ * @version 0.2 * @date 2021/12/9 */ @Mapper public interface IFileMapper extends BaseMapper<MediaFileEntity> { Page<MediaFileEntity> getPage(@Param("page") Page<MediaFileEntity> mediaFileEntityPage, @Param("workspaceId") String workspaceId,@Param("query") MediaFileQueryParam mediaFileQueryParam); src/main/java/com/dji/sample/media/service/IFileService.java
@@ -5,7 +5,9 @@ import com.dji.sample.common.model.ResponseResult; import com.dji.sample.media.model.*; import com.drew.imaging.ImageProcessingException; import org.springframework.web.bind.annotation.RequestParam; import javax.servlet.http.HttpServletResponse; import java.awt.*; import java.io.IOException; import java.net.URL; @@ -55,6 +57,7 @@ * @return */ Object mediaInfo(String fileId); List<MediaFileEntity> getMedia(String jobId); /** * Query information about all files in this workspace based on the workspace id. * @@ -101,6 +104,8 @@ */ URL getObjectUrl(String workspaceId, String fileId); void downloadImages( String jobId, HttpServletResponse response); /** * Query all media files of a job. * src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java
@@ -43,6 +43,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletResponse; import java.awt.*; import java.io.File; import java.io.FileInputStream; @@ -54,6 +55,8 @@ import java.util.*; import java.util.List; import java.util.stream.Collectors; import static com.dji.sample.media.util.ImageDownloaderAndCompressor.*; /** * @author sean @@ -112,10 +115,12 @@ MediaFileEntity fileEntity = this.fileUploadConvertToEntity(file); fileEntity.setWorkspaceId(workspaceId); fileEntity.setFileId(UUID.randomUUID().toString()); if (!file.getObjectKey().endsWith(".mp4")){ String url = pojo.getEndpoint() + "/" + pojo.getBucket() + file.getObjectKey(); File file1 = TbFjServiceImpl.downloadFile(url); Object data = ImgUtil.getInfo(file1); fileEntity.setDroneData(data); } return mapper.insert(fileEntity); } @@ -424,6 +429,27 @@ } return ossService.getObjectUrl(OssConfiguration.bucket, mediaFileOpt.get().getObjectKey()); } @Override public void downloadImages(String jobId, HttpServletResponse response) { String address = pojo.getEndpoint() + "/" + pojo.getBucket(); List<MediaFileEntity> entities = getMedia(jobId); List<String> urls = entities.stream() .map(MediaFileEntity::getObjectKey) .map(objectKey -> address + objectKey) .collect(Collectors.toList()); String outputFolder = "images"; // 存放图片的文件夹 new File(outputFolder).mkdirs(); // 创建文件夹 try { downloadAndSaveImages(urls, outputFolder); zipAndSendFolder(outputFolder, response); } catch (Exception e) { e.printStackTrace(); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } finally { cleanUp(outputFolder); } } @Override @@ -787,37 +813,64 @@ e.printStackTrace(); } } @Override public PaginationData<MediaFileEntity> getJobId(int pageNum, int pageSize, String workspaceId) { List<MediaFileEntity> allRecords = new ArrayList<>(); int currentPageNum = 1; // 从第一页开始获取记录 public PaginationData<MediaFileEntity> getJobId( int pageNum, int pageSize,String workspaceId) { // 分页查询 Page<MediaFileEntity> page = new Page<>(pageNum, pageSize); Page<MediaFileEntity> resultPage = mapper.selectPage(page, new LambdaQueryWrapper<MediaFileEntity>() .eq(MediaFileEntity::getWorkspaceId, workspaceId)); // 用于存储去重后的记录 Map<String, MediaFileEntity> uniqueFilesMap = new HashMap<>(); List<MediaFileEntity> result = resultPage.getRecords(); while (true) { // 分页查询 Page<MediaFileEntity> page = new Page<>(currentPageNum, pageSize); Page<MediaFileEntity> resultPage = mapper.selectPage(page, new LambdaQueryWrapper<MediaFileEntity>() .eq(MediaFileEntity::getWorkspaceId, workspaceId)); // 根据 fileName 字段进行去重并设置 JobName Map<String, MediaFileEntity> uniqueFilesMap = result.stream() .peek(mediaFile -> { String taskNameResult = waylineJobService.getName(mediaFile.getJobId()); mediaFile.setJobName(taskNameResult); }) .collect(Collectors.toMap( MediaFileEntity::getFileName, entity -> entity, (existing, replacement) -> existing // 如果有重复的,保留已有的 )); List<MediaFileEntity> result = resultPage.getRecords(); // 检查是否还有更多记录 if (result.isEmpty()) { break; // 没有更多记录了,停止请求 } // 根据 fileName 字段进行去重并设置 JobName result.stream() .peek(mediaFile -> { String taskNameResult = waylineJobService.getName(mediaFile.getJobId()); mediaFile.setJobName(taskNameResult); }) .forEach(mediaFile -> uniqueFilesMap.putIfAbsent(mediaFile.getFileName(), mediaFile)); // 增加当前页数以获取更多记录 currentPageNum++; } // 获取去重后的实际总数 List<MediaFileEntity> uniqueFiles = new ArrayList<>(uniqueFilesMap.values()); int uniqueTotal = uniqueFiles.size(); // 使用分页对象构造 Pagination Pagination pagination = new Pagination(resultPage); return new PaginationData<>(uniqueFiles, pagination); // 计算当前页的起始和结束索引 int fromIndex = Math.min((pageNum - 1) * pageSize, uniqueTotal); int toIndex = Math.min(fromIndex + pageSize, uniqueTotal); // 获取当前页的数据 List<MediaFileEntity> pagedUniqueFiles = uniqueFiles.subList(fromIndex, toIndex); // 创建新的分页对象,使用去重后的总数 Page<MediaFileEntity> uniquePage = new Page<>(pageNum, pageSize, uniqueTotal); // 使用新的分页对象构造 Pagination Pagination pagination = new Pagination(uniquePage); return new PaginationData<>(pagedUniqueFiles, pagination); } @Override public PaginationData<MediaFileEntity> getPhotoByJobId(int pageNum,int pageSize,String workspaceId, String jobId) { public PaginationData<MediaFileEntity> getPhotoByJobId(int pageNum, int pageSize, String workspaceId, String jobId) { // 分页查询 Page<MediaFileEntity> page = new Page<>(pageNum, pageSize); @@ -837,13 +890,31 @@ List<MediaFileEntity> uniqueFiles = new ArrayList<>(uniqueFilesMap.values()); // 使用分页对象构造 Pagination Pagination pagination = new Pagination(resultPage); return new PaginationData<>(uniqueFiles, pagination); // 使用去重后的列表重新计算总数 int uniqueTotal = uniqueFiles.size(); // 创建新的分页对象,使用去重后的总数 Page<MediaFileEntity> uniquePage = new Page<>(pageNum, pageSize, uniqueTotal); // 截取当前页的数据 int fromIndex = Math.min((pageNum - 1) * pageSize, uniqueTotal); int toIndex = Math.min(fromIndex + pageSize, uniqueTotal); List<MediaFileEntity> pagedUniqueFiles = uniqueFiles.subList(fromIndex, toIndex); // 使用新的分页对象构造 Pagination Pagination pagination = new Pagination(uniquePage); return new PaginationData<>(pagedUniqueFiles, pagination); } public List<MediaFileEntity> getMedia(String jobId) { return mapper.selectList(new LambdaQueryWrapper<MediaFileEntity>() .eq(MediaFileEntity::getJobId, jobId) .groupBy(MediaFileEntity::getFileName)); // 使用groupBy去重 } public void updateById(Integer id, MediaFileMarkEntity entity) { entity.setIsadd(1); UpdateWrapper<MediaFileMarkEntity> updateWrapper = new UpdateWrapper<>(); src/main/java/com/dji/sample/media/util/ImageDownloaderAndCompressor.java
New file @@ -0,0 +1,133 @@ package com.dji.sample.media.util; import java.awt.image.BufferedImage; import java.io.*; import java.net.URL; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import javax.imageio.ImageIO; import javax.servlet.http.HttpServletResponse; public class ImageDownloaderAndCompressor { private static final int THREAD_POOL_SIZE = 10; public static void downloadAndSaveImages(List<String> urls, String outputFolder) { ExecutorService executorService = Executors.newFixedThreadPool(THREAD_POOL_SIZE); CountDownLatch latch = new CountDownLatch(urls.size()); int count = 0; for (String imageUrl : urls) { final int index = count++; executorService.submit(() -> { try { // 下载图片 URL url = new URL(imageUrl); BufferedImage image = ImageIO.read(url); // 保存图片 File outputfile = new File(outputFolder, "image_" + index + ".jpg"); ImageIO.write(image, "jpg", outputfile); System.out.println("Saved: " + outputfile.getAbsolutePath()); } catch (IOException e) { System.err.println("Failed to download image: " + imageUrl); e.printStackTrace(); } finally { latch.countDown(); } }); } try { latch.await(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); System.err.println("Image downloading was interrupted."); } finally { executorService.shutdown(); } } public static void zipAndSendFolder(String folderName, HttpServletResponse response) { File zipFile = new File(folderName + ".zip"); try { zipFolder(folderName, zipFile.getPath()); // 设置响应头 response.setContentType("application/zip"); response.setHeader("Content-Disposition", "attachment; filename=" + zipFile.getName()); response.setContentLength((int) zipFile.length()); // 将压缩文件写入响应 try (InputStream is = new FileInputStream(zipFile); OutputStream os = response.getOutputStream()) { byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } } } catch (IOException e) { System.err.println("Failed to compress or send folder: " + folderName); e.printStackTrace(); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); try { response.getWriter().write("Failed to compress or send folder: " + folderName); } catch (IOException ex) { ex.printStackTrace(); } } finally { // 删除临时压缩文件 if (zipFile.exists()) { zipFile.delete(); } } } public static void zipFolder(String srcFolder, String destZipFile) throws IOException { try (FileOutputStream fos = new FileOutputStream(destZipFile); ZipOutputStream zos = new ZipOutputStream(fos)) { File srcFile = new File(srcFolder); for (File file : srcFile.listFiles()) { try (FileInputStream fis = new FileInputStream(file)) { ZipEntry zipEntry = new ZipEntry(file.getName()); zos.putNextEntry(zipEntry); byte[] bytes = new byte[1024]; int length; while ((length = fis.read(bytes)) >= 0) { zos.write(bytes, 0, length); } zos.closeEntry(); } } } } public static void cleanUp(String folderName) { File folder = new File(folderName); deleteFolder(folder); } public static void deleteFolder(File folder) { File[] files = folder.listFiles(); if (files != null) { for (File f : files) { if (f.isDirectory()) { deleteFolder(f); } else { f.delete(); } } } folder.delete(); } } src/main/java/com/dji/sample/media/util/UnZipPhotoUtil.java
New file @@ -0,0 +1,80 @@ package com.dji.sample.media.util; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.net.URL; import java.util.List; import java.util.Objects; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class UnZipPhotoUtil { public static void downloadAndSaveImages(List<String> urls, String outputFolder) throws IOException { int count = 0; for (String imageUrl : urls) { try { // 下载图片 URL url = new URL(imageUrl); BufferedImage image = ImageIO.read(url); // 保存图片 File outputfile = new File(outputFolder, "image_" + (count++) + ".jpg"); ImageIO.write(image, "jpg", outputfile); System.out.println("Saved: " + outputfile.getAbsolutePath()); } catch (IOException e) { System.err.println("Failed to download image: " + imageUrl); e.printStackTrace(); throw e; } } } public static void zipFolder(String srcFolder, String destZipFile) throws IOException { try (FileOutputStream fos = new FileOutputStream(destZipFile); ZipOutputStream zos = new ZipOutputStream(fos)) { File srcFile = new File(srcFolder); for (File file : Objects.requireNonNull(srcFile.listFiles())) { try (FileInputStream fis = new FileInputStream(file)) { ZipEntry zipEntry = new ZipEntry(file.getName()); zos.putNextEntry(zipEntry); byte[] bytes = new byte[1024]; int length; while ((length = fis.read(bytes)) >= 0) { zos.write(bytes, 0, length); } zos.closeEntry(); } catch (IOException e) { System.err.println("Failed to zip file: " + file.getPath()); e.printStackTrace(); throw e; } } } } public static void cleanUp(String folderName) { File folder = new File(folderName); deleteFolder(folder); } public static void deleteFolder(File folder) { File[] files = folder.listFiles(); if (files != null) { for (File f : files) { if (f.isDirectory()) { deleteFolder(f); } else { f.delete(); } } } folder.delete(); } } src/main/java/com/dji/sample/patches/controller/PatchesController.java
@@ -143,7 +143,7 @@ @RequestParam String patchesId, @RequestParam double lat, @RequestParam double lon, @RequestParam String isTemp, @RequestParam(defaultValue = "1",required = false) String isTemp, HttpServletRequest request) throws IOException { CustomClaim customClaim = (CustomClaim) request.getAttribute(TOKEN_CLAIM); String creator = customClaim.getUsername(); @@ -165,7 +165,7 @@ @GetMapping("/useMyTask") public ResponseResult useMyTask() throws Exception { try { TimerUtil.mytask10(); // TimerUtil.mytask10(); // timerUtil.myTask2(); // timerUtil.myTask3(); // timerUtil.mytask4(); src/main/java/com/dji/sample/patches/utils/TimerUtil.java
@@ -142,100 +142,100 @@ // waylineJobService.publishOneFlightTask(waylineJobDTO.get()); // } // } @Scheduled(cron = "0 0 1 * * ?") public void mytask4() throws IOException { Long time = getCurrentTimestampPlus8Hours(8); List<List<Long>> listOfLists = new ArrayList<>(); List<Long> sublist = new ArrayList<>(); sublist.add(time); // 添加整数值 listOfLists.add(sublist); List<Long> lists1 = new ArrayList<>(); lists1.add(time); String times = convertTimestampToFormattedString(time); sendPostWithParameters("别墅巡查一段", "2a44748a-1500-406f-80cf-ad92186fe8d2", times, lists1, listOfLists); } @Scheduled(cron = "0 50 0 * * ?") public void mytask5() throws IOException { Long time = getCurrentTimestampPlus8Hours(9); List<List<Long>> listOfLists = new ArrayList<>(); List<Long> sublist = new ArrayList<>(); sublist.add(time); // 添加整数值 listOfLists.add(sublist); List<Long> lists1 = new ArrayList<>(); lists1.add(time); String times = convertTimestampToFormattedString(time); sendPostWithParameters("别墅巡查二段", "a07229af-471a-4058-9da6-5a2b84308b9e", times, lists1, listOfLists); } @Scheduled(cron = "0 40 1 * * ?") public void mytask6() throws IOException { Long time = getCurrentTimestampPlus8Hours(9); List<List<Long>> listOfLists = new ArrayList<>(); List<Long> sublist = new ArrayList<>(); sublist.add(time); // 添加整数值 listOfLists.add(sublist); List<Long> lists1 = new ArrayList<>(); lists1.add(time); String times = convertTimestampToFormattedString(time); sendPostWithParameters("九洲巡河一段", "9f471686-a73a-4e90-8f37-92eed8ed5929", times, lists1, listOfLists); } @Scheduled(cron = "0 40 2 * * ?") public void mytask7() throws IOException { Long time = getCurrentTimestampPlus8Hours(9); List<List<Long>> listOfLists = new ArrayList<>(); List<Long> sublist = new ArrayList<>(); sublist.add(time); // 添加整数值 listOfLists.add(sublist); List<Long> lists1 = new ArrayList<>(); lists1.add(time); String times = convertTimestampToFormattedString(time); sendPostWithParameters("九洲巡河二段", "58cd4261-02d7-4c4e-b876-25a4a2630c18", times, lists1, listOfLists); } @Scheduled(cron = "0 30 2 * * ?") public void mytask8() throws IOException { Long time = getCurrentTimestampPlus8Hours(12); List<List<Long>> listOfLists = new ArrayList<>(); List<Long> sublist = new ArrayList<>(); sublist.add(time); // 添加整数值 listOfLists.add(sublist); List<Long> lists1 = new ArrayList<>(); lists1.add(time); String times = convertTimestampToFormattedString(time); sendPostWithParameters("定时任务2:30", "c3a7b125-bc0b-49d4-96ed-80743200ab80", times, lists1, listOfLists); } @Scheduled(cron = "0 30 2 * * ?") public void mytask9() throws IOException { Long time = getCurrentTimestampPlus8Hours(14); List<List<Long>> listOfLists = new ArrayList<>(); List<Long> sublist = new ArrayList<>(); sublist.add(time); // 添加整数值 listOfLists.add(sublist); List<Long> lists1 = new ArrayList<>(); lists1.add(time); 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; // 跳出内层循环,以免重复删除同一个文件 } } } } } } // @Scheduled(cron = "0 0 1 * * ?") // public void mytask4() throws IOException { // Long time = getCurrentTimestampPlus8Hours(8); // List<List<Long>> listOfLists = new ArrayList<>(); // List<Long> sublist = new ArrayList<>(); // sublist.add(time); // 添加整数值 // listOfLists.add(sublist); // List<Long> lists1 = new ArrayList<>(); // lists1.add(time); // String times = convertTimestampToFormattedString(time); // sendPostWithParameters("别墅巡查一段", "2a44748a-1500-406f-80cf-ad92186fe8d2", times, lists1, listOfLists); // } // // @Scheduled(cron = "0 50 0 * * ?") // public void mytask5() throws IOException { // Long time = getCurrentTimestampPlus8Hours(9); // List<List<Long>> listOfLists = new ArrayList<>(); // List<Long> sublist = new ArrayList<>(); // sublist.add(time); // 添加整数值 // listOfLists.add(sublist); // List<Long> lists1 = new ArrayList<>(); // lists1.add(time); // String times = convertTimestampToFormattedString(time); // sendPostWithParameters("别墅巡查二段", "a07229af-471a-4058-9da6-5a2b84308b9e", times, lists1, listOfLists); // } // // @Scheduled(cron = "0 40 1 * * ?") // public void mytask6() throws IOException { // Long time = getCurrentTimestampPlus8Hours(9); // List<List<Long>> listOfLists = new ArrayList<>(); // List<Long> sublist = new ArrayList<>(); // sublist.add(time); // 添加整数值 // listOfLists.add(sublist); // List<Long> lists1 = new ArrayList<>(); // lists1.add(time); // String times = convertTimestampToFormattedString(time); // sendPostWithParameters("九洲巡河一段", "9f471686-a73a-4e90-8f37-92eed8ed5929", times, lists1, listOfLists); // } // // @Scheduled(cron = "0 40 2 * * ?") // public void mytask7() throws IOException { // Long time = getCurrentTimestampPlus8Hours(9); // List<List<Long>> listOfLists = new ArrayList<>(); // List<Long> sublist = new ArrayList<>(); // sublist.add(time); // 添加整数值 // listOfLists.add(sublist); // List<Long> lists1 = new ArrayList<>(); // lists1.add(time); // String times = convertTimestampToFormattedString(time); // sendPostWithParameters("九洲巡河二段", "58cd4261-02d7-4c4e-b876-25a4a2630c18", times, lists1, listOfLists); // } // // @Scheduled(cron = "0 30 2 * * ?") // public void mytask8() throws IOException { // Long time = getCurrentTimestampPlus8Hours(12); // List<List<Long>> listOfLists = new ArrayList<>(); // List<Long> sublist = new ArrayList<>(); // sublist.add(time); // 添加整数值 // listOfLists.add(sublist); // List<Long> lists1 = new ArrayList<>(); // lists1.add(time); // String times = convertTimestampToFormattedString(time); // sendPostWithParameters("定时任务2:30", "c3a7b125-bc0b-49d4-96ed-80743200ab80", times, lists1, listOfLists); // } // @Scheduled(cron = "0 30 2 * * ?") // public void mytask9() throws IOException { // Long time = getCurrentTimestampPlus8Hours(14); // List<List<Long>> listOfLists = new ArrayList<>(); // List<Long> sublist = new ArrayList<>(); // sublist.add(time); // 添加整数值 // listOfLists.add(sublist); // List<Long> lists1 = new ArrayList<>(); // lists1.add(time); // 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; // 跳出内层循环,以免重复删除同一个文件 // } // } // } // } // } // } /** * 完成对未推送的图斑数据进行整合发送 * src/main/java/com/dji/sample/wayline/controller/WaylineFileController.java
@@ -230,14 +230,14 @@ public ResponseResult importKmzFile(@PathVariable(name = "workspace_id") String workspaceId, HttpServletRequest request, MultipartFile file, @RequestParam(required = false) String patchesId, @RequestParam(defaultValue = "1") String isTemp @RequestParam(defaultValue = "1",required = false) String isTemp ) { if (Objects.isNull(file)) { return ResponseResult.error("未上传文件"); } CustomClaim customClaim = (CustomClaim) request.getAttribute(TOKEN_CLAIM); String creator = customClaim.getUsername(); String back = waylineFileService.importKmzFile(file, workspaceId, creator, patchesId, isTemp); String back = waylineFileService.importKmzFile(file, workspaceId, creator, patchesId,isTemp); if (back != null) { return ResponseResult.error(back); } src/main/java/com/dji/sample/wayline/service/impl/FlightTaskServiceImpl.java
@@ -78,7 +78,7 @@ @ServiceActivator(inputChannel = ChannelName.INBOUND_EVENTS_FLIGHT_TASK_PROGRESS, outputChannel = ChannelName.OUTBOUND_EVENTS) public CommonTopicReceiver handleProgress(CommonTopicReceiver receiver, MessageHeaders headers) { log.info("上报航线任务进度: {}", receiver.toString()); EventsReceiver<WaylineTaskProgressReceiver> eventsReceiver = mapper.convertValue(receiver.getData(), EventsReceiver<WaylineTaskProgressReceiver> eventsReceiver = mapper.convertValue(receiver.getData(), new TypeReference<EventsReceiver<WaylineTaskProgressReceiver>>(){}); eventsReceiver.setBid(receiver.getBid()); eventsReceiver.setSn(receiver.getGateway()); src/main/java/com/dji/sample/wayline/service/impl/WaylineFileServiceImpl.java
@@ -155,7 +155,7 @@ } @Override public Integer saveWaylineFiles(String workspaceId, WaylineFileDTO metadata, String patchesId, String isTemp) { public Integer saveWaylineFiles(String workspaceId, WaylineFileDTO metadata, String patchesId,String isTemp) { metadata.setPatchesId(patchesId); WaylineFileEntity file = this.dtoConvertToEntity(metadata); file.setWaylineId(UUID.randomUUID().toString()); @@ -219,7 +219,7 @@ } @Override public String importKmzFile(MultipartFile file, String workspaceId, String creator, String patchesId, String isTemp) { public String importKmzFile(MultipartFile file, String workspaceId, String creator, String patchesId,String isTemp) { Optional<WaylineFileDTO> waylineFileOpt = validKmzFile(file); if (waylineFileOpt.isEmpty()) { throw new RuntimeException("文件格式错误"); @@ -232,7 +232,7 @@ waylineFile.setIsTemp(isTemp); back = ossService.putObject(OssConfiguration.bucket, waylineFile.getObjectKey(), file.getInputStream()); if (back == null) { this.saveWaylineFiles(workspaceId, waylineFile, patchesId, isTemp); this.saveWaylineFiles(workspaceId, waylineFile, patchesId,isTemp); } } catch (IOException e) { e.printStackTrace(); src/main/resources/application-dev.yml
@@ -85,15 +85,15 @@ oss: enable: true provider: minio endpoint: http://139.196.74.78:9000 external-endpoint: http://139.196.74.78:9000 access-key: sxkj secret-key: sxkj2024 endpoint: http://dev.jxpskj.com:9000 external-endpoint: http://dev.jxpskj.com:9000 access-key: pskj secret-key: pskj@2021 bucket: cloud-bucket expire: 3600 region: us-east-1 object-dir-prefix: out-net-file-address: https://wrj.shuixiongit.com/minio out-net-file-address: https://dev.jxpskj.com:8026 #图斑的解压地址和图斑文件转航线文件的地址 patches: