From be438dd071400936c44a1425ec8d886f63c83329 Mon Sep 17 00:00:00 2001
From: wankeda <Administrator@DESKTOP-HAU3ST3>
Date: 星期五, 11 七月 2025 14:33:08 +0800
Subject: [PATCH] 1

---
 WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs | 1883 +++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 1,404 insertions(+), 479 deletions(-)

diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
index 92bdead..77ca387 100644
--- a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
+++ b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
@@ -17,6 +17,7 @@
 
 using AutoMapper;
 using MailKit.Search;
+using Microsoft.AspNetCore.SignalR;
 using Newtonsoft.Json;
 using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
 using Org.BouncyCastle.Asn1.Tsp;
@@ -32,13 +33,16 @@
 using System.Threading.Tasks;
 using WIDESEA_BasicRepository;
 using WIDESEA_Common;
+using WIDESEA_Common.TaskEnum;
 using WIDESEA_Core;
 using WIDESEA_Core.BaseRepository;
 using WIDESEA_Core.BaseServices;
 using WIDESEA_Core.Enums;
 using WIDESEA_Core.Helper;
+using WIDESEA_Core.TaskEnum;
 using WIDESEA_DTO.Inbound;
 using WIDESEA_DTO.Stock;
+using WIDESEA_DTO.Task;
 using WIDESEA_IBasicRepository;
 using WIDESEA_IBasicService;
 using WIDESEA_IInboundService;
@@ -80,10 +84,11 @@
         private readonly IInboundOrderDetail_HtyService _inboundOrderDetail_HtyService;
         private readonly IOutboundOrder_HtyService _outboundOrder_HtyService;
         private readonly IOutboundOrderDetail_HtyService _outboundOrderDetail_HtyService;
-
+        private readonly IPalletTypeInfoRepository _palletTypeInfoRepository;
+        private readonly IOutboundOrderDetailRepository _outboundOrderDetailRepository;
         public ITaskRepository Repository => BaseDal;
 
-        public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IMaterielInfoService materielInfoService, IInboundOrderDetail_HtyService inboundOrderDetail_HtyService, IOutboundOrder_HtyService outboundOrder_HtyService, IOutboundOrderDetail_HtyService outboundOrderDetail_HtyService, IInboundOrder_HtyService inboundOrder_HtyService, IStockRepository stockRepository, IInboundOrderDetailService inboundOrderDetailService, IBasicService basicService, IOutboundService outboundService, IInboundService inboundService, IRecordService recordService, IStockService stockService, ITask_HtyService taskHtyService, ILocationInfoService locationInfoService) : base(BaseDal)
+        public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IMaterielInfoService materielInfoService, IInboundOrderDetail_HtyService inboundOrderDetail_HtyService, IOutboundOrder_HtyService outboundOrder_HtyService, IOutboundOrderDetail_HtyService outboundOrderDetail_HtyService, IInboundOrder_HtyService inboundOrder_HtyService, IStockRepository stockRepository, IInboundOrderDetailService inboundOrderDetailService, IBasicService basicService, IOutboundService outboundService, IInboundService inboundService, IRecordService recordService, IStockService stockService, ITask_HtyService taskHtyService, ILocationInfoService locationInfoService, IOutboundOrderDetailRepository outboundOrderDetailRepository) : base(BaseDal)
         {
             _mapper = mapper;
             _stockRepository = stockRepository;
@@ -101,13 +106,65 @@
             _inboundOrderDetail_HtyService = inboundOrderDetail_HtyService;
             _outboundOrder_HtyService = outboundOrder_HtyService;
             _outboundOrderDetail_HtyService = outboundOrderDetail_HtyService;
-
+            _outboundOrderDetailRepository = outboundOrderDetailRepository;
         }
 
         public string ReceiveWMSTaskin = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskin"];
         public string ReceiveWMSTaskout = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskout"];
         public string ReceiveWMSTaskAUT = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskAUT"];
         public string ReceiveWMSTaskAllocatein = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskAllocatein"];
+
+
+        /// <summary>
+        /// 浠诲姟淇℃伅鎺ㄩ�佽嚦WCS
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent PushTasksToWCS(List<Dt_Task> tasks, string agvDescription = "")
+        {
+            try
+            {
+                List<WMSTaskDTO> taskDTOs = _mapper.Map<List<WMSTaskDTO>>(tasks);
+                taskDTOs.ForEach(x =>
+                {
+                    x.AGVArea = agvDescription;
+                });
+                string url = AppSettings.app("WCS");
+                if (string.IsNullOrEmpty(url))
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒癢CSApi鍦板潃,璇锋鏌ラ厤缃枃浠�");
+                }
+                string response = HttpHelper.Post($"{url}/api/Task/ReceiveTask", taskDTOs.Serialize());
+
+                return JsonConvert.DeserializeObject<WebResponseContent>(response) ?? WebResponseContent.Instance.Error("杩斿洖閿欒");
+            }
+            catch (Exception ex)
+            {
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+        /// <summary>
+        /// 鏀捐揣瀹屾垚
+        /// </summary>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public WebResponseContent PutFinish(string code)
+        {
+            try
+            {
+                string url = AppSettings.app("WCS");
+                if (string.IsNullOrEmpty(url))
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒癢CSAApi鍦板潃,璇锋鏌ラ厤缃枃浠�");
+                }
+                string response = HttpHelper.Post($"{url}/api/CTU_AGV/PutFinish?code=" + code);
+
+                return JsonConvert.DeserializeObject<WebResponseContent>(response) ?? WebResponseContent.Instance.Error("杩斿洖閿欒");
+            }
+            catch (Exception ex)
+            {
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
 
         /// <summary>
         /// 浠诲姟瀹屾垚
@@ -140,7 +197,140 @@
             }
 
         }
