From 6eb89d4e6921b45d1e31fbedd5b59d5f6750773e Mon Sep 17 00:00:00 2001 From: Felix Morales Date: Fri, 1 Sep 2023 17:40:19 -0500 Subject: [PATCH] feature/creacion del reporte semanal de newell --- .../ICorresponsaliasTraficosRepository.cs | 2 + .../Corresponsalias/TraficosController.cs | 9 +++ Controllers/FileManagerController.cs | 64 ++++++++++--------- DTO/Reportes/DTOReporteSemanalNewel.cs | 10 +++ .../CorresponsaliasTraficosRepository.cs | 13 ++++ 5 files changed, 69 insertions(+), 29 deletions(-) create mode 100644 DTO/Reportes/DTOReporteSemanalNewel.cs diff --git a/Contracts/Corresponsalias/ICorresponsaliasTraficosRepository.cs b/Contracts/Corresponsalias/ICorresponsaliasTraficosRepository.cs index e788009..8702a40 100644 --- a/Contracts/Corresponsalias/ICorresponsaliasTraficosRepository.cs +++ b/Contracts/Corresponsalias/ICorresponsaliasTraficosRepository.cs @@ -2,12 +2,14 @@ using CORRESPONSALBackend.Models; using CORRESPONSALBackend.DTO.Corresponsales; using CORRESPONSALBackend.Models.Corresponsales; using CORRESPONSALBackend.Repository.Corresponsalias; +using CORRESPONSALBackend.DTO.Reportes; namespace CORRESPONSALBackend.Contracts.Corresponsalias { public interface ICorresponsaliasTraficosRepository { public Task Get(int id); + public Task GetByPedimento(int pedimento); public Task GetAll(int Mode); public Task> GetRectificaciones(int id); public Task AddRectificacion(int id); diff --git a/Controllers/Corresponsalias/TraficosController.cs b/Controllers/Corresponsalias/TraficosController.cs index 65c348f..9349c2f 100644 --- a/Controllers/Corresponsalias/TraficosController.cs +++ b/Controllers/Corresponsalias/TraficosController.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using CORRESPONSALBackend.Services.C1896; using CORRESPONSALBackend.Repository.Corresponsalias; +using CORRESPONSALBackend.DTO.Reportes; namespace CORRESPONSALBackend.Controllers.Corresponsalias { @@ -45,6 +46,14 @@ namespace CORRESPONSALBackend.Controllers.Corresponsalias return entrada; } + [HttpGet] + [Route("GetByPedimento")] + public async Task GetByPedimento([FromQuery] int pedimento) + { + var entrada = await _Repo.GetByPedimento(pedimento); + return entrada; + } + [HttpPut("AddRectificacion/{id}")] public async Task AddRectificacion(int id) { diff --git a/Controllers/FileManagerController.cs b/Controllers/FileManagerController.cs index 64b7955..3d21f77 100644 --- a/Controllers/FileManagerController.cs +++ b/Controllers/FileManagerController.cs @@ -7,6 +7,7 @@ using CORRESPONSALBackend.Contracts.Utils; using CORRESPONSALBackend.Models.Utils; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http.HttpResults; namespace CORRESPONSALBackend.Controllers { @@ -57,41 +58,46 @@ namespace CORRESPONSALBackend.Controllers [Route("AppendFileByProcess")] [HttpPost] - public async Task AppendFileByProcess(IFormFile file, int IdUsuario, int Proceso, string Tags, int crud) + public async Task AppendFileByProcess(IFormFile file, int IdUsuario, int Proceso, string Tags, int crud) { - DateTime time = DateTime.Now; - FilePaths4Process RelativePath = await _RepoRelativePath.getPaths4ProcessById(Proceso); - string fullPath = ""; - fullPath = RootPathCorresponsales + RelativePath.Path; - string fileMime = file.FileName.Substring(file.FileName.LastIndexOf('.') + 1); - string newFileName = file.FileName.Replace("." + fileMime, "") + "_" + time.ToString("yyyy_MM_dd_HH_mm_ss") + "." + fileMime; - FileManager data = new FileManager(); - data.id = 0; - data.IdUsuario = IdUsuario; - data.NombreArchivo = newFileName; - data.Proceso = Proceso; - data.FechaRegistro = ""; - data.Tags = Tags; - data.Activo = 1; - long fileLength = 0; - if (@crud == 1) - { - if (file.Length > 0) + try{ + DateTime time = DateTime.Now; + FilePaths4Process RelativePath = await _RepoRelativePath.getPaths4ProcessById(Proceso); + string fullPath = ""; + fullPath = RootPathCorresponsales + RelativePath.Path; + string fileMime = file.FileName.Substring(file.FileName.LastIndexOf('.') + 1); + string newFileName = file.FileName.Replace("." + fileMime, "") + "_" + time.ToString("yyyy_MM_dd_HH_mm_ss") + "." + fileMime; + FileManager data = new FileManager(); + data.id = 0; + data.IdUsuario = IdUsuario; + data.NombreArchivo = newFileName; + data.Proceso = Proceso; + data.FechaRegistro = ""; + data.Tags = Tags; + data.Activo = 1; + long fileLength = 0; + if (@crud == 1) { - var filePath = fullPath + newFileName; - using (var stream = System.IO.File.Create(filePath)) - { - await file.CopyToAsync(stream); - } - fileLength = new System.IO.FileInfo(filePath).Length / 1024; - data.Size = fileLength; - if (fileLength > 0) + if (file.Length > 0) { - return await _Repo.FileManager(data); + var filePath = fullPath + newFileName; + using (var stream = System.IO.File.Create(filePath)) + { + await file.CopyToAsync(stream); + } + fileLength = new System.IO.FileInfo(filePath).Length / 1024; + data.Size = fileLength; + if (fileLength > 0) + { + return await _Repo.FileManager(data); + } } } + return data; + }catch(Exception ex){ + return Ok(ex.Message); } - return data; + } diff --git a/DTO/Reportes/DTOReporteSemanalNewel.cs b/DTO/Reportes/DTOReporteSemanalNewel.cs new file mode 100644 index 0000000..52d7981 --- /dev/null +++ b/DTO/Reportes/DTOReporteSemanalNewel.cs @@ -0,0 +1,10 @@ +namespace CORRESPONSALBackend.DTO.Reportes +{ + public class DTOReporteSemanalNewell{ + public string GC {get;set;} + public string Contenedor { get; set; } + public string CuentaDeGastos { get; set; } + public string Razon { get; set; } + public float Maniobras { get; set; } + } +} \ No newline at end of file diff --git a/Repository/Corresponsalias/CorresponsaliasTraficosRepository.cs b/Repository/Corresponsalias/CorresponsaliasTraficosRepository.cs index 3f08f39..3f2e6cc 100644 --- a/Repository/Corresponsalias/CorresponsaliasTraficosRepository.cs +++ b/Repository/Corresponsalias/CorresponsaliasTraficosRepository.cs @@ -6,6 +6,7 @@ using CORRESPONSALBackend.Models; using CORRESPONSALBackend.DTO.Corresponsales; using System.Data; using CORRESPONSALBackend.Models.Corresponsales; +using CORRESPONSALBackend.DTO.Reportes; namespace CORRESPONSALBackend.Repository.Corresponsalias { @@ -38,6 +39,18 @@ namespace CORRESPONSALBackend.Repository.Corresponsalias return entrada.FirstOrDefault(new ITrafico { }); } + public async Task GetByPedimento(int pedimento) + { + var query = "[Corresponsales.Trafico.GetByPedimento]"; + using var connection = _context.CreateConnection(); + var entrada = await connection.QueryAsync(query, new + { + @pedimento + }, + commandType: CommandType.StoredProcedure); + return entrada.FirstOrDefault(new DTOReporteSemanalNewell { }); + } + public async Task> GetRectificaciones(int id) { var query = "[Corresponsales.Trafico.Rectificacion.GetAll]";