Browse Source

Función para devolver consumo de ONUs por OLT

Daniel Libonati 6 years ago
parent
commit
df3aff98dd
1 changed files with 31 additions and 0 deletions
  1. 31 0
      src/StatsBundle/Controller/StatsController.php

+ 31 - 0
src/StatsBundle/Controller/StatsController.php

@@ -2419,4 +2419,35 @@ class StatsController extends Controller
         die;
     }
 
+    /**
+     * @Route("/admin/stats/olt/{deviceId}/getConsumption", name="get_device_consumption_by_device_id")
+     */
+    public function getDeviceConsumptionByDeviceId($deviceId) {
+        
+        $from = date("Y-m-d",strtotime('-30 days'));
+        $to = date("Y-m-d");
+        
+        $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')
+            ->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', 2)
+            ->setParameter('from', $from)
+            ->setParameter('to', $to)
+            ->groupBy('c.device')
+            ->getQuery()
+            ->getResult();
+
+        $jsonClients = $serializer->serialize($devices, 'json');
+        return JsonResponse::fromJsonString($jsonClients);
+    }
+
 }