From 5961260ccd21891b358e2fdef01dcce9a863fb7e Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Mon, 17 Apr 2023 11:31:27 +0500 Subject: [PATCH 1/2] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=B1=D0=B0?= =?UTF-8?q?=D0=B3=D0=B0=20=D0=BF=D1=80=D0=B8=20=D1=84=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B8=20=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D1=85=20(=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20Ge?= =?UTF-8?q?tGroupOperationsStatAsync=20=D0=B2=20WellOperationRepository)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository/WellOperationRepository.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index 2c8944a4..d4cff5da 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -227,7 +227,7 @@ namespace AsbCloudInfrastructure.Repository IdParent = parentRelationDictionary[g.Key].IdParent }); var defaultId = 0; - while (dtos.Any(x => x.IdParent != null)) + while (dtos.Any(x => x.IdParent == null)) { defaultId--; dtos = dtos @@ -235,12 +235,16 @@ namespace AsbCloudInfrastructure.Repository .Select(g => new WellGroupOpertionDto { IdCategory = g.Key ?? defaultId, - Category = g.Key.HasValue ? parentRelationDictionary[g.Key.Value].Name : "unknown", + Category = g.Key.HasValue + ? parentRelationDictionary.GetValueOrDefault(g.Key.Value)?.Name ?? "unknown" + : "unknown", Count = g.Sum(o => o.Count), DeltaDepth = g.Sum(o => o.DeltaDepth), TotalMinutes = g.Sum(o => o.TotalMinutes), Items = g.ToList(), - IdParent = g.Key.HasValue ? parentRelationDictionary[g.Key.Value].IdParent : defaultId, + IdParent = g.Key.HasValue + ? parentRelationDictionary.GetValueOrDefault(g.Key.Value)?.IdParent ?? defaultId + : defaultId, }); } return dtos; From 94a152388f77dd08f6d78114835151f2fd1e23f9 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Mon, 17 Apr 2023 11:59:16 +0500 Subject: [PATCH 2/2] fix WellOperationRepository.GetGroupOperationsStatAsync() --- .../Repository/WellOperationRepository.cs | 34 +++++++++---------- AsbCloudWebApi/Rest/WellOperation.http | 12 +++++++ 2 files changed, 29 insertions(+), 17 deletions(-) create mode 100644 AsbCloudWebApi/Rest/WellOperation.http diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index d4cff5da..69740a37 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -226,25 +226,25 @@ namespace AsbCloudInfrastructure.Repository DeltaDepth = g.Sum(o => o.DurationDepth), IdParent = parentRelationDictionary[g.Key].IdParent }); - var defaultId = 0; - while (dtos.Any(x => x.IdParent == null)) + + while (dtos.All(x => x.IdParent != null)) { - defaultId--; dtos = dtos - .GroupBy(o => o.IdParent) - .Select(g => new WellGroupOpertionDto - { - IdCategory = g.Key ?? defaultId, - Category = g.Key.HasValue - ? parentRelationDictionary.GetValueOrDefault(g.Key.Value)?.Name ?? "unknown" - : "unknown", - Count = g.Sum(o => o.Count), - DeltaDepth = g.Sum(o => o.DeltaDepth), - TotalMinutes = g.Sum(o => o.TotalMinutes), - Items = g.ToList(), - IdParent = g.Key.HasValue - ? parentRelationDictionary.GetValueOrDefault(g.Key.Value)?.IdParent ?? defaultId - : defaultId, + .GroupBy(o => o.IdParent!) + .Select(g => { + var idCategory = g.Key ?? int.MinValue; + var category = parentRelationDictionary.GetValueOrDefault(idCategory); + var newDto = new WellGroupOpertionDto + { + IdCategory = idCategory, + Category = category?.Name ?? "unknown", + Count = g.Sum(o => o.Count), + DeltaDepth = g.Sum(o => o.DeltaDepth), + TotalMinutes = g.Sum(o => o.TotalMinutes), + Items = g.ToList(), + IdParent = category?.IdParent, + }; + return newDto; }); } return dtos; diff --git a/AsbCloudWebApi/Rest/WellOperation.http b/AsbCloudWebApi/Rest/WellOperation.http new file mode 100644 index 00000000..37dd8e2c --- /dev/null +++ b/AsbCloudWebApi/Rest/WellOperation.http @@ -0,0 +1,12 @@ +@baseUrl = http://127.0.0.1:5000 +@contentType = application/json +@auth = Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImN0eSI6IkpXVCJ9.eyJpZCI6IjEiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiZGV2IiwiaWRDb21wYW55IjoiMSIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6InJvb3QiLCJuYmYiOjE2NjI1NDgxNjIsImV4cCI6MTY5NDEwNTc2MiwiaXNzIjoiYSIsImF1ZCI6ImEifQ.OEAlNzxi7Jat6pzDBTAjTbChskc-tdJthJexyWwwUKE + +@wellId = 1 + +### +GET {{baseUrl}}/api/well/{{wellId}}/wellOperations/groupStat +Content-Type: {{contentType}} +accept: */* +Authorization: {{auth}} +