Esempio n. 1
0
        private async Task CarregaFechamentoTurma(FechamentoTurmaDisciplina fechamentoTurmaDisciplina, Turma turma, PeriodoEscolar periodoEscolar)
        {
            if (fechamentoTurmaDisciplina.Id > 0)
            {
                // Alterando registro de fechamento
                fechamentoTurmaDisciplina.FechamentoTurma.Turma            = turma;
                fechamentoTurmaDisciplina.FechamentoTurma.TurmaId          = turma.Id;
                fechamentoTurmaDisciplina.FechamentoTurma.PeriodoEscolar   = periodoEscolar;
                fechamentoTurmaDisciplina.FechamentoTurma.PeriodoEscolarId = periodoEscolar.Id;
            }
            else
            {
                // Incluindo registro de fechamento turma disciplina

                // Busca registro existente de fechamento da turma
                var fechamentoTurma = await repositorioFechamentoTurma.ObterPorTurmaPeriodo(turma.Id, periodoEscolar.Id);

                if (fechamentoTurma == null)
                {
                    fechamentoTurma = new FechamentoTurma(turma, periodoEscolar);
                }

                fechamentoTurmaDisciplina.FechamentoTurma = fechamentoTurma;
            }
        }
Esempio n. 2
0
 private string MontaTextoAuditoriaAlteracao(FechamentoTurmaDisciplina fechamentoTurmaDisciplina, bool EhNota)
 {
     if (fechamentoTurmaDisciplina != null && !string.IsNullOrEmpty(fechamentoTurmaDisciplina.AlteradoPor))
     {
         return($"{(EhNota ? "Notas" : "Conceitos")} finais {(EhNota ? "alteradas" : "alterados")} por {fechamentoTurmaDisciplina.AlteradoPor}({fechamentoTurmaDisciplina.AlteradoRF}) em {fechamentoTurmaDisciplina.AlteradoEm.Value.ToString("dd/MM/yyyy")},às {fechamentoTurmaDisciplina.AlteradoEm.Value.ToString("HH:mm")}.");
     }
     else
     {
         return(string.Empty);
     }
 }
Esempio n. 3
0
        private FechamentoTurmaDisciplina MapearParaEntidade(long id, FechamentoTurmaDisciplinaDto fechamentoDto)
        {
            var fechamento = new FechamentoTurmaDisciplina();

            if (id > 0)
            {
                fechamento = repositorioFechamentoTurmaDisciplina.ObterPorId(id);
            }

            fechamento.Turma        = repositorioTurma.ObterPorId(fechamentoDto.TurmaId);
            fechamento.TurmaId      = fechamento.Turma.Id;
            fechamento.DisciplinaId = fechamentoDto.DisciplinaId;

            return(fechamento);
        }
Esempio n. 4
0
        private string MontaTextoAuditoriaInclusao(FechamentoTurmaDisciplina fechamentoTurmaDisciplina, bool EhNota)
        {
            var criadorRf = fechamentoTurmaDisciplina != null && fechamentoTurmaDisciplina.CriadoRF != "0" && !string.IsNullOrEmpty(fechamentoTurmaDisciplina.CriadoRF) ?
                            $"({fechamentoTurmaDisciplina.CriadoRF})" : "";

            if (fechamentoTurmaDisciplina != null)
            {
                return($"{(EhNota ? "Notas" : "Conceitos")} finais {(EhNota ? "incluídas" : "incluídos")} por {fechamentoTurmaDisciplina.CriadoPor}{criadorRf} em {fechamentoTurmaDisciplina.CriadoEm.ToString("dd/MM/yyyy")},às {fechamentoTurmaDisciplina.CriadoEm.ToString("HH:mm")}.");
            }

            else
            {
                return(string.Empty);
            }
        }
