5 changed files with 227 additions and 0 deletions
@ -0,0 +1,124 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Admin; |
|||
|
|||
use App\Models\LicensePlateRecognition; |
|||
use Exception; |
|||
use Illuminate\Http\JsonResponse; |
|||
use Illuminate\Http\Request; |
|||
|
|||
class LicensePlateRecognitionController extends BaseController |
|||
{ |
|||
|
|||
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->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() |
|||
); |
|||
} |
|||
} |
|||
|
|||
protected function getCount($time_slot) |
|||
{ |
|||
$manualWhere = $highWhere = $middleWhere = $where = [ |
|||
'time_slot' => $time_slot |
|||
]; |
|||
$where['manual_modification'] = 0; |
|||
$sumCount = LicensePlateRecognition::query()->where($where) |
|||
->count(); |
|||
$highWhere['recognition'] = 5; |
|||
$highCount = LicensePlateRecognition::query()->where( |
|||
$highWhere |
|||
)->count(); |
|||
$middleWhere['recognition'] = 1; |
|||
$middleCount = LicensePlateRecognition::query()->where( |
|||
$middleWhere |
|||
)->count(); |
|||
$manualWhere['manual_modification'] = 1; |
|||
$manualCount = LicensePlateRecognition::query()->where( |
|||
$manualWhere |
|||
)->count(); |
|||
return [ |
|||
'sum_count' => $sumCount, |
|||
'high_count' => $highCount, |
|||
'middle_count' => $middleCount, |
|||
'manual_count' => $manualCount, |
|||
'high_ratio' => get_ratio($sumCount, $highCount), |
|||
'middle_ratio' => get_ratio($sumCount, $middleCount), |
|||
'manual_ratio' => get_ratio($sumCount, $manualCount) |
|||
]; |
|||
} |
|||
|
|||
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->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() |
|||
); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
<?php |
|||
|
|||
namespace App\Models; |
|||
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
|
|||
class LicensePlateRecognition extends Model |
|||
{ |
|||
use HasFactory; |
|||
|
|||
protected $table = 'license_plate_recognition'; |
|||
|
|||
protected $hidden |
|||
= [ |
|||
'updated_at' |
|||
]; |
|||
|
|||
public function getCreatedAtAttribute($value): string |
|||
{ |
|||
return get_datetime('datetime', strtotime($value)); |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
<?php |
|||
|
|||
namespace App\Services; |
|||
|
|||
use App\Models\LicensePlateRecognition; |
|||
use App\Models\ParkingLicensePlate; |
|||
use App\Models\ParkingSpaceType; |
|||
use Exception; |
|||
use Illuminate\Support\Facades\DB; |
|||
|
|||
class LicensePlateRecognitionService extends BaseService |
|||
{ |
|||
|
|||
/** |
|||
* 构造函数 |
|||
* @param OperationLogService $logService |
|||
*/ |
|||
public function __construct(OperationLogService $logService) |
|||
{ |
|||
parent::__construct($logService); |
|||
$this->logService->menuTitle = 'recognition_rate'; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* @param $data |
|||
* @throws Exception |
|||
*/ |
|||
public function createData($data) |
|||
{ |
|||
$model = LicensePlateRecognition::query()->create([ |
|||
'time_slot' => get_datetime('date'), |
|||
'manual_modification' => $data['manual_modification'], |
|||
'license_plate' => $data['license_plate'], |
|||
'recognition' => $data['recognition'], |
|||
'capture_images' => $data['capture_images'], |
|||
'created_at' => get_datetime() |
|||
]); |
|||
return $model; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
<?php |
|||
|
|||
use Illuminate\Database\Migrations\Migration; |
|||
use Illuminate\Database\Schema\Blueprint; |
|||
use Illuminate\Support\Facades\Schema; |
|||
|
|||
return new class extends Migration |
|||
{ |
|||
/** |
|||
* Run the migrations. |
|||
*/ |
|||
public function up(): void |
|||
{ |
|||
Schema::create('license_plate_recognition', function (Blueprint $table) { |
|||
$table->id(); |
|||
$table->date('time_slot')->comment('时间段'); |
|||
$table->tinyInteger('manual_modification')->default(0)->comment('手动修改 0无 1有'); |
|||
$table->string('license_plate', 50)->default('')->comment('车牌号码'); |
|||
$table->tinyInteger('recognition')->default(0)->comment('识别度 0无法识别 1低 5高'); |
|||
$table->string('capture_images', 255)->default('')->comment('抓取图片'); |
|||
$table->innoDb(); |
|||
$table->timestamps(); |
|||
$table->comment('车牌识别'); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Reverse the migrations. |
|||
*/ |
|||
public function down(): void |
|||
{ |
|||
Schema::dropIfExists('license_plate_recognition'); |
|||
} |
|||
}; |
|||
Loading…
Reference in new issue