2022-04-19 12:14:03 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2022-04-26 16:45:52 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
2022-04-19 12:14:03 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/well/{idWell}/[controller]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class DailyReportController : ControllerBase
|
|
|
|
|
{
|
2022-04-26 16:45:52 +05:00
|
|
|
|
private readonly IDailyReportService dailyReportService;
|
2022-05-05 10:06:15 +05:00
|
|
|
|
private readonly IWellService wellService;
|
2022-04-26 16:45:52 +05:00
|
|
|
|
|
2022-05-05 10:06:15 +05:00
|
|
|
|
public DailyReportController(IDailyReportService dailyReportService, IWellService wellService)
|
2022-04-26 16:45:52 +05:00
|
|
|
|
{
|
|
|
|
|
this.dailyReportService = dailyReportService;
|
2022-05-05 10:06:15 +05:00
|
|
|
|
this.wellService = wellService;
|
2022-04-26 16:45:52 +05:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 12:14:03 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Список наборов данных для формирования рапорта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="begin"></param>
|
|
|
|
|
/// <param name="end"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
//[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<DailyReportDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetListAsync(int idWell, DateTime? begin = null, DateTime? end = null, CancellationToken token = default)
|
|
|
|
|
{
|
2022-04-26 16:45:52 +05:00
|
|
|
|
var result = await dailyReportService.GetListAsync(idWell, begin, end, token);
|
2022-04-19 12:14:03 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// новый набор данных для формирования рапорта (на новую дату). Если в архиве на эту дату уже есть данные то вернуться они.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="date"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("{date}")]
|
|
|
|
|
//[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(DailyReportDto), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetOrGenerateAsync(int idWell, [Required] DateTime date, CancellationToken token = default)
|
|
|
|
|
{
|
2022-04-26 16:45:52 +05:00
|
|
|
|
var dto = await dailyReportService.GetOrGenerateAsync(idWell, date, token);
|
2022-04-19 12:14:03 +05:00
|
|
|
|
return Ok(dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранение нового набора данных для формирования рапорта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="dto"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
//[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
2022-04-29 15:39:12 +05:00
|
|
|
|
public async Task<IActionResult> AddAsync(int idWell, [Required][FromBody] DailyReportDto dto, CancellationToken token = default)
|
2022-04-19 12:14:03 +05:00
|
|
|
|
{
|
2022-04-26 16:45:52 +05:00
|
|
|
|
var result = await dailyReportService.AddAsync(idWell, dto, token);
|
|
|
|
|
return Ok(result);
|
2022-04-19 12:14:03 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранение изменений набора данных для формирования рапорта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="date"></param>
|
|
|
|
|
/// <param name="dto"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPut("{date}")]
|
|
|
|
|
//[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> UpdateAsync(int idWell, [Required] DateTime date, [Required] DailyReportDto dto, CancellationToken token = default)
|
|
|
|
|
{
|
2022-04-26 16:45:52 +05:00
|
|
|
|
var result = await dailyReportService.UpdateAsync(idWell, date, dto, token);
|
|
|
|
|
return Ok(result);
|
2022-04-19 12:14:03 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сформировать и скачать рапорт в формате excel
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("{date}/excel")]
|
|
|
|
|
//[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
|
2022-04-26 16:45:52 +05:00
|
|
|
|
public async Task<IActionResult> DownloadAsync(int idWell, DateTime date, CancellationToken token = default)
|
2022-04-19 12:14:03 +05:00
|
|
|
|
{
|
2022-05-05 15:14:29 +05:00
|
|
|
|
var well = await wellService.GetAsync(idWell, token);
|
2022-04-29 15:39:12 +05:00
|
|
|
|
var stream = await dailyReportService.MakeReportAsync(idWell, date, token);
|
|
|
|
|
if (stream != null)
|
|
|
|
|
{
|
2022-05-05 15:14:29 +05:00
|
|
|
|
|
|
|
|
|
var fileName = $"Суточный рапорт по скважине {well.Caption} куст {well.Cluster}.xlsx";
|
2022-04-29 15:39:12 +05:00
|
|
|
|
return File(stream, "application/octet-stream", fileName);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return NoContent();
|
2022-04-19 12:14:03 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|