src/Application/Internit/ApiBundle/Controller/CronApiController.php line 49

Open in your IDE?
  1. <?php
  2. namespace App\Application\Internit\ApiBundle\Controller;
  3. use App\Application\Internit\BlocoBundle\Entity\Bloco;
  4. use App\Application\Internit\ClienteBundle\Entity\Cliente;
  5. use App\Application\Internit\PesquisaSatisfacaoBundle\Entity\PesquisaSatisfacao;
  6. use App\Application\Internit\SolicitacaoBundle\Entity\Solicitacao;
  7. use App\Application\Project\ContentBundle\Attributes\Acl as ACL;
  8. use App\Application\Project\ContentBundle\Controller\Base\BaseApiController;
  9. use Doctrine\ORM\Query\QueryException;
  10. use Doctrine\Persistence\ObjectRepository;
  11. use OpenApi\Attributes as OA;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. #[Route('/api/cron'name'api_cron_')]
  16. class CronApiController extends BaseApiController
  17. {
  18.     #[Route('/notificacaoSolicitacaoAberto'name'list'methods: ['GET'])]
  19.     #[ACL\Api(enabletruetitle'notificacaoSolicitacaoAbertoAction'description'notificacaoSolicitacaoAberto')]
  20.     public function notificacaoSolicitacaoAbertoAction(Request $request): Response
  21.     {
  22.         // Solicitação com Status "Aberto" com 72h sem interação ADCIONAR automaticamente um status de "Em Análise" e seguir o fluxo padrão (igual o adicionar manualmente)
  23.         $empreendimento $request->query->get('empreendimento');
  24.         $em $this->doctrine->getManager();
  25.         $solicitacoes $em->getRepository(Solicitacao::class)->findAll();
  26.         return $this->json([
  27.             'status' => true,
  28.             'message' => 'Cron Executado!'
  29.         ], 404);
  30.     }
  31.     #[Route('/notificacaoPesquisaSatisfacaoNaoRespondida'name'list'methods: ['GET'])]
  32.     #[ACL\Api(enabletruetitle'notificacaoPesquisaSatisfacaoNaoRespondida'description'Notificacao Pesquisa não respondia')]
  33.     public function notificacaoPesquisaSatisfacaoNaoRespondidaAction(Request $request): Response
  34.     {
  35.         $em $this->doctrine->getManager();
  36.         $pesquisas $em->getRepository(PesquisaSatisfacao::class)->findAll();
  37.         foreach ($pesquisas as $pesquisa) {
  38.             if($pesquisa->getRespondido())
  39.                 continue;
  40.             $dateNow = new \DateTime();
  41.             $dateNow date_format($dateNow'Y-m-d');
  42.             $datePesquisa3 date_format($pesquisa->getCreatedAt()->modify('+3 day'), 'Y-m-d');
  43.             $datePesquisa6 date_format($pesquisa->getCreatedAt()->modify('+3 day'), 'Y-m-d');
  44.             /** Envia Notificação por Email */
  45.             if(($datePesquisa3 == $dateNow) && !$pesquisa->getNotification3()){
  46.                 $mail $this->serviceEmail->getEmail();
  47.                 $mail->addAddress($pesquisa->getCliente()->getEmail());
  48.                 $mail->Subject 'Pesquisa de Satisfação';
  49.                 $mail->Body $this->renderTemplateEmail('emails/cron/notificacao_pesquisa_nao_repondida.html.twig', [
  50.                     'cliente' => $pesquisa->getCliente(),
  51.                 ]);
  52.                 $mail->send();
  53.                 $pesquisa->setNotification3(1);
  54.                 $em->persist($pesquisa);
  55.                 $em->flush();
  56.             }
  57.             /** Envia Notificação por SMS */
  58.             if(($datePesquisa6 == $dateNow) && !$pesquisa->getNotification6()){
  59.                 $cliente $pesquisa->getCliente();
  60.                 $phone = ($cliente->getCelular())?: $cliente->getTelefone();
  61.                 $message "Ola, voce ainda não respondeu a sua pesquisa de satisfacao. Acesse o portal da Ass. Tecnica. Att. Construtora Dinamica";
  62.                 if($phone)
  63.                     $this->serviceComteleSMS->sendSMS($phone,$message);
  64.                 $pesquisa->setNotification6(1);
  65.                 $em->persist($pesquisa);
  66.                 $em->flush();
  67.             }
  68.         }
  69.         return $this->json([
  70.             'status' => true,
  71.             'message' => 'Cron Executado!'
  72.         ], 404);
  73.     }
  74. //    /** ****************************************************************************************** */
  75. //    /**
  76. //     * Cria o Recurso — Bloco.
  77. //     * Cria o Recurso — Bloco.
  78. //     */
  79. //    #[OA\Response(
  80. //        response: 201,
  81. //        description: 'Retorna novo recurso Bloco',
  82. //        content: new OA\JsonContent(
  83. //            properties: [
  84. //                new OA\Property(property: 'id', type: 'integer'),
  85. //                new OA\Property(property: 'bloco', type: 'string'),
  86. //                new OA\Property(property: 'descricao', type: 'string'),
  87. //                new OA\Property(property: 'visivel', type: 'boolean'),
  88. //                new OA\Property(property: 'empreendimento', type: 'integer' ),
  89. //            ],
  90. //            type: 'object'
  91. //        )
  92. //    )]
  93. //    #[OA\Response(response: 400, description: 'Dados inválidos!')]
  94. //    #[OA\RequestBody(
  95. //        description: 'Json Payload',
  96. //        content: new OA\JsonContent(
  97. //            properties: [
  98. //                new OA\Property(property: 'bloco', type: 'string'),
  99. //                new OA\Property(property: 'descricao', type: 'string'),
  100. //                new OA\Property(property: 'visivel', type: 'boolean'),
  101. //                new OA\Property(property: 'empreendimento', type: 'integer' ),
  102. //            ],
  103. //            type: 'object'
  104. //        )
  105. //    )]
  106. //    #[Route('', name: 'create', methods: ['POST'])]
  107. //    #[ACL\Api(enable: true, title: 'Criar', description: 'Criar Bloco')]
  108. //    public function createAction(Request $request): Response
  109. //    {
  110. //        $this->validateAccess("createAction");
  111. //
  112. //        if(!$request->getContent())
  113. //            return $this->json(['status' => false, 'message' => 'Dados inválidos!'], 400);
  114. //
  115. //        /** Tranforma Corpo da requisação em um objeto da classe. */
  116. //        $object = $this->objectTransformer->JsonToObject( $this->getClass(), $request , [
  117. //            'bloco', 'descricao', 'visivel', 'empreendimento',
  118. //        ]);
  119. //
  120. //        /** Valida Restrições do objeto */
  121. //        $errors = $this->validateConstraintErros($object);
  122. //        if($errors)
  123. //            return $this->json($errors);
  124. //
  125. //        $em = $this->doctrine->getManager();
  126. //        $em->persist($object);
  127. //        $em->flush();
  128. //
  129. //        $response = $this->objectTransformer->ObjectToJson( $object, [
  130. //            'id', 'bloco', 'descricao', 'visivel', 'empreendimento',
  131. //        ]);
  132. //
  133. //        return $this->json($response, 201);
  134. //    }
  135. //
  136. //    /** ****************************************************************************************** */
  137. //    /**
  138. //     * Recupera o recurso — Bloco.
  139. //     * Recupera o recurso — Bloco.
  140. //     */
  141. //    #[OA\Parameter( name: 'id', description: 'Identificador do recurso', in: 'path')]
  142. //    #[OA\Response(
  143. //        response: 200,
  144. //        description: 'Retorna recurso Bloco',
  145. //        content: new OA\JsonContent(
  146. //            properties: [
  147. //                new OA\Property(property: 'id', type: 'integer'),
  148. //                new OA\Property(property: 'bloco', type: 'string'),
  149. //                new OA\Property(property: 'descricao', type: 'string'),
  150. //                new OA\Property(property: 'visivel', type: 'boolean'),
  151. //                new OA\Property(property: 'empreendimento', type: 'integer' ),
  152. //            ],
  153. //            type: 'object'
  154. //        )
  155. //    )]
  156. //    #[OA\Response(response: 404, description: 'Recurso não encontrado')]
  157. //    #[Route('/{id}', name: 'show', methods: ['GET'])]
  158. //    #[ACL\Api(enable: true, title: 'Visualizar', description: 'Visualizar Bloco')]
  159. //    public function showAction(Request $request, mixed $id): Response
  160. //    {
  161. //        $this->validateAccess("showAction");
  162. //
  163. //        $object = $this->getRepository()->find($id);
  164. //        if (!$object)
  165. //            return $this->json(['status' => false, 'message' => 'Bloco não encontrado!'], 404);
  166. //
  167. //        $response = $this->objectTransformer->ObjectToJson( $object, [
  168. //            'id', 'bloco', 'descricao', 'visivel', 'empreendimento',
  169. //        ]);
  170. //
  171. //        return $this->json($response);
  172. //    }
  173. //
  174. //    /** ****************************************************************************************** */
  175. //    /**
  176. //     * Substitui o recurso — Bloco.
  177. //     * Substitui o recurso — Bloco.
  178. //     */
  179. //    #[OA\Parameter( name: 'id', description: 'Identificador do recurso', in: 'path')]
  180. //    #[OA\Response(
  181. //        response: 200,
  182. //        description: 'Retorna recurso Bloco',
  183. //        content: new OA\JsonContent(
  184. //            properties: [
  185. //                new OA\Property(property: 'id', type: 'integer'),
  186. //                new OA\Property(property: 'bloco', type: 'string'),
  187. //                new OA\Property(property: 'descricao', type: 'string'),
  188. //                new OA\Property(property: 'visivel', type: 'boolean'),
  189. //                new OA\Property(property: 'empreendimento', type: 'integer' ),
  190. //            ],
  191. //            type: 'object'
  192. //        )
  193. //    )]
  194. //    #[OA\Response(response: 400, description: 'Dados inválidos!')]
  195. //    #[OA\Response(response: 404, description: 'Recurso não encontrado')]
  196. //    #[OA\RequestBody(
  197. //        description: 'Json Payload',
  198. //        content: new OA\JsonContent(
  199. //            properties: [
  200. //                new OA\Property(property: 'bloco', type: 'string'),
  201. //                new OA\Property(property: 'descricao', type: 'string'),
  202. //                new OA\Property(property: 'visivel', type: 'boolean'),
  203. //                new OA\Property(property: 'empreendimento', type: 'integer' ),
  204. //            ],
  205. //            type: 'object'
  206. //        )
  207. //    )]
  208. //    #[Route('/{id}', name: 'edit', methods: ['PUT','PATCH'])]
  209. //    #[ACL\Api(enable: true, title: 'Editar', description: 'Editar Bloco')]
  210. //    public function editAction(Request $request, mixed $id): Response
  211. //    {
  212. //        $this->validateAccess("editAction");
  213. //
  214. //        $object = $this->getRepository()->find($id);
  215. //        if(!$object)
  216. //            return $this->json(['status' => false, 'message' => 'Bloco não encontrado!'], 404);
  217. //
  218. //        /** Transforma corpo da requisição em um objeto da classe. */
  219. //        $object = $this->objectTransformer->JsonToObject($object, $request, [
  220. //            'bloco', 'descricao', 'visivel', 'empreendimento',
  221. //        ]);
  222. //
  223. //        /** Valida Restrições do objeto */
  224. //        $errors = $this->validateConstraintErros($object);
  225. //        if($errors)
  226. //            return $this->json($errors);
  227. //
  228. //        /** Persiste o objeto */
  229. //        $em = $this->doctrine->getManager();
  230. //        $em->persist($object);
  231. //        $em->flush();
  232. //
  233. //        $response = $this->objectTransformer->ObjectToJson( $object, [
  234. //            'id', 'bloco', 'descricao', 'visivel', 'empreendimento',
  235. //        ]);
  236. //
  237. //        return $this->json($response);
  238. //    }
  239. //
  240. //    /** ****************************************************************************************** */
  241. //    /**
  242. //    * Remove o recurso — Bloco.
  243. //    * Remove o recurso — Bloco.
  244. //    */
  245. //    #[OA\Parameter( name: 'id', description: 'Identificador do recurso', in: 'path')]
  246. //    #[OA\Response(response: 204, description: 'Recurso excluído')]
  247. //    #[OA\Response(response: 404, description: 'Recurso não encontrado')]
  248. //    #[Route('/{id}', name: 'delete', methods: ['DELETE'])]
  249. //    #[ACL\Api(enable: true, title: 'Deletar', description: 'Deletar Bloco')]
  250. //    public function deleteAction(mixed $id): Response
  251. //    {
  252. //        $this->validateAccess("deleteAction");
  253. //
  254. //        $object = $this->getRepository()->find($id);
  255. //        if (!$object)
  256. //            return $this->json(['status' => false, 'message' => 'Bloco não encontrado.'], 404);
  257. //
  258. //        $em = $this->doctrine->getManager();
  259. //        $em->remove($object);
  260. //        $em->flush();
  261. //
  262. //        return $this->json(['status' => true, 'message' => 'Bloco removido com sucesso.'], 204);
  263. //    }
  264. }