From 3fff7e8eb6fe78f3a512eff51bf16aee39cf9072 Mon Sep 17 00:00:00 2001
From: 647556386 <647556386@qq.com>
Date: 星期一, 08 十二月 2025 21:21:10 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/ZhongRui/ALDbanyunxiangmu

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Inbound/InboundOrderController.cs            |   30 
 项目代码/WIDESEA_WMSClient/src/extension/outbound/outboundOrder.js                                            |    2 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs                                               |   10 
 项目代码/WIDESEA_WMSClient/src/router/viewGird.js                                                             |    5 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/CopilotIndices/17.14.878.3237/SemanticSymbols.db-shm |    0 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Stock/StockInfoDetailController.cs           |    5 
 项目代码/WIDESEA_WMSClient/src/extension/stock/stockInfoDetailByMaterielSum.js                                |   59 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_IStockService/IStockInfoDetailService.cs                           |    1 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundBatchPickingService.cs                     | 3443 ++++++++++++++++++++++++++++++-----
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_InboundService/InboundOrderService.cs                              |   60 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_BasicService/ErpApiService.cs                                      |    3 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs                                     |    9 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_Model/Models/Stock/StockDetailByMateriel.cs                        |   81 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_StockService/StockDetailByMaterielService.cs                       |  164 +
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_DTO/Stock/StockDetailDtO.cs                                        |   76 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs                          |   37 
 项目代码/WIDESEA_WMSClient/src/views/stock/stockInfoDetailByMaterielSum.vue                                   |  194 ++
 项目代码/WMS无仓储版/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/CopilotIndices/17.14.878.3237/CodeChunks.db-shm      |    0 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_AllocateService/AllocateDetailService.cs                           |   73 
 项目代码/WIDESEA_WMSClient/src/extension/check/recheckOrder.js                                                |   95 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_IStockService/IStockDetailByMaterielService.cs                     |   18 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Stock/StockDetailByMaterielController.cs     |   26 
 项目代码/WIDESEA_WMSClient/src/extension/outbound/allocateoutboundOrder.js                                    |    2 
 项目代码/WIDESEA_WMSClient/src/views/outbound/BatchPickingConfirm.vue                                         |    4 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderService.cs                            |    2 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Allocate/AllocateOrderDetailController.cs    |    6 
 项目代码/WIDESEA_WMSClient/config/buttons.js                                                                  |   18 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_IAllocateService/IAllocateDetailService.cs                         |    1 
 项目代码/WIDESEA_WMSClient/src/extension/outbound/extend/newAllocateOrderDetail.vue                           |  797 ++++++++
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_BasicService/InvokeMESService.cs                                   |  438 +++-
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoDetailService.cs                             |    1 
 31 files changed, 4,865 insertions(+), 795 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/config/buttons.js" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/config/buttons.js"
index 32004c1..1bcc4fb 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/config/buttons.js"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/config/buttons.js"
@@ -208,6 +208,24 @@
     onClick: function () {
     }
 },
+{
+    name: "鍒嗘嫞",
+    // icon: 'el-icon-upload2',
+    class: '',
+    value: 'BatchOrder',
+    type: 'primary',
+    onClick: function () {
+    }
+},
+{
+    name: "缁勭洏",
+    // icon: 'el-icon-upload2',
+    class: '',
+    value: 'GroupPallet',
+    type: 'primary',
+    onClick: function () {
+    }
+},
 ]
 
 export default buttons
\ No newline at end of file
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/check/recheckOrder.js" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/check/recheckOrder.js"
index c79a67f..1ac007c 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/check/recheckOrder.js"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/check/recheckOrder.js"
@@ -1,15 +1,8 @@
-/*****************************************************************************************
-**  Author:jxx 2022
-**  QQ:283591387
-**瀹屾暣鏂囨。瑙侊細http://v2.volcore.xyz/document/api 銆愪唬鐮佺敓鎴愰〉闈iewGrid銆�
-**甯哥敤绀轰緥瑙侊細http://v2.volcore.xyz/document/vueDev
-**鍚庡彴鎿嶄綔瑙侊細http://v2.volcore.xyz/document/netCoreDev
-*****************************************************************************************/
 //姝s鏂囦欢鏄敤鏉ヨ嚜瀹氫箟鎵╁睍涓氬姟浠g爜锛屽彲浠ユ墿灞曚竴浜涜嚜瀹氫箟椤甸潰鎴栬�呴噸鏂伴厤缃敓鎴愮殑浠g爜
 import gridBody from './extend/StockSelect.vue'
 import http from '@/api/http.js'
