| | |
| | | using MailKit.Search; |
| | | using AngleSharp.Dom; |
| | | using MailKit.Search; |
| | | using Masuit.Tools; |
| | | using Microsoft.Extensions.Hosting; |
| | | using Microsoft.Extensions.Logging; |
| | |
| | | private readonly ISys_ConfigService _configService; |
| | | private readonly ILocationInfoRepository _locationRepository; |
| | | private readonly IDt_InboundOrderRepository _inboundOrderRepository; |
| | | private readonly IDt_ProductionOutboundOrderRepository _productionoutboundorderRepository; |
| | | 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) |
| | | 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; |
| | |
| | | _stationManagerRepository = stationManagerRepository; |
| | | _configService = configService; |
| | | _inboundOrderRepository = inboundOrderRepository; |
| | | _allocateoutboundorderRepository = allocateoutboundorderRepository; |
| | | _productionoutboundorderRepository = productionOutboundOrderRepository; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | |
| | |
| | | { |
| | | 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>(); |
| | |
| | | { |
| | | Dt_InboundOrder Print = new Dt_InboundOrder() |
| | | { |
| | | OrderNo = GetOrderPintCode(), |
| | | OrderNo = GetOrderPintCode("OrderNoIn"), |
| | | UpperOrderNo = item.åå·, |
| | | DemandClassification = item.éæ±åç±», |
| | | OrderType = item.åæ®ç±»å, |
| | |
| | | { |
| | | if (x.OrderNo == null || x.OrderNo == "") |
| | | { |
| | | x.OrderNo = GetOrderPintCode(); |
| | | x.OrderNo = GetOrderPintCode("OrderNoIn"); |
| | | x.UpperOrderNo = item.åå·; |
| | | x.DemandClassification = item.éæ±åç±»; |
| | | x.OrderType = item.åæ®ç±»å; |
| | |
| | | { |
| | | _inboundOrderRepository.UpdateData(inboundOrderUpdate); |
| | | } |
| | | #endregion |
| | | |
| | | #region ERPçäº§é¢æå忥 |
| | | |
| | | var productionOutOrder = _productionoutboundorderRepository.Db.Queryable<Dt_ProductionOutboundOrder>().Includes(x => x.Details).ToList(); |
| | | |
| | | List<Dt_ProductionOutboundOrder> productionoutboundOrderAdd = 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.åå· && x.DemandClassification == item.éæ±åç§° && x.OrderPartNumber == item.订åæå· && x.OrderSpec == item.订åè§æ ¼).FirstOrDefault(); |
| | | if (x == 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.åå·, |
| | | 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.åå·).FirstOrDefault(); |
| | | existingOrder.Details.Add(new Dt_ProductionOutboundOrderDetail() |
| | | { |
| | | MaterielCode = item.åä»¶æå·, |
| | | MaterielName = item.åä»¶åå, |
| | | Specs = item.åä»¶è§æ ¼, |
| | | Weight = 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); |
| | | //} |
| | | SqlSugarHelper.DbWMS.InsertNav(productionoutboundOrderAdd).Include(x => x.Details).ExecuteCommandAsync(); |
| | | } |
| | | if (allocateoutboundorderAdd.Count > 0) |
| | | { |
| | | SqlSugarHelper.DbWMS.InsertNav(allocateoutboundorderAdd).Include(x=>x.Details).ExecuteCommandAsync(); |
| | | } |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | |
| | | #endregion |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | ConsoleHelper.WriteErrorLine($"é误信æ¯ï¼" + ex.Message); |
| | | } |
| | | } |
| | | |
| | | 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")) |
| | | { |