70 lines
1.8 KiB
PHP
70 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Command;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Doctrine\DBAL\Connection;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use App\Service\JobOrderCache;
|
|
use App\Entity\JobOrder;
|
|
use App\Ramcar\JOStatus;
|
|
|
|
use DateTime;
|
|
|
|
|
|
class RefreshJobOrderCacheCommand extends Command
|
|
{
|
|
protected $em;
|
|
protected $jo_cache;
|
|
|
|
public function __construct(EntityManagerInterface $om, JobOrderCache $jo_cache)
|
|
{
|
|
$this->em = $om;
|
|
$this->jo_cache = $jo_cache;
|
|
|
|
parent::__construct();
|
|
}
|
|
|
|
protected function configure()
|
|
{
|
|
$this->setName('joborder:refresh_cache')
|
|
->setDescription('Refresh active job order cache from database.')
|
|
->setHelp('Refresh active job order cache from database.');
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
$date = new DateTime();
|
|
$date->modify('-3 day');
|
|
|
|
$status_list = [
|
|
JOStatus::PENDING,
|
|
JOStatus::RIDER_ASSIGN,
|
|
JOStatus::ASSIGNED,
|
|
JOStatus::IN_TRANSIT,
|
|
JOStatus::IN_PROGRESS,
|
|
];
|
|
|
|
$qb = $this->em->getRepository(JobOrder::class)
|
|
->createQueryBuilder('jo');
|
|
$res = $qb->select('jo')
|
|
->where('jo.status IN (:statuses)')
|
|
->andWhere('jo.date_schedule >= :date')
|
|
->setParameter('statuses', $status_list, Connection::PARAM_STR_ARRAY)
|
|
->setParameter('date', $date)
|
|
->getQuery()
|
|
->execute();
|
|
|
|
// fulfill each
|
|
foreach ($res as $jo)
|
|
{
|
|
$this->jo_cache->addActiveJobOrder($jo);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|