-import { h,createVNode, render,reactive,ref  } from 'vue';
-import { ElDialog , ElForm, ElFormItem, ElInput, ElButton, ElMessage ,ElSelect ,ElOption } from 'element-plus'; // 寮曞叆ElMessage锛岃В鍐虫彁绀烘棤鍙嶅簲
+import { h, createVNode, render, reactive, ref } from 'vue';
+import { ElDialog, ElForm, ElFormItem, ElInput, ElButton, ElMessage, ElSelect, ElOption } from 'element-plus'; // 寮曞叆ElMessage锛岃В鍐虫彁绀烘棤鍙嶅簲
 let extension = {
   components: {
     //鏌ヨ鐣岄潰鎵╁睍缁勪欢
@@ -22,36 +15,40 @@
     modelFooter: ''
   },
   tableAction: '', //鎸囧畾鏌愬紶琛ㄧ殑鏉冮檺(杩欓噷濉啓琛ㄥ悕,榛樿涓嶇敤濉啓)
-  buttons: { view: [ {
-          name: '缁勭洏',
-          type: 'primary',
-          value: '缁勭洏',
-          onClick: function () { // 淇1锛氱Щ闄ゆ棤鐢╮ow鍙傛暟锛屽姞鏃ュ織璋冭瘯
-            console.log('缁勭洏鎸夐挳琚偣鍑伙紝寮�濮嬫牎楠�');
-            const selectedRows = this.$refs.table.getSelected();
-  
-            // 鏍¢獙1锛氭槸鍚﹂�変腑琛�
-            if (selectedRows.length === 0) {
-              console.log('鏍¢獙涓嶉�氳繃锛氭湭閫変腑浠讳綍鍗曟嵁');
-              ElMessage.warning('璇烽�夋嫨涓�鏉″崟鎹�');
-              return;
-            }
-            // 鏍¢獙2锛氭槸鍚﹂�変腑鍗曡
-            if (selectedRows.length > 1) {
-              console.log('鏍¢獙涓嶉�氳繃锛氶�変腑澶氳鍗曟嵁');
-              ElMessage.warning('鍙兘閫夋嫨涓�鏉″崟鎹�');
-              return;
-            }
-  
-            const targetRow = selectedRows[0];
-       
-            this.$emit('openPalletDialog', targetRow.orderNo);
-          }
-        },], box: [], detail: [] }, //鎵╁睍鐨勬寜閽�
+  buttons: {
+     view: [
+      //{
+    //   name: '缁勭洏',
+    //   type: 'primary',
+    //   value: '缁勭洏',
+    //   onClick: function () { // 淇1锛氱Щ闄ゆ棤鐢╮ow鍙傛暟锛屽姞鏃ュ織璋冭瘯
+    //     console.log('缁勭洏鎸夐挳琚偣鍑伙紝寮�濮嬫牎楠�');
+    //     const selectedRows = this.$refs.table.getSelected();
+
+    //     // 鏍¢獙1锛氭槸鍚﹂�変腑琛�
+    //     if (selectedRows.length === 0) {
+    //       console.log('鏍¢獙涓嶉�氳繃锛氭湭閫変腑浠讳綍鍗曟嵁');
+    //       ElMessage.warning('璇烽�夋嫨涓�鏉″崟鎹�');
+    //       return;
+    //     }
+    //     // 鏍¢獙2锛氭槸鍚﹂�変腑鍗曡
+    //     if (selectedRows.length > 1) {
+    //       console.log('鏍¢獙涓嶉�氳繃锛氶�変腑澶氳鍗曟嵁');
+    //       ElMessage.warning('鍙兘閫夋嫨涓�鏉″崟鎹�');
+    //       return;
+    //     }
+
+    //     const targetRow = selectedRows[0];
+
+    //     this.$emit('openPalletDialog', targetRow.orderNo);
+    //   }
+    // },
+    ], box: [], detail: []
+  }, //鎵╁睍鐨勬寜閽�
   methods: {
-     //涓嬮潰杩欎簺鏂规硶鍙互淇濈暀涔熷彲浠ュ垹闄�
+    //涓嬮潰杩欎簺鏂规硶鍙互淇濈暀涔熷彲浠ュ垹闄�
     onInit() {  //妗嗘灦鍒濆鍖栭厤缃墠锛�
-        this.columns.push({
+      this.columns.push({
         field: '鎿嶄綔',
         title: '鎿嶄綔',
         width: 90,
@@ -71,6 +68,30 @@
           this.$refs.gridBody.open(row);
         }
       });
+      let EmptyTrayOutboundBtn = this.buttons.find(x => x.value == 'BatchOrder');
+      if (EmptyTrayOutboundBtn) {
+        EmptyTrayOutboundBtn.onClick = function () {
+          let rows = this.$refs.table.getSelected();
+          if (rows.length == 0) return this.$error("璇烽�夋嫨鏁版嵁!");
+          if (rows.length > 1) return this.$error("璇烽�夋嫨涓�鏉℃暟鎹�!");
+          this.$router.push({
+            path: '/outbound/picking',
+            query: { orderId: rows[0].id,orderNo:rows[0].orderNo}
+          })
+
+        }
+      }
+
+      let GroupPalletBtn = this.buttons.find(x=>x.value =='GroupPallet')
+      if(GroupPalletBtn){
+        GroupPalletBtn.onClick = function(){
+          let rows  = this.$refs.table.getSelected();
+          if(rows.length ==0 || rows.length>1) return ElMessage.warning('璇烽�夋嫨涓�鏉″崟鎹�');
+          const targetRow = rows[0];
+
+          this.$emit('openPalletDialog', targetRow.orderNo);
+        }
+      }
     },
     onInited() {
       //妗嗘灦鍒濆鍖栭厤缃悗
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/outbound/allocateoutboundOrder.js" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/outbound/allocateoutboundOrder.js"
index 487648b..76d2980 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/outbound/allocateoutboundOrder.js"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/outbound/allocateoutboundOrder.js"
@@ -4,7 +4,7 @@
 import { h,createVNode, render,reactive ,ref } from 'vue';
 import { ElDialog , ElForm, ElFormItem, ElInput, ElButton, ElMessage ,ElSelect, ElOption} from 'element-plus';
 
-import gridBody from './extend/outOrderDetail.vue'
+import gridBody from './extend/newAllocateOrderDetail.vue'
 let extension = {
     components: {
       //鏌ヨ鐣岄潰鎵╁睍缁勪欢
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/outbound/extend/newAllocateOrderDetail.vue" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/outbound/extend/newAllocateOrderDetail.vue"
new file mode 100644
index 0000000..2de8386
--- /dev/null
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/outbound/extend/newAllocateOrderDetail.vue"
@@ -0,0 +1,797 @@
+<template>
+  <div>
+    <vol-box
+      v-model="showDetialBox"
+      :lazy="true"
+      width="75%"
+      :padding="15"
+      title="鍗曟嵁鏄庣粏淇℃伅"
+    >
+      <div class="box-head">
+        <el-alert :closable="false" style="width: 100%">
+          <el-row>
+            <el-col :span="16">
+              <span>宸查�変腑 {{ selection.length }} 椤�</span>
+            </el-col>
+            <el-col :span="8">
+          <!--     <el-link
+                type="primary"
+                size="small"
+                style="float: right; height: 20px"
+                @click="lockstocks"
+                >閿佸畾搴撳瓨</el-link> -->
+
+              <el-link
+                type="primary"
+                size="small"
+                    v-if="isBatch === 0"
+                style="float: right; height: 20px"
+                @click="handleOpenPicking"
+                >鎷i��</el-link>
+                        <el-link
+                type="primary"
+                size="small"
+                style="float: right; height: 20px; margin-right: 10px"
+                  v-if="isBatch === 1"
+                @click="handleOpenBatchPicking"
+                >鍒嗘壒鎷i��</el-link>
+              <el-link
+                type="primary"
+                size="small"
+                   v-if="isBatch === 0"
+                style="float: right; height: 20px; margin-right: 10px"
+                @click="outbound"
+                >鐩存帴鍑哄簱</el-link
+              >
+               <el-link
+                type="primary"
+                size="small"
+                 v-if="isBatch === 1"
+                style="float: right; height: 20px; margin-right: 10px"
+                @click="outboundbatch"
+                >鍒嗘壒鍑哄簱</el-link
+              >
+              <el-link
+                type="primary"
+                size="small"
+                style="float: right; height: 20px; margin-right: 10px"
+                @click="getData"
+                >鍒锋柊</el-link
+              ></el-col
+            >
+          </el-row>
+        </el-alert>
+      </div>
+      <div class="box-table" style="margin-top: 1%">
+        <el-table
+          ref="singleTable"
+          :data="tableData"
+          style="width: 100%; height: 100%"
+          highlight-current-row
+          @current-change="handleCurrentChange"
+          height="500px"
+          @row-click="handleRowClick"
+          @selection-change="handleSelectionChange"
+        >
+          <el-table-column type="selection" width="55"> </el-table-column>
+          <el-table-column
+            label="搴忓彿"
+            type="index"
+            fixed="left"
+            width="55"
+            align="center"
+          ></el-table-column>
+          <el-table-column
+            v-for="(item, index) in tableColumns.filter((x) => !x.hidden)"
+            :key="index"
+            :prop="item.prop"
+            :label="item.title"
+            :width="item.width"
+            align="center"
+          >
+            <template #default="scoped">
+              <div v-if="item.type == 'icon'">
+                <el-tooltip
+                  class="item"
+                  effect="dark"
+                  :content="item.title"
+                  placement="bottom"
+                  ><el-link
+                    type="primary"
+                    :disabled="getButtonEnable(item.prop, scoped.row)"
+                    @click="tableButtonClick(scoped.row, item)"
+                    ><i :class="item.icon" style="font-size: 22px"></i></el-link
+                ></el-tooltip>
+              </div>
+
+              <div v-else-if="item.type == 'tag'">
+                <el-tag size="small">
+                  {{ getDictionary(scoped.row, item) }}
+                </el-tag>
+              </div>
+            </template>
+          </el-table-column>
+        </el-table>
+      </div>
+    </vol-box>
+    <stock-select ref="child" @parentCall="parentCall"></stock-select>
+    <selected-stock
+      ref="selectedStock"
+      @parentCall="parentCall"
+    ></selected-stock>
+    <NoStockOut ref="NoStockOut" @parentCall="parentCall"></NoStockOut>
+  </div>
+</template>
+<script>
+import VolBox from "@/components/basic/VolBox.vue";
+import VolForm from "@/components/basic/VolForm.vue";
+import StockSelect from "./StockSelect.vue";
+import SelectedStock from "./SelectedStock.vue";
+import NoStockOut from "./NoStockOut.vue";
+import { h,createVNode, render,reactive  } from 'vue';
+import { ElDialog , ElForm, ElFormItem, ElSelect,ElOption, ElButton, ElInput, ElMessage } from 'element-plus';
+import { th } from 'element-plus/es/locale';
+
+export default {
+  components: { VolBox, VolForm, StockSelect, SelectedStock,NoStockOut},
+  data() {
+    return {
+      row: null,
+      isBatch :0,
+      showDetialBox: false,
+      flag: false,
+      currentRow: null,
+      selection: [],
+      tableData: [],
+      tableColumns: [
+        {
+          prop: "id",
+          title: "Id",
+          type: "int",
+          width: 90,
+          hidden: true,
+        },
+        {
+          prop: "orderId",
+          title: "鍑哄簱鍗曚富閿�",
+          type: "string",
+          width: 90,
+          hidden: true,
+        },
+        {
+          prop: "materielCode",
+          title: "鐗╂枡缂栧彿",
+          type: "string",
+          width: 150,
+        },
+        {
+          prop: "materielName",
+          title: "鐗╂枡鍚嶇О",
+          type: "string",
+          width: 150,
+        },
+        {
+          prop: "batchNo",
+          title: "鎵规鍙�",
+          type: "string",
+          width: 90,
+        },
+        {
+          prop: "supplyCode",
+          title: "渚涘簲鍟嗙紪鍙�",
+          type: "string",
+          width: 150,
+        },
+        {
+          prop: "orderQuantity",
+          title: "鍗曟嵁鏁伴噺",
+          type: "string",
+          width: 90,
+        },
+        {
+          prop: "lockQuantity",
+          title: "閿佸畾鏁伴噺",
+          type: "int",
+          width: 90,
+        },
+        {
+          prop: "overOutQuantity",
+          title: "宸插嚭鏁伴噺",
+          type: "string",
+          width: 90,
+        },
+        {
+          prop: "overOutQuantity",
+          title: "鎸枡鏁伴噺",
+          type: "string",
+          width: 90,
+        },
+        {
+          prop: "unit",
+          title: "鍗曚綅",
+          type: "string",
+          width: 90,
+        },
+        {
+          prop: "orderDetailStatus",
+          title: "璁㈠崟鏄庣粏鐘舵��",
+          type: "tag",
+          width: 90,
+          bindKey: "orderDetailStatusEnum",
+        },
+        {
+          prop: "assignStock",
+          title: "鎸囧畾搴撳瓨",
+          type: "icon",
+          width: 90,
+          hidden:true,
+          icon: "el-icon-s-grid",
+        },
+        {
+          prop: "viewDetail",
+          title: "鍑哄簱璇︾粏",
+          type: "icon",
+          width: 90,
+          icon: "el-icon-s-operation",
+        },
+        {
+          prop: "creater",
+          title: "鍒涘缓浜�",
+          type: "string",
+          width: 90,
+        },
+        {
+          prop: "createDate",
+          title: "鍒涘缓鏃堕棿",
+          type: "datetime",
+          width: 160,
+        },
+        {
+          prop: "modifier",
+          title: "淇敼浜�",
+          type: "string",
+          width: 100,
+        },
+        {
+          prop: "modifyDate",
+          title: "淇敼鏃堕棿",
+          type: "datetime",
+          width: 160,
+        },
+        {
+          prop: "remark",
+          title: "澶囨敞",
+          type: "string",
+        },
+      ],
+      paginations: {
+        sort: "id",
+        order: "desc",
+        Foots: "",
+        total: 0,
+        // 2020.08.29澧炲姞鑷畾涔夊垎椤垫潯澶у皬
+        sizes: [30, 60, 100, 120],
+        size: 30, // 榛樿鍒嗛〉澶у皬
+        Wheres: [],
+        page: 1,
+        rows: 30,
+      },
+      searchFormOptions: [
+        [
+          {
+            title: "鍗曟嵁缂栧彿",
+            field: "allocation_code",
+            type: "like",
+          },
+          {
+            title: "鍗曟嵁绫诲瀷",
+            field: "allocation_type",
+            type: "select",
+            dataKey: "OrderType",
+            data: [],
+          },
+          {
+            title: "鍗曟嵁鐘舵��",
+            field: "allocation_state",
+            type: "select",
+            dataKey: "OrderState",
+            data: [],
+          },
+        ],
+      ],
+      searchFormFields: {
+        allocation_code: "",
+        allocation_type: "",
+        allocation_state: "",
+      },
+      dictionaryList: null,
+    };
+  },
+  methods: {
+    open(row) {
+      this.row = row;
+      this.showDetialBox = true;
+      console.log(this.row);  
+      this.isBatch = row.isBatch;
+      this.getDictionaryData();
+      this.getData();
+    },
+    getData() {
+      var wheres = [{ name: "orderId", value: this.row.id }];
+      var param = {
+        page: this.paginations.page,
+        rows: this.paginations.rows,
+        sort: this.paginations.sort,
+        order: this.paginations.order,
+        wheres: JSON.stringify(wheres), // 鏌ヨ鏉′欢锛屾牸寮忎负[{ name: "瀛楁", value: "xx" }]
+      };
+      this.http
+        .post("api/AllocateOrderDetail/GetDetailPage", param, "鏌ヨ涓�")
+        .then((x) => {
+          this.tableData = x.rows;
+        });
+    },
+    tableButtonClick(row, column) {
+      if (column.prop == "assignStock") {
+        this.$refs.child.open(row);
+      } else if (column.prop == "NoStockOut") {
+        this.$refs.NoStockOut.open(row);
+      }else{
+          //鐐瑰嚮鎵撳紑鍑哄簱璇︽儏
+        this.$refs.selectedStock.open(row);
+      }
+    },
+    lockstocks() {
+      if (this.selection.length === 0) {
+        return this.$message.error("璇烽�夋嫨鍗曟嵁鏄庣粏");
+      }
+      var keys = this.selection.map((item) => item.id); // 鑾峰彇閫変腑琛岀殑id
+      this.http
+        .post("api/OutboundOrderDetail/LockOutboundStocks", keys, "鏁版嵁澶勭悊涓�")
+        .then((x) => {
+          if (!x.status) return this.$message.error(x.message);
+          this.$message.success("鎿嶄綔鎴愬姛");
+          this.showDetialBox = false;
+          this.$emit("parentCall", ($vue) => {
+            $vue.getData();
+          });
+        });
+    },
+    // 鎵撳紑鎷i�夐〉闈�
+   handleOpenPicking() {
+      this.$router.push({
+        path: '/outbound/picking',
+        query: { orderId: this.row.id ,orderNo:this.row.orderNo}
+      })
+    },
+    handleOpenBatchPicking() {
+      this.$router.push({ 
+        path: '/outbound/batchpicking',
+        query: { orderId: this.row.id ,orderNo:this.row.orderNo}})
+    },
+    outbound() {
+      if (this.selection.length === 0) {
+        return this.$message.error("璇烽�夋嫨鍗曟嵁鏄庣粏");
+      }
+      const platformOptions = [{label:'绔欏彴2',value:'2-1'},{label:'绔欏彴3',value:'3-1'}];
+      const mountNode = document.createElement('div');
+      document.body.appendChild(mountNode);
+
+      // 2. 琛ㄥ崟鏁版嵁锛堥粯璁ら�変腑绔欏彴3锛�
+      const formData = reactive({
+        selectedPlatform: platformOptions[0].value // 榛樿缁戝畾銆岀珯鍙�3銆嶇殑value
+      });
+
+      // 3. 鍔ㄦ�佸垱寤哄脊绐楃粍浠�
+      const vnode = createVNode(ElDialog, {
+        title: '鍑哄簱鎿嶄綔 - 閫夋嫨鍑哄簱绔欏彴',
+        width: '500px',
+        modelValue: true,
+        appendToBody: true,
+        'onUpdate:modelValue': (isVisible) => {
+          if (!isVisible) {
+            render(null, mountNode);
+            document.body.removeChild(mountNode);
+          }
+        }, 
+        style: {
+          padding: '20px 0',
+          borderRadius: '8px'
+        }
+      }, {
+        default: () => h(ElForm, {
+          model: formData,
+          rules: {
+            selectedPlatform: [
+              { required: true, message: '璇烽�夋嫨鍑哄簱绔欏彴', trigger: 'change' }
+            ]
+          },
+          ref: 'outboundForm',
+          labelWidth: '100px',
+          style: {
+            padding: '0 30px'
+          }
+        }, [
+          // 鍑哄簱绔欏彴閫夋嫨椤癸紙鏍稿績琛ㄥ崟椤癸級
+          h(ElFormItem, {
+            label: '鍑哄簱绔欏彴',
+            prop: 'selectedPlatform',
+            style: {
+              marginBottom: '24px'
+            }
+          }, [
+            h(ElSelect, {
+              placeholder: '璇烽�夋嫨鍑哄簱绔欏彴锛�3-12锛�',
+              modelValue: formData.selectedPlatform,
+              'onUpdate:modelValue': (val) => {
+                formData.selectedPlatform = val;
+              },
+              style: {
+                width: '100%',
+                height: '40px',
+                borderRadius: '4px',
+                borderColor: '#dcdfe6'
+              }
+            }, platformOptions.map(platform => 
+              h(ElOption, { label: platform.label, value: platform.value })
+            ))
+          ]),
+          // 搴曢儴鎸夐挳鍖�
+          h('div', {
+            style: {
+              textAlign: 'right',
+              marginTop: '8px',
+              paddingRight: '4px'
+            }
+          }, [
+            h(ElButton, {
+              type: 'text',
+              onClick: () => {
+                render(null, mountNode);
+                document.body.removeChild(mountNode);
+                ElMessage.info('鍙栨秷鍑哄簱鎿嶄綔');
+              },
+              style: {
+                marginRight: '8px',
+                color: '#606266'
+              }
+            }, '鍙栨秷'),
+            h(ElButton, {
+              type: 'primary',
+              onClick: async () => {
+                const formRef = vnode.component.refs.outboundForm;
+                try {
+                  // 琛ㄥ崟鏍¢獙
+                  await formRef.validate();
+                } catch (err) {
+                  return;
+                }
+
+                // 4. 鏋勯�犺姹傚弬鏁帮紙閫変腑鍗曟嵁ID + 閫夋嫨鐨勫嚭搴撶珯鍙帮級
+                const keys = this.selection.map((item) => item.id);
+                const requestParams = {
+                  taskIds: keys,
+                  outboundPlatform: formData.selectedPlatform // 鍑哄簱绔欏彴
+                };
+
+                // 5. 璋冪敤鍑哄簱鎺ュ彛
+                this.http
+                  .post("api/Task/GenerateOutboundTasks", requestParams, "鏁版嵁澶勭悊涓�")
+                  .then((x) => {
+                    if (!x.status) return ElMessage.error(x.message);
+                    
+                    ElMessage.success("鎿嶄綔鎴愬姛");
+                    this.showDetialBox = false; // 鍏抽棴璇︽儏妗�
+                    this.$emit("parentCall", ($vue) => {
+                      $vue.getData(); // 閫氱煡鐖剁粍浠跺埛鏂�
+                    });
+                    // 鍏抽棴寮圭獥
+                    render(null, mountNode);
+                    document.body.removeChild(mountNode);
+                  })
+                  .catch(() => {
+                    ElMessage.error('璇锋眰澶辫触锛岃绋嶅悗閲嶈瘯');
+                  });
+              },
+              style: {
+                borderRadius: '4px',
+                padding: '8px 20px'
+              }
+            }, '纭畾鍑哄簱')
+          ])
+        ])
+      });
+
+      // 缁戝畾app涓婁笅鏂囷紝纭繚El缁勪欢姝e父宸ヤ綔
+      vnode.appContext = this.$.appContext;
+      render(vnode, mountNode);
+    },
+    outboundbatch() {
+  if (this.selection.length === 0) {
+    return this.$message.error("璇烽�夋嫨鍗曟嵁鏄庣粏");
+  }
+    if (this.selection.length>1) {
+    return this.$message.error("鍙兘閫夋嫨涓�鏉″崟鎹槑缁嗚繘琛屽垎鎵瑰嚭搴�");
+  }
+  const platformOptions = [{label:'绔欏彴2',value:'2-1'},{label:'绔欏彴3',value:'3-1'}];
+  const mountNode = document.createElement('div');
+  document.body.appendChild(mountNode);
+
+  // 2. 琛ㄥ崟鏁版嵁锛堥粯璁ら�変腑绔欏彴3锛屾柊澧炲皬鏁板瓧娈碉級
+  const formData = reactive({
+    selectedPlatform: platformOptions[0].value, // 榛樿缁戝畾銆岀珯鍙�3銆嶇殑value
+    outboundDecimal: '' // 鏂板锛氬皬鏁拌緭鍏ユ瀛楁
+  });
+
+  // 3. 鍔ㄦ�佸垱寤哄脊绐楃粍浠�
+  const vnode = createVNode(ElDialog, {
+    title: '鍑哄簱鎿嶄綔 - 閫夋嫨鍑哄簱绔欏彴',
+    width: '500px',
+    modelValue: true,
+    appendToBody: true,
+    'onUpdate:modelValue': (isVisible) => {
+      if (!isVisible) {
+        render(null, mountNode);
+        document.body.removeChild(mountNode);
+      }
+    }, 
+    style: {
+      padding: '20px 0',
+      borderRadius: '8px'
+    }
+  }, {
+    default: () => h(ElForm, {
+      model: formData,
+      rules: {
+        selectedPlatform: [
+          { required: true, message: '璇烽�夋嫨鍑哄簱绔欏彴', trigger: 'change' }
+        ],
+        // 鏂板锛氬皬鏁板瓧娈甸獙璇佽鍒欙紙蹇呭~ + 鏈夋晥灏忔暟鏍煎紡锛�
+        outboundDecimal: [
+          { required: true, message: '璇疯緭鍏ュ皬鏁版暟鍊�', trigger: 'blur' },
+          { 
+            validator: (rule, value, callback) => {
+              // 楠岃瘉瑙勫垯锛氭鏁般�佹敮鎸佸皬鏁扮偣鍚庢渶澶�2浣嶏紙鍙牴鎹渶姹傝皟鏁村皬鏁颁綅鏁帮級
+              const decimalReg = /^(([1-9]\d*)|0)(\.\d{1,2})?$/;
+              if (value && !decimalReg.test(value)) {
+                callback(new Error('璇疯緭鍏ユ湁鏁堢殑灏忔暟锛堟鏁帮紝鏈�澶�2浣嶅皬鏁帮級'));
+              } else {
+                callback();
+              }
+            },
+            trigger: 'blur'
+          }
+        ]
+      },
+      ref: 'outboundForm',
+      labelWidth: '100px',
+      style: {
+        padding: '0 30px'
+      }
+    }, [
+      // 鍑哄簱绔欏彴閫夋嫨椤癸紙鏍稿績琛ㄥ崟椤癸級
+      h(ElFormItem, {
+        label: '鍑哄簱绔欏彴',
+        prop: 'selectedPlatform',
+        style: {
+          marginBottom: '24px'
+        }
+      }, [
+        h(ElSelect, {
+          placeholder: '璇烽�夋嫨鍑哄簱绔欏彴锛�3-12锛�',
+          modelValue: formData.selectedPlatform,
+          'onUpdate:modelValue': (val) => {
+            formData.selectedPlatform = val;
+          },
+          style: {
+            width: '100%',
+            height: '40px',
+            borderRadius: '4px',
+            borderColor: '#dcdfe6'
+          }
+        }, platformOptions.map(platform => 
+          h(ElOption, { label: platform.label, value: platform.value })
+        ))
+      ]),
+      // 鏂板锛氬皬鏁拌緭鍏ユ琛ㄥ崟椤�
+      h(ElFormItem, {
+        label: '鍑哄簱鏁�', // 鍙牴鎹笟鍔¢渶姹備慨鏀规爣绛惧悕锛堝鈥滃嚭搴撴暟閲忊�濃�滈噸閲忊�濈瓑锛�
+        prop: 'outboundDecimal',
+        style: {
+          marginBottom: '24px'
+        }
+      }, [
+        h(ElInput, {
+          type: 'number', // 鏁板瓧绫诲瀷锛屽師鐢熸敮鎸佸皬鏁拌緭鍏�
+          placeholder: '璇疯緭鍏ュ皬鏁版暟鍊硷紙鏈�澶�2浣嶅皬鏁帮級',
+          modelValue: formData.outboundDecimal,
+          'onUpdate:modelValue': (val) => {
+            formData.outboundDecimal = val;
+          },
+          style: {
+            width: '100%',
+            height: '40px',
+            borderRadius: '4px',
+            borderColor: '#dcdfe6'
+          },
+          step: '0.01', // 姝ラ暱0.01锛岀偣鍑讳笂涓嬬澶存椂鎸�0.01澧炲噺
+          precision: 2, // 闄愬埗鏈�澶氳緭鍏�2浣嶅皬鏁帮紙Element Plus灞炴�э級
+          min: 0.01, // 鍙�夛細闄愬埗鏈�灏忓�间负0.01锛岄伩鍏嶈緭鍏�0鎴栬礋鏁�
+        })
+      ]),
+      // 搴曢儴鎸夐挳鍖�
+      h('div', {
+        style: {
+          textAlign: 'right',
+          marginTop: '8px',
+          paddingRight: '4px'
+        }
+      }, [
+        h(ElButton, {
+          type: 'text',
+          onClick: () => {
+            render(null, mountNode);
+            document.body.removeChild(mountNode);
+            ElMessage.info('鍙栨秷鍒嗘壒鍑哄簱鎿嶄綔');
+          },
+          style: {
+            marginRight: '8px',
+            color: '#606266'
+          }
+        }, '鍙栨秷'),
+        h(ElButton, {
+          type: 'primary',
+          onClick: async () => {
+            const formRef = vnode.component.refs.outboundForm;
+            try {
+              // 琛ㄥ崟鏍¢獙锛堜細鍚屾椂鏍¢獙鍑哄簱绔欏彴鍜屽皬鏁板瓧娈碉級
+              await formRef.validate();
+            } catch (err) {
+              return;
+            }
+console.log(this.selection);
+            // 4. 鏋勯�犺姹傚弬鏁帮紙鏂板灏忔暟瀛楁锛�
+            const keys = this.selection.map((item) => item.id);
+            const requestParams = {
+              orderDetailId: keys[0], // 鍒嗘壒鍑哄簱浠呮敮鎸佸崟鏉℃槑缁�
+              outboundPlatform: formData.selectedPlatform, // 鍑哄簱绔欏彴
+              batchQuantity: formData.outboundDecimal // 鏂板锛氬皬鏁板瓧娈典紶缁欏悗绔�
+            };
+
+            // 5. 璋冪敤鍑哄簱鎺ュ彛
+            this.http
+              .post("api/Task/GenerateOutboundBatchTasks", requestParams, "鏁版嵁澶勭悊涓�")
+              .then((x) => {
+                if (!x.status) return ElMessage.error(x.message);
+                
+                ElMessage.success("鎿嶄綔鎴愬姛");
+                this.showDetialBox = false; // 鍏抽棴璇︽儏妗�
+                this.$emit("parentCall", ($vue) => {
+                  $vue.getData(); // 閫氱煡鐖剁粍浠跺埛鏂�
+                });
+                // 鍏抽棴寮圭獥
+                render(null, mountNode);
+                document.body.removeChild(mountNode);
+              })
+              .catch(() => {
+                ElMessage.error('璇锋眰澶辫触锛岃绋嶅悗閲嶈瘯');
+              });
+          },
+          style: {
+            borderRadius: '4px',
+            padding: '8px 20px'
+          }
+        }, '纭畾鍒嗘壒鍑哄簱')
+      ])
+    ])
+  });
+
+  // 缁戝畾app涓婁笅鏂囷紝纭繚El缁勪欢姝e父宸ヤ綔
+  vnode.appContext = this.$.appContext;
+  render(vnode, mountNode);
+},
+      
+
+    setCurrent(row) {
+      this.$refs.singleTable.setCurrentRow(row);
+    },
+    handleCurrentChange(val) {
+      this.currentRow = val;
+    },
+    getButtonEnable(propName, row) {
+      if (propName == "assignStock") {
+        if (
+          row.orderDetailStatus !== 0 &&
+          row.orderDetailStatus !== 60 &&
+          row.orderDetailStatus !== 70 &&
+          row.orderDetailStatus !== 80
+        ) {
+          return true;
+        } else {
+          return false;
+        }
+      }
+      return false;
+    },
+    parentCall(fun) {
+      if (typeof fun != "function") {
+        return console.log("鎵╁睍缁勪欢闇�瑕佷紶鍏ヤ竴涓洖璋冩柟娉曟墠鑳借幏鍙栫埗绾ue瀵硅薄");
+      }
+      fun(this);
+    },
+    handleRowClick(row) {
+      this.$refs.singleTable.toggleRowSelection(row);
+    },
+    handleSelectionChange(val) {
+      this.selection = val;
+    },
+    getDictionaryData() {
+      if (this.dictionaryList) {
+        return;
+      }
+      var param = [];
+      this.tableColumns.forEach((x) => {
+        if (x.type == "tag" && x.bindKey != "") {
+          param.push(x.bindKey);
+        }
+      });
+      this.http
+        .post("api/Sys_Dictionary/GetVueDictionary", param, "鏌ヨ涓�")
+        .then((x) => {
+          if (x.length > 0) {
+            this.dictionaryList = x;
+          }
+        });
+    },
+    getDictionary(row, column) {
+      if (this.dictionaryList) {
+        var item = this.dictionaryList.find((x) => x.dicNo == column.bindKey);
+        if (item) {
+          var dicItem = item.data.find((x) => x.key == row[column.prop]);
+          console.log(dicItem);
+          if (dicItem) {
+            return dicItem.value;
+          } else {
+            return row[column.prop];
+          }
+        } else {
+          return row[column.prop];
+        }
+      }
+    },
+  },
+};
+</script>
+<style scoped>
+.text-button {
+  border: 0px;
+}
+</style>
+
+<style>
+.text-button:hover {
+  background-color: #f0f9eb !important;
+}
+
+.el-table .warning-row {
+  background: oldlace;
+}
+
+.box-table .el-table tbody tr:hover > td {
+  background-color: #d8e0d4 !important;
+  /* color: #ffffff; */
+}
+
+.box-table .el-table tbody tr.current-row > td {
+  background-color: #f0f9eb !important;
+  /* color: #ffffff; */
+}
+
+.el-table .success-row {
+  background: #f0f9eb;
+}
+
+.box-table .el-table {
+  border: 1px solid #ebeef5;
+}
+</style>
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/outbound/outboundOrder.js" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/outbound/outboundOrder.js"
index 0d4264a..97ad4e9 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/outbound/outboundOrder.js"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/outbound/outboundOrder.js"
@@ -383,8 +383,6 @@
     searchBefore(param) {
       //鐣岄潰鏌ヨ鍓�,鍙互缁檖aram.wheres娣诲姞鏌ヨ鍙傛暟
       //杩斿洖false锛屽垯涓嶄細鎵ц鏌ヨ
-
-
       return true;
     },
     searchAfter(result) {
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/stock/stockInfoDetailByMaterielSum.js" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/stock/stockInfoDetailByMaterielSum.js"
new file mode 100644
index 0000000..2d89d3f
--- /dev/null
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/stock/stockInfoDetailByMaterielSum.js"
@@ -0,0 +1,59 @@
+
+//姝s鏂囦欢鏄敤鏉ヨ嚜瀹氫箟鎵╁睍涓氬姟浠g爜锛屽彲浠ユ墿灞曚竴浜涜嚜瀹氫箟椤甸潰鎴栬�呴噸鏂伴厤缃敓鎴愮殑浠g爜
+
+let extension = {
+    components: {
+      //鏌ヨ鐣岄潰鎵╁睍缁勪欢
+      gridHeader: '',
+      gridBody: '',
+      gridFooter: '',
+      //鏂板缓銆佺紪杈戝脊鍑烘鎵╁睍缁勪欢
+      modelHeader: '',
+      modelBody: '',
+      modelFooter: ''
+    },
+    tableAction: '', //鎸囧畾鏌愬紶琛ㄧ殑鏉冮檺(杩欓噷濉啓琛ㄥ悕,榛樿涓嶇敤濉啓)
+    buttons: { view: [], box: [], detail: [] }, //鎵╁睍鐨勬寜閽�
+    methods: {
+       //涓嬮潰杩欎簺鏂规硶鍙互淇濈暀涔熷彲浠ュ垹闄�
+      onInit() {  
+        console.log(this)
+      },
+      onInited() {
+        //妗嗘灦鍒濆鍖栭厤缃悗
+        //濡傛灉瑕侀厤缃槑缁嗚〃,鍦ㄦ鏂规硶鎿嶄綔
+        //this.detailOptions.columns.forEach(column=>{ });
+      },
+      searchBefore(param) {
+        //鐣岄潰鏌ヨ鍓�,鍙互缁檖aram.wheres娣诲姞鏌ヨ鍙傛暟
+        //杩斿洖false锛屽垯涓嶄細鎵ц鏌ヨ
+        return true;
+      },
+      searchAfter(result) {
+        //鏌ヨ鍚庯紝result杩斿洖鐨勬煡璇㈡暟鎹�,鍙互鍦ㄦ樉绀哄埌琛ㄦ牸鍓嶅鐞嗚〃鏍肩殑鍊�
+        return true;
+      },
+      addBefore(formData) {
+        //鏂板缓淇濆瓨鍓峟ormData涓哄璞★紝鍖呮嫭鏄庣粏琛紝鍙互缁欑粰琛ㄥ崟璁剧疆鍊硷紝鑷繁杈撳嚭鐪媐ormData鐨勫��
+        return true;
+      },
+      updateBefore(formData) {
+        //缂栬緫淇濆瓨鍓峟ormData涓哄璞★紝鍖呮嫭鏄庣粏琛ㄣ�佸垹闄よ鐨処d
+        return true;
+      },
+      rowClick({ row, column, event }) {
+        //鏌ヨ鐣岄潰鐐瑰嚮琛屼簨浠�
+        this.$refs.table.$refs.table.toggleRowSelection(row); //鍗曞嚮琛屾椂閫変腑褰撳墠琛�;
+      },
+      modelOpenAfter(row) {
+        //鐐瑰嚮缂栬緫銆佹柊寤烘寜閽脊鍑烘鍚庯紝鍙互鍦ㄦ澶勫啓閫昏緫锛屽锛屼粠鍚庡彴鑾峰彇鏁版嵁
+        //(1)鍒ゆ柇鏄紪杈戣繕鏄柊寤烘搷浣滐細 this.currentAction=='Add';
+        //(2)缁欏脊鍑烘璁剧疆榛樿鍊�
+        //(3)this.editFormFields.瀛楁='xxx';
+        //濡傛灉闇�瑕佺粰涓嬫媺妗嗚缃粯璁ゅ�硷紝璇烽亶鍘唗his.editFormOptions鎵惧埌瀛楁閰嶇疆瀵瑰簲data灞炴�х殑key鍊�
+        //鐪嬩笉鎳傚氨鎶婅緭鍑虹湅锛歝onsole.log(this.editFormOptions)
+      }
+    }
+  };
+  export default extension;
+  
\ No newline at end of file
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/router/viewGird.js" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/router/viewGird.js"
index 3896357..3c3b62e 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/router/viewGird.js"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/router/viewGird.js"
@@ -217,6 +217,11 @@
     path: '/reCheckOrder',
     name: 'Dt_ReCheckOrder',
     component: () => import('@/views/check/ReCheckOrder.vue')
+  },
+  {
+    path: '/StockDetailByMateriel',
+    name: 'StockDetailByMateriel',
+    component: () => import('@/views/stock/stockInfoDetailByMaterielSum.vue')
   }
 ]
 
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 48d960a..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/stockInfoDetailByMaterielSum.vue" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/views/stock/stockInfoDetailByMaterielSum.vue"
new file mode 100644
index 0000000..2b97cf8
--- /dev/null
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/views/stock/stockInfoDetailByMaterielSum.vue"
@@ -0,0 +1,194 @@
+<template>
+  <view-grid ref="grid" :columns="columns" :detail="detail" :editFormFields="editFormFields"
+    :editFormOptions="editFormOptions" :searchFormFields="searchFormFields" :searchFormOptions="searchFormOptions"
+    :table="table" :extend="extend">
+  </view-grid>
+</template>
+<script>
+import extend from "@/extension/stock/stockInfoDetailByMaterielSum.js";
+import { ref, defineComponent } from "vue";
+export default defineComponent({
+  setup() {
+    const table = ref({
+      key: "id",
+      footer: "Foots",
+      cnName: "搴撳瓨姹囨��",
+      name: "StockDetailByMateriel",
+      url: "/StockDetailByMateriel/",
+      sortName: "id",
+    });
+    const editFormFields = ref({
+      deviceCode: "",
+      deviceName: "",
+      deviceType: "",
+      deviceStatus: "",
+      deviceIp: "",
+      devicePort: "",
+      devicePlcType: "",
+      deviceRemark: "",
+    });
+    const editFormOptions = ref([
+      [
+        {
+          title: "鐗╂枡缂栧彿",
+          required: true,
+          field: "materielCode",
+          type: "string",
+        },
+        {
+          title: "鍗曟嵁缂栧彿",
+          required: true,
+          field: "materielName",
+          type: "string",
+        },
+        {
+          title: "鎵规鍙�",
+          required: true,
+          field: "orderNo",
+          type: "string",
+        },
+        {
+          title: "搴忓垪鍙�",
+          required: true,
+          field: "serialNumber",
+          type: "string",
+        },
+      ],
+      
+    ]);
+    const searchFormFields = ref({
+      materielCode: "",
+      materielName: "",
+      orderNo: "",
+    });
+    const searchFormOptions = ref([
+      [
+        { title: "鐗╂枡缂栧彿", field: "materielCode" ,type:'like'},
+        { title: "鐗╂枡鍚嶇О", field: "materielName" ,type:'like'},
+        { title: "鍗曟嵁缂栧彿", field: "orderNo" ,type:'like'},
+        { title: "鎵樼洏鍙�", field: "palletCode" ,type:'like'},
+      ],
+    ]);
+    const columns = ref([
+      {
+        field: "id",
+        title: "Id",
+        type: "int",
+        width: 90,
+        hidden: true,
+        readonly: true,
+        require: true,
+        align: "left",
+      },
+      {
+        field: "materielCode",
+        title: "鐗╂枡缂栧彿",
+        type: "string",
+        width: 150,
+        align: "left",
+      },
+      {
+        field: "materielName",
+        title: "鐗╂枡鍚嶇О",
+        type: "string",
+        width: 150,
+        align: "left",
+      },
+      {
+        field: "batchNo",
+        title: "鎵规鍙�",
+        type: "string",
+        width: 90,
+        align: "left",
+      },
+      {
+        field: "supplyCode",
+        title: "渚涘簲鍟嗙紪鍙�",
+        type: "string",
+        width: 120,
+        align: "left",
+      },
+      {
+        field: "warehouseCode",
+        title: "浠撳簱鍙�",
+        type: "string",
+        width: 120,
+        align: "left",
+      },        
+      {
+        field: "stockQuantity",
+        title: "搴撳瓨鏁伴噺",
+        type: "string",
+        width: 200,
+        align: "left",
+      },
+      {
+        field: "outboundQuantity",
+        title: "鍑哄簱鏁伴噺",
+        type: "string",
+        width: 180,
+        align: "left",
+      },
+      {
+        field: "status",
+        title: "搴撳瓨鏄庣粏鐘舵��",
+        type: "string",
+        width: 120,
+        align: "left",
+        bind: { key: "stockStatusEmun", data: [] },
+      },
+      {
+        field: "creater",
+        title: "鍒涘缓浜�",
+        type: "string",
+        width: 90,
+        align: "left",
+      },
+      {
+        field: "createDate",
+        title: "鍒涘缓鏃堕棿",
+        type: "datetime",
+        width: 160,
+        align: "left",
+      },
+      {
+        field: "modifier",
+        title: "淇敼浜�",
+        type: "string",
+        width: 100,
+        align: "left",
+      },
+      {
+        field: "modifyDate",
+        title: "淇敼鏃堕棿",
+        type: "datetime",
+        width: 160,
+        align: "left",
+      },
+      {
+        field: "remark",
+        title: "澶囨敞",
+        type: "string",
+        width: 100,
+        align: "left",
+      },
+    ]);
+    const detail = ref({
+      cnName: "#detailCnName",
+      table: "",
+      columns: [],
+      sortName: "",
+    });
+    return {
+      table,
+      extend,
+      editFormFields,
+      editFormOptions,
+      searchFormFields,
+      searchFormOptions,
+      columns,
+      detail,
+    };
+  },
+});
+</script>
\ No newline at end of file
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/.vs/WIDESEA_WMSServer/CopilotIndices/17.14.878.3237/CodeChunks.db-shm" "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/.vs/WIDESEA_WMSServer/CopilotIndices/17.14.878.3237/CodeChunks.db-shm"
index 97ece0b..90089a4 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/.vs/WIDESEA_WMSServer/CopilotIndices/17.14.878.3237/CodeChunks.db-shm"
+++ "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/.vs/WIDESEA_WMSServer/CopilotIndices/17.14.878.3237/CodeChunks.db-shm"
Binary files differ
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/.vs/WIDESEA_WMSServer/CopilotIndices/17.14.878.3237/SemanticSymbols.db-shm" "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/.vs/WIDESEA_WMSServer/CopilotIndices/17.14.878.3237/SemanticSymbols.db-shm"
index 81243ca..05d54c7 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/.vs/WIDESEA_WMSServer/CopilotIndices/17.14.878.3237/SemanticSymbols.db-shm"
+++ "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/.vs/WIDESEA_WMSServer/CopilotIndices/17.14.878.3237/SemanticSymbols.db-shm"
Binary files differ
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_AllocateService/AllocateDetailService.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_AllocateService/AllocateDetailService.cs"
index 16ac24f..cd2b75e 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_AllocateService/AllocateDetailService.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_AllocateService/AllocateDetailService.cs"
@@ -15,37 +15,72 @@
 {
     public class AllocateDetailService : ServiceBase<Dt_AllocateOrderDetail, IRepository<Dt_AllocateOrderDetail>>, IAllocateDetailService
     {
-        public AllocateDetailService(IRepository<Dt_AllocateOrderDetail> BaseDal) : base(BaseDal)
+        public readonly IRepository<Dt_AllocateOrder> _allocateOrderRepository;
+        public AllocateDetailService(IRepository<Dt_AllocateOrderDetail> BaseDal, IRepository<Dt_AllocateOrder> allocateOrderRepository) : base(BaseDal)
         {
+            _allocateOrderRepository = allocateOrderRepository;
         }
 
         IRepository<Dt_AllocateOrderDetail> IAllocateDetailService.Repository => BaseDal;
 
-        public override PageGridData<Dt_AllocateOrderDetail> GetPageData(PageDataOptions options)
+        public override PageGridData<Dt_OutboundOrderDetail> GetDetailPage(PageDataOptions options)
         {
+            string wheres = ValidatePageOptions(options);
+            //鑾峰彇鎺掑簭瀛楁
+            Dictionary<string, SqlSugar.OrderByType> orderbyDic = GetPageDataSort(options, TProperties);
+            List<OrderByModel> orderByModels = new List<OrderByModel>();
+            foreach (var item in orderbyDic)
+            {
+                OrderByModel orderByModel = new()
+                {
+                    FieldName = item.Key,
+                    OrderByType = item.Value
+                };
+                orderByModels.Add(orderByModel);
+            }
 
-            ISugarQueryable<Dt_AllocateOrderDetail> sugarQueryable1 = BaseDal.Db.Queryable<Dt_AllocateOrderDetail>();
+
+            int totalCount = 0;
+            List<SearchParameters> searchParametersList = new List<SearchParameters>();
             if (!string.IsNullOrEmpty(options.Wheres))
             {
-
-                List<SearchParameters> searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
-                int totalCount = 0;
-                if (searchParametersList.Count > 0)
+                try
                 {
-                    {
-                        SearchParameters? searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_AllocateOrderDetail.OrderId).FirstLetterToLower());
-                        if (searchParameters != null)
-                        {
-                            sugarQueryable1 = sugarQueryable1.Where(x => x.OrderId == searchParameters.Value.ObjToInt());
-                            var dataList = sugarQueryable1.ToPageList(options.Page, options.Rows, ref totalCount);
-                            return new PageGridData<Dt_AllocateOrderDetail>(totalCount, dataList);
-                        }
-                    }
-
-
+                    searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
+                    options.Filter = searchParametersList;
                 }
+                catch { }
             }
-            return new PageGridData<Dt_AllocateOrderDetail>();
+            //var data = BaseDal.Db.Queryable<Dt_AllocateOrderDetail>()
+            //    .WhereIF(!wheres.IsNullOrEmpty(), wheres)
+            //    .OrderBy(orderByModels)
+            //    .ToPageList(options.Page, options.Rows, ref totalCount);
+            //Dt_AllocateOrder allocateOrder = _allocateOrderRepository.QueryFirst(x => x.Id == (int)options.Value);
+            //Dt_InboundOrder _InboundOrder = SqlSugarHelper.DbWMS.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == allocateOrder.UpperOrderNo).First();
+            //var details = _inboundOrderDetailRepository.QueryData(x => x.OrderId == _InboundOrder.Id );
+            //foreach (var item in data)
+            //{
+            //    var detail = details.Where(x => x.MaterielCode == item.MaterielCode).FirstOrDefault();
+            //    if (detail != null)
+            //    {
+            //        item.OrderQuantity = detail.OrderQuantity;
+            //        item.ReceiptQuantity = detail.ReceiptQuantity;
+            //        item.OverInQuantity = detail.OverInQuantity;
+            //        item.OrderDetailStatus = detail.OrderDetailStatus;
+            //    }
+            //}
+            //return new PageGridData<Dt_AllocateOrderDetail>(totalCount, data);
+
+            Dt_AllocateOrder allocateOrder = _allocateOrderRepository.QueryFirst(x => x.Id == options.Filter.FirstOrDefault().Value.ObjToInt());
+            Dt_OutboundOrder _InboundOrder = SqlSugarHelper.DbWMS.Queryable<Dt_OutboundOrder>().Where(x => x.UpperOrderNo == allocateOrder.UpperOrderNo).First();
+
+            var data = BaseDal.Db.Queryable<Dt_OutboundOrderDetail>()
+                .WhereIF(!_InboundOrder.IsNullOrEmpty(), x => x.OrderId == _InboundOrder.Id)
+                .OrderBy(orderByModels)
+                .ToPageList(options.Page, options.Rows, ref totalCount);
+
+
+            return new PageGridData<Dt_OutboundOrderDetail>(totalCount, data);
         }
     }
 }
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_BasicService/ErpApiService.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_BasicService/ErpApiService.cs"
index b1efea1..52a7bc9 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_BasicService/ErpApiService.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_BasicService/ErpApiService.cs"
@@ -6,6 +6,7 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Net;
 using System.Reflection.Emit;
 using System.Text;
 using System.Threading.Tasks;
@@ -355,11 +356,13 @@
                 json = JsonConvert.SerializeObject(request);
             }
 
+      
             var content = new StringContent(json, Encoding.UTF8, "application/json");
             var _client = _httpClientFactory.CreateClient("ERPUrl");
             _client.DefaultRequestHeaders.Clear();
 
 
+
             string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
             string base64Header = Convert.ToBase64String(Encoding.UTF8.GetBytes(timestamp));
             _client.DefaultRequestHeaders.Add("X-Custom-Header", base64Header);
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_BasicService/InvokeMESService.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_BasicService/InvokeMESService.cs"
index 81b25b0..458cce5 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_BasicService/InvokeMESService.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_BasicService/InvokeMESService.cs"
@@ -245,147 +245,145 @@
         public async Task<WebResponseContent> BatchOrderFeedbackToMes(List<string> orderNos, int inout)
         {
             try
-            {             // 1. 銆愬唴瀛橀攣鎶㈠崰銆�
-                //if (MemoryLockManager.TryAcquireLock(orderNos[0]))
-                //{
-                   
-                        if (inout == 1)
+            {         
+
+                if (inout == 1)
+                {
+                    foreach (var orderNo in orderNos)
+                    {
+                        try
                         {
-                            foreach (var orderNo in orderNos)
+                            var stockinfos = _stockInfoRepository.Db.Queryable<Dt_StockInfo>("info").Where(info => info.StockStatus == 6)
+                                            .Where(it => SqlFunc.Subqueryable<Dt_StockInfoDetail>().Where(s => s.StockId == it.Id && s.OrderNo == orderNo).Any())
+                                            .ToList();
+                            var feeds = _feedbacktomesRepository.Db.Queryable<Dt_FeedbackToMes>().Where(x => x.OrderNo == orderNo && x.ReportStatus == 1).Select(o => o.PalletCode).ToList();
+                            var unreports = stockinfos.Where(x => !feeds.Contains(x.PalletCode)).ToList();
+                            if (unreports != null && !unreports.Any())
                             {
-                                try
+                                return WebResponseContent.Instance.Error("娌℃湁闇�瑕佸洖浼犵殑鏁版嵁");
+                            }
+                            foreach (var item in unreports)
+                            {
+                                var lists = _stockInfoDetailRepository.Db.Queryable<Dt_StockInfoDetail>().Where(x => x.StockId == item.Id).ToList();
+                                if (lists.Any())
                                 {
-                                    var stockinfos = _stockInfoRepository.Db.Queryable<Dt_StockInfo>("info").Where(info => info.StockStatus == 6)
-                                                    .Where(it => SqlFunc.Subqueryable<Dt_StockInfoDetail>().Where(s => s.StockId == it.Id && s.OrderNo == orderNo).Any())
-                                                    .ToList();
-                                    var feeds = _feedbacktomesRepository.Db.Queryable<Dt_FeedbackToMes>().Where(x => x.OrderNo == orderNo && x.ReportStatus == 1).Select(o => o.PalletCode).ToList();
-                                    var unreports = stockinfos.Where(x => !feeds.Contains(x.PalletCode)).ToList();
-                                    if (unreports != null && !unreports.Any())
+                                    var inboundOrder = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>().First(x => x.InboundOrderNo == lists.FirstOrDefault().OrderNo);
+                                    if (inboundOrder != null)
                                     {
-                                        return WebResponseContent.Instance.Error("娌℃湁闇�瑕佸洖浼犵殑鏁版嵁");
-                                    }
-                                    foreach (var item in unreports)
-                                    {
-                                        var lists = _stockInfoDetailRepository.Db.Queryable<Dt_StockInfoDetail>().Where(x => x.StockId == item.Id).ToList();
-                                        if (lists.Any())
+                                        if (inboundOrder.OrderType == (int)InOrderTypeEnum.AllocatInbound)//璋冩嫧鍏ュ簱
                                         {
-                                            var inboundOrder = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>().First(x => x.InboundOrderNo == lists.FirstOrDefault().OrderNo);
-                                            if (inboundOrder != null)
+                                            var allocate = SqlSugarHelper.DbWMS.Queryable<Dt_AllocateOrder>().Where(x => x.OrderNo == inboundOrder.InboundOrderNo).First();
+                                            var allocatefeedmodel = new AllocateDto
                                             {
-                                                if (inboundOrder.OrderType == (int)InOrderTypeEnum.AllocatInbound)//璋冩嫧鍏ュ簱
-                                                {
-                                                    var allocate = SqlSugarHelper.DbWMS.Queryable<Dt_AllocateOrder>().Where(x => x.OrderNo == inboundOrder.InboundOrderNo).First();
-                                                    var allocatefeedmodel = new AllocateDto
-                                                    {
-                                                        ReqCode = Guid.NewGuid().ToString(),
-                                                        ReqTime = DateTime.Now.ToString(),
-                                                        BusinessType = "2",
-                                                        FactoryArea = inboundOrder.FactoryArea,
-                                                        OperationType = 1,
-                                                        Operator = inboundOrder.Operator,
-                                                        OrderNo = inboundOrder.UpperOrderNo,
-                                                        fromWarehouse = allocate?.FromWarehouse ?? "",
-                                                        toWarehouse = allocate?.ToWarehouse ?? "",
-                                                        Details = new List<AllocateDtoDetail>()
+                                                ReqCode = Guid.NewGuid().ToString(),
+                                                ReqTime = DateTime.Now.ToString(),
+                                                BusinessType = "2",
+                                                FactoryArea = inboundOrder.FactoryArea,
+                                                OperationType = 1,
+                                                Operator = inboundOrder.Operator,
+                                                OrderNo = inboundOrder.UpperOrderNo,
+                                                fromWarehouse = allocate?.FromWarehouse ?? "",
+                                                toWarehouse = allocate?.ToWarehouse ?? "",
+                                                Details = new List<AllocateDtoDetail>()
 
-                                                    };
+                                            };
 
-                                                    var groupedData = lists.GroupBy(item => new { item.MaterielCode, item.InboundOrderRowNo, item.BarcodeUnit, item.WarehouseCode })
-                                                       .Select(group => new AllocateDtoDetail
-                                                       {
-                                                           MaterialCode = group.Key.MaterielCode,
-                                                           LineNo = group.Key.InboundOrderRowNo,
-                                                           WarehouseCode = group.Key.WarehouseCode,
-                                                           Qty = group.Sum(x => x.BarcodeQty),
-                                                           Unit = group.Key.BarcodeUnit,
-                                                           Barcodes = group.Select(row => new BarcodeInfo
-                                                           {
-                                                               Barcode = row.Barcode,
-                                                               Qty = row.BarcodeQty,
-                                                               BatchNo = row.BatchNo,
-                                                               SupplyCode = row.SupplyCode,
-                                                               Unit = row.BarcodeUnit
-                                                           }).ToList()
-                                                       }).ToList();
-                                                    allocatefeedmodel.Details = groupedData;
+                                            var groupedData = lists.GroupBy(item => new { item.MaterielCode, item.InboundOrderRowNo, item.BarcodeUnit, item.WarehouseCode })
+                                               .Select(group => new AllocateDtoDetail
+                                               {
+                                                   MaterialCode = group.Key.MaterielCode,
+                                                   LineNo = group.Key.InboundOrderRowNo,
+                                                   WarehouseCode = group.Key.WarehouseCode,
+                                                   Qty = group.Sum(x => x.BarcodeQty),
+                                                   Unit = group.Key.BarcodeUnit,
+                                                   Barcodes = group.Select(row => new BarcodeInfo
+                                                   {
+                                                       Barcode = row.Barcode,
+                                                       Qty = row.BarcodeQty,
+                                                       BatchNo = row.BatchNo,
+                                                       SupplyCode = row.SupplyCode,
+                                                       Unit = row.BarcodeUnit
+                                                   }).ToList()
+                                               }).ToList();
+                                            allocatefeedmodel.Details = groupedData;
 
-                                                    var result = await FeedbackAllocate(allocatefeedmodel);
-                                                    if (result != null && result.code == 200)
-                                                    {
-                                                        _feedbacktomesRepository.Db.Insertable(new Dt_FeedbackToMes { OrderNo = orderNo, PalletCode = item.PalletCode, ReportStatus = 1 }).ExecuteCommand();
-                                                    }
-                                                }
-                                                else
-                                                {
-                                                    var feedmodel = new FeedbackInboundRequestModel
-                                                    {
-                                                        reqCode = Guid.NewGuid().ToString(),
-                                                        reqTime = DateTime.Now.ToString(),
-                                                        business_type = inboundOrder.BusinessType,
-                                                        factoryArea = inboundOrder.FactoryArea,
-                                                        operationType = 1,
-                                                        Operator = inboundOrder.Operator,
-                                                        orderNo = inboundOrder.UpperOrderNo,
-                                                        status = inboundOrder.OrderStatus,
-                                                        details = new List<FeedbackInboundDetailsModel>()
+                                            var result = await FeedbackAllocate(allocatefeedmodel);
+                                            if (result != null && result.code == 200)
+                                            {
+                                                _feedbacktomesRepository.Db.Insertable(new Dt_FeedbackToMes { OrderNo = orderNo, PalletCode = item.PalletCode, ReportStatus = 1 }).ExecuteCommand();
+                                            }
+                                        }
+                                        else
+                                        {
+                                            var feedmodel = new FeedbackInboundRequestModel
+                                            {
+                                                reqCode = Guid.NewGuid().ToString(),
+                                                reqTime = DateTime.Now.ToString(),
+                                                business_type = inboundOrder.BusinessType,
+                                                factoryArea = inboundOrder.FactoryArea,
+                                                operationType = 1,
+                                                Operator = inboundOrder.Operator,
+                                                orderNo = inboundOrder.UpperOrderNo,
+                                                status = inboundOrder.OrderStatus,
+                                                details = new List<FeedbackInboundDetailsModel>()
 
-                                                    };
+                                            };
 
-                                                    var groupedData = lists.GroupBy(item => new { item.MaterielCode, item.SupplyCode, item.BatchNo, item.InboundOrderRowNo, item.BarcodeUnit, item.WarehouseCode })
-                                                       .Select(group => new FeedbackInboundDetailsModel
-                                                       {
-                                                           materialCode = group.Key.MaterielCode,
-                                                           supplyCode = group.Key.SupplyCode,
-                                                           batchNo = group.Key.BatchNo,
-                                                           lineNo = group.Key.InboundOrderRowNo,
-                                                           qty = group.Sum(x => x.BarcodeQty),
-                                                           // warehouseCode = group.Key.WarehouseCode=="0"?"1072": group.Key.WarehouseCode,
-                                                           warehouseCode = group.Key.WarehouseCode,
-                                                           unit = group.Key.BarcodeUnit,
-                                                           barcodes = group.Select(row => new FeedbackBarcodesModel
-                                                           {
-                                                               barcode = row.Barcode,
-                                                               qty = row.BarcodeQty
-                                                           }).ToList()
-                                                       }).ToList();
-                                                    feedmodel.details = groupedData;
-                                                    var result = await FeedbackInbound(feedmodel);
-                                                    if (result != null && result.code == 200)
-                                                    {
-                                                        _feedbacktomesRepository.Db.Insertable(new Dt_FeedbackToMes { OrderNo = orderNo, PalletCode = item.PalletCode, ReportStatus = 1 }).ExecuteCommand();
-                                                    }
-                                                }
+                                            var groupedData = lists.GroupBy(item => new { item.MaterielCode, item.SupplyCode, item.BatchNo, item.InboundOrderRowNo, item.BarcodeUnit, item.WarehouseCode })
+                                               .Select(group => new FeedbackInboundDetailsModel
+                                               {
+                                                   materialCode = group.Key.MaterielCode,
+                                                   supplyCode = group.Key.SupplyCode,
+                                                   batchNo = group.Key.BatchNo,
+                                                   lineNo = group.Key.InboundOrderRowNo,
+                                                   qty = group.Sum(x => x.BarcodeQty),
+                                                   // warehouseCode = group.Key.WarehouseCode=="0"?"1072": group.Key.WarehouseCode,
+                                                   warehouseCode = group.Key.WarehouseCode,
+                                                   unit = group.Key.BarcodeUnit,
+                                                   barcodes = group.Select(row => new FeedbackBarcodesModel
+                                                   {
+                                                       barcode = row.Barcode,
+                                                       qty = row.BarcodeQty
+                                                   }).ToList()
+                                               }).ToList();
+                                            feedmodel.details = groupedData;
+                                            var result = await FeedbackInbound(feedmodel);
+                                            if (result != null && result.code == 200)
+                                            {
+                                                _feedbacktomesRepository.Db.Insertable(new Dt_FeedbackToMes { OrderNo = orderNo, PalletCode = item.PalletCode, ReportStatus = 1 }).ExecuteCommand();
                                             }
                                         }
                                     }
                                 }
-                                catch (Exception ex)
-                                {
-                                    _logger.LogInformation("InvokeMESService  BatchOrderFeedbackToMes 鍥炲啓MES澶辫触:  " + ex.Message);
-                                    return WebResponseContent.Instance.Error(ex.Message);
-                                }
-
                             }
                         }
-                        else if (inout == 2)
+                        catch (Exception ex)
                         {
-                            foreach (var orderNo in orderNos)
-                            {
-                                var outboundOrder = await _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().FirstAsync(x => x.OrderNo == orderNo);
-                                if (outboundOrder != null && outboundOrder.IsBatch == 0)
-                                {
-                                    var result = await HandleOutboundOrderToMESCompletion(outboundOrder, orderNo);
-                                    return result;
-                                }
-                                else if (outboundOrder != null && outboundOrder.IsBatch == 1)
-                                {
-                                    var result = await HandleOutboundOrderBatchToMESCompletion(outboundOrder, orderNo);
-                                    return result;
-                                }
-                            }
-
+                            _logger.LogInformation("InvokeMESService  BatchOrderFeedbackToMes 鍥炲啓MES澶辫触:  " + ex.Message);
+                            return WebResponseContent.Instance.Error(ex.Message);
                         }
-                     
+
+                    }
+                }
+                else if (inout == 2)
+                {
+                    foreach (var orderNo in orderNos)
+                    {
+                        var outboundOrder = await _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().FirstAsync(x => x.OrderNo == orderNo);
+                        if (outboundOrder != null && outboundOrder.IsBatch == 0)
+                        {
+                            var result = await HandleOutboundOrderToMESCompletion(outboundOrder, orderNo);
+                            return result;
+                        }
+                        else if (outboundOrder != null && outboundOrder.IsBatch == 1)
+                        {
+                            var result = await HandleOutboundOrderBatchToMESCompletion(outboundOrder, orderNo);
+                            return result;
+                        }
+                    }
+
+                }
+
                 //}
                 //else
                 //{
@@ -394,14 +392,14 @@
                 //    return WebResponseContent.Instance.Error("WMS姝e湪澶勭悊姝ゅ洖浼犱换鍔★紝璇峰嬁閲嶅鎿嶄綔銆�");
                 //}
             }
-            catch(Exception ex)
+            catch (Exception ex)
             {
-                _logger.LogInformation("InvokeMESService  BatchOrderFeedbackToMes :  " +ex.Message);
+                _logger.LogInformation("InvokeMESService  BatchOrderFeedbackToMes :  " + ex.Message);
             }
             finally
             {
                 // 2. 銆愰噴鏀惧唴瀛橀攣銆戞棤璁烘垚鍔熷け璐ワ紝蹇呴』閲婃斁
-               // MemoryLockManager.ReleaseLock(orderNos[0]);
+                // MemoryLockManager.ReleaseLock(orderNos[0]);
             }
             return WebResponseContent.Instance.OK();
         }
@@ -913,52 +911,188 @@
 
     public static class MemoryLockManager
     {
-        // 瀛樺偍璧勬簮ID鍙婂叾瀵瑰簲鐨勯攣瀵硅薄銆備娇鐢� ConcurrentDictionary 纭繚瀵瑰瓧鍏告搷浣滄湰韬殑绾跨▼瀹夊叏銆�
-        private static readonly ConcurrentDictionary<string, object> _resourceLocks = new ConcurrentDictionary<string, object>();
+        // 瀛樺偍璧勬簮閿佺殑鍏冩暟鎹紙閿佸璞°�佹寔鏈夌嚎绋嬨�佸崰鐢ㄦ椂闂淬�佽秴鏃舵椂闂达級
+        private class LockMetadata
+        {
+            public object LockObject { get; } = new object();
+            public int HoldingThreadId { get; set; } = -1; // 鎸佹湁閿佺殑绾跨▼ID
+            public DateTime AcquireTime { get; set; } // 鑾峰彇閿佺殑鏃堕棿
+            public TimeSpan Timeout { get; set; } // 閿佽秴鏃舵椂闂�
+            public bool IsReleased { get; set; } // 鏄惁宸查噴鏀�
+        }
 
-        // 鍏ㄥ眬闈欐�侀攣锛氱敤浜庝繚鎶� _resourceLocks 瀛楀吀涓� GetOrAdd 鎴� TryRemove 鏃剁殑绔炰簤
-        private static readonly object _globalLocker = new object();
+        // 璧勬簮ID -> 閿佸厓鏁版嵁
+        private static readonly ConcurrentDictionary<string, LockMetadata> _resourceLocks = new();
+        // 鍏ㄥ眬閿侊紙淇濇姢閿佸厓鏁版嵁鐨勫垱寤�/鍒犻櫎锛�
+        private static readonly object _globalLocker = new();
+        // 闅忔満鏁扮敓鎴愬櫒锛堢敤浜庣敓鎴�3-5绉掗殢鏈鸿秴鏃讹級
+        private static readonly Random _random = new Random();
 
         /// <summary>
-        /// 灏濊瘯閿佸畾涓�涓祫婧怚D銆�
+        /// 灏濊瘯閿佸畾璧勬簮锛堝甫瓒呮椂鑷姩閲婃斁锛�
         /// </summary>
-        /// <param name="resourceId">瑕侀攣瀹氱殑璧勬簮ID锛堜緥濡� InboundRecord ID锛�</param>
+        /// <param name="resourceId">璧勬簮ID</param>
+        /// <param name="timeoutSeconds">瓒呮椂鏃堕棿锛堥粯璁�3-5绉掗殢鏈猴級</param>
         /// <returns>鏄惁鎴愬姛鑾峰彇閿�</returns>
-        public static bool TryAcquireLock(string resourceId)
+        public static bool TryAcquireLock(string resourceId, int? timeoutSeconds = null)
         {
-            object lockObject = null;
+            if (string.IsNullOrEmpty(resourceId))
+                throw new ArgumentNullException(nameof(resourceId));
 
-            // 鏍稿績鎬濊矾锛氫负姣忎釜璧勬簮鍒涘缓涓�涓敮涓�鐨勯攣瀵硅薄
+            // 纭畾瓒呮椂鏃堕棿锛�3-5绉掗殢鏈猴級
+            var timeout = TimeSpan.FromSeconds(timeoutSeconds ?? _random.Next(3, 6));
+            var currentThreadId = Thread.CurrentThread.ManagedThreadId;
+
+            LockMetadata lockMeta = null;
             lock (_globalLocker)
             {
-                // 濡傛灉璧勬簮ID涓嶅湪瀛楀吀涓紝鍒欐坊鍔犱竴涓柊鐨勯攣瀵硅薄
-                // 鍚﹀垯锛屼娇鐢ㄥ凡瀛樺湪鐨勯攣瀵硅薄
-                lockObject = _resourceLocks.GetOrAdd(resourceId, new object());
+                // 鑾峰彇鎴栧垱寤洪攣鍏冩暟鎹�
+                lockMeta = _resourceLocks.GetOrAdd(resourceId, key => new LockMetadata());
+
+                // 闃叉閲嶅鑾峰彇锛堝綋鍓嶇嚎绋嬪凡鎸佹湁閿侊級
+                if (lockMeta.HoldingThreadId == currentThreadId && !lockMeta.IsReleased)
+                    return true; // 绾跨▼鍙噸鍏�
             }
 
-            // 灏濊瘯鑾峰彇璧勬簮鐗瑰畾鐨勯攣
-            // 浣跨敤 Monitor.TryEnter 閬垮厤闃诲锛屽苟瀹炵幇闈為樆濉炵殑鎶㈤攣
-            return Monitor.TryEnter(lockObject);
+            // 灏濊瘯鑾峰彇閿侊紙闈為樆濉烇級
+            if (!Monitor.TryEnter(lockMeta.LockObject))
+                return false;
+
+            // 鏍囪閿佹寔鏈夌姸鎬�
+            lockMeta.HoldingThreadId = currentThreadId;
+            lockMeta.AcquireTime = DateTime.Now;
+            lockMeta.Timeout = timeout;
+            lockMeta.IsReleased = false;
+
+            // 鍚姩瓒呮椂鑷姩閲婃斁浠诲姟
+            _ = Task.Delay(timeout).ContinueWith(_ =>
+            {
+                try
+                {
+                    ReleaseLock(resourceId, force: true);
+                }
+                catch (Exception ex)
+                {
+                    // 璁板綍瓒呮椂閲婃斁寮傚父 
+                    Console.WriteLine($"璧勬簮[{resourceId}]瓒呮椂鑷姩閲婃斁澶辫触锛歿ex.Message}");
+                }
+            });
+
+            return true;
         }
 
         /// <summary>
-        /// 閲婃斁璧勬簮ID鐨勯攣瀹氥��
+        /// 閲婃斁璧勬簮閿�
         /// </summary>
-        /// <param name="resourceId">瑕侀噴鏀剧殑璧勬簮ID</param>
-        public static void ReleaseLock(string resourceId)
+        /// <param name="resourceId">璧勬簮ID</param>
+        /// <param name="force">鏄惁寮哄埗閲婃斁锛堣秴鏃惰嚜鍔ㄩ噴鏀炬椂浣跨敤锛�</param>
+        public static void ReleaseLock(string resourceId, bool force = false)
         {
-            if (_resourceLocks.TryGetValue(resourceId, out object lockObject))
-            {
-                // 纭繚閲婃斁鐨勬槸褰撳墠绾跨▼鎸佹湁鐨勯攣
-                if (Monitor.IsEntered(lockObject))
-                {
-                    Monitor.Exit(lockObject);
+            if (string.IsNullOrEmpty(resourceId))
+                throw new ArgumentNullException(nameof(resourceId));
 
-                    // 閲婃斁閿佸悗锛屽皾璇曚粠瀛楀吀涓Щ闄よ繖涓攣瀵硅薄锛屾竻鐞嗗唴瀛樸��
-                    // 蹇呴』鍦� Monitor.Exit 涔嬪悗鎵ц銆�
+            if (!_resourceLocks.TryGetValue(resourceId, out var lockMeta))
+                return;
+
+            var currentThreadId = Thread.CurrentThread.ManagedThreadId;
+
+            // 鏍¢獙閲婃斁鍚堟硶鎬э細浠呮寔鏈夐攣鐨勭嚎绋嬫垨寮哄埗閲婃斁鍙墽琛�
+            if (!force && lockMeta.HoldingThreadId != currentThreadId)
+            {
+                // 闈炴寔鏈夌嚎绋嬪皾璇曢噴鏀撅紝鎶涘嚭寮傚父鎴栬繑鍥烇紙鏍规嵁涓氬姟閫夋嫨锛�
+                throw new InvalidOperationException($"绾跨▼[{currentThreadId}]鏃犳潈閲婃斁璧勬簮[{resourceId}]鐨勯攣锛堝綋鍓嶆寔鏈夌嚎绋嬶細{lockMeta.HoldingThreadId}锛�");
+            }
+
+            // 鍙岄噸鏍¢獙閿佺姸鎬�
+            lock (_globalLocker)
+            {
+                if (lockMeta.IsReleased)
+                    return;
+
+                // 纭繚閿佽褰撳墠绾跨▼鎸佹湁锛堝己鍒堕噴鏀鹃櫎澶栵級
+                if (Monitor.IsEntered(lockMeta.LockObject))
+                {
+                    try
+                    {
+                        Monitor.Exit(lockMeta.LockObject);
+                    }
+                    catch (SynchronizationLockException)
+                    {
+                        // 宸茶閲婃斁锛屽拷鐣�
+                        return;
+                    }
+                }
+
+                // 鏍囪閿佸凡閲婃斁
+                lockMeta.IsReleased = true;
+                lockMeta.HoldingThreadId = -1;
+
+                // 寤惰繜娓呯悊閿佸厓鏁版嵁锛堥伩鍏嶅苟鍙戝垱寤猴級
+                // 绛夊緟1绉掑悗娓呯悊锛岄槻姝㈠垰閲婃斁灏辨湁鏂扮嚎绋嬫姠閿佸鑷撮噸澶嶅垱寤�
+                _ = Task.Delay(1000).ContinueWith(_ =>
+                {
                     lock (_globalLocker)
                     {
-                        _resourceLocks.TryRemove(resourceId, out _);
+                        // 浠呭綋閿佹湭琚噸鏂版寔鏈変笖宸查噴鏀炬椂娓呯悊
+                        if (_resourceLocks.TryGetValue(resourceId, out var meta)
+                            && meta.IsReleased
+                            && meta.HoldingThreadId == -1)
+                        {
+                            _resourceLocks.TryRemove(resourceId, out var _resid);
+                        }
+                    }
+                });
+            }
+        }
+
+        /// <summary>
+        /// 妫�鏌ヨ祫婧愭槸鍚﹁閿佸畾
+        /// </summary>
+        public static bool IsLocked(string resourceId)
+        {
+            if (!_resourceLocks.TryGetValue(resourceId, out var meta))
+                return false;
+
+            return !meta.IsReleased && meta.HoldingThreadId != -1;
+        }
+
+        public static void TestUsed()
+        {
+            string orderNo = "testt";
+            bool lockAcquired = false;
+            try
+            {
+                // 灏濊瘯鑾峰彇閿侊紙鑷姩3-5绉掕秴鏃讹級
+                lockAcquired = MemoryLockManager.TryAcquireLock(orderNo);
+                if (lockAcquired)
+                {
+                    // 鎵ц涓氬姟閫昏緫锛堝澶勭悊璁㈠崟锛�
+                    Console.WriteLine($"绾跨▼[{Thread.CurrentThread.ManagedThreadId}]鑾峰彇閿侊細{orderNo}");
+                    // 妯℃嫙涓氬姟鑰楁椂锛堟祴璇曡秴鏃堕噴鏀撅級
+                    // Thread.Sleep(6000); 
+                }
+                else
+                {
+                    Console.WriteLine($"璧勬簮[{orderNo}]琚崰鐢紝鑾峰彇閿佸け璐�");
+                }
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine($"涓氬姟澶勭悊寮傚父锛歿ex.Message}");
+            }
+            finally
+            {
+                // 閲婃斁閿侊紙浠呭綋鎴愬姛鑾峰彇鏃讹級
+                if (lockAcquired)
+                {
+                    try
+                    {
+                        MemoryLockManager.ReleaseLock(orderNo);
+                        Console.WriteLine($"绾跨▼[{Thread.CurrentThread.ManagedThreadId}]閲婃斁閿侊細{orderNo}");
+                    }
+                    catch (Exception ex)
+                    {
+                        Console.WriteLine($"閲婃斁閿佸け璐ワ細{ex.Message}");
                     }
                 }
             }
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_DTO/Stock/StockDetailDtO.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_DTO/Stock/StockDetailDtO.cs"
new file mode 100644
index 0000000..c82c12f
--- /dev/null
+++ "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_DTO/Stock/StockDetailDtO.cs"
@@ -0,0 +1,76 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WIDESEA_DTO.Stock
+{
+    public class StockDetailDtO
+    {
+       
+        public int Id { get; set; }
+
+       
+        public int StockId { get; set; }
+
+       
+        public string MaterielCode { get; set; }
+
+     
+        public string MaterielName { get; set; }
+
+      
+        public string OrderNo { get; set; }
+
+       
+        public string BatchNo { get; set; }
+
+       
+        public string ProductionDate { get; set; }
+
+     
+        public string EffectiveDate { get; set; }
+
+       
+        public string SerialNumber { get; set; }
+
+       
+        public decimal StockQuantity { get; set; }
+
+       
+        public decimal OutboundQuantity { get; set; }
+
+        
+        public int Status { get; set; }
+
+        
+        public string Unit { get; set; }
+        
+        public string InboundOrderRowNo { get; set; }
+
+      
+        public string? SupplyCode { get; set; }
+
+        public string FactoryArea { get; set; }
+      
+        public string? WarehouseCode { get; set; }
+
+     
+        public string? Barcode { get; set; }
+
+
+        
+        public string? BusinessType { get; set; }
+
+
+        public decimal BarcodeQty { get; set; }
+
+        public string BarcodeUnit { get; set; }
+
+        public DateTime? ValidDate { get; set; }
+      
+        public string Remark { 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_IAllocateService/IAllocateDetailService.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_IAllocateService/IAllocateDetailService.cs"
index 0d40c4b..e99b66e 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_IAllocateService/IAllocateDetailService.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_IAllocateService/IAllocateDetailService.cs"
@@ -12,5 +12,6 @@
     public interface IAllocateDetailService : IService<Dt_AllocateOrderDetail>
     {
         IRepository<Dt_AllocateOrderDetail> Repository { get; }
+
     }
 }
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_IStockService/IStockDetailByMaterielService.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_IStockService/IStockDetailByMaterielService.cs"
new file mode 100644
index 0000000..d7838cc
--- /dev/null
+++ "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_IStockService/IStockDetailByMaterielService.cs"
@@ -0,0 +1,18 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using WIDESEA_Core;
+using WIDESEA_Core.BaseRepository;
+using WIDESEA_Core.BaseServices;
+using WIDESEA_DTO.Stock;
+using WIDESEA_Model.Models;
+
+namespace WIDESEA_IStockService
+{
+    public interface IStockDetailByMaterielService : IDependency
+    {
+        PageGridData<StockDetailByMateriel> GetPageGridData(PageDataOptions options);
+    }
+}
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_IStockService/IStockInfoDetailService.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_IStockService/IStockInfoDetailService.cs"
index ff8345e..93c7e76 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_IStockService/IStockInfoDetailService.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_IStockService/IStockInfoDetailService.cs"
@@ -14,5 +14,6 @@
         bool ExistBarcodes(List<string> barcodes);
 
         PageGridData<StockInfoDetailWithPalletDto> GetPageData2(PageDataOptions options);
+
     }
 }
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_InboundService/InboundOrderService.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_InboundService/InboundOrderService.cs"
index 2dd5af5..51e758d 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_InboundService/InboundOrderService.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_InboundService/InboundOrderService.cs"
@@ -652,7 +652,7 @@
             {
                 return WebResponseContent.Instance.Error("鎵樼洏鍙蜂笉鑳戒负绌�");
             }
-            var stock = _stockRepository.Db.Queryable<Dt_StockInfo>().Includes(o => o.Details).First(x => x.PalletCode == palletCode && x.StockStatus == (int)StockStatusEmun.缁勭洏鏆傚瓨);
+            var stock = _stockRepository.Db.Queryable<Dt_StockInfo>().Includes(o => o.Details).First(x => x.PalletCode == palletCode && (x.StockStatus == (int)StockStatusEmun.缁勭洏鏆傚瓨|| x.StockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt()));
             if (stock == null)
             {
                 return WebResponseContent.Instance.Error($"鏈壘鍒版墭鐩樺彿{palletCode}瀵瑰簲鐨勫簱瀛樿褰�");
@@ -705,7 +705,7 @@
                 };
                 orderByModels.Add(orderByModel);
             }
-
+            ISugarQueryable<Dt_InboundOrder> sugarQueryable1 = BaseDal.Db.Queryable<Dt_InboundOrder>();
 
             int totalCount = 0;
             List<SearchParameters> searchParametersList = new List<SearchParameters>();
@@ -714,16 +714,68 @@
                 try
                 {
                     searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
+                    if (searchParametersList.Count > 0)
+                    {
+
+                        SearchParameters? searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_InboundOrder.InboundOrderNo).FirstLetterToLower());
+                        if (searchParameters != null)
+                        {
+                            sugarQueryable1 = sugarQueryable1.Where(x => x.InboundOrderNo.Contains(searchParameters.Value.ToString())
+                            || x.UpperOrderNo.Contains(searchParameters.Value.ToString()) ||
+                            x.Details.Any(d => d.Barcode == searchParameters.Value.ToString()));
+                        }
+                        searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_InboundOrder.OrderType).FirstLetterToLower());
+                        if (searchParameters != null)
+                        {
+                            sugarQueryable1 = sugarQueryable1.Where(x => x.OrderType.Equals(searchParameters.Value.ToString()));
+                        }
+                        //var dataList = sugarQueryable1.ToPageList(options.Page, options.Rows, ref totalCount);
+                        //return new PageGridData<Dt_InboundOrder>(totalCount, dataList);
+                    }
                     options.Filter = searchParametersList;
                 }
                 catch { }
             }
-            var data = BaseDal.Db.Queryable<Dt_InboundOrder>()
+            var data = sugarQueryable1
                 .WhereIF(!wheres.IsNullOrEmpty(), wheres)
-                .OrderBy(orderByModels).Includes(x=>x.Details)
+                .Where(x => x.OrderType == 0)
+                .OrderBy(orderByModels).Includes(x => x.Details)
                 .ToPageList(options.Page, options.Rows, ref totalCount);
 
             return new PageGridData<Dt_InboundOrder>(totalCount, data);
         }
