From 927ce822017ff8459be84b742d519970ca614096 Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期五, 24 十月 2025 17:18:56 +0800
Subject: [PATCH] 1

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/AspNetCoreSchedule.cs |  233 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 220 insertions(+), 13 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/AspNetCoreSchedule.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/AspNetCoreSchedule.cs"
index b6c1b44..6240332 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/AspNetCoreSchedule.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/AspNetCoreSchedule.cs"
@@ -30,10 +30,14 @@
         private readonly ISys_ConfigService _configService;
         private readonly ILocationInfoRepository _locationRepository;
         private readonly IDt_InboundOrderRepository _inboundOrderRepository;
+        private readonly IDt_OtherOutboundOrderRepository _otheroutboundorderRepository;
+        private readonly IDt_ProductionOutboundOrderRepository _productionoutboundorderRepository;
+        private readonly IDt_InventoryOutboundOrderRepository _inventoryoutboundorderRepository;
+        private readonly IDt_AllocateOutboundOrderRepository _allocateoutboundorderRepository;
 
         private Timer _timer;
 
-        public MyBackgroundService(ILogger<MyBackgroundService> logger, ILocationInfoRepository locationRepository, IStockInfoRepository stockInfoRepository, IDt_AreaInfoRepository areaInfoRepository, IDt_TaskRepository taskRepository, IDt_StationManagerRepository stationManagerRepository, ISys_ConfigService configService,IDt_InboundOrderRepository inboundOrderRepository)
+        public MyBackgroundService(ILogger<MyBackgroundService> logger, ILocationInfoRepository locationRepository, IStockInfoRepository stockInfoRepository, IDt_AreaInfoRepository areaInfoRepository, IDt_TaskRepository taskRepository, IDt_StationManagerRepository stationManagerRepository, ISys_ConfigService configService,IDt_InboundOrderRepository inboundOrderRepository, IDt_OtherOutboundOrderRepository otheroutboundorderRepository, IDt_AllocateOutboundOrderRepository allocateoutboundorderRepository, IDt_InventoryOutboundOrderRepository inventoryOutboundOrderRepository,IDt_ProductionOutboundOrderRepository productionOutboundOrderRepository)
         {
             _logger = logger;
             _locationRepository = locationRepository;
@@ -43,11 +47,15 @@
             _stationManagerRepository = stationManagerRepository;
             _configService = configService;
             _inboundOrderRepository = inboundOrderRepository;
+            _otheroutboundorderRepository = otheroutboundorderRepository;
+            _allocateoutboundorderRepository = allocateoutboundorderRepository;
+            _inventoryoutboundorderRepository = inventoryOutboundOrderRepository;
+            _productionoutboundorderRepository = productionOutboundOrderRepository;
         }
 
         public Task StartAsync(CancellationToken cancellationToken)
         {
-            _timer = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromMinutes(1));
+            _timer = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromMinutes(5));
             return Task.CompletedTask;
         }
 
