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 | 135 +++++++++++++++++++++++++-------------------
1 files changed, 76 insertions(+), 59 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 b9edc3a..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,6 +56,11 @@
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;
import java.net.URLDecoder;
@@ -235,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()));
}
@@ -260,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);
// 淇濆瓨宸ュ崟鍜屾晠闅滅被鍨�
@@ -298,14 +305,14 @@
@Override
public Result add(WorkOrderForm form) {
//鏌edis浠婃棩宸ュ崟鏁伴噺
- int workOrderNum = 1;
+ int workOrderNum = 0;
//UUID浣滀负value锛屼繚璇佷笂閿佺殑绾跨▼鑷繁瑙i攣
String requestId = IdUtils.fastSimpleUUID();
boolean result = redisCache.acquireLock(RedisConstant.WORKORDER_NUM_LOCK, requestId, 10000);
if (result) {
//鏌ヤ粖鏃ュ伐鍗曢噺
Object redisNum = redisCache.getCacheObject(RedisConstant.WORKORDER_NUM);
- workOrderNum = redisNum == null ? 1 : (Integer) redisNum;
+ workOrderNum = redisNum == null ? 0 : (Integer) redisNum;
workOrderNum++;
redisCache.setCacheObject(RedisConstant.WORKORDER_NUM, workOrderNum);
redisCache.releaseLock(RedisConstant.WORKORDER_NUM_LOCK, requestId);
@@ -758,66 +765,76 @@
@Override
- public 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.info("鎷垮埌鍙栨祦鍥剧墖鍝嶅簲缁撴灉锛�" + result);
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 = FFmpegFrameGrabber.createDefault(rtspUrl);
- 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 (Exception e) {
- e.printStackTrace();
- } finally {
- if (grabber != null) {
- try {
- grabber.stop(); // 鍋滄鎹曡幏
- grabber.release();
- } catch (FrameGrabber.Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
- } else {
- System.out.println("璇锋眰澶辫触锛岄敊璇爜锛�" + wvpResult.getCode());
+ if(wvpResult.getCode() == 0) {
+ Object imgUrl = (Object) wvpResult.getData();
+ imgUrl = Objects.isNull(imgUrl) ? "" : imgUrl;
+ log.info("鎷垮埌鍙栨祦鍥剧墖锛�" + imgUrl);
+ return (String) imgUrl;
}
- System.out.println("鍥剧墖URL锛�" + 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;
@@ -871,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)
@@ -885,7 +902,7 @@
}
@Override
- public Result processImg(String workOrderNo) {
+ public Result processImg (String workOrderNo){
WorkOrder workOrder = new LambdaQueryChainWrapper<>(baseMapper)
.eq(WorkOrder::getWorkOrderNo, workOrderNo)
.one();
@@ -926,7 +943,7 @@
}
@Override
- public Result detailByNo(String workOrderNo) {
+ public Result detailByNo (String workOrderNo){
WorkOrderDetailVO workOrder = baseMapper.detailByNo(workOrderNo);
// 鏄惁鎶ュ
boolean hasReport = new LambdaQueryChainWrapper<>(reportMapper)
@@ -948,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