+        public WebResponseContent UpdateTaskStatus(int taskNum, int tasktype)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.TaskType == tasktype);
+                if (task == null) return WebResponseContent.Instance.Error("鏈壘鍒颁换鍔′俊鎭�");
+                if (TaskEnumHelper.GetTaskTypeGroup(task.TaskType) == TaskTypeGroup.InboundGroup)
+                {
+                    task.TaskStatus = TaskInStatusEnum.InFinish.ObjToInt();
+                    content = UpdateTaskStatusInFinish(task);
+                }
+            }
+            catch (Exception)
+            {
 
+                throw;
+            }
+            return content;
+        }
+
+        public WebResponseContent UpdateTaskStatusInFinish(Dt_Task task)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);//缁勭洏搴撳瓨
+                Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);//璐т綅
+                var result = CheckCompleted(stockInfo, locationInfo);
+                if (!result.Item1)
+                {
+                    throw new Exception(result.Item2);
+                }
+
+                if (stockInfo.StockStatus != StockStatusEmun.鍏ュ簱涓�.ObjToInt()) throw new Exception($"鎵樼洏[{task.PalletCode}],璇ョ粍鐩樼姸鎬佷笉鍙叆搴�");
+                Dt_StockInfoDetail stockInfoDetail = stockInfo.Details.FirstOrDefault(x => x.StockId == stockInfo.Id);
+
+                List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.Repository.LocationCodesGetStockInfos(new List<string> { stockInfo.LocationCode }).Where(x => x.StockStatus == (int)StockStatusEmun.宸插叆搴�.ObjToInt()).ToList();
+                if (task.TaskType == TaskTypeEnum.PalletInbound.ObjToInt())
+                {
+                    stockInfo.SerialNumber = stockInfos.Count + 1;
+                    stockInfo.InDate = DateTime.Now;
+                    stockInfo.StockStatus = StockStatusEmun.宸插叆搴�.ObjToInt();
+                    stockInfoDetail.Status = StockStatusEmun.宸插叆搴�.ObjToInt();
+                    locationInfo.LocationStatus = LocationStatusEnum.Pallet.ObjToInt();
+                    task.CurrentAddress = task.NextAddress;
+                    task.NextAddress = string.Empty;
+                    Db.Ado.BeginTran();
+                    BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
+                    _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
+                    _stockService.StockInfoService.Repository.UpdateData(stockInfo);
+                    _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail);
+                    Db.Ado.CommitTran();
+                    return content;
+                }
+                #region 鍏ュ簱鍗�
+                Dt_InboundOrder inboundOrder = _inboundService.InbounOrderService.GetInboundOrder(stockInfoDetail.OrderNo);
+                if (inboundOrder != null || inboundOrder.Details.Count < 1) throw new Exception($"鏈壘鍒版墭鐩榌{task.PalletCode}]鐨勫叆搴撳崟鏄庣粏淇℃伅");
+                Dt_InboundOrderDetail inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.BatchNo == stockInfoDetail.BatchNo && x.MaterielCode == stockInfoDetail.MaterielCode);
+                inboundOrderDetail.OrderDetailStatus = inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity ? OrderDetailStatusEnum.Over.ObjToInt() : OrderDetailStatusEnum.GroupAndInbound.ObjToInt();
+                if (inboundOrder.Details.FirstOrDefault(x => x.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt()) == null)
+                {
+                    inboundOrder.OrderStatus = InboundStatusEnum.鍏ュ簱瀹屾垚.ObjToInt();
+                }
+                else if (inboundOrder.OrderStatus == InboundStatusEnum.鏈紑濮�.ObjToInt())
+                {
+                    inboundOrder.OrderStatus = InboundStatusEnum.鍏ュ簱涓�.ObjToInt();
+                }
+                stockInfo.SerialNumber = stockInfos.Count + 1;
+                stockInfo.InDate = DateTime.Now;
+                stockInfo.StockStatus = StockStatusEmun.宸插叆搴�.ObjToInt();
+                stockInfoDetail.Status = StockStatusEmun.宸插叆搴�.ObjToInt();
+                locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+                task.CurrentAddress = task.NextAddress;
+                task.NextAddress = string.Empty;
+                Db.Ado.BeginTran();
+                #region 浠诲姟鍜屽叆搴撳崟
+                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
+                if (inboundOrder.OrderStatus != InboundStatusEnum.鍏ュ簱瀹屾垚.ObjToInt())
+                {
+                    _inboundService.InbounOrderService.Repository.UpdateData(inboundOrder);
+                    _inboundService.InboundOrderDetailService.Repository.UpdateData(inboundOrderDetail);
+                }
+                else
+                {
+                    List<Dt_InboundOrderDetail> orderDetails = inboundOrder.Details;
+                    inboundOrder.Details = null;
+                    _inboundService.InbounOrderService.Repository.DeleteAndMoveIntoHty(inboundOrder, OperateType.鑷姩瀹屾垚);
+                    _inboundService.InboundOrderDetailService.Repository.DeleteAndMoveIntoHty(orderDetails, OperateType.鑷姩瀹屾垚);
+                }
+                #endregion
+                _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
+                _stockService.StockInfoService.Repository.UpdateData(stockInfo);
+                _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail);
+                //_recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
+                Db.Ado.CommitTran();
+                SendInboundInfoToWMS(task, inboundOrder, stockInfoDetail);
+                #endregion
+            }
+            catch (Exception ex)
+            {
+                Db.Ado.RollbackTran();
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+
+        /// <summary>
+        /// 楠岃瘉鏁版嵁
+        /// </summary>
+        /// <param name="stockInfo"></param>
+        /// <param name="locationInfo"></param>
+        /// <returns></returns>
+        private (bool, string) CheckCompleted(Dt_StockInfo stockInfo, Dt_LocationInfo locationInfo, bool isCheckStockDetail = true)
+        {
+            if (stockInfo == null)
+            {
+                return (false, "鏈壘鍒扮粍鐩樹俊鎭�");
+            }
+
+            if (locationInfo == null)
+            {
+                return (false, "鏈壘鍒拌揣浣嶄俊鎭�");
+            }
+
+            if (isCheckStockDetail && (stockInfo.Details == null || stockInfo.Details.Count == 0))
+            {
+                return (false, "鏈壘鍒扮粍鐩樻槑缁嗕俊鎭�");
+            }
+
+            return (true, "鎴愬姛");
+        }
+
+        #region 鍏ュ簱浠诲姟瀹屾垚
         public WebResponseContent InboundTaskCompleted(int taskNum)
         {
             try
@@ -179,251 +369,18 @@
                 {
                     return WebResponseContent.Instance.Error($"璐т綅鐘舵�佷笉姝g‘");
                 }
-                int lastStatus = dt_LocationInfo.LocationStatus;
-                dt_LocationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+                //int lastStatus = dt_LocationInfo.LocationStatus;
+                //dt_LocationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
                 Dt_Warehouse warehouse = _basicService.WarehouseService.Repository.QueryFirst(x => x.WarehouseId == task.WarehouseId);
 
                 dt_StockInfo.LocationCode = dt_LocationInfo.LocationCode;
 
 
-                Dt_InboundOrder? inboundOrder = _inboundService.InbounOrderService.Db.Queryable<Dt_InboundOrder>().Where(x => x.InboundOrderNo == dt_StockInfo.Details.FirstOrDefault().OrderNo).Includes(x => x.Details).First();
+                Dt_InboundOrder? inboundOrder = _inboundService.InbounOrderService.Db.Queryable<Dt_InboundOrder>().Where(x => x.OrderNo == dt_StockInfo.Details.FirstOrDefault().OrderNo).Includes(x => x.Details).First();
                 Dt_InboundOrderDetail? inboundOrderDetail = null;
-                //鍒ゆ柇鍗曟嵁绫诲瀷鏄叆搴撹繕鏄皟鎷ㄥ叆搴撱�傘�傘�傚叆搴�
-                if (inboundOrder.OrderType == 0 && inboundOrder != null && dt_StockInfo.StockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt())
-                {
-                    #region //鍒ゆ柇鍏ュ簱鍗曟嵁鏄庣粏鍙湁鏈�鍚庝竴鏉″畬鎴愭椂鍒犻櫎鍏ュ簱鍗�
-                    //鏌ヨ鍘熷畬鎴愮殑鍏ュ簱鏄庣粏鏁伴噺
-                    int overCount = inboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).ToList().Count;
-                    //鏄庣粏id鏌ヨ
-                    inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.LinId == dt_StockInfo.Details.FirstOrDefault()?.LinId);
-                    foreach (var item in dt_StockInfo.Details)
-                    {
-                        if (inboundOrderDetail == null)
-                        {
-                            continue;
-                        }
-                        inboundOrderDetail.OverInQuantity += item.StockQuantity;
-                        if (inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity)
-                        {
-                            inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
-                            overCount += 1;
-                        }
-                        else if (inboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt())
-                        {
-                            inboundOrderDetail.OrderDetailStatus = InboundStatusEnum.鍏ュ簱涓�.ObjToInt();
-                        }
-                    }
-                    dt_StockInfo.Details.ForEach(x =>
-                    {
-                        x.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
-                    });
 
-                    _unitOfWorkManage.BeginTran();
-                    task.TaskStatus = InTaskStatusEnum.InFinish.ObjToInt();
-                    BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateType.浜哄伐瀹屾垚 : OperateType.鑷姩瀹屾垚);
-
-                    _basicService.LocationInfoService.Repository.UpdateData(dt_LocationInfo);
-                    _stockRepository.StockInfoRepository.UpdateData(dt_StockInfo);
-                    _stockRepository.StockInfoDetailRepository.UpdateData(dt_StockInfo.Details);
-                    _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(dt_LocationInfo, lastStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
-                    _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(dt_StockInfo, dt_StockInfo.Details, dt_StockInfo.Details.Sum(x => x.StockQuantity), dt_StockInfo.Details.Sum(x => x.StockQuantity), StockChangeType.Inbound, task.TaskNum);
-                    if (inboundOrder != null)
-                    {
-                        _inboundService.InbounOrderService.UpdateData(inboundOrder);
-                        _inboundService.InboundOrderDetailService.UpdateData(inboundOrderDetail);
-                    }
-                    _unitOfWorkManage.CommitTran();
-
-
-
-
-                    if (inboundOrder.Details.Count == 1)
-                    {
-                        var stockInfoDetail = dt_StockInfo.Details.FirstOrDefault();
-                        //    Dt_InboundOrder_Hty inboundOrder_Hty = new Dt_InboundOrder_Hty
-                        //    {
-                        //        OrderStatus = inboundOrder.OrderStatus,
-                        //        CreateType = inboundOrder.CreateType,
-                        //        //SourceId = oldOutboundOrder.SourceId,
-                        //        UpperOrderNo = inboundOrder.UpperOrderNo,
-                        //        OrderNo = inboundOrder.OrderNo,
-                        //        //OutWareHouse = inboundOrder.OutWareHouse,
-                        //        TransactionCode = inboundOrder.TransactionCode,
-                        //        InoutType = inboundOrder.InoutType,
-                        //        OrderType = inboundOrder.OrderType,
-                        //        Creater = "WMS",
-                        //        CreateDate = DateTime.Now,
-                        //    };
-                        //    //_inboundOrder_HtyService.AddData(inboundOrder_Hty);
-                        //    //_inboundService.InbounOrderService.DeleteData(inboundOrder);
-                        //}
-                        //Dt_InboundOrderDetail_Hty dt_InboundOrderDetail_Hty = new Dt_InboundOrderDetail_Hty
-                        //{
-                        //    OrderId = inboundOrderDetail.OrderId,
-                        //    MaterielCode = inboundOrderDetail.MaterielCode,
-                        //    MaterielName = inboundOrderDetail.MaterielName,
-                        //    BatchNo = inboundOrderDetail.BatchNo,
-                        //    OrderQuantity = inboundOrderDetail.OrderQuantity,
-                        //    ReceiptQuantity = inboundOrderDetail.ReceiptQuantity,
-                        //    OverInQuantity = inboundOrderDetail.OverInQuantity,
-                        //    OrderDetailStatus = inboundOrderDetail.OrderDetailStatus,
-                        //    Creater = "WMS",
-                        //    CreateDate = DateTime.Now,
-                        //};
-                        //_inboundOrderDetail_HtyService.AddData(dt_InboundOrderDetail_Hty);
-                        //_inboundService.InboundOrderDetailService.DeleteData(inboundOrderDetail);
-                        #endregion
-                        #region//鍏ュ簱淇℃伅杩斿洖涓婁綅WMS銆傘�傜珛搴撳叆搴撴暟閲忓洖浼�
-                        HouseInboundPassBack houseInboundPassBack = new HouseInboundPassBack();
-                        houseInboundPassBack.ApiType = "AsnController";
-                        houseInboundPassBack.Method = "AsrsGroudingAsn";
-                        data data = new data();
-                        data.data1 data1 = new data.data1();
-                        data1.AsnNo = task.OrderNo;
-                        data1.InWarehouse = task.Roadway;
-                        data1.TransactionCode = inboundOrder.TransactionCode;
-                        data1.InoutType = inboundOrder.OrderType;
-                        data1.OrderType = inboundOrder.InoutType;
-                        data.data1.Inbound inbound = new data.data1.Inbound
-                        {
-                            LinId = stockInfoDetail.LinId,
-                            MaterielCode = stockInfoDetail.MaterielCode,
-                            OrderQuantity = stockInfoDetail.StockQuantity,
-                            BatchNo = stockInfoDetail.BatchNo,
-                            FinishQty = stockInfoDetail.StockQuantity,
-                            LocationName = task.TargetAddress
-                        };
-                        data.Value.Add(data1);
-                        data1.DetailList.Add(inbound);
-                        houseInboundPassBack.Parameters.Add(data);
-                        Authentication authentication = new Authentication()
-                        {
-                            ApiType = "AuthenticationController",
-                            Parameters = new List<Parameter>
-                {
-                     new Parameter { Value = "LKAdmin"},
-                     new Parameter { Value = "LKAdmin"},
-                },
-                            Method = "Login",
-                        };
-                        var responses1 = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAUT, authentication, "鐧诲綍WMS璐﹀彿");
-                        var Ticket = responses1.Context["Ticket"].ToString();
-                        var InvOrgId = responses1.Context["InvOrgId"].ToString();
-                        if (Ticket != null)
-                        {
-                            houseInboundPassBack.Context = new Dictionary<string, string>();
-                            houseInboundPassBack.Context.Add("Ticket", Ticket);
-                            houseInboundPassBack.Context.Add("InvOrgId", InvOrgId);
-                            var responses = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskin, houseInboundPassBack, "绔嬪簱鍏ュ簱鏁伴噺鍥炰紶WMS");
-                        }
-                        #endregion
-                    }
-                }
-                else
-                {
-                    #region //鍒ゆ柇璋冩嫧鍏ュ簱鍗曟嵁鏄庣粏鍙湁鏈�鍚庝竴鏉″畬鎴愭椂鍒犻櫎鍏ュ簱鍗曞苟涓�娆¤繑鍥炲叆搴撴槑缁嗕俊鎭�
-                    if (inboundOrder.Details.Count == 1)
-                    {
-                        List<Dt_StockInfo> StockInfo = _stockService.StockInfoService.Repository.QueryData(x => x.BatchNo == inboundOrderDetail.BatchNo);
-                        Dt_InboundOrder_Hty inboundOrder_Hty = new Dt_InboundOrder_Hty
-                        {
-                            OrderStatus = inboundOrder.OrderStatus,
-                            CreateType = inboundOrder.CreateType,
-                            //SourceId = oldOutboundOrder.SourceId,
-                            UpperOrderNo = inboundOrder.UpperOrderNo,
-                            OrderNo = inboundOrder.OrderNo,
-                            //OutWareHouse = inboundOrder.OutWareHouse,
-                            TransactionCode = inboundOrder.TransactionCode,
-                            InoutType = inboundOrder.InoutType,
-                            OrderType = inboundOrder.OrderType,
-                            Creater = "WMS",
-                            CreateDate = DateTime.Now,
-                        };
-                        _inboundOrder_HtyService.AddData(inboundOrder_Hty);
-                        _inboundService.InbounOrderService.DeleteData(inboundOrder);
-                        Dt_InboundOrderDetail_Hty dt_InboundOrderDetail_HtyS = new Dt_InboundOrderDetail_Hty
-                        {
-                            OrderId = inboundOrderDetail.OrderId,
-                            MaterielCode = inboundOrderDetail.MaterielCode,
-                            MaterielName = inboundOrderDetail.MaterielName,
-                            BatchNo = inboundOrderDetail.BatchNo,
-                            OrderQuantity = inboundOrderDetail.OrderQuantity,
-                            ReceiptQuantity = inboundOrderDetail.ReceiptQuantity,
-                            OverInQuantity = inboundOrderDetail.OverInQuantity,
-                            OrderDetailStatus = inboundOrderDetail.OrderDetailStatus,
-                            Creater = "WMS",
-                            CreateDate = DateTime.Now,
-                        };
-                        _inboundOrderDetail_HtyService.AddData(dt_InboundOrderDetail_HtyS);
-                        _inboundService.InboundOrderDetailService.DeleteData(inboundOrderDetail);
-                        #endregion
-                        #region//璋冩嫧浠诲姟鏁伴噺鍥炰紶WMS
-                        InventoryAllocate inventoryAllocate = new InventoryAllocate();
-                        inventoryAllocate.ApiType = "InventoryAllocateController";
-                        inventoryAllocate.Method = "AsrsFinishedStockCount";
-
-                        Allocate allocate = new Allocate();
-
-                        Allocate.data1 data1 = new Allocate.data1();
-                        data1.No = task.OrderNo;
-                        data1.InWarehouse = task.Roadway;
-                        data1.TransactionCode = inboundOrder.TransactionCode;
-                        data1.InoutType = inboundOrder.OrderType;
-                        data1.OrderType = inboundOrder.InoutType;
-                        foreach (var item in StockInfo)
-                        {
-                            Dt_StockInfoDetail detail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == item.Id);
-                            Allocate.data1.Inventory inbound = new Allocate.data1.Inventory();
-                            inbound.LinId = detail.LinId;
-                            inbound.LPN_No = item.PalletCode;
-                            inbound.MaterielCode = detail.MaterielCode;
-                            inbound.OrderQuantity = detail.StockQuantity;
-                            inbound.BatchNo = detail.BatchNo;
-                            inbound.FinishQty = detail.StockQuantity;
-                            inbound.LocationName = item.LocationCode;
-                            data1.DetailList.Add(inbound);
-                        }
-                        allocate.Value.Add(data1);
-                        inventoryAllocate.Parameters.Add(allocate);
-                        Authentication authentication = new Authentication()
-                        {
-                            ApiType = "AuthenticationController",
-                            Parameters = new List<Parameter>
-                    {
-                     new Parameter { Value = "LKAdmin"},
-                     new Parameter { Value = "LKAdmin"},
-                    },
-                            Method = "Login",
-                        };
-                        var responses1 = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAUT, authentication, "鐧诲綍WMS璐﹀彿");
-                        var Ticket = responses1.Context["Ticket"].ToString();
-                        var InvOrgId = responses1.Context["InvOrgId"].ToString();
-                        if (Ticket != null)
-                        {
-                            inventoryAllocate.Context = new Dictionary<string, string>();
-                            inventoryAllocate.Context.Add("Ticket", Ticket);
-                            inventoryAllocate.Context.Add("InvOrgId", InvOrgId);
-                            var responses = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAllocatein, inventoryAllocate, "璋冩嫧鍏ュ簱鏁伴噺鍥炰紶WMS");
-                        }
-                    }
-                    #endregion
-                    Dt_InboundOrderDetail_Hty dt_InboundOrderDetail_Hty = new Dt_InboundOrderDetail_Hty
-                    {
-                        OrderId = inboundOrderDetail.OrderId,
-                        MaterielCode = inboundOrderDetail.MaterielCode,
-                        MaterielName = inboundOrderDetail.MaterielName,
-                        BatchNo = inboundOrderDetail.BatchNo,
-                        OrderQuantity = inboundOrderDetail.OrderQuantity,
-                        ReceiptQuantity = inboundOrderDetail.ReceiptQuantity,
-                        OverInQuantity = inboundOrderDetail.OverInQuantity,
-                        OrderDetailStatus = inboundOrderDetail.OrderDetailStatus,
-                        Creater = "WMS",
-                        CreateDate = DateTime.Now,
-                    };
-                    _inboundOrderDetail_HtyService.AddData(dt_InboundOrderDetail_Hty);
-                    _inboundService.InboundOrderDetailService.DeleteData(inboundOrderDetail);
-                }
-                return WebResponseContent.Instance.OK();
+                // 3. 澶勭悊鍏ュ簱閫昏緫
+                return ProcessInbound(task, dt_StockInfo, dt_LocationInfo);
             }
             catch (Exception ex)
             {
@@ -432,250 +389,382 @@
             }
         }
 
