|
|
@@ -5,12 +5,14 @@ namespace App\Services;
|
|
|
|
|
|
|
|
|
use App\Batch;
|
|
|
+use App\Exceptions\ErrorException;
|
|
|
use App\Log;
|
|
|
use App\Station;
|
|
|
use App\StationTask;
|
|
|
use App\StationTaskBatch;
|
|
|
use App\StationTaskBatchType;
|
|
|
use Exception;
|
|
|
+use Illuminate\Foundation\Mix;
|
|
|
use Illuminate\Support\Collection;
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
|
|
@@ -75,22 +77,35 @@ class StationTaskBatchService
|
|
|
}
|
|
|
$this->batchService->updateWhereIn('id', data_get($batches_handled, '*.id'), ['status' => '处理中']);
|
|
|
$this->insert($stationTaskBatches_toCreate->toArray());
|
|
|
+ $stationTaskBatches_toCreate=$this->getWithIds($stationTaskBatches_toCreate);
|
|
|
$this->stationTaskService->registerSubTasks(
|
|
|
$stationTasks_toAttach,
|
|
|
- collect(
|
|
|
- [$stationTaskBatches_toCreate]
|
|
|
- )
|
|
|
+ $stationTaskBatches_toCreate->map(function($taskBatch){
|
|
|
+ return [$taskBatch];
|
|
|
+ })
|
|
|
);
|
|
|
|
|
|
return $stationTaskBatches_toCreate;
|
|
|
}
|
|
|
|
|
|
+ function getWithIds($stationMissionBatches): Collection
|
|
|
+ {
|
|
|
+ $md5=is_array($stationMissionBatches)
|
|
|
+ ?$md5=md5(json_encode($stationMissionBatches)):null;
|
|
|
+
|
|
|
+ return Cache::remember(
|
|
|
+ $md5??md5(json_encode($stationMissionBatches->toArray()))
|
|
|
+ ,config('cache.expirations.rarelyChange')
|
|
|
+ ,function()use($stationMissionBatches){
|
|
|
+ return StationTaskBatch::query()
|
|
|
+ ->whereIn('status',data_get($stationMissionBatches,'*.status'))
|
|
|
+ ->whereIn('batch_id',data_get($stationMissionBatches,'*.batch_id'))
|
|
|
+ ->get();
|
|
|
+ });
|
|
|
+ }
|
|
|
function insert(array $stationMissionBatches): bool
|
|
|
{
|
|
|
- $inserted = StationTaskBatch::query()->insert($stationMissionBatches);
|
|
|
- LogService::log(__METHOD__, __FUNCTION__, json_encode($stationMissionBatches) .
|
|
|
- '||' . json_encode(array_slice(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), 0, 3)));
|
|
|
- return $inserted;
|
|
|
+ return StationTaskBatch::query()->insert($stationMissionBatches);
|
|
|
}
|
|
|
|
|
|
function markManyExcepted(Collection $stationTaskBatches_failed)
|
|
|
@@ -105,10 +120,7 @@ class StationTaskBatchService
|
|
|
($logAtFailings_andWait =
|
|
|
function ($stationTaskBatches_failed) {
|
|
|
if ($stationTaskBatches_failed->isEmpty()) return;
|
|
|
- LogService::log(__METHOD__, __FUNCTION__,
|
|
|
- '任务波次异常失败的:' . $stationTaskBatches_failed->toJson()
|
|
|
- . '调用堆栈:' . json_encode(array_slice(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), 0, 3))
|
|
|
- );
|
|
|
+ throw new ErrorException('任务波次异常失败的');
|
|
|
})($stationTaskBatches_failed);
|
|
|
}
|
|
|
|