init
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\admin\app\service;
|
||||
|
||||
use plugin\admin\app\repository\DeviceUsageRepository;
|
||||
|
||||
/**
|
||||
* 设备使用情况服务层
|
||||
* 负责业务逻辑组装,Repository 只做数据访问
|
||||
* 设备下拉选项复用 DeviceStatusService
|
||||
*/
|
||||
class DeviceUsageService extends BaseService
|
||||
{
|
||||
private DeviceUsageRepository $repository;
|
||||
private DeviceStatusService $deviceStatusService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->repository = DeviceUsageRepository::new();
|
||||
$this->deviceStatusService = new DeviceStatusService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备使用情况列表(带分页、筛选)
|
||||
*/
|
||||
public function getUsageList(array $params): array
|
||||
{
|
||||
$page = max(1, (int)($params['page'] ?? 1));
|
||||
$limit = max(1, (int)($params['limit'] ?? 20));
|
||||
|
||||
// 解析医院多选参数
|
||||
$filters = [];
|
||||
$hospitalId = $params['hospital_id'] ?? null;
|
||||
if ($hospitalId) {
|
||||
if (is_array($hospitalId) && ($hospitalId[0] ?? '') === 'in') {
|
||||
$filters['hospital_ids'] = explode(',', trim($hospitalId[1] ?? ''));
|
||||
} else {
|
||||
$filters['hospital_ids'] = (array)$hospitalId;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($params['device_id'])) {
|
||||
$filters['device_id'] = $params['device_id'];
|
||||
}
|
||||
if (!empty($params['start_time'])) {
|
||||
$filters['start_time'] = $params['start_time'];
|
||||
}
|
||||
if (!empty($params['end_time'])) {
|
||||
$filters['end_time'] = $params['end_time'];
|
||||
}
|
||||
|
||||
$result = $this->repository->paginateCycles($filters, $page, $limit);
|
||||
|
||||
$data = [];
|
||||
foreach ($result['items'] as $item) {
|
||||
$data[] = $this->repository->formatCycleItem($item);
|
||||
}
|
||||
|
||||
return ['total' => $result['total'], 'data' => $data];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备下拉选项(复用 DeviceStatusService)
|
||||
*/
|
||||
public function getDeviceOptions(): array
|
||||
{
|
||||
return $this->deviceStatusService->getDeviceOptions();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user