<?php

namespace App\Jobs;

use App\Http\Controllers\Controller;
use App\OrderPackage;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class FetchPackageFromOracle implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;


    protected $package;
    /**
     * Create a new job instance.
     * @param OrderPackage $package
     * @return void
     */
    public function __construct($package)
    {
        $this->package=$package;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        Controller::logS(__METHOD__,__FUNCTION__,"进入FetchPackageFromOracle",null);
        if (!$this->package){
            Controller::logS(__METHOD__,'error_'.__FUNCTION__,"队列传递的package为空",null);
            return;
        }
        $package=OrderPackage::query()->find($this->package->id);
        Controller::logS(__METHOD__,__FUNCTION__,"通过package->id搜索:".$this->package->id,null);
        if(!$package){
            Controller::logS(__METHOD__,'error_'.__FUNCTION__,"队列查询的package为空",null);
            return;
        }
        $package->fetchAllFromOracle();
        $package->update();
    }
}
