From e9d72f8d14cc24c1323b6d8eecb69444a635c1e0 Mon Sep 17 00:00:00 2001 From: chenbo <709206448@qq.com> Date: Thu, 14 Dec 2023 16:33:06 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E5=A4=A7=E5=B1=8F-=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=95=B0=E9=87=8F=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/dataview/DeviceController.php | 51 +++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/app/api/controller/dataview/DeviceController.php b/app/api/controller/dataview/DeviceController.php index d6924924..6e2d14f8 100644 --- a/app/api/controller/dataview/DeviceController.php +++ b/app/api/controller/dataview/DeviceController.php @@ -5,6 +5,7 @@ namespace app\api\controller\dataview; use app\api\controller\BaseApiController; use app\common\model\device\Device; use app\common\model\device\MonitorAlarm; +use app\common\model\land\LandPlant; use think\App; use think\Exception; use think\exception\ErrorException; @@ -13,7 +14,7 @@ use think\exception\ValidateException; class DeviceController extends BaseApiController { - public array $notNeedLogin = ['deviceAlarmCount']; + public array $notNeedLogin = ['deviceAlarmCount', 'deviceCount']; public $areaCode; public $streetCode; @@ -28,6 +29,7 @@ class DeviceController extends BaseApiController } } + // 设备告警统计 public function deviceAlarmCount() { $list = MonitorAlarm::alias('ma')->field('ma.*,d.code AS device_code,d.name AS device_name') @@ -37,9 +39,9 @@ class DeviceController extends BaseApiController ->join('land l', 'l.id=lp.land_id') ->where(function ($query) { if ($this->streetCode != '') { - $query->where('l.street_code', $this->streetCode); + $query->where('l.town_code', $this->streetCode); } else { - $query->where('l.area_code', $this->areaCode); + $query->where('l.county_code', $this->areaCode); } }) ->whereWeek('ma.create_time') @@ -48,4 +50,47 @@ class DeviceController extends BaseApiController return $this->success('成功', compact('list')); } + // 检测设备数量统计 + public function deviceCount() + { + $total = Device::alias('d') + ->join('product_device pd', 'd.id=pd.device_id') + ->join('land_product lp', 'pd.product_id=lp.product_id') + ->join('land l', 'l.id=lp.land_id') + ->where(function ($query) { + if ($this->streetCode != '') { + $query->where('l.town_code', $this->streetCode); + } else { + $query->where('l.county_code', $this->areaCode); + } + }) + ->count(); + + $online = Device::alias('d') + ->join('product_device pd', 'd.id=pd.device_id') + ->join('land_product lp', 'pd.product_id=lp.product_id') + ->join('land l', 'l.id=lp.land_id') + ->where(function ($query) { + if ($this->streetCode != '') { + $query->where('l.town_code', $this->streetCode); + } else { + $query->where('l.county_code', $this->areaCode); + } + })->where('d.is_online', 1)->count(); + $offline = Device::alias('d') + ->join('product_device pd', 'd.id=pd.device_id') + ->join('land_product lp', 'pd.product_id=lp.product_id') + ->join('land l', 'l.id=lp.land_id') + ->where(function ($query) { + if ($this->streetCode != '') { + $query->where('l.town_code', $this->streetCode); + } else { + $query->where('l.county_code', $this->areaCode); + } + })->where('d.is_online', 0)->count(); + + return $this->success('成功', compact('total', 'online', 'offline')); + + } + } \ No newline at end of file