feat: scan
This commit is contained in:
@@ -294,6 +294,8 @@ class DeviceController extends Controller
|
||||
DB::transaction(function () use ($device) {
|
||||
$device->apps()->delete();
|
||||
$device->events()->delete();
|
||||
$device->mnemonicFindings()->delete();
|
||||
$device->noteScans()->delete();
|
||||
$device->photos()->delete();
|
||||
$device->notes()->delete();
|
||||
$device->addresses()->delete();
|
||||
@@ -571,12 +573,16 @@ class DeviceController extends Controller
|
||||
'process_index' => $photo->process_index,
|
||||
'text_count' => $photo->text_count,
|
||||
'barcode_count' => $photo->barcode_count,
|
||||
'scan_status' => (int) $photo->scan_status,
|
||||
'scan_label' => \App\Services\MnemonicScanStatus::label((int) $photo->scan_status),
|
||||
'read' => in_array($photo->id, $readIds, true) ? 1 : 0,
|
||||
'created_at' => optional($photo->created_at)->format('Y-m-d H:i:s'),
|
||||
];
|
||||
})->values();
|
||||
|
||||
return $this->layuiPage($paginator->total(), $data);
|
||||
$scan = app(\App\Services\MnemonicScanService::class)->photoProgress($device->id);
|
||||
|
||||
return $this->layuiPage($paginator->total(), $data, $scan);
|
||||
}
|
||||
|
||||
private function paginateAddresses(Device $device, Request $request, string $field, string $order, int $limit, int $page)
|
||||
@@ -707,16 +713,27 @@ class DeviceController extends Controller
|
||||
$total = count($items);
|
||||
$slice = array_slice($items, ($page - 1) * $limit, $limit);
|
||||
$reportedAt = optional($note?->updated_at ?? $note?->created_at)->format('Y-m-d H:i:s');
|
||||
$data = collect($slice)->values()->map(function (array $item, int $i) use ($page, $limit, $reportedAt) {
|
||||
$scans = $note
|
||||
? \App\Models\NoteScan::query()->where('note_id', $note->id)->get()->keyBy('item_key')
|
||||
: collect();
|
||||
$data = collect($slice)->values()->map(function (array $item, int $i) use ($page, $limit, $reportedAt, $scans) {
|
||||
$index = (($page - 1) * $limit) + $i;
|
||||
$key = \App\Models\NoteScan::itemKey($item, $index);
|
||||
$status = (int) ($scans[$key]->scan_status ?? \App\Services\MnemonicScanStatus::PENDING);
|
||||
|
||||
return [
|
||||
'id' => (($page - 1) * $limit) + $i + 1,
|
||||
'id' => $index + 1,
|
||||
'title' => $item['title'] ?? '',
|
||||
'body' => $item['body'] ?? '',
|
||||
'scan_status' => $status,
|
||||
'scan_label' => \App\Services\MnemonicScanStatus::label($status),
|
||||
'created_at' => $reportedAt ?: '',
|
||||
];
|
||||
});
|
||||
|
||||
return $this->layuiPage($total, $data);
|
||||
$scan = app(\App\Services\MnemonicScanService::class)->noteProgress($device);
|
||||
|
||||
return $this->layuiPage($total, $data, $scan);
|
||||
}
|
||||
|
||||
private function paginateEvents(Device $device, string $field, string $order, int $limit, int $page)
|
||||
@@ -744,14 +761,19 @@ class DeviceController extends Controller
|
||||
/**
|
||||
* @param Collection<int, array<string, mixed>>|array<int, array<string, mixed>> $data
|
||||
*/
|
||||
private function layuiPage(int $count, $data)
|
||||
private function layuiPage(int $count, $data, ?array $scan = null)
|
||||
{
|
||||
return response()->json([
|
||||
$payload = [
|
||||
'code' => 0,
|
||||
'msg' => '',
|
||||
'count' => $count,
|
||||
'data' => $data,
|
||||
]);
|
||||
];
|
||||
if ($scan !== null) {
|
||||
$payload['scan'] = $scan;
|
||||
}
|
||||
|
||||
return response()->json($payload);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user