Commit 21222d80bfa62b4218edb69007d99e6b53f90832
1 parent
2e2fb435
Exists in
master
and in
2 other branches
Corrige a coleta para forçar atualizaçao no getTest e melhorias de relatorio do Cocar
Showing
3 changed files
with
81 additions
and
35 deletions
Show diff stats
Command/CronCommand.php
@@ -14,7 +14,7 @@ class CronCommand extends ContainerAwareCommand | @@ -14,7 +14,7 @@ class CronCommand extends ContainerAwareCommand | ||
14 | * | 14 | * |
15 | * @var type object | 15 | * @var type object |
16 | */ | 16 | */ |
17 | - private $em; | 17 | + //private $em; |
18 | 18 | ||
19 | protected function configure() | 19 | protected function configure() |
20 | { | 20 | { |
@@ -70,7 +70,7 @@ class CronCommand extends ContainerAwareCommand | @@ -70,7 +70,7 @@ class CronCommand extends ContainerAwareCommand | ||
70 | 70 | ||
71 | protected function execute(InputInterface $input, OutputInterface $output) | 71 | protected function execute(InputInterface $input, OutputInterface $output) |
72 | { | 72 | { |
73 | - $this->em = $this->getContainer()->get('doctrine')->getManager(); | 73 | + //$this->em = $this->getContainer()->get('doctrine')->getManager(); |
74 | //$this->getApplication()->getKernel()->getContainer()->get('doctrine')->getManager(); | 74 | //$this->getApplication()->getKernel()->getContainer()->get('doctrine')->getManager(); |
75 | 75 | ||
76 | $return = null; | 76 | $return = null; |
@@ -130,8 +130,11 @@ class CronCommand extends ContainerAwareCommand | @@ -130,8 +130,11 @@ class CronCommand extends ContainerAwareCommand | ||
130 | file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/endalarm"); | 130 | file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/endalarm"); |
131 | elseif($task == 'graphdailyperform') | 131 | elseif($task == 'graphdailyperform') |
132 | file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/graphdailyperform"); | 132 | file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/graphdailyperform"); |
133 | - elseif($task == 'printer') | ||
134 | - $this->getContainer()->get('printer')->totalizer(); | 133 | + elseif($task == 'printer') { |
134 | + $printer_controller = $this->getContainer()->get('printer'); | ||
135 | + $printer_controller->setContainer($this->getContainer()); | ||
136 | + $printer_controller->totalizer(); | ||
137 | + } | ||
135 | 138 | ||
136 | } | 139 | } |
137 | catch(Exception $e) | 140 | catch(Exception $e) |
Controller/PrinterController.php
@@ -64,6 +64,7 @@ class PrinterController extends Controller | @@ -64,6 +64,7 @@ class PrinterController extends Controller | ||
64 | $start = $start->format('U'); | 64 | $start = $start->format('U'); |
65 | 65 | ||
66 | $end = new \DateTime($form['endDate']); | 66 | $end = new \DateTime($form['endDate']); |
67 | + $end->setTime('23', '59', '59'); | ||
67 | $end = $end->format('U'); | 68 | $end = $end->format('U'); |
68 | } | 69 | } |
69 | 70 | ||
@@ -109,6 +110,7 @@ class PrinterController extends Controller | @@ -109,6 +110,7 @@ class PrinterController extends Controller | ||
109 | $start = $start->format('U'); | 110 | $start = $start->format('U'); |
110 | 111 | ||
111 | $end = new \DateTime($form['endDate']); | 112 | $end = new \DateTime($form['endDate']); |
113 | + $end->setTime('23', '59', '59'); | ||
112 | $endcsv = $end->format('d/m/Y'); | 114 | $endcsv = $end->format('d/m/Y'); |
113 | $end = $end->format('U'); | 115 | $end = $end->format('U'); |
114 | } | 116 | } |
@@ -118,8 +120,20 @@ class PrinterController extends Controller | @@ -118,8 +120,20 @@ class PrinterController extends Controller | ||
118 | 120 | ||
119 | $printers = $em->getRepository('CocarBundle:PrinterCounter')->relatorioCsvGeral($start, $end); | 121 | $printers = $em->getRepository('CocarBundle:PrinterCounter')->relatorioCsvGeral($start, $end); |
120 | 122 | ||
123 | + // Gera cabeçalho | ||
124 | + $cabecalho = array(); | ||
125 | + foreach($printers as $elm) { | ||
126 | + array_push($cabecalho, array_keys($elm)); | ||
127 | + break; | ||
128 | + } | ||
129 | + // Adiciona contagem no cabeçalho | ||
130 | + array_push($cabecalho[0], 'totalPrints'); | ||
131 | + | ||
132 | + // Gera CSV | ||
133 | + $reader = new ArrayReader(array_merge($cabecalho, $printers)); | ||
134 | + | ||
121 | // Gera CSV | 135 | // Gera CSV |
122 | - $reader = new ArrayReader($printers); | 136 | + //$reader = new ArrayReader($printers); |
123 | 137 | ||
124 | // Create the workflow from the reader | 138 | // Create the workflow from the reader |
125 | $workflow = new Workflow($reader); | 139 | $workflow = new Workflow($reader); |
@@ -127,7 +141,11 @@ class PrinterController extends Controller | @@ -127,7 +141,11 @@ class PrinterController extends Controller | ||
127 | 141 | ||
128 | // Contador geral das impressorasa | 142 | // Contador geral das impressorasa |
129 | $converter = new CallbackItemConverter(function ($item) { | 143 | $converter = new CallbackItemConverter(function ($item) { |
130 | - $item['totalPrints'] = $item['printsEnd'] - $item['printsStart']; | 144 | + if (array_key_exists('printsEnd', $item) && array_key_exists('printsStart', $item)) { |
145 | + $item['totalPrints'] = $item['printsEnd'] - $item['printsStart']; | ||
146 | + } else { | ||
147 | + $item['totalPrints'] = null; | ||
148 | + } | ||
131 | return $item; | 149 | return $item; |
132 | }); | 150 | }); |
133 | $workflow->addItemConverter($converter); | 151 | $workflow->addItemConverter($converter); |
@@ -185,6 +203,7 @@ class PrinterController extends Controller | @@ -185,6 +203,7 @@ class PrinterController extends Controller | ||
185 | $start = $start->format('U'); | 203 | $start = $start->format('U'); |
186 | 204 | ||
187 | $end = new \DateTime($form['endDate']); | 205 | $end = new \DateTime($form['endDate']); |
206 | + $end->setTime('23', '59', '59'); | ||
188 | $end = $end->format('U'); | 207 | $end = $end->format('U'); |
189 | } | 208 | } |
190 | 209 | ||
@@ -233,7 +252,10 @@ class PrinterController extends Controller | @@ -233,7 +252,10 @@ class PrinterController extends Controller | ||
233 | $start = $start->format('U'); | 252 | $start = $start->format('U'); |
234 | 253 | ||
235 | $end = new \DateTime($form['endDate']); | 254 | $end = new \DateTime($form['endDate']); |
255 | + $end->setTime('23', '59', '59'); | ||
236 | $end = $end->format('U'); | 256 | $end = $end->format('U'); |
257 | + | ||
258 | + $this->get('logger')->debug("Relatório CSV Detalhado. Início = " . $form['startDate'] . " Fim = " . $form['endDate']); | ||
237 | } | 259 | } |
238 | 260 | ||
239 | $start = isset($start) ? $start : (time() - ((60*60*24)*30)); | 261 | $start = isset($start) ? $start : (time() - ((60*60*24)*30)); |
@@ -241,15 +263,31 @@ class PrinterController extends Controller | @@ -241,15 +263,31 @@ class PrinterController extends Controller | ||
241 | 263 | ||
242 | $printers = $em->getRepository('CocarBundle:PrinterCounter')->relatorioCsvGeralDetalhado($start, $end); | 264 | $printers = $em->getRepository('CocarBundle:PrinterCounter')->relatorioCsvGeralDetalhado($start, $end); |
243 | 265 | ||
266 | + // Gera cabeçalho | ||
267 | + $cabecalho = array(); | ||
268 | + foreach($printers as $elm) { | ||
269 | + array_push($cabecalho, array_keys($elm)); | ||
270 | + break; | ||
271 | + } | ||
272 | + // Adiciona contagem no cabeçalho | ||
273 | + array_push($cabecalho[0], 'totalPrints'); | ||
274 | + | ||
275 | + // Gera CSV | ||
276 | + $reader = new ArrayReader(array_merge($cabecalho, $printers)); | ||
277 | + | ||
244 | // Gera CSV | 278 | // Gera CSV |
245 | - $reader = new ArrayReader($printers); | 279 | + //$reader = new ArrayReader($printers); |
246 | 280 | ||
247 | // Create the workflow from the reader | 281 | // Create the workflow from the reader |
248 | $workflow = new Workflow($reader); | 282 | $workflow = new Workflow($reader); |
249 | 283 | ||
250 | // Contador geral das impressorasa | 284 | // Contador geral das impressorasa |
251 | $converter = new CallbackItemConverter(function ($item) { | 285 | $converter = new CallbackItemConverter(function ($item) { |
252 | - $item['totalPrints'] = $item['printsEnd'] - $item['printsStart']; | 286 | + if (array_key_exists('printsEnd', $item) && array_key_exists('printsStart', $item)) { |
287 | + $item['totalPrints'] = $item['printsEnd'] - $item['printsStart']; | ||
288 | + } else { | ||
289 | + $item['totalPrints'] = null; | ||
290 | + } | ||
253 | return $item; | 291 | return $item; |
254 | }); | 292 | }); |
255 | $workflow->addItemConverter($converter); | 293 | $workflow->addItemConverter($converter); |
@@ -567,6 +605,9 @@ class PrinterController extends Controller | @@ -567,6 +605,9 @@ class PrinterController extends Controller | ||
567 | 605 | ||
568 | public function totalizer() | 606 | public function totalizer() |
569 | { | 607 | { |
608 | + ini_set('memory_limit', '1024M'); | ||
609 | + gc_enable(); | ||
610 | + | ||
570 | $printers = $this->em->getRepository('CocarBundle:Printer')->findAll(); | 611 | $printers = $this->em->getRepository('CocarBundle:Printer')->findAll(); |
571 | 612 | ||
572 | foreach($printers as $printer) | 613 | foreach($printers as $printer) |
@@ -587,6 +628,7 @@ class PrinterController extends Controller | @@ -587,6 +628,7 @@ class PrinterController extends Controller | ||
587 | catch(Exception $e) | 628 | catch(Exception $e) |
588 | { | 629 | { |
589 | #return new Response($e->getMessage()); | 630 | #return new Response($e->getMessage()); |
631 | + $this->get('logger')->error("Erro na coleta da impressora $host \n".$e->getMessage()); | ||
590 | } | 632 | } |
591 | } | 633 | } |
592 | return new Response(); | 634 | return new Response(); |
@@ -609,7 +651,7 @@ class PrinterController extends Controller | @@ -609,7 +651,7 @@ class PrinterController extends Controller | ||
609 | if(empty($counter)) { | 651 | if(empty($counter)) { |
610 | $counter = new PrinterCounter; | 652 | $counter = new PrinterCounter; |
611 | } else { | 653 | } else { |
612 | - $this->get('logger')->info("Entrada repetida para impressora $printer e data $time"); | 654 | + $this->get('logger')->error("Entrada repetida para impressora $printer e data $time"); |
613 | return true; | 655 | return true; |
614 | } | 656 | } |
615 | 657 |
Entity/PrinterCounterRepository.php
@@ -309,7 +309,33 @@ class PrinterCounterRepository extends EntityRepository | @@ -309,7 +309,33 @@ class PrinterCounterRepository extends EntityRepository | ||
309 | $sql = "SELECT printer.id, | 309 | $sql = "SELECT printer.id, |
310 | pc1.blackink, | 310 | pc1.blackink, |
311 | pc1.coloredink, | 311 | pc1.coloredink, |
312 | - to_timestamp(CASE WHEN max(pc1.date) IS NULL | 312 | + |
313 | + (CASE WHEN min(pc1.date) IS NULL | ||
314 | + THEN (SELECT max(date) | ||
315 | + FROM tb_printer_counter | ||
316 | + WHERE date <= ? | ||
317 | + AND printer_id = printer.id) | ||
318 | + ELSE min(pc1.date) | ||
319 | + END) as startDate, | ||
320 | + | ||
321 | + (CASE WHEN (SELECT pc2.prints | ||
322 | + FROM tb_printer_counter pc2 | ||
323 | + WHERE pc2.date = min(pc1.date) | ||
324 | + AND pc2.printer_id = printer.id) IS NULL | ||
325 | + THEN (SELECT pc5.prints | ||
326 | + FROM tb_printer_counter pc5 | ||
327 | + WHERE pc5.date = (SELECT max(date) | ||
328 | + FROM tb_printer_counter | ||
329 | + WHERE date <= ? | ||
330 | + AND printer_id = printer.id) | ||
331 | + AND pc5.printer_id = printer.id) | ||
332 | + ELSE (SELECT pc4.prints | ||
333 | + FROM tb_printer_counter pc4 | ||
334 | + WHERE pc4.date = min(pc1.date) | ||
335 | + AND pc4.printer_id = printer.id) | ||
336 | + END) as printsStart, | ||
337 | + | ||
338 | + (CASE WHEN max(pc1.date) IS NULL | ||
313 | THEN (CASE WHEN (SELECT min(date) | 339 | THEN (CASE WHEN (SELECT min(date) |
314 | FROM tb_printer_counter | 340 | FROM tb_printer_counter |
315 | WHERE date >= ? | 341 | WHERE date >= ? |
@@ -356,31 +382,6 @@ class PrinterCounterRepository extends EntityRepository | @@ -356,31 +382,6 @@ class PrinterCounterRepository extends EntityRepository | ||
356 | AND pc2.printer_id = printer.id) | 382 | AND pc2.printer_id = printer.id) |
357 | END) as printsEnd, | 383 | END) as printsEnd, |
358 | 384 | ||
359 | - (CASE WHEN min(pc1.date) IS NULL | ||
360 | - THEN (SELECT max(date) | ||
361 | - FROM tb_printer_counter | ||
362 | - WHERE date <= ? | ||
363 | - AND printer_id = printer.id) | ||
364 | - ELSE min(pc1.date) | ||
365 | - END) as startDate, | ||
366 | - | ||
367 | - (CASE WHEN (SELECT pc2.prints | ||
368 | - FROM tb_printer_counter pc2 | ||
369 | - WHERE pc2.date = min(pc1.date) | ||
370 | - AND pc2.printer_id = printer.id) IS NULL | ||
371 | - THEN (SELECT pc5.prints | ||
372 | - FROM tb_printer_counter pc5 | ||
373 | - WHERE pc5.date = (SELECT max(date) | ||
374 | - FROM tb_printer_counter | ||
375 | - WHERE date <= ? | ||
376 | - AND printer_id = printer.id) | ||
377 | - AND pc5.printer_id = printer.id) | ||
378 | - ELSE (SELECT pc4.prints | ||
379 | - FROM tb_printer_counter pc4 | ||
380 | - WHERE pc4.date = min(pc1.date) | ||
381 | - AND pc4.printer_id = printer.id) | ||
382 | - END) as printsStart, | ||
383 | - | ||
384 | printer.name, | 385 | printer.name, |
385 | printer.description, | 386 | printer.description, |
386 | printer.serie, | 387 | printer.serie, |