Delete Work Material
Added InfinityQSV3-GetEpiProTempVerification Added nigth shift
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
using OI.Metrology.Server.Models;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Shared.Repositories;
|
||||
@ -15,9 +16,9 @@ public class InfinityQSRepository : IInfinityQSRepository
|
||||
private readonly string _RepositoryName;
|
||||
private readonly IDbConnectionFactory _DBConnectionFactory;
|
||||
|
||||
public InfinityQSRepository(string mockRoot, IDbConnectionFactory dbConnectionFactory)
|
||||
public InfinityQSRepository(AppSettings appSettings, IDbConnectionFactory dbConnectionFactory)
|
||||
{
|
||||
_MockRoot = mockRoot;
|
||||
_MockRoot = appSettings.MockRoot;
|
||||
_DBConnectionFactory = dbConnectionFactory;
|
||||
_RepositoryName = nameof(InfinityQSRepository)[..^10];
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
using OI.Metrology.Server.Models;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Shared.Repositories;
|
||||
@ -15,9 +16,9 @@ public class InfinityQSV2Repository : IInfinityQSV2Repository
|
||||
private readonly string _RepositoryName;
|
||||
private readonly IDbConnectionFactory _DBConnectionFactory;
|
||||
|
||||
public InfinityQSV2Repository(string mockRoot, IDbConnectionFactory dbConnectionFactory)
|
||||
public InfinityQSV2Repository(AppSettings appSettings, IDbConnectionFactory dbConnectionFactory)
|
||||
{
|
||||
_MockRoot = mockRoot;
|
||||
_MockRoot = appSettings.MockRoot;
|
||||
_DBConnectionFactory = dbConnectionFactory;
|
||||
_RepositoryName = nameof(InfinityQSV2Repository)[..^10];
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
using OI.Metrology.Server.Models;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Models;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Shared.Repositories;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
@ -13,13 +16,17 @@ public class InfinityQSV3Repository : IInfinityQSV3Repository
|
||||
|
||||
private readonly string _MockRoot;
|
||||
private readonly string _RepositoryName;
|
||||
private readonly IHttpClientFactory _HttpClientFactory;
|
||||
private readonly IDbConnectionFactory _DBConnectionFactory;
|
||||
private readonly string _OpenInsightApplicationProgrammingInterface;
|
||||
|
||||
public InfinityQSV3Repository(string mockRoot, IDbConnectionFactory dbConnectionFactory)
|
||||
public InfinityQSV3Repository(AppSettings appSettings, IDbConnectionFactory dbConnectionFactory, IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_MockRoot = mockRoot;
|
||||
_MockRoot = appSettings.MockRoot;
|
||||
_HttpClientFactory = httpClientFactory;
|
||||
_DBConnectionFactory = dbConnectionFactory;
|
||||
_RepositoryName = nameof(InfinityQSV3Repository)[..^10];
|
||||
_OpenInsightApplicationProgrammingInterface = appSettings.OpenInsightApplicationProgrammingInterface;
|
||||
}
|
||||
|
||||
string IInfinityQSV3Repository.GetCommandText(string subGroupId)
|
||||
@ -318,4 +325,218 @@ public class InfinityQSV3Repository : IInfinityQSV3Repository
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
private JsonElement[] GetAllReactorsAsJsonElementElement()
|
||||
{
|
||||
JsonElement[]? results;
|
||||
HttpClient httpClient = _HttpClientFactory.CreateClient();
|
||||
Task<string> task = httpClient.GetStringAsync($"{_OpenInsightApplicationProgrammingInterface}/reactors");
|
||||
task.Wait();
|
||||
JsonElement? jsonElement = JsonSerializer.Deserialize<JsonElement>(task.Result);
|
||||
if (jsonElement is null)
|
||||
throw new NullReferenceException(nameof(jsonElement));
|
||||
string json = jsonElement.Value.EnumerateObject().First().Value.ToString();
|
||||
results = JsonSerializer.Deserialize<JsonElement[]>(json);
|
||||
if (results is null)
|
||||
throw new NullReferenceException(nameof(results));
|
||||
return results;
|
||||
}
|
||||
|
||||
private ReadOnlyDictionary<int, Reactor> GetReactorsMatchingType(string? reactTypeFilter)
|
||||
{
|
||||
Dictionary<int, Reactor> results = new();
|
||||
string json;
|
||||
Reactor? reactor;
|
||||
JsonElement[]? jsonElements = GetAllReactorsAsJsonElementElement();
|
||||
foreach (JsonElement jsonElement in jsonElements)
|
||||
{
|
||||
json = jsonElement.EnumerateObject().First().Value.ToString();
|
||||
if (reactTypeFilter is not null && !json.Contains(reactTypeFilter))
|
||||
continue;
|
||||
try
|
||||
{ reactor = JsonSerializer.Deserialize(json, ReactorSourceGenerationContext.Default.Reactor); }
|
||||
catch (Exception) { reactor = null; }
|
||||
if (reactor is null || reactor.ReactType != reactTypeFilter)
|
||||
continue;
|
||||
results.Add(reactor.ReactorNo, reactor);
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
|
||||
string IInfinityQSV3Repository.GetCommandText(List<string> eppReactorNumbers)
|
||||
{
|
||||
StringBuilder result = new();
|
||||
_ = result
|
||||
.AppendLine(" select se.f_sgrp, ")
|
||||
.AppendLine(" dateadd(HH, -7, (dateadd(SS, convert(bigint, se.f_sgrp), '19700101'))) date_time, ")
|
||||
.AppendLine(" iq.pr_name, ")
|
||||
.AppendLine(" iq.pd_name, ")
|
||||
.AppendLine(" max(case ")
|
||||
.AppendLine(" when td.f_test = 1104769646 ")
|
||||
.AppendLine(" then se.f_val ")
|
||||
.AppendLine(" else null ")
|
||||
.AppendLine(" end) as iq_value, ")
|
||||
.AppendLine(" max(case ")
|
||||
.AppendLine(" when td.f_test = 1312288843 ")
|
||||
.AppendLine(" then se.f_val else null ")
|
||||
.AppendLine(" end) as iq_temp_offset_percent ")
|
||||
.AppendLine(" from ( ")
|
||||
.AppendLine(" select ")
|
||||
.AppendLine(" max(se.f_sgrp) se_max_sgrp, ")
|
||||
.AppendLine(" se.f_test se_test, ")
|
||||
.AppendLine(" pr.f_name pr_name, ")
|
||||
.AppendLine(" pd.f_name pd_name ")
|
||||
.AppendLine(" from [spcepiworld].[dbo].[sgrp_ext] se ")
|
||||
.AppendLine(" join [spcepiworld].[dbo].[prcs_dat] pr ")
|
||||
.AppendLine(" on se.f_prcs = pr.f_prcs ")
|
||||
.AppendLine(" join [spcepiworld].[dbo].[part_dat] pd ")
|
||||
.AppendLine(" on se.f_part = pd.f_part ")
|
||||
.AppendLine(" where se.f_flag = 0 ")
|
||||
.Append(" and pr.f_name in (").Append(string.Join(',', eppReactorNumbers)).AppendLine(") ")
|
||||
.AppendLine(" and pd.f_name = '1090 - Full Load' ")
|
||||
.AppendLine(" and se.f_test in (1104769646, 1312288843) ")
|
||||
.AppendLine(" group by se.f_test, ")
|
||||
.AppendLine(" pr.f_name, ")
|
||||
.AppendLine(" pd.f_name ")
|
||||
.AppendLine(" ) as iq ")
|
||||
.AppendLine(" join [spcepiworld].[dbo].[sgrp_ext] se ")
|
||||
.AppendLine(" on iq.se_max_sgrp = se.f_sgrp ")
|
||||
.AppendLine(" join [spcepiworld].[dbo].[test_dat] td ")
|
||||
.AppendLine(" on iq.se_test = td.f_test ")
|
||||
.AppendLine(" and se.f_test = td.f_test ")
|
||||
.AppendLine(" where se.f_flag = 0 ")
|
||||
.AppendLine(" and td.f_test in (1104769646, 1312288843) ")
|
||||
.AppendLine(" group by se.f_sgrp, ")
|
||||
.AppendLine(" iq.pr_name, ")
|
||||
.AppendLine(" iq.pd_name ")
|
||||
.AppendLine(" order by iq.pr_name ")
|
||||
.AppendLine(" for json path; ");
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
private List<string> Convert(int[] night)
|
||||
{
|
||||
List<string> results = new();
|
||||
foreach (int reactor in night)
|
||||
results.Add(reactor.ToString());
|
||||
return results;
|
||||
}
|
||||
|
||||
private static void Append(StringBuilder result, int loadedCount, Reactor reactor, string loadedRDS, TimeSpan timeSpan, InfinityQS1090FullLoad infinityQS1090FullLoad)
|
||||
{
|
||||
_ = result.
|
||||
Append("<td>").Append(reactor.ReactorNo).Append("</td>").
|
||||
Append("<td class='").Append(reactor.E10State).Append("'>").Append(reactor.E10State).Append("</td>").
|
||||
Append("<td class='LoadedRDSCount").Append(loadedCount).Append("'>").Append(loadedRDS).Append("</td>").
|
||||
Append("<td>").Append(infinityQS1090FullLoad.Value).Append("</td>").
|
||||
Append("<td>").Append(infinityQS1090FullLoad.TemperatureOffsetPercentage).Append("</td>").
|
||||
Append("<td>").Append(infinityQS1090FullLoad.SubGroupIdFormated).Append("</td>").
|
||||
Append("<td>").Append(Math.Floor(timeSpan.TotalHours)).Append("</td>");
|
||||
}
|
||||
|
||||
private static void Append(StringBuilder result)
|
||||
{
|
||||
_ = result.
|
||||
Append("<td> </td>").
|
||||
Append("<td> </td>").
|
||||
Append("<td> </td>").
|
||||
Append("<td> </td>").
|
||||
Append("<td> </td>").
|
||||
Append("<td> </td>").
|
||||
Append("<td> </td>").
|
||||
Append("<td> </td>");
|
||||
}
|
||||
|
||||
string IInfinityQSV3Repository.GetEpiProTempVerification(int[] night)
|
||||
{
|
||||
StringBuilder result;
|
||||
List<string> eppReactorNumbers = new();
|
||||
List<string> nightSiftReactors = Convert(night);
|
||||
ReadOnlyDictionary<int, Reactor> eppReactors = GetReactorsMatchingType("EPP");
|
||||
foreach (KeyValuePair<int, Reactor> keyValuePair in eppReactors)
|
||||
eppReactorNumbers.Add($"'{keyValuePair.Key}'");
|
||||
if (!string.IsNullOrEmpty(_MockRoot))
|
||||
{
|
||||
string html = File.ReadAllText(Path.Combine(string.Concat(AppContext.BaseDirectory, _MockRoot), $"{_RepositoryName}-{nameof(IInfinityQSV3Repository.GetEpiProTempVerification)}.html"));
|
||||
result = new(html);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool found;
|
||||
result = new();
|
||||
int loadedCount;
|
||||
Reactor? reactor;
|
||||
string loadedRDS;
|
||||
int reactorNumber;
|
||||
TimeSpan timeSpan;
|
||||
List<int> used = new();
|
||||
List<int> dayShiftOrder = new();
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
List<int> nightShiftOrder = new();
|
||||
InfinityQS1090FullLoad infinityQS1090FullLoad;
|
||||
IInfinityQSV3Repository infinityQSV3Repository = this;
|
||||
string commandText = infinityQSV3Repository.GetCommandText(eppReactorNumbers);
|
||||
StringBuilder stringBuilder = GetForJsonPath(_DBConnectionFactory, commandText);
|
||||
InfinityQS1090FullLoad[]? results = stringBuilder.Length == 0 ? Array.Empty<InfinityQS1090FullLoad>() : JsonSerializer.Deserialize(stringBuilder.ToString(), InfinityQS1090FullLoadArraySourceGenerationContext.Default.InfinityQS1090FullLoadArray);
|
||||
if (results is null)
|
||||
throw new NullReferenceException(nameof(results));
|
||||
for (int i = 0; i < results.Length; i++)
|
||||
{
|
||||
infinityQS1090FullLoad = results[i];
|
||||
if (infinityQS1090FullLoad.Reactor is null)
|
||||
continue;
|
||||
if (!int.TryParse(infinityQS1090FullLoad.Reactor, out reactorNumber))
|
||||
continue;
|
||||
if (!eppReactors.TryGetValue(reactorNumber, out reactor))
|
||||
continue;
|
||||
if (!nightSiftReactors.Contains(infinityQS1090FullLoad.Reactor))
|
||||
dayShiftOrder.Add(i);
|
||||
else
|
||||
nightShiftOrder.Add(i);
|
||||
}
|
||||
for (int i = 0; i < results.Length; i++)
|
||||
{
|
||||
if (used.Contains(i) || !dayShiftOrder.Contains(i))
|
||||
continue;
|
||||
infinityQS1090FullLoad = results[i];
|
||||
if (infinityQS1090FullLoad.Reactor is null)
|
||||
continue;
|
||||
if (!int.TryParse(infinityQS1090FullLoad.Reactor, out reactorNumber))
|
||||
continue;
|
||||
if (!eppReactors.TryGetValue(reactorNumber, out reactor))
|
||||
continue;
|
||||
used.Add(i);
|
||||
found = false;
|
||||
timeSpan = new(ticks - infinityQS1090FullLoad.SubGroupIdFormated.Ticks);
|
||||
loadedCount = reactor.LoadedRDS is null ? 0 : reactor.LoadedRDS.Count;
|
||||
loadedRDS = reactor.LoadedRDS is null ? "" : reactor.LoadedRDS[0].ToString();
|
||||
_ = result.Append("<tr>");
|
||||
Append(result, loadedCount, reactor, loadedRDS, timeSpan, infinityQS1090FullLoad);
|
||||
for (int j = i + 1; j < results.Length; j++)
|
||||
{
|
||||
if (used.Contains(j) || !nightShiftOrder.Contains(j))
|
||||
continue;
|
||||
infinityQS1090FullLoad = results[j];
|
||||
if (infinityQS1090FullLoad.Reactor is null)
|
||||
continue;
|
||||
if (!int.TryParse(infinityQS1090FullLoad.Reactor, out reactorNumber))
|
||||
continue;
|
||||
if (!eppReactors.TryGetValue(reactorNumber, out reactor))
|
||||
continue;
|
||||
used.Add(j);
|
||||
found = true;
|
||||
_ = result.Append("<td> </td>");
|
||||
timeSpan = new(ticks - infinityQS1090FullLoad.SubGroupIdFormated.Ticks);
|
||||
loadedCount = reactor.LoadedRDS is null ? 0 : reactor.LoadedRDS.Count;
|
||||
loadedRDS = reactor.LoadedRDS is null ? "" : reactor.LoadedRDS[0].ToString();
|
||||
Append(result, loadedCount, reactor, loadedRDS, timeSpan, infinityQS1090FullLoad);
|
||||
break;
|
||||
}
|
||||
if (!found)
|
||||
Append(result);
|
||||
_ = result.Append("</tr>");
|
||||
}
|
||||
}
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
using OI.Metrology.Server.Models;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using System.Text.Json;
|
||||
@ -11,9 +12,9 @@ public class PinRepository : IPinRepository
|
||||
private readonly string _RepositoryName;
|
||||
private readonly Dictionary<string, Dictionary<long, HeaderCommon>> _RdsToHeaderCommonCollection;
|
||||
|
||||
public PinRepository(string mockRoot)
|
||||
public PinRepository(AppSettings appSettings)
|
||||
{
|
||||
_MockRoot = mockRoot;
|
||||
_MockRoot = appSettings.MockRoot;
|
||||
_RdsToHeaderCommonCollection = new();
|
||||
_RepositoryName = nameof(PinRepository)[..^10];
|
||||
}
|
||||
|
@ -7,11 +7,6 @@ namespace OI.Metrology.Server.Repository;
|
||||
public class ServiceShopOrderRepository : IServiceShopOrderRepository
|
||||
{
|
||||
|
||||
private readonly ILogger<ServiceShopOrderRepository> _Logger;
|
||||
|
||||
public ServiceShopOrderRepository(ILogger<ServiceShopOrderRepository> logger) =>
|
||||
_Logger = logger;
|
||||
|
||||
private static ServiceShopOrder[] GetServiceShopOrders(Shared.Models.ServiceShop? serviceShop)
|
||||
{
|
||||
ServiceShopOrder[] result = IServiceShopOrder.GetServiceShopOrders(serviceShop);
|
||||
|
@ -1,3 +1,4 @@
|
||||
using OI.Metrology.Server.Models;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Shared.Services;
|
||||
@ -13,9 +14,9 @@ public class ToolTypesRepository : IToolTypesRepository
|
||||
private readonly string _MockRoot;
|
||||
private readonly string _RepositoryName;
|
||||
|
||||
public ToolTypesRepository(string mockRoot)
|
||||
public ToolTypesRepository(AppSettings appSettings)
|
||||
{
|
||||
_MockRoot = mockRoot;
|
||||
_MockRoot = appSettings.MockRoot;
|
||||
_RepositoryName = nameof(ToolTypesRepository)[..^10];
|
||||
}
|
||||
|
||||
|
@ -1,164 +0,0 @@
|
||||
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(string mockRoot, IDbConnectionFactory dbConnectionFactory)
|
||||
{
|
||||
_MockRoot = 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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user