From 387731cab892804912e68cb91e6fb804411c4756 Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期一, 27 十月 2025 23:32:16 +0800
Subject: [PATCH] 优化与ERP出库单逻辑,增加打印程序
---
项目代码/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/AspNetCoreSchedule.cs | 286 +++++++++++++++++++++++++++-----------------------------
1 files changed, 139 insertions(+), 147 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 6240332..d2824f8 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"
@@ -1,4 +1,5 @@
-锘縰sing MailKit.Search;
+锘縰sing AngleSharp.Dom;
+using MailKit.Search;
using Masuit.Tools;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
@@ -30,14 +31,13 @@
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 readonly IUnitOfWorkManage _unitOfWorkManage;
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, IDt_OtherOutboundOrderRepository otheroutboundorderRepository, IDt_AllocateOutboundOrderRepository allocateoutboundorderRepository, IDt_InventoryOutboundOrderRepository inventoryOutboundOrderRepository,IDt_ProductionOutboundOrderRepository productionOutboundOrderRepository)
+ 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_AllocateOutboundOrderRepository allocateoutboundorderRepository,IDt_ProductionOutboundOrderRepository productionOutboundOrderRepository,IUnitOfWorkManage unitOfWorkManage)
{
_logger = logger;
_locationRepository = locationRepository;
@@ -47,10 +47,9 @@
_stationManagerRepository = stationManagerRepository;
_configService = configService;
_inboundOrderRepository = inboundOrderRepository;
- _otheroutboundorderRepository = otheroutboundorderRepository;
_allocateoutboundorderRepository = allocateoutboundorderRepository;
- _inventoryoutboundorderRepository = inventoryOutboundOrderRepository;
_productionoutboundorderRepository = productionOutboundOrderRepository;
+ _unitOfWorkManage = unitOfWorkManage;
}
public Task StartAsync(CancellationToken cancellationToken)
@@ -130,121 +129,28 @@
}
#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();
+ var x = productionOutOrder.Where(x => x.UpperOrderNo == item.鍗曞彿 && x.DemandClassification == item.闇�姹傚悕绉� && x.OrderPartNumber == item.璁㈠崟鏂欏彿 && x.OrderSpec == item.璁㈠崟瑙勬牸).FirstOrDefault();
if (x == null)
{
- if(productionoutboundOrderAdd.Where(x => x.UpperOrderNo == item.鍗曞彿).FirstOrDefault()==null)
+ if(productionoutboundOrderAdd.Where(x => x.UpperOrderNo == item.鍗曞彿 && x.DemandClassification == item.闇�姹傚悕绉� && x.OrderPartNumber == item.璁㈠崟鏂欏彿 && x.OrderSpec == 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.瀛愪欢鍝佸悕,
+ OrderName = 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.鍗曞彿,
+ OrderPartNumber = item.璁㈠崟鏂欏彿,
+ OrderSpec = item.璁㈠崟瑙勬牸,
OrderStatus = (int)OrderStateEmun.鏈紑濮�,
OrderType = (int)OrderTypeEmun.鐢熶骇棰嗘枡鍗�,
CreateType = (int)OrderCreateTypeEmun.ERP鎺ㄩ��,
@@ -254,7 +160,8 @@
{
MaterielCode = item.瀛愪欢鏂欏彿,
MaterielName = item.瀛愪欢鍝佸悕,
- DemandClassification = item.闇�姹傚悕绉�,
+ Specs = item.瀛愪欢瑙勬牸,
+ Weight = item.瀛愪欢鍗曢噸,
OrderQuantity = item.瀛愪欢瀹為檯鐢ㄩ噺,
NotOutQuantity = item.瀛愪欢鏈彂鏁伴噺,
OverOutQuantity = item.瀛愪欢鍙戞斁鏁伴噺,
@@ -270,67 +177,152 @@
{
MaterielCode = item.瀛愪欢鏂欏彿,
MaterielName = item.瀛愪欢鍝佸悕,
- DemandClassification = item.闇�姹傚悕绉�,
+ Specs = item.瀛愪欢瑙勬牸,
+ Weight = 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.瀛愪欢鍙戞斁鏁伴噺,
- // });
- // }
- // }
- //}
+ }
+ foreach (var item in productERP)
+ {
+ var x = productionOutOrder.Where(x => x.UpperOrderNo == item.鍗曞彿 && x.DemandClassification == item.闇�姹傚悕绉� && x.OrderPartNumber == item.璁㈠崟鏂欏彿).FirstOrDefault();
+ if (x == null)
+ {
+ if (productionoutboundOrderAdd.Where(x => x.UpperOrderNo == item.鍗曞彿 && x.DemandClassification == item.闇�姹傚悕绉� && x.OrderPartNumber == item.璁㈠崟鏂欏彿).FirstOrDefault() == null)
+ {
+ Dt_ProductionOutboundOrder outOrder = new Dt_ProductionOutboundOrder()
+ {
+ OrderNo = GetOrderPintCode("OrderNoOut"),
+ UpperOrderNo = item.鍗曞彿,
+ OrderName = item.璁㈠崟鍝佸悕,
+ DemandClassification = item.闇�姹傚悕绉�,
+ OrderPartNumber = item.璁㈠崟鏂欏彿,
+ //OrderSpec = item.璁㈠崟瑙勬牸,
+ OrderStatus = (int)OrderStateEmun.鏈紑濮�,
+ OrderType = (int)OrderTypeEmun.鐢熶骇棰嗘枡鍗�,
+ CreateType = (int)OrderCreateTypeEmun.ERP鎺ㄩ��,
+ Details = new List<Dt_ProductionOutboundOrderDetail>()
+ {
+ new Dt_ProductionOutboundOrderDetail()
+ {
+ MaterielCode = item.瀛愪欢鏂欏彿,
+ MaterielName = item.瀛愪欢鍝佸悕,
+ Specs = item.瀛愪欢瑙勬牸,
+ Weight = item.瀛愪欢鍗曢噸,
+ OrderQuantity = item.瀛愪欢瀹為檯鐢ㄩ噺,
+ NotOutQuantity = item.瀛愪欢鏈彂鏁伴噺,
+ OverOutQuantity = item.瀛愪欢鍙戞斁鏁伴噺,
+ }
+ }
+ };
+ productionoutboundOrderAdd.Add(outOrder);
+ }
+ else
+ {
+ var existingOrder = productionoutboundOrderAdd.Where(x => x.UpperOrderNo == item.鍗曞彿 && x.DemandClassification == item.闇�姹傚悕绉� && x.OrderPartNumber == item.璁㈠崟鏂欏彿).FirstOrDefault();
+ existingOrder.Details.Add(new Dt_ProductionOutboundOrderDetail()
+ {
+ MaterielCode = item.瀛愪欢鏂欏彿,
+ MaterielName = item.瀛愪欢鍝佸悕,
+ Specs = item.瀛愪欢瑙勬牸,
+ Weight = item.瀛愪欢鍗曢噸,
+ OrderQuantity = item.瀛愪欢瀹為檯鐢ㄩ噺,
+ NotOutQuantity = item.瀛愪欢鏈彂鏁伴噺,
+ OverOutQuantity = item.瀛愪欢鍙戞斁鏁伴噺,
+ });
+ }
+ }
+
}
+ #endregion
+
+ #region ERP璋冩嫧鍑哄簱鍗曞悓姝�
+
+ var allocateoutboundorder = _allocateoutboundorderRepository.Db.Queryable<Dt_AllocateOutboundOrder>().Includes(x => x.Details).ToList();
+
+ List<Dt_AllocateOutboundOrder> allocateoutboundorderAdd = new List<Dt_AllocateOutboundOrder>();
+ List<Dt_AllocateOutboundOrder> allocateoutboundorderUpdate = new List<Dt_AllocateOutboundOrder>();
+ List<WMS_鐢ㄥ弸鐢垫帶鏌滆皟鎷ㄤ竴瑙堣〃_ST> ERPallocateOrder = SqlSugarHelper.DBERP.Queryable<WMS_鐢ㄥ弸鐢垫帶鏌滆皟鎷ㄤ竴瑙堣〃_ST>().Where(x => true).ToList();
+ foreach (var item in ERPallocateOrder)
+ {
+ var x = allocateoutboundorder.Where(x => x.UpperOrderNo == item.鍗曞彿 && x.DemandClassification == item.闇�姹傚悕绉� && x.OrderPartNumber == item.璁㈠崟鏂欏彿 && x.OrderSpec == item.璁㈠崟瑙勬牸).FirstOrDefault();
+ if (x == null)
+ {
+ if (allocateoutboundorderAdd.Where(x => x.UpperOrderNo == item.鍗曞彿).FirstOrDefault() == null)
+ {
+ Dt_AllocateOutboundOrder outOrder = new Dt_AllocateOutboundOrder()
+ {
+ OrderNo = GetOrderPintCode("OrderNoOut"),
+ UpperOrderNo = item.鍗曞彿,
+ OrderName=item.璁㈠崟鍝佸悕,
+ DemandClassification=item.闇�姹傚悕绉�,
+ OrderPartNumber =item.璁㈠崟鏂欏彿,
+ OrderSpec =item.璁㈠崟瑙勬牸,
+ OrderStatus = (int)OrderStateEmun.鏈紑濮�,
+ OrderType = (int)OrderTypeEmun.璋冩嫧鍑哄簱鍗�,
+ CreateType = (int)OrderCreateTypeEmun.ERP鎺ㄩ��,
+ Details = new List<Dt_AllocateOutboundOrderDetail>()
+ {
+ new Dt_AllocateOutboundOrderDetail()
+ {
+ MaterielCode = item.瀛愪欢鏂欏彿,
+ MaterielName = item.瀛愪欢鍝佸悕,
+ Specs = item.瀛愪欢瑙勬牸,
+ Weight = item.瀛愪欢鍗曢噸,
+ OrderQuantity = item.瀛愪欢瀹為檯鐢ㄩ噺,
+ NotOutQuantity = item.瀛愪欢鏈彂鏁伴噺,
+ OverOutQuantity = item.瀛愪欢鍙戞斁鏁伴噺,
+ }
+ }
+ };
+ allocateoutboundorderAdd.Add(outOrder);
+ }
+ else
+ {
+ var existingOrder = allocateoutboundorderAdd.Where(x => x.UpperOrderNo == item.鍗曞彿 && x.DemandClassification == item.闇�姹傚悕绉� && x.OrderPartNumber == item.璁㈠崟鏂欏彿 && x.OrderSpec == item.璁㈠崟瑙勬牸).FirstOrDefault();
+ existingOrder.Details.Add(new Dt_AllocateOutboundOrderDetail()
+ {
+ MaterielCode = item.瀛愪欢鏂欏彿,
+ MaterielName = item.瀛愪欢鍝佸悕,
+ Specs = item.瀛愪欢瑙勬牸,
+ Weight = item.瀛愪欢鍗曢噸,
+ OrderQuantity = item.瀛愪欢瀹為檯鐢ㄩ噺,
+ NotOutQuantity = item.瀛愪欢鏈彂鏁伴噺,
+ OverOutQuantity = item.瀛愪欢鍙戞斁鏁伴噺,
+ });
+ }
+ }
+ }
+ #endregion
+
+ #region 鏁版嵁澶勭悊
+ _unitOfWorkManage.BeginTran();
if (productionoutboundOrderAdd.Count > 0)
{
- foreach (var order in productionoutboundOrderAdd)
- {
- _productionoutboundorderRepository.AddDataNavAsync(order);
- }
+ //foreach (var order in productionoutboundOrderAdd)
+ //{
+ // _productionoutboundorderRepository.AddDataNavAsync(order);
+ //}
+ SqlSugarHelper.DbWMS.InsertNav(productionoutboundOrderAdd).Include(x => x.Details).ExecuteCommandAsync();
}
- if (productionoutboundOrderUpdate.Count > 0)
+ if (allocateoutboundorderAdd.Count > 0)
{
- _productionoutboundorderRepository.UpdateDataNav(productionoutboundOrderUpdate);
+ SqlSugarHelper.DbWMS.InsertNav(allocateoutboundorderAdd).Include(x=>x.Details).ExecuteCommandAsync();
}
+ _unitOfWorkManage.CommitTran();
+
+
#endregion
}
catch (Exception ex)
{
+ _unitOfWorkManage.RollbackTran();
ConsoleHelper.WriteErrorLine($"閿欒淇℃伅锛�" + ex.Message);
}
}
--
Gitblit v1.9.3