101 lines
3.8 KiB
C#
101 lines
3.8 KiB
C#
using Azure.Core;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Data;
|
|
using SystemX.Core.DB;
|
|
using SystemX.Core.Services;
|
|
using Web.Tra.Model;
|
|
using WebClient.Library.Config;
|
|
|
|
namespace Web.Tra.Services
|
|
{
|
|
public class CPXV2LogService
|
|
{
|
|
private readonly IServiceScopeFactory _scopeFactory;
|
|
private readonly ConfigService<WebClientConfig>? _configService;
|
|
|
|
public CPXV2LogService(IServiceProvider serviceProvider, IServiceScopeFactory scopeFactory, ConfigService<WebClientConfig> configService)
|
|
{
|
|
_scopeFactory = scopeFactory;
|
|
_configService = configService;
|
|
}
|
|
|
|
//Get Overview
|
|
public async Task<List<Overview>> GetOverview(RequestSearch request)
|
|
{
|
|
List<Overview> overview = new List<Overview>();
|
|
|
|
int startYear = request.SearchStart.Year;
|
|
int endYear = request.SearchEnd.Year;
|
|
|
|
//search log
|
|
List<HIST_LogSummary> SearchLogList = new List<HIST_LogSummary>();
|
|
for (int i = startYear; i <= endYear; i++)
|
|
{
|
|
using (var scope = _scopeFactory.CreateScope())
|
|
{
|
|
var provider = scope.ServiceProvider.GetRequiredService<DbContextProvider>();
|
|
using (var context = GetDBContext<CPXV2Log>(provider, i))
|
|
{
|
|
if (context is not null)
|
|
{
|
|
SearchLogList.AddRange(await context.HIST_LogSummaries.Where(x => request.SearchStart <= DateOnly.FromDateTime(x.TestDT) && DateOnly.FromDateTime(x.TestDT) <= request.SearchEnd).ToListAsync());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//search testlist
|
|
using (var scope = _scopeFactory.CreateScope())
|
|
{
|
|
var provider = scope.ServiceProvider.GetRequiredService<DbContextProvider>();
|
|
using (var context = GetDBContext<CPXV2>(provider, 1))
|
|
{
|
|
if (context is not null)
|
|
{
|
|
var varProdVariant = context.PROD_Variants.ToList();
|
|
var varProudGroup = context.PROD_Groups.ToList();
|
|
var TesetInfoList = varProdVariant.Select(x => new TestInfo
|
|
{
|
|
PROD_Variant = x,
|
|
PROD_Group = varProudGroup.Find(y => y.No == x.GroupNo)
|
|
}).ToList();
|
|
|
|
var search = SearchLogList.Select(x => new SearchData
|
|
{
|
|
Summary = x,
|
|
TestInfo = TesetInfoList.Find(y => y.PROD_Variant.No == x.TestListVariantNo)
|
|
});
|
|
|
|
var ListSearchData = search
|
|
.Where(x => x.Summary.TestListVariantNo > 0)
|
|
.OrderBy(x => x.Summary.TestDT).ToList();
|
|
|
|
var group = ListSearchData
|
|
.GroupBy(x => (x.Summary.HostID, x.Summary.Section))
|
|
.Select(x => x.ToOverview())
|
|
.OrderBy(x => x.Host);
|
|
|
|
overview.AddRange(group);
|
|
}
|
|
}
|
|
}
|
|
|
|
return overview.OrderBy(x=>x.TestDate).ToList();
|
|
}
|
|
|
|
//Get DBContext
|
|
private T? GetDBContext<T>(DbContextProvider provider, int dbID) where T : DbContext
|
|
{
|
|
var contextName = typeof(T).Name;
|
|
|
|
var findDB = provider.DBDictionary.Values.First(x => x.DBID == dbID);
|
|
if(findDB is not null)
|
|
{
|
|
return provider?.GetDBContext<T>($"{findDB.DBName}");
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|