Compare commits
No commits in common. 'b68cffe74148d95eb3ed7d32a37b4fe2404b0adf' and 'dcff6f0e911e1cb24668749a523dce29c5293abd' have entirely different histories.
b68cffe741
...
dcff6f0e91
@ -1,9 +0,0 @@ |
|||||||
using CORRESPONSALBackend.DTO.ArchivoElectronico; |
|
||||||
using GEMCO.Backend.Models.Reportes; |
|
||||||
|
|
||||||
namespace CORRESPONSALBackend.Contracts.ArchivoElectronico{ |
|
||||||
public interface IArchivoElectronicoRepository |
|
||||||
{ |
|
||||||
public Task<List<RptPedimentosPagadosAEO>> getRptPedimentoPagadosAEO(DTOAEPeriodo dTOData); |
|
||||||
} |
|
||||||
} |
|
@ -1,5 +0,0 @@ |
|||||||
namespace CORRESPONSALBackend.Contracts.ArchivoElectronico{ |
|
||||||
public interface IArchivoElectronicoService{ |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
@ -1,93 +0,0 @@ |
|||||||
using CORRESPONSALBackend.Contracts.ArchivoElectronico; |
|
||||||
using CORRESPONSALBackend.Contracts.Corresponsalias; |
|
||||||
using CORRESPONSALBackend.Contracts.Utils; |
|
||||||
using CORRESPONSALBackend.DTO.ArchivoElectronico; |
|
||||||
using CORRESPONSALBackend.Models.Utils; |
|
||||||
using CORRESPONSALBackend.Repository.Utils; |
|
||||||
using GEMCO.Backend.Models.Reportes; |
|
||||||
using Microsoft.AspNetCore.Mvc; |
|
||||||
|
|
||||||
namespace CORRESPONSALBackend.Controllers.Utils{ |
|
||||||
[Route("api/[controller]")]
|
|
||||||
[ApiController] |
|
||||||
public class ArchivoElectronicoController : ControllerBase { |
|
||||||
|
|
||||||
private readonly IArchivoElectronicoRepository _AERepo; |
|
||||||
private readonly IConfiguration _config; |
|
||||||
private readonly IFilePaths4ProcessRepository _RepoRelativePath; |
|
||||||
private readonly string RootPathCorresponsales; |
|
||||||
private readonly ICorresponsaliasTraficosRepository _traficosRepository; |
|
||||||
private readonly IFileManagerRepository _fileManagerRepo; |
|
||||||
public ArchivoElectronicoController(IArchivoElectronicoRepository AERepo, IConfiguration config, |
|
||||||
ICorresponsaliasTraficosRepository traficosRepository, IFilePaths4ProcessRepository RepoRelativePath, |
|
||||||
IFileManagerRepository fileManagerRepo){ |
|
||||||
_AERepo = AERepo; |
|
||||||
_traficosRepository = traficosRepository; |
|
||||||
_config = config; |
|
||||||
_RepoRelativePath = RepoRelativePath; |
|
||||||
_fileManagerRepo = fileManagerRepo; |
|
||||||
RootPathCorresponsales = _config.GetValue<string>("AllFiles"); |
|
||||||
} |
|
||||||
|
|
||||||
[HttpGet] |
|
||||||
[Route("RptArchivoElectronicoOficial")] |
|
||||||
public async Task<List<RptPedimentosPagadosAEO>> GetReporteArchivElectronicoOficial([FromQuery] DTOAEPeriodo DTOData) |
|
||||||
{ |
|
||||||
List<RptPedimentosPagadosAEO> data = await _AERepo.getRptPedimentoPagadosAEO(DTOData); |
|
||||||
return data; |
|
||||||
} |
|
||||||
|
|
||||||
[HttpPost] |
|
||||||
[Route("DownloadZippedArchivosOficiales")] |
|
||||||
public async Task<IActionResult> DownloadZippedArchivosOficiales([FromBody] DTOAEPeriodoSeleccion data){ |
|
||||||
try{ |
|
||||||
//Se obtiene la ruta donde se alojará temporalmente el zip |
|
||||||
FilePaths4Process tempFilesRelativePath = await _RepoRelativePath.getPaths4ProcessById(44); // Path: Corresponsales\Zips\Facturacion\Entregas\ |
|
||||||
var tempFilesPath = RootPathCorresponsales + tempFilesRelativePath.Path;// Path: C:data\Corresponsales\Zips\Clientes\ArchivosElectronicos |
|
||||||
string tempFolderName = "ReporteArchivosElectronicos";//Nombre del folder Temporal |
|
||||||
string tempFolderPath= tempFilesPath + $"{tempFolderName}\\";//ruta del folder temporal Path: C:data\Corresponsales\Zips\Clientes\ArchivosElectronicos\ReporteArchivosElectronicos |
|
||||||
string zipFileName = $"{tempFolderName}.zip";//Nombre del zip final |
|
||||||
var zipFilePath = tempFilesPath + zipFileName;//Ruta del zip final Path: C:data\Corresponsales\Zips\Clientes\ArchivosElectronicos\ReporteArchivosElectronicos.zip |
|
||||||
|
|
||||||
if(System.IO.File.Exists(zipFilePath)){//Si ya existe un zip de una descarga anterior lo borra |
|
||||||
System.IO.File.Delete(zipFilePath); |
|
||||||
} |
|
||||||
|
|
||||||
if(System.IO.Directory.Exists(tempFolderPath)){//Si ya existe la carpeta temporal de una descarga anterior la borra |
|
||||||
System.IO.Directory.Delete(tempFolderPath, true); |
|
||||||
} |
|
||||||
|
|
||||||
System.IO.Directory.CreateDirectory(tempFolderPath);//Se crea el folder temporal donde se pondran los archivos oficiales |
|
||||||
foreach(var referencia in data.Referencias){ |
|
||||||
var trafico = await _traficosRepository.GetByReferencia(referencia); |
|
||||||
string folderAE = tempFolderPath + $"{referencia}\\";//Se obtiene el nombre de la subcarpeta del AE de cada referencia |
|
||||||
if(System.IO.Directory.Exists(folderAE)){//Si existe la carpeta se borra |
|
||||||
System.IO.Directory.Delete(folderAE); |
|
||||||
} |
|
||||||
System.IO.Directory.CreateDirectory(folderAE);//Se crea la carpeta |
|
||||||
//Obtener la lista de archivos de la referencia actual. |
|
||||||
var filesLog = await _fileManagerRepo.GetTraficoFiles(trafico.id); |
|
||||||
var filteredFilesLog = filesLog.Where(x => new List<int>(){2,10,11,12,13,14,15,19,17,18,37,38,39,41}.Contains(x.Proceso)); |
|
||||||
foreach(var fileLog in filteredFilesLog){ |
|
||||||
FilePaths4Process fileRelativePath = await _RepoRelativePath.getPaths4ProcessById(fileLog.Proceso);//Se obtiene la ruta relativa donde debe estar alojado el archivo |
|
||||||
var filePath = RootPathCorresponsales + fileRelativePath.Path + fileLog!.NombreArchivo;//Ahora se obtiene la ruta completa del archivo. |
|
||||||
if(System.IO.File.Exists(filePath)){ |
|
||||||
var bytes = await System.IO.File.ReadAllBytesAsync(filePath); |
|
||||||
var originalFileStream = new MemoryStream(bytes); |
|
||||||
using(var tempFileStream = System.IO.File.Create(folderAE + fileLog.NombreArchivo)){ |
|
||||||
await originalFileStream.CopyToAsync(tempFileStream); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
System.IO.Compression.ZipFile.CreateFromDirectory(tempFolderPath, zipFilePath);//Se comprime la carpeta con los archivos electronicos de las referencias |
|
||||||
Directory.Delete(tempFolderPath, true);//Se borra el folder temporal |
|
||||||
var zipBytes = await System.IO.File.ReadAllBytesAsync(zipFilePath); |
|
||||||
var zipStream = new MemoryStream(zipBytes); |
|
||||||
return File(zipStream, "application/zip", zipFileName); |
|
||||||
}catch(Exception ex){ |
|
||||||
return BadRequest(ex.Message); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,31 +0,0 @@ |
|||||||
using System.Data; |
|
||||||
using CORRESPONSALBackend.Context; |
|
||||||
using CORRESPONSALBackend.Contracts.ArchivoElectronico; |
|
||||||
using CORRESPONSALBackend.DTO.ArchivoElectronico; |
|
||||||
using Dapper; |
|
||||||
using GEMCO.Backend.Models.Reportes; |
|
||||||
|
|
||||||
namespace CORRESPONSALBackend.Repository{ |
|
||||||
public class ArchivoElectronicoRepository : IArchivoElectronicoRepository |
|
||||||
{ |
|
||||||
private readonly DapperContext _context; |
|
||||||
public ArchivoElectronicoRepository(DapperContext context) { _context = context; } |
|
||||||
public async Task<List<RptPedimentosPagadosAEO>> getRptPedimentoPagadosAEO(DTOAEPeriodo data) |
|
||||||
{ |
|
||||||
var query = "getRptArchivoElectronicoOficial"; |
|
||||||
using (var connection = _context.CreateConnection()) |
|
||||||
{ |
|
||||||
var entrada = await connection.QueryAsync<RptPedimentosPagadosAEO>(query, |
|
||||||
new |
|
||||||
{ |
|
||||||
@Anio = data.Anio, |
|
||||||
@Mes = data.Mes, |
|
||||||
@NoCliente = data.NoCliente, |
|
||||||
@TipoOperacion = data.TipoOperacion |
|
||||||
}, |
|
||||||
commandType: CommandType.StoredProcedure); |
|
||||||
return entrada.ToList(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,7 +0,0 @@ |
|||||||
using CORRESPONSALBackend.Contracts.ArchivoElectronico; |
|
||||||
|
|
||||||
namespace CORRESPONSALBackend.Services{ |
|
||||||
public class ArchivoElectronicoService : IArchivoElectronicoService{ |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue