From a754e362987bd0e0de55a23b22824ad4a3a166bb Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期四, 16 十月 2025 16:44:24 +0800
Subject: [PATCH] 后端

---
 新建文件夹/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs |  228 ++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 186 insertions(+), 42 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 248a7fe..ee48bc6 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"
@@ -84,95 +84,239 @@
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-        public ApiResponse<Dt_Inventory> OrderFeedback(EdiOrderCallbackRequest request)
+        //public ApiResponse<Dt_Inventory> OrderFeedback(EdiOrderCallbackRequest request)
+        //{
+        //    try
+        //    {
+        //        if (request == null || request.details == null || !request.details.Any())
+        //        {
+        //            return new ApiResponse<Dt_Inventory> { code = "500", msg = "璇锋眰鍙傛暟鏃犳晥" };
+        //        }
+        //        BaseDal.Db.Ado.BeginTran();//寮�鍚簨鍔�
+        //        foreach (var detail in request.details)
+        //        {
+        //            // 鍏堟煡搴撳瓨鏄惁瀛樺湪锛堟寜鐓т骇鍝佺紪鍙峰拰鎵规鏉ュ鎵撅級
+        //            var entity = BaseDal.Db.Queryable<Dt_Inventory>()
+        //                           .First(x => x.Goods_no == detail.productCode && x.Batch_num == detail.batchNo);
+        //            //灏嗛泦鍚堜腑鐨勬暟閲忚繘琛岀疮鍔�
+        //            // 瀹夊叏杞崲
+
+        //            //姝e父鍑哄叆搴�
+        //            decimal orderQty = detail.orderDetails?.Sum(x => decimal.TryParse(x.quantity, out var q) ? q : 0) ?? 0;
+        //            //鐩樼偣鐩樹簭
+        //            decimal diffQty = detail.stocktakingDetails?.Sum(x => Convert.ToDecimal(x.differenceQuantity)) ?? 0;
+        //            if (entity == null)
+        //            {
+        //                // 濡傛灉涓嶅瓨鍦紝鏂板缓涓�鏉�
+        //                entity = new Dt_Inventory
+        //                {
+        //                    Goods_no = detail.productCode ?? detail.productName,
+        //                    Reservoirarea = "榛樿搴撳尯",
+        //                    Batch_num = detail.batchNo,
+        //                    //涓氬姟搴撳瓨
+        //                    Business_qty = 0,
+        //                    //瀹為檯搴撳瓨
+        //                    Actual_qty = 0
+        //                };
+        //            }
+
+        //            switch (request.orderType)
+        //            {
+        //                case "1": // 鍏ュ簱
+        //                    entity.Business_qty += orderQty;
+        //                    entity.Actual_qty += orderQty;
+        //                    break;
+
+        //                case "2": // 鍑哄簱
+        //                    entity.Business_qty -= orderQty;
+        //                    entity.Actual_qty -= orderQty;
+        //                    if (entity.Business_qty < 0) entity.Business_qty = 0; // 鍙�夛細闃叉璐熸暟
+        //                    if (entity.Actual_qty < 0) entity.Actual_qty = 0;
+        //                    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.Business_qty += diff;//濡傛灉鐩樼泩浜嗗浜嗭紝灏卞皢涓氬姟鏁伴噺+锛岀洏浜忓垯鐩稿弽
+        //                                entity.PalletCode = stock.palletCode;
+        //                            }
+        //                            else // 鐩樹簭
+        //                            {
+        //                                entity.Business_qty -= diff;
+        //                                entity.PalletCode = stock.palletCode;
+        //                            }
+        //                        }
+        //                    }
+        //                    break;
+        //            }
+
+        //            // 淇濆瓨鏁版嵁
+        //            if (entity.Id == 0) // 鏂板缓
+        //                BaseDal.Db.Insertable(entity).ExecuteCommand();
+        //            else // 鏇存柊
+        //                BaseDal.Db.Updateable(entity).ExecuteCommand();
+        //        }
+        //        BaseDal.Db.Ado.CommitTran(); // 鎻愪氦浜嬪姟
+        //        return new ApiResponse<Dt_Inventory> { code = "0", msg = "鎴愬姛" };
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        BaseDal.Db.Ado.RollbackTran();//鍥炴粴浜嬪姟
+        //        return new ApiResponse<Dt_Inventory> { code = "500", msg = ex.Message };
+        //    }
+        //}
+
+
+        public ApiResponse<Dt_InventoryInfo> OrderFeedback(EdiOrderCallbackRequest request)
         {
             try
             {
                 if (request == null || request.details == null || !request.details.Any())
                 {
-                    return new ApiResponse<Dt_Inventory> { code = "500", msg = "璇锋眰鍙傛暟鏃犳晥" };
+                    return new ApiResponse<Dt_InventoryInfo> { code = "500", msg = "璇锋眰鍙傛暟鏃犳晥" };
                 }
-                BaseDal.Db.Ado.BeginTran();//寮�鍚簨鍔�
+
+                BaseDal.Db.Ado.BeginTran(); // 寮�鍚簨鍔�
+
                 foreach (var detail in request.details)
                 {
-                    // 鍏堟煡搴撳瓨鏄惁瀛樺湪锛堟寜鐓т骇鍝佺紪鍙峰拰鎵规鏉ュ鎵撅級
-                    var entity = BaseDal.Db.Queryable<Dt_Inventory>()
-                                   .First(x => x.Goods_no == detail.productCode && x.Batch_num == detail.batchNo);
-                    //灏嗛泦鍚堜腑鐨勬暟閲忚繘琛岀疮鍔�
-                    // 瀹夊叏杞崲
+                    // 鍏ュ簱鏁伴噺锛堣嚜鍔ㄥ彇姝o級
+                    decimal orderQty = detail.orderDetails?
+                        .Sum(x => decimal.TryParse(x.quantity, out var q) ? Math.Abs(q) : 0)
+                        ?? 0;
 
-                    //姝e父鍑哄叆搴�
-                    decimal orderQty = detail.orderDetails?.Sum(x => decimal.TryParse(x.quantity, out var q) ? q : 0) ?? 0;
-                    //鐩樼偣鐩樹簭
-                    decimal diffQty = detail.stocktakingDetails?.Sum(x => Convert.ToDecimal(x.differenceQuantity)) ?? 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_Inventory
+                        //涓嶅瓨鍦ㄥ垯鏂板缓搴撳瓨鏄庣粏璁板綍
+                        entity = new Dt_InventoryInfo
                         {
-                            Goods_no = detail.productCode ?? detail.productName,
-                            Reservoirarea = "榛樿搴撳尯",
-                            Batch_num = detail.batchNo,
-                            //涓氬姟搴撳瓨
-                            Business_qty = 0,
-                            //瀹為檯搴撳瓨
-                            Actual_qty = 0
+                            PalletCode = detail.orderDetails?.FirstOrDefault()?.palletCode ?? "",
+                            WarehouseId = 1,  // 榛樿搴撴埧缂栧彿
+                            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鍥炰紶鍒涘缓"
+                        };
+                    }
+
+                    // 鎵规琛ㄨ褰曪紙鐢ㄤ簬姹囨�伙級
+                    var batch = BaseDal.Db.Queryable<Dt_Inventory_Batch>()
+                        .First(x => x.MaterielCode == detail.productCode && x.BatchNo == detail.batchNo);
+
+                    if (batch == null)
+                    {
+                        batch = new Dt_Inventory_Batch
+                        {
+                            MaterielCode = detail.productCode ?? detail.productName,
+                            MaterielName = detail.productName ?? "",
+                            MaterielSpec = detail.productSpecifications ?? "",
+                            BatchNo = detail.batchNo,
+                            StockQuantity = 0,
+                            OutboundQuantity = 0,
+                            SupplyQuantity = 0,
+                            ERPStockQuantity = 0,
+                            Status = false,
+                            ProductionDate = detail.finishDate.ToString("yyyy-MM-dd"),
+                            ValidityPeriod = DateTime.Now.AddYears(1).ToString("yyyy-MM-dd"),
+                            Remark = "鑷姩鍒涘缓"
                         };
                     }
 
                     switch (request.orderType)
                     {
                         case "1": // 鍏ュ簱
-                            entity.Business_qty += orderQty;
-                            entity.Actual_qty += orderQty;
+                            entity.StockQuantity += (float)orderQty;
+                            entity.InDate = DateTime.Now;
+                            entity.Remark = "鍏ュ簱鍗曞洖浼�";
+
+                            batch.StockQuantity += (float)orderQty;
+                            batch.Remark = "鍏ュ簱鍗曞洖浼�";
                             break;
 
                         case "2": // 鍑哄簱
-                            entity.Business_qty -= orderQty;
-                            entity.Actual_qty -= orderQty;
-                            if (entity.Business_qty < 0) entity.Business_qty = 0; // 鍙�夛細闃叉璐熸暟
-                            if (entity.Actual_qty < 0) entity.Actual_qty = 0;
+                            entity.OutboundQuantity += (float)orderQty;
+                            entity.StockQuantity -= (float)orderQty;
+                            if (entity.StockQuantity < 0) entity.StockQuantity = 0;
+                            entity.Remark = "鍑哄簱鍗曞洖浼�";
+
+                            batch.OutboundQuantity += (float)orderQty;
+                            batch.StockQuantity -= (float)orderQty;
+                            if (batch.StockQuantity < 0) batch.StockQuantity = 0;
+                            batch.Remark = "鍑哄簱鍗曞洖浼�";
                             break;
 
-                        case "3": // 鐩樼偣
+                        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.Business_qty += diff;//濡傛灉鐩樼泩浜嗗浜嗭紝灏卞皢涓氬姟鏁伴噺+锛岀洏浜忓垯鐩稿弽
-                                        entity.PalletCode = stock.palletCode;
+                                        entity.SupplyQuantity += (float)Math.Abs(diff);
+                                        batch.SupplyQuantity += (float)Math.Abs(diff);
                                     }
                                     else // 鐩樹簭
                                     {
-                                        entity.Business_qty -= diff;
-                                        entity.PalletCode = stock.palletCode;
+                                        entity.SupplyQuantity -= (float)Math.Abs(diff);
+                                        batch.SupplyQuantity -= (float)Math.Abs(diff);
+                                        if (entity.SupplyQuantity < 0) entity.SupplyQuantity = 0;
+                                        if (batch.SupplyQuantity < 0) batch.SupplyQuantity = 0;
                                     }
+                                    entity.PalletCode = stock.palletCode;
+                                    entity.Remark = "鐩樼偣鍗曞洖浼�";
+                                    batch.Remark = "鐩樼偣鍗曞洖浼�";
                                 }
                             }
                             break;
                     }
 
