mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-11-19 23:00:36 +01:00
critères de followup plus amples
This commit is contained in:
parent
b5b2880637
commit
a5cd69961f
3 changed files with 250 additions and 85 deletions
109
src/Command/RegenerateFollowupsCommand.php
Normal file
109
src/Command/RegenerateFollowupsCommand.php
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Entity\Stats;
|
||||
use App\Service\FollowUpService;
|
||||
use App\Service\Motocultrice;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'app:regenerate-followups',
|
||||
description: 'Régénère les followups pour une ville spécifique avec les nouveaux critères',
|
||||
)]
|
||||
class RegenerateFollowupsCommand extends Command
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $entityManager,
|
||||
private FollowUpService $followUpService,
|
||||
private Motocultrice $motocultrice
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->addArgument('insee_code', InputArgument::REQUIRED, 'Code INSEE de la ville')
|
||||
->addOption('delete-existing', 'd', InputOption::VALUE_NONE, 'Supprimer les followups existants avant de régénérer')
|
||||
->addOption('disable-cleanup', 'c', InputOption::VALUE_NONE, 'Désactiver le nettoyage des followups redondants')
|
||||
->setHelp('Cette commande régénère les followups pour une ville avec les nouveaux critères de completion.')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$inseeCode = $input->getArgument('insee_code');
|
||||
$deleteExisting = $input->getOption('delete-existing');
|
||||
$disableCleanup = $input->getOption('disable-cleanup');
|
||||
|
||||
$io->title('Régénération des followups pour ' . $inseeCode);
|
||||
|
||||
// Vérifier que la ville existe
|
||||
$stats = $this->entityManager->getRepository(Stats::class)->findOneBy(['zone' => $inseeCode]);
|
||||
if (!$stats) {
|
||||
$io->error('Aucune stats trouvée pour le code INSEE ' . $inseeCode);
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$io->info('Ville trouvée : ' . $stats->getName());
|
||||
|
||||
// Supprimer les followups existants si demandé
|
||||
if ($deleteExisting) {
|
||||
$io->section('Suppression des followups existants');
|
||||
$followups = $stats->getCityFollowUps();
|
||||
$count = count($followups);
|
||||
|
||||
foreach ($followups as $followup) {
|
||||
$this->entityManager->remove($followup);
|
||||
}
|
||||
$this->entityManager->flush();
|
||||
|
||||
$io->success($count . ' followups supprimés');
|
||||
}
|
||||
|
||||
// Régénérer les followups
|
||||
$io->section('Régénération des followups');
|
||||
$io->note('Utilisation des nouveaux critères de completion plus réalistes');
|
||||
|
||||
try {
|
||||
$this->followUpService->generateCityFollowUps(
|
||||
$stats,
|
||||
$this->motocultrice,
|
||||
$this->entityManager,
|
||||
$disableCleanup
|
||||
);
|
||||
|
||||
$io->success('Followups régénérés avec succès');
|
||||
|
||||
// Afficher les résultats
|
||||
$newFollowups = $stats->getCityFollowUps();
|
||||
$io->section('Résultats');
|
||||
|
||||
$table = [];
|
||||
foreach ($newFollowups as $followup) {
|
||||
$table[] = [
|
||||
$followup->getName(),
|
||||
$followup->getMeasure(),
|
||||
$followup->getDate()->format('Y-m-d H:i:s')
|
||||
];
|
||||
}
|
||||
|
||||
$io->table(['Nom', 'Valeur', 'Date'], $table);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$io->error('Erreur lors de la régénération : ' . $e->getMessage());
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue