Commit f8c765a442a325204b9e159d956a39436e0f26a1
1 parent
2aa4d924
Exists in
master
relatório de usuário logado
Showing
1 changed file
with
91 additions
and
2 deletions
Show diff stats
src/Cacic/CommonBundle/Entity/LogAcessoRepository.php
| @@ -160,10 +160,99 @@ GROUP BY c0_.te_node_address, | @@ -160,10 +160,99 @@ GROUP BY c0_.te_node_address, | ||
| 160 | return $query->execute(); | 160 | return $query->execute(); |
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | + /* | ||
| 164 | + * Consulta para relatório de contendo ultimo usuário logado | ||
| 165 | + */ | ||
| 166 | + public function gerarRelatorioUsuario( $filtros, $filtroLocais, $dataInicio, $dataFim, $usuario ) | ||
| 167 | + { | ||
| 168 | + $rsm = new ResultSetMapping(); | ||
| 169 | + $rsm->addScalarResult('te_node_address', 'teNodeAddress'); | ||
| 170 | + $rsm->addScalarResult('id_computador', 'idComputador'); | ||
| 171 | + $rsm->addScalarResult('te_ip_computador', 'teIpComputador'); | ||
| 172 | + $rsm->addScalarResult('nm_computador', 'nmComputador'); | ||
| 173 | + $rsm->addScalarResult('id_so', 'idSo'); | ||
| 174 | + $rsm->addScalarResult('sg_so', 'sgSo'); | ||
| 175 | + $rsm->addScalarResult('id_rede', 'idRede'); | ||
| 176 | + $rsm->addScalarResult('nm_rede', 'nmRede'); | ||
| 177 | + $rsm->addScalarResult('te_ip_rede', 'teIpRede'); | ||
| 178 | + $rsm->addScalarResult('max_data', 'data'); | ||
| 179 | + $rsm->addScalarResult('nm_local', 'nmLocal'); | ||
| 180 | + $rsm->addScalarResult('id_local', 'idLocal'); | ||
| 181 | + $rsm->addScalarResult('usuario', 'usuario'); | ||
| 182 | + | ||
| 183 | + $sql = " | ||
| 184 | +SELECT c0_.te_node_address AS te_node_address, | ||
| 185 | + string_agg(DISTINCT CAST(c0_.id_computador AS text), ', ') as id_computador, | ||
| 186 | + string_agg(DISTINCT c0_.te_ip_computador, ', ') as te_ip_computador, | ||
| 187 | + string_agg(DISTINCT c0_.nm_computador, ', ') AS nm_computador, | ||
| 188 | + string_agg(DISTINCT CAST(s2_.id_so AS text), ', ') AS id_so, | ||
| 189 | + string_agg(DISTINCT s2_.sg_so, ', ') AS sg_so, | ||
| 190 | + string_agg(DISTINCT CAST(r3_.id_rede AS text), ', ') AS id_rede, | ||
| 191 | + string_agg(DISTINCT r3_.nm_rede, ', ') AS nm_rede, | ||
| 192 | + string_agg(DISTINCT r3_.te_ip_rede, ', ') AS te_ip_rede, | ||
| 193 | + string_agg(DISTINCT la5_.usuario, ', ') AS usuario, | ||
| 194 | + max(l1_.data) AS max_data, | ||
| 195 | + l4_.nm_local AS nm_local, | ||
| 196 | + l4_.id_local AS id_local | ||
| 197 | +FROM log_acesso l1_ | ||
| 198 | +INNER JOIN computador c0_ ON l1_.id_computador = c0_.id_computador | ||
| 199 | +INNER JOIN so s2_ ON c0_.id_so = s2_.id_so | ||
| 200 | +INNER JOIN rede r3_ ON c0_.id_rede = r3_.id_rede | ||
| 201 | +INNER JOIN local l4_ ON r3_.id_local = l4_.id_local | ||
| 202 | +INNER JOIN log_acesso la5_ ON c0_.id_computador = la5_.id_computador | ||
| 203 | +WHERE 1 = 1 | ||
| 204 | +"; | ||
| 205 | + | ||
| 206 | + /** | ||
| 207 | + * Verifica os filtros que foram parametrizados | ||
| 208 | + */ | ||
| 209 | + if ( $dataInicio ) { | ||
| 210 | + $sql .= " AND l1_.data >= ? "; | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + if ( $dataFim ) { | ||
| 214 | + $sql .= " AND l1_.data <= ?"; | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + if ( $usuario ) { | ||
| 218 | + $sql .= " AND lower(l1_.usuario) LIKE lower(?)"; | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + if ( $filtroLocais ) { | ||
| 222 | + $sql .= " AND r3_.id_local IN (?)"; | ||
| 223 | + } | ||
| 224 | + | ||
| 225 | + $sql .= " | ||
| 226 | +GROUP BY c0_.te_node_address, | ||
| 227 | + l4_.nm_local, | ||
| 228 | + l4_.id_local | ||
| 229 | + "; | ||
| 230 | + | ||
| 231 | + $query = $this->getEntityManager()->createNativeQuery($sql, $rsm); | ||
| 232 | + | ||
| 233 | + /** | ||
| 234 | + * Verifica os filtros que foram parametrizados | ||
| 235 | + */ | ||
| 236 | + if ( $dataInicio ) { | ||
| 237 | + $query->setParameter(1, ( $dataInicio.' 00:00:00' )); | ||
| 238 | + } | ||
| 239 | + | ||
| 240 | + | ||
| 241 | + if ( $dataFim ) | ||
| 242 | + $query->setParameter(2, ( $dataFim.' 23:59:59' )); | ||
| 243 | + | ||
| 244 | + if ( $usuario ) | ||
| 245 | + $query->setParameter(3, "%$usuario%" ); | ||
| 246 | + | ||
| 247 | + if ( $filtroLocais ) | ||
| 248 | + $query->setParameter(4, $filtroLocais); | ||
| 249 | + | ||
| 250 | + | ||
| 251 | + return $query->execute(); | ||
| 252 | + } | ||
| 253 | + | ||
| 163 | /** | 254 | /** |
| 164 | - * | ||
| 165 | * Total de computadores monitorados nos últimos 30 dias | 255 | * Total de computadores monitorados nos últimos 30 dias |
| 166 | - * | ||
| 167 | */ | 256 | */ |
| 168 | 257 | ||
| 169 | public function countPorComputador() { | 258 | public function countPorComputador() { |