From f47ca83956575f49572a6f20166d98b7ca7af2fb Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期三, 28 八月 2024 17:55:03 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 ycl-server/src/main/java/com/ycl/platform/service/impl/WorkOrderServiceImpl.java |   92 ++++++++++++++++++++++++++++++---------------
 1 files changed, 61 insertions(+), 31 deletions(-)

diff --git a/ycl-server/src/main/java/com/ycl/platform/service/impl/WorkOrderServiceImpl.java b/ycl-server/src/main/java/com/ycl/platform/service/impl/WorkOrderServiceImpl.java
index 00718ae..d944fb8 100644
--- a/ycl-server/src/main/java/com/ycl/platform/service/impl/WorkOrderServiceImpl.java
+++ b/ycl-server/src/main/java/com/ycl/platform/service/impl/WorkOrderServiceImpl.java
@@ -44,9 +44,9 @@
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
-import org.bytedeco.javacv.FFmpegFrameGrabber;
-import org.bytedeco.javacv.Frame;
-import org.bytedeco.javacv.Java2DFrameConverter;
+import org.bytedeco.javacv.*;
+import org.bytedeco.opencv.global.opencv_imgcodecs;
+import org.bytedeco.opencv.opencv_core.Mat;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -57,6 +57,7 @@
 import org.springframework.util.StringUtils;
 
 import javax.imageio.ImageIO;
+import javax.swing.*;
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
@@ -157,6 +158,7 @@
                     ywRecord.setCommitUser(1);
                     ywRecord.setYwCondition("鏁呴殰绫诲瀷鏇存柊锛屽伐鍗曠姸鎬佽皟鏁翠负寰呭鐞�");
                     ywRecord.setCreateTime(new Date());
+                    ywRecord.setSysMsg(Boolean.TRUE);
                     willAddMsg.add(ywRecord);
                 }
             } else {
@@ -300,7 +302,7 @@
         baseMapper.updateById(workOrder);
         // 娣诲姞涓�鏉″鏍歌褰�
         WorkOrderAuditingRecord workOrderAuditingRecord = new WorkOrderAuditingRecord();
-        workOrderAuditingRecord.setWorkOrderId(workOrder.getId());
+        workOrderAuditingRecord.setWorkOrderNo(workOrder.getWorkOrderNo());
         workOrderAuditingRecord.setAuditingUser(SecurityUtils.getLoginUser().getUserId().intValue());
         workOrderAuditingRecord.setResult(form.getAuditingResult().getDesc());
         workOrderAuditingRecord.setRemark(form.getAuditingRemark());
@@ -314,7 +316,7 @@
         notifyService.save(notify);
         // 鍚屾鐐逛綅鐘舵��
         if (form.getAuditingResult() == WorkOrderStatusEnum.AUDITING_SUCCESS) {
-            ywPointService.updateRecovery(Arrays.asList(workOrder.getSerialNumber()), 0);
+            ywPointService.updateRecovery(Collections.singletonList(workOrder.getSerialNumber()), 0);
         }
         return Result.ok("鎿嶄綔鎴愬姛");
     }
@@ -326,22 +328,23 @@
         List<WorkOrder> list = new LambdaQueryChainWrapper<>(baseMapper)
                 .in(WorkOrder::getStatus, WorkOrderStatusEnum.YW_HANDLE.getValue())
                 .in(WorkOrder::getErrorType, form.getErrorTypes())
-                .select(WorkOrder::getId, WorkOrder::getUnitId, WorkOrder::getWorkOrderNo)
+                .select(WorkOrder::getId, WorkOrder::getUnitId, WorkOrder::getWorkOrderNo, WorkOrder::getSerialNumber)
                 .list();
         if (list.isEmpty()) {
             return Result.error("娌℃湁宸ュ崟鍙互瀹℃牳");
         }
-        List<Integer> ids = list.stream().map(WorkOrder::getId).collect(Collectors.toList());
+        List<String> workOrderNoList = list.stream().map(WorkOrder::getWorkOrderNo).collect(Collectors.toList());
+        List<String> serialNumbers = list.stream().map(WorkOrder::getSerialNumber).toList();
         // 宸ュ崟鐘舵��
         LambdaUpdateWrapper<WorkOrder> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
