src/Controller/HomeController.php line 41

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\CropWise\Load\CropWiseReportDownload;
  4. use App\CropWise\Load\CropWiseReportLoad;
  5. use App\Entity\Agro\Card;
  6. use App\Entity\Agro\Operation;
  7. use App\Entity\Agro\Parameter;
  8. use App\Entity\Field;
  9. use App\Entity\Report\Report;
  10. use App\Entity\Report\ReportValue;
  11. use App\Entity\Report\Task;
  12. use App\Entity\User;
  13. use App\Method\Api\FireStore\FireBaseReportUpdater;
  14. use App\Method\Api\FireStore\FireBaseUserUpdater;
  15. use App\Method\Api\NeuralNetwork;
  16. use App\Method\Api\Report\ReportConvertToWeb;
  17. use App\Method\Api\Storage\ParamSaveImageStorage;
  18. use App\Method\Api\Storage\ReportSaveImageStorage;
  19. use App\Method\Api\Storage\SelectelStorage;
  20. use App\Method\Api\Telegram\TelegramSender;
  21. use App\Method\CopyImageToYandex;
  22. use App\Model\ApiJsonResponseModel;
  23. use App\Repository\Report\ReportRepository;
  24. use App\Repository\Report\ReportValueRepository;
  25. use Arhitector\Yandex\Disk;
  26. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  27. use Symfony\Component\Cache\CacheItem;
  28. use Symfony\Component\HttpFoundation\JsonResponse;
  29. use Symfony\Component\HttpFoundation\Request;
  30. use Symfony\Component\HttpFoundation\Response;
  31. use Symfony\Component\HttpKernel\KernelInterface;
  32. use Symfony\Component\Routing\Annotation\Route;
  33. class HomeController extends AbstractController
  34. {
  35.     /**
  36.      * @Route("/", name="app_home")
  37.      */
  38.     public function index()
  39.     {
  40.         return $this->redirectToRoute('app_login');
  41.     }
  42.   /**
  43.    * @Route("/telegram", name="app_home_telegram")
  44.    */
  45.   public function test(FireBaseUserUpdater $baseUserUpdaterNeuralNetwork $neuralNetwork)
  46.   {
  47. //      $baseUserUpdater->updateAllUser();
  48. //      $report = $this->getDoctrine()->getRepository(Report::class)->find(30406);
  49. //      $baseReportUpdater->updateAllReport();
  50. //    $cropWiseReportLoad->run(30308,1190);
  51. //    $cropWiseReportLoad->run(30309,1188);
  52. //    $cropWiseReportLoad->run(30310,1188);
  53. //      $cropWiseReportLoad->run(3308,1190);
  54. //    $report = $this->getDoctrine()->getRepository(Report::class)->find(30363);
  55. //   $response = $telegramSender->send($report);
  56. //    dump($response);die;
  57.       $neuralNetwork->run();
  58.       return $this->json([
  59.           'message' => 'Welcome to your new controller!',
  60.           'path' => 'src/Controller/LoadFireBaseController.php',
  61.       ]);
  62.   }
  63.     /**
  64.      * @Route("/telegram2", name="app_home_telegram2")
  65.      */
  66.     public function telegram(TelegramSender $telegramSender,ReportSaveImageStorage $storage)
  67.     {
  68.         $reports = [];
  69. //        $reports = $this->getDoctrine()->getRepository(Report::class)->findBy([
  70. //            'user' =>357,
  71. //        ]);
  72.        $telegramSender->setTest(true);
  73. //        $telegramSender->setOneImage(true);
  74.        $telegramSender->setDump(true);
  75.         $reports[] = $this->getDoctrine()->getRepository(Report::class)->find(39465);
  76. //        $reports[] = $this->getDoctrine()->getRepository(Report::class)->find(39466);
  77. //        $reports[] = $this->getDoctrine()->getRepository(Report::class)->find(39467);
  78. //        $reports[] = $this->getDoctrine()->getRepository(Report::class)->find(39468);
  79. //        $reports[] = $this->getDoctrine()->getRepository(Report::class)->find(39469);
  80. //        $reports[] = $this->getDoctrine()->getRepository(Report::class)->find(39470);
  81.         $count 0;
  82.         foreach ($reports as $report) {
  83. //            $storage->save($report);
  84.             $response $telegramSender->send($report);
  85. //            $count++;
  86. //            dump($count);
  87.         }
  88.         die;
  89. //    dump($response);die;
  90.         return $this->json([
  91.             'message' => 'Welcome to your new controller!',
  92.             'path' => 'src/Controller/LoadFireBaseController.php',
  93.         ]);
  94.     }
  95.   /**
  96.    * @Route("/load/fire/base", name="app_load_fire_base")
  97.    */
  98.   public function index2(FireBaseUserUpdater $fireBaseUserUpdater): JsonResponse
  99.   {
  100.     $fireBaseUserUpdater->updateAllUser();
  101.     return $this->json([
  102.       'message' => 'Welcome to your new controller!',
  103.       'path' => 'src/Controller/LoadFireBaseController.php',
  104.     ]);
  105.   }
  106.     /**
  107.      * @Route("/log-save", name="app_recommendation_log_save")
  108.      */
  109.     public function recommendationLogSave(Request $requestKernelInterface $kernel): JsonResponse
  110.     {
  111.         $dir $kernel->getProjectDir()."/var/recommendation";
  112.         if(!is_dir($dir)){
  113.             mkdir($dir,0777,true);
  114.         }
  115.         $content $request->request->get('content');
  116.         if($content){
  117.             file_put_contents($dir."/".date("Y-m-d_H-i-s-u"), json_encode($content));
  118.             return $this->json([
  119.                 'status' => true,
  120.             ]);
  121.         }
  122.         return $this->json([
  123.             'message' => 'Parameter "content" not found',
  124.             'status' => false,
  125.         ]);
  126.     }
  127.     /**
  128.      * @Route("/log-view", name="app_recommendation_log_view")
  129.      */
  130.     public function recommendationLogView(Request $requestKernelInterface $kernel): JsonResponse
  131.     {
  132.         $limit $request->query->get('limit')?$request->query->get('limit'):20;
  133.         $page $request->query->get('page')?$request->query->get('page'):1;
  134.         $offset = ($page-1)*$limit;
  135.         $dir $kernel->getProjectDir()."/var/recommendation";
  136.         $files glob($dir."/*");
  137.         $files array_reverse($files);
  138.         $dumpFiles array_splice($files$offset,$limit);
  139.         foreach ($dumpFiles as $file) {
  140.             dump(json_decode(file_get_contents($file)));
  141.         }
  142.         if(count($files) > 20){
  143.             $dumpFiles array_splice($files0,$limit);
  144.         foreach ($files as $file) {
  145.             unlink($file);
  146.         }
  147.         }
  148.         die;
  149.     }
  150.     /**
  151.      * @Route("/images", name="app_home_images_storage")
  152.      */
  153.     public function images(SelectelStorage $storageKernelInterface $kernel)
  154.     {
  155.         $dir $kernel->getProjectDir()."/public/reports";
  156.         $dirThumb $kernel->getProjectDir()."/public/thump";
  157.        $reports $this->getDoctrine()->getRepository(ReportValue::class)->findAllImages(10);
  158.        foreach($reports as  $value){
  159.            $path $dir."/".$value->getImage();
  160.            $pathThump $dirThumb."/".$value->getImage();
  161.             $key $storage->createKey($value);
  162.             $object $storage->save($path,$key);
  163.             $url $this->getParameter('selectel_storage_public_domain')."/".$key;
  164.             if(!empty($object['ObjectURL']) && !empty($object['ObjectURL'])){
  165.                 $value->setStorageImage($url);
  166.                 $this->getDoctrine()->getManager()->persist($value);
  167.                 $this->getDoctrine()->getManager()->flush();
  168.             }
  169. //            if(file_exists($pathThump)){
  170.            $command 'convert -resize 100x100 -quality 50% '$path." ".$pathThump;
  171.            exec($command);
  172.            $thumpKey str_replace('params','thumb',$key);
  173.            $object $storage->save($pathThump,$thumpKey);
  174. //           unlink($path);
  175. //           unlink($pathThump);
  176. //            }
  177.        }
  178.     }
  179.     /**
  180.      * @Route("/images-parameter", name="app_home_images_storage")
  181.      */
  182.     public function imagesParameter(ParamSaveImageStorage $storageKernelInterface $kernel)
  183.     {
  184.         $dir $kernel->getProjectDir()."/public/params";
  185.         $start microtime(true);
  186.         $end = (new \DateTime("+ 55 minutes"))->getTimestamp();
  187.         $reports $this->getDoctrine()->getRepository(Parameter::class)->findAllImagesByOperation(9445);
  188.         foreach($reports as  $value){
  189.             if($end $start){
  190.                 return 1;
  191.             }
  192.             $object $storage->save($value);
  193.         }
  194.         dd($reports);
  195.     }
  196.     /**
  197.      * @Route("/images-report", name="app_home_images_storage_report")
  198.      */
  199.     public function imagesReport(ReportSaveImageStorage $storageKernelInterface $kernel)
  200.     {
  201.         $dir $kernel->getProjectDir()."/public/reports";
  202.         $start microtime(true);
  203.         $end = (new \DateTime("+ 55 minutes"))->getTimestamp();
  204.         $reports $this->getDoctrine()->getRepository(Report::class)->findAllImages(100);
  205.         foreach($reports as  $value){
  206.             if($end $start){
  207.                 return 1;
  208.             }
  209.             $object $storage->save($value);
  210.         }
  211.     }
  212.     /**
  213.      * @Route("/field-change-to-field", name="app_home_field_change_to_field")
  214.      */
  215.     public function changeField()
  216.     {
  217.         die;
  218.         $seasons = [
  219. //            2023,
  220.             2024
  221.         ];
  222.         $fileldIdDonor 3140;
  223.         $fileldIdTarget 22054;
  224.         /** @var Field $donor */
  225.         $donor $this->getDoctrine()->getRepository(Field::class)->find($fileldIdDonor);
  226.         $target $this->getDoctrine()->getRepository(Field::class)->find($fileldIdTarget);
  227. //        if($donor->getTechcard()->getId() == $target->getTechcard()->getId()) {
  228.             $donor->setHash();
  229.             $target->setHash();
  230.             $reports $donor->getReports();
  231.             foreach ($reports as $report) {
  232.                 if(in_array($report->getTechcard()->getSeason()->getName(),$seasons)){
  233.                 $report->setField($target);
  234.                 $this->getDoctrine()->getManager()->persist($report);
  235.             }
  236.             }
  237.             $this->getDoctrine()->getManager()->flush();
  238.             $objectives $donor->getObjectives();
  239.             foreach ($objectives as $objective) {
  240.                 if(in_array($objective->getSeason()->getName(),$seasons)) {
  241.                     $objective->setField($target);
  242.                     $objective->setHash();
  243.                     $this->getDoctrine()->getManager()->persist($objective);
  244.                 }
  245.             }
  246.             $this->getDoctrine()->getManager()->flush();
  247.             $tasks $donor->getTaskLists();
  248.             foreach ($tasks as $task) {
  249.                 if(in_array($task->getSeason()->getName(),$seasons)) {
  250.                     $task->setField($target);
  251.                     $this->getDoctrine()->getManager()->persist($task);
  252.                 }
  253.             }
  254.             $this->getDoctrine()->getManager()->persist($donor);
  255.             $this->getDoctrine()->getManager()->persist($target);
  256.             $this->getDoctrine()->getManager()->flush();
  257.             die('complete');
  258. //        }
  259. //        die('techcard -');
  260.     }
  261.     /**
  262.      * @Route("/send-report-cropio", name="app_home_send_report_cropio")
  263.      */
  264.     public function sendReportCropiowiseReportRepository $reportRepository,
  265.                                           CropWiseReportLoad $cropWiseReportLoad)
  266.     {
  267.         $reports $reportRepository->findAllForCropWise();
  268.         /** @var Report $report */
  269.         $all count($reports);
  270. //        $reports = [];
  271. //        $reports[] = $this->getDoctrine()->getRepository(Report::class)->find(49392);
  272.         $load 0;
  273.         foreach ($reports as $report) {
  274.             $cropWiseReportLoad->run($report->getId(),$report->getField()->getId());
  275.             $load++;
  276.             $now microtime(true);
  277.         }
  278.         die('end');
  279.     }
  280.     /**
  281.      * @Route("/download-report-cropwise", name="app_home_download_report_cropwise")
  282.      */
  283.     public function downloadReportCropWiseReportDownload $downloadReportConvertToWeb $reportConvertToWeb)
  284.     {
  285.         if(isset($_REQUEST['dev']) && $_REQUEST['dev'] == '1') {
  286.         $this->removedublicateTemplate();
  287.         $this->removeUser();die;
  288.         }
  289.         $fields $this->getDoctrine()->getRepository(Field::class)->findAllDownloadCropWiseReport();
  290.         if(!empty($fields)) {
  291.             foreach ($fields as $key =>  $field) {
  292.                 $download->run($field->getId());
  293.             }
  294.         }die;
  295.         $download->run(22815);
  296.     }
  297.     public function removedublicateTemplate()
  298.     {
  299.         $em $this->getDoctrine()->getManager();
  300.         $em->flush();
  301.         $count 0;
  302.         $ids = ['64','54',10,52,54,55,42,13,9,11,12,13,14,15,16,0,45,48];
  303.         foreach ($ids as $id) {
  304.             $operations $this->getDoctrine()->getRepository(Operation::class)->findBy(["cropWiseTemplateId" => $id]);
  305.             $problems $this->getDoctrine()->getRepository(Operation::class)->findBy(["cropWiseGrowthStageId" => 0]);
  306.             $operations array_merge($operations,$problems);
  307.             foreach ($operations as $operation) {
  308. //        $operation = $this->getDoctrine()->getRepository(Operation::class)->find(21688);
  309.                 $tasks $this->getDoctrine()->getRepository(Task::class)->findBy(["operation" => $operation->getId()]);
  310.                 foreach ($tasks as $task) {
  311.                     $em->remove($task);
  312.                 }
  313.                 foreach ($operation->getObjectives() as $objective) {
  314.                     /** @var Report $report */
  315.                     foreach ($objective->getReports() as $report) {
  316.                         $task $report->getTask();
  317.                         $task->setOperation(null);
  318.                         $em->persist($task);
  319.                         $getObjective $report->getObjective();
  320.                             $em->persist($task->getTaskList());
  321.                         $em->persist($task);
  322.                         $em->persist($getObjective);
  323.                         $report->setObjective(null);
  324.                         $report->setTask(null);
  325.                         foreach ($report->getReportValues() as $value) {
  326.                             $report->removeReportValue($value);
  327.                             $em->remove($value);
  328.                         }
  329.                         $objective->removeReport($report);
  330.                         $em->persist($objective);
  331. //                        $em->remove($objective);
  332.                         $em->remove($report);
  333.                     }
  334.                     $em->remove($objective);
  335.                     $em->flush();
  336.                 }
  337. /** @var Card $card */
  338.                 foreach ($operation->getCards() as $card) {
  339.                     foreach ($card->getAllParams(true) as $param) {
  340.                         foreach ($param->getChildren(true) as $child) {
  341.                             foreach ($child->getParametersValues() as $value) {
  342.                                 $em->remove($value);
  343.                                 $em->flush();
  344.                             }
  345.                             $card->removeParam($child);
  346.                             $em->remove($child);
  347.                             $em->flush();
  348.                         }
  349.                         foreach ($param->getAnswers(true) as $answer) {
  350.                             foreach ($answer->getParametersValues() as $value) {
  351.                                 $em->remove($value);
  352.                                 $em->flush();
  353.                             }
  354.                             $card->removeParam($answer);
  355.                             $em->remove($answer);
  356.                             $em->flush();
  357.                         }
  358.                         foreach ($param->getParametersValues() as $value) {
  359.                             $em->remove($value);
  360.                             $em->flush();
  361.                         }
  362.                         $card->removeParam($param);
  363.                         $em->remove($param);
  364.                         $em->flush();
  365.                     }
  366.                     $em->persist($card);
  367.                     $em->flush();
  368.                     $em->remove($card);
  369.                     $em->flush();
  370.                 }
  371.                 dump($count++);
  372.                 dump($operation->getId());
  373.                 $em->remove($operation);
  374.                 $em->flush();
  375.             }
  376.         }
  377.         $reports $this->getDoctrine()->getRepository(Report::class)->findBy(["cropWiseStatusDownload" => 'complete']);
  378.         foreach ($reports as $report) {
  379.             foreach ($report->getReportValues() as $value) {
  380.                 $em->remove($value);
  381.             }
  382.             dump($report->getId());
  383.             $em->remove($report);
  384.         }
  385.         $em->flush();
  386.         die;
  387.     }
  388.     public function removeUser()
  389.     {
  390.         $em $this->getDoctrine()->getManager();
  391.         for($id 376;$id <= 437$id++) {
  392.             $user $this->getDoctrine()->getRepository(User::class)->find($id);
  393.             if(!empty($user) && strpos($user->getEmail(),'cerera2025@gap-rs.ru') !== false){
  394.                 foreach ($user->getCreatorObjectives() as $creatorObjective) {
  395.                     $tasks $this->getDoctrine()->getRepository(Task::class)->findBy(["operation" => $creatorObjective->getOperation()->getId()]);
  396.                     $em $this->getDoctrine()->getManager();
  397.                     foreach ($tasks as $task) {
  398.                         $em->remove($task);
  399.                     }
  400.                     foreach ($creatorObjective->getOperation()->getObjectives() as $objective) {
  401.                         foreach ($objective->getReports() as $report) {
  402.                             foreach ($report->getReportValues() as $value) {
  403.                                 $em->remove($value);
  404.                             }
  405.                             $em->remove($objective);
  406.                         }
  407.                         $em->remove($report);
  408.                     }
  409.                 }
  410.                 $user->setCompany(null);
  411.                 $em->persist($user);
  412.                 $em->remove($user);
  413.             }
  414.             $em->flush();
  415.         }
  416.         die;
  417.     }
  418. }