From 7cfa09050726578c2cc5114e5bc8a419e6e2e466 Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期二, 15 十月 2024 11:03:45 +0800
Subject: [PATCH] 人脸上传数据延迟修复
---
ycl-server/src/main/java/com/ycl/platform/service/impl/WorkOrderServiceImpl.java | 140 ++++++++++++++++++++++++----------------------
1 files changed, 72 insertions(+), 68 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 a1bbc45..0438581 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
@@ -56,7 +56,10 @@
import org.springframework.util.CollectionUtils;
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;
import java.net.HttpURLConnection;
import java.net.URL;
@@ -237,9 +240,6 @@
notAddList.add(workOrder);
continue;
}
- //鏁板瓧鍓嶉潰琛�0
- workOrderNum++;
- workOrder.setWorkOrderNo(IdUtils.workOrderNO(now, String.format("%05d", workOrderNum)));
if (Objects.nonNull(point.getUnitId())) {
workOrder.setUnitId(Math.toIntExact(point.getUnitId()));
}
@@ -262,7 +262,12 @@
if (CollectionUtils.isEmpty(waitAddList)) {
return Boolean.TRUE;
}
- //璁板綍宸ュ崟鏁�
+ //璁板綍宸ュ崟鏁�,琛ュ厖宸ュ崟鍙�
+ for (WorkOrder workOrder : waitAddList) {
+ //鏁板瓧鍓嶉潰琛�0
+ workOrderNum++;
+ workOrder.setWorkOrderNo(IdUtils.workOrderNO(now, String.format("%05d", workOrderNum)));
+ }
redisCache.setCacheObject(RedisConstant.WORKORDER_NUM, workOrderNum);
redisCache.releaseLock(RedisConstant.WORKORDER_NUM_LOCK, requestId);
// 淇濆瓨宸ュ崟鍜屾晠闅滅被鍨�
@@ -760,77 +765,76 @@
@Override
- public synchronized String getFrameImgByDevice(String deviceId, String channelId, String workOrderNo) {
- String url = String.format(this.rtspServer + "/api/play/start/%s/%s", deviceId, channelId);
+ public synchronized String getFrameImgByDevice(String deviceId, String channelId, String workOrderNo) throws Exception {
+ String url = String.format(this.rtspServer + "/api/play/start/img/%s/%s", deviceId, channelId);
String result = HttpUtils.sendGet(url);
- log.error("鎷垮埌鍙栨祦鍝嶅簲缁撴灉锛�" + result);
+ log.info("鎷垮埌鍙栨祦鍥剧墖鍝嶅簲缁撴灉锛�" + result);
WVPResult wvpResult = JSON.parseObject(result, WVPResult.class);
- String imgUrl = null;
- if (0 == wvpResult.getCode()) {
- log.error("璇锋眰鎴愬姛");
- JSONObject data = (JSONObject) wvpResult.getData();
- String rtspUrl = data.getString("rtsp"); // 鍙栧湴鍧�
- log.error("鐩爣鍦板潃锛�" + rtspUrl);
- if (StringUtils.hasText(rtspUrl)) {
- try {
- 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);
-
- OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat();
- int ex = 0;
- while (true) {
- if (ex > 1) {
- break;
- }
- Frame frame = grabber.grabImage();
- canvasFrame.showImage(frame);
- //绋嬪簭鍒拌繖閲屽叾瀹炲凡缁忓疄鐜颁簡棰勮鐨勫姛鑳戒簡锛屼笅闈㈢殑鏂规硶灏辨槸灏嗘祦淇濆瓨鎴愬浘鐗�
-
- //opencv_core.Mat
- Mat mat = converter.convertToMat(frame);
-
- imgUrl = workOrderNo + "_" + IdUtils.fastSimpleUUID() + ".png";
- // 鐢熸垚鍥剧墖璺緞
- String imgPath = PlatformConfig.getProfile() + "/" + imgUrl;
- System.out.println("鍥剧墖淇濆瓨鍦板潃锛�" + imgPath);
- imgUrl = Constants.RESOURCE_PREFIX + "/" + imgUrl;
-
- opencv_imgcodecs.imwrite(imgPath, mat);
-
- ex++;
- try {
- Thread.sleep(1000);
- }
- catch (InterruptedException e)
- {
- e.printStackTrace();
- } // 1000姣鍒锋柊涓�娆″湒鍍�
- }
- grabber.stop(); // 鍋滄鎹曡幏
- grabber.release(); // 閲婃斁璧勬簮
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
+ if(wvpResult.getCode() == 0) {
+ Object imgUrl = (Object) wvpResult.getData();
+ imgUrl = Objects.isNull(imgUrl) ? "" : imgUrl;
+ log.info("鎷垮埌鍙栨祦鍥剧墖锛�" + imgUrl);
+ return (String) imgUrl;
}
- return imgUrl;
+ return null;
+// WVPResult wvpResult = JSON.parseObject(result, WVPResult.class);
+// String imgUrl = null;
+// if (wvpResult.getCode() == 0) {
+// JSONObject data = (JSONObject) wvpResult.getData();
+// String rtspUrl = data.getString("fmp4"); // 鍙杕p4鍦板潃
+// if (StringUtils.hasText(rtspUrl)) {
+// System.out.println("鐩爣鍦板潃锛�" + rtspUrl);
+// FFmpegFrameGrabber grabber = null;
+// try {
+// grabber = new FFmpegFrameGrabber(rtspUrl);
+//// grabber.setOption("rtsp_transport", "tcp"); // 浣跨敤tcp鐨勬柟寮忥紝涓嶇劧浼氫涪鍖呭緢涓ラ噸
+//// grabber.setVideoOption("probesize", "10000"); // 璁剧疆鎹曡幏鍒嗘瀽鐨勬渶澶у瓧鑺�
+// grabber.start();
+// Frame frame = grabber.grabImage(); // 鐩存帴鎹曡幏涓�甯�
+// if (frame != null) {
+// System.out.println("鎴愬姛鎹曡幏涓�甯�");
+// // 灏咶rame杞崲涓篗at
+// OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat();
+// Mat mat = converter.convertToMat(frame);
+//
+// imgUrl = workOrderNo + "_" + IdUtils.fastSimpleUUID() + ".png";
+// // 鐢熸垚鍥剧墖璺緞
+// String imgPath = PlatformConfig.getProfile() + "/" + imgUrl;
+// System.out.println("鍥剧墖淇濆瓨鍦板潃锛�" + imgPath);
+// imgUrl = Constants.RESOURCE_PREFIX + "/" + imgUrl;
+// // 淇濆瓨鍥剧墖
+// opencv_imgcodecs.imwrite(imgPath, mat);
+// } else {
+// System.out.println("鏈崟鑾峰埌甯�");
+// }
+// } catch (FrameGrabber.Exception e) {
+// e.printStackTrace();
+// } finally {
+// if (grabber != null) {
+// try {
+// grabber.stop(); // 鍋滄鎹曡幏
+// } catch (FrameGrabber.Exception e) {
+// e.printStackTrace();
+// }
+// }
+// }
+// }
+// } else {
+// System.out.println("璇锋眰澶辫触锛岄敊璇爜锛�" + wvpResult.getCode() + "--" + wvpResult.getMsg());
+// }
+// System.out.println("鍥剧墖URL锛�" + imgUrl);
+// return imgUrl;
}
@Override
- public void saveFrameImgByDevice(String deviceId, String channelId, String workOrderNo) {
+ public void saveFrameImgByDevice (String deviceId, String channelId, String workOrderNo){
String url = String.format(this.rtspServer + "/api/play/start/%s/%s", deviceId, channelId);
String result = HttpUtils.sendGet(url);
WVPResult wvpResult = JSON.parseObject(result, WVPResult.class);
String imgUrl = null;
if (wvpResult.getCode() == 0) {
JSONObject data = (JSONObject) wvpResult.getData();
- String rtspUrl = data.getString("fmp4"); // 鍙杕p4鍦板潃
+ String rtspUrl = data.getString("rtsp"); // 鍙杕p4鍦板潃
if (StringUtils.hasText(rtspUrl)) {
System.out.println("鐩爣鍦板潃锛�" + rtspUrl);
FFmpegFrameGrabber grabber = null;
@@ -884,13 +888,13 @@
}
@Override
- public List<DeviceInfoVO> hasErrorWorkOrderList(Date start, Date end) {
+ public List<DeviceInfoVO> hasErrorWorkOrderList (Date start, Date end){
List<DeviceInfoVO> list = baseMapper.hasErrorWorkOrderList(start, end);
return list;
}
@Override
- public void updateImgById(Integer workOrderId, String imgPath) {
+ public void updateImgById (Integer workOrderId, String imgPath){
new LambdaUpdateChainWrapper<>(baseMapper)
.eq(WorkOrder::getId, workOrderId)
.set(WorkOrder::getYwCheckResult, imgPath)
@@ -898,7 +902,7 @@
}
@Override
- public Result processImg(String workOrderNo) {
+ public Result processImg (String workOrderNo){
WorkOrder workOrder = new LambdaQueryChainWrapper<>(baseMapper)
.eq(WorkOrder::getWorkOrderNo, workOrderNo)
.one();
@@ -939,7 +943,7 @@
}
@Override
- public Result detailByNo(String workOrderNo) {
+ public Result detailByNo (String workOrderNo){
WorkOrderDetailVO workOrder = baseMapper.detailByNo(workOrderNo);
// 鏄惁鎶ュ
boolean hasReport = new LambdaQueryChainWrapper<>(reportMapper)
@@ -961,7 +965,7 @@
}
@Override
- public List<WorkOrderVO> export(WorkOrderExportQuery query) {
+ public List<WorkOrderVO> export (WorkOrderExportQuery query){
query.setUnitId(SecurityUtils.getUnitId());
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if (query.getStart() == null) {
--
Gitblit v1.8.0