| | |
| | | using Masuit.Tools; |
| | | using MailKit.Search; |
| | | using Masuit.Tools; |
| | | using Microsoft.Extensions.Hosting; |
| | | using Microsoft.Extensions.Logging; |
| | | using System.Net.Mail; |
| | | using SixLabors.Fonts; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Net; |
| | | using System.Net.Mail; |
| | | using System.Text; |
| | | using WIDESEA_Cache; |
| | | using WIDESEA_Core.Const; |
| | | using WIDESEA_DTO.WMS; |
| | | using WIDESEA_IOrderRepository; |
| | | using WIDESEA_IServices; |
| | | using WIDESEA_Model.Models.ERP; |
| | | using WIDESEA_Model.Models.Order; |
| | | using WIDESEA_OrderRepository; |
| | | using WIDESEAWCS_BasicInfoRepository; |
| | | |
| | | namespace WIDESEA_StorageTaskServices |
| | |
| | | private readonly IDt_StationManagerRepository _stationManagerRepository; |
| | | 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) |
| | | 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; |
| | |
| | | _taskRepository = taskRepository; |
| | | _stationManagerRepository = stationManagerRepository; |
| | | _configService = configService; |
| | | _inboundOrderRepository = inboundOrderRepository; |
| | | _otheroutboundorderRepository = otheroutboundorderRepository; |
| | | _allocateoutboundorderRepository = allocateoutboundorderRepository; |
| | | _inventoryoutboundorderRepository = inventoryOutboundOrderRepository; |
| | | _productionoutboundorderRepository = productionOutboundOrderRepository; |
| | | } |
| | | |
| | | public Task StartAsync(CancellationToken cancellationToken) |
| | |
| | | { |
| | | 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>(); |
| | | foreach (var item in ERPPrintChecklist) |
| | | { |
| | | var x = printCheckList.Where(x => x.MaterialNo == item.æå· && x.UpperOrderNo == item.åå· && x.WarehouseName == item.å
¥åºä»åºåç§°).FirstOrDefault(); |
| | | if (x == null) |
| | | { |
| | | Dt_InboundOrder Print = new Dt_InboundOrder() |
| | | { |
| | | OrderNo = GetOrderPintCode("OrderNoIn"), |
| | | UpperOrderNo = item.åå·, |
| | | DemandClassification = item.éæ±åç±», |
| | | OrderType = item.åæ®ç±»å, |
| | | WarehouseName = item.å
¥åºä»åºåç§°, |
| | | Datetime = item.æ¥æ.ToString(), |
| | | LineNumber = item.è¡å·, |
| | | ProductDrawingNumber = item.产åå¾å·, |
| | | MaterialNo = item.æå·, |
| | | MaterialName = item.åå, |
| | | Weight = item.åé, |
| | | Specs = item.è§æ ¼, |
| | | Unit = item.åä½, |
| | | Texture = item.ç¨åæè´¨, |
| | | Quantity = item.å
¥åºæ°é, |
| | | OrderStatus = item.åæ®ç¶æ |
| | | |
| | | }; |
| | | inboundOrderAdd.Add(Print); |
| | | } |
| | | else |
| | | { |
| | | if (x.OrderNo == null || x.OrderNo == "") |
| | | { |
| | | x.OrderNo = GetOrderPintCode("OrderNoIn"); |
| | | x.UpperOrderNo = item.åå·; |
| | | x.DemandClassification = item.éæ±åç±»; |
| | | x.OrderType = item.åæ®ç±»å; |
| | | x.WarehouseName = item.å
¥åºä»åºåç§°; |
| | | x.Datetime = item.æ¥æ.ToString(); |
| | | x.LineNumber = item.è¡å·; |
| | | x.ProductDrawingNumber = item.产åå¾å·; |
| | | x.MaterialNo = item.æå·; |
| | | x.MaterialName = item.åå; |
| | | x.Weight = item.åé; |
| | | x.Specs = item.è§æ ¼; |
| | | x.Unit = item.åä½; |
| | | x.Texture = item.ç¨åæè´¨; |
| | | x.Quantity = item.å
¥åºæ°é; |
| | | x.OrderStatus = item.åæ®ç¶æ; |
| | | inboundOrderUpdate.Add(x); |
| | | } |
| | | } |
| | | } |
| | | if (inboundOrderAdd.Count > 0) |
| | | { |
| | | _inboundOrderRepository.AddData(inboundOrderAdd); |
| | | } |
| | | if (inboundOrderUpdate.Count > 0) |
| | | { |
| | | _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) |
| | | { |
| | | ConsoleHelper.WriteErrorLine($"é误信æ¯ï¼" + ex.Message); |
| | | } |
| | | } |
| | | |
| | | public string GetOrderPintCode(string printCode) |
| | | { |
| | | string PrintCode = ""; |
| | | var PrintSetting = SqlSugarHelper.DbWMS.Queryable<Dt_PrintSetting>().Where(x => x.PrintCode == printCode).ToList().FirstOrDefault(); |
| | | |
| | | if (PrintSetting.Spare1 == DateTime.Now.ToString("yyyyMMdd")) |
| | | { |
| | | PrintCode = PrintSetting.Spare1 + PrintSetting.PrintNo.ToString().PadLeft(PrintSetting.Spare2, '0'); |
| | | PrintSetting.PrintNo = PrintSetting.PrintNo + 1; |
| | | } |
| | | else |
| | | { |
| | | PrintSetting.Spare1 = DateTime.Now.ToString("yyyyMMdd"); |
| | | PrintSetting.PrintNo = 2; |
| | | PrintCode = PrintSetting.Spare1 + 1.ToString().PadLeft(PrintSetting.Spare2, '0'); |
| | | } |
| | | SqlSugarHelper.DbWMS.Updateable(PrintSetting).ExecuteCommand(); |
| | | return PrintCode; |
| | | } |
| | | |
| | | public Task StopAsync(CancellationToken cancellationToken) |
| | | { |