diff --git a/resources/queries/listarAlunosPosAtivos.sql b/resources/queries/listarAlunosPosAtivos.sql new file mode 100644 index 0000000..c2916b6 --- /dev/null +++ b/resources/queries/listarAlunosPosAtivos.sql @@ -0,0 +1,22 @@ +SELECT DISTINCT + V.codpes AS codpes, + L.codema AS email, + L.nompes AS nome, + V.codare AS codarea, + C.codcur AS codcur, + NC.nomcur AS nomcur, + V.dtainivin, + V.dtafimvin +FROM VINCULOPESSOAUSP AS V + INNER JOIN AREA AS A + ON A.codare = V.codare + INNER JOIN CURSO AS C + ON C.codcur = A.codcur + INNER JOIN NOMECURSO AS NC + ON C.codcur = NC.codcur + INNER JOIN LOCALIZAPESSOA as L + ON (V.codpes = L.codpes) +WHERE V.tipvin = 'ALUNOPOS' + AND V.sitatl = 'A' + AND L.tipvin = 'ALUNOPOS' + AND V.codfusclgund in (__unidades__) \ No newline at end of file diff --git a/resources/queries/listarDisciplinasDocentes.sql b/resources/queries/listarDisciplinasDocentes.sql new file mode 100644 index 0000000..ca92a3d --- /dev/null +++ b/resources/queries/listarDisciplinasDocentes.sql @@ -0,0 +1,11 @@ +SELECT DISTINCT + S.nomset AS nomset, + V.tipmer AS meritoDocente, + M.codpes AS codpes, + V.nompes AS nompes, + M.coddis AS disciplina, + M.codtur AS turma +FROM MINISTRANTE M +INNER JOIN VINCULOPESSOAUSP V ON V.codpes = M.codpes +INNER JOIN SETOR S ON S.codset = V.codset +WHERE V.codund IN (__unidades__) \ No newline at end of file diff --git a/resources/queries/listarDocentes.sql b/resources/queries/listarDocentes.sql new file mode 100644 index 0000000..4b1469c --- /dev/null +++ b/resources/queries/listarDocentes.sql @@ -0,0 +1,10 @@ +SELECT DISTINCT +V.*, S.nomset, L.idfpescpq +FROM VINCULOPESSOAUSP V +INNER JOIN SETOR S + ON S.codset = V.codset +LEFT JOIN DIM_PESSOA_XMLUSP L + ON V.codpes = L.codpes +WHERE V.codfusclgund IN (__unidades__) +AND V.tipvin = 'SERVIDOR' +AND ( V.tipfnc = 'Docente' or V.nomcaa = 'Pesquisador' ) \ No newline at end of file diff --git a/resources/queries/listarEstagiarios.sql b/resources/queries/listarEstagiarios.sql new file mode 100644 index 0000000..9fb6c40 --- /dev/null +++ b/resources/queries/listarEstagiarios.sql @@ -0,0 +1,5 @@ +SELECT V.codpes, V.nompes, S.nomset, V.dtainivin, V.dtafimvin + from VINCULOPESSOAUSP V + INNER JOIN SETOR S ON V.codset = S.codset +WHERE V.tipvin = 'ESTAGIARIORH' + AND V.codund IN (__unidades__) \ No newline at end of file diff --git a/resources/queries/listarIntercambistasRecebidos.sql b/resources/queries/listarIntercambistasRecebidos.sql new file mode 100644 index 0000000..054ca1c --- /dev/null +++ b/resources/queries/listarIntercambistasRecebidos.sql @@ -0,0 +1,4 @@ +SELECT DISTINCT v.nompes, v.codpes, v.dtainivin, v.dtafimvin, v.numseqpes +FROM VINCULOPESSOAUSP v +WHERE v.tipvin IN ('ALUNOICD', 'ALUNOCONVENIOINT') +AND codfusclgund in (__unidades__) \ No newline at end of file diff --git a/resources/queries/listarTurmasGraduacaoAtuais.sql b/resources/queries/listarTurmasGraduacaoAtuais.sql new file mode 100644 index 0000000..5ca3601 --- /dev/null +++ b/resources/queries/listarTurmasGraduacaoAtuais.sql @@ -0,0 +1,16 @@ +SELECT DISTINCT TR.coddis, TR.codtur, TR.verdis, D.nomdis, P.nompes, horario = (O.diasmnocp + ' - ' + PH.horent + ' - ' + PH.horsai) FROM TURMAGR TR + LEFT JOIN DISCIPLINAGR D ON + TR.coddis = D.coddis AND TR.verdis = D.verdis + LEFT JOIN MINISTRANTE M ON + TR.codtur = M.codtur AND TR.verdis = M.verdis AND TR.coddis = M.coddis + LEFT JOIN PESSOA P ON + M.codpes = P.codpes + LEFT JOIN OCUPTURMA O ON + TR.codtur = O.codtur AND TR.verdis = O.verdis AND TR.coddis = O.coddis + LEFT JOIN PERIODOHORARIO PH ON + O.codperhor = PH.codperhor + WHERE + TR.codtur LIKE '__semestre__%' + AND TR.verdis = (SELECT MAX(DI.verdis) FROM DISCIPLINAGR AS DI WHERE (DI.coddis = TR.coddis) AND dtaatvdis IS NOT NULL) + AND (D.coddis LIKE '__siglas__%') + \ No newline at end of file diff --git a/src/Collections/Collection.php b/src/Collections/Collection.php index 802d529..bed2db4 100644 --- a/src/Collections/Collection.php +++ b/src/Collections/Collection.php @@ -1,6 +1,7 @@ getQuery('listarAlunosPosAtivos.sql', + [ + '__unidades__' => env('REPLICADO_CODUNDCLG') + ]); + + $data = ReplicadoDB::fetchAll($query); + // Pegar dados do replicado + $now = new UTCDateTime(); + foreach ($data as $aluno) { + $bulk[] = [ + 'updateOne' => [ + ['codpes' => (int)$aluno['codpes']], + [ + '$set' => [ + 'nome' => $aluno['nome'], + 'email' => $aluno['email'], + 'codarea' => $aluno['codarea'], + 'codPrograma' => $aluno['codcur'], + 'programa' => $aluno['nomcur'], + + 'dtaInicioVinculo' => $this->DateTime($aluno['dtainivin']), + + 'updated_at_sync' => $now + ] + ], + ['upsert' => true] + ] + ]; + } + + $collection = MongoConnection::getCollection('alunosPos'); + if (!empty($bulk)) { + $collection->bulkWrite($bulk); + } + + // delete antigos + $collection->deleteMany([ + 'updated_at_sync' => ['$lt' => $now] + ]); + } +} \ No newline at end of file diff --git a/src/Collections/disciplinasDocentesCollection.php b/src/Collections/disciplinasDocentesCollection.php new file mode 100644 index 0000000..b445608 --- /dev/null +++ b/src/Collections/disciplinasDocentesCollection.php @@ -0,0 +1,56 @@ +getQuery('listarDisciplinasDocentes.sql', + [ + '__unidades__' => env('REPLICADO_CODUNDCLG') + ]); + + $data = ReplicadoDB::fetchAll($query); + // Pegar dados do replicado + $now = new UTCDateTime(); + foreach ($data as $row) { + $bulk[] = [ + 'updateOne' => [ + ['cod' => $row['codpes'].$row['turma'].$row['disciplina']], + [ + '$set' => [ + 'nomeDocente' => $row['nompes'], + 'codpes' => (int)$row['codpes'], + 'nomeDepartamento' => $row['nomset'], + 'meritoDocente' => $row['meritoDocente'], + 'turma' => $row['turma'], + 'disciplina' => $row['disciplina'], + 'semestre' => (int)substr($row['turma'],0,5), + + 'updated_at_sync' => $now + ] + ], + ['upsert' => true] + ] + ]; + } + + $collection = MongoConnection::getCollection('disciplinasDocentes'); + if (!empty($bulk)) { + $collection->bulkWrite($bulk); + } + + // delete antigos + $collection->deleteMany([ + 'updated_at_sync' => ['$lt' => $now] + ]); + } +} \ No newline at end of file diff --git a/src/Collections/docentesCollection.php b/src/Collections/docentesCollection.php new file mode 100644 index 0000000..b48cbb0 --- /dev/null +++ b/src/Collections/docentesCollection.php @@ -0,0 +1,64 @@ +getQuery('listarDocentes.sql', + [ + '__unidades__' => env('REPLICADO_CODUNDCLG') + ]); + + $data = ReplicadoDB::fetchAll($query); + // Pegar dados do replicado + $now = new UTCDateTime(); + foreach ($data as $docente) { + $bulk[] = [ + 'updateOne' => [ + ['codpes' => (int)$docente['codpes']], + [ + '$set' => [ + 'nome' => $docente['nompes'], + 'codset' => (int)$docente['codset'], + 'departamento' => $docente['nomset'], + 'merito' => $docente['tipmer'], + 'classe' => $docente['nomabvcla'], + 'funcao' => $docente['nomabvfnc'], + 'status' => $docente['sitatl'], + 'ultimaOcorrencia' => $docente['sitoco'], + 'idLattes' => $docente['idfpescpq'], + + 'dtaInicioAtividade' => $this->DateTime($docente['dtainidctati']), + 'dtaFimAtividade' => $this->DateTime($docente['dtafimdctati']), + + 'dtaInicioVinculo' => $this->DateTime($docente['dtainivin']), + 'dtaFimVinculo' => $this->DateTime($docente['dtafimvin']), + + 'updated_at_sync' => $now + ] + ], + ['upsert' => true] + ] + ]; + } + + $collection = MongoConnection::getCollection('docentes'); + if (!empty($bulk)) { + $collection->bulkWrite($bulk); + } + + // delete antigos + $collection->deleteMany([ + 'updated_at_sync' => ['$lt' => $now] + ]); + } +} \ No newline at end of file diff --git a/src/Collections/estagiariosCollection.php b/src/Collections/estagiariosCollection.php new file mode 100644 index 0000000..e041113 --- /dev/null +++ b/src/Collections/estagiariosCollection.php @@ -0,0 +1,53 @@ +getQuery('listarEstagiarios.sql', + [ + '__unidades__' => env('REPLICADO_CODUNDCLG') + ]); + + $data = ReplicadoDB::fetchAll($query); + // Pegar dados do replicado + $now = new UTCDateTime(); + foreach ($data as $estagiario) { + $bulk[] = [ + 'updateOne' => [ + ['codpes' => (int)$estagiario['codpes']], + [ + '$set' => [ + 'nome' => $estagiario['nompes'], + 'setor' => $estagiario['nomset'], + 'dtaInicio' => $this->DateTime($estagiario['dtainivin']), + 'dtaFim' => $this->DateTime($estagiario['dtafimvin']), + + 'updated_at_sync' => $now + ] + ], + ['upsert' => true] + ] + ]; + } + + $collection = MongoConnection::getCollection('estagiarios'); + if (!empty($bulk)) { + $collection->bulkWrite($bulk); + } + + // delete antigos + $collection->deleteMany([ + 'updated_at_sync' => ['$lt' => $now] + ]); + } +} \ No newline at end of file diff --git a/src/Collections/intercambistasCollection.php b/src/Collections/intercambistasCollection.php new file mode 100644 index 0000000..aa93b86 --- /dev/null +++ b/src/Collections/intercambistasCollection.php @@ -0,0 +1,54 @@ +getQuery('listarIntercambistasRecebidos.sql', + [ + '__unidades__' => env('REPLICADO_CODUNDCLG') + ]); + + $data = ReplicadoDB::fetchAll($query); + // Pegar dados do replicado + $now = new UTCDateTime(); + foreach ($data as $intercambista) { + $bulk[] = [ + 'updateOne' => [ + ['codpesseq' => ($intercambista['codpes'].' '.$intercambista['numseqpes'])], + [ + '$set' => [ + 'nome' => $intercambista['nompes'], + 'codpes' => (int)$intercambista['codpes'], + 'numseq' => (int)$intercambista['numseqpes'], + 'dtaInicioVinculo' => $this->DateTime($intercambista['dtainivin']), + 'dtaFimVinculo' => $this->DateTime($intercambista['dtafimvin']), + + 'updated_at_sync' => $now + ] + ], + ['upsert' => true] + ] + ]; + } + + $collection = MongoConnection::getCollection('intercambistas'); + if (!empty($bulk)) { + $collection->bulkWrite($bulk); + } + + // delete antigos + $collection->deleteMany([ + 'updated_at_sync' => ['$lt' => $now] + ]); + } +} \ No newline at end of file diff --git a/src/Collections/turmasGraduacaoCollection.php b/src/Collections/turmasGraduacaoCollection.php new file mode 100644 index 0000000..0eb3a55 --- /dev/null +++ b/src/Collections/turmasGraduacaoCollection.php @@ -0,0 +1,88 @@ +getQuery('listarTurmasGraduacaoAtuais.sql', + [ + '__semestre__' => date("Y") . (date("m") > 6 ? 2 : 1), + + '__siglas__' => implode("%' OR D.coddis LIKE '",$siglas) + ]); + + $tempTurmas = ReplicadoDB::fetchAll($query); + $turmas =[]; + + //arrumar cada disciplina com um array de horários e um array de professores + + foreach ($tempTurmas as $turma) { + $codtur = $turma['codtur']; + $coddis = $turma['coddis']; + $verdis = $turma['verdis']; + $cod = $codtur. $coddis . $verdis; + if (!isset($turmas[$cod])) { + $turmas[$cod]=[ + 'codtur' => $turma['codtur'], + 'nomdis' => $turma['nomdis'], + 'coddis' => $turma['coddis'], + 'verdis' => $turma['verdis'], + 'nompes' => [], + 'horario' => [] + + ]; + } + if (!empty($turma['nompes']) && !in_array($turma['nompes'], $turmas[$cod]['nompes'])) { + $turmas[$cod]['nompes'][] = $turma['nompes']; + } + + if (!empty($turma['horario']) && !in_array($turma['horario'], $turmas[$cod]['horario'])) { + $turmas[$cod]['horario'][] = $turma['horario']; + } + } + + $now = new UTCDateTime(); + foreach ($turmas as $cod => $turma) { + $bulk[] = [ + 'updateOne' => [ + ['cod' => $cod], + [ + '$set' => [ + 'turma' => $turma['codtur'], + 'nomeDisciplina' => $turma['nomdis'], + 'disciplina' => $turma['coddis'], + 'versao' => $turma['verdis'], + 'docentes' => $turma['nompes'], + 'horario' => $turma['horario'], + + 'updated_at_sync' => $now + ] + ], + ['upsert' => true] + ] + ]; + } + + $collection = MongoConnection::getCollection('turmasGraduacaoAtuais'); + if (!empty($bulk)) { + $collection->bulkWrite($bulk); + } + + // delete antigos + $collection->deleteMany([ + 'updated_at_sync' => ['$lt' => $now] + ]); + } +} \ No newline at end of file