fix WellService controller

This commit is contained in:
Фролов 2021-07-21 17:23:57 +05:00
parent e447473a71
commit 9c5c1fc9c5
8 changed files with 42 additions and 18 deletions

View File

@ -3,7 +3,7 @@
public class ClusterDto : IMapPoint
{
public int Id { get; set; }
public string Name { get; set; }
public string Caption { get; set; }
public string Description { get; set; }
public double? Latitude { get; set; }
public double? Longitude { get; set; }

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AsbCloudApp.Data
{
public class ClusterStatDto: ClusterDto
{
public IEnumerable<WellStatDto> WellsStat { get; set; }
}
}

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace AsbCloudApp.Data
{
public class WellDrillingStatDto : WellDto
public class WellStatDto : WellDto
{
public DateTime? PlanStart { get; set; }
public DateTime? PlanEnd { get; set; }

View File

@ -9,6 +9,6 @@ namespace AsbCloudApp.Services
IEnumerable<ClusterDto> GetClusters(int idCompany, int depositId);
IEnumerable<ClusterDto> GetClusters(int idCompany);
IEnumerable<WellDto> GetWells(int idCompany, int clusterId);
IEnumerable<WellDrillingStatDto> GetStat(int idCompany, int clusterId);
ClusterStatDto GetStat(int idCompany, int clusterId);
}
}

View File

@ -12,13 +12,13 @@ namespace AsbCloudInfrastructure.Services
{
private readonly IAsbCloudDbContext db;
private readonly ITelemetryTracker telemetryTracker;
private readonly CacheTable<Well> cacheWells;
private readonly CacheTable<RelationCompanyWell> cacheRelationCompaniesWells;
public WellService(IAsbCloudDbContext db, ITelemetryTracker telemetryTracker, CacheDb cacheDb)
{
this.db = db;
this.telemetryTracker = telemetryTracker;
cacheWells = cacheDb.GetCachedTable<Well>((AsbCloudDbContext)db);
cacheRelationCompaniesWells = cacheDb.GetCachedTable<RelationCompanyWell>((AsbCloudDbContext)db);
}
public IEnumerable<WellDto> GetTransmittingWells(int idCompany)
@ -40,10 +40,9 @@ namespace AsbCloudInfrastructure.Services
return wells.Select(w => From(w));
}
public bool CheckWellOwnership(int idCompany, int wellId)
=> cacheWells.Contains(w => w.Id == wellId && w.RelationCompaniesWells.Any(r => r.IdCompany == idCompany));
public bool CheckWellOwnership(int idCompany, int idWell)
=> cacheRelationCompaniesWells.Contains(r => r.IdWell == idWell && r.IdCompany == idCompany);
private static WellDto From(Well well)
{
var wellDto = new WellDto

View File

@ -44,7 +44,7 @@ namespace AsbCloudInfrastructure.Services
var dtos = entities.Select(e => new ClusterDto
{
Id = e.Id,
Name = e.Caption,
Caption = e.Caption,
Latitude = e.Latitude,
Longitude = e.Longitude,
});
@ -63,7 +63,7 @@ namespace AsbCloudInfrastructure.Services
var dtos = entities.Select(e => new ClusterDto
{
Id = e.Id,
Name = e.Caption,
Caption = e.Caption,
Latitude = e.Latitude,
Longitude = e.Longitude,
});
@ -90,13 +90,13 @@ namespace AsbCloudInfrastructure.Services
return dtos;
}
public IEnumerable<WellDrillingStatDto> GetStat(int idCompany, int idCluster)
public ClusterStatDto GetStat(int idCompany, int idCluster)
{
var entities = from w in db.Wells
var wellEntities = from w in db.Wells
where w.IdCluster == idCluster && w.RelationCompaniesWells.Any(c => c.IdCompany == idCompany)
select w;
var dtos = entities.Select(e => new WellDrillingStatDto
var wellStatDtos = wellEntities.Select(e => new WellStatDto
{
Id = e.Id,
Caption = e.Caption,
@ -139,9 +139,21 @@ namespace AsbCloudInfrastructure.Services
CompanyType = c.Company.CompanyType.Caption,
}),
WellType = e.WellType.Caption,
});
}).ToList();
return dtos;
if (!wellStatDtos.Any())
return null;
var clusterById = db.Clusters.FirstOrDefault(c => c.Id == idCluster);
return new ClusterStatDto {
Id = clusterById.Id,
Description = "",
Caption = clusterById.Caption,
Latitude = clusterById.Latitude,
Longitude = clusterById.Longitude,
WellsStat = wellStatDtos,
};
}
}
}

View File

@ -62,7 +62,7 @@ namespace AsbCloudWebApi.Controllers
/// <param name="idCluster"></param>
/// <returns></returns>
[HttpGet("{idCluster}/Stat")]
[ProducesResponseType(typeof(IEnumerable<WellDrillingStatDto>), (int)System.Net.HttpStatusCode.OK)]
[ProducesResponseType(typeof(IEnumerable<WellStatDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetStat(int idCluster)
{
int? idCompany = User.GetCompanyId();

View File

@ -14,7 +14,7 @@ namespace AsbCloudWebApi.Controllers
[Authorize]
public class DepositController : ControllerBase
{
IClusterService clusterService;
private readonly IClusterService clusterService;
public DepositController(IClusterService clusterService)
{