+
+        //public override PageGridData<Dt_InboundOrder> GetPageData(PageDataOptions options)
+        //{
+        //    //var  pageGridData = base.GetPageData(options);
+
+        //    ISugarQueryable<Dt_InboundOrder> sugarQueryable1 = BaseDal.Db.Queryable<Dt_InboundOrder>();
+        //    if (!string.IsNullOrEmpty(options.Wheres))
+        //    {
+
+        //        List<SearchParameters> searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
+        //        int totalCount = 0;
+        //        if (searchParametersList.Count > 0)
+        //        {
+
+        //            SearchParameters? searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_InboundOrder.InboundOrderNo).FirstLetterToLower());
+        //            if (searchParameters != null)
+        //            {
+        //                sugarQueryable1 = sugarQueryable1.Where(x => x.InboundOrderNo.Contains(searchParameters.Value.ToString())
+        //                || x.UpperOrderNo.Contains(searchParameters.Value.ToString()) ||
+        //                x.Details.Any(d => d.Barcode == searchParameters.Value.ToString()));
+        //            }
+        //            searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_InboundOrder.OrderType).FirstLetterToLower());
+        //            if (searchParameters != null)
+        //            {
+        //                sugarQueryable1 = sugarQueryable1.Where(x => x.OrderType.Equals(searchParameters.Value.ToString()));
+        //            }
+        //            var dataList = sugarQueryable1.ToPageList(options.Page, options.Rows, ref totalCount);
+        //            return new PageGridData<Dt_InboundOrder>(totalCount, dataList);
+        //        }
+        //    }
+        //    return new PageGridData<Dt_InboundOrder>();
+        //}
+
     }
 }
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_Model/Models/Stock/StockDetailByMateriel.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_Model/Models/Stock/StockDetailByMateriel.cs"
new file mode 100644
index 0000000..0ce5391
--- /dev/null
+++ "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_Model/Models/Stock/StockDetailByMateriel.cs"
@@ -0,0 +1,81 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WIDESEA_Model.Models
+{
+    public class StockDetailByMateriel
+    {
+        public int Id { get; set; }
+
+
+        public int StockId { get; set; }
+
+
+        public string MaterielCode { get; set; }
+
+
+        public string MaterielName { get; set; }
+
+
+        public string OrderNo { get; set; }
+
+
+        public string BatchNo { get; set; }
+
+
+        public string ProductionDate { get; set; }
+
+
+        public string EffectiveDate { get; set; }
+
+
+        public string SerialNumber { get; set; }
+
+
+        public decimal StockQuantity { get; set; }
+
+
+        public decimal OutboundQuantity { get; set; }
+
+
+        public int Status { get; set; }
+
+
+        public string Unit { get; set; }
+
+        public string InboundOrderRowNo { get; set; }
+
+
+        public string? SupplyCode { get; set; }
+
+        public string FactoryArea { get; set; }
+
+        public string? WarehouseCode { get; set; }
+
+
+        public string? Barcode { get; set; }
+
+
+
+        public string? BusinessType { get; set; }
+
+
+        public decimal BarcodeQty { get; set; }
+
+        public string BarcodeUnit { get; set; }
+
+        public DateTime? ValidDate { get; set; }
+
+        public string Remark { get; set; }
+
+        public string Creater { get; set; }
+
+        public DateTime? CreateDate { get; set; }
+        public string Modifier { get; set; }
+        public DateTime? ModifyDate { 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_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 c0e37a5..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,27 +249,48 @@
 
         #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)
+                {
+                    _unitOfWorkManage.RollbackTran();
                     return WebResponseContent.Instance.Error(validationResult.ErrorMessage);
+                }
 
                 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)
                     {
@@ -278,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)
@@ -321,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>
@@ -371,12 +662,13 @@
         #region 鍙栬蛋绌虹閫昏緫
 
 
-
         /// <summary>
-        /// 楠岃瘉绌虹鍙栬蛋鏉′欢
+        /// 楠岃瘉绌虹鍙栬蛋鏉′欢 
         /// </summary>
         private async Task<ValidationResult<List<Dt_OutStockLockInfo>>> ValidateEmptyPalletRemoval(string orderNo, string palletCode)
         {
+            _logger.LogInformation($"寮�濮嬮獙璇佺┖鎵樼洏鍙栬蛋 - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}");
+
             // 鑾峰彇鎵樼洏鐨勬墍鏈夐攣瀹氳褰�
             var lockInfos = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
                 .Where(x => x.OrderNo == orderNo && x.PalletCode == palletCode)
@@ -385,7 +677,33 @@
             if (!lockInfos.Any())
                 return ValidationResult<List<Dt_OutStockLockInfo>>.Error("璇ユ墭鐩樻病鏈夐攣瀹氳褰�");
 
-            // 妫�鏌ユ槸鍚︽湁鏈畬鎴愮殑閿佸畾璁板綍
+            // 鑾峰彇搴撳瓨淇℃伅
+            var stockInfo = await _stockInfoService.Db.Queryable<Dt_StockInfo>()
+                .FirstAsync(x => x.PalletCode == palletCode);
+
+            if (stockInfo == null)
+            {
+                _logger.LogWarning($"鏈壘鍒版墭鐩樼殑搴撳瓨淇℃伅锛屽彲鑳藉凡琚竻鐞�");
+                // 濡傛灉鎵句笉鍒板簱瀛樹俊鎭紝鍙鏌ラ攣瀹氳褰�
+            }
+            else
+            {
+                // 妫�鏌ユ墭鐩樹笂鏄惁杩樻湁搴撳瓨璐х墿
+                var remainingStock = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+                    .Where(x => x.StockId == stockInfo.Id &&
+                               x.StockQuantity > 0)  // 鍙鏌ユ暟閲忓ぇ浜�0鐨勫簱瀛�
+                    .ToListAsync();
+
+                if (remainingStock.Any())
+                {
+                    var remainingQty = remainingStock.Sum(x => x.StockQuantity);
+                    var barcodes = string.Join(", ", remainingStock.Select(x => x.Barcode).Take(5)); // 鍙樉绀哄墠5涓�
+                    return ValidationResult<List<Dt_OutStockLockInfo>>.Error(
+                        $"鎵樼洏涓婅繕鏈夊簱瀛樿揣鐗╋紝鏁伴噺{remainingQty}锛屾潯鐮�: {barcodes}锛屼笉鑳藉彇璧扮┖绠�");
+                }
+            }
+
+            // 妫�鏌ユ槸鍚︽湁鏈畬鎴愮殑閿佸畾璁板綍锛堢姸鎬佷负鍑哄簱涓垨鍥炲簱涓級
             var unfinishedLocks = lockInfos.Where(x =>
                 x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓� ||
                 x.Status == (int)OutLockStockStatusEnum.鍥炲簱涓�).ToList();
@@ -398,35 +716,19 @@
                     $"鎵樼洏杩樻湁{unfinishedCount}鏉℃湭瀹屾垚璁板綍锛屽墿浣欐暟閲弡unfinishedQty}锛屼笉鑳藉彇璧扮┖绠�");
             }
 
-            // 妫�鏌ユ墭鐩樹笂鏄惁杩樻湁搴撳瓨璐х墿
-            var stockInfo = await _stockInfoService.Db.Queryable<Dt_StockInfo>()
-                .FirstAsync(x => x.PalletCode == palletCode);
-
-            if (stockInfo != null)
-            {
-                var remainingStock = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
-                    .Where(x => x.StockId == stockInfo.Id &&
-                               x.Status == (int)StockStatusEmun.鍑哄簱閿佸畾 &&
-                               x.StockQuantity > 0)
-                    .ToListAsync();
-
-                if (remainingStock.Any())
-                {
-                    var remainingQty = remainingStock.Sum(x => x.StockQuantity);
-                    return ValidationResult<List<Dt_OutStockLockInfo>>.Error(
-                        $"鎵樼洏涓婅繕鏈夊簱瀛樿揣鐗╋紝鏁伴噺{remainingQty}锛屼笉鑳藉彇璧扮┖绠�");
-                }
-            }
-
-            // 鑾峰彇宸插畬鎴愮殑閿佸畾璁板綍
+            // 鑾峰彇宸插畬鎴愮殑閿佸畾璁板綍锛堢姸鎬佷负鎷i�夊畬鎴愭垨宸插彇璧帮級
             var completedLocks = lockInfos.Where(x =>
-                x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�).ToList();
+                x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴� ||
+                x.Status == (int)OutLockStockStatusEnum.宸插彇璧�).ToList();
 
             if (!completedLocks.Any())
                 return ValidationResult<List<Dt_OutStockLockInfo>>.Error("璇ユ墭鐩樻病鏈夊凡瀹屾垚鎷i�夌殑璁板綍");
 
