From 0b6eb64722adee9e5f9986a2fca8413401ad5dfb Mon Sep 17 00:00:00 2001 From: Leonardo Gomes Date: Thu, 28 May 2026 16:26:02 -0300 Subject: [PATCH 1/6] dockerfile e compose inicial --- Dockerfile | 57 +++++++++++++++------------------------------- docker-compose.yml | 21 ++++------------- 2 files changed, 22 insertions(+), 56 deletions(-) diff --git a/Dockerfile b/Dockerfile index 78c4a1d..ef8a128 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,51 +1,30 @@ -FROM php:8.5-cli - -RUN sed -i 's|main|main non-free|' /etc/apt/sources.list.d/debian.sources && apt-get update && apt-get install -y \ - unixodbc \ - unixodbc-dev \ - freetds-bin \ - freetds-dev \ - libicu-dev \ - git \ - unzip \ - libzip-dev \ - libpng-dev \ - libonig-dev \ - libxml2-dev \ - libjpeg-dev \ - libfreetype6-dev \ - libssl-dev \ - curl +FROM uspdev/uspdev-php-apache:8.4 -RUN apt-get clean && rm -rf /var/lib/apt/lists/* +RUN sed -i 's|/var/www/html|/var/www/html/public|' \ + /etc/apache2/sites-available/000-default.conf -COPY --from=composer:latest /usr/bin/composer /usr/bin/composer +# bibliotecas para mongo +RUN apt-get update && apt-get install -y \ + libssl-dev \ + pkg-config -# php libs (Core) -RUN docker-php-ext-install \ - intl \ - pdo_mysql \ - soap \ - zip \ - mbstring \ - bcmath \ - pdo_dblib +#essa linha é necessária? +RUN apt-get clean && rm -rf /var/lib/apt/lists/* # Driver do MongoDB (Obrigatório para CLI também) RUN pecl install mongodb && docker-php-ext-enable mongodb -# gd -RUN docker-php-ext-configure gd --with-freetype --with-jpeg && \ - docker-php-ext-install gd - -# php memory +# php memory #na imagem uspdev-php-apache o limite é 512M, deve tirar? ENV PHP_MEMORY_LIMIT=2048M RUN echo "memory_limit=${PHP_MEMORY_LIMIT}" > "${PHP_INI_DIR}/conf.d/memory.ini" -# Setup do diretório de trabalho -WORKDIR /app +USER www-data + +COPY --chown=www-data . . -COPY . . -RUN composer install +RUN composer install \ + --no-dev \ + --optimize-autoloader \ + --no-interaction -CMD ["tail", "-f", "/dev/null"] \ No newline at end of file +CMD ["apache2-foreground"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 4afc674..cd04b26 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,15 @@ services: - replicado2mongodb: + app: build: . container_name: replicado2mongodb + ports: + - "8000:80" depends_on: - mongodb networks: - replicado2mongodb-network volumes: - - ./:/app + - ./:/var/www/html environment: HOME: /tmp user: "${UID:-1000}:${GID:-1000}" @@ -26,21 +28,6 @@ services: networks: - replicado2mongodb-network - mongo-express: - image: mongo-express:latest - container_name: replicado2mongodb_mongo_express - restart: always - ports: - - "8081:8081" - environment: - ME_CONFIG_MONGODB_URL: mongodb://root:replicado2mongodb@mongodb:27017/admin - ME_CONFIG_BASICAUTH_USERNAME: admin - ME_CONFIG_BASICAUTH_PASSWORD: admin - depends_on: - - mongodb - networks: - - replicado2mongodb-network - networks: replicado2mongodb-network: From 2f5dc62ae03c564346452bd86e967fd2f2b845a5 Mon Sep 17 00:00:00 2001 From: Leonardo Gomes Date: Fri, 29 May 2026 12:47:51 -0300 Subject: [PATCH 2/6] update dockerfile e compose --- Dockerfile | 5 +---- docker-compose.yml | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index ef8a128..70944ea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,13 +8,10 @@ RUN apt-get update && apt-get install -y \ libssl-dev \ pkg-config -#essa linha é necessária? -RUN apt-get clean && rm -rf /var/lib/apt/lists/* - # Driver do MongoDB (Obrigatório para CLI também) RUN pecl install mongodb && docker-php-ext-enable mongodb -# php memory #na imagem uspdev-php-apache o limite é 512M, deve tirar? +# php memory ENV PHP_MEMORY_LIMIT=2048M RUN echo "memory_limit=${PHP_MEMORY_LIMIT}" > "${PHP_INI_DIR}/conf.d/memory.ini" diff --git a/docker-compose.yml b/docker-compose.yml index cd04b26..07c3b01 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,7 @@ services: - app: + replicado2mongodb: build: . + image: replicado2mongodb container_name: replicado2mongodb ports: - "8000:80" @@ -27,6 +28,21 @@ services: - mongodb_data:/data/db networks: - replicado2mongodb-network + + mongo-express: + image: mongo-express:latest + container_name: replicado2mongodb_mongo_express + restart: always + ports: + - "8081:8081" + environment: + ME_CONFIG_MONGODB_URL: mongodb://root:replicado2mongodb@mongodb:27017/admin + ME_CONFIG_BASICAUTH_USERNAME: admin + ME_CONFIG_BASICAUTH_PASSWORD: admin + depends_on: + - mongodb + networks: + - replicado2mongodb-network networks: replicado2mongodb-network: From cf36b6970816aa77d2ed2fc5d7207c03e396ef92 Mon Sep 17 00:00:00 2001 From: Leonardo Gomes Date: Fri, 29 May 2026 18:13:06 -0300 Subject: [PATCH 3/6] mongo 8.0 e comando para gerar collection --- bin/make-collection.php | 37 +++++++++++++++++ docker-compose.yml | 2 +- resources/queries/listarEstagiarios.sql | 6 +++ src/Collections/estagiariosCollection.php | 50 +++++++++++++++++++++++ stubs/collection.stub | 45 ++++++++++++++++++++ 5 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 bin/make-collection.php create mode 100644 resources/queries/listarEstagiarios.sql create mode 100644 src/Collections/estagiariosCollection.php create mode 100644 stubs/collection.stub diff --git a/bin/make-collection.php b/bin/make-collection.php new file mode 100644 index 0000000..3368b0d --- /dev/null +++ b/bin/make-collection.php @@ -0,0 +1,37 @@ +getQuery('listarEstagiarios.sql'); + $registros = ReplicadoDB::fetchAll($query); + + //passar os dados do replicado para o mongoDB + $now = new UTCDateTime(); + $collection = MongoConnection::getCollection('estagiarios'); + $bulkWrite = ClientBulkWrite::createWithCollection($collection); + + foreach ($registros as $registro) { + $bulkWrite->updateOne( + ['codpes' => $registro['codpes']], + ['$set' => [ + 'codpes' => $registro['codpes'], + 'nome' => $registro['nompes'], + 'setor' => $registro['nomset'], + 'data_inicio'=> explode(' ', $registro['dtainivin'])[0], + 'data_fim' => explode(' ', $registro['dtafimvin'])[0], + 'updated_at_sync' => $now + ] + ], + ['upsert' => true] + ); + } + + // deletar antigos + $bulkWrite->deleteMany([ + 'updated_at_sync' => ['$lt' => $now] + ]); + + //executar o bulkWrite + MongoConnection::getClient()->bulkWrite($bulkWrite); + } +} \ No newline at end of file diff --git a/stubs/collection.stub b/stubs/collection.stub new file mode 100644 index 0000000..56ee030 --- /dev/null +++ b/stubs/collection.stub @@ -0,0 +1,45 @@ +getQuery('listar{{ name_capitalize }}.sql'); + + $registros = ReplicadoDB::fetchAll($query); + + //passar os dados do replicado para o mongoDB + $now = new UTCDateTime(); + $collection = MongoConnection::getCollection('{{ name_lower }}'); + $bulkWrite = ClientBulkWrite::createWithCollection($collection); + + foreach ($registros as $registro) { + $bulkWrite->updateOne( + [], + ['$set' => [ + 'updated_at_sync' => $now + ] + ], + ['upsert' => true] + ); + } + + // delete antigos + $bulkWrite->deleteMany([ + 'updated_at_sync' => ['$lt' => $now] + ]); + + MongoConnection::getClient()->bulkWrite($bulkWrite); + } +} \ No newline at end of file From 4f62268e57b417352faa6c39b7fbaac0925c9029 Mon Sep 17 00:00:00 2001 From: Leonardo Gomes Date: Tue, 2 Jun 2026 13:18:35 -0300 Subject: [PATCH 4/6] mongo 7 --- docker-compose.yml | 2 +- stubs/collection.stub | 40 ++++++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 57894b7..07c3b01 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,7 +16,7 @@ services: user: "${UID:-1000}:${GID:-1000}" mongodb: - image: mongo:8.0 + image: mongo:7 container_name: replicado2mongodb_mongodb restart: always ports: diff --git a/stubs/collection.stub b/stubs/collection.stub index 56ee030..c324f50 100644 --- a/stubs/collection.stub +++ b/stubs/collection.stub @@ -5,7 +5,6 @@ namespace Uspdev\Replicado2MongoDB\Collections; use Uspdev\Replicado2MongoDB\Contracts\CollectionInterface; use MongoDB\BSON\UTCDateTime; -use MongoDB\ClientBulkWrite; use Uspdev\Replicado2MongoDB\Database\MongoConnection; use Uspdev\Replicado\DB as ReplicadoDB; @@ -14,32 +13,37 @@ class {{ name_lower }}Collection extends Collection implements CollectionInterfa { public function sync(): void { - // Pegar dados do replicado $query = $this->getQuery('listar{{ name_capitalize }}.sql'); + $query = str_replace('__unidades__', env('REPLICADO_CODUNDCLG'), $query); $registros = ReplicadoDB::fetchAll($query); - //passar os dados do replicado para o mongoDB + // Pegar dados do replicado $now = new UTCDateTime(); + foreach ($registros as $registro) { + $bulk[] = [ + 'updateOne' => [ + ['codcur' => $registro['codcur']], + [ + '$set' => [ + 'codcur' => $registro['codcur'], + 'nomcur' => $registro['nomcur'], + 'updated_at_sync' => $now + ] + ], + ['upsert' => true] + ] + ]; + } + $collection = MongoConnection::getCollection('{{ name_lower }}'); - $bulkWrite = ClientBulkWrite::createWithCollection($collection); - - foreach ($registros as $registro) { - $bulkWrite->updateOne( - [], - ['$set' => [ - 'updated_at_sync' => $now - ] - ], - ['upsert' => true] - ); + if (!empty($bulk)) { + $collection->bulkWrite($bulk); } - + // delete antigos - $bulkWrite->deleteMany([ + $collection->deleteMany([ 'updated_at_sync' => ['$lt' => $now] ]); - - MongoConnection::getClient()->bulkWrite($bulkWrite); } } \ No newline at end of file From cf4959998ec8861fe005e768cb77f56faa493724 Mon Sep 17 00:00:00 2001 From: Leonardo Gomes Date: Wed, 3 Jun 2026 15:02:33 -0300 Subject: [PATCH 5/6] update --- bin/sync.php | 12 ++-- .../queries/listarDisciplinasDocentes.sql | 15 +++++ resources/queries/listarDocentes.sql | 11 ++++ resources/queries/listarEstagiarios.sql | 6 +- .../disciplinasdocentesCollection.php | 50 ++++++++++++++++ src/Collections/docentesCollection.php | 59 +++++++++++++++++++ src/Collections/estagiariosCollection.php | 52 ++++++++-------- stubs/collection.stub | 4 +- 8 files changed, 172 insertions(+), 37 deletions(-) create mode 100644 resources/queries/listarDisciplinasDocentes.sql create mode 100644 resources/queries/listarDocentes.sql create mode 100644 src/Collections/disciplinasdocentesCollection.php create mode 100644 src/Collections/docentesCollection.php diff --git a/bin/sync.php b/bin/sync.php index 6065fd1..ec0d729 100755 --- a/bin/sync.php +++ b/bin/sync.php @@ -9,15 +9,15 @@ Bootstrap::init(); // Roda uma collection em particular -/* -use Uspdev\Replicado2MongoDB\Collections\programasCollection; -$sync = new programasCollection(); + +use Uspdev\Replicado2MongoDB\Collections\docentesCollection; +$sync = new docentesCollection(); $sync->sync(); -*/ + // Roda todas collections -$runner = new SyncRunner(); +/* $runner = new SyncRunner(); $runner->run(); - + */ diff --git a/resources/queries/listarDisciplinasDocentes.sql b/resources/queries/listarDisciplinasDocentes.sql new file mode 100644 index 0000000..e76ead1 --- /dev/null +++ b/resources/queries/listarDisciplinasDocentes.sql @@ -0,0 +1,15 @@ +SELECT DISTINCT + S.nomset AS NomeDepartamento, + V.tipmer AS MeritoDocente, + M.codpes AS NUSP, + V.nompes AS NomeDocente, + 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 AND (V.tipmer LIKE '%MS-5%' OR V.tipmer LIKE '%MS-6%' OR V.tipmer='NULL') +WHERE M.codpes IN ( __docentes__ ) +AND SUBSTRING(CONVERT(VARCHAR, M.codtur), 1, 5) IN ( + __semestres__ +) +ORDER BY S.codset, V.tipmer DESC, V.nompes \ No newline at end of file diff --git a/resources/queries/listarDocentes.sql b/resources/queries/listarDocentes.sql new file mode 100644 index 0000000..9016a2f --- /dev/null +++ b/resources/queries/listarDocentes.sql @@ -0,0 +1,11 @@ +SELECT DISTINCT +V.codpes, V.nompes, S.nomset, V.tipmer, V.nomabvcla, V.nomabvfnc, V.sitatl, V.sitoco, V.dtafimvin, V.dtafimdctati +FROM VINCULOPESSOAUSP V +INNER JOIN SETOR S + ON S.codset = V.codset +WHERE V.codfusclgund = __unidades__ +AND V.tipvin = 'SERVIDOR' +AND V.nomcaa = 'Docente' +AND V.codset IN (__departamentos__) +__filtros__ +ORDER BY V.codpes \ No newline at end of file diff --git a/resources/queries/listarEstagiarios.sql b/resources/queries/listarEstagiarios.sql index 25f3b41..cd7713c 100644 --- a/resources/queries/listarEstagiarios.sql +++ b/resources/queries/listarEstagiarios.sql @@ -1,6 +1,6 @@ SELECT V.codpes, V.nompes, S.nomset, V.dtainivin, V.dtafimvin - from VINCULOPESSOAUSP V - INNER JOIN dbo.SETOR S ON V.codset = S.codset + FROM VINCULOPESSOAUSP V + INNER JOIN SETOR S ON V.codset = S.codset AND tipvin = 'ESTAGIARIORH' - AND V.dtainivin LIKE '%2026%' + AND V.dtainivin LIKE '%__ano__%' ORDER BY V.nompes \ No newline at end of file diff --git a/src/Collections/disciplinasdocentesCollection.php b/src/Collections/disciplinasdocentesCollection.php new file mode 100644 index 0000000..f47cc8b --- /dev/null +++ b/src/Collections/disciplinasdocentesCollection.php @@ -0,0 +1,50 @@ +getQuery('listarDisciplinasDocentes.sql'); + $query = str_replace('__docentes__', [1963793] ,$query); + $query = str_replace('__semestres__', env('REPLICADO_CODUNDCLG'), $query); + + $disciplinasdocentes = ReplicadoDB::fetchAll($query); + + // Pegar dados do replicado + $now = new UTCDateTime(); + foreach ($disciplinasdocentes as $registro) { + $bulk[] = [ + 'updateOne' => [ + ['codcur' => $registro['codcur']], + [ + '$set' => [ + 'codcur' => $registro['codcur'], + 'nomcur' => $registro['nomcur'], + '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..1272da3 --- /dev/null +++ b/src/Collections/docentesCollection.php @@ -0,0 +1,59 @@ +getQuery('listarDocentes.sql'); + $query = str_replace('__unidades__', env('REPLICADO_CODUNDCLG'), $query); + $query = str_replace('__departamentos__', '598,594,598,592,600,601,599,604,603,596', $query); + $query = str_replace('__filtros__', '', $query); + + $docentes = ReplicadoDB::fetchAll($query); + //,594,598,592,600,601,599,604,603,596 + // Pegar dados do replicado + $now = new UTCDateTime(); + foreach ($docentes as $registro) { + $bulk[] = [ + 'updateOne' => [ + ['codpes' => $registro['codpes']], + [ + '$set' => [ + 'codpes' => $registro['codpes'], + 'nome' => $registro['nompes'], + 'setor' => $registro['nomset'], + 'merito' => $registro['tipmer'], + 'classe' => $registro['nomabvcla'], + 'funcao' => $registro['nomabvfnc'], + 'status' => $registro['sitatl'], + 'ultima_ocorrencia' => $registro['sitoco'], + 'fim_vinculo' => explode(' ',$registro['dtafimvin'] ?? '')[0], + 'fim_atividade' => explode(' ',$registro['dtafimdctati'] ?? '')[0] ?? '', + '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 index 4477d8a..fb555e6 100644 --- a/src/Collections/estagiariosCollection.php +++ b/src/Collections/estagiariosCollection.php @@ -5,7 +5,6 @@ use Uspdev\Replicado2MongoDB\Contracts\CollectionInterface; use MongoDB\BSON\UTCDateTime; -use MongoDB\ClientBulkWrite; use Uspdev\Replicado2MongoDB\Database\MongoConnection; use Uspdev\Replicado\DB as ReplicadoDB; @@ -14,37 +13,38 @@ class estagiariosCollection extends Collection implements CollectionInterface { public function sync(): void { - //pegar dados do replicado $query = $this->getQuery('listarEstagiarios.sql'); - $registros = ReplicadoDB::fetchAll($query); + $estagiarios = ReplicadoDB::fetchAll($query); - //passar os dados do replicado para o mongoDB + // Pegar dados do replicado $now = new UTCDateTime(); + foreach ($estagiarios as $registro) { + $bulk[] = [ + 'updateOne' => [ + ['codpes' => $registro['codpes']], + [ + '$set' => [ + 'codpes'=> $registro['codpes'], + 'nome' => $registro['nompes'], + 'setor' => $registro['nomset'], + 'inicio'=> explode(' ', $registro['dtainivin'])[0], + 'fim' => explode(' ', $registro['dtafimvin'])[0], + 'updated_at_sync' => $now + ] + ], + ['upsert' => true] + ] + ]; + } + $collection = MongoConnection::getCollection('estagiarios'); - $bulkWrite = ClientBulkWrite::createWithCollection($collection); - - foreach ($registros as $registro) { - $bulkWrite->updateOne( - ['codpes' => $registro['codpes']], - ['$set' => [ - 'codpes' => $registro['codpes'], - 'nome' => $registro['nompes'], - 'setor' => $registro['nomset'], - 'data_inicio'=> explode(' ', $registro['dtainivin'])[0], - 'data_fim' => explode(' ', $registro['dtafimvin'])[0], - 'updated_at_sync' => $now - ] - ], - ['upsert' => true] - ); + if (!empty($bulk)) { + $collection->bulkWrite($bulk); } - - // deletar antigos - $bulkWrite->deleteMany([ + + // delete antigos + $collection->deleteMany([ 'updated_at_sync' => ['$lt' => $now] ]); - - //executar o bulkWrite - MongoConnection::getClient()->bulkWrite($bulkWrite); } } \ No newline at end of file diff --git a/stubs/collection.stub b/stubs/collection.stub index c324f50..455bba0 100644 --- a/stubs/collection.stub +++ b/stubs/collection.stub @@ -16,11 +16,11 @@ class {{ name_lower }}Collection extends Collection implements CollectionInterfa $query = $this->getQuery('listar{{ name_capitalize }}.sql'); $query = str_replace('__unidades__', env('REPLICADO_CODUNDCLG'), $query); - $registros = ReplicadoDB::fetchAll($query); + ${{ name_lower }} = ReplicadoDB::fetchAll($query); // Pegar dados do replicado $now = new UTCDateTime(); - foreach ($registros as $registro) { + foreach (${{ name_lower }} as $registro) { $bulk[] = [ 'updateOne' => [ ['codcur' => $registro['codcur']], From 54cb54806c8f5885b940db8b8350d63488bda776 Mon Sep 17 00:00:00 2001 From: Leonardo Gomes Date: Fri, 12 Jun 2026 12:05:19 -0300 Subject: [PATCH 6/6] queries e collections atualizadas --- bin/sync.php | 4 +- .../queries/listarDisciplinasDocentes.sql | 20 +++---- resources/queries/listarDocentes.sql | 16 ++---- resources/queries/listarEstagiarios.sql | 5 +- .../queries/listarIntercambistasRecebidos.sql | 4 ++ resources/queries/listarPosGrad.sql | 10 ++++ .../disciplinasdocentesCollection.php | 23 +++++--- src/Collections/docentesCollection.php | 19 ++++--- src/Collections/estagiariosCollection.php | 6 +- .../intercambistasrecebidosCollection.php | 55 +++++++++++++++++++ src/Collections/posgradCollection.php | 54 ++++++++++++++++++ src/Database/MongoConnection.php | 5 +- 12 files changed, 177 insertions(+), 44 deletions(-) create mode 100644 resources/queries/listarIntercambistasRecebidos.sql create mode 100644 resources/queries/listarPosGrad.sql create mode 100644 src/Collections/intercambistasrecebidosCollection.php create mode 100644 src/Collections/posgradCollection.php diff --git a/bin/sync.php b/bin/sync.php index ec0d729..6e76d2d 100755 --- a/bin/sync.php +++ b/bin/sync.php @@ -17,7 +17,7 @@ // Roda todas collections /* $runner = new SyncRunner(); -$runner->run(); - */ +$runner->run(); */ + diff --git a/resources/queries/listarDisciplinasDocentes.sql b/resources/queries/listarDisciplinasDocentes.sql index e76ead1..de0fb68 100644 --- a/resources/queries/listarDisciplinasDocentes.sql +++ b/resources/queries/listarDisciplinasDocentes.sql @@ -1,15 +1,11 @@ SELECT DISTINCT - S.nomset AS NomeDepartamento, - V.tipmer AS MeritoDocente, - M.codpes AS NUSP, - V.nompes AS NomeDocente, - M.coddis AS Disciplina, - M.codtur AS Turma + S.nomset, --AS NomeDepartamento, + V.tipmer, --AS MeritoDocente, + M.codpes, --AS NUSP, + V.nompes, --AS NomeDocente, + 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 AND (V.tipmer LIKE '%MS-5%' OR V.tipmer LIKE '%MS-6%' OR V.tipmer='NULL') -WHERE M.codpes IN ( __docentes__ ) -AND SUBSTRING(CONVERT(VARCHAR, M.codtur), 1, 5) IN ( - __semestres__ -) -ORDER BY S.codset, V.tipmer DESC, V.nompes \ No newline at end of file +INNER JOIN SETOR S ON S.codset = V.codset +WHERE V.codfusclgund IN (__unidades__) \ No newline at end of file diff --git a/resources/queries/listarDocentes.sql b/resources/queries/listarDocentes.sql index 9016a2f..41744d7 100644 --- a/resources/queries/listarDocentes.sql +++ b/resources/queries/listarDocentes.sql @@ -1,11 +1,7 @@ SELECT DISTINCT -V.codpes, V.nompes, S.nomset, V.tipmer, V.nomabvcla, V.nomabvfnc, V.sitatl, V.sitoco, V.dtafimvin, V.dtafimdctati -FROM VINCULOPESSOAUSP V -INNER JOIN SETOR S - ON S.codset = V.codset -WHERE V.codfusclgund = __unidades__ -AND V.tipvin = 'SERVIDOR' -AND V.nomcaa = 'Docente' -AND V.codset IN (__departamentos__) -__filtros__ -ORDER BY V.codpes \ No newline at end of file +V.codpes, V.nompes, S.nomset, V.codset, S.nomabvset, V.tipmer, V.nomabvcla, V.nomabvfnc, V.sitatl, V.sitoco, V.dtafimvin, V.dtafimdctati +FROM VINCULOPESSOAUSP AS V +INNER JOIN SETOR AS S ON S.codset = V.codset +WHERE V.tipvin = 'SERVIDOR' + AND V.nomcaa = 'Docente' + AND V.codfusclgund IN (__unidades__) \ No newline at end of file diff --git a/resources/queries/listarEstagiarios.sql b/resources/queries/listarEstagiarios.sql index cd7713c..f89a585 100644 --- a/resources/queries/listarEstagiarios.sql +++ b/resources/queries/listarEstagiarios.sql @@ -1,6 +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 - AND tipvin = 'ESTAGIARIORH' - AND V.dtainivin LIKE '%__ano__%' - ORDER BY V.nompes \ No newline at end of file + WHERE V.tipvin = 'ESTAGIARIORH' + AND V.codfusclgund 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..052eba7 --- /dev/null +++ b/resources/queries/listarIntercambistasRecebidos.sql @@ -0,0 +1,4 @@ +SELECT DISTINCT V.nompes, V.codpes, V.dtainivin, V.dtafimvin, V.tipvin + FROM VINCULOPESSOAUSP AS V + WHERE V.tipvin IN ('ALUNOICD', 'ALUNOCONVENIOINT') + AND V.codfusclgund IN (__unidades__) \ No newline at end of file diff --git a/resources/queries/listarPosGrad.sql b/resources/queries/listarPosGrad.sql new file mode 100644 index 0000000..84cbe27 --- /dev/null +++ b/resources/queries/listarPosGrad.sql @@ -0,0 +1,10 @@ +SELECT DISTINCT + V.codpes, --AS NUSP, + L.codema, --AS Email, + L.nompes, --AS Nome, + V.codare + FROM VINCULOPESSOAUSP AS V + INNER JOIN LOCALIZAPESSOA as L ON (V.codpes = L.codpes) + WHERE V.tipvin = 'ALUNOPOS' + AND V.sitatl = 'A' + AND V.codfusclgund IN (__unidades__) \ No newline at end of file diff --git a/src/Collections/disciplinasdocentesCollection.php b/src/Collections/disciplinasdocentesCollection.php index f47cc8b..53035c3 100644 --- a/src/Collections/disciplinasdocentesCollection.php +++ b/src/Collections/disciplinasdocentesCollection.php @@ -13,22 +13,31 @@ class disciplinasdocentesCollection extends Collection implements CollectionInte { public function sync(): void { - $query = $this->getQuery('listarDisciplinasDocentes.sql'); - $query = str_replace('__docentes__', [1963793] ,$query); - $query = str_replace('__semestres__', env('REPLICADO_CODUNDCLG'), $query); - + $query = $this->getQuery('listarDisciplinasDocentes.sql', + [ + '__unidades__' => env('REPLICADO_CODUNDCLG') + ] + ); $disciplinasdocentes = ReplicadoDB::fetchAll($query); + $qtd = count($disciplinasdocentes); // Pegar dados do replicado $now = new UTCDateTime(); foreach ($disciplinasdocentes as $registro) { $bulk[] = [ 'updateOne' => [ - ['codcur' => $registro['codcur']], + ['nusp_docente' => $registro['codpes'], + 'disciplina' => $registro['coddis'], + 'turma' => $registro['codtur'] + ], [ '$set' => [ - 'codcur' => $registro['codcur'], - 'nomcur' => $registro['nomcur'], + 'departamento' => $registro['nomset'], + 'merito_docente' => $registro['tipmer'], + 'nusp_docente' => $registro['codpes'], + 'nome_docente' => $registro['nompes'], + 'disciplina' => $registro['coddis'], + 'turma' => $registro['codtur'], 'updated_at_sync' => $now ] ], diff --git a/src/Collections/docentesCollection.php b/src/Collections/docentesCollection.php index 1272da3..28ada47 100644 --- a/src/Collections/docentesCollection.php +++ b/src/Collections/docentesCollection.php @@ -13,13 +13,14 @@ class docentesCollection extends Collection implements CollectionInterface { public function sync(): void { - $query = $this->getQuery('listarDocentes.sql'); - $query = str_replace('__unidades__', env('REPLICADO_CODUNDCLG'), $query); - $query = str_replace('__departamentos__', '598,594,598,592,600,601,599,604,603,596', $query); - $query = str_replace('__filtros__', '', $query); + $query = $this->getQuery('listarDocentes.sql', + [ + '__unidades__' => env('REPLICADO_CODUNDCLG') + ] + ); $docentes = ReplicadoDB::fetchAll($query); - //,594,598,592,600,601,599,604,603,596 + // Pegar dados do replicado $now = new UTCDateTime(); foreach ($docentes as $registro) { @@ -29,15 +30,17 @@ public function sync(): void [ '$set' => [ 'codpes' => $registro['codpes'], - 'nome' => $registro['nompes'], - 'setor' => $registro['nomset'], + 'nome_docente' => $registro['nompes'], + 'nome_setor' => $registro['nomset'], + 'cod_setor' => $registro['codset'], + 'clg_setor' => $registro['nomabvset'], 'merito' => $registro['tipmer'], 'classe' => $registro['nomabvcla'], 'funcao' => $registro['nomabvfnc'], 'status' => $registro['sitatl'], 'ultima_ocorrencia' => $registro['sitoco'], 'fim_vinculo' => explode(' ',$registro['dtafimvin'] ?? '')[0], - 'fim_atividade' => explode(' ',$registro['dtafimdctati'] ?? '')[0] ?? '', + 'fim_atividade' => explode(' ',$registro['dtafimdctati'] ?? '')[0], 'updated_at_sync' => $now ] ], diff --git a/src/Collections/estagiariosCollection.php b/src/Collections/estagiariosCollection.php index fb555e6..09b2c9e 100644 --- a/src/Collections/estagiariosCollection.php +++ b/src/Collections/estagiariosCollection.php @@ -13,7 +13,11 @@ class estagiariosCollection extends Collection implements CollectionInterface { public function sync(): void { - $query = $this->getQuery('listarEstagiarios.sql'); + $query = $this->getQuery('listarEstagiarios.sql', + [ + '__unidades__' => env('REPLICADO_CODUNDCLG') + ] + ); $estagiarios = ReplicadoDB::fetchAll($query); // Pegar dados do replicado diff --git a/src/Collections/intercambistasrecebidosCollection.php b/src/Collections/intercambistasrecebidosCollection.php new file mode 100644 index 0000000..301129c --- /dev/null +++ b/src/Collections/intercambistasrecebidosCollection.php @@ -0,0 +1,55 @@ +getQuery('listarIntercambistasRecebidos.sql', + [ + '__unidades__' => env('REPLICADO_CODUNDCLG') + ] + ); + + $intercambistasrecebidos = ReplicadoDB::fetchAll($query); + + // Pegar dados do replicado + $now = new UTCDateTime(); + foreach ($intercambistasrecebidos as $registro) { + $bulk[] = [ + 'updateOne' => [ + ['codpes' => $registro['codpes']], + [ + '$set' => [ + 'codpes' => $registro['codpes'], + 'nome' => $registro['nompes'], + 'tipo_vinculo' => $registro['tipvin'], + 'inicio' => explode(' ', $registro['dtainivin'] ?? '')[0], + 'fim' => explode(' ', $registro['dtafimvin'] ?? '')[0], + 'updated_at_sync' => $now + ] + ], + ['upsert' => true] + ] + ]; + } + + $collection = MongoConnection::getCollection('intercambistasrecebidos'); + 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/posgradCollection.php b/src/Collections/posgradCollection.php new file mode 100644 index 0000000..43b522e --- /dev/null +++ b/src/Collections/posgradCollection.php @@ -0,0 +1,54 @@ +getQuery('listarPosGrad.sql', + [ + '__unidades__' => env('REPLICADO_CODUNDCLG') + ] + ); + + $posgrad = ReplicadoDB::fetchAll($query); + + // Pegar dados do replicado + $now = new UTCDateTime(); + foreach ($posgrad as $registro) { + $bulk[] = [ + 'updateOne' => [ + ['codpes' => $registro['codpes']], + [ + '$set' => [ + 'codpes' => $registro['codpes'], + 'email' => $registro['codema'], + 'nome' => $registro['nompes'], + 'cod_area' => $registro['codare'], + 'updated_at_sync' => $now + ] + ], + ['upsert' => true] + ] + ]; + } + + $collection = MongoConnection::getCollection('posgrad'); + 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/Database/MongoConnection.php b/src/Database/MongoConnection.php index e8167fc..fb6b348 100644 --- a/src/Database/MongoConnection.php +++ b/src/Database/MongoConnection.php @@ -15,9 +15,12 @@ public static function getClient(): Client $port = env('REPLICADO2MONGODB_PORT', 27017); $user = env('REPLICADO2MONGODB_DB', 'root'); $pass = env('REPLICADO2MONGODB_PASS', 'replicado2mongodb'); + + $uriOptions = ['socketTimeoutMS' => 900000]; self::$client = new Client( - "mongodb://$user:$pass@$host:$port" + "mongodb://$user:$pass@$host:$port", + $uriOptions ); }