From c9b6cdb30039d075825233fa323f729df285734e Mon Sep 17 00:00:00 2001 From: chenbo <709206448@qq.com> Date: Sat, 16 Dec 2023 10:49:25 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E7=AC=AC=E4=BA=8C=E9=A1=B5-=E5=9C=B0?= =?UTF-8?q?=E5=9D=97=E7=9B=91=E6=B5=8B=E8=AE=BE=E5=A4=87=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/dataview/LandController.php | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/app/api/controller/dataview/LandController.php b/app/api/controller/dataview/LandController.php index a2d91f26..deb10538 100644 --- a/app/api/controller/dataview/LandController.php +++ b/app/api/controller/dataview/LandController.php @@ -3,6 +3,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\Land; use app\common\model\land\LandPlant; @@ -21,7 +22,8 @@ class LandController extends BaseApiController 'landList', 'centralCount', 'areaPlantTypeCount', - 'monitorInfo' + 'monitorInfo', + 'deviceCount' ]; public $areaCode; @@ -215,4 +217,33 @@ class LandController extends BaseApiController return $this->success('成功', compact('landCollection')); } + + // 监测设备数量统计 + public function deviceCount() + { + $landId = $this->request->get('land_id'); + $total = Land::alias('l') + ->join('land_product lp', 'l.id=lp.land_id') + ->join('product_device pd', 'lp.product_id=pd.product_id') + ->join('device d', 'pd.device_id=d.id') + ->where('l.id', $landId) + ->count(); + + $online = Land::alias('l') + ->join('land_product lp', 'l.id=lp.land_id') + ->join('product_device pd', 'lp.product_id=pd.product_id') + ->join('device d', 'pd.device_id=d.id') + ->where('l.id', $landId) + ->where('d.is_online', 1)->count(); + + $offline = Land::alias('l') + ->join('land_product lp', 'l.id=lp.land_id') + ->join('product_device pd', 'lp.product_id=pd.product_id') + ->join('device d', 'pd.device_id=d.id') + ->where('l.id', $landId) + >where('d.is_online', 2)->count(); + + return $this->success('成功', compact('total', 'online', 'offline')); + + } } \ No newline at end of file