|
|
@@ -7,6 +7,7 @@ namespace App\Services;
|
|
|
use App\Batch;
|
|
|
use App\Log;
|
|
|
use App\Station;
|
|
|
+use App\StationTask;
|
|
|
use App\StationTaskBatch;
|
|
|
use App\StationTaskBatchType;
|
|
|
use Exception;
|
|
|
@@ -23,46 +24,55 @@ class StationTaskBatchService
|
|
|
private $batchService;
|
|
|
/** @var StationTypeService $stationTypeService */
|
|
|
private $stationTypeService;
|
|
|
+ /** @var StationTaskService $stationTaskService */
|
|
|
+ private $stationTaskService;
|
|
|
public function __construct(){
|
|
|
$this->stationService=null;
|
|
|
$this->stationTypeService=null;
|
|
|
$this->stationTaskBatchTypeService=null;
|
|
|
$this->batchService=null;
|
|
|
+ $this->stationTaskService=null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param $batches Batch[]
|
|
|
+ * @param Collection $stationTasks_toAttach
|
|
|
* @return Collection
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- function createByBatches(array $batches): Collection
|
|
|
+ function createByBatches(array $batches, Collection $stationTasks_toAttach): Collection
|
|
|
{
|
|
|
$this->stationService=app('StationService');
|
|
|
$this->stationTypeService=app('StationTypeService');
|
|
|
$this->stationTaskBatchTypeService=app('StationTaskBatchTypeService');
|
|
|
$this->batchService=app('BatchService');
|
|
|
|
|
|
- $stationMissionBatches_toCreate=new Collection();
|
|
|
+ $stationTaskBatches_toCreate=new Collection();
|
|
|
$id_stationTaskBatchType=$this->stationTaskBatchTypeService->firstByWhere('name','U型线分捡');
|
|
|
|
|
|
- $batches_handled=[];
|
|
|
+ $batches_handled=collect();
|
|
|
foreach ($batches as $batch){
|
|
|
if ($batch['status']=='未处理'){
|
|
|
$stationType=$this->stationTypeService->getByBatch($batch);
|
|
|
$station=$this->stationService->getStation_byType($stationType['name']);
|
|
|
- $stationMissionBatches_toCreate->push([
|
|
|
+ $stationTaskBatches_toCreate->push([
|
|
|
'batch_id'=>$batch['id'],
|
|
|
'station_id'=>$station['id'],
|
|
|
'station_task_batch_type_id'=> $id_stationTaskBatchType,
|
|
|
'status'=>'待处理'
|
|
|
]);
|
|
|
- $batches_handled[]=$batch;
|
|
|
+ $batches_handled->push($batch);
|
|
|
}
|
|
|
}
|
|
|
$this->batchService->updateWhereIn('id',data_get($batches_handled,'*.id'),['status'=>'处理中']);
|
|
|
- $this->insert($stationMissionBatches_toCreate->toArray());
|
|
|
+ $this->insert($stationTaskBatches_toCreate->toArray());
|
|
|
+ $this->stationTaskService->registerSubTasks($stationTasks_toAttach,
|
|
|
+ $stationTaskBatches_toCreate->map(function ($stationMissionBatch){
|
|
|
+ return [$stationMissionBatch];
|
|
|
+ })
|
|
|
+ );
|
|
|
|
|
|
- return $stationMissionBatches_toCreate;
|
|
|
+ return $stationTaskBatches_toCreate;
|
|
|
}
|
|
|
|
|
|
public function insert(array $stationMissionBatches): bool
|