Make command to load active job order cache #299
This commit is contained in:
parent
cba80ddd90
commit
f350b3ebb8
1 changed files with 68 additions and 0 deletions
68
src/Command/RefreshJobOrderCacheCommand.php
Normal file
68
src/Command/RefreshJobOrderCacheCommand.php
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?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\Common\Persistence\ObjectManager;
|
||||
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(ObjectManager $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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue