update
This commit is contained in:
parent
3a7be52fa5
commit
15977d3d89
|
@ -5,7 +5,11 @@ namespace app\api\controller\dataview;
|
||||||
use app\api\controller\BaseApiController;
|
use app\api\controller\BaseApiController;
|
||||||
use app\common\model\device\Device;
|
use app\common\model\device\Device;
|
||||||
use app\common\model\device\MonitorAlarm;
|
use app\common\model\device\MonitorAlarm;
|
||||||
|
use app\common\model\farm\Farm;
|
||||||
|
use app\common\model\fence_house\FenceHouse;
|
||||||
use app\common\model\land\LandPlant;
|
use app\common\model\land\LandPlant;
|
||||||
|
use app\common\model\land\Product;
|
||||||
|
use app\common\model\product\ProductDevice;
|
||||||
use think\App;
|
use think\App;
|
||||||
use think\Exception;
|
use think\Exception;
|
||||||
use think\exception\ErrorException;
|
use think\exception\ErrorException;
|
||||||
|
@ -59,43 +63,59 @@ class DeviceController extends BaseApiController
|
||||||
// 监测设备数量统计
|
// 监测设备数量统计
|
||||||
public function deviceCount()
|
public function deviceCount()
|
||||||
{
|
{
|
||||||
$total = Device::alias('d')
|
$total = Device::alias('d')->where(function ($query) {
|
||||||
->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 != '') {
|
if ($this->streetCode != '') {
|
||||||
$query->where('l.town_code', $this->streetCode);
|
$farmIds = Farm::where('street', $this->streetCode)->column('id');
|
||||||
|
$fenceHouseIds = FenceHouse::whereIn('farm_id', $farmIds)->column('id');
|
||||||
|
$productIds = Product::whereIn('fence_house_id', $fenceHouseIds)->column('id');
|
||||||
|
$deviceIds = ProductDevice::whereIn('product_id', $productIds)->column('device_id');
|
||||||
|
$query->whereIn('d.id', $deviceIds);
|
||||||
} else {
|
} else {
|
||||||
$query->where('l.county_code', $this->areaCode);
|
$farmIds = Farm::where('area', $this->areaCode)->column('id');
|
||||||
|
$fenceHouseIds = FenceHouse::whereIn('farm_id', $farmIds)->column('id');
|
||||||
|
$productIds = Product::whereIn('fence_house_id', $fenceHouseIds)->column('id');
|
||||||
|
$deviceIds = ProductDevice::whereIn('product_id', $productIds)->column('device_id');
|
||||||
|
$query->whereIn('d.id', $deviceIds);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
->count();
|
->count();
|
||||||
|
|
||||||
$online = Device::alias('d')
|
$online = Device::alias('d')->where(function ($query) {
|
||||||
->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 != '') {
|
if ($this->streetCode != '') {
|
||||||
$query->where('l.town_code', $this->streetCode);
|
$farmIds = Farm::where('street', $this->streetCode)->column('id');
|
||||||
|
$fenceHouseIds = FenceHouse::whereIn('farm_id', $farmIds)->column('id');
|
||||||
|
$productIds = Product::whereIn('fence_house_id', $fenceHouseIds)->column('id');
|
||||||
|
$deviceIds = ProductDevice::whereIn('product_id', $productIds)->column('device_id');
|
||||||
|
$query->whereIn('d.id', $deviceIds);
|
||||||
} else {
|
} else {
|
||||||
$query->where('l.county_code', $this->areaCode);
|
$farmIds = Farm::where('area', $this->areaCode)->column('id');
|
||||||
|
$fenceHouseIds = FenceHouse::whereIn('farm_id', $farmIds)->column('id');
|
||||||
|
$productIds = Product::whereIn('fence_house_id', $fenceHouseIds)->column('id');
|
||||||
|
$deviceIds = ProductDevice::whereIn('product_id', $productIds)->column('device_id');
|
||||||
|
$query->whereIn('d.id', $deviceIds);
|
||||||
}
|
}
|
||||||
})->where('d.is_online', 1)->count();
|
})->where('d.is_online', 1)->count();
|
||||||
$offline = Device::alias('d')
|
|
||||||
->join('product_device pd', 'd.id=pd.device_id')
|
$offline = Device::alias('d')->where(function ($query) {
|
||||||
->join('land_product lp', 'pd.product_id=lp.product_id')
|
|
||||||
->join('land l', 'l.id=lp.land_id')
|
|
||||||
->where(function ($query) {
|
|
||||||
if ($this->streetCode != '') {
|
if ($this->streetCode != '') {
|
||||||
$query->where('l.town_code', $this->streetCode);
|
$farmIds = Farm::where('street', $this->streetCode)->column('id');
|
||||||
|
$fenceHouseIds = FenceHouse::whereIn('farm_id', $farmIds)->column('id');
|
||||||
|
$productIds = Product::whereIn('fence_house_id', $fenceHouseIds)->column('id');
|
||||||
|
$deviceIds = ProductDevice::whereIn('product_id', $productIds)->column('device_id');
|
||||||
|
$query->whereIn('d.id', $deviceIds);
|
||||||
} else {
|
} else {
|
||||||
$query->where('l.county_code', $this->areaCode);
|
$farmIds = Farm::where('area', $this->areaCode)->column('id');
|
||||||
|
$fenceHouseIds = FenceHouse::whereIn('farm_id', $farmIds)->column('id');
|
||||||
|
$productIds = Product::whereIn('fence_house_id', $fenceHouseIds)->column('id');
|
||||||
|
$deviceIds = ProductDevice::whereIn('product_id', $productIds)->column('device_id');
|
||||||
|
$query->whereIn('d.id', $deviceIds);
|
||||||
}
|
}
|
||||||
})->where('d.is_online', 2)->count();
|
})->where('d.is_online', 2)->count();
|
||||||
|
|
||||||
return $this->success('成功', compact('total', 'online', 'offline'));
|
$alarmCount = 0;
|
||||||
|
$todayAlarmCount = 0;
|
||||||
|
|
||||||
|
return $this->success('成功', compact('total', 'online', 'offline', 'alarmCount', 'todayAlarmCount'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue