Commit f9b81ba2bf6adcc752d9f25366f5f3d7446e8927
1 parent
4a178b15
Exists in
master
and in
1 other branch
Indicador 27 - Enviando apenas a quantidade de acessos de usuarios dos dias ainda não enviados
Showing
3 changed files
with
57 additions
and
37 deletions
Show diff stats
rn/MdEstatisticasAgendamentoRN.php
@@ -15,10 +15,32 @@ class MdEstatisticasAgendamentoRN extends InfraRN { | @@ -15,10 +15,32 @@ class MdEstatisticasAgendamentoRN extends InfraRN { | ||
15 | InfraDebug::getInstance()->setBolEcho(false); | 15 | InfraDebug::getInstance()->setBolEcho(false); |
16 | InfraDebug::getInstance()->limpar(); | 16 | InfraDebug::getInstance()->limpar(); |
17 | 17 | ||
18 | - $indicadores = (new MdEstatisticasColetarRN())-> coletarIndicadores(); | ||
19 | - (new MdEstatisticasEnviarRN())-> enviarIndicadores($indicadores); | 18 | + try { |
19 | + $coletor = new MdEstatisticasColetarRN(); | ||
20 | + $indicadores = $coletor->coletarIndicadores(); | ||
21 | + InfraDebug::getInstance()->gravar('JSON: ' . json_encode($indicadores), InfraLog::$INFORMACAO); | ||
20 | 22 | ||
21 | - LogSEI::getInstance()->gravar(InfraDebug::getInstance()->getStrDebug(),InfraLog::$INFORMACAO); | 23 | + $enviar = new MdEstatisticasEnviarRN(); |
24 | + | ||
25 | + $saida = $enviar->enviarIndicadores($indicadores); | ||
26 | + InfraDebug::getInstance()->gravar('Retorno: ' . json_encode($saida), InfraLog::$INFORMACAO); | ||
27 | + | ||
28 | + $id = $saida['id']; | ||
29 | + | ||
30 | + $data = $enviar->obterUltimoAcesso(); | ||
31 | + InfraDebug::getInstance()->gravar('Data: ' . $data, InfraLog::$INFORMACAO); | ||
32 | + | ||
33 | + $acessos = $coletor->obterAcessosUsuarios($data); | ||
34 | + $enviar->enviarAcessos($acessos, $id); | ||
35 | + | ||
36 | + LogSEI::getInstance()->gravar(InfraDebug::getInstance()->getStrDebug(),InfraLog::$INFORMACAO); | ||
37 | + | ||
38 | + } catch(Exception $e) { | ||
39 | + InfraDebug::getInstance()->setBolLigado(false); | ||
40 | + InfraDebug::getInstance()->setBolDebugInfra(false); | ||
41 | + InfraDebug::getInstance()->setBolEcho(false); | ||
42 | + throw new InfraException('Erro processando estatísticas do sistema.',$e); | ||
43 | + } | ||
22 | } | 44 | } |
23 | 45 | ||
24 | } | 46 | } |
rn/MdEstatisticasColetarRN.php
@@ -48,8 +48,7 @@ class MdEstatisticasColetarRN extends InfraRN { | @@ -48,8 +48,7 @@ class MdEstatisticasColetarRN extends InfraRN { | ||
48 | 'tamanhoFilesystem' => $this->obterTamanhoFileSystem(), | 48 | 'tamanhoFilesystem' => $this->obterTamanhoFileSystem(), |
49 | 'anexosTamanhos' => $this->obterTamanhoDocumentosExternos(), | 49 | 'anexosTamanhos' => $this->obterTamanhoDocumentosExternos(), |
50 | 'extensoes' => $this->obterQuantidadeDocumentosExternosPorExtensao(), | 50 | 'extensoes' => $this->obterQuantidadeDocumentosExternosPorExtensao(), |
51 | - 'velocidades' => $this->obterVelocidadePorCidade(), | ||
52 | - 'acessosUsuarios' => $this->obterAcessosUsuarios() | 51 | + 'velocidades' => $this->obterVelocidadePorCidade() |
53 | ); | 52 | ); |
54 | 53 | ||
55 | return $indicadores; | 54 | return $indicadores; |
@@ -452,11 +451,11 @@ class MdEstatisticasColetarRN extends InfraRN { | @@ -452,11 +451,11 @@ class MdEstatisticasColetarRN extends InfraRN { | ||
452 | $sgbd = $this->obterTipoSGBD(); | 451 | $sgbd = $this->obterTipoSGBD(); |
453 | $query = ''; | 452 | $query = ''; |
454 | if ($sgbd == 'MySql') { | 453 | if ($sgbd == 'MySql') { |
455 | - $query = "select count(*) as quantidade, date(dth_acesso) as data from infra_navegador where dth_acesso >= '" . $ultimadata . "' group by date(dth_acesso)"; | 454 | + $query = "select count(*) as quantidade, date(dth_acesso) as data from infra_navegador where date(dth_acesso) > " . $ultimadata . " group by date(dth_acesso)"; |
456 | } elseif ($sgbd == 'SqlServer') { | 455 | } elseif ($sgbd == 'SqlServer') { |
457 | - $query = "select count(*) as quantidade, CONVERT(date, dth_acesso) as data from infra_navegador where dth_acesso >= '" . $ultimadata . "' group by CONVERT(date, dth_acesso)"; | 456 | + $query = "select count(*) as quantidade, CONVERT(date, dth_acesso) as data from infra_navegador where dth_acesso >= " . $ultimadata . " group by CONVERT(date, dth_acesso)"; |
458 | } elseif ($sgbd == 'Oracle') { | 457 | } elseif ($sgbd == 'Oracle') { |
459 | - $query = "select count(*) as quantidade, to_char(dth_acesso,'YYYY-MM-DD') AS data from infra_navegador where dth_acesso >= date '" . $ultimadata . "' group by to_char(dth_acesso,'YYYY-MM-DD')"; | 458 | + $query = "select count(*) as quantidade, to_char(dth_acesso,'YYYY-MM-DD') AS data from infra_navegador where dth_acesso >= date " . $ultimadata . " group by to_char(dth_acesso,'YYYY-MM-DD')"; |
460 | } | 459 | } |
461 | 460 | ||
462 | $rs = array(); | 461 | $rs = array(); |
rn/MdEstatisticasEnviarRN.php
@@ -6,6 +6,10 @@ class MdEstatisticasEnviarRN extends InfraRN { | @@ -6,6 +6,10 @@ class MdEstatisticasEnviarRN extends InfraRN { | ||
6 | 6 | ||
7 | public function __construct(){ | 7 | public function __construct(){ |
8 | parent::__construct(); | 8 | parent::__construct(); |
9 | + | ||
10 | + $objConfiguracaoSEI = ConfiguracaoSEI::getInstance(); | ||
11 | + $this->url = $objConfiguracaoSEI->getValor('MdEstatisticas','url', false, 'http://estatisticas.planejamento.gov.br'); | ||
12 | + $this->orgaoSigla = $objConfiguracaoSEI->getValor('MdEstatisticas','sigla', false, ''); | ||
9 | } | 13 | } |
10 | 14 | ||
11 | protected function inicializarObjInfraIBanco(){ | 15 | protected function inicializarObjInfraIBanco(){ |
@@ -13,48 +17,43 @@ class MdEstatisticasEnviarRN extends InfraRN { | @@ -13,48 +17,43 @@ class MdEstatisticasEnviarRN extends InfraRN { | ||
13 | } | 17 | } |
14 | 18 | ||
15 | public function enviarIndicadores($indicadores) { | 19 | public function enviarIndicadores($indicadores) { |
20 | + return $this->doPost($this->url, $indicadores); | ||
21 | + } | ||
16 | 22 | ||
17 | - try { | ||
18 | - | ||
19 | - $json = json_encode($indicadores); | ||
20 | - InfraDebug::getInstance()->gravar('JSON: ' . $json, InfraLog::$INFORMACAO); | ||
21 | - | ||
22 | - $objConfiguracaoSEI = ConfiguracaoSEI::getInstance(); | ||
23 | - $url = $objConfiguracaoSEI->getValor('MdEstatisticas','url', false, 'http://estatisticas.planejamento.gov.br'); | ||
24 | - $orgaoSigla = $objConfiguracaoSEI->getValor('MdEstatisticas','sigla', false, ''); | ||
25 | - | ||
26 | - $output = $this->doPost($url, $json); | ||
27 | - $id = $output['id']; | ||
28 | - InfraDebug::getInstance()->gravar('Output: ' . json_encode($output), InfraLog::$INFORMACAO); | ||
29 | - InfraDebug::getInstance()->gravar('iD: ' . $id, InfraLog::$INFORMACAO); | ||
30 | - | ||
31 | - $data = $this->doGet($url . '/ultimoacesso?sigla=' . $orgaoSigla); | ||
32 | - $data = date($data); | ||
33 | - InfraDebug::getInstance()->gravar('Data: ' . $data, InfraLog::$INFORMACAO); | ||
34 | - | ||
35 | - return true; | 23 | + public function obterUltimoAcesso() { |
24 | + $data = $this->doGet($this->url . '/ultimoacesso?sigla=' . $this->orgaoSigla, false); | ||
25 | + return date($data); | ||
26 | + } | ||
36 | 27 | ||
37 | - } catch(Exception $e) { | ||
38 | - InfraDebug::getInstance()->setBolLigado(false); | ||
39 | - InfraDebug::getInstance()->setBolDebugInfra(false); | ||
40 | - InfraDebug::getInstance()->setBolEcho(false); | ||
41 | - throw new InfraException('Erro processando estatísticas do sistema.',$e); | ||
42 | - } | 28 | + public function enviarAcessos($acessos, $id) { |
29 | + $url = $this->url . '/acessos'; | ||
30 | + InfraDebug::getInstance()->gravar('URL: ' . $url, InfraLog::$INFORMACAO); | ||
31 | + $obj = array( | ||
32 | + id => $id, | ||
33 | + acessosUsuarios => $acessos | ||
34 | + ); | ||
35 | + InfraDebug::getInstance()->gravar('URL: ' . json_encode($obj), InfraLog::$INFORMACAO); | ||
36 | + return $this->doPost($url, $obj, false); | ||
43 | } | 37 | } |
44 | 38 | ||
45 | - private function doPost($url, $json) { | 39 | + private function doPost($url, $json, $isjson=true) { |
40 | + $data = json_encode($json); | ||
46 | $ch = curl_init(); | 41 | $ch = curl_init(); |
47 | curl_setopt($ch, CURLOPT_URL, $url); | 42 | curl_setopt($ch, CURLOPT_URL, $url); |
48 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | 43 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
49 | curl_setopt($ch, CURLOPT_POST, true); | 44 | curl_setopt($ch, CURLOPT_POST, true); |
50 | curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); | 45 | curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); |
51 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $json); | 46 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
52 | $output = curl_exec($ch); | 47 | $output = curl_exec($ch); |
53 | curl_close($ch); | 48 | curl_close($ch); |
54 | - return json_decode($output, true); | 49 | + |
50 | + if ($isjson) { | ||
51 | + return json_decode($output, true); | ||
52 | + } | ||
53 | + return $output; | ||
55 | } | 54 | } |
56 | 55 | ||
57 | - private function doGet($url, $isjson=false) { | 56 | + private function doGet($url, $isjson=true) { |
58 | $ch = curl_init(); | 57 | $ch = curl_init(); |
59 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | 58 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
60 | curl_setopt($ch, CURLOPT_URL, $url); | 59 | curl_setopt($ch, CURLOPT_URL, $url); |