You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
4.5 KiB
125 lines
4.5 KiB
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Exports\LicensePlateRecognitionExport;
|
|
use App\Models\LicensePlateRecognition;
|
|
use App\Services\ApiResponseService;
|
|
use App\Services\LicensePlateRecognitionService;
|
|
use Exception;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
|
|
|
class LicensePlateRecognitionController extends BaseController
|
|
{
|
|
protected LicensePlateRecognitionService $service;
|
|
|
|
/**
|
|
* 构造函数
|
|
* @param ApiResponseService $responseService
|
|
* @param LicensePlateRecognitionService $service
|
|
*/
|
|
public function __construct(
|
|
ApiResponseService $responseService,
|
|
LicensePlateRecognitionService $service
|
|
) {
|
|
parent::__construct($responseService);
|
|
$this->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'
|
|
);
|
|
}
|
|
}
|
|
|