✨ feat: 扫码后直接插入记录
This commit is contained in:
@@ -9,20 +9,17 @@ import java.util.ArrayList;
|
||||
import org.glassfish.tyrus.server.Server;
|
||||
|
||||
import MvCodeReaderCtrlWrapper.*;
|
||||
import MvCodeReaderCtrlWrapper.MvCodeReaderCtrl.*;
|
||||
import MvCodeReaderCtrlWrapper.MvCodeReaderCtrlDefine.*;
|
||||
import MvCodeReaderCtrlWrapper.ParameterException.*;
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Main {
|
||||
static Handle hHandle = null;
|
||||
static HttpRequestUtil http = null;
|
||||
|
||||
// 保存所有读取到的设备列表
|
||||
private static ArrayList<MV_CODEREADER_DEVICE_INFO> allDevices = new ArrayList<>();
|
||||
|
||||
// 保存正在监听的设备列表
|
||||
private static ArrayList<MV_CODEREADER_DEVICE_INFO> activeDevices = new ArrayList<>();
|
||||
private static final ArrayList<MV_CODEREADER_DEVICE_INFO> activeDevices = new ArrayList<>();
|
||||
private static byte[] pdata;
|
||||
|
||||
// 获取所有读取到的设备列表JSON(推送给前端)
|
||||
public static String getAllDevicesJson() {
|
||||
@@ -94,8 +91,9 @@ public class Main {
|
||||
}
|
||||
}
|
||||
|
||||
// 回调函数
|
||||
// 回调函数, 当扫码枪扫码后触发
|
||||
private static void printImgCBInfo(byte[] pdata, MV_CODEREADER_IMAGE_OUT_INFO_EX2 stOutInfo) {
|
||||
Main.pdata = pdata;
|
||||
if (null == stOutInfo) {
|
||||
System.out.println("stOutInfo is null");
|
||||
return;
|
||||
@@ -103,10 +101,10 @@ public class Main {
|
||||
|
||||
System.out.print("/**CBpstOutInfo***************************************/\n");
|
||||
|
||||
System.out.print(String.format("获取一帧: nEventID[%d], nChannelID[%d], nWidth[%d], nHeight[%d], nFrameNum[%d], nTriggerIndex[%d], nFrameLen[%d], "
|
||||
System.out.printf("获取一帧: nEventID[%d], nChannelID[%d], nWidth[%d], nHeight[%d], nFrameNum[%d], nTriggerIndex[%d], nFrameLen[%d], "
|
||||
+ " nCodeNumber[%d] \r\n",
|
||||
stOutInfo.nEventID, stOutInfo.nChannelID, stOutInfo.nWidth, stOutInfo.nHeight, stOutInfo.nFrameNum,
|
||||
stOutInfo.nTriggerIndex, stOutInfo.nFrameLen, stOutInfo.pstCodeListEx.nCodeNum));
|
||||
stOutInfo.nTriggerIndex, stOutInfo.nFrameLen, stOutInfo.pstCodeListEx.nCodeNum);
|
||||
|
||||
System.out.print("解码状态: bIsGetCode[" + stOutInfo.bIsGetCode + "]\r\n");
|
||||
|
||||
@@ -118,34 +116,44 @@ public class Main {
|
||||
obj.put("type", "scanMessage");
|
||||
// 解析码中的数据,用下划线分割,第一个为物料类型,第二个为物料id
|
||||
String code = stOutInfo.pstCodeListEx.stBcrInfoEx.get(a).chCode;
|
||||
String[] parts = code.split("__");
|
||||
if (parts.length >= 2) {
|
||||
String itemType = parts[0];
|
||||
String itemId = parts[1];
|
||||
obj.put("itemType", itemType);
|
||||
obj.put("itemId", itemId);
|
||||
} else {
|
||||
obj.put("rawCode", code);
|
||||
obj.put("error", "格式不正确");
|
||||
// String[] parts = code.split("__");
|
||||
// if (parts.length >= 2) {
|
||||
// String itemType = parts[0];
|
||||
// String itemId = parts[1];
|
||||
// obj.put("itemType", itemType);
|
||||
// obj.put("itemId", itemId);
|
||||
// } else {
|
||||
// obj.put("rawCode", code);
|
||||
// obj.put("error", "格式不正确");
|
||||
// }
|
||||
// 直接将解析出的数据返回到页面上
|
||||
// WsServer.broadcast(code);
|
||||
// 发送http请求,存储信息
|
||||
try {
|
||||
String s = HttpRequestUtil.postJson("http://140.143.206.120:8080/wms/stockIoDetail", code);
|
||||
System.out.println("返回值" + s);
|
||||
System.out.println("明细记录创建成功" + code);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
WsServer.broadcast(obj.toString());
|
||||
|
||||
System.out.print(String.format("解码信息: TheCodeID[%d], CodeString[%s], nCodeLen[%d], nAngle[%d], nBarType[%d],"
|
||||
|
||||
System.out.printf("解码信息: TheCodeID[%d], CodeString[%s], nCodeLen[%d], nAngle[%d], nBarType[%d],"
|
||||
+ "sAlgoCost[%d], nIDRScore[%d], n1DIsGetQuality[%d]\r\n",
|
||||
a, stOutInfo.pstCodeListEx.stBcrInfoEx.get(a).chCode, stOutInfo.pstCodeListEx.stBcrInfoEx.get(a).nLen,
|
||||
stOutInfo.pstCodeListEx.stBcrInfoEx.get(a).nAngle, stOutInfo.pstCodeListEx.stBcrInfoEx.get(a).nBarType,
|
||||
stOutInfo.pstCodeListEx.stBcrInfoEx.get(a).sAlgoCost, stOutInfo.pstCodeListEx.stBcrInfoEx.get(a).nIDRScore,
|
||||
stOutInfo.pstCodeListEx.stBcrInfoEx.get(a).n1DIsGetQuality));
|
||||
stOutInfo.pstCodeListEx.stBcrInfoEx.get(a).n1DIsGetQuality);
|
||||
}
|
||||
}
|
||||
|
||||
private static void PrintDeviceInfo(MV_CODEREADER_DEVICE_INFO stCamInfo) {
|
||||
if (stCamInfo.nTLayerType == MvCodeReaderCtrlDefine.MV_CODEREADER_GIGE_DEVICE) {
|
||||
System.out.print("IP地址: " + getIpAddress(stCamInfo.stGigEInfo.nCurrentIp) + "\r\n");
|
||||
System.out.print(String.format("设备信息: 自定义名称:[%s], 序列号:[%s], 型号:[%s] \r\n\r\n",
|
||||
System.out.printf("设备信息: 自定义名称:[%s], 序列号:[%s], 型号:[%s] \r\n\r\n",
|
||||
stCamInfo.stGigEInfo.chUserDefinedName,
|
||||
stCamInfo.stGigEInfo.chSerialNumber,
|
||||
stCamInfo.stGigEInfo.chModelName));
|
||||
stCamInfo.stGigEInfo.chModelName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,6 +229,8 @@ public class Main {
|
||||
|
||||
System.out.println("所有设备处理完毕。活跃设备数量: " + activeDevices.size() + "\r\n");
|
||||
|
||||
http = new HttpRequestUtil();
|
||||
System.out.println("http请求工具创建完成");
|
||||
// 启动WebSocket服务器,用于向前端推送设备列表和扫描结果
|
||||
Server server = new Server("localhost", 9000, "/", null, WsServer.class);
|
||||
try {
|
||||
@@ -242,4 +252,8 @@ public class Main {
|
||||
System.out.println("程序已退出");
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] getPdata() {
|
||||
return pdata;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ public class ScanDataUtil {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("stockIoId", Long.valueOf(parts[0]));
|
||||
obj.put("warehouseId", Long.valueOf(parts[1]));
|
||||
obj.put("fromWarehouseId", Long.valueOf(parts[1]));
|
||||
obj.put("itemId", Long.valueOf(parts[2]));
|
||||
obj.put("quantity", new BigDecimal(parts[3]));
|
||||
obj.put("itemType", itemType);
|
||||
@@ -31,4 +32,4 @@ public class ScanDataUtil {
|
||||
obj.put("recordType", recordType);
|
||||
return obj.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user