Esempio n. 5
0
        private FechamentoTurmaDisciplina MapearParaEntidade(long id, FechamentoTurmaDisciplinaDto fechamentoDto)
        {
            var fechamento = new FechamentoTurmaDisciplina();

            if (id > 0)
            {
                fechamento = repositorioFechamentoTurmaDisciplina.ObterPorId(id);
            }

            fechamento.AtualizarSituacao(SituacaoFechamento.EmProcessamento);
            fechamento.DisciplinaId  = fechamentoDto.DisciplinaId;
            fechamento.Justificativa = fechamentoDto.Justificativa;

            return(fechamento);
        }
        public async Task <int> ValidarPercentualAlunosAbaixoDaMedia(FechamentoTurmaDisciplina fechamentoTurma)
        {
            if (!string.IsNullOrEmpty(fechamentoTurma.Justificativa))
            {
                var percentualReprovacao = double.Parse(await mediator.Send(new ObterValorParametroSistemaTipoEAnoQuery(TipoParametroSistema.PercentualAlunosInsuficientes, DateTime.Today.Year)));
                var mensagem             = new StringBuilder($"O fechamento do bimestre possui mais de {percentualReprovacao}% das notas consideradas insuficientes<br>");

                await GerarPendencia(fechamentoTurma.Id, TipoPendencia.ResultadosFinaisAbaixoDaMedia, mensagem.ToString(), fechamentoTurma.CriadoRF);

                alunosAbaixoMedia = 1;
            }
            else
            {
                alunosAbaixoMedia = 0;
                repositorioPendencia.AtualizarPendencias(fechamentoTurma.Id, SituacaoPendencia.Resolvida, TipoPendencia.ResultadosFinaisAbaixoDaMedia);
            }

            return(alunosAbaixoMedia);
        }
