From d48e486d63ae2a0fc454c27c79b8f12115e4bcbe Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期六, 18 十月 2025 16:20:45 +0800
Subject: [PATCH] 修改

---
 新建文件夹/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/DeliveryOrderServices.cs |  516 ++++++++++++++------------------------------------------
 1 files changed, 132 insertions(+), 384 deletions(-)

diff --git "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/DeliveryOrderServices.cs" "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/DeliveryOrderServices.cs"
index b0801af..8a41ce8 100644
--- "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/DeliveryOrderServices.cs"
+++ "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/DeliveryOrderServices.cs"
@@ -1,4 +1,5 @@
 锘縰sing HslCommunication;
+using MailKit.Search;
 using Newtonsoft.Json;
 using System;
 using System.Collections.Generic;
@@ -25,7 +26,7 @@
 
 namespace WIDESEA_SquareCabinServices
 {
-    public class DeliveryOrderServices : ServiceBase<Dt_DeliveryOrder, IRepository<Dt_DeliveryOrder>>, IDeliveryOrderServices
+    public partial class DeliveryOrderServices : ServiceBase<Dt_DeliveryOrder, IRepository<Dt_DeliveryOrder>>, IDeliveryOrderServices
     {
         static string SearchDate = "";
         private readonly IBasicService _basicService;
@@ -34,8 +35,9 @@
         private readonly IInventoryInfoService _inventoryInfoService;
         private readonly IDeliveryOrderDetailServices _deliveryOrderDetailServices;
         private readonly ISupplyTaskService _supplyTaskService;
+        private readonly ICabinOrderServices _cabinOrderServices;
         public IRepository<Dt_DeliveryOrder> Repository => BaseDal;
-        public DeliveryOrderServices(IRepository<Dt_DeliveryOrder> BaseDal, IBasicService basicService, IUnitOfWorkManage unitOfWorkManage, IInventory_BatchServices inventory_BatchServices, IInventoryInfoService inventoryInfoService, IDeliveryOrderDetailServices deliveryOrderDetailServices, ISupplyTaskService supplyTaskService) : base(BaseDal)
+        public DeliveryOrderServices(IRepository<Dt_DeliveryOrder> BaseDal, IBasicService basicService, IUnitOfWorkManage unitOfWorkManage, IInventory_BatchServices inventory_BatchServices, IInventoryInfoService inventoryInfoService, IDeliveryOrderDetailServices deliveryOrderDetailServices, ISupplyTaskService supplyTaskService, ICabinOrderServices cabinOrderServices) : base(BaseDal)
         {
             _basicService = basicService;
             _unitOfWorkManage = unitOfWorkManage;
@@ -43,6 +45,7 @@
             _supplyTaskService = supplyTaskService;
             _inventory_BatchServices = inventory_BatchServices;
             _inventoryInfoService = inventoryInfoService;
+            _cabinOrderServices = cabinOrderServices;
         }
 
         /// <summary>
@@ -173,288 +176,11 @@
         //}
 
 
-
-        public WebResponseContent GetUpstreamOutOrder()
-        {
-            var responseContent = new WebResponseContent();
-            try
-            {
-                var url = "http://121.37.118.63:80/GYZ2/95fck/outOrder";
-
-                var requestData = new
-                {
-                    searchDate = "2022-10-10 20:45:16"
-                };
-
-                var result = HttpHelper.Post(url, requestData.ToJsonString());
-                var response = JsonConvert.DeserializeObject<UpstreamResponse<UpstramOutOrderInfo>>(result);
-
-                if (response.resultCode != "0")
-                {
-                    SendErrorToUpstream(3, "", response.resultMsg ?? "涓婃父鎺ュ彛杩斿洖澶辫触", "");
-                    return responseContent.Error(response.resultMsg ?? "涓婃父鎺ュ彛杩斿洖澶辫触");
-                }
-
-                if (response.data == null || !response.data.Any())
-                {
-                    return responseContent.OK("鏃犳柊鍑哄簱鍗曟暟鎹�");
-                }
-
-                // 宸插瓨鍦ㄥ嚭搴撳崟鍙�
-                var existingOutOrderNos = BaseDal.Db.Queryable<Dt_DeliveryOrder>()
-                    .Select(x => x.Out_no)
-                    .ToList();
-
-                // 鏂板嚭搴撳崟
-                var newOutOrders = response.data
-                    .Where(outorder => !existingOutOrderNos.Contains(outorder.order_no))
-                    .ToList();
-
-                if (!newOutOrders.Any())
-                {
-                    return responseContent.OK("鎵�鏈夊嚭搴撳崟宸插瓨鍦紝鏃犻渶鏂板");
-                }
-
-                Db.Ado.BeginTran();
-                try
-                {
-                    List<Dt_DeliveryOrder> _DeliveryOrders = new List<Dt_DeliveryOrder>();
-
-                    foreach (var outorder in newOutOrders)
-                    {
-                        var entityOrder = new Dt_DeliveryOrder
-                        {
-                            Out_no = outorder.order_no,
-                            Out_type = outorder.order_type,
-                            Client_no = outorder.client_no,
-                            Client_name = outorder.client_name,
-                            Account_time = outorder.account_time,
-                            Warehouse_no = outorder.warehouse_no,
-                            OutStatus = "鏈畬鎴�",
-                            Details = new List<Dt_DeliveryOrderDetail>()
-                        };
-
-                        // 閬嶅巻鍑哄簱鏄庣粏
-                        foreach (var item in outorder.details)
-                        {
-                            //  1锔忊儯 杞负姝f暟锛堜笂娓稿彲鑳戒紶璐熸暟锛�
-                            item.order_qty = Math.Abs(item.order_qty);
-                            decimal orderQty = (decimal)item.order_qty;
-
-                            //  2锔忊儯 鏌ョ墿鏂欏熀纭�淇℃伅锛堣幏鍙栫瑙勶級
-                            var medication = BaseDal.Db.Queryable<Dt_MedicineGoods>()
-                                .Where(m => m.Goods_no == item.goods_no)
-                                .First();
-
-                            if (medication == null)
-                            {
-                                SendErrorToUpstream(3, "", $"鎵句笉鍒扮墿鏂欎俊鎭細{item.goods_no}", "");
-                                continue;
-                            }
-
-                            decimal boxQty = medication.BoxQty <= 0 ? 1 : medication.BoxQty;
-
-                            //  3锔忊儯 璁$畻鏁翠欢涓庢暎浠舵暟閲�
-                            var fullBoxes = (int)(orderQty / boxQty);   // 鏁翠欢绠辨暟
-                            var partialQty = orderQty % boxQty;         // 鏁d欢鏁伴噺
-
-                            // 鑻ヤ笂娓哥粰浜嗘壒娆″彿锛屽垯浼樺厛鍖归厤
-                            string requestedBatch = string.IsNullOrEmpty(item.batch_num) ? null : item.batch_num;
-
-                            // helper: 鏌ヨ搴撳瓨鍑芥暟锛堟寜鍏ュ簱鏃堕棿鍗囧簭锛�
-                            Func<int, List<Dt_InventoryInfo>> queryInventoryByStockStatus = (stockStatus) =>
-                            {
-                                var q = BaseDal.Db.Queryable<Dt_InventoryInfo>()
-                                    .Where(i => i.MaterielCode == item.goods_no &&
-                                                (i.StockQuantity - i.OutboundQuantity) > 0 &&
-                                                i.StockStatus == stockStatus);
-
-                                if (!string.IsNullOrEmpty(requestedBatch))
-                                    q = q.Where(i => i.BatchNo == requestedBatch);
-
-                                return q.OrderBy(i => i.InDate).ToList();
-                            };
-
-                            // 4锔忊儯鍒嗛厤鏁d欢锛堜紭鍏堢珛搴� Status=1锛�
-                            decimal remainingPartial = partialQty;
-                            if (remainingPartial > 0)
-                            {
-                                var invList_ly = queryInventoryByStockStatus(1);
-                                foreach (var inv in invList_ly)
-                                {
-                                    if (remainingPartial <= 0) break;
-
-                                    decimal available = (decimal)(inv.StockQuantity - inv.OutboundQuantity);
-                                    if (available <= 0) continue;
-
-                                    decimal use = Math.Min(available, remainingPartial);
-
-                                    var detail = new Dt_DeliveryOrderDetail
-                                    {
-                                        Goods_no = item.goods_no,
-                                        Order_qty = use,
-                                        Batch_num = inv.BatchNo,
-                                        Exp_date = inv.ValidityPeriod,
-                                        OotDetailStatus = "鏂板缓",
-                                        Status = 0, //绔嬪簱
-                                        Reservoirarea = inv.LocationCode
-                                    };
-                                    entityOrder.Details.Add(detail);
-
-                                    inv.OutboundQuantity += (float)use;
-                                    BaseDal.Db.Updateable(inv).ExecuteCommand();
-
-                                    remainingPartial -= use;
-                                }
-
-                                // 绔嬪簱涓嶅 鈫� 骞冲簱琛� (Status=2)
-                                if (remainingPartial > 0)
-                                {
-                                    var invList_pk = queryInventoryByStockStatus(2);
-                                    foreach (var inv in invList_pk)
-                                    {
-                                        if (remainingPartial <= 0) break;
-
-                                        decimal available = (decimal)(inv.StockQuantity - inv.OutboundQuantity);
-                                        if (available <= 0) continue;
-
-                                        decimal use = Math.Min(available, remainingPartial);
-
-                                        var detail = new Dt_DeliveryOrderDetail
-                                        {
-                                            Goods_no = item.goods_no,
-                                            Order_qty = use,
-                                            Batch_num = inv.BatchNo,
-                                            Exp_date = inv.ValidityPeriod,
-                                            OotDetailStatus = "鏂板缓",
-                                            Status = 2, //骞冲簱
-                                            Reservoirarea = inv.LocationCode
-                                        };
-                                        entityOrder.Details.Add(detail);
-
-                                        inv.OutboundQuantity += (float)use;
-                                        BaseDal.Db.Updateable(inv).ExecuteCommand();
-
-                                        remainingPartial -= use;
-                                    }
-                                }
-
-                                if (remainingPartial > 0)
-                                {
-                                    SendErrorToUpstream(3, "", $"鍑哄簱鍗昜{outorder.order_no}]鐗╂枡[{item.goods_no}]鏁d欢搴撳瓨涓嶈冻锛屾湭鍒嗛厤锛歿remainingPartial}", "");
-                                }
-                            }
-
-                            //鍒嗛厤鏁翠欢锛堜紭鍏堝钩搴� Status=2锛�
-                            int remainingFullBoxes = fullBoxes;
-                            if (remainingFullBoxes > 0)
-                            {
-                                var invList_pk = queryInventoryByStockStatus(2);
-                                foreach (var inv in invList_pk)
-                                {
-                                    if (remainingFullBoxes <= 0) break;
-
-                                    decimal available = (decimal)(inv.StockQuantity - inv.OutboundQuantity);
-                                    if (available < boxQty) continue;
-
-                                    int canProvideBoxes = (int)(available / boxQty);
-                                    if (canProvideBoxes <= 0) continue;
-
-                                    int useBoxes = Math.Min(canProvideBoxes, remainingFullBoxes);
-                                    decimal useQty = useBoxes * boxQty;
-
-                                    var detail = new Dt_DeliveryOrderDetail
-                                    {
-                                        Goods_no = item.goods_no,
-                                        Order_qty = useQty,
-                                        Batch_num = inv.BatchNo,
-                                        Exp_date = inv.ValidityPeriod,
-                                        OotDetailStatus = "鏂板缓",
-                                        Status = 2, //骞冲簱
-                                        Reservoirarea = inv.LocationCode
-                                    };
-                                    entityOrder.Details.Add(detail);
-
-                                    inv.OutboundQuantity += (float)useQty;
-                                    BaseDal.Db.Updateable(inv).ExecuteCommand();
-
-                                    remainingFullBoxes -= useBoxes;
-                                }
-
-                                // 骞冲簱涓嶅 鈫� 绔嬪簱琛� (Status=1)
-                                if (remainingFullBoxes > 0)
-                                {
-                                    var invList_ly = queryInventoryByStockStatus(1);
-                                    foreach (var inv in invList_ly)
-                                    {
-                                        if (remainingFullBoxes <= 0) break;
-
-                                        decimal available = (decimal)(inv.StockQuantity - inv.OutboundQuantity);
-                                        if (available < boxQty) continue;
-
-                                        int canProvideBoxes = (int)(available / boxQty);
-                                        if (canProvideBoxes <= 0) continue;
-
-                                        int useBoxes = Math.Min(canProvideBoxes, remainingFullBoxes);
-                                        decimal useQty = useBoxes * boxQty;
-
-                                        var detail = new Dt_DeliveryOrderDetail
-                                        {
-                                            Goods_no = item.goods_no,
-                                            Order_qty = useQty,
-                                            Batch_num = inv.BatchNo,
-                                            Exp_date = inv.ValidityPeriod,
-                                            OotDetailStatus = "鏂板缓",
-                                            Status = 0, //绔嬪簱锛堣ˉ鏁寸锛�
-                                            Reservoirarea = inv.LocationCode
-                                        };
-                                        entityOrder.Details.Add(detail);
-
-                                        inv.OutboundQuantity += (float)useQty;
-                                        BaseDal.Db.Updateable(inv).ExecuteCommand();
-
-                                        remainingFullBoxes -= useBoxes;
-                                    }
-                                }
-
-                                if (remainingFullBoxes > 0)
-                                {
-                                    decimal unfilledQty = remainingFullBoxes * boxQty;
-                                    SendErrorToUpstream(3, "", $"鍑哄簱鍗昜{outorder.order_no}]鐗╂枡[{item.goods_no}]鏁寸搴撳瓨涓嶈冻锛屾湭鍒嗛厤鏁伴噺锛歿unfilledQty}", "");
-                                }
-                            }
-                        }
-
-                        _DeliveryOrders.Add(entityOrder);
-                    }
-
-                    // 鎻掑叆涓昏〃+鏄庣粏
-                    BaseDal.Db.InsertNav(_DeliveryOrders)
-                        .Include(x => x.Details)
-                        .ExecuteCommand();
-
-                    Db.Ado.CommitTran();
-                    return responseContent.OK("鍚屾鍑哄簱鍗曟垚鍔�");
-                }
-                catch (Exception ex)
-                {
-                    Db.Ado.RollbackTran();
-                    SendErrorToUpstream(3, "", ex.Message, "");
-                    return responseContent.Error("鍚屾澶辫触: " + ex.Message);
-                }
-            }
-            catch (Exception ex)
-            {
-                SendErrorToUpstream(3, "", ex.Message, "");
-                return responseContent.Error("鍚屾澶辫触: " + ex.Message);
-            }
-        }
-
         /// <summary>
         /// 杩囨护娌℃湁瀵瑰晢鍝佽繘琛岀淮鎶ょ殑鍑哄簱鍗曡繘琛岃繃婊�
         /// </summary>
         /// <returns></returns>
-        public WebResponseContent GetUpstreamOutOrder2()
+        public WebResponseContent GetUpstreamOutOrder()
         {
             var responseContent = new WebResponseContent();
             try
@@ -522,12 +248,15 @@
                         {
                             //  1锔忊儯 杞负姝f暟锛堜笂娓稿彲鑳戒紶璐熸暟锛�
                             item.order_qty = Math.Abs(item.order_qty);
+
+                            //鍑哄簱鏁伴噺
                             decimal orderQty = (decimal)item.order_qty;
 
                             //  2锔忊儯 鏌ョ墿鏂欏熀纭�淇℃伅锛堣幏鍙栫瑙勶級
-                            var medication = BaseDal.Db.Queryable<Dt_MedicineGoods>()
-                                .Where(m => m.Goods_no == item.goods_no)
+                            var medication = BaseDal.Db.Queryable<Dt_MaterielInfo>()
+                                .Where(m => m.MaterielCode == item.goods_no)
                                 .First();
+                            #region 妫�鏌ヨ繖涓嚭搴撳崟涓殑鐗╂枡淇℃伅鏄惁瀛樺湪
                             //濡傛灉鐗╂枡淇℃伅涓嶅瓨鍦紝璺宠繃鏁翠釜鍏ュ簱鍗�
                             if (medication == null)
                             {
@@ -544,12 +273,15 @@
                                 break;
                             }
 
+                            
                             if (medication == null)
                             {
                                 SendErrorToUpstream(3, "", $"鎵句笉鍒扮墿鏂欎俊鎭細{item.goods_no}", "");
                                 continue;
                             }
+                            #endregion
 
+                            // 濡傛灉绠辫灏忎簬绛変簬0锛屼娇鐢ㄩ粯璁ゅ��1,鍚﹀垯灏辩敤瀹為檯鏁伴噺
                             decimal boxQty = medication.BoxQty <= 0 ? 1 : medication.BoxQty;
 
                             //  3锔忊儯 璁$畻鏁翠欢涓庢暎浠舵暟閲�
@@ -560,34 +292,61 @@
                             string requestedBatch = string.IsNullOrEmpty(item.batch_num) ? null : item.batch_num;
 
                             // helper: 鏌ヨ搴撳瓨鍑芥暟锛堟寜鍏ュ簱鏃堕棿鍗囧簭锛�
+                            #region 浣跨敤搴撳瓨淇℃伅涓殑stockStatus鏉ュ尯鍒嗗钩搴撳拰绔嬪簱
                             // 瀹氫箟涓�涓鎵樺彉閲忥細杈撳叆int鍙傛暟锛岃繑鍥濴ist<Dt_InventoryInfo>
-                            Func<int, List<Dt_InventoryInfo>> queryInventoryByStockStatus = (stockStatus) =>
-                            {
-                                // 1. 鍒涘缓鍩虹鏌ヨ
-                                var q = BaseDal.Db.Queryable<Dt_InventoryInfo>()
-                                    .Where(i => i.MaterielCode == item.goods_no &&           // 鐗╂枡缂栧彿鍖归厤
-                                                (i.StockQuantity - i.OutboundQuantity) > 0 && // 鍙敤搴撳瓨>0
-                                                i.StockStatus == stockStatus);               // 搴撳瓨鐘舵�佸尮閰�
+                            //Func<int, List<Dt_InventoryInfo>> queryInventoryByStockStatus = (stockStatus) =>
+                            //{
+                            //    // 1. 鍒涘缓鍩虹鏌ヨ
+                            //    var q = BaseDal.Db.Queryable<Dt_InventoryInfo>()
+                            //        .Where(i => i.MaterielCode == item.goods_no &&           // 鐗╂枡缂栧彿鍖归厤
+                            //                    (i.StockQuantity - i.OutboundQuantity) > 0 && // 鍙敤搴撳瓨>0
+                            //                    i.StockStatus == stockStatus);               // 搴撳瓨鐘舵�佸尮閰�
 
-                                // 2. 鏉′欢绛涢�夛紙濡傛灉鏈夋壒娆″彿瑕佹眰锛�
+                            //    // 2. 鏉′欢绛涢�夛紙濡傛灉鏈夋壒娆″彿瑕佹眰锛�
+                            //    if (!string.IsNullOrEmpty(requestedBatch))
+                            //        q = q.Where(i => i.BatchNo == requestedBatch);
+
+                            //    // 3. 鎵ц鏌ヨ骞惰繑鍥炵粨鏋�
+                            //    return q.OrderBy(i => i.InDate).ToList();  // 鎸夊叆搴撴椂闂存帓搴�
+                            //}; 
+                            #endregion
+
+                            #region 浣跨敤搴撴埧缂栧彿鏉ュ尯鍒嗘槸骞冲簱鍜岀珛搴�
+                            // helper: 鏌ヨ搴撳瓨鍑芥暟锛堟寜鍏ュ簱鏃堕棿鍗囧簭锛�
+                            // 鐢ㄥ簱鎴跨紪鍙峰尯鍒嗙珛搴撳拰骞冲簱锛氱珛搴� WarehouseCode == "001" 杈撳叆true灏辨槸绔嬪簱鍚﹀垯灏辨槸骞冲簱
+                            Func<bool, List<Dt_InventoryInfo>> queryInventoryByWarehouseType = (isLiku) =>
+                            {
+                                var q = BaseDal.Db.Queryable<Dt_InventoryInfo>()
+                                    .Where(i => i.MaterielCode == item.goods_no &&
+                                                (i.StockQuantity - i.OutboundQuantity) > 0);
+
+                                if (isLiku)
+                                    q = q.Where(i => i.WarehouseCode == "001"); // 绔嬪簱
+                                else
+                                    q = q.Where(i => i.WarehouseCode != "001"); // 骞冲簱
+
                                 if (!string.IsNullOrEmpty(requestedBatch))
                                     q = q.Where(i => i.BatchNo == requestedBatch);
 
-                                // 3. 鎵ц鏌ヨ骞惰繑鍥炵粨鏋�
-                                return q.OrderBy(i => i.InDate).ToList();  // 鎸夊叆搴撴椂闂存帓搴�
+                                return q.OrderBy(i => i.InDate).ToList();
                             };
-                            // 4锔忊儯鍒嗛厤鏁d欢锛堜紭鍏堢珛搴� Status=0锛�
-                            decimal remainingPartial = partialQty;
+                            #endregion
+                            // 4锔忊儯鍒嗛厤鏁d欢锛堜紭鍏堢珛搴� WarehouseCode == "001锛�
+                            decimal remainingPartial = partialQty; //鏁d欢
                             if (remainingPartial > 0)
                             {
-                                var invList_ly = queryInventoryByStockStatus(0);
+                                //杩斿洖涓�涓狶ist<Dt_InventoryInfo>stockStatus==0鐨勫簱瀛樺垪琛�
+                                var invList_ly = queryInventoryByWarehouseType(true); //绔嬪簱 WarehouseCode == "001"
                                 foreach (var inv in invList_ly)
                                 {
                                     if (remainingPartial <= 0) break;
 
+                                    //鍙敤搴撳瓨鏁伴噺
                                     decimal available = (decimal)(inv.StockQuantity - inv.OutboundQuantity);
+
                                     if (available <= 0) continue;
 
+                                    //琛ㄧず銆屽綋鍓嶈繕闇�瑕佸嚭搴撶殑鏁伴噺銆嶆垨銆屽緟鍒嗛厤鏁伴噺銆嶃��
                                     decimal use = Math.Min(available, remainingPartial);
 
                                     var detail = new Dt_DeliveryOrderDetail
@@ -598,11 +357,11 @@
                                         Exp_date = inv.ValidityPeriod,
                                         OotDetailStatus = "鏂板缓",
                                         Status = 0, //绔嬪簱
-                                        Reservoirarea = inv.LocationCode
+                                        Reservoirarea = inv.WarehouseCode
                                     };
                                     entityOrder.Details.Add(detail);
 
-                                    inv.OutboundQuantity += (float)use;
+                                    inv.OutboundQuantity += use;
                                     BaseDal.Db.Updateable(inv).ExecuteCommand();
 
                                     remainingPartial -= use;
@@ -611,7 +370,7 @@
                                 // 绔嬪簱涓嶅 鈫� 骞冲簱琛� (Status=2)
                                 if (remainingPartial > 0)
                                 {
-                                    var invList_pk = queryInventoryByStockStatus(2);
+                                    var invList_pk = queryInventoryByWarehouseType(false); //骞冲簱
                                     foreach (var inv in invList_pk)
                                     {
                                         if (remainingPartial <= 0) break;
@@ -629,11 +388,11 @@
                                             Exp_date = inv.ValidityPeriod,
                                             OotDetailStatus = "鏂板缓",
                                             Status = 2, //骞冲簱
-                                            Reservoirarea = inv.LocationCode
+                                            Reservoirarea = inv.WarehouseCode
                                         };
                                         entityOrder.Details.Add(detail);
 
-                                        inv.OutboundQuantity += (float)use;
+                                        inv.OutboundQuantity += use;
                                         BaseDal.Db.Updateable(inv).ExecuteCommand();
 
                                         remainingPartial -= use;
@@ -647,10 +406,10 @@
                             }
 
                             //鍒嗛厤鏁翠欢锛堜紭鍏堝钩搴� Status=2锛�
-                            int remainingFullBoxes = fullBoxes;
+                            int remainingFullBoxes = fullBoxes;//鏁翠欢绠辨暟
                             if (remainingFullBoxes > 0)
                             {
-                                var invList_pk = queryInventoryByStockStatus(2);
+                                var invList_pk = queryInventoryByWarehouseType(true);
                                 foreach (var inv in invList_pk)
                                 {
                                     if (remainingFullBoxes <= 0) break;
@@ -672,20 +431,20 @@
                                         Exp_date = inv.ValidityPeriod,
                                         OotDetailStatus = "鏂板缓",
                                         Status = 2, //骞冲簱
-                                        Reservoirarea = inv.LocationCode
+                                        Reservoirarea = inv.WarehouseCode
                                     };
                                     entityOrder.Details.Add(detail);
 
-                                    inv.OutboundQuantity += (float)useQty;
+                                    inv.OutboundQuantity += useQty;
                                     BaseDal.Db.Updateable(inv).ExecuteCommand();
 
                                     remainingFullBoxes -= useBoxes;
                                 }
 
-                                // 骞冲簱涓嶅 鈫� 绔嬪簱琛� (Status=1)
+                                // 骞冲簱涓嶅 鈫� 绔嬪簱琛� (Status=0)
                                 if (remainingFullBoxes > 0)
                                 {
-                                    var invList_ly = queryInventoryByStockStatus(1);
+                                    var invList_ly = queryInventoryByWarehouseType(true); //绔嬪簱
                                     foreach (var inv in invList_ly)
                                     {
                                         if (remainingFullBoxes <= 0) break;
@@ -711,7 +470,7 @@
                                         };
                                         entityOrder.Details.Add(detail);
 
-                                        inv.OutboundQuantity += (float)useQty;
+                                        inv.OutboundQuantity += useQty;
                                         BaseDal.Db.Updateable(inv).ExecuteCommand();
 
                                         remainingFullBoxes -= useBoxes;
@@ -792,10 +551,10 @@
                         string materialCode = "YY";//榛樿鍊�
                                                    //鑾峰彇褰撳墠璁㈠崟鐨勭涓�涓槑缁嗛」
                         var firstDetail = order.Details.FirstOrDefault();
-                        if (firstDetail?.MedicineGoods != null && !string.IsNullOrEmpty(firstDetail.MedicineGoods.MaterialCode))
+                        if (firstDetail?.MedicineGoods != null && !string.IsNullOrEmpty(firstDetail.MedicineGoods.MaterielErpType))
                         {
                             //濡傛灉鏉′欢婊¤冻锛屽皢鐗╂枡浠g爜璁剧疆涓虹涓�涓槑缁嗛」瀵瑰簲鐨勮嵂鍝佺墿鏂欎唬鐮�
-                            materialCode = firstDetail.MedicineGoods.MaterialCode;
+                            materialCode = firstDetail.MedicineGoods.MaterielErpType;
                         }
                         // 3. 缁勮 DTO
                         var ediDto = new TowcsDto.ToediOutInfo
@@ -810,8 +569,8 @@
                             {
                                 batchNo = d.Batch_num,
                                 productCode = d.Goods_no,
-                                productName = d.MedicineGoods?.Goods_spm,
-                                productSpecifications = d.MedicineGoods?.Model,
+                                productName = d.MedicineGoods?.MaterielName,
+                                productSpecifications = d.MedicineGoods?.MaterielModel,
                                 quantity = (int)d.Order_qty,
                                 //stocktakingDetails = order.Out_type == "3"
                                 //    ? new List<ToOutediInStock>
@@ -840,7 +599,6 @@
                               .SetColumns(d => new Dt_DeliveryOrderDetail { Status = 1, OotDetailStatus = "宸插畬鎴�" })
                               .Where(d => d.DeliveryOrderId == order.Id && d.Status == 0)
                               .ExecuteCommand();
-
                             Console.WriteLine($"璁㈠崟 {order.Out_no} 鎺ㄩ�佹垚鍔�");
                         }
                         else
@@ -1072,7 +830,7 @@
         }
 
 
-    
+
 
         /// <summary>
         /// 鎺ㄩ�佸紓甯镐俊鎭粰涓婃父绯荤粺 1.鍏ュ簱鍗曟帴鍙o紱2.鍏ュ簱鍗曟姤瀹屾垚鎺ュ彛锛�3.鍑哄簱鍗曟帴鍙o紱4.鍑哄簱鎶ュ畬鎴愭帴鍙o紱5.鑽搧鍩虹淇℃伅鍚屾鎺ュ彛锛�6.渚涘簲鍟嗕俊鎭帴鍙o紱7.瀹㈡埛淇℃伅鎺ュ彛锛�8.搴撳瓨鏌ヨ鎺ュ彛
@@ -1101,33 +859,6 @@
             }
         }
 
-        public WebResponseContent GetPdDeliveryOrders(SaveModel saveModel)
-        {
-            WebResponseContent content = new WebResponseContent();
-            try
-            {
-                int pageNo = saveModel.MainData["pageNo"].ObjToInt();
-                string warehouseCode = saveModel.MainData["warehouseId"].ToString();
-                string orderNo = saveModel.MainData["orderNo"].ToString();
-                List<Dt_DeliveryOrder> dt_ReceiveOrders = new List<Dt_DeliveryOrder>();
-                if (string.IsNullOrEmpty(orderNo))
-                {
-                    dt_ReceiveOrders = Db.Queryable<Dt_DeliveryOrder>().Where(x => (x.OutStatus == "鏂板缓" || x.OutStatus == "寮�濮�") && x.Warehouse_no == warehouseCode && x.Out_type == "3").Includes(x => x.Details).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 5);
-                }
-                else
-                {
-                    dt_ReceiveOrders = Db.Queryable<Dt_DeliveryOrder>().Where(x => (x.Out_no.Contains(orderNo) || x.Client_no.Contains(orderNo)) && (x.OutStatus == "鏂板缓" || x.OutStatus == "寮�濮�" && x.Out_type == "3") && x.Warehouse_no == warehouseCode).OrderByDescending(x => x.CreateDate).Includes(x => x.Details).ToPageList(pageNo, 5);
-                }
-
-                content.OK(data: dt_ReceiveOrders);
-            }
-            catch (Exception)
-            {
-
-                throw;
-            }
-            return content;
-        }
 
         public WebResponseContent GetDeliveryOrders(SaveModel saveModel)
         {
@@ -1144,7 +875,7 @@
                 }
                 else
                 {
-                    dt_ReceiveOrders = Db.Queryable<Dt_DeliveryOrder>().Where(x => (x.Out_no.Contains(orderNo) || x.Client_no.Contains(orderNo)) && (x.OutStatus == "鏂板缓" || x.OutStatus == "寮�濮�" && x.Out_type != "3") && x.Warehouse_no == warehouseCode).OrderByDescending(x => x.CreateDate).Includes(x => x.Details).ToPageList(pageNo, 5);
+                    dt_ReceiveOrders = Db.Queryable<Dt_DeliveryOrder>().Where(x => (x.Out_no.Contains(orderNo) || x.Client_no.Contains(orderNo)) && (x.OutStatus == "鏂板缓" || x.OutStatus == "寮�濮�") && x.Out_type != "3" && x.Warehouse_no == warehouseCode).OrderByDescending(x => x.CreateDate).Includes(x => x.Details).ToPageList(pageNo, 5);
                 }
 
                 content.OK(data: dt_ReceiveOrders);
@@ -1157,6 +888,13 @@
             return content;
         }
 
+        /// <summary>
+        /// 鏌ヨ鍑哄簱/鐩樼偣鍗曡鎯� 鐪嬪嚭搴撳崟鏄庣粏銆�
+        /// </summary>
+        /// <param name="pageNo"></param>
+        /// <param name="orderNo"></param>
+        /// <param name="isPick"></param>
+        /// <returns></returns>
         public WebResponseContent GetDeliveryOrderDetail(int pageNo, string orderNo, bool isPick)
         {
             WebResponseContent content = new WebResponseContent();
@@ -1165,29 +903,34 @@
                 cabinOrder = Db.Queryable<Dt_DeliveryOrder>().Includes(x => x.Details).First(x => x.Out_no == orderNo && x.Out_type == "3");
             else
                 cabinOrder = Db.Queryable<Dt_DeliveryOrder>().Includes(x => x.Details).First(x => x.Out_no == orderNo && x.Out_type != "3");
-            List<Dt_DeliveryOrderDetail>? cabinOrderDetails = cabinOrder.Details?.Where(x => x.Reservoirarea == pageNo.ToString()).ToList();
-            content.OK(data: cabinOrderDetails);
+            List<Dt_DeliveryOrderDetail>? cabinOrderDetails = cabinOrder.Details?.Where(x => x.Reservoirarea == pageNo.ToString()).ToList(); 
+            content.OK(data: cabinOrderDetails); 
             return content;
         }
-        public WebResponseContent MatPicking(SaveModel saveModel)
+
+        public WebResponseContent OutFinish(SaveModel saveModel)
         {
             WebResponseContent content = new WebResponseContent();
             try
             {
-                var LocationCode = saveModel.MainData["LocationCode"].ToString();
-                var orderNo = saveModel.MainData["orderNo"].ToString();
-                var batchNo = saveModel.MainData["batchNo"].ToString();
-                var Inqty = saveModel.MainData["Inqty"].ObjToInt();
-                var warehouseCode = saveModel.MainData["warehouseCode"].ToString();
-                Dt_DeliveryOrder cabinOrder = BaseDal.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == orderNo && x.Warehouse_no == warehouseCode && x.Out_type == "3").Includes(x => x.Details).First();
-                if (cabinOrder == null) return WebResponseContent.Instance.Error($"鐩樼偣鍗曞凡瀹屾垚");
-                Dt_DeliveryOrderDetail cabinOrderDetail = cabinOrder.Details.Where(x => x.Batch_num == batchNo && x.Reservoirarea == warehouseCode).First();
-                if (cabinOrderDetail == null) return WebResponseContent.Instance.Error($"鐩樼偣鍗曟槑缁嗗凡瀹屾垚");
+                var LocationCode = saveModel.MainData["locationCode"].ToString();
+                var TaskId = saveModel.MainData["taskId"].ObjToInt();
+                Dt_SupplyTask supplyTask = _supplyTaskService.Repository.QueryFirst(x => x.TaskId == TaskId && x.TaskStatus == SupplyStatusEnum.NewOut.ObjToInt());
+                if (supplyTask == null) throw new Exception("褰撳墠鍑哄簱浠诲姟宸插畬鎴�");
+                if (supplyTask.LocationCode != LocationCode) throw new Exception($"褰撳墠鍑哄簱璐т綅銆恵LocationCode}銆戜笌浠诲姟鍒嗛厤璐т綅涓嶅尮閰�");
+                supplyTask.TaskStatus = SupplyStatusEnum.OutFinish.ObjToInt();
+
+                Dt_DeliveryOrder cabinOrder = BaseDal.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == supplyTask.OrderNo && x.Warehouse_no == supplyTask.WarehouseCode).Includes(x => x.Details).First();
+                if (cabinOrder == null) return WebResponseContent.Instance.Error($"鍑哄簱鍗曞凡瀹屾垚");
+
+                Dt_DeliveryOrderDetail cabinOrderDetail = cabinOrder.Details.Where(x => x.Batch_num == supplyTask.BatchNo && x.Reservoirarea == supplyTask.WarehouseCode && x.Goods_no == supplyTask.MaterielCode).First();
+                if (cabinOrderDetail == null) return WebResponseContent.Instance.Error($"鍑哄簱鍗曟槑缁嗗凡瀹屾垚");
                 Dt_MaterielInfo materielInfo = _basicService.MaterielInfoService.Repository.QueryFirst(x => x.MaterielCode == cabinOrderDetail.Goods_no);
                 if (materielInfo == null) return WebResponseContent.Instance.Error($"璇风淮鎶ょ墿鏂欑紪鍙枫�恵cabinOrderDetail.Goods_no}銆戠殑鐗╂枡淇℃伅");
-                cabinOrderDetail.Order_Outqty += Inqty;
+                cabinOrderDetail.Order_Outqty += supplyTask.StockQuantity;
                 if (cabinOrderDetail.Order_Outqty > cabinOrderDetail.Order_qty)
-                    return WebResponseContent.Instance.Error($"瀹炵洏鏁伴噺涓嶅彲瓒呭嚭璐﹂潰鏁伴噺");
+                    return WebResponseContent.Instance.Error($"鍑哄簱鏁伴噺涓嶅彲瓒呭嚭鍗曟嵁鏁伴噺");
+
 
                 #region 澶勭悊鍑哄簱鍗曪紝璐т綅锛屽簱瀛橈紝搴撳瓨鎵规淇℃伅
                 _unitOfWorkManage.BeginTran();
@@ -1204,54 +947,51 @@
                 {
                     _deliveryOrderDetailServices.Repository.UpdateData(cabinOrderDetail);
                 }
-                var cabinOrder1 = BaseDal.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == cabinOrder.Out_no && x.Out_type == "3").Includes(x => x.Details).First();
+                var cabinOrder1 = BaseDal.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == cabinOrder.Out_no && x.Out_type != "3").Includes(x => x.Details).First();
                 if (cabinOrder1.Details == null || cabinOrder1.Details.Count < 1) cabinOrder.OutStatus = "宸插畬鎴�";
