Advertisement
Guest User

API-Chart.pm

a guest
Jul 18th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.12 KB | None | 0 0
  1. package GR::Controller::API;
  2. use Mojo::Base 'Mojolicious::Controller';
  3.  
  4. # This action will render a template
  5. sub classificacao {
  6.     my $self = shift;
  7.  
  8.     my $schema = $self->schema;
  9.  
  10.     my $result = [];
  11.  
  12.     $schema->storage->dbh_do( sub {
  13.         my ( $storage, $dbh, @args ) = @_;
  14.         my $sth = $dbh->prepare("SELECT queue.name AS Filas, COUNT(*) Quantidade FROM ticket, queue  WHERE ticket.create_time  BETWEEN '2015-07-01' and '2015-07-16'  AND ticket.queue_id = queue.id AND queue.valid_id = 1  GROUP BY queue.name;" );
  15.         $sth->execute(@args);
  16.  
  17.         while ( my $l = $sth->fetchrow_hashref ) {
  18.             push @{$result}, { name => $l->{Filas}, y => $l->{Quantidade}, drilldown => $l->{Filas} };
  19.         }
  20.  
  21.     } );
  22.    
  23.     $self->render( json => $result );
  24. }
  25.  
  26. ### Output in browser ###
  27. [{"y":"223","name":"Grupo de Operação Service Desk - SESMA","drilldown":"Grupo de Operação Service Desk - SESMA"},{"y":"56","name":"Grupo Especialista da Cibernix Tecnologia","drilldown":"Grupo Especialista da Cibernix Tecnologia"},{"y":"191","name":"Postmaster","drilldown":"Postmaster"}]
  28.  
  29. 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement