model = new OpmDsWarnRecord; $this->repository = WarnRecordRepository::new(); } public function index(): Response { return raw_view('warn-record/index'); } /** * 处置页面 / 处置提交 */ public function deal(Request $request): Response { if ($request->method() === 'POST') { $id = (int)$request->post('id'); $record = $this->repository->findWithPermission($id); $record->action = $request->post('action', ''); $record->action_name = $request->post('action_name', ''); $record->action_time = $request->post('action_time', date('Y-m-d H:i:s')); $record->status = 2; // 已处理 $record->save(); return $this->json(0, 'ok'); } return raw_view('warn-record/deal'); } protected function afterQuery($items) { $typeMap = [1 => '温度预警', 2 => '压力预警', 3 => '时间预警']; $levelMap = [1 => '初级', 2 => '中级', 3 => '高级']; $statusMap = [1 => '未处理', 2 => '已处理']; $notifierTypeMap = [1 => '短信', 2 => '电话', 3 => '微信']; foreach ($items as &$item) { $hospital = OpmMwHospital::find($item->hospital_id); $device = OpmDsDevice::find($item->device_id); $item->hospital_name = $hospital->organ_name ?? '未知'; $item->device_name = $device->name ?? '未知'; $item->type_text = $typeMap[$item->type] ?? '未知'; $item->level_text = $levelMap[$item->level] ?? '未知'; $item->status_text = $statusMap[$item->status] ?? '未知'; $item->notifier_type_text = $notifierTypeMap[$item->notifier_type] ?? '未知'; } return $items; } }