|
@@ -0,0 +1,72 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+
|
|
|
+namespace FTTHBundle\Service;
|
|
|
+
|
|
|
+
|
|
|
+use FTTHBundle\Entity\ONU;
|
|
|
+use FTTHBundle\Utils\PageTrait;
|
|
|
+use PhpAmqpLib\Message\AMQPMessage;
|
|
|
+use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
+
|
|
|
+class OnuExportService
|
|
|
+{
|
|
|
+ use PageTrait;
|
|
|
+
|
|
|
+ private $container;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * OnuExportService constructor.
|
|
|
+ * @param ContainerInterface $container
|
|
|
+ */
|
|
|
+ public function __construct(ContainerInterface $container)
|
|
|
+ {
|
|
|
+ $this->container = $container;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function send($tenancyId, $format){
|
|
|
+ $amqpChannel = $this->container->get('amqp.channel');
|
|
|
+
|
|
|
+ try{
|
|
|
+ $msgBody = serialize([
|
|
|
+ 'tenancyId' => $tenancyId,
|
|
|
+ 'format' => $format,
|
|
|
+ 'endpointToken' => 'https://'.getenv('HOST_BASE')."/oauth/v2/token",
|
|
|
+ 'endpointOnus' => 'https://'.getenv('HOST_FTTH')."/api/onus-export",
|
|
|
+ 'params' => [
|
|
|
+ 'client_id' => getenv('OAUTH_CLIENT_ID'),
|
|
|
+ 'client_secret' => getenv('OAUTH_CLIENT_SECRET'),
|
|
|
+ 'grant_type' => 'client_credentials'
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+ $amqpChannel->basic_publish(new AMQPMessage((string) $msgBody), '','export.ftth');
|
|
|
+ }catch (\Exception $ex){
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getOnusWithCostumer($tenancyId = 1, $currentPage = 1, $limit = 2){
|
|
|
+ $entityManager = $this->container->get('doctrine')->getManager();
|
|
|
+ $onuRepository = $entityManager->getRepository(ONU::class);
|
|
|
+
|
|
|
+
|
|
|
+ $currentPage = $this->getPage($currentPage);
|
|
|
+ $limit = $this->getLimit($limit);
|
|
|
+ $offset = $this->getOffset($currentPage, $limit);
|
|
|
+ $total = 0;
|
|
|
+
|
|
|
+ $result = $onuRepository->getAllOnusToExport($tenancyId, $offset, $limit);
|
|
|
+ if ($result) {
|
|
|
+ $total = $onuRepository->getAllOnusToExportCount($tenancyId);
|
|
|
+ }
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'data' => $result,
|
|
|
+ 'currentPage' => $currentPage,
|
|
|
+ 'limit' => $limit,
|
|
|
+ 'total' => $total,
|
|
|
+ 'pages' => ceil($total / $limit),
|
|
|
+ 'hasNext' => ceil($total / $limit) > $currentPage
|
|
|
+ ];
|
|
|
+ }
|
|
|
+}
|