-                    // 淇濆瓨鏁版嵁
-                    if (entity.Id == 0) // 鏂板缓
+                    //淇濆瓨鍒版暟鎹簱
+                    if (entity.Id == 0)
                         BaseDal.Db.Insertable(entity).ExecuteCommand();
-                    else // 鏇存柊
+                    else
                         BaseDal.Db.Updateable(entity).ExecuteCommand();
+
+                    if (batch.Id == 0)
+                        BaseDal.Db.Insertable(batch).ExecuteCommand();
+                    else
+                        BaseDal.Db.Updateable(batch).ExecuteCommand();
                 }
-                BaseDal.Db.Ado.CommitTran(); // 鎻愪氦浜嬪姟
-                return new ApiResponse<Dt_Inventory> { code = "0", msg = "鎴愬姛" };
+
+                BaseDal.Db.Ado.CommitTran();
+                return new ApiResponse<Dt_InventoryInfo> { code = "0", msg = "鎴愬姛" };
             }
             catch (Exception ex)
             {
-                BaseDal.Db.Ado.RollbackTran();//鍥炴粴浜嬪姟
-                return new ApiResponse<Dt_Inventory> { code = "500", msg = ex.Message };
+                BaseDal.Db.Ado.RollbackTran();
+                return new ApiResponse<Dt_InventoryInfo> { code = "500", msg = ex.Message };
             }
         }
-
-
 
 
 

--
Gitblit v1.9.3