feat: 扫码后直接插入记录

This commit is contained in:
砂糖
2025-08-22 13:19:22 +08:00
parent 7ff779946d
commit 76926c3a10
4 changed files with 90 additions and 63 deletions

View File

@@ -62,10 +62,10 @@
</el-col>
<el-col :span="12">
<el-form-item label="物料信息" style="margin-bottom: 8px;">
<ProductSelect v-if="cfg.itemType === 'product'" v-model="cfg.itemId" placeholder="请选择产品" />
<SemiSelect v-else-if="cfg.itemType === 'semi'" v-model="cfg.itemId" placeholder="请选择半成品" />
<ProductSelect v-if="cfg.itemType === 'product'" v-model="cfg.itemId" placeholder="请选择产品" @change="onItemChange($event, idx)" />
<SemiSelect v-else-if="cfg.itemType === 'semi'" v-model="cfg.itemId" placeholder="请选择半成品" @change="onItemChange($event, idx)" />
<RawMaterialSelect v-else-if="cfg.itemType === 'raw_material'" v-model="cfg.itemId"
placeholder="请选择原材料" />
placeholder="请选择原材料" @change="onItemChange($event, idx)" />
<el-input v-else disabled v-model="cfg.itemId" placeholder="请先选择物料类型" :disabled="true"
style="width: 100%;" />
</el-form-item>
@@ -135,7 +135,10 @@ export default {
warehouseId: b.warehouseId,
itemType: b.itemType,
itemId: b.itemId,
batchNo: b.batchNo
batchNo: b.batchNo,
quantity: b.count,
unit: b.unit,
recordType: 1,
}),
count: b.count || 1,
textTpl: b.text || ''
@@ -143,19 +146,8 @@ export default {
}
},
methods: {
onItemChange(item) {
// 选中后构造条码数据并插入
console.log(item);
const itemType = this.itemType;
const name = (itemType == 'semi' || itemType == 'product') ? item.productName : item.rawMaterialName;
const code = (itemType == 'semi' || itemType == 'product') ? item.productCode : item.rawMaterialCode;
const itemId = (itemType == 'semi' || itemType == 'product') ? item.productId : item.rawMaterialId;
const o = {
code: encodeURIComponent(`${itemType}__${itemId || ''}`),
count: 1,
textTpl: `${name}[${code}]`
}
this.drawerBarcodeData.push(o);
onItemChange(item, idx) {
this.drawerBarcodeData[idx].unit = item.unit;
},
fetchMaster() {
listStockIo({ pageSize: 9999, pageNum: 1 }).then(res => {
@@ -182,6 +174,7 @@ export default {
itemId: undefined,
batchNo: 'auto',
count: 0,
unit: '',
text: '默认文字',
}

View File

@@ -19,6 +19,41 @@
<br />
<!-- 明细表格 -->
<el-tabs v-model="activeTab" style="margin-bottom: 10px;">
<el-tab-pane label="扫码枪" name="scanner">
<el-table :data="scannerList" :show-header="true" :border="true" style="width: 100%;" :default-sort="{}" :highlight-current-row="true">
<el-table-column type="index" width="55" align="center" label="#" />
<el-table-column label="库区/库位" align="center" prop="warehouseName" />
<el-table-column v-if="stockIo.ioType === 'transfer'" label="源库区/库位" align="center" prop="fromWarehouseName" />
<el-table-column label="物品类型" align="center" prop="itemType">
<template slot-scope="scope">
<dict-tag :options="dict.type.stock_item_type" :value="scope.row.itemType" />
</template>
</el-table-column>
<el-table-column label="物品ID" align="center" prop="itemId" />
<el-table-column label="数量" align="center" prop="quantity" />
<el-table-column label="单位" align="center" prop="unit" />
<!-- <el-table-column label="批次号" align="center" prop="batchNo" /> -->
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
:disabled="stockIo.status >= 2"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
:disabled="stockIo.status >= 2"
>删除</el-button>
</template>
</el-table-column>
</el-table>
</el-tab-pane>
<el-tab-pane label="手动录入" name="manual">
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
@@ -90,7 +125,7 @@
</el-table-column>
<el-table-column label="数量" align="center" prop="quantity" />
<el-table-column label="单位" align="center" prop="unit" />
<el-table-column label="批次号" align="center" prop="batchNo" />
<!-- <el-table-column label="批次号" align="center" prop="batchNo" /> -->
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
@@ -112,23 +147,7 @@
</el-table-column>
</el-table>
</el-tab-pane>
<el-tab-pane label="扫码枪" name="scanner">
<el-table :data="scannerList" :show-header="true" :border="true" style="width: 100%;" :default-sort="{}" :highlight-current-row="true">
<el-table-column type="index" width="55" align="center" label="#" />
<el-table-column label="库区/库位" align="center" prop="warehouseName" />
<el-table-column v-if="stockIo.ioType === 'transfer'" label="源库区/库位" align="center" prop="fromWarehouseName" />
<el-table-column label="物品类型" align="center" prop="itemType">
<template slot-scope="scope">
<dict-tag :options="dict.type.stock_item_type" :value="scope.row.itemType" />
</template>
</el-table-column>
<el-table-column label="物品ID" align="center" prop="itemId" />
<el-table-column label="数量" align="center" prop="quantity" />
<el-table-column label="单位" align="center" prop="unit" />
<el-table-column label="批次号" align="center" prop="batchNo" />
<el-table-column label="备注" align="center" prop="remark" />
</el-table>
</el-tab-pane>
</el-tabs>
<pagination
v-show="total>0"
@@ -186,9 +205,9 @@
<el-form-item label="单位" prop="unit">
<el-input v-model="form.unit" placeholder="请输入单位" :disabled="unitDisabled" />
</el-form-item>
<el-form-item label="批次号" prop="batchNo">
<!-- <el-form-item label="批次号" prop="batchNo">
<el-input v-model="form.batchNo" placeholder="请输入批次号" />
</el-form-item>
</el-form-item> -->
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" placeholder="请输入备注" />
</el-form-item>
@@ -275,7 +294,7 @@ export default {
statusLoading: false, // 新增状态修改按钮加载状态
cancelLoading: false, // 撤回按钮加载状态
unitDisabled: false, // 新增:单位输入框是否禁用
activeTab: 'manual' // 新增:当前激活的标签页
activeTab: 'scanner' // 新增:当前激活的标签页
};
},
watch: {
@@ -443,7 +462,7 @@ export default {
itemId: undefined,
quantity: undefined,
unit: undefined,
batchNo: undefined,
batchNo: 'auto',
remark: undefined
};
this.unitDisabled = false; // 新增:重置单位输入框为可编辑

View File

@@ -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;
}
}

View File

@@ -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();
}
}
}