| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace App\Services;
- use App\Batch;
- use App\StationRuleBatch;
- use App\StationTaskBatch;
- use App\StationType;
- use Illuminate\Support\Collection;
- use Illuminate\Support\Facades\Cache;
- use App\Traits\ServiceAppAop;
- class StationRuleBatchService
- {
- use ServiceAppAop;
- protected $modelClass=StationRuleBatch::class;
- function getByBatch(Batch $batch): ?StationRuleBatch
- {
- $batchType = $batch['type'] ?? 'null';
- $ownerId = $batch['owner_id'] ?? 'null';
- $batch->loadMissing('stationTaskBatch');
- if($batch['stationTaskBatch'])return null;
- return Cache::remember('stationRuleBatch_batchType_'.$batchType.'_ownerId_'.$ownerId, config('cache.expirations.rarelyChange'),function()use($batch){
- $builder= StationRuleBatch::query()->with('stationType')
- ->where('owner_id',$batch['owner_id']);
- if($batch['type']
- && $batch['type']!='无'){
- $builder=$builder->where('batch_type',$batch['type']);
- }
- return $builder->first();
- });
- }
- function getStationType_toBeTask(Batch $batch): ?StationType{
- $stationRuleBatch=$this->getByBatch($batch);
- if(!$stationRuleBatch)return null;
- return $stationRuleBatch['stationType'];
- }
- /**
- * @param Collection $batches
- * @return Collection Batches
- */
- function getBatches_shouldProcess(Collection $batches): Collection
- {
- $batches_toProcess=collect();
- $batches_inTask=StationTaskBatch::query()->whereIn('batch_id',data_get($batches,'*.id'))->get();
- $batches=$batches->whereNotIn('id',data_get($batches_inTask,'*.id')??[]);
- foreach ($batches as $batch){
- $stationRuleBatch=$this->getByBatch($batch);
- if($stationRuleBatch)
- $batches_toProcess->push($batch);
- }
- return $batches_toProcess;
- }
- }
|