+            _logger.LogInformation($"绌烘墭鐩橀獙璇侀�氳繃 - 鎵惧埌 {completedLocks.Count} 鏉″凡瀹屾垚璁板綍");
+
             return ValidationResult<List<Dt_OutStockLockInfo>>.Success(completedLocks);
         }
+
 
         /// <summary>
         /// 娓呯悊宸插畬鎴愮殑閿佸畾璁板綍
@@ -445,21 +747,86 @@
             }
         }
 
+
         /// <summary>
-        /// 娓呯悊搴撳瓨淇℃伅
+        /// 娓呯悊搴撳瓨淇℃伅 - 瀹屾暣淇鐗�
+        /// 纭繚OutboundQuantity姝g‘娓呴浂
         /// </summary>
         private async Task CleanupStockInfo(Dt_OutStockLockInfo lockInfo)
         {
-            var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
-                .FirstAsync(x => x.Barcode == lockInfo.CurrentBarcode && x.StockId == lockInfo.StockId);
-
-            if (stockDetail != null && stockDetail.Status == (int)StockStatusEmun.鍑哄簱瀹屾垚)
+            try
             {
-                stockDetail.Status = (int)StockStatusEmun.宸叉竻鐞�;
-                await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
+                _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);
+
+                if (stockDetail != null)
+                {
+                    // 璁板綍娓呯悊鍓嶇殑鐘舵��
+                    decimal originalStockQty = stockDetail.StockQuantity;
+                    decimal originalOutboundQty = stockDetail.OutboundQuantity;
+                    int originalStatus = stockDetail.Status;
+
+                    _logger.LogInformation($"娓呯悊鍓嶇姸鎬� - 搴撳瓨: {originalStockQty}, 鍑哄簱: {originalOutboundQty}, 鐘舵��: {GetStockStatusName(originalStatus)}");
+
+                    // 銆愰噸瑕併�戞鏌ュ簱瀛樻暟閲忔槸鍚﹀簲璇ヤ负0
+                    // 濡傛灉閿佸畾鐘舵�佹槸鎷i�夊畬鎴愶紝鐞嗚涓婂簱瀛樺簲璇ヤ负0
+                    if (lockInfo.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�)
+                    {
+                        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($"娓呯悊搴撳瓨鏄庣粏瀹屾垚");
+                    _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;  // 銆愪慨姝c�戠‘淇濆嚭搴撴暟閲忔竻闆�
+                        stock.Status = (int)StockStatusEmun.宸叉竻鐞�;
+
+                        await _stockInfoDetailService.Db.Updateable(stock).ExecuteCommandAsync();
+                        _logger.LogInformation($"娓呯悊閬楁紡搴撳瓨 - 鏉$爜: {stock.Barcode}, 搴撳瓨: {originalQty}->0, 鍑哄簱: {originalOutbound}->0");
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError($"娓呯悊搴撳瓨淇℃伅澶辫触 - 閿佸畾ID: {lockInfo.Id}, 鏉$爜: {lockInfo.CurrentBarcode}, Error: {ex.Message}");
+                // 涓嶆姏鍑哄紓甯革紝缁х画澶勭悊鍏朵粬璁板綍
             }
         }
-
 
         /// <summary>
         /// 鏇存柊璁㈠崟鐘舵��
@@ -495,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
@@ -536,7 +903,6 @@
             }
         };
         }
-
 
 
         #region 鎵嬪姩鎷嗗寘   
@@ -676,101 +1042,199 @@
             return lockInfos.Sum(x => x.AssignQuantity);
         }
 
+
+
         /// <summary>
-        /// 鎵ц鎵嬪姩鎷嗗寘閫昏緫 - 澧炲己鍒嗛厤鏁伴噺鎺у埗
+        /// 鎵ц鎵嬪姩鎷嗗寘閫昏緫 - 淇鐗堟湰
         /// </summary>
         private async Task<List<SplitResult>> ExecuteManualSplitLogic(Dt_OutStockLockInfo lockInfo, Dt_StockInfoDetail stockDetail,
             decimal splitQuantity, string palletCode)
         {
             _logger.LogInformation($"寮�濮嬫墽琛屾墜鍔ㄦ媶鍖呴�昏緫 - 鍘熸潯鐮�: {stockDetail.Barcode}, 鎷嗗寘鏁伴噺: {splitQuantity}");
 
-            // 楠岃瘉鎷嗗寘鏁伴噺
-            if (lockInfo.AssignQuantity < splitQuantity)
+            try
             {
-                throw new InvalidOperationException($"鎷嗗寘鏁伴噺瓒呰繃閿佸畾淇℃伅鍒嗛厤鏁伴噺锛屾媶鍖呮暟閲�: {splitQuantity}, 鍒嗛厤鏁伴噺: {lockInfo.AssignQuantity}");
+                // 楠岃瘉搴撳瓨鏁伴噺鏄惁瓒冲
+                decimal availableStock = stockDetail.StockQuantity;
+                if (availableStock < splitQuantity)
+                {
+                    throw new InvalidOperationException($"搴撳瓨涓嶈冻锛屽綋鍓嶅簱瀛�: {availableStock}, 闇�瑕佹媶鍖�: {splitQuantity}");
+                }
+
+                // 楠岃瘉鎷嗗寘鏁伴噺涓嶈兘绛変簬鎴栧ぇ浜庡師閿佸畾淇℃伅鍒嗛厤鏁伴噺
+                if (splitQuantity >= lockInfo.AssignQuantity)
+                {
+                    throw new InvalidOperationException($"鎷嗗寘鏁伴噺涓嶈兘绛変簬鎴栧ぇ浜庡師閿佸畾淇℃伅鍒嗛厤鏁伴噺锛屾媶鍖呮暟閲�: {splitQuantity}, 鍘熷垎閰嶆暟閲�: {lockInfo.AssignQuantity}");
+                }
+
+                // 璁$畻鍓╀綑鏁伴噺
+                decimal remainQty = lockInfo.AssignQuantity - splitQuantity;
+
+                // 楠岃瘉鍓╀綑鏁伴噺鏄惁鍚堢悊
+                if (remainQty <= 0)
+                {
+                    throw new InvalidOperationException($"鎷嗗寘鍚庡墿浣欐暟閲忓繀椤诲ぇ浜�0锛屽綋鍓嶅墿浣�: {remainQty}");
+                }
+
+                _logger.LogInformation($"鎷嗗寘璁$畻 - 鍘熷垎閰嶆暟閲�: {lockInfo.AssignQuantity}, 鎷嗗寘鏁伴噺: {splitQuantity}, 鍓╀綑鏁伴噺: {remainQty}");
+                _logger.LogInformation($"鍘熷簱瀛樹俊鎭� - 搴撳瓨鏁伴噺: {stockDetail.StockQuantity}, 鍑哄簱鏁伴噺: {stockDetail.OutboundQuantity}");
+
+                // 鐢熸垚鏂版潯鐮�
+                string newBarcode = await GenerateNewBarcode();
+                _logger.LogInformation($"鐢熸垚鏂版潯鐮�: {newBarcode}");
+
+                // 璁板綍鎷嗗寘鍓嶇殑鍏抽敭鏁版嵁
+                decimal originalLockAssignQty = lockInfo.AssignQuantity;
+                decimal originalLockOrderQty = lockInfo.OrderQuantity;
+                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 = newStockQuantity,  // 淇锛氫娇鐢ㄦ纭殑鎷嗗寘鏁伴噺
+                    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}, 搴撳瓨鏁伴噺: {newStockQuantity}");
+
+                // 淇锛氭洿鏂板師搴撳瓨鏄庣粏 - 纭繚鏁版嵁涓�鑷存��
+                stockDetail.StockQuantity = originalRemainingStockQuantity;
+
+                // 纭繚涓嶄細涓鸿礋鏁�
+                if (stockDetail.StockQuantity < 0)
+                {
+                    _logger.LogWarning($"鍘熷簱瀛樻暟閲忓嚭鐜拌礋鏁帮紝閲嶇疆涓�0");
+                    stockDetail.StockQuantity = 0;
+                }
+
+                // 鍑哄簱鏁伴噺淇濇寔涓嶅彉锛屽洜涓烘槸鎷嗗寘锛屼笉鏄疄闄呭嚭搴�
+                // stockDetail.OutboundQuantity = stockDetail.OutboundQuantity;
+
+                await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
+                _logger.LogInformation($"鏇存柊鍘熷簱瀛樻槑缁� - 鏉$爜: {stockDetail.Barcode}, " +
+                                     $"搴撳瓨鏁伴噺: {originalStockQty} -> {stockDetail.StockQuantity}, " +
+                                     $"鍑哄簱鏁伴噺: {originalOutboundQty} -> {stockDetail.OutboundQuantity}");
+
+                // 鍒涘缓鏂伴攣瀹氫俊鎭�
+                var newLockInfo = new Dt_OutStockLockInfo
+                {
+                    OrderNo = lockInfo.OrderNo,
+                    OrderDetailId = lockInfo.OrderDetailId,
+                    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,
+                };
+
+                await _outStockLockInfoService.Db.Insertable(newLockInfo).ExecuteCommandAsync();
+                _logger.LogInformation($"鍒涘缓鏂伴攣瀹氫俊鎭垚鍔� - 鏉$爜: {newBarcode}, 鍒嗛厤鏁伴噺: {splitQuantity}");
+
+                // 鏇存柊鍘熼攣瀹氫俊鎭�
+                lockInfo.AssignQuantity = remainQty;
+                lockInfo.OrderQuantity = remainQty;
+
+                await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
+                _logger.LogInformation($"鏇存柊鍘熼攣瀹氫俊鎭� - 鍒嗛厤鏁伴噺: {originalLockAssignQty} -> {lockInfo.AssignQuantity}, " +
+                                     $"璁㈠崟鏁伴噺: {originalLockOrderQty} -> {lockInfo.OrderQuantity}");
+
+                // 楠岃瘉鎷嗗寘鍚庢暟鎹竴鑷存��
+                await ValidateDataConsistencyAfterSplit(lockInfo.OrderDetailId, originalLockAssignQty, originalLockOrderQty);
+
+                // 璁板綍鎷嗗寘鍘嗗彶
+                await RecordSplitHistory(lockInfo, stockDetail, splitQuantity, newBarcode, false, originalStockQty);
+
+                // 鍒涘缓鎷嗗寘缁撴灉鍒楄〃
+                var splitResults = CreateSplitResults(lockInfo, splitQuantity, remainQty, newBarcode, stockDetail.Barcode);
+
+                _logger.LogInformation($"鎵嬪姩鎷嗗寘閫昏緫鎵ц瀹屾垚 - 鍘熸潯鐮�: {stockDetail.Barcode}, 鏂版潯鐮�: {newBarcode}, 鎷嗗寘鏁伴噺: {splitQuantity}");
+
+                return splitResults;
             }
-
-            // 鐢熸垚鏂版潯鐮�
-            string newBarcode = await GenerateNewBarcode();
-
-            // 璁$畻鍓╀綑鏁伴噺
-            decimal remainQty = lockInfo.AssignQuantity - splitQuantity;
-
-            // 鍒涘缓鏂板簱瀛樻槑缁�
-            var newStockDetail = new Dt_StockInfoDetail
+            catch (Exception ex)
             {
-                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.LogError($"鎵嬪姩鎷嗗寘閫昏緫鎵ц澶辫触 - 鍘熸潯鐮�: {stockDetail.Barcode}, 鎷嗗寘鏁伴噺: {splitQuantity}, Error: {ex.Message}");
+                throw;
+            }
+        }
 
-            // 鏇存柊鍘熷簱瀛樻槑缁�
-            stockDetail.StockQuantity -= splitQuantity;
-            if (stockDetail.StockQuantity < 0) stockDetail.StockQuantity = 0;
-            await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
-
-            // 鍒涘缓鏂伴攣瀹氫俊鎭�
-            var newLockInfo = new Dt_OutStockLockInfo
+        /// <summary>
+        /// 楠岃瘉鎷嗗寘鍚庤鍗曟槑缁嗙殑鍒嗛厤鏁伴噺鏄惁淇濇寔涓嶅彉
+        /// </summary>
+        private async Task ValidateOrderDetailAllocationAfterSplit(long orderDetailId, decimal originalTotalAssignQty)
+        {
+            try
             {
-                OrderNo = lockInfo.OrderNo,
-                OrderDetailId = lockInfo.OrderDetailId, // 缁戝畾鍒板悓涓�涓鍗曟槑缁�
-                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,
-            };
+                // 鑾峰彇璁㈠崟鏄庣粏鐨勬墍鏈夐攣瀹氫俊鎭殑鎬诲垎閰嶆暟閲�
+                var allLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+                    .Where(x => x.OrderDetailId == orderDetailId)
+                    .ToListAsync();
 
-            await _outStockLockInfoService.Db.Insertable(newLockInfo).ExecuteCommandAsync();
+                decimal totalLockAssignQty = allLocks.Sum(x => x.AssignQuantity);
 
-            // 鏇存柊鍘熼攣瀹氫俊鎭�
-            lockInfo.AssignQuantity = remainQty;
-            lockInfo.OrderQuantity = remainQty;
-            await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
+                _logger.LogInformation($"鎷嗗寘鍚庡垎閰嶆暟閲忛獙璇� - 璁㈠崟鏄庣粏ID: {orderDetailId}");
+                _logger.LogInformation($"鍘熷鎬诲垎閰嶆暟閲�: {originalTotalAssignQty}, 褰撳墠鎬诲垎閰嶆暟閲�: {totalLockAssignQty}");
 
-            // 閲嶈锛氭墜鍔ㄦ媶鍖呬笉鏀瑰彉璁㈠崟鏄庣粏鐨勬�诲垎閰嶆暟閲�
-            // 鍥犱负鍒嗛厤鏁伴噺鍙槸浠庝竴涓攣瀹氫俊鎭浆绉诲埌鍙︿竴涓攣瀹氫俊鎭�
-            _logger.LogInformation($"鎵嬪姩鎷嗗寘 - 璁㈠崟鏄庣粏鎬诲垎閰嶆暟閲忎繚鎸佷笉鍙�");
+                // 鎵嬪姩鎷嗗寘鍚庢�诲垎閰嶆暟閲忓簲璇ヤ繚鎸佷笉鍙�
+                if (Math.Abs(originalTotalAssignQty - totalLockAssignQty) > 0.01m)
+                {
+                    _logger.LogWarning($"鎷嗗寘鍚庢�诲垎閰嶆暟閲忓彂鐢熷彉鍖� - 鏈熸湜: {originalTotalAssignQty}, 瀹為檯: {totalLockAssignQty}");
 
-            // 璁板綍鎷嗗寘鍘嗗彶
-            await RecordSplitHistory(lockInfo, stockDetail, splitQuantity, newBarcode, false);
-
-            // 鍒涘缓鎷嗗寘缁撴灉鍒楄〃
-            var splitResults = CreateSplitResults(lockInfo, splitQuantity, remainQty, newBarcode, stockDetail.Barcode);
-
-            _logger.LogInformation($"鎵嬪姩鎷嗗寘閫昏緫鎵ц瀹屾垚");
-
-            return splitResults;
+                    // 濡傛灉鍙樺寲寰堝皬锛屽彲鑳芥槸绮惧害闂锛岃褰曚絾涓嶆姏鍑哄紓甯�
+                    if (Math.Abs(originalTotalAssignQty - totalLockAssignQty) > 1.0m)
+                    {
+                        throw new InvalidOperationException($"鎷嗗寘鍚庢�诲垎閰嶆暟閲忓紓甯稿彉鍖栵紝鏈熸湜: {originalTotalAssignQty}, 瀹為檯: {totalLockAssignQty}");
+                    }
+                }
+                else
+                {
+                    _logger.LogInformation($"鎷嗗寘鍚庡垎閰嶆暟閲忛獙璇侀�氳繃 - 鎬诲垎閰嶆暟閲忎繚鎸佷笉鍙�");
+                }
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError($"楠岃瘉鎷嗗寘鍚庡垎閰嶆暟閲忓け璐� - OrderDetailId: {orderDetailId}, Error: {ex.Message}");
+                throw;
+            }
         }
         /// <summary>
         /// 楠岃瘉鎷嗗寘鍚庢暟鎹竴鑷存��
