Removed Work Material
This commit is contained in:
parent
9fe4327850
commit
e02ad376ad
@ -1,20 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace OI.Metrology.Server.ApiControllers;
|
||||
|
||||
[Route("api/[controller]")]
|
||||
public class WorkMaterialController : Controller, IWorkMaterialController<IActionResult>
|
||||
{
|
||||
|
||||
private readonly IWorkMaterialRepository _WorkMaterialRepository;
|
||||
|
||||
public WorkMaterialController(IWorkMaterialRepository WorkMaterialRepository) =>
|
||||
_WorkMaterialRepository = WorkMaterialRepository;
|
||||
|
||||
[HttpGet("{mid}")]
|
||||
public IActionResult GetCassette(string mid) =>
|
||||
Json(_WorkMaterialRepository.GetCassette(mid), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
|
||||
|
||||
}
|
@ -76,7 +76,6 @@ public class Program
|
||||
_ = webApplicationBuilder.Services.AddScoped<IOpenInsightV1Repository, OpenInsightV1Repository>();
|
||||
_ = webApplicationBuilder.Services.AddSingleton<IInfinityQSV2Repository, InfinityQSV2Repository>();
|
||||
_ = webApplicationBuilder.Services.AddSingleton<IInfinityQSV3Repository, InfinityQSV3Repository>();
|
||||
_ = webApplicationBuilder.Services.AddSingleton<IWorkMaterialRepository, WorkMaterialRepository>();
|
||||
_ = webApplicationBuilder.Services.AddSingleton<IClientSettingsRepository>(_ => clientSettingsRepository);
|
||||
_ = webApplicationBuilder.Services.AddSingleton<IServiceShopOrderRepository, ServiceShopOrderRepository>();
|
||||
_ = webApplicationBuilder.Services.AddSingleton<ISpreadingResistanceProfileService, SpreadingResistanceProfileService>();
|
||||
|
@ -1,165 +0,0 @@
|
||||
using OI.Metrology.Server.Models;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Shared.Repositories;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace OI.Metrology.Server.Repository;
|
||||
|
||||
public class WorkMaterialRepository : IWorkMaterialRepository
|
||||
{
|
||||
|
||||
private readonly string _MockRoot;
|
||||
private readonly string _RepositoryName;
|
||||
private readonly IDbConnectionFactory _DBConnectionFactory;
|
||||
|
||||
public WorkMaterialRepository(AppSettings appSettings, IDbConnectionFactory dbConnectionFactory)
|
||||
{
|
||||
_MockRoot = appSettings.MockRoot;
|
||||
_DBConnectionFactory = dbConnectionFactory;
|
||||
_RepositoryName = nameof(WorkMaterialRepository)[..^10];
|
||||
}
|
||||
|
||||
string IWorkMaterialRepository.GetCommandText(int? workOrderNumber, int? workOrderStep, int? workOrderCassette)
|
||||
{
|
||||
StringBuilder result = new();
|
||||
_ = result.Append("select ( ").
|
||||
Append(" select wi.rds_no, ").
|
||||
Append(" rr.reactor, ").
|
||||
Append(" wi.pocket_no, ").
|
||||
Append(" wi.zone, ").
|
||||
Append(" wi.in_cass_no, ").
|
||||
Append(" wi.slot_no [in_slot_no], ").
|
||||
Append(" isnull(wo.out_cass_no, -1) [out_cass_no], ").
|
||||
Append(" isnull(wo.slot_no, -1) [out_slot_no], ").
|
||||
Append(" rr.ps_no, ").
|
||||
Append(" rr.recipe_name, ").
|
||||
Append(" rr.recipe_no, ").
|
||||
Append(" rr.spec_type ").
|
||||
Append(" from lsl2sql.dbo.wm_in_slot_no wi ").
|
||||
Append(" inner join lsl2sql.dbo.react_run rr ").
|
||||
Append(" on wi.wo_no = rr.wo_no ").
|
||||
Append(" and wi.rds_no = rr.rds_no ").
|
||||
Append(" left join lsl2sql.dbo.wm_out_slot wo ").
|
||||
Append(" on wo.wo_no = wi.wo_no ").
|
||||
Append(" and wo.rds = wi.rds_no ").
|
||||
Append(" and wo.in_cass_no = wi.in_cass_no ").
|
||||
Append(" and wo.in_slot_no = wi.slot_no ").
|
||||
Append(" where wi.wo_no = ").Append(workOrderNumber is null ? -1 : workOrderNumber.Value).Append(' ').
|
||||
Append(" and wi.rds_no = wm.rds ").
|
||||
Append(" order by wi.in_cass_no, wi.slot_no ").
|
||||
Append(" for json path ").
|
||||
Append(" ) [group] ").
|
||||
Append("from lsl2sql.dbo.wm_out_slot wm ").
|
||||
Append("where wm.wo_no = ").Append(workOrderNumber is null ? -1 : workOrderNumber.Value).Append(' ').
|
||||
Append(" and wm.proc_step_no = ").Append(workOrderStep is null ? -1 : workOrderStep.Value).Append(' ').
|
||||
Append(" and wm.out_cass_no = ").Append(workOrderCassette is null ? -1 : workOrderCassette.Value).Append(' ').
|
||||
Append("group by wm.rds ").
|
||||
Append("order by wm.rds ").
|
||||
Append("for json path ");
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
private static (int?, int?, int?, bool) GetWorkOrder(string mid)
|
||||
{
|
||||
int? workOrderStep = null;
|
||||
int? workOrderNumber = null;
|
||||
MatchCollection[] collection;
|
||||
int? workOrderCassette = null;
|
||||
if (string.IsNullOrEmpty(mid))
|
||||
collection = Array.Empty<MatchCollection>();
|
||||
else
|
||||
{
|
||||
string pattern = @"^([oiOI])?([0-9]{6,7})\.([0-5]{1})\.([0-9]{1,2})$"; // o171308.1.51
|
||||
collection = (from l in mid.Split('-') select Regex.Matches(l, pattern)).ToArray();
|
||||
}
|
||||
foreach (MatchCollection matchCollection in collection)
|
||||
{
|
||||
if (matchCollection.Count == 0)
|
||||
continue;
|
||||
if (!matchCollection[0].Success || matchCollection[0].Groups.Count != 5)
|
||||
continue;
|
||||
if (!int.TryParse(matchCollection[0].Groups[3].Value, out int workOrderStepValue))
|
||||
continue;
|
||||
if (!int.TryParse(matchCollection[0].Groups[2].Value, out int workOrderNumberValue))
|
||||
continue;
|
||||
if (!int.TryParse(matchCollection[0].Groups[4].Value, out int workOrderCassetteValue))
|
||||
continue;
|
||||
workOrderStep = workOrderStepValue;
|
||||
workOrderNumber = workOrderNumberValue;
|
||||
workOrderCassette = workOrderCassetteValue;
|
||||
break;
|
||||
}
|
||||
return new(workOrderNumber, workOrderStep, workOrderCassette, workOrderStep is not null || workOrderNumber is not null || workOrderCassette is not null);
|
||||
}
|
||||
|
||||
private static StringBuilder GetForJsonPath(IDbConnectionFactory dbConnectionFactory, string commandText)
|
||||
{
|
||||
StringBuilder stringBuilder = new();
|
||||
using DbConnection dbConnection = dbConnectionFactory.GetDbConnection(useOI2Sql: true);
|
||||
DbCommand dbCommand = dbConnection.CreateCommand();
|
||||
dbCommand.CommandText = commandText;
|
||||
DbDataReader dbDataReader = dbCommand.ExecuteReader(CommandBehavior.SequentialAccess);
|
||||
while (dbDataReader.Read())
|
||||
_ = stringBuilder.Append(dbDataReader.GetString(0));
|
||||
return stringBuilder;
|
||||
}
|
||||
|
||||
Result<WorkMaterialV2[]> IWorkMaterialRepository.GetCassette(string mid)
|
||||
{
|
||||
Result<WorkMaterialV2[]>? result;
|
||||
if (!string.IsNullOrEmpty(_MockRoot))
|
||||
{
|
||||
string json = File.ReadAllText(Path.Combine(string.Concat(AppContext.BaseDirectory, _MockRoot), $"{_RepositoryName}-{nameof(IWorkMaterialRepository.GetCassette)}.json"));
|
||||
result = JsonSerializer.Deserialize<Result<WorkMaterialV2[]>>(json);
|
||||
if (result is null)
|
||||
throw new NullReferenceException(nameof(result));
|
||||
}
|
||||
else
|
||||
{
|
||||
WorkMaterialV2[] results;
|
||||
(int? workOrderNumber, int? workOrderStep, int? workOrderCassette, bool isWorkOrder) = GetWorkOrder(mid);
|
||||
if (!isWorkOrder)
|
||||
results = Array.Empty<WorkMaterialV2>();
|
||||
else
|
||||
{
|
||||
WorkMaterial[]? group;
|
||||
JsonProperty[] jsonProperties;
|
||||
List<WorkMaterial> collection = new();
|
||||
IWorkMaterialRepository workMaterialRepository = this;
|
||||
string commandText = workMaterialRepository.GetCommandText(workOrderNumber, workOrderStep, workOrderCassette);
|
||||
StringBuilder stringBuilder = GetForJsonPath(_DBConnectionFactory, commandText);
|
||||
JsonElement[]? jsonElements = stringBuilder.Length == 0 ? Array.Empty<JsonElement>() : JsonSerializer.Deserialize<JsonElement[]>(stringBuilder.ToString());
|
||||
if (jsonElements is null)
|
||||
throw new NullReferenceException(nameof(jsonElements));
|
||||
foreach (JsonElement jsonElement in jsonElements)
|
||||
{
|
||||
if (jsonElement.ValueKind != JsonValueKind.Object)
|
||||
continue;
|
||||
jsonProperties = jsonElement.EnumerateObject().ToArray();
|
||||
if (jsonProperties.Length == 0)
|
||||
continue;
|
||||
group = JsonSerializer.Deserialize<WorkMaterial[]>(jsonProperties.First().Value.ToString(), new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
if (group is null)
|
||||
continue;
|
||||
foreach (WorkMaterial workMaterial in group)
|
||||
collection.Add(workMaterial);
|
||||
}
|
||||
if (collection is null)
|
||||
throw new NullReferenceException(nameof(collection));
|
||||
results = WorkMaterial.Convert(collection);
|
||||
}
|
||||
result = new()
|
||||
{
|
||||
Results = results,
|
||||
TotalRows = results.Length,
|
||||
};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -73,7 +73,6 @@
|
||||
<li>@Html.ActionLink("Run Information", "RunInfo", "Pages", new { area = "" }, null)</li>
|
||||
<li>@Html.ActionLink("Run Headers", "RunHeaders", "Pages", new { area = "" }, null)</li>
|
||||
<li>@Html.ActionLink("Export", "Index", "Export", new { area = "" }, null)</li>
|
||||
<li>@Html.ActionLink("Work Material", "WorkMaterial", "Reactors", new { area = "" }, null)</li>
|
||||
<li><a href="https://oi-metrology-viewer-archive.mes.infineon.com/" target="_blank">Archive</a></li>
|
||||
</ul>
|
||||
<p class="navbar-text navbar-right">
|
||||
|
@ -1,50 +0,0 @@
|
||||
namespace OI.Metrology.Shared.DataModels;
|
||||
|
||||
public record WorkMaterial(string RDS_NO,
|
||||
int REACTOR,
|
||||
string POCKET_NO,
|
||||
string ZONE,
|
||||
int IN_CASS_NO,
|
||||
int IN_SLOT_NO,
|
||||
int OUT_CASS_NO,
|
||||
int OUT_SLOT_NO,
|
||||
string PS_NO,
|
||||
string RECIPE_NAME,
|
||||
int RECIPE_NO,
|
||||
string SPEC_TYPE)
|
||||
{
|
||||
|
||||
public static WorkMaterialV2[] Convert(List<WorkMaterial> collection)
|
||||
{
|
||||
List<WorkMaterialV2> results = new();
|
||||
foreach (WorkMaterial item in collection)
|
||||
results.Add(Map(item));
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
public static WorkMaterialV2 Map(WorkMaterial item)
|
||||
{
|
||||
WorkMaterialV2 result = new(item.RDS_NO,
|
||||
item.REACTOR,
|
||||
item.POCKET_NO,
|
||||
item.ZONE,
|
||||
item.IN_CASS_NO,
|
||||
item.IN_SLOT_NO,
|
||||
item.OUT_CASS_NO,
|
||||
item.OUT_SLOT_NO,
|
||||
item.PS_NO);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public record WorkMaterialV2(string RunDataSheet,
|
||||
int Reactor,
|
||||
string Pocket,
|
||||
string Zone,
|
||||
int InCassetteNumber,
|
||||
int InSlotNumber,
|
||||
int OutCassetteNumber,
|
||||
int OutSlotNumber,
|
||||
string PSN)
|
||||
{ }
|
@ -1,14 +0,0 @@
|
||||
namespace OI.Metrology.Shared.Models.Stateless;
|
||||
|
||||
public interface IWorkMaterialController<T>
|
||||
{
|
||||
|
||||
enum Action : int
|
||||
{
|
||||
Get = 0
|
||||
}
|
||||
|
||||
static string GetRouteName() => nameof(IWorkMaterialController<T>)[1..^10];
|
||||
T GetCassette(string mid);
|
||||
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
|
||||
namespace OI.Metrology.Shared.Models.Stateless;
|
||||
|
||||
public interface IWorkMaterialRepository
|
||||
{
|
||||
|
||||
string GetCommandText(int? workOrderNumber, int? workOrderStep, int? workOrderCassette);
|
||||
Result<WorkMaterialV2[]> GetCassette(string mid);
|
||||
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
|
||||
namespace OI.Metrology.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class UnitTestWorkMaterialController
|
||||
{
|
||||
|
||||
#pragma warning disable CS8618
|
||||
|
||||
private static ILogger? _Logger;
|
||||
private static string _ControllerName;
|
||||
private static TestContext _TestContext;
|
||||
private static WebApplicationFactory<Server.Program>? _WebApplicationFactory;
|
||||
|
||||
#pragma warning restore
|
||||
|
||||
[ClassInitialize]
|
||||
public static void ClassInitAsync(TestContext testContext)
|
||||
{
|
||||
_TestContext = testContext;
|
||||
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
_Logger = serviceProvider.GetRequiredService<ILogger<Server.Program>>();
|
||||
_ControllerName = nameof(Server.ApiControllers.WorkMaterialController)[..^10];
|
||||
}
|
||||
|
||||
private static void NonThrowTryCatch()
|
||||
{
|
||||
try
|
||||
{ throw new Exception(); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestControllerName()
|
||||
{
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.AreEqual(IWorkMaterialController<string>.GetRouteName(), _ControllerName);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
[Ignore]
|
||||
#endif
|
||||
[TestMethod]
|
||||
public void GetCassette()
|
||||
{
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IWorkMaterialRepository? workMaterialRepository = serviceProvider?.GetRequiredService<IWorkMaterialRepository>();
|
||||
Result<WorkMaterialV2[]>? result = workMaterialRepository?.GetCassette("O171927.1.37");
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
[Ignore]
|
||||
#endif
|
||||
[TestMethod]
|
||||
public async Task GetCassetteApi()
|
||||
{
|
||||
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.IsTrue(httpClient is not null);
|
||||
string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/O171927.1.37/");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetCassette)}.json"), json);
|
||||
Result<WorkMaterialV2[]>? result = System.Text.Json.JsonSerializer.Deserialize<Result<WorkMaterialV2[]>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user