add 第二页-地块监测设备统计

This commit is contained in:
chenbo 2023-12-16 10:49:25 +08:00
parent a24e238880
commit c9b6cdb300
1 changed files with 32 additions and 1 deletions

View File

@ -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'));
}
}