Moved API and DB methods to interfaces in order to leverage Dependency Injection, disolved APICaller class, including functionality in several other functions, included Single Load Lock information into Production Passdown report, changed persistant data file to json instead of xml, and adjusted persistant data file to include a week's worth of data instead of a single day.
This commit is contained in:
@ -0,0 +1,41 @@
|
||||
using ReportingServices.ReportingObjects;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ReportingServices.Dependency_Injections
|
||||
{
|
||||
public class FabTimeReportingRepository : IFabTimeReportingRepository
|
||||
{
|
||||
public async Task<List<ReactorOutsByRDS>> GetMovesTrendData(string url)
|
||||
{
|
||||
return await GetJsonData<List<ReactorOutsByRDS>>(url);
|
||||
}
|
||||
|
||||
public async Task<List<EquipmentStateByDay>> GetToolStateTrendData(string url)
|
||||
{
|
||||
return await GetJsonData<List<EquipmentStateByDay>>(url);
|
||||
}
|
||||
|
||||
public async Task<List<ToolStateCurrent>> GetToolStateData(string url)
|
||||
{
|
||||
return await GetJsonData<List<ToolStateCurrent>>(url);
|
||||
}
|
||||
|
||||
public async Task<T> GetJsonData<T>(string url)
|
||||
{
|
||||
T deserializedJson;
|
||||
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
using (HttpResponseMessage response = await client.GetAsync(url))
|
||||
{
|
||||
string apiResponse = await response.Content.ReadAsStringAsync();
|
||||
deserializedJson = JsonSerializer.Deserialize<T>(apiResponse);
|
||||
}
|
||||
}
|
||||
|
||||
return deserializedJson;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ReportingServices.Dependency_Injections
|
||||
{
|
||||
public class JsonFileHandler : IJsonFileHandler
|
||||
{
|
||||
public T LoadJSONFile<T>(string file)
|
||||
{
|
||||
string json = File.ReadAllText(file);
|
||||
return JsonSerializer.Deserialize<T>(json);
|
||||
}
|
||||
|
||||
public void SaveJSONFile<T>(T obj, string file)
|
||||
{
|
||||
string json = JsonSerializer.Serialize(obj);
|
||||
File.WriteAllText(file, json);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,164 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using ReportingServices.Models.PlanningReport;
|
||||
using ReportingServices.ReportingObjects;
|
||||
using System.Data;
|
||||
|
||||
namespace ReportingServices.Dependency_Injections
|
||||
{
|
||||
public class ScrapeDatabaseRepository : IScrapeDatabaseRepository
|
||||
{
|
||||
private SqlConnection _connection;
|
||||
private string _connectionString = "Server=Messv01ec.ec.local\\PROD1,53959;Database=LSL2SQL;User Id=srpadmin;Password=0okm9ijn;TrustServerCertificate=true";
|
||||
|
||||
public void OpenConnection()
|
||||
{
|
||||
if (_connection == null)
|
||||
_connection = new SqlConnection(_connectionString);
|
||||
|
||||
if (_connection.State != ConnectionState.Open)
|
||||
_connection.Open();
|
||||
}
|
||||
|
||||
public void CloseConnection()
|
||||
{
|
||||
if (_connection.State != ConnectionState.Closed)
|
||||
_connection.Close();
|
||||
}
|
||||
|
||||
public int GetNumberOfPartChanges(string startDate, string endDate)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
OpenConnection();
|
||||
|
||||
SqlCommand cmd = _connection.CreateCommand();
|
||||
|
||||
string query = "SELECT COUNT(*) FROM " +
|
||||
"(SELECT REACTOR, COUNT(PROD_SPEC_ID) - 1 AS PCHANGE FROM " +
|
||||
"(SELECT REACTOR, PROD_SPEC_ID, COUNT(WO) AS PSN_COUNT FROM RDS WHERE DATE_OUT BETWEEN @startDate AND @endDate GROUP BY REACTOR, PROD_SPEC_ID) AS t " +
|
||||
"GROUP BY REACTOR) AS l WHERE PCHANGE > 0";
|
||||
|
||||
cmd.CommandText = query;
|
||||
cmd.Parameters.AddWithValue("@startDate", startDate);
|
||||
cmd.Parameters.AddWithValue("@endDate", endDate);
|
||||
|
||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
reader.Read();
|
||||
|
||||
result = int.Parse(reader[0].ToString());
|
||||
}
|
||||
|
||||
cmd.Dispose();
|
||||
|
||||
CloseConnection();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<ScrapByDay> GetScrapByDay(List<ReactorOutsByRDS> outs)
|
||||
{
|
||||
List<ScrapByDay> scrap = new();
|
||||
string rdsNumbers = "";
|
||||
|
||||
foreach (ReactorOutsByRDS rout in outs)
|
||||
rdsNumbers = rdsNumbers + "'" + rout.RDS_NO + "', ";
|
||||
|
||||
rdsNumbers = rdsNumbers.Substring(0, rdsNumbers.Length - 2);
|
||||
|
||||
OpenConnection();
|
||||
|
||||
SqlCommand cmd = _connection.CreateCommand();
|
||||
|
||||
string query = "SELECT " +
|
||||
" DATE_OUT," +
|
||||
" SUM(CUST_TOT_REJ) AS TOT_REJ_CUST," +
|
||||
" SUM(LSL_TOT_REJ) AS TOT_REJ_MANU," +
|
||||
" SUM(TW_PROD) AS TW_PROD " +
|
||||
"FROM RDS " +
|
||||
"WHERE SEQ IN (" + rdsNumbers + ") " +
|
||||
"GROUP BY DATE_OUT " +
|
||||
"ORDER BY 1 DESC";
|
||||
|
||||
cmd.CommandText = query;
|
||||
|
||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read() && reader[0].ToString() != "1/1/1900 12:00:00 AM")
|
||||
scrap.Add(new ScrapByDay(reader[0].ToString(), reader[3].ToString(), reader[1].ToString(), reader[2].ToString()));
|
||||
}
|
||||
|
||||
cmd.Dispose();
|
||||
|
||||
CloseConnection();
|
||||
|
||||
return scrap;
|
||||
}
|
||||
|
||||
public List<ReactorPSNWORuns> GetReactorPSNWORuns(string startDate, string endDate)
|
||||
{
|
||||
List<ReactorPSNWORuns> weeklyPartChanges = new();
|
||||
|
||||
OpenConnection();
|
||||
|
||||
SqlCommand cmd = _connection.CreateCommand();
|
||||
|
||||
string query = "SELECT REACTOR, PROD_SPEC_ID, COUNT(WO) FROM RDS " +
|
||||
"WHERE DATE_OUT BETWEEN @startDate AND @endDate " +
|
||||
"GROUP BY REACTOR, PROD_SPEC_ID " +
|
||||
"ORDER BY 1";
|
||||
|
||||
cmd.CommandText = query;
|
||||
cmd.Parameters.AddWithValue("@startDate", startDate);
|
||||
cmd.Parameters.AddWithValue("@endDate", endDate);
|
||||
|
||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
weeklyPartChanges.Add(new ReactorPSNWORuns(reader[0].ToString(), reader[1].ToString(), int.Parse(reader[2].ToString())));
|
||||
}
|
||||
|
||||
cmd.Dispose();
|
||||
|
||||
CloseConnection();
|
||||
|
||||
return weeklyPartChanges;
|
||||
}
|
||||
|
||||
public int[] GetNumberOfSingleLoadLocks()
|
||||
{
|
||||
int[] singleLoadLocks = new int[2];
|
||||
|
||||
OpenConnection();
|
||||
|
||||
SqlCommand cmd = _connection.CreateCommand();
|
||||
|
||||
string query = "SELECT REACT_TYPE, COUNT(ACTIVE_LL_DISABLED) AS SLL" +
|
||||
" FROM REACTOR " +
|
||||
" WHERE REACT_ASSIGNMENT IS NOT NULL " +
|
||||
" AND REACT_ASSIGNMENT <> 'Out of Service' " +
|
||||
" AND REACT_ASSIGNMENT<> '' " +
|
||||
" AND REACT_TYPE IN('ASM', 'HTR') " +
|
||||
"GROUP BY REACT_TYPE";
|
||||
|
||||
cmd.CommandText = query;
|
||||
|
||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
reader.Read();
|
||||
|
||||
singleLoadLocks[0] = int.Parse(reader[1].ToString());
|
||||
|
||||
reader.Read();
|
||||
|
||||
singleLoadLocks[1] = int.Parse(reader[1].ToString());
|
||||
}
|
||||
|
||||
cmd.Dispose();
|
||||
|
||||
CloseConnection();
|
||||
|
||||
return singleLoadLocks;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user