| | |
| | | using MailKit.Search; |
| | | using AngleSharp.Dom; |
| | | using MailKit.Search; |
| | | using Masuit.Tools; |
| | | using Microsoft.Extensions.Hosting; |
| | | using Microsoft.Extensions.Logging; |
| | | using SixLabors.Fonts; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Data; |
| | | using System.Net; |
| | | using System.Net.Mail; |
| | | using System.Text; |
| | | using System.Xml.Linq; |
| | | using WIDESEA_Cache; |
| | | using WIDESEA_Core.Const; |
| | | using WIDESEA_DTO.WMS; |
| | | using WIDESEA_IOrderRepository; |
| | | using WIDESEA_IOrderServices; |
| | | using WIDESEA_IServices; |
| | | using WIDESEA_Model.Models.ERP; |
| | | using WIDESEA_Model.Models.Order; |
| | |
| | | { |
| | | private readonly ILogger<MyBackgroundService> _logger; |
| | | private readonly IStockInfoRepository _stockInfoRepository; |
| | | private readonly IDt_AreaInfoRepository _areaInfoRepository; //åºå |
| | | private readonly IDt_TaskRepository _taskRepository; |
| | | private readonly IDt_StationManagerRepository _stationManagerRepository; |
| | | private readonly ISys_ConfigService _configService; |
| | | private readonly ILocationInfoRepository _locationRepository; |
| | | private readonly IDt_InboundOrderRepository _inboundOrderRepository; |
| | | private readonly IDt_OutboundOrderRepository _outboundorderRepository; |
| | | |
| | | private readonly IDt_ProductionOutboundOrderRepository _productionoutboundorderRepository; |
| | | private readonly IDt_AllocateOutboundOrderRepository _allocateoutboundorderRepository; |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | private readonly IDt_ProductionOutboundOrderService _productionOutboundOrderService; |
| | | private readonly IDt_AllocateOutboundOrderService _allocateOutboundOrderService; |
| | | 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_OutboundOrderRepository outboundorderRepository) |
| | | public MyBackgroundService(ILogger<MyBackgroundService> logger, ILocationInfoRepository locationRepository, IStockInfoRepository stockInfoRepository,IDt_TaskRepository taskRepository,ISys_ConfigService configService,IDt_InboundOrderRepository inboundOrderRepository,IDt_AllocateOutboundOrderRepository allocateoutboundorderRepository,IDt_ProductionOutboundOrderRepository productionOutboundOrderRepository,IUnitOfWorkManage unitOfWorkManage, IDt_ProductionOutboundOrderService productionOutboundOrderService, IDt_AllocateOutboundOrderService allocateOutboundOrderService) |
| | | { |
| | | _logger = logger; |
| | | _locationRepository = locationRepository; |
| | | _stockInfoRepository = stockInfoRepository; |
| | | _areaInfoRepository = areaInfoRepository; |
| | | _taskRepository = taskRepository; |
| | | _stationManagerRepository = stationManagerRepository; |
| | | _configService = configService; |
| | | _inboundOrderRepository = inboundOrderRepository; |
| | | _outboundorderRepository = outboundorderRepository; |
| | | _allocateoutboundorderRepository = allocateoutboundorderRepository; |
| | | _productionoutboundorderRepository = productionOutboundOrderRepository; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _productionOutboundOrderService = productionOutboundOrderService; |
| | | _allocateOutboundOrderService = allocateOutboundOrderService; |
| | | } |
| | | |
| | | public Task StartAsync(CancellationToken cancellationToken) |
| | | { |
| | | _timer = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromMinutes(1)); |
| | | _timer = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromMinutes(10)); |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | |
| | | try |
| | | { |
| | | #region å
¥åºåæ®åæ¥ |
| | | List<WMS_éè´å
¥æåå
¥åºèªå¨æå°æ¸
å_ST> ERPPrintChecklist =SqlSugarHelper.DBERP.Queryable<WMS_éè´å
¥æåå
¥åºèªå¨æå°æ¸
å_ST>().Where(x => true).ToList(); |
| | | |
| | | 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>(); |
| | |
| | | MaterialNo = item.æå·, |
| | | MaterialName = item.åå, |
| | | Weight = item.åé, |
| | | WareHouseId = item.å
¥åºä»åºç¼ç , |
| | | Specs = item.è§æ ¼, |
| | | Unit = item.åä½, |
| | | Texture = item.ç¨åæè´¨, |
| | |
| | | x.Texture = item.ç¨åæè´¨; |
| | | x.Quantity = item.å
¥åºæ°é; |
| | | x.OrderStatus = item.åæ®ç¶æ; |
| | | x.WareHouseId = item.å
¥åºä»åºç¼ç ; |
| | | inboundOrderUpdate.Add(x); |
| | | } |
| | | } |
| | | } |
| | | #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.订åæå·).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 = item.åå·, |
| | | UpperOrderNo = item.åå·, |
| | | OrderName = item.订ååå, |
| | | DemandClassification = item.éæ±åç§°, |
| | | OrderPartNumber = 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.åä»¶åé, |
| | | ERPOrderId = item.夿åID, |
| | | WareHouseId =item.åå¨å°ç¹ID, |
| | | 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.åä»¶åé, |
| | | ERPOrderId = item.夿åID, |
| | | WareHouseId = item.åå¨å°ç¹ID, |
| | | 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 = item.åå·, |
| | | UpperOrderNo = item.åå·, |
| | | OrderName = item.订ååå, |
| | | DemandClassification = item.éæ±åç§°, |
| | | OrderPartNumber = 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.åä»¶åé, |
| | | ERPOrderId = item.夿åID, |
| | | WareHouseId =item.åå¨å°ç¹ID, |
| | | 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.åä»¶åé, |
| | | ERPOrderId = item.夿åID, |
| | | WareHouseId = item.åå¨å°ç¹ID, |
| | | 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.订åæå·).FirstOrDefault(); |
| | | if (x == null) |
| | | { |
| | | if (allocateoutboundorderAdd.Where(x => x.UpperOrderNo == item.åå·).FirstOrDefault() == null) |
| | | { |
| | | Dt_AllocateOutboundOrder outOrder = new Dt_AllocateOutboundOrder() |
| | | { |
| | | OrderNo = item.åå·, |
| | | UpperOrderNo = item.åå·, |
| | | OrderName = item.订ååå, |
| | | DemandClassification = item.éæ±åç§°, |
| | | OrderPartNumber = 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.åä»¶åé, |
| | | ERPOrderId = item.夿åID, |
| | | WareHouseId =item.åå¨å°ç¹ID, |
| | | OrderQuantity = item.åä»¶å®é
ç¨é, |
| | | NotOutQuantity = item.åä»¶æªåæ°é, |
| | | OverOutQuantity = item.åä»¶åæ¾æ°é, |
| | | } |
| | | } |
| | | }; |
| | | allocateoutboundorderAdd.Add(outOrder); |
| | | } |
| | | else |
| | | { |
| | | var existingOrder = allocateoutboundorderAdd.Where(x => x.UpperOrderNo == item.åå· && x.DemandClassification == item.éæ±åç§° && x.OrderPartNumber == item.订åæå·).FirstOrDefault(); |
| | | existingOrder.Details.Add(new Dt_AllocateOutboundOrderDetail() |
| | | { |
| | | MaterielCode = item.åä»¶æå·, |
| | | MaterielName = item.åä»¶åå, |
| | | Specs = item.åä»¶è§æ ¼, |
| | | Weight = item.åä»¶åé, |
| | | ERPOrderId = item.夿åID, |
| | | WareHouseId = item.åå¨å°ç¹ID, |
| | | OrderQuantity = item.åä»¶å®é
ç¨é, |
| | | NotOutQuantity = item.åä»¶æªåæ°é, |
| | | OverOutQuantity = item.åä»¶åæ¾æ°é, |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region æ°æ®å¤ç |
| | | |
| | | if (inboundOrderAdd.Count > 0) |
| | | { |
| | | //PrintInbound(inboundOrderAdd); |
| | | _inboundOrderRepository.AddData(inboundOrderAdd); |
| | | } |
| | | if (inboundOrderUpdate.Count > 0) |
| | | { |
| | | //PrintInbound(inboundOrderUpdate); |
| | | _inboundOrderRepository.UpdateData(inboundOrderUpdate); |
| | | } |
| | | #endregion |
| | | |
| | | var OutBoundOrder = _outboundorderRepository.QueryData(x => true); |
| | | List<Dt_OutboundOrder> outboundOrderAdd = new List<Dt_OutboundOrder>(); |
| | | List<Dt_OutboundOrder> outboundOrderUpdate = new List<Dt_OutboundOrder>(); |
| | | |
| | | #region ERPçäº§é¢æå忥 |
| | | List<WMS_ç¨åå·¥ç¨åè´§åä¸è§è¡¨_ST> ERPMaterialRequisition = SqlSugarHelper.DBERP.Queryable<WMS_ç¨åå·¥ç¨åè´§åä¸è§è¡¨_ST>().Where(x => true).ToList(); |
| | | foreach (var item in ERPMaterialRequisition) |
| | | if (productionoutboundOrderAdd.Count > 0) |
| | | { |
| | | var x = OutBoundOrder.Where(x => x.MaterielCode == item.åä»¶æå· && x.UpperOrderNo == item.åå·).FirstOrDefault(); |
| | | if(x == null) |
| | | { |
| | | Dt_OutboundOrder outOrder = new Dt_OutboundOrder() |
| | | { |
| | | OrderNo = GetOrderPintCode("OrderNoOut"), |
| | | UpperOrderNo = item.åå·, |
| | | MaterielCode = item.åä»¶æå·, |
| | | MaterielName = item.åä»¶åå, |
| | | DemandClassification = item.éæ±åç§°, |
| | | OrderQuantity = item.åä»¶å®é
ç¨é, |
| | | OverOutQuantity = item.åä»¶åæ¾æ°é, |
| | | NotOutQuantity = item.åä»¶æªåæ°é, |
| | | OrderStatus =(int)OrderStateEmun.æªå¼å§, |
| | | OrderType =(int)OrderTypeEmun.çäº§é¢æå, |
| | | CreateType =(int)OrderCreateTypeEmun.ERPæ¨é, |
| | | }; |
| | | outboundOrderAdd.Add(outOrder); |
| | | } |
| | | SqlSugarHelper.DbWMS.InsertNav(productionoutboundOrderAdd).Include(x => x.Details).ExecuteCommand(); |
| | | } |
| | | if (allocateoutboundorderAdd.Count > 0) |
| | | { |
| | | SqlSugarHelper.DbWMS.InsertNav(allocateoutboundorderAdd).Include(x => x.Details).ExecuteCommand(); |
| | | } |
| | | |
| | | #endregion |
| | | if (outboundOrderAdd.Count > 0) |
| | | { |
| | | _outboundorderRepository.AddData(outboundOrderAdd); |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | public void PrintInbound(List<Dt_InboundOrder> orders) |
| | | { |
| | | var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); |
| | | var Base = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.PrintIPAddress)?.ConfigValue; |
| | | var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.PrintInboundOrder)?.ConfigValue; |
| | | if (Base == null || ipAddress == null) |
| | | { |
| | | throw new InvalidOperationException("WMS IP æªé
ç½®"); |
| | | } |
| | | var IpAddress = Base + ipAddress; |
| | | var result = HttpHelper.PostAsync(IpAddress, orders.ToJsonString()).Result; |
| | | } |
| | | |
| | | public void Dispose() |
| | | { |
| | | _timer?.Dispose(); |