model = new OpmDsDevice; $this->repository = DeviceRepository::new(); } public function index(): Response { return raw_view('device/index'); } public function insert(Request $request): Response { if ($request->method() === 'POST') { return parent::insert($request); } return raw_view('device/insert'); } public function update(Request $request): Response { if ($request->method() === 'POST') { return parent::update($request); } return raw_view('device/update'); } protected function afterQuery($items) { $statusMap = [1 => '正常', 2 => '离线', 3 => '报警']; $typeMap = [1 => '网关', 2 => '消毒灭菌器']; foreach ($items as &$item) { $hospital = OpmMwHospital::find($item->hospital_id); $department = OpmMwDepartment::find($item->department_id); $item->hospital_name = $hospital->organ_name ?? '未知'; $item->department_name = $department->dept_name ?? '未知'; $item->status_text = $statusMap[$item->status] ?? '未知'; $item->type_text = $typeMap[$item->type] ?? '未知'; } return $items; } }