204 lines
11 KiB
C#
204 lines
11 KiB
C#
//using System;
|
|
//using System.Linq;
|
|
//using System.Threading.Tasks;
|
|
//using Microsoft.EntityFrameworkCore;
|
|
//using bdAsegasa;
|
|
//using bdAsegasa.db;
|
|
//using System.Security.Cryptography;
|
|
|
|
//namespace Servicio_Gestion_Asegasa.Procesos
|
|
//{
|
|
// public class ProcesosZurich
|
|
// {
|
|
// public static async Task ObtieneDocumentosPolizasPendientes()
|
|
// {
|
|
// try
|
|
// {
|
|
// using var bd = tscgestionasegasa.NuevoContexto();
|
|
|
|
// int idZurich = bd.companias.First(x => x.Codigo == "0013").idCompania;
|
|
// int tipoFichero = bd.enumeraciones.First(x => x.Codigo == "TIPFIC.DOCPOL").idEnumeracion;
|
|
// var fi = new DateTime(2024, 10, 5);
|
|
|
|
// var pols = bd.polizassg
|
|
// .Where(x => x.idCompania == idZurich &&
|
|
// x.NumeroPoliza != null &&
|
|
// x.FechaAlta > fi &&
|
|
// x.documentospolizassg.All(y => y.Tipo == 0))
|
|
// .ToList();
|
|
|
|
// var cz = bd.enumeraciones.First(x => x.Codigo == "CONF.0013");
|
|
|
|
// // Asumimos que ServicioDocumentos es un cliente WCF / Servicio inyectado en el scope superior
|
|
// dynamic sv = Activator.CreateInstance(Type.GetType("ServicioDocumentos") ?? throw new Exception("ServicioDocumentos no encontrado"), cz.ValorAlfabetico1, cz.ValorAlfabetico2)!;
|
|
|
|
// foreach (var p in pols)
|
|
// {
|
|
// string numpol = p.NumeroPoliza.PadLeft(14, '0');
|
|
// var ld = await sv.ObtenerDocumentosAsync(numpol, -1);
|
|
|
|
// // Obtener la lista de documentos que no son recibos
|
|
// // En VB: ld.Document.Where(Function(x) Not String.IsNullOrEmpty(x.documentTypeDesc) AndAlso Not x.documentTypeDesc.ToLower().Contains("recibo"))
|
|
// System.Collections.Generic.IEnumerable<dynamic> docList = ld.Document;
|
|
// var ldocs = docList.Where(x => !string.IsNullOrEmpty((string)x.documentTypeDesc) && !((string)x.documentTypeDesc).ToLower().Contains("recibo"));
|
|
|
|
// foreach (var d in ldocs)
|
|
// {
|
|
// try
|
|
// {
|
|
// var dr = await sv.DescargarDocumentoAsync("", (string)d.documentCode, false, numpol, (string)ld.policyVersion);
|
|
|
|
// byte[] data = dr.documentFileContent.data;
|
|
// string sha1 = GetSha1Hash(data);
|
|
|
|
// var docpol = p.documentospolizassg.FirstOrDefault(x => x.Hash == sha1);
|
|
|
|
// if (docpol == null)
|
|
// {
|
|
// docpol = new documentospolizassg();
|
|
// var fichero = new ficheros
|
|
// {
|
|
// Descripcion = d.documentTypeDesc,
|
|
// Fecha = DateTime.Now,
|
|
// idTipo = tipoFichero,
|
|
// Fichero = data,
|
|
// NombreFichero = dr.documentFileContent.fileName,
|
|
// idAplicacion = p.idPoliza
|
|
// };
|
|
|
|
// // Crear y almacenar el documento de la póliza
|
|
// docpol.Descripcion = ((string)d.documentTypeDesc).ToUpper();
|
|
// docpol.idFicheroNavigation = fichero;
|
|
// docpol.FechaComprobacion = DateTime.Now;
|
|
// docpol.Fecha = DateTime.Now;
|
|
// docpol.Codigo = d.documentCode;
|
|
// docpol.Hash = sha1;
|
|
// docpol.Tipo = ObtieneTipoDocumento((string)d.typeCode);
|
|
|
|
// p.documentospolizassg.Add(docpol);
|
|
// }
|
|
// else
|
|
// {
|
|
// docpol.Codigo = d.documentCode;
|
|
// docpol.Tipo = ObtieneTipoDocumento((string)d.typeCode);
|
|
// }
|
|
|
|
// bd.SaveChanges();
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// await tsUtilidades.TsNotificacionesClient.RegistrarAsync("En ObtieneDocumentosPolizasPendientes.", $"Rutina: ObtieneDocumentosPolizasPendientes. Poliza:{p.NumeroPoliza} dc:{d.documentCode} {ex.Message}",tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR);
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// await tsUtilidades.TsNotificacionesClient.RegistrarAsync("En ObtieneDocumentosPolizasPendientes.", $"Rutina: ObtieneDocumentosPolizasPendientes. {ex.Message}", tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR);
|
|
// }
|
|
// }
|
|
|
|
// public static async Task ObtieneDocumentosRecibosPendientes()
|
|
// {
|
|
// try
|
|
// {
|
|
// using var bd = tscgestionasegasa.NuevoContexto();
|
|
|
|
// int idZurich = bd.companias.First(x => x.Codigo == "0013").idCompania;
|
|
// int tipoFichero = bd.enumeraciones.First(x => x.Codigo == "TIPFIC.DOCPOL").idEnumeracion;
|
|
// var fi = new DateOnly(2024, 9, 23);
|
|
// var cz = bd.enumeraciones.First(x => x.Codigo == "CONF.0013");
|
|
|
|
// dynamic svRecibos = Activator.CreateInstance(Type.GetType("ServicioRecibos") ?? throw new Exception("ServicioRecibos no encontrado"), cz.ValorAlfabetico1, cz.ValorAlfabetico2)!;
|
|
// dynamic svDocumentos = Activator.CreateInstance(Type.GetType("ServicioDocumentos") ?? throw new Exception("ServicioDocumentos no encontrado"), cz.ValorAlfabetico1, cz.ValorAlfabetico2)!;
|
|
|
|
// var recs = bd.recibos
|
|
// .Where(x => x.idPolizaNavigation.idCompania == idZurich &&
|
|
// x.FechaEfecto > fi &&
|
|
// x.idPolizaNavigation.documentospolizassg.Count == 0)
|
|
// .ToList();
|
|
|
|
// dynamic dr = null;
|
|
|
|
// foreach (var r in recs)
|
|
// {
|
|
// try
|
|
// {
|
|
// var p = r.idPolizaNavigation;
|
|
// dr = await svRecibos.ObtenerReciboDuplicadoAsync(r.NumeroRecibo, cz.ValorAlfabetico1);
|
|
// string numpol = p.NumeroPoliza != null ? p.NumeroPoliza.PadLeft(14, '0') : string.Empty;
|
|
|
|
// var bpdf = await svDocumentos.DescargarDocumentoAsync("", (string)dr.documentCode, false, numpol, (string)dr.policyVersion);
|
|
// byte[] data = bpdf.documentFileContent.data;
|
|
|
|
// string sha1 = GetSha1Hash(data);
|
|
// var docpol = p.documentospolizassg.FirstOrDefault(x => x.Hash == sha1);
|
|
|
|
// if (docpol == null)
|
|
// {
|
|
// docpol = new documentospolizassg();
|
|
// var fichero = new ficheros
|
|
// {
|
|
// Descripcion = "RECIBO",
|
|
// Fecha = DateTime.Now,
|
|
// idTipo = tipoFichero,
|
|
// Fichero = data,
|
|
// NombreFichero = dr.documentCode + ".pdf",
|
|
// idAplicacion = p.idPoliza
|
|
// };
|
|
|
|
// docpol.Descripcion = "RECIBO";
|
|
// docpol.idFicheroNavigation = fichero;
|
|
// docpol.FechaComprobacion = DateTime.Now;
|
|
// docpol.Fecha = DateTime.Now;
|
|
// docpol.Codigo = dr.documentCode;
|
|
// docpol.Hash = sha1;
|
|
// docpol.Tipo = (int)bdAsegasa.db.documentospolizassg.TipoDocumentoEnum.RECIBO;
|
|
// docpol.idRecibo = r.idRecibo;
|
|
|
|
// p.documentospolizassg.Add(docpol);
|
|
// }
|
|
// else
|
|
// {
|
|
// docpol.Codigo = dr.documentCode;
|
|
// docpol.Tipo = (int)bdAsegasa.db.documentospolizassg.TipoDocumentoEnum.RECIBO;
|
|
// }
|
|
|
|
// bd.SaveChanges();
|
|
// dr = null;
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// string dcCode = dr == null ? "" : $" dc:{dr.documentCode}";
|
|
// await tsUtilidades.TsNotificacionesClient.RegistrarAsync("En ObtieneDocumentosRecibosPendientes.",$"Rutina: ObtieneDocumentosRecibosPendientes. Recibo:{r.CodigoRecibo}{dcCode} {ex.Message}",tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR);
|
|
// }
|
|
// }
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// await tsUtilidades.TsNotificacionesClient.RegistrarAsync("En ObtieneDocumentosRecibosPendientes.", $"Rutina: ObtieneDocumentosRecibosPendientes. {ex.Message}", tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR);
|
|
// }
|
|
// }
|
|
|
|
// private static int ObtieneTipoDocumento(string typeCode)
|
|
// {
|
|
// switch (typeCode)
|
|
// {
|
|
// case "CL":
|
|
// return (int)bdAsegasa.db.documentospolizassg.TipoDocumentoEnum.PÓLIZA;
|
|
// case "CE":
|
|
// return (int)bdAsegasa.db.documentospolizassg.TipoDocumentoEnum.CERTIFICADO_SEGURO;
|
|
// default:
|
|
// return (int)bdAsegasa.db.documentospolizassg.TipoDocumentoEnum.OTROS;
|
|
// }
|
|
// }
|
|
|
|
// private static string GetSha1Hash(byte[] data)
|
|
// {
|
|
// using var sha1 = SHA1.Create();
|
|
// var hashBytes = sha1.ComputeHash(data);
|
|
// return BitConverter.ToString(hashBytes).Replace("-", "").ToUpperInvariant();
|
|
// }
|
|
// }
|
|
//}
|