+        private WebResponseContent ProcessInbound(Dt_Task task, Dt_StockInfo stockInfo, Dt_LocationInfo locationInfo)
+        {
+            int lastStatus = locationInfo.LocationStatus;
+            locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+
+            Dt_InboundOrder inboundOrder = _inboundService.InbounOrderService.Db.Queryable<Dt_InboundOrder>()
+                .Where(x => x.OrderNo == stockInfo.Details.FirstOrDefault().OrderNo)
+                .Includes(x => x.Details)
+                .First();
+
+            if (inboundOrder == null) return WebResponseContent.Instance.Error("鏈壘鍒板叆搴撳崟淇℃伅");
+
+            Dt_InboundOrderDetail inboundOrderDetail = inboundOrder.Details
+                .FirstOrDefault(x => x.LinId == stockInfo.Details.FirstOrDefault()?.LinId);
+
+            if (inboundOrder.OrderType == 0 && inboundOrder != null && stockInfo.StockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt())
+            {
+                //鍏ュ簱鏁伴噺鍥炰紶
+                return ProcessNormalInbound(task, stockInfo, locationInfo, lastStatus, inboundOrder, inboundOrderDetail);
+            }
+            else
+            {
+                //璋冩嫧鍑哄叆搴撲换鍔℃暟閲忓洖浼�
+                return ProcessAllocateInbound(task, stockInfo, locationInfo, lastStatus, inboundOrder, inboundOrderDetail);
+            }
+        }
+
+        private WebResponseContent ProcessNormalInbound(Dt_Task task, Dt_StockInfo stockInfo, Dt_LocationInfo locationInfo,
+            int lastStatus, Dt_InboundOrder inboundOrder, Dt_InboundOrderDetail inboundOrderDetail)
+        {
+            // 鏇存柊鍏ュ簱鍗曟槑缁嗙姸鎬�
+            UpdateInboundOrderDetails(stockInfo, inboundOrder, ref inboundOrderDetail);
+
+            // 鏇存柊搴撳瓨鏄庣粏鐘舵��
+            stockInfo.Details.ForEach(x => x.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt());
+
+            try
+            {
+                _unitOfWorkManage.BeginTran();
+
+                // 鏇存柊浠诲姟鐘舵��
+                UpdateTaskStatus(task);
+
+                // 鏇存柊璐т綅鐘舵��
+                UpdateLocationStatus(locationInfo, lastStatus);
+
+                // 鏇存柊搴撳瓨淇℃伅
+                UpdateStockInfo(stockInfo);
+
+                // 娣诲姞璁板綍
+                AddRecords(task, stockInfo, locationInfo, lastStatus);
+
+                // 鏇存柊鍏ュ簱鍗�
+                UpdateInboundOrder(inboundOrder, inboundOrderDetail);
+
+                // 濡傛灉鏄渶鍚庝竴鏉℃槑缁嗭紝澶勭悊WMS鍥炰紶
+                if (inboundOrder.Details.Count == 1)
+                {
+                    var stockInfoDetail = stockInfo.Details.FirstOrDefault();
+                    SendInboundInfoToWMS(task, inboundOrder, stockInfoDetail);
+                }
+
+                _unitOfWorkManage.CommitTran();
+                return WebResponseContent.Instance.OK();
+            }
+            catch
+            {
+                _unitOfWorkManage.RollbackTran();
+                throw;
+            }
+        }
+
+        private WebResponseContent ProcessAllocateInbound(Dt_Task task, Dt_StockInfo stockInfo, Dt_LocationInfo locationInfo,
+            int lastStatus, Dt_InboundOrder inboundOrder, Dt_InboundOrderDetail inboundOrderDetail)
+        {
+            // 濡傛灉鏄渶鍚庝竴鏉℃槑缁�
+            if (inboundOrder.Details.Count == 1)
+            {
+                try
+                {
+                    _unitOfWorkManage.BeginTran();
+
+                    // 澶勭悊璋冩嫧鍏ュ簱鍗�
+                    //ProcessAllocateInboundOrder(inboundOrder, inboundOrderDetail);
+
+                    // 鑾峰彇鐩稿叧搴撳瓨淇℃伅
+                    var relatedStockInfo = _stockService.StockInfoService.Repository
+                        .QueryData(x => x.BatchNo == inboundOrderDetail.BatchNo);
+
+                    // 鍙戦�佽皟鎷ㄤ俊鎭埌WMS
+                    SendAllocateInfoToWMS(task, inboundOrder, relatedStockInfo);
+
+                    _unitOfWorkManage.CommitTran();
+                }
+                catch
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    throw;
+                }
+            }
+
+            // 娣诲姞鍘嗗彶璁板綍
+            AddInboundOrderDetailHistory(inboundOrderDetail);
+
+            return WebResponseContent.Instance.OK();
+        }
+
+        #region Helper Methods
+
+        private void UpdateInboundOrderDetails(Dt_StockInfo stockInfo, Dt_InboundOrder inboundOrder,
+            ref Dt_InboundOrderDetail inboundOrderDetail)
+        {
+            int overCount = inboundOrder.Details.Count(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt());
+            inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.LinId == stockInfo.Details.FirstOrDefault()?.LinId);
+
+            foreach (var item in stockInfo.Details)
+            {
+                if (inboundOrderDetail == null) continue;
+
+                inboundOrderDetail.OverInQuantity += item.StockQuantity;
+
+                if (inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity)
+                {
+                    inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
+                    overCount++;
+                }
+                else if (inboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt())
+                {
+                    inboundOrderDetail.OrderDetailStatus = InboundStatusEnum.鍏ュ簱涓�.ObjToInt();
+                }
+            }
+        }
+
+        private void UpdateTaskStatus(Dt_Task task)
+        {
+            task.TaskStatus = InTaskStatusEnum.InFinish.ObjToInt();
+            BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateType.浜哄伐瀹屾垚 : OperateType.鑷姩瀹屾垚);
+        }
+
+        private void UpdateLocationStatus(Dt_LocationInfo locationInfo, int lastStatus)
+        {
+            _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
+        }
+
+        private void UpdateStockInfo(Dt_StockInfo stockInfo)
+        {
+            _stockRepository.StockInfoRepository.UpdateData(stockInfo);
+            _stockRepository.StockInfoDetailRepository.UpdateData(stockInfo.Details);
+        }
+
+        private void AddRecords(Dt_Task task, Dt_StockInfo stockInfo, Dt_LocationInfo locationInfo, int lastStatus)
+        {
+            _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(
+                locationInfo, lastStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
+
+            _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(
+                stockInfo, stockInfo.Details,
+                stockInfo.Details.Sum(x => x.StockQuantity),
+                stockInfo.Details.Sum(x => x.StockQuantity),
+                StockChangeType.Inbound, task.TaskNum);
+        }
+
+        private void UpdateInboundOrder(Dt_InboundOrder inboundOrder, Dt_InboundOrderDetail inboundOrderDetail)
+        {
+            if (inboundOrder != null)
+            {
+                _inboundService.InbounOrderService.UpdateData(inboundOrder);
+                _inboundService.InboundOrderDetailService.UpdateData(inboundOrderDetail);
+            }
+        }
+
+        private void SendInboundInfoToWMS(Dt_Task task, Dt_InboundOrder inboundOrder, Dt_StockInfoDetail stockInfoDetail)
+        {
+            if (stockInfoDetail == null) return;
+
+            var houseInboundPassBack = new HouseInboundPassBack
+            {
+                ApiType = "AsnController",
+                Method = "AsrsGroudingAsn",
+                Parameters = new List<HouseInboundPassBack.data>
+        {
+            new HouseInboundPassBack.data
+            {
+                Value = new List<data.data1>
+                {
+                    new data.data1
+                    {
+                        AsnNo = task.OrderNo,
+                        InWarehouse = task.Roadway,
+                        TransactionCode = inboundOrder.TransactionCode,
+                        InoutType = inboundOrder.OrderType,
+                        OrderType = inboundOrder.InoutType,
+                        DetailList = new List<data.data1.Inbound>
+                        {
+                            new data.data1.Inbound
+                            {
+                                LinId = stockInfoDetail.LinId,
+                                MaterielCode = stockInfoDetail.MaterielCode,
+                                OrderQuantity = stockInfoDetail.StockQuantity,
+                                BatchNo = stockInfoDetail.BatchNo,
+                                FinishQty = stockInfoDetail.StockQuantity,
+                                LocationName = task.TargetAddress
+                            }
+                        }
+                    }
+                }
+            }
+        }
+            };
+
+            var authResult = AuthenticateWithWMS();
+            if (authResult.IsSuccess)
+            {
+                houseInboundPassBack.Context = new Dictionary<string, string>
+        {
+            { "Ticket", authResult.Ticket },
+            { "InvOrgId", authResult.InvOrgId }
+        };
+
+                HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskin, houseInboundPassBack, "绔嬪簱鍏ュ簱鏁伴噺鍥炰紶WMS");
+            }
+        }
+
+        private void ProcessAllocateInboundOrder(Dt_InboundOrder inboundOrder, Dt_InboundOrderDetail inboundOrderDetail)
+        {
+            // 娣诲姞鍘嗗彶璁板綍
+            var history = new Dt_InboundOrder_Hty
+            {
+                OrderStatus = inboundOrder.OrderStatus,
+                CreateType = inboundOrder.CreateType,
+                UpperOrderNo = inboundOrder.UpperOrderNo,
+                OrderNo = inboundOrder.OrderNo,
+                TransactionCode = inboundOrder.TransactionCode,
+                InoutType = inboundOrder.InoutType,
+                OrderType = inboundOrder.OrderType,
+                Creater = "WMS",
+                CreateDate = DateTime.Now,
+            };
+            _inboundOrder_HtyService.AddData(history);
+
+            // 娣诲姞鏄庣粏鍘嗗彶璁板綍
+            var detailHistory = new Dt_InboundOrderDetail_Hty
+            {
+                OrderId = inboundOrderDetail.OrderId,
+                MaterielCode = inboundOrderDetail.MaterielCode,
+                MaterielName = inboundOrderDetail.MaterielName,
+                BatchNo = inboundOrderDetail.BatchNo,
+                OrderQuantity = inboundOrderDetail.OrderQuantity,
+                ReceiptQuantity = inboundOrderDetail.ReceiptQuantity,
+                OverInQuantity = inboundOrderDetail.OverInQuantity,
+                OrderDetailStatus = inboundOrderDetail.OrderDetailStatus,
+                Creater = "WMS",
+                CreateDate = DateTime.Now,
+            };
+            _inboundOrderDetail_HtyService.AddData(detailHistory);
+
+            // 鍒犻櫎鍘熸暟鎹�
+            _inboundService.InbounOrderService.DeleteData(inboundOrder);
+            _inboundService.InboundOrderDetailService.DeleteData(inboundOrderDetail);
+        }
+
+        private void SendAllocateInfoToWMS(Dt_Task task, Dt_InboundOrder inboundOrder, List<Dt_StockInfo> stockInfos)
+        {
+
+            var detail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == stockInfos.FirstOrDefault().Id);
+            var inventoryAllocate = new InventoryAllocate
+            {
+                ApiType = "AsnController",
+                Method = "AsrsGroudingAsn",
+                Parameters = new List<InventoryAllocate.Allocate>
+        {
+             new InventoryAllocate.Allocate
+            {
+                Value = new List<Allocate.data1>
+                {
+                    new Allocate.data1
+                    {
+                        No = task.OrderNo,
+                        InWarehouse = task.Roadway,
+                        TransactionCode = inboundOrder.TransactionCode,
+                        InoutType = inboundOrder.OrderType,
+                        OrderType = inboundOrder.InoutType,
+                        DetailList = new List<Allocate.data1.Inventory>
+                        {
+                            new Allocate.data1.Inventory
+                            {
+                                LinId = detail.LinId,
+                                MaterielCode = detail.MaterielCode,
+                                OrderQuantity = detail.StockQuantity,
+                                BatchNo = detail.BatchNo,
+                                FinishQty = detail.StockQuantity,
+                                LocationName = task.TargetAddress
+                            }
+                        }
+                    }
+                }
+            }
+        }
+            };
+
+            var authResult = AuthenticateWithWMS();
+            if (authResult.IsSuccess)
+            {
+                inventoryAllocate.Context = new Dictionary<string, string>
+        {
+            { "Ticket", authResult.Ticket },
+            { "InvOrgId", authResult.InvOrgId }
+        };
+
+                HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAllocatein, inventoryAllocate, "璋冩嫧鍏ュ簱鏁伴噺鍥炰紶WMS");
+            }
+        }
+
+        private void AddInboundOrderDetailHistory(Dt_InboundOrderDetail inboundOrderDetail)
+        {
+            var history = new Dt_InboundOrderDetail_Hty
+            {
+                OrderId = inboundOrderDetail.OrderId,
+                MaterielCode = inboundOrderDetail.MaterielCode,
+                MaterielName = inboundOrderDetail.MaterielName,
+                BatchNo = inboundOrderDetail.BatchNo,
+                OrderQuantity = inboundOrderDetail.OrderQuantity,
+                ReceiptQuantity = inboundOrderDetail.ReceiptQuantity,
+                OverInQuantity = inboundOrderDetail.OverInQuantity,
+                OrderDetailStatus = inboundOrderDetail.OrderDetailStatus,
+                Creater = "WMS",
+                CreateDate = DateTime.Now,
+            };
+            _inboundOrderDetail_HtyService.AddData(history);
+            _inboundService.InboundOrderDetailService.DeleteData(inboundOrderDetail);
+        }
+
+        private (bool IsSuccess, string Ticket, string InvOrgId) AuthenticateWithWMS()
+        {
+            var authentication = new Authentication
+            {
+                ApiType = "AuthenticationController",
+                Parameters = new List<Parameter>
+        {
+            new Parameter { Value = "LKAdmin" },
+            new Parameter { Value = "LKAdmin" }
+        },
+                Method = "Login",
+            };
+
+            var response = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAUT, authentication, "鐧诲綍WMS璐﹀彿");
+
+            if (response.Status && response.Context != null)
+            {
+                return (true, response.Context["Ticket"].ToString(), response.Context["InvOrgId"].ToString());
+            }
+
+            return (false, null, null);
+        }
+
+        #endregion
+        #endregion
+
+
+
+
+        #region//鍑哄簱浠诲姟瀹屾垚
         public WebResponseContent OutboundTaskCompleted(int taskNum)
         {
             try
             {
-                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
-                if (task == null)
-                {
-                    return WebResponseContent.Instance.Error($"鏈壘鍒颁换鍔′俊鎭�");
-                }
+                // 1. 楠岃瘉浠诲姟鍜岃幏鍙栧熀纭�鏁版嵁
+                var validationResult = ValidateAndGetBaseData(taskNum, out var task, out var stockInfo,
+                    out var locationInfo, out var outStockLockInfos);
+                if (!validationResult.Status) return validationResult;
 
-                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
+                // 2. 澶勭悊鍑哄簱璁㈠崟璇︽儏
+                var outboundOrderDetails = ProcessOutboundOrderDetails(outStockLockInfos);
 
-                Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress);
-                if (stockInfo == null)
-                {
-                    return WebResponseContent.Instance.Error($"鏈壘鍒板簱瀛樹俊鎭�");
-                }
-                if (locationInfo == null)
-                {
-                    return WebResponseContent.Instance.Error($"鏈壘鍒拌揣浣嶄俊鎭�");
-                }
-
-                List<Dt_OutStockLockInfo> outStockLockInfos = _outboundService.OutboundStockLockInfoService.Repository.QueryData(x => x.TaskNum == taskNum);
-                if (outStockLockInfos == null || outStockLockInfos.Count == 0)
-                {
-                    return WebResponseContent.Instance.Error($"鏈壘鍒板嚭搴撹鎯呬俊鎭�");
-                }
-
-                List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>();
-                for (int i = 0; i < outStockLockInfos.Count; i++)
-                {
-                    Dt_OutboundOrderDetail outboundOrderDetail = _outboundService.OutboundOrderDetailService.Repository.QueryFirst(x => x.Id == outStockLockInfos[i].OrderDetailId);
-                    if (outboundOrderDetail != null)
-                    {
-                        outboundOrderDetail.OverOutQuantity = outboundOrderDetail.LockQuantity;
-                        if (outboundOrderDetail.LockQuantity == outboundOrderDetail.OrderQuantity)
-                        {
-                            outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
-                        }
-                        outboundOrderDetails.Add(outboundOrderDetail);
-                    }
-                }
-
-                _unitOfWorkManage.BeginTran();
-                _outboundService.OutboundOrderDetailService.Repository.UpdateData(outboundOrderDetails);
-
-                stockInfo.LocationCode = locationInfo.LocationCode;
-                stockInfo.StockStatus = StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt();
-                _stockService.StockInfoService.Repository.UpdateData(stockInfo);
-
-                int beforeStatus = locationInfo.LocationStatus;
-                locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
-                _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
-                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
-
-                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
-                _unitOfWorkManage.CommitTran();
-                Dt_StockInfoDetail stockInfoDetail = _stockRepository.StockInfoDetailRepository.Db.Queryable<Dt_StockInfoDetail>().Where(x => x.StockId == stockInfo.Id).First();
-                Dt_OutboundOrderDetail outDetail = _outboundService.OutboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>().Where(x => x.LPNNo == stockInfo.PalletCode).First();
-                Dt_OutboundOrder outboundOrder = _outboundService.OutboundOrderService.Db.Queryable<Dt_OutboundOrder>().Where(x => x.Id == outDetail.OrderId).Includes(x => x.Details).First();
-                //鍒ゆ柇鍗曟嵁绫诲瀷鏄嚭搴撹繕鏄皟鎷ㄥ嚭搴撱�傘�傘�傚嚭搴�
-                if (outboundOrder.OrderType == 1)
-                {
-                    #region //鍒ゆ柇鍑哄簱鍗曟嵁鏄庣粏鍙湁鏈�鍚庝竴鏉″畬鎴愭椂鍒犻櫎鍑哄簱鍗�
-                    if (outboundOrder.Details.Count == 1)
-                    {
-                        Dt_OutboundOrder_Hty inboundOrder_Hty = new Dt_OutboundOrder_Hty
-                        {
-                            OrderStatus = outboundOrder.OrderStatus,
-                            CreateType = outboundOrder.CreateType,
-                            //SourceId = oldOutboundOrder.SourceId,
-                            UpperOrderNo = outboundOrder.UpperOrderNo,
-                            OrderNo = outboundOrder.OrderNo,
-                            OutWareHouse = outboundOrder.OutWareHouse,
-                            TransactionCode = outboundOrder.TransactionCode,
-                            InoutType = outboundOrder.InoutType,
-                            OrderType = outboundOrder.OrderType,
-                            Creater = "WMS",
-                            CreateDate = DateTime.Now,
-                        };
-                        _outboundOrder_HtyService.AddData(inboundOrder_Hty);
-                        _outboundService.OutboundOrderService.DeleteData(outboundOrder);
-                    }
-                    Dt_OutboundOrderDetail_Hty dt_InboundOrderDetail_Hty = new Dt_OutboundOrderDetail_Hty
-                    {
-                        OrderId = outDetail.OrderId,
-                        MaterielCode = outDetail.MaterielCode,
-                        MaterielName = outDetail.MaterielName,
-                        BatchNo = outDetail.BatchNo,
-                        OrderQuantity = outDetail.OrderQuantity,
-                        //ReceiptQuantity = outDetail.ReceiptQuantity,
-                        //OverInQuantity = outDetail.OverInQuantity,
-                        OrderDetailStatus = outDetail.OrderDetailStatus,
-                        Creater = "WMS",
-                        CreateDate = DateTime.Now,
-                    };
-                    _outboundOrderDetail_HtyService.AddData(dt_InboundOrderDetail_Hty);
-                    _outboundService.OutboundOrderService.DeleteData(outDetail);
-                    #endregion
-                    #region//鍑哄簱淇℃伅杩斿洖涓婁綅WMS銆傘�傘�傜珛搴撳嚭搴撴暟閲忓洖浼�
-                    HouseoutboundPassBack houseInboundPassBack = new HouseoutboundPassBack();
-                    houseInboundPassBack.ApiType = "ShippingOrderController";
-                    houseInboundPassBack.Method = "AsrsOutboundSO";
-                    datas datas = new datas();
-                    datas.data1 data1 = new datas.data1();
-                    data1.No = outboundOrder.OrderNo;
-                    data1.OutWareHouse = task.Roadway;
-                    data1.TransactionCode = outboundOrder.TransactionCode;
-                    data1.InoutType = outboundOrder.OrderType;
-                    data1.OrderType = outboundOrder.InoutType;
-
-                    datas.data1.Inbound inbound = new datas.data1.Inbound();
-                    inbound.LinId = outDetail.LinId;
-                    inbound.LPN_No = task.PalletCode;
-                    inbound.MaterielCode = stockInfoDetail.MaterielCode;
-                    inbound.OrderQuantity = stockInfoDetail.OutboundQuantity;
-                    inbound.BatchNo = stockInfoDetail.BatchNo;
-                    inbound.FinishQty = stockInfoDetail.OutboundQuantity;
-                    inbound.LocationName = task.SourceAddress;
-                    datas.Value.Add(data1);
-                    data1.DetailList.Add(inbound);
-                    houseInboundPassBack.Parameters.Add(datas);
-                    Authentication authentication = new Authentication()
-                    {
-                        ApiType = "AuthenticationController",
-                        Parameters = new List<Parameter>
-                    {
-                     new Parameter { Value = "LKAdmin"},
-                     new Parameter { Value = "LKAdmin"},
-                    },
-                        Method = "Login",
-                    };
-                    var responses1 = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAUT, authentication, "鐧诲綍WMS璐﹀彿");
-                    var Ticket = responses1.Context["Ticket"].ToString();
-                    var InvOrgId = responses1.Context["InvOrgId"].ToString();
-                    if (Ticket != null)
-                    {
-                        houseInboundPassBack.Context = new Dictionary<string, string>();
-                        houseInboundPassBack.Context.Add("Ticket", Ticket);
-                        houseInboundPassBack.Context.Add("InvOrgId", InvOrgId);
-                        var responses = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskout, houseInboundPassBack, "绔嬪簱鍑哄簱鏁伴噺鍥炰紶WMS");
-                    }
-                    #endregion
-                    //鍒犻櫎搴撳瓨淇℃伅
-                    _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
-                    _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(stockInfo.Details, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
-                }
-                else if (outboundOrder.OrderType == 240)
-                {
-                    //鐩樼偣鍑哄簱浠诲姟瀹屾垚銆併�併�併�併�併�併�併�併�佷笉鑳藉垹闄ゅ簱瀛樼瓑閫昏緫
-                }
-                else
-                {
-
-                    List<Dt_StockInfo> StockInfo = _stockService.StockInfoService.Repository.QueryData(x => x.BatchNo == outDetail.BatchNo);
-                    if (outboundOrder.Details.Count == 1)
-                    {
-                        Dt_OutboundOrder_Hty inboundOrder_Hty = new Dt_OutboundOrder_Hty
-                        {
-                            OrderStatus = outboundOrder.OrderStatus,
-                            CreateType = outboundOrder.CreateType,
-                            //SourceId = oldOutboundOrder.SourceId,
-                            UpperOrderNo = outboundOrder.UpperOrderNo,
-                            OrderNo = outboundOrder.OrderNo,
-                            OutWareHouse = outboundOrder.OutWareHouse,
-                            TransactionCode = outboundOrder.TransactionCode,
-                            InoutType = outboundOrder.InoutType,
-                            OrderType = outboundOrder.OrderType,
-                            Creater = "WMS",
-                            CreateDate = DateTime.Now,
-                        };
-                        _outboundOrder_HtyService.AddData(inboundOrder_Hty);
-                        _outboundService.OutboundOrderService.DeleteData(outboundOrder);
-                    }
-                    Dt_OutboundOrderDetail_Hty dt_InboundOrderDetail_Hty = new Dt_OutboundOrderDetail_Hty
-                    {
-                        OrderId = outDetail.OrderId,
-                        MaterielCode = outDetail.MaterielCode,
-                        MaterielName = outDetail.MaterielName,
-                        BatchNo = outDetail.BatchNo,
-                        OrderQuantity = outDetail.OrderQuantity,
-                        //ReceiptQuantity = outDetail.ReceiptQuantity,
-                        //OverInQuantity = outDetail.OverInQuantity,
-                        OrderDetailStatus = outDetail.OrderDetailStatus,
-                        Creater = "WMS",
-                        CreateDate = DateTime.Now,
-                    };
-                    _outboundOrderDetail_HtyService.AddData(dt_InboundOrderDetail_Hty);
-                    _outboundService.OutboundOrderService.DeleteData(outDetail);
-
-                    InventoryAllocate inventoryAllocate = new InventoryAllocate();
-                    inventoryAllocate.ApiType = "InventoryAllocateController";
-                    inventoryAllocate.Method = "AsrsFinishedStockCount";
-
-                    Allocate allocate = new Allocate();
-
-                    Allocate.data1 data1 = new Allocate.data1();
-                    data1.No = outboundOrder.OrderNo;
-                    data1.InWarehouse = task.Roadway;
-                    data1.TransactionCode = outboundOrder.TransactionCode;
-                    data1.InoutType = outboundOrder.OrderType;
-                    data1.OrderType = outboundOrder.InoutType;
-
-                    foreach (var item in StockInfo)
-                    {
-                        Dt_StockInfoDetail detail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == item.Id);
-                        Allocate.data1.Inventory inbound = new Allocate.data1.Inventory();
-                        inbound.LinId = outDetail.LinId;
-                        inbound.LPN_No = item.PalletCode;
-                        inbound.MaterielCode = detail.MaterielCode;
-                        inbound.OrderQuantity = detail.OutboundQuantity;
-                        inbound.BatchNo = detail.BatchNo;
-                        inbound.FinishQty = detail.OutboundQuantity;
-                        inbound.LocationName = task.SourceAddress;
-                        data1.DetailList.Add(inbound);
-                    }
-
-
-                    allocate.Value.Add(data1);
-                    inventoryAllocate.Parameters.Add(allocate);
-                    Authentication authentication = new Authentication()
-                    {
-                        ApiType = "AuthenticationController",
-                        Parameters = new List<Parameter>
-                    {
-                     new Parameter { Value = "LKAdmin"},
-                     new Parameter { Value = "LKAdmin"},
-                    },
-                        Method = "Login",
-                    };
-                    var responses1 = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAUT, authentication, "鐧诲綍WMS璐﹀彿");
-                    var Ticket = responses1.Context["Ticket"].ToString();
-                    var InvOrgId = responses1.Context["InvOrgId"].ToString();
-                    if (Ticket != null)
-                    {
-                        inventoryAllocate.Context = new Dictionary<string, string>();
-                        inventoryAllocate.Context.Add("Ticket", Ticket);
-                        inventoryAllocate.Context.Add("InvOrgId", InvOrgId);
-                        var responses = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAllocatein, inventoryAllocate, "璋冩嫧鍑哄簱鏁伴噺鍥炰紶WMS");
-                    }
-                    _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
-                    _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(stockInfo.Details, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
-                }
-                return WebResponseContent.Instance.OK();
+                // 3. 鎵ц鏍稿績鍑哄簱閫昏緫
+                return ExecuteOutboundLogic(task, stockInfo, locationInfo, outboundOrderDetails);
             }
             catch (Exception ex)
             {
@@ -684,5 +773,841 @@
             }
         }
 
+        #region 绉佹湁鏂规硶
+
+        private WebResponseContent ValidateAndGetBaseData(int taskNum, out Dt_Task task,
+            out Dt_StockInfo stockInfo, out Dt_LocationInfo locationInfo,
+            out List<Dt_OutStockLockInfo> outStockLockInfos)
+        {
+            task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
+            if (task == null)
+            {
+                stockInfo = null;
+                locationInfo = null;
+                outStockLockInfos = null;
+                return WebResponseContent.Instance.Error("鏈壘鍒颁换鍔′俊鎭�");
+            }
+            var SourceAddress = task.SourceAddress;
+            stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
+            locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == SourceAddress);
+            outStockLockInfos = _outboundService.OutboundStockLockInfoService.Repository.QueryData(x => x.TaskNum == taskNum);
+
+            if (stockInfo == null) return WebResponseContent.Instance.Error("鏈壘鍒板簱瀛樹俊鎭�");
+            if (locationInfo == null) return WebResponseContent.Instance.Error("鏈壘鍒拌揣浣嶄俊鎭�");
+            if (outStockLockInfos == null || outStockLockInfos.Count == 0)
+                return WebResponseContent.Instance.Error("鏈壘鍒板嚭搴撹鎯呬俊鎭�");
+
+            return WebResponseContent.Instance.OK();
+        }
+
+        private List<Dt_OutboundOrderDetail> ProcessOutboundOrderDetails(List<Dt_OutStockLockInfo> outStockLockInfos)
+        {
+            var outboundOrderDetails = new List<Dt_OutboundOrderDetail>();
+
+            foreach (var lockInfo in outStockLockInfos)
+            {
+                var detail = _outboundService.OutboundOrderDetailService.Repository.QueryFirst(x => x.Id == lockInfo.OrderDetailId);
+                if (detail != null)
+                {
+                    detail.OverOutQuantity = detail.LockQuantity;
+                    if (detail.LockQuantity == detail.OrderQuantity)
+                    {
+                        detail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
+                    }
+                    outboundOrderDetails.Add(detail);
+                }
+            }
+
+            return outboundOrderDetails;
+        }
+
+        private WebResponseContent ExecuteOutboundLogic(Dt_Task task, Dt_StockInfo stockInfo,
+            Dt_LocationInfo locationInfo, List<Dt_OutboundOrderDetail> outboundOrderDetails)
+        {
+            try
+            {
+                _unitOfWorkManage.BeginTran();
+
+                // 鏇存柊鍑哄簱璁㈠崟璇︽儏
+                _outboundService.OutboundOrderDetailService.Repository.UpdateData(outboundOrderDetails);
+
+                // 鏇存柊搴撳瓨鐘舵��
+                UpdateStockStatus(stockInfo, locationInfo);
+
+                // 鏇存柊璐т綅鐘舵��
+                UpdateLocationStatus(locationInfo);
+
+                // 澶勭悊浠诲姟瀹屾垚
+                CompleteTask(task);
+
+                // 娣诲姞鐘舵�佸彉鏇磋褰�
+                AddStatusChangeRecord(task, stockInfo, locationInfo);
+
+                // 鏍规嵁璁㈠崟绫诲瀷澶勭悊涓嶅悓閫昏緫
+                var outDetail = _outboundService.OutboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
+                    .Where(x => x.LPNNo == stockInfo.PalletCode).First();
+                var outboundOrder = _outboundService.OutboundOrderService.Db.Queryable<Dt_OutboundOrder>()
+                    .Where(x => x.Id == outDetail.OrderId).Includes(x => x.Details).First();
+
+                if (outboundOrder.OrderType == 1) // 鏅�氬嚭搴�
+                {
+                    ProcessNormalOutbound(task, stockInfo, outboundOrder, outDetail);
+                }
+                else if (outboundOrder.OrderType == 240) // 鐩樼偣鍑哄簱
+                {
+                    // 鐩樼偣鍑哄簱鐗规畩澶勭悊閫昏緫
+                }
+                else // 璋冩嫧鍑哄簱
+                {
+                    ProcessAllocateOutbound(task, stockInfo, outboundOrder, outDetail);
+                }
+
+                _unitOfWorkManage.CommitTran();
+                return WebResponseContent.Instance.OK();
+            }
+            catch
+            {
+                _unitOfWorkManage.RollbackTran();
+                throw;
+            }
+        }
+
+        private void UpdateStockStatus(Dt_StockInfo stockInfo, Dt_LocationInfo locationInfo)
+        {
+            stockInfo.LocationCode = locationInfo.LocationCode;
+            stockInfo.StockStatus = StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt();
+            _stockService.StockInfoService.Repository.UpdateData(stockInfo);
+        }
+
+        private void UpdateLocationStatus(Dt_LocationInfo locationInfo)
+        {
+            int beforeStatus = locationInfo.LocationStatus;
+            locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
+            _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
+        }
+
+        private void CompleteTask(Dt_Task task)
+        {
+            BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
+        }
+
+        private void AddStatusChangeRecord(Dt_Task task, Dt_StockInfo stockInfo, Dt_LocationInfo locationInfo)
+        {
+            _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(
+                locationInfo,
+                locationInfo.LocationStatus,
+                StockChangeType.Outbound.ObjToInt(),
+                stockInfo.Details.FirstOrDefault()?.OrderNo ?? "",
+                task.TaskNum);
+        }
+
+        private void ProcessNormalOutbound(Dt_Task task, Dt_StockInfo stockInfo,
+            Dt_OutboundOrder outboundOrder, Dt_OutboundOrderDetail outDetail)
+        {
+            var stockInfoDetail = _stockRepository.StockInfoDetailRepository.Db.Queryable<Dt_StockInfoDetail>()
+                .Where(x => x.StockId == stockInfo.Id).First();
+
+            if (outboundOrder.Details.Count == 1)
+            {
+                MoveOutboundOrderToHistory(outboundOrder);
+            }
+
+            MoveOutboundDetailToHistory(outDetail);
+
+            // 鍙戦�佸嚭搴撲俊鎭埌WMS
+            SendNormalOutboundToWMS(task, outboundOrder, stockInfoDetail, outDetail);
+
+            // 鍒犻櫎搴撳瓨淇℃伅
+            DeleteStockInfo(stockInfo);
+        }
+
+        private void ProcessAllocateOutbound(Dt_Task task, Dt_StockInfo stockInfo,
+            Dt_OutboundOrder outboundOrder, Dt_OutboundOrderDetail outDetail)
+        {
+            var relatedStockInfos = _stockService.StockInfoService.Repository.QueryData(x => x.BatchNo == outDetail.BatchNo);
+
+            if (outboundOrder.Details.Count == 1)
+            {
+                MoveOutboundOrderToHistory(outboundOrder);
+            }
+
+            MoveOutboundDetailToHistory(outDetail);
+
+            // 鍙戦�佽皟鎷ㄥ嚭搴撲俊鎭埌WMS
+            SendAllocateOutboundToWMS(task, outboundOrder, outDetail, relatedStockInfos);
+
+            // 鍒犻櫎搴撳瓨淇℃伅
+            DeleteStockInfo(stockInfo);
+        }
+
+        private void MoveOutboundOrderToHistory(Dt_OutboundOrder outboundOrder)
+        {
+            var history = new Dt_OutboundOrder_Hty
+            {
+                OrderStatus = outboundOrder.OrderStatus,
+                CreateType = outboundOrder.CreateType,
+                UpperOrderNo = outboundOrder.UpperOrderNo,
+                OrderNo = outboundOrder.OrderNo,
+                OutWareHouse = outboundOrder.OutWareHouse,
+                TransactionCode = outboundOrder.TransactionCode,
+                InoutType = outboundOrder.InoutType,
+                OrderType = outboundOrder.OrderType,
+                Creater = "WMS",
+                CreateDate = DateTime.Now,
+            };
+            _outboundOrder_HtyService.AddData(history);
+            _outboundService.OutboundOrderService.DeleteData(outboundOrder);
+        }
+
+        private void MoveOutboundDetailToHistory(Dt_OutboundOrderDetail outDetail)
+        {
+            var detailHistory = new Dt_OutboundOrderDetail_Hty
+            {
+                OrderId = outDetail.OrderId,
+                MaterielCode = outDetail.MaterielCode,
+                MaterielName = outDetail.MaterielName,
+                BatchNo = outDetail.BatchNo,
+                OrderQuantity = outDetail.OrderQuantity,
+                OrderDetailStatus = outDetail.OrderDetailStatus,
+                Creater = "WMS",
+                CreateDate = DateTime.Now,
+            };
+            _outboundOrderDetail_HtyService.AddData(detailHistory);
+            _outboundService.OutboundOrderService.DeleteData(outDetail);
+        }
+
+        private void SendNormalOutboundToWMS(Dt_Task task, Dt_OutboundOrder outboundOrder,
+            Dt_StockInfoDetail stockInfoDetail, Dt_OutboundOrderDetail outDetail)
+        {
+            var passBack = new HouseoutboundPassBack
+            {
+                ApiType = "ShippingOrderController",
+                Method = "AsrsOutboundSO",
+                Parameters = new List<HouseoutboundPassBack.datas>
+        {
+            new HouseoutboundPassBack.datas
+            {
+                Value = new List<HouseoutboundPassBack.datas.data1>
+                {
+                    new HouseoutboundPassBack.datas.data1
+                    {
+                        No = outboundOrder.OrderNo,
+                        OutWareHouse = task.Roadway,
+                        TransactionCode = outboundOrder.TransactionCode,
+                        InoutType = outboundOrder.OrderType,
+                        OrderType = outboundOrder.InoutType,
+                        DetailList = new List<HouseoutboundPassBack.datas.data1.Inbound>
+                        {
+                            new HouseoutboundPassBack.datas.data1.Inbound
+                            {
+                                LinId = outDetail.LinId,
+                                LPN_No = task.PalletCode,
+                                MaterielCode = stockInfoDetail.MaterielCode,
+                                OrderQuantity = stockInfoDetail.OutboundQuantity,
+                                BatchNo = stockInfoDetail.BatchNo,
+                                FinishQty = stockInfoDetail.OutboundQuantity,
+                                LocationName = task.SourceAddress
+                            }
+                        }
+                    }
+                }
+            }
+        }
+            };
+
+            var authResult = AuthenticateWithWMS();
+            if (authResult.IsSuccess)
+            {
+                passBack.Context = new Dictionary<string, string>
+        {
+            { "Ticket", authResult.Ticket },
+            { "InvOrgId", authResult.InvOrgId }
+        };
+
+                HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskin, passBack, "绔嬪簱鍏ュ簱鏁伴噺鍥炰紶WMS");
+            }
+        }
+
+        private void SendAllocateOutboundToWMS(Dt_Task task, Dt_OutboundOrder outboundOrder,
+            Dt_OutboundOrderDetail outDetail, List<Dt_StockInfo> stockInfos)
+        {
+            var allocate = new InventoryAllocate
+            {
+                ApiType = "InventoryAllocateController",
+                Method = "AsrsFinishedStockCount",
+                Parameters = new List<Allocate>
+        {
+            new Allocate
+            {
+                Value = new List<Allocate.data1>
+                {
+                    new Allocate.data1
+                    {
+                        No = outboundOrder.OrderNo,
+                        InWarehouse = task.Roadway,
+                        TransactionCode = outboundOrder.TransactionCode,
+                        InoutType = outboundOrder.OrderType,
+                        OrderType = outboundOrder.InoutType,
+                        DetailList = stockInfos.Select(item =>
+                        {
+                            var detail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == item.Id);
+                            return new Allocate.data1.Inventory
+                            {
+                                LinId = outDetail.LinId,
+                                LPN_No = item.PalletCode,
+                                MaterielCode = detail.MaterielCode,
+                                OrderQuantity = detail.OutboundQuantity,
+                                BatchNo = detail.BatchNo,
+                                FinishQty = detail.OutboundQuantity,
+                                LocationName = task.SourceAddress
+                            };
+                        }).ToList()
+                    }
+                }
+            }
+        }
+            };
+
+            var authResult = AuthenticateWithWMS();
+            if (authResult.IsSuccess)
+            {
+                allocate.Context = new Dictionary<string, string>
+        {
+            { "Ticket", authResult.Ticket },
+            { "InvOrgId", authResult.InvOrgId }
+        };
+
+                HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskin, allocate, "绔嬪簱鍏ュ簱鏁伴噺鍥炰紶WMS");
+            }
+        }
+
+        private void DeleteStockInfo(Dt_StockInfo stockInfo)
+        {
+            _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo,
+                App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
+            _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(stockInfo.Details,
+                App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
+        }
+
+        #endregion
+        #endregion
+
+
+
+
+
+        #region
+        //public WebResponseContent InboundTaskCompleted(int taskNum)
+        //{
+        //    try
+        //    {
+        //        Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
+        //        if (task == null)
+        //        {
+        //            return WebResponseContent.Instance.Error($"鏈壘鍒拌浠诲姟");
+        //        }
+        //        if (task.TaskType != TaskTypeEnum.Inbound.ObjToInt())
+        //        {
+        //            return WebResponseContent.Instance.Error($"浠诲姟绫诲瀷閿欒");
+        //        }
+        //        Dt_StockInfo dt_StockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == task.PalletCode).Includes(x => x.Details).First();
+        //        if (dt_StockInfo == null)
+        //        {
+        //            return WebResponseContent.Instance.Error($"鏈壘鍒版墭鐩樺搴旂殑缁勭洏淇℃伅");
+        //        }
+
+        //        if (!string.IsNullOrEmpty(dt_StockInfo.LocationCode))
+        //        {
+        //            return WebResponseContent.Instance.Error($"璇ユ墭鐩樺凡缁戝畾璐т綅");
+        //        }
+
+        //        if (dt_StockInfo.Details == null || dt_StockInfo.Details.Count == 0)
+        //        {
+        //            return WebResponseContent.Instance.Error($"鏈壘鍒拌鎵樼洏搴撳瓨鏄庣粏淇℃伅");
+        //        }
+        //        Dt_LocationInfo dt_LocationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
+        //        if (dt_LocationInfo == null)
+        //        {
+        //            return WebResponseContent.Instance.Error($"鏈壘鍒扮洰鏍囪揣浣嶄俊鎭�");
+        //        }
+
+        //        if (dt_LocationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
+        //        {
+        //            return WebResponseContent.Instance.Error($"璐т綅鐘舵�佷笉姝g‘");
+        //        }
+        //        int lastStatus = dt_LocationInfo.LocationStatus;
+        //        dt_LocationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+        //        Dt_Warehouse warehouse = _basicService.WarehouseService.Repository.QueryFirst(x => x.WarehouseId == task.WarehouseId);
+
+        //        dt_StockInfo.LocationCode = dt_LocationInfo.LocationCode;
+
+
+        //        Dt_InboundOrder? inboundOrder = _inboundService.InbounOrderService.Db.Queryable<Dt_InboundOrder>().Where(x => x.InboundOrderNo == dt_StockInfo.Details.FirstOrDefault().OrderNo).Includes(x => x.Details).First();
+        //        Dt_InboundOrderDetail? inboundOrderDetail = null;
+        //        //鍒ゆ柇鍗曟嵁绫诲瀷鏄叆搴撹繕鏄皟鎷ㄥ叆搴撱�傘�傘�傚叆搴�
+        //        if (inboundOrder.OrderType == 0 && inboundOrder != null && dt_StockInfo.StockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt())
+        //        {
+        //            #region //鍒ゆ柇鍏ュ簱鍗曟嵁鏄庣粏鍙湁鏈�鍚庝竴鏉″畬鎴愭椂鍒犻櫎鍏ュ簱鍗�
+        //            //鏌ヨ鍘熷畬鎴愮殑鍏ュ簱鏄庣粏鏁伴噺
+        //            int overCount = inboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).ToList().Count;
+        //            //鏄庣粏id鏌ヨ
+        //            inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.LinId == dt_StockInfo.Details.FirstOrDefault()?.LinId);
+        //            foreach (var item in dt_StockInfo.Details)
+        //            {
+        //                if (inboundOrderDetail == null)
+        //                {
+        //                    continue;
+        //                }
+        //                inboundOrderDetail.OverInQuantity += item.StockQuantity;
+        //                if (inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity)
+        //                {
+        //                    inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
+        //                    overCount += 1;
+        //                }
+        //                else if (inboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt())
+        //                {
+        //                    inboundOrderDetail.OrderDetailStatus = InboundStatusEnum.鍏ュ簱涓�.ObjToInt();
+        //                }
+        //            }
+        //            dt_StockInfo.Details.ForEach(x =>
+        //            {
+        //                x.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+        //            });
+
+        //            _unitOfWorkManage.BeginTran();
+        //            task.TaskStatus = InTaskStatusEnum.InFinish.ObjToInt();
+        //            BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateType.浜哄伐瀹屾垚 : OperateType.鑷姩瀹屾垚);
+
+        //            _basicService.LocationInfoService.Repository.UpdateData(dt_LocationInfo);
+        //            _stockRepository.StockInfoRepository.UpdateData(dt_StockInfo);
+        //            _stockRepository.StockInfoDetailRepository.UpdateData(dt_StockInfo.Details);
+        //            _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(dt_LocationInfo, lastStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
+        //            _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(dt_StockInfo, dt_StockInfo.Details, dt_StockInfo.Details.Sum(x => x.StockQuantity), dt_StockInfo.Details.Sum(x => x.StockQuantity), StockChangeType.Inbound, task.TaskNum);
+        //            if (inboundOrder != null)
+        //            {
+        //                _inboundService.InbounOrderService.UpdateData(inboundOrder);
+        //                _inboundService.InboundOrderDetailService.UpdateData(inboundOrderDetail);
+        //            }
+        //            _unitOfWorkManage.CommitTran();
+
+
+
+
+        //            if (inboundOrder.Details.Count == 1)
+        //            {
+        //                var stockInfoDetail = dt_StockInfo.Details.FirstOrDefault();
+
+        //                #region//鍏ュ簱淇℃伅杩斿洖涓婁綅WMS銆傘�傜珛搴撳叆搴撴暟閲忓洖浼�
+        //                HouseInboundPassBack houseInboundPassBack = new HouseInboundPassBack();
+        //                houseInboundPassBack.ApiType = "AsnController";
+        //                houseInboundPassBack.Method = "AsrsGroudingAsn";
+        //                data data = new data();
+        //                data.data1 data1 = new data.data1();
+        //                data1.AsnNo = task.OrderNo;
+        //                data1.InWarehouse = task.Roadway;
+        //                data1.TransactionCode = inboundOrder.TransactionCode;
+        //                data1.InoutType = inboundOrder.OrderType;
+        //                data1.OrderType = inboundOrder.InoutType;
+        //                data.data1.Inbound inbound = new data.data1.Inbound
+        //                {
+        //                    LinId = stockInfoDetail.LinId,
+        //                    MaterielCode = stockInfoDetail.MaterielCode,
+        //                    OrderQuantity = stockInfoDetail.StockQuantity,
+        //                    BatchNo = stockInfoDetail.BatchNo,
+        //                    FinishQty = stockInfoDetail.StockQuantity,
+        //                    LocationName = task.TargetAddress
+        //                };
+        //                data.Value.Add(data1);
+        //                data1.DetailList.Add(inbound);
+        //                houseInboundPassBack.Parameters.Add(data);
+        //                Authentication authentication = new Authentication()
+        //                {
+        //                    ApiType = "AuthenticationController",
+        //                    Parameters = new List<Parameter>
+        //        {
+        //             new Parameter { Value = "LKAdmin"},
+        //             new Parameter { Value = "LKAdmin"},
+        //        },
+        //                    Method = "Login",
+        //                };
+        //                var responses1 = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAUT, authentication, "鐧诲綍WMS璐﹀彿");
+        //                var Ticket = responses1.Context["Ticket"].ToString();
+        //                var InvOrgId = responses1.Context["InvOrgId"].ToString();
+        //                if (Ticket != null)
+        //                {
+        //                    houseInboundPassBack.Context = new Dictionary<string, string>();
+        //                    houseInboundPassBack.Context.Add("Ticket", Ticket);
+        //                    houseInboundPassBack.Context.Add("InvOrgId", InvOrgId);
+        //                    var responses = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskin, houseInboundPassBack, "绔嬪簱鍏ュ簱鏁伴噺鍥炰紶WMS");
+        //                }
+        //                #endregion
+        //            }
+        //        }
+        //        else
+        //        {
+        //            #region //鍒ゆ柇璋冩嫧鍏ュ簱鍗曟嵁鏄庣粏鍙湁鏈�鍚庝竴鏉″畬鎴愭椂鍒犻櫎鍏ュ簱鍗曞苟涓�娆¤繑鍥炲叆搴撴槑缁嗕俊鎭�
+        //            if (inboundOrder.Details.Count == 1)
+        //            {
+        //                List<Dt_StockInfo> StockInfo = _stockService.StockInfoService.Repository.QueryData(x => x.BatchNo == inboundOrderDetail.BatchNo);
+        //                Dt_InboundOrder_Hty inboundOrder_Hty = new Dt_InboundOrder_Hty
+        //                {
+        //                    OrderStatus = inboundOrder.OrderStatus,
+        //                    CreateType = inboundOrder.CreateType,
+        //                    //SourceId = oldOutboundOrder.SourceId,
+        //                    UpperOrderNo = inboundOrder.UpperOrderNo,
+        //                    OrderNo = inboundOrder.OrderNo,
+        //                    //OutWareHouse = inboundOrder.OutWareHouse,
+        //                    TransactionCode = inboundOrder.TransactionCode,
+        //                    InoutType = inboundOrder.InoutType,
+        //                    OrderType = inboundOrder.OrderType,
+        //                    Creater = "WMS",
+        //                    CreateDate = DateTime.Now,
+        //                };
+        //                _inboundOrder_HtyService.AddData(inboundOrder_Hty);
+        //                _inboundService.InbounOrderService.DeleteData(inboundOrder);
+        //                Dt_InboundOrderDetail_Hty dt_InboundOrderDetail_HtyS = new Dt_InboundOrderDetail_Hty
+        //                {
+        //                    OrderId = inboundOrderDetail.OrderId,
+        //                    MaterielCode = inboundOrderDetail.MaterielCode,
+        //                    MaterielName = inboundOrderDetail.MaterielName,
+        //                    BatchNo = inboundOrderDetail.BatchNo,
+        //                    OrderQuantity = inboundOrderDetail.OrderQuantity,
+        //                    ReceiptQuantity = inboundOrderDetail.ReceiptQuantity,
+        //                    OverInQuantity = inboundOrderDetail.OverInQuantity,
+        //                    OrderDetailStatus = inboundOrderDetail.OrderDetailStatus,
+        //                    Creater = "WMS",
+        //                    CreateDate = DateTime.Now,
+        //                };
+        //                _inboundOrderDetail_HtyService.AddData(dt_InboundOrderDetail_HtyS);
+        //                _inboundService.InboundOrderDetailService.DeleteData(inboundOrderDetail);
+        //                #endregion
+        //                #region//璋冩嫧浠诲姟鏁伴噺鍥炰紶WMS
+        //                InventoryAllocate inventoryAllocate = new InventoryAllocate();
+        //                inventoryAllocate.ApiType = "InventoryAllocateController";
+        //                inventoryAllocate.Method = "AsrsFinishedStockCount";
+
+        //                Allocate allocate = new Allocate();
+
+        //                Allocate.data1 data1 = new Allocate.data1();
+        //                data1.No = task.OrderNo;
+        //                data1.InWarehouse = task.Roadway;
+        //                data1.TransactionCode = inboundOrder.TransactionCode;
+        //                data1.InoutType = inboundOrder.OrderType;
+        //                data1.OrderType = inboundOrder.InoutType;
+        //                foreach (var item in StockInfo)
+        //                {
+        //                    Dt_StockInfoDetail detail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == item.Id);
+        //                    Allocate.data1.Inventory inbound = new Allocate.data1.Inventory();
+        //                    inbound.LinId = detail.LinId;
+        //                    inbound.LPN_No = item.PalletCode;
+        //                    inbound.MaterielCode = detail.MaterielCode;
+        //                    inbound.OrderQuantity = detail.StockQuantity;
+        //                    inbound.BatchNo = detail.BatchNo;
+        //                    inbound.FinishQty = detail.StockQuantity;
+        //                    inbound.LocationName = item.LocationCode;
+        //                    data1.DetailList.Add(inbound);
+        //                }
+        //                allocate.Value.Add(data1);
+        //                inventoryAllocate.Parameters.Add(allocate);
+        //                Authentication authentication = new Authentication()
+        //                {
+        //                    ApiType = "AuthenticationController",
+        //                    Parameters = new List<Parameter>
+        //            {
+        //             new Parameter { Value = "LKAdmin"},
+        //             new Parameter { Value = "LKAdmin"},
+        //            },
+        //                    Method = "Login",
+        //                };
+        //                var responses1 = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAUT, authentication, "鐧诲綍WMS璐﹀彿");
+        //                var Ticket = responses1.Context["Ticket"].ToString();
+        //                var InvOrgId = responses1.Context["InvOrgId"].ToString();
+        //                if (Ticket != null)
+        //                {
+        //                    inventoryAllocate.Context = new Dictionary<string, string>();
+        //                    inventoryAllocate.Context.Add("Ticket", Ticket);
+        //                    inventoryAllocate.Context.Add("InvOrgId", InvOrgId);
+        //                    var responses = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAllocatein, inventoryAllocate, "璋冩嫧鍏ュ簱鏁伴噺鍥炰紶WMS");
+        //                }
+        //            }
+        //            #endregion
+        //            Dt_InboundOrderDetail_Hty dt_InboundOrderDetail_Hty = new Dt_InboundOrderDetail_Hty
+        //            {
+        //                OrderId = inboundOrderDetail.OrderId,
+        //                MaterielCode = inboundOrderDetail.MaterielCode,
+        //                MaterielName = inboundOrderDetail.MaterielName,
+        //                BatchNo = inboundOrderDetail.BatchNo,
+        //                OrderQuantity = inboundOrderDetail.OrderQuantity,
+        //                ReceiptQuantity = inboundOrderDetail.ReceiptQuantity,
+        //                OverInQuantity = inboundOrderDetail.OverInQuantity,
+        //                OrderDetailStatus = inboundOrderDetail.OrderDetailStatus,
+        //                Creater = "WMS",
+        //                CreateDate = DateTime.Now,
+        //            };
+        //            _inboundOrderDetail_HtyService.AddData(dt_InboundOrderDetail_Hty);
+        //            _inboundService.InboundOrderDetailService.DeleteData(inboundOrderDetail);
+        //        }
+        //        return WebResponseContent.Instance.OK();
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        _unitOfWorkManage.RollbackTran();
+        //        return WebResponseContent.Instance.Error(ex.Message);
+        //    }
+        //}
+        #endregion
+        #region
+        //public WebResponseContent OutboundTaskCompleted(int taskNum)
+        //{
+        //    try
+        //    {
+        //        Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
+        //        if (task == null)
+        //        {
+        //            return WebResponseContent.Instance.Error($"鏈壘鍒颁换鍔′俊鎭�");
+        //        }
+
+        //        Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
+
+        //        Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress);
+        //        if (stockInfo == null)
+        //        {
+        //            return WebResponseContent.Instance.Error($"鏈壘鍒板簱瀛樹俊鎭�");
+        //        }
+        //        if (locationInfo == null)
+        //        {
+        //            return WebResponseContent.Instance.Error($"鏈壘鍒拌揣浣嶄俊鎭�");
+        //        }
+
+        //        List<Dt_OutStockLockInfo> outStockLockInfos = _outboundService.OutboundStockLockInfoService.Repository.QueryData(x => x.TaskNum == taskNum);
+        //        if (outStockLockInfos == null || outStockLockInfos.Count == 0)
+        //        {
+        //            return WebResponseContent.Instance.Error($"鏈壘鍒板嚭搴撹鎯呬俊鎭�");
+        //        }
+
+        //        List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>();
+        //        for (int i = 0; i < outStockLockInfos.Count; i++)
+        //        {
+        //            Dt_OutboundOrderDetail outboundOrderDetail = _outboundService.OutboundOrderDetailService.Repository.QueryFirst(x => x.Id == outStockLockInfos[i].OrderDetailId);
+        //            if (outboundOrderDetail != null)
+        //            {
+        //                outboundOrderDetail.OverOutQuantity = outboundOrderDetail.LockQuantity;
+        //                if (outboundOrderDetail.LockQuantity == outboundOrderDetail.OrderQuantity)
+        //                {
+        //                    outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
+        //                }
+        //                outboundOrderDetails.Add(outboundOrderDetail);
+        //            }
+        //        }
+
+        //        _unitOfWorkManage.BeginTran();
+        //        _outboundService.OutboundOrderDetailService.Repository.UpdateData(outboundOrderDetails);
+
+        //        stockInfo.LocationCode = locationInfo.LocationCode;
+        //        stockInfo.StockStatus = StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt();
+        //        _stockService.StockInfoService.Repository.UpdateData(stockInfo);
+
+        //        int beforeStatus = locationInfo.LocationStatus;
+        //        locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
+        //        _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
+        //        BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
+
+        //        _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
+        //        _unitOfWorkManage.CommitTran();
+        //        Dt_StockInfoDetail stockInfoDetail = _stockRepository.StockInfoDetailRepository.Db.Queryable<Dt_StockInfoDetail>().Where(x => x.StockId == stockInfo.Id).First();
+        //        Dt_OutboundOrderDetail outDetail = _outboundService.OutboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>().Where(x => x.LPNNo == stockInfo.PalletCode).First();
+        //        Dt_OutboundOrder outboundOrder = _outboundService.OutboundOrderService.Db.Queryable<Dt_OutboundOrder>().Where(x => x.Id == outDetail.OrderId).Includes(x => x.Details).First();
+        //        //鍒ゆ柇鍗曟嵁绫诲瀷鏄嚭搴撹繕鏄皟鎷ㄥ嚭搴撱�傘�傘�傚嚭搴�
+        //        if (outboundOrder.OrderType == 1)
+        //        {
+        //            #region //鍒ゆ柇鍑哄簱鍗曟嵁鏄庣粏鍙湁鏈�鍚庝竴鏉″畬鎴愭椂鍒犻櫎鍑哄簱鍗�
+        //            if (outboundOrder.Details.Count == 1)
+        //            {
+        //                Dt_OutboundOrder_Hty inboundOrder_Hty = new Dt_OutboundOrder_Hty
+        //                {
+        //                    OrderStatus = outboundOrder.OrderStatus,
+        //                    CreateType = outboundOrder.CreateType,
+        //                    //SourceId = oldOutboundOrder.SourceId,
+        //                    UpperOrderNo = outboundOrder.UpperOrderNo,
+        //                    OrderNo = outboundOrder.OrderNo,
+        //                    OutWareHouse = outboundOrder.OutWareHouse,
+        //                    TransactionCode = outboundOrder.TransactionCode,
+        //                    InoutType = outboundOrder.InoutType,
+        //                    OrderType = outboundOrder.OrderType,
+        //                    Creater = "WMS",
+        //                    CreateDate = DateTime.Now,
+        //                };
+        //                _outboundOrder_HtyService.AddData(inboundOrder_Hty);
+        //                _outboundService.OutboundOrderService.DeleteData(outboundOrder);
+        //            }
+        //            Dt_OutboundOrderDetail_Hty dt_InboundOrderDetail_Hty = new Dt_OutboundOrderDetail_Hty
+        //            {
+        //                OrderId = outDetail.OrderId,
+        //                MaterielCode = outDetail.MaterielCode,
+        //                MaterielName = outDetail.MaterielName,
+        //                BatchNo = outDetail.BatchNo,
+        //                OrderQuantity = outDetail.OrderQuantity,
+        //                //ReceiptQuantity = outDetail.ReceiptQuantity,
+        //                //OverInQuantity = outDetail.OverInQuantity,
+        //                OrderDetailStatus = outDetail.OrderDetailStatus,
+        //                Creater = "WMS",
+        //                CreateDate = DateTime.Now,
+        //            };
+        //            _outboundOrderDetail_HtyService.AddData(dt_InboundOrderDetail_Hty);
+        //            _outboundService.OutboundOrderService.DeleteData(outDetail);
+        //            #endregion
+        //            #region//鍑哄簱淇℃伅杩斿洖涓婁綅WMS銆傘�傘�傜珛搴撳嚭搴撴暟閲忓洖浼�
+        //            HouseoutboundPassBack houseInboundPassBack = new HouseoutboundPassBack();
+        //            houseInboundPassBack.ApiType = "ShippingOrderController";
+        //            houseInboundPassBack.Method = "AsrsOutboundSO";
+        //            datas datas = new datas();
+        //            datas.data1 data1 = new datas.data1();
+        //            data1.No = outboundOrder.OrderNo;
+        //            data1.OutWareHouse = task.Roadway;
+        //            data1.TransactionCode = outboundOrder.TransactionCode;
+        //            data1.InoutType = outboundOrder.OrderType;
+        //            data1.OrderType = outboundOrder.InoutType;
+
+        //            datas.data1.Inbound inbound = new datas.data1.Inbound();
+        //            inbound.LinId = outDetail.LinId;
+        //            inbound.LPN_No = task.PalletCode;
+        //            inbound.MaterielCode = stockInfoDetail.MaterielCode;
+        //            inbound.OrderQuantity = stockInfoDetail.OutboundQuantity;
+        //            inbound.BatchNo = stockInfoDetail.BatchNo;
+        //            inbound.FinishQty = stockInfoDetail.OutboundQuantity;
+        //            inbound.LocationName = task.SourceAddress;
+        //            datas.Value.Add(data1);
+        //            data1.DetailList.Add(inbound);
+        //            houseInboundPassBack.Parameters.Add(datas);
+        //            Authentication authentication = new Authentication()
+        //            {
+        //                ApiType = "AuthenticationController",
+        //                Parameters = new List<Parameter>
+        //            {
+        //             new Parameter { Value = "LKAdmin"},
+        //             new Parameter { Value = "LKAdmin"},
+        //            },
+        //                Method = "Login",
+        //            };
+        //            var responses1 = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAUT, authentication, "鐧诲綍WMS璐﹀彿");
+        //            var Ticket = responses1.Context["Ticket"].ToString();
+        //            var InvOrgId = responses1.Context["InvOrgId"].ToString();
+        //            if (Ticket != null)
+        //            {
+        //                houseInboundPassBack.Context = new Dictionary<string, string>();
+        //                houseInboundPassBack.Context.Add("Ticket", Ticket);
+        //                houseInboundPassBack.Context.Add("InvOrgId", InvOrgId);
+        //                var responses = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskout, houseInboundPassBack, "绔嬪簱鍑哄簱鏁伴噺鍥炰紶WMS");
+        //            }
+        //            #endregion
+        //            //鍒犻櫎搴撳瓨淇℃伅
+        //            _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
+        //            _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(stockInfo.Details, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
+        //        }
+        //        else if (outboundOrder.OrderType == 240)
+        //        {
+        //            //鐩樼偣鍑哄簱浠诲姟瀹屾垚銆併�併�併�併�併�併�併�併�佷笉鑳藉垹闄ゅ簱瀛樼瓑閫昏緫
+        //        }
+        //        else
+        //        {
+
+        //            List<Dt_StockInfo> StockInfo = _stockService.StockInfoService.Repository.QueryData(x => x.BatchNo == outDetail.BatchNo);
+        //            if (outboundOrder.Details.Count == 1)
+        //            {
+        //                Dt_OutboundOrder_Hty inboundOrder_Hty = new Dt_OutboundOrder_Hty
+        //                {
+        //                    OrderStatus = outboundOrder.OrderStatus,
+        //                    CreateType = outboundOrder.CreateType,
+        //                    //SourceId = oldOutboundOrder.SourceId,
+        //                    UpperOrderNo = outboundOrder.UpperOrderNo,
+        //                    OrderNo = outboundOrder.OrderNo,
+        //                    OutWareHouse = outboundOrder.OutWareHouse,
+        //                    TransactionCode = outboundOrder.TransactionCode,
+        //                    InoutType = outboundOrder.InoutType,
+        //                    OrderType = outboundOrder.OrderType,
+        //                    Creater = "WMS",
+        //                    CreateDate = DateTime.Now,
+        //                };
+        //                _outboundOrder_HtyService.AddData(inboundOrder_Hty);
+        //                _outboundService.OutboundOrderService.DeleteData(outboundOrder);
+        //            }
+        //            Dt_OutboundOrderDetail_Hty dt_InboundOrderDetail_Hty = new Dt_OutboundOrderDetail_Hty
+        //            {
+        //                OrderId = outDetail.OrderId,
+        //                MaterielCode = outDetail.MaterielCode,
+        //                MaterielName = outDetail.MaterielName,
+        //                BatchNo = outDetail.BatchNo,
+        //                OrderQuantity = outDetail.OrderQuantity,
+        //                //ReceiptQuantity = outDetail.ReceiptQuantity,
+        //                //OverInQuantity = outDetail.OverInQuantity,
+        //                OrderDetailStatus = outDetail.OrderDetailStatus,
+        //                Creater = "WMS",
+        //                CreateDate = DateTime.Now,
+        //            };
+        //            _outboundOrderDetail_HtyService.AddData(dt_InboundOrderDetail_Hty);
+        //            _outboundService.OutboundOrderService.DeleteData(outDetail);
+
+        //            InventoryAllocate inventoryAllocate = new InventoryAllocate();
+        //            inventoryAllocate.ApiType = "InventoryAllocateController";
+        //            inventoryAllocate.Method = "AsrsFinishedStockCount";
+
+        //            Allocate allocate = new Allocate();
+
+        //            Allocate.data1 data1 = new Allocate.data1();
+        //            data1.No = outboundOrder.OrderNo;
+        //            data1.InWarehouse = task.Roadway;
+        //            data1.TransactionCode = outboundOrder.TransactionCode;
+        //            data1.InoutType = outboundOrder.OrderType;
+        //            data1.OrderType = outboundOrder.InoutType;
+
+        //            foreach (var item in StockInfo)
+        //            {
+        //                Dt_StockInfoDetail detail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == item.Id);
+        //                Allocate.data1.Inventory inbound = new Allocate.data1.Inventory();
+        //                inbound.LinId = outDetail.LinId;
+        //                inbound.LPN_No = item.PalletCode;
+        //                inbound.MaterielCode = detail.MaterielCode;
+        //                inbound.OrderQuantity = detail.OutboundQuantity;
+        //                inbound.BatchNo = detail.BatchNo;
+        //                inbound.FinishQty = detail.OutboundQuantity;
+        //                inbound.LocationName = task.SourceAddress;
+        //                data1.DetailList.Add(inbound);
+        //            }
+
+
+        //            allocate.Value.Add(data1);
+        //            inventoryAllocate.Parameters.Add(allocate);
+        //            Authentication authentication = new Authentication()
+        //            {
+        //                ApiType = "AuthenticationController",
+        //                Parameters = new List<Parameter>
+        //            {
+        //             new Parameter { Value = "LKAdmin"},
+        //             new Parameter { Value = "LKAdmin"},
+        //            },
+        //                Method = "Login",
+        //            };
+        //            var responses1 = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAUT, authentication, "鐧诲綍WMS璐﹀彿");
+        //            var Ticket = responses1.Context["Ticket"].ToString();
+        //            var InvOrgId = responses1.Context["InvOrgId"].ToString();
+        //            if (Ticket != null)
+        //            {
+        //                inventoryAllocate.Context = new Dictionary<string, string>();
+        //                inventoryAllocate.Context.Add("Ticket", Ticket);
+        //                inventoryAllocate.Context.Add("InvOrgId", InvOrgId);
+        //                var responses = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAllocatein, inventoryAllocate, "璋冩嫧鍑哄簱鏁伴噺鍥炰紶WMS");
+        //            }
+        //            _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
+        //            _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(stockInfo.Details, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
+        //        }
+        //        return WebResponseContent.Instance.OK();
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        _unitOfWorkManage.RollbackTran();
+        //        return WebResponseContent.Instance.Error(ex.Message);
+        //    }
+        //}
+        #endregion
     }
 }

--
Gitblit v1.9.3