Esempio n. 7
0
        public async Task <List <string> > SalvarAsync(FechamentoTurmaDisciplina fechamentoFinal, Turma turma)
        {
            var mensagens = new List <string>();

            unitOfWork.IniciarTransacao();
            try
            {
                var fechamentoTurmaId = await repositorioFechamentoTurma.SalvarAsync(fechamentoFinal.FechamentoTurma);

                fechamentoFinal.FechamentoTurmaId = fechamentoTurmaId;
                var fechamentoTurmaDisciplinaId = await repositorioFechamentoTurmaDisciplina.SalvarAsync(fechamentoFinal);

                foreach (var fechamentoAluno in fechamentoFinal.FechamentoAlunos)
                {
                    try
                    {
                        fechamentoAluno.FechamentoTurmaDisciplinaId = fechamentoTurmaDisciplinaId;
                        var fechamentoAlunoId = await repositorioFechamentoAluno.SalvarAsync(fechamentoAluno);

                        foreach (var fechamentoNota in fechamentoAluno.FechamentoNotas)
                        {
                            try
                            {
                                if (turma.AnoLetivo == 2020)
                                {
                                    ValidarNotasFechamento2020(fechamentoNota);
                                }

                                fechamentoNota.FechamentoAlunoId = fechamentoAlunoId;
                                await repositorioFechamentoNota.SalvarAsync(fechamentoNota);
                            }
                            catch (NegocioException e)
                            {
                                servicoLog.Registrar(e);
                                mensagens.Add(e.Message);
                            }
                            catch (Exception e)
                            {
                                servicoLog.Registrar(e);
                                mensagens.Add($"Não foi possível salvar a nota do componente [{fechamentoNota.DisciplinaId}] aluno [{fechamentoAluno.AlunoCodigo}]");
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        servicoLog.Registrar(e);
                        mensagens.Add($"Não foi possível gravar o fechamento do aluno [{fechamentoAluno.AlunoCodigo}]");
                    }
                }
                unitOfWork.PersistirTransacao();

                await ExcluirPendenciaAusenciaFechamento(fechamentoFinal.DisciplinaId, fechamentoFinal.FechamentoTurma.TurmaId);

                return(mensagens);
            }
            catch (Exception e)
            {
                servicoLog.Registrar(e);

                unitOfWork.Rollback();
                throw e;
            }
        }
Esempio n. 8
0
        private async Task <FechamentoTurmaDisciplina> TransformarDtoSalvarEmEntidade(FechamentoFinalSalvarDto fechamentoFinalSalvarDto, Turma turma)
        {
            var disciplinaId = fechamentoFinalSalvarDto.EhRegencia ? long.Parse(fechamentoFinalSalvarDto.DisciplinaId) : fechamentoFinalSalvarDto.Itens.First().ComponenteCurricularCodigo;

            FechamentoTurmaDisciplina fechamentoTurmaDisciplina = null;
            var fechamentoFinalTurma = await repositorioFechamentoTurma.ObterPorTurmaPeriodo(turma.Id);

            if (fechamentoFinalTurma == null)
            {
                fechamentoFinalTurma = new FechamentoTurma(0, turma.Id);
            }
            else
            {
                fechamentoTurmaDisciplina = await repositorioFechamentoTurmaDisciplina.ObterFechamentoTurmaDisciplina(fechamentoFinalSalvarDto.TurmaCodigo, disciplinaId);
            }

            if (fechamentoTurmaDisciplina == null)
            {
                fechamentoTurmaDisciplina = new FechamentoTurmaDisciplina()
                {
                    DisciplinaId = disciplinaId, Situacao = SituacaoFechamento.ProcessadoComSucesso
                }
            }
            ;

            fechamentoTurmaDisciplina.FechamentoTurma = fechamentoFinalTurma;

            foreach (var agrupamentoAluno in fechamentoFinalSalvarDto.Itens.GroupBy(a => a.AlunoRf))
            {
                var fechamentoAluno = await repositorioFechamentoAluno.ObterFechamentoAlunoENotas(fechamentoTurmaDisciplina.Id, agrupamentoAluno.Key);

                if (fechamentoAluno == null)
                {
                    fechamentoAluno = new FechamentoAluno()
                    {
                        AlunoCodigo = agrupamentoAluno.Key
                    }
                }
                ;

                foreach (var fechamentoItemDto in agrupamentoAluno)
                {
                    var fechamentoNota = fechamentoAluno.FechamentoNotas.FirstOrDefault(c => c.DisciplinaId == fechamentoItemDto.ComponenteCurricularCodigo);

                    if (fechamentoNota != null)
                    {
                        if (fechamentoItemDto.Nota.HasValue)
                        {
                            if (fechamentoNota.Nota.Value != fechamentoItemDto.Nota.Value)
                            {
                                await mediator.Send(new SalvarHistoricoNotaFechamentoCommand(fechamentoNota.Nota.Value, fechamentoItemDto.Nota.Value, fechamentoNota.Id));
                            }
                        }
                        else
                        if (fechamentoNota.ConceitoId.Value != fechamentoItemDto.ConceitoId.Value)
                        {
                            await mediator.Send(new SalvarHistoricoConceitoFechamentoCommand(fechamentoNota.ConceitoId.Value, fechamentoItemDto.ConceitoId.Value, fechamentoNota.Id));
                        }
                    }

                    MapearParaEntidade(fechamentoNota, fechamentoItemDto, fechamentoAluno);
                }

                fechamentoTurmaDisciplina.FechamentoAlunos.Add(fechamentoAluno);
            }
            return(fechamentoTurmaDisciplina);
        }
Esempio n. 9
0
        private async Task GerarNotificacaoFechamento(FechamentoTurmaDisciplina fechamentoTurmaDisciplina, Turma turma, int quantidadePendencias, Usuario usuarioLogado, PeriodoEscolar periodoEscolar)
        {
            var componentes = await repositorioComponenteCurricular.ObterDisciplinasPorIds(new long[] { fechamentoTurmaDisciplina.DisciplinaId });

            if (componentes == null || !componentes.Any())
            {
                throw new NegocioException("Componente curricular não encontrado.");
            }
            var ue = turma.Ue;

            if (ue == null)
            {
                throw new NegocioException("UE não encontrada.");
            }

            var dre = ue.Dre;

            if (dre == null)
            {
                throw new NegocioException("DRE não encontrada.");
            }

            var urlFrontEnd = configuration["UrlFrontEnd"];

            if (string.IsNullOrWhiteSpace(urlFrontEnd))
            {
                throw new NegocioException("Url do frontend não encontrada.");
            }

            var notificacao = new Notificacao()
            {
                UsuarioId = usuarioLogado.Id,
                Ano       = DateTime.Now.Year,
                Categoria = NotificacaoCategoria.Aviso,
                Titulo    = $"Pendência no fechamento da turma {turma.Nome}",
                Tipo      = NotificacaoTipo.Fechamento,
                Mensagem  = $"O fechamento do {periodoEscolar.Bimestre}º bimestre de {componentes.FirstOrDefault().Nome} da turma {turma.Nome} da {ue.Nome} ({dre.Nome}) gerou {quantidadePendencias} pendência(s). " +
                            $"Clique <a href='{urlFrontEnd}fechamento/pendencias-fechamento/{periodoEscolar.Bimestre}/{fechamentoTurmaDisciplina.DisciplinaId}'>aqui</a> para mais detalhes."
            };

            servicoNotificacao.Salvar(notificacao);

            var diretores = servicoEOL.ObterFuncionariosPorCargoUe(ue.CodigoUe, (long)Cargo.Diretor);

            if (diretores != null)
            {
                foreach (var diretor in diretores)
                {
                    var notificacaoDiretor = notificacao;
                    notificacaoDiretor.Id = 0;
                    var usuario = servicoUsuario.ObterUsuarioPorCodigoRfLoginOuAdiciona(diretor.CodigoRf);
                    notificacaoDiretor.UsuarioId = usuario.Id;
                    servicoNotificacao.Salvar(notificacaoDiretor);
                }
            }

            var cps = servicoEOL.ObterFuncionariosPorCargoUe(ue.CodigoUe, (long)Cargo.CP);

            if (cps != null)
            {
                foreach (var cp in cps)
                {
                    var notificacaoCp = notificacao;
                    notificacaoCp.Id = 0;
                    var usuario = servicoUsuario.ObterUsuarioPorCodigoRfLoginOuAdiciona(cp.CodigoRf);
                    notificacaoCp.UsuarioId = usuario.Id;
                    servicoNotificacao.Salvar(notificacaoCp);
                }
            }
        }
Esempio n. 10
0
        public async Task GerarPendenciasFechamento(long disciplinaId, Turma turma, PeriodoEscolar periodoEscolar, FechamentoTurmaDisciplina fechamento, Usuario usuarioLogado, bool componenteSemNota = false, bool registraFrequencia = true)
        {
            var situacaoFechamento = SituacaoFechamento.ProcessadoComSucesso;

            if (!componenteSemNota)
            {
                await servicoPendenciaFechamento.ValidarAvaliacoesSemNotasParaNenhumAluno(fechamento.Id, turma.CodigoTurma, disciplinaId, periodoEscolar.PeriodoInicio, periodoEscolar.PeriodoFim);

                await servicoPendenciaFechamento.ValidarPercentualAlunosAbaixoDaMedia(fechamento);

                await servicoPendenciaFechamento.ValidarAlteracaoExtemporanea(fechamento.Id, turma.CodigoTurma, fechamento.CriadoRF);
            }
            await servicoPendenciaFechamento.ValidarAulasReposicaoPendente(fechamento.Id, turma, disciplinaId, periodoEscolar.PeriodoInicio, periodoEscolar.PeriodoFim);

            await servicoPendenciaFechamento.ValidarAulasSemPlanoAulaNaDataDoFechamento(fechamento.Id, turma, disciplinaId, periodoEscolar.PeriodoInicio, periodoEscolar.PeriodoFim);

            if (registraFrequencia)
            {
                await servicoPendenciaFechamento.ValidarAulasSemFrequenciaRegistrada(fechamento.Id, turma, disciplinaId, periodoEscolar.PeriodoInicio, periodoEscolar.PeriodoFim);
            }

            var quantidadePendencias = servicoPendenciaFechamento.ObterQuantidadePendenciasGeradas();

            if (quantidadePendencias > 0)
            {
                situacaoFechamento = SituacaoFechamento.ProcessadoComPendencias;
                await GerarNotificacaoFechamento(fechamento, turma, quantidadePendencias, usuarioLogado, periodoEscolar);
            }

            fechamento.AtualizarSituacao(situacaoFechamento);
            await repositorioFechamentoTurmaDisciplina.SalvarAsync(fechamento);
        }
Esempio n. 11
0
        public async Task <ConselhoClasseNotaRetornoDto> SalvarConselhoClasseAlunoNotaAsync(ConselhoClasseNotaDto conselhoClasseNotaDto, string alunoCodigo, long conselhoClasseId, long fechamentoTurmaId, string codigoTurma, int bimestre)
        {
            var conselhoClasseNota = new ConselhoClasseNota();

            var fechamentoTurma = await repositorioFechamentoTurma.ObterCompletoPorIdAsync(fechamentoTurmaId);

            var fechamentoTurmaDisciplina = new FechamentoTurmaDisciplina();

            if (fechamentoTurma == null)
            {
                var turma = await consultasTurma.ObterPorCodigo(codigoTurma);

                if (turma == null)
                {
                    throw new NegocioException("Turma não encontrada");
                }

                var ue = repositorioUe.ObterPorId(turma.UeId);
                ue.AdicionarDre(repositorioDre.ObterPorId(ue.DreId));
                turma.AdicionarUe(ue);

                if (turma.AnoLetivo == DateTime.Today.Year)
                {
                    throw new NegocioException("Não existe fechamento de turma para o conselho de classe");
                }

                var tipoCalendario = await repositorioTipoCalendario.BuscarPorAnoLetivoEModalidade(turma.AnoLetivo, turma.ModalidadeTipoCalendario, turma.Semestre);

                if (tipoCalendario == null)
                {
                    throw new NegocioException("Tipo calendário não encontrado");
                }

                var periodoEscolar = await consultasPeriodoEscolar.ObterPeriodoEscolarPorTipoCalendarioBimestre(tipoCalendario.Id, bimestre);

                fechamentoTurma = new FechamentoTurma()
                {
                    TurmaId          = turma.Id,
                    Migrado          = false,
                    PeriodoEscolarId = periodoEscolar?.Id,
                    Turma            = turma,
                    PeriodoEscolar   = periodoEscolar
                };

                fechamentoTurmaDisciplina = new FechamentoTurmaDisciplina()
                {
                    DisciplinaId = conselhoClasseNotaDto.CodigoComponenteCurricular
                };
            }
            try
            {
                unitOfWork.IniciarTransacao();
                if (fechamentoTurmaDisciplina.DisciplinaId > 0)
                {
                    await repositorioFechamentoTurma.SalvarAsync(fechamentoTurma);

                    fechamentoTurmaDisciplina.FechamentoTurmaId = fechamentoTurma.Id;
                    await repositorioFechamentoTurmaDisciplina.SalvarAsync(fechamentoTurmaDisciplina);
                }
                if (fechamentoTurma.PeriodoEscolarId.HasValue)
                {
                    // Fechamento Bimestral
                    if (!await consultasPeriodoFechamento.TurmaEmPeriodoDeFechamento(fechamentoTurma.Turma, DateTime.Today, fechamentoTurma.PeriodoEscolar.Bimestre))
                    {
                        throw new NegocioException($"Turma {fechamentoTurma.Turma.Nome} não esta em período de fechamento para o {fechamentoTurma.PeriodoEscolar.Bimestre}º Bimestre!");
                    }
                }
                else
                {
                    // Fechamento Final
                    if (fechamentoTurma.Turma.AnoLetivo != 2020)
                    {
                        var validacaoConselhoFinal = await consultasConselhoClasse.ValidaConselhoClasseUltimoBimestre(fechamentoTurma.Turma);

                        if (!validacaoConselhoFinal.Item2 && fechamentoTurma.Turma.AnoLetivo == DateTime.Today.Year)
                        {
                            throw new NegocioException($"Para acessar este aba você precisa registrar o conselho de classe do {validacaoConselhoFinal.Item1}º bimestre");
                        }
                    }
                }
                unitOfWork.PersistirTransacao();
            }
            catch (Exception e)
            {
                unitOfWork.Rollback();
                throw e;
            }

            long conselhoClasseAlunoId = 0;

            try
            {
                if (conselhoClasseId == 0)
                {
                    var conselhoClasse = new ConselhoClasse();
                    conselhoClasse.FechamentoTurmaId = fechamentoTurma.Id;

                    unitOfWork.IniciarTransacao();
                    await repositorioConselhoClasse.SalvarAsync(conselhoClasse);

                    conselhoClasseId = conselhoClasse.Id;

                    conselhoClasseAlunoId = await SalvarConselhoClasseAlunoResumido(conselhoClasse.Id, alunoCodigo);

                    conselhoClasseNota = ObterConselhoClasseNota(conselhoClasseNotaDto, conselhoClasseAlunoId);

                    if (fechamentoTurma.Turma.AnoLetivo == 2020)
                    {
                        ValidarNotasFechamentoConselhoClasse2020(conselhoClasseNota);
                    }

                    await repositorioConselhoClasseNota.SalvarAsync(conselhoClasseNota);

                    unitOfWork.PersistirTransacao();
                }
                else
                {
                    var conselhoClasseAluno = await repositorioConselhoClasseAluno.ObterPorConselhoClasseAlunoCodigoAsync(conselhoClasseId, alunoCodigo);

                    unitOfWork.IniciarTransacao();

                    conselhoClasseAlunoId = conselhoClasseAluno != null ? conselhoClasseAluno.Id : await SalvarConselhoClasseAlunoResumido(conselhoClasseId, alunoCodigo);

                    conselhoClasseNota = await repositorioConselhoClasseNota.ObterPorConselhoClasseAlunoComponenteCurricularAsync(conselhoClasseAlunoId, conselhoClasseNotaDto.CodigoComponenteCurricular);

                    if (conselhoClasseNota == null)
                    {
                        conselhoClasseNota = ObterConselhoClasseNota(conselhoClasseNotaDto, conselhoClasseAlunoId);
                    }
                    else
                    {
                        conselhoClasseNota.Justificativa = conselhoClasseNotaDto.Justificativa;
                        if (conselhoClasseNotaDto.Nota.HasValue)
                        {
                            // Gera histórico de alteração
                            if (conselhoClasseNota.Nota != conselhoClasseNotaDto.Nota.Value)
                            {
                                await mediator.Send(new SalvarHistoricoNotaConselhoClasseCommand(conselhoClasseNota.Id, conselhoClasseNota.Nota.Value, conselhoClasseNotaDto.Nota.Value));
                            }

                            conselhoClasseNota.Nota = conselhoClasseNotaDto.Nota.Value;
                        }
                        else
                        {
                            conselhoClasseNota.Nota = null;
                        }

                        if (conselhoClasseNotaDto.Conceito.HasValue)
                        {
                            // Gera histórico de alteração
                            if (conselhoClasseNota.ConceitoId != conselhoClasseNotaDto.Conceito.Value)
                            {
                                await mediator.Send(new SalvarHistoricoConceitoConselhoClasseCommand(conselhoClasseNota.Id, conselhoClasseNota.ConceitoId.Value, conselhoClasseNotaDto.Conceito.Value));
                            }

                            conselhoClasseNota.ConceitoId = conselhoClasseNotaDto.Conceito.Value;
                        }
                    }

                    if (fechamentoTurma.Turma.AnoLetivo == 2020)
                    {
                        ValidarNotasFechamentoConselhoClasse2020(conselhoClasseNota);
                    }

                    await repositorioConselhoClasseNota.SalvarAsync(conselhoClasseNota);

                    unitOfWork.PersistirTransacao();
                }
            }
            catch (Exception e)
            {
                unitOfWork.Rollback();
                throw e;
            }

            // TODO Verificar se o fechamentoTurma.Turma carregou UE
            if (await VerificaNotasTodosComponentesCurriculares(alunoCodigo, fechamentoTurma.Turma, fechamentoTurma.PeriodoEscolarId))
            {
                await VerificaRecomendacoesAluno(conselhoClasseAlunoId);
            }

            var usuarioLogado = await mediator.Send(new ObterUsuarioLogadoQuery());

            await mediator.Send(new PublicaFilaAtualizacaoSituacaoConselhoClasseCommand(conselhoClasseId, usuarioLogado));

            var auditoria = (AuditoriaDto)conselhoClasseNota;
            var conselhoClasseNotaRetorno = new ConselhoClasseNotaRetornoDto()
            {
                ConselhoClasseId  = conselhoClasseId,
                FechamentoTurmaId = fechamentoTurma.Id,
                Auditoria         = auditoria
            };

            return(conselhoClasseNotaRetorno);
        }