<?php

namespace App\Jobs;

use App\Process;
use App\Services\LogService;
use App\Services\ProcessService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

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

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

    /**
     * Execute the job.
     *
     * @param ProcessService $service
     * @return void
     * @throws
     */
    public function handle(ProcessService $service)
    {
        try{
            $service->createInstantBill($this->process);
        }catch (\Exception $e){
            LogService::log(__METHOD__,"ERROR-入库生成即时账单",$this->process->toJson()." | ".$e->getMessage());
            throw new \Exception($e->getMessage());
        }
    }
}
