From aae8b5dc994fffdc211b1f0fc860840cb0d4687a Mon Sep 17 00:00:00 2001
From: zhaowenyu <35589726@qq.com>
Date: Tue, 25 Nov 2025 14:34:02 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev

---
 ard-work/src/main/java/com/ard/work/service/impl/ArdFlightTaskServiceServiceImpl.java |  122 +++++++++++++++++++---------------------
 1 files changed, 57 insertions(+), 65 deletions(-)

diff --git a/ard-work/src/main/java/com/ard/work/service/impl/ArdFlightTaskServiceServiceImpl.java b/ard-work/src/main/java/com/ard/work/service/impl/ArdFlightTaskServiceServiceImpl.java
index cb0a57b..1627d98 100644
--- a/ard-work/src/main/java/com/ard/work/service/impl/ArdFlightTaskServiceServiceImpl.java
+++ b/ard-work/src/main/java/com/ard/work/service/impl/ArdFlightTaskServiceServiceImpl.java
@@ -1,5 +1,8 @@
 package com.ard.work.service.impl;
 
+import com.ard.common.constant.CacheConstants;
+import com.ard.common.core.domain.entity.SysUser;
+import com.ard.common.core.redis.RedisCache;
 import com.ard.common.utils.DateUtils;
 import com.ard.common.utils.file.MimeTypeUtils;
 import com.ard.common.utils.uuid.IdUtils;
@@ -16,8 +19,10 @@
 import com.ard.work.mapper.ArdMediaMapper;
 import com.ard.work.service.IArdFlightTaskService;
 import com.ard.work.service.IArdServerInfoService;
+import com.ard.work.service.control.UavControlService;
 import com.ard.work.util.osSelect;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Service;
@@ -57,7 +62,10 @@
     private OssServiceContext ossServiceContext;
     @Resource
     private ThreadPoolTaskExecutor threadPoolTaskExecutor;  // 使用线程池执行异步任务
-
+    @Resource
+    private UavControlService uavControlService;
+    @Autowired
+    private RedisCache redisCache;
     /**
      * 查询飞行架次列表
      *
@@ -128,6 +136,14 @@
                     .startTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, boxHistoryReceiver.getStartTime()))
                     .endTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, boxHistoryReceiver.getEndTime()))
                     .build();
+
+            Long flyUserId = uavControlService.getCurrentController(flightTask.getBoxSn(), "fly");
+            if (flyUserId != null) {
+                SysUser flyUser = redisCache.getCacheObject(CacheConstants.SYS_USER_KEY + flyUserId);
+                if (flyUser != null && flyUser.getNickName() != null) {
+                    flightTask.setCreateBy(flyUser.getNickName());
+                }
+            }
             flightTask.setCreateTime(DateUtils.getNowDate());
             // 插入新记录
             int rows = ardFlightTaskMapper.insertArdFlightTask(flightTask);
@@ -144,12 +160,46 @@
         } else {
             // 如果存在,则更新记录
             log.debug("Updating task {}", boxHistoryReceiver.getTaskId());
+            updateFlightTask(ardFlightTask, boxHistoryReceiver);
             // 增量更新
             updateVideoToDatabase(ardFlightTask, boxHistoryReceiver.getVideoPathList());
             // 增量更新图片
             updatePhotoToDatabase(ardFlightTask, serverId, boxHistoryReceiver.getBoxSn());
 
         }
+    }
+    private void updateFlightTask(ArdFlightTask local, BoxHistoryReceiver remote) {
+
+        boolean needUpdate = false;
+
+        // endTime 更新(重要!!!)
+        Date newEnd = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, remote.getEndTime());
+        if (newEnd != null && (local.getEndTime() == null || !local.getEndTime().equals(newEnd))) {
+            local.setEndTime(newEnd);
+            needUpdate = true;
+        }
+
+        // photoCount 更新
+        int remotePhotoCount = Integer.parseInt(remote.getPhotoCount());
+        if (local.getPhotoCount() != remotePhotoCount) {
+            local.setPhotoCount(remotePhotoCount);
+            needUpdate = true;
+        }
+
+        // videoCount 更新
+        int remoteVideoCount = remote.getVideoPathList() != null ? remote.getVideoPathList().size() : 0;
+        if (local.getVideoCount() != remoteVideoCount) {
+            local.setVideoCount(remoteVideoCount);
+            needUpdate = true;
+        }
+
+        if (needUpdate) {
+            ardFlightTaskMapper.updateArdFlightTask(local);
+        }
+
+        // 其它媒体增量更新
+        updateVideoToDatabase(local, remote.getVideoPathList());
+        updatePhotoToDatabase(local, local.getServerId(), remote.getBoxSn());
     }
 
 
@@ -415,70 +465,6 @@
     }
 
     // 生成视频缩略图
-    public ByteArrayInputStream generateThumbnail1(String videoFile, int skipFrames, int targetWidth) {
-//        long start = System.currentTimeMillis();
-//        FFmpegFrameGrabber grabber = null;
-//
-//        try {
-//            grabber = new FFmpegFrameGrabber(videoFile);
-//            grabber.start();
-//
-//            int totalFrames = grabber.getLengthInFrames();
-//            System.out.println("视频总帧数: " + totalFrames);
-//            System.out.println("视频时长: " + grabber.getLengthInTime() / 1000000 + "秒");
-//
-//            Frame frame = null;
-//            int currentFrame = 0;
-//
-//            // 读取指定帧数后的第一帧有效图像
-//            while (currentFrame < totalFrames) {
-//                frame = grabber.grabImage();
-//                if (frame == null) {
-//                    break;
-//                }
-//
-//                if (currentFrame > skipFrames && frame.image != null) {
-//                    break;
-//                }
-//                currentFrame++;
-//            }
-//
-//            if (frame == null || frame.image == null) {
-//                throw new Exception("无法获取有效视频帧");
-//            }
-//
-//            // 转换 Frame 为 BufferedImage
-//            Java2DFrameConverter converter = new Java2DFrameConverter();
-//            BufferedImage image = converter.getBufferedImage(frame);
-//
-//            // 按目标宽度等比缩放
-//            int targetHeight = (int) ((double) targetWidth / image.getWidth() * image.getHeight());
-//            BufferedImage scaledImage = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_3BYTE_BGR);
-//            scaledImage.getGraphics().drawImage(image, 0, 0, targetWidth, targetHeight, null);
-//
-//            // 转成 ByteArrayInputStream
-//            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-//            ImageIO.write(scaledImage, "jpg", baos);
-//            long cost = System.currentTimeMillis() - start;
-//            System.out.println("处理耗时: " + cost + "ms");
-//
-//            return new ByteArrayInputStream(baos.toByteArray());
-//
-//        } catch (Exception e) {
-//            throw new RuntimeException(e);
-//        } finally {
-//            if (grabber != null) {
-//                try {
-//                    grabber.stop();
-//                    grabber.close();
-//                } catch (Exception e) {
-//                    e.printStackTrace();
-//                }
-//            }
-//        }
-        return null;
-    }
-
     public ByteArrayInputStream generateThumbnail(
             String videoFile,
             int skipSeconds,
@@ -492,6 +478,12 @@
         try {
             List<String> command = new ArrayList<>();
             command.add(ffmpegPath);
+
+            command.add("-timeout");
+            command.add("3000000");
+            command.add("-rw_timeout");
+            command.add("3000000");
+
             command.add("-ss");
             command.add(String.format("00:00:%02d", skipSeconds));
             command.add("-i");

--
Gitblit v1.9.3