Commit 62add16dc4c907cb535b419d40daa10aeb36d17a

Authored by Guilherme Andrade Del Cantoni
1 parent 29a37c57

Alinhamento de compatibilidade de scripts entre Oracle e SQLServer

Showing 1 changed file with 12 additions and 5 deletions   Show diff stats
rn/ProcessoExpedidoRN.php
@@ -15,9 +15,11 @@ class ProcessoExpedidoRN extends InfraRN { @@ -15,9 +15,11 @@ class ProcessoExpedidoRN extends InfraRN {
15 public function listarProcessoExpedido(ProtocoloDTO &$objProtocoloDTO) { 15 public function listarProcessoExpedido(ProtocoloDTO &$objProtocoloDTO) {
16 16
17 $bolSqlServer = $this->getObjInfraIBanco() instanceof InfraSqlServer; 17 $bolSqlServer = $this->getObjInfraIBanco() instanceof InfraSqlServer;
  18 + $bolOracle = $this->getObjInfraIBanco() instanceof InfraOracle;
18 $numLimit = $objProtocoloDTO->getNumMaxRegistrosRetorno(); 19 $numLimit = $objProtocoloDTO->getNumMaxRegistrosRetorno();
19 $numOffset = $objProtocoloDTO->getNumPaginaAtual() * $objProtocoloDTO->getNumMaxRegistrosRetorno(); 20 $numOffset = $objProtocoloDTO->getNumPaginaAtual() * $objProtocoloDTO->getNumMaxRegistrosRetorno();
20 $strInstrucaoPaginacao = (!$bolSqlServer) ? "LIMIT ".$numOffset.",".$numLimit : "OFFSET $numOffset ROWS FETCH NEXT $numLimit ROWS ONLY"; 21 $strInstrucaoPaginacao = (!$bolSqlServer) ? "LIMIT ".$numOffset.",".$numLimit : "OFFSET $numOffset ROWS FETCH NEXT $numLimit ROWS ONLY";
  22 + $strInstrucaoPaginacao = ($bolOracle) ? "" : $strInstrucaoPaginacao;
21 23
22 $sql = "SELECT 24 $sql = "SELECT
23 p.id_protocolo, 25 p.id_protocolo,
@@ -41,14 +43,20 @@ class ProcessoExpedidoRN extends InfraRN { @@ -41,14 +43,20 @@ class ProcessoExpedidoRN extends InfraRN {
41 ptra.dth_registro = (SELECT MAX(pt.dth_registro) dth_registro FROM md_pen_tramite pt WHERE pt.numero_registro = pe.numero_registro) 43 ptra.dth_registro = (SELECT MAX(pt.dth_registro) dth_registro FROM md_pen_tramite pt WHERE pt.numero_registro = pe.numero_registro)
42 AND 44 AND
43 NOT EXISTS ( 45 NOT EXISTS (
44 - SELECT at2.* FROM atividade as at2 46 + SELECT at2.* FROM atividade at2
45 WHERE at2.id_protocolo = p.id_protocolo 47 WHERE at2.id_protocolo = p.id_protocolo
46 AND at2.id_tarefa = ". ProcessoEletronicoRN::obterIdTarefaModulo(ProcessoEletronicoRN::$TI_PROCESSO_ELETRONICO_PROCESSO_RECEBIDO) ." 48 AND at2.id_tarefa = ". ProcessoEletronicoRN::obterIdTarefaModulo(ProcessoEletronicoRN::$TI_PROCESSO_ELETRONICO_PROCESSO_RECEBIDO) ."
47 AND at2.dth_abertura > a.dth_abertura ) 49 AND at2.dth_abertura > a.dth_abertura )
48 GROUP BY 50 GROUP BY
49 p.id_protocolo, p.protocolo_formatado, a.id_unidade , atd.valor , us.id_usuario, us.nome, a.dth_abertura ORDER BY a.dth_abertura DESC ".$strInstrucaoPaginacao; 51 p.id_protocolo, p.protocolo_formatado, a.id_unidade , atd.valor , us.id_usuario, us.nome, a.dth_abertura ORDER BY a.dth_abertura DESC ".$strInstrucaoPaginacao;
50 52
51 - $sqlCount = "SELECT 53 +
  54 + if ($this->getObjInfraIBanco() instanceof InfraOracle){
  55 + $qtd = $numLimit + $numLimit;
  56 + $sql = "select a.* from ($sql) a where rownum >= $numOffset and rownum <= $qtd";
  57 + }
  58 +
  59 + $sqlCount = "SELECT
52 count(*) total 60 count(*) total
53 FROM protocolo p 61 FROM protocolo p
54 INNER JOIN atividade a ON a.id_protocolo = p.id_protocolo 62 INNER JOIN atividade a ON a.id_protocolo = p.id_protocolo
@@ -64,13 +72,12 @@ class ProcessoExpedidoRN extends InfraRN { @@ -64,13 +72,12 @@ class ProcessoExpedidoRN extends InfraRN {
64 ptra.dth_registro = (SELECT MAX(pt.dth_registro) dth_registro FROM md_pen_tramite pt WHERE pt.numero_registro = pe.numero_registro) 72 ptra.dth_registro = (SELECT MAX(pt.dth_registro) dth_registro FROM md_pen_tramite pt WHERE pt.numero_registro = pe.numero_registro)
65 AND 73 AND
66 NOT EXISTS ( 74 NOT EXISTS (
67 - SELECT at2.* FROM atividade as at2 75 + SELECT at2.* FROM atividade at2
68 WHERE at2.id_protocolo = p.id_protocolo 76 WHERE at2.id_protocolo = p.id_protocolo
69 AND at2.id_tarefa = ". ProcessoEletronicoRN::obterIdTarefaModulo(ProcessoEletronicoRN::$TI_PROCESSO_ELETRONICO_PROCESSO_RECEBIDO) ." 77 AND at2.id_tarefa = ". ProcessoEletronicoRN::obterIdTarefaModulo(ProcessoEletronicoRN::$TI_PROCESSO_ELETRONICO_PROCESSO_RECEBIDO) ."
70 AND at2.dth_abertura > a.dth_abertura ) "; 78 AND at2.dth_abertura > a.dth_abertura ) ";
71 79
72 -  
73 - 80 +//die($sql);
74 $pag = $this->getObjInfraIBanco()->consultarSql($sql); 81 $pag = $this->getObjInfraIBanco()->consultarSql($sql);
75 $count = $this->getObjInfraIBanco()->consultarSql($sqlCount); 82 $count = $this->getObjInfraIBanco()->consultarSql($sqlCount);
76 $total = $count ? $count[0]['total'] : 0; 83 $total = $count ? $count[0]['total'] : 0;