From a323ddb10b07799cfb0fb3b62a9d0935d601ee3b Mon Sep 17 00:00:00 2001 From: zc Date: Sun, 12 Apr 2026 19:56:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=87=E8=A7=86=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E4=BF=9D=E5=AD=98=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wms/admin/controller/ys/NetCommon.java | 44 ++++++------------- .../admin/controller/ys/req/CaptureReq.java | 27 ++++++++++++ .../admin/controller/ys/ysNetController.java | 26 ++++++++--- 3 files changed, 61 insertions(+), 36 deletions(-) create mode 100644 wms-webapi/src/main/java/top/wms/admin/controller/ys/req/CaptureReq.java diff --git a/wms-webapi/src/main/java/top/wms/admin/controller/ys/NetCommon.java b/wms-webapi/src/main/java/top/wms/admin/controller/ys/NetCommon.java index 2a4ad9b..1002146 100644 --- a/wms-webapi/src/main/java/top/wms/admin/controller/ys/NetCommon.java +++ b/wms-webapi/src/main/java/top/wms/admin/controller/ys/NetCommon.java @@ -1,10 +1,12 @@ package top.wms.admin.controller.ys; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.sun.jna.Pointer; import com.sun.jna.ptr.IntByReference; import lombok.extern.slf4j.Slf4j; import top.wms.admin.controller.ys.lib.NetDEVSDKLib; +import top.wms.admin.controller.ys.req.CaptureReq; import java.io.File; import java.util.Timer; @@ -51,33 +53,6 @@ public class NetCommon { return true; } - /** - * Launch the application. - */ - public static void main(String[] args) { - // 初始化SDK - initSDK(); - - // 登录设备 - boolean loginSuccess = loginDevice(); - if (!loginSuccess) { - System.out.println("登录失败,退出程序"); - cleanupSDK(); - return; - } - - // 抓拍图片 - captureImage(null); - - // 登出设备 - logoutDevice(); - - // 释放SDK - cleanupSDK(); - - System.out.println("程序执行完成"); - } - /** * 登录设备 * @@ -145,8 +120,9 @@ public class NetCommon { /** * 抓拍图片 + * 两处调用,一处是定时任务,一处是接口调用 */ - public static boolean captureImage(String strPicPath) { + public static boolean captureImage(CaptureReq req) { if (null == lpUserID) { log.error("请先登录设备"); return false; @@ -154,15 +130,22 @@ public class NetCommon { // 设置通道为1 ChannelID = 1; - if (StrUtil.isBlank(strPicPath)) { + //定时任务 + String strPicPath = req.getPicPath(); + if (ObjectUtil.isNull(req)) { strPicPath = "E:\\img\\ys\\carousel"; // 创建保存目录 File picDir = new File("E:\\img\\ys"); if (!picDir.exists()) { picDir.mkdir(); } + } else if (req.getType() == 1) {//接口调用 + File picDir = new File("E:\\img\\ys\\" + req.getBatch()); + if (!picDir.exists()) { + picDir.mkdir(); + } } else { - File picDir = new File("E:\\img\\ys\\workOrder"); + File picDir = new File("E:\\img\\ys\\fullWorkOrder"); if (!picDir.exists()) { picDir.mkdir(); } @@ -175,7 +158,6 @@ public class NetCommon { return true; } else { log.error("抓图失败, 错误码:{}", netdevsdk.NETDEV_GetLastError()); - log.error("请确认设备是否支持非预览抓图功能"); return false; } } diff --git a/wms-webapi/src/main/java/top/wms/admin/controller/ys/req/CaptureReq.java b/wms-webapi/src/main/java/top/wms/admin/controller/ys/req/CaptureReq.java new file mode 100644 index 0000000..582e5ad --- /dev/null +++ b/wms-webapi/src/main/java/top/wms/admin/controller/ys/req/CaptureReq.java @@ -0,0 +1,27 @@ +package top.wms.admin.controller.ys.req; + +import lombok.Data; + +@Data +public class CaptureReq { + + /** + * 类型:1-称重,2-整箱 + */ + private Integer type; + + /** + * 批次号 + */ + private String batch; + + /** + * 物料编码 + */ + private String encoding; + + /** + * 图片名称 + */ + private String picPath; +} diff --git a/wms-webapi/src/main/java/top/wms/admin/controller/ys/ysNetController.java b/wms-webapi/src/main/java/top/wms/admin/controller/ys/ysNetController.java index b15dfb9..eaba2d6 100644 --- a/wms-webapi/src/main/java/top/wms/admin/controller/ys/ysNetController.java +++ b/wms-webapi/src/main/java/top/wms/admin/controller/ys/ysNetController.java @@ -1,9 +1,11 @@ package top.wms.admin.controller.ys; +import com.alibaba.fastjson2.JSONObject; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import top.continew.starter.log.annotation.Log; import top.continew.starter.web.model.R; +import top.wms.admin.controller.ys.req.CaptureReq; @RestController @RequestMapping("/api/ys") @@ -80,7 +82,19 @@ public class ysNetController { * 手动触发一次抓图 */ @GetMapping("/capture-image") - public R captureImage(@RequestParam String imgName) { + public R captureImage(CaptureReq req) { + if (req == null) { + return R.fail("500", "系统异常!"); + } + + long l = System.currentTimeMillis(); + if (1 == req.getType()) { + String strPicPath = "E:\\img\\ys\\" + req.getBatch() + "\\" + req.getEncoding() + "_" + l; + req.setPicPath(strPicPath); + } else if (2 == req.getType()) { + req.setPicPath("E:\\img\\ys\\fullWorkOrder\\" + l); + } + try { // 检查设备是否已登录 if (!NetCommon.isDeviceLoggedIn()) { @@ -88,11 +102,13 @@ public class ysNetController { } // 执行抓图 - long l = System.currentTimeMillis(); - imgName = imgName + "_" + l; - boolean success = NetCommon.captureImage("E:\\img\\ys\\workOrder\\" + imgName); + boolean success = NetCommon.captureImage(req); if (success) { - return R.ok("http://localhost:6609/file/ys/workOrder/" + imgName + ".jpg"); + if (req.getType() == 1) { + return R.ok("http://localhost:6609/file/ys/" + req.getBatch() + "/" + req.getEncoding() + "_" + l + ".jpg"); + } else { + return R.ok("http://localhost:6609/file/ys/fullWorkOrder/" + l + ".jpg"); + } } else { return R.fail("500", "抓图失败:抓图失败"); }