65 lines
2.3 KiB
PHP
65 lines
2.3 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace plugin\produce\app\adminapi\controller;
|
||
|
|
|
||
|
|
use app\adminapi\middleware\OperationMiddleware;
|
||
|
|
use app\adminapi\middleware\PermissionMiddleware;
|
||
|
|
use core\tool\Json;
|
||
|
|
use madong\swagger\annotation\response\DataResponse;
|
||
|
|
use madong\swagger\attribute\Permission;
|
||
|
|
use OpenApi\Attributes as OA;
|
||
|
|
use plugin\produce\app\service\admin\WorkStatisticsService;
|
||
|
|
use support\annotation\Middleware;
|
||
|
|
use support\Request;
|
||
|
|
use support\Response;
|
||
|
|
|
||
|
|
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
|
||
|
|
class WorkStatisticsController
|
||
|
|
{
|
||
|
|
public function __construct(protected WorkStatisticsService $service)
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
#[OA\Get(path: '/produce/statistics/monthly', summary: '月工作统计', tags: ['produce-statistics'])]
|
||
|
|
#[DataResponse(description: '获取月工作统计成功')]
|
||
|
|
#[Permission(code: 'produce:statistics:monthly', description: '月工作统计')]
|
||
|
|
public function monthly(Request $request): Response
|
||
|
|
{
|
||
|
|
return Json::success('获取成功', [
|
||
|
|
'columns' => $this->monthlyColumns((string) $request->input('month', date('Y-m'))),
|
||
|
|
'items' => $this->service->monthly($request->all()),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
#[OA\Get(path: '/produce/statistics/daily', summary: '日工作统计', tags: ['produce-statistics'])]
|
||
|
|
#[DataResponse(description: '获取日工作统计成功')]
|
||
|
|
#[Permission(code: 'produce:statistics:daily', description: '日工作统计')]
|
||
|
|
public function daily(Request $request): Response
|
||
|
|
{
|
||
|
|
return Json::success('获取成功', [
|
||
|
|
'columns' => $this->dailyColumns(),
|
||
|
|
'items' => $this->service->daily($request->all()),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
private function monthlyColumns(string $month): array
|
||
|
|
{
|
||
|
|
$month = preg_match('/^\d{4}-\d{2}$/', $month) ? $month : date('Y-m');
|
||
|
|
$days = (int) date('t', strtotime($month . '-01'));
|
||
|
|
return array_map(static fn (int $day): array => [
|
||
|
|
'key' => (string) $day,
|
||
|
|
'label' => str_pad((string) $day, 2, '0', STR_PAD_LEFT),
|
||
|
|
], range(1, $days));
|
||
|
|
}
|
||
|
|
|
||
|
|
private function dailyColumns(): array
|
||
|
|
{
|
||
|
|
return array_map(static fn (int $hour): array => [
|
||
|
|
'key' => str_pad((string) $hour, 2, '0', STR_PAD_LEFT) . ':00',
|
||
|
|
'label' => str_pad((string) $hour, 2, '0', STR_PAD_LEFT) . ':00',
|
||
|
|
], range(0, 23));
|
||
|
|
}
|
||
|
|
}
|