From bfc11f87e2b64420c9917c0b9881b3e327d6f796 Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期二, 04 十一月 2025 22:19:59 +0800
Subject: [PATCH] 优化调拨出入库

---
 新建文件夹/WIDESEA_WMSServer/ClassLibrary2/InventoryInfoService.cs |  167 +++++++++++--------------------------------------------
 1 files changed, 35 insertions(+), 132 deletions(-)

diff --git "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/ClassLibrary2/InventoryInfoService.cs" "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/ClassLibrary2/InventoryInfoService.cs"
index 4b6696c..876073f 100644
--- "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/ClassLibrary2/InventoryInfoService.cs"
+++ "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/ClassLibrary2/InventoryInfoService.cs"
@@ -1,10 +1,12 @@
 锘縰sing HslCommunication;
+using MailKit.Search;
 using SqlSugar;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEA_Common.WareHouseEnum;
 using WIDESEA_Core;
 using WIDESEA_Core.BaseRepository;
 using WIDESEA_Core.BaseServices;
@@ -23,153 +25,54 @@
         }
         public IRepository<Dt_InventoryInfo> Repository => BaseDal;
 
+
         /// <summary>
-        /// wcs鍥炰紶缁欐垜璋冪敤鎴戠殑鏂规硶
+        /// 鑾峰彇搴撳瓨
         /// </summary>
-        /// <param name="request"></param>
         /// <returns></returns>
-        public ApiResponse<Dt_InventoryInfo> OrderFeedback(EdiOrderCallbackRequest request)
+        public WebResponseContent GetInventory()
         {
+            WebResponseContent content = new WebResponseContent();
             try
             {
-                if (request == null || request.details == null || !request.details.Any())
+                List<object> lists = new List<object>();
+                #region 鍐峰喕搴�
+                string WareCodeLD = WarehouseEnum.鍐峰喕搴�.ObjToInt().ToString("000");
+                var LDQty = Convert.ToInt32(BaseDal.QueryData(x => x.WarehouseCode == WareCodeLD).Sum(x => x.StockQuantity));
+                lists.Add(new
                 {
-                    return new ApiResponse<Dt_InventoryInfo> { code = "500", msg = "璇锋眰鍙傛暟鏃犳晥" };
-                }
-
-                BaseDal.Db.Ado.BeginTran(); // 寮�鍚簨鍔�
-
-                foreach (var detail in request.details)
+                    name = WarehouseEnum.鍐峰喕搴�.ObjToString(),
+                    count = LDQty
+                });
+                #endregion
+                #region 楹荤簿搴�
+                string WareCodeMJ = WarehouseEnum.楹荤簿搴�.ObjToInt().ToString("000");
+                var MJQty = Convert.ToInt32(BaseDal.QueryData(x => x.WarehouseCode == WareCodeMJ).Sum(x => x.StockQuantity));
+                lists.Add(new
                 {
-                    // 鑾峰彇鏄庣粏涓殑鎬诲叆搴撴暟閲忥紙鑷姩杞负姝f暟锛�
-                    decimal orderQty = detail.orderDetails?
-                        .Sum(x => decimal.TryParse(x.quantity, out var q) ? Math.Abs(q) : 0)
-                        ?? 0;
-
-                    //鐩樼偣
-                    decimal diffQty = detail.stocktakingDetails?
-                        .Sum(x => Convert.ToDecimal(x.differenceQuantity))
-                        ?? 0;
-
-                    // 鏍规嵁鐗╂枡缂栧彿 + 鎵规鍙� 鏌ユ壘鏄惁宸叉湁搴撳瓨
-                    var entity = BaseDal.Db.Queryable<Dt_InventoryInfo>()
-                        .First(x => x.MaterielCode == detail.productCode && x.BatchNo == detail.batchNo);
-
-                    if (entity == null)
-                    {
-                        // 馃啎 涓嶅瓨鍦ㄥ垯鏂板缓搴撳瓨璁板綍
-                        entity = new Dt_InventoryInfo
-                        {
-                            PalletCode = detail.orderDetails?.FirstOrDefault()?.palletCode ?? "",
-                            WarehouseCode = 001.ToString(),  // 榛樿搴撴埧缂栧彿锛屽彲鏍规嵁涓氬姟鏀�
-                            LocationCode = "", // 鏆傛棤鍙┖
-                            StockStatus = 1,   // 绔嬪簱鍥哄畾涓� 1
-                            MaterielCode = detail.productCode ?? detail.productName,
-                            MaterielName = detail.productName ?? "",
-                            MaterielSpec = detail.productSpecifications ?? "",
-                            BatchNo = detail.batchNo,
-                            // 鍒濇鍏ュ簱鏁伴噺 = 瀹為檯鍏ュ簱鏁伴噺
-                            StockQuantity = 0,
-                            OutboundQuantity = 0,
-                            SupplyQuantity = 0,
-                            InDate = DateTime.Now,
-                            ProductionDate = detail.finishDate.ToString("yyyy-MM-dd"),
-                            ShelfLife = 0,
-                            ValidityPeriod = "",
-                            Remark = "WCS鍥炰紶鍒涘缓"
-                        };
-                    }
-
-                    switch (request.orderType)
-                    {
-                        case "1": // 鍏ュ簱
-                            entity.StockQuantity += orderQty;
-                            entity.InDate = DateTime.Now;
-                            entity.Remark = "鍏ュ簱鍗曞洖浼�";
-                            break;
-
-                        case "2": // 鍑哄簱
-                            entity.OutboundQuantity += orderQty;
-                            entity.StockQuantity -= orderQty;
-                            if (entity.StockQuantity < 0) entity.StockQuantity = 0;
-                            entity.Remark = "鍑哄簱鍗曞洖浼�";
-                            break;
-
-                        case "3": // 鐩樼偣
-                            if (detail.stocktakingDetails != null && detail.stocktakingDetails.Any())
-                            {
-                                foreach (var stock in detail.stocktakingDetails)
-                                {
-                                    decimal diff = Convert.ToDecimal(stock.differenceQuantity);
-                                    if (stock.IsProfit == "1") // 鐩樼泩
-                                    {
-                                        entity.SupplyQuantity += Math.Abs(diff);
-                                    }
-                                    else // 鐩樹簭
-                                    {
-                                        entity.SupplyQuantity -= Math.Abs(diff);
-                                        if (entity.SupplyQuantity < 0) entity.SupplyQuantity = 0;
-                                    }
-                                    entity.PalletCode = stock.palletCode;
-                                    entity.Remark = "鐩樼偣鍗曞洖浼�";
-                                }
-                            }
-                            break;
-                    }
-
-                    // 鎻掑叆鎴栨洿鏂版暟鎹簱
-                    if (entity.Id == 0)
-                    {
-                        BaseDal.Db.Insertable(entity).ExecuteCommand();
-                    }
-                    else
-                    {
-                        BaseDal.Db.Updateable(entity).ExecuteCommand();
-                    }
-                }
-
-                BaseDal.Db.Ado.CommitTran();
-                return new ApiResponse<Dt_InventoryInfo> { code = "0", msg = "鎴愬姛" };
+                    name = WarehouseEnum.楹荤簿搴�.ObjToString(),
+                    count = MJQty
+                });
+                #endregion
+                #region 澶т欢搴�
+                string WareCodeDJ = WarehouseEnum.澶т欢搴�.ObjToInt().ToString("000");
+                var DJQty = Convert.ToInt32(BaseDal.QueryData(x => x.WarehouseCode == WareCodeDJ).Sum(x => x.StockQuantity));
+                lists.Add(new
+                {
+                    name = WarehouseEnum.澶т欢搴�.ObjToString(),
+                    count = DJQty
+                });
+                #endregion
+                content.OK(data: lists);
             }
             catch (Exception ex)
             {
-                BaseDal.Db.Ado.RollbackTran();
-                return new ApiResponse<Dt_InventoryInfo> { code = "500", msg = ex.Message };
+                content.Error(ex.Message);
             }