-        lambdaUpdateWrapper.in(WorkOrder::getId, ids);
+        lambdaUpdateWrapper.in(WorkOrder::getWorkOrderNo, workOrderNoList);
         lambdaUpdateWrapper.set(WorkOrder::getStatus, form.getAuditingResult());
         baseMapper.update(lambdaUpdateWrapper);
         // 娣诲姞澶氭潯瀹℃牳璁板綍
         List<WorkOrderAuditingRecord> workOrderAuditingRecords = new ArrayList<>();
-        for (Integer id : ids) {
+        for (String workOrderNo : workOrderNoList) {
             WorkOrderAuditingRecord workOrderAuditingRecord = new WorkOrderAuditingRecord();
-            workOrderAuditingRecord.setWorkOrderId(id);
+            workOrderAuditingRecord.setWorkOrderNo(workOrderNo);
             workOrderAuditingRecord.setAuditingUser(SecurityUtils.getLoginUser().getUserId().intValue());
             workOrderAuditingRecord.setResult(form.getAuditingResult().getDesc());
             workOrderAuditingRecord.setRemark(form.getAuditingRemark());
@@ -357,6 +360,10 @@
                     UrgentLevelEnum.WARNING,
                     workOrder.getWorkOrderNo());
             notifies.add(notify);
+        }
+        // 鍚屾鐐逛綅鐘舵��
+        if (form.getAuditingResult() == WorkOrderStatusEnum.AUDITING_SUCCESS) {
+            ywPointService.updateRecovery(serialNumbers, 0);
         }
         notifyService.saveBatch(notifies);
         return Result.ok("鎿嶄綔鎴愬姛");
@@ -385,8 +392,8 @@
     }
 
     @Override
