更新122
This commit is contained in:
@@ -23,12 +23,31 @@ namespace TabletTester2025.Services
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
public void InsertBatch(TestBatch batch, IEnumerable<DissolutionSamplePoint> dissolutionSamples)
|
||||
public void InsertBatch(
|
||||
TestBatch batch,
|
||||
IEnumerable<DissolutionSamplePoint> dissolutionSamples,
|
||||
IEnumerable<HardnessSamplePoint>? hardnessSamples = null)
|
||||
{
|
||||
using var db = new AppDbContext(_connectionString);
|
||||
db.TestBatches.Add(batch);
|
||||
db.SaveChanges();
|
||||
|
||||
var hardnessDetails = (hardnessSamples ?? Enumerable.Empty<HardnessSamplePoint>())
|
||||
.Where(s => double.IsFinite(s.Value) && s.Value > 0)
|
||||
.OrderBy(s => s.SequenceNo)
|
||||
.Select(s => new HardnessSamplePoint
|
||||
{
|
||||
TestBatchId = batch.Id,
|
||||
SequenceNo = s.SequenceNo,
|
||||
Value = s.Value,
|
||||
DeviationFromAverage = s.DeviationFromAverage,
|
||||
RecordedAt = s.RecordedAt
|
||||
})
|
||||
.ToList();
|
||||
|
||||
if (hardnessDetails.Count > 0)
|
||||
db.HardnessSamplePoints.AddRange(hardnessDetails);
|
||||
|
||||
var samples = dissolutionSamples
|
||||
.Where(s => s.Percent.HasValue)
|
||||
.Select(s => new DissolutionSamplePoint
|
||||
@@ -42,18 +61,24 @@ namespace TabletTester2025.Services
|
||||
})
|
||||
.ToList();
|
||||
|
||||
if (samples.Count == 0)
|
||||
if (samples.Count > 0)
|
||||
db.DissolutionSamplePoints.AddRange(samples);
|
||||
|
||||
if (hardnessDetails.Count == 0 && samples.Count == 0)
|
||||
return;
|
||||
|
||||
db.DissolutionSamplePoints.AddRange(samples);
|
||||
db.SaveChanges();
|
||||
batch.HardnessSamples = hardnessDetails;
|
||||
batch.DissolutionSamples = samples;
|
||||
}
|
||||
|
||||
public List<TestBatch> GetBatches(int? stationId = null, int limit = 100)
|
||||
{
|
||||
using var db = new AppDbContext(_connectionString);
|
||||
var query = db.TestBatches.Include(b => b.DissolutionSamples).AsQueryable();
|
||||
var query = db.TestBatches
|
||||
.Include(b => b.HardnessSamples)
|
||||
.Include(b => b.DissolutionSamples)
|
||||
.AsQueryable();
|
||||
if (stationId.HasValue)
|
||||
query = query.Where(b => b.StationId == stationId.Value);
|
||||
query = query.OrderByDescending(b => b.TestTime).Take(limit);
|
||||
|
||||
Reference in New Issue
Block a user