using AsbCloudApp.Data;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers
{
[Route("api/well/{idWell}/[controller]")]
[ApiController]
[Authorize]
public class DailyReportController : ControllerBase
{
///
/// Список наборов данных для формирования рапорта
///
///
///
///
///
///
[HttpGet]
//[Permission]
[ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)]
public async Task GetListAsync(int idWell, DateTime? begin = null, DateTime? end = null, CancellationToken token = default)
{
await Task.Delay(1);
var dto = new DailyReportDto
{
};
var result = new List { dto };
return Ok(result);
}
///
/// новый набор данных для формирования рапорта (на новую дату). Если в архиве на эту дату уже есть данные то вернуться они.
///
///
///
///
///
[HttpGet("{date}")]
//[Permission]
[ProducesResponseType(typeof(DailyReportDto), (int)System.Net.HttpStatusCode.OK)]
public async Task GetOrGenerateAsync(int idWell, [Required] DateTime date, CancellationToken token = default)
{
await Task.Delay(1);
var dto = new DailyReportDto
{
ReportDate = date,
};
return Ok(dto);
}
///
/// Сохранение нового набора данных для формирования рапорта
///
///
///
///
///
[HttpPost]
//[Permission]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task AddAsync(int idWell, [Required] DailyReportDto dto, CancellationToken token = default)
{
await Task.Delay(1);
return Ok(1);
}
///
/// Сохранение изменений набора данных для формирования рапорта
///
///
///
///
///
///
[HttpPut("{date}")]
//[Permission]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task UpdateAsync(int idWell, [Required] DateTime date, [Required] DailyReportDto dto, CancellationToken token = default)
{
await Task.Delay(1);
return Ok(1);
}
///
/// Сформировать и скачать рапорт в формате excel
///
///
///
///
[HttpGet("{date}/excel")]
//[Permission]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
public async Task DownloadAsync(int idWell, CancellationToken token = default)
{
await Task.Delay(1);
var stream = GetExcelTemplateStream();
var fileName = "CP.xlsx";
return File(stream, "application/octet-stream", fileName);
}
private static Stream GetExcelTemplateStream()
{
var assembly = System.Reflection.Assembly.GetAssembly(typeof(AsbCloudInfrastructure.IInfrastructureMarker));
var stream = assembly.GetManifestResourceStream("AsbCloudInfrastructure.Services.DailyReport.DailyReportTemplate.xlsx");
return stream;
}
}
}