+            return content;
         }
 
 
 
-
-
-
-
-
-        /// <summary>
-        /// 鎺ㄩ�佸紓甯镐俊鎭粰涓婃父绯荤粺1.鍏ュ簱鍗曟帴鍙o紱2.鍏ュ簱鍗曟姤瀹屾垚鎺ュ彛锛�3.鍑哄簱鍗曟帴鍙o紱4.鍑哄簱鎶ュ畬鎴愭帴鍙o紱5.鑽搧鍩虹淇℃伅鍚屾鎺ュ彛锛�6.渚涘簲鍟嗕俊鎭帴鍙o紱7.瀹㈡埛淇℃伅鎺ュ彛锛�8.搴撳瓨
-        /// </summary>
-        public void SendErrorToUpstream(int type, string code, string message, string remark)
-        {
-            try
-            {
-                var url = "http://121.37.118.63:80/GYZ2/95fck/exceptionLog";
-
-                var requestData = new
-                {
-                    type = type.ToString(),
-                    code = code,
-                    message = message,
-                    remark = remark
-                };
-
-                var result = HttpHelper.Post(url, requestData.ToJsonString());
-                // 鍙互鍙嶅簭鍒楀寲妫�鏌� resultCode 鏄惁涓�0
-            }
-            catch (Exception e)
-            {
-                // 杩欓噷涓嶈鍐嶆姏寮傚父浜嗭紝閬垮厤姝诲惊鐜�
-                Console.WriteLine("寮傚父鎺ュ彛鎺ㄩ�佸け璐ワ細" + e.Message);
-            }
-        }
     }
 }

--
Gitblit v1.9.3