No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

95 líneas
2.3KB

  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Jobs\SeasonTicketContract\Selection\SetResult;
  4. use App\Kintone\KintoneRecordQueryOperator;
  5. use App\Kintone\Models\DropDown\SeasonTicketContractSelection\SelectionStatus;
  6. use App\Kintone\Models\SeasonTicketContractSelection;
  7. use App\Util\DateUtil;
  8. use App\Util\DBUtil;
  9. use Exception;
  10. class SeasonTikcetContractSelectionSetResult extends BaseCommand
  11. {
  12. const COMMAND = "season-ticket-contract-selection:set-result";
  13. /**
  14. * The name and signature of the console command.
  15. *
  16. * @var string
  17. */
  18. protected $signature = self::COMMAND;
  19. /**
  20. * The console command description.
  21. *
  22. * @var string
  23. */
  24. protected $description = '定期選考の選考者設定のジョブを登録する';
  25. static public function getCommand()
  26. {
  27. return self::COMMAND;
  28. }
  29. /**
  30. * Create a new command instance.
  31. *
  32. * @return void
  33. */
  34. public function __construct()
  35. {
  36. parent::__construct();
  37. $this->managers = collect();
  38. }
  39. /**
  40. * Execute the console command.
  41. *
  42. * @return int
  43. */
  44. public function service(): int
  45. {
  46. try {
  47. $db = DBUtil::instance();
  48. $db->beginTransaction();
  49. $targets = $this->getTargets();
  50. $this->outputInfo(sprintf("取得対象 %d件", $targets->count()));
  51. // データハンドリング
  52. foreach ($targets as $data) {
  53. $this->handleData($data);
  54. }
  55. $db->commit();
  56. } catch (Exception $e) {
  57. $db->rollBack();
  58. throw $e;
  59. }
  60. return self::RESULTCODE_SUCCESS;
  61. }
  62. private function getTargets()
  63. {
  64. $today = DateUtil::now();
  65. $access = SeasonTicketContractSelection::getAccess();
  66. $query = SeasonTicketContractSelection::getQuery()
  67. ->whereIn(SeasonTicketContractSelection::FIELD_STATUS, [SelectionStatus::ENTRY_ACCEPTING])
  68. ->whereDate(SeasonTicketContractSelection::FIELD_SELECTION_FINAL_DATE, $today, KintoneRecordQueryOperator::LT);
  69. return $access->all($query);
  70. }
  71. private function handleData(SeasonTicketContractSelection $data)
  72. {
  73. SetResult::dispatch($data->getRecordId());
  74. }
  75. }