init
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\admin\app\controller;
|
||||
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 申诉管理(占位)
|
||||
*/
|
||||
class AppealController extends Base
|
||||
{
|
||||
/**
|
||||
* 浏览
|
||||
*/
|
||||
public function index(): Response
|
||||
{
|
||||
return raw_view('appeal/index');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\admin\app\controller;
|
||||
|
||||
use plugin\admin\app\service\DataOverviewService;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
class DataOverviewController extends Crud
|
||||
{
|
||||
protected $model = null;
|
||||
|
||||
private DataOverviewService $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new DataOverviewService();
|
||||
}
|
||||
|
||||
public function index(): Response
|
||||
{
|
||||
return raw_view('data-overview/index');
|
||||
}
|
||||
|
||||
/**
|
||||
* 消毒灭菌次数概况(今日/本周/本月/本年)
|
||||
*/
|
||||
public function getIndexCount(): Response
|
||||
{
|
||||
return json(['code' => 0, 'data' => $this->service->getIndexCount()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 消毒灭菌锅(设备)运行状态
|
||||
*/
|
||||
public function getIndexRunStatus(): Response
|
||||
{
|
||||
return json(['code' => 0, 'data' => $this->service->getDeviceRunStatus()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 消毒灭菌统计折线图(7日/30日/本年)
|
||||
*/
|
||||
public function getIndexLine(Request $request): Response
|
||||
{
|
||||
$parameterTime = $request->get('parameter_time', 'week');
|
||||
return json(['code' => 0, 'data' => $this->service->getLineData($parameterTime)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 预警概览(预警次数/处理次数)
|
||||
*/
|
||||
public function getIndexWarnCount(): Response
|
||||
{
|
||||
return json(['code' => 0, 'data' => $this->service->getWarnCount()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 预警分布饼图数据
|
||||
*/
|
||||
public function getIndexWarnTypePie(): Response
|
||||
{
|
||||
return json(['code' => 0, 'data' => $this->service->getWarnTypePie()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 预警分布百分比信息
|
||||
*/
|
||||
public function getIndexWarnTypePieInfo(): Response
|
||||
{
|
||||
return json(['code' => 0, 'data' => $this->service->getWarnTypePieInfo()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 预警设备列表
|
||||
*/
|
||||
public function getIndexWarnDeviceList(): Response
|
||||
{
|
||||
$data = $this->service->getWarnDeviceList();
|
||||
return json(['code' => 0, 'data' => $data ?? false]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 事件数据
|
||||
*/
|
||||
public function getIndexEvent(): Response
|
||||
{
|
||||
return json(['code' => 0, 'data' => $this->service->getEventData()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\admin\app\controller;
|
||||
|
||||
use plugin\admin\app\model\OpmMwDepartment;
|
||||
use plugin\admin\app\model\OpmMwHospital;
|
||||
use plugin\admin\app\repository\DepartmentRepository;
|
||||
use plugin\admin\app\service\DepartmentService;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 科室管理
|
||||
*/
|
||||
class DepartmentController extends Crud
|
||||
{
|
||||
use WithDataPermission;
|
||||
|
||||
/**
|
||||
* @var OpmMwDepartment
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
private DepartmentService $service;
|
||||
private DepartmentRepository $repository;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new OpmMwDepartment;
|
||||
$this->service = new DepartmentService();
|
||||
$this->repository = DepartmentRepository::new();
|
||||
}
|
||||
|
||||
public function index(): Response
|
||||
{
|
||||
return raw_view('department/index');
|
||||
}
|
||||
|
||||
public function insert(Request $request): Response
|
||||
{
|
||||
if ($request->method() === 'POST') {
|
||||
return parent::insert($request);
|
||||
}
|
||||
return raw_view('department/insert');
|
||||
}
|
||||
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
if ($request->method() === 'POST') {
|
||||
return parent::update($request);
|
||||
}
|
||||
return raw_view('department/update');
|
||||
}
|
||||
|
||||
protected function afterQuery($items)
|
||||
{
|
||||
foreach ($items as &$item) {
|
||||
$hospital = OpmMwHospital::find($item->organ_id);
|
||||
$item->hospital_name = $hospital->organ_name ?? '未知';
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定医院下科室选项
|
||||
*/
|
||||
public function options(Request $request): Response
|
||||
{
|
||||
$hospitalId = (int)$request->get('hospital_id', 0);
|
||||
if ($hospitalId <= 0) {
|
||||
return $this->json(1, '缺少医院ID参数');
|
||||
}
|
||||
return $this->json(0, 'ok', $this->service->getDepartmentOptions($hospitalId));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\admin\app\controller;
|
||||
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 设备监控(占位)
|
||||
*/
|
||||
class DeviceMonitorController extends Base
|
||||
{
|
||||
/**
|
||||
* 浏览
|
||||
*/
|
||||
public function index(): Response
|
||||
{
|
||||
return raw_view('device-monitor/index');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\admin\app\controller;
|
||||
|
||||
use plugin\admin\app\service\DeviceStatusService;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 设备情况管理(参照旧系统 device.tpl.html)
|
||||
*/
|
||||
class DeviceStatusController extends Base
|
||||
{
|
||||
private DeviceStatusService $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new DeviceStatusService();
|
||||
}
|
||||
|
||||
public function index(): Response
|
||||
{
|
||||
return raw_view('device-status/index');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备按钮列表(带数据权限)
|
||||
*/
|
||||
public function getDeviceNameList(): Response
|
||||
{
|
||||
return json(['code' => 0, 'data' => $this->service->getDeviceNameList()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备基本信息
|
||||
*/
|
||||
public function getDeviceBasicInfo(): Response
|
||||
{
|
||||
$deviceId = request()->get('id') ? (int)request()->get('id') : null;
|
||||
return json(['code' => 0, 'data' => $this->service->getDeviceBasicInfo($deviceId)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备灭菌次数及合规次数
|
||||
*/
|
||||
public function getDeviceRunInfo(): Response
|
||||
{
|
||||
$deviceId = request()->get('id') ? (int)request()->get('id') : null;
|
||||
return json(['code' => 0, 'data' => $this->service->getDeviceRunInfo($deviceId)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备预警次数(按类型分)
|
||||
*/
|
||||
public function getDeviceWarnInfo(): Response
|
||||
{
|
||||
$deviceId = request()->get('id') ? (int)request()->get('id') : null;
|
||||
return json(['code' => 0, 'data' => $this->service->getDeviceWarnInfo($deviceId)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备最近周期运行折线图数据
|
||||
*/
|
||||
public function getDeviceCycleRunLine(): Response
|
||||
{
|
||||
$deviceId = request()->get('id') ? (int)request()->get('id') : null;
|
||||
return json(['code' => 0, 'data' => $this->service->getDeviceCycleRunLine($deviceId)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备最近周期运行列表(右侧小表格)
|
||||
*/
|
||||
public function getDeviceCycleRunList(): Response
|
||||
{
|
||||
$deviceId = request()->get('id') ? (int)request()->get('id') : null;
|
||||
return json(['code' => 0, 'data' => $this->service->getDeviceCycleRunList($deviceId)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取该设备下所有周期运行信息(操作记录)
|
||||
*/
|
||||
public function getDeviceAllCycleInfo(): Response
|
||||
{
|
||||
$deviceId = request()->get('id') ? (int)request()->get('id') : null;
|
||||
return json(['code' => 0, 'data' => $this->service->getDeviceAllCycleInfo($deviceId)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\admin\app\controller;
|
||||
|
||||
use plugin\admin\app\service\DeviceUsageService;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 设备使用情况(参照旧系统 device_details.tpl.html)
|
||||
*/
|
||||
class DeviceUsageController extends Base
|
||||
{
|
||||
private DeviceUsageService $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new DeviceUsageService();
|
||||
}
|
||||
|
||||
public function index(): Response
|
||||
{
|
||||
return raw_view('device-usage/index');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备使用情况列表(Layui table 格式,带数据权限)
|
||||
*/
|
||||
public function select(): Response
|
||||
{
|
||||
$params = request()->get();
|
||||
$result = $this->service->getUsageList($params);
|
||||
|
||||
return json([
|
||||
'code' => 0,
|
||||
'msg' => '',
|
||||
'count' => $result['total'],
|
||||
'data' => $result['data'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备下拉选项(带数据权限,复用 DeviceStatusService)
|
||||
*/
|
||||
public function deviceOptions(): Response
|
||||
{
|
||||
return json(['code' => 0, 'msg' => 'ok', 'data' => $this->service->getDeviceOptions()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\admin\app\controller;
|
||||
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 执法事件管理(占位)
|
||||
*/
|
||||
class EnforcementController extends Base
|
||||
{
|
||||
/**
|
||||
* 浏览
|
||||
*/
|
||||
public function index(): Response
|
||||
{
|
||||
return raw_view('enforcement/index');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\admin\app\controller;
|
||||
|
||||
use plugin\admin\app\model\OpmMwHospital;
|
||||
use plugin\admin\app\repository\HospitalRepository;
|
||||
use plugin\admin\app\service\HospitalService;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 医院管理
|
||||
*/
|
||||
class HospitalController extends Crud
|
||||
{
|
||||
use WithDataPermission;
|
||||
|
||||
/**
|
||||
* @var OpmMwHospital
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
private HospitalService $service;
|
||||
private HospitalRepository $repository;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new OpmMwHospital;
|
||||
$this->service = new HospitalService();
|
||||
$this->repository = HospitalRepository::new();
|
||||
}
|
||||
|
||||
public function index(): Response
|
||||
{
|
||||
return raw_view('hospital/index');
|
||||
}
|
||||
|
||||
public function insert(Request $request): Response
|
||||
{
|
||||
if ($request->method() === 'POST') {
|
||||
return parent::insert($request);
|
||||
}
|
||||
return raw_view('hospital/insert');
|
||||
}
|
||||
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
if ($request->method() === 'POST') {
|
||||
return parent::update($request);
|
||||
}
|
||||
return raw_view('hospital/update');
|
||||
}
|
||||
|
||||
protected function afterQuery($items)
|
||||
{
|
||||
$levelMap = [0 => '未定级', 1 => '一级', 2 => '二级', 3 => '三级'];
|
||||
$gradeMap = [0 => '未定级', 1 => '甲等', 2 => '乙等'];
|
||||
|
||||
foreach ($items as &$item) {
|
||||
$level = $levelMap[$item->organ_level] ?? '未知';
|
||||
$grade = $gradeMap[$item->grade] ?? '未知';
|
||||
$item->level_grade_text = $level . $grade;
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* 医院下拉选项(供其他页面使用)
|
||||
*/
|
||||
public function options(): Response
|
||||
{
|
||||
return $this->json(0, 'ok', $this->service->getHospitalOptions());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\admin\app\controller;
|
||||
|
||||
use plugin\admin\app\model\OpmDsSensor;
|
||||
use plugin\admin\app\model\OpmMwDepartment;
|
||||
use plugin\admin\app\model\OpmMwHospital;
|
||||
use plugin\admin\app\repository\SensorRepository;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 传感器管理
|
||||
*/
|
||||
class SensorController extends Crud
|
||||
{
|
||||
use WithDataPermission;
|
||||
|
||||
/**
|
||||
* @var OpmDsSensor
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
private SensorRepository $repository;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new OpmDsSensor;
|
||||
$this->repository = SensorRepository::new();
|
||||
}
|
||||
|
||||
public function index(): Response
|
||||
{
|
||||
return raw_view('sensor/index');
|
||||
}
|
||||
|
||||
public function insert(Request $request): Response
|
||||
{
|
||||
if ($request->method() === 'POST') {
|
||||
return parent::insert($request);
|
||||
}
|
||||
return raw_view('sensor/insert');
|
||||
}
|
||||
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
if ($request->method() === 'POST') {
|
||||
return parent::update($request);
|
||||
}
|
||||
return raw_view('sensor/update');
|
||||
}
|
||||
|
||||
protected function afterQuery($items)
|
||||
{
|
||||
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 ?? '未知';
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\admin\app\controller;
|
||||
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 视频监控(占位)
|
||||
*/
|
||||
class VideoController extends Base
|
||||
{
|
||||
/**
|
||||
* 浏览
|
||||
*/
|
||||
public function index(): Response
|
||||
{
|
||||
return raw_view('video/index');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\admin\app\controller;
|
||||
|
||||
use plugin\admin\app\model\OpmDsDevice;
|
||||
use plugin\admin\app\model\OpmDsWarnRecord;
|
||||
use plugin\admin\app\model\OpmMwHospital;
|
||||
use plugin\admin\app\repository\WarnRecordRepository;
|
||||
use support\exception\BusinessException;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 异常记录管理(预警记录)
|
||||
*/
|
||||
class WarnRecordController extends Crud
|
||||
{
|
||||
use WithDataPermission;
|
||||
|
||||
/**
|
||||
* @var OpmDsWarnRecord
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
private WarnRecordRepository $repository;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\admin\app\controller;
|
||||
|
||||
use plugin\admin\app\model\OpmDsDevice;
|
||||
use plugin\admin\app\model\OpmDsWarnRule;
|
||||
use plugin\admin\app\model\OpmMwHospital;
|
||||
use plugin\admin\app\repository\WarnRuleRepository;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 报警规则管理
|
||||
*/
|
||||
class WarnRuleController extends Crud
|
||||
{
|
||||
use WithDataPermission;
|
||||
|
||||
/**
|
||||
* @var OpmDsWarnRule
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
private WarnRuleRepository $repository;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new OpmDsWarnRule;
|
||||
$this->repository = WarnRuleRepository::new();
|
||||
}
|
||||
|
||||
public function index(): Response
|
||||
{
|
||||
return raw_view('warn-rule/index');
|
||||
}
|
||||
|
||||
public function insert(Request $request): Response
|
||||
{
|
||||
if ($request->method() === 'POST') {
|
||||
return parent::insert($request);
|
||||
}
|
||||
return raw_view('warn-rule/insert');
|
||||
}
|
||||
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
if ($request->method() === 'POST') {
|
||||
return parent::update($request);
|
||||
}
|
||||
return raw_view('warn-rule/update');
|
||||
}
|
||||
|
||||
protected function afterQuery($items)
|
||||
{
|
||||
$typeMap = [1 => '温度', 2 => '压力', 3 => '时间'];
|
||||
$levelMap = [1 => '初级', 2 => '中级', 3 => '高级'];
|
||||
$noticeTypeMap = [1 => '短信', 2 => '电话', 3 => '微信'];
|
||||
$isOpenMap = [1 => '开启', 2 => '关闭'];
|
||||
|
||||
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->notice_type_text = $noticeTypeMap[$item->notice_type] ?? '未知';
|
||||
$item->is_open_text = $isOpenMap[$item->is_open] ?? '未知';
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\admin\app\controller;
|
||||
|
||||
/**
|
||||
* 需要数据权限的 Controller 使用此 Trait
|
||||
* 要求 Controller 中有 $this->repository 属性(BaseRepository 子类)
|
||||
* 重写 doSelect / doUpdate / doDelete,走 Repository 的 scopedQuery
|
||||
*/
|
||||
trait WithDataPermission
|
||||
{
|
||||
/**
|
||||
* 查询 - 以 repository->scopedQuery() 为基础,注入 withDataPermission
|
||||
*/
|
||||
protected function doSelect(array $where, ?string $field = null, string $order = 'desc')
|
||||
{
|
||||
$model = $this->repository->scopedQuery();
|
||||
foreach ($where as $column => $value) {
|
||||
if (is_array($value)) {
|
||||
if ($value[0] === 'like' || $value[0] === 'not like') {
|
||||
$model = $model->where($column, $value[0], "%$value[1]%");
|
||||
} elseif (in_array($value[0], ['>', '=', '<', '<>'])) {
|
||||
$model = $model->where($column, $value[0], $value[1]);
|
||||
} elseif ($value[0] == 'in' && !empty($value[1])) {
|
||||
$valArr = is_string($value[1]) ? explode(",", trim($value[1])) : $value[1];
|
||||
$model = $model->whereIn($column, $valArr);
|
||||
} elseif ($value[0] == 'not in' && !empty($value[1])) {
|
||||
$valArr = is_string($value[1]) ? explode(",", trim($value[1])) : $value[1];
|
||||
$model = $model->whereNotIn($column, $valArr);
|
||||
} elseif ($value[0] == 'null') {
|
||||
$model = $model->whereNull($column);
|
||||
} elseif ($value[0] == 'not null') {
|
||||
$model = $model->whereNotNull($column);
|
||||
} elseif ($value[0] !== '' || $value[1] !== '') {
|
||||
$model = $model->whereBetween($column, $value);
|
||||
}
|
||||
} else {
|
||||
$model = $model->where($column, $value);
|
||||
}
|
||||
}
|
||||
if ($field) {
|
||||
$model = $model->orderBy($field, $order);
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新 - 带数据权限查找记录
|
||||
*/
|
||||
protected function doUpdate($id, $data)
|
||||
{
|
||||
$model = $this->repository->findWithPermission($id);
|
||||
foreach ($data as $key => $val) {
|
||||
$model->{$key} = $val;
|
||||
}
|
||||
$model->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 - 带数据权限
|
||||
*/
|
||||
protected function doDelete(array $ids)
|
||||
{
|
||||
$this->repository->deleteWithPermission($ids);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user