add 设备告警统计

This commit is contained in:
chenbo 2023-12-14 15:00:45 +08:00
parent 6f9152bccf
commit 8571666ad5
1 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,51 @@
<?php
namespace app\api\controller\dataview;
use app\api\controller\BaseApiController;
use app\common\model\device\Device;
use app\common\model\device\MonitorAlarm;
use think\App;
use think\Exception;
use think\exception\ErrorException;
use think\exception\HttpResponseException;
use think\exception\ValidateException;
class DeviceController extends BaseApiController
{
public array $notNeedLogin = ['deviceAlarmCount'];
public $areaCode;
public $streetCode;
public function initialize()
{
parent::initialize();
$this->areaCode = $this->request->param('areaCode', '');
$this->streetCode = $this->request->param('streetCode', '');
if ($this->areaCode == '') {
throw new ValidateException('未获取到位置信息');
}
}
public function deviceAlarmCount()
{
$list = MonitorAlarm::alias('ma')->field('ma.*,d.code AS device_code,d.name AS device_name')
->join('device d', 'ma.device_id=d.id')
->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.street_code', $this->streetCode);
} else {
$query->where('l.area_code', $this->areaCode);
}
})
->whereWeek('ma.create_time')
->limit(30)
->select();
return $this->success('成功', compact('list'));
}
}