From 2b49f7643d15b74889d190f216630559006ed93a Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期一, 01 十二月 2025 09:48:43 +0800
Subject: [PATCH] pad和后端的优化

---
 新建文件夹/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs |  117 ++++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 76 insertions(+), 41 deletions(-)

diff --git "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs" "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs"
index d0f0bb3..4b58f33 100644
--- "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs"
+++ "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs"
@@ -1,12 +1,7 @@
 锘縰sing HslCommunication;
-using MailKit.Search;
 using Newtonsoft.Json;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection.Metadata;
-using System.Text;
-using System.Threading.Tasks;
+using SqlSugar;
+using WIDESEA_Common;
 using WIDESEA_Common.OrderEnum;
 using WIDESEA_Common.StockEnum;
 using WIDESEA_Common.TaskEnum;
@@ -30,12 +25,22 @@
     {
         private readonly ICabinOrderServices _cabinOrderServices;
         private readonly IDeliveryOrderServices _deliveryOrderServices;
+        private readonly ICabinOrderHtyServices _cabinOrderHtyServices;
+        private readonly IDeliveryOrderHtyServices _deliveryOrderHtyServices;
         private readonly ISupplyTaskService _supplyTaskService;
-        public InventoryServices(IRepository<Dt_Inventory> BaseDal, ICabinOrderServices cabinOrderServices, IDeliveryOrderServices deliveryOrderServices, ISupplyTaskService supplyTaskService) : base(BaseDal)
+        private readonly ISupplyTaskHtyService _supplyTaskHtyService;
+        private readonly IInventory_BatchServices _inventoryBatchServices;
+        private readonly IMessageInfoService _infoService;
+        public InventoryServices(IRepository<Dt_Inventory> BaseDal, ICabinOrderServices cabinOrderServices, IDeliveryOrderServices deliveryOrderServices, ISupplyTaskService supplyTaskService, IInventory_BatchServices inventoryBatchServices, IMessageInfoService infoService,ICabinOrderHtyServices cabinOrderlHtyServices,IDeliveryOrderHtyServices deliveryOrderHtyServices, ISupplyTaskHtyService supplyTaskHtyService) : base(BaseDal)
         {
             _cabinOrderServices = cabinOrderServices;
             _deliveryOrderServices = deliveryOrderServices;
             _supplyTaskService = supplyTaskService;
+            _inventoryBatchServices = inventoryBatchServices;
+            _infoService = infoService;
+            _cabinOrderHtyServices = cabinOrderlHtyServices;
+            _deliveryOrderHtyServices = deliveryOrderHtyServices;
+            _supplyTaskHtyService = supplyTaskHtyService;
         }
 
         /// <summary>
@@ -45,51 +50,41 @@
         /// <param name="batch_num">鎵瑰彿</param>
         /// <returns></returns>
         /// <exception cref="NotImplementedException"></exception>
-        public WebResponseContent GetInventoryList(string goods_no, string batch_num)
+        public WebResponseContent GetInventoryList(int[] keys)
         {
             var responseContent = new WebResponseContent();
             try
             {
-                var url = "http://121.37.118.63/GYZ2/95fck/repositoryInfo";
-                var result = HttpHelper.Post(url, new { goods_no, batch_num }.ToJsonString());
+                //鏍规嵁id鏌ヨ搴撳瓨鎵规淇℃伅琛紝鑾峰彇鍒颁粬浠殑鍟嗗搧缂栫爜鍜屾壒娆″彿
+                var inventoryBatches = _inventoryBatchServices.Repository.QueryData(x => keys.Contains(x.Id)); //鏌ュ叏閮�
 
-                var response = JsonConvert.DeserializeObject<UpstreamResponse<InventoryInfo>>(result);
-
-                if (response.resultCode != "0")
+                var url = "http://192.168.1.100:80/GYZ2/95fck/repositoryInfo";
+                foreach (var item in inventoryBatches)
                 {
-                    //SendErrorToUpstream(8, "", response.resultMsg ?? "涓婃父鎺ュ彛杩斿洖澶辫触", "");
-                    return responseContent.Error(response.resultMsg ?? "涓婃父鎺ュ彛杩斿洖澶辫触");
-                }
+                    var result = HttpHelper.Post(url, new { goods_no = item.MaterielCode, batch_num = item.BatchNo }.ToJsonString());
 
-                if (response.data == null || !response.data.Any())
-                {
-                    return responseContent.OK("鏃犳柊搴撳瓨鏁版嵁");
+                    var response = JsonConvert.DeserializeObject<UpstreamResponse<InventoryInfo>>(result);
+                    if (response == null) continue;
+                    var data = response.data.FirstOrDefault();
+                    if (data != null)
+                        item.ERPStockQuantity = data.business_qty;
                 }
-
-                Db.Ado.BeginTran();
-                foreach (var item in response.data)
-                {
-                    // 浣跨敤 FirstOrDefault 閬垮厤鎵句笉鍒拌褰曟椂鎶涘嚭寮傚父
-                    var Inver = Db.Queryable<Dt_Inventory_Batch>()
-                        .First(x => x.MaterielCode == item.goods_no && x.BatchNo == item.batch_num);
-
-                    if (Inver != null)
-                    {
-                        Inver.ERPStockQuantity = item.business_qty;
-                        Db.Updateable(Inver).ExecuteCommand();
-                    }
-                }
-                Db.Ado.CommitTran();
+                _inventoryBatchServices.UpdateData(inventoryBatches);
                 return responseContent.OK("搴撳瓨淇℃伅鍚屾瀹屾垚");
+
             }
             catch (Exception ex)
             {
-                Db.Ado.RollbackTran();
-                //SendErrorToUpstream(8, "", ex.Message, "");
                 return responseContent.Error("鍚屾澶辫触: " + ex.Message);
             }
         }
 
+
+        /// <summary>
+        /// wcs鍥炰紶缁欐垜璋冪敤鎴戠殑鏂规硶 涓嶇鏄叆搴� 鍑哄簱 鐩樼偣閮戒細璋冪敤杩欎釜鎺ュ彛(鐜板湪鐢ㄨ繖涓�)
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
 
         public ApiResponse<Dt_InventoryInfo> OrderFeedback(EdiOrderCallbackRequest request)
         {
@@ -102,7 +97,22 @@
                     case "1": //鍏ュ簱
                         {
                             Dt_CabinOrder cabinOrder = _cabinOrderServices.Db.Queryable<Dt_CabinOrder>().Where(x => x.Order_no == request.externalOrderNo && x.Warehouse_no == Warecode).Includes(x => x.Details).First();
-                            if (cabinOrder == null) throw new Exception($"鏈壘鍒板叆搴撳崟鍙枫�恵request.externalOrderNo}銆戠殑鍏ュ簱鍗曚俊鎭�");
+                            if (cabinOrder == null)
+                            {
+                                //鏌ユ壘鍘嗗彶鍏ュ簱鍗曪紝濡傛灉鏈夊氨杩斿洖0缁欎笅娓�
+                              
+                                    var inHty = _cabinOrderHtyServices.Repository.QueryData(x => x.Order_no == request.externalOrderNo && x.Warehouse_no == Warecode).ToList();
+                                    if (inHty.Count>0)
+                                    {
+                                        return new ApiResponse<Dt_InventoryInfo>
+                                        {
+                                            code = "0",
+                                            msg = $"鎴愬姛"
+                                        };
+                                }
+                                throw new Exception($"鏈壘鍒板叆搴撳崟鍙枫�恵request.externalOrderNo}銆戠殑鍏ュ簱鍗曚俊鎭�");
+
+                            }
                             if (cabinOrder.OdrderStatus == "宸插畬鎴�")
                                 return new ApiResponse<Dt_InventoryInfo> { code = "0", msg = $"鎴愬姛" };
                             WebResponseContent content = _cabinOrderServices.CompleteLKInOrder(cabinOrder, request);
@@ -112,7 +122,19 @@
                     case "2":
                         {
                             Dt_DeliveryOrder deliveryOrder = _deliveryOrderServices.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == request.externalOrderNo && x.Warehouse_no == Warecode).Includes(x => x.Details).First();
-                            if (deliveryOrder == null) throw new Exception($"鏈壘鍒板嚭搴撳崟鍙枫�恵request.externalOrderNo}銆戠殑鍑哄簱鍗曚俊鎭�");
+                            if (deliveryOrder == null)
+                                {
+                                var outHty = _deliveryOrderHtyServices.Repository.QueryData(x => x.Out_no == request.externalOrderNo && x.Warehouse_no == Warecode).ToList();
+                                    if (outHty.Count>0)
+                                    {
+                                        return new ApiResponse<Dt_InventoryInfo>
+                                        {
+                                            code = "0",
+                                            msg = $"鎴愬姛"
+                                        };
+                                }
+                                    throw new Exception($"鏈壘鍒板嚭搴撳崟鍙枫�恵request.externalOrderNo}銆戠殑鍑哄簱鍗曚俊鎭�");
+                                }
                             if (deliveryOrder.OutStatus == "宸插畬鎴�")
                                 return new ApiResponse<Dt_InventoryInfo> { code = "0", msg = $"鎴愬姛" };
                             WebResponseContent content = _deliveryOrderServices.CompleteLKOutOrder(deliveryOrder, request);
@@ -126,7 +148,20 @@
                             foreach (var detail in request.details)
                             {
                                 Dt_SupplyTask? supplyTask = supplyTasks.Where(x => x.MaterielCode == detail.productCode && x.BatchNo == detail.batchNo).FirstOrDefault();
-                                if (supplyTask == null) throw new Exception($"鏈壘鍒拌鍗曞彿銆恵request.externalOrderNo}銆戠墿鏂欑紪鍙枫�恵detail.productCode}銆戠殑鐩樼偣浠诲姟");
+                                if (supplyTask == null)
+                                {
+                                    var suppHty = _supplyTaskHtyService.Repository.QueryData(x => x.OrderNo == request.externalOrderNo && x.WarehouseCode == Warecode).ToList();
+                                    if (suppHty.Count>0)
+                                    {
+                                        return new ApiResponse<Dt_InventoryInfo>
+                                        {
+                                            code = "0",
+                                            msg = $"鎴愬姛"
+                                        };
+                                    }
+                                    throw new Exception($"鏈壘鍒拌鍗曞彿銆恵request.externalOrderNo}銆戠墿鏂欑紪鍙枫�恵detail.productCode}銆戠殑鐩樼偣浠诲姟");
+                                }
+                                    
                                 if (detail.isLossOrProfit == 1) // 鐩樹簭
                                 {
                                     supplyTask.SupplyQuantity = supplyTask.StockQuantity - detail.ea;
@@ -553,7 +588,7 @@
         {
             try
             {
-                var url = "http://121.37.118.63:80/GYZ2/95fck/exceptionLog";
+                var url = "http://192.168.1.100:80/GYZ2/95fck/exceptionLog";
 
                 var requestData = new
                 {

--
Gitblit v1.9.3