CS2-30 Создать контроллер куста и контроллер месторождения

This commit is contained in:
Фролов 2021-07-19 15:11:01 +05:00
parent 9b7dfe1d7e
commit f30cafcb1e
13 changed files with 327 additions and 4 deletions

View File

@ -0,0 +1,7 @@
namespace AsbCloudApp.Data
{
public class ClusterAnalysisDto
{
public int Id { get; set; }
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AsbCloudApp.Data
{
public class ClusterDto: IMapPoint
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
//public IEnumerable<WellDto> Wells { get; set; }
}
}

View File

@ -0,0 +1,13 @@
namespace AsbCloudApp.Data
{
public class DepositDto: IMapPoint
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
//public IEnumerable<ClusterDto> Clusters { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AsbCloudApp.Data
{
public interface IMapPoint
{
double Latitude { get; set; }
double Longitude { get; set; }
}
}

View File

@ -1,8 +1,11 @@
namespace AsbCloudApp.Data namespace AsbCloudApp.Data
{ {
public class WellDto : WellInfoDto
public class WellDto : WellInfoDto, IMapPoint
{ {
public int Id { get; set; } public int Id { get; set; }
public object LastData { get; set; }//DataSaubBaseDto public object LastData { get; set; }//DataSaubBaseDto
public double Latitude { get; set; }
public double Longitude { get; set; }
} }
} }

View File

@ -0,0 +1,17 @@
using AsbCloudApp.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AsbCloudApp.Services
{
public interface IClusterService
{
IEnumerable<DepositDto> GetDeposits(int idCustomer);
IEnumerable<ClusterDto> GetClusters(int idCustomer, int depositId);
IEnumerable<WellDto> GetWells(int idCustomer, int clusterId);
IEnumerable<ClusterAnalysisDto> GetAnalysis(int idCustomer, int clusterId);
}
}

View File

@ -8,7 +8,7 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace AsbCloudDb.Model namespace AsbCloudDb.Model
{ {
[Table("t_cluster"), Comment("Кусты")] [Table("t_cluster"), Comment("Кусты")]
public partial class Cluster : IId public partial class Cluster : IId, IMapPoint
{ {
public Cluster() public Cluster()
{ {
@ -18,16 +18,25 @@ namespace AsbCloudDb.Model
[Key] [Key]
[Column("id")] [Column("id")]
public int Id { get; set; } public int Id { get; set; }
[Column("caption"), Comment("Название")] [Column("caption"), Comment("Название")]
[StringLength(255)] [StringLength(255)]
public string Caption { get; set; } public string Caption { get; set; }
[Column("id_deposit")] [Column("id_deposit")]
public int? IdDeposit { get; set; } public int? IdDeposit { get; set; }
[ForeignKey(nameof(IdDeposit))] [ForeignKey(nameof(IdDeposit))]
[InverseProperty(nameof(Model.Deposit.Clusters))] [InverseProperty(nameof(Model.Deposit.Clusters))]
public virtual Deposit Deposit { get; set; } public virtual Deposit Deposit { get; set; }
[InverseProperty(nameof(Well.Cluster))] [InverseProperty(nameof(Well.Cluster))]
public virtual ICollection<Well> Wells { get; set; } public virtual ICollection<Well> Wells { get; set; }
[Column("latitude")]
public double Latitude { get; set; }
[Column("longitude")]
public double Longitude { get; set; }
} }
} }

View File

@ -8,7 +8,7 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace AsbCloudDb.Model namespace AsbCloudDb.Model
{ {
[Table("t_deposit"), Comment("Месторождение")] [Table("t_deposit"), Comment("Месторождение")]
public partial class Deposit : IId public partial class Deposit : IId, IMapPoint
{ {
public Deposit() public Deposit()
{ {
@ -18,11 +18,18 @@ namespace AsbCloudDb.Model
[Key] [Key]
[Column("id")] [Column("id")]
public int Id { get; set; } public int Id { get; set; }
[Column("caption")] [Column("caption")]
[StringLength(255)] [StringLength(255)]
public string Caption { get; set; } public string Caption { get; set; }
[InverseProperty(nameof(Cluster.Deposit))] [InverseProperty(nameof(Cluster.Deposit))]
public virtual ICollection<Cluster> Clusters { get; set; } public virtual ICollection<Cluster> Clusters { get; set; }
[Column("latitude")]
public double Latitude { get; set; }
[Column("longitude")]
public double Longitude { get; set; }
} }
} }

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AsbCloudDb.Model
{
public interface IMapPoint
{
double Latitude { get; set; }
double Longitude { get; set; }
}
}

View File

@ -7,7 +7,7 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace AsbCloudDb.Model namespace AsbCloudDb.Model
{ {
[Table("t_well"), Comment("скважины")] [Table("t_well"), Comment("скважины")]
public partial class Well : IId public partial class Well : IId, IMapPoint
{ {
[Key] [Key]
[Column("id")] [Column("id")]
@ -37,5 +37,11 @@ namespace AsbCloudDb.Model
[ForeignKey(nameof(IdTelemetry))] [ForeignKey(nameof(IdTelemetry))]
[InverseProperty(nameof(Model.Telemetry.Well))] [InverseProperty(nameof(Model.Telemetry.Well))]
public virtual Telemetry Telemetry { get; set; } public virtual Telemetry Telemetry { get; set; }
[Column("latitude")]
public double Latitude { get; set; }
[Column("longitude")]
public double Longitude { get; set; }
} }
} }

View File

@ -0,0 +1,84 @@
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.Cache;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services
{
public class СlusterService : IClusterService
{
private readonly IAsbCloudDbContext db;
public СlusterService(IAsbCloudDbContext db)
{
this.db = db;
}
public IEnumerable<DepositDto> GetDeposits(int idCustomer)
{
var entities = db.GetWellsByCustomer(idCustomer)
.Select(e=>e.Cluster.Deposit)
.Distinct()
.ToList();
var dtos = entities.Select(e => new DepositDto
{
Id = e.Id,
Name = e.Caption,
Latitude = e.Latitude,
Longitude = e.Longitude,
});
return dtos;
}
public IEnumerable<ClusterDto> GetClusters(int idCustomer, int depositId)
{
var entities = db.GetWellsByCustomer(idCustomer)
.Select(e => e.Cluster)
.Where(e=>e.IdDeposit == depositId)
.Distinct()
.ToList();
var dtos = entities.Select(e => new ClusterDto
{
Id = e.Id,
Name = e.Caption,
Latitude = e.Latitude,
Longitude = e.Longitude,
});
return dtos;
}
public IEnumerable<WellDto> GetWells(int idCustomer, int clusterId)
{
var entities = db.GetWellsByCustomer(idCustomer)
.Where(e => e.IdCluster == clusterId)
.ToList();
var dtos = entities.Select(e => new WellDto
{
Id = e.Id,
Caption = e.Caption,
Latitude = e.Latitude,
Longitude = e.Longitude,
Cluster = e.Cluster.Caption,
Deposit = e.Cluster.Deposit.Caption,
});
return dtos;
}
public IEnumerable<ClusterAnalysisDto> GetAnalysis(int idCustomer, int clusterId)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,64 @@
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers
{
/// <summary>
/// Контроллер кустов
/// </summary>
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class ClusterController : ControllerBase
{
private readonly IClusterService clusterService;
public ClusterController(IClusterService clusterService)
{
this.clusterService = clusterService;
}
/// <summary>
/// Получение доступных пользователю скважин
/// </summary>
/// <param name="clusterId"></param>
/// <returns></returns>
[HttpGet("{clusterId}")]
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetWells(int clusterId)
{
int? idCustomer = User.GetCustomerId();
if (idCustomer is null)
return Forbid();
var result = clusterService.GetWells((int)idCustomer, clusterId);
return Ok(result);
}
/// <summary>
/// Получение обопщенной аналитики по кусту (лучшая/худшая скважина)
/// </summary>
/// <param name="clusterId"></param>
/// <returns></returns>
[HttpGet("{clusterId}")]
[ProducesResponseType(typeof(IEnumerable<ClusterAnalysisDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetAnalysis(int clusterId)
{
int? idCustomer = User.GetCustomerId();
if (idCustomer is null)
return Forbid();
var result = clusterService.GetAnalysis((int)idCustomer, clusterId);
return Ok(result);
}
}
}

View File

@ -0,0 +1,64 @@
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers
{
/// <summary>
/// Контроллер для месторождений
/// </summary>
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class DepositController : ControllerBase
{
IClusterService clusterService;
public DepositController(IClusterService clusterService)
{
this.clusterService = clusterService;
}
/// <summary>
/// Получает список доступных пользователю месторождений
/// </summary>
/// <returns></returns>
[HttpGet]
[ProducesResponseType(typeof(IEnumerable<DepositDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetDeposits()
{
int? idCustomer = User.GetCustomerId();
if (idCustomer is null)
return Forbid();
var result = clusterService.GetDeposits((int)idCustomer);
return Ok(result);
}
/// <summary>
/// Получает список доступных пользователю кустов месторождения
/// </summary>
/// <param name="depositId"></param>
/// <returns></returns>
[HttpGet("{depositId}")]
[ProducesResponseType(typeof(IEnumerable<ClusterDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetClusters(int depositId)
{
int? idCustomer = User.GetCustomerId();
if (idCustomer is null)
return Forbid();
var result = clusterService.GetClusters((int)idCustomer, depositId);
return Ok(result);
}
}
}