@@ -811,8 +1275,6 @@
             }
         }
         #endregion
-
-
 
         #region 鍙栨秷鎷嗗寘 
 
@@ -870,6 +1332,45 @@
         {
             _logger.LogInformation($"寮�濮嬫墽琛屽彇娑堟媶鍖呴�昏緫 - 鍘熸潯鐮�: {splitRecord.OriginalBarcode}, 鏂版潯鐮�: {splitRecord.NewBarcode}, 鎷嗗寘鏁伴噺: {splitRecord.SplitQty}");
 
+            try
+            {
+                // 鏍规嵁鎷嗗寘绫诲瀷璋冪敤涓嶅悓鐨勫鐞嗘柟娉�
+                if (splitRecord.IsAutoSplit)
+                {
+                    await HandleAutoSplitCancel(splitRecord, originalLockInfo, newLockInfo, newStockDetail);
+                }
+                else
+                {
+                    await HandleManualSplitCancel(splitRecord, originalLockInfo, newLockInfo, newStockDetail);
+                }
+
+                // 楠岃瘉鍙栨秷鎷嗗寘鍚庢暟鎹竴鑷存��
+                await ValidateDataConsistencyAfterCancelSplit(originalLockInfo.OrderDetailId,
+                    originalLockInfo.AssignQuantity, originalLockInfo.OrderQuantity,
+                    splitRecord.IsAutoSplit, splitRecord.SplitQty);
+
+                // 妫�鏌ュ苟鏇存柊鎵规鍜岃鍗曠姸鎬�
+                await CheckAndUpdateBatchStatus(originalLockInfo.BatchNo);
+                await CheckAndUpdateOrderStatus(originalLockInfo.OrderNo);
+
+                _logger.LogInformation($"鍙栨秷鎷嗗寘閫昏緫鎵ц瀹屾垚");
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError($"鍙栨秷鎷嗗寘閫昏緫鎵ц澶辫触: {ex.Message}");
+                throw;
+            }
+        }
+
+        /// <summary>
+        /// 澶勭悊鑷姩鎷嗗寘鍙栨秷
+        /// </summary>
+        private async Task HandleAutoSplitCancel(Dt_SplitPackageRecord splitRecord,
+            Dt_OutStockLockInfo originalLockInfo, Dt_OutStockLockInfo newLockInfo,
+            Dt_StockInfoDetail newStockDetail)
+        {
+            _logger.LogInformation($"澶勭悊鑷姩鎷嗗寘鍙栨秷 - 鍘熸潯鐮�: {splitRecord.OriginalBarcode}, 鏂版潯鐮�: {splitRecord.NewBarcode}");
+
             // 鑾峰彇璁㈠崟鏄庣粏
             var orderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
                 .FirstAsync(x => x.Id == originalLockInfo.OrderDetailId);
@@ -877,124 +1378,113 @@
             if (orderDetail == null)
                 throw new InvalidOperationException("鏈壘鍒拌鍗曟槑缁�");
 
-            // 璁板綍鍙栨秷鎷嗗寘鍓嶇殑鍏抽敭鏁版嵁
-            decimal originalOrderDetailAllocatedQty = orderDetail.AllocatedQuantity;
-            decimal originalOrderDetailLockQty = orderDetail.LockQuantity;
+            // 1. 鎭㈠璁㈠崟鏄庣粏鐨勫垎閰嶆暟閲忥紙鑷姩鎷嗗寘浼氬鍔犲垎閰嶆暟閲忥級
+            decimal originalAllocatedQty = orderDetail.AllocatedQuantity;
+            decimal originalLockQty = orderDetail.LockQuantity;
 
-            _logger.LogInformation($"鍙栨秷鎷嗗寘鍓嶆暟鎹� - 璁㈠崟鏄庣粏鍒嗛厤鏁伴噺: {originalOrderDetailAllocatedQty}, 閿佸畾鏁伴噺: {originalOrderDetailLockQty}");
+            orderDetail.AllocatedQuantity -= splitRecord.SplitQty;
+            orderDetail.LockQuantity -= splitRecord.SplitQty;
 
-            // 鎭㈠鍘熼攣瀹氫俊鎭�
-            decimal originalAssignQtyBefore = originalLockInfo.AssignQuantity;
-            decimal originalOrderQtyBefore = originalLockInfo.OrderQuantity;
+            // 杈圭晫妫�鏌�
+            if (orderDetail.AllocatedQuantity < 0) orderDetail.AllocatedQuantity = 0;
+            if (orderDetail.LockQuantity < 0) orderDetail.LockQuantity = 0;
 
-            // 鏍规嵁鎷嗗寘绫诲瀷鍐冲畾濡備綍鎭㈠
-            if (splitRecord.IsAutoSplit)
-            {
-                // 鑷姩鎷嗗寘锛氬師閿佸畾淇℃伅淇濇寔涓嶅彉锛屽彧闇�瑕佸垹闄ゆ柊閿佸畾淇℃伅
-                _logger.LogInformation($"鍙栨秷鑷姩鎷嗗寘 - 鍘熼攣瀹氫俊鎭繚鎸佷笉鍙�");
-            }
-            else
-            {
-                // 鎵嬪姩鎷嗗寘锛氭仮澶嶅師閿佸畾淇℃伅鐨勫垎閰嶆暟閲�
-                originalLockInfo.AssignQuantity += splitRecord.SplitQty;
-                originalLockInfo.OrderQuantity += splitRecord.SplitQty;
+            await _outboundOrderDetailService.Db.Updateable(orderDetail).ExecuteCommandAsync();
+            _logger.LogInformation($"鑷姩鎷嗗寘鍙栨秷鎭㈠璁㈠崟鏄庣粏 - 鍒嗛厤鏁伴噺: {originalAllocatedQty} -> {orderDetail.AllocatedQuantity}");
 
-                _logger.LogInformation($"鍙栨秷鎵嬪姩鎷嗗寘 - 鎭㈠鍘熼攣瀹氫俊鎭垎閰嶆暟閲忎粠 {originalAssignQtyBefore} 澧炲姞鍒� {originalLockInfo.AssignQuantity}");
-            }
-
-            // 濡傛灉鍘熼攣瀹氫俊鎭殑鐘舵�佹槸鎷i�夊畬鎴愶紝闇�瑕侀噸鏂拌缃负鍑哄簱涓�
-            if (originalLockInfo.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�)
-            {
-                originalLockInfo.Status = (int)OutLockStockStatusEnum.鍑哄簱涓�;
-                _logger.LogInformation($"鍘熼攣瀹氫俊鎭姸鎬佷粠鎷i�夊畬鎴愭仮澶嶄负鍑哄簱涓�");
-            }
-
-            await _outStockLockInfoService.Db.Updateable(originalLockInfo).ExecuteCommandAsync();
-
-            // 鎭㈠鍘熷簱瀛樻槑缁�
+            // 2. 鎭㈠鍘熷簱瀛橈紙灏嗘媶鍖呯殑鏁伴噺鍔犲洖鍘熷簱瀛橈級
             var originalStock = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
                 .FirstAsync(x => x.Barcode == splitRecord.OriginalBarcode && x.StockId == splitRecord.StockId);
 
             if (originalStock != null)
             {
-                if (splitRecord.IsAutoSplit)
+                decimal originalStockQty = originalStock.StockQuantity;
+                originalStock.StockQuantity += splitRecord.SplitQty;
+
+                // 濡傛灉鍘熷簱瀛樼姸鎬佹槸鍑哄簱瀹屾垚锛屾仮澶嶄负鍑哄簱閿佸畾
+                if (originalStock.Status == (int)StockStatusEmun.鍑哄簱瀹屾垚)
                 {
-                    // 鑷姩鎷嗗寘锛氬師搴撳瓨鏄庣粏淇濇寔涓嶅彉
-                    _logger.LogInformation($"鍙栨秷鑷姩鎷嗗寘 - 鍘熷簱瀛樻槑缁嗕繚鎸佷笉鍙�");
+                    originalStock.Status = (int)StockStatusEmun.鍑哄簱閿佸畾;
                 }
-                else
-                {
-                    // 鎵嬪姩鎷嗗寘锛氭仮澶嶅師搴撳瓨鏁伴噺
-                    decimal originalStockQtyBefore = originalStock.StockQuantity;
-                    originalStock.StockQuantity += splitRecord.SplitQty;
 
-                    _logger.LogInformation($"鍙栨秷鎵嬪姩鎷嗗寘 - 鎭㈠鍘熷簱瀛樻槑缁嗘暟閲忎粠 {originalStockQtyBefore} 澧炲姞鍒� {originalStock.StockQuantity}");
-
-                    // 濡傛灉鍘熷簱瀛樼姸鎬佹槸鍑哄簱瀹屾垚锛岄渶瑕侀噸鏂拌缃负鍑哄簱閿佸畾
-                    if (originalStock.Status == (int)StockStatusEmun.鍑哄簱瀹屾垚)
-                    {
-                        originalStock.Status = (int)StockStatusEmun.鍑哄簱閿佸畾;
-                        _logger.LogInformation($"鍘熷簱瀛樼姸鎬佷粠鍑哄簱瀹屾垚鎭㈠涓哄嚭搴撻攣瀹�");
-                    }
-
-                    await _stockInfoDetailService.Db.Updateable(originalStock).ExecuteCommandAsync();
-                }
+                await _stockInfoDetailService.Db.Updateable(originalStock).ExecuteCommandAsync();
+                _logger.LogInformation($"鑷姩鎷嗗寘鍙栨秷鎭㈠鍘熷簱瀛� - 鏉$爜: {originalStock.Barcode}, 鏁伴噺: {originalStockQty} -> {originalStock.StockQuantity}");
             }
 
+            // 3. 鍒犻櫎鏂伴攣瀹氫俊鎭拰搴撳瓨鏄庣粏
+            await DeleteNewSplitRecords(newLockInfo, newStockDetail);
+        }
+
+        /// <summary>
+        /// 澶勭悊鎵嬪姩鎷嗗寘鍙栨秷
+        /// </summary>
+        private async Task HandleManualSplitCancel(Dt_SplitPackageRecord splitRecord,
+            Dt_OutStockLockInfo originalLockInfo, Dt_OutStockLockInfo newLockInfo,
+            Dt_StockInfoDetail newStockDetail)
+        {
+            _logger.LogInformation($"澶勭悊鎵嬪姩鎷嗗寘鍙栨秷 - 鍘熸潯鐮�: {splitRecord.OriginalBarcode}, 鏂版潯鐮�: {splitRecord.NewBarcode}");
+
+            // 1. 鎭㈠鍘熼攣瀹氫俊鎭殑鍒嗛厤鏁伴噺
+            decimal originalAssignQty = originalLockInfo.AssignQuantity;
+            decimal originalOrderQty = originalLockInfo.OrderQuantity;
+
+            originalLockInfo.AssignQuantity += splitRecord.SplitQty;
+            originalLockInfo.OrderQuantity += splitRecord.SplitQty;
+
+            // 鎭㈠鐘舵��
+            if (originalLockInfo.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�)
+            {
+                originalLockInfo.Status = (int)OutLockStockStatusEnum.鍑哄簱涓�;
+            }
+
+            await _outStockLockInfoService.Db.Updateable(originalLockInfo).ExecuteCommandAsync();
+            _logger.LogInformation($"鎵嬪姩鎷嗗寘鍙栨秷鎭㈠鍘熼攣瀹氫俊鎭� - 鍒嗛厤鏁伴噺: {originalAssignQty} -> {originalLockInfo.AssignQuantity}");
+
+            // 2. 鎭㈠鍘熷簱瀛樻槑缁�
+            var originalStock = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+                .FirstAsync(x => x.Barcode == splitRecord.OriginalBarcode && x.StockId == splitRecord.StockId);
+
+            if (originalStock != null)
+            {
+                decimal originalStockQty = originalStock.StockQuantity;
+                originalStock.StockQuantity += splitRecord.SplitQty;
+
+                // 鎭㈠搴撳瓨鐘舵��
+                if (originalStock.Status == (int)StockStatusEmun.鍑哄簱瀹屾垚)
+                {
+                    originalStock.Status = (int)StockStatusEmun.鍑哄簱閿佸畾;
+                }
+
+                await _stockInfoDetailService.Db.Updateable(originalStock).ExecuteCommandAsync();
+                _logger.LogInformation($"鎵嬪姩鎷嗗寘鍙栨秷鎭㈠鍘熷簱瀛� - 鏉$爜: {originalStock.Barcode}, 鏁伴噺: {originalStockQty} -> {originalStock.StockQuantity}");
+            }
+
+            // 3. 鍒犻櫎鏂伴攣瀹氫俊鎭拰搴撳瓨鏄庣粏
+            await DeleteNewSplitRecords(newLockInfo, newStockDetail);
+        }
+
+        /// <summary>
+        /// 鍒犻櫎鏂版媶鍖呰褰曠浉鍏崇殑鏁版嵁
+        /// </summary>
+        private async Task DeleteNewSplitRecords(Dt_OutStockLockInfo newLockInfo, Dt_StockInfoDetail newStockDetail)
+        {
             // 鍒犻櫎鏂伴攣瀹氫俊鎭�
-            _logger.LogInformation($"鍒犻櫎鏂伴攣瀹氫俊鎭� - 鏉$爜: {newLockInfo.CurrentBarcode}, 鍒嗛厤鏁伴噺: {newLockInfo.AssignQuantity}");
-            await _outStockLockInfoService.Db.Deleteable<Dt_OutStockLockInfo>()
-                .Where(x => x.Id == newLockInfo.Id)
-                .ExecuteCommandAsync();
+            if (newLockInfo != null)
+            {
+                _logger.LogInformation($"鍒犻櫎鏂伴攣瀹氫俊鎭� - 鏉$爜: {newLockInfo.CurrentBarcode}, 鍒嗛厤鏁伴噺: {newLockInfo.AssignQuantity}");
+                await _outStockLockInfoService.Db.Deleteable<Dt_OutStockLockInfo>()
+                    .Where(x => x.Id == newLockInfo.Id)
+                    .ExecuteCommandAsync();
+            }
 
             // 鍒犻櫎鏂板簱瀛樻槑缁�
-            _logger.LogInformation($"鍒犻櫎鏂板簱瀛樻槑缁� - 鏉$爜: {newStockDetail.Barcode}, 搴撳瓨鏁伴噺: {newStockDetail.StockQuantity}");
-            await _stockInfoDetailService.Db.Deleteable<Dt_StockInfoDetail>()
-                .Where(x => x.Barcode == newLockInfo.CurrentBarcode)
-                .ExecuteCommandAsync();
-
-            // 濡傛灉鏄嚜鍔ㄦ媶鍖咃紝闇�瑕佸噺灏戣鍗曟槑缁嗙殑鍒嗛厤鏁伴噺鍜岄攣瀹氭暟閲�
-            if (splitRecord.IsAutoSplit)
+            if (newStockDetail != null)
             {
-                decimal originalAllocatedBefore = orderDetail.AllocatedQuantity;
-                decimal originalLockBefore = orderDetail.LockQuantity;
-
-                orderDetail.AllocatedQuantity -= splitRecord.SplitQty;
-                orderDetail.LockQuantity -= splitRecord.SplitQty;
-
-                // 杈圭晫妫�鏌ワ細纭繚鏁伴噺涓嶄細涓鸿礋鏁�
-                if (orderDetail.AllocatedQuantity < 0)
-                {
-                    _logger.LogWarning($"鍒嗛厤鏁伴噺鍑虹幇璐熸暟锛岄噸缃负0銆傚師鍊�: {orderDetail.AllocatedQuantity + splitRecord.SplitQty}, 鍑忓皯: {splitRecord.SplitQty}");
-                    orderDetail.AllocatedQuantity = 0;
-                }
-                if (orderDetail.LockQuantity < 0)
-                {
-                    _logger.LogWarning($"閿佸畾鏁伴噺鍑虹幇璐熸暟锛岄噸缃负0銆傚師鍊�: {orderDetail.LockQuantity + splitRecord.SplitQty}, 鍑忓皯: {splitRecord.SplitQty}");
-                    orderDetail.LockQuantity = 0;
-                }
-
-                await _outboundOrderDetailService.Db.Updateable(orderDetail).ExecuteCommandAsync();
-
-                _logger.LogInformation($"鍙栨秷鑷姩鎷嗗寘鍑忓皯璁㈠崟鏄庣粏鏁伴噺 - 鍒嗛厤鏁伴噺浠� {originalAllocatedBefore} 鍑忓皯鍒� {orderDetail.AllocatedQuantity}");
-                _logger.LogInformation($"鍙栨秷鑷姩鎷嗗寘鍑忓皯璁㈠崟鏄庣粏鏁伴噺 - 閿佸畾鏁伴噺浠� {originalLockBefore} 鍑忓皯鍒� {orderDetail.LockQuantity}");
+                _logger.LogInformation($"鍒犻櫎鏂板簱瀛樻槑缁� - 鏉$爜: {newStockDetail.Barcode}, 搴撳瓨鏁伴噺: {newStockDetail.StockQuantity}");
+                await _stockInfoDetailService.Db.Deleteable<Dt_StockInfoDetail>()
+                    .Where(x => x.Barcode == newStockDetail.Barcode)
+                    .ExecuteCommandAsync();
             }
-
-            // 鏍囪鎷嗗寘璁板綍涓哄凡鎾ら攢
-            splitRecord.IsReverted = true;
-            splitRecord.RevertTime = DateTime.Now;
-            splitRecord.RevertOperator = App.User.UserName;
-            await _splitPackageService.Db.Updateable(splitRecord).ExecuteCommandAsync();
-            _logger.LogInformation($"鏍囪鎷嗗寘璁板綍涓哄凡鎾ら攢");
-
-            // 楠岃瘉鍙栨秷鎷嗗寘鍚庢暟鎹竴鑷存��
-            await ValidateDataConsistencyAfterCancelSplit(orderDetail.Id, originalOrderDetailAllocatedQty, originalOrderDetailLockQty, splitRecord.IsAutoSplit, splitRecord.SplitQty);
-
-            // 妫�鏌ュ苟鏇存柊鎵规鍜岃鍗曠姸鎬�
-            await CheckAndUpdateBatchStatus(originalLockInfo.BatchNo);
-            await CheckAndUpdateOrderStatus(originalLockInfo.OrderNo);
-
-            _logger.LogInformation($"鍙栨秷鎷嗗寘閫昏緫鎵ц瀹屾垚");
         }
         /// <summary>
         /// 楠岃瘉鍙栨秷鎷嗗寘鍚庢暟鎹竴鑷存�� - 鏈�鏂扮増鏈�
@@ -1682,45 +2172,93 @@
 
             return totalQty;
         }
-
+             
         /// <summary>
