扫码枪页面
This commit is contained in:
@@ -42,3 +42,11 @@ export function delRawMaterial(rawMaterialId) {
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
|
||||
export function listRawMaterialWithDemand(query) {
|
||||
return request({
|
||||
url: '/wms/rawMaterial//listWithDemand',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
@@ -235,14 +235,14 @@
|
||||
title="新增采购计划"
|
||||
:visible.sync="addDrawerOpen"
|
||||
direction="btt"
|
||||
size="90%"
|
||||
size="98%"
|
||||
:with-header="true"
|
||||
:wrapperClosable="false"
|
||||
custom-class="purchase-drawer"
|
||||
append-to-body
|
||||
mask-closable="false"
|
||||
>
|
||||
<CreatePurchasePanel
|
||||
<Transfer
|
||||
:order-id="''"
|
||||
:recommend-data="{}"
|
||||
@confirm="onAddConfirm"
|
||||
@@ -256,17 +256,17 @@ import { listPurchasePlan, getPurchasePlan, delPurchasePlan, addPurchasePlan, up
|
||||
import { listOrder } from "@/api/wms/order";
|
||||
import PurchasePlanClac from "./panels/clac.vue";
|
||||
import PurchasePlanDetail from "./panels/detail.vue";
|
||||
import CreatePurchasePanel from "./panels/CreatePurchasePanel.vue";
|
||||
import { EOrderStatus } from "../../../utils/enums";
|
||||
import UserSelect from '@/components/KLPService/UserSelect'
|
||||
import Transfer from './panels/transfer.vue'
|
||||
|
||||
export default {
|
||||
name: "PurchasePlan",
|
||||
components: {
|
||||
PurchasePlanClac,
|
||||
PurchasePlanDetail,
|
||||
CreatePurchasePanel,
|
||||
UserSelect
|
||||
UserSelect,
|
||||
Transfer,
|
||||
},
|
||||
dicts: ['order_status'],
|
||||
data() {
|
||||
@@ -334,9 +334,6 @@ export default {
|
||||
owner: [
|
||||
{ required: true, message: "负责人不能为空", trigger: "blur" }
|
||||
],
|
||||
// orderId: [
|
||||
// { required: true, message: "关联订单ID不能为空", trigger: "blur" }
|
||||
// ],
|
||||
status: [
|
||||
{ required: true, message: "状态不能为空", trigger: "change" }
|
||||
],
|
||||
|
||||
@@ -70,7 +70,11 @@
|
||||
<el-table-column label="单位" align="center" prop="unit" />
|
||||
<el-table-column label="状态" align="center" prop="status">
|
||||
<template slot-scope="scope">
|
||||
<dict-tag :options="dict.type.pruchase_detail_status" :value="scope.row.status"/>
|
||||
<el-select v-model="scope.row.status" @change="handleStatusChange(scope.row, scope.row.status, scope.row.status)">
|
||||
<el-option v-for="item in dict.type.pruchase_detail_status" :key="item.value" :label="item.label" :value="parseInt(item.value)">
|
||||
<dict-tag :options="dict.type.pruchase_detail_status" :value="item.value" />
|
||||
</el-option>
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="备注" align="center" prop="remark" />
|
||||
@@ -110,6 +114,12 @@
|
||||
icon="el-icon-refresh"
|
||||
@click="handleStatusChange(scope.row, EPurchaseDetailStatus.REVIEW, '待审核')"
|
||||
>设为待审核</el-button>
|
||||
<!-- <el-button
|
||||
v-if="scope.row.status === EPurchaseDetailStatus.REVIEW || scope.row.status === EPurchaseDetailStatus.FINISH"
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-document"
|
||||
>质保单</el-button> -->
|
||||
<el-button
|
||||
v-if="scope.row.status === EPurchaseDetailStatus.REVIEW"
|
||||
size="mini"
|
||||
@@ -382,7 +392,7 @@ export default {
|
||||
},
|
||||
/** 状态修改按钮操作 */
|
||||
handleStatusChange(row, status, label) {
|
||||
this.$modal.confirm('是否确认将采购计划明细编号为"' + row.detailId + '"的状态改为"' + label + '"?').then(() => {
|
||||
// this.$modal.confirm('是否确认将采购计划明细编号为"' + row.detailId + '"的状态改为"' + label + '"?').then(() => {
|
||||
this.loading = true;
|
||||
updatePurchasePlanDetail({ detailId: row.detailId, status: status }).then(response => {
|
||||
this.$modal.msgSuccess("状态修改成功");
|
||||
@@ -393,7 +403,7 @@ export default {
|
||||
}).finally(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
});
|
||||
// });
|
||||
},
|
||||
/** 创建入库单按钮操作 */
|
||||
handleCreateStockIn() {
|
||||
|
||||
285
klp-ui/src/views/wms/purchasePlan/panels/transfer.vue
Normal file
285
klp-ui/src/views/wms/purchasePlan/panels/transfer.vue
Normal file
@@ -0,0 +1,285 @@
|
||||
<template>
|
||||
<div class="purchase-plan-transfer">
|
||||
<!-- 采购单信息区 -->
|
||||
<el-card class="section-card" shadow="never">
|
||||
<div slot="header" class="section-title">采购单信息</div>
|
||||
<el-form :model="mainForm" :rules="mainFormRules" ref="mainFormRef" :inline="true" label-width="120px" style="margin-bottom: 0;" v-loading="formLoading" element-loading-text="正在加载主数据...">
|
||||
<el-form-item label="计划编号" prop="planCode">
|
||||
<el-input v-model="mainForm.planCode" placeholder="请输入计划编号" style="width: 200px;" />
|
||||
</el-form-item>
|
||||
<el-form-item label="负责人" prop="owner">
|
||||
<el-input v-model="mainForm.owner" :multiple="false" placeholder="请填写负责人" style="width: 200px;" />
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="mainForm.remark" placeholder="请输入备注" style="width: 300px;" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
<div>
|
||||
<el-row style="height: 60vh;">
|
||||
<el-col :span="8">
|
||||
<!-- 原材料表格 -->
|
||||
<el-table v-loading="rawMaterialLoading" ref="leftTable" :data="rawMaterialList" style="width: 100%" height="600" class="message-table" stripe @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column prop="rawMaterialId" label="原材料" align="center">
|
||||
<template #default="scope">
|
||||
<RawMaterialInfo :materialId="scope.row.rawMaterialId" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="unit" label="单位" align="center" />
|
||||
<el-table-column prop="onTheWay" label="在途" align="center" />
|
||||
<el-table-column prop="inventory" label="在库" align="center" />
|
||||
<el-table-column prop="demand" label="所需" align="center" />
|
||||
</el-table>
|
||||
|
||||
<el-pagination
|
||||
style="margin-top: 10px;"
|
||||
background
|
||||
layout="prev, pager, next"
|
||||
:total="total"
|
||||
:page-size="pageSize"
|
||||
:current-page="pageNum"
|
||||
@current-change="handlePageChange"
|
||||
/>
|
||||
</el-col>
|
||||
<!-- 穿梭操作 -->
|
||||
<el-col :span="2">
|
||||
<div style="display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%;">
|
||||
<el-button type="primary" @click="addToPurchase">添加》</el-button>
|
||||
<el-button type="danger" @click="removeFromPurchase" style="margin-top: 10px;">《删除</el-button>
|
||||
</div>
|
||||
</el-col>
|
||||
<el-col :span="14">
|
||||
<div slot="header" class="section-title">采购单明细</div>
|
||||
<el-table
|
||||
:data="purchaseList"
|
||||
@selection-change="handleRightSelectionChange"
|
||||
style="width: 100%"
|
||||
height="600"
|
||||
ref="rightTable"
|
||||
border
|
||||
>
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column prop="rawMaterialId" label="原材料">
|
||||
<template #default="scope">
|
||||
<RawMaterialInfo :materialId="scope.row.rawMaterialId" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="unit" label="单位" />
|
||||
<el-table-column prop="onTheWay" label="在途" />
|
||||
<el-table-column prop="inventory" label="在库" />
|
||||
<el-table-column prop="demand" label="所需" />
|
||||
<el-table-column prop="quantity" label="计划采购数">
|
||||
<template #default="scope">
|
||||
<el-input-number v-model="scope.row.quantity" :min="0" size="small" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="owner" label="负责人">
|
||||
<template #default="scope">
|
||||
<el-input v-model="scope.row.owner" :multiple="false" placeholder="请填写负责人" size="small" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="remark" label="备注">
|
||||
<template #default="scope">
|
||||
<el-input v-model="scope.row.remark" size="small" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
<div style="margin-top: 20px; text-align: right;" v-loading="submitLoading" element-loading-text="正在提交数据...">
|
||||
<el-button type="primary" @click="confirm" :loading="submitLoading">{{ submitLoading ? '提交中...' : '确认' }}</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { createPurchasePlan } from '@/api/wms/purchasePlan'
|
||||
import { listRawMaterial, listRawMaterialWithDemand } from '@/api/wms/rawMaterial'
|
||||
import UserSelect from '@/components/KLPService/UserSelect'
|
||||
import RawMaterialSelect from '@/components/KLPService/RawMaterialSelect'
|
||||
import RawMaterialInfo from '@/components/KLPService/Renderer/RawMaterialInfo.vue'
|
||||
|
||||
|
||||
export default {
|
||||
name: 'CreatePurchasePanel',
|
||||
components: { UserSelect, RawMaterialSelect, RawMaterialInfo },
|
||||
props: {
|
||||
orderId: {
|
||||
type: [String, Number],
|
||||
required: true
|
||||
},
|
||||
recommendData: {
|
||||
type: Object,
|
||||
default: () => ({})
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
// 原材料表格相关
|
||||
rawMaterialList: [],
|
||||
total: 0,
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
rawMaterialLoading: false,
|
||||
leftSelected: [],
|
||||
rightSelected: [],
|
||||
rawMaterialNameFilter: '',
|
||||
// 采购列表
|
||||
purchaseList: [],
|
||||
// 细化的loading状态
|
||||
formLoading: false,
|
||||
submitLoading: false,
|
||||
mainForm: {
|
||||
planCode: '',
|
||||
owner: '',
|
||||
remark: ''
|
||||
},
|
||||
mainFormRules: {
|
||||
planCode: [
|
||||
{ required: true, message: '请输入计划编号', trigger: 'blur' }
|
||||
],
|
||||
owner: [
|
||||
{ required: true, message: '请输入负责人', trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
recommendData: {
|
||||
immediate: true,
|
||||
handler(newVal) {
|
||||
if (newVal && newVal.detailList) {
|
||||
this.purchaseList = newVal.detailList
|
||||
this.mainForm = {
|
||||
planCode: newVal.planCode || '',
|
||||
owner: newVal.owner || '',
|
||||
remark: newVal.remark || ''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.fetchRawMaterials();
|
||||
},
|
||||
methods: {
|
||||
// 原材料分页查询
|
||||
fetchRawMaterials() {
|
||||
this.rawMaterialLoading = true;
|
||||
listRawMaterialWithDemand({ pageNum: this.pageNum, pageSize: this.pageSize, rawMaterialName: this.rawMaterialNameFilter }).then(res => {
|
||||
// 过滤掉已在采购列表中的原材料
|
||||
const purchaseIds = this.purchaseList.map(item => item.rawMaterialId);
|
||||
this.rawMaterialList = (res.rows || []).filter(item => !purchaseIds.includes(item.rawMaterialId));
|
||||
this.total = res.total || 0;
|
||||
this.rawMaterialLoading = false;
|
||||
}).catch(() => {
|
||||
this.rawMaterialLoading = false;
|
||||
});
|
||||
},
|
||||
handlePageChange(page) {
|
||||
this.pageNum = page;
|
||||
this.fetchRawMaterials();
|
||||
},
|
||||
handleSelectionChange(selection) {
|
||||
this.leftSelected = selection;
|
||||
},
|
||||
handleRightSelectionChange(selection) {
|
||||
this.rightSelected = selection;
|
||||
},
|
||||
handleRawMaterialFilter() {
|
||||
this.pageNum = 1;
|
||||
this.fetchRawMaterials();
|
||||
},
|
||||
addToPurchase() {
|
||||
// 去重添加
|
||||
const ids = this.purchaseList.map(item => item.rawMaterialId);
|
||||
const newItems = this.leftSelected.filter(item => !ids.includes(item.rawMaterialId)).map(item => ({
|
||||
...item,
|
||||
quantity: 0,
|
||||
owner: '',
|
||||
remark: ''
|
||||
}));
|
||||
this.purchaseList = this.purchaseList.concat(newItems);
|
||||
this.$refs.leftTable.clearSelection();
|
||||
this.fetchRawMaterials();
|
||||
},
|
||||
removeFromPurchase() {
|
||||
const removeIds = this.rightSelected.map(item => item.rawMaterialId);
|
||||
this.purchaseList = this.purchaseList.filter(item => !removeIds.includes(item.rawMaterialId));
|
||||
this.$refs.rightTable.clearSelection();
|
||||
this.fetchRawMaterials();
|
||||
},
|
||||
confirm() {
|
||||
this.submitLoading = true;
|
||||
this.$refs.mainFormRef.validate(async(valid) => {
|
||||
if (!valid) {
|
||||
this.$message.error('请完整填写主数据信息');
|
||||
this.submitLoading = false;
|
||||
return;
|
||||
}
|
||||
// 校验采购列表数据(除remark外都不能为空)
|
||||
const filtered = this.purchaseList.filter(row => row.rawMaterialId && row.rawMaterialId !== '');
|
||||
const invalid = filtered.some(row => {
|
||||
return !row.rawMaterialId || !row.owner || !row.unit || row.quantity === '' || row.quantity === null || row.quantity === undefined;
|
||||
});
|
||||
if (invalid) {
|
||||
this.$message.error('请完整填写所有必填项');
|
||||
this.submitLoading = false;
|
||||
return;
|
||||
}
|
||||
// 合并主数据和明细数据
|
||||
const submitData = {
|
||||
...this.mainForm,
|
||||
orderId: this.orderId,
|
||||
detailList: filtered
|
||||
};
|
||||
await createPurchasePlan(submitData);
|
||||
this.$emit('confirm', submitData);
|
||||
this.submitLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.purchase-plan-transfer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.section-card {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.section-title {
|
||||
font-weight: bold;
|
||||
font-size: 16px;
|
||||
color: #333;
|
||||
}
|
||||
.transfer-content {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.left-table {
|
||||
width: 30%;
|
||||
}
|
||||
.right-table {
|
||||
width: 60%;
|
||||
}
|
||||
.transfer-actions {
|
||||
width: 10%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.transfer-actions .el-button {
|
||||
margin: 10px 0;
|
||||
}
|
||||
.filter-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
</style>
|
||||
38
scaner/.gitignore
vendored
Normal file
38
scaner/.gitignore
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
92
scaner/pom.xml
Normal file
92
scaner/pom.xml
Normal file
@@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>jar</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<mainClass>org.example.Main</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>org.example.Main</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!-- MQTT dependency removed -->
|
||||
<dependency>
|
||||
<groupId>com.klp</groupId>
|
||||
<artifactId>mv-code-reader-ctrl-wrapper</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20210307</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.tyrus</groupId>
|
||||
<artifactId>tyrus-server</artifactId>
|
||||
<version>1.17</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.tyrus</groupId>
|
||||
<artifactId>tyrus-container-grizzly-server</artifactId>
|
||||
<version>1.17</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.tyrus</groupId>
|
||||
<artifactId>tyrus-container-servlet</artifactId>
|
||||
<version>2.1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.websocket</groupId>
|
||||
<artifactId>javax.websocket-api</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
68
scaner/src/main/java/org/example/HttpRequestUtil.java
Normal file
68
scaner/src/main/java/org/example/HttpRequestUtil.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package org.example;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
public class HttpRequestUtil {
|
||||
/**
|
||||
* 向指定URL发送POST请求,发送JSON数据
|
||||
* @param urlStr 目标接口地址
|
||||
* @param jsonData 发送的JSON字符串
|
||||
* @return 响应内容
|
||||
* @throws Exception 网络异常
|
||||
*/
|
||||
public static String postJson(String urlStr, String jsonData) throws Exception {
|
||||
URL url = new URL(urlStr);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
|
||||
conn.setDoOutput(true);
|
||||
conn.setDoInput(true);
|
||||
try (OutputStream os = conn.getOutputStream()) {
|
||||
os.write(jsonData.getBytes("UTF-8"));
|
||||
}
|
||||
int code = conn.getResponseCode();
|
||||
if (code == 200) {
|
||||
try (java.io.InputStream is = conn.getInputStream()) {
|
||||
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int len;
|
||||
while ((len = is.read(buffer)) != -1) {
|
||||
baos.write(buffer, 0, len);
|
||||
}
|
||||
return new String(baos.toByteArray(), "UTF-8");
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("HTTP请求失败,状态码: " + code);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 向指定URL发送GET请求
|
||||
* @param urlStr 目标接口地址
|
||||
* @return 响应内容
|
||||
* @throws Exception 网络异常
|
||||
*/
|
||||
public static String get(String urlStr) throws Exception {
|
||||
URL url = new URL(urlStr);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setRequestProperty("Accept", "application/json");
|
||||
conn.setDoInput(true);
|
||||
int code = conn.getResponseCode();
|
||||
if (code == 200) {
|
||||
try (java.io.InputStream is = conn.getInputStream()) {
|
||||
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int len;
|
||||
while ((len = is.read(buffer)) != -1) {
|
||||
baos.write(buffer, 0, len);
|
||||
}
|
||||
return new String(baos.toByteArray(), "UTF-8");
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("HTTP GET请求失败,状态码: " + code);
|
||||
}
|
||||
}
|
||||
}
|
||||
240
scaner/src/main/java/org/example/Main.java
Normal file
240
scaner/src/main/java/org/example/Main.java
Normal file
@@ -0,0 +1,240 @@
|
||||
package org.example;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
// Main.java 顶部增加
|
||||
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;
|
||||
|
||||
// 保存设备列表
|
||||
private static ArrayList<MV_CODEREADER_DEVICE_INFO> stCamListCache = new ArrayList<>();
|
||||
|
||||
// 获取设备列表JSON(推送给前端)
|
||||
public static String getDeviceListJson() {
|
||||
org.json.JSONObject obj = new org.json.JSONObject();
|
||||
obj.put("type", "deviceList");
|
||||
org.json.JSONArray arr = new org.json.JSONArray();
|
||||
for (int i = 0; i < stCamListCache.size(); i++) {
|
||||
MV_CODEREADER_DEVICE_INFO camInfo = stCamListCache.get(i);
|
||||
// System.out.println(camInfo.toString() + "设备相信信息");
|
||||
System.out.println(camInfo.stGigEInfo.chModelName + camInfo.stGigEInfo.chUserDefinedName + camInfo.stGigEInfo.nCurrentIp + camInfo.stGigEInfo.chSerialNumber + camInfo.stGigEInfo.chDeviceVersion
|
||||
+ camInfo.stGigEInfo.chManufacturerName + camInfo.stGigEInfo.chManufacturerSpecificInfo + camInfo.stGigEInfo.nIpCfgCurrent);
|
||||
org.json.JSONObject dev = new org.json.JSONObject();
|
||||
dev.put("id", camInfo.stGigEInfo.chSerialNumber); // 序列号
|
||||
dev.put("name", camInfo.stGigEInfo.chUserDefinedName != null ? camInfo.stGigEInfo.chUserDefinedName : camInfo.stGigEInfo.chModelName);
|
||||
dev.put("type", "scanner");
|
||||
dev.put("on", true); // 默认开
|
||||
arr.put(dev);
|
||||
}
|
||||
obj.put("devices", arr);
|
||||
return obj.toString();
|
||||
}
|
||||
|
||||
public static void saveDataToFile(byte[] dataToSave, int dataSize, String fileName) {
|
||||
OutputStream os = null;
|
||||
|
||||
try {
|
||||
// Create saveImg directory
|
||||
File tempFile = new File("saveImg");
|
||||
if (!tempFile.exists()) {
|
||||
tempFile.mkdirs();
|
||||
}
|
||||
|
||||
stCamListCache = MvCodeReaderCtrl.MV_CODEREADER_EnumDevices();
|
||||
os.write(dataToSave, 0, dataSize);
|
||||
System.out.println("SaveImage succeed.");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// Close file stream
|
||||
try {
|
||||
os.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CallBack function
|
||||
private static void printImgCBInfo(byte[] pdata, MV_CODEREADER_IMAGE_OUT_INFO_EX2 stOutInfo) {
|
||||
if (null == stOutInfo) {
|
||||
System.out.println("stOutInfo is null");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.print("/**CBpstOutInfo***************************************/\n");
|
||||
|
||||
|
||||
// 示例:扫码时调用POST接口,解析扫码内容并发送JSON
|
||||
try {
|
||||
// 假设扫码内容为第一个条码内容
|
||||
// String scanStr = null;
|
||||
// if (stOutInfo != null && stOutInfo.pstCodeListEx != null && stOutInfo.pstCodeListEx.nCodeNum > 0) {
|
||||
// scanStr = stOutInfo.pstCodeListEx.stBcrInfoEx.get(0).chCode;
|
||||
// }
|
||||
// if (scanStr != null && !scanStr.isEmpty()) {
|
||||
// String json = ScanDataUtil.buildRequestJson(
|
||||
// scanStr,
|
||||
// "raw_material", // 物品类型
|
||||
// "扫码入库", // 备注
|
||||
// null, // 源库位ID
|
||||
// 1 // 记录类型
|
||||
// );
|
||||
// System.out.println("json: " + json);
|
||||
// // 发送两次请求:修改库存并且插入一条记录
|
||||
// // 插入记录
|
||||
// String postUrl1 = "http://localhost:8080/wms/stockIoDetail"; // TODO: 替换为实际接口
|
||||
// String postResponse = HttpRequestUtil.postJson(postUrl1, json);
|
||||
// System.out.println("POST接口响应: " + postResponse);
|
||||
// // 修改库存
|
||||
// String postUrl2 = "http://localhost:8080/wms/stockIo/scanInStock";
|
||||
// String postResponse2 = HttpRequestUtil.postJson(postUrl2, json);
|
||||
// System.out.println("修改库存POST接口响应: " + postResponse2);
|
||||
// } else {
|
||||
// System.out.println("未获取到扫码内容,未发送POST请求");
|
||||
// }
|
||||
} catch (Exception e) {
|
||||
System.err.println("POST请求失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
// save buffer to file follow Image Type to Save
|
||||
// saveDataToFile(pdata, stOutInfo.nFrameLen, "Image.jpg");
|
||||
// saveDataToFile(pdata, stOutInfo.nFrameLen, "Image.raw");
|
||||
|
||||
System.out.print(String.format("Get One Frame: 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));
|
||||
|
||||
System.out.print("Get One Code: bIsGetCode[" + stOutInfo.bIsGetCode + "]success\r\n");
|
||||
|
||||
System.out.print("Get GvspPixelType: MvCodeReaderGvspPixelType[" + stOutInfo.enPixelType + "]success\r\n");
|
||||
|
||||
// print code info
|
||||
for (int a = 0; a < stOutInfo.pstCodeListEx.nCodeNum; a++) {
|
||||
org.json.JSONObject obj = new org.json.JSONObject();
|
||||
obj.put("type", "scanMessage");
|
||||
// 解析码中的数据,用下划线分割,第一个为物料类型,第二个为物料id
|
||||
String code = stOutInfo.pstCodeListEx.stBcrInfoEx.get(a).chCode;
|
||||
String[] parts = code.split("__");
|
||||
String itemType = parts[0];
|
||||
String itemId = parts[1];
|
||||
obj.put("itemType", itemType);
|
||||
obj.put("itemId", itemId);
|
||||
WsServer.broadcast(obj.toString());
|
||||
System.out.print(String.format("CodeInfo: 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));
|
||||
|
||||
System.out.print(String.format("CodePointInfo: stCornerLeftTop.X[%d], stCornerLeftTop.Y[%d], stCornerRightTop.X[%d], stCornerRightTop.Y[%d],"
|
||||
+ "stCornerRightBottom.X[%d], stCornerRightBottom.Y[%d], stCornerLeftBottom.X[%d], stCornerLeftBottom.Y[%d]\r\n",
|
||||
stOutInfo.pstCodeListEx.stBcrInfoEx.get(a).stCornerLeftTop.nX, stOutInfo.pstCodeListEx.stBcrInfoEx.get(a).stCornerLeftTop.nY,
|
||||
stOutInfo.pstCodeListEx.stBcrInfoEx.get(a).stCornerRightTop.nX, stOutInfo.pstCodeListEx.stBcrInfoEx.get(a).stCornerRightTop.nY,
|
||||
stOutInfo.pstCodeListEx.stBcrInfoEx.get(a).stCornerRightBottom.nX, stOutInfo.pstCodeListEx.stBcrInfoEx.get(a).stCornerRightBottom.nY,
|
||||
stOutInfo.pstCodeListEx.stBcrInfoEx.get(a).stCornerLeftBottom.nX, stOutInfo.pstCodeListEx.stBcrInfoEx.get(a).stCornerLeftBottom.nY));
|
||||
|
||||
System.out.print("Get CodeQuality: bIsGetQuality[" + stOutInfo.pstCodeListEx.stBcrInfoEx.get(a).bIsGetQuality + "]success\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
private static void PrintDeviceInfo(MV_CODEREADER_DEVICE_INFO stCamInfo) {
|
||||
if (stCamInfo.nTLayerType == MvCodeReaderCtrlDefine.MV_CODEREADER_GIGE_DEVICE) {
|
||||
int nIp1 = ((stCamInfo.stGigEInfo.nCurrentIp & 0xff000000) >> 24) & 0xff;
|
||||
int nIp2 = ((stCamInfo.stGigEInfo.nCurrentIp & 0x00ff0000) >> 16);
|
||||
int nIp3 = ((stCamInfo.stGigEInfo.nCurrentIp & 0x0000ff00) >> 8);
|
||||
int nIp4 = (stCamInfo.stGigEInfo.nCurrentIp & 0x000000ff);
|
||||
|
||||
System.out.print("CurrentIp: " + nIp1 + "." + nIp2 + "." + nIp3 + "." + nIp4 + "\r\n");
|
||||
|
||||
System.out.print(String.format("GiGEInfo: UserDefinedName:[%s], chSerialNumber:[%s] \r\n\r\n",
|
||||
stCamInfo.stGigEInfo.chUserDefinedName, stCamInfo.stGigEInfo.chSerialNumber));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
|
||||
System.out.print(" ***************Begin****************** \r\n");
|
||||
|
||||
String strVersion = MvCodeReaderCtrl.MV_CODEREADER_GetSDKVersion();
|
||||
System.out.print("Get version " + strVersion + "\r\n");
|
||||
|
||||
ArrayList<MV_CODEREADER_DEVICE_INFO> stCamList = MvCodeReaderCtrl.MV_CODEREADER_EnumDevices();
|
||||
Main.stCamListCache = stCamList;
|
||||
if (stCamList == null || stCamList.isEmpty()) {
|
||||
System.out.print("Find No Device!\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<Handle> handleList = new ArrayList<>();
|
||||
for (int i = 0; i < stCamList.size(); i++) {
|
||||
MV_CODEREADER_DEVICE_INFO camInfo = stCamList.get(i);
|
||||
PrintDeviceInfo(camInfo);
|
||||
|
||||
Handle handle = null;
|
||||
try {
|
||||
handle = MvCodeReaderCtrl.MV_CODEREADER_CreateHandle(camInfo);
|
||||
} catch (ParameterException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (handle == null) {
|
||||
System.out.print("Create handle failed for device " + i + "!\r\n");
|
||||
continue;
|
||||
}
|
||||
int nRet = MvCodeReaderCtrl.MV_CODEREADER_OpenDevice(handle);
|
||||
if (nRet != 0) {
|
||||
System.out.print("Open Device fail for device " + i + "! nRet[" + String.format("0x%x", nRet) + "]\r\n");
|
||||
continue;
|
||||
}
|
||||
nRet = MvCodeReaderCtrl.MV_CODEREADER_RegisterImageCallBackEx2(handle, new ImageCallBack() {
|
||||
@Override
|
||||
public int OnImageCallBack(byte[] pdata, MV_CODEREADER_IMAGE_OUT_INFO_EX2 stOutInfo) {
|
||||
printImgCBInfo(pdata, stOutInfo);
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
if (nRet != 0) {
|
||||
System.out.print("RegisterImageCallBackEx2 Failed for device " + i + "! nRet[" + String.format("0x%x", nRet) + "]\r\n");
|
||||
continue;
|
||||
}
|
||||
nRet = MvCodeReaderCtrl.MV_CODEREADER_StartGrabbing(handle);
|
||||
if (nRet != 0) {
|
||||
System.out.print("StartGrabbing Failed for device " + i + "! nRet[" + String.format("0x%x", nRet) + "]\r\n");
|
||||
continue;
|
||||
}
|
||||
handleList.add(handle);
|
||||
System.out.print("Device " + i + " startGrabbing success!\r\n");
|
||||
}
|
||||
|
||||
// 阻塞主线程直到退出
|
||||
System.out.println("所有扫码枪已开始监听");
|
||||
|
||||
// 启动 Socket 服务器
|
||||
Server server = new Server("localhost", 9000, "/", null, WsServer.class);
|
||||
try {
|
||||
server.start();
|
||||
System.out.println("WebSocket服务器已启动,端口9000");
|
||||
System.in.read(); // 阻塞主线程直到回车
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
server.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
34
scaner/src/main/java/org/example/ScanDataUtil.java
Normal file
34
scaner/src/main/java/org/example/ScanDataUtil.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package org.example;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class ScanDataUtil {
|
||||
/**
|
||||
* 解析扫码内容并构造请求体
|
||||
* @param scanStr 扫码内容,格式:入库单id_仓库id_物料id_数量
|
||||
* @param itemType 物品类型
|
||||
* @param itemId 物品ID
|
||||
* @param unit 单位
|
||||
* @param remark 备注(可选)
|
||||
* @param fromWarehouseId 源库位ID(可选)
|
||||
* @param recordType 记录类型(0/1)
|
||||
* @return JSON字符串
|
||||
*/
|
||||
public static String buildRequestJson(String scanStr, String itemType, String remark, Long fromWarehouseId, Integer recordType) {
|
||||
String[] parts = scanStr.split("_");
|
||||
if (parts.length != 4) throw new IllegalArgumentException("扫码内容格式不正确,应为:入库单id_仓库id_物料id_数量");
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("stockIoId", Long.valueOf(parts[0]));
|
||||
obj.put("warehouseId", Long.valueOf(parts[1]));
|
||||
obj.put("itemId", Long.valueOf(parts[2]));
|
||||
obj.put("quantity", new BigDecimal(parts[3]));
|
||||
obj.put("itemType", itemType);
|
||||
obj.put("unit", 'g'); // 单位为null
|
||||
obj.put("batchNo", 100); // 批次号为null
|
||||
obj.put("remark", remark);
|
||||
obj.put("fromWarehouseId", fromWarehouseId);
|
||||
obj.put("recordType", recordType);
|
||||
return obj.toString();
|
||||
}
|
||||
}
|
||||
53
scaner/src/main/java/org/example/WsServer.java
Normal file
53
scaner/src/main/java/org/example/WsServer.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package org.example;
|
||||
|
||||
import javax.websocket.OnClose;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.OnOpen;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
@javax.websocket.server.ServerEndpoint("/ws")
|
||||
public class WsServer {
|
||||
private static final Set<javax.websocket.Session> sessions = new CopyOnWriteArraySet<>();
|
||||
|
||||
@javax.websocket.OnOpen
|
||||
public void onOpen(javax.websocket.Session session) {
|
||||
sessions.add(session);
|
||||
System.out.println("WebSocket连接已建立: " + session.getId());
|
||||
// 推送扫码枪列表给前端
|
||||
String deviceListJson = org.example.Main.getDeviceListJson();
|
||||
try {
|
||||
System.out.println("发送消息到前端");
|
||||
session.getBasicRemote().sendText(deviceListJson);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@javax.websocket.OnMessage
|
||||
public void onMessage(String message, javax.websocket.Session session) throws IOException {
|
||||
System.out.println("收到消息: " + message);
|
||||
session.getBasicRemote().sendText("服务器已收到: " + message);
|
||||
}
|
||||
|
||||
@javax.websocket.OnClose
|
||||
public void onClose(javax.websocket.Session session) {
|
||||
sessions.remove(session);
|
||||
System.out.println("WebSocket连接已关闭: " + session.getId());
|
||||
}
|
||||
|
||||
public static void broadcast(String message) {
|
||||
for (javax.websocket.Session session : sessions) {
|
||||
if (session.isOpen()) {
|
||||
try {
|
||||
session.getBasicRemote().sendText(message);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
80
scaner/src/views/ScannerList.vue
Normal file
80
scaner/src/views/ScannerList.vue
Normal file
@@ -0,0 +1,80 @@
|
||||
<template>
|
||||
<el-row>
|
||||
<el-col :span="6">
|
||||
<ul>
|
||||
<li v-for="item in deviceList" :key="item.id">
|
||||
<span>{{ item.name }}</span>
|
||||
<span>{{ item.status }}</span>
|
||||
<span>{{ item.type }}</span>
|
||||
<el-switch v-model="item.on" @change="handleDeviceChange(item)" />
|
||||
</li>
|
||||
</ul>
|
||||
</el-col>
|
||||
<el-col :span="18">
|
||||
<el-table :data="messageList" style="width: 100%">
|
||||
<el-table-column prop="time" label="时间" width="180" />
|
||||
<el-table-column prop="message" label="消息" width="180" />
|
||||
<el-table-column prop="device" label="设备" width="180" />
|
||||
<el-table-column prop="type" label="类型" width="180" />
|
||||
<el-table-column prop="recordType" label="记录类型" width="180" />
|
||||
</el-table>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
deviceList: [],
|
||||
messageList: [],
|
||||
socket: null,
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.initSocket();
|
||||
},
|
||||
methods: {
|
||||
initSocket() {
|
||||
this.socket = new WebSocket("ws://localhost:8080");
|
||||
this.socket.onopen = () => {
|
||||
console.log("Socket 连接已建立");
|
||||
};
|
||||
this.socket.onmessage = (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.type === "deviceList") {
|
||||
this.deviceList = data.devices;
|
||||
} else if (data.type === "scanMessage") {
|
||||
this.messageList.push(data.message);
|
||||
}
|
||||
};
|
||||
this.socket.onclose = () => {
|
||||
console.log("Socket 连接已关闭");
|
||||
};
|
||||
},
|
||||
handleDeviceChange(item) {
|
||||
this.socket.send(
|
||||
JSON.stringify({
|
||||
type: "toggleDevice",
|
||||
deviceId: item.id,
|
||||
status: item.on,
|
||||
})
|
||||
);
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
}
|
||||
li {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user