@@ -55,22 +63,21 @@
         {
             try
             {
+                #region 鍏ュ簱鍗曟嵁鍚屾
                 List<WMS_閲囪喘鍏ユ垚鍝佸叆搴撹嚜鍔ㄦ墦鍗版竻鍗昣ST> ERPPrintChecklist =SqlSugarHelper.DBERP.Queryable<WMS_閲囪喘鍏ユ垚鍝佸叆搴撹嚜鍔ㄦ墦鍗版竻鍗昣ST>().Where(x => true).ToList();
-
                 
                 var printCheckList = _inboundOrderRepository.QueryData(x => true);
                 List<Dt_InboundOrder> inboundOrderAdd = new List<Dt_InboundOrder>();
                 List<Dt_InboundOrder> inboundOrderUpdate = new List<Dt_InboundOrder>();
-                if (ERPPrintChecklist != null) return;
                 foreach (var item in ERPPrintChecklist)
                 {
-                    var x = printCheckList.Where(x => x.MaterialNo == item.鏂欏彿 && x.OrderNo == item.鍗曞彿 && x.WarehouseName == item.鍏ュ簱浠撳簱鍚嶇О).FirstOrDefault();
+                    var x = printCheckList.Where(x => x.MaterialNo == item.鏂欏彿 && x.UpperOrderNo == item.鍗曞彿 && x.WarehouseName == item.鍏ュ簱浠撳簱鍚嶇О).FirstOrDefault();
                     if (x == null)
                     {
                         Dt_InboundOrder Print = new Dt_InboundOrder()
                         {
-                            PrintCode = GetOrderPintCode(),
-                            OrderNo = item.鍗曞彿,
+                            OrderNo = GetOrderPintCode("OrderNoIn"),
+                            UpperOrderNo = item.鍗曞彿,
                             DemandClassification = item.闇�姹傚垎绫�,
                             OrderType = item.鍗曟嵁绫诲瀷,
                             WarehouseName = item.鍏ュ簱浠撳簱鍚嶇О,
@@ -91,10 +98,10 @@
                     }
                     else
                     {
-                        if (x.PrintCode == null || x.PrintCode == "")
+                        if (x.OrderNo == null || x.OrderNo == "")
                         {
-                            x.PrintCode = GetOrderPintCode();
-                            x.OrderNo = item.鍗曞彿;
+                            x.OrderNo = GetOrderPintCode("OrderNoIn");
+                            x.UpperOrderNo = item.鍗曞彿;
                             x.DemandClassification = item.闇�姹傚垎绫�;
                             x.OrderType = item.鍗曟嵁绫诲瀷;
                             x.WarehouseName = item.鍏ュ簱浠撳簱鍚嶇О;
@@ -121,6 +128,206 @@
                 {
                     _inboundOrderRepository.UpdateData(inboundOrderUpdate);
                 }
+                #endregion
+
+
+                #region ERP鐢熶骇棰嗘枡鍗曞悓姝�
+
+                var productionOutOrder = _productionoutboundorderRepository.Db.Queryable<Dt_ProductionOutboundOrder>().Includes(x => x.Details).ToList();
+
+                List<Dt_ProductionOutboundOrder> EngineeringoutboundOrderAdd = new List<Dt_ProductionOutboundOrder>();
+                List<Dt_ProductionOutboundOrder> EngineeringoutboundOrderUpdate = new List<Dt_ProductionOutboundOrder>();
+                List<Dt_ProductionOutboundOrder> productionoutboundOrderAdd = new List<Dt_ProductionOutboundOrder>();
+                List<Dt_ProductionOutboundOrder> productionoutboundOrderUpdate = new List<Dt_ProductionOutboundOrder>();
+                List<WMS_鐢ㄥ弸宸ョ▼鍙戣揣鍗曚竴瑙堣〃_ST> EngineeringERP = SqlSugarHelper.DBERP.Queryable<WMS_鐢ㄥ弸宸ョ▼鍙戣揣鍗曚竴瑙堣〃_ST>().Where(x => true).ToList();
+                List<WMS_鐢ㄥ弸鐢熶骇棰嗘枡鍗曚竴瑙堣〃_ST> productERP = SqlSugarHelper.DBERP.Queryable<WMS_鐢ㄥ弸鐢熶骇棰嗘枡鍗曚竴瑙堣〃_ST>().Where(x => true).ToList();
+                foreach (var item in EngineeringERP)
+                {
+                    var x = productionOutOrder.Where(x => x.UpperOrderNo == item.鍗曞彿).FirstOrDefault();
+                    if (x == null)
+                    {
+                        if(productionoutboundOrderAdd.Where(x => x.UpperOrderNo == item.鍗曞彿).FirstOrDefault()==null)
+                        {
+                            Dt_ProductionOutboundOrder outOrder = new Dt_ProductionOutboundOrder()
+                            {
+                                OrderNo = GetOrderPintCode("OrderNoOut"),
+                                UpperOrderNo = item.鍗曞彿,
+                                OrderStatus = (int)OrderStateEmun.鏈紑濮�,
+                                OrderType = (int)OrderTypeEmun.鐢熶骇棰嗘枡鍗�,
+                                CreateType = (int)OrderCreateTypeEmun.ERP鎺ㄩ��,
+                                Details = new List<Dt_ProductionOutboundOrderDetail>()
+                                {
+                                    new Dt_ProductionOutboundOrderDetail()
+                                    {
+                                        MaterielCode = item.瀛愪欢鏂欏彿,
+                                        MaterielName = item.瀛愪欢鍝佸悕,
+                                        DemandClassification = item.闇�姹傚悕绉�,
+                                        OrderQuantity = item.瀛愪欢瀹為檯鐢ㄩ噺,
+                                        NotOutQuantity = item.瀛愪欢鏈彂鏁伴噺,
+                                        OverOutQuantity = item.瀛愪欢鍙戞斁鏁伴噺,
+                                    }
+                                }
+                            };
+                            EngineeringoutboundOrderAdd.Add(outOrder);
+                        }
+                        else
+                        {
+                            var existingOrder = EngineeringoutboundOrderAdd.Where(x => x.UpperOrderNo == item.鍗曞彿).FirstOrDefault();
+                            existingOrder.Details.Add(new Dt_ProductionOutboundOrderDetail()
+                            {
+                                MaterielCode = item.瀛愪欢鏂欏彿,
+                                MaterielName = item.瀛愪欢鍝佸悕,
+                                DemandClassification = item.闇�姹傚悕绉�,
+                                OrderQuantity = item.瀛愪欢瀹為檯鐢ㄩ噺,
+                                NotOutQuantity = item.瀛愪欢鏈彂鏁伴噺,
+                                OverOutQuantity = item.瀛愪欢鍙戞斁鏁伴噺,
+                            });
+                        }
+                    }
+                    //else
+                    //{
+                    //    foreach (var detail in x.Details)
+                    //    {
+                    //        if (detail.MaterielCode != item.瀛愪欢鏂欏彿 && detail.MaterielName != item.瀛愪欢鍝佸悕)
+                    //        {
+                    //            if (EngineeringoutboundOrderUpdate.Where(o => o.UpperOrderNo == item.鍗曞彿).FirstOrDefault() == null)
+                    //            {
+                    //                x.Details = new List<Dt_ProductionOutboundOrderDetail>()
+                    //                        {
+                    //                            new Dt_ProductionOutboundOrderDetail()
+                    //                            {
+                    //                                MaterielCode = item.瀛愪欢鏂欏彿,
+                    //                                MaterielName = item.瀛愪欢鍝佸悕,
+                    //                                DemandClassification = item.闇�姹傚悕绉�,
+                    //                                OrderQuantity = item.瀛愪欢瀹為檯鐢ㄩ噺,
+                    //                                NotOutQuantity = item.瀛愪欢鏈彂鏁伴噺,
+                    //                                OverOutQuantity = item.瀛愪欢鍙戞斁鏁伴噺,
+                    //                            }
+                    //                        };
+                    //                EngineeringoutboundOrderUpdate.Add(x);
+                    //            }
+                    //            else
+                    //            {
+                    //                var existingOrder = EngineeringoutboundOrderUpdate.Where(o => o.UpperOrderNo == item.鍗曞彿).FirstOrDefault();
+                    //                existingOrder.Details.Add(new Dt_ProductionOutboundOrderDetail()
+                    //                {
+                    //                    MaterielCode = item.瀛愪欢鏂欏彿,
+                    //                    MaterielName = item.瀛愪欢鍝佸悕,
+                    //                    DemandClassification = item.闇�姹傚悕绉�,
+                    //                    OrderQuantity = item.瀛愪欢瀹為檯鐢ㄩ噺,
+                    //                    NotOutQuantity = item.瀛愪欢鏈彂鏁伴噺,
+                    //                    OverOutQuantity = item.瀛愪欢鍙戞斁鏁伴噺,
+                    //                });
+                    //            }
+                    //        }
+                    //    }
+                    //}
+                }
+                if (EngineeringoutboundOrderAdd.Count > 0)
+                {
+                    foreach (var order in EngineeringoutboundOrderAdd)
+                    {
+                        _productionoutboundorderRepository.AddDataNavAsync(order);
+                    }
+                }
+                if (EngineeringoutboundOrderUpdate.Count > 0)
+                {
+                    _productionoutboundorderRepository.UpdateDataNav(EngineeringoutboundOrderUpdate);
+                }
+                foreach (var item in productERP)
+                {
+                    var x = productionOutOrder.Where(x => x.UpperOrderNo == item.鍗曞彿).FirstOrDefault();
+                    if (x == null)
+                    {
+                        if (productionoutboundOrderAdd.Where(x => x.UpperOrderNo == item.鍗曞彿).FirstOrDefault() == null)
+                        {
+                            Dt_ProductionOutboundOrder outOrder = new Dt_ProductionOutboundOrder()
+                            {
+                                OrderNo = GetOrderPintCode("OrderNoOut"),
+                                UpperOrderNo = item.鍗曞彿,
+                                OrderStatus = (int)OrderStateEmun.鏈紑濮�,
+                                OrderType = (int)OrderTypeEmun.鐢熶骇棰嗘枡鍗�,
+                                CreateType = (int)OrderCreateTypeEmun.ERP鎺ㄩ��,
+                                Details = new List<Dt_ProductionOutboundOrderDetail>()
+                                {
+                                    new Dt_ProductionOutboundOrderDetail()
+                                    {
+                                        MaterielCode = item.瀛愪欢鏂欏彿,
+                                        MaterielName = item.瀛愪欢鍝佸悕,
+                                        DemandClassification = item.闇�姹傚悕绉�,
+                                        OrderQuantity = item.瀛愪欢瀹為檯鐢ㄩ噺,
+                                        NotOutQuantity = item.瀛愪欢鏈彂鏁伴噺,
+                                        OverOutQuantity = item.瀛愪欢鍙戞斁鏁伴噺,
+                                    }
+                                }
+                            };
+                            productionoutboundOrderAdd.Add(outOrder);
+                        }
+                        else
+                        {
+                            var existingOrder = productionoutboundOrderAdd.Where(x => x.UpperOrderNo == item.鍗曞彿).FirstOrDefault();
+                            existingOrder.Details.Add(new Dt_ProductionOutboundOrderDetail()
+                            {
+                                MaterielCode = item.瀛愪欢鏂欏彿,
+                                MaterielName = item.瀛愪欢鍝佸悕,
+                                DemandClassification = item.闇�姹傚悕绉�,
+                                OrderQuantity = item.瀛愪欢瀹為檯鐢ㄩ噺,
+                                NotOutQuantity = item.瀛愪欢鏈彂鏁伴噺,
+                                OverOutQuantity = item.瀛愪欢鍙戞斁鏁伴噺,
+                            });
+                        }
+                    }
+                    //else
+                    //{
+                    //    foreach (var detail in x.Details)
+                    //    {
+                    //        if (productionoutboundOrderUpdate.Where(o => o.UpperOrderNo == item.鍗曞彿).FirstOrDefault() == null)
+                    //        {
+                    //            x.Details = new List<Dt_ProductionOutboundOrderDetail>()
+                    //                        {
+                    //                            new Dt_ProductionOutboundOrderDetail()
+                    //                            {
+                    //                                MaterielCode = item.瀛愪欢鏂欏彿,
+                    //                                MaterielName = item.瀛愪欢鍝佸悕,
+                    //                                DemandClassification = item.闇�姹傚悕绉�,
+                    //                                OrderQuantity = item.瀛愪欢瀹為檯鐢ㄩ噺,
+                    //                                NotOutQuantity = item.瀛愪欢鏈彂鏁伴噺,
+                    //                                OverOutQuantity = item.瀛愪欢鍙戞斁鏁伴噺,
+                    //                            }
+                    //                        };
+                    //            productionoutboundOrderUpdate.Add(x);
+                    //        }
+                    //        else
+                    //        {
+                    //            var existingOrder = productionoutboundOrderUpdate.Where(o => o.UpperOrderNo == item.鍗曞彿).FirstOrDefault();
+                    //            existingOrder.Details.Add(new Dt_ProductionOutboundOrderDetail()
+                    //            {
+                    //                MaterielCode = item.瀛愪欢鏂欏彿,
+                    //                MaterielName = item.瀛愪欢鍝佸悕,
+                    //                DemandClassification = item.闇�姹傚悕绉�,
+                    //                OrderQuantity = item.瀛愪欢瀹為檯鐢ㄩ噺,
+                    //                NotOutQuantity = item.瀛愪欢鏈彂鏁伴噺,
+                    //                OverOutQuantity = item.瀛愪欢鍙戞斁鏁伴噺,
+                    //            });
+                    //        }
+                    //    }
+                    //}
+                }
+                
+
+                if (productionoutboundOrderAdd.Count > 0)
+                {
+                    foreach (var order in productionoutboundOrderAdd)
+                    {
+                        _productionoutboundorderRepository.AddDataNavAsync(order);
+                    } 
+                }
+                if (productionoutboundOrderUpdate.Count > 0)
+                {
+                    _productionoutboundorderRepository.UpdateDataNav(productionoutboundOrderUpdate);
+                }
+                #endregion
+
             }
             catch (Exception ex)
             {
@@ -128,10 +335,10 @@
             }
         }
 
-        public string GetOrderPintCode()
+        public string GetOrderPintCode(string printCode)
         {
             string PrintCode = "";
-            var PrintSetting = SqlSugarHelper.DbWMS.Queryable<Dt_PrintSetting>().Where(x => x.PrintCode == "OrderNo").ToList().FirstOrDefault();
+            var PrintSetting = SqlSugarHelper.DbWMS.Queryable<Dt_PrintSetting>().Where(x => x.PrintCode == printCode).ToList().FirstOrDefault();
 
             if (PrintSetting.Spare1 == DateTime.Now.ToString("yyyyMMdd"))
             {
@@ -142,7 +349,7 @@
             {
                 PrintSetting.Spare1 = DateTime.Now.ToString("yyyyMMdd");
                 PrintSetting.PrintNo = 2;
-                PrintCode = PrintSetting.PrintCode + PrintSetting.Spare1 + 1.ToString().PadLeft(PrintSetting.Spare2, '0');
+                PrintCode = PrintSetting.Spare1 + 1.ToString().PadLeft(PrintSetting.Spare2, '0');
             }
             SqlSugarHelper.DbWMS.Updateable(PrintSetting).ExecuteCommand();
             return PrintCode;

--
Gitblit v1.9.3