From aa12f448f4aea5202e2f935057f534cdee933ab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LAPTOP-S9HJSOEB=5C=E6=98=8A=E5=A4=A9?= Date: Tue, 10 Dec 2024 19:48:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/config/ConfigProperties.java | 3 + .../com/zhehekeji/web/service/PlcService.java | 70 ++++++++++++++++--- web/src/main/resources/application-prod.yml | 4 ++ 3 files changed, 66 insertions(+), 11 deletions(-) diff --git a/web/src/main/java/com/zhehekeji/web/config/ConfigProperties.java b/web/src/main/java/com/zhehekeji/web/config/ConfigProperties.java index 96ca79f..32ec262 100644 --- a/web/src/main/java/com/zhehekeji/web/config/ConfigProperties.java +++ b/web/src/main/java/com/zhehekeji/web/config/ConfigProperties.java @@ -66,6 +66,9 @@ public class ConfigProperties { private Long B2OutDelayTime; private Long delayDownloadMp4; + private Double IdentificationProbability=0.9; + private int maximumRecognitionTime=9000; + public Long verticalAdjustmentTime = 2L; } diff --git a/web/src/main/java/com/zhehekeji/web/service/PlcService.java b/web/src/main/java/com/zhehekeji/web/service/PlcService.java index 163393f..fea6aaf 100644 --- a/web/src/main/java/com/zhehekeji/web/service/PlcService.java +++ b/web/src/main/java/com/zhehekeji/web/service/PlcService.java @@ -41,10 +41,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.time.Duration; import java.time.LocalDateTime; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingDeque; import java.util.concurrent.ThreadPoolExecutor; @@ -665,14 +662,19 @@ public class PlcService { } catch (InterruptedException e) { throw new RuntimeException(e); } - - - - String path = PathUtil.createFileNameByRowColumn("jpg",cameraIdQt,plcCmdInfo.getRow1(),plcCmdInfo.getColumn1()); //拍照识别一维码后,保存图片 - String code = blinkGetCode(cameraIdQt,path); - + //String code = blinkGetCode(cameraIdQt,path); + cameraCapture(cameraIdQt,false,null,path); + String code = wmsCode; + if (!simulateQRCodeScan( configProperties.getCameraConfig().getIdentificationProbability())){ + code = ""; + } + try { + Thread.sleep(generateRandomNumber(5000,configProperties.getCameraConfig().getMaximumRecognitionTime())); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } OrderInfo orderInfo = new OrderInfo(street,plcCmdInfo,1,cmdCode); Stock stock = stockMapper.getByStreetAndDirectionAndSideAndRowColumn(orderInfo.getStreetId(),orderInfo.getLeftRight(),orderInfo.getSeparation(),orderInfo.getRow(),orderInfo.getColumn()); //核对异常 @@ -703,7 +705,7 @@ public class PlcService { stock.setExportTime(LocalDateTime.now()); stock.setCheckPic(path); stock.setCheckNum(plcCmdInfo.getOrderNum()); - //stock.setTrayCode(trayCode); + stock.setTrayCode(wmsCode); stock.setWmsTrayCode(wmsTrayCode); stock.setWmsCategory(wmsCatagary); stock.setCategory(wmsCatagary); @@ -735,7 +737,53 @@ public class PlcService { log.info("time:{}millisecond",s); return true; } + /** + * 生成一个在指定范围内的随机数 + * + * @param min 最小值(包含) + * @param max 最大值(包含) + * @return 随机生成的数值 + */ + public static int generateRandomNumber(int min, int max) { + if (min > max) { + return min; + } + + Random random = new Random(); + return random.nextInt(max - min + 1) + min; + } + + /** + * 模拟二维码扫描的成功率 + * + * @param successRate 成功率,范围在 0.0 到 1.0 之间 + * @return 扫描是否成功 + */ + public static boolean simulateQRCodeScan(double successRate) { + if (successRate < 0.0 || successRate > 1.0) { + throw new IllegalArgumentException("成功率必须在 0.0 到 1.0 之间"); + } + Random random = new Random(); + double randomValue = random.nextDouble(); + + return randomValue <= successRate; + } + + public static void main(String[] args) { + int c = 0; + for (int i = 0; i < 5000; i++){ + if (!simulateQRCodeScan(0.95)) + System.out.println(c++); + } + } + + /** + * 获取二维码 并交予灵闪识别 + * @param cameraIdQt 球机id + * @param path 拍照位置 + * @return + */ String blinkGetCode(Integer cameraIdQt ,String path){ String workPath = "work\\1.jpg"; IntByReference intByReference = new IntByReference(1); diff --git a/web/src/main/resources/application-prod.yml b/web/src/main/resources/application-prod.yml index 8767713..9f50ae8 100644 --- a/web/src/main/resources/application-prod.yml +++ b/web/src/main/resources/application-prod.yml @@ -55,6 +55,10 @@ cameraConfig: # 利珀延迟10s就可 # 单位毫秒 delayDownloadMp4: 10000 +# 识别置信度(成功率配置) + IdentificationProbability: 0.1 +# 最大扫描时间(单位:ms), + maximumRecognitionTime: 9000 cameraTimeUpdateCron: 0/10 * * * * ? # ------------ # -----图片 mp4下载地址