From 375ace27ad6afbc3c83d92add0fb5a0347a6edbf Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期一, 08 十二月 2025 21:24:24 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/ZhongRui/ALDbanyunxiangmu
---
项目代码/WIDESEA_WMSClient/src/extension/stock/stockView.js | 164 ++-
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Outbound/OutboundPickingController.cs | 6
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs | 26
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_IOutboundService/IOutboundPickingService.cs | 7
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_StockService/StockViewService.cs | 133 +
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_DictionaryService.cs | 62 +
项目代码/WIDESEA_WMSClient/src/extension/basic/locationInfo.js | 16
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundBatchPickingService.cs | 2222 ++++++++++++++++++++++++++++++-------------
项目代码/WIDESEA_WMSClient/src/views/stock/stockView.vue | 64 +
项目代码/WIDESEA_WMSClient/src/views/outbound/BatchPickingConfirm.vue | 4
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs | 9
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_RoleService.cs | 23
项目代码/WIDESEA_WMSClient/src/extension/outbound/extend/NoStockOut.vue | 176 ++
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoDetailService.cs | 64 +
14 files changed, 2,113 insertions(+), 863 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/basic/locationInfo.js" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/basic/locationInfo.js"
index d805115..8fd6b94 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/basic/locationInfo.js"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/basic/locationInfo.js"
@@ -48,21 +48,7 @@
}
}
- this.columns.push({
- field: '鎿嶄綔',
- title: '鎿嶄綔',
- width: 90,
- fixed: 'right',
- align: 'center',
- formatter: (row) => {
- return (
- '<i style="cursor: pointer;color: #2d8cf0;"class="el-icon-view">鏌ョ湅鏄庣粏</i>'
- );
- },
- click: (row) => {
- this.$refs.gridBody.open(row);
- }
- });
+
},
onInited() {
//妗嗘灦鍒濆鍖栭厤缃悗
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/outbound/extend/NoStockOut.vue" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/outbound/extend/NoStockOut.vue"
index 95df14e..7e80215 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/outbound/extend/NoStockOut.vue"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/outbound/extend/NoStockOut.vue"
@@ -10,7 +10,12 @@
>
<div>
<!-- 鍗曟嵁杈撳叆鍖哄煙锛堟敮鎸佹壂鐮侊級 -->
- <el-form :inline="true" :model="orderForm" style="margin-bottom: 20px; align-items: flex-end;">
+ <el-form
+ :inline="true"
+ :model="orderForm"
+ style="margin-bottom: 20px; align-items: flex-end;"
+ @submit.prevent
+ >
<el-form-item label="鍑哄簱鍗曟嵁:" name="outboundOrderNo">
<el-input
v-model="orderForm.outboundOrderNo"
@@ -18,25 +23,35 @@
clearable
style="width: 220px; margin-right: 10px;"
@input="handleOutboundInput"
- @keyup.enter="focusPurchaseInput"
+ @keyup.enter="(e) => {
+ e.stopPropagation(); // 闃绘浜嬩欢鍐掓场
+ e.preventDefault(); // 闃绘榛樿琛屼负
+ focusBarcodeInputDirectly();
+ }"
ref="outboundInputRef"
></el-input>
</el-form-item>
<el-form-item label="閲囪喘鍗曟嵁:" name="purchaseOrderNo">
<el-input
v-model="orderForm.purchaseOrderNo"
- placeholder="璇疯緭鍏ユ垨鎵弿閲囪喘鍗曟嵁鍙�"
+ placeholder="鎵爜鏉$爜鍚庤嚜鍔ㄥ~鍏�"
clearable
style="width: 220px; margin-right: 10px;"
@input="handlePurchaseInput"
- @keyup.enter="focusBarcodeInput"
+ readonly
ref="purchaseInputRef"
></el-input>
</el-form-item>
</el-form>
<!-- 涓婃柟杈撳叆妗� -->
- <el-form :inline="true" :model="formData" ref="formRef" style="margin-bottom: 20px; align-items: flex-end;">
+ <el-form
+ :inline="true"
+ :model="formData"
+ ref="formRef"
+ style="margin-bottom: 20px; align-items: flex-end;"
+ @submit.prevent
+ >
<el-form-item
label="鎵弿鏉$爜:"
style="width: 80%"
@@ -47,10 +62,10 @@
ref="barcodeInputRef"
v-model="formData.barcode"
placeholder="璇蜂娇鐢ㄦ壂鐮佹灙鎵弿鏉$爜锛屾垨鎵嬪姩杈撳叆"
- @keyup.enter="handleScan"
+ @keydown.enter="debouncedHandleScan"
autofocus
class="custom-input"
- :disabled="!orderForm.outboundOrderNo || !orderForm.purchaseOrderNo"
+ :disabled="!orderForm.outboundOrderNo || loading"
></el-input>
</el-form-item>
<el-form-item>
@@ -59,7 +74,7 @@
size="small"
@click="handleScan"
class="custom-button"
- :disabled="!orderForm.outboundOrderNo || !orderForm.purchaseOrderNo || loading"
+ :disabled="!orderForm.outboundOrderNo || loading"
>
<Search /> 纭鎵弿
</el-button>
@@ -87,7 +102,7 @@
</div>
</transition-group>
<div class="empty-tip" v-if="scannedBarcodes.length === 0">
- <span>鏆傛棤鎵弿璁板綍锛岃鍏堣緭鍏ュ崟鎹悗鎵弿鏉$爜</span>
+ <span>鏆傛棤鎵弿璁板綍锛岃鍏堣緭鍏ュ嚭搴撳崟鎹悗鎵弿鏉$爜</span>
</div>
</el-scrollbar>
</div>
@@ -106,7 +121,17 @@
>
<Check /> 鎻愪氦鍑哄簱
</el-button>
- <el-button type="text" size="small" @click="showDetailBox = false" class="cancel-btn" :disabled="loading">
+ <el-button
+ type="text"
+ size="small"
+ @click="(e) => {
+ e.stopPropagation();
+ e.preventDefault();
+ showDetailBox = false;
+ }"
+ class="cancel-btn"
+ :disabled="loading"
+ >
鍙栨秷
</el-button>
</div>
@@ -116,9 +141,9 @@
</template>
<script setup>
-import { ref, reactive, onMounted, nextTick } from 'vue';
+import { ref, reactive, onMounted, nextTick, watch } from 'vue';
import { ElMessage } from 'element-plus';
-import { Search } from '@element-plus/icons-vue';
+import { Search, Check } from '@element-plus/icons-vue';
import VolBox from "@/components/basic/VolBox.vue";
import http from '@/api/http';
@@ -134,6 +159,8 @@
});
const scannedBarcodes = ref([]);
const loading = ref(false);
+// 鏂板锛氬瓨鍌ㄩ娆℃壂鎻忕殑閲囪喘鍗曞彿锛堢敤浜庝竴鑷存�ф牎楠岋級
+const firstPurchaseOrderNo = ref(null);
// 妯℃澘寮曠敤
const formRef = ref(null);
@@ -148,6 +175,25 @@
});
});
+// 鐩戝惉鎵弿鍒楄〃锛岃嫢涓虹┖鍒欓噸缃娆¢噰璐崟鍙�
+watch(scannedBarcodes, (newVal) => {
+ if (newVal.length === 0) {
+ firstPurchaseOrderNo.value = null;
+ orderForm.purchaseOrderNo = ""; // 鍚屾娓呯┖閲囪喘鍗曡緭鍏ユ
+ }
+}, { deep: true });
+
+// 绠�鍗曢槻鎶栧嚱鏁帮紙鏃犻渶渚濊禆lodash锛�
+const debounce = (fn, delay = 100) => {
+ let timer = null;
+ return (...args) => {
+ if (timer) clearTimeout(timer);
+ timer = setTimeout(() => {
+ fn.apply(this, args);
+ }, delay);
+ };
+};
+
// 鎵撳紑寮圭獥
const open = () => {
showDetailBox.value = true;
@@ -155,6 +201,8 @@
formData.barcode = "";
orderForm.outboundOrderNo = "";
orderForm.purchaseOrderNo = "";
+ // 閲嶇疆棣栨閲囪喘鍗曞彿
+ firstPurchaseOrderNo.value = null;
nextTick(() => {
outboundInputRef.value?.focus();
});
@@ -162,43 +210,55 @@
// 鍑哄簱鍗曡緭鍏ュ鐞嗭紙鎵爜鎴栨墜鍔ㄨ緭鍏ワ級
const handleOutboundInput = (value) => {
- // 鎵爜鏋緭鍏ラ�氬父浼氳嚜鍔ㄨЕ鍙慹nter浜嬩欢锛岃繖閲屼富瑕佸鐞嗘墜鍔ㄨ緭鍏ョ殑鎯呭喌
if (value && value.trim()) {
- // 鍙互鍦ㄨ繖閲屾坊鍔犲嚭搴撳崟鍙风殑鏍煎紡楠岃瘉閫昏緫
+ // 鍑哄簱鍗曞彿鏍煎紡楠岃瘉閫昏緫锛堟寜闇�淇濈暀锛�
}
};
// 閲囪喘鍗曡緭鍏ュ鐞嗭紙鎵爜鎴栨墜鍔ㄨ緭鍏ワ級
const handlePurchaseInput = (value) => {
if (value && value.trim()) {
- // 鍙互鍦ㄨ繖閲屾坊鍔犻噰璐崟鍙风殑鏍煎紡楠岃瘉閫昏緫
+ // 閲囪喘鍗曞彿鏍煎紡楠岃瘉閫昏緫锛堟寜闇�淇濈暀锛�
}
};
-// 鐒︾偣璺宠浆鍑芥暟
-const focusPurchaseInput = () => {
+// 鐩存帴璺宠浆鍒版潯鐮佽緭鍏ユ锛堟棤闇�鍏堝~閲囪喘鍗曪級
+const focusBarcodeInputDirectly = () => {
if (orderForm.outboundOrderNo.trim()) {
- purchaseInputRef.value?.focus();
+ barcodeInputRef.value?.focus();
} else {
ElMessage.warning("璇峰厛杈撳叆鏈夋晥鐨勫嚭搴撳崟鎹彿");
}
};
-const focusBarcodeInput = () => {
- if (orderForm.purchaseOrderNo.trim()) {
- barcodeInputRef.value?.focus();
- } else {
- ElMessage.warning("璇峰厛杈撳叆鏈夋晥鐨勯噰璐崟鎹彿");
+/**
+ * 鏍规嵁鏉$爜鏌ヨ閲囪喘鍗曟帴鍙o紙瀹屽叏瀵归綈绀轰緥璇锋眰鏍煎紡锛�
+ * @param {string} barcode 鏉$爜
+ * @returns {Promise<string>} 閲囪喘鍗曞彿
+ */
+const getPurchaseOrderByBarcode = async (barcode) => {
+ // 瀹屽叏鎸夌収绀轰緥鏍煎紡锛歶rl鎷兼帴鍙傛暟 + 绗簩涓弬鏁颁紶鎻愮ず鏂囨湰
+ const res = await http.post(`/api/OutboundPicking/GetPurchaseOrderByBarcode?barCode=${encodeURIComponent(barcode)}`, "鏌ヨ閲囪喘鍗曚腑...");
+
+ if (res.status !== true) {
+ throw new Error(res.message || "鏌ヨ閲囪喘鍗曞け璐�");
}
+ if (!res.data?.purchaseOrderNo) {
+ throw new Error("鏈煡璇㈠埌璇ユ潯鐮佸搴旂殑閲囪喘鍗�");
+ }
+ return res.data.purchaseOrderNo;
};
-// 鎵弿鏉$爜澶勭悊
+// 鎵弿鏉$爜鏍稿績閫昏緫
const handleScan = async () => {
if (!formRef.value) return;
+ // 楠岃瘉鏉$爜蹇呭~
await formRef.value.validateField('barcode');
const barcode = formData.barcode.trim();
-
+ const outboundOrderNo = orderForm.outboundOrderNo.trim();
+
+ // 妫�鏌ユ潯鐮佹槸鍚﹀凡鎵弿
if (scannedBarcodes.value.some(item => item.barcode === barcode)) {
ElMessage.warning(`鏉$爜 ${barcode} 宸叉壂鎻忚繃锛岃鍕块噸澶嶆壂鎻廯);
formData.barcode = "";
@@ -208,33 +268,72 @@
try {
loading.value = true;
- // 杩欓噷淇濈暀浜嗗師鏈夌殑鏉$爜楠岃瘉鎺ュ彛锛屼綘鍙互鏍规嵁瀹為檯闇�姹備慨鏀规垨淇濈暀
- const res = await http.post("/api/OutboundPicking/BarcodeValidate", {
- outOder: orderForm.outboundOrderNo, // 娉ㄦ剰锛氳繖閲岀幇鍦ㄤ紶閫掔殑鏄崟鎹彿瀛楃涓诧紝鑰屼笉鏄疘D
- inOder: orderForm.purchaseOrderNo, // 娉ㄦ剰锛氳繖閲岀幇鍦ㄤ紶閫掔殑鏄崟鎹彿瀛楃涓诧紝鑰屼笉鏄疘D
+
+ // 姝ラ1锛氫粎浼犳潯鐮佹煡璇㈤噰璐崟锛堜娇鐢ㄧず渚嬫牸寮忕殑璇锋眰锛�
+ const purchaseOrderNo = await getPurchaseOrderByBarcode(barcode);
+
+ // 鏍稿績鏍¢獙锛氶噰璐崟涓�鑷存�ф鏌�
+ if (firstPurchaseOrderNo.value) {
+ // 闈為娆℃壂鎻忥紝鏍¢獙閲囪喘鍗曞彿鏄惁涓�鑷�
+ if (purchaseOrderNo !== firstPurchaseOrderNo.value) {
+ throw new Error(`褰撳墠鏉$爜瀵瑰簲鐨勯噰璐崟銆�${purchaseOrderNo}銆戜笌棣栨鎵弿鐨勯噰璐崟銆�${firstPurchaseOrderNo.value}銆戜笉涓�鑷达紝绂佹鎵弿锛乣);
+ }
+ } else {
+ // 棣栨鎵弿锛岃褰曢噰璐崟鍙�
+ firstPurchaseOrderNo.value = purchaseOrderNo;
+ }
+
+ // 璧嬪�奸噰璐崟鍒拌緭鍏ユ
+ orderForm.purchaseOrderNo = purchaseOrderNo;
+ ElMessage.success(`鎴愬姛鏌ヨ鍒伴噰璐崟锛�${purchaseOrderNo}`);
+
+ // 姝ラ2锛氳皟鐢ㄥ師鏈夋潯鐮侀獙璇佹帴鍙o紙濡傞渶瀵归綈鏍煎紡鍙悓姝ヤ慨鏀癸紝姝ゅ淇濈暀鍘熸湁鏍煎紡锛�
+ const validateRes = await http.post("/api/OutboundPicking/BarcodeValidate", {
+ outOder: outboundOrderNo,
+ inOder: purchaseOrderNo,
barCode: barcode
});
- if (res.status === true) {
+ if (validateRes.status === true) {
scannedBarcodes.value.push({ barcode });
ElMessage.success("鎵弿鎴愬姛");
formData.barcode = "";
} else {
- ElMessage.error("鎵弿澶辫触锛�" + (res.message || '楠岃瘉澶辫触'));
+ ElMessage.error("鎵弿澶辫触锛�" + (validateRes.message || '鏉$爜楠岃瘉澶辫触'));
}
} catch (error) {
- ElMessage.error("鎵弿楠岃瘉寮傚父锛�" + error.message);
+ // 鎹曡幏閲囪喘鍗曚笉涓�鑷寸瓑閿欒骞舵彁绀�
+ ElMessage.error(error.message);
+ // 娓呯┖褰撳墠杈撳叆妗嗭紝鑱氱劍鏉$爜杈撳叆妗�
+ formData.barcode = "";
+ nextTick(() => barcodeInputRef.value?.focus());
} finally {
loading.value = false;
- nextTick(() => barcodeInputRef.value?.focus());
+ // 寮哄埗鑱氱劍鏉$爜杈撳叆妗嗭紝閬垮厤鐒︾偣璺冲埌寮圭獥澶�
+ nextTick(() => {
+ if (barcodeInputRef.value) {
+ barcodeInputRef.value.focus();
+ // 娓呯┖杈撳叆妗嗛�変腑鐘舵�侊紙鎵爜鏋彲鑳芥畫鐣欓�変腑锛�
+ if (barcodeInputRef.value.input) {
+ barcodeInputRef.value.input.select = () => {};
+ }
+ }
+ });
}
};
+
+// 甯﹂槻鎶栧拰浜嬩欢鎷︽埅鐨勬壂鎻忓鐞嗭紙閫傞厤鎵爜鏋級
+const debouncedHandleScan = debounce(async (e) => {
+ // 闃绘浜嬩欢鍐掓场鍜岄粯璁よ涓�
+ e.stopPropagation();
+ e.preventDefault();
+ await handleScan();
+}, 100);
// 绉婚櫎鍗曟潯鎵弿璁板綍
const removeItem = async (index, barcode) => {
try {
loading.value = true;
- // 杩欓噷淇濈暀浜嗗師鏈夌殑鍒犻櫎鏉$爜鎺ュ彛锛屼綘鍙互鏍规嵁瀹為檯闇�姹備慨鏀规垨淇濈暀
const res = await http.post("/api/OutboundPicking/DeleteBarcode", {
outOder: orderForm.outboundOrderNo,
inOder: orderForm.purchaseOrderNo,
@@ -244,6 +343,11 @@
if (res.status === true) {
scannedBarcodes.value.splice(index, 1);
ElMessage.success("鍒犻櫎鎴愬姛");
+ // 鑻ュ垹闄ゅ悗鏃犳潯鐮侊紝鑷姩閲嶇疆棣栨閲囪喘鍗曞彿鍜岄噰璐崟杈撳叆妗�
+ if (scannedBarcodes.value.length === 0) {
+ firstPurchaseOrderNo.value = null;
+ orderForm.purchaseOrderNo = "";
+ }
} else {
ElMessage.error("鍒犻櫎澶辫触锛�" + (res.message || '鍒犻櫎澶辫触'));
}
@@ -265,7 +369,6 @@
try {
loading.value = true;
- // 杩欓噷淇濈暀浜嗗師鏈夌殑鎻愪氦鎺ュ彛锛屾敞鎰忓弬鏁扮幇鍦ㄤ紶閫掔殑鏄崟鎹彿瀛楃涓�
const res = await http.post("/api/OutboundPicking/NoStockOutSubmit", {
OutOderSubmit: orderForm.outboundOrderNo,
InOderSubmit: orderForm.purchaseOrderNo,
@@ -275,6 +378,9 @@
if (res.status === true) {
ElMessage.success("鍑哄簱鎻愪氦鎴愬姛");
showDetailBox.value = false;
+ // 鎻愪氦鎴愬姛鍚庨噸缃姸鎬�
+ firstPurchaseOrderNo.value = null;
+ scannedBarcodes.value = [];
} else {
ElMessage.error("鍑哄簱鎻愪氦澶辫触锛�" + (res.message || '鎻愪氦澶辫触'));
}
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/stock/stockView.js" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/stock/stockView.js"
index 047c354..6e73be0 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/stock/stockView.js"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/stock/stockView.js"
@@ -31,65 +31,117 @@
// });
// }
// }
- // this.columns.forEach(column => {
- // if (column.field == 'materielCode') {
- // column.formatter = (row) => {
- // var str = '';
- // var list = row.materielCode.split(',');
- // for (let index = 0; index < list.length; index++) {
- // str += list[index] + '<br>';
- // }
- // return str = list[0] == "" ? "绌虹" : str;
- // }
- // }
- // if (column.field == 'batchNo') {
- // column.formatter = (row) => {
- // var str = '';
- // var list = row.batchNo.split(',');
- // for (let index = 0; index < list.length; index++) {
- // str += list[index] + '<br>';
- // }
- // return str = list[0] == "" ? "鏃�" : str;
- // }
- // }
- // if (column.field == 'materielInfo') {
- // const today = new Date()
- // column.formatter = (row) => {
- // if (row.details.length > 0) {
- // const today = new Date();
- // const closestDate = row.details
- // .map(x => {
- // const date = new Date(x.effectiveDate);
- // const diffInDays = Math.ceil(Math.abs((today - date) / (1000 * 60 * 60 * 24)));
- // return { date, diffInDays };
- // })
- // .reduce((closest, current) => (current.diffInDays < closest.diffInDays ? current : closest))
- // .date;
+ this.columns.forEach(column => {
+ // if (column.field == 'materielCode') {
+ // column.formatter = (row) => {
+ // var str = '';
+ // var list = row.materielCode.split(',');
+ // for (let index = 0; index < list.length; index++) {
+ // str += list[index] + '<br>';
+ // }
+ // return str = list[0] == "" ? "绌虹" : str;
+ // }
+ // }
+ // if (column.field == 'batchNo') {
+ // column.formatter = (row) => {
+ // var str = '';
+ // var list = row.batchNo.split(',');
+ // for (let index = 0; index < list.length; index++) {
+ // str += list[index] + '<br>';
+ // }
+ // return str = list[0] == "" ? "鏃�" : str;
+ // }
+ // }
+ // if (column.field == 'materielInfo') {
+ // const today = new Date()
+ // column.formatter = (row) => {
+ // if (row.details.length > 0) {
+ // const today = new Date();
+ // const closestDate = row.details
+ // .map(x => {
+ // const date = new Date(x.effectiveDate);
+ // const diffInDays = Math.ceil(Math.abs((today - date) / (1000 * 60 * 60 * 24)));
+ // return { date, diffInDays };
+ // })
+ // .reduce((closest, current) => (current.diffInDays < closest.diffInDays ? current : closest))
+ // .date;
- // const daysSinceClosest = Math.ceil(Math.abs((today - closestDate) / (1000 * 60 * 60 * 24)));
- // return '<span style="color: #F56C6C">' + daysSinceClosest + "澶�" + '</span>';
- // } else {
- // return '<span style="color: #F56C6C">' + "鏃犱繚璐ㄦ湡" + '</span>';
- // }
+ // const daysSinceClosest = Math.ceil(Math.abs((today - closestDate) / (1000 * 60 * 60 * 24)));
+ // return '<span style="color: #F56C6C">' + daysSinceClosest + "澶�" + '</span>';
+ // } else {
+ // return '<span style="color: #F56C6C">' + "鏃犱繚璐ㄦ湡" + '</span>';
+ // }
- // }
- // }
- // if (column.field == 'sumStock') {
- // column.formatter = (row) => {
- // if (row.details.length > 0) {
- // var sum = 0;
- // const closestDate = row.details
- // .map(x => {
- // sum += (x.stockQuantity)
- // })
- // return '<span style="color: #F56C6C">' + sum + row.details[0].unit + '</span>';
- // } else {
- // return '<span style="color: #F56C6C">' + "1涓�" + '</span>';
- // }
+ // }
+ // }
+ if (column.field == 'sumStock') {
+ column.formatter = (row) => {
+ if (row.details.length > 0) {
+ var sum = 0;
+ const closestDate = row.details
+ .map(x => {
+ sum += (x.stockQuantity)
+ })
+ return '<span style="color: #F56C6C">' + sum + row.details[0].unit + '</span>';
+ } else {
+ return '<span style="color: #F56C6C">' + "1涓�" + '</span>';
+ }
- // }
- // }
- // })
+ }
+ }
+ if (column.field === 'orderStatistics') {
+ column.formatter = (row) => {
+ // 鏍¢獙details鏄惁瀛樺湪涓旀湁鏁版嵁
+ if (row.details && row.details.length > 0) {
+ // 鎸塵aterielCode鍒嗙粍缁熻stockQuantity鎬诲拰锛屽苟璁板綍鍗曚綅锛堝彇绗竴涓潪绌哄崟浣嶏級
+ const materielSumMap = row.details.reduce((acc, item) => {
+ const materielCode = item.materielCode || '鏈煡鐗╂枡';
+ const quantity = Number(item.stockQuantity) || 0;
+ const unit = item.unit || ''; // 鑾峰彇鍗曚綅锛屾棤鍒欎负绌�
+
+ // 绱姞鏁伴噺
+ acc[materielCode] = {
+ total: (acc[materielCode]?.total || 0) + quantity,
+ unit: acc[materielCode]?.unit || unit // 淇濈暀绗竴涓潪绌哄崟浣�
+ };
+ return acc;
+ }, {});
+
+ // 姣忎釜鐗╂枡椤圭敓鎴愮嫭绔媎iv锛岃法琛屾樉绀猴紙鍖呭惈鍗曚綅锛�
+ const displayItems = Object.entries(materielSumMap).map(([code, data]) => {
+ // 澶勭悊鍗曚綅鏄剧ず锛氭湁鍗曚綅鍒欏姞绌烘牸鏄剧ず锛屾棤鍒欎笉鏄剧ず
+ const unitText = data.unit ? ` ${data.unit}` : '';
+ return `<div style="line-height: 1.5; white-space: normal;">${code}锛�${data.total}${unitText}</div>`;
+ });
+ const displayContent = displayItems.join('');
+ return `<div style="color: #F56C6C; white-space: normal; word-break: break-all;">${displayContent}</div>`;
+ } else {
+ return '<span style="color: #F56C6C">绌虹</span>';
+ }
+ };
+ }
+ if (column.field == 'stockOrderNo') {
+ column.formatter = (row) => {
+ // 鏈夋槑缁嗘暟鎹椂澶勭悊
+ if (row.details && row.details.length > 0) {
+ // 鎻愬彇鎵�鏈夐潪绌虹殑orderNO骞跺幓閲�
+ const uniqueOrderNOs = [...new Set(
+ row.details.map(item => item.orderNo).filter(no => no) // 杩囨护绌哄崟鎹彿
+ )];
+
+ // 鏈夋湁鏁堝崟鎹彿鍒欐崲琛屾樉绀猴紝鍚﹀垯鏄剧ず榛樿鏂囨湰
+ if (uniqueOrderNOs.length > 0) {
+ return `<span style="color: #F56C6C">${uniqueOrderNOs.join('<br>')}</span>`;
+ } else {
+ return '<span style="color: #F56C6C">鏆傛棤鍗曟嵁</span>';
+ }
+ } else {
+ // 鏃犳槑缁嗘暟鎹椂鏄剧ず榛樿鏂囨湰
+ return '<span style="color: #F56C6C">鏆傛棤鍗曟嵁</span>';
+ }
+ }
+ }
+ })
},
onInited() {
//妗嗘灦鍒濆鍖栭厤缃悗
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/views/outbound/BatchPickingConfirm.vue" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/views/outbound/BatchPickingConfirm.vue"
index 1c9c6a2..0de29c5 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/views/outbound/BatchPickingConfirm.vue"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/views/outbound/BatchPickingConfirm.vue"
@@ -27,8 +27,8 @@
@keyup.enter.native="onBarcodeScan">
</el-input>
<el-button type="success" @click="confirmPicking">纭鎷i��</el-button>
- <!-- <el-button type="warning" @click="openSplitDialog">鎷嗗寘</el-button>
- <el-button type="info" @click="openRevertSplitDialog">鎾ら攢鎷嗗寘</el-button> -->
+ <!-- <el-button type="warning" @click="openSplitDialog">鎷嗗寘</el-button>
+ <el-button type="info" @click="openRevertSplitDialog">鎾ら攢鎷嗗寘</el-button> -->
<el-button type="info" @click="handleEmptyPallet">鍙栫┖绠�</el-button>
<el-button type="primary" @click="openBatchReturnDialog">鍥炲簱</el-button>
</div>
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/views/stock/stockView.vue" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/views/stock/stockView.vue"
index 13ce26a..2b25f87 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/views/stock/stockView.vue"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/views/stock/stockView.vue"
@@ -37,7 +37,7 @@
const searchFormOptions = ref([
[
{ title: "鎵樼洏缂栧彿", field: "palletCode",type: "like" },
- // { title: "璐т綅缂栧彿", field: "locationCode",type: "like" },
+ { title: "璐т綅缂栧彿", field: "locationCode",type: "like" },
{ title: "璐т綅鐘舵��", field: "locationStatus" ,type: "selectList",dataKey: "locationStatusEnum",data: [],},
{ title: "搴撳瓨鐘舵��", field: "stockStatus",type: "selectList",dataKey: "stockStatusEmun",data: [],},
],
@@ -77,16 +77,10 @@
field: "locationName",
title: "璐т綅鍚嶇О",
type: "string",
- width: 270,
+ width: 150,
align: "left",
},
- {
- field: "warehouseId",
- title: "鎵�灞炰粨搴�",
- type: "string",
- width: 80,
- align: "left",
- },
+
{
field: "roadwayNo",
title: "宸烽亾缂栧彿",
@@ -96,15 +90,22 @@
hidden:true
},
{
- field: "materielCode",
- title: "鎵�鍚墿鏂欑紪鍙�",
+ field: "orderStatistics",
+ title: "鎵�鍚墿鏂欐槑缁�",
type: "string",
- width: 120,
+ width: 240,
align: "left",
},
{
field: "sumStock",
title: "鎬诲簱瀛�",
+ type: "string",
+ width: 140,
+ align: "left",
+ },
+ {
+ field: "stockOrderNo",
+ title: "鎵�鍚崟鎹�",
type: "string",
width: 140,
align: "left",
@@ -125,6 +126,45 @@
align: "left",
},
{
+ field: "enalbeStatus",
+ title: "璐т綅绂佺敤鐘舵��",
+ type: "string",
+ width: 140,
+ align: "left",
+ bind: { key: "enableStatusEnum", data: [] },
+ },
+ {
+ field: "locationStatus",
+ title: "璐т綅鐘舵��",
+ type: "string",
+ width: 140,
+ align: "left",
+ bind: { key: "locationStatusEnum", data: [] },
+ },
+ {
+ field: "locationType",
+ title: "璐т綅绫诲瀷",
+ type: "string",
+ width: 140,
+ align: "left",
+ bind:{key: "locationTypeEnum", data: []}
+ },
+ {
+ field: "stockStatus",
+ title: "搴撳瓨鐘舵��",
+ type: "string",
+ width: 140,
+ align: "left",
+ bind:{key: "stockStatusEmun", data: []}
+ },
+ {
+ field: "warehouseId",
+ title: "鎵�灞炰粨搴�",
+ type: "string",
+ width: 80,
+ align: "left",
+ },
+ {
field: "modifier",
title: "淇敼浜�",
type: "string",
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_IOutboundService/IOutboundPickingService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_IOutboundService/IOutboundPickingService.cs"
index dda5c65..cb38bdc 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_IOutboundService/IOutboundPickingService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_IOutboundService/IOutboundPickingService.cs"
@@ -51,5 +51,12 @@
WebResponseContent UnPalletQuantity(string orderNo);
WebResponseContent BarcodeMaterielGroup(BarcodeMaterielGroupDTO materielGroupDTO);
+
+ /// <summary>
+ /// 鏉$爜鏌ヨ鍏ュ簱鍗�
+ /// </summary>
+ /// <param name="barcode"></param>
+ /// <returns></returns>
+ public WebResponseContent GetPurchaseOrderByBarcode(string barcode);
}
}
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundBatchPickingService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundBatchPickingService.cs"
index bb29ac6..0948e79 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundBatchPickingService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundBatchPickingService.cs"
@@ -1,6 +1,5 @@
锘縰sing Microsoft.Extensions.Logging;
using SqlSugar;
-using SqlSugar.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -15,6 +14,7 @@
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Enums;
+using WIDESEA_Core.Helper;
using WIDESEA_DTO.Basic;
using WIDESEA_DTO.Outbound;
using WIDESEA_IAllocateService;
@@ -249,16 +249,19 @@
#region 鍒嗘壒鍒嗘嫞
+
/// <summary>
- /// 鍒嗘壒鍒嗘嫞纭
+ /// 鍒嗘壒鍒嗘嫞纭 - 淇鐗堬紙鍖呭惈鎷嗗寘鍚庨獙璇侊級
/// </summary>
public async Task<WebResponseContent> ConfirmBatchPicking(string orderNo, string palletCode, string barcode)
{
try
{
+ _logger.LogInformation($"銆愬垎鎷e紑濮嬨�戣鍗�: {orderNo}, 鎵樼洏: {palletCode}, 鏉$爜: {barcode}");
+
_unitOfWorkManage.BeginTran();
- // 楠岃瘉鍒嗘嫞璇锋眰
+ // 1. 楠岃瘉鍒嗘嫞璇锋眰
var validationResult = await ValidatePickingRequest(orderNo, palletCode, barcode);
if (!validationResult.IsValid)
{
@@ -268,11 +271,26 @@
var (lockInfo, orderDetail, stockDetail, batch) = validationResult.Data;
- // 妫�鏌ユ槸鍚﹂渶瑕佽嚜鍔ㄦ媶鍖�
+ _logger.LogInformation($"楠岃瘉閫氳繃 - 閿佸畾ID: {lockInfo.Id}, 鍒嗛厤鏁伴噺: {lockInfo.AssignQuantity}, 宸叉嫞閫�: {lockInfo.PickedQty}");
+ _logger.LogInformation($"搴撳瓨淇℃伅 - 鏉$爜: {stockDetail.Barcode}, 搴撳瓨鏁伴噺: {stockDetail.StockQuantity}, 鍑哄簱鏁伴噺: {stockDetail.OutboundQuantity}");
+
+
+ decimal originalStockQtyBeforeSplit = stockDetail.StockQuantity;
+ decimal originalOutboundQtyBeforeSplit = stockDetail.OutboundQuantity;
+
+ // 璁板綍鎷嗗寘鍓嶇殑鍏抽敭鏁版嵁锛堢敤浜庡悗缁獙璇侊級
+ decimal originalAllocatedQty = orderDetail.AllocatedQuantity;
+ decimal originalLockQty = orderDetail.LockQuantity;
+ decimal originalStockQty = stockDetail.StockQuantity;
+ decimal originalOutboundQty = stockDetail.OutboundQuantity;
+
+ // 2. 妫�鏌ユ槸鍚﹂渶瑕佽嚜鍔ㄦ媶鍖�
var autoSplitResult = await CheckAndAutoSplitIfNeeded(lockInfo, stockDetail, palletCode);
if (autoSplitResult != null)
{
- // 濡傛灉鎵ц浜嗚嚜鍔ㄦ媶鍖咃紝閲嶆柊鑾峰彇鏈�鏂扮殑閿佸畾淇℃伅鍜屽簱瀛樹俊鎭�
+ _logger.LogInformation($"鎵ц浜嗚嚜鍔ㄦ媶鍖咃紝閲嶆柊鑾峰彇鏁版嵁");
+
+ // 閲嶆柊鑾峰彇鏈�鏂扮殑閿佸畾淇℃伅鍜屽簱瀛樹俊鎭�
var refreshedValidation = await ValidatePickingRequest(orderNo, palletCode, barcode);
if (!refreshedValidation.IsValid)
{
@@ -281,40 +299,56 @@
}
(lockInfo, orderDetail, stockDetail, batch) = refreshedValidation.Data;
+
+ // 銆愰噸瑕併�戣皟鐢ㄨ嚜鍔ㄦ媶鍖呭悗楠岃瘉
+ decimal splitQuantity = autoSplitResult.FirstOrDefault()?.quantityTotal.ObjToDecimal()??0 ;
+ bool autoSplitValid = await ValidateAfterAutoSplit(lockInfo, orderDetail, stockDetail, splitQuantity,originalStockQtyBeforeSplit);
- var actualPickedQty = lockInfo.AssignQuantity;
- var pickingResult = await ExecutePickingLogic(lockInfo, orderDetail, stockDetail, actualPickedQty);
+ if (!autoSplitValid)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return WebResponseContent.Instance.Error("鑷姩鎷嗗寘鍚庢暟鎹獙璇佸け璐ワ紝璇锋鏌ョ郴缁熸棩蹇�");
+ }
- // 鏇存柊鎵规鍜岃鍗曟暟鎹�
- await UpdateBatchAndOrderData(batch, orderDetail, actualPickedQty, orderNo);
-
- // 璁板綍鎷i�夊巻鍙�
- await RecordPickingHistory(pickingResult, orderNo, palletCode);
-
- _unitOfWorkManage.CommitTran();
-
- return WebResponseContent.Instance.OK("鑷姩鎷嗗寘骞跺垎鎷f垚鍔�", autoSplitResult);
+ _logger.LogInformation($"鑷姩鎷嗗寘楠岃瘉閫氳繃锛岀户缁墽琛屽垎鎷�");
}
- // 姝e父鍒嗘嫞娴佺▼锛堜笉闇�瑕佽嚜鍔ㄦ媶鍖咃級
- var normalPickedQty = lockInfo.AssignQuantity;
- var normalPickingResult = await ExecutePickingLogic(lockInfo, orderDetail, stockDetail, normalPickedQty);
+ // 3. 璁$畻瀹為檯鎷i�夋暟閲�
+ decimal actualPickedQty = lockInfo.AssignQuantity - lockInfo.PickedQty;
- // 鏇存柊鎵规鍜岃鍗曟暟鎹�
- await UpdateBatchAndOrderData(batch, orderDetail, normalPickedQty, orderNo);
+ if (actualPickedQty <= 0)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return WebResponseContent.Instance.Error("璇ユ潯鐮佸凡鎷i�夊畬鎴愶紝鏃犻渶閲嶅鎷i��");
+ }
- // 璁板綍鎷i�夊巻鍙�
- await RecordPickingHistory(normalPickingResult, orderNo, palletCode);
+ _logger.LogInformation($"寮�濮嬫嫞閫� - 鏁伴噺: {actualPickedQty}");
+
+ // 4. 鎵ц鍒嗘嫞閫昏緫
+ var pickingResult = await ExecutePickingLogic(lockInfo, orderDetail, stockDetail, actualPickedQty);
+
+ // 5. 鏇存柊鎵规鍜岃鍗曟暟鎹�
+ await UpdateBatchAndOrderData(batch, orderDetail, actualPickedQty, orderNo);
+
+ // 6. 璁板綍鎷i�夊巻鍙�
+ await RecordPickingHistory(pickingResult, orderNo, palletCode);
+
+ // 7. 鎷i�夊悗楠岃瘉
+ await ValidateAfterPicking(orderNo, palletCode, barcode, actualPickedQty);
_unitOfWorkManage.CommitTran();
return WebResponseContent.Instance.OK("鍒嗘嫞鎴愬姛", new
{
- PickedQuantity = normalPickedQty,
+ PickedQuantity = actualPickedQty,
Barcode = barcode,
MaterialCode = lockInfo.MaterielCode,
- AutoSplitted = false
+ AutoSplitted = autoSplitResult != null,
+ RemainingStock = stockDetail.StockQuantity,
+ CurrentOutbound = stockDetail.OutboundQuantity,
+ // 濡傛灉鏄嚜鍔ㄦ媶鍖咃紝杩斿洖鐩稿叧淇℃伅
+ UnallocatedCreated = autoSplitResult != null ? "鏄�" : "鍚�"
});
}
catch (Exception ex)
@@ -324,6 +358,260 @@
return WebResponseContent.Instance.Error($"鍒嗘嫞澶辫触锛歿ex.Message}");
}
}
+
+
+ /// <summary>
+ /// 鑷姩鎷嗗寘鍚庨獙璇佹暟鎹竴鑷存�� - 淇鐗�
+ /// 閲嶇偣淇锛氭纭殑鍘熷簱瀛樻湡鏈涘�艰绠�
+ /// </summary>
+ private async Task<bool> ValidateAfterAutoSplit(Dt_OutStockLockInfo lockInfo, Dt_OutboundOrderDetail orderDetail,
+ Dt_StockInfoDetail originalStockDetail, decimal splitQuantity, decimal originalStockQtyBeforeSplit)
+ {
+ try
+ {
+ _logger.LogInformation($"寮�濮嬭嚜鍔ㄦ媶鍖呭悗楠岃瘉 - 鍘熸潯鐮�: {originalStockDetail.Barcode}, 鎷嗗寘鏁伴噺: {splitQuantity}");
+ _logger.LogInformation($"鎷嗗寘鍓嶅師搴撳瓨鏁伴噺: {originalStockQtyBeforeSplit}, 鍒嗛厤鏁伴噺: {lockInfo.AssignQuantity}");
+
+ bool allValid = true;
+ List<string> validationErrors = new List<string>();
+
+ // 1. 閲嶆柊鑾峰彇鏈�鏂扮殑鏁版嵁锛堟媶鍖呭悗鐨勫綋鍓嶇姸鎬侊級
+ var refreshedOrderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
+ .FirstAsync(x => x.Id == orderDetail.Id);
+
+ var refreshedLockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .FirstAsync(x => x.Id == lockInfo.Id);
+
+ var refreshedStockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .FirstAsync(x => x.Id == originalStockDetail.Id);
+
+ // 2. 銆愭牳蹇冧慨姝c�戦獙璇佸師搴撳瓨鏄庣粏鏁版嵁
+ // 閲嶈锛氭媶鍖呭悗鍘熷簱瀛樼殑鏈熸湜鍊� = 鍒嗛厤鏁伴噺 (鍥犱负鑷姩鎷嗗寘鏃讹紝鍘熷簱瀛樺簲鍙繚鐣欏垎閰嶆暟閲�)
+ decimal expectedOriginalStockQty = lockInfo.AssignQuantity; // 搴旇鏄�120锛岃�屼笉鏄敤璁$畻
+
+ _logger.LogInformation($"搴撳瓨楠岃瘉鍩哄噯:");
+ _logger.LogInformation($" 鎷嗗寘鍓嶅師搴撳瓨: {originalStockQtyBeforeSplit}");
+ _logger.LogInformation($" 鍒嗛厤鏁伴噺: {lockInfo.AssignQuantity}");
+ _logger.LogInformation($" 鎷嗗寘鏁伴噺: {splitQuantity}");
+ _logger.LogInformation($" 鏈熸湜鍘熷簱瀛�: {expectedOriginalStockQty}");
+ _logger.LogInformation($" 瀹為檯鍘熷簱瀛�: {refreshedStockDetail.StockQuantity}");
+
+ // 鍏佽灏戦噺璇樊鐨勯獙璇�
+ if (Math.Abs(refreshedStockDetail.StockQuantity - expectedOriginalStockQty) > 0.01m)
+ {
+ // 棰濆妫�鏌ワ細濡傛灉鍘熷簱瀛樻暟閲忎笉鍚堢悊锛屽彲鑳芥槸鏁版嵁闂
+ if (refreshedStockDetail.StockQuantity < 0)
+ {
+ string error = $"鍘熷簱瀛樻暟閲忓紓甯革紙璐熸暟锛夛紒瀹為檯: {refreshedStockDetail.StockQuantity}";
+ validationErrors.Add(error);
+ allValid = false;
+ _logger.LogError(error);
+ }
+ else if (refreshedStockDetail.StockQuantity > originalStockQtyBeforeSplit)
+ {
+ string error = $"鍘熷簱瀛樻暟閲忓紓甯革紙澶т簬鎷嗗寘鍓嶏級锛佹媶鍖呭墠: {originalStockQtyBeforeSplit}, 褰撳墠: {refreshedStockDetail.StockQuantity}";
+ validationErrors.Add(error);
+ allValid = false;
+ _logger.LogError(error);
+ }
+ else
+ {
+ // 鍙兘鏄悎鐞嗙殑璇樊锛岃褰曡鍛婁絾涓嶆爣璁颁负澶辫触
+ _logger.LogWarning($"鍘熷簱瀛樻暟閲忎笌鏈熸湜鍊兼湁宸紓锛屾湡鏈�: {expectedOriginalStockQty}, 瀹為檯: {refreshedStockDetail.StockQuantity}");
+ }
+ }
+
+ // 楠岃瘉鍘熷簱瀛樼殑鍑哄簱鏁伴噺鏄惁淇濇寔涓嶅彉
+ if (Math.Abs(refreshedStockDetail.OutboundQuantity - originalStockDetail.OutboundQuantity) > 0.01m)
+ {
+ string error = $"鍘熷簱瀛樺嚭搴撴暟閲忎笉搴斿彉鍖栵紒鎷嗗寘鍓�: {originalStockDetail.OutboundQuantity}, 鎷嗗寘鍚�: {refreshedStockDetail.OutboundQuantity}";
+ validationErrors.Add(error);
+ allValid = false;
+ _logger.LogError(error);
+ }
+
+ // 3. 楠岃瘉鏂板簱瀛樻槑缁嗭紙鎷嗗寘浜х敓鐨勶級
+ // 鏌ユ壘鏂版潯鐮侊紙閫氳繃鎷嗗寘璁板綍锛�
+ var splitRecords = await _splitPackageService.Db.Queryable<Dt_SplitPackageRecord>()
+ .Where(x => x.OutStockLockInfoId == lockInfo.Id &&
+ !x.IsReverted &&
+ x.IsAutoSplit == true)
+ .OrderByDescending(x => x.SplitTime)
+ .ToListAsync();
+
+ if (splitRecords.Any())
+ {
+ var latestSplit = splitRecords.First();
+ if (!string.IsNullOrEmpty(latestSplit.NewBarcode))
+ {
+ var newStockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .FirstAsync(x => x.Barcode == latestSplit.NewBarcode && x.StockId == originalStockDetail.StockId);
+
+ if (newStockDetail != null)
+ {
+ // 鏂板簱瀛樼殑鏈熸湜鍊� = 鎷嗗寘鏁伴噺
+ decimal expectedNewStockQty = splitQuantity;
+
+ _logger.LogInformation($"鏂板簱瀛橀獙璇�:");
+ _logger.LogInformation($" 鏂版潯鐮�: {newStockDetail.Barcode}");
+ _logger.LogInformation($" 鏈熸湜鏁伴噺: {expectedNewStockQty}");
+ _logger.LogInformation($" 瀹為檯鏁伴噺: {newStockDetail.StockQuantity}");
+ _logger.LogInformation($" 鍑哄簱鏁伴噺: {newStockDetail.OutboundQuantity} (搴斾负0)");
+
+ if (Math.Abs(newStockDetail.StockQuantity - expectedNewStockQty) > 0.01m)
+ {
+ string error = $"鏂板簱瀛樻暟閲忎笉姝g‘锛佹湡鏈�: {expectedNewStockQty}, 瀹為檯: {newStockDetail.StockQuantity}";
+ validationErrors.Add(error);
+ allValid = false;
+ _logger.LogError(error);
+ }
+
+ // 鏂板簱瀛樺嚭搴撴暟閲忓簲涓�0
+ if (Math.Abs(newStockDetail.OutboundQuantity - 0) > 0.01m)
+ {
+ string error = $"鏂板簱瀛樺嚭搴撴暟閲忎笉涓�0锛佸疄闄�: {newStockDetail.OutboundQuantity}";
+ validationErrors.Add(error);
+ allValid = false;
+ _logger.LogError(error);
+ }
+ }
+ }
+ }
+
+ // 4. 楠岃瘉鏈垎閰嶉攣瀹氳褰�
+ var unallocatedLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.ParentLockId == lockInfo.Id &&
+ x.IsUnallocated == 1 &&
+ x.OrderDetailId == 0)
+ .ToListAsync();
+
+ if (!unallocatedLocks.Any())
+ {
+ string error = $"鏈壘鍒拌嚜鍔ㄦ媶鍖呭垱寤虹殑鏈垎閰嶉攣瀹氳褰�";
+ validationErrors.Add(error);
+ allValid = false;
+ _logger.LogError(error);
+ }
+
+ // 5. 楠岃瘉璁㈠崟鏄庣粏鏁版嵁鏈敼鍙�
+ if (Math.Abs(refreshedOrderDetail.AllocatedQuantity - orderDetail.AllocatedQuantity) > 0.01m)
+ {
+ string error = $"璁㈠崟鏄庣粏鍒嗛厤鏁伴噺寮傚父鍙樺寲锛佹媶鍖呭墠: {orderDetail.AllocatedQuantity}, 鎷嗗寘鍚�: {refreshedOrderDetail.AllocatedQuantity}";
+ validationErrors.Add(error);
+ allValid = false;
+ _logger.LogError(error);
+ }
+
+ // 6. 楠岃瘉鍘熼攣瀹氳褰曟暟鎹湭鏀瑰彉锛堝垎閰嶆暟閲忎笉鍙橈級
+ if (Math.Abs(refreshedLockInfo.AssignQuantity - lockInfo.AssignQuantity) > 0.01m)
+ {
+ string error = $"閿佸畾璁板綍鍒嗛厤鏁伴噺寮傚父鍙樺寲锛佹媶鍖呭墠: {lockInfo.AssignQuantity}, 鎷嗗寘鍚�: {refreshedLockInfo.AssignQuantity}";
+ validationErrors.Add(error);
+ allValid = false;
+ _logger.LogError(error);
+ }
+
+ // 7. 銆愭柊澧炪�戦獙璇佹�诲簱瀛樺畧鎭�
+ // 鎷嗗寘鍓嶆�诲簱瀛� = 鍘熷簱瀛樻暟閲�
+ // 鎷嗗寘鍚庢�诲簱瀛� = 鍘熷簱瀛樼幇鏈夋暟閲� + 鏂板簱瀛樻暟閲�
+ decimal totalStockAfterSplit = refreshedStockDetail.StockQuantity;
+ if (splitRecords.Any() && !string.IsNullOrEmpty(splitRecords.First().NewBarcode))
+ {
+ var newStock = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .FirstAsync(x => x.Barcode == splitRecords.First().NewBarcode);
+ if (newStock != null)
+ {
+ totalStockAfterSplit += newStock.StockQuantity;
+ }
+ }
+
+ _logger.LogInformation($"搴撳瓨瀹堟亽楠岃瘉:");
+ _logger.LogInformation($" 鎷嗗寘鍓嶆�诲簱瀛�: {originalStockQtyBeforeSplit}");
+ _logger.LogInformation($" 鎷嗗寘鍚庢�诲簱瀛�: {totalStockAfterSplit}");
+ _logger.LogInformation($" 宸紓: {originalStockQtyBeforeSplit - totalStockAfterSplit}");
+
+ // 鍏佽寰堝皬鐨勬诞鐐规暟璇樊
+ if (Math.Abs(originalStockQtyBeforeSplit - totalStockAfterSplit) > 0.02m)
+ {
+ string error = $"搴撳瓨涓嶅畧鎭掞紒鎷嗗寘鍓�: {originalStockQtyBeforeSplit}, 鎷嗗寘鍚庢�诲簱瀛�: {totalStockAfterSplit}";
+ validationErrors.Add(error);
+ allValid = false;
+ _logger.LogError(error);
+ }
+
+ // 姹囨�婚獙璇佺粨鏋�
+ if (allValid)
+ {
+ _logger.LogInformation($"鉁� 鑷姩鎷嗗寘鍚庨獙璇佸叏閮ㄩ�氳繃");
+ }
+ else
+ {
+ string errorSummary = $"鑷姩鎷嗗寘鍚庨獙璇佸け璐ワ紝鍙戠幇{validationErrors.Count}涓棶棰橈細" +
+ string.Join("; ", validationErrors.Take(3));
+ _logger.LogError(errorSummary);
+
+ // 璁板綍璇︾粏闂鍒版棩蹇�
+ for (int i = 0; i < validationErrors.Count; i++)
+ {
+ _logger.LogError($"闂{i + 1}: {validationErrors[i]}");
+ }
+ }
+
+ return allValid;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError($"鑷姩鎷嗗寘鍚庨獙璇佸紓甯�: {ex.Message}");
+ return false;
+ }
+ }
+
+
+ /// <summary>
+ /// 鎷i�夊悗楠岃瘉
+ /// </summary>
+ private async Task ValidateAfterPicking(string orderNo, string palletCode, string barcode, decimal pickedQty)
+ {
+ try
+ {
+ _logger.LogInformation($"寮�濮嬫嫞閫夊悗楠岃瘉");
+
+ // 1. 楠岃瘉搴撳瓨鏄庣粏
+ var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .FirstAsync(x => x.Barcode == barcode);
+
+ // 2. 鏌ユ壘璇ユ潯鐮佺殑鎵�鏈夋嫞閫夎褰�
+ var pickingRecords = await Db.Queryable<Dt_PickingRecord>()
+ .Where(x => x.Barcode == barcode && x.OrderNo == orderNo && !x.IsCancelled)
+ .ToListAsync();
+
+ decimal totalPickedFromRecords = pickingRecords.Sum(x => x.PickQuantity);
+
+ _logger.LogInformation($"鎷i�夐獙璇� - 鏉$爜: {barcode}");
+ _logger.LogInformation($" 搴撳瓨鍑哄簱鏁伴噺: {stockDetail.OutboundQuantity}");
+ _logger.LogInformation($" 鎷i�夎褰曟�诲拰: {totalPickedFromRecords}");
+
+ if (Math.Abs(stockDetail.OutboundQuantity - totalPickedFromRecords) > 0.01m)
+ {
+ _logger.LogError($"鎷i�夋暟鎹笉涓�鑷达紒搴撳瓨鍑哄簱鏁伴噺({stockDetail.OutboundQuantity}) 鈮� 鎷i�夎褰曟�诲拰({totalPickedFromRecords})");
+
+ // 鑷姩淇锛氫互鎷i�夎褰曟�诲拰涓哄噯
+ decimal originalOutbound = stockDetail.OutboundQuantity;
+ stockDetail.OutboundQuantity = totalPickedFromRecords;
+ await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
+
+ _logger.LogWarning($"宸茶嚜鍔ㄤ慨澶嶅嚭搴撴暟閲�: {originalOutbound} -> {totalPickedFromRecords}");
+ }
+
+ _logger.LogInformation($"鎷i�夊悗楠岃瘉瀹屾垚");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError($"鎷i�夊悗楠岃瘉澶辫触: {ex.Message}");
+ }
+ }
+
+
/// <summary>
/// 鍙栨秷鍒嗘嫞
/// </summary>
@@ -459,13 +747,17 @@
}
}
+
/// <summary>
- /// 娓呯悊搴撳瓨淇℃伅 - 澧炲己鐗堟湰
+ /// 娓呯悊搴撳瓨淇℃伅 - 瀹屾暣淇鐗�
+ /// 纭繚OutboundQuantity姝g‘娓呴浂
/// </summary>
private async Task CleanupStockInfo(Dt_OutStockLockInfo lockInfo)
{
try
{
+ _logger.LogInformation($"娓呯悊搴撳瓨淇℃伅 - 閿佸畾ID: {lockInfo.Id}, 鏉$爜: {lockInfo.CurrentBarcode}");
+
// 鏌ユ壘閿佸畾鐨勫簱瀛樻槑缁�
var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
.FirstAsync(x => x.Barcode == lockInfo.CurrentBarcode && x.StockId == lockInfo.StockId);
@@ -473,44 +765,59 @@
if (stockDetail != null)
{
// 璁板綍娓呯悊鍓嶇殑鐘舵��
- decimal originalQty = stockDetail.StockQuantity;
+ decimal originalStockQty = stockDetail.StockQuantity;
+ decimal originalOutboundQty = stockDetail.OutboundQuantity;
int originalStatus = stockDetail.Status;
- // 濡傛灉搴撳瓨鏁伴噺澶т簬0锛岄渶瑕佸厛娓呴浂
- if (stockDetail.StockQuantity > 0)
+ _logger.LogInformation($"娓呯悊鍓嶇姸鎬� - 搴撳瓨: {originalStockQty}, 鍑哄簱: {originalOutboundQty}, 鐘舵��: {GetStockStatusName(originalStatus)}");
+
+ // 銆愰噸瑕併�戞鏌ュ簱瀛樻暟閲忔槸鍚﹀簲璇ヤ负0
+ // 濡傛灉閿佸畾鐘舵�佹槸鎷i�夊畬鎴愶紝鐞嗚涓婂簱瀛樺簲璇ヤ负0
+ if (lockInfo.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�)
{
- _logger.LogWarning($"鍙栬蛋绌烘墭鐩樻椂鍙戠幇鏉$爜 {lockInfo.CurrentBarcode} 杩樻湁搴撳瓨 {stockDetail.StockQuantity}锛岃嚜鍔ㄦ竻闆�");
- stockDetail.StockQuantity = 0;
- stockDetail.OutboundQuantity = 0;
+ if (stockDetail.StockQuantity > 0)
+ {
+ _logger.LogWarning($"鎷i�夊畬鎴愪絾搴撳瓨涓嶄负0 - 鏉$爜: {stockDetail.Barcode}, 搴撳瓨: {stockDetail.StockQuantity}");
+ }
}
- // 鏍囪涓哄凡娓呯悊鐘舵��
+ // 娓呯悊搴撳瓨鍜屽嚭搴撴暟閲�
+ stockDetail.StockQuantity = 0;
+ stockDetail.OutboundQuantity = 0; // 銆愪慨姝c�戠‘淇濆嚭搴撴暟閲忔竻闆�
stockDetail.Status = (int)StockStatusEmun.宸叉竻鐞�;
await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
- _logger.LogInformation($"娓呯悊搴撳瓨鏄庣粏 - 鏉$爜: {stockDetail.Barcode}, 鍘熺姸鎬�: {originalStatus} -> 宸叉竻鐞�, 鍘熸暟閲�: {originalQty} -> 0");
+ _logger.LogInformation($"娓呯悊搴撳瓨鏄庣粏瀹屾垚");
+ _logger.LogInformation($" 搴撳瓨鏁伴噺: {originalStockQty} -> 0");
+ _logger.LogInformation($" 鍑哄簱鏁伴噺: {originalOutboundQty} -> 0");
+ _logger.LogInformation($" 鐘舵��: {GetStockStatusName(originalStatus)} -> 宸叉竻鐞�");
}
else
{
_logger.LogWarning($"鏈壘鍒版潯鐮佸搴旂殑搴撳瓨鏄庣粏: {lockInfo.CurrentBarcode}");
}
- // 鍚屾椂娓呯悊璇ユ墭鐩樹笂鐨勬墍鏈夊簱瀛橈紙閬垮厤閬楁紡锛�
+ // 娓呯悊璇ユ墭鐩樹笂鐨勬墍鏈夊簱瀛橈紙閬垮厤閬楁紡锛�
var allStockDetails = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
.Where(x => x.StockId == lockInfo.StockId && x.StockQuantity > 0)
.ToListAsync();
if (allStockDetails.Any())
{
+ _logger.LogInformation($"娓呯悊鎵樼洏涓婂叾浠栧簱瀛� - 鍏� {allStockDetails.Count} 鏉¤褰�");
+
foreach (var stock in allStockDetails)
{
+ decimal originalQty = stock.StockQuantity;
+ decimal originalOutbound = stock.OutboundQuantity;
+
stock.StockQuantity = 0;
- stock.OutboundQuantity = 0;
+ stock.OutboundQuantity = 0; // 銆愪慨姝c�戠‘淇濆嚭搴撴暟閲忔竻闆�
stock.Status = (int)StockStatusEmun.宸叉竻鐞�;
await _stockInfoDetailService.Db.Updateable(stock).ExecuteCommandAsync();
- _logger.LogWarning($"娓呯悊閬楁紡搴撳瓨 - 鏉$爜: {stock.Barcode}, 鏁伴噺: {stock.StockQuantity} -> 0");
+ _logger.LogInformation($"娓呯悊閬楁紡搴撳瓨 - 鏉$爜: {stock.Barcode}, 搴撳瓨: {originalQty}->0, 鍑哄簱: {originalOutbound}->0");
}
}
}
@@ -520,7 +827,6 @@
// 涓嶆姏鍑哄紓甯革紝缁х画澶勭悊鍏朵粬璁板綍
}
}
-
/// <summary>
/// 鏇存柊璁㈠崟鐘舵��
@@ -556,17 +862,17 @@
/// </summary>
private async Task RecordEmptyPalletRemoval(string orderNo, string palletCode, List<Dt_OutStockLockInfo> completedLocks)
{
- var removalRecord = new Dt_EmptyPalletRemoval
- {
- OrderNo = orderNo,
- PalletCode = palletCode,
- RemovalTime = DateTime.Now,
- Operator = App.User.UserName,
- CompletedItemsCount = completedLocks.Count,
- TotalPickedQuantity = completedLocks.Sum(x => x.PickedQty)
- };
+ //var removalRecord = new Dt_EmptyPalletRemoval
+ //{
+ // OrderNo = orderNo,
+ // PalletCode = palletCode,
+ // RemovalTime = DateTime.Now,
+ // Operator = App.User.UserName,
+ // CompletedItemsCount = completedLocks.Count,
+ // TotalPickedQuantity = completedLocks.Sum(x => x.PickedQty)
+ //};
- await Db.Insertable(removalRecord).ExecuteCommandAsync();
+ //await Db.Insertable(removalRecord).ExecuteCommandAsync();
}
#endregion
@@ -597,7 +903,6 @@
}
};
}
-
#region 鎵嬪姩鎷嗗寘
@@ -737,8 +1042,10 @@
return lockInfos.Sum(x => x.AssignQuantity);
}
+
+
/// <summary>
- /// 鎵ц鎵嬪姩鎷嗗寘閫昏緫 - 瀹屾暣鐗堟湰
+ /// 鎵ц鎵嬪姩鎷嗗寘閫昏緫 - 淇鐗堟湰
/// </summary>
private async Task<List<SplitResult>> ExecuteManualSplitLogic(Dt_OutStockLockInfo lockInfo, Dt_StockInfoDetail stockDetail,
decimal splitQuantity, string palletCode)
@@ -782,15 +1089,22 @@
decimal originalStockQty = stockDetail.StockQuantity;
decimal originalOutboundQty = stockDetail.OutboundQuantity;
- // 鍒涘缓鏂板簱瀛樻槑缁�
+ // 淇锛氳绠楁柊搴撳瓨鏄庣粏鐨勬纭暟閲�
+ // 鏂版潯鐮佸簲璇ュ彧鏈夋媶鍖呮暟閲忥紝鑰屼笉鏄�2鍊�
+ decimal newStockQuantity = splitQuantity;
+ decimal originalRemainingStockQuantity = originalStockQty - splitQuantity;
+
+ _logger.LogInformation($"鏁伴噺鍒嗛厤 - 鏂版潯鐮佹暟閲�: {newStockQuantity}, 鍘熸潯鐮佸墿浣欐暟閲�: {originalRemainingStockQuantity}");
+
+ // 鍒涘缓鏂板簱瀛樻槑缁� - 淇鏁伴噺闂
var newStockDetail = new Dt_StockInfoDetail
{
StockId = stockDetail.StockId,
MaterielCode = stockDetail.MaterielCode,
OrderNo = stockDetail.OrderNo,
BatchNo = stockDetail.BatchNo,
- StockQuantity = splitQuantity,
- OutboundQuantity = 0,
+ StockQuantity = newStockQuantity, // 淇锛氫娇鐢ㄦ纭殑鎷嗗寘鏁伴噺
+ OutboundQuantity = 0, // 鏂版潯鐮佸垵濮嬪嚭搴撴暟閲忎负0
Barcode = newBarcode,
Status = (int)StockStatusEmun.鍑哄簱閿佸畾,
SupplyCode = stockDetail.SupplyCode,
@@ -802,11 +1116,10 @@
};
await _stockInfoDetailService.Db.Insertable(newStockDetail).ExecuteCommandAsync();
- _logger.LogInformation($"鍒涘缓鏂板簱瀛樻槑缁嗘垚鍔� - 鏉$爜: {newBarcode}, 搴撳瓨鏁伴噺: {splitQuantity}");
+ _logger.LogInformation($"鍒涘缓鏂板簱瀛樻槑缁嗘垚鍔� - 鏉$爜: {newBarcode}, 搴撳瓨鏁伴噺: {newStockQuantity}");
// 淇锛氭洿鏂板師搴撳瓨鏄庣粏 - 纭繚鏁版嵁涓�鑷存��
- // 鍘熷簱瀛樺噺灏戞媶鍖呮暟閲忥紝浣嗗嚭搴撴暟閲忎繚鎸佷笉鍙橈紙鍥犱负鏄墜鍔ㄦ媶鍖咃紝涓嶆秹鍙婂疄闄呭嚭搴擄級
- stockDetail.StockQuantity -= splitQuantity;
+ stockDetail.StockQuantity = originalRemainingStockQuantity;
// 纭繚涓嶄細涓鸿礋鏁�
if (stockDetail.StockQuantity < 0)
@@ -815,8 +1128,8 @@
stockDetail.StockQuantity = 0;
}
- // 鍑哄簱鏁伴噺淇濇寔涓嶅彉
- // stockDetail.OutboundQuantity = stockDetail.OutboundQuantity; // 淇濇寔涓嶅彉
+ // 鍑哄簱鏁伴噺淇濇寔涓嶅彉锛屽洜涓烘槸鎷嗗寘锛屼笉鏄疄闄呭嚭搴�
+ // stockDetail.OutboundQuantity = stockDetail.OutboundQuantity;
await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
_logger.LogInformation($"鏇存柊鍘熷簱瀛樻槑缁� - 鏉$爜: {stockDetail.Barcode}, " +
@@ -827,7 +1140,7 @@
var newLockInfo = new Dt_OutStockLockInfo
{
OrderNo = lockInfo.OrderNo,
- OrderDetailId = lockInfo.OrderDetailId, // 缁戝畾鍒板悓涓�涓鍗曟槑缁�
+ OrderDetailId = lockInfo.OrderDetailId,
OutboundBatchNo = lockInfo.OutboundBatchNo,
MaterielCode = lockInfo.MaterielCode,
MaterielName = lockInfo.MaterielName,
@@ -864,18 +1177,14 @@
_logger.LogInformation($"鏇存柊鍘熼攣瀹氫俊鎭� - 鍒嗛厤鏁伴噺: {originalLockAssignQty} -> {lockInfo.AssignQuantity}, " +
$"璁㈠崟鏁伴噺: {originalLockOrderQty} -> {lockInfo.OrderQuantity}");
- // 閲嶈锛氭墜鍔ㄦ媶鍖呬笉鏀瑰彉璁㈠崟鏄庣粏鐨勬�诲垎閰嶆暟閲�
- // 楠岃瘉璁㈠崟鏄庣粏鐨勬�诲垎閰嶆暟閲忔槸鍚︿繚鎸佷笉鍙�
- await ValidateOrderDetailAllocationAfterSplit(lockInfo.OrderDetailId, originalLockAssignQty);
+ // 楠岃瘉鎷嗗寘鍚庢暟鎹竴鑷存��
+ await ValidateDataConsistencyAfterSplit(lockInfo.OrderDetailId, originalLockAssignQty, originalLockOrderQty);
// 璁板綍鎷嗗寘鍘嗗彶
await RecordSplitHistory(lockInfo, stockDetail, splitQuantity, newBarcode, false, originalStockQty);
// 鍒涘缓鎷嗗寘缁撴灉鍒楄〃
var splitResults = CreateSplitResults(lockInfo, splitQuantity, remainQty, newBarcode, stockDetail.Barcode);
-
- // 楠岃瘉鎷嗗寘鍚庢暟鎹竴鑷存��
- await ValidateDataConsistencyAfterSplit(lockInfo.OrderDetailId, originalLockAssignQty, originalLockOrderQty);
_logger.LogInformation($"鎵嬪姩鎷嗗寘閫昏緫鎵ц瀹屾垚 - 鍘熸潯鐮�: {stockDetail.Barcode}, 鏂版潯鐮�: {newBarcode}, 鎷嗗寘鏁伴噺: {splitQuantity}");
@@ -887,6 +1196,7 @@
throw;
}
}
+
/// <summary>
/// 楠岃瘉鎷嗗寘鍚庤鍗曟槑缁嗙殑鍒嗛厤鏁伴噺鏄惁淇濇寔涓嶅彉
/// </summary>
@@ -965,8 +1275,6 @@
}
}
#endregion
-
-
#region 鍙栨秷鎷嗗寘
@@ -1864,136 +2172,7 @@
return totalQty;
}
-
- /// <summary>
- /// 缁熶竴鍥炲簱鏂规硶 - 澶勭悊鎵樼洏涓婃墍鏈夊墿浣欒揣鐗�
- /// </summary>
- //public async Task<WebResponseContent> ExecutePalletReturn(string orderNo, string palletCode, string returnReason = "鍒嗘壒鍥炲簱")
- //{
- // try
- // {
- // int stockId = 0;
- // Dt_StockInfo stockInfo = null;
- // PalletStatusAnalysis statusAnalysis = null;
- // _unitOfWorkManage.BeginTran();
-
- // if (string.IsNullOrEmpty(orderNo) || string.IsNullOrEmpty(palletCode))
- // return WebResponseContent.Instance.Error("璁㈠崟鍙峰拰鎵樼洏鐮佷笉鑳戒负绌�");
-
- // // 鑾峰彇搴撳瓨淇℃伅
- // stockInfo = await _stockInfoService.Db.Queryable<Dt_StockInfo>()
- // .FirstAsync(x => x.PalletCode == palletCode);
- // if (stockInfo == null)
- // return WebResponseContent.Instance.Error($"鏈壘鍒版墭鐩� {palletCode} 瀵瑰簲鐨勫簱瀛樹俊鎭�");
-
- // stockId = stockInfo.Id;
-
- // var beforeValidationResult = await ValidateReturnData(orderNo, palletCode, stockId, true);
- // if (!beforeValidationResult)
- // {
- // _logger.LogWarning("鍥炲簱鍓嶆暟鎹獙璇佸彂鐜伴棶棰橈紝浣嗙户缁墽琛屽洖搴撴搷浣�");
- // }
- // _logger.LogInformation($"姝ラ4瀹屾垚: 鍥炲簱鍓嶆暟鎹獙璇亄(beforeValidationResult ? "閫氳繃" : "鍙戠幇闂")}");
-
-
- // // 鍒嗘瀽鎵樼洏鐘舵��
- // statusAnalysis = await AnalyzePalletStatusForReturn(orderNo, palletCode, stockInfo.Id);
- // _logger.LogInformation($"銆愭楠�6銆戞墭鐩樼姸鎬佸垎鏋愬畬鎴�");
- // _logger.LogInformation($" - 鏄惁鏈夊洖搴撶墿鍝�: {statusAnalysis.HasItemsToReturn}");
- // _logger.LogInformation($" - 鏄惁绌烘墭鐩�: {statusAnalysis.IsEmptyPallet}");
- // _logger.LogInformation($" - 鎬诲洖搴撴暟閲�: {statusAnalysis.TotalReturnQty}");
- // _logger.LogInformation($" - 鏉$爜鏁伴噺: {statusAnalysis.AllBarcodes.Count}");
-
- // if (!statusAnalysis.HasItemsToReturn)
- // {
- // _logger.LogInformation($"銆愭楠�7銆戞棤鍥炲簱鐗╁搧锛屽鐞嗙┖鎵樼洏");
- // var result = await HandleEmptyPalletReturn(orderNo, palletCode, stockInfo);
- // if (result.Status)
- // {
- // _unitOfWorkManage.CommitTran();
- // _logger.LogInformation($"銆愮┖鎵樼洏鍥炲簱鎴愬姛銆戣鍗�: {orderNo}, 鎵樼洏: {palletCode}");
- // }
- // else
- // {
- // _unitOfWorkManage.RollbackTran();
- // _logger.LogError($"銆愮┖鎵樼洏鍥炲簱澶辫触銆戝師鍥�: {result.Message}");
- // }
- // return result;
- // }
-
- // _logger.LogInformation($"寮�濮嬪洖搴撴搷浣� - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}, 鍥炲簱鏁伴噺: {statusAnalysis.TotalReturnQty}");
-
- // try
- // {
- // // 鎵ц鍥炲簱鏁版嵁鎿嶄綔
- // await ExecuteReturnDataOperations(statusAnalysis);
- // }
- // catch (Exception ex)
- // {
- // _logger.LogError($"鍥炲簱鏁版嵁鎿嶄綔澶辫触: {ex.Message}");
- // try
- // {
- // await ExecuteSimpleReturnDataOperations(statusAnalysis);
- // _logger.LogInformation($"绠�鍖栧洖搴撴暟鎹搷浣滄垚鍔�");
- // }
- // catch (Exception simpleEx)
- // {
- // _logger.LogError($"绠�鍖栧洖搴撴暟鎹搷浣滀篃澶辫触 - {simpleEx.Message}");
- // throw new InvalidOperationException($"鍥炲簱鏁版嵁鎿嶄綔澶辫触锛屼富鏂规硶: {ex.Message}, 绠�鍖栨柟娉�: {simpleEx.Message}", ex);
- // }
- // }
-
- // // 鏇存柊璁㈠崟鐘舵��
- // await UpdateOrderStatusAfterReturn(orderNo);
-
- // _unitOfWorkManage.CommitTran();
-
- // _logger.LogInformation($"姝ラ10: 寮�濮嬪洖搴撳悗鏁版嵁楠岃瘉");
- // var afterValidationResult = await ValidateReturnData(orderNo, palletCode, stockId, false);
- // if (!afterValidationResult)
- // {
- // _logger.LogWarning("鍥炲簱鍚庢暟鎹獙璇佸彂鐜伴棶棰橈紝寤鸿妫�鏌ユ暟鎹竴鑷存��");
- // }
- // _logger.LogInformation($"姝ラ10瀹屾垚: 鍥炲簱鍚庢暟鎹獙璇亄(afterValidationResult ? "閫氳繃" : "鍙戠幇闂")}");
-
- // try
- // {
- // await CreateReturnTask(orderNo, palletCode, stockInfo);
- // _logger.LogInformation($"姝ラ11鎴愬姛: 鍥炲簱浠诲姟鍒涘缓鎴愬姛");
- // }
- // catch (Exception taskEx)
- // {
- // // 浠诲姟鍒涘缓澶辫触涓嶅奖鍝嶅洖搴撴暟鎹搷浣滅殑鎴愬姛锛屽彧璁板綍閿欒
- // _logger.LogError($"姝ラ11璀﹀憡: 鍥炲簱浠诲姟鍒涘缓澶辫触 - {taskEx.Message}");
- // _logger.LogError($"鍥炲簱鏁版嵁鎿嶄綔宸叉垚鍔燂紝浣嗕换鍔″垱寤哄け璐ワ紝鍙兘闇�瑕佹墜鍔ㄥ鐞�");
- // }
-
- // _logger.LogInformation($"銆愬洖搴撴垚鍔熴�戣鍗�: {orderNo}, 鎵樼洏: {palletCode}, 鍥炲簱鏁伴噺: {statusAnalysis.TotalReturnQty}");
-
- // return WebResponseContent.Instance.OK($"鍥炲簱鎿嶄綔鎴愬姛锛屽叡鍥炲簱鏁伴噺锛歿statusAnalysis.TotalReturnQty}", new
- // {
- // ReturnQuantity = statusAnalysis.TotalReturnQty,
- // ReturnBarcodes = statusAnalysis.AllBarcodes,
- // Reason = returnReason,
- // PalletCode = palletCode,
- // OrderNo = orderNo
- // });
- // }
- // catch (Exception ex)
- // {
- // _unitOfWorkManage.RollbackTran();
- // _logger.LogError($"銆愬洖搴撳け璐ャ�戣鍗�: {orderNo}, 鎵樼洏: {palletCode}, 閿欒绫诲瀷: {ex.GetType().Name}");
- // _logger.LogError($"銆愰敊璇俊鎭�憑ex.Message}");
- // _logger.LogError($"銆愬爢鏍堜俊鎭�憑ex.StackTrace}");
-
- // if (ex.InnerException != null)
- // {
- // _logger.LogError($"銆愬唴閮ㄩ敊璇�憑ex.InnerException.Message}");
- // }
- // return WebResponseContent.Instance.Error($"鍥炲簱鎿嶄綔澶辫触: {ex.Message}");
- // }
- //}
-
+
/// <summary>
/// 缁熶竴鍥炲簱鏂规硶
/// </summary>
@@ -2005,11 +2184,11 @@
_unitOfWorkManage.BeginTran();
- // 1. 鍩虹楠岃瘉
+ // 鍩虹楠岃瘉
if (string.IsNullOrEmpty(orderNo) || string.IsNullOrEmpty(palletCode))
return WebResponseContent.Instance.Error("璁㈠崟鍙峰拰鎵樼洏鐮佷笉鑳戒负绌�");
- // 2. 鑾峰彇搴撳瓨淇℃伅
+ // 鑾峰彇搴撳瓨淇℃伅
var stockInfo = await _stockInfoService.Db.Queryable<Dt_StockInfo>()
.FirstAsync(x => x.PalletCode == palletCode);
@@ -2018,7 +2197,7 @@
int stockId = stockInfo.Id;
- // 3. 鎵ц鍥炲簱鍓嶆暟鎹獙璇�
+ // 鎵ц鍥炲簱鍓嶆暟鎹獙璇�
var validationResult = await ValidateDataBeforeReturn(orderNo, palletCode, stockId);
if (!validationResult.IsValid)
{
@@ -2026,7 +2205,7 @@
// 鍙互鏍规嵁瀹為檯鎯呭喌鍐冲畾鏄惁缁х画
}
- // 4. 鍒嗘瀽鎵樼洏鐘舵��
+ // 鍒嗘瀽鎵樼洏鐘舵��
var statusAnalysis = await AnalyzePalletStatusForReturn(orderNo, palletCode, stockInfo.Id);
if (!statusAnalysis.HasItemsToReturn)
@@ -2048,7 +2227,7 @@
_logger.LogInformation($"銆愬紑濮嬪洖搴撱�戞�诲洖搴撴暟閲�: {statusAnalysis.TotalReturnQty}, 鏉$爜鏁�: {statusAnalysis.AllBarcodes.Count}");
- // 5. 鎵ц鍥炲簱鎿嶄綔
+ // 鎵ц鍥炲簱鎿嶄綔
try
{
await ExecuteEnhancedReturnOperations(statusAnalysis);
@@ -2060,12 +2239,12 @@
await ExecuteSimpleReturnDataOperations(statusAnalysis);
}
- // 6. 鏇存柊璁㈠崟鐘舵��
+ // 鏇存柊璁㈠崟鐘舵��
await UpdateOrderStatusAfterReturn(orderNo);
- _unitOfWorkManage.CommitTran();
+
- // 7. 鍒涘缓鍥炲簱浠诲姟
+ // 鍒涘缓鍥炲簱浠诲姟
try
{
await CreateReturnTask(orderNo, palletCode, stockInfo);
@@ -2174,40 +2353,569 @@
}
}
- /// <summary>
- /// 鎵ц澧炲己鐨勫洖搴撴搷浣�
+ // <summary>
+ /// 鎵ц澧炲己鐨勫洖搴撴搷浣� - 淇鐗堬紙閬垮厤閲嶅澶勭悊锛�
/// </summary>
private async Task ExecuteEnhancedReturnOperations(PalletStatusAnalysis statusAnalysis)
{
- _logger.LogInformation($"鎵ц澧炲己鍥炲簱鎿嶄綔 - 璁㈠崟: {statusAnalysis.OrderNo}, 鎵樼洏: {statusAnalysis.PalletCode}");
+ _logger.LogInformation($"銆愬紑濮嬫墽琛屽洖搴撴搷浣溿�戣鍗�: {statusAnalysis.OrderNo}, 鎵樼洏: {statusAnalysis.PalletCode}");
- // 澶勭悊宸插垎閰嶇殑閿佸畾璁板綍
+ // 浣跨敤鏈湴宸插鐞嗛泦鍚堬紝閬垮厤閲嶅
+ var locallyProcessedBarcodes = new HashSet<string>();
+ decimal totalProcessedQty = 0;
+
+ // 1. 澶勭悊宸插垎閰嶇殑閿佸畾璁板綍
if (statusAnalysis.HasRemainingLocks)
{
- await HandleAllocatedLocksReturn(statusAnalysis.RemainingLocks);
+ _logger.LogInformation($"澶勭悊宸插垎閰嶉攣瀹氳褰� - {statusAnalysis.RemainingLocks.Count} 鏉�");
+ foreach (var lockInfo in statusAnalysis.RemainingLocks)
+ {
+ if (string.IsNullOrEmpty(lockInfo.CurrentBarcode) ||
+ locallyProcessedBarcodes.Contains(lockInfo.CurrentBarcode))
+ {
+ _logger.LogInformation($"璺宠繃宸插鐞嗘潯鐮佺殑閿佸畾璁板綍: {lockInfo.CurrentBarcode}");
+ continue;
+ }
+
+ decimal returnQty = lockInfo.AssignQuantity - lockInfo.PickedQty;
+ if (returnQty > 0)
+ {
+ // 銆愪慨澶嶃�戜紶閫� isUnallocated = false
+ await ProcessSingleBarcodeReturn(lockInfo.CurrentBarcode, statusAnalysis.StockId, returnQty, false);
+ locallyProcessedBarcodes.Add(lockInfo.CurrentBarcode);
+ totalProcessedQty += returnQty;
+ _logger.LogInformation($"宸插鐞嗛攣瀹氳褰� - 鏉$爜: {lockInfo.CurrentBarcode}, 鏁伴噺: {returnQty}");
+ }
+ }
}
- // 澶勭悊鏈垎閰嶇殑閿佸畾璁板綍
+ // 2. 澶勭悊鏈垎閰嶇殑閿佸畾璁板綍
if (statusAnalysis.HasUnallocatedLocks)
{
- await HandleUnallocatedLocksReturn(statusAnalysis.UnallocatedLocks);
+ _logger.LogInformation($"澶勭悊鏈垎閰嶉攣瀹氳褰� - {statusAnalysis.UnallocatedLocks.Count} 鏉�");
+ foreach (var lockInfo in statusAnalysis.UnallocatedLocks)
+ {
+ if (string.IsNullOrEmpty(lockInfo.CurrentBarcode) ||
+ locallyProcessedBarcodes.Contains(lockInfo.CurrentBarcode))
+ {
+ _logger.LogInformation($"璺宠繃宸插鐞嗘潯鐮佺殑鏈垎閰嶉攣瀹�: {lockInfo.CurrentBarcode}");
+ continue;
+ }
+
+ decimal returnQty = lockInfo.AssignQuantity - lockInfo.PickedQty;
+ if (returnQty > 0)
+ {
+ // 銆愪慨澶嶃�戜娇鐢ㄤ笓闂ㄧ殑鏈垎閰嶉攣瀹氬鐞嗘柟娉�
+ await ProcessUnallocatedLockReturn(lockInfo, returnQty);
+ locallyProcessedBarcodes.Add(lockInfo.CurrentBarcode);
+ totalProcessedQty += returnQty;
+ _logger.LogInformation($"宸插鐞嗘湭鍒嗛厤閿佸畾 - 鏉$爜: {lockInfo.CurrentBarcode}, 鏁伴噺: {returnQty}");
+ }
+ }
}
- // 澶勭悊鏈垎閰嶇殑搴撳瓨璐х墿
+ // 3. 澶勭悊鏈垎閰嶇殑搴撳瓨璐х墿
if (statusAnalysis.HasPalletStockGoods)
{
- await HandleUnallocatedStockReturn(statusAnalysis.PalletStockGoods);
+ _logger.LogInformation($"澶勭悊鏈垎閰嶅簱瀛樿揣鐗� - {statusAnalysis.PalletStockGoods.Count} 涓�");
+ foreach (var stockDetail in statusAnalysis.PalletStockGoods)
+ {
+ if (string.IsNullOrEmpty(stockDetail.Barcode) ||
+ locallyProcessedBarcodes.Contains(stockDetail.Barcode))
+ {
+ _logger.LogInformation($"璺宠繃宸插鐞嗘潯鐮佺殑搴撳瓨: {stockDetail.Barcode}");
+ continue;
+ }
+
+ decimal returnQty = stockDetail.StockQuantity;
+ if (returnQty > 0)
+ {
+ await ProcessUnallocatedStockReturn(stockDetail);
+ locallyProcessedBarcodes.Add(stockDetail.Barcode);
+ totalProcessedQty += returnQty;
+ _logger.LogInformation($"宸插鐞嗘湭鍒嗛厤搴撳瓨 - 鏉$爜: {stockDetail.Barcode}, 鏁伴噺: {returnQty}");
+ }
+ }
}
- // 澶勭悊鎷嗗寘璁板綍
- if (statusAnalysis.HasSplitRecords)
+ // 4. 銆愪慨姝c�戝鐞嗘媶鍖呰褰� - 鍙鐞嗘湭琚叾浠栭�昏緫瑕嗙洊鐨勬潯鐮�
+ if (statusAnalysis.HasSplitRecords && statusAnalysis.SplitReturnQty > 0)
{
- await HandleSplitRecordsReturn(statusAnalysis.SplitRecords, statusAnalysis.StockId);
+ _logger.LogInformation($"澶勭悊鎷嗗寘璁板綍鐩稿叧搴撳瓨 - 鏂板鏁伴噺: {statusAnalysis.SplitReturnQty}");
+
+ // 鍙鐞嗗湪SplitRecords涓絾涓嶅湪宸插鐞嗛泦鍚堜腑鐨勬潯鐮�
+ var splitBarcodes = statusAnalysis.SplitRecords
+ .SelectMany(r => new[] { r.OriginalBarcode, r.NewBarcode })
+ .Where(b => !string.IsNullOrEmpty(b))
+ .Distinct()
+ .ToList();
+
+ foreach (var barcode in splitBarcodes)
+ {
+ if (locallyProcessedBarcodes.Contains(barcode))
+ {
+ _logger.LogInformation($"璺宠繃宸插鐞嗙殑鎷嗗寘鏉$爜: {barcode}");
+ continue;
+ }
+
+ var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .FirstAsync(x => x.Barcode == barcode && x.StockId == statusAnalysis.StockId);
+
+ if (stockDetail != null && stockDetail.StockQuantity > 0)
+ {
+ decimal returnQty = stockDetail.StockQuantity;
+ await ProcessSingleBarcodeReturn(barcode, statusAnalysis.StockId, returnQty);
+ locallyProcessedBarcodes.Add(barcode);
+ totalProcessedQty += returnQty;
+ _logger.LogInformation($"澶勭悊鎷嗗寘鏉$爜 - {barcode}, 鏁伴噺: {returnQty}");
+ }
+ }
+ }
+
+ _logger.LogInformation($"銆愬洖搴撴搷浣滃畬鎴愩�戞�诲鐞嗘暟閲�: {totalProcessedQty}, 澶勭悊鏉$爜鏁�: {locallyProcessedBarcodes.Count}");
+
+ // 楠岃瘉澶勭悊鏁伴噺涓庨鏈熶竴鑷�
+ if (Math.Abs(totalProcessedQty - statusAnalysis.TotalReturnQty) > 0.01m)
+ {
+ _logger.LogWarning($"澶勭悊鏁伴噺({totalProcessedQty})涓庨鏈�({statusAnalysis.TotalReturnQty})涓嶄竴鑷达紝浣嗙户缁墽琛�");
+ }
+ }
+
+
+ /// <summary>
+ /// 澶勭悊宸插垎閰嶉攣瀹氳褰曠殑鍥炲簱
+ /// 宸插垎閰嶉攣瀹氳褰曢渶瑕侊細1.鎭㈠搴撳瓨 2.鏇存柊閿佸畾鐘舵�� 3.鍑忓皯璁㈠崟鏄庣粏鍒嗛厤鏁伴噺
+ /// </summary>
+ private async Task ProcessSingleLockReturn(Dt_OutStockLockInfo lockInfo, decimal returnQty)
+ {
+ try
+ {
+ _logger.LogInformation($"寮�濮嬪鐞嗗凡鍒嗛厤閿佸畾璁板綍鍥炲簱 - 閿佸畾ID: {lockInfo.Id}, 鏉$爜: {lockInfo.CurrentBarcode}, 鍥炲簱鏁伴噺: {returnQty}");
+
+ if (returnQty <= 0)
+ {
+ _logger.LogInformation($"鍥炲簱鏁伴噺鏃犳晥({returnQty})锛岃烦杩囧鐞�");
+ return;
+ }
+
+ // 1. 楠岃瘉閿佸畾璁板綍鐘舵��
+ if (lockInfo.Status != (int)OutLockStockStatusEnum.鍑哄簱涓� &&
+ lockInfo.Status != (int)OutLockStockStatusEnum.鍥炲簱涓�)
+ {
+ _logger.LogWarning($"閿佸畾璁板綍鐘舵�佷笉鏄嚭搴撲腑鎴栧洖搴撲腑锛岃烦杩囧鐞� - 鐘舵��: {lockInfo.Status}");
+ return;
+ }
+
+ // 2. 鑾峰彇鍏宠仈鐨勫簱瀛樻槑缁�
+ var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .FirstAsync(x => x.Barcode == lockInfo.CurrentBarcode && x.StockId == lockInfo.StockId);
+
+ if (stockDetail == null)
+ {
+ _logger.LogError($"鏈壘鍒板簱瀛樻槑缁� - 鏉$爜: {lockInfo.CurrentBarcode}, StockId: {lockInfo.StockId}");
+ throw new InvalidOperationException($"搴撳瓨鏄庣粏涓嶅瓨鍦�: {lockInfo.CurrentBarcode}");
+ }
+
+ // 3. 鑾峰彇鍏宠仈鐨勮鍗曟槑缁�
+ var orderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
+ .FirstAsync(x => x.Id == lockInfo.OrderDetailId);
+
+ if (orderDetail == null)
+ {
+ _logger.LogError($"鏈壘鍒拌鍗曟槑缁� - OrderDetailId: {lockInfo.OrderDetailId}");
+ throw new InvalidOperationException($"璁㈠崟鏄庣粏涓嶅瓨鍦�: {lockInfo.OrderDetailId}");
+ }
+
+ // 璁板綍鍘熷鍊硷紙鐢ㄤ簬鏃ュ織鍜屽洖婊氭鏌ワ級
+ decimal originalStockQty = stockDetail.StockQuantity;
+ decimal originalOutboundQty = stockDetail.OutboundQuantity;
+ int originalStockStatus = stockDetail.Status;
+
+ decimal originalAllocatedQty = orderDetail.AllocatedQuantity;
+ decimal originalLockQty = orderDetail.LockQuantity;
+ decimal originalOverOutQty = orderDetail.OverOutQuantity;
+
+ decimal originalLockPickedQty = lockInfo.PickedQty;
+ decimal originalLockAssignQty = lockInfo.AssignQuantity;
+ int originalLockStatus = lockInfo.Status;
+
+ _logger.LogInformation($"鍥炲簱鍓嶆暟鎹姸鎬�:");
+ _logger.LogInformation($" 搴撳瓨 - 鏉$爜: {stockDetail.Barcode}, 鏁伴噺: {originalStockQty}, 鍑哄簱: {originalOutboundQty}, 鐘舵��: {GetStockStatusName(originalStockStatus)}");
+ _logger.LogInformation($" 璁㈠崟鏄庣粏 - 鍒嗛厤: {originalAllocatedQty}, 閿佸畾: {originalLockQty}, 宸插嚭搴�: {originalOverOutQty}");
+ _logger.LogInformation($" 閿佸畾璁板綍 - 鍒嗛厤: {originalLockAssignQty}, 宸叉嫞閫�: {originalLockPickedQty}, 鐘舵��: {GetLockStatusName(originalLockStatus)}");
+
+ // 4. 銆愭牳蹇冮�昏緫銆戞仮澶嶅簱瀛樻暟鎹�
+ // 4.1 澧炲姞搴撳瓨鏁伴噺
+ stockDetail.StockQuantity += returnQty;
+
+ // 4.2 鍑忓皯鍑哄簱鏁伴噺锛堜絾闇�纭繚涓嶄細鍑虹幇璐熸暟锛�
+ if (stockDetail.OutboundQuantity >= returnQty)
+ {
+ stockDetail.OutboundQuantity -= returnQty;
+ }
+ else
+ {
+ // 濡傛灉鍑哄簱鏁伴噺灏忎簬鍥炲簱鏁伴噺锛岃鏄庢暟鎹紓甯�
+ _logger.LogWarning($"鍑哄簱鏁伴噺({stockDetail.OutboundQuantity})灏忎簬鍥炲簱鏁伴噺({returnQty})锛屾暟鎹紓甯�");
+ stockDetail.OutboundQuantity = 0;
+ }
+
+ // 4.3 鏇存柊搴撳瓨鐘舵��
+ if (stockDetail.OutboundQuantity <= 0 && stockDetail.StockQuantity > 0)
+ {
+ stockDetail.Status = (int)StockStatusEmun.鍏ュ簱瀹屾垚;
+ _logger.LogInformation($"搴撳瓨鐘舵�佹洿鏂颁负: 鍏ュ簱瀹屾垚");
+ }
+ else if (stockDetail.StockQuantity > 0)
+ {
+ stockDetail.Status = (int)StockStatusEmun.鍑哄簱閿佸畾;
+ _logger.LogInformation($"搴撳瓨鐘舵�佷繚鎸佷负: 鍑哄簱閿佸畾");
+ }
+
+ await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
+ _logger.LogInformation($"搴撳瓨鏇存柊瀹屾垚 - 鏉$爜: {stockDetail.Barcode}");
+ _logger.LogInformation($" 搴撳瓨鏁伴噺: {originalStockQty} -> {stockDetail.StockQuantity}");
+ _logger.LogInformation($" 鍑哄簱鏁伴噺: {originalOutboundQty} -> {stockDetail.OutboundQuantity}");
+ _logger.LogInformation($" 鐘舵��: {GetStockStatusName(originalStockStatus)} -> {GetStockStatusName(stockDetail.Status)}");
+
+ // 5. 鏇存柊閿佸畾璁板綍鐘舵��
+ lockInfo.Status = (int)OutLockStockStatusEnum.宸插洖搴�;
+ lockInfo.Operator = App.User.UserName;
+
+ // 銆愰噸瑕併�戝鏋滈攣瀹氳褰曟槸閮ㄥ垎鎷i�夊悗鍥炲簱锛岄渶瑕佽皟鏁村凡鎷i�夋暟閲�
+ // 浣嗕竴鑸儏鍐典笅锛屽洖搴撶殑鏄湭鎷i�夌殑閮ㄥ垎锛屾墍浠ickedQty淇濇寔涓嶅彉
+
+ await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
+ _logger.LogInformation($"閿佸畾璁板綍鏇存柊瀹屾垚 - ID: {lockInfo.Id}");
+ _logger.LogInformation($" 鐘舵��: {GetLockStatusName(originalLockStatus)} -> {GetLockStatusName(lockInfo.Status)}");
+ _logger.LogInformation($" 鍒嗛厤鏁伴噺: {originalLockAssignQty} (涓嶅彉)");
+ _logger.LogInformation($" 宸叉嫞閫夋暟閲�: {originalLockPickedQty} (涓嶅彉)");
+
+ // 6. 鏇存柊璁㈠崟鏄庣粏鏁版嵁
+ // 6.1 鍑忓皯宸插垎閰嶆暟閲�
+ if (orderDetail.AllocatedQuantity >= returnQty)
+ {
+ orderDetail.AllocatedQuantity -= returnQty;
+ }
+ else
+ {
+ // 濡傛灉鍒嗛厤鏁伴噺灏忎簬鍥炲簱鏁伴噺锛岃鏄庢暟鎹紓甯�
+ _logger.LogWarning($"鍒嗛厤鏁伴噺({orderDetail.AllocatedQuantity})灏忎簬鍥炲簱鏁伴噺({returnQty})锛岄噸缃负0");
+ orderDetail.AllocatedQuantity = 0;
+ }
+
+ // 6.2 鍑忓皯閿佸畾鏁伴噺锛堝簲涓庡垎閰嶆暟閲忎繚鎸佸悓姝ワ級
+ if (orderDetail.LockQuantity >= returnQty)
+ {
+ orderDetail.LockQuantity -= returnQty;
+ }
+ else
+ {
+ _logger.LogWarning($"閿佸畾鏁伴噺({orderDetail.LockQuantity})灏忎簬鍥炲簱鏁伴噺({returnQty})锛岄噸缃负0");
+ orderDetail.LockQuantity = 0;
+ }
+
+ // 6.3 宸插嚭搴撴暟閲忎繚鎸佷笉鍙橈紙鍥炲簱涓嶅奖鍝嶅凡鍑哄簱鏁伴噺锛�
+ // orderDetail.OverOutQuantity = orderDetail.OverOutQuantity;
+
+ // 6.4 鏇存柊鎵规鍒嗛厤鐘舵��
+ await UpdateBatchAllocateStatus(orderDetail);
+
+ await _outboundOrderDetailService.Db.Updateable(orderDetail).ExecuteCommandAsync();
+ _logger.LogInformation($"璁㈠崟鏄庣粏鏇存柊瀹屾垚 - ID: {orderDetail.Id}");
+ _logger.LogInformation($" 鍒嗛厤鏁伴噺: {originalAllocatedQty} -> {orderDetail.AllocatedQuantity}");
+ _logger.LogInformation($" 閿佸畾鏁伴噺: {originalLockQty} -> {orderDetail.LockQuantity}");
+ _logger.LogInformation($" 宸插嚭搴撴暟閲�: {originalOverOutQty} (淇濇寔涓嶅彉)");
+
+ // 7. 楠岃瘉鍥炲簱鍚庣殑鏁版嵁涓�鑷存��
+ await ValidateAfterLockReturn(lockInfo, stockDetail, orderDetail, returnQty);
+
+ _logger.LogInformation($"宸插垎閰嶉攣瀹氳褰曞洖搴撳鐞嗗畬鎴� - 閿佸畾ID: {lockInfo.Id}, 鍥炲簱鏁伴噺: {returnQty}");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError($"澶勭悊宸插垎閰嶉攣瀹氳褰曞洖搴撳け璐� - 閿佸畾ID: {lockInfo.Id}, Error: {ex.Message}");
+ throw new InvalidOperationException($"澶勭悊閿佸畾璁板綍鍥炲簱澶辫触: {ex.Message}", ex);
}
}
/// <summary>
- /// 鍥炲簱鍚庢暟鎹獙璇�
+ /// 閿佸畾璁板綍鍥炲簱鍚庨獙璇佹暟鎹竴鑷存��
+ /// </summary>
+ private async Task ValidateAfterLockReturn(Dt_OutStockLockInfo lockInfo, Dt_StockInfoDetail stockDetail,
+ Dt_OutboundOrderDetail orderDetail, decimal returnQty)
+ {
+ try
+ {
+ _logger.LogInformation($"寮�濮嬪洖搴撳悗鏁版嵁楠岃瘉 - 閿佸畾ID: {lockInfo.Id}");
+
+ bool allValid = true;
+ List<string> validationErrors = new List<string>();
+
+ // 1. 閲嶆柊鑾峰彇鏈�鏂版暟鎹�
+ var refreshedStock = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .FirstAsync(x => x.Id == stockDetail.Id);
+
+ var refreshedOrder = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
+ .FirstAsync(x => x.Id == orderDetail.Id);
+
+ var refreshedLock = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .FirstAsync(x => x.Id == lockInfo.Id);
+
+ // 2. 楠岃瘉搴撳瓨鏁版嵁
+ // 璁$畻搴撳瓨鏁伴噺搴旇澧炲姞鍥炲簱鏁伴噺
+ decimal expectedStockQty = stockDetail.StockQuantity + returnQty;
+ if (Math.Abs(refreshedStock.StockQuantity - expectedStockQty) > 0.01m)
+ {
+ string error = $"搴撳瓨鏁伴噺涓嶆纭紒鏈熸湜: {expectedStockQty}, 瀹為檯: {refreshedStock.StockQuantity}";
+ validationErrors.Add(error);
+ allValid = false;
+ _logger.LogError(error);
+ }
+
+ // 楠岃瘉搴撳瓨鐘舵�佸簲涓哄叆搴撳畬鎴愭垨鍑哄簱閿佸畾
+ if (refreshedStock.Status != (int)StockStatusEmun.鍏ュ簱瀹屾垚 &&
+ refreshedStock.Status != (int)StockStatusEmun.鍑哄簱閿佸畾)
+ {
+ string error = $"搴撳瓨鐘舵�佸紓甯革紒鏈熸湜:鍏ュ簱瀹屾垚鎴栧嚭搴撻攣瀹�, 瀹為檯:{GetStockStatusName(refreshedStock.Status)}";
+ validationErrors.Add(error);
+ allValid = false;
+ _logger.LogError(error);
+ }
+
+ // 3. 楠岃瘉閿佸畾璁板綍鐘舵��
+ if (refreshedLock.Status != (int)OutLockStockStatusEnum.宸插洖搴�)
+ {
+ string error = $"閿佸畾璁板綍鐘舵�佸紓甯革紒鏈熸湜:宸插洖搴�, 瀹為檯:{GetLockStatusName(refreshedLock.Status)}";
+ validationErrors.Add(error);
+ allValid = false;
+ _logger.LogError(error);
+ }
+
+ // 4. 楠岃瘉璁㈠崟鏄庣粏鏁版嵁
+ // 璁$畻鍒嗛厤鏁伴噺搴旇鍑忓皯鍥炲簱鏁伴噺
+ decimal expectedAllocatedQty = Math.Max(0, orderDetail.AllocatedQuantity - returnQty);
+ if (Math.Abs(refreshedOrder.AllocatedQuantity - expectedAllocatedQty) > 0.01m)
+ {
+ string error = $"璁㈠崟鍒嗛厤鏁伴噺涓嶆纭紒鏈熸湜: {expectedAllocatedQty}, 瀹為檯: {refreshedOrder.AllocatedQuantity}";
+ validationErrors.Add(error);
+ allValid = false;
+ _logger.LogError(error);
+ }
+
+ // 鍒嗛厤鏁伴噺搴斾笌閿佸畾鏁伴噺涓�鑷�
+ if (Math.Abs(refreshedOrder.AllocatedQuantity - refreshedOrder.LockQuantity) > 0.01m)
+ {
+ string error = $"璁㈠崟鍒嗛厤鏁伴噺涓庨攣瀹氭暟閲忎笉涓�鑷达紒鍒嗛厤: {refreshedOrder.AllocatedQuantity}, 閿佸畾: {refreshedOrder.LockQuantity}";
+ validationErrors.Add(error);
+ allValid = false;
+ _logger.LogError(error);
+ }
+
+ // 5. 鏁版嵁鍏宠仈鎬ч獙璇�
+ // 閿佸畾璁板綍鐨勫凡鎷i�夋暟閲� + 褰撳墠搴撳瓨鐨勫嚭搴撴暟閲忓簲绛変簬鍘熷鍑哄簱鏁伴噺
+ decimal totalOutboundFromLock = refreshedLock.PickedQty + refreshedStock.OutboundQuantity;
+
+ // 鏌ユ壘璇ユ潯鐮佺殑鎵�鏈夋湭鍙栨秷鎷i�夎褰�
+ var pickingRecords = await Db.Queryable<Dt_PickingRecord>()
+ .Where(x => x.Barcode == stockDetail.Barcode && !x.IsCancelled)
+ .ToListAsync();
+
+ decimal totalPickedFromRecords = pickingRecords.Sum(x => x.PickQuantity);
+
+ if (Math.Abs(totalOutboundFromLock - totalPickedFromRecords) > 0.01m)
+ {
+ string error = $"鏁版嵁鍏宠仈鎬у紓甯革紒閿佸畾鎷i��({refreshedLock.PickedQty})+搴撳瓨鍑哄簱({refreshedStock.OutboundQuantity})={totalOutboundFromLock}, 浣嗘嫞閫夎褰曟�诲拰={totalPickedFromRecords}";
+ validationErrors.Add(error);
+ allValid = false;
+ _logger.LogError(error);
+ }
+
+ // 6. 杈撳嚭楠岃瘉缁撴灉
+ if (allValid)
+ {
+ _logger.LogInformation($"鍥炲簱鍚庢暟鎹獙璇佸叏閮ㄩ�氳繃");
+ }
+ else
+ {
+ _logger.LogError($"鍥炲簱鍚庢暟鎹獙璇佸け璐ワ紝鍙戠幇{validationErrors.Count}涓棶棰�");
+ foreach (var error in validationErrors.Take(3)) // 鍙樉绀哄墠3涓棶棰�
+ {
+ _logger.LogError($"楠岃瘉闂: {error}");
+ }
+
+ // 濡傛灉闂涓ラ噸锛屽彲浠ユ姏鍑哄紓甯�
+ if (validationErrors.Any(e => e.Contains("寮傚父")))
+ {
+ throw new InvalidOperationException($"鍥炲簱鍚庢暟鎹獙璇佸け璐�: {string.Join("; ", validationErrors.Take(2))}");
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError($"鍥炲簱鍚庨獙璇佸紓甯�: {ex.Message}");
+ // 涓嶉噸鏂版姏鍑猴紝閬垮厤褰卞搷涓绘祦绋�
+ }
+ }
+
+ /// <summary>
+ /// 澶勭悊鍗曚釜鏉$爜鍥炲簱锛堥�氱敤鏂规硶锛�- 鍖哄垎宸插垎閰嶅拰鏈垎閰�
+ /// </summary>
+ private async Task ProcessSingleBarcodeReturn(string barcode, int stockId, decimal returnQty, bool isUnallocated = false)
+ {
+ try
+ {
+ _logger.LogInformation($"澶勭悊鍗曚釜鏉$爜鍥炲簱 - {barcode}, 鏁伴噺: {returnQty}, 鏄惁鏈垎閰�: {isUnallocated}");
+
+ var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .FirstAsync(x => x.Barcode == barcode && x.StockId == stockId);
+
+ if (stockDetail == null)
+ {
+ _logger.LogWarning($"鏈壘鍒板簱瀛樻槑缁�: {barcode}");
+ return;
+ }
+
+ decimal originalStockQty = stockDetail.StockQuantity;
+ decimal originalOutboundQty = stockDetail.OutboundQuantity;
+ int originalStatus = stockDetail.Status;
+
+ _logger.LogInformation($"鍥炲簱鍓嶇姸鎬� - 搴撳瓨: {originalStockQty}, 鍑哄簱: {originalOutboundQty}, 鐘舵��: {GetStockStatusName(originalStatus)}");
+
+ // 銆愪慨澶嶃�戞牴鎹槸鍚︽湭鍒嗛厤鍐冲畾澶勭悊閫昏緫
+ if (isUnallocated)
+ {
+ // 鏈垎閰嶉攣瀹氾細鍙仮澶嶇姸鎬侊紝涓嶆敼鍙樺簱瀛樻暟閲�
+ // 鍑哄簱鏁伴噺搴斾负0
+ if (stockDetail.OutboundQuantity > 0)
+ {
+ _logger.LogWarning($"鏈垎閰嶉攣瀹氱殑搴撳瓨鍑哄簱鏁伴噺涓嶄负0锛岄噸缃负0 - 鏉$爜: {stockDetail.Barcode}, 褰撳墠鍑哄簱: {stockDetail.OutboundQuantity}");
+ stockDetail.OutboundQuantity = 0;
+ }
+
+ // 搴撳瓨鏁伴噺淇濇寔涓嶅彉
+ _logger.LogInformation($"鏈垎閰嶉攣瀹氬洖搴� - 搴撳瓨鏁伴噺淇濇寔涓嶅彉: {stockDetail.StockQuantity}");
+ }
+ else
+ {
+ // 宸插垎閰嶉攣瀹氾細鎭㈠搴撳瓨鏁伴噺
+ stockDetail.StockQuantity += returnQty;
+
+ // 鍑忓皯鍑哄簱鏁伴噺锛堝鏋滃嚭搴撴暟閲忓ぇ浜�0锛�
+ if (stockDetail.OutboundQuantity >= returnQty)
+ {
+ stockDetail.OutboundQuantity -= returnQty;
+ }
+ else
+ {
+ // 濡傛灉鍑哄簱鏁伴噺灏忎簬鍥炲簱鏁伴噺锛岃鏄庢暟鎹紓甯革紝鍑哄簱鏁伴噺娓呴浂
+ _logger.LogWarning($"鍑哄簱鏁伴噺({stockDetail.OutboundQuantity})灏忎簬鍥炲簱鏁伴噺({returnQty})锛屾竻闆�");
+ stockDetail.OutboundQuantity = 0;
+ }
+
+ _logger.LogInformation($"宸插垎閰嶉攣瀹氬洖搴� - 搴撳瓨鏁伴噺澧炲姞: {originalStockQty} -> {stockDetail.StockQuantity}");
+ }
+
+ // 鏇存柊鐘舵��
+ stockDetail.Status = (int)StockStatusEmun.鍏ュ簱瀹屾垚;
+
+ await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
+
+ _logger.LogInformation($"鏉$爜鍥炲簱瀹屾垚 - {barcode}: 搴撳瓨 {originalStockQty}->{stockDetail.StockQuantity}, 鍑哄簱 {originalOutboundQty}->{stockDetail.OutboundQuantity}");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError($"澶勭悊鏉$爜鍥炲簱澶辫触 - {barcode}: {ex.Message}");
+ throw;
+ }
+ }
+ /// <summary>
+ /// 澶勭悊鏈垎閰嶉攣瀹氳褰曞洖搴� - 淇鐗堟湰
+ /// 鏈垎閰嶉攣瀹氳褰曪細鍙仮澶嶇姸鎬侊紝涓嶅鍔犲簱瀛樻暟閲�
+ /// </summary>
+ private async Task ProcessUnallocatedLockReturn(Dt_OutStockLockInfo lockInfo, decimal returnQty)
+ {
+ _logger.LogInformation($"澶勭悊鏈垎閰嶉攣瀹氬洖搴� - 閿佸畾ID: {lockInfo.Id}, 鏉$爜: {lockInfo.CurrentBarcode}, 鏁伴噺: {returnQty}");
+
+ try
+ {
+ // 楠岃瘉閿佸畾璁板綍鐘舵��
+ if (lockInfo.Status != (int)OutLockStockStatusEnum.鍑哄簱涓� &&
+ lockInfo.Status != (int)OutLockStockStatusEnum.鍥炲簱涓�)
+ {
+ _logger.LogWarning($"閿佸畾璁板綍鐘舵�佷笉鏄嚭搴撲腑鎴栧洖搴撲腑锛岃烦杩囧鐞� - 鐘舵��: {lockInfo.Status}");
+ return;
+ }
+
+ // 銆愪慨澶嶃�戣幏鍙栧簱瀛樻槑缁�
+ var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .FirstAsync(x => x.Barcode == lockInfo.CurrentBarcode && x.StockId == lockInfo.StockId);
+
+ if (stockDetail == null)
+ {
+ _logger.LogError($"鏈壘鍒板簱瀛樻槑缁� - 鏉$爜: {lockInfo.CurrentBarcode}, StockId: {lockInfo.StockId}");
+ throw new InvalidOperationException($"搴撳瓨鏄庣粏涓嶅瓨鍦�: {lockInfo.CurrentBarcode}");
+ }
+
+ // 璁板綍鍘熷鐘舵��
+ decimal originalStockQty = stockDetail.StockQuantity;
+ decimal originalOutboundQty = stockDetail.OutboundQuantity;
+ int originalStatus = stockDetail.Status;
+
+ _logger.LogInformation($"鏈垎閰嶉攣瀹氬洖搴撳墠鐘舵��:");
+ _logger.LogInformation($" 搴撳瓨 - 鏉$爜: {stockDetail.Barcode}, 鏁伴噺: {originalStockQty}, 鍑哄簱: {originalOutboundQty}, 鐘舵��: {GetStockStatusName(originalStatus)}");
+
+ // 銆愪慨澶嶅叧閿�戝浜庢湭鍒嗛厤閿佸畾璁板綍锛屽簱瀛樻暟閲忎笉搴旀敼鍙橈紒
+ // 鍥犱负搴撳瓨鏈潵灏卞瓨鍦紝鍙槸鐘舵�佽閿佸畾
+ // stockDetail.StockQuantity 淇濇寔涓嶅彉
+
+ // 鍑哄簱鏁伴噺搴斾负0锛堟湭鍒嗛厤閿佸畾涓嶅簲璇ユ湁鍑哄簱锛�
+ if (stockDetail.OutboundQuantity > 0)
+ {
+ _logger.LogWarning($"鏈垎閰嶉攣瀹氱殑搴撳瓨鍑哄簱鏁伴噺涓嶄负0锛岄噸缃负0 - 鏉$爜: {stockDetail.Barcode}, 褰撳墠鍑哄簱: {stockDetail.OutboundQuantity}");
+ stockDetail.OutboundQuantity = 0;
+ }
+
+ // 鏇存柊搴撳瓨鐘舵�佷负鍏ュ簱瀹屾垚锛堟仮澶嶄负鍙敤鐘舵�侊級
+ stockDetail.Status = (int)StockStatusEmun.鍏ュ簱瀹屾垚;
+
+ await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
+
+ _logger.LogInformation($"鏇存柊鏈垎閰嶅簱瀛樼姸鎬� - 鏉$爜: {stockDetail.Barcode}");
+ _logger.LogInformation($" 搴撳瓨鏁伴噺: {originalStockQty} -> {stockDetail.StockQuantity} (淇濇寔涓嶅彉)");
+ _logger.LogInformation($" 鍑哄簱鏁伴噺: {originalOutboundQty} -> {stockDetail.OutboundQuantity}");
+ _logger.LogInformation($" 鐘舵��: {GetStockStatusName(originalStatus)} -> {GetStockStatusName(stockDetail.Status)}");
+
+ // 鏇存柊閿佸畾璁板綍鐘舵�佷负宸插洖搴�
+ lockInfo.Status = (int)OutLockStockStatusEnum.宸插洖搴�;
+ lockInfo.Operator = App.User.UserName;
+
+ await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
+
+ _logger.LogInformation($"鏇存柊鏈垎閰嶉攣瀹氱姸鎬� - 閿佸畾ID: {lockInfo.Id}, 鐘舵��: 鍑哄簱涓� -> 宸插洖搴�");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError($"澶勭悊鏈垎閰嶉攣瀹氬洖搴撳け璐� - 閿佸畾ID: {lockInfo.Id}, Error: {ex.Message}");
+ throw new InvalidOperationException($"澶勭悊鏈垎閰嶉攣瀹氬洖搴撳け璐�: {ex.Message}", ex);
+ }
+ }
+
+ /// <summary>
+ /// 澶勭悊鏈垎閰嶅簱瀛樺洖搴�
+ /// </summary>
+ private async Task ProcessUnallocatedStockReturn(Dt_StockInfoDetail stockDetail)
+ {
+ _logger.LogInformation($"澶勭悊鏈垎閰嶅簱瀛樺洖搴� - 鏉$爜: {stockDetail.Barcode}, 鏁伴噺: {stockDetail.StockQuantity}");
+
+ // 鐩存帴鏇存柊搴撳瓨鐘舵��
+ stockDetail.Status = (int)StockStatusEmun.鍏ュ簱瀹屾垚;
+ await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
+ }
+
+
+ /// <summary>
+ /// 鍥炲簱鍚庢暟鎹獙璇� - 澧炲己鐗�
/// </summary>
private async Task ValidateDataAfterReturn(string orderNo, string palletCode, int stockId)
{
@@ -2215,17 +2923,18 @@
{
_logger.LogInformation($"寮�濮嬪洖搴撳悗鏁版嵁楠岃瘉");
- // 1. 楠岃瘉搴撳瓨鐘舵��
+ // 1. 楠岃瘉搴撳瓨鐘舵�佸拰鏁伴噺
var stockDetails = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
.Where(x => x.StockId == stockId)
.ToListAsync();
- var stillOutboundLocked = stockDetails.Where(x =>
- x.Status == (int)StockStatusEmun.鍑哄簱閿佸畾 && x.StockQuantity > 0).ToList();
+ decimal totalStock = stockDetails.Sum(x => x.StockQuantity);
- if (stillOutboundLocked.Any())
+ // 楠岃瘉搴撳瓨鏁伴噺鏄惁鍚堢悊
+ var unreasonableStocks = stockDetails.Where(x => x.StockQuantity < 0).ToList();
+ if (unreasonableStocks.Any())
{
- _logger.LogWarning($"鍥炲簱鍚庝粛鏈夊嚭搴撻攣瀹氱姸鎬佺殑搴撳瓨: {stillOutboundLocked.Count}涓�");
+ _logger.LogError($"鍙戠幇璐熸暟搴撳瓨鏁伴噺锛佹潯鐮�: {string.Join(", ", unreasonableStocks.Select(x => x.Barcode))}");
}
// 2. 楠岃瘉閿佸畾璁板綍鐘舵��
@@ -2235,16 +2944,42 @@
var notReturnedLocks = lockInfos.Where(x =>
x.Status != (int)OutLockStockStatusEnum.宸插洖搴� &&
- x.Status != (int)OutLockStockStatusEnum.宸插彇璧�).ToList();
+ x.Status != (int)OutLockStockStatusEnum.宸插彇璧� &&
+ x.Status != (int)OutLockStockStatusEnum.鎷i�夊畬鎴�).ToList();
if (notReturnedLocks.Any())
{
_logger.LogWarning($"鍥炲簱鍚庝粛鏈夋湭鍥炲簱鐘舵�佺殑閿佸畾璁板綍: {notReturnedLocks.Count}鏉�");
+ foreach (var lockInfo in notReturnedLocks)
+ {
+ _logger.LogWarning($"鏈洖搴撻攣瀹� - ID: {lockInfo.Id}, 鐘舵��: {GetLockStatusName(lockInfo.Status)}, 鏉$爜: {lockInfo.CurrentBarcode}");
+ }
}
// 3. 鏁版嵁涓�鑷存�ч獙璇�
- decimal totalStock = stockDetails.Sum(x => x.StockQuantity);
- _logger.LogInformation($"鍥炲簱鍚庡簱瀛樻�婚噺: {totalStock}");
+ decimal totalExpectedReturnQty = lockInfos
+ .Where(x => x.Status == (int)OutLockStockStatusEnum.宸插洖搴�)
+ .Sum(x => x.AssignQuantity - x.PickedQty);
+
+ _logger.LogInformation($"鍥炲簱楠岃瘉姹囨��:");
+ _logger.LogInformation($" 鍥炲簱鍚庡簱瀛樻�婚噺: {totalStock}");
+ _logger.LogInformation($" 宸插洖搴撻攣瀹氳褰曟暟閲�: {lockInfos.Count(x => x.Status == (int)OutLockStockStatusEnum.宸插洖搴�)}");
+ _logger.LogInformation($" 鎬诲洖搴撴暟閲忥紙閿佸畾璁板綍璁$畻锛�: {totalExpectedReturnQty}");
+
+ // 4. 楠岃瘉搴撳瓨鏁伴噺涓庨攣瀹氳褰曠殑涓�鑷存��
+ foreach (var lockInfo in lockInfos.Where(x => !string.IsNullOrEmpty(x.CurrentBarcode)))
+ {
+ var stock = stockDetails.FirstOrDefault(x => x.Barcode == lockInfo.CurrentBarcode);
+ if (stock != null)
+ {
+ // 濡傛灉閿佸畾璁板綍鏄凡鍥炲簱鐘舵�侊紝瀵瑰簲鐨勫簱瀛樺簲璇ユ槸鍏ュ簱瀹屾垚鐘舵��
+ if (lockInfo.Status == (int)OutLockStockStatusEnum.宸插洖搴� &&
+ stock.Status != (int)StockStatusEmun.鍏ュ簱瀹屾垚)
+ {
+ _logger.LogWarning($"閿佸畾璁板綍宸插洖搴撲絾搴撳瓨鐘舵�佷笉姝g‘ - 鏉$爜: {lockInfo.CurrentBarcode}, 搴撳瓨鐘舵��: {GetStockStatusName(stock.Status)}");
+ }
+ }
+ }
_logger.LogInformation($"鍥炲簱鍚庢暟鎹獙璇佸畬鎴�");
}
@@ -2253,7 +2988,6 @@
_logger.LogError($"鍥炲簱鍚庨獙璇佸け璐�: {ex.Message}");
}
}
-
/// <summary>
/// 楠岃瘉鍥炲簱鍓嶅悗鏁版嵁涓�鑷存��
@@ -2336,6 +3070,7 @@
_ => $"鏈煡({status})"
};
}
+
/// <summary>
/// 绠�鍖栧洖搴撴暟鎹搷浣滐紙褰撲富鏂规硶澶辫触鏃朵娇鐢級
/// </summary>
@@ -2345,22 +3080,51 @@
try
{
- // 鑾峰彇璇ユ墭鐩樼殑鎵�鏈夋潯鐮�
+ // 鑾峰彇璇ユ墭鐩樼殑鎵�鏈夋潯鐮侊紙鍖呮嫭鎵�鏈夌姸鎬佺殑搴撳瓨锛�
var allStockDetails = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
- .Where(x => x.StockId == statusAnalysis.StockId && x.StockQuantity > 0)
+ .Where(x => x.StockId == statusAnalysis.StockId)
.ToListAsync();
- _logger.LogInformation($"鎵惧埌 {allStockDetails.Count} 涓湁搴撳瓨鐨勬潯鐮�");
+ _logger.LogInformation($"鎵惧埌 {allStockDetails.Count} 涓簱瀛樻槑缁嗚褰�");
foreach (var stockDetail in allStockDetails)
{
- // 鎭㈠鎵�鏈夊簱瀛樼姸鎬佷负鍏ュ簱瀹屾垚
- if (stockDetail.Status == (int)StockStatusEmun.鍑哄簱閿佸畾)
+ // 璁板綍鍘熷鐘舵��
+ int originalStatus = stockDetail.Status;
+ decimal originalStockQty = stockDetail.StockQuantity;
+
+ // 灏嗘墍鏈夊嚭搴撶浉鍏崇殑鐘舵�佹仮澶嶄负鍏ュ簱瀹屾垚
+ if (stockDetail.Status == (int)StockStatusEmun.鍑哄簱閿佸畾 ||
+ //stockDetail.Status == (int)StockStatusEmun.鍑哄簱涓� ||
+ stockDetail.Status == (int)StockStatusEmun.鍑哄簱瀹屾垚)
{
+ // 濡傛灉鏄嚭搴撳畬鎴愮姸鎬佷笖搴撳瓨涓�0锛屽彲鑳介渶瑕佺壒娈婂鐞�
+ if (stockDetail.Status == (int)StockStatusEmun.鍑哄簱瀹屾垚 && stockDetail.StockQuantity == 0)
+ {
+ _logger.LogInformation($"璺宠繃宸插嚭搴撳畬鎴愮殑闆跺簱瀛樻潯鐮�: {stockDetail.Barcode}");
+ continue;
+ }
+
stockDetail.Status = (int)StockStatusEmun.鍏ュ簱瀹屾垚;
+ // 濡傛灉鏄嚭搴撻攣瀹氱姸鎬佷絾搴撳瓨涓�0锛岄噸缃簱瀛樹负1锛堥伩鍏嶉浂搴撳瓨闂锛�
+ if (stockDetail.Status == (int)StockStatusEmun.鍑哄簱閿佸畾 && stockDetail.StockQuantity == 0)
+ {
+ // 鏌ユ壘鏄惁鏈夊搴旂殑閿佸畾璁板綍鏉ョ‘瀹氬簲璇ユ仮澶嶇殑鏁伴噺
+ var lockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.CurrentBarcode == stockDetail.Barcode &&
+ x.StockId == stockDetail.StockId)
+ .FirstAsync();
+
+ if (lockInfo != null)
+ {
+ stockDetail.StockQuantity = lockInfo.AssignQuantity - lockInfo.PickedQty;
+ _logger.LogInformation($"鎭㈠闆跺簱瀛樻潯鐮佺殑鏁伴噺 - 鏉$爜: {stockDetail.Barcode}, 鏁伴噺: {stockDetail.StockQuantity}");
+ }
+ }
+
await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
- _logger.LogInformation($"绠�鍖栧洖搴� - 鏉$爜: {stockDetail.Barcode}, 鏁伴噺: {stockDetail.StockQuantity}");
+ _logger.LogInformation($"绠�鍖栧洖搴� - 鏉$爜: {stockDetail.Barcode}, 鐘舵��: {GetStockStatusName(originalStatus)} -> 鍏ュ簱瀹屾垚, 鏁伴噺: {originalStockQty} -> {stockDetail.StockQuantity}");
}
}
@@ -2378,7 +3142,7 @@
lockInfo.Operator = App.User.UserName;
await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
- _logger.LogInformation($"绠�鍖栧洖搴� - 閿佸畾璁板綍: {lockInfo.Id}");
+ _logger.LogInformation($"绠�鍖栧洖搴� - 閿佸畾璁板綍: {lockInfo.Id}, 鐘舵��: 宸插洖搴�");
}
_logger.LogInformation($"銆愮畝鍖栧洖搴撱�戝畬鎴� - 澶勭悊 {allStockDetails.Count} 涓潯鐮�, {allLocks.Count} 鏉¢攣瀹氳褰�");
@@ -2389,6 +3153,25 @@
throw;
}
}
+
+ /// <summary>
+ /// 鑾峰彇搴撳瓨鐘舵�佸悕绉�
+ /// </summary>
+ private string GetStockStatusName(int status)
+ {
+ return status switch
+ {
+ 1 => "鍏ュ簱纭",
+ 2 => "鍏ュ簱瀹屾垚",
+ 3 => "鍑哄簱閿佸畾",
+ 4 => "鍑哄簱涓�",
+ 5 => "鍑哄簱瀹屾垚",
+ 6 => "宸叉竻鐞�",
+ _ => $"鏈煡({status})"
+ };
+ }
+
+
/// <summary>
/// 鎵ц鍥炲簱鏁版嵁鎿嶄綔 - 绠�鍖栫増鏈�
/// </summary>
@@ -2541,13 +3324,18 @@
throw;
}
}
+
+
/// <summary>
- /// 澶勭悊搴撳瓨鍥炲簱 - 绠�鍖栭�昏緫
+ /// 澶勭悊搴撳瓨鍥炲簱 - 瀹屾暣淇鐗�
+ /// 纭繚OutboundQuantity姝g‘鍑忓皯
/// </summary>
private async Task ProcessStockForReturn(string barcode, int stockId, decimal returnQty)
{
try
{
+ _logger.LogInformation($"澶勭悊搴撳瓨鍥炲簱 - 鏉$爜: {barcode}, 鍥炲簱鏁伴噺: {returnQty}");
+
var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
.FirstAsync(x => x.Barcode == barcode && x.StockId == stockId);
@@ -2562,22 +3350,37 @@
decimal originalOutboundQty = stockDetail.OutboundQuantity;
int originalStatus = stockDetail.Status;
- // 绠�鍖栧鐞嗭細濡傛灉搴撳瓨鏁伴噺澶т簬0锛屾仮澶嶄负鍏ュ簱瀹屾垚鐘舵��
- if (stockDetail.StockQuantity > 0)
+ _logger.LogInformation($"鍥炲簱鍓嶇姸鎬� - 搴撳瓨: {originalStockQty}, 鍑哄簱: {originalOutboundQty}, 鐘舵��: {GetStockStatusName(originalStatus)}");
+
+ // 銆愭牳蹇冧慨姝c�戠‘淇濆洖搴撴搷浣滄纭鐞�
+ // 1. 搴撳瓨鏁伴噺澧炲姞锛堝洖搴撶殑璐х墿鍥炲埌搴撳瓨锛�
+ stockDetail.StockQuantity += returnQty;
+
+ // 2. 鍑哄簱鏁伴噺鍑忓皯锛堝洜涓鸿揣鐗╂病鏈夊嚭搴擄紝鑰屾槸鍥炲簱浜嗭級
+ // 浣嗛渶瑕佺‘淇濅笉浼氬嚭鐜拌礋鏁�
+ if (stockDetail.OutboundQuantity >= returnQty)
{
- stockDetail.Status = (int)StockStatusEmun.鍏ュ簱瀹屾垚;
+ stockDetail.OutboundQuantity -= returnQty;
+ }
+ else
+ {
+ // 濡傛灉鍑哄簱鏁伴噺灏忎簬鍥炲簱鏁伴噺锛岃鏄庢暟鎹紓甯�
+ _logger.LogWarning($"鍑哄簱鏁伴噺({stockDetail.OutboundQuantity})灏忎簬鍥炲簱鏁伴噺({returnQty})锛岄噸缃嚭搴撴暟閲忎负0");
+ stockDetail.OutboundQuantity = 0;
}
- // 璋冩暣鍑哄簱鏁伴噺锛堥伩鍏嶅嚭鐜拌礋鏁帮級
- if (stockDetail.OutboundQuantity > 0)
- {
- stockDetail.OutboundQuantity = Math.Max(0, stockDetail.OutboundQuantity - returnQty);
- }
+ // 3. 鏇存柊鐘舵�佷负鍏ュ簱瀹屾垚
+ stockDetail.Status = (int)StockStatusEmun.鍏ュ簱瀹屾垚;
+
await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
- _logger.LogInformation($"搴撳瓨鍥炲簱澶勭悊 - 鏉$爜: {barcode}, 鐘舵��: {originalStatus} -> {stockDetail.Status}, " +
- $"搴撳瓨: {originalStockQty} -> {stockDetail.StockQuantity}, " +
- $"鍑哄簱: {originalOutboundQty} -> {stockDetail.OutboundQuantity}");
+ _logger.LogInformation($"搴撳瓨鍥炲簱瀹屾垚 - 鏉$爜: {barcode}");
+ _logger.LogInformation($" 搴撳瓨鏁伴噺: {originalStockQty} -> {stockDetail.StockQuantity}");
+ _logger.LogInformation($" 鍑哄簱鏁伴噺: {originalOutboundQty} -> {stockDetail.OutboundQuantity}");
+ _logger.LogInformation($" 鐘舵��: {GetStockStatusName(originalStatus)} -> {GetStockStatusName(stockDetail.Status)}");
+
+ // 楠岃瘉鍥炲簱鍚庣殑鏁版嵁
+ await ValidateStockAfterReturn(barcode, stockId, returnQty);
}
catch (Exception ex)
{
@@ -2585,6 +3388,35 @@
throw;
}
}
+
+ /// <summary>
+ /// 楠岃瘉鍥炲簱鍚庡簱瀛樻暟鎹�
+ /// </summary>
+ private async Task ValidateStockAfterReturn(string barcode, int stockId, decimal returnQty)
+ {
+ try
+ {
+ var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .FirstAsync(x => x.Barcode == barcode && x.StockId == stockId);
+
+ // 妫�鏌ュ嚭搴撴暟閲忔槸鍚︿负0鎴栧悎鐞�
+ if (stockDetail.OutboundQuantity > stockDetail.StockQuantity)
+ {
+ _logger.LogWarning($"鍥炲簱鍚庢暟鎹紓甯� - 鍑哄簱鏁伴噺({stockDetail.OutboundQuantity})澶т簬搴撳瓨鏁伴噺({stockDetail.StockQuantity})");
+ }
+
+ // 妫�鏌ョ姸鎬佹槸鍚︽纭�
+ if (stockDetail.Status != (int)StockStatusEmun.鍏ュ簱瀹屾垚)
+ {
+ _logger.LogWarning($"鍥炲簱鍚庣姸鎬佸紓甯� - 鏈熸湜:鍏ュ簱瀹屾垚, 瀹為檯:{GetStockStatusName(stockDetail.Status)}");
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError($"楠岃瘉鍥炲簱鍚庢暟鎹け璐�: {ex.Message}");
+ }
+ }
+
/// <summary>
/// 涓洪攣瀹氳褰曞噺灏戣鍗曟槑缁嗙殑鍒嗛厤鏁伴噺
/// </summary>
@@ -2638,8 +3470,8 @@
}
/// <summary>
- /// 澶勭悊鏈垎閰嶇殑閿佸畾璁板綍鍥炲簱
- /// 涓嶉渶瑕佸噺灏戣鍗曟槑缁嗙殑鍒嗛厤鏁伴噺
+ /// 澶勭悊鏈垎閰嶇殑閿佸畾璁板綍鍥炲簱 - 淇鐗�
+ /// 娉ㄦ剰锛氭湭鍒嗛厤閿佸畾璁板綍娌℃湁缁戝畾璁㈠崟鏄庣粏锛屼笉闇�瑕佸噺灏戣鍗曟槑缁嗙殑鍒嗛厤鏁伴噺
/// </summary>
private async Task HandleUnallocatedLocksReturn(List<Dt_OutStockLockInfo> unallocatedLocks)
{
@@ -2664,22 +3496,21 @@
if (stockDetail != null)
{
- // 鎭㈠搴撳瓨鏁伴噺
+ // 銆愪慨姝c�戞仮澶嶅簱瀛樻暟閲忥紝鍑哄簱鏁伴噺淇濇寔涓嶅彉锛堝洜涓烘湭鍒嗛厤閿佸畾鐨勫嚭搴撴暟閲忔湰鏉ュ氨鏄�0锛�
decimal originalStockQty = stockDetail.StockQuantity;
stockDetail.StockQuantity += returnQty;
- // 鎭㈠搴撳瓨鐘舵��
- if (stockDetail.Status == (int)StockStatusEmun.鍑哄簱瀹屾垚)
- {
- stockDetail.Status = (int)StockStatusEmun.鍏ュ簱瀹屾垚;
- }
- else if (stockDetail.Status == (int)StockStatusEmun.鍑哄簱閿佸畾)
+ // 鍑哄簱鏁伴噺淇濇寔涓�0涓嶅彉锛�
+ // stockDetail.OutboundQuantity = stockDetail.OutboundQuantity; // 淇濇寔涓嶅彉
+
+ // 鎭㈠搴撳瓨鐘舵�佷负鍙敤鐘舵��
+ if (stockDetail.Status == (int)StockStatusEmun.鍑哄簱閿佸畾)
{
stockDetail.Status = (int)StockStatusEmun.鍏ュ簱瀹屾垚;
}
await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
- _logger.LogInformation($"鎭㈠搴撳瓨 - 鏉$爜: {stockDetail.Barcode}, 搴撳瓨鏁伴噺: {originalStockQty} -> {stockDetail.StockQuantity}");
+ _logger.LogInformation($"鎭㈠鏈垎閰嶅簱瀛� - 鏉$爜: {stockDetail.Barcode}, 搴撳瓨鏁伴噺: {originalStockQty} -> {stockDetail.StockQuantity}");
}
// 鏇存柊閿佸畾璁板綍鐘舵�佷负宸插洖搴�
@@ -2927,8 +3758,7 @@
/// </summary>
/// <summary>
- /// 鍒嗘瀽鎵樼洏鐘舵�佺敤浜庡洖搴� - 瀹屾暣鐗堟湰
- /// 纭繚涓嶄細閿欒璇嗗埆闇�瑕佸洖搴撶殑鐗╁搧锛岄伩鍏嶉噸澶嶈绠�
+ /// 鍒嗘瀽鎵樼洏鐘舵�佺敤浜庡洖搴� - 淇鐗堬紙瑙e喅鎷嗗寘璁板綍閲嶅璁$畻闂锛�
/// </summary>
private async Task<PalletStatusAnalysis> AnalyzePalletStatusForReturn(string orderNo, string palletCode, int stockId)
{
@@ -2938,250 +3768,158 @@
PalletCode = palletCode,
StockId = stockId,
AllBarcodes = new List<string>(),
- RemainingLocks = new List<Dt_OutStockLockInfo>(),
- UnallocatedLocks = new List<Dt_OutStockLockInfo>(),
- PalletStockGoods = new List<Dt_StockInfoDetail>(),
- SplitRecords = new List<Dt_SplitPackageRecord>()
+ ProcessedBarcodes = new HashSet<string>()
};
- _logger.LogInformation($"寮�濮嬪垎鏋愭墭鐩樼姸鎬佺敤浜庡洖搴� - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}, StockId: {stockId}");
+ _logger.LogInformation($"銆愬洖搴撳垎鏋愩�戝紑濮嬪垎鏋愭墭鐩樼姸鎬� - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}, StockId: {stockId}");
try
{
- // 1. 鍒嗘瀽鎵�鏈夐攣瀹氳褰曪紙鐘舵�佷负鍑哄簱涓級
- var allUnfinishedLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
- .Where(x => x.OrderNo == orderNo &&
- x.PalletCode == palletCode &&
- x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓�)
- .ToListAsync();
-
- if (allUnfinishedLocks.Any())
- {
- _logger.LogInformation($"鎵惧埌 {allUnfinishedLocks.Count} 鏉″嚭搴撲腑鐘舵�佺殑閿佸畾璁板綍");
-
- // 鍖哄垎宸插垎閰嶅拰鏈垎閰嶇殑閿佸畾璁板綍
- var allocatedLocks = allUnfinishedLocks
- .Where(x => x.IsUnallocated != 1 && x.OrderDetailId > 0)
- .ToList();
-
- var unallocatedLocks = allUnfinishedLocks
- .Where(x => x.IsUnallocated == 1 || x.OrderDetailId == 0)
- .ToList();
-
- // 澶勭悊宸插垎閰嶇殑閿佸畾璁板綍
- if (allocatedLocks.Any())
- {
- result.HasRemainingLocks = true;
- result.RemainingLocks = allocatedLocks;
- result.RemainingLocksReturnQty = allocatedLocks.Sum(x => x.AssignQuantity - x.PickedQty);
-
- foreach (var lockInfo in allocatedLocks)
- {
- if (!string.IsNullOrEmpty(lockInfo.CurrentBarcode))
- {
- result.AllBarcodes.Add(lockInfo.CurrentBarcode);
- }
- }
-
- _logger.LogInformation($"鍙戠幇{allocatedLocks.Count}鏉″凡鍒嗛厤鏈垎鎷i攣瀹氳褰曪紝鎬绘暟閲�: {result.RemainingLocksReturnQty}");
- }
-
- // 澶勭悊鏈垎閰嶇殑閿佸畾璁板綍锛堝鑷姩鎷嗗寘浜х敓鐨勶級
- if (unallocatedLocks.Any())
- {
- result.HasUnallocatedLocks = true;
- result.UnallocatedLocks = unallocatedLocks;
- result.UnallocatedLocksReturnQty = unallocatedLocks.Sum(x => x.AssignQuantity - x.PickedQty);
-
- foreach (var lockInfo in unallocatedLocks)
- {
- if (!string.IsNullOrEmpty(lockInfo.CurrentBarcode))
- {
- result.AllBarcodes.Add(lockInfo.CurrentBarcode);
- }
- }
-
- _logger.LogInformation($"鍙戠幇{unallocatedLocks.Count}鏉℃湭鍒嗛厤閿佸畾璁板綍锛屾�绘暟閲�: {result.UnallocatedLocksReturnQty}");
- }
- }
- else
- {
- _logger.LogInformation($"鏈壘鍒板嚭搴撲腑鐘舵�佺殑閿佸畾璁板綍");
- }
-
- // 2. 鍒嗘瀽鎵樼洏涓婄殑鍓╀綑搴撳瓨璐х墿锛堢姸鎬佷负鍑哄簱閿佸畾浣嗘湭鍒嗛厤锛�
+ // 1. 棣栧厛鑾峰彇鎵樼洏涓婃墍鏈夌殑搴撳瓨鏄庣粏锛堝熀纭�鏁版嵁锛�
var allStockDetails = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
- .Where(x => x.StockId == stockId &&
- x.Status == (int)StockStatusEmun.鍑哄簱閿佸畾 &&
- x.StockQuantity > 0)
+ .Where(x => x.StockId == stockId && x.StockQuantity > 0)
.ToListAsync();
- if (allStockDetails.Any())
- {
- _logger.LogInformation($"鎵惧埌 {allStockDetails.Count} 涓嚭搴撻攣瀹氱姸鎬佺殑搴撳瓨璐х墿");
+ _logger.LogInformation($"鎵惧埌 {allStockDetails.Count} 涓湁搴撳瓨鐨勬槑缁嗚褰�");
- // 杩囨护鎺夊凡缁忚閿佸畾璁板綍鍗犵敤鐨勫簱瀛�
- var lockedBarcodes = allUnfinishedLocks.Select(x => x.CurrentBarcode).Where(b => !string.IsNullOrEmpty(b)).ToList();
- var unlockedStockGoods = allStockDetails
- .Where(x => !lockedBarcodes.Contains(x.Barcode))
- .ToList();
-
- _logger.LogInformation($"杩囨护鍚庡墿浣� {unlockedStockGoods.Count} 涓湭琚攣瀹氱殑搴撳瓨璐х墿");
-
- // 杩涗竴姝ヨ繃婊わ細妫�鏌ヨ繖浜涘簱瀛樻槸鍚︽湁鍏宠仈鐨勯攣瀹氳褰曪紙鍖呮嫭鐘舵�佷笉鏄嚭搴撲腑鐨勶級
- var trulyUnallocatedGoods = new List<Dt_StockInfoDetail>();
- foreach (var stock in unlockedStockGoods)
- {
- var hasActiveLock = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
- .Where(x => x.CurrentBarcode == stock.Barcode &&
- (x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓� ||
- x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�))
- .AnyAsync();
-
- if (!hasActiveLock)
- {
- trulyUnallocatedGoods.Add(stock);
- }
- else
- {
- _logger.LogInformation($"鏉$爜 {stock.Barcode} 鏈夋椿璺冪殑閿佸畾璁板綍锛岃烦杩囦綔涓烘湭鍒嗛厤搴撳瓨");
- }
- }
-
- if (trulyUnallocatedGoods.Any())
- {
- result.HasPalletStockGoods = true;
- result.PalletStockGoods = trulyUnallocatedGoods;
- result.PalletStockReturnQty = trulyUnallocatedGoods.Sum(x => x.StockQuantity);
-
- foreach (var stock in trulyUnallocatedGoods)
- {
- result.AllBarcodes.Add(stock.Barcode);
- }
-
- _logger.LogInformation($"鍙戠幇{trulyUnallocatedGoods.Count}涓湡姝f湭鍒嗛厤搴撳瓨璐х墿锛屾�绘暟閲�: {result.PalletStockReturnQty}");
-
- // 璁板綍姣忎釜璐х墿鐨勮缁嗕俊鎭�
- foreach (var stock in trulyUnallocatedGoods)
- {
- _logger.LogInformation($"鏈垎閰嶅簱瀛� - 鏉$爜: {stock.Barcode}, 鐗╂枡: {stock.MaterielCode}, 鏁伴噺: {stock.StockQuantity}");
- }
- }
- }
- else
- {
- _logger.LogInformation($"鏈壘鍒板嚭搴撻攣瀹氱姸鎬佺殑搴撳瓨璐х墿");
- }
-
- // 3. 鍒嗘瀽鎷嗗寘璁板綍锛堢姸鎬佷笉鏄凡鎷i�夊拰宸插洖搴撶殑锛�
- var splitRecords = await _splitPackageService.Db.Queryable<Dt_SplitPackageRecord>()
- .Where(x => x.OrderNo == orderNo &&
- x.PalletCode == palletCode &&
- !x.IsReverted &&
- x.Status != (int)SplitPackageStatusEnum.宸叉嫞閫� &&
- x.Status != (int)SplitPackageStatusEnum.宸插洖搴�)
+ // 2. 鍒嗘瀽鎵�鏈夐攣瀹氳褰曪紙宸插垎閰嶅拰鏈垎閰嶏級
+ var allLockInfos = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.OrderNo == orderNo && x.PalletCode == palletCode)
.ToListAsync();
- if (splitRecords.Any())
+ // 鍖哄垎宸插垎閰嶅拰鏈垎閰嶉攣瀹氳褰�
+ var allocatedLocks = allLockInfos
+ .Where(x => x.IsUnallocated != 1 && x.OrderDetailId > 0 &&
+ x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓�)
+ .ToList();
+
+ var unallocatedLocks = allLockInfos
+ .Where(x => (x.IsUnallocated == 1 || x.OrderDetailId == 0) &&
+ x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓�)
+ .ToList();
+
+ // 澶勭悊宸插垎閰嶉攣瀹氳褰�
+ if (allocatedLocks.Any())
{
- result.HasSplitRecords = true;
- result.SplitRecords = splitRecords;
+ result.HasRemainingLocks = true;
+ result.RemainingLocks = allocatedLocks;
- // 璁$畻鎷嗗寘璁板綍鐩稿叧鐨勫洖搴撴暟閲忥紙閬垮厤閲嶅璁$畻锛�
- var splitBarcodes = new HashSet<string>();
- decimal splitReturnQty = 0;
-
- foreach (var splitRecord in splitRecords)
+ // 銆愪慨澶嶃�戝浜庡凡鍒嗛厤閿佸畾璁板綍锛屽洖搴撴暟閲忔槸鏈嫞閫夌殑閮ㄥ垎
+ result.RemainingLocksReturnQty = allocatedLocks.Sum(x =>
{
- // 鍘熸潯鐮�
- if (!string.IsNullOrEmpty(splitRecord.OriginalBarcode) && !splitBarcodes.Contains(splitRecord.OriginalBarcode))
+ var returnQty = x.AssignQuantity - x.PickedQty;
+ return returnQty > 0 ? returnQty : 0;
+ });
+
+ foreach (var lockInfo in allocatedLocks)
+ {
+ if (!string.IsNullOrEmpty(lockInfo.CurrentBarcode))
{
- var originalStock = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
- .FirstAsync(x => x.Barcode == splitRecord.OriginalBarcode && x.StockId == stockId);
-
- if (originalStock != null && originalStock.StockQuantity > 0)
- {
- splitReturnQty += originalStock.StockQuantity;
-
- // 娣诲姞鍒版墍鏈夋潯鐮佸垪琛紙濡傛灉娌℃湁閲嶅锛�
- if (!result.AllBarcodes.Contains(splitRecord.OriginalBarcode))
- {
- result.AllBarcodes.Add(splitRecord.OriginalBarcode);
- }
-
- splitBarcodes.Add(splitRecord.OriginalBarcode);
- _logger.LogInformation($"鎷嗗寘璁板綍 - 鍘熸潯鐮�: {splitRecord.OriginalBarcode}, 鏁伴噺: {originalStock.StockQuantity}");
- }
+ result.AllBarcodes.Add(lockInfo.CurrentBarcode);
+ result.ProcessedBarcodes.Add(lockInfo.CurrentBarcode);
}
-
- // 鏂版潯鐮�
- if (!string.IsNullOrEmpty(splitRecord.NewBarcode) && !splitBarcodes.Contains(splitRecord.NewBarcode))
- {
- var newStock = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
- .FirstAsync(x => x.Barcode == splitRecord.NewBarcode && x.StockId == stockId);
-
- if (newStock != null && newStock.StockQuantity > 0)
- {
- splitReturnQty += newStock.StockQuantity;
-
- // 娣诲姞鍒版墍鏈夋潯鐮佸垪琛紙濡傛灉娌℃湁閲嶅锛�
- if (!result.AllBarcodes.Contains(splitRecord.NewBarcode))
- {
- result.AllBarcodes.Add(splitRecord.NewBarcode);
- }
-
- splitBarcodes.Add(splitRecord.NewBarcode);
- _logger.LogInformation($"鎷嗗寘璁板綍 - 鏂版潯鐮�: {splitRecord.NewBarcode}, 鏁伴噺: {newStock.StockQuantity}");
- }
- }
-
- // 璁板綍鎷嗗寘淇℃伅
- _logger.LogInformation($"鎷嗗寘璁板綍 - ID: {splitRecord.Id}, 鍘熸潯鐮�: {splitRecord.OriginalBarcode}, " +
- $"鏂版潯鐮�: {splitRecord.NewBarcode}, 鎷嗗寘鏁伴噺: {splitRecord.SplitQty}, " +
- $"鏄惁鑷姩: {splitRecord.IsAutoSplit}, 鏄惁鎾ら攢: {splitRecord.IsReverted}");
}
-
- result.SplitReturnQty = splitReturnQty;
- _logger.LogInformation($"鍙戠幇{splitRecords.Count}鏉℃媶鍖呰褰曪紝鍏宠仈 {splitBarcodes.Count} 涓潯鐮侊紝鎬绘暟閲�: {splitReturnQty}");
+ _logger.LogInformation($"鍙戠幇 {allocatedLocks.Count} 鏉″凡鍒嗛厤閿佸畾璁板綍锛屽洖搴撴暟閲�: {result.RemainingLocksReturnQty}");
}
- else
+
+ // 澶勭悊鏈垎閰嶉攣瀹氳褰曪紙鑷姩鎷嗗寘浜х敓鐨勶級
+ if (unallocatedLocks.Any())
{
- _logger.LogInformation($"鏈壘鍒伴渶瑕佸洖搴撶殑鎷嗗寘璁板綍");
+ result.HasUnallocatedLocks = true;
+ result.UnallocatedLocks = unallocatedLocks;
+
+ // 銆愪慨澶嶃�戝浜庢湭鍒嗛厤閿佸畾璁板綍锛屽洖搴撴暟閲忔槸瀹冪殑鍒嗛厤鏁伴噺锛堝洜涓烘湭鎷i�夎繃锛�
+ // 浣嗗疄闄呬笂锛屽簱瀛樻湰鏉ュ氨瀛樺湪锛屽彧鏄姸鎬侀渶瑕佹仮澶�
+ result.UnallocatedLocksReturnQty = unallocatedLocks.Sum(x => x.AssignQuantity);
+
+ foreach (var lockInfo in unallocatedLocks)
+ {
+ if (!string.IsNullOrEmpty(lockInfo.CurrentBarcode) &&
+ !result.ProcessedBarcodes.Contains(lockInfo.CurrentBarcode))
+ {
+ result.AllBarcodes.Add(lockInfo.CurrentBarcode);
+ result.ProcessedBarcodes.Add(lockInfo.CurrentBarcode);
+ }
+ }
+ _logger.LogInformation($"鍙戠幇 {unallocatedLocks.Count} 鏉℃湭鍒嗛厤閿佸畾璁板綍锛屽洖搴撴暟閲忥紙鐘舵�佹仮澶嶏級: {result.UnallocatedLocksReturnQty}");
}
- // 4. 璁$畻鎬诲洖搴撴暟閲忓拰绌烘墭鐩樼姸鎬�
- result.TotalReturnQty = result.RemainingLocksReturnQty +
- result.UnallocatedLocksReturnQty +
- result.PalletStockReturnQty +
- result.SplitReturnQty;
+ // 3. 銆愰噸瑕佷慨澶嶃�戦噸鏂拌绠楁�诲洖搴撴暟閲�
+ // 瀵逛簬宸插垎閰嶉攣瀹氾細鍥炲簱鏁伴噺 = 鏈嫞閫夋暟閲�
+ // 瀵逛簬鏈垎閰嶉攣瀹氾細娌℃湁瀹為檯鐨勫簱瀛樻暟閲忓彉鍖栵紝鍙槸鐘舵�佹仮澶�
+ result.TotalReturnQty = result.RemainingLocksReturnQty; // 鍙绠楀凡鍒嗛厤閿佸畾鐨勫洖搴撴暟閲�
- result.HasItemsToReturn = result.TotalReturnQty > 0;
+ // 璁板綍搴撳瓨鏁伴噺锛堢敤浜庨獙璇侊級
+ decimal totalStockOnPallet = allStockDetails.Sum(x => x.StockQuantity);
+
+ _logger.LogInformation($"鍥炲簱鍒嗘瀽瀹屾垚:");
+ _logger.LogInformation($" 鎵樼洏鎬诲簱瀛�: {totalStockOnPallet}");
+ _logger.LogInformation($" 宸插垎閰嶉攣瀹氬洖搴撴暟閲�: {result.RemainingLocksReturnQty}");
+ _logger.LogInformation($" 鏈垎閰嶉攣瀹氱姸鎬佹仮澶嶆暟閲�: {result.UnallocatedLocksReturnQty}");
+ _logger.LogInformation($" 瀹為檯鐗╃悊鍥炲簱鏁伴噺: {result.TotalReturnQty}");
+
+ result.HasItemsToReturn = result.TotalReturnQty > 0 || result.UnallocatedLocksReturnQty > 0;
result.IsEmptyPallet = !result.HasItemsToReturn;
-
- // 鍘婚噸鎵�鏈夋潯鐮�
- result.AllBarcodes = result.AllBarcodes.Distinct().ToList();
-
- _logger.LogInformation($"鎵樼洏鐘舵�佸垎鏋愬畬鎴� - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}");
- _logger.LogInformation($"姹囨�讳俊鎭�:");
- _logger.LogInformation($" - 宸插垎閰嶉攣瀹氳褰�: {result.RemainingLocks.Count} 鏉�, 鏁伴噺: {result.RemainingLocksReturnQty}");
- _logger.LogInformation($" - 鏈垎閰嶉攣瀹氳褰�: {result.UnallocatedLocks.Count} 鏉�, 鏁伴噺: {result.UnallocatedLocksReturnQty}");
- _logger.LogInformation($" - 鏈垎閰嶅簱瀛樿揣鐗�: {result.PalletStockGoods.Count} 涓�, 鏁伴噺: {result.PalletStockReturnQty}");
- _logger.LogInformation($" - 鎷嗗寘璁板綍: {result.SplitRecords.Count} 鏉�, 鏁伴噺: {result.SplitReturnQty}");
- _logger.LogInformation($" - 鎬诲洖搴撴暟閲�: {result.TotalReturnQty}");
- _logger.LogInformation($" - 鏄惁绌烘墭鐩�: {result.IsEmptyPallet}");
- _logger.LogInformation($" - 娑夊強鏉$爜: {string.Join(", ", result.AllBarcodes)}");
-
- // 5. 棰濆鐨勬暟鎹獙璇�
- await ValidateAnalysisResults(result, stockId);
return result;
}
catch (Exception ex)
{
- _logger.LogError($"鎵樼洏鐘舵�佸垎鏋愬け璐� - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}, Error: {ex.Message}");
+ _logger.LogError($"鍥炲簱鍒嗘瀽澶辫触 - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}, Error: {ex.Message}");
throw;
}
}
+
+
+ /// <summary>
+ /// 楠岃瘉娌℃湁閲嶅鏉$爜
+ /// </summary>
+ private async Task ValidateNoDuplicateBarcodes(PalletStatusAnalysis analysis, List<Dt_StockInfoDetail> allStockDetails)
+ {
+ try
+ {
+ // 妫�鏌llBarcodes涓槸鍚︽湁閲嶅
+ var duplicateBarcodes = analysis.AllBarcodes
+ .GroupBy(b => b)
+ .Where(g => g.Count() > 1)
+ .Select(g => g.Key)
+ .ToList();
+
+ if (duplicateBarcodes.Any())
+ {
+ _logger.LogError($"鍙戠幇閲嶅鏉$爜: {string.Join(", ", duplicateBarcodes)}");
+
+ // 鑷姩鍘婚噸
+ analysis.AllBarcodes = analysis.AllBarcodes.Distinct().ToList();
+ _logger.LogWarning($"宸茶嚜鍔ㄥ幓閲嶏紝鏉$爜鏁�: {analysis.AllBarcodes.Count}");
+ }
+
+ // 妫�鏌ユ瘡涓潯鐮佺殑瀹為檯搴撳瓨
+ decimal totalStockFromBarcodes = 0;
+ foreach (var barcode in analysis.AllBarcodes)
+ {
+ var stock = allStockDetails.FirstOrDefault(x => x.Barcode == barcode);
+ if (stock != null)
+ {
+ totalStockFromBarcodes += stock.StockQuantity;
+ _logger.LogInformation($"鏉$爜搴撳瓨 - {barcode}: {stock.StockQuantity}");
+ }
+ }
+
+ _logger.LogInformation($"鍥炲簱鍒嗘瀽鎬诲簱瀛�: {analysis.TotalReturnQty}, 鏉$爜瀹為檯鎬诲簱瀛�: {totalStockFromBarcodes}");
+
+ // 濡傛灉鍒嗘瀽鐨勬暟閲忓ぇ浜庡疄闄呭簱瀛橈紝璇存槑鏈夐噸澶嶈绠�
+ if (analysis.TotalReturnQty > totalStockFromBarcodes * 1.1m) // 鍏佽10%鐨勮宸�
+ {
+ _logger.LogError($"鍥炲簱鏁伴噺({analysis.TotalReturnQty})鏄庢樉澶т簬瀹為檯搴撳瓨({totalStockFromBarcodes})锛屽彲鑳藉瓨鍦ㄩ噸澶嶈绠楋紒");
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError($"楠岃瘉閲嶅鏉$爜澶辫触: {ex.Message}");
+ }
+ }
+
/// <summary>
/// 楠岃瘉鍒嗘瀽缁撴灉锛岀‘淇濇暟鎹竴鑷存��
@@ -3499,7 +4237,7 @@
}
/// <summary>
- /// 鍙栬蛋绌虹 - 鍏堟墽琛屽洖搴撳啀娓呯悊
+ /// 鍙栬蛋绌虹 - 淇鐗堬紝姝g‘澶勭悊鏈垎閰嶉攣瀹氳褰�
/// </summary>
public async Task<WebResponseContent> RemoveEmptyPallet(string orderNo, string palletCode)
{
@@ -3512,35 +4250,79 @@
// 1. 鍏堝皾璇曟墽琛屽洖搴撴搷浣滐紝纭繚鎵�鏈夌墿鍝侀兘鍥炲簱
_logger.LogInformation($"姝ラ1: 鍏堟墽琛屽洖搴撴搷浣�");
var returnResult = await ExecutePalletReturn(orderNo, palletCode, "鍙栬蛋绌虹鍓嶅洖搴�");
+
+ // 鍗充娇鍥炲簱澶辫触锛岀户缁獙璇佺┖绠辨潯浠讹紙鍙兘鏄湡鐨勭┖鎵樼洏锛�
if (!returnResult.Status)
{
- // 鍥炲簱澶辫触锛屽彲鑳芥槸绌烘墭鐩樻垨鑰呮湁鍏朵粬闂
- _logger.LogWarning($"鍥炲簱鎿嶄綔澶辫触: {returnResult.Message}");
-
- // 缁х画楠岃瘉绌虹鍙栬蛋鏉′欢
+ _logger.LogWarning($"鍥炲簱鎿嶄綔鍙兘澶辫触鎴栨棤鐗╁搧: {returnResult.Message}");
}
- // 2. 楠岃瘉绌虹鍙栬蛋鏉′欢锛堝繀椤诲叏閮ㄥ畬鎴愭嫞閫夛級
+ // 2. 楠岃瘉绌虹鍙栬蛋鏉′欢锛堝繀椤诲叏閮ㄥ畬鎴愭嫞閫夋垨宸插洖搴擄級
_logger.LogInformation($"姝ラ2: 楠岃瘉绌虹鍙栬蛋鏉′欢");
- var validationResult = await ValidateEmptyPalletRemoval(orderNo, palletCode);
- if (!validationResult.IsValid)
+
+ // 鑾峰彇鎵樼洏鐨勬墍鏈夐攣瀹氳褰曪紙鍖呮嫭宸插洖搴撳拰宸插彇璧扮殑锛�
+ var allLockInfos = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.OrderNo == orderNo && x.PalletCode == palletCode)
+ .ToListAsync();
+
+ if (!allLockInfos.Any())
{
_unitOfWorkManage.RollbackTran();
- _logger.LogError($"绌虹楠岃瘉澶辫触: {validationResult.ErrorMessage}");
- return WebResponseContent.Instance.Error(validationResult.ErrorMessage);
+ return WebResponseContent.Instance.Error("璇ユ墭鐩樻病鏈夐攣瀹氳褰�");
}
- var completedLocks = validationResult.Data;
+ // 銆愪慨姝c�戞鏌ユ槸鍚︽湁鏈畬鎴愮殑閿佸畾璁板綍
+ var unfinishedLocks = allLockInfos.Where(x =>
+ x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓� ||
+ x.Status == (int)OutLockStockStatusEnum.鍥炲簱涓�).ToList();
+
+ if (unfinishedLocks.Any())
+ {
+ var unfinishedCount = unfinishedLocks.Count;
+ // 鍖哄垎宸插垎閰嶅拰鏈垎閰�
+ var allocatedUnfinished = unfinishedLocks.Where(x => x.IsUnallocated != 1).ToList();
+ var unallocatedUnfinished = unfinishedLocks.Where(x => x.IsUnallocated == 1).ToList();
+
+ string errorMsg = $"鎵樼洏杩樻湁{unfinishedCount}鏉℃湭瀹屾垚璁板綍";
+ if (allocatedUnfinished.Any()) errorMsg += $"锛屽叾涓凡鍒嗛厤{allocatedUnfinished.Count}鏉�";
+ if (unallocatedUnfinished.Any()) errorMsg += $"锛屾湭鍒嗛厤{unallocatedUnfinished.Count}鏉�";
+
+ errorMsg += "锛屼笉鑳藉彇璧扮┖绠�";
+
+ _unitOfWorkManage.RollbackTran();
+ return WebResponseContent.Instance.Error(errorMsg);
+ }
+
+ // 鑾峰彇宸插畬鎴愮殑閿佸畾璁板綍锛堢姸鎬佷负鎷i�夊畬鎴愭垨宸插彇璧帮級
+ var completedLocks = allLockInfos.Where(x =>
+ x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴� ||
+ x.Status == (int)OutLockStockStatusEnum.宸插彇璧�).ToList();
+
+ if (!completedLocks.Any())
+ {
+ // 妫�鏌ユ槸鍚﹂兘鏄凡鍥炲簱鐘舵��
+ var returnedLocks = allLockInfos.Where(x => x.Status == (int)OutLockStockStatusEnum.宸插洖搴�).ToList();
+ if (returnedLocks.Any())
+ {
+ _logger.LogInformation($"鎵�鏈夐攣瀹氳褰曢兘宸插洖搴擄紝鍙互鍙栬蛋绌虹");
+ completedLocks = returnedLocks;
+ }
+ else
+ {
+ _unitOfWorkManage.RollbackTran();
+ return WebResponseContent.Instance.Error("璇ユ墭鐩樻病鏈夊凡瀹屾垚鎷i�夋垨宸插洖搴撶殑璁板綍");
+ }
+ }
+
_logger.LogInformation($"楠岃瘉閫氳繃锛屾壘鍒� {completedLocks.Count} 鏉″凡瀹屾垚璁板綍");
// 3. 娓呯悊宸插畬鎴愮殑閿佸畾璁板綍锛堟爣璁颁负宸插彇璧帮級
_logger.LogInformation($"姝ラ3: 娓呯悊閿佸畾璁板綍");
foreach (var lockInfo in completedLocks)
{
- // 鍙鐞嗙姸鎬佷负鎷i�夊畬鎴愮殑璁板綍锛堝凡鍙栬蛋鐨勮烦杩囷級
- if (lockInfo.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�)
+ // 鍙鐞嗙姸鎬佷笉鏄凡鍙栬蛋鐨勮褰�
+ if (lockInfo.Status != (int)OutLockStockStatusEnum.宸插彇璧�)
{
- // 鏍囪閿佸畾璁板綍涓哄凡鍙栬蛋
lockInfo.Status = (int)OutLockStockStatusEnum.宸插彇璧�;
lockInfo.Operator = App.User.UserName;
await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
@@ -3576,6 +4358,8 @@
return WebResponseContent.Instance.Error($"鍙栬蛋绌虹澶辫触锛歿ex.Message}");
}
}
+
+
/// <summary>
/// 鏀堕泦闇�瑕佸洖搴撶殑鏉$爜
/// </summary>
@@ -4304,9 +5088,6 @@
#endregion
-
-
-
#region 楠岃瘉鏂规硶
private async Task<ValidationResult<(Dt_OutStockLockInfo, Dt_OutboundOrderDetail, Dt_StockInfoDetail, Dt_OutboundBatch)>> ValidatePickingRequest(
string orderNo, string palletCode, string barcode)
@@ -4410,6 +5191,7 @@
_logger.LogInformation($"璺宠繃鏈垎閰嶉攣瀹氳褰曠殑鑷姩鎷嗗寘妫�鏌� - 閿佸畾ID: {lockInfo.Id}");
return null;
}
+
// 妫�鏌ユ槸鍚﹂渶瑕佽嚜鍔ㄦ媶鍖呯殑鏉′欢锛�
// 1. 搴撳瓨鏁伴噺澶т簬鍒嗛厤鏁伴噺
// 2. 閿佸畾淇℃伅鐘舵�佷负鍑哄簱涓�
@@ -4424,127 +5206,134 @@
// 璁$畻鎷嗗寘鏁伴噺 = 搴撳瓨鏁伴噺 - 鍒嗛厤鏁伴噺
decimal splitQuantity = stockDetail.StockQuantity - lockInfo.AssignQuantity;
+ _logger.LogInformation($"闇�瑕佽嚜鍔ㄦ媶鍖� - 搴撳瓨: {stockDetail.StockQuantity}, 鍒嗛厤: {lockInfo.AssignQuantity}, 鎷嗗寘鏁伴噺: {splitQuantity}");
+
// 鎵ц鑷姩鎷嗗寘
var splitResult = await ExecuteAutoSplitLogic(lockInfo, stockDetail, splitQuantity, palletCode);
+
+ // 灏嗘媶鍖呮暟閲忎紶閫掔粰璋冪敤鏂癸紝鐢ㄤ簬楠岃瘉
+ if (splitResult != null && splitResult.Any())
+ {
+ // 鍦ㄨ繑鍥炵粨鏋滀腑鎼哄甫鎷嗗寘鏁伴噺淇℃伅
+ foreach (var result in splitResult)
+ {
+ result.quantityTotal = splitQuantity.ToString("F2");
+ }
+ }
return splitResult;
}
/// <summary>
- /// 鎵ц鑷姩鎷嗗寘閫昏緫
- /// 纭繚鑷姩鎷嗗寘涓嶄細褰卞搷鍥炲簱閫昏緫
+ /// 鎵ц鑷姩鎷嗗寘閫昏緫 - 瀹屽叏淇鐗�
+ /// 鍘熷垯锛氬彧鍒嗙鐗╃悊搴撳瓨锛屼笉鏀瑰彉鍘熻鍗曠殑浠讳綍鍒嗛厤鍜屽嚭搴撴暟閲�
/// </summary>
private async Task<List<SplitResult>> ExecuteAutoSplitLogic(Dt_OutStockLockInfo lockInfo, Dt_StockInfoDetail stockDetail,
decimal splitQuantity, string palletCode)
{
_logger.LogInformation($"寮�濮嬫墽琛岃嚜鍔ㄦ媶鍖呴�昏緫 - 鍘熸潯鐮�: {stockDetail.Barcode}, 鎷嗗寘鏁伴噺: {splitQuantity}");
- // 楠岃瘉鎷嗗寘鏁伴噺鍚堢悊鎬�
- if (splitQuantity <= 0)
+ try
{
- throw new InvalidOperationException($"鎷嗗寘鏁伴噺蹇呴』澶т簬0锛屽綋鍓嶅��: {splitQuantity}");
+ // 1. 楠岃瘉鎷嗗寘鏁伴噺鍚堢悊鎬�
+ if (splitQuantity <= 0)
+ throw new InvalidOperationException($"鎷嗗寘鏁伴噺蹇呴』澶т簬0锛屽綋鍓嶅��: {splitQuantity}");
+
+ if (stockDetail.StockQuantity < lockInfo.AssignQuantity + splitQuantity)
+ throw new InvalidOperationException($"搴撳瓨鏁伴噺涓嶈冻浠ヨ繘琛岃嚜鍔ㄦ媶鍖咃紝搴撳瓨: {stockDetail.StockQuantity}, 闇�瑕�: {lockInfo.AssignQuantity + splitQuantity}");
+
+ // 2. 鐢熸垚鏂版潯鐮�
+ string newBarcode = await GenerateNewBarcode();
+ _logger.LogInformation($"鐢熸垚鏂版潯鐮�: {newBarcode}");
+
+ // 3. 銆愭牳蹇冧慨姝c�戞洿鏂板師搴撳瓨鏄庣粏锛氬彧鍑忓皯鐗╃悊搴撳瓨锛屼笉褰卞搷鍑哄簱鏁伴噺
+ decimal originalStockQty = stockDetail.StockQuantity;
+ stockDetail.StockQuantity -= splitQuantity; // 浠呭簱瀛樺噺灏�
+ // stockDetail.OutboundQuantity 淇濇寔涓嶅彉锛�
+
+ await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
+ _logger.LogInformation($"鏇存柊鍘熷簱瀛樻槑缁嗭細鏉$爜 {stockDetail.Barcode} 搴撳瓨 {originalStockQty} -> {stockDetail.StockQuantity}锛屽嚭搴撴暟閲忎笉鍙�({stockDetail.OutboundQuantity})");
+
+ // 4. 鍒涘缓鏂板簱瀛樻槑缁嗭紙澶氫綑閮ㄥ垎锛�- 鍑哄簱鏁伴噺涓�0
+ var newStockDetail = new Dt_StockInfoDetail
+ {
+ StockId = stockDetail.StockId,
+ MaterielCode = stockDetail.MaterielCode,
+ OrderNo = stockDetail.OrderNo,
+ BatchNo = stockDetail.BatchNo,
+ StockQuantity = splitQuantity, // 鏂板簱瀛樻暟閲�
+ OutboundQuantity = 0, // 銆愰噸鐐广�戝垵濮嬪嚭搴撴暟閲忎负0
+ Barcode = newBarcode,
+ Status = (int)StockStatusEmun.鍑哄簱閿佸畾, // 浠嶄负閿佸畾鐘舵�侊紝浣嗘湭缁戝畾璁㈠崟
+ SupplyCode = stockDetail.SupplyCode,
+ Unit = stockDetail.Unit,
+ BarcodeQty = stockDetail.BarcodeQty,
+ BarcodeUnit = stockDetail.BarcodeUnit,
+ BusinessType = stockDetail.BusinessType,
+ InboundOrderRowNo = stockDetail.InboundOrderRowNo,
+ };
+
+ await _stockInfoDetailService.Db.Insertable(newStockDetail).ExecuteCommandAsync();
+ _logger.LogInformation($"鍒涘缓鏂板簱瀛樻槑缁嗭細鏉$爜 {newBarcode}锛屽簱瀛� {splitQuantity}锛屽嚭搴� 0");
+
+ // 5. 鍒涘缓鏂伴攣瀹氫俊鎭� - 鏍囪涓烘湭鍒嗛厤
+ var newLockInfo = new Dt_OutStockLockInfo
+ {
+ OrderNo = lockInfo.OrderNo,
+ OrderDetailId = 0, // 銆愰噸鐐广�戜笉缁戝畾鍒板叿浣撹鍗曟槑缁嗭紝琛ㄧず鏈垎閰�
+ OutboundBatchNo = lockInfo.OutboundBatchNo,
+ MaterielCode = lockInfo.MaterielCode,
+ MaterielName = lockInfo.MaterielName,
+ StockId = lockInfo.StockId,
+ OrderQuantity = splitQuantity,
+ AssignQuantity = splitQuantity,
+ PickedQty = 0,
+ LocationCode = lockInfo.LocationCode,
+ PalletCode = lockInfo.PalletCode,
+ TaskNum = lockInfo.TaskNum,
+ Status = (int)OutLockStockStatusEnum.鍑哄簱涓�,
+ Unit = lockInfo.Unit,
+ SupplyCode = lockInfo.SupplyCode,
+ OrderType = lockInfo.OrderType,
+ CurrentBarcode = newBarcode,
+ IsSplitted = 1,
+ ParentLockId = lockInfo.Id,
+ Operator = App.User.UserName,
+ FactoryArea = lockInfo.FactoryArea,
+ lineNo = lockInfo.lineNo,
+ WarehouseCode = lockInfo.WarehouseCode,
+ BarcodeQty = lockInfo.BarcodeQty,
+ BarcodeUnit = lockInfo.BarcodeUnit,
+ IsUnallocated = 1 // 銆愰噸鐐广�戞槑纭爣璁颁负"鏈垎閰�"鐨勯攣瀹氳褰�
+ };
+
+ await _outStockLockInfoService.Db.Insertable(newLockInfo).ExecuteCommandAsync();
+ _logger.LogInformation($"鍒涘缓鏈垎閰嶉攣瀹氳褰曪細ID {newLockInfo.Id}锛屾潯鐮� {newBarcode}锛屾暟閲� {splitQuantity}");
+
+ // 6. 銆愬叧閿慨姝c�戝師閿佸畾璁板綍鍜屽師璁㈠崟鏄庣粏鏁版嵁瀹屽叏淇濇寔涓嶅彉锛�
+ // - 涓嶄慨鏀� lockInfo 鐨勪换浣曞瓧娈�
+ // - 涓嶄慨鏀瑰叧鑱旂殑 Dt_OutboundOrderDetail 鐨� AllocatedQuantity 鍜� LockQuantity
+
+ // 璁板綍鎷嗗寘鍘嗗彶
+ await RecordSplitHistory(lockInfo, stockDetail, splitQuantity, newBarcode, true, originalStockQty);
+
+ // 鍒涘缓鎷嗗寘缁撴灉鍒楄〃
+ var splitResults = CreateSplitResults(lockInfo, splitQuantity, lockInfo.AssignQuantity, newBarcode, stockDetail.Barcode);
+
+ _logger.LogInformation($"鑷姩鎷嗗寘閫昏緫鎵ц瀹屾垚 - 鍒涘缓浜嗘湭鍒嗛厤鐨勫簱瀛樺拰閿佸畾璁板綍");
+
+ return splitResults;
}
-
- if (stockDetail.StockQuantity < lockInfo.AssignQuantity + splitQuantity)
+ catch (Exception ex)
{
- throw new InvalidOperationException($"搴撳瓨鏁伴噺涓嶈冻浠ヨ繘琛岃嚜鍔ㄦ媶鍖�");
+ _logger.LogError($"鑷姩鎷嗗寘閫昏緫鎵ц澶辫触 - 鍘熸潯鐮�: {stockDetail.Barcode}, Error: {ex.Message}");
+ throw;
}
-
- // 鐢熸垚鏂版潯鐮�
- string newBarcode = await GenerateNewBarcode();
-
- // 璁板綍鎷嗗寘鍓嶇殑鍒嗛厤鏁伴噺
- decimal originalAssignQty = lockInfo.AssignQuantity;
- decimal remainQty = originalAssignQty; // 鍘熼攣瀹氫俊鎭垎閰嶆暟閲忎繚鎸佷笉鍙�
-
- // 鍒涘缓鏂板簱瀛樻槑缁嗭紙澶氫綑閮ㄥ垎锛�
- var newStockDetail = new Dt_StockInfoDetail
- {
- StockId = stockDetail.StockId,
- MaterielCode = stockDetail.MaterielCode,
- OrderNo = stockDetail.OrderNo,
- BatchNo = stockDetail.BatchNo,
- StockQuantity = splitQuantity,
- OutboundQuantity = 0,
- Barcode = newBarcode,
- Status = (int)StockStatusEmun.鍑哄簱閿佸畾,
- SupplyCode = stockDetail.SupplyCode,
- Unit = stockDetail.Unit,
- BarcodeQty = stockDetail.BarcodeQty,
- BarcodeUnit = stockDetail.BarcodeUnit,
- BusinessType = stockDetail.BusinessType,
- InboundOrderRowNo = stockDetail.InboundOrderRowNo,
- };
-
- await _stockInfoDetailService.Db.Insertable(newStockDetail).ExecuteCommandAsync();
- _logger.LogInformation($"鍒涘缓鏂板簱瀛樻槑缁� - 鏉$爜: {newBarcode}, 搴撳瓨鏁伴噺: {splitQuantity}");
-
- // 鍒涘缓鏂伴攣瀹氫俊鎭紙澶氫綑閮ㄥ垎锛�- 鏍囪涓烘湭鍒嗛厤
- var newLockInfo = new Dt_OutStockLockInfo
- {
- OrderNo = lockInfo.OrderNo,
- OrderDetailId = 0, // 閲嶈锛氫笉缁戝畾鍒板叿浣撹鍗曟槑缁�
- OutboundBatchNo = lockInfo.OutboundBatchNo,
- MaterielCode = lockInfo.MaterielCode,
- MaterielName = lockInfo.MaterielName,
- StockId = lockInfo.StockId,
- OrderQuantity = splitQuantity,
- AssignQuantity = splitQuantity,
- PickedQty = 0,
- LocationCode = lockInfo.LocationCode,
- PalletCode = lockInfo.PalletCode,
- TaskNum = lockInfo.TaskNum,
- Status = (int)OutLockStockStatusEnum.鍑哄簱涓�,
- Unit = lockInfo.Unit,
- SupplyCode = lockInfo.SupplyCode,
- OrderType = lockInfo.OrderType,
- CurrentBarcode = newBarcode,
- IsSplitted = 1,
- ParentLockId = lockInfo.Id,
- Operator = App.User.UserName,
- FactoryArea = lockInfo.FactoryArea,
- lineNo = lockInfo.lineNo,
- WarehouseCode = lockInfo.WarehouseCode,
- BarcodeQty = lockInfo.BarcodeQty,
- BarcodeUnit = lockInfo.BarcodeUnit,
- IsUnallocated = 1 // 鏍囪涓烘湭鍒嗛厤
- };
-
- await _outStockLockInfoService.Db.Insertable(newLockInfo).ExecuteCommandAsync();
- _logger.LogInformation($"鍒涘缓鏂伴攣瀹氫俊鎭� - 鏉$爜: {newBarcode}, 鍒嗛厤鏁伴噺: {splitQuantity}, 鏍囪涓烘湭鍒嗛厤");
-
- // 閲嶈锛氳嚜鍔ㄦ媶鍖呴渶瑕佸鍔犺鍗曟槑缁嗙殑鍒嗛厤鏁伴噺鍜岄攣瀹氭暟閲�
- var orderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
- .FirstAsync(x => x.Id == lockInfo.OrderDetailId);
-
- if (orderDetail != null)
- {
- decimal originalAllocated = orderDetail.AllocatedQuantity;
- decimal originalLock = orderDetail.LockQuantity;
-
- orderDetail.AllocatedQuantity += splitQuantity;
- orderDetail.LockQuantity += splitQuantity;
-
- await UpdateBatchAllocateStatus(orderDetail);
- await _outboundOrderDetailService.Db.Updateable(orderDetail).ExecuteCommandAsync();
-
- _logger.LogInformation($"鑷姩鎷嗗寘澧炲姞璁㈠崟鏄庣粏鍒嗛厤 - 鍒嗛厤鏁伴噺: {originalAllocated} -> {orderDetail.AllocatedQuantity}, " +
- $"閿佸畾鏁伴噺: {originalLock} -> {orderDetail.LockQuantity}");
- }
-
- // 璁板綍鎷嗗寘鍘嗗彶
- await RecordSplitHistory(lockInfo, stockDetail, splitQuantity, newBarcode, true, stockDetail.StockQuantity);
-
- // 鍒涘缓鎷嗗寘缁撴灉鍒楄〃
- var splitResults = CreateSplitResults(lockInfo, splitQuantity, remainQty, newBarcode, stockDetail.Barcode);
-
- _logger.LogInformation($"鑷姩鎷嗗寘閫昏緫鎵ц瀹屾垚");
-
- return splitResults;
}
/// <summary>
- /// 楠岃瘉鑷姩鎷嗗寘鍚庢暟鎹竴鑷存��
+ /// 楠岃瘉鑷姩鎷嗗寘鍚庢暟鎹竴鑷存�� - 淇鐗�
+ /// 鍘熷垯锛氶獙璇佹湭鍒嗛厤閿佸畾璁板綍鐨勫垱寤猴紝鑰屼笉鏄鍗曟槑缁嗘暟閲忕殑鍙樺寲
/// </summary>
private async Task ValidateDataConsistencyAfterAutoSplit(long orderDetailId, decimal originalAllocatedQty, decimal originalLockQty, decimal splitQuantity)
{
@@ -4555,60 +5344,104 @@
if (orderDetail == null)
return;
- // 璁$畻鎵�鏈夐攣瀹氫俊鎭殑鎬诲垎閰嶆暟閲�
- var allLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
- .Where(x => x.OrderDetailId == orderDetailId)
- .ToListAsync();
-
- decimal totalLockAssignQty = allLocks.Sum(x => x.AssignQuantity);
-
- _logger.LogInformation($"鑷姩鎷嗗寘鍚庢暟鎹竴鑷存�ч獙璇� - 璁㈠崟鏄庣粏鍒嗛厤鏁伴噺: {orderDetail.AllocatedQuantity}, 閿佸畾淇℃伅鎬诲垎閰嶆暟閲�: {totalLockAssignQty}");
-
- // 楠岃瘉鑷姩鎷嗗寘鍚庣殑鏁版嵁涓�鑷存��
- decimal expectedAllocatedQty = originalAllocatedQty + splitQuantity;
- decimal expectedLockQty = originalLockQty + splitQuantity;
-
- if (Math.Abs(orderDetail.AllocatedQuantity - expectedAllocatedQty) > 0.01m)
+ // 銆愪慨姝c�戣嚜鍔ㄦ媶鍖呭悗锛岃鍗曟槑缁嗗垎閰嶆暟閲忓簲璇ヤ繚鎸佷笉鍙橈紒
+ if (Math.Abs(orderDetail.AllocatedQuantity - originalAllocatedQty) > 0.01m)
{
- _logger.LogWarning($"鑷姩鎷嗗寘鍚庡垎閰嶆暟閲忓紓甯� - 鏈熸湜: {expectedAllocatedQty}, 瀹為檯: {orderDetail.AllocatedQuantity}");
+ _logger.LogError($"鑷姩鎷嗗寘鍚庤鍗曟槑缁嗗垎閰嶆暟閲忓紓甯稿彉鍖栵紒鏈熸湜淇濇寔涓嶅彉: {originalAllocatedQty}, 瀹為檯: {orderDetail.AllocatedQuantity}");
+ // 璁板綍涓ラ噸閿欒锛屼絾涓嶆姏鍑哄紓甯革紙鐢熶骇鐜鍙兘闇�瑕佸憡璀︼級
}
- if (Math.Abs(orderDetail.LockQuantity - expectedLockQty) > 0.01m)
+ if (Math.Abs(orderDetail.LockQuantity - originalLockQty) > 0.01m)
{
- _logger.LogWarning($"鑷姩鎷嗗寘鍚庨攣瀹氭暟閲忓紓甯� - 鏈熸湜: {expectedLockQty}, 瀹為檯: {orderDetail.LockQuantity}");
+ _logger.LogError($"鑷姩鎷嗗寘鍚庤鍗曟槑缁嗛攣瀹氭暟閲忓紓甯稿彉鍖栵紒鏈熸湜淇濇寔涓嶅彉: {originalLockQty}, 瀹為檯: {orderDetail.LockQuantity}");
}
- if (Math.Abs(orderDetail.AllocatedQuantity - totalLockAssignQty) > 0.01m)
+ // 楠岃瘉鏈垎閰嶉攣瀹氳褰曠殑鍒涘缓
+ // 鏌ユ壘鐖堕攣瀹氳褰�
+ var parentLockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .FirstAsync(x => x.OrderDetailId == orderDetailId);
+
+ if (parentLockInfo != null)
{
- _logger.LogWarning($"鑷姩鎷嗗寘鍚庢暟鎹笉涓�鑷� - 璁㈠崟鏄庣粏鍒嗛厤鏁伴噺: {orderDetail.AllocatedQuantity}, 閿佸畾淇℃伅鎬诲垎閰嶆暟閲�: {totalLockAssignQty}");
+ // 鏌ユ壘鏈垎閰嶇殑瀛愰攣瀹氳褰曪紙鑷姩鎷嗗寘鐢熸垚鐨勶級
+ var unallocatedChildLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.ParentLockId == parentLockInfo.Id &&
+ x.IsUnallocated == 1 &&
+ x.OrderDetailId == 0)
+ .ToListAsync();
+
+ if (unallocatedChildLocks.Any())
+ {
+ decimal totalUnallocatedQty = unallocatedChildLocks.Sum(x => x.AssignQuantity);
+ _logger.LogInformation($"楠岃瘉閫氳繃锛氬垱寤轰簡{unallocatedChildLocks.Count}鏉℃湭鍒嗛厤閿佸畾璁板綍锛屾�绘暟閲�: {totalUnallocatedQty}");
+
+ if (Math.Abs(totalUnallocatedQty - splitQuantity) > 0.01m)
+ {
+ _logger.LogWarning($"鏈垎閰嶉攣瀹氳褰曟�绘暟閲忎笌鎷嗗寘鏁伴噺涓嶅尮閰嶏紝鎷嗗寘鏁伴噺: {splitQuantity}, 鏈垎閰嶆�绘暟: {totalUnallocatedQty}");
+ }
+ }
+ else
+ {
+ _logger.LogWarning($"鏈壘鍒拌嚜鍔ㄦ媶鍖呯敓鎴愮殑鏈垎閰嶉攣瀹氳褰�");
+ }
}
+
+ _logger.LogInformation($"鑷姩鎷嗗寘鏁版嵁涓�鑷存�ч獙璇佸畬鎴�");
}
+
#endregion
#region 鏍稿績閫昏緫鏂规硶
+ /// <summary>
+ /// 鎵ц鍒嗘嫞閫昏緫 - 瀹屽叏淇鐗�
+ /// 纭繚OutboundQuantity鍑嗙‘绱姞锛屼笉鍖呭惈鎷嗗寘鏁伴噺
+ /// </summary>
private async Task<PickingResult> ExecutePickingLogic(
Dt_OutStockLockInfo lockInfo, Dt_OutboundOrderDetail orderDetail,
Dt_StockInfoDetail stockDetail, decimal actualPickedQty)
{
_logger.LogInformation($"寮�濮嬫墽琛屽垎鎷i�昏緫 - 鏉$爜: {stockDetail.Barcode}, 鍒嗛厤鏁伴噺: {lockInfo.AssignQuantity}, 瀹為檯鎷i��: {actualPickedQty}");
- // 鍐嶆楠岃瘉璁㈠崟鏄庣粏鐨勫垎閰嶆暟閲忥紙闃叉骞跺彂鎿嶄綔锛�
- if (orderDetail.AllocatedQuantity < actualPickedQty)
+ // 鍐嶆楠岃瘉搴撳瓨鏁伴噺
+ if (stockDetail.StockQuantity < actualPickedQty)
{
- throw new InvalidOperationException($"璁㈠崟鏄庣粏鍒嗛厤鏁伴噺涓嶈冻锛岄渶瑕佹嫞閫� {actualPickedQty}锛屽彲鐢ㄥ垎閰嶆暟閲� {orderDetail.AllocatedQuantity}");
+ throw new InvalidOperationException($"搴撳瓨鏁伴噺涓嶈冻锛岄渶瑕佹嫞閫� {actualPickedQty}锛屽疄闄呭簱瀛� {stockDetail.StockQuantity}");
}
- if (orderDetail.LockQuantity < actualPickedQty)
+ // 璁板綍鎷i�夊墠鐨勫��
+ decimal originalStockQty = stockDetail.StockQuantity;
+ decimal originalOutboundQty = stockDetail.OutboundQuantity;
+ int originalStatus = stockDetail.Status;
+
+ // 銆愭牳蹇冧慨姝c�戠‘淇漁utboundQuantity鍙鍔犳湰娆℃嫞閫夋暟閲忥紝涓嶅寘鍚叾浠�
+ stockDetail.StockQuantity -= actualPickedQty;
+ stockDetail.OutboundQuantity += actualPickedQty; // 鍙鍔犳湰娆℃嫞閫夋暟閲�
+
+ _logger.LogInformation($"鏇存柊搴撳瓨淇℃伅 - 鏉$爜: {stockDetail.Barcode}");
+ _logger.LogInformation($" 搴撳瓨鏁伴噺: {originalStockQty} -> {stockDetail.StockQuantity}");
+ _logger.LogInformation($" 鍑哄簱鏁伴噺: {originalOutboundQty} -> {stockDetail.OutboundQuantity}");
+
+ // 鏇存柊搴撳瓨鐘舵��
+ if (stockDetail.StockQuantity <= 0)
{
- throw new InvalidOperationException($"璁㈠崟鏄庣粏閿佸畾鏁伴噺涓嶈冻锛岄渶瑕佹嫞閫� {actualPickedQty}锛屽彲鐢ㄩ攣瀹氭暟閲� {orderDetail.LockQuantity}");
+ stockDetail.Status = (int)StockStatusEmun.鍑哄簱瀹屾垚;
+ _logger.LogInformation($"搴撳瓨鐘舵�佹洿鏂颁负鍑哄簱瀹屾垚");
}
+ else
+ {
+ stockDetail.Status = (int)StockStatusEmun.鍑哄簱閿佸畾;
+ _logger.LogInformation($"搴撳瓨鐘舵�佷繚鎸佷负鍑哄簱閿佸畾");
+ }
+
+ await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
// 鏇存柊閿佸畾淇℃伅
+ decimal originalPickedQty = lockInfo.PickedQty;
lockInfo.PickedQty += actualPickedQty;
- _logger.LogInformation($"鏇存柊閿佸畾淇℃伅 - 宸叉嫞閫夋暟閲忎粠 {lockInfo.PickedQty - actualPickedQty} 澧炲姞鍒� {lockInfo.PickedQty}");
+ _logger.LogInformation($"鏇存柊閿佸畾淇℃伅 - 宸叉嫞閫夋暟閲忎粠 {originalPickedQty} 澧炲姞鍒� {lockInfo.PickedQty}");
- // 鍑嗙‘鍒ゆ柇鎷i�夊畬鎴愮姸鎬�
+ // 鍒ゆ柇鎷i�夊畬鎴愮姸鎬�
if (Math.Abs(lockInfo.PickedQty - lockInfo.AssignQuantity) < 0.001m)
{
lockInfo.Status = (int)OutLockStockStatusEnum.鎷i�夊畬鎴�;
@@ -4623,29 +5456,8 @@
lockInfo.Operator = App.User.UserName;
await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
- // 鏇存柊搴撳瓨淇℃伅
- decimal originalStockQty = stockDetail.StockQuantity;
- decimal originalOutboundQty = stockDetail.OutboundQuantity;
-
- stockDetail.StockQuantity -= actualPickedQty;
- stockDetail.OutboundQuantity += actualPickedQty;
-
- _logger.LogInformation($"鏇存柊搴撳瓨淇℃伅 - 搴撳瓨鏁伴噺浠� {originalStockQty} 鍑忓皯鍒� {stockDetail.StockQuantity}");
- _logger.LogInformation($"鏇存柊搴撳瓨淇℃伅 - 鍑哄簱鏁伴噺浠� {originalOutboundQty} 澧炲姞鍒� {stockDetail.OutboundQuantity}");
-
- // 鍑嗙‘鍒ゆ柇搴撳瓨鐘舵��
- if (stockDetail.StockQuantity <= 0)
- {
- stockDetail.Status = (int)StockStatusEmun.鍑哄簱瀹屾垚;
- _logger.LogInformation($"搴撳瓨鐘舵�佹洿鏂颁负鍑哄簱瀹屾垚");
- }
- else
- {
- stockDetail.Status = (int)StockStatusEmun.鍑哄簱閿佸畾;
- _logger.LogInformation($"搴撳瓨鐘舵�佷繚鎸佷负鍑哄簱閿佸畾");
- }
-
- await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
+ // 楠岃瘉鎷i�夊悗鐨勬暟鎹竴鑷存��
+ await ValidatePickingDataConsistency(lockInfo, stockDetail, actualPickedQty);
_logger.LogInformation($"鍒嗘嫞閫昏緫鎵ц瀹屾垚 - 鏉$爜: {stockDetail.Barcode}");
@@ -4654,6 +5466,40 @@
FinalLockInfo = lockInfo,
ActualPickedQty = actualPickedQty
};
+ }
+
+ /// <summary>
+ /// 楠岃瘉鎷i�夊悗鏁版嵁涓�鑷存��
+ /// </summary>
+ private async Task ValidatePickingDataConsistency(Dt_OutStockLockInfo lockInfo, Dt_StockInfoDetail stockDetail, decimal pickedQty)
+ {
+ _logger.LogInformation($"楠岃瘉鎷i�夋暟鎹竴鑷存�� - 鏉$爜: {stockDetail.Barcode}");
+
+ // 1. 楠岃瘉搴撳瓨鏄庣粏鐨凮utboundQuantity澧炲姞閲忕瓑浜庢嫞閫夋暟閲�
+ var refreshedStockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .FirstAsync(x => x.Id == stockDetail.Id);
+
+ decimal outboundIncrease = refreshedStockDetail.OutboundQuantity - stockDetail.OutboundQuantity;
+
+ if (Math.Abs(outboundIncrease - pickedQty) > 0.01m)
+ {
+ _logger.LogError($"鎷i�夋暟鎹笉涓�鑷达細鍑哄簱鏁伴噺澧炲姞 {outboundIncrease}锛屼絾鎷i�夋暟閲忔槸 {pickedQty}");
+ // 淇锛氱‘淇漁utboundQuantity姝g‘
+ refreshedStockDetail.OutboundQuantity = stockDetail.OutboundQuantity + pickedQty;
+ await _stockInfoDetailService.Db.Updateable(refreshedStockDetail).ExecuteCommandAsync();
+ _logger.LogWarning($"宸蹭慨澶嶅嚭搴撴暟閲忥細{stockDetail.OutboundQuantity} -> {refreshedStockDetail.OutboundQuantity}");
+ }
+
+ // 2. 楠岃瘉閿佸畾璁板綍鐨勫凡鎷i�夋暟閲�
+ var refreshedLockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .FirstAsync(x => x.Id == lockInfo.Id);
+
+ if (Math.Abs(refreshedLockInfo.PickedQty - (lockInfo.PickedQty - pickedQty) - pickedQty) > 0.01m)
+ {
+ _logger.LogError($"閿佸畾璁板綍宸叉嫞閫夋暟閲忎笉涓�鑷�");
+ }
+
+ _logger.LogInformation($"鎷i�夋暟鎹竴鑷存�ч獙璇侀�氳繃");
}
private async Task<RevertPickingResult> RevertPickingData(Dt_PickingRecord pickingRecord)
@@ -4746,59 +5592,85 @@
#region 鏁版嵁鏇存柊鏂规硶
+ /// <summary>
+ /// 鏇存柊鎵规鍜岃鍗曟暟鎹� - 淇鐗�
+ /// 纭繚鍙洿鏂板疄闄呯殑鎷i�夋暟閲�
+ /// </summary>
private async Task UpdateBatchAndOrderData(Dt_OutboundBatch batch, Dt_OutboundOrderDetail orderDetail, decimal pickedQty, string orderNo)
{
_logger.LogInformation($"寮�濮嬫洿鏂版壒娆″拰璁㈠崟鏁版嵁 - 鎷i�夋暟閲�: {pickedQty}");
- var latestOrderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>().FirstAsync(x => x.Id == orderDetail.Id);
+
+ // 閲嶆柊鑾峰彇鏈�鏂版暟鎹紙闃叉骞跺彂闂锛�
+ var latestOrderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
+ .FirstAsync(x => x.Id == orderDetail.Id);
if (latestOrderDetail == null)
throw new InvalidOperationException("鏈壘鍒拌鍗曟槑缁�");
orderDetail = latestOrderDetail;
- // 楠岃瘉鍒嗛厤鏁伴噺涓嶄細鍙樻垚璐熸暟
- if (orderDetail.AllocatedQuantity < pickedQty)
+
+ // 楠岃瘉鎷i�夋暟閲忓悎鐞嗘��
+ if (pickedQty <= 0)
{
- decimal actualPickedQty = orderDetail.AllocatedQuantity;
- _logger.LogWarning($"鍒嗛厤鏁伴噺涓嶈冻锛岃皟鏁存嫞閫夋暟閲� - 鍘熼渶瑕�: {pickedQty}, 瀹為檯鍙敤: {actualPickedQty}");
- pickedQty = actualPickedQty;
+ _logger.LogWarning($"鎷i�夋暟閲忔棤鏁�: {pickedQty}");
+ return;
}
- if (orderDetail.LockQuantity < pickedQty)
- {
- decimal actualPickedQty = orderDetail.LockQuantity;
- _logger.LogWarning($"閿佸畾鏁伴噺涓嶈冻锛岃皟鏁存嫞閫夋暟閲� - 鍘熼渶瑕�: {pickedQty}, 瀹為檯鍙敤: {actualPickedQty}");
- pickedQty = actualPickedQty;
- }
-
- // 1. 鏇存柊鎵规瀹屾垚鏁伴噺
- decimal originalBatchCompletedQty = batch.CompletedQuantity;
- batch.CompletedQuantity += pickedQty;
-
- _logger.LogInformation($"鏇存柊鎵规瀹屾垚鏁伴噺 - 浠� {originalBatchCompletedQty} 澧炲姞鍒� {batch.CompletedQuantity}");
-
- if (batch.CompletedQuantity >= batch.BatchQuantity)
- {
- batch.BatchStatus = (int)BatchStatusEnum.宸插畬鎴�;
- _logger.LogInformation($"鎵规鐘舵�佹洿鏂颁负宸插畬鎴�");
- }
- await _outboundBatchRepository.Db.Updateable(batch).ExecuteCommandAsync();
-
- // 鏇存柊璁㈠崟鏄庣粏
+ // 璁板綍鍘熷鍊�
decimal originalOverOutQty = orderDetail.OverOutQuantity;
decimal originalAllocatedQty = orderDetail.AllocatedQuantity;
decimal originalLockQty = orderDetail.LockQuantity;
- orderDetail.OverOutQuantity += pickedQty;
- orderDetail.AllocatedQuantity -= pickedQty;
- // LockQuantity 鍚屾鍑忓皯
- orderDetail.LockQuantity = orderDetail.AllocatedQuantity;
- if (orderDetail.AllocatedQuantity < 0) orderDetail.AllocatedQuantity = 0;
- if (orderDetail.LockQuantity < 0) orderDetail.LockQuantity = 0;
- _logger.LogInformation($"鏇存柊璁㈠崟鏄庣粏 - 宸插嚭搴撴暟閲忎粠 {originalOverOutQty} 澧炲姞鍒� {orderDetail.OverOutQuantity}");
- _logger.LogInformation($"鏇存柊璁㈠崟鏄庣粏 - 宸插垎閰嶆暟閲忎粠 {originalAllocatedQty} 鍑忓皯鍒� {orderDetail.AllocatedQuantity}");
- _logger.LogInformation($"鏇存柊璁㈠崟鏄庣粏 - 閿佸畾鏁伴噺浠� {originalLockQty} 鍑忓皯鍒� {orderDetail.LockQuantity}");
+ // 鏇存柊璁㈠崟鏄庣粏
+ orderDetail.OverOutQuantity += pickedQty; // 宸插嚭搴撴暟閲忓鍔�
+ orderDetail.AllocatedQuantity -= pickedQty; // 宸插垎閰嶆暟閲忓噺灏�
+ orderDetail.LockQuantity -= pickedQty; // 閿佸畾鏁伴噺鍑忓皯
+
+ // 纭繚鏁伴噺涓嶄細涓鸿礋鏁�
+ if (orderDetail.AllocatedQuantity < 0)
+ {
+ _logger.LogWarning($"鍒嗛厤鏁伴噺鍑虹幇璐熸暟锛岄噸缃负0銆傚師鍊�: {orderDetail.AllocatedQuantity + pickedQty}");
+ orderDetail.AllocatedQuantity = 0;
+ }
+
+ if (orderDetail.LockQuantity < 0)
+ {
+ _logger.LogWarning($"閿佸畾鏁伴噺鍑虹幇璐熸暟锛岄噸缃负0銆傚師鍊�: {orderDetail.LockQuantity + pickedQty}");
+ orderDetail.LockQuantity = 0;
+ }
+
+ // 鏇存柊鎵规鍒嗛厤鐘舵��
+ await UpdateBatchAllocateStatus(orderDetail);
await _outboundOrderDetailService.Db.Updateable(orderDetail).ExecuteCommandAsync();
+
+ _logger.LogInformation($"鏇存柊璁㈠崟鏄庣粏鎴愬姛");
+ _logger.LogInformation($" 宸插嚭搴撴暟閲�: {originalOverOutQty} -> {orderDetail.OverOutQuantity}");
+ _logger.LogInformation($" 宸插垎閰嶆暟閲�: {originalAllocatedQty} -> {orderDetail.AllocatedQuantity}");
+ _logger.LogInformation($" 閿佸畾鏁伴噺: {originalLockQty} -> {orderDetail.LockQuantity}");
+
+ // 鏇存柊鎵规瀹屾垚鏁伴噺
+ if (batch != null)
+ {
+ decimal originalBatchCompletedQty = batch.CompletedQuantity;
+ batch.CompletedQuantity += pickedQty;
+
+ _logger.LogInformation($"鏇存柊鎵规瀹屾垚鏁伴噺 - 浠� {originalBatchCompletedQty} 澧炲姞鍒� {batch.CompletedQuantity}");
+
+ // 鏇存柊鎵规鐘舵��
+ if (batch.CompletedQuantity >= batch.BatchQuantity)
+ {
+ batch.BatchStatus = (int)BatchStatusEnum.宸插畬鎴�;
+ _logger.LogInformation($"鎵规鐘舵�佹洿鏂颁负宸插畬鎴�");
+ }
+ else if (batch.CompletedQuantity > 0)
+ {
+ batch.BatchStatus = (int)BatchStatusEnum.鎵ц涓�;
+ _logger.LogInformation($"鎵规鐘舵�佹洿鏂颁负鎵ц涓�");
+ }
+
+ await _outboundBatchRepository.Db.Updateable(batch).ExecuteCommandAsync();
+ }
// 妫�鏌ヨ鍗曠姸鎬�
await CheckAndUpdateOrderStatus(orderNo);
@@ -5071,7 +5943,6 @@
}
}
-
#region 杈呭姪鏂规硶
private async Task<string> GenerateNewBarcode()
@@ -5159,7 +6030,6 @@
};
}
#endregion
-
#region DTO绫�
/// <summary>
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs"
index 78f61ba..599aedd 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs"
@@ -2965,6 +2965,30 @@
return WebResponseContent.Instance.Error(ex.Message);
}
}
+
+ public WebResponseContent GetPurchaseOrderByBarcode(string barcode)
+ {
+ try
+ {
+ Dt_InboundOrderDetail inboundOrderDetail = _stockInfoDetailService.Db.Queryable<Dt_InboundOrderDetail>().Where(x=>x.Barcode == barcode&& x.OrderDetailStatus !=OrderDetailStatusEnum.Over.ObjToInt()).First();
+ if(inboundOrderDetail == null)
+ {
+ return WebResponseContent.Instance.Error($"鏈壘鍒拌鏉$爜{barcode}鐨勫叆搴撴槑缁嗘垨鑰呮槑缁嗙姸鎬佸凡鍏ユ櫤浠撳畬鎴�");
+ }
+ Dt_InboundOrder inboundOrder = _inboundOrderRepository.QueryFirst(x => x.Id == inboundOrderDetail.OrderId && x.OrderStatus != InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt());
+ if (inboundOrder == null)
+ {
+ return WebResponseContent.Instance.Error($"璇ュ叆搴撳崟{inboundOrder}鐘舵�佸凡鍏ユ櫤浠撳畬鎴�");
+ }
+ var resultData = new { purchaseOrderNo = inboundOrder.UpperOrderNo };
+
+ return WebResponseContent.Instance.OK("鏌ヨ閲囪喘鍗曟垚鍔�", data: resultData);
+ }
+ catch(Exception ex)
+ {
+ return WebResponseContent.Instance.Error(ex.Message);
+ }
+ }
#endregion
public WebResponseContent UnPalletQuantity(string orderNo)
@@ -3278,6 +3302,8 @@
public List<Dt_StockInfoDetail> PalletStockGoods { get; set; } = new List<Dt_StockInfoDetail>();
public List<Dt_SplitPackageRecord> SplitRecords { get; set; } = new List<Dt_SplitPackageRecord>();
+ // 銆愭柊澧炪�戝凡澶勭悊鐨勬潯鐮侀泦鍚堬紙鐢ㄤ簬閬垮厤閲嶅锛�
+ public HashSet<string> ProcessedBarcodes { get; set; } = new HashSet<string>();
public List<string> AllBarcodes { get; set; } = new List<string>();
// 绌烘墭鐩樼浉鍏冲睘鎬�
public bool IsEmptyPallet { get; set; }
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoDetailService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoDetailService.cs"
index 61edf7a..2e53c0f 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoDetailService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoDetailService.cs"
@@ -2,6 +2,8 @@
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
+using WIDESEA_Core.Enums;
+using WIDESEA_Core.Helper;
using WIDESEA_Core.HttpContextUser;
using WIDESEA_DTO.Stock;
using WIDESEA_IStockService;
@@ -31,16 +33,53 @@
public PageGridData<StockInfoDetailWithPalletDto> GetPageData2(PageDataOptions options)
{
- PageGridData<Dt_StockInfoDetail> lists = base.GetPageData (options);
+ // 1. 鑾峰彇鍩虹鍒嗛〉鏁版嵁
+ PageGridData<Dt_StockInfoDetail> pageData = base.GetPageData(options);
+ List<Dt_StockInfoDetail> filteredDetails = pageData.Rows.ToList(); // 鍏堟嫹璐濆師濮嬫暟鎹�
- List<int> stockIds = lists.Rows.Select(detail => detail.StockId).Distinct().ToList();
- var stocks= _stockinfoRepository.QueryData(x => stockIds.Contains(x.Id)).ToList();
-
+ if (!string.IsNullOrEmpty(options.Wheres))
+ {
+ try
+ {
+ List<SearchParameters> searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
+ if (searchParametersList?.Any() == true)
+ {
+ foreach (var param in searchParametersList)
+ {
+ // 鍖归厤鎵樼洏缂栧彿鏌ヨ鏉′欢锛堝皬鍐欏瓧娈靛悕锛�
+ if (param.Name.Equals(nameof(Dt_StockInfo.PalletCode).FirstLetterToLower(), StringComparison.OrdinalIgnoreCase)
+ && !string.IsNullOrEmpty(param.Value?.ToString()))
+ {
+ // 浼樺寲锛氭壒閲忔煡璇紙濡傛灉鏈夊涓墭鐩樼爜锛岃繖閲屼篃鍙互鎵╁睍锛�
+ string palletCode = param.Value.ToString().Trim();
+ var targetStock = _stockinfoRepository.QueryFirst(x => x.PalletCode == palletCode);
- List<StockInfoDetailWithPalletDto> dtoList = lists.Rows
+ // 绌哄�兼牎楠岋細鏈壘鍒板搴旀墭鐩樼殑搴撳瓨锛岀洿鎺ヨ繃婊や负绌�
+ if (targetStock != null)
+ {
+ filteredDetails = filteredDetails.Where(x => x.StockId == targetStock.Id).ToList();
+ }
+ else
+ {
+ filteredDetails = new List<Dt_StockInfoDetail>();
+ }
+ break; // 鍗曚釜鎵樼洏鐮佹煡璇紝鍖归厤鍚庨��鍑哄惊鐜�
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+
+ List<int> stockIds = filteredDetails.Select(detail => detail.StockId).Distinct().ToList();
+ var stockDict = _stockinfoRepository.QueryData(x => stockIds.Contains(x.Id))
+ .ToDictionary(x => x.Id, x => x.PalletCode ?? "鏃犳墭鐩樼紪鍙�");
+
+ List<StockInfoDetailWithPalletDto> dtoList = filteredDetails
.Select(detail => new StockInfoDetailWithPalletDto
{
-
Id = detail.Id,
StockId = detail.StockId,
MaterielCode = detail.MaterielCode,
@@ -64,15 +103,18 @@
CreateDate = detail.CreateDate,
Modifier = detail.Modifier,
ModifyDate = detail.ModifyDate,
- PalletCode= stocks
- .FirstOrDefault(stock => stock.Id == detail.StockId)?
- .PalletCode ?? "鏃犳墭鐩樼紪鍙�"
+ PalletCode = stockDict.TryGetValue(detail.StockId, out var palletCode) ? palletCode : "鏃犳墭鐩樼紪鍙�"
})
.ToList();
- return new PageGridData<StockInfoDetailWithPalletDto> { Rows = dtoList, Total = lists.Total, Summary = lists.Summary };
+ return new PageGridData<StockInfoDetailWithPalletDto>
+ {
+ Rows = dtoList,
+ Total = pageData.Total,
+ Summary = pageData.Summary
+ };
}
}
- }
+ }
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_StockService/StockViewService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_StockService/StockViewService.cs"
index e6aadcc..98cd527 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_StockService/StockViewService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_StockService/StockViewService.cs"
@@ -5,6 +5,7 @@
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.DB.Models;
+using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
//using WIDESEA_Core.HostedService;
using WIDESEA_Core.Utilities;
@@ -27,52 +28,98 @@
public virtual PageGridData<StockViewDTO> GetPageData(PageDataOptions options)
{
- string where = options.ValidatePageOptions(typeof(StockViewDTO).GetProperties());
- //鑾峰彇鎺掑簭瀛楁
- //Dictionary<string, OrderByType> orderbyDic = options.GetPageDataSort(typeof(StockViewDTO).GetProperties());
- //List<OrderByModel> orderByModels = new List<OrderByModel>();
- //foreach (var item in orderbyDic)
- //{
- // OrderByModel orderByModel = new OrderByModel()
- // {
- // FieldName = item.Key,
- // OrderByType = item.Value
- // };
- // orderByModels.Add(orderByModel);
- //}
- int totalCount = 0;
-
- ISugarQueryable<Dt_StockInfo> sugarQueryable1 = _dbBase.Queryable<Dt_StockInfo>().Includes(x=>x.Details);
- ISugarQueryable<Dt_LocationInfo> sugarQueryable = _dbBase.Queryable<Dt_LocationInfo>();
- ISugarQueryable<Dt_StockInfoDetail> sugarQueryable2 = _dbBase.Queryable<Dt_StockInfoDetail>();
-
-
- List<StockViewDTO> list = sugarQueryable1.InnerJoin(sugarQueryable, (b, a) => a.LocationCode == b.LocationCode).WhereIF(!string.IsNullOrEmpty(where), where).Select((b, a) => new StockViewDTO
+ try
{
- LocationCode = b.LocationCode,
- Column = a.Column,
- CreateDate = b.CreateDate,
- Creater = b.Creater,
- Depth = a.Depth,
- EnalbeStatus = a.EnableStatus,
- Layer = a.Layer,
- LocationName = a.LocationName,
- LocationStatus = a.LocationStatus,
- LocationType = a.LocationType,
- Modifier = b.Modifier,
- ModifyDate = b.ModifyDate,
- PalletCode = b.PalletCode,
- StockRemark = b.Remark,
- RoadwayNo = a.RoadwayNo,
- Row = a.Row,
- StockId = b.Id,
- StockStatus = b.StockStatus,
- Details = b.Details,
- }).ToPageList(options.Page, options.Rows, ref totalCount);
+ ISugarQueryable<Dt_StockInfo> sugarQueryable1 = _dbBase.Queryable<Dt_StockInfo>().Includes(x => x.Details);
+ if (!string.IsNullOrEmpty(options.Wheres))
+ {
+ try
+ {
+ List<SearchParameters> searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
+ if (searchParametersList?.Any() == true)
+ {
+ foreach (var param in searchParametersList)
+ {
+ switch (param.Name)
+ {
+ case var name when name == nameof(Dt_StockInfoDetail.MaterielCode).FirstLetterToLower():
+ if (!string.IsNullOrEmpty(param.Value?.ToString()))
+ {
+ sugarQueryable1 = sugarQueryable1
+ .Where(x => x.Details.Any(v => v.MaterielCode.Contains(param.Value.ToString())));
+ }
+ break;
+ case var name when name == nameof(Dt_StockInfoDetail.BatchNo).FirstLetterToLower():
+ if (!string.IsNullOrEmpty(param.Value?.ToString()))
+ {
+ sugarQueryable1 = sugarQueryable1
+ .Where(x => x.Details.Any(v => v.BatchNo.Contains(param.Value.ToString())));
+ }
+ break;
+ case var name when name == nameof(Dt_StockInfo.LocationCode).FirstLetterToLower():
+ if (!string.IsNullOrEmpty(param.Value?.ToString()))
+ {
+ sugarQueryable1 = sugarQueryable1
+ .Where(x => x.LocationCode == param.Value.ToString());
+ }
+ break;
+ case var name when name == nameof(Dt_StockInfo.CreateDate).FirstLetterToLower():
+ if (DateTime.TryParse(param.Value?.ToString(), out DateTime minDate))
+ {
+ LinqExpressionType expressionType = param.DisplayType.GetLinqCondition();
+ if (expressionType == LinqExpressionType.ThanOrEqual)
+ {
+ sugarQueryable1 = sugarQueryable1.Where(x => x.CreateDate >= minDate);
+ }
+ else if (expressionType == LinqExpressionType.LessThanOrEqual)
+ {
+ sugarQueryable1 = sugarQueryable1.Where(x => x.CreateDate <= minDate);
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ EntityProperties.ValidatePageOptions(options, ref sugarQueryable1);
+ ISugarQueryable<Dt_LocationInfo> sugarQueryable = _dbBase.Queryable<Dt_LocationInfo>();
+ ISugarQueryable<StockViewDTO> list = sugarQueryable1.InnerJoin(sugarQueryable, (b, a) => a.LocationCode == b.LocationCode).Select((b, a) => new StockViewDTO
+ {
+ LocationCode = b.LocationCode,
+ Column = a.Column,
+ WarehouseId = b.WarehouseId,
+ CreateDate = b.CreateDate,
+ Creater = b.Creater,
+ Depth = a.Depth,
+ EnalbeStatus = a.EnableStatus,
+ Layer = a.Layer,
+ LocationName = a.LocationName,
+ LocationStatus = a.LocationStatus,
+ LocationType = a.LocationType,
+ Modifier = b.Modifier,
+ ModifyDate = b.ModifyDate,
+ PalletCode = b.PalletCode,
+ StockRemark = b.Remark,
+ RoadwayNo = a.RoadwayNo,
+ Row = a.Row,
+ StockId = b.Id,
+ StockStatus = b.StockStatus,
+ Details = b.Details,
+ });
+ int totalCount = 0;
+ var stockViewDTOs = list.ToPageList(options.Page, options.Rows, ref totalCount);
+ return new PageGridData<StockViewDTO>(totalCount, stockViewDTOs);
- return new PageGridData<StockViewDTO>(totalCount, list);
-
+ }
+ catch (Exception ex)
+ {
+ }
+ return new PageGridData<StockViewDTO>();
}
public virtual object GetDetailPage(PageDataOptions pageData)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_DictionaryService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_DictionaryService.cs"
index 4e2449d..9fde9bf 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_DictionaryService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_DictionaryService.cs"
@@ -24,6 +24,7 @@
using WIDESEA_DTO.System;
using WIDESEA_ISystemService;
using WIDESEA_Model.Models;
+using WIDESEA_Model.Models.Basic;
namespace WIDESEA_SystemService
{
@@ -211,9 +212,66 @@
{
switch (key)
{
- default:
- return result;
+ case "warehouses":
+ {
+ List<object> data = new List<object>();
+
+ {
+ List<Dt_WarehouseArea> warehouses = BaseDal.Db.Queryable<Dt_WarehouseArea>().ToList();
+ int index = 0;
+ foreach (var item in warehouses)
+ {
+ data.Add(new { key = item.Code, value = item.Name });
+ index++;
+ }
+ }
+
+ result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
+ }
+ break;
+ case "locationTypes":
+ {
+ List<object> data = new List<object>();
+
+ {
+ List<Dt_LocationType> warehouses = BaseDal.Db.Queryable<Dt_LocationType>().ToList();
+ int index = 0;
+ foreach (var item in warehouses)
+ {
+ data.Add(new { key = item.LocationType, value = item.LocationTypeDesc });
+ index++;
+ }
+ }
+
+ result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
+ }
+ break;
+ case "stockStatusEmun":
+ {
+ List<object> data = new List<object>();
+ Type type = typeof(StockStatusEmun);
+ List<int> enums = Enum.GetValues(typeof(StockStatusEmun)).Cast<int>().ToList();
+ int index = 0;
+ foreach (var item in enums)
+ {
+ FieldInfo? fieldInfo = typeof(StockStatusEmun).GetField(((StockStatusEmun)item).ToString());
+ DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
+ if (description != null)
+ {
+ data.Add(new { key = item.ToString(), value = description.Description });
+ }
+ else
+ {
+ data.Add(new { key = item.ToString(), value = item.ToString() });
+ }
+ index++;
+ }
+
+ result = new VueDictionaryDTO { DicNo = key, Config = "", Data = data };
+ }
+ break;
}
+ return result;
}
catch (Exception ex)
{
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_RoleService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_RoleService.cs"
index fb668b1..8762d58 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_RoleService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_RoleService.cs"
@@ -187,12 +187,11 @@
//褰撳墠鐢ㄦ埛鐨勬潈闄�
List<Permissions> permissions = _MenuService.GetPermissions(App.User.RoleId);
- List<int> menuIds = _MenuService.Repository.QueryData(x => x.MenuId, x => x.MenuType == 1);
-
List<int> originalMeunIds = new List<int>();
//琚垎閰嶈鑹茬殑鏉冮檺
- List<Sys_RoleAuth> roleAuths = _RoleAuthService.Repository.QueryData(x => x.RoleId == roleId && menuIds.Contains(x.MenuId));
+ List<Sys_RoleAuth> roleAuths = _RoleAuthService.Repository.QueryData(x => x.RoleId == roleId);
List<Sys_RoleAuth> updateAuths = new List<Sys_RoleAuth>();
+ List<Sys_RoleAuth> addAuths = new List<Sys_RoleAuth>();
foreach (UserPermissionDTO x in userPermissions)
{
Permissions per = permissions.FirstOrDefault(p => p.MenuId == x.Id);
@@ -208,7 +207,21 @@
var auth = roleAuths.Where(r => r.MenuId == x.Id).Select(s => new { s.AuthId, s.AuthValue, s.MenuId }).FirstOrDefault();
string newAuthValue = string.Join(",", arr);
//鏉冮檺娌℃湁鍙戠敓鍙樺寲鍒欎笉澶勭悊
- if (auth == null || auth.AuthValue != newAuthValue)
+ if (auth == null)
+ {
+ addAuths.Add(new Sys_RoleAuth()
+ {
+ RoleId = roleId,
+ MenuId = x.Id,
+ AuthValue = string.Join(",", arr),
+ AuthId = auth == null ? 0 : auth.AuthId,
+ ModifyDate = DateTime.Now,
+ Modifier = App.User.UserName,
+ CreateDate = DateTime.Now,
+ Creater = App.User.UserName
+ });
+ }
+ else if (auth.AuthValue != newAuthValue)
{
updateAuths.Add(new Sys_RoleAuth()
{
@@ -231,7 +244,7 @@
//鏇存柊鏉冮檺
_RoleAuthService.Repository.UpdateData(updateAuths);
//鏂板鐨勬潈闄�
- _RoleAuthService.Repository.AddData(updateAuths);
+ _RoleAuthService.Repository.AddData(addAuths);
//鑾峰彇鏉冮檺鍙栨秷鐨勬潈闄�
int[] authIds = roleAuths.Where(x => userPermissions.Select(u => u.Id)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
index c72a941..1ef2cfc 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
@@ -627,8 +627,7 @@
// 鏇存柊鍑哄簱閿佸畾璁板綍鐘舵�佷负鍥炲簱瀹屾垚
foreach (var lockInfo in returnLocks)
{
- lockInfo.Status = (int)OutLockStockStatusEnum.宸插洖搴�;
- lockInfo.Operator = App.User.UserName;
+ lockInfo.Status = (int)OutLockStockStatusEnum.宸插洖搴�;
}
if (returnLocks.Any())
@@ -965,8 +964,7 @@
await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
.SetColumns(x => new Dt_OutboundOrder
{
- OrderStatus = newStatus,
- Operator = App.User.UserName,
+ OrderStatus = newStatus,
})
.Where(x => x.OrderNo == orderNo)
.ExecuteCommandAsync();
@@ -1120,8 +1118,7 @@
await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
.SetColumns(x => new Dt_OutboundOrder
{
- ReturnToMESStatus = 1,
- Operator = App.User.UserName,
+ ReturnToMESStatus = 1,
}).Where(x => x.OrderNo == orderNo).ExecuteCommandAsync();
}
}
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Outbound/OutboundPickingController.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Outbound/OutboundPickingController.cs"
index 051be09..d62ed14 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Outbound/OutboundPickingController.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Outbound/OutboundPickingController.cs"
@@ -145,5 +145,11 @@
{
return await Service.NoStockOutSubmit(noStockOutSubmit);
}
+
+ [HttpPost, HttpGet, Route("GetPurchaseOrderByBarcode"), AllowAnonymous]
+ public WebResponseContent GetPurchaseOrderByBarcode(string barcode)
+ {
+ return Service.GetPurchaseOrderByBarcode(barcode);
+ }
}
}
--
Gitblit v1.9.3