Migration to DevOps
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
using Newtonsoft.Json;
|
||||
using PartSource.Automation.Models;
|
||||
using PartSource.Data;
|
||||
using PartSource.Data.Contexts;
|
||||
using PartSource.Data.Models;
|
||||
using PartSource.Services;
|
||||
using Ratermania.Automation.Interfaces;
|
||||
using Ratermania.Shopify;
|
||||
using Ratermania.Shopify.Resources;
|
||||
using System;
|
||||
@@ -15,20 +17,22 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace PartSource.Automation.Jobs
|
||||
{
|
||||
public class UpdatePositioning// : IAutomationJob
|
||||
public class UpdatePositioning : IAutomationJob
|
||||
{
|
||||
private readonly ShopifyClient _shopifyClient;
|
||||
private readonly PartSourceContext _partSourceContext;
|
||||
private readonly FitmentContext _fitmentContext;
|
||||
private readonly VehicleService _vehicleService;
|
||||
|
||||
public UpdatePositioning(PartSourceContext partSourceContext, ShopifyClient shopifyClient, VehicleService vehicleService)
|
||||
public UpdatePositioning(PartSourceContext partSourceContext, FitmentContext fitmentContext, ShopifyClient shopifyClient, VehicleService vehicleService)
|
||||
{
|
||||
_partSourceContext = partSourceContext;
|
||||
_fitmentContext = fitmentContext;
|
||||
_shopifyClient = shopifyClient;
|
||||
_vehicleService = vehicleService;
|
||||
}
|
||||
|
||||
public async Task<AutomationJobResult> Run()
|
||||
public async Task Run()
|
||||
{
|
||||
IDictionary<string, object> parameters = new Dictionary<string, object>
|
||||
{
|
||||
@@ -58,31 +62,29 @@ namespace PartSource.Automation.Jobs
|
||||
continue;
|
||||
}
|
||||
|
||||
//await DeletePositionMetafields(product.Id);
|
||||
string currentPosition = fitments[0].Position;
|
||||
List<int> vehicleIds = new List<int>();
|
||||
|
||||
//string currentPosition = fitments[0].Position;
|
||||
//List<int> vehicleIds = new List<int>();
|
||||
foreach (Fitment fitment in fitments)
|
||||
{
|
||||
if (fitment.Position != currentPosition)
|
||||
{
|
||||
await SavePositionMetafield(product, vehicleIds, currentPosition);
|
||||
|
||||
//foreach (Fitment fitment in fitments)
|
||||
//{
|
||||
// if (fitment.Position != currentPosition)
|
||||
// {
|
||||
// await SavePositionMetafield(product, vehicleIds, currentPosition);
|
||||
currentPosition = fitment.Position;
|
||||
vehicleIds = new List<int>();
|
||||
}
|
||||
|
||||
// currentPosition = fitment.Position;
|
||||
// vehicleIds = new List<int>();
|
||||
// }
|
||||
// We don't need to DCF map because these are both sourced from WHI
|
||||
IList<int> fitmentVehicleIds = vehicles.Where(v => v.BaseVehicleId == fitment.BaseVehicleId && v.EngineConfigId == fitment.EngineConfigId)
|
||||
.Select(v => v.VehicleToEngineConfigId)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
// // We don't need to DCF map because these are both sourced from WHI
|
||||
// IList<int> fitmentVehicleIds = vehicles.Where(v => v.BaseVehicleId == fitment.BaseVehicleId && v.EngineConfigId == fitment.EngineConfigId)
|
||||
// .Select(v => v.VehicleToEngineConfigId)
|
||||
// .Distinct()
|
||||
// .ToList();
|
||||
vehicleIds.AddRange(fitmentVehicleIds);
|
||||
}
|
||||
|
||||
// vehicleIds.AddRange(fitmentVehicleIds);
|
||||
//}
|
||||
|
||||
//await SavePositionMetafield(product, vehicleIds, currentPosition);
|
||||
await SavePositionMetafield(product, vehicleIds, currentPosition);
|
||||
|
||||
|
||||
IList<string> notes = fitments.Select(f => f.NoteText)
|
||||
@@ -93,13 +95,12 @@ namespace PartSource.Automation.Jobs
|
||||
|
||||
foreach (string noteText in notes)
|
||||
{
|
||||
IList<int> vehicleIds = fitments.Where(f => f.NoteText == noteText)
|
||||
vehicleIds = fitments.Where(f => f.NoteText == noteText)
|
||||
.Select(f => new { f.EngineConfigId, f.BaseVehicleId })
|
||||
.SelectMany(f => vehicles.Where(v => v.BaseVehicleId == f.BaseVehicleId && v.EngineConfigId == f.EngineConfigId))
|
||||
.Select(v => v.VehicleToEngineConfigId)
|
||||
.ToList();
|
||||
|
||||
|
||||
vehicleNotes.Add(new { noteText, vehicleIds });
|
||||
}
|
||||
|
||||
@@ -123,8 +124,6 @@ namespace PartSource.Automation.Jobs
|
||||
|
||||
//importData.UpdatedAt = DateTime.Now;
|
||||
//importData.UpdateType = "Positioning";
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
@@ -134,9 +133,7 @@ namespace PartSource.Automation.Jobs
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Console.Write('.');
|
||||
// await _partSourceContext.SaveChangesAsync();
|
||||
{
|
||||
products = await _shopifyClient.Products.GetNext();
|
||||
}
|
||||
|
||||
@@ -147,23 +144,17 @@ namespace PartSource.Automation.Jobs
|
||||
products = await _shopifyClient.Products.GetPrevious();
|
||||
}
|
||||
}
|
||||
|
||||
return new AutomationJobResult
|
||||
{
|
||||
Message = "Positioning updated successfully",
|
||||
IsSuccess = true
|
||||
};
|
||||
}
|
||||
|
||||
private IList<Fitment> GetPositionOrderedFitments(string partNumber, string lineCode)
|
||||
{
|
||||
partNumber = Regex.Replace(partNumber, "[^a-zA-Z0-9]", string.Empty);
|
||||
|
||||
IQueryable<string> whiCodes = _partSourceContext.DcfMappings
|
||||
IQueryable<string> whiCodes = _fitmentContext.DcfMappings
|
||||
.Where(d => d.LineCode == lineCode)
|
||||
.Select(d => d.WhiCode);
|
||||
|
||||
return _partSourceContext.Fitments
|
||||
return _fitmentContext.Fitments
|
||||
.Where(f => f.PartNumber == partNumber && whiCodes.Contains(f.LineCode) && !string.IsNullOrEmpty(f.Position))
|
||||
.OrderBy(f => f.Position)
|
||||
.ToList();
|
||||
|
||||
Reference in New Issue
Block a user