forked from ddrilling/AsbCloudServer
WellOperationRepository TrimOverlapping()
This commit is contained in:
parent
df8ddf3122
commit
44bb602350
@ -67,6 +67,23 @@ namespace AsbCloudDb.Model
|
||||
[JsonIgnore]
|
||||
[ForeignKey(nameof(IdPlan))]
|
||||
public virtual WellOperation? OperationPlan { get; set; } = null!;
|
||||
|
||||
public bool IsSame(WellOperation other)
|
||||
{
|
||||
var isSame = IdWell == other.IdWell &&
|
||||
IdWellSectionType == other.IdWellSectionType &&
|
||||
IdCategory == other.IdCategory &&
|
||||
IdType == other.IdType &&
|
||||
IdPlan == other.IdPlan &&
|
||||
DepthStart == other.DepthStart &&
|
||||
DepthEnd == other.DepthEnd &&
|
||||
DateStart == other.DateStart &&
|
||||
DurationHours == other.DurationHours &&
|
||||
CategoryInfo == other.CategoryInfo &&
|
||||
Comment == other.Comment;
|
||||
|
||||
return isSame;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb;
|
||||
using AsbCloudDb.Model;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using Irony.Parsing;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
@ -530,4 +532,60 @@ public class WellOperationRepository : IWellOperationRepository
|
||||
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public async Task RemoveDuplicates(CancellationToken token)
|
||||
{
|
||||
var dbset = db.Set<WellOperation>();
|
||||
var groups = await dbset
|
||||
.GroupBy(o => new { o.IdWell, o.IdType })
|
||||
.ToArrayAsync(token);
|
||||
|
||||
foreach (var group in groups)
|
||||
await RemoveDuplicatesInGroup(group.Key.IdWell, group.Key.IdType, token);
|
||||
}
|
||||
|
||||
private async Task RemoveDuplicatesInGroup(int idWell, int idType, CancellationToken token)
|
||||
{
|
||||
var dbset = db.Set<WellOperation>();
|
||||
var operationsEnumerator = dbset
|
||||
.Where(o => o.IdWell == idWell && o.IdType == idType)
|
||||
.OrderBy(o => o.DateStart)
|
||||
.GetEnumerator();
|
||||
|
||||
if (!operationsEnumerator.MoveNext())
|
||||
return;
|
||||
|
||||
var preOperation = operationsEnumerator.Current;
|
||||
while (operationsEnumerator.MoveNext())
|
||||
{
|
||||
var operation = operationsEnumerator.Current;
|
||||
if (preOperation.IsSame(operation))
|
||||
dbset.Remove(operation);
|
||||
else
|
||||
preOperation = operation;
|
||||
}
|
||||
await db.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
public async Task TrimOverlapping(DateTimeOffset leDate, CancellationToken token)
|
||||
{
|
||||
var leDateUtc = leDate.ToUniversalTime();
|
||||
var dbset = db.Set<WellOperation>();
|
||||
var groups = await dbset
|
||||
.GroupBy(o => new { o.IdWell, o.IdType })
|
||||
.Select(g => new{
|
||||
MaxDate = g.Max(o => o.DateStart),
|
||||
g.Key.IdWell,
|
||||
g.Key.IdType,
|
||||
})
|
||||
.ToArrayAsync(token);
|
||||
|
||||
foreach (var group in groups)
|
||||
await TrimOverlapping(group.IdWell, group.IdType, token);
|
||||
}
|
||||
|
||||
private Task TrimOverlapping(int idWell, int idType, CancellationToken token)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user