Добавил базовые датасеты и агрегации для конструктора отчетов
This commit is contained in:
73
app/Services/Analytics/DataSets/UnwantedEventsDataSet.php
Normal file
73
app/Services/Analytics/DataSets/UnwantedEventsDataSet.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Analytics\DataSets;
|
||||
|
||||
use App\Models\Department;
|
||||
use App\Services\Analytics\AbstractDataSet;
|
||||
use App\Services\Analytics\AnalyticsQuery;
|
||||
use App\Services\Analytics\Dimension;
|
||||
use App\Services\Analytics\Measure;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UnwantedEventsDataSet extends AbstractDataSet
|
||||
{
|
||||
public function key(): string
|
||||
{
|
||||
return 'unwanted_events';
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return 'Нежелательные события';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Нежелательные события дежурных смен отделения';
|
||||
}
|
||||
|
||||
public function category(): string
|
||||
{
|
||||
return 'События';
|
||||
}
|
||||
|
||||
protected function dateField(): string
|
||||
{
|
||||
return 'e.created_at';
|
||||
}
|
||||
|
||||
protected function baseQuery(AnalyticsQuery $query): Builder
|
||||
{
|
||||
return DB::table('duty_unwanted_events as e')
|
||||
->join('report_duties as rd', 'rd.id', '=', 'e.report_duty_id')
|
||||
->where('rd.rf_department_id', $query->department->department_id)
|
||||
->where('rd.status_id', 2)
|
||||
->where('rd.period_start', '>=', $query->dateRange->startSql())
|
||||
->where('rd.period_end', '<=', $query->dateRange->endSql());
|
||||
}
|
||||
|
||||
public function dimensions(): array
|
||||
{
|
||||
return [
|
||||
new Dimension('event_title', 'Событие', 'string', 'e.title'),
|
||||
new Dimension('created_date', 'Дата', 'date', 'CAST(e.created_at AS date)'),
|
||||
new Dimension(
|
||||
'department',
|
||||
'Отделение',
|
||||
'string',
|
||||
'rd.rf_department_id',
|
||||
labels: fn (array $ids) => Department::whereIn('department_id', $ids)->get()
|
||||
->mapWithKeys(fn ($d) => [$d->department_id => $d->name_full ?? $d->name_short])
|
||||
->all(),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
public function measures(): array
|
||||
{
|
||||
return [
|
||||
new Measure('events_count', 'Количество событий', 'count', 'COUNT(*)'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user