优化宇视图片保存地址
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
package top.wms.admin.controller.ys;
|
package top.wms.admin.controller.ys;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.sun.jna.Pointer;
|
import com.sun.jna.Pointer;
|
||||||
import com.sun.jna.ptr.IntByReference;
|
import com.sun.jna.ptr.IntByReference;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import top.wms.admin.controller.ys.lib.NetDEVSDKLib;
|
import top.wms.admin.controller.ys.lib.NetDEVSDKLib;
|
||||||
|
import top.wms.admin.controller.ys.req.CaptureReq;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
@@ -51,33 +53,6 @@ public class NetCommon {
|
|||||||
return true;
|
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) {
|
if (null == lpUserID) {
|
||||||
log.error("请先登录设备");
|
log.error("请先登录设备");
|
||||||
return false;
|
return false;
|
||||||
@@ -154,15 +130,22 @@ public class NetCommon {
|
|||||||
|
|
||||||
// 设置通道为1
|
// 设置通道为1
|
||||||
ChannelID = 1;
|
ChannelID = 1;
|
||||||
if (StrUtil.isBlank(strPicPath)) {
|
//定时任务
|
||||||
|
String strPicPath = req.getPicPath();
|
||||||
|
if (ObjectUtil.isNull(req)) {
|
||||||
strPicPath = "E:\\img\\ys\\carousel";
|
strPicPath = "E:\\img\\ys\\carousel";
|
||||||
// 创建保存目录
|
// 创建保存目录
|
||||||
File picDir = new File("E:\\img\\ys");
|
File picDir = new File("E:\\img\\ys");
|
||||||
if (!picDir.exists()) {
|
if (!picDir.exists()) {
|
||||||
picDir.mkdir();
|
picDir.mkdir();
|
||||||
}
|
}
|
||||||
|
} else if (req.getType() == 1) {//接口调用
|
||||||
|
File picDir = new File("E:\\img\\ys\\" + req.getBatch());
|
||||||
|
if (!picDir.exists()) {
|
||||||
|
picDir.mkdir();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
File picDir = new File("E:\\img\\ys\\workOrder");
|
File picDir = new File("E:\\img\\ys\\fullWorkOrder");
|
||||||
if (!picDir.exists()) {
|
if (!picDir.exists()) {
|
||||||
picDir.mkdir();
|
picDir.mkdir();
|
||||||
}
|
}
|
||||||
@@ -175,7 +158,6 @@ public class NetCommon {
|
|||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
log.error("抓图失败, 错误码:{}", netdevsdk.NETDEV_GetLastError());
|
log.error("抓图失败, 错误码:{}", netdevsdk.NETDEV_GetLastError());
|
||||||
log.error("请确认设备是否支持非预览抓图功能");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
package top.wms.admin.controller.ys;
|
package top.wms.admin.controller.ys;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import top.continew.starter.log.annotation.Log;
|
import top.continew.starter.log.annotation.Log;
|
||||||
import top.continew.starter.web.model.R;
|
import top.continew.starter.web.model.R;
|
||||||
|
import top.wms.admin.controller.ys.req.CaptureReq;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/ys")
|
@RequestMapping("/api/ys")
|
||||||
@@ -80,7 +82,19 @@ public class ysNetController {
|
|||||||
* 手动触发一次抓图
|
* 手动触发一次抓图
|
||||||
*/
|
*/
|
||||||
@GetMapping("/capture-image")
|
@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 {
|
try {
|
||||||
// 检查设备是否已登录
|
// 检查设备是否已登录
|
||||||
if (!NetCommon.isDeviceLoggedIn()) {
|
if (!NetCommon.isDeviceLoggedIn()) {
|
||||||
@@ -88,11 +102,13 @@ public class ysNetController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 执行抓图
|
// 执行抓图
|
||||||
long l = System.currentTimeMillis();
|
boolean success = NetCommon.captureImage(req);
|
||||||
imgName = imgName + "_" + l;
|
|
||||||
boolean success = NetCommon.captureImage("E:\\img\\ys\\workOrder\\" + imgName);
|
|
||||||
if (success) {
|
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 {
|
} else {
|
||||||
return R.fail("500", "抓图失败:抓图失败");
|
return R.fail("500", "抓图失败:抓图失败");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user