From 6c7a356b784efde61e2babc17fa6e05047dcc5a7 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期三, 15 十月 2025 00:21:36 +0800
Subject: [PATCH] 添加数据库表及出入库单处理业务逻辑

---
 新建文件夹/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/CabinOrderServices.cs |  147 ++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 120 insertions(+), 27 deletions(-)

diff --git "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/CabinOrderServices.cs" "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/CabinOrderServices.cs"
index d4560c4..8a1872f 100644
--- "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/CabinOrderServices.cs"
+++ "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/CabinOrderServices.cs"
@@ -7,11 +7,12 @@
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEA_Common;
 using WIDESEA_Core;
 using WIDESEA_Core.BaseRepository;
 using WIDESEA_Core.BaseServices;
 using WIDESEA_Core.Helper;
-
+using WIDESEA_IBasicService;
 using WIDESEA_ISquareCabinServices;
 using WIDESEA_Model.Models;
 
@@ -24,11 +25,13 @@
 {
     public class CabinOrderServices : ServiceBase<Dt_CabinOrder, IRepository<Dt_CabinOrder>>, ICabinOrderServices
     {
-       
-        static string SearchDate = "";
 
-        public CabinOrderServices(IRepository<Dt_CabinOrder> BaseDal) : base(BaseDal)
+        static string SearchDate = "";
+        private readonly IBasicService _basicService;
+
+        public CabinOrderServices(IRepository<Dt_CabinOrder> BaseDal, IBasicService basicService) : base(BaseDal)
         {
+            _basicService = basicService;
         }
 
         /// <summary>
@@ -195,28 +198,118 @@
                             Supplier_no = order.supplier_no,
                             Account_tiem = order.account_time,
                             OdrderStatus = "鏂板缓",
-                            Supplier_name=order.supplier_name,
+                            Supplier_name = order.supplier_name,
                             Warehouse_no = order.warehouse_no,
-                            Details = order.details.Select(d => new Dt_CabinOrderDetail
-                            {
-                                //OrderId 瑕佹嬁鍒板叆搴撳崟琛ㄤ腑鐨刬d锛屽浣曟嬁涓嶅埌灏卞皢杩欎釜瀛楁鏀逛簡锛屾敼鎴愬叆搴撳崟鍙�
-                                // SqlSugar InsertNav宸ヤ綔鍘熺悊鍏堟彃鍏ヤ富琛� (Dt_CabinOrder)//鑾峰彇鐢熸垚鐨勪富閿甀D//鑷姩璁剧疆瀛愯〃鐨勫叧鑱斿瓧娈� (OrderId)//鍐嶆彃鍏�(Dt_CabinOrderDetail)
-                                Goods_no = d.goods_no,
-                                Order_qty = d.order_qty,
-                                Batch_num = d.batch_num,
-                                Exp_date = d.exp_date,
-                                OrderDetailStatus="鏂板缓",
-                                Status = order.warehouse_no== "001" ? 0 : 2, //濡傛灉鏄�001鎴块偅涔堝氨鏄湭鍚屾鐘舵�侊紝濡傛灉涓嶆槸001鎴块偅涔堝氨鏄棤闇�鍚屾鐘舵��
-                            }).ToList()
+                            Details = new List<Dt_CabinOrderDetail>()
+                            //Details = order.details.Select(d => new Dt_CabinOrderDetail
+                            //{
+                            //    //OrderId 瑕佹嬁鍒板叆搴撳崟琛ㄤ腑鐨刬d锛屽浣曟嬁涓嶅埌灏卞皢杩欎釜瀛楁鏀逛簡锛屾敼鎴愬叆搴撳崟鍙�
+                            //    // SqlSugar InsertNav宸ヤ綔鍘熺悊鍏堟彃鍏ヤ富琛� (Dt_CabinOrder)//鑾峰彇鐢熸垚鐨勪富閿甀D//鑷姩璁剧疆瀛愯〃鐨勫叧鑱斿瓧娈� (OrderId)//鍐嶆彃鍏�(Dt_CabinOrderDetail)
+                            //    Goods_no = d.goods_no,
+                            //    Order_qty = d.order_qty,
+                            //    Batch_num = d.batch_num,
+                            //    Exp_date = d.exp_date,
+                            //    OrderDetailStatus = "鏂板缓",
+                            //    Status = order.warehouse_no == "001" ? 0 : 2, //濡傛灉鏄�001鎴块偅涔堝氨鏄湭鍚屾鐘舵�侊紝濡傛灉涓嶆槸001鎴块偅涔堝氨鏄棤闇�鍚屾鐘舵��
+                            //}).ToList()
                         };
+                        foreach (var item in order.details)
+                        {
+                            #region 鏍规嵁鐗╂枡缂栫爜鏌ヨ鐗╂枡淇℃伅
+                            Dt_MaterielInfo materielInfo = _basicService.MaterielInfoService.Repository.QueryFirst(x => x.MaterielCode == item.goods_no);
+                            ///鏍规嵁鐗╂枡淇℃伅澶у皬浠跺睘鎬у尯鍒嗘槸鍚﹀叆绔嬪簱
+                            if (materielInfo.MaterielSourceType == MaterielSourceTypeEnum.PurchasePart)
+                            {
+                                Dt_CabinOrderDetail orderDetail = new Dt_CabinOrderDetail()
+                                {
+                                    Reservoirarea= order.warehouse_no,
+                                    Goods_no = item.goods_no,
+                                    Order_qty = item.order_qty,
+                                    Batch_num = item.batch_num,
+                                    Exp_date = item.exp_date,
+                                    OrderDetailStatus = "鏂板缓",
+                                    Status = 2
+                                };
+                                entityOrder.Details.Add(orderDetail);
+                            }
+                            else
+                            {
+                                Dt_CabinOrderDetail orderDetail = null;
+                                var ys = item.order_qty % materielInfo.BoxQty;
+                                var xs = item.order_qty / materielInfo.BoxQty;
+                                #region 鐢熸垚绔嬪簱鍏ュ簱鍗�
+
+                                #region 鍒ゆ柇鏄惁鏈夋暎浠�
+                                if (ys > 0)
+                                {
+                                    orderDetail = new Dt_CabinOrderDetail()
+                                    {
+                                        Goods_no = item.goods_no,
+                                        Order_qty = ys,
+                                        Batch_num = item.batch_num,
+                                        Exp_date = item.exp_date,
+                                        OrderDetailStatus = "鏂板缓",
+                                        Status = 0
+                                    };
+                                    materielInfo.Business_qty += ys;
+                                }
+                                #endregion
+
+                                #region 鍒ゆ柇绔嬪簱搴撳瓨鏄惁澶т簬绔嬪簱鏈�浣庡簱瀛樻暟
+                                while (materielInfo.Business_qty < materielInfo.MinQty && xs > 0)
+                                {
+                                    xs--;
+                                    if (orderDetail == null)
+                                    {
+                                        orderDetail = new Dt_CabinOrderDetail()
+                                        {
+                                            Goods_no = item.goods_no,
+                                            Order_qty = materielInfo.BoxQty,
+                                            Batch_num = item.batch_num,
+                                            Exp_date = item.exp_date,
+                                            OrderDetailStatus = "鏂板缓",
+                                            Status = 0
+                                        };
+                                        materielInfo.Business_qty += materielInfo.BoxQty;
+                                    }
+                                    else
+                                    {
+                                        orderDetail.Order_qty += materielInfo.BoxQty;
+                                        materielInfo.Business_qty += materielInfo.BoxQty;
+                                    }
+                                }
+                                #endregion 
+
+                                if (orderDetail != null) entityOrder.Details.Add(orderDetail);
+                                #endregion
+
+                                #region 鍓╀綑鏁翠欢鍏ュ钩搴�
+                                if (xs > 0)
+                                {
+                                    orderDetail = new Dt_CabinOrderDetail()
+                                    {
+                                        Goods_no = item.goods_no,
+                                        Order_qty = materielInfo.BoxQty * xs,
+                                        Batch_num = item.batch_num,
+                                        Exp_date = item.exp_date,
+                                        OrderDetailStatus = "鏂板缓",
+                                        Status = 2
+                                    };
+                                    entityOrder.Details.Add(orderDetail);
+                                }
+                                #endregion
+                            }
+                            _basicService.MaterielInfoService.Repository.UpdateData(materielInfo);
+                            #endregion
+                        }
                         _CabinOrders.Add(entityOrder);
                         orderNos.Add(order.order_no);
                     };
                     BaseDal.Db.InsertNav(_CabinOrders).Include(x => x.Details).ExecuteCommand();
 
                     //鍦ㄤ笅鍙戠粰wcs 
