69 lines
1.8 KiB
PHP
69 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace plugin\admin\app\controller;
|
|
|
|
use plugin\admin\app\model\OpmDsDevice;
|
|
use plugin\admin\app\model\OpmMwDepartment;
|
|
use plugin\admin\app\model\OpmMwHospital;
|
|
use plugin\admin\app\repository\DeviceRepository;
|
|
use support\Request;
|
|
use support\Response;
|
|
|
|
/**
|
|
* 设备管理
|
|
*/
|
|
class DeviceController extends Crud
|
|
{
|
|
use WithDataPermission;
|
|
|
|
/**
|
|
* @var OpmDsDevice
|
|
*/
|
|
protected $model = null;
|
|
|
|
private DeviceRepository $repository;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->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;
|
|
}
|
|
}
|