|
- <?php
-
- namespace App\Console\Commands;
-
- use App\Jobs\SeasonTicketContract\Selection\SetResult;
- use App\Kintone\KintoneRecordQueryOperator;
- use App\Kintone\Models\DropDown\SeasonTicketContractSelection\SelectionStatus;
- use App\Kintone\Models\SeasonTicketContractSelection;
- use App\Util\DateUtil;
- use App\Util\DBUtil;
- use Exception;
-
- class SeasonTikcetContractSelectionSetResult extends BaseCommand
- {
-
- const COMMAND = "season-ticket-contract-selection:set-result";
-
-
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = self::COMMAND;
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '定期選考の選考者設定のジョブを登録する';
-
- static public function getCommand()
- {
- return self::COMMAND;
- }
-
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- $this->managers = collect();
- }
-
- /**
- * Execute the console command.
- *
- * @return int
- */
- public function service(): int
- {
- try {
- $db = DBUtil::instance();
- $db->beginTransaction();
-
-
- $targets = $this->getTargets();
-
- $this->outputInfo(sprintf("取得対象 %d件", $targets->count()));
-
- // データハンドリング
- foreach ($targets as $data) {
- $this->handleData($data);
- }
-
- $db->commit();
- } catch (Exception $e) {
- $db->rollBack();
- throw $e;
- }
-
- return self::RESULTCODE_SUCCESS;
- }
-
- private function getTargets()
- {
- $today = DateUtil::now();
- $access = SeasonTicketContractSelection::getAccess();
- $query = SeasonTicketContractSelection::getQuery()
- ->whereIn(SeasonTicketContractSelection::FIELD_STATUS, [SelectionStatus::ENTRY_ACCEPTING])
- ->whereDate(SeasonTicketContractSelection::FIELD_SELECTION_FINAL_DATE, $today, KintoneRecordQueryOperator::LT);
- return $access->all($query);
- }
-
-
- private function handleData(SeasonTicketContractSelection $data)
- {
- SetResult::dispatch($data->getRecordId());
- }
- }
|