-                  //var reslut=  EdiIn(); //鍙戠粰涓嬫父
-                                        //濡傛灉杩欎釜鏂规硶鎴愬姛浜嗭紝閭d箞灏辫皟鐢–ompleteOrder鎺ュ彛锛岀劧鍚庢敼鍙�
+                    //var reslut=  EdiIn(); //鍙戠粰涓嬫父
+                    //濡傛灉杩欎釜鏂规硶鎴愬姛浜嗭紝閭d箞灏辫皟鐢–ompleteOrder鎺ュ彛锛岀劧鍚庢敼鍙�
                     Db.Ado.CommitTran();
                     return responseContent.OK("鍚屾鍏ュ簱鍗曟垚鍔�");
                 }
@@ -264,7 +357,7 @@
                     Console.WriteLine("娌℃湁绗﹀悎鏉′欢鐨勮鍗曢渶瑕佹帹閫�");
                     return WebResponseContent.Instance.Error("娌℃湁绗﹀悎鏉′欢鐨勮鍗曢渶瑕佹帹閫�");
                 }
-                
+
 
                 // 4. 閬嶅巻璁㈠崟锛岀粍瑁� DTO 骞舵帹閫�
                 foreach (var order in orders)
@@ -333,10 +426,10 @@
                     if (resp != null && resp.code == "0")
                     {
                         // 鏇存柊琛ㄥご鐘舵��
-                       BaseDal.Db.Updateable<Dt_CabinOrder>()
-                          .SetColumns(o => new Dt_CabinOrder { OdrderStatus = "寮�濮�" })
-                          .Where(o => o.Id == order.Id)
-                          .ExecuteCommand();
+                        BaseDal.Db.Updateable<Dt_CabinOrder>()
+                           .SetColumns(o => new Dt_CabinOrder { OdrderStatus = "寮�濮�" })
+                           .Where(o => o.Id == order.Id)
+                           .ExecuteCommand();
 
                         // 鏇存柊鏄庣粏鐘舵�佷负宸插悓姝�
                         BaseDal.Db.Updateable<Dt_CabinOrderDetail>()
@@ -357,7 +450,7 @@
             }
             catch (Exception ex)
             {
-                
+
                 Console.WriteLine("EdiIn 寮傚父锛�" + ex.Message);
                 return new WebResponseContent { Status = false, Message = ex.Message };
             }
@@ -444,7 +537,7 @@
                                     Exp_date = d.Exp_date,
                                     OrderDetailStatus = d.OrderDetailStatus,
                                     Status = d.Status,
-                                   
+
                                 }).ToList();
 
                                 BaseDal.Db.Insertable(detailsHistory).ExecuteCommand();
@@ -486,7 +579,7 @@
         }
 
 
-     
+
 
 
         /// <summary>
@@ -518,7 +611,7 @@
 
 
 
-      
+
 
 
     }

--
Gitblit v1.9.3