-                if (cabinOrder.OutStatus == "宸插畬鎴�")
-                    Repository.DeleteAndMoveIntoHty(cabinOrder, OperateTypeEnum.鑷姩瀹屾垚);
-                else
-                    Repository.UpdateData(cabinOrder);
+                Repository.UpdateData(cabinOrder);
                 #endregion
 
                 #region 搴撳瓨
                 Dt_InventoryInfo inventoryInfo = _inventoryInfoService.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no && x.LocationCode == LocationCode);
                 if (inventoryInfo == null) return WebResponseContent.Instance.Error($"鏈壘鍒拌揣浣嶃�恵LocationCode}銆戠殑搴撳瓨淇℃伅");
-                inventoryInfo.SupplyQuantity += Inqty;
-                _inventoryInfoService.UpdateData(inventoryInfo);
+                inventoryInfo.StockQuantity -= supplyTask.StockQuantity;
+                if (inventoryInfo.StockQuantity <= 0)
+                    _inventoryInfoService.DeleteData(inventoryInfo);
+                else
+                    _inventoryInfoService.UpdateData(inventoryInfo);
                 #endregion
 
-                #region 浠诲姟璁板綍
-                Dt_SupplyTask supplyTask = new Dt_SupplyTask()
+                #region 璐т綅
+                var location = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == LocationCode);
+                if (location == null) return WebResponseContent.Instance.Error($"璇风淮鎶よ揣浣嶇紪鍙枫�恵LocationCode}銆戠殑璐т綅淇℃伅");
+                if (location.EnableStatus == EnableStatusEnum.Disable.ObjToInt())
+                    return WebResponseContent.Instance.Error($"璐т綅缂栧彿銆恵LocationCode}銆戝凡绂佺敤锛岃鎭㈠姝e父鍐嶄娇鐢�");
+                Dt_InventoryInfo inventoryInfo1 = _inventoryInfoService.Repository.QueryFirst(x => x.LocationCode == LocationCode);
+                if (inventoryInfo1 == null)
                 {
-                    WarehouseCode = cabinOrderDetail.Reservoirarea,
-                    BatchNo = inventoryInfo.BatchNo,
-                    MaterielName = inventoryInfo.MaterielName,
-                    MaterielCode = inventoryInfo.MaterielCode,
-                    MaterielSpec = inventoryInfo.MaterielSpec,
-                    TaskType = TaskTypeEnum.OutInventory.ObjToInt(),
-                    CreateDate = DateTime.Now,
-                    Creater = App.User.UserName,
-                    LocationCode = LocationCode,
-                    OrderNo = cabinOrder.Out_no,
-                    StockQuantity = inventoryInfo.StockQuantity,
-                    SupplyQuantity = Inqty,
-                    Remark = "鐩樼偣"
-                };
-                _supplyTaskService.AddData(supplyTask);
+                    location.LocationStatus = LocationStatusEnum.Free.ObjToInt();
+                    _basicService.LocationInfoService.UpdateData(location);
+                }
                 #endregion
