agregado procesos y bd clases
This commit is contained in:
388
Servicio Gestion Asegasa/Procesos/ProcesosSiniestros.cs
Normal file
388
Servicio Gestion Asegasa/Procesos/ProcesosSiniestros.cs
Normal file
@@ -0,0 +1,388 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using bdAsegasa;
|
||||
using bdAsegasa.db;
|
||||
|
||||
namespace Servicio_Gestion_Asegasa.Procesos
|
||||
{
|
||||
public class ProcesosSiniestros
|
||||
{
|
||||
public static void IncorporaSiniestrosEIACV6()
|
||||
{
|
||||
try
|
||||
{
|
||||
using var bd = gestionasegasaEntities.NuevoContexto();
|
||||
var ltpa = bd.enumeraciones.Where(x => x.idGrupoEnumeracionNavigation.Grupo == "TIPP").ToList();
|
||||
int tipo = (int)ficheroscompanias.TipoFicheroCompania.SINIESTROS_EIAC;
|
||||
|
||||
var ficspen = bd.ficheroscompanias
|
||||
.Where(x => x.FechaProcesado == null &&
|
||||
x.FechaError == null &&
|
||||
x.Tipo == tipo &&
|
||||
x.Version == "6.0")
|
||||
.OrderBy(x => x.idFichero)
|
||||
.ToList();
|
||||
|
||||
foreach (var f in ficspen)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Asumimos ProcesosEIAC_V6 existe y Utilizamos una librería genérica de serialización
|
||||
dynamic DatosEIAC = tsUtilidades.Utilidades.Deserializa(f.Fichero, Type.GetType("ProcesosEIAC_V6.ProcesosEIAC") ?? typeof(object));
|
||||
|
||||
if (DatosEIAC?.Objetos?.Items != null)
|
||||
{
|
||||
IEnumerable<dynamic> items = DatosEIAC.Objetos.Items;
|
||||
var lSins = items.Where(x => x != null && x.GetType().Name == "tipo_siniestro");
|
||||
|
||||
foreach (var s in lSins)
|
||||
{
|
||||
List<siniestros> sins = null;
|
||||
string idSiniestroEntidad = s.DatosSiniestro.IdSiniestroEntidad;
|
||||
|
||||
var seiac = bd.siniestros_eiac.FirstOrDefault(x => x.idSiniestroEntidad == idSiniestroEntidad);
|
||||
if (seiac == null)
|
||||
{
|
||||
seiac = new siniestros_eiac
|
||||
{
|
||||
idSiniestroEntidad = idSiniestroEntidad,
|
||||
idFicheroCompania = f.idFichero,
|
||||
idCompania = f.idCompania
|
||||
};
|
||||
bd.siniestros_eiac.Add(seiac);
|
||||
}
|
||||
|
||||
seiac.NumeroPoliza = s.DatosPoliza.IdPoliza;
|
||||
var pol = bd.polizassg
|
||||
.Where(x => x.NumeroPoliza == seiac.NumeroPoliza && x.idCompania == seiac.idCompania)
|
||||
.OrderByDescending(x => x.NumeroSuplemento)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (pol != null)
|
||||
seiac.idPoliza = pol.idPoliza;
|
||||
|
||||
seiac.NumeroSuplemento = s.DatosPoliza.NumeroSuplemento;
|
||||
seiac.FechaDeclaracion = s.DatosSiniestro.FechaDeclaracion;
|
||||
seiac.FechaOcurrencia = s.DatosSiniestro.FechaOcurrencia;
|
||||
seiac.PosicionSiniestro = (int)bdAsegasa.db.siniestros_eiac.ObtienePosicionSiniestroV6((string)s.DatosSiniestro.PosicionSiniestro);
|
||||
seiac.DescripcionSiniestro = tsUtilidades.Extensiones.StringExtensions.Acortar((string)s.DatosSiniestro.DescripcionSiniestro, 2048);
|
||||
seiac.TipologiaSiniestro = s.DatosSiniestro.TipologiaSiniestro;
|
||||
seiac.ImporteIndemnizacion = s.DatosSiniestro.ImporteIndemnizacion;
|
||||
seiac.ImporteReserva = s.DatosSiniestro.ImporteReserva;
|
||||
|
||||
if (s.DatosSiniestro.LugarSiniestro != null)
|
||||
{
|
||||
if (seiac.idLugarSiniestroNavigation == null)
|
||||
{
|
||||
seiac.idLugarSiniestroNavigation = new direcciones();
|
||||
}
|
||||
seiac.idLugarSiniestroNavigation.Direccion = s.DatosSiniestro.LugarSiniestro.ClaseVia + " " + s.DatosSiniestro.LugarSiniestro.NombreVia + " " + s.DatosSiniestro.LugarSiniestro.OtrosDatosVia;
|
||||
seiac.idLugarSiniestroNavigation.CodigoPostal = s.DatosSiniestro.LugarSiniestro.CodigoPostal;
|
||||
|
||||
string codmun = bd.ObtieneCodigoMunicipioMasCoincidente(seiac.idLugarSiniestroNavigation.CodigoPostal, (string)s.DatosSiniestro.LugarSiniestro.Poblacion, true);
|
||||
if (string.IsNullOrEmpty(codmun))
|
||||
{
|
||||
seiac.idLugarSiniestroNavigation.Direccion += " " + s.DatosSiniestro.LugarSiniestro.Poblacion;
|
||||
}
|
||||
else
|
||||
{
|
||||
seiac.idLugarSiniestroNavigation.CodigoMunicipio = codmun;
|
||||
}
|
||||
seiac.idLugarSiniestroNavigation.Direccion = tsUtilidades.Extensiones.StringExtensions.Acortar(seiac.idLugarSiniestroNavigation.Direccion, 200);
|
||||
}
|
||||
|
||||
if (s.DatosSiniestro.SituacionesSiniestro != null)
|
||||
{
|
||||
var yaincorporados = new List<int>();
|
||||
foreach (var sit in s.DatosSiniestro.SituacionesSiniestro)
|
||||
{
|
||||
int numeroOrden = sit.NumeroOrden;
|
||||
if (numeroOrden == 0) numeroOrden = sit.GetHashCode();
|
||||
if (!yaincorporados.Contains(numeroOrden))
|
||||
{
|
||||
var est = seiac.estadossiniestros_eiac.FirstOrDefault(x => x.NumeroOrden == numeroOrden);
|
||||
if (est == null)
|
||||
{
|
||||
est = new estadossiniestros_eiac { NumeroOrden = numeroOrden };
|
||||
seiac.estadossiniestros_eiac.Add(est);
|
||||
}
|
||||
est.SituacionSiniestro = bdAsegasa.estadossiniestros_eiac.ObtieneSituacionSiniestroV6((string)sit.SituacionSiniestro);
|
||||
est.DescripcionSituacion = tsUtilidades.Extensiones.StringExtensions.Acortar((string)sit.DescripcionSituacion, 45);
|
||||
yaincorporados.Add(numeroOrden);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (s.DatosSiniestro.PagosSiniestro != null)
|
||||
{
|
||||
var yaincorporados = new List<int>();
|
||||
foreach (var pag in s.DatosSiniestro.PagosSiniestro)
|
||||
{
|
||||
int numeroOrden = pag.NumeroOrden;
|
||||
if (numeroOrden == 0) numeroOrden = pag.GetHashCode();
|
||||
if (!yaincorporados.Contains(numeroOrden))
|
||||
{
|
||||
var ps = seiac.pagossiniestros_eiac.FirstOrDefault(x => x.NumeroOrden == numeroOrden);
|
||||
if (ps == null)
|
||||
{
|
||||
ps = new pagossiniestros_eiac { NumeroOrden = numeroOrden };
|
||||
seiac.pagossiniestros_eiac.Add(ps);
|
||||
}
|
||||
ps.FechaPago = pag.FechaPago;
|
||||
ps.FechaLiquidacion = pag.FechaLiquidacion;
|
||||
ps.ImportePago = pag.ImportePago;
|
||||
ps.DescripcionPago = tsUtilidades.Extensiones.StringExtensions.Acortar((string)pag.DescripcionPago, 255);
|
||||
ps.idTipoPago = bdAsegasa.siniestros_eiac.ObtenerTipoPagoV6((string)pag.FormaPago, ltpa);
|
||||
|
||||
if (pag.FormaPago != null && pag.FormaPago.DatosCuentaCorriente != null)
|
||||
{
|
||||
ps.IBAN = pag.FormaPago.DatosCuentaCorriente.IBAN;
|
||||
}
|
||||
yaincorporados.Add(numeroOrden);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (s.DatosSiniestro.AccionesSiniestro != null)
|
||||
{
|
||||
var yaincorporados = new List<int>();
|
||||
foreach (var accs in s.DatosSiniestro.AccionesSiniestro)
|
||||
{
|
||||
int numeroOrden = accs.NumeroOrden;
|
||||
if (numeroOrden == 0) numeroOrden = accs.GetHashCode();
|
||||
if (!yaincorporados.Contains(numeroOrden))
|
||||
{
|
||||
var acs = seiac.accionessiniestros_eiac.FirstOrDefault(x => x.NumeroOrden == numeroOrden);
|
||||
if (acs == null)
|
||||
{
|
||||
acs = new accionessiniestros_eiac { NumeroOrden = numeroOrden };
|
||||
seiac.accionessiniestros_eiac.Add(acs);
|
||||
}
|
||||
acs.AccionSiniestro = bdAsegasa.accionessiniestros_eiac.ObtieneAccionSiniestroV6((string)accs.AccionSiniestro);
|
||||
acs.FechaAccion = accs.FechaAccion;
|
||||
acs.DescripcionAccion = accs.DescripcionAccion;
|
||||
acs.SituacionAccion = bdAsegasa.accionessiniestros_eiac.ObtieneSituacionAccionV6((string)accs.SituacionAccion);
|
||||
yaincorporados.Add(numeroOrden);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (s.DatosSiniestro.Expedientes != null)
|
||||
{
|
||||
var yaincorporados = new List<string>();
|
||||
foreach (var exp in s.DatosSiniestro.Expedientes)
|
||||
{
|
||||
string numeroExpediente = exp.NumeroExpediente;
|
||||
if (string.IsNullOrEmpty(numeroExpediente)) numeroExpediente = exp.GetHashCode().ToString();
|
||||
|
||||
if (!yaincorporados.Contains(numeroExpediente))
|
||||
{
|
||||
var ep = seiac.expedientessiniestros_eiac.FirstOrDefault(x => x.NumeroExpediente == numeroExpediente);
|
||||
if (ep == null)
|
||||
{
|
||||
ep = new expedientessiniestros_eiac { NumeroExpediente = numeroExpediente };
|
||||
seiac.expedientessiniestros_eiac.Add(ep);
|
||||
}
|
||||
ep.EstadoExpediente = bdAsegasa.expedientessiniestros_eiac.ObtieneEstadoExpedienteV6((string)exp.EstadoExpediente);
|
||||
ep.ImporteReserva = exp.ImporteReserva;
|
||||
ep.TotalPagos = exp.TotalPagos;
|
||||
ep.TotalRecobros = exp.TotalRecobros;
|
||||
ep.FechaInicio = exp.FechaInicio;
|
||||
ep.FechaFin = exp.FechaFin;
|
||||
ep.NumeroOrden = exp.NumeroOrden;
|
||||
yaincorporados.Add(numeroExpediente);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (seiac.idSiniestroNavigation == null)
|
||||
{
|
||||
var fi = seiac.FechaOcurrencia.AddDays(-5);
|
||||
var ff = seiac.FechaOcurrencia.AddDays(5);
|
||||
|
||||
|
||||
var fechaInicio = DateOnly.FromDateTime(fi);
|
||||
var fechaFinal = DateOnly.FromDateTime(ff);
|
||||
|
||||
sins = bd.siniestros.Where(x =>
|
||||
x.idPolizaNavigation.NumeroPoliza == seiac.NumeroPoliza &&
|
||||
x.FechaAccidente.HasValue &&
|
||||
x.FechaAccidente >= fechaInicio &&
|
||||
x.FechaAccidente <= fechaFinal).ToList();
|
||||
|
||||
if (sins.Count == 1)
|
||||
{
|
||||
seiac.idSiniestroNavigation = sins[0];
|
||||
}
|
||||
}
|
||||
|
||||
bool bModificados = false;
|
||||
if (bd.ChangeTracker.Entries().Any(e => e.State == EntityState.Added))
|
||||
{
|
||||
bModificados = true;
|
||||
seiac.SituacionAsegasa = (int)bdAsegasa.siniestros_eiac.SituacionAsegasaENUM.NUEVO;
|
||||
seiac.FechaSituacion = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
var prmods = bd.ChangeTracker.Entries().Where(e => e.State == EntityState.Modified).ToList();
|
||||
if (prmods.Count > 0)
|
||||
{
|
||||
foreach (var pr in prmods)
|
||||
{
|
||||
var original = pr.OriginalValues;
|
||||
var nuevosvalores = pr.CurrentValues;
|
||||
foreach (var prop in original.Properties)
|
||||
{
|
||||
var origVal = original[prop];
|
||||
var newVal = nuevosvalores[prop];
|
||||
|
||||
if (origVal?.GetHashCode() != newVal?.GetHashCode())
|
||||
{
|
||||
bModificados = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (bModificados) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bModificados)
|
||||
{
|
||||
if (!seiac.SituacionAsegasa.HasValue || seiac.SituacionAsegasa.Value != (int)bdAsegasa.siniestros_eiac.SituacionAsegasaENUM.DESCARTADO)
|
||||
{
|
||||
seiac.SituacionAsegasa = (int)bdAsegasa.siniestros_eiac.SituacionAsegasaENUM.MODIFICADO;
|
||||
seiac.FechaSituacion = DateTime.Now;
|
||||
}
|
||||
|
||||
var nact = new actualizacionessiniestros_eiac
|
||||
{
|
||||
idSiniestroEIACNavigation = seiac,
|
||||
Fecha = DateTime.Now,
|
||||
idFicheroCompania = f.idFichero
|
||||
};
|
||||
bd.actualizacionessiniestros_eiac.Add(nact);
|
||||
|
||||
if (seiac.SituacionAsegasa.Value != (int)bdAsegasa.siniestros_eiac.SituacionAsegasaENUM.DESCARTADO)
|
||||
{
|
||||
if (!seiac.idPoliza.HasValue)
|
||||
{
|
||||
seiac.SituacionAsegasa = (int)bdAsegasa.siniestros_eiac.SituacionAsegasaENUM.POLIZA_NO_ENCONTRADA;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sins == null || sins.Count == 0)
|
||||
{
|
||||
seiac.SituacionAsegasa = (int)bdAsegasa.siniestros_eiac.SituacionAsegasaENUM.SINIESTRO_NO_ENCONTRADO;
|
||||
}
|
||||
else if (sins.Count > 1)
|
||||
{
|
||||
seiac.SituacionAsegasa = (int)bdAsegasa.siniestros_eiac.SituacionAsegasaENUM.VARIOS_SINIESTROS_POSIBLES;
|
||||
}
|
||||
}
|
||||
}
|
||||
bd.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
f.FechaProcesado = DateTime.Now;
|
||||
bd.SaveChanges();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
f.FechaError = DateTime.Now;
|
||||
bd.SaveChanges();
|
||||
tsUtilidades.TsNotificacionesClient.RegistrarAsync("En IncorporaSiniestrosEIACV6.", $"Rutina: IncorporaSiniestrosEIACV6. Fichero:{f.NombreFichero} {ex.Message}", tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
tsUtilidades.TsNotificacionesClient.RegistrarAsync("En IncorporaSiniestrosEIACV6.", $"Rutina: IncorporaSiniestrosEIACV6. {ex.Message}", tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
public static void IncorporaExpSiniestrosEIACV6()
|
||||
{
|
||||
try
|
||||
{
|
||||
using var bd = tscgestionasegasa.NuevoContexto();
|
||||
var ltpa = bd.enumeraciones.Where(x => x.idGrupoEnumeracionNavigation.Grupo == "TIPP").ToList();
|
||||
int tipo = (int)ficheroscompanias.TipoFicheroCompania.SINIESTROS_EIAC;
|
||||
var ficspen = bd.ficheroscompanias
|
||||
.Where(x => x.Tipo == tipo && x.Version == "6.0")
|
||||
.OrderBy(x => x.idFichero)
|
||||
.ToList();
|
||||
|
||||
foreach (var f in ficspen)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Asumimos ProcesosEIAC_V6 existe y Utilizamos una librería genérica de serialización
|
||||
dynamic DatosEIAC = tsUtilidades.Utilidades.Deserializa(f.Fichero, Type.GetType("ProcesosEIAC_V6.ProcesosEIAC") ?? typeof(object));
|
||||
|
||||
if (DatosEIAC?.Objetos?.Items != null)
|
||||
{
|
||||
IEnumerable<dynamic> items = DatosEIAC.Objetos.Items;
|
||||
var lSins = items.Where(x => x != null && x.GetType().Name == "tipo_siniestro");
|
||||
|
||||
foreach (var s in lSins)
|
||||
{
|
||||
string idSiniestroEntidad = s.DatosSiniestro.IdSiniestroEntidad;
|
||||
var seiac = bd.siniestros_eiac.FirstOrDefault(x => x.idSiniestroEntidad == idSiniestroEntidad);
|
||||
|
||||
if (seiac != null)
|
||||
{
|
||||
if (s.DatosSiniestro.Expedientes != null)
|
||||
{
|
||||
var yaincorporados = new List<string>();
|
||||
foreach (var exp in s.DatosSiniestro.Expedientes)
|
||||
{
|
||||
string numeroExpediente = exp.NumeroExpediente;
|
||||
if (string.IsNullOrEmpty(numeroExpediente)) numeroExpediente = exp.GetHashCode().ToString();
|
||||
|
||||
if (!yaincorporados.Contains(numeroExpediente))
|
||||
{
|
||||
var ep = seiac.expedientessiniestros_eiac.FirstOrDefault(x => x.NumeroExpediente == numeroExpediente);
|
||||
if (ep == null)
|
||||
{
|
||||
ep = new expedientessiniestros_eiac { NumeroExpediente = numeroExpediente };
|
||||
seiac.expedientessiniestros_eiac.Add(ep);
|
||||
}
|
||||
ep.EstadoExpediente = bdAsegasa.expedientessiniestros_eiac.ObtieneEstadoExpedienteV6((string)exp.EstadoExpediente);
|
||||
ep.ImporteReserva = exp.ImporteReserva;
|
||||
ep.TotalPagos = exp.TotalPagos;
|
||||
ep.TotalRecobros = exp.TotalRecobros;
|
||||
ep.FechaInicio = exp.FechaInicio;
|
||||
ep.FechaFin = exp.FechaFin;
|
||||
ep.NumeroOrden = exp.NumeroOrden;
|
||||
|
||||
yaincorporados.Add(numeroExpediente);
|
||||
}
|
||||
}
|
||||
bd.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// f.FechaProcesado = Now (Comentado en el código original)
|
||||
bd.SaveChanges();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
f.FechaError = DateTime.Now;
|
||||
bd.SaveChanges();
|
||||
tsUtilidades.TsNotificacionesClient.RegistrarAsync("En IncorporaSiniestrosEIACV6.", $"Rutina: IncorporaSiniestrosEIACV6. Fichero:{f.NombreFichero} {ex.Message}", tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
tsUtilidades.TsNotificacionesClient.RegistrarAsync("En IncorporaSiniestrosEIACV6.", $"Rutina: IncorporaSiniestrosEIACV6. {ex.Message}", tsUtilidades.TsNotificacionesClient.TipoNotificacionEnum.ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user