-    public Result selectYwConditionByYwId(Integer id) {
-        List<WorkOrderYwConditionRecordVO> ywConditionList = workOrderYwConditionRecordMapper.selectYwConditionByYwId(id);
+    public Result selectYwConditionByYwId(String workOrderNo) {
+        List<WorkOrderYwConditionRecordVO> ywConditionList = workOrderYwConditionRecordMapper.selectYwConditionByYwId(workOrderNo);
         ywConditionList.stream().forEach(item -> {
             if (Objects.nonNull(item.getSysMsg()) && item.getSysMsg()) {
                 item.setCommitUserName("绯荤粺娑堟伅");
@@ -396,10 +403,10 @@
     }
 
     @Override
-    public Result selectYwAuditingListByYwId(String id) {
+    public Result selectYwAuditingListByYwId(String workOrderNo) {
         return Result.ok().data(
                 new LambdaQueryChainWrapper<>(workOrderAuditingRecordMapper)
-                        .eq(WorkOrderAuditingRecord::getWorkOrderId, id)
+                        .eq(WorkOrderAuditingRecord::getWorkOrderNo, workOrderNo)
                         .orderByAsc(WorkOrderAuditingRecord::getCreateTime)
                         .list());
     }
@@ -489,7 +496,7 @@
 
         // 鏌ヨ绗﹀悎鏉′欢鐨勫伐鍗�
         List<WorkOrder> list = new LambdaQueryChainWrapper<>(baseMapper)
-                .select(WorkOrder::getSerialNumber, WorkOrder::getSerialNumber)
+                .select(WorkOrder::getSerialNumber, WorkOrder::getWorkOrderNo)
                 .eq(WorkOrder::getStatus, WorkOrderStatusEnum.WAIT_DISTRIBUTE)
                 .eq(Objects.nonNull(data.getUnitId()), WorkOrder::getUnitId, data.getUnitId())
                 .eq(WorkOrder::getErrorType, data.getErrorType())
@@ -528,7 +535,7 @@
                 query.setWorkOrderNOList(new LambdaQueryChainWrapper<>(baseMapper)
                         .eq(WorkOrder::getStatus, WorkOrderStatusEnum.WAIT_DISTRIBUTE)
                         .eq(Objects.nonNull(query.getUnitId()), WorkOrder::getUnitId, query.getUnitId())
-                        .select(WorkOrder::getId)
+                        .select(WorkOrder::getWorkOrderNo)
                         .list()
                         .stream()
                         .map(WorkOrder::getWorkOrderNo)
@@ -542,7 +549,7 @@
                     .update();
             addDistributeRecord(query.getWorkOrderNOList(), distributeWayEnum);
             // 鍚屾鐐逛綅鐘舵��
-            List<String> serialNumberList = new LambdaQueryChainWrapper<>(baseMapper).select(WorkOrder::getSerialNumber).in(WorkOrder::getId, query.getWorkOrderNOList()).list().stream().map(WorkOrder::getSerialNumber).toList();
+            List<String> serialNumberList = new LambdaQueryChainWrapper<>(baseMapper).select(WorkOrder::getSerialNumber).in(WorkOrder::getWorkOrderNo, query.getWorkOrderNOList()).list().stream().map(WorkOrder::getSerialNumber).toList();
             ywPointService.updateRecovery(serialNumberList, 1);
             return Result.ok("鎴愬姛涓嬪彂" + query.getWorkOrderNOList().size() + "鏉″伐鍗�");
         } catch (Exception e) {
@@ -656,31 +663,54 @@
 
     @Override
     public String getFrameImgByDevice(String deviceId, String channelId) {
-        String url = String.format(this.rtspServer + "/start/%s/%s", deviceId, channelId);
+        String url = String.format(this.rtspServer + "/api/play/start/%s/%s", deviceId, channelId);
         String result = HttpUtils.sendGet(url);
+        log.error("鎷垮埌鍙栨祦鍝嶅簲缁撴灉锛�" + result);
         WVPResult wvpResult = JSON.parseObject(result, WVPResult.class);
         if (0 == wvpResult.getCode()) {
+            log.error("璇锋眰鎴愬姛");
             StreamContent data = (StreamContent) wvpResult.getData();
             String rtspUrl = data.getRtsp();
+            log.error("鐩爣鍦板潃锛�" + rtspUrl);
             if (StringUtils.hasText(rtspUrl)) {
                 try {
-                    // 鍒涘缓FFmpegFrameGrabber瀵硅薄
-                    FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(rtspUrl);
-                    grabber.start(); // 寮�濮嬫崟鑾�
+                    FFmpegFrameGrabber grabber = FFmpegFrameGrabber.createDefault(rtspUrl);
+                    grabber.setOption("rtsp_transport", "tcp"); // 浣跨敤tcp鐨勬柟寮忥紝涓嶇劧浼氫涪鍖呭緢涓ラ噸
+                    grabber.setImageWidth(960);
+                    grabber.setImageHeight(540);
+                    grabber.start();
+                    CanvasFrame canvasFrame = new CanvasFrame("姝h寕");// 鍒涘缓绐楀彛
+                    canvasFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 璁剧疆绐楀彛鍏抽棴绋嬪簭鏄惁涔熻窡闅忓叧闂�
+                    canvasFrame.setAlwaysOnTop(true);
 
-                    Frame frame;
-                    if ((frame = grabber.grabFrame()) != null) {
-                        // 灏嗗抚杞崲涓哄浘鐗�
-                        Java2DFrameConverter converter = new Java2DFrameConverter();
-                        BufferedImage image = converter.convert(frame);
-                        File outputfile = new File(serverConfig.getUrl() + PlatformConfig.getUploadPath() + deviceId + IdUtils.fastSimpleUUID() + ".png");
-                        ImageIO.write(image, "png", outputfile);
-                        String imgPath = outputfile.getAbsolutePath();
-                        System.out.println("Saved " + imgPath);
-                        return imgPath;
+                    OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat();
+                    int ex = 0;
+                    String imgPath = null;
+                    while (true) {
+                        if (ex > 1) {
+                            break;
+                        }
+                        Frame frame = grabber.grabImage();
+                        canvasFrame.showImage(frame);
+                        //绋嬪簭鍒拌繖閲屽叾瀹炲凡缁忓疄鐜颁簡棰勮鐨勫姛鑳戒簡锛屼笅闈㈢殑鏂规硶灏辨槸灏嗘祦淇濆瓨鎴愬浘鐗�
+
+                        //opencv_core.Mat
+                        Mat mat = converter.convertToMat(frame);
+                        imgPath = serverConfig.getUrl() + PlatformConfig.getUploadPath() + deviceId + IdUtils.fastSimpleUUID() + ".png";
+                        opencv_imgcodecs.imwrite(imgPath, mat);
+
+                        ex++;
+                        try {
+                            Thread.sleep(1000);
+                        }
+                        catch (InterruptedException e)
+                        {
+                            e.printStackTrace();
+                        } // 1000姣鍒锋柊涓�娆″湒鍍�
                     }
                     grabber.stop(); // 鍋滄鎹曡幏
                     grabber.release(); // 閲婃斁璧勬簮
+                    return imgPath;
                 } catch (IOException e) {
                     e.printStackTrace();
                 }

--
Gitblit v1.8.0