| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace App\Services;
- use App\Batch;
- use App\StationRuleBatch;
- 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';
- 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();
- foreach ($batches as $batch){
- $stationRuleBatch=$this->getByBatch($batch);
- if($stationRuleBatch)
- $batches_toProcess->push($batch);
- }
- return $batches_toProcess;
- }
- }
|