-        /// 缁熶竴鍥炲簱鏂规硶 - 澶勭悊鎵樼洏涓婃墍鏈夊墿浣欒揣鐗�
+        /// 缁熶竴鍥炲簱鏂规硶
         /// </summary>
         public async Task<WebResponseContent> ExecutePalletReturn(string orderNo, string palletCode, string returnReason = "鍒嗘壒鍥炲簱")
         {
             try
             {
+                _logger.LogInformation($"銆愬寮哄洖搴撳紑濮嬨�戣鍗�: {orderNo}, 鎵樼洏: {palletCode}");
+
                 _unitOfWorkManage.BeginTran();
 
+                //  鍩虹楠岃瘉
                 if (string.IsNullOrEmpty(orderNo) || string.IsNullOrEmpty(palletCode))
                     return WebResponseContent.Instance.Error("璁㈠崟鍙峰拰鎵樼洏鐮佷笉鑳戒负绌�");
 
                 // 鑾峰彇搴撳瓨淇℃伅
                 var stockInfo = await _stockInfoService.Db.Queryable<Dt_StockInfo>()
                     .FirstAsync(x => x.PalletCode == palletCode);
+
                 if (stockInfo == null)
                     return WebResponseContent.Instance.Error($"鏈壘鍒版墭鐩� {palletCode} 瀵瑰簲鐨勫簱瀛樹俊鎭�");
+
+                int stockId = stockInfo.Id;
+
+                //  鎵ц鍥炲簱鍓嶆暟鎹獙璇�
+                var validationResult = await ValidateDataBeforeReturn(orderNo, palletCode, stockId);
+                if (!validationResult.IsValid)
+                {
+                    _logger.LogWarning($"鍥炲簱鍓嶆暟鎹獙璇佸け璐�: {validationResult.ErrorMessage}");
+                    // 鍙互鏍规嵁瀹為檯鎯呭喌鍐冲畾鏄惁缁х画
+                }
 
                 // 鍒嗘瀽鎵樼洏鐘舵��
                 var statusAnalysis = await AnalyzePalletStatusForReturn(orderNo, palletCode, stockInfo.Id);
 
                 if (!statusAnalysis.HasItemsToReturn)
-                    return await HandleEmptyPalletReturn(orderNo, palletCode, stockInfo);
+                {
+                    try
+                    {
+                        _logger.LogInformation($"銆愭棤鍥炲簱鐗╁搧銆戝鐞嗙┖鎵樼洏");
+                        var result = await HandleEmptyPalletReturn(orderNo, palletCode, stockInfo);
+                        _unitOfWorkManage.CommitTran();
+                        return result;
+                    }
+                    catch (Exception ex)
+                    {
+                        _unitOfWorkManage.RollbackTran();
+                        _logger.LogError($"绌虹鍥炲簱澶辫触: {ex.Message}");
+                        return WebResponseContent.Instance.Error($"绌虹鍥炲簱澶辫触锛歿ex.Message}");
+                    }
+                }
 
-                _logger.LogInformation($"寮�濮嬪洖搴撴搷浣� - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}, 鍥炲簱鏁伴噺: {statusAnalysis.TotalReturnQty}");
+                _logger.LogInformation($"銆愬紑濮嬪洖搴撱�戞�诲洖搴撴暟閲�: {statusAnalysis.TotalReturnQty}, 鏉$爜鏁�: {statusAnalysis.AllBarcodes.Count}");
 
-                // 鎵ц鍥炲簱鏁版嵁鎿嶄綔
-                await ExecuteReturnDataOperations(statusAnalysis);
+                //  鎵ц鍥炲簱鎿嶄綔
+                try
+                {
+                    await ExecuteEnhancedReturnOperations(statusAnalysis);
+                }
+                catch (Exception ex)
+                {
+                    _logger.LogError($"涓诲洖搴撴柟娉曞け璐�: {ex.Message}");
+                    // 灏濊瘯绠�鍖栨柟娉�
+                    await ExecuteSimpleReturnDataOperations(statusAnalysis);
+                }
 
-                // 鏇存柊璁㈠崟鐘舵��
+                //  鏇存柊璁㈠崟鐘舵��
                 await UpdateOrderStatusAfterReturn(orderNo);
 
+              
+
+                //  鍒涘缓鍥炲簱浠诲姟
+                try
+                {
+                    await CreateReturnTask(orderNo, palletCode, stockInfo);
+                }
+                catch (Exception taskEx)
+                {
+                    _logger.LogError($"鍥炲簱浠诲姟鍒涘缓澶辫触: {taskEx.Message}");
+                    // 浠诲姟鍒涘缓澶辫触涓嶅奖鍝嶆暟鎹洖搴�
+                }
                 _unitOfWorkManage.CommitTran();
+                // 8. 鍥炲簱鍚庨獙璇�
+                await ValidateDataAfterReturn(orderNo, palletCode, stockId);
 
-                // 鍒涘缓鍥炲簱浠诲姟锛圓GV锛�
-                await CreateReturnTask(orderNo, palletCode, stockInfo);
-
-                return WebResponseContent.Instance.OK($"鍥炲簱鎿嶄綔鎴愬姛锛屽叡鍥炲簱鏁伴噺锛歿statusAnalysis.TotalReturnQty}", new
+                return WebResponseContent.Instance.OK($"鍥炲簱鎴愬姛锛屽洖搴撴暟閲忥細{statusAnalysis.TotalReturnQty}", new
                 {
                     ReturnQuantity = statusAnalysis.TotalReturnQty,
                     ReturnBarcodes = statusAnalysis.AllBarcodes,
@@ -1732,13 +2270,910 @@
             catch (Exception ex)
             {
                 _unitOfWorkManage.RollbackTran();
-                _logger.LogError($"鍥炲簱鎿嶄綔澶辫触 - OrderNo: {orderNo}, PalletCode: {palletCode}, Error: {ex.Message}");
-                return WebResponseContent.Instance.Error($"鍥炲簱鎿嶄綔澶辫触: {ex.Message}");
+                _logger.LogError($"鍥炲簱澶辫触: {ex.Message}");
+                return WebResponseContent.Instance.Error($"鍥炲簱澶辫触锛歿ex.Message}");
+            }
+        }
+
+        /// <summary>
+        /// 澧炲己鐨勫洖搴撳墠鏁版嵁楠岃瘉
+        /// </summary>
+        private async Task<ValidationResult<bool>> ValidateDataBeforeReturn(string orderNo, string palletCode, int stockId)
+        {
+            var errors = new List<string>();
+
+            try
+            {
+                // 1. 楠岃瘉搴撳瓨鏁版嵁
+                var stockDetails = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+                    .Where(x => x.StockId == stockId)
+                    .ToListAsync();
+
+                // 妫�鏌ュ簱瀛樻暟閲忔槸鍚︿负璐熸暟
+                var negativeStocks = stockDetails.Where(x => x.StockQuantity < 0).ToList();
+                if (negativeStocks.Any())
+                {
+                    errors.Add($"鍙戠幇璐熸暟搴撳瓨: {string.Join(", ", negativeStocks.Select(x => $"{x.Barcode}:{x.StockQuantity}"))}");
+                }
+
+                // 2. 楠岃瘉閿佸畾璁板綍
+                var lockInfos = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+                    .Where(x => x.OrderNo == orderNo && x.PalletCode == palletCode)
+                    .ToListAsync();
+
+                // 妫�鏌ュ凡鎷i�夋暟閲忔槸鍚﹀ぇ浜庡垎閰嶆暟閲�
+                var invalidLocks = lockInfos.Where(x => x.PickedQty > x.AssignQuantity).ToList();
+                if (invalidLocks.Any())
+                {
+                    errors.Add($"鍙戠幇宸叉嫞閫夋暟閲忓ぇ浜庡垎閰嶆暟閲忕殑閿佸畾璁板綍");
+                }
+
+                // 3. 楠岃瘉鎷嗗寘璁板綍
+                var splitRecords = await _splitPackageService.Db.Queryable<Dt_SplitPackageRecord>()
+                    .Where(x => x.OrderNo == orderNo && x.PalletCode == palletCode)
+                    .ToListAsync();
+
+                // 妫�鏌ュ惊鐜媶鍖�
+                var barcodeMap = new Dictionary<string, string>();
+                foreach (var record in splitRecords.Where(x => !x.IsReverted))
+                {
+                    if (!barcodeMap.ContainsKey(record.OriginalBarcode))
+                        barcodeMap[record.OriginalBarcode] = record.NewBarcode;
+                }
+
+                // 妫�鏌ュ惊鐜紩鐢�
+                foreach (var record in splitRecords)
+                {
+                    var current = record.OriginalBarcode;
+                    var visited = new HashSet<string>();
+
+                    while (barcodeMap.ContainsKey(current))
+                    {
+                        if (visited.Contains(current))
+                        {
+                            errors.Add($"鍙戠幇寰幆鎷嗗寘寮曠敤: {record.OriginalBarcode}");
+                            break;
+                        }
+                        visited.Add(current);
+                        current = barcodeMap[current];
+                    }
+                }
+
+                if (errors.Any())
+                {
+                    return ValidationResult<bool>.Error($"鍥炲簱鍓嶆暟鎹獙璇佸彂鐜伴棶棰�: {string.Join("; ", errors)}");
+                }
+
+                return ValidationResult<bool>.Success(true);
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError($"鏁版嵁楠岃瘉澶辫触: {ex.Message}");
+                return ValidationResult<bool>.Error($"鏁版嵁楠岃瘉寮傚父: {ex.Message}");
+            }
+        }
+
+        // <summary>
+        /// 鎵ц澧炲己鐨勫洖搴撴搷浣� - 淇鐗堬紙閬垮厤閲嶅澶勭悊锛�
+        /// </summary>
+        private async Task ExecuteEnhancedReturnOperations(PalletStatusAnalysis statusAnalysis)
+        {
+            _logger.LogInformation($"銆愬紑濮嬫墽琛屽洖搴撴搷浣溿�戣鍗�: {statusAnalysis.OrderNo}, 鎵樼洏: {statusAnalysis.PalletCode}");
+
+            // 浣跨敤鏈湴宸插鐞嗛泦鍚堬紝閬垮厤閲嶅
+            var locallyProcessedBarcodes = new HashSet<string>();
+            decimal totalProcessedQty = 0;
+
+            // 1. 澶勭悊宸插垎閰嶇殑閿佸畾璁板綍
+            if (statusAnalysis.HasRemainingLocks)
+            {
+                _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)
+            {
+                _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)
+            {
+                _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}");
+                    }
+                }
+            }
+
+            // 4. 銆愪慨姝c�戝鐞嗘媶鍖呰褰� - 鍙鐞嗘湭琚叾浠栭�昏緫瑕嗙洊鐨勬潯鐮�
+            if (statusAnalysis.HasSplitRecords && statusAnalysis.SplitReturnQty > 0)
+            {
+                _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)
+        {
+            try
+            {
+                _logger.LogInformation($"寮�濮嬪洖搴撳悗鏁版嵁楠岃瘉");
+
+                // 1. 楠岃瘉搴撳瓨鐘舵�佸拰鏁伴噺
+                var stockDetails = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+                    .Where(x => x.StockId == stockId)
+                    .ToListAsync();
+
+                decimal totalStock = stockDetails.Sum(x => x.StockQuantity);
+
+                // 楠岃瘉搴撳瓨鏁伴噺鏄惁鍚堢悊
+                var unreasonableStocks = stockDetails.Where(x => x.StockQuantity < 0).ToList();
+                if (unreasonableStocks.Any())
+                {
+                    _logger.LogError($"鍙戠幇璐熸暟搴撳瓨鏁伴噺锛佹潯鐮�: {string.Join(", ", unreasonableStocks.Select(x => x.Barcode))}");
+                }
+
+                // 2. 楠岃瘉閿佸畾璁板綍鐘舵��
+                var lockInfos = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+                    .Where(x => x.OrderNo == orderNo && x.PalletCode == palletCode)
+                    .ToListAsync();
+
+                var notReturnedLocks = lockInfos.Where(x =>
+                    x.Status != (int)OutLockStockStatusEnum.宸插洖搴� &&
+                    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 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($"鍥炲簱鍚庢暟鎹獙璇佸畬鎴�");
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError($"鍥炲簱鍚庨獙璇佸け璐�: {ex.Message}");
+            }
+        }
+
+        /// <summary>
+        /// 楠岃瘉鍥炲簱鍓嶅悗鏁版嵁涓�鑷存��
+        /// </summary>
+        private async Task<bool> ValidateReturnData(string orderNo, string palletCode, int stockId, bool isBefore = true)
+        {
+            string phase = isBefore ? "鍥炲簱鍓�" : "鍥炲簱鍚�";
+            try
+            {
+
+                _logger.LogInformation($"銆恵phase}鏁版嵁楠岃瘉銆戝紑濮� - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}");
+
+                // 1. 妫�鏌ュ簱瀛樻槑缁�
+                var stockDetails = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+                    .Where(x => x.StockId == stockId)
+                    .ToListAsync();
+
+                decimal totalStockQty = stockDetails.Sum(x => x.StockQuantity);
+                _logger.LogInformation($"{phase}搴撳瓨鎬婚噺: {totalStockQty}");
+
+                // 2. 妫�鏌ラ攣瀹氳褰�
+                var lockInfos = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+                    .Where(x => x.OrderNo == orderNo && x.PalletCode == palletCode)
+                    .ToListAsync();
+
+                // 妫�鏌ラ攣瀹氳褰曠姸鎬佸垎甯�
+                var statusGroups = lockInfos.GroupBy(x => x.Status)
+                    .Select(g => new { Status = g.Key, Count = g.Count() })
+                    .ToList();
+
+                foreach (var group in statusGroups)
+                {
+                    _logger.LogInformation($"{phase}閿佸畾鐘舵�� {GetLockStatusName(group.Status)}: {group.Count} 鏉�");
+                }
+
+                // 3. 鍩烘湰楠岃瘉
+                bool isValid = true;
+
+                // 楠岃瘉1: 濡傛灉閿佸畾璁板綍鐘舵�佷负"鎷i�夊畬鎴�"锛屽搴斿簱瀛樺簲璇ヤ负0
+                var completedLocks = lockInfos.Where(x => x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�).ToList();
+                foreach (var lockInfo in completedLocks)
+                {
+                    if (!string.IsNullOrEmpty(lockInfo.CurrentBarcode))
+                    {
+                        var stock = stockDetails.FirstOrDefault(x => x.Barcode == lockInfo.CurrentBarcode);
+                        if (stock != null && stock.StockQuantity > 0)
+                        {
+                            _logger.LogWarning($"{phase}楠岃瘉璀﹀憡 - 閿佸畾ID {lockInfo.Id} 鎷i�夊畬鎴愪絾搴撳瓨涓嶄负0: {stock.StockQuantity}");
+                        }
+                    }
+                }
+
+                // 楠岃瘉2: 搴撳瓨鐘舵�佷竴鑷存��
+                foreach (var stock in stockDetails)
+                {
+                    if (stock.Status == (int)StockStatusEmun.鍑哄簱閿佸畾 && stock.StockQuantity == 0)
+                    {
+                        _logger.LogWarning($"{phase}楠岃瘉璀﹀憡 - 鏉$爜 {stock.Barcode} 鐘舵�佷负鍑哄簱閿佸畾浣嗗簱瀛樹负0");
+                    }
+                }
+
+                _logger.LogInformation($"銆恵phase}鏁版嵁楠岃瘉銆戝畬鎴� - 鐘舵��: {(isValid ? "閫氳繃" : "鏈夎鍛�")}");
+                return isValid;
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError($"{phase} 鏁版嵁楠岃瘉澶辫触: {ex.Message}");
+                return false;
+            }
+        }
+
+        private string GetLockStatusName(int status)
+        {
+            return status switch
+            {
+                1 => "鍑哄簱涓�",
+                2 => "鎷i�夊畬鎴�",
+                3 => "宸插洖搴�",
+                4 => "宸插彇璧�",
+                _ => $"鏈煡({status})"
+            };
+        }
+
+        /// <summary>
+        /// 绠�鍖栧洖搴撴暟鎹搷浣滐紙褰撲富鏂规硶澶辫触鏃朵娇鐢級
+        /// </summary>
+        private async Task ExecuteSimpleReturnDataOperations(PalletStatusAnalysis statusAnalysis)
+        {
+            _logger.LogInformation($"銆愮畝鍖栧洖搴撱�戝紑濮嬫墽琛岀畝鍖栧洖搴撴搷浣�");
+
+            try
+            {
+                // 鑾峰彇璇ユ墭鐩樼殑鎵�鏈夋潯鐮侊紙鍖呮嫭鎵�鏈夌姸鎬佺殑搴撳瓨锛�
+                var allStockDetails = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+                    .Where(x => x.StockId == statusAnalysis.StockId)
+                    .ToListAsync();
+
+                _logger.LogInformation($"鎵惧埌 {allStockDetails.Count} 涓簱瀛樻槑缁嗚褰�");
+
+                foreach (var stockDetail in allStockDetails)
+                {
+                    // 璁板綍鍘熷鐘舵��
+                    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}, 鐘舵��: {GetStockStatusName(originalStatus)} -> 鍏ュ簱瀹屾垚, 鏁伴噺: {originalStockQty} -> {stockDetail.StockQuantity}");
+                    }
+                }
+
+                // 鏇存柊鎵�鏈夐攣瀹氳褰曚负宸插洖搴�
+                var allLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+                    .Where(x => x.OrderNo == statusAnalysis.OrderNo &&
+                               x.PalletCode == statusAnalysis.PalletCode &&
+                               (x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓� ||
+                                x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�))
+                    .ToListAsync();
+
+                foreach (var lockInfo in allLocks)
+                {
+                    lockInfo.Status = (int)OutLockStockStatusEnum.宸插洖搴�;
+                    lockInfo.Operator = App.User.UserName;
+
+                    await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
+                    _logger.LogInformation($"绠�鍖栧洖搴� - 閿佸畾璁板綍: {lockInfo.Id}, 鐘舵��: 宸插洖搴�");
+                }
+
+                _logger.LogInformation($"銆愮畝鍖栧洖搴撱�戝畬鎴� - 澶勭悊 {allStockDetails.Count} 涓潯鐮�, {allLocks.Count} 鏉¢攣瀹氳褰�");
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError($"绠�鍖栧洖搴撳け璐�: {ex.Message}");
+                throw;
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇搴撳瓨鐘舵�佸悕绉�
+        /// </summary>
+        private string GetStockStatusName(int status)
+        {
+            return status switch
+            {
+                1 => "鍏ュ簱纭",
+                2 => "鍏ュ簱瀹屾垚",
+                3 => "鍑哄簱閿佸畾",
+                4 => "鍑哄簱涓�",
+                5 => "鍑哄簱瀹屾垚",
+                6 => "宸叉竻鐞�",
+                _ => $"鏈煡({status})"
+            };
+        }
+
+
+        /// <summary>
+        /// 鎵ц鍥炲簱鏁版嵁鎿嶄綔 - 绠�鍖栫増鏈�
         /// </summary>
         private async Task ExecuteReturnDataOperations(PalletStatusAnalysis statusAnalysis)
         {
@@ -1746,28 +3181,142 @@
 
             try
             {
+                // 浣跨敤 HashSet 閬垮厤閲嶅澶勭悊鏉$爜
+                var processedBarcodes = new HashSet<string>();
+                decimal totalReturnedQty = 0;
+
                 // 1. 澶勭悊宸插垎閰嶇殑鏈垎鎷i攣瀹氳褰�
                 if (statusAnalysis.HasRemainingLocks)
                 {
                     _logger.LogInformation($"澶勭悊 {statusAnalysis.RemainingLocks.Count} 鏉″凡鍒嗛厤鏈垎鎷i攣瀹氳褰�");
-                    await HandleAllocatedLocksReturn(statusAnalysis.RemainingLocks);
+
+                    foreach (var lockInfo in statusAnalysis.RemainingLocks)
+                    {
+                        if (string.IsNullOrEmpty(lockInfo.CurrentBarcode) || processedBarcodes.Contains(lockInfo.CurrentBarcode))
+                        {
+                            _logger.LogInformation($"璺宠繃閲嶅鎴栫┖鏉$爜鐨勯攣瀹氳褰� - ID: {lockInfo.Id}");
+                            continue;
+                        }
+
+                        // 璁$畻鍥炲簱鏁伴噺锛堟湭鎷i�夌殑閮ㄥ垎锛�
+                        decimal returnQty = lockInfo.AssignQuantity - lockInfo.PickedQty;
+
+                        if (returnQty > 0)
+                        {
+                            _logger.LogInformation($"澶勭悊閿佸畾璁板綍鍥炲簱 - ID: {lockInfo.Id}, 鏉$爜: {lockInfo.CurrentBarcode}, 鍥炲簱鏁伴噺: {returnQty}");
+
+                            // 澶勭悊搴撳瓨
+                            await ProcessStockForReturn(lockInfo.CurrentBarcode, statusAnalysis.StockId, returnQty);
+
+                            // 鏍囪涓哄凡鍥炲簱
+                            lockInfo.Status = (int)OutLockStockStatusEnum.宸插洖搴�;
+                            lockInfo.Operator = App.User.UserName;
+
+
+                            await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
+
+                            // 鍑忓皯璁㈠崟鏄庣粏鐨勫垎閰嶆暟閲�
+                            if (lockInfo.OrderDetailId > 0)
+                            {
+                                var orderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>().FirstAsync(x => x.Id == lockInfo.OrderDetailId);
+                                await ReduceOrderDetailAllocation(orderDetail, returnQty);
+                            }
+
+                            processedBarcodes.Add(lockInfo.CurrentBarcode);
+                            totalReturnedQty += returnQty;
+
+                            _logger.LogInformation($"閿佸畾璁板綍鍥炲簱瀹屾垚 - ID: {lockInfo.Id}, 鍥炲簱鏁伴噺: {returnQty}");
+                        }
+                        else
+                        {
+                            _logger.LogInformation($"閿佸畾璁板綍鏃犻渶鍥炲簱 - ID: {lockInfo.Id}, 宸叉嫞閫夊畬鎴�");
+                        }
+                    }
                 }
 
-                // 2. 澶勭悊鏈垎閰嶇殑閿佸畾璁板綍锛堝鑷姩鎷嗗寘浜х敓鐨勶級
-                if (statusAnalysis.HasUnallocatedLocks)
-                {
-                    _logger.LogInformation($"澶勭悊 {statusAnalysis.UnallocatedLocks.Count} 鏉℃湭鍒嗛厤閿佸畾璁板綍");
-                    await HandleUnallocatedLocksReturn(statusAnalysis.UnallocatedLocks);
-                }
-
-                // 3. 澶勭悊鏈垎閰嶇殑搴撳瓨璐х墿
+                // 2. 澶勭悊鏈垎閰嶇殑搴撳瓨璐х墿
                 if (statusAnalysis.HasPalletStockGoods)
                 {
                     _logger.LogInformation($"澶勭悊 {statusAnalysis.PalletStockGoods.Count} 涓湭鍒嗛厤搴撳瓨璐х墿");
-                    await HandleUnallocatedStockReturn(statusAnalysis.PalletStockGoods);
+
+                    foreach (var stockDetail in statusAnalysis.PalletStockGoods)
+                    {
+                        if (string.IsNullOrEmpty(stockDetail.Barcode) || processedBarcodes.Contains(stockDetail.Barcode))
+                        {
+                            _logger.LogInformation($"璺宠繃閲嶅鎴栫┖鏉$爜鐨勫簱瀛� - 搴撳瓨ID: {stockDetail.Id}");
+                            continue;
+                        }
+
+                        if (stockDetail.StockQuantity > 0)
+                        {
+                            decimal returnQty = stockDetail.StockQuantity;
+                            _logger.LogInformation($"澶勭悊鏈垎閰嶅簱瀛樺洖搴� - 鏉$爜: {stockDetail.Barcode}, 鍥炲簱鏁伴噺: {returnQty}");
+
+                            // 鐩存帴鎭㈠搴撳瓨鐘舵��
+                            stockDetail.Status = (int)StockStatusEmun.鍏ュ簱瀹屾垚;
+
+                            await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
+
+                            processedBarcodes.Add(stockDetail.Barcode);
+                            totalReturnedQty += returnQty;
+
+                            _logger.LogInformation($"鏈垎閰嶅簱瀛樺洖搴撳畬鎴� - 鏉$爜: {stockDetail.Barcode}, 鏁伴噺: {returnQty}");
+                        }
+                    }
                 }
 
-                _logger.LogInformation($"鍥炲簱鏁版嵁鎿嶄綔瀹屾垚 - 鎬诲洖搴撴暟閲�: {statusAnalysis.TotalReturnQty}");
+                // 3. 澶勭悊鎷嗗寘璁板綍鐩稿叧鐨勬潯鐮�
+                if (statusAnalysis.HasSplitRecords)
+                {
+                    _logger.LogInformation($"澶勭悊 {statusAnalysis.SplitRecords.Count} 鏉℃媶鍖呰褰�");
+
+                    // 鏀堕泦鎷嗗寘鐩稿叧鐨勬墍鏈夋潯鐮�
+                    var splitBarcodes = new List<string>();
+                    foreach (var splitRecord in statusAnalysis.SplitRecords)
+                    {
+                        if (!string.IsNullOrEmpty(splitRecord.OriginalBarcode))
+                            splitBarcodes.Add(splitRecord.OriginalBarcode);
+                        if (!string.IsNullOrEmpty(splitRecord.NewBarcode))
+                            splitBarcodes.Add(splitRecord.NewBarcode);
+                    }
+
+                    // 鍘婚噸
+                    splitBarcodes = splitBarcodes.Distinct().ToList();
+
+                    foreach (var barcode in splitBarcodes)
+                    {
+                        if (processedBarcodes.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;
+                            _logger.LogInformation($"澶勭悊鎷嗗寘鐩稿叧搴撳瓨鍥炲簱 - 鏉$爜: {barcode}, 鍥炲簱鏁伴噺: {returnQty}");
+
+                            // 鎭㈠搴撳瓨鐘舵��
+                            if (stockDetail.Status == (int)StockStatusEmun.鍑哄簱閿佸畾)
+                            {
+                                stockDetail.Status = (int)StockStatusEmun.鍏ュ簱瀹屾垚;
+
+                                await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
+
+                                processedBarcodes.Add(barcode);
+                                totalReturnedQty += returnQty;
+
+                                _logger.LogInformation($"鎷嗗寘搴撳瓨鍥炲簱瀹屾垚 - 鏉$爜: {barcode}, 鏁伴噺: {returnQty}");
+                            }
+                        }
+                    }
+                }
+
+                _logger.LogInformation($"鍥炲簱鏁版嵁鎿嶄綔瀹屾垚 - 鎬诲洖搴撴暟閲�: {totalReturnedQty}, 澶勭悊鏉$爜鏁�: {processedBarcodes.Count}");
             }
             catch (Exception ex)
             {
@@ -1775,9 +3324,154 @@
                 throw;
             }
         }
-        // <summary>
-        /// 澶勭悊鏈垎閰嶇殑閿佸畾璁板綍鍥炲簱
-        /// 涓嶉渶瑕佸噺灏戣鍗曟槑缁嗙殑鍒嗛厤鏁伴噺
+
+
+        /// <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);
+
+                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)}");
+
+                // 銆愭牳蹇冧慨姝c�戠‘淇濆洖搴撴搷浣滄纭鐞�
+                // 1. 搴撳瓨鏁伴噺澧炲姞锛堝洖搴撶殑璐х墿鍥炲埌搴撳瓨锛�
+                stockDetail.StockQuantity += returnQty;
+
+                // 2. 鍑哄簱鏁伴噺鍑忓皯锛堝洜涓鸿揣鐗╂病鏈夊嚭搴擄紝鑰屾槸鍥炲簱浜嗭級
+                // 浣嗛渶瑕佺‘淇濅笉浼氬嚭鐜拌礋鏁�
+                if (stockDetail.OutboundQuantity >= returnQty)
+                {
+                    stockDetail.OutboundQuantity -= returnQty;
+                }
+                else
+                {
+                    // 濡傛灉鍑哄簱鏁伴噺灏忎簬鍥炲簱鏁伴噺锛岃鏄庢暟鎹紓甯�
+                    _logger.LogWarning($"鍑哄簱鏁伴噺({stockDetail.OutboundQuantity})灏忎簬鍥炲簱鏁伴噺({returnQty})锛岄噸缃嚭搴撴暟閲忎负0");
+                    stockDetail.OutboundQuantity = 0;
+                }
+
+                // 3. 鏇存柊鐘舵�佷负鍏ュ簱瀹屾垚
+                stockDetail.Status = (int)StockStatusEmun.鍏ュ簱瀹屾垚;
+
+                await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
+
+                _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)
+            {
+                _logger.LogError($"澶勭悊搴撳瓨鍥炲簱澶辫触 - 鏉$爜: {barcode}, Error: {ex.Message}");
+                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>
+        private async Task ReduceOrderDetailAllocationForLock(long orderDetailId, decimal reduceQty)
+        {
+            if (orderDetailId <= 0)
+                return;
+
+            var orderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
+                .FirstAsync(x => x.Id == orderDetailId);
+
+            if (orderDetail == null)
+                return;
+
+            decimal originalAllocated = orderDetail.AllocatedQuantity;
+            decimal originalLock = orderDetail.LockQuantity;
+
+            // 楠岃瘉鍑忓皯鏁伴噺涓嶄細瀵艰嚧璐熸暟
+            if (orderDetail.AllocatedQuantity < reduceQty)
+            {
+                _logger.LogWarning($"鍒嗛厤鏁伴噺涓嶈冻锛岃皟鏁村噺灏戞暟閲� - 鍘熻鍒掑噺灏�: {reduceQty}, 瀹為檯鍙敤: {orderDetail.AllocatedQuantity}");
+                reduceQty = orderDetail.AllocatedQuantity;
+            }
+
+            // 鍑忓皯鍒嗛厤鏁伴噺鍜岄攣瀹氭暟閲�
+            orderDetail.AllocatedQuantity -= reduceQty;
+            orderDetail.LockQuantity -= reduceQty;
+
+            // 纭繚鏁伴噺涓嶄細涓鸿礋鏁�
+            if (orderDetail.AllocatedQuantity < 0)
+            {
+                _logger.LogWarning($"鍒嗛厤鏁伴噺鍑虹幇璐熸暟锛岄噸缃负0銆傚師鍊�: {orderDetail.AllocatedQuantity + reduceQty}, 鍑忓皯: {reduceQty}");
+                orderDetail.AllocatedQuantity = 0;
+            }
+
+            if (orderDetail.LockQuantity < 0)
+            {
+                _logger.LogWarning($"閿佸畾鏁伴噺鍑虹幇璐熸暟锛岄噸缃负0銆傚師鍊�: {orderDetail.LockQuantity + reduceQty}, 鍑忓皯: {reduceQty}");
+                orderDetail.LockQuantity = 0;
+            }
+
+            // 鏇存柊鎵规鍒嗛厤鐘舵��
+            await UpdateBatchAllocateStatus(orderDetail);
+
+            await _outboundOrderDetailService.Db.Updateable(orderDetail).ExecuteCommandAsync();
+
+            _logger.LogInformation($"鍑忓皯璁㈠崟鏄庣粏鍒嗛厤 - OrderDetailId: {orderDetail.Id}, " +
+                                  $"鍒嗛厤鏁伴噺: {originalAllocated} -> {orderDetail.AllocatedQuantity}, " +
+                                  $"閿佸畾鏁伴噺: {originalLock} -> {orderDetail.LockQuantity}, " +
+                                  $"鍑忓皯鏁伴噺: {reduceQty}");
+        }
+
+        /// <summary>
+        /// 澶勭悊鏈垎閰嶇殑閿佸畾璁板綍鍥炲簱 - 淇鐗�
+        /// 娉ㄦ剰锛氭湭鍒嗛厤閿佸畾璁板綍娌℃湁缁戝畾璁㈠崟鏄庣粏锛屼笉闇�瑕佸噺灏戣鍗曟槑缁嗙殑鍒嗛厤鏁伴噺
         /// </summary>
         private async Task HandleUnallocatedLocksReturn(List<Dt_OutStockLockInfo> unallocatedLocks)
         {
@@ -1797,7 +3491,27 @@
                 _logger.LogInformation($"澶勭悊鏈垎閰嶉攣瀹氳褰曞洖搴� - 閿佸畾ID: {lockInfo.Id}, 鏉$爜: {lockInfo.CurrentBarcode}, 鍥炲簱鏁伴噺: {returnQty}");
 
                 // 鎭㈠搴撳瓨鐘舵��
-                await RestoreStockForLockInfo(lockInfo, returnQty);
+                var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+                    .FirstAsync(x => x.Barcode == lockInfo.CurrentBarcode && x.StockId == lockInfo.StockId);
+
+                if (stockDetail != null)
+                {
+                    // 銆愪慨姝c�戞仮澶嶅簱瀛樻暟閲忥紝鍑哄簱鏁伴噺淇濇寔涓嶅彉锛堝洜涓烘湭鍒嗛厤閿佸畾鐨勫嚭搴撴暟閲忔湰鏉ュ氨鏄�0锛�
+                    decimal originalStockQty = stockDetail.StockQuantity;
+                    stockDetail.StockQuantity += returnQty;
+
+                    // 鍑哄簱鏁伴噺淇濇寔涓�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}");
+                }
 
                 // 鏇存柊閿佸畾璁板綍鐘舵�佷负宸插洖搴�
                 lockInfo.Status = (int)OutLockStockStatusEnum.宸插洖搴�;
@@ -1806,13 +3520,11 @@
                 await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
 
                 _logger.LogInformation($"鏇存柊鏈垎閰嶉攣瀹氱姸鎬� - 閿佸畾ID: {lockInfo.Id}, 鐘舵��: 鍑哄簱涓� -> 宸插洖搴�");
-
-                // 閲嶈锛氭湭鍒嗛厤閿佸畾璁板綍涓嶉渶瑕佸噺灏戣鍗曟槑缁嗙殑鍒嗛厤鏁伴噺
-                _logger.LogInformation($"鏈垎閰嶉攣瀹氳褰曞洖搴撳畬鎴� - 閿佸畾ID: {lockInfo.Id}, 鍥炲簱鏁伴噺: {returnQty}, 鏃犻渶鏇存柊璁㈠崟鏄庣粏");
             }
 
             _logger.LogInformation($"鏈垎閰嶉攣瀹氳褰曞洖搴撳鐞嗗畬鎴� - 鍏卞鐞� {unallocatedLocks.Count} 鏉¤褰�");
         }
