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