service = $service; } public function index(Request $request): JsonResponse { try { $query = LicensePlateRecognition::query(); if ($request->has('start_time') && $request->has('end_time')) { $start_time = $request->input('start_time'); $end_time = $request->input('end_time'); if (strtotime($start_time) && strtotime($end_time)) { $query->whereBetween('time_slot', [$start_time, $end_time]); } } // 分页 $page = $request->input('page', 1); $perPage = $request->input('per_page', 10); $columns = ['time_slot']; $total = 0; $all = $query->groupBy('time_slot')->select($columns)->get(); if ($all) { $total = count($all); } $items = $query->groupBy(['time_slot'])->latest('time_slot') ->forPage($page, $perPage)->get()->each(function ($item) { $countData = $this->service->getCount($item['time_slot']); $item['sum_count'] = $countData['sum_count']; $item['high_ratio'] = $countData['high_ratio']; $item['middle_ratio'] = $countData['middle_ratio']; $item['manual_count'] = $countData['manual_count']; $item['manual_ratio'] = $countData['manual_ratio']; return $item; }); return $this->responseService->success([ 'items' => $items, 'total' => $total, 'page' => $page, 'per_page' => $perPage, 'last_page' => ceil($total / $perPage), ]); } catch (Exception $e) { $m_prefix = __('exception.exception_handler.resource'); return $this->responseService->systemError( $m_prefix . ':' . $e->getMessage() ); } } public function curveGraph(Request $request): JsonResponse { try { $query = LicensePlateRecognition::query(); if ($request->has('start_time') && $request->has('end_time')) { $start_time = $request->input('start_time'); $end_time = $request->input('end_time'); if (strtotime($start_time) && strtotime($end_time)) { $query->whereBetween('time_slot', [$start_time, $end_time]); } } // 分页 $page = 1; $perPage = 16; $items = $query->groupBy(['time_slot'])->latest('time_slot') ->forPage($page, $perPage)->select('time_slot')->get() ->each(function ($item) { $countData = $this->service->getCount($item['time_slot']); $item['high_ratio'] = $countData['high_ratio']; $item['middle_ratio'] = $countData['middle_ratio']; $item['manual_ratio'] = $countData['manual_ratio']; return $item; }); return $this->responseService->success($items); } catch (Exception $e) { $m_prefix = __('exception.exception_handler.resource'); return $this->responseService->systemError( $m_prefix . ':' . $e->getMessage() ); } } /** * @return BinaryFileResponse */ public function export(): BinaryFileResponse { return Excel::download( new LicensePlateRecognitionExport(), set_space_underline(__('exports.license_plate_recognition.list')) . get_datetime('date_') . '.xlsx' ); } }