+
         private async Task HandleAllocatedLocksReturn(List<Dt_OutStockLockInfo> allocatedLocks)
         {
             _logger.LogInformation($"寮�濮嬪鐞嗗凡鍒嗛厤閿佸畾璁板綍鍥炲簱 - 鍏� {allocatedLocks.Count} 鏉¤褰�");
@@ -1953,7 +3665,7 @@
                 try
                 {
                     await _taskRepository.Db.Insertable(returnTask).ExecuteCommandAsync();
-                 
+
                     _logger.LogInformation($"CreateReturnTaskAndHandleESS  鍒嗘壒鍒犻櫎鍘嗗彶浠诲姟: {orderNo} 锛� {currentTask.TaskNum}");
                     // 鍒犻櫎鍘熷鍑哄簱浠诲姟
                     //_taskRepository.DeleteAndMoveIntoHty(originalTask, OperateTypeEnum.鑷姩瀹屾垚);
@@ -1971,7 +3683,7 @@
                 {
                     _logger.LogInformation($"鍒涘缓鍥炲簱浠诲姟澶辫触 - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}");
                     throw new Exception($"鍒涘缓鍥炲簱浠诲姟澶辫触 - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}");
-                  
+
                 }
                 // 鍙戦�丒SS鍛戒护
                 await SendESSCommands(palletCode, targetAddress, returnTask);
@@ -2044,114 +3756,231 @@
         /// 鍒嗘瀽鎵樼洏鐘舵�佺敤浜庡洖搴�
         /// 纭繚涓嶄細閿欒璇嗗埆闇�瑕佸洖搴撶殑鐗╁搧
         /// </summary>
+
+        /// <summary>
+        /// 鍒嗘瀽鎵樼洏鐘舵�佺敤浜庡洖搴� - 淇鐗堬紙瑙e喅鎷嗗寘璁板綍閲嶅璁$畻闂锛�
+        /// </summary>
         private async Task<PalletStatusAnalysis> AnalyzePalletStatusForReturn(string orderNo, string palletCode, int stockId)
         {
             var result = new PalletStatusAnalysis
             {
                 OrderNo = orderNo,
                 PalletCode = palletCode,
-                StockId = stockId
+                StockId = stockId,
+                AllBarcodes = new List<string>(),
+                ProcessedBarcodes = new HashSet<string>()
             };
 
-            // 1. 鍒嗘瀽鏈垎鎷g殑閿佸畾璁板綍锛堢姸鎬佷负鍑哄簱涓級
-            var unfinishedLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
-                .Where(x => x.OrderNo == orderNo &&
-                           x.PalletCode == palletCode &&
-                           x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓�)
-                .ToListAsync();
+            _logger.LogInformation($"銆愬洖搴撳垎鏋愩�戝紑濮嬪垎鏋愭墭鐩樼姸鎬� - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}, StockId: {stockId}");
 
-            if (unfinishedLocks.Any())
+            try
             {
-                //  鍖哄垎宸插垎閰嶅拰鏈垎閰嶇殑閿佸畾璁板綍
-                var allocatedLocks = unfinishedLocks.Where(x => x.IsUnallocated != 1 && x.OrderDetailId > 0).ToList();
-                var unallocatedLocks = unfinishedLocks.Where(x => x.IsUnallocated == 1 || x.OrderDetailId == 0).ToList();
+                // 1. 棣栧厛鑾峰彇鎵樼洏涓婃墍鏈夌殑搴撳瓨鏄庣粏锛堝熀纭�鏁版嵁锛�
+                var allStockDetails = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+                    .Where(x => x.StockId == stockId && x.StockQuantity > 0)
+                    .ToListAsync();
 
-                // 澶勭悊宸插垎閰嶇殑閿佸畾璁板綍
+                _logger.LogInformation($"鎵惧埌 {allStockDetails.Count} 涓湁搴撳瓨鐨勬槑缁嗚褰�");
+
+                // 2. 鍒嗘瀽鎵�鏈夐攣瀹氳褰曪紙宸插垎閰嶅拰鏈垎閰嶏級
+                var allLockInfos = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+                    .Where(x => x.OrderNo == orderNo && x.PalletCode == palletCode)
+                    .ToListAsync();
+
+                // 鍖哄垎宸插垎閰嶅拰鏈垎閰嶉攣瀹氳褰�
+                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.HasRemainingLocks = true;
                     result.RemainingLocks = allocatedLocks;
-                    result.RemainingLocksReturnQty = allocatedLocks.Sum(x => x.AssignQuantity - x.PickedQty);
+
+                    // 銆愪慨澶嶃�戝浜庡凡鍒嗛厤閿佸畾璁板綍锛屽洖搴撴暟閲忔槸鏈嫞閫夌殑閮ㄥ垎
+                    result.RemainingLocksReturnQty = allocatedLocks.Sum(x =>
+                    {
+                        var returnQty = x.AssignQuantity - x.PickedQty;
+                        return returnQty > 0 ? returnQty : 0;
+                    });
 
                     foreach (var lockInfo in allocatedLocks)
                     {
                         if (!string.IsNullOrEmpty(lockInfo.CurrentBarcode))
                         {
                             result.AllBarcodes.Add(lockInfo.CurrentBarcode);
+                            result.ProcessedBarcodes.Add(lockInfo.CurrentBarcode);
                         }
                     }
-
-                    _logger.LogInformation($"鍙戠幇{allocatedLocks.Count}鏉″凡鍒嗛厤鏈垎鎷i攣瀹氳褰曪紝鎬绘暟閲�: {result.RemainingLocksReturnQty}");
+                    _logger.LogInformation($"鍙戠幇 {allocatedLocks.Count} 鏉″凡鍒嗛厤閿佸畾璁板綍锛屽洖搴撴暟閲�: {result.RemainingLocksReturnQty}");
                 }
 
-                // 澶勭悊鏈垎閰嶇殑閿佸畾璁板綍锛堝鑷姩鎷嗗寘浜х敓鐨勶級
+                // 澶勭悊鏈垎閰嶉攣瀹氳褰曪紙鑷姩鎷嗗寘浜х敓鐨勶級
                 if (unallocatedLocks.Any())
                 {
                     result.HasUnallocatedLocks = true;
                     result.UnallocatedLocks = unallocatedLocks;
-                    result.UnallocatedLocksReturnQty = unallocatedLocks.Sum(x => x.AssignQuantity - x.PickedQty);
+
+                    // 銆愪慨澶嶃�戝浜庢湭鍒嗛厤閿佸畾璁板綍锛屽洖搴撴暟閲忔槸瀹冪殑鍒嗛厤鏁伴噺锛堝洜涓烘湭鎷i�夎繃锛�
+                    // 浣嗗疄闄呬笂锛屽簱瀛樻湰鏉ュ氨瀛樺湪锛屽彧鏄姸鎬侀渶瑕佹仮澶�
+                    result.UnallocatedLocksReturnQty = unallocatedLocks.Sum(x => x.AssignQuantity);
 
                     foreach (var lockInfo in unallocatedLocks)
                     {
-                        if (!string.IsNullOrEmpty(lockInfo.CurrentBarcode))
+                        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}");
+                    _logger.LogInformation($"鍙戠幇 {unallocatedLocks.Count} 鏉℃湭鍒嗛厤閿佸畾璁板綍锛屽洖搴撴暟閲忥紙鐘舵�佹仮澶嶏級: {result.UnallocatedLocksReturnQty}");
                 }
+
+                // 3. 銆愰噸瑕佷慨澶嶃�戦噸鏂拌绠楁�诲洖搴撴暟閲�
+                // 瀵逛簬宸插垎閰嶉攣瀹氾細鍥炲簱鏁伴噺 = 鏈嫞閫夋暟閲�
+                // 瀵逛簬鏈垎閰嶉攣瀹氾細娌℃湁瀹為檯鐨勫簱瀛樻暟閲忓彉鍖栵紝鍙槸鐘舵�佹仮澶�
+                result.TotalReturnQty = result.RemainingLocksReturnQty; // 鍙绠楀凡鍒嗛厤閿佸畾鐨勫洖搴撴暟閲�
+
+                // 璁板綍搴撳瓨鏁伴噺锛堢敤浜庨獙璇侊級
+                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;
+
+                return result;
             }
-
-            // 2. 鍒嗘瀽鎵樼洏涓婄殑鍓╀綑搴撳瓨璐х墿锛堢姸鎬佷负鍑哄簱閿佸畾浣嗘湭鍒嗛厤锛�
-            var palletStockGoods = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
-                .Where(x => x.StockId == stockId &&
-                           x.Status == (int)StockStatusEmun.鍑哄簱閿佸畾 &&
-                           x.StockQuantity > 0)
-                .ToListAsync();
-
-            // 杩囨护鎺夊凡缁忚閿佸畾璁板綍鍗犵敤鐨勫簱瀛�
-            var lockedBarcodes = unfinishedLocks.Select(x => x.CurrentBarcode).ToList();
-            var unlockedStockGoods = palletStockGoods.Where(x => !lockedBarcodes.Contains(x.Barcode)).ToList();
-
-            // 杩涗竴姝ヨ繃婊わ細妫�鏌ヨ繖浜涘簱瀛樻槸鍚︽湁鍏宠仈鐨勯攣瀹氳褰�
-            var trulyUnallocatedGoods = new List<Dt_StockInfoDetail>();
-            foreach (var stock in unlockedStockGoods)
+            catch (Exception ex)
             {
-                var hasLock = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
-                    .Where(x => x.CurrentBarcode == stock.Barcode &&
-                               x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓�)
-                    .AnyAsync();
-
-                if (!hasLock)
-                {
-                    trulyUnallocatedGoods.Add(stock);
-                }
+                _logger.LogError($"鍥炲簱鍒嗘瀽澶辫触 - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}, Error: {ex.Message}");
+                throw;
             }
-
-            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}");
-            }
-
-            // 3. 璁$畻鎬诲洖搴撴暟閲�
-            result.TotalReturnQty = result.RemainingLocksReturnQty + result.UnallocatedLocksReturnQty + result.PalletStockReturnQty;
-            result.HasItemsToReturn = result.TotalReturnQty > 0;
-            result.IsEmptyPallet = !result.HasItemsToReturn;
-
-            _logger.LogInformation($"鎵樼洏鐘舵�佸垎鏋愬畬鎴� - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}, 鎬诲洖搴撴暟閲�: {result.TotalReturnQty}");
-
-            return result;
         }
+
+
+        /// <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>
+        /// 楠岃瘉鍒嗘瀽缁撴灉锛岀‘淇濇暟鎹竴鑷存��
+        /// </summary>
+        private async Task ValidateAnalysisResults(PalletStatusAnalysis analysis, int stockId)
+        {
+            _logger.LogInformation($"寮�濮嬮獙璇佸垎鏋愮粨鏋� - 璁㈠崟: {analysis.OrderNo}, 鎵樼洏: {analysis.PalletCode}");
+
+            try
+            {
+                // 1. 楠岃瘉閿佸畾璁板綍鍜屽簱瀛樻槑缁嗙殑鍖归厤
+                foreach (var lockInfo in analysis.RemainingLocks.Concat(analysis.UnallocatedLocks))
+                {
+                    if (!string.IsNullOrEmpty(lockInfo.CurrentBarcode))
+                    {
+                        var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+                            .FirstAsync(x => x.Barcode == lockInfo.CurrentBarcode && x.StockId == lockInfo.StockId);
+
+                        if (stockDetail == null)
+                        {
+                            _logger.LogWarning($"閿佸畾璁板綍 {lockInfo.Id} 鐨勬潯鐮� {lockInfo.CurrentBarcode} 鍦ㄥ簱瀛樻槑缁嗕腑涓嶅瓨鍦�");
+                        }
+                        else if (stockDetail.StockQuantity <= 0)
+                        {
+                            _logger.LogWarning($"閿佸畾璁板綍 {lockInfo.Id} 鐨勬潯鐮� {lockInfo.CurrentBarcode} 搴撳瓨鏁伴噺涓�0鎴栬礋鏁�");
+                        }
+                    }
+                }
+
+                // 2. 楠岃瘉鎬诲洖搴撴暟閲忕殑鍚堢悊鎬�
+                // 鑾峰彇鎵樼洏涓婄殑鎬诲簱瀛樻暟閲�
+                var totalStockOnPallet = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+                    .Where(x => x.StockId == stockId)
+                    .SumAsync(x => x.StockQuantity);
+
+                if (analysis.TotalReturnQty > totalStockOnPallet)
+                {
+                    _logger.LogWarning($"鎬诲洖搴撴暟閲� {analysis.TotalReturnQty} 澶т簬鎵樼洏鎬诲簱瀛� {totalStockOnPallet}锛屽彲鑳藉瓨鍦ㄨ绠楅敊璇�");
+                }
+
+                // 3. 楠岃瘉鏉$爜鐨勫敮涓�鎬�
+                var duplicateBarcodes = analysis.AllBarcodes
+                    .GroupBy(x => x)
+                    .Where(g => g.Count() > 1)
+                    .Select(g => g.Key)
+                    .ToList();
+
+                if (duplicateBarcodes.Any())
+                {
+                    _logger.LogWarning($"鍙戠幇閲嶅鐨勬潯鐮�: {string.Join(", ", duplicateBarcodes)}");
+                }
+
+                _logger.LogInformation($"鍒嗘瀽缁撴灉楠岃瘉瀹屾垚");
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError($"鍒嗘瀽缁撴灉楠岃瘉澶辫触 - Error: {ex.Message}");
+                // 涓嶆姏鍑哄紓甯革紝鍙褰曢敊璇�
+            }
+        }
+
         /// <summary>
         /// 澶勭悊鏈垎鎷g殑閿佸畾璁板綍鍥炲簱
         /// 纭繚涓嶄細閿欒缁戝畾鏉$爜鏁伴噺鍒伴攣瀹氭暟閲�
@@ -2408,44 +4237,117 @@
         }
 
         /// <summary>
-        /// 鍙栬蛋绌虹 - 鍏堟墽琛屽洖搴撳啀娓呯悊 - 澧炲己鐗堟湰
+        /// 鍙栬蛋绌虹 - 淇鐗堬紝姝g‘澶勭悊鏈垎閰嶉攣瀹氳褰�
         /// </summary>
         public async Task<WebResponseContent> RemoveEmptyPallet(string orderNo, string palletCode)
         {
             try
             {
+                _logger.LogInformation($"銆愬彇璧扮┖绠卞紑濮嬨�戣鍗�: {orderNo}, 鎵樼洏: {palletCode}");
+
                 _unitOfWorkManage.BeginTran();
 
-                _logger.LogInformation($"寮�濮嬪彇璧扮┖绠� - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}");
+                // 1. 鍏堝皾璇曟墽琛屽洖搴撴搷浣滐紝纭繚鎵�鏈夌墿鍝侀兘鍥炲簱
+                _logger.LogInformation($"姝ラ1: 鍏堟墽琛屽洖搴撴搷浣�");
+                var returnResult = await ExecutePalletReturn(orderNo, palletCode, "鍙栬蛋绌虹鍓嶅洖搴�");
 
-                // 1. 楠岃瘉绌虹鍙栬蛋鏉′欢锛堝繀椤诲叏閮ㄥ畬鎴愭嫞閫夛級
-                var validationResult = await ValidateEmptyPalletRemoval(orderNo, palletCode);
-                if (!validationResult.IsValid)
+                // 鍗充娇鍥炲簱澶辫触锛岀户缁獙璇佺┖绠辨潯浠讹紙鍙兘鏄湡鐨勭┖鎵樼洏锛�
+                if (!returnResult.Status)
                 {
-                    _unitOfWorkManage.RollbackTran();
-                    return WebResponseContent.Instance.Error(validationResult.ErrorMessage);
+                    _logger.LogWarning($"鍥炲簱鎿嶄綔鍙兘澶辫触鎴栨棤鐗╁搧: {returnResult.Message}");
                 }
 
-                var completedLocks = validationResult.Data;
+                // 2. 楠岃瘉绌虹鍙栬蛋鏉′欢锛堝繀椤诲叏閮ㄥ畬鎴愭嫞閫夋垨宸插洖搴擄級
+                _logger.LogInformation($"姝ラ2: 楠岃瘉绌虹鍙栬蛋鏉′欢");
 
-                // 2. 娓呯悊宸插畬鎴愮殑閿佸畾璁板綍锛堟爣璁颁负宸插彇璧帮級
-                await CleanupCompletedLocks(completedLocks);
+                // 鑾峰彇鎵樼洏鐨勬墍鏈夐攣瀹氳褰曪紙鍖呮嫭宸插洖搴撳拰宸插彇璧扮殑锛�
+                var allLockInfos = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+                    .Where(x => x.OrderNo == orderNo && x.PalletCode == palletCode)
+                    .ToListAsync();
 
-                // 3. 娓呯悊瀵瑰簲鐨勫簱瀛樿褰曠姸鎬�
+                if (!allLockInfos.Any())
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    return WebResponseContent.Instance.Error("璇ユ墭鐩樻病鏈夐攣瀹氳褰�");
+                }
+
+                // 銆愪慨姝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)
+                {
+                    // 鍙鐞嗙姸鎬佷笉鏄凡鍙栬蛋鐨勮褰�
+                    if (lockInfo.Status != (int)OutLockStockStatusEnum.宸插彇璧�)
+                    {
+                        lockInfo.Status = (int)OutLockStockStatusEnum.宸插彇璧�;
+                        lockInfo.Operator = App.User.UserName;
+                        await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
+                        _logger.LogInformation($"閿佸畾璁板綍鏍囪涓哄凡鍙栬蛋 - ID: {lockInfo.Id}");
+                    }
+                }
+
+                // 4. 娓呯悊瀵瑰簲鐨勫簱瀛樿褰曠姸鎬�
+                _logger.LogInformation($"姝ラ4: 娓呯悊搴撳瓨璁板綍");
                 foreach (var lockInfo in completedLocks)
                 {
                     await CleanupStockInfo(lockInfo);
                 }
 
-                // 4. 鏇存柊鐩稿叧璁㈠崟鐘舵��
+                // 5. 鏇存柊鐩稿叧璁㈠崟鐘舵��
+                _logger.LogInformation($"姝ラ5: 鏇存柊璁㈠崟鐘舵��");
                 await UpdateOrderStatusAfterPalletRemoval(orderNo);
 
-                // 5. 璁板綍鎿嶄綔鍘嗗彶
+                // 6. 璁板綍鎿嶄綔鍘嗗彶
+                _logger.LogInformation($"姝ラ6: 璁板綍鎿嶄綔鍘嗗彶");
                 await RecordEmptyPalletRemoval(orderNo, palletCode, completedLocks);
 
                 _unitOfWorkManage.CommitTran();
 
-                _logger.LogInformation($"鍙栬蛋绌虹鎴愬姛 - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}");
+                _logger.LogInformation($"銆愬彇璧扮┖绠辨垚鍔熴�戣鍗�: {orderNo}, 鎵樼洏: {palletCode}");
 
                 return WebResponseContent.Instance.OK("鍙栬蛋绌虹鎴愬姛");
             }
@@ -2456,6 +4358,8 @@
                 return WebResponseContent.Instance.Error($"鍙栬蛋绌虹澶辫触锛歿ex.Message}");
             }
         }
+
+
         /// <summary>
         /// 鏀堕泦闇�瑕佸洖搴撶殑鏉$爜
         /// </summary>
@@ -2718,6 +4622,359 @@
             }
         }
 
+        /// <summary>
+        /// 鏀堕泦闇�瑕佸洖搴撶殑鏉$爜锛堥伩鍏嶉噸澶嶏級
+        /// </summary>
+        private async Task<HashSet<string>> CollectBarcodesForReturn(string orderNo, string palletCode, int stockId)
+        {
+            var barcodes = new HashSet<string>();
+
+            try
+            {
+                _logger.LogInformation($"寮�濮嬫敹闆嗗洖搴撴潯鐮� - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}, StockId: {stockId}");
+
+                // 1. 浠庨攣瀹氳褰曟敹闆�
+                var lockInfos = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+                    .Where(x => x.OrderNo == orderNo &&
+                               x.PalletCode == palletCode &&
+                               (x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓�
+                              // || x.Status == (int)OutLockStockStatusEnum.鍑哄簱閿佸畾)
+                              ))
+                    .ToListAsync();
+
+                foreach (var lockInfo in lockInfos)
+                {
+                    if (!string.IsNullOrEmpty(lockInfo.CurrentBarcode))
+                    {
+                        barcodes.Add(lockInfo.CurrentBarcode);
+                        _logger.LogInformation($"浠庨攣瀹氳褰曟坊鍔犳潯鐮�: {lockInfo.CurrentBarcode}");
+                    }
+                }
+
+                // 2. 浠庡簱瀛樻槑缁嗘敹闆嗭紙鐘舵�佷负鍑哄簱閿佸畾鐨勶級
+                var stockDetails = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+                    .Where(x => x.StockId == stockId &&
+                               x.Status == (int)StockStatusEmun.鍑哄簱閿佸畾 &&
+                               x.StockQuantity > 0)
+                    .ToListAsync();
+
+                foreach (var stockDetail in stockDetails)
+                {
+                    if (!barcodes.Contains(stockDetail.Barcode) && !string.IsNullOrEmpty(stockDetail.Barcode))
+                    {
+                        barcodes.Add(stockDetail.Barcode);
+                        _logger.LogInformation($"浠庡簱瀛樻槑缁嗘坊鍔犳潯鐮�: {stockDetail.Barcode}, 鏁伴噺: {stockDetail.StockQuantity}");
+                    }
+                }
+
+                // 3. 浠庢媶鍖呰褰曟敹闆�
+                var splitRecords = await _splitPackageService.Db.Queryable<Dt_SplitPackageRecord>()
+                    .Where(x => x.OrderNo == orderNo &&
+                               x.PalletCode == palletCode &&
+                               !x.IsReverted &&
+                               x.Status != (int)SplitPackageStatusEnum.宸叉嫞閫�)
+                    .ToListAsync();
+
+                foreach (var splitRecord in splitRecords)
+                {
+                    // 娣诲姞鍘熸潯鐮�
+                    if (!string.IsNullOrEmpty(splitRecord.OriginalBarcode) && !barcodes.Contains(splitRecord.OriginalBarcode))
+                    {
+                        barcodes.Add(splitRecord.OriginalBarcode);
+                        _logger.LogInformation($"浠庢媶鍖呰褰曟坊鍔犲師鏉$爜: {splitRecord.OriginalBarcode}");
+                    }
+
+                    // 娣诲姞鏂版潯鐮�
+                    if (!string.IsNullOrEmpty(splitRecord.NewBarcode) && !barcodes.Contains(splitRecord.NewBarcode))
+                    {
+                        barcodes.Add(splitRecord.NewBarcode);
+                        _logger.LogInformation($"浠庢媶鍖呰褰曟坊鍔犳柊鏉$爜: {splitRecord.NewBarcode}");
+                    }
+                }
+
+                _logger.LogInformation($"鏉$爜鏀堕泦瀹屾垚 - 鍏� {barcodes.Count} 涓潯鐮�: {string.Join(", ", barcodes)}");
+
+                return barcodes;
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError($"鏀堕泦鍥炲簱鏉$爜澶辫触 - Error: {ex.Message}");
+                return barcodes;
+            }
+        }
+
+        /// <summary>
+        /// 缁熶竴澶勭悊鏉$爜鍥炲簱锛堥伩鍏嶉噸澶嶅鐞嗭級
+        /// </summary>
+        private async Task ProcessBarcodeReturn(string barcode, int stockId, decimal returnQty, HashSet<string> processedBarcodes)
+        {
+            if (returnQty <= 0)
+                return;
+
+            // 妫�鏌ユ槸鍚﹀凡澶勭悊杩�
+            if (processedBarcodes.Contains(barcode))
+            {
+                _logger.LogInformation($"璺宠繃宸插鐞嗙殑鏉$爜: {barcode}");
+                return;
+            }
+
+            // 鑾峰彇搴撳瓨鏄庣粏
+            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($"澶勭悊鏉$爜鍥炲簱 - {barcode}: 鍘熷搴撳瓨={originalStockQty}, 鍘熷鍑哄簱={originalOutboundQty}, 鐘舵��={originalStatus}");
+
+            // 楠岃瘉鏁版嵁涓�鑷存��
+            if (originalOutboundQty < returnQty)
+            {
+                _logger.LogWarning($"鍑哄簱鏁伴噺灏忎簬鍥炲簱鏁伴噺锛岃皟鏁村洖搴撴暟閲� - 鏉$爜: {barcode}, 鍑哄簱鏁伴噺: {originalOutboundQty}, 鍥炲簱鏁伴噺: {returnQty}");
+                returnQty = originalOutboundQty;
+            }
+
+            // 鏇存柊搴撳瓨锛氬嚭搴撴暟閲忓噺灏戯紝搴撳瓨鏁伴噺澧炲姞
+            stockDetail.OutboundQuantity -= returnQty;
+            stockDetail.StockQuantity += returnQty;
+
+            // 纭繚涓嶄細鍑虹幇璐熸暟
+            if (stockDetail.OutboundQuantity < 0)
+            {
+                _logger.LogWarning($"鍑哄簱鏁伴噺鍑虹幇璐熸暟锛岄噸缃负0 - 鏉$爜: {barcode}");
+                stockDetail.OutboundQuantity = 0;
+            }
+
+            // 鏇存柊鐘舵��
+            if (stockDetail.OutboundQuantity <= 0 && stockDetail.StockQuantity > 0)
+            {
+                stockDetail.Status = (int)StockStatusEmun.鍏ュ簱瀹屾垚;
+                _logger.LogInformation($"搴撳瓨鐘舵�佹洿鏂颁负鍏ュ簱瀹屾垚 - 鏉$爜: {barcode}");
+            }
+            else if (stockDetail.StockQuantity > 0)
+            {
+                stockDetail.Status = (int)StockStatusEmun.鍑哄簱閿佸畾;
+                _logger.LogInformation($"搴撳瓨鐘舵�佷繚鎸佷负鍑哄簱閿佸畾 - 鏉$爜: {barcode}");
+            }
+
+            await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
+
+            // 鏍囪涓哄凡澶勭悊
+            processedBarcodes.Add(barcode);
+
+            _logger.LogInformation($"鏉$爜鍥炲簱瀹屾垚 - {barcode}: " +
+                                  $"搴撳瓨 {originalStockQty} -> {stockDetail.StockQuantity}, " +
+                                  $"鍑哄簱 {originalOutboundQty} -> {stockDetail.OutboundQuantity}, " +
+                                  $"鐘舵�� {originalStatus} -> {stockDetail.Status}");
+        }
+
+        /// <summary>
+        /// 澶勭悊鎷嗗寘璁板綍鍥炲簱 - 閬垮厤閲嶅
+        /// </summary>
+        private async Task HandleSplitRecordsReturn(List<Dt_SplitPackageRecord> splitRecords, int stockId, HashSet<string> processedBarcodes)
+        {
+            if (!splitRecords.Any())
+                return;
+
+            _logger.LogInformation($"寮�濮嬪鐞嗘媶鍖呰褰曞洖搴� - 鍏� {splitRecords.Count} 鏉¤褰�");
+
+            foreach (var splitRecord in splitRecords)
+            {
+                // 鍙鐞嗘湭鎾ら攢鐨勬媶鍖呰褰�
+                if (splitRecord.IsReverted)
+                {
+                    _logger.LogInformation($"璺宠繃宸叉挙閿�鐨勬媶鍖呰褰� - ID: {splitRecord.Id}");
+                    continue;
+                }
+
+                // 澶勭悊鏂版潯鐮�
+                if (!string.IsNullOrEmpty(splitRecord.NewBarcode) && !processedBarcodes.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)
+                    {
+                        // 鎷嗗寘鐨勬柊鏉$爜鍥炲簱鏁伴噺搴旇鏄叾搴撳瓨鏁伴噺
+                        await ProcessBarcodeReturn(splitRecord.NewBarcode, stockId, newStock.StockQuantity, processedBarcodes);
+                    }
+                }
+
+                // 澶勭悊鍘熸潯鐮�
+                if (!string.IsNullOrEmpty(splitRecord.OriginalBarcode) && !processedBarcodes.Contains(splitRecord.OriginalBarcode))
+                {
+                    var originalStock = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+                        .FirstAsync(x => x.Barcode == splitRecord.OriginalBarcode && x.StockId == stockId);
+
+                    if (originalStock != null && originalStock.StockQuantity > 0)
+                    {
+                        // 鍘熸潯鐮佺殑鍥炲簱鏁伴噺搴旇鏄媶鍖呭悗鍓╀綑鐨勬暟閲�
+                        await ProcessBarcodeReturn(splitRecord.OriginalBarcode, stockId, originalStock.StockQuantity, processedBarcodes);
+                    }
+                }
+
+                // 鏇存柊鎷嗗寘璁板綍鐘舵�佷负宸插洖搴�
+                splitRecord.Status = (int)SplitPackageStatusEnum.宸插洖搴�;
+                await _splitPackageService.Db.Updateable(splitRecord).ExecuteCommandAsync();
+
+                _logger.LogInformation($"鎷嗗寘璁板綍鐘舵�佹洿鏂颁负宸插洖搴� - 璁板綍ID: {splitRecord.Id}");
+            }
+
+            _logger.LogInformation($"鎷嗗寘璁板綍鍥炲簱澶勭悊瀹屾垚");
+        }
+
+        /// <summary>
+        /// 绠�鍖栫増鍥炲簱鏂规硶 - 缁曡繃澶嶆潅楠岃瘉
+        /// </summary>
+        public async Task<WebResponseContent> SimplePalletReturn(string orderNo, string palletCode, string returnReason = "绠�鍖栧洖搴�")
+        {
+            try
+            {
+                _logger.LogInformation($"銆愮畝鍖栧洖搴撳紑濮嬨�戣鍗�: {orderNo}, 鎵樼洏: {palletCode}");
+
+                _unitOfWorkManage.BeginTran();
+
+                // 1. 鑾峰彇搴撳瓨淇℃伅锛堣烦杩囧鏉傞獙璇侊級
+                var stockInfo = await _stockInfoService.Db.Queryable<Dt_StockInfo>()
+                    .FirstAsync(x => x.PalletCode == palletCode);
+
+                if (stockInfo == null)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    return WebResponseContent.Instance.Error($"鏈壘鍒版墭鐩� {palletCode} 瀵瑰簲鐨勫簱瀛樹俊鎭�");
+                }
+
+                // 2. 鐩存帴鏌ユ壘闇�瑕佸洖搴撶殑鏉$爜锛堢畝鍖栭�昏緫锛�
+                var barcodesToReturn = await GetBarcodesForSimpleReturn(orderNo, palletCode, stockInfo.Id);
+
+                if (!barcodesToReturn.Any())
+                {                             
+                    try
+                    {
+                        _logger.LogInformation($"銆愭棤鍥炲簱鐗╁搧銆戝鐞嗙┖鎵樼洏");
+                        var result = await HandleEmptyPalletReturn(orderNo, palletCode, stockInfo);
+                        _unitOfWorkManage.CommitTran();
+                        return result;
+                    }
+                    catch (Exception ex)
+                    {
+                        _unitOfWorkManage.RollbackTran();
+                        _logger.LogError($"绌虹鍥炲簱澶辫触: {ex.Message}");
+                        return WebResponseContent.Instance.Error($"绌虹鍥炲簱澶辫触锛歿ex.Message}");
+                    }
+                }
+
+                // 3. 绠�鍖栧鐞嗘瘡涓潯鐮�
+                foreach (var barcode in barcodesToReturn)
+                {
+                    await ProcessSimpleBarcodeReturn(barcode, stockInfo.Id);
+                }
+
+                // 4. 鏇存柊璁㈠崟鐘舵�侊紙绠�鍖栵級
+                await UpdateOrderStatusAfterReturn(orderNo);
+
+
+                // 5. 鍒涘缓鍥炲簱浠诲姟
+                await CreateReturnTask(orderNo, palletCode, stockInfo);
+
+                _unitOfWorkManage.CommitTran();
+                return WebResponseContent.Instance.OK($"绠�鍖栧洖搴撴垚鍔燂紝澶勭悊 {barcodesToReturn.Count} 涓潯鐮�");
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                _logger.LogError($"绠�鍖栧洖搴撳け璐�: {ex.Message}");
+                return WebResponseContent.Instance.Error($"鍥炲簱澶辫触: {ex.Message}");
+            }
+        }
+        /// <summary>
+        /// 绠�鍖栬幏鍙栧洖搴撴潯鐮�
+        /// </summary>
+        private async Task<List<string>> GetBarcodesForSimpleReturn(string orderNo, string palletCode, int stockId)
+        {
+            var barcodes = new List<string>();
+
+            try
+            {
+                // 1. 浠庨攣瀹氳褰曡幏鍙�
+                var lockInfos = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+                    .Where(x => x.OrderNo == orderNo && x.PalletCode == palletCode)
+                    .Select(x => x.CurrentBarcode)
+                    .ToListAsync();
+
+                barcodes.AddRange(lockInfos.Where(b => !string.IsNullOrEmpty(b)));
+
+                // 2. 浠庡簱瀛樻槑缁嗚幏鍙�
+                var stockDetails = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+                    .Where(x => x.StockId == stockId && x.StockQuantity > 0)
+                    .Select(x => x.Barcode)
+                    .ToListAsync();
+
+                barcodes.AddRange(stockDetails.Where(b => !string.IsNullOrEmpty(b)));
+
+                // 鍘婚噸
+                return barcodes.Distinct().ToList();
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError($"鑾峰彇鍥炲簱鏉$爜澶辫触: {ex.Message}");
+                return barcodes;
+            }
+        }
+
+        /// <summary>
+        /// 绠�鍖栧鐞嗘潯鐮佸洖搴�
+        /// </summary>
+        private async Task ProcessSimpleBarcodeReturn(string barcode, int stockId)
+        {
+            try
+            {
+                // 1. 鑾峰彇搴撳瓨鏄庣粏
+                var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+                    .FirstAsync(x => x.Barcode == barcode && x.StockId == stockId);
+
+                if (stockDetail == null)
+                {
+                    _logger.LogWarning($"鏈壘鍒版潯鐮佸搴旂殑搴撳瓨鏄庣粏: {barcode}");
+                    return;
+                }
+
+                // 2. 濡傛灉鏄嚭搴撻攣瀹氱姸鎬侊紝鎭㈠涓哄叆搴撳畬鎴�
+                if (stockDetail.Status == (int)StockStatusEmun.鍑哄簱閿佸畾)
+                {
+                    stockDetail.Status = (int)StockStatusEmun.鍏ュ簱瀹屾垚;
+                    await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
+                    _logger.LogInformation($"鏉$爜鐘舵�佹仮澶� - {barcode}: 鍑哄簱閿佸畾 -> 鍏ュ簱瀹屾垚");
+                }
+
+                // 3. 鏇存柊鐩稿叧鐨勯攣瀹氳褰�
+                var lockInfos = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+                    .Where(x => x.CurrentBarcode == barcode &&
+                               (x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓� ||
+                                x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�))
+                    .ToListAsync();
+
+                foreach (var lockInfo in lockInfos)
+                {
+                    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($"澶勭悊鏉$爜鍥炲簱澶辫触 - 鏉$爜: {barcode}, Error: {ex.Message}");
+            }
+        }
         #endregion
 
         #region 杈呭姪鏂规硶
@@ -2831,9 +5088,6 @@
 
         #endregion
 
-
-
-
         #region 楠岃瘉鏂规硶
         private async Task<ValidationResult<(Dt_OutStockLockInfo, Dt_OutboundOrderDetail, Dt_StockInfoDetail, Dt_OutboundBatch)>> ValidatePickingRequest(
        string orderNo, string palletCode, string barcode)
@@ -2937,6 +5191,7 @@
                 _logger.LogInformation($"璺宠繃鏈垎閰嶉攣瀹氳褰曠殑鑷姩鎷嗗寘妫�鏌� - 閿佸畾ID: {lockInfo.Id}");
                 return null;
             }
