From 07b532a6a6adf0a9d965b037cf98c1f98accd138 Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期五, 07 十一月 2025 20:11:09 +0800
Subject: [PATCH] 优化出入退货代码

---
 新建文件夹/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/NewBusiness.cs |  279 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 258 insertions(+), 21 deletions(-)

diff --git "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/NewBusiness.cs" "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/NewBusiness.cs"
index dfdc13f..7c2b623 100644
--- "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/NewBusiness.cs"
+++ "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/NewBusiness.cs"
@@ -16,6 +16,171 @@
     public partial class Business
     {
         #region 鑾峰彇ERP鍏ュ簱鍗�
+        //static string SearchInOrderDate = "2025-11-01 00:00:00";
+        //public WebResponseContent GetInOrder()
+        //{
+        //    WebResponseContent content = new WebResponseContent();
+        //    try
+        //    {
+        //        var url = "http://121.37.118.63:80/GYZ2/95fck/inOrder";
+        //        string GetOutOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+        //        if (string.IsNullOrEmpty(SearchInOrderDate)) SearchInOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+        //        var requestData = new { searchDate = SearchInOrderDate };
+        //        //SearchInOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+        //        var result = HttpHelper.Post(url, requestData.ToJsonString());
+        //        var response = JsonConvert.DeserializeObject<UpstreamResponse<UpstreamOrderInfo>>(result);
+        //        if (response == null) return content;
+        //        if (response.data.Count < 1)
+        //        {
+        //            SearchInOrderDate = GetOutOrderDate;
+        //            return content;
+        //        }
+        //        var ordernos = response.data.Select(x => x.order_no).ToList();
+        //        var existingOrderNos = _cabinOrderServices.Repository.QueryData(x => ordernos.Contains(x.Order_no)).Select(x => x.Order_no).Distinct().ToList();
+        //        var newOrders = response.data.Where(order => !existingOrderNos.Contains(order.order_no)).ToList();
+        //        if (newOrders.Count < 1)
+        //        {
+        //            SearchInOrderDate = GetOutOrderDate;
+        //            return content;
+        //        }
+        //        int messQty = 0;
+        //        foreach (var order in newOrders)
+        //        {
+        //            try
+        //            {
+        //                if (order.order_type == "1")
+        //                {
+        //                    content = _cabinOrderServices.CreateInboundOrder(order);
+        //                    if (!content.Status) messQty++;
+        //                }
+        //                else if (order.order_type == "3")//鍏ュ簱閫�鏂�
+        //                {
+        //                    #region 杞崲涓哄嚭搴撳崟
+        //                    UpstramOutOrderInfo upstramOutOrderInfo = new UpstramOutOrderInfo()
+        //                    {
+        //                        order_no = order.order_no,
+        //                        order_type = order.order_type,
+        //                        warehouse_no = order.warehouse_no,
+        //                        details = new List<UpstreamOutOrderDetail>()
+        //                    };
+        //                    foreach (var item in order.details)
+        //                    {
+        //                        UpstreamOutOrderDetail detail = new UpstreamOutOrderDetail()
+        //                        {
+        //                            batch_num = item.batch_num,
+        //                            goods_no = item.goods_no,
+        //                            order_qty = item.order_qty,
+        //                            exp_date = item.exp_date,
+        //                        };
+        //                        upstramOutOrderInfo.details.Add(detail);
+        //                    }
+        //                    #endregion
+        //                    content = _deliveryOrderServices.CreateOutboundOrder(upstramOutOrderInfo);
+        //                    if (!content.Status) messQty++;
+        //                }
+        //                else if (order.order_type == "5")//鎶ユ孩鍏ュ簱
+        //                {
+        //                    content = _cabinOrderServices.CreateCheckInOrder(order);
+        //                    if (!content.Status) messQty++;
+        //                }
+        //            }
+        //            catch (Exception ex)
+        //            {
+        //                continue;
+        //            }
+        //        }
+        //        if (messQty == 0) SearchInOrderDate = GetOutOrderDate;
+        //        return content.OK();
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        Console.WriteLine("鑾峰彇ERP鍏ュ簱鍗曚俊鎭紓甯革細" + ex.Message);
+        //        return content.Error(ex.Message);
+        //    }
+        //}
+        #endregion
+
+        #region 鑾峰彇ERP鍑哄簱鍗�
+        //static string SearchOutOrderDate = "2025-11-01 00:00:00";
+        //public WebResponseContent GetOutOrder()
+        //{
+        //    WebResponseContent content = new WebResponseContent();
+        //    try
+        //    {
+        //        //var url = "http://121.37.118.63:80/GYZ2/95fck/outOrder";
+        //         var url = "http://127.0.0.1:4523/m2/5660322-5340849-default/366751306?apifoxApiId=366751306";
+        //        string GetOutOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+        //        if (string.IsNullOrEmpty(SearchOutOrderDate)) SearchOutOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+        //        var requestData = new { searchDate = SearchOutOrderDate };
+        //        var result = HttpHelper.Post(url, requestData.ToJsonString());
+        //        var response = JsonConvert.DeserializeObject<UpstreamResponse<UpstramOutOrderInfo>>(result);
+
+        //        if (response == null) return content;
+        //        if (response.data.Count < 1)
+        //        {
+        //            SearchOutOrderDate = GetOutOrderDate;
+        //            return content;
+        //        }
+        //        var ordernos = response.data.Select(x => x.order_no).ToList();
+        //        var existingOutOrderNos = _deliveryOrderServices.Repository.QueryData(x => ordernos.Contains(x.Out_no)).Select(x => x.Out_no).Distinct().ToList();
+        //        var newOutOrders = response.data.Where(outorder => !existingOutOrderNos.Contains(outorder.order_no)).ToList();
+        //        if (newOutOrders.Count < 1)
+        //        {
+        //            SearchOutOrderDate = GetOutOrderDate;
+        //            return content;
+        //        }
+        //        int messQty = 0;
+        //        foreach (var outorder in newOutOrders)
+        //        {
+        //            if (outorder.order_type == "1")// 姝e父鍑哄簱鍗�
+        //            {
+        //                content = _deliveryOrderServices.CreateOutboundOrder(outorder);
+        //                if (!content.Status) messQty++;
+        //            }
+        //            else if (outorder.order_type == "2")//鍑哄簱閫�璐�
+        //            {
+        //                #region 杞崲鎴愬叆搴撳崟
+        //                UpstreamOrderInfo order = new UpstreamOrderInfo()
+        //                {
+        //                    order_no = outorder.order_no,
+        //                    order_type = outorder.order_type,
+        //                    warehouse_no = outorder.warehouse_no,
+        //                    details = new List<UpstreamOrderDetail>()
+        //                };
+        //                foreach (var item in outorder.details)
+        //                {
+        //                    UpstreamOrderDetail detail = new UpstreamOrderDetail()
+        //                    {
+        //                        batch_num = item.batch_num,
+        //                        goods_no = item.goods_no,
+        //                        order_qty = item.order_qty,
+        //                        exp_date = item.exp_date,
+        //                    };
+        //                    order.details.Add(detail);
+        //                }
+        //                #endregion
+        //                content = _cabinOrderServices.CreateInboundOrder(order);
+        //                if (!content.Status) messQty++;
+        //            }
+        //            else if (outorder.order_type == "6")//鎶ユ崯鍑哄簱
+        //            {
+        //                content = _deliveryOrderServices.CreateCheckOutOrder(outorder);
+        //                if (!content.Status) messQty++;
+        //            }
+        //        }
+        //        if (messQty == 0) SearchOutOrderDate = GetOutOrderDate;
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        content.Error(ex.Message);
+        //    }
+        //    return content;
+        //}
+        #endregion
+
+
+
+        #region 鑾峰彇ERP鍏ュ簱鍗�
         static string SearchInOrderDate = "2025-11-01 00:00:00";
         public WebResponseContent GetInOrder()
         {
@@ -23,24 +188,53 @@
             try
             {
                 var url = "http://121.37.118.63:80/GYZ2/95fck/inOrder";
+                string GetOutOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                 if (string.IsNullOrEmpty(SearchInOrderDate)) SearchInOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                 var requestData = new { searchDate = SearchInOrderDate };
-                SearchInOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                 var result = HttpHelper.Post(url, requestData.ToJsonString());
                 var response = JsonConvert.DeserializeObject<UpstreamResponse<UpstreamOrderInfo>>(result);
-                if (response == null || response.resultCode != "0") return content;
-                if (response.data.Count < 1) return content;
+                if (response == null) return content;
+                if (response.data.Count < 1)
+                {
+                    SearchInOrderDate = GetOutOrderDate;
+                    return content;
+                }
+
                 var ordernos = response.data.Select(x => x.order_no).ToList();
-                var existingOrderNos = _cabinOrderServices.Repository.QueryData(x => ordernos.Contains(x.Order_no)).Select(x => x.Order_no).Distinct().ToList();
-                var newOrders = response.data.Where(order => !existingOrderNos.Contains(order.order_no)).ToList();
-                if (newOrders.Count < 1) return content;
+
+                // 鍏抽敭淇敼锛氭寜璁㈠崟绫诲瀷鍒嗗埆妫�鏌ュ搴旂殑琛�
+                var inOrderTypes = new List<string> { "1", "5" }; // 鍏ュ簱绫诲瀷
+                var outOrderTypes = new List<string> { "3" };      // 鍑哄簱绫诲瀷
+
+                // 妫�鏌ュ叆搴撳崟琛紙鍙鏌ュ叆搴撶被鍨嬬殑璁㈠崟锛夋槸鍚﹀瓨鍦�
+                var existingInOrderNos = _cabinOrderServices.Repository.QueryData(x => ordernos.Contains(x.Order_no))
+                    .Select(x => x.Order_no).Distinct().ToList();
+
+                // 妫�鏌ュ嚭搴撳崟琛紙鍙鏌ュ嚭搴撶被鍨嬬殑璁㈠崟锛�
+                var existingOutOrderNos = _deliveryOrderServices.Repository.QueryData(x => ordernos.Contains(x.Out_no))
+                    .Select(x => x.Out_no).Distinct().ToList();
+
+                // 绛涢�夋柊璁㈠崟锛氬叆搴撶被鍨嬫鏌ュ叆搴撹〃锛屽嚭搴撶被鍨嬫鏌ュ嚭搴撹〃 閫夊嚭涓嶅寘鍚凡瀛樺湪鍦�
+                var newOrders = response.data.Where(order =>
+                    (inOrderTypes.Contains(order.order_type) && !existingInOrderNos.Contains(order.order_no)) ||
+                    (outOrderTypes.Contains(order.order_type) && !existingOutOrderNos.Contains(order.order_no))
+                ).ToList();
+
+                if (newOrders.Count < 1)
+                {
+                    SearchInOrderDate = GetOutOrderDate;
+                    return content;
+                }
+
+                int messQty = 0;
                 foreach (var order in newOrders)
                 {
                     try
                     {
                         if (order.order_type == "1")
                         {
-                            _cabinOrderServices.CreateInboundOrder(order);
+                            content = _cabinOrderServices.CreateInboundOrder(order);
+                            if (!content.Status) messQty++;
                         }
                         else if (order.order_type == "3")//鍏ュ簱閫�鏂�
                         {
@@ -49,6 +243,9 @@
                             {
                                 order_no = order.order_no,
                                 order_type = order.order_type,
+                                client_no=order.supplier_no,
+                                client_name=order.supplier_name,
+                                account_time=order.account_time,
                                 warehouse_no = order.warehouse_no,
                                 details = new List<UpstreamOutOrderDetail>()
                             };
@@ -63,12 +260,14 @@
                                 };
                                 upstramOutOrderInfo.details.Add(detail);
                             }
-                            _deliveryOrderServices.CreateOutboundOrder(upstramOutOrderInfo);
                             #endregion
+                            content = _deliveryOrderServices.CreateOutboundOrder(upstramOutOrderInfo);
+                            if (!content.Status) messQty++;
                         }
                         else if (order.order_type == "5")//鎶ユ孩鍏ュ簱
                         {
-                            _cabinOrderServices.CreateCheckInOrder(order);
+                            content = _cabinOrderServices.CreateCheckInOrder(order);
+                            if (!content.Status) messQty++;
                         }
                     }
                     catch (Exception ex)
@@ -76,6 +275,7 @@
                         continue;
                     }
                 }
