private async Task <IEnumerable <DataAulasProfessorDto> > ObterAulasNosPeriodos(PeriodoEscolarListaDto periodosEscolares, int anoLetivo, string turmaCodigo, string disciplinaCodigo, Usuario usuarioLogado, string usuarioRF) { if (disciplinaCodigo.ToCharArray().Any(a => !char.IsDigit(a))) { throw new NegocioException("Código da disciplina inválido"); } var disciplina = await consultasDisciplina.ObterDisciplina(Convert.ToInt64(disciplinaCodigo)); if (disciplina == null) { throw new NegocioException("Disciplina não encontrada"); } var aulasRetorno = new List <DataAulasProfessorDto>(); periodosEscolares.Periodos.ForEach(p => { var aulas = repositorio .ObterDatasDeAulasPorAnoTurmaEDisciplina(p.Id, anoLetivo, turmaCodigo, disciplinaCodigo, disciplina.Regencia ? string.Empty : usuarioRF, usuarioLogado.EhProfessorCj(), usuarioLogado.EhProfessor() || usuarioLogado.EhProfessorCj()); aulas.ToList().ForEach(aula => { if (!disciplina.Regencia) { aulasRetorno.Add(MapearParaDto(aula, p.Bimestre)); } var rfsOrnedadosPorDataCriacaoAula = aulas.OrderBy(a => a.CriadoEm) .Select(a => a.ProfessorRf).Distinct(); var ultimoRegente = rfsOrnedadosPorDataCriacaoAula.Last(); // se regente atual, titular anterior ou professor anterior visualiza a aula if (ultimoRegente.Equals(usuarioRF, StringComparison.InvariantCultureIgnoreCase) || aula.ProfessorRf.Equals(usuarioRF, StringComparison.InvariantCultureIgnoreCase) || aula.Turma.EhTurmaInfantil || usuarioLogado.PerfilAtual != Perfis.PERFIL_PROFESSOR || usuarioLogado.PerfilAtual != Perfis.PERFIL_CJ || usuarioLogado.PerfilAtual != Perfis.PERFIL_CJ_INFANTIL ) { aulasRetorno.Add(MapearParaDto(aula, p.Bimestre)); } }); }); return(aulasRetorno.OrderBy(a => a.Data)); }
public async Task <FechamentoFinalConsultaRetornoDto> ObterFechamentos(FechamentoFinalConsultaFiltroDto filtros) { var retorno = new FechamentoFinalConsultaRetornoDto(); var turma = await repositorioTurma.ObterTurmaComUeEDrePorCodigo(filtros.TurmaCodigo); if (turma == null) { throw new NegocioException("Não foi possível localizar a turma."); } var tipoCalendario = await repositorioTipoCalendario.BuscarPorAnoLetivoEModalidade(turma.AnoLetivo, turma.ObterModalidadeTipoCalendario()); 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."); } if (turma.AnoLetivo != 2020) { await VerificaSePodeFazerFechamentoFinal(periodosEscolares, turma); } var ultimoPeriodoEscolar = periodosEscolares.OrderByDescending(a => a.Bimestre).FirstOrDefault(); retorno.EventoData = ultimoPeriodoEscolar.PeriodoFim; var alunosDaTurma = await servicoEOL.ObterAlunosPorTurma(turma.CodigoTurma); if (alunosDaTurma == null || !alunosDaTurma.Any()) { throw new NegocioException("Não foram encontrandos alunos para a turma informada."); } var tipoNota = repositorioNotaTipoValor.ObterPorTurmaId(turma.Id); if (tipoNota == null) { throw new NegocioException("Não foi possível localizar o tipo de nota para esta turma."); } retorno.EhNota = tipoNota.EhNota(); //Codigo aluno / NotaConceito / Código Disciplina / bimestre var listaAlunosNotas = new List <(string, string, long, int)>(); var disciplinas = new List <DisciplinaResposta>(); var disciplinaEOL = await consultasDisciplina.ObterDisciplina(filtros.DisciplinaCodigo); var usuarioAtual = await servicoUsuario.ObterUsuarioLogado(); if (filtros.EhRegencia) { var disciplinasRegencia = await consultasDisciplina.ObterComponentesRegencia(turma, filtros.DisciplinaCodigo); if (disciplinasRegencia == null || !disciplinasRegencia.Any()) { throw new NegocioException("Não foram encontrados componentes curriculares para a regência informada."); } disciplinas.AddRange(disciplinasRegencia); } else { disciplinas.Add(new DisciplinaResposta() { Nome = disciplinaEOL.Nome, CodigoComponenteCurricular = disciplinaEOL.CodigoComponenteCurricular }); } retorno.EhSintese = !disciplinaEOL.LancaNota; var fechamentosTurmaDisciplina = await repositorioFechamentoTurmaDisciplina.ObterFechamentosTurmaDisciplinas(turma.CodigoTurma, new long[] { filtros.DisciplinaCodigo }); var notasFechamentosFinais = Enumerable.Empty <FechamentoNota>(); if (fechamentosTurmaDisciplina != null && fechamentosTurmaDisciplina.Any()) { notasFechamentosFinais = await repositorioFechamentoNota.ObterPorFechamentosTurma(fechamentosTurmaDisciplina.Select(ftd => ftd.Id).ToArray()); } var notasFechamentosBimestres = Enumerable.Empty <FechamentoNotaAlunoDto>(); if (!retorno.EhSintese) { notasFechamentosBimestres = await ObterNotasFechamentosBimestres(filtros.DisciplinaCodigo, turma, periodosEscolares, retorno.EhNota); } var usuarioEPeriodoPodeEditar = await PodeEditarNotaOuConceitoPeriodoUsuario(usuarioAtual, ultimoPeriodoEscolar, turma, filtros.DisciplinaCodigo.ToString(), retorno.EventoData); foreach (var aluno in alunosDaTurma.Where(a => a.NumeroAlunoChamada > 0 || a.CodigoSituacaoMatricula.Equals(SituacaoMatriculaAluno.Ativo)).OrderBy(a => a.NumeroAlunoChamada).ThenBy(a => a.NomeValido())) { FechamentoFinalConsultaRetornoAlunoDto fechamentoFinalAluno = await TrataFrequenciaAluno(filtros, periodosEscolares, aluno, turma); var marcador = servicoAluno.ObterMarcadorAluno(aluno, new PeriodoEscolar() { PeriodoFim = retorno.EventoData }); if (marcador != null) { fechamentoFinalAluno.Informacao = marcador.Descricao; } if (retorno.EhSintese) { var sinteseDto = await consultasFrequencia.ObterSinteseAluno(fechamentoFinalAluno.Frequencia, disciplinaEOL); fechamentoFinalAluno.Sintese = sinteseDto.Valor; } else { foreach (var periodo in periodosEscolares.OrderBy(a => a.Bimestre)) { foreach (var disciplinaParaAdicionar in disciplinas) { //BIMESTRE / NOTA / DISCIPLINA ID / ALUNO CODIGO var nota = notasFechamentosBimestres.FirstOrDefault(a => a.Bimestre == periodo.Bimestre && a.DisciplinaId == disciplinaParaAdicionar.CodigoComponenteCurricular && a.AlunoCodigo == aluno.CodigoAluno); var notaParaAdicionar = (nota == null ? null : nota.NotaConceito); fechamentoFinalAluno.NotasConceitoBimestre.Add(new FechamentoFinalConsultaRetornoAlunoNotaConceitoDto() { Bimestre = periodo.Bimestre, Disciplina = disciplinaParaAdicionar.Nome, DisciplinaCodigo = disciplinaParaAdicionar.CodigoComponenteCurricular, NotaConceito = notaParaAdicionar }); } } foreach (var disciplinaParaAdicionar in disciplinas) { var nota = notasFechamentosFinais.FirstOrDefault(a => a.DisciplinaId == disciplinaParaAdicionar.CodigoComponenteCurricular && a.FechamentoAluno.AlunoCodigo == aluno.CodigoAluno); string notaParaAdicionar = string.Empty; if (nota != null) { notaParaAdicionar = (tipoNota.EhNota() ? nota.Nota.ToString() : nota.ConceitoId.ToString()); } fechamentoFinalAluno.NotasConceitoFinal.Add(new FechamentoFinalConsultaRetornoAlunoNotaConceitoDto() { Disciplina = disciplinaParaAdicionar.Nome, DisciplinaCodigo = disciplinaParaAdicionar.CodigoComponenteCurricular, NotaConceito = notaParaAdicionar == string.Empty ? null : notaParaAdicionar, }); } } fechamentoFinalAluno.PodeEditar = usuarioEPeriodoPodeEditar ? aluno.PodeEditarNotaConceito() : false; fechamentoFinalAluno.Codigo = aluno.CodigoAluno; retorno.Alunos.Add(fechamentoFinalAluno); } retorno.AuditoriaAlteracao = MontaTextoAuditoriaAlteracao(fechamentosTurmaDisciplina.Any() ? fechamentosTurmaDisciplina.FirstOrDefault() : null, retorno.EhNota); retorno.AuditoriaInclusao = MontaTextoAuditoriaInclusao(fechamentosTurmaDisciplina.Any() ? fechamentosTurmaDisciplina.FirstOrDefault() : null, retorno.EhNota); retorno.NotaMedia = double.Parse(await mediator.Send(new ObterValorParametroSistemaTipoEAnoQuery(TipoParametroSistema.MediaBimestre, DateTime.Today.Year))); retorno.FrequenciaMedia = await consultasFrequencia.ObterFrequenciaMedia(disciplinaEOL); return(retorno); }
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); }
public async Task <AuditoriaPersistenciaDto> Salvar(long id, FechamentoTurmaDisciplinaDto entidadeDto, bool componenteSemNota = false) { notasEnvioWfAprovacao = new List <FechamentoNotaDto>(); var fechamentoTurmaDisciplina = MapearParaEntidade(id, entidadeDto); await CarregarTurma(entidadeDto.TurmaId); // Valida periodo de fechamento var tipoCalendario = await repositorioTipoCalendario.BuscarPorAnoLetivoEModalidade(turmaFechamento.AnoLetivo , turmaFechamento.ModalidadeCodigo == Modalidade.EJA?ModalidadeTipoCalendario.EJA : ModalidadeTipoCalendario.FundamentalMedio , DateTime.Now.Semestre()); var ue = turmaFechamento.Ue; PeriodoEscolar periodoEscolar = await ObterPeriodoEscolarFechamentoReabertura(tipoCalendario.Id, ue, entidadeDto.Bimestre); if (periodoEscolar == null) { throw new NegocioException($"Não localizado período de fechamento em aberto para turma informada no {entidadeDto.Bimestre}º Bimestre"); } await CarregaFechamentoTurma(fechamentoTurmaDisciplina, turmaFechamento, periodoEscolar); var usuarioLogado = await servicoUsuario.ObterUsuarioLogado(); // Valida Permissão do Professor na Turma/Disciplina await VerificaSeProfessorPodePersistirTurma(usuarioLogado.CodigoRf, entidadeDto.TurmaId, periodoEscolar.PeriodoFim); var fechamentoAlunos = Enumerable.Empty <FechamentoAluno>(); DisciplinaDto disciplinaEOL = await consultasDisciplina.ObterDisciplina(fechamentoTurmaDisciplina.DisciplinaId); if (disciplinaEOL == null) { throw new NegocioException("Não foi possível localizar o componente curricular no EOL."); } // reprocessar do fechamento de componente sem nota deve atualizar a sintise de frequencia if (componenteSemNota && id > 0) { fechamentoAlunos = await AtualizaSinteseAlunos(id, periodoEscolar.PeriodoFim, disciplinaEOL); } else { // Carrega notas alunos fechamentoAlunos = await CarregarFechamentoAlunoENota(id, entidadeDto.NotaConceitoAlunos); } var alunos = await servicoEOL.ObterAlunosPorTurma(turmaFechamento.CodigoTurma); var parametroDiasAlteracao = await repositorioParametrosSistema.ObterValorPorTipoEAno(TipoParametroSistema.QuantidadeDiasAlteracaoNotaFinal, turmaFechamento.AnoLetivo); var diasAlteracao = DateTime.Today.DayOfYear - fechamentoTurmaDisciplina.CriadoEm.Date.DayOfYear; var acimaDiasPermitidosAlteracao = parametroDiasAlteracao != null && diasAlteracao > int.Parse(parametroDiasAlteracao); var alunosComNotaAlterada = ""; unitOfWork.IniciarTransacao(); try { var fechamentoTurmaId = await repositorioFechamentoTurma.SalvarAsync(fechamentoTurmaDisciplina.FechamentoTurma); fechamentoTurmaDisciplina.FechamentoTurmaId = fechamentoTurmaId; await repositorioFechamentoTurmaDisciplina.SalvarAsync(fechamentoTurmaDisciplina); foreach (var fechamentoAluno in fechamentoAlunos) { fechamentoAluno.FechamentoTurmaDisciplinaId = fechamentoTurmaDisciplina.Id; await repositorioFechamentoAluno.SalvarAsync(fechamentoAluno); foreach (var fechamentoNota in fechamentoAluno.FechamentoNotas) { fechamentoNota.FechamentoAlunoId = fechamentoAluno.Id; await repositorioFechamentoNota.SalvarAsync(fechamentoNota); } if (!componenteSemNota) { var notaAlunoAlterada = entidadeDto.NotaConceitoAlunos.FirstOrDefault(n => n.CodigoAluno.Equals(fechamentoAluno.AlunoCodigo)); if (id > 0 && acimaDiasPermitidosAlteracao && notaAlunoAlterada != null && !alunosComNotaAlterada.Contains(fechamentoAluno.AlunoCodigo)) { var aluno = alunos.FirstOrDefault(a => a.CodigoAluno == fechamentoAluno.AlunoCodigo); alunosComNotaAlterada += $"<li>{aluno.CodigoAluno} - {aluno.NomeAluno}</li>"; } } } await EnviarNotasWfAprovacao(fechamentoTurmaDisciplina.Id, fechamentoTurmaDisciplina.FechamentoTurma.PeriodoEscolar, usuarioLogado); unitOfWork.PersistirTransacao(); if (alunosComNotaAlterada.Length > 0) { Cliente.Executar <IServicoFechamentoTurmaDisciplina>(s => s.GerarNotificacaoAlteracaoLimiteDias(turmaFechamento, usuarioLogado, ue, entidadeDto.Bimestre, alunosComNotaAlterada)); } Cliente.Executar <IServicoFechamentoTurmaDisciplina>(c => c.GerarPendenciasFechamento(fechamentoTurmaDisciplina.DisciplinaId, turmaFechamento, periodoEscolar, fechamentoTurmaDisciplina, usuarioLogado, componenteSemNota, disciplinaEOL.RegistraFrequencia)); await mediator.Send(new PublicaFilaExcluirPendenciaAusenciaFechamentoCommand(fechamentoTurmaDisciplina.DisciplinaId, periodoEscolar.Id, turmaFechamento.Id, usuarioLogado)); return((AuditoriaPersistenciaDto)fechamentoTurmaDisciplina); } catch (Exception e) { unitOfWork.Rollback(); throw e; } }