395 lines
20 KiB
C#
395 lines
20 KiB
C#
namespace LaaProductionWeb.Services
|
|
{
|
|
using FluentSQLClient.Interfaces;
|
|
|
|
using LaaProductionWeb.Services.Interfaces;
|
|
using LaaProductionWeb.Services.Models.Reports;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
public partial class ReportService : IReportService
|
|
{
|
|
private readonly IFluentSQLConnection fluentSQL;
|
|
|
|
public ReportService(IFluentSQLConnection fluentSQL)
|
|
=> this.fluentSQL = fluentSQL;
|
|
|
|
public CordonelPressureSensorModel LoadCordonelPressureSensorReport(CordonelPressureSensorModel model = null)
|
|
{
|
|
if (model is null)
|
|
{
|
|
model = new CordonelPressureSensorModel();
|
|
}
|
|
|
|
var where = model.Filter.Where();
|
|
var orderBy = model.Filter.OrderBy();
|
|
|
|
model.Items = this.fluentSQL
|
|
.CreateCommand($@"
|
|
SELECT [APS].[AuftragNr] AS [AuftragNr]
|
|
, [APS].[PositionNr] AS [PosNr]
|
|
, [APS].[SerienNr] AS [SerialNr]
|
|
, [APS].[KundeneigeneSerienNr] AS [CustomerSerialNr]
|
|
, [ID].[IdentNr] AS [IdentNr]
|
|
, [CPSTR].[PcbId] AS [PcbId]
|
|
, [ID].[Typ] AS [TypeI]
|
|
, [ID].[Typzusatz] AS [TypeII]
|
|
, [ID].[Nennweite] AS [Nennweite]
|
|
, [ID].[Baulaenge] AS [Baulaenge]
|
|
, [CPSTR].[AvgPressureInBar] AS [AvgPressure]
|
|
, [CPSTR].[TestPassed] AS [TestPassed]
|
|
, [CPSTR].[TestDate] AS [TestDate]
|
|
FROM [Cordonel_PressureSensor_TestResults] AS [CPSTR]
|
|
LEFT JOIN [AuftragPositionSerienNr] AS [APS]
|
|
ON [APS].[FabNr] = [CPSTR].[PcbId]
|
|
LEFT JOIN [AuftragPosition_Gesamt] AS [APG]
|
|
ON [APG].[AuftragNr] = [APS].[AuftragNr]
|
|
AND [APG].[PositionNr] = [APS].[PositionNr]
|
|
LEFT JOIN [Identnr] AS [ID]
|
|
ON [ID].[IdentNr] = [APG].[Identnr]
|
|
WHERE {where.Query}
|
|
ORDER BY {orderBy.Query}")
|
|
.SetParameters(where.Parameters)
|
|
.SetParameters(orderBy.Parameters)
|
|
.ExecuteReader(reader => new CordonelPressureSensorItem
|
|
{
|
|
AuftragNr = reader.GetValue<int?>(),
|
|
PosNr = reader.GetValue<short?>(),
|
|
SerialNr = reader.GetValue<int?>(),
|
|
CustomerSerialNr = reader.GetString(),
|
|
IdentNr = reader.GetValue<int?>(),
|
|
PcbId = reader.GetInt(),
|
|
TypeI = reader.GetString(),
|
|
TypeII = reader.GetString(),
|
|
Nennweite = reader.GetValue<int?>(),
|
|
Baulaenge = reader.GetValue<int?>(),
|
|
AVGPressure = reader.GetValue<float>(),
|
|
TestPassed = reader.GetValue<bool>(),
|
|
TestDate = reader.GetValue<DateTime>(),
|
|
});
|
|
|
|
return model;
|
|
}
|
|
|
|
public HeliumReportModel LoadHeliumPressureReport(HeliumReportModel model = null)
|
|
{
|
|
if (model is null)
|
|
{
|
|
model = new HeliumReportModel();
|
|
}
|
|
|
|
var where = model.Filter.Where();
|
|
var orderBy = model.Filter.OrderBy();
|
|
|
|
model.Items = this.fluentSQL
|
|
.CreateCommand($@"
|
|
SELECT DISTINCT
|
|
[PT].[CordonelPressureTest_FertigungsAuftragsNr] AS [FertigungNr] -- 0
|
|
, [POS].[AuftragNr] AS [AuftragNr] -- 1
|
|
, [POS].[PositionNr] AS [PositionNr] -- 2
|
|
, [PCB2SN].[MapPcbIdToSerialNumber_SerialNumber] AS [SerialNr] -- 3
|
|
, [ID].[IdentNr] AS [IdentNr] -- 4
|
|
, [PT_HE].[CordonelPressureTestHe_Id] AS [HeId] -- 5
|
|
, [PT_HE].[CordonelPressureTestHe_TestID] AS [HeTestId] -- 6
|
|
, [PT].[CordonelPressureTest_PcbId] AS [PcbId] -- 7
|
|
, [ID].[Nennweite] AS [Nennweite] -- 8
|
|
, [ID].[Baulaenge] AS [Baulaenge] -- 9
|
|
, [ID].[Typ] AS [Typ] -- 10
|
|
, [ID].[Druck] AS [Druck] -- 11
|
|
, [ID].[Temperatur] AS [Temperatur] -- 12
|
|
, [PT_HE].[CordonelPressureTestHe_LeakRate] AS [HeLakeRate] -- 13
|
|
, [PT_HE].[CordonelPressureTestHe_TestPressure] AS [HeTestPressure] -- 14
|
|
, [PT].[CordonelPressureTest_Valid] AS [IsValid] -- 15
|
|
, [PT].[CordonelPressureTest_Date] AS [TestDate] -- 16
|
|
, [PT].[CordonelPressureTest_Text] AS [Text] -- 17
|
|
, [PT_HE].[CordonelPressureTestHe_TesterName] AS [Tester] -- 18
|
|
FROM [Cordonel_PressureTest] AS [PT]
|
|
JOIN [Cordonel_PressureTest_He] AS [PT_HE] ON [PT_HE].[CordonelPressureTestHe_TestID] = [PT].[CordonelPressureTest_Id]
|
|
LEFT JOIN [Druckpruefung] AS [DP] ON [DP].[FabNr] = [PT].[CordonelPressureTest_PcbId]
|
|
JOIN [MapPcbIdToSerialNumber] AS [PCB2SN] ON [PCB2SN].[MapPcbIdToSerialNumber_PcbId] = [PT].[CordonelPressureTest_PcbId]
|
|
JOIN [AuftragPosition_Gesamt] AS [POS] ON [POS].[FertigungsauftragNr] = [PT].[CordonelPressureTest_FertigungsAuftragsNr]
|
|
JOIN [Identnr] AS [ID] ON [ID].[IdentNr] = [POS].[Identnr]
|
|
WHERE [CordonelPressureTest_IsDeleted] = 0
|
|
AND {where.Query}
|
|
ORDER BY {orderBy.Query}")
|
|
.SetParameters(where.Parameters)
|
|
.SetParameters(orderBy.Parameters)
|
|
.ExecuteReader(reader => new HeliumReportItem
|
|
{
|
|
FertigungNr = reader.GetInt(),
|
|
AuftragNr = reader.GetInt(),
|
|
PositionNr = reader.GetValue<short>(),
|
|
SerialNr = reader.GetInt(),
|
|
IdentNr = reader.GetInt(),
|
|
HeId = reader.GetInt(),
|
|
HeTestId = reader.GetInt(),
|
|
PcbId = reader.GetInt(),
|
|
Nennweite = reader.GetValue<int?>(),
|
|
Baulaenge = reader.GetValue<int?>(),
|
|
Typ = reader.GetString(),
|
|
Druck = reader.GetValue<int?>(),
|
|
Temperatur = reader.GetValue<int?>(),
|
|
HeLakeRate = reader.GetString(),
|
|
HeTestPressure = reader.GetString(),
|
|
IsValid = reader.GetValue<bool>(),
|
|
TestDate = reader.GetValue<DateTimeOffset>(),
|
|
Text = reader.GetString(),
|
|
Tester = reader.GetString()
|
|
});
|
|
|
|
return model;
|
|
}
|
|
|
|
public byte[] LoadHeliumPressureReportAsCSV(HeliumReportModel model)
|
|
{
|
|
if (model is null)
|
|
{
|
|
model = new HeliumReportModel();
|
|
}
|
|
|
|
var where = model.Filter.Where();
|
|
var orderBy = model.Filter.OrderBy();
|
|
var csvItems = new List<object[]>
|
|
{
|
|
new object[]
|
|
{
|
|
"[FertigungNr]",
|
|
"[AuftragNr]",
|
|
"[PositionNr]",
|
|
"[SerialNr]",
|
|
"[IdentNr]",
|
|
"[HeId]",
|
|
"[HeTestId]",
|
|
"[PcbId]",
|
|
"[Nennweite]",
|
|
"[Baulaenge]",
|
|
"[Typ]",
|
|
"[Druck]",
|
|
"[Temperatur]",
|
|
"[HeLakeRate]",
|
|
"[HeTestPressure]",
|
|
"[IsValid]",
|
|
"[TestDate]",
|
|
"[Text]",
|
|
"[Tester]",
|
|
}
|
|
};
|
|
var headers = Array.Empty<string>();
|
|
var items = this.fluentSQL
|
|
.CreateCommand($@"
|
|
SELECT DISTINCT
|
|
[PT].[CordonelPressureTest_FertigungsAuftragsNr] AS [FertigungNr] -- 0 Filter
|
|
, [POS].[AuftragNr] AS [AuftragNr] -- 1 Filter
|
|
, [POS].[PositionNr] AS [PositionNr] -- 2 Filter
|
|
, [PCB2SN].[MapPcbIdToSerialNumber_SerialNumber] AS [SerialNr] -- 3
|
|
, [ID].[IdentNr] AS [IdentNr] -- 4 Filter
|
|
, [PT_HE].[CordonelPressureTestHe_Id] AS [HeId] -- 5
|
|
, [PT_HE].[CordonelPressureTestHe_TestID] AS [HeTestId] -- 6
|
|
, [PT].[CordonelPressureTest_PcbId] AS [PcbId] -- 7 Filter
|
|
, [ID].[Nennweite] AS [Nennweite] -- 8 Filter
|
|
, [ID].[Baulaenge] AS [Baulaenge] -- 9 Filter
|
|
, [ID].[Typ] AS [Typ] -- 10 Filter
|
|
, [ID].[Druck] AS [Druck] -- 11 Filter
|
|
, [ID].[Temperatur] AS [Temperatur] -- 12 Filter
|
|
, [PT_HE].[CordonelPressureTestHe_LeakRate] AS [HeLakeRate] -- 13
|
|
, [PT_HE].[CordonelPressureTestHe_TestPressure] AS [HeTestPressure] -- 14
|
|
, [PT].[CordonelPressureTest_Valid] AS [IsValid] -- 15 Filter
|
|
, [PT].[CordonelPressureTest_Date] AS [TestDate] -- 16 Filter
|
|
, [PT].[CordonelPressureTest_Text] AS [Text] -- 17 Filter
|
|
, [PT_HE].[CordonelPressureTestHe_TesterName] AS [Tester] -- 18
|
|
FROM [Cordonel_PressureTest] AS [PT]
|
|
JOIN [Cordonel_PressureTest_He] AS [PT_HE] ON [PT_HE].[CordonelPressureTestHe_TestID] = [PT].[CordonelPressureTest_Id]
|
|
LEFT JOIN [Druckpruefung] AS [DP] ON [DP].[FabNr] = [PT].[CordonelPressureTest_PcbId]
|
|
JOIN [MapPcbIdToSerialNumber] AS [PCB2SN] ON [PCB2SN].[MapPcbIdToSerialNumber_PcbId] = [PT].[CordonelPressureTest_PcbId]
|
|
JOIN [AuftragPosition_Gesamt] AS [POS] ON [POS].[FertigungsauftragNr] = [PT].[CordonelPressureTest_FertigungsAuftragsNr]
|
|
JOIN [Identnr] AS [ID] ON [ID].[IdentNr] = [POS].[Identnr]
|
|
WHERE [CordonelPressureTest_IsDeleted] = 0
|
|
AND {where.Query}
|
|
ORDER BY {orderBy.Query}")
|
|
.SetParameters(where.Parameters)
|
|
.SetParameters(orderBy.Parameters)
|
|
.ExecuteReader(reader => new object[]
|
|
{
|
|
reader.GetInt(),
|
|
reader.GetInt(),
|
|
reader.GetSmallint(),
|
|
reader.GetInt(),
|
|
reader.GetInt(),
|
|
reader.GetInt(),
|
|
reader.GetInt(),
|
|
reader.GetInt(),
|
|
reader.GetValue<int?>(),
|
|
reader.GetValue<int?>(),
|
|
reader.GetString().Replace(',', ' '),
|
|
reader.GetValue<int?>(),
|
|
reader.GetValue<int?>(),
|
|
reader.GetString().Replace(',', '.'),
|
|
reader.GetString().Replace(',', ' '),
|
|
reader.GetValue<bool>(),
|
|
$"{reader.GetValue<DateTimeOffset>():yyyy-MM-dd}",
|
|
reader.GetString().Replace(',', ' '),
|
|
reader.GetString().Replace(',', ' ')
|
|
});
|
|
|
|
csvItems.AddRange(items);
|
|
|
|
var csvLines = csvItems.Select(x => string.Join(",", x));
|
|
var csvContent = string.Join(Environment.NewLine, csvLines);
|
|
|
|
return Encoding.UTF8.GetBytes(csvContent);
|
|
}
|
|
|
|
public IEnumerable<HeliumPressurePoint> LoadHeliumPressureResults(int testId)
|
|
=> this.fluentSQL
|
|
.CreateCommand($@"
|
|
SELECT [CordonelPressureTestTestPoints_Id]
|
|
, [CordonelPressureTest_TestPointNr]
|
|
, CAST([CordonelPressureTest_TestPointResult] AS NUMERIC(9, 8))
|
|
FROM [Cordonel_PressureTest_TestPoints]
|
|
WHERE [CordonelPressureTest_Id] = @{nameof(testId)}")
|
|
.SetParameter(nameof(testId), testId)
|
|
.ExecuteReader(reader => new HeliumPressurePoint
|
|
{
|
|
TestId = reader.GetInt(),
|
|
PointNr = reader.GetInt(),
|
|
Result = reader.GetValue<decimal>(),
|
|
});
|
|
|
|
public KottmannReportModel LoadKottmannPressureReport(KottmannReportModel model = null)
|
|
{
|
|
if (model is null)
|
|
{
|
|
model = new KottmannReportModel();
|
|
}
|
|
|
|
var where = model.Filter.Where();
|
|
var orderBy = model.Filter.OrderBy();
|
|
|
|
model.Items = this.fluentSQL
|
|
.CreateCommand($@"
|
|
SELECT [DP].[FertigungsauftragNr] AS [FertigungNr]
|
|
, [PCB2SN].[MapPcbIdToSerialNumber_SerialNumber] AS [SerienNr]
|
|
, [DP].[FabNr] AS [PcbId]
|
|
, [ID].[Typ] AS [Typ]
|
|
, [ID].[Nennweite] AS [Nennweite]
|
|
, [ID].[Baulaenge] AS [Baulaenge]
|
|
, [DP].[StartDruck] AS [StartDruck]
|
|
, [DP].[EndDruck] AS [EndDruck]
|
|
, [DP].[Pruefzeit] AS [Pruefzeit]
|
|
, [DP].[Dicht] AS [Dicht]
|
|
, [DP].[Datum] AS [Datum]
|
|
, [DP].[Bemerkung] AS [Bemerkung]
|
|
FROM [Druckpruefung] AS [DP]
|
|
JOIN [AuftragPosition_Gesamt] AS [POS]
|
|
ON [POS].[FertigungsauftragNr] = [DP].[FertigungsauftragNr]
|
|
JOIN [Identnr] AS [ID]
|
|
ON [ID].[IdentNr] = [POS].[Identnr]
|
|
JOIN [MapPcbIdToSerialNumber] AS [PCB2SN]
|
|
ON [PCB2SN].[MapPcbIdToSerialNumber_PcbId] = [DP].[FabNr]
|
|
AND [PCB2SN].[MapPcbIdToSerialNumber_Deleted] = 0
|
|
AND {where.Query}
|
|
ORDER BY {orderBy.Query}")
|
|
.SetParameters(where.Parameters)
|
|
.SetParameters(orderBy.Parameters)
|
|
.ExecuteReader(reader => new KottmannReportItem
|
|
{
|
|
FertigungsNr = reader.GetValue<int?>(),
|
|
SerialNr = reader.GetInt(),
|
|
PcbId = reader.GetInt(),
|
|
Typ = reader.GetString(),
|
|
Nennweite = reader.GetValue<int?>(),
|
|
Baulaenge = reader.GetValue<int?>(),
|
|
StartDruck = reader.GetValue<double>(),
|
|
EndDruck = reader.GetValue<double>(),
|
|
DruckZeit = reader.GetInt(),
|
|
Dicht = reader.GetValue<bool>(),
|
|
Datum = reader.GetValue<DateTime>(),
|
|
Bemerkung = reader.GetValue<string>()
|
|
});
|
|
|
|
return model;
|
|
}
|
|
|
|
public byte[] LoadKottmannPressureReportAsCSV(KottmannReportModel model)
|
|
{
|
|
if (model is null)
|
|
{
|
|
model = new KottmannReportModel();
|
|
}
|
|
|
|
var where = model.Filter.Where();
|
|
var orderBy = model.Filter.OrderBy();
|
|
var csvItems = new List<object[]>
|
|
{
|
|
new object[]
|
|
{
|
|
"[FertigungNr]",
|
|
"[SerienNr]",
|
|
"[PcbId]",
|
|
"[Typ]",
|
|
"[Nennweite]",
|
|
"[Baulaenge]",
|
|
"[StartDruck]",
|
|
"[EndDruck]",
|
|
"[Pruefzeit]",
|
|
"[Dicht]",
|
|
"[Datum]",
|
|
"[Bemerkung]"
|
|
}
|
|
};
|
|
var headers = Array.Empty<string>();
|
|
var items = this.fluentSQL
|
|
.CreateCommand($@"
|
|
SELECT [DP].[FertigungsauftragNr] AS [FertigungNr]
|
|
, [PCB2SN].[MapPcbIdToSerialNumber_SerialNumber] AS [SerienNr]
|
|
, [DP].[FabNr] AS [PcbId]
|
|
, [ID].[Typ] AS [Typ]
|
|
, [ID].[Nennweite] AS [Nennweite]
|
|
, [ID].[Baulaenge] AS [Baulaenge]
|
|
, [DP].[StartDruck] AS [StartDruck]
|
|
, [DP].[EndDruck] AS [EndDruck]
|
|
, [DP].[Pruefzeit] AS [Pruefzeit]
|
|
, [DP].[Dicht] AS [Dicht]
|
|
, [DP].[Datum] AS [Datum]
|
|
, [DP].[Bemerkung] AS [Bemerkung]
|
|
FROM [Druckpruefung] AS [DP]
|
|
JOIN [AuftragPosition_Gesamt] AS [POS]
|
|
ON [POS].[FertigungsauftragNr] = [DP].[FertigungsauftragNr]
|
|
JOIN [Identnr] AS [ID]
|
|
ON [ID].[IdentNr] = [POS].[Identnr]
|
|
JOIN [MapPcbIdToSerialNumber] AS [PCB2SN]
|
|
ON [PCB2SN].[MapPcbIdToSerialNumber_PcbId] = [DP].[FabNr]
|
|
AND [PCB2SN].[MapPcbIdToSerialNumber_Deleted] = 0
|
|
AND {where.Query}
|
|
ORDER BY {orderBy.Query}")
|
|
.SetParameters(where.Parameters)
|
|
.SetParameters(orderBy.Parameters)
|
|
.ExecuteReader(reader => new object[]
|
|
{
|
|
reader.GetValue<int?>(),
|
|
reader.GetInt(),
|
|
reader.GetInt(),
|
|
reader.GetString(),
|
|
reader.GetValue<int?>(),
|
|
reader.GetValue<int?>(),
|
|
reader.GetValue<double>(),
|
|
reader.GetValue<double>(),
|
|
reader.GetInt(),
|
|
reader.GetValue<bool>(),
|
|
$"{reader.GetValue<DateTime>():yyyy-MM-dd}",
|
|
reader.GetValue<string>().Replace(',', ' ')
|
|
});
|
|
|
|
csvItems.AddRange(items);
|
|
|
|
var csvLines = csvItems.Select(x => string.Join(",", x));
|
|
var csvContent = string.Join(Environment.NewLine, csvLines);
|
|
|
|
return Encoding.UTF8.GetBytes(csvContent);
|
|
}
|
|
}
|
|
}
|