Sfoglia il codice sorgente

Merge branch '1-onu-consumption-function-not-working-properly' into 'master'

Resolve "ONU Consumption Function Not Working Properly"

Closes #1

See merge request interlink-sa/flowdat3/modules/stats!50
Daniel Libonati 6 anni fa
parent
commit
dde9b3c082
1 ha cambiato i file con 25 aggiunte e 4 eliminazioni
  1. 25 4
      src/StatsBundle/Controller/StatsController.php

+ 25 - 4
src/StatsBundle/Controller/StatsController.php

@@ -2429,23 +2429,44 @@ class StatsController extends Controller
         
         $serializer = $this->container->get('serializer');
         $em = $this->get('doctrine')->getManager();
+
         $devices = $em->getRepository('StatsBundle:DeviceConsumption')->createQueryBuilder('c')
-            ->select('c.device AS device', 'SUM(c.in) AS i','SUM(c.out) AS o')
-            ->leftJoin('StatsBundle:Onu', 'onu', 'WITH', 'c.device = onu.ponSerialNumber')
+            ->select('c.device AS device', 'SUM(c.in) AS i','SUM(c.out) AS o', 'SUM(c.in + c.out) AS total')
             ->where('c.server = :server')
-            ->andWhere('onu.oltDeviceId = :deviceId')
+            ->andWhere('c.fatherDevice = :fatherDevice')
             ->andWhere('c.fatherDeviceType = :fatherDeviceType')
             ->andWhere('c.date >= :from')
             ->andWhere('c.date <= :to')
             ->setParameter('server', 1)
-            ->setParameter('deviceId', $deviceId)
+            ->setParameter('fatherDevice', $deviceId)
             ->setParameter('fatherDeviceType', 2)
             ->setParameter('from', $from)
             ->setParameter('to', $to)
+            ->setMaxResults(intval($limit))
             ->groupBy('c.device')
             ->getQuery()
             ->getResult();
 
+        if(empty($devices)) {
+            $devices = $em->getRepository('StatsBundle:DeviceConsumption')->createQueryBuilder('c')
+                ->select('c.device AS device', 'SUM(c.in) AS i','SUM(c.out) AS o', 'SUM(c.in + c.out) AS total')
+                ->leftJoin('StatsBundle:Onu', 'onu', 'WITH', 'c.device = onu.ponSerialNumber')
+                ->where('c.server = :server')
+                ->andWhere('onu.oltDeviceId = :deviceId')
+                ->andWhere('c.fatherDeviceType = :fatherDeviceType')
+                ->andWhere('c.date >= :from')
+                ->andWhere('c.date <= :to')
+                ->setParameter('server', 1)
+                ->setParameter('deviceId', $deviceId)
+                ->setParameter('fatherDeviceType', 3)
+                ->setParameter('from', $from)
+                ->setParameter('to', $to)
+                ->setMaxResults(intval($limit))
+                ->groupBy('c.device')
+                ->getQuery()
+                ->getResult();
+        }
+
         $jsonClients = $serializer->serialize($devices, 'json');
         return JsonResponse::fromJsonString($jsonClients);
     }