private async Task <IEnumerable <FechamentoAluno> > AtualizaSinteseAlunos(long fechamentoTurmaDisciplinaId, DateTime dataReferencia, DisciplinaDto disciplina) { var fechamentoAlunos = await repositorioFechamentoAluno.ObterPorFechamentoTurmaDisciplina(fechamentoTurmaDisciplinaId); foreach (var fechamentoAluno in fechamentoAlunos) { foreach (var fechamentoNota in fechamentoAluno.FechamentoNotas) { var frequencia = consultasFrequencia.ObterPorAlunoDisciplinaData(fechamentoAluno.AlunoCodigo, fechamentoNota.DisciplinaId.ToString(), dataReferencia); var sinteseDto = consultasFrequencia.ObterSinteseAluno(frequencia.PercentualFrequencia, disciplina); fechamentoNota.SinteseId = (long)sinteseDto.Id; } } return(fechamentoAlunos); }
public async Task <CompensacaoAusenciaCompletoDto> ObterPorId(long id) { var compensacao = repositorioCompensacaoAusencia.ObterPorId(id); if (compensacao == null) { throw new NegocioException("Compensação de ausencia não localizada."); } var compensacaoDto = MapearParaDtoCompleto(compensacao); compensacao.Alunos = await consultasCompensacaoAusenciaAluno.ObterPorCompensacao(compensacao.Id); // Busca os nomes de alunos do EOL por turma var turma = await repositorioTurma.ObterPorId(compensacao.TurmaId); compensacaoDto.TurmaId = turma.CodigoTurma; var alunos = await servicoEOL.ObterAlunosPorTurma(turma.CodigoTurma); if (alunos == null) { throw new NegocioException("Alunos não localizados para a turma."); } var disciplinasEOL = await repositorioComponenteCurricular.ObterDisciplinasPorIds(new long[] { long.Parse(compensacao.DisciplinaId) }); if (disciplinasEOL == null || !disciplinasEOL.Any()) { throw new NegocioException("Disciplina informada na compensação não localizada no EOL."); } var quantidadeMaximaCompensacoes = int.Parse(await mediator.Send(new ObterValorParametroSistemaTipoEAnoQuery(TipoParametroSistema.QuantidadeMaximaCompensacaoAusencia, DateTime.Today.Year))); var percentualFrequenciaAlerta = int.Parse(await mediator.Send(new ObterValorParametroSistemaTipoEAnoQuery(disciplinasEOL.First().Regencia ? TipoParametroSistema.CompensacaoAusenciaPercentualRegenciaClasse : TipoParametroSistema.CompensacaoAusenciaPercentualFund2, DateTime.Today.Year))); foreach (var aluno in compensacao.Alunos) { // Adiciona nome do aluno no Dto de retorno var alunoEol = alunos.FirstOrDefault(a => a.CodigoAluno == aluno.CodigoAluno); if (alunoEol != null) { var alunoDto = MapearParaDtoAlunos(aluno); alunoDto.Nome = alunoEol.NomeAluno; var frequenciaAluno = consultasFrequencia.ObterPorAlunoDisciplinaData(aluno.CodigoAluno, compensacao.DisciplinaId, DateTime.Now); if (frequenciaAluno != null) { alunoDto.QuantidadeFaltasTotais = int.Parse((frequenciaAluno.NumeroFaltasNaoCompensadas + alunoDto.QuantidadeFaltasCompensadas).ToString()); alunoDto.PercentualFrequencia = frequenciaAluno.PercentualFrequencia; alunoDto.MaximoCompensacoesPermitidas = quantidadeMaximaCompensacoes > alunoDto.QuantidadeFaltasTotais ? alunoDto.QuantidadeFaltasTotais : quantidadeMaximaCompensacoes; alunoDto.Alerta = frequenciaAluno.PercentualFrequencia <= percentualFrequenciaAlerta; } else { alunoDto.PercentualFrequencia = 100; } compensacaoDto.Alunos.Add(alunoDto); } } if (disciplinasEOL.First().Regencia) { var disciplinasRegencia = await consultasCompensacaoAusenciaDisciplinaRegencia.ObterPorCompensacao(compensacao.Id); var disciplinasIds = disciplinasRegencia.Select(x => long.Parse(x.DisciplinaId)); if (!disciplinasIds.Any()) { return(compensacaoDto); } disciplinasEOL = await repositorioComponenteCurricular.ObterDisciplinasPorIds(disciplinasIds.ToArray()); foreach (var disciplinaEOL in disciplinasEOL) { compensacaoDto.DisciplinasRegencia.Add(new DisciplinaNomeDto() { Codigo = disciplinaEOL.CodigoComponenteCurricular.ToString(), Nome = disciplinaEOL.Nome }); } } return(compensacaoDto); }
public async Task <FechamentoTurmaDisciplinaBimestreDto> ObterNotasFechamentoTurmaDisciplina(string turmaId, long disciplinaId, int?bimestre, int semestre) { var turma = await repositorioTurma.ObterPorCodigo(turmaId); var tipoCalendario = await repositorioTipoCalendario.BuscarPorAnoLetivoEModalidade(turma.AnoLetivo, ModalidadeParaModalidadeTipoCalendario(turma.ModalidadeCodigo), semestre); if (tipoCalendario == null) { throw new NegocioException("Não foi encontrado tipo de calendário escolar, para a modalidade informada."); } var periodosEscolares = await repositorioPeriodoEscolar.ObterPorTipoCalendario(tipoCalendario.Id); if (periodosEscolares == null || !periodosEscolares.Any()) { throw new NegocioException("Não foi encontrado período Escolar para a modalidade informada."); } var bimestreAtual = bimestre; if (!bimestreAtual.HasValue || bimestre == 0) { bimestreAtual = ObterBimestreAtual(periodosEscolares); } var periodoAtual = periodosEscolares.FirstOrDefault(x => x.Bimestre == bimestreAtual); if (periodoAtual == null) { throw new NegocioException("Não foi encontrado período escolar para o bimestre solicitado."); } // Carrega alunos var alunos = await servicoEOL.ObterAlunosPorTurma(turma.CodigoTurma, turma.AnoLetivo); if (alunos == null || !alunos.Any()) { throw new NegocioException("Não foi encontrado alunos para a turma informada"); } // DTO de retorno var fechamentoBimestre = new FechamentoTurmaDisciplinaBimestreDto() { Bimestre = bimestreAtual.Value, Periodo = tipoCalendario.Periodo, TotalAulasDadas = 0, // Carregar TotalAulasPrevistas = 0, // Carregar Alunos = new List <NotaConceitoAlunoBimestreDto>() }; var disciplinaEOL = await consultasDisciplina.ObterDisciplina(disciplinaId); IEnumerable <DisciplinaResposta> disciplinasRegencia = null; if (disciplinaEOL.Regencia) { disciplinasRegencia = await servicoEOL.ObterDisciplinasParaPlanejamento(long.Parse(turmaId), servicoUsuario.ObterLoginAtual(), servicoUsuario.ObterPerfilAtual()); } fechamentoBimestre.EhSintese = !disciplinaEOL.LancaNota; // Carrega fechamento da Turma x Disciplina x Bimestre var fechamentosTurma = await ObterFechamentosTurmaDisciplina(turmaId, disciplinaId.ToString(), bimestreAtual.Value); if ((fechamentosTurma != null && fechamentosTurma.Any()) || fechamentoBimestre.EhSintese) { if (fechamentosTurma != null && fechamentosTurma.Any()) { fechamentoBimestre.Situacao = fechamentosTurma.First().Situacao; fechamentoBimestre.SituacaoNome = fechamentosTurma.First().Situacao.Name(); fechamentoBimestre.FechamentoId = fechamentosTurma.First().Id; fechamentoBimestre.DataFechamento = fechamentosTurma.First().AlteradoEm.HasValue ? fechamentosTurma.First().AlteradoEm.Value : fechamentosTurma.First().CriadoEm; } fechamentoBimestre.Alunos = new List <NotaConceitoAlunoBimestreDto>(); var bimestreDoPeriodo = await consultasPeriodoEscolar.ObterPeriodoEscolarPorData(tipoCalendario.Id, periodoAtual.PeriodoFim); foreach (var aluno in alunos.Where(a => a.NumeroAlunoChamada > 0 || a.CodigoSituacaoMatricula.Equals(SituacaoMatriculaAluno.Ativo)).OrderBy(a => a.NumeroAlunoChamada).ThenBy(a => a.NomeValido())) { var fechamentoTurma = (from ft in fechamentosTurma from fa in ft.FechamentoAlunos where fa.AlunoCodigo.Equals(aluno.CodigoAluno) select ft).FirstOrDefault(); var alunoDto = new NotaConceitoAlunoBimestreDto(); alunoDto.CodigoAluno = aluno.CodigoAluno; alunoDto.NumeroChamada = aluno.NumeroAlunoChamada; alunoDto.Nome = aluno.NomeAluno; alunoDto.Ativo = aluno.CodigoSituacaoMatricula.Equals(SituacaoMatriculaAluno.Ativo); var anotacaoAluno = await consultasFehcamentoAluno.ObterAnotacaoPorAlunoEFechamento(fechamentoTurma?.Id ?? 0, aluno.CodigoAluno); alunoDto.TemAnotacao = anotacaoAluno != null && anotacaoAluno.Anotacao != null && !string.IsNullOrEmpty(anotacaoAluno.Anotacao.Trim()); var marcador = servicoAluno.ObterMarcadorAluno(aluno, bimestreDoPeriodo); if (marcador != null) { alunoDto.Informacao = marcador.Descricao; } var frequenciaAluno = consultasFrequencia.ObterPorAlunoDisciplinaData(aluno.CodigoAluno, disciplinaId.ToString(), periodoAtual.PeriodoFim); if (frequenciaAluno != null) { alunoDto.QuantidadeFaltas = frequenciaAluno.TotalAusencias; alunoDto.QuantidadeCompensacoes = frequenciaAluno.TotalCompensacoes; alunoDto.PercentualFrequencia = frequenciaAluno.PercentualFrequencia; } else { // Quando não tem registro de frequencia assume 100% alunoDto.QuantidadeFaltas = 0; alunoDto.QuantidadeCompensacoes = 0; alunoDto.PercentualFrequencia = 100; } // Carrega Frequencia do aluno if (aluno.CodigoAluno != null) { if (fechamentoBimestre.EhSintese && fechamentoTurma == null) { var sinteseDto = await consultasFrequencia.ObterSinteseAluno(alunoDto.PercentualFrequencia, disciplinaEOL); alunoDto.SinteseId = sinteseDto.Id; alunoDto.Sintese = sinteseDto.Valor; } else { // Carrega notas do bimestre var notasConceitoBimestre = await ObterNotasBimestre(aluno.CodigoAluno, fechamentoTurma != null?fechamentoTurma.Id : 0); if (notasConceitoBimestre.Any()) { alunoDto.Notas = new List <FechamentoNotaRetornoDto>(); } if (fechamentoBimestre.EhSintese) { var notaConceitoBimestre = notasConceitoBimestre.FirstOrDefault(); if (notaConceitoBimestre != null && notaConceitoBimestre.SinteseId.HasValue) { alunoDto.SinteseId = (SinteseEnum)notaConceitoBimestre.SinteseId.Value; alunoDto.Sintese = ObterSintese(notaConceitoBimestre.SinteseId.Value); } } else { foreach (var notaConceitoBimestre in notasConceitoBimestre) { string nomeDisciplina; if (disciplinaEOL.Regencia) { nomeDisciplina = disciplinasRegencia.FirstOrDefault(a => a.CodigoComponenteCurricular == notaConceitoBimestre.DisciplinaId)?.Nome; } else { nomeDisciplina = disciplinaEOL.Nome; } ((List <FechamentoNotaRetornoDto>)alunoDto.Notas).Add(new FechamentoNotaRetornoDto() { DisciplinaId = notaConceitoBimestre.DisciplinaId, Disciplina = nomeDisciplina, NotaConceito = notaConceitoBimestre.ConceitoId.HasValue ? ObterConceito(notaConceitoBimestre.ConceitoId.Value) : notaConceitoBimestre.Nota, EhConceito = notaConceitoBimestre.ConceitoId.HasValue, ConceitoDescricao = notaConceitoBimestre.ConceitoId.HasValue ? ObterConceitoDescricao(notaConceitoBimestre.ConceitoId.Value) : string.Empty }); } } } fechamentoBimestre.Alunos.Add(alunoDto); } } } var aulaPrevisa = await consultasAulaPrevista.ObterAulaPrevistaDada(turma.ModalidadeCodigo, turma.CodigoTurma, disciplinaId.ToString(), semestre); var aulaPrevistaBimestreAtual = new AulasPrevistasDadasDto(); if (aulaPrevisa != null) { aulaPrevistaBimestreAtual = aulaPrevisa.AulasPrevistasPorBimestre.FirstOrDefault(a => a.Bimestre == bimestreAtual); } fechamentoBimestre.Bimestre = bimestreAtual.Value; fechamentoBimestre.TotalAulasDadas = aulaPrevistaBimestreAtual.Cumpridas; fechamentoBimestre.TotalAulasPrevistas = aulaPrevistaBimestreAtual.Previstas.Quantidade; fechamentoBimestre.PodeProcessarReprocessar = await consultasFechamento.TurmaEmPeriodoDeFechamento(turma.CodigoTurma, DateTime.Today, bimestreAtual.Value); return(fechamentoBimestre); }