+                if (messQty == 0) SearchInOrderDate = GetOutOrderDate;
                 return content.OK();
             }
             catch (Exception ex)
@@ -94,24 +294,52 @@
             try
             {
                 var url = "http://121.37.118.63:80/GYZ2/95fck/outOrder";
+                string GetOutOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                 if (string.IsNullOrEmpty(SearchOutOrderDate)) SearchOutOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                 var requestData = new { searchDate = SearchOutOrderDate };
-                SearchOutOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                 var result = HttpHelper.Post(url, requestData.ToJsonString());
                 var response = JsonConvert.DeserializeObject<UpstreamResponse<UpstramOutOrderInfo>>(result);
 
-                if (response == null || response.resultCode != "0") return content;
-                if (response.data.Count < 1) return content;
-                var ordernos = response.data.Select(x => x.order_no).ToList();
-                var existingOutOrderNos = _deliveryOrderServices.Repository.QueryData(x => ordernos.Contains(x.Out_no)).Select(x => x.Out_no).Distinct().ToList();
-                var newOutOrders = response.data.Where(outorder => !existingOutOrderNos.Contains(outorder.order_no)).ToList();
-                if (newOutOrders.Count < 1) return content;
+                if (response == null) return content;
+                if (response.data.Count < 1)
+                {
+                    SearchOutOrderDate = GetOutOrderDate;
+                    return content;
+                }
 
-                foreach (var outorder in newOutOrders)
+                var ordernos = response.data.Select(x => x.order_no).ToList();
+
+                // 鎸夎鍗曠被鍨嬪垎鍒鏌ュ搴旂殑琛�
+                var outOrderTypes = new List<string> { "1", "6" }; // 鍑哄簱绫诲瀷
+                var inOrderTypes = new List<string> { "2" };       // 鍏ュ簱绫诲瀷
+
+                // 妫�鏌ュ嚭搴撳崟琛紙鍙鏌ュ嚭搴撶被鍨嬬殑璁㈠崟锛�
+                var existingOutOrderNos = _deliveryOrderServices.Repository.QueryData(x => ordernos.Contains(x.Out_no))
+                    .Select(x => x.Out_no).Distinct().ToList();
+
+                // 妫�鏌ュ叆搴撳崟琛紙鍙鏌ュ叆搴撶被鍨嬬殑璁㈠崟锛�
+                var existingInOrderNos = _cabinOrderServices.Repository.QueryData(x => ordernos.Contains(x.Order_no))
+                    .Select(x => x.Order_no).Distinct().ToList();
+
+                // 绛涢�夋柊璁㈠崟锛氬嚭搴撶被鍨嬫鏌ュ嚭搴撹〃锛屽叆搴撶被鍨嬫鏌ュ叆搴撹〃
+                var newOrders = response.data.Where(order =>
+                    (outOrderTypes.Contains(order.order_type) && !existingOutOrderNos.Contains(order.order_no)) ||
+                    (inOrderTypes.Contains(order.order_type) && !existingInOrderNos.Contains(order.order_no))
+                ).ToList();
+
+                if (newOrders.Count < 1)
+                {
+                    SearchOutOrderDate = GetOutOrderDate;
+                    return content;
+                }
+
+                int messQty = 0;
+                foreach (var outorder in newOrders)
                 {
                     if (outorder.order_type == "1")// 姝e父鍑哄簱鍗�
                     {
-                        _deliveryOrderServices.CreateOutboundOrder(outorder);
+                        content = _deliveryOrderServices.CreateOutboundOrder(outorder);
+                        if (!content.Status) messQty++;
                     }
                     else if (outorder.order_type == "2")//鍑哄簱閫�璐�
                     {
@@ -120,6 +348,9 @@
                         {
                             order_no = outorder.order_no,
                             order_type = outorder.order_type,
+                            supplier_no=outorder.client_no,
+                            supplier_name=outorder.client_name,
+                            account_time=outorder.account_time,
                             warehouse_no = outorder.warehouse_no,
                             details = new List<UpstreamOrderDetail>()
                         };
@@ -135,13 +366,17 @@
                             order.details.Add(detail);
                         }
                         #endregion
-                        _cabinOrderServices.CreateInboundOrder(order);
+                        content = _cabinOrderServices.CreateInboundOrder(order);
+                        if (!content.Status) messQty++;
                     }
                     else if (outorder.order_type == "6")//鎶ユ崯鍑哄簱
                     {
-                        _deliveryOrderServices.CreateCheckOutOrder(outorder);
+                        content = _deliveryOrderServices.CreateCheckOutOrder(outorder);
+                        if (!content.Status) messQty++;
                     }
                 }
+
+                if (messQty == 0) SearchOutOrderDate = GetOutOrderDate;
             }
             catch (Exception ex)
             {
@@ -149,6 +384,8 @@
             }
             return content;
         }
-        #endregion
+
+        #endregion  
+
     }
 }

--
Gitblit v1.9.3