<?php
namespace App\Application\Internit\ApiBundle\Controller;
use App\Application\Internit\BlocoBundle\Entity\Bloco;
use App\Application\Internit\ClienteBundle\Entity\Cliente;
use App\Application\Internit\PesquisaSatisfacaoBundle\Entity\PesquisaSatisfacao;
use App\Application\Internit\SolicitacaoBundle\Entity\Solicitacao;
use App\Application\Project\ContentBundle\Attributes\Acl as ACL;
use App\Application\Project\ContentBundle\Controller\Base\BaseApiController;
use Doctrine\ORM\Query\QueryException;
use Doctrine\Persistence\ObjectRepository;
use OpenApi\Attributes as OA;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/api/cron', name: 'api_cron_')]
class CronApiController extends BaseApiController
{
#[Route('/notificacaoSolicitacaoAberto', name: 'list', methods: ['GET'])]
#[ACL\Api(enable: true, title: 'notificacaoSolicitacaoAbertoAction', description: 'notificacaoSolicitacaoAberto')]
public function notificacaoSolicitacaoAbertoAction(Request $request): Response
{
// 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)
$empreendimento = $request->query->get('empreendimento');
$em = $this->doctrine->getManager();
$solicitacoes = $em->getRepository(Solicitacao::class)->findAll();
return $this->json([
'status' => true,
'message' => 'Cron Executado!'
], 404);
}
#[Route('/notificacaoPesquisaSatisfacaoNaoRespondida', name: 'list', methods: ['GET'])]
#[ACL\Api(enable: true, title: 'notificacaoPesquisaSatisfacaoNaoRespondida', description: 'Notificacao Pesquisa não respondia')]
public function notificacaoPesquisaSatisfacaoNaoRespondidaAction(Request $request): Response
{
$em = $this->doctrine->getManager();
$pesquisas = $em->getRepository(PesquisaSatisfacao::class)->findAll();
foreach ($pesquisas as $pesquisa) {
if($pesquisa->getRespondido())
continue;
$dateNow = new \DateTime();
$dateNow = date_format($dateNow, 'Y-m-d');
$datePesquisa3 = date_format($pesquisa->getCreatedAt()->modify('+3 day'), 'Y-m-d');
$datePesquisa6 = date_format($pesquisa->getCreatedAt()->modify('+3 day'), 'Y-m-d');
/** Envia Notificação por Email */
if(($datePesquisa3 == $dateNow) && !$pesquisa->getNotification3()){
$mail = $this->serviceEmail->getEmail();
$mail->addAddress($pesquisa->getCliente()->getEmail());
$mail->Subject = 'Pesquisa de Satisfação';
$mail->Body = $this->renderTemplateEmail('emails/cron/notificacao_pesquisa_nao_repondida.html.twig', [
'cliente' => $pesquisa->getCliente(),
]);
$mail->send();
$pesquisa->setNotification3(1);
$em->persist($pesquisa);
$em->flush();
}
/** Envia Notificação por SMS */
if(($datePesquisa6 == $dateNow) && !$pesquisa->getNotification6()){
$cliente = $pesquisa->getCliente();
$phone = ($cliente->getCelular())?: $cliente->getTelefone();
$message = "Ola, voce ainda não respondeu a sua pesquisa de satisfacao. Acesse o portal da Ass. Tecnica. Att. Construtora Dinamica";
if($phone)
$this->serviceComteleSMS->sendSMS($phone,$message);
$pesquisa->setNotification6(1);
$em->persist($pesquisa);
$em->flush();
}
}
return $this->json([
'status' => true,
'message' => 'Cron Executado!'
], 404);
}
// /** ****************************************************************************************** */
// /**
// * Cria o Recurso — Bloco.
// * Cria o Recurso — Bloco.
// */
// #[OA\Response(
// response: 201,
// description: 'Retorna novo recurso Bloco',
// content: new OA\JsonContent(
// properties: [
// new OA\Property(property: 'id', type: 'integer'),
// new OA\Property(property: 'bloco', type: 'string'),
// new OA\Property(property: 'descricao', type: 'string'),
// new OA\Property(property: 'visivel', type: 'boolean'),
// new OA\Property(property: 'empreendimento', type: 'integer' ),
// ],
// type: 'object'
// )
// )]
// #[OA\Response(response: 400, description: 'Dados inválidos!')]
// #[OA\RequestBody(
// description: 'Json Payload',
// content: new OA\JsonContent(
// properties: [
// new OA\Property(property: 'bloco', type: 'string'),
// new OA\Property(property: 'descricao', type: 'string'),
// new OA\Property(property: 'visivel', type: 'boolean'),
// new OA\Property(property: 'empreendimento', type: 'integer' ),
// ],
// type: 'object'
// )
// )]
// #[Route('', name: 'create', methods: ['POST'])]
// #[ACL\Api(enable: true, title: 'Criar', description: 'Criar Bloco')]
// public function createAction(Request $request): Response
// {
// $this->validateAccess("createAction");
//
// if(!$request->getContent())
// return $this->json(['status' => false, 'message' => 'Dados inválidos!'], 400);
//
// /** Tranforma Corpo da requisação em um objeto da classe. */
// $object = $this->objectTransformer->JsonToObject( $this->getClass(), $request , [
// 'bloco', 'descricao', 'visivel', 'empreendimento',
// ]);
//
// /** Valida Restrições do objeto */
// $errors = $this->validateConstraintErros($object);
// if($errors)
// return $this->json($errors);
//
// $em = $this->doctrine->getManager();
// $em->persist($object);
// $em->flush();
//
// $response = $this->objectTransformer->ObjectToJson( $object, [
// 'id', 'bloco', 'descricao', 'visivel', 'empreendimento',
// ]);
//
// return $this->json($response, 201);
// }
//
// /** ****************************************************************************************** */
// /**
// * Recupera o recurso — Bloco.
// * Recupera o recurso — Bloco.
// */
// #[OA\Parameter( name: 'id', description: 'Identificador do recurso', in: 'path')]
// #[OA\Response(
// response: 200,
// description: 'Retorna recurso Bloco',
// content: new OA\JsonContent(
// properties: [
// new OA\Property(property: 'id', type: 'integer'),
// new OA\Property(property: 'bloco', type: 'string'),
// new OA\Property(property: 'descricao', type: 'string'),
// new OA\Property(property: 'visivel', type: 'boolean'),
// new OA\Property(property: 'empreendimento', type: 'integer' ),
// ],
// type: 'object'
// )
// )]
// #[OA\Response(response: 404, description: 'Recurso não encontrado')]
// #[Route('/{id}', name: 'show', methods: ['GET'])]
// #[ACL\Api(enable: true, title: 'Visualizar', description: 'Visualizar Bloco')]
// public function showAction(Request $request, mixed $id): Response
// {
// $this->validateAccess("showAction");
//
// $object = $this->getRepository()->find($id);
// if (!$object)
// return $this->json(['status' => false, 'message' => 'Bloco não encontrado!'], 404);
//
// $response = $this->objectTransformer->ObjectToJson( $object, [
// 'id', 'bloco', 'descricao', 'visivel', 'empreendimento',
// ]);
//
// return $this->json($response);
// }
//
// /** ****************************************************************************************** */
// /**
// * Substitui o recurso — Bloco.
// * Substitui o recurso — Bloco.
// */
// #[OA\Parameter( name: 'id', description: 'Identificador do recurso', in: 'path')]
// #[OA\Response(
// response: 200,
// description: 'Retorna recurso Bloco',
// content: new OA\JsonContent(
// properties: [
// new OA\Property(property: 'id', type: 'integer'),
// new OA\Property(property: 'bloco', type: 'string'),
// new OA\Property(property: 'descricao', type: 'string'),
// new OA\Property(property: 'visivel', type: 'boolean'),
// new OA\Property(property: 'empreendimento', type: 'integer' ),
// ],
// type: 'object'
// )
// )]
// #[OA\Response(response: 400, description: 'Dados inválidos!')]
// #[OA\Response(response: 404, description: 'Recurso não encontrado')]
// #[OA\RequestBody(
// description: 'Json Payload',
// content: new OA\JsonContent(
// properties: [
// new OA\Property(property: 'bloco', type: 'string'),
// new OA\Property(property: 'descricao', type: 'string'),
// new OA\Property(property: 'visivel', type: 'boolean'),
// new OA\Property(property: 'empreendimento', type: 'integer' ),
// ],
// type: 'object'
// )
// )]
// #[Route('/{id}', name: 'edit', methods: ['PUT','PATCH'])]
// #[ACL\Api(enable: true, title: 'Editar', description: 'Editar Bloco')]
// public function editAction(Request $request, mixed $id): Response
// {
// $this->validateAccess("editAction");
//
// $object = $this->getRepository()->find($id);
// if(!$object)
// return $this->json(['status' => false, 'message' => 'Bloco não encontrado!'], 404);
//
// /** Transforma corpo da requisição em um objeto da classe. */
// $object = $this->objectTransformer->JsonToObject($object, $request, [
// 'bloco', 'descricao', 'visivel', 'empreendimento',
// ]);
//
// /** Valida Restrições do objeto */
// $errors = $this->validateConstraintErros($object);
// if($errors)
// return $this->json($errors);
//
// /** Persiste o objeto */
// $em = $this->doctrine->getManager();
// $em->persist($object);
// $em->flush();
//
// $response = $this->objectTransformer->ObjectToJson( $object, [
// 'id', 'bloco', 'descricao', 'visivel', 'empreendimento',
// ]);
//
// return $this->json($response);
// }
//
// /** ****************************************************************************************** */
// /**
// * Remove o recurso — Bloco.
// * Remove o recurso — Bloco.
// */
// #[OA\Parameter( name: 'id', description: 'Identificador do recurso', in: 'path')]
// #[OA\Response(response: 204, description: 'Recurso excluído')]
// #[OA\Response(response: 404, description: 'Recurso não encontrado')]
// #[Route('/{id}', name: 'delete', methods: ['DELETE'])]
// #[ACL\Api(enable: true, title: 'Deletar', description: 'Deletar Bloco')]
// public function deleteAction(mixed $id): Response
// {
// $this->validateAccess("deleteAction");
//
// $object = $this->getRepository()->find($id);
// if (!$object)
// return $this->json(['status' => false, 'message' => 'Bloco não encontrado.'], 404);
//
// $em = $this->doctrine->getManager();
// $em->remove($object);
// $em->flush();
//
// return $this->json(['status' => true, 'message' => 'Bloco removido com sucesso.'], 204);
// }
}