forked from ddrilling/AsbCloudServer
CS2-1: Добавлена возможность получения диапазона дат сообщений
This commit is contained in:
parent
f21c75d450
commit
dd9c985e65
@ -7,6 +7,7 @@ namespace AsbCloudApp.Services
|
|||||||
public interface IMessageService
|
public interface IMessageService
|
||||||
{
|
{
|
||||||
PaginationContainer<MessageDto> GetMessages(int wellId, IEnumerable<int> categoryids = null, DateTime begin = default, DateTime end = default, int skip = 0, int take = 32);
|
PaginationContainer<MessageDto> GetMessages(int wellId, IEnumerable<int> categoryids = null, DateTime begin = default, DateTime end = default, int skip = 0, int take = 32);
|
||||||
|
IDictionary<string, DateTime> GetMessagesDatesRange(int wellId);
|
||||||
void Insert(string uid, IEnumerable<TelemetryMessageDto> dtos);
|
void Insert(string uid, IEnumerable<TelemetryMessageDto> dtos);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -31,6 +31,23 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
cacheWells = cacheDb.GetCachedTable<Well>((AsbCloudDbContext)db);
|
cacheWells = cacheDb.GetCachedTable<Well>((AsbCloudDbContext)db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IEnumerable<Message> GetMessagesByWell(int wellId)
|
||||||
|
{
|
||||||
|
var well = cacheWells.FirstOrDefault(w => w.Id == wellId);
|
||||||
|
if (well is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var telemetry = cacheTelemetry.FirstOrDefault(t => t.Id == well.Id);
|
||||||
|
if (telemetry is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var messages = from m in db.Messages
|
||||||
|
where m.IdTelemetry == telemetry.Id
|
||||||
|
select m;
|
||||||
|
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
|
|
||||||
public PaginationContainer<MessageDto> GetMessages(int wellId, IEnumerable<int> categoryids = default, DateTime begin = default, DateTime end = default, int skip = 0, int take = 32)
|
public PaginationContainer<MessageDto> GetMessages(int wellId, IEnumerable<int> categoryids = default, DateTime begin = default, DateTime end = default, int skip = 0, int take = 32)
|
||||||
{
|
{
|
||||||
var well = cacheWells.FirstOrDefault(w => w.Id == wellId);
|
var well = cacheWells.FirstOrDefault(w => w.Id == wellId);
|
||||||
@ -106,6 +123,21 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IDictionary<string, DateTime> GetMessagesDatesRange(int wellId)
|
||||||
|
{
|
||||||
|
IEnumerable<Message> wellMessages = GetMessagesByWell(wellId) ?? new List<Message>();
|
||||||
|
|
||||||
|
IEnumerable<DateTime> wellMessagesDates = wellMessages.Select(wm => wm.Date);
|
||||||
|
|
||||||
|
IDictionary<string, DateTime> messagesDatesRange = new Dictionary<string, DateTime>();
|
||||||
|
|
||||||
|
messagesDatesRange.Add("From", wellMessagesDates.Any() ? wellMessagesDates.Min() : DateTime.MinValue);
|
||||||
|
|
||||||
|
messagesDatesRange.Add("To", wellMessagesDates.Any() ? wellMessagesDates.Max() : DateTime.MaxValue);
|
||||||
|
|
||||||
|
return messagesDatesRange;
|
||||||
|
}
|
||||||
|
|
||||||
public void Insert(string uid, IEnumerable<TelemetryMessageDto> dtos)
|
public void Insert(string uid, IEnumerable<TelemetryMessageDto> dtos)
|
||||||
{
|
{
|
||||||
if (dtos.Count() == 0)
|
if (dtos.Count() == 0)
|
||||||
|
@ -41,5 +41,15 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
var result = messageService.GetMessages(wellId, categoryids, begin, end, skip, take);
|
var result = messageService.GetMessages(wellId, categoryids, begin, end, skip, take);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Route("{wellId}/messagesDatesRange")]
|
||||||
|
[ProducesResponseType(typeof(IDictionary<string, DateTime>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public IActionResult GetMessagesDateRange(int wellId)
|
||||||
|
{
|
||||||
|
IDictionary<string, DateTime> wellMessagesDatesRange = messageService.GetMessagesDatesRange(wellId);
|
||||||
|
|
||||||
|
return Ok(wellMessagesDatesRange);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user