+
             // 妫�鏌ユ槸鍚﹂渶瑕佽嚜鍔ㄦ媶鍖呯殑鏉′欢锛�
             // 1. 搴撳瓨鏁伴噺澶т簬鍒嗛厤鏁伴噺
             // 2. 閿佸畾淇℃伅鐘舵�佷负鍑哄簱涓�
@@ -2951,109 +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)
+            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}, 鏍囪涓烘湭鍒嗛厤");
-
-            // 鑷姩鎷嗗寘涓嶆敼鍙樿鍗曟槑缁嗙殑鍒嗛厤鏁伴噺
-            _logger.LogInformation($"鑷姩鎷嗗寘 - 璁㈠崟鏄庣粏鍒嗛厤鏁伴噺淇濇寔涓嶅彉");
-
-            // 璁板綍鎷嗗寘鍘嗗彶
-            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)
         {
@@ -3064,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�夊畬鎴�;
@@ -3132,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}");
 
@@ -3163,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)
@@ -3255,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);
@@ -3513,7 +5876,7 @@
             _logger.LogInformation($"CreateReturnTaskAndHandleESS  鍒嗘壒鍒犻櫎鍘嗗彶浠诲姟: {orderNo} 锛� {originalTask.TaskNum}");
             // 鍒犻櫎鍘熷鍑哄簱浠诲姟
             //_taskRepository.DeleteAndMoveIntoHty(originalTask, OperateTypeEnum.鑷姩瀹屾垚);
-           var result= _task_HtyService.DeleteAndMoveIntoHty(originalTask, OperateTypeEnum.浜哄伐鍒犻櫎);
+            var result = _task_HtyService.DeleteAndMoveIntoHty(originalTask, OperateTypeEnum.浜哄伐鍒犻櫎);
             await _taskRepository.Db.Deleteable(originalTask).ExecuteCommandAsync();
 
             if (!result)
@@ -3579,7 +5942,6 @@
                 throw new Exception($"ESS绯荤粺閫氫俊澶辫触: {ex.Message}");
             }
         }
-
 
         #region 杈呭姪鏂规硶
 
@@ -3668,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/OutboundOrderService.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/OutboundOrderService.cs"
index f8db1b6..63fed46 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/OutboundOrderService.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/OutboundOrderService.cs"
@@ -334,7 +334,7 @@
             }
             var data = BaseDal.Db.Queryable<Dt_OutboundOrder>()
                 .WhereIF(!wheres.IsNullOrEmpty(), wheres)
-                .Where(x => x.OrderType == 0 || x.OrderType == 116)
+                .Where(x => x.OrderType == 0)
                 .OrderBy(orderByModels)
                 .ToPageList(options.Page, options.Rows, ref totalCount);
 
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 6b06a77..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"
@@ -87,7 +87,7 @@
         public OutboundPickingService(IRepository<Dt_PickingRecord> BaseDal, IUnitOfWorkManage unitOfWorkManage, IStockInfoService stockInfoService, IStockService stockService,
             IOutStockLockInfoService outStockLockInfoService, IStockInfoDetailService stockInfoDetailService, ILocationInfoService locationInfoService,
             IOutboundOrderDetailService outboundOrderDetailService, ISplitPackageService splitPackageService, IOutboundOrderService outboundOrderService,
-            IRepository<Dt_Task> taskRepository, IESSApiService eSSApiService, ILogger<OutboundPickingService> logger, IInvokeMESService invokeMESService, IDailySequenceService dailySequenceService, IAllocateService allocateService, IRepository<Dt_InboundOrder> inboundOrderRepository, IInboundOrderDetailService inboundOrderDetailService, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IReCheckOrderService reCheckOrderService, ITask_HtyService task_HtyService,IRepository<Dt_InterfaceLog> interfaceLog) : base(BaseDal)
+            IRepository<Dt_Task> taskRepository, IESSApiService eSSApiService, ILogger<OutboundPickingService> logger, IInvokeMESService invokeMESService, IDailySequenceService dailySequenceService, IAllocateService allocateService, IRepository<Dt_InboundOrder> inboundOrderRepository, IInboundOrderDetailService inboundOrderDetailService, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IReCheckOrderService reCheckOrderService, ITask_HtyService task_HtyService, IRepository<Dt_InterfaceLog> interfaceLog) : base(BaseDal)
         {
             _unitOfWorkManage = unitOfWorkManage;
             _stockInfoService = stockInfoService;
@@ -304,7 +304,27 @@
 
                 var statusAnalysis = await AnalyzePalletStatus(orderNo, palletCode, stockInfo.Id);
                 if (!statusAnalysis.HasItemsToReturn)
-                    return await HandleNoReturnItems(orderNo, palletCode, task, stockInfo.Id);
+                {
+                    try
+                    {
+                        var result = await HandleNoReturnItems(orderNo, palletCode, task, stockInfo.Id);
+                        _unitOfWorkManage.CommitTran();
+                        if (result.Status)
+                        {
+                            task.PalletType = PalletTypeEnum.Empty.ObjToInt();
+                            await CreateReturnTaskAndHandleESS(orderNo, palletCode, task, TaskTypeEnum.InEmpty, PalletTypeEnum.Empty.ObjToInt());
+                        }
+                        return result;
+                    }
+                    catch (Exception ex)
+                    {
+                        _unitOfWorkManage.RollbackTran();
+                        _logger.LogError($"ReturnRemaining 鍥炲簱绌虹澶辫触 - OrderNo: {orderNo}, PalletCode: {palletCode}, Error: {ex.Message}");
+                        return WebResponseContent.Instance.Error($"鍥炲簱绌虹鎿嶄綔澶辫触: {ex.Message}");
+                    }
+
+
+                }
 
                 // 4. 妫�鏌ユ槸鍚︽湁杩涜涓殑浠诲姟
                 if (statusAnalysis.HasActiveTasks)
@@ -1314,8 +1334,6 @@
                 //绌烘墭鐩樺浣曞鐞�  杩樻湁涓�涓嚭搴撲换鍔¤澶勭悊銆�
                 originalTask.PalletType = PalletTypeEnum.Empty.ObjToInt();
 
-                await CreateReturnTaskAndHandleESS(orderNo, palletCode, originalTask, TaskTypeEnum.InEmpty, PalletTypeEnum.Empty.ObjToInt());
-
             }
             catch (Exception ex)
             {
@@ -1700,7 +1718,7 @@
                     throw new Exception("鍒涘缓浠诲姟澶辫触锛�");
                 }
             }
-            catch (Exception ex) 
+            catch (Exception ex)
             {
                 _logger.LogInformation($"CreateReturnTaskAndHandleESS 鍒涘缓浠诲姟澶辫触: {orderNo} 锛� {palletCode}");
                 throw new Exception("鍒涘缓浠诲姟澶辫触锛�");
@@ -2119,8 +2137,7 @@
                     .Where(x => x.StockId == stockId && x.StockQuantity == 0)
                     .ExecuteCommandAsync();
 
-                await _stockInfoService.Db.Deleteable<Dt_StockInfo>()
-                   .Where(x => x.Id == stockId).ExecuteCommandAsync();
+                _stockInfoService.DeleteData(stockId);
 
                 _logger.LogInformation($"娓呯悊闆跺簱瀛樻槑缁嗚褰� - StockId: {stockId}, 鍒犻櫎璁板綍鏁�: {deleteDetailCount}");
 
@@ -2937,7 +2954,7 @@
 
                     await _interfaceLog.Db.Updateable<Dt_InterfaceLog>()
                         .SetColumns(x => x.ReturnToMESStatus == 1)
-                        .Where(x=>x.DocumentNo == documentNo)
+                        .Where(x => x.DocumentNo == documentNo)
                         .ExecuteCommandAsync();
                 }
                 return WebResponseContent.Instance.OK();
@@ -3040,7 +3057,7 @@
                 if (materielGroupDTO.orderTypes == InOrderTypeEnum.ReCheck.ObjToInt())
                 {
                     var dborder = _reCheckOrderService.Db.Queryable<Dt_ReCheckOrder>().First(x => x.OrderNo == materielGroupDTO.OrderNo);
-                    if (dborder != null && dborder.SignSeq == 0)
+                    if (dborder != null && (dborder.SignSeq == 0 || dborder.SignSeq == 1))
                     {
                         return content.Error("鍙湁鎷垮埌閲嶆缁撴灉鎵嶈兘鍏ュ簱锛�");
                     }
@@ -3285,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/StockDetailByMaterielService.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/StockDetailByMaterielService.cs"
new file mode 100644
index 0000000..ea36886
--- /dev/null
+++ "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/StockDetailByMaterielService.cs"
@@ -0,0 +1,164 @@
+锘縰sing SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using WIDESEA_Core;
+using WIDESEA_Core.BaseRepository;
+using WIDESEA_Core.BaseServices;
+using WIDESEA_Core.Helper;
+using WIDESEA_DTO.Stock;
+using WIDESEA_IStockService;
+using WIDESEA_Model.Models;
+
+namespace WIDESEA_StockService
+{
+    public class StockDetailByMaterielService :IStockDetailByMaterielService
+    {
+        private readonly IUnitOfWorkManage _unitOfWorkManage;
+        private readonly SqlSugarClient _dbBase;
+
+        public StockDetailByMaterielService(IUnitOfWorkManage unitOfWorkManage)
+        {
+            _unitOfWorkManage = unitOfWorkManage;
+            _dbBase = unitOfWorkManage.GetDbClient();
+        }
+
+
+        public virtual PageGridData<StockDetailByMateriel> GetPageGridData(PageDataOptions options)
+        {
+            try
+            {
+
+                List<StockDetailByMateriel> materielnfoStatistics = new List<StockDetailByMateriel>();
+                ISugarQueryable<Dt_StockInfoDetail> sugarQueryable1 = _dbBase.Queryable<Dt_StockInfoDetail>();
+
+                ISugarQueryable<Dt_StockInfo> sugarQueryable = _dbBase.Queryable<Dt_StockInfo>();
+                if (!string.IsNullOrEmpty(options.Wheres))
+                {
+                    try
+                    {
+                        List<SearchParameters> searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
+                        if (searchParametersList.Count > 0)
+                        {
+                            {
+                                SearchParameters? searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_StockInfoDetail.MaterielCode).FirstLetterToLower());
+                                if (searchParameters != null)
+                                {
+                                    sugarQueryable1 = sugarQueryable1.Where(x => x.MaterielCode.Contains(searchParameters.Value));
+                                }
+                            }
+                            {
+                                SearchParameters? searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_StockInfo.WarehouseId).FirstLetterToLower());
+                                if (searchParameters != null)
+                                {
+                                    sugarQueryable = sugarQueryable.Where(x => x.WarehouseId.Equals(searchParameters.Value));
+                                }
+                            }
+                            {
+                                SearchParameters? searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_StockInfo.StockStatus).FirstLetterToLower());
+                                if (searchParameters != null)
+                                {
+                                    sugarQueryable = sugarQueryable.Where(x => x.StockStatus.Equals(searchParameters.Value));
+                                }
+                            }
+                            {
+                                SearchParameters? searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_StockInfoDetail.MaterielName).FirstLetterToLower());
+                                if (searchParameters != null)
+                                {
+                                    sugarQueryable1 = sugarQueryable1.Where(x => x.MaterielName.Contains(searchParameters.Value));
+                                }
+                            }
+
+                        }
+
+                    }
+                    catch (Exception ex)
+                    {
+
+                    }
+                }
+
+
+                ISugarQueryable<StockDetailByMateriel> sugarQueryable2 = sugarQueryable1.InnerJoin(sugarQueryable, (b, a) => b.StockId == a.Id).Where((b, a) => a.LocationCode != "" && a.LocationCode != null).Select((b, a)
+                    => new StockDetailByMateriel
+                    {
+                       StockId = b.StockId,
+                        MaterielCode = b.MaterielCode,
+                        MaterielName = b.MaterielName,
+                        StockQuantity = (decimal)b.StockQuantity,
+                        OutboundQuantity = (decimal)b.OutboundQuantity,
+                        OrderNo = b.OrderNo,
+                        BatchNo = b.BatchNo,
+                        SerialNumber = b.SerialNumber,
+                        SupplyCode = b.SupplyCode,
+                        WarehouseCode = b.WarehouseCode,
+                        Barcode = b.Barcode,
+                        Unit = b.Unit,
+                        Creater = b.Creater,
+                        CreateDate= b.CreateDate,
+                        Modifier = b.Modifier,
+                        ModifyDate = b.ModifyDate,
+                        Remark = a.Remark,
+
+                    });
+                // 鑾峰彇鎵�鏈夋暟鎹�
+                var allData = sugarQueryable2.ToList();
+
+                // 浣跨敤瀛楀吀杩涜鍒嗙粍姹囨��
+                var groupedData = new Dictionary<string, StockDetailByMateriel>();
+                foreach (var item in allData)
+                {
+                    // 纭繚鍒濆鍊间负decimal绫诲瀷
+                    if (groupedData.ContainsKey(item.MaterielCode))
+                    {
+                        groupedData[item.MaterielCode].StockQuantity += Convert.ToDecimal(item.StockQuantity);
+                        groupedData[item.MaterielCode].OutboundQuantity += Convert.ToDecimal(item.OutboundQuantity);
+                    }
+                    else
+                    {
+                        groupedData[item.MaterielCode] = new StockDetailByMateriel
+                        {
+                            StockId = item.StockId,
+                            MaterielCode = item.MaterielCode,
+                            MaterielName = item.MaterielName,
+                            StockQuantity = Convert.ToDecimal(item.StockQuantity),
+                            OutboundQuantity = Convert.ToDecimal(item.OutboundQuantity),
+                            OrderNo = item.OrderNo,
+                            BatchNo = item.BatchNo,
+                            SerialNumber = item.SerialNumber,
+                            SupplyCode = item.SupplyCode,
+                            WarehouseCode = item.WarehouseCode,
+                            Barcode = item.Barcode,
+                            Creater = item.Creater,
+                            CreateDate = item.CreateDate,
+                            Modifier = item.Modifier,
+                            ModifyDate = item.ModifyDate,
+                            Unit = item.Unit,
+                            Remark = item.Remark
+                        };
+                    }
+                }
+
+                // 杞崲涓哄垪琛�
+                materielnfoStatistics = groupedData.Values.ToList();
+
+                // 鍒嗛〉澶勭悊
+                int startIndex = (options.Page - 1) * options.Rows;
+                int endIndex = Math.Min(startIndex + options.Rows, materielnfoStatistics.Count);
+                materielnfoStatistics = materielnfoStatistics.GetRange(startIndex, endIndex - startIndex);
+
+                int count = groupedData.Count;
+
+                return new PageGridData<StockDetailByMateriel>(count, materielnfoStatistics);
+
+            }
+            catch (Exception ex)
+            {
+
+            }
+            return new PageGridData<StockDetailByMateriel>();
+        }
+    }
+}
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 89e548a..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"
@@ -114,6 +114,7 @@
                 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_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/Allocate/AllocateOrderDetailController.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/Allocate/AllocateOrderDetailController.cs"
index 7f0c236..e259237 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/Allocate/AllocateOrderDetailController.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/Allocate/AllocateOrderDetailController.cs"
@@ -1,5 +1,9 @@
-锘縰sing Microsoft.AspNetCore.Mvc;
+锘縰sing Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using WIDESEA_Core;
+using WIDESEA_Core.Attributes;
 using WIDESEA_Core.BaseController;
+using WIDESEA_DTO.Inbound;
 using WIDESEA_IAllocateService;
 using WIDESEA_Model.Models;
 
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/Inbound/InboundOrderController.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/Inbound/InboundOrderController.cs"
index d5dd7a6..5246ce1 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/Inbound/InboundOrderController.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/Inbound/InboundOrderController.cs"
@@ -93,21 +93,21 @@
 
             erpApiService.GetMaterialUnitAsync();
 
-            var sss = await _invokeMESService.NewMaterielToMes(new WIDESEA_DTO.Basic.MaterielToMesDTO
-            {
-                reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
-                reqCode = Guid.NewGuid().ToString(),
-                oldmaterialCode = "b001",
-                newmaterialCode = "Bar01",
-                unit = "A01",
-                operationType = 1,
-                supplyCode = "A0001",
-                batchNo = "A0002",
-                materialCode = "FC00001",
-                warehouseCode = "",
-                factoryArea = "A01",
-                qty =20,
-            });
+            //var sss = await _invokeMESService.NewMaterielToMes(new WIDESEA_DTO.Basic.MaterielToMesDTO
+            //{
+            //    reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+            //    reqCode = Guid.NewGuid().ToString(),
+            //    oldmaterialCode = "b001",
+            //    newmaterialCode = "Bar01",
+            //    unit = "A01",
+            //    operationType = 1,
+            //    supplyCode = "A0001",
+            //    batchNo = "A0002",
+            //    materialCode = "FC00001",
+            //    warehouseCode = "",
+            //    factoryArea = "A01",
+            //    qty =20,
+            //});
 
             //await _eSSApiService.MoveContainerAsync(new WIDESEA_DTO.Basic.MoveContainerRequest
             //{
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/Stock/StockDetailByMaterielController.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/Stock/StockDetailByMaterielController.cs"
new file mode 100644
index 0000000..27e5858
--- /dev/null
+++ "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/Stock/StockDetailByMaterielController.cs"
@@ -0,0 +1,26 @@
+锘縰sing Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using WIDESEA_Core;
+using WIDESEA_DTO.Stock;
+using WIDESEA_IStockService;
+using WIDESEA_Model.Models;
+using WIDESEA_StockService;
+
+namespace WIDESEA_WMSServer.Controllers.Stock
+{
+    [Route("api/StockDetailByMateriel")]
+    [Authorize, ApiController]
+    public class StockDetailByMaterielController:Controller
+    {
+        public readonly IStockDetailByMaterielService _stockDetailByMaterielService;
+        public StockDetailByMaterielController(IStockDetailByMaterielService stockDetailByMaterielService)
+        {
+            _stockDetailByMaterielService = stockDetailByMaterielService;
+        }
+        [HttpPost, Route("GetPageData")]
+        public PageGridData<StockDetailByMateriel> GetPageData([FromBody] PageDataOptions options)
+        {
+            return _stockDetailByMaterielService.GetPageGridData(options);
+        }
+    }
+}
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/Stock/StockInfoDetailController.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/Stock/StockInfoDetailController.cs"
index e5de3a4..e192624 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/Stock/StockInfoDetailController.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/Stock/StockInfoDetailController.cs"
@@ -1,10 +1,12 @@
-锘縰sing Microsoft.AspNetCore.Http;
+锘縰sing Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
 using WIDESEA_Core;
 using WIDESEA_Core.BaseController;
 using WIDESEA_DTO.Stock;
 using WIDESEA_IStockService;
 using WIDESEA_Model.Models;
+using WIDESEA_StockService;
 
 namespace WIDESEA_WMSServer.Controllers.Stock
 {
@@ -28,5 +30,6 @@
 
             return Json(result);
         }
+
     }
 }
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/Program.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/Program.cs"
index c284b28..ee35fae 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/Program.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/Program.cs"
@@ -1,5 +1,3 @@
-using System.Reflection;
-using System.Text;
 using Autofac;
 using Autofac.Core;
 using Autofac.Extensions.DependencyInjection;
@@ -11,7 +9,12 @@
 using Newtonsoft.Json;
 using Newtonsoft.Json.Converters;
 using Newtonsoft.Json.Serialization;
+using Quartz;
 using Serilog;
+using System.Net.Security;
+using System.Reflection;
+using System.Runtime.ConstrainedExecution;
+using System.Text;
 using WIDESEA_Core;
 using WIDESEA_Core.Authorization;
 using WIDESEA_Core.BaseServices;
@@ -22,7 +25,6 @@
 //using WIDESEA_Core.HostedService;
 using WIDESEA_Core.Middlewares;
 using WIDESEA_WMSServer.Filter;
-using Quartz;
 using WIDESEA_WMSServer.Jobs;
 
 var builder = WebApplication.CreateBuilder(args);
@@ -147,7 +149,7 @@
     client.BaseAddress = new Uri(erpurl!);
     client.Timeout = TimeSpan.FromSeconds(30);
 
-});
+})  ;
  
 builder.Services.AddQuartz(q =>
 {

--
Gitblit v1.9.3