From 674ca83ba9243a9e95a7568c797668dab6aee26a Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:35:25 -0300 Subject: feat: upload files --- .../RegistroAcaoRepository.cs | 183 +++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/RegistroAcaoRepository.cs (limited to 'Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/RegistroAcaoRepository.cs') diff --git a/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/RegistroAcaoRepository.cs b/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/RegistroAcaoRepository.cs new file mode 100644 index 0000000..158bcb9 --- /dev/null +++ b/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/RegistroAcaoRepository.cs @@ -0,0 +1,183 @@ +using AutoMapper; +using Gestor.Infrastructure.Entities.Common; +using Gestor.Infrastructure.Mappers; +using Gestor.Infrastructure.Repository.Generic; +using Gestor.Infrastructure.Repository.Interface; +using Gestor.Infrastructure.UnitOfWork.Generic; +using Gestor.Model.Common; +using Gestor.Model.Domain.Common; +using Gestor.Model.Domain.Relatorios; +using NHibernate; +using NHibernate.Connection; +using NHibernate.Impl; +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.Common; +using System.Data.SqlClient; +using System.Linq; +using System.Linq.Expressions; +using System.Runtime.CompilerServices; + +namespace Gestor.Infrastructure.Repository.Logic +{ + public class RegistroAcaoRepository : GenericRepository, IRegistroAcaoRepository, IGenericRepository + { + private readonly GenericUnitOfWork _unitOfWork; + + public RegistroAcaoRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session) + { + this._unitOfWork = unitOfWork; + } + + public void Delete(long id) + { + RegistroAcaoDb registroAcaoDb = base.FindEntityById(id); + if (registroAcaoDb == null) + { + return; + } + base.Delete(registroAcaoDb); + } + + public List Find(Filtros filtros) + { + return this.Select(filtros); + } + + public List FindByEntityId(long id, TipoTela tela) + { + List list = ( + from x in base.All() + where x.EntidadeId == id && (int?)x.Tela == (int?)tela + select x).ToList(); + return ApplicationMapper.Mapper.Map, List>(list); + } + + public RegistroAcao FindById(long id) + { + RegistroAcaoDb registroAcaoDb = base.FindEntityById(id); + return ApplicationMapper.Mapper.Map(registroAcaoDb); + } + + public List FindOld(Filtros filtros, string connection) + { + return this.SelectOld(filtros, connection); + } + + public RegistroAcao SaveOrUpdate(RegistroAcao log) + { + RegistroAcaoDb registroAcaoDb = ApplicationMapper.Mapper.Map(log); + this.SaveOrUpdate(registroAcaoDb); + return ApplicationMapper.Mapper.Map(registroAcaoDb); + } + + private List Select(Filtros filtros) + { + List registroAcaos; + object connection; + DataTable dataTable = new DataTable(); + string str = (filtros.Usuarios == null || filtros.Usuarios.Count == 0 ? "" : string.Concat(" AND IdUsuario IN (", string.Join(",", + from v in filtros.Usuarios + select v), ")")); + string str1 = (filtros.Telas == null || filtros.Telas.Count == 0 ? "" : string.Concat(" AND Tela IN (", string.Join(",", + from v in filtros.Telas + select v), ")")); + string str2 = (filtros.Relatorios == null || filtros.Relatorios.Count == 0 ? "" : string.Concat(" AND Relatorio IN (", string.Join(",", + from v in filtros.Relatorios + select v), ")")); + string str3 = (filtros.Inicio == DateTime.MinValue ? "" : string.Format(" AND CAST(DataHora AS DATE) >= '{0:yyyy-MM-dd}'", filtros.Inicio)); + string str4 = (filtros.Fim == DateTime.MinValue ? "" : string.Format(" AND CAST(DataHora AS DATE) <= '{0:yyyy-MM-dd}'", filtros.Fim)); + SessionFactoryImpl sessionFactory = this._unitOfWork.Session.SessionFactory as SessionFactoryImpl; + if (sessionFactory != null) + { + connection = sessionFactory.ConnectionProvider.GetConnection(); + } + else + { + connection = null; + } + using (SqlConnection sqlConnection = connection as SqlConnection) + { + using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) + { + sqlCommand.CommandText = string.Concat(new string[] { "SELECT * FROM RegistroAcao WHERE 1=1 ", str3, str4, str, str1, str2 }); + using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter()) + { + sqlDataAdapter.SelectCommand = sqlCommand; + sqlDataAdapter.Fill(dataTable); + } + if (dataTable.Rows.Count != 0) + { + return CustomMap.MapLogAcao(dataTable); + } + else + { + registroAcaos = new List(); + } + } + } + return registroAcaos; + } + + private List SelectOld(Filtros filtros, string conn) + { + List registroAcaos; + object connection; + try + { + DataTable dataTable = new DataTable(); + string str = (filtros.Usuarios == null || filtros.Usuarios.Count == 0 ? "" : string.Concat(" AND IDUSUARIO IN (", string.Join(",", + from v in filtros.Usuarios + select v), ")")); + string str1 = (filtros.Inicio == DateTime.MinValue ? "" : string.Format(" AND CAST(DATA AS DATE) >= '{0:yyyy-MM-dd}'", filtros.Inicio)); + string str2 = (filtros.Fim == DateTime.MinValue ? "" : string.Format(" AND CAST(DATA AS DATE) <= '{0:yyyy-MM-dd}'", filtros.Fim)); + SessionFactoryImpl sessionFactory = this._unitOfWork.Session.SessionFactory as SessionFactoryImpl; + if (sessionFactory != null) + { + connection = sessionFactory.ConnectionProvider.GetConnection(); + } + else + { + connection = null; + } + using (SqlConnection sqlConnection = connection as SqlConnection) + { + using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) + { + sqlCommand.CommandText = "SELECT TOP 1 * FROM controlelog"; + SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); + sqlDataReader.Read(); + string str3 = sqlDataReader["bdname"].ToString(); + sqlDataReader["tabela"].ToString(); + sqlDataReader.Close(); + if (sqlConnection.Database != str3) + { + conn = conn.Replace(sqlConnection.Database, str3); + } + } + } + using (SqlConnection sqlConnection1 = new SqlConnection(conn)) + { + sqlConnection1.Open(); + using (SqlCommand sqlCommand1 = sqlConnection1.CreateCommand()) + { + sqlCommand1.CommandTimeout = 15000; + sqlCommand1.CommandText = string.Concat("SELECT IDACTION, ID, FORM, IDUSUARIO, DATA, ACAO, historico, maquina FROM actionlog WHERE 1=1 ", str1, str2, str); + using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter()) + { + sqlDataAdapter.SelectCommand = sqlCommand1; + sqlDataAdapter.Fill(dataTable); + } + } + } + registroAcaos = (dataTable.Rows.Count != 0 ? CustomMap.MapOldLogAcao(dataTable) : new List()); + } + catch (Exception exception) + { + registroAcaos = new List(); + } + return registroAcaos; + } + } +} \ No newline at end of file -- cgit v1.2.3