<?php


namespace App\Http\Controllers;


use App\Services\StationTaskBatchService;
use App\StationTaskBatch;
use Illuminate\Http\Request;
use App\Traits\TestableInstant;
class ForeignHaiRoboticsController
{
    use TestableInstant;

    /** @var StationTaskBatchService $stationTaskBatchService */
    private $stationTaskBatchService=null;

    function runBatch(Request $request){
        $request->validate(
            ['id'=>'required|exists:station_task_batches,id']
        );
        $batchTask=StationTaskBatch::query()->first($request['id']);
        $batchesFailed=$this->stationTaskBatchService->runMany(collect([$batchTask]));//执行波次任务
        if($batchesFailed && $batchesFailed->isNotEmpty()){
            return [
                'success'=>false,
                'errorMsg'=>'有部分失败波次：'.$batchesFailed->toJson()
            ];
        }
        return ['success'=>true];
    }
}
