示例#1
0
        public IList <Processo> Pesquisar(PesquisaDossieViewModel filtros)
        {
            Processo         processo         = null;
            Lote             lote             = null;
            Pacote           pacote           = null;
            PacoteProcessado pacoteProcessado = null;
            DossieEsperado   dossieEsperado   = null;
            Ocorrencia       ultimaOcorrencia = null;

            var query = this.Session.QueryOver <Processo>(() => processo)
                        .JoinAlias(() => processo.Lote, () => lote)
                        .JoinAlias(() => lote.Pacote, () => pacote)
                        .Left.JoinAlias(() => lote.PacoteProcessado, () => pacoteProcessado)
                        .JoinAlias(() => lote.DossieEsperado, () => dossieEsperado)
                        .Fetch(x => x.Lote).Eager
                        .Fetch(x => x.Lote.Pacote).Eager
                        .Fetch(x => x.Lote.PacoteProcessado).Eager
                        .Fetch(x => x.Lote.DossieEsperado).Eager
                        .Fetch(x => x.Lote.LoteCef).Eager
                        .Left.JoinAlias(() => lote.DossieEsperado.UltimaOcorrencia, () => ultimaOcorrencia)
                        .Fetch(x => x.Lote.DossieEsperado.UltimaOcorrencia).Eager;

            ////if (string.IsNullOrEmpty(filtros.DataInicio) == false)
            ////{
            ////    query.Where(() => lote.DataCriacao >= filtros.ObjetoDataInicio());
            ////}

            ////if (string.IsNullOrEmpty(filtros.DataFim) == false)
            ////{
            ////    query.Where(() => lote.DataCriacao < filtros.ObjetoDataFim().AddDays(1));
            ////}

            ////if (string.IsNullOrEmpty(filtros.DataInicioMovimento) == false)
            ////{
            ////    query.Where(() => pacoteProcessado.ArquivoRecebidoEm >= filtros.ObjetoDataInicioMovimento());
            ////}

            ////if (string.IsNullOrEmpty(filtros.DataFimMovimento) == false)
            ////{
            ////    query.Where(() => pacoteProcessado.ArquivoRecebidoEm < filtros.ObjetoDataFimMovimento().AddDays(1));
            ////}

            if (string.IsNullOrEmpty(filtros.Identificacao) == false)
            {
                query.WhereRestrictionOn(() => lote.Identificacao).IsLike(".%" + filtros.Identificacao + "%-", MatchMode.Anywhere);
            }

            if (string.IsNullOrEmpty(filtros.IdentificacaoCompleta) == false)
            {
                query.Where(() => processo.Identificacao == filtros.IdentificacaoCompleta);
            }

            if (filtros.LoteId > 0)
            {
                query.Where(() => processo.Lote.Id == filtros.LoteId);
            }

            if (filtros.ProcessoId > 0)
            {
                query.Where(() => processo.Id == filtros.ProcessoId);
            }

            if (string.IsNullOrEmpty(filtros.FolderCompleto) == false)
            {
                query.Where(() => dossieEsperado.CodigoDeBarras == filtros.FolderCompleto);
            }

            if (string.IsNullOrEmpty(filtros.Agente) == false)
            {
                query.WhereRestrictionOn(x => x.Identificacao).IsLike(filtros.Agente + "%.", MatchMode.Anywhere);
            }

            if (string.IsNullOrEmpty(filtros.Contrato) == false)
            {
                query.WhereRestrictionOn(() => processo.Identificacao).IsInsensitiveLike(filtros.Contrato.ToUpper(), MatchMode.Anywhere);
            }

            if (filtros.TipoProcessoId > 0)
            {
                query.Where(() => processo.TipoDeProcesso.Id == filtros.TipoProcessoId);
            }

            if (string.IsNullOrEmpty(filtros.Caixa) == false)
            {
                query.WhereRestrictionOn(() => pacote.Identificacao).IsLike("%" + filtros.Caixa.ToUpper() + "%", MatchMode.Anywhere);
            }

            if (string.IsNullOrEmpty(filtros.Folder) == false)
            {
                query.WhereRestrictionOn(() => dossieEsperado.CodigoDeBarras).IsLike("%" + filtros.Folder.ToUpper() + "%", MatchMode.Anywhere);
            }

            if (filtros.ColetaId > 0)
            {
                query.Where(() => pacote.Coleta.Id == filtros.ColetaId);
            }

            if (filtros.LotecefId > 0)
            {
                query.Where(() => lote.LoteCef.Id == filtros.LotecefId);
            }

            if (string.IsNullOrEmpty(filtros.Fase) == false)
            {
                query.Where(() => lote.Status == LoteStatus.ObterPorSigla(filtros.Fase));
            }

            ////if (filtros.UltimoLoteId > 0)
            ////{
            ////    if (filtros.TipoDeOrdenacao == "A")
            ////    {
            ////        query.Where(() => lote.Id > filtros.UltimoLoteId);
            ////    }
            ////    else
            ////    {
            ////        query.Where(() => lote.Id < filtros.UltimoLoteId);
            ////    }
            ////}

            query.Where(() => lote.Status != LoteStatus.Excluido && lote.Status != LoteStatus.Erro);

            switch (filtros.ColunaDeOrdenacao)
            {
            case "tipo":
                if (filtros.TipoDeOrdenacao == "A")
                {
                    query.OrderBy(() => processo.TipoDeProcesso.Id).Asc();
                }
                else
                {
                    query.OrderBy(() => processo.TipoDeProcesso.Id).Desc();
                }

                break;

            case "identificacao":
                if (filtros.TipoDeOrdenacao == "A")
                {
                    query.OrderBy(() => processo.Identificacao).Asc();
                }
                else
                {
                    query.OrderBy(() => processo.Identificacao).Desc();
                }

                break;

            case "caixa":
                if (filtros.TipoDeOrdenacao == "A")
                {
                    query.OrderBy(() => pacote.Identificacao).Asc();
                }
                else
                {
                    query.OrderBy(() => pacote.Identificacao).Desc();
                }

                break;

            case "data":
                if (filtros.TipoDeOrdenacao == "A")
                {
                    query.OrderBy(() => lote.DataCriacao).Asc();
                }
                else
                {
                    query.OrderBy(() => lote.DataCriacao).Desc();
                }

                break;

            case "dataMovimento":
                if (filtros.TipoDeOrdenacao == "A")
                {
                    query.OrderBy(() => pacoteProcessado.ArquivoRecebidoEm).Asc();
                }
                else
                {
                    query.OrderBy(() => pacoteProcessado.ArquivoRecebidoEm).Desc();
                }

                break;

            case "status":
                if (filtros.TipoDeOrdenacao == "A")
                {
                    query.OrderBy(() => lote.Status).Asc().ThenBy(() => processo.Status).Asc();
                }
                else
                {
                    query.OrderBy(() => lote.Status).Desc().ThenBy(() => processo.Status).Desc();
                }

                break;

            default:
                if (filtros.TipoDeOrdenacao == "A")
                {
                    query.OrderBy(() => lote.Id).Asc();
                }
                else
                {
                    query.OrderBy(() => lote.Id).Desc();
                }

                break;
            }

            return(query
                   .TransformUsing(Transformers.DistinctRootEntity)
                   .Paginado(filtros.PaginaId, 30)
                   ////.Take(30)
                   .List());
        }