Explorar o código

Created service and pagination to get a ONU and changed composer.lock to do update from oauth bundle

Jean Sumara %!s(int64=5) %!d(string=hai) anos
pai
achega
f162973340

+ 1 - 1
composer.lock

@@ -1924,7 +1924,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@gogs.infra.flowdat.com:222/VendorSoftwareFlowdat3/AuthBundle.git",
-                "reference": "d19a60264e20574138f0cfec26b6a95322f85557"
+                "reference": "786c3bec2a96ec95b64823f6789a6842dcc881f8"
             },
             "type": "library",
             "autoload": {

+ 16 - 0
src/FTTHBundle/Controller/ONUCRUDController.php

@@ -2,6 +2,7 @@
 
 namespace FTTHBundle\Controller;
 
+use Symfony\Component\HttpFoundation\Request;
 use WorkflowBundle\Controller\CRUDController;
 use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -79,4 +80,19 @@ class ONUCRUDController extends CRUDController
         ), null);
     }
 
+    public function exportAction(Request $request)
+    {
+        $this->admin->checkAccess('export');
+        $tenancyService = $this->get('base_tenancy.tenancy_service');
+        $tenancyId = $tenancyService->getTenancyIdCurrent();
+
+        $format = $request->get('format');
+
+        $onuExportService = $this->get('onu_export_service');
+        $onuExportService->send($tenancyId, $format);
+
+        return $this->redirect('/admin/ftth/onu/list');
+    }
+
+
 }

+ 17 - 0
src/FTTHBundle/Controller/REST/ONURESTController.php

@@ -8,6 +8,8 @@ use FOS\RestBundle\Controller\Annotations\RouteResource;
 use FOS\RestBundle\Controller\Annotations\View;
 use FOS\RestBundle\Util\Codes;
 use FOS\RestBundle\View\View as FOSView;
+use FTTHBundle\Utils\JsonResponseUtils;
+use Symfony\Component\HttpFoundation\JsonResponse;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\Response;
 use WebserviceBundle\Controller\RESTController;
@@ -216,4 +218,19 @@ class ONURESTController extends RESTController
 
         return $output->fetch();
     }
+
+    /**
+     * GET Route annotation.
+     * @Get("/onus-export")
+     * @param Request $request
+     * @return JsonResponse
+     */
+    public function onuExportAction(Request $request)
+    {
+        $tenancyId = $request->headers->get('tenancyid') != null ? (int) $request->headers->get('tenancyid') : 1;
+        $currentPage = $request->headers->get('currentpage') != null ? (int) $request->headers->get('currentpage') : 1;
+        $limit = $request->headers->get('limit') != null ? (int) $request->headers->get('limit') : 20;
+        $onuExportService = $this->get('onu_export_service');
+        return JsonResponseUtils::make($onuExportService->getOnusWithCostumer($tenancyId, $currentPage, $limit));
+    }
 }

+ 48 - 0
src/FTTHBundle/Repository/ONURepository.php

@@ -2,6 +2,8 @@
 
 namespace FTTHBundle\Repository;
 
+use Doctrine\ORM\Query;
+
 class ONURepository extends \Doctrine\ORM\EntityRepository
 {
 
@@ -30,5 +32,51 @@ class ONURepository extends \Doctrine\ORM\EntityRepository
 
         return $qb->getQuery()->getResult();
     }
+
+    public function getAllOnusToExport($tenancyId, $offset, $limit){
+        $query = $this->createQueryBuilder('o');
+        $query
+            ->select([
+                'o.serialNumber',
+                'o.ponSerialNumber',
+                'o.currentState',
+                'o.clientId',
+                'o.ip',
+                'o.mac',
+                'o.radiusAuth',
+                'olt.name AS oltName',
+                'nap.name AS napName',
+                'nap.slot',
+                'nap.link',
+                'o.position',
+                'o.catv',
+                'o.voip',
+                'o.activationCode',
+                'o.created',
+                'o.updated'
+            ])
+            ->join('o.olt', "olt")
+            ->leftJoin('o.nap', "nap")
+            ->where('o.tenancyId = :tenancyId')
+            ->setParameter('tenancyId', $tenancyId)
+            ->orderBy('o.created', 'DESC')
+            ->setMaxResults($limit)
+            ->setFirstResult($offset);
+
+        return $query->getQuery()->getResult();
+    }
+
+
+
+    public function getAllOnusToExportCount($tenancyId){
+        $query = $this->createQueryBuilder('o');
+        $query
+            ->select('COUNT(o)')
+            ->join('o.olt', "olt")
+            ->leftJoin('o.nap', "nap")
+            ->where('o.tenancyId = :tenancyId')
+            ->setParameter('tenancyId', $tenancyId);
+        return $query->getQuery()->getResult(Query::HYDRATE_SINGLE_SCALAR);
+    }
     
 }

+ 5 - 1
src/FTTHBundle/Resources/config/services.yml

@@ -145,4 +145,8 @@ services:
 
     client_service:
         class: FTTHBundle\Service\ClientService
-        arguments: ["@doctrine.orm.entity_manager", "@base_tenancy.tenancy_service", "@service_container"]
+        arguments: ["@doctrine.orm.entity_manager", "@base_tenancy.tenancy_service", "@service_container"]
+
+    onu_export_service:
+        class: FTTHBundle\Service\OnuExportService
+        arguments: ["@service_container"]