+
+                _supplyTaskService.UpdateData(supplyTask);
 
                 #region 搴撳瓨鎵规
                 Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode == inventoryInfo.MaterielCode);
                 if (inventory_Batch != null)
                 {
-                    inventory_Batch.SupplyQuantity += Inqty;
-                    _inventory_BatchServices.UpdateData(inventory_Batch);
+                    inventory_Batch.StockQuantity -= supplyTask.StockQuantity;
+                    if (inventory_Batch.StockQuantity <= 0)
+                        _inventory_BatchServices.DeleteData(inventory_Batch);
+                    else
+                        _inventory_BatchServices.UpdateData(inventory_Batch);
                 }
                 #endregion
 
                 _unitOfWorkManage.CommitTran();
                 #endregion
-
-                content.OK(cabinOrderDetail.Order_Outqty.ToString());
+                content.OK();
             }
             catch (Exception ex)
             {
@@ -1260,7 +1000,14 @@
             }
             return content;
         }
-        public WebResponseContent FeedbackOut(SaveModel saveModel)
+
+
+        /// <summary>
+        /// 骞冲簱浜哄伐鎷f枡鍑哄簱澶勭悊锛堝嵆浜哄伐鎵爜鍑哄簱鏃惰皟鐢級
+        /// </summary>
+        /// <param name="saveModel"></param>
+        /// <returns></returns>
+        public WebResponseContent MatPicking(SaveModel saveModel)
         {
             WebResponseContent content = new WebResponseContent();
             try
@@ -1331,6 +1078,7 @@
                     MaterielName = inventoryInfo.MaterielName,
                     MaterielCode = inventoryInfo.MaterielCode,
                     MaterielSpec = inventoryInfo.MaterielSpec,
+                    TaskStatus = SupplyStatusEnum.OutFinish.ObjToInt(),
                     TaskType = TaskTypeEnum.OutPick.ObjToInt(),
                     CreateDate = DateTime.Now,
                     Creater = App.User.UserName,

--
Gitblit v1.9.3