Browse Source

增加能耗大屏

zgg 8 months ago
parent
commit
b6721b0ee8

+ 8 - 0
application/admin/controller/ElectricalDegree.php

@@ -44,6 +44,14 @@ class ElectricalDegree extends Auth
             $result['rows'] = $lists;
             return json($result);
         }else{
+            $param = [
+                'userId'=>$this->userId,
+                'orgId'=>$this->orgId,
+                'create_time'=>date('Y-m-d H:i:s')
+            ];
+            $token = think_encrypt(json_encode($param));
+            $screen_url1 =  request()->root().'/wap/screen1/#'.'/energy?token='.$token;
+            $this->assign('screen_url1',$screen_url1);
             $this->assign('meta_title','电度量列表');
             return $this->fetch();
         }

+ 4 - 1
application/admin/view/electrical_degree/index.html

@@ -3,7 +3,10 @@
 <div class="ibox">
     <div class="ibox-content">
         <div class="row">
-            <div class="col-sm-12" style="text-align: right;">
+            <div class="col-sm-3">
+                <a href="{$screen_url1}" target="_blank" class="btn btn-sm btn-primary">能耗大屏</a>
+            </div>
+            <div class="col-sm-9" style="text-align: right;">
                 <a onclick="layerOpen(this)" data-title="近7日用电量" url="{:url('tj1',[],'')}" href="javascript:;" class="btn btn-sm btn-primary" >近7日用电量</a>&nbsp;
                 <a onclick="layerOpen(this)" data-title="近30日用电量" url="{:url('tj2',[],'')}" href="javascript:;" class="btn btn-sm btn-primary" >近30日用电量</a>&nbsp;
             </div>

+ 46 - 0
application/api/controller/energy/Base.php

@@ -0,0 +1,46 @@
+<?php
+namespace app\api\controller\energy;
+
+use app\hander\HelpHander;
+use think\Controller;
+use think\Db;
+class Base extends Controller
+{
+
+    protected $userId;
+
+    protected $orgId;
+
+    protected function initialize()
+    {
+        parent::initialize();
+
+//        $data = [
+//            'userId' => 1,
+//            'orgId' => 3,
+//            'time' => date('Y-m-d H:i:s')
+//        ];
+//
+//        $token = think_decrypt(think_encrypt(json_encode($data)));
+
+
+        $token = think_decrypt(input('token','','trim'));
+
+        if(!$token){
+            HelpHander::error('token不正确');
+        }
+        $tdata = json_decode($token,true);
+//        $tdata = json_decode(think_decrypt($token),true);
+
+        if(!$tdata || !isset($tdata['userId']) || !isset($tdata['orgId'])){
+            HelpHander::error('token不正确');
+        }
+
+        $this->userId = $tdata['userId'];
+        $this->orgId = $tdata['orgId'];
+
+    }
+
+
+
+}

+ 271 - 0
application/api/controller/energy/Elector.php

@@ -0,0 +1,271 @@
+<?php
+namespace app\api\controller\energy;
+
+use app\common\model\EnergyParam;
+use app\common\util\YsUtil;
+use app\hander\HelpHander;
+use think\Controller;
+use think\Db;
+class Elector extends Base
+{
+
+    public function deviceCount(){
+
+        $count = Db::name('energy_device')
+            ->where('org_id',$this->orgId)
+            ->where('del',0)
+            ->count();
+
+        $count1 = Db::name('energy_device')
+            ->where('org_id',$this->orgId)
+            ->where('del',0)
+            ->where('status',0)
+            ->count();
+
+        $count2 = Db::name('energy_device')
+            ->where('org_id',$this->orgId)
+            ->where('del',0)
+            ->where('status',1)
+            ->count();
+
+        $count3 = Db::name('energy_alarm_event')
+            ->alias('eae')
+            ->join('energy_alarm ea','ea.id=eae.alarm_id')
+            ->where('ea.org_id',$this->orgId)
+            ->where('eae.status',1)
+            ->count();
+
+
+        $day = date('Y-m-d');
+        $kwh = (new EnergyParam())->getDegreeByDay($this->orgId,$day);
+
+        $data = [
+            'count'=>$count,
+            'count1'=>$count1,
+            'count2'=>$count2,
+            'count3'=>$count3,
+            'kwh'=>round($kwh,1),
+        ];
+        HelpHander::success($data);
+    }
+
+    public function warningList(){
+        $lists = Db::name('energy_alarm_event')
+            ->alias('eae')
+            ->field('ea.alarm_time,ea.point_id,ea.point_label,ea.alarm_type,ea.current_value,eae.status')
+            ->join('energy_alarm ea','ea.id=eae.alarm_id')
+            ->where('ea.org_id',$this->orgId)
+//            ->where('eae.status','in',[0,1])
+            ->where('eae.status','=',0)
+            ->order('eae.id desc')
+            ->limit(10)
+            ->select();
+        foreach ($lists as $k=>$v){
+            $lists[$k]['time'] = date('m-d H:i',strtotime($v['alarm_time']));
+            $lists[$k]['content'] = $v['point_id'].' '.$v['point_label'].' '.$v['alarm_type'].'-高水位告警当前值:'.$v['current_value'];
+        }
+
+        HelpHander::success($lists);
+    }
+
+    public function roomInfo(){
+       $t =  Db::name('energy_param')
+           ->alias("pa")
+           ->join("energy_device a","a.sn = pa.device_sn")
+           ->field("pa.content")
+           ->where('pa.org_id',$this->orgId)
+           ->where('a.cate',3)
+           ->order('pa.id desc')
+           ->find();
+
+        $content = isset($t['content']) && !empty($t['content']) ? json_decode($t['content'],true):[];
+
+        $temp = ['men'=>'', 'yan'=>'', 'wenshi'=>'', 'shui'=>'','shui1'=>'','monitor'=>'','monitor1'=>''];
+
+        if(isset($content['Temp']) && !empty($content['Temp'])){
+            $wen = round($content['Temp'],1).'℃/';
+            $shi = round($content['Humi'],0).'%RH';
+            $temp['wenshi'] = $wen.$shi;
+        }
+
+        $t1 =  Db::name('energy_param')
+            ->alias("pa")
+            ->join("energy_device a","a.sn = pa.device_sn")
+            ->join("energy_device_cate b","a.cate = b.id")
+            ->field("pa.content,a.*,b.title as cate_title")
+            ->where('pa.org_id',$this->orgId)
+            ->where('b.id',4)
+            ->order('pa.id desc')
+            ->find();
+        $content1 = isset($t1['content']) && !empty($t1['content']) ? json_decode($t1['content'],true):[];
+        if(isset($content1['遥信1']) && !empty($content1['遥信1'])){
+            $temp['shui'] = $content1['遥信1'] == 1?"有":"无";
+            $temp['shui1'] = $content1['遥信2'] == 1?"有":"无";
+            $temp['yan'] = $content1['遥信3'] == 1?"开":"关";
+            $temp['men'] = $content1['遥信4'] == 1?"开":"关";
+        }
+
+        $monitorList = Db::name('energy_monitor')
+            ->where('org_id',$this->orgId)
+            ->where('del',0)
+            ->where('enable',1)
+            ->order('id asc')
+            ->limit(2)
+            ->select();
+        if($monitorList){
+            $ysUtil = new YsUtil();
+            foreach ($monitorList as $k=>$v){
+                $v['url'] =  $ysUtil->getLiveUrl($v['device_sn'],$v['channel']);
+                if(isset($k) && $k==0){
+                    $temp['monitor'] =  $v;
+                }
+                if(isset($k) && $k==1){
+                    $temp['monitor1'] =  $v;
+                }
+            }
+        }
+
+        HelpHander::success($temp);
+    }
+
+    public function roomParamList(){
+
+        $lists = Db::name('energy_room')
+            ->field('id,title')
+            ->where('org_id',$this->orgId)
+            ->where('del',0)
+            ->limit(5)
+            ->select();
+
+        foreach ($lists as $k=>$v){
+            $lists[$k]['status'] = 1;
+
+            $count = 0;
+            $deviceList = Db::name('energy_device')
+                ->field('id,sn,title,cate,address_id')
+                ->where('del',0)
+                ->where('room_id',$v['id'])
+                ->where('cate',1)
+                ->group('sn')
+                ->select();
+            $lists[$k]['cate_count'] = count($deviceList);
+            $lists[$k]['cate_title'] = Db::name('energy_device_cate')->where('id',1)->value('title');
+
+            foreach ($deviceList as $kk=>$vv){
+                $deviceList[$kk]['title'] = Db::name('energy_address')->where('id',$vv['address_id'])->value('title');
+                $count +=1;
+                $paramInfo = Db::name('energy_param')
+                    ->field('id,content,status')
+                    ->where('device_sn',$vv['sn'])
+                    ->order('report_time desc,id desc')
+                    ->find();
+
+                $contents = $paramInfo ? json_decode($paramInfo['content'],true):[];
+                $ua = $ub = $uc = $switch = $s = '0.00'; //电压
+                $wa = $wb = $wc = '32'; //温度
+                $bl = '1'; //占比
+
+                if(isset($contents['EPI'])){
+                    $ua = isset($contents['Ua']) ? $contents['Ua'] :'0.00';
+                    $ub = isset($contents['Ub']) ? $contents['Ub'] :'0.00';
+                    $uc =  isset($contents['Uc']) ? $contents['Uc'] :'0.00';
+                    $s =  isset($contents['S']) ? $contents['S'] :'0.00';
+
+                    if(isset($contents['Switch']) && $contents['Switch'] == '1'){
+                        $switch = '合闸';
+                    }else{
+                        $switch = '分闸';
+                    }
+                }
+
+                if(!empty($paramInfo['status']) && $paramInfo['status'] == 0){
+                    $statusTxt = '离线';
+                }elseif(!empty($paramInfo['status']) && $paramInfo['status'] == 1){
+                    $statusTxt = '在线';
+                }else{
+                    $statusTxt = '';
+                }
+
+
+                $deviceList[$kk]['status_txt'] = $statusTxt;
+                $deviceList[$kk]['ua'] = round($ua,1);
+                $deviceList[$kk]['ub'] = round($ub,1);
+                $deviceList[$kk]['uc'] = round($uc,1);
+                $deviceList[$kk]['switch'] = $switch;
+                $deviceList[$kk]['wa'] = round($wa,1);
+                $deviceList[$kk]['wb'] = round($wb,1);
+                $deviceList[$kk]['wc'] = round($wc,1);
+                $deviceList[$kk]['bl'] = $bl;
+                $deviceList[$kk]['s'] = round($s,1);
+            }
+            $lists[$k]['list'] = $deviceList;
+
+
+
+            $deviceList1 = Db::name('energy_device')
+                ->field('id,sn,title,cate,address_id')
+                ->where('del',0)
+                ->where('room_id',$v['id'])
+                ->where('cate',5)
+                ->group('sn')
+                ->select();
+
+            $lists[$k]['cate_count5'] = count($deviceList1);
+            $lists[$k]['cate_title5'] = Db::name('energy_device_cate')->where('id',5)->value('title');
+
+            foreach ($deviceList1 as $kkk=>$vvv){
+                $deviceList1[$kkk]['title'] = Db::name('energy_address')->where('id',$vvv['address_id'])->value('title');
+                $count +=1;
+                $paramInfo1 = Db::name('energy_param')
+                    ->field('id,content,status')
+                    ->where('device_sn',$vvv['sn'])
+                    ->order('report_time desc,id desc')
+                    ->find();
+
+
+                $contents1 = $paramInfo1 ? json_decode($paramInfo1['content'],true):[];
+                $ua1 = $ub1 = $uc1 = $switch1 = $s1 ='0.00'; //电压
+                $wa1 = $wb1 = $wc1 = '32'; //温度
+                $bl1 = '1'; //占比
+
+                if(isset($contents1['EPI'])){
+                    $ua1 = isset($contents1['Ua']) ? $contents1['Ua'] :'0.00';
+                    $ub1 = isset($contents1['Ub']) ? $contents1['Ub'] :'0.00';
+                    $uc1 =  isset($contents1['Uc']) ? $contents1['Uc'] :'0.00';
+                    $s1 =  isset($contents1['S']) ? $contents1['S'] :'0.00';
+
+                    if(isset($contents1['Switch']) && $contents1['Switch'] == '1'){
+                        $switch1 = '合闸';
+                    }else{
+                        $switch1 = '分闸';
+                    }
+                }
+
+                if(!empty($paramInfo1['status']) && $paramInfo1['status'] == 0){
+                    $statusTxt1 = '离线';
+                }elseif(!empty($paramInfo1['status']) && $paramInfo1['status'] == 1){
+                    $statusTxt1 = '在线';
+                }else{
+                    $statusTxt1 = '';
+                }
+
+
+                $deviceList1[$kkk]['status_txt'] = $statusTxt1;
+                $deviceList1[$kkk]['ua'] = round($ua1,1);
+                $deviceList1[$kkk]['ub'] = round($ub1,1);
+                $deviceList1[$kkk]['uc'] = round($uc1,1);
+                $deviceList1[$kkk]['switch'] = $switch1;
+                $deviceList1[$kkk]['wa'] = round($wa1,1);
+                $deviceList1[$kkk]['wb'] = round($wb1,1);
+                $deviceList1[$kkk]['wc'] = round($wc1,1);
+                $deviceList1[$kkk]['bl'] = $bl1;
+                $deviceList1[$kkk]['s'] = round($s1,1);
+            }
+            $lists[$k]['list1'] = $deviceList1;
+
+            $lists[$k]['count'] = $count;
+        }
+        HelpHander::success($lists);
+    }
+
+}

+ 496 - 0
application/api/controller/energy/Energy.php

@@ -0,0 +1,496 @@
+<?php
+namespace app\api\controller\energy;
+
+use app\hander\HelpHander;
+use think\Controller;
+use think\Db;
+class Energy extends Base
+{
+
+    public function energyCount(){
+
+        $addr = input('addr','');
+        $ssmap = [];
+        if($addr !=''){
+            $ids = $this->addrSubIds($addr);
+            $map[] = ['ed.room_id','in',$ids];
+            $ssmap[] = ['room_id','in',$ids];
+        }
+        $map[] = ['ed.del','=',1];
+        $map[] = ['ed.cate','=',1];
+        $map[] = ['ed.org_id','=',$this->orgId];
+        $map1[] = ['ep.report_time','>=',date('Y-m-d').' 00:00:00'];
+        $map1[] = ['ep.report_time','<=',date('Y-m-d').' 23:59:59'];
+
+        $map2[] = ['ep.report_time','>=',date('Y-m-d',strtotime('-1 day')).' 00:00:00'];
+        $map2[] = ['ep.report_time','<=',date('Y-m-d',strtotime('-1 day')).' 23:59:59'];
+
+        $lists = Db::name('energy_param')
+            ->alias('ep')
+            ->join('energy_device ed','ep.device_sn = ed.sn')
+            ->where($map)
+            ->where($map1)
+            ->field('ep.device_sn,max(ep.degree) as degree')
+            ->group('ep.device_sn')
+            ->order('ep.report_time desc')
+            ->select();
+        $count = 0;
+        foreach ($lists as $k=>$v){
+            $count += $v['degree'];
+        }
+
+        $lists2 = Db::name('energy_param')
+            ->alias('ep')
+            ->join('energy_device ed','ep.device_sn = ed.sn')
+            ->where($map)
+            ->where($map2)
+            ->field('ep.device_sn,max(ep.degree) as degree')
+            ->group('ep.device_sn')
+            ->order('ep.report_time desc')
+            ->select();
+        $count1 = 0;
+        foreach ($lists2 as $k=>$v){
+            $count1 += $v['degree'];
+        }
+
+
+        $power = 0;
+        $devices = Db::name('energy_device')
+            ->where('org_id',$this->orgId)
+            ->where('cate',5)
+            ->where($ssmap)
+            ->where('del',0)
+            ->select();
+        foreach ($devices as $k=>$v){
+            $info = Db::name('energy_param')->where('device_sn',$v['sn'])->where('org_id',$this->orgId)->order('report_time desc')->find();
+            if($info){
+                $content = json_decode($info['content'],true);
+                if(isset($content['P'])){
+                    $power += $content['P'];
+                }
+            }
+        }
+
+
+        $zongList = Db::name('energy_param')
+            ->alias('ep')
+            ->join('energy_device ed','ep.device_sn = ed.sn')
+            ->where($map)
+            ->field('ep.device_sn,max(ep.degree) as degree')
+            ->group('ep.device_sn')
+            ->order('ep.report_time desc')
+            ->select();
+        $zongNum = 0;
+        foreach ($zongList as $k=>$v){
+            $zongNum += $v['degree'];
+        }
+        $pfm = 85000; //面积(m2)
+        $bzm = round($zongNum/8137*1000/$pfm,2);
+        //用电量折算标准煤:1.229(t/万KWh) 1万千瓦时=1.229吨标煤;8137千瓦时=1吨标煤
+
+        //1千瓦时的二氧化碳排放量约为960克。
+        $co2 = round($zongNum*0.96/85000,2);
+
+        $data = [
+            'count'=>round($count,2),
+            'count1'=>round($count1,2),
+            'num'=>round($power,2),
+            'num1'=>$bzm,
+            'num2'=>$co2,
+        ];
+
+        HelpHander::success($data);
+
+    }
+
+
+    public function addrList(){
+
+        $lists = Db::name('energy_address')
+            ->where('pid',0)
+            ->where('org_id',$this->orgId)
+            ->where('del',0)
+            ->where('enable',1)
+            ->select();
+        HelpHander::success($lists);
+
+    }
+
+
+    public function addrSubIds($id){
+
+        $lists = Db::name('energy_address')
+            ->where('pid',$id)
+            ->where('org_id',$this->orgId)
+            ->where('del',0)
+            ->where('enable',1)
+            ->select();
+        $ids = [];
+        foreach ($lists as $k=>$v){
+            $ids[] = Db::name('energy_address')
+                ->where('pid',$v['id'])
+                ->where('org_id',$this->orgId)
+                ->where('del',0)
+                ->where('enable',1)
+                ->column('id');
+        }
+        $aids = [];
+        foreach ($ids as $k=>$v){
+            foreach ($v as $kk=>$vv){
+                $aids[] = $vv;
+            }
+        }
+        return $aids;
+    }
+
+    public function addrElectricityList(){
+        $lists = Db::name('energy_address')
+            ->where('pid',0)
+            ->where('org_id',$this->orgId)
+            ->where('del',0)
+            ->where('enable',1)
+            ->order('id desc')
+            ->limit(8)
+            ->select();
+
+        $map[] = ['ed.del','=',1];
+        $map[] = ['ed.org_id','=',$this->orgId];
+        $map1[] = ['ep.report_time','>=',date('Y-m-d').' 00:00:00'];
+        $map1[] = ['ep.report_time','<=',date('Y-m-d').' 23:59:59'];
+        $data = [];
+        foreach ($lists as $k=>$v){
+            $ids = $this->addrSubIds($v['id']);
+            $value =  Db::name('energy_device')
+                ->alias('ed')
+                ->join('energy_param ep','ep.device_sn=ed.sn')
+                ->where('ed.room_id','in',$ids)
+                ->where($map)
+                ->where($map1)
+                ->sum('degree');
+            $data[$k]['name'] = $v['title'];
+            $data[$k]['value'] = $value;
+        }
+        HelpHander::success($data);
+    }
+
+    public function timesList(){
+        $x = $y = $y1 = [];
+        $list = [];
+        for ($i=1;$i<=24;$i++){
+            $x[] = $i;
+            $t= $i-1;
+            if($i < 10){
+              $i = '0'.$i;
+            }
+            if($t < 10){
+                $t = '0'.$i;
+            }
+            $list[$i-1]['st'] = date('Y-m-d').' '.$t.'00:00';
+            $list[$i-1]['et'] = date('Y-m-d').' '.$i.'00:00';
+        }
+
+        foreach ($list as $k=>$v){
+            $jin = Db::name('energy_param')
+                ->where('org_id',$this->orgId)
+                ->where('report_time','>=',$v['st'])
+                ->where('report_time','<=',$v['et'])
+                ->sum('degree');
+            $y[] = round($jin,1);
+
+            $zuo = Db::name('energy_param')
+                ->where('org_id',$this->orgId)
+                ->where('report_time','>=',date('Y-m-d H:i:s',strtotime($v['st'])-86400))
+                ->where('report_time','<=',date('Y-m-d H:i:s',strtotime($v['et'])-86400))
+                ->sum('degree');
+            $y1[] = round($zuo,1);
+        }
+        $data =[
+            'x'=>$x,
+            'y'=>$y,
+            'y1'=>$y1
+        ];
+
+        HelpHander::success($data);
+
+    }
+
+    public function deviceList(){
+
+        $lists = Db::name('energy_device')
+            ->where('org_id',$this->orgId)
+            ->where('del',0)
+            ->limit(6)
+            ->select();
+        $x = $y = [];
+        foreach ($lists as $k=>$v){
+            $x[] = $v['title'];
+            $degree = Db::name('energy_param')
+                ->where('device_sn',$v['sn'])
+                ->where('org_id',$this->orgId)
+                ->where('report_time','>=',date('Y-m-d').' 00:00:00')
+                ->where('report_time','<=',date('Y-m-d').' 23:59:59')
+                ->sum('degree');
+
+            $y[] = round($degree,1);
+        }
+        $data = [
+            'x'=>$x,
+            'y'=>$y
+        ];
+        HelpHander::success($data);
+    }
+
+    //电耗报表
+    public function meterList(){
+        $date = input('date','');
+        $deviceName = input('deviceName');
+
+        if($deviceName !=''){
+            $map[] = ['ed.title','like','%'.$deviceName.'%'];
+        }
+        $where = [];
+        if($date !=''){
+            $st = $date[0];
+            $et = $date[1];
+            $where[] = ['report_time','>=',date('Y-m-d H:i:s',strtotime($st))];
+            $where[] = ['report_time','<=',date('Y-m-d H:i:s',strtotime($et))];
+        }
+        $map[] = ['ed.org_id','=',$this->orgId];
+        $map[] = ['ed.del','=',0];
+        $map[] = ['ed.protocol','=',1];
+        $map[] = ['ed.cate','in',[1,2,5]];
+
+//        $list =  Db::name('energy_device')
+//            ->alias('ed')
+//            ->field('ed.*,er.title as room')
+//            ->join('energy_room er','er.id=ed.room_id')
+//            ->where($map)
+//            ->order('ed.id desc')
+//            ->limit(50)
+//            ->select();
+
+        $list =  Db::name('energy_device')
+            ->alias('ed')
+            ->field('ed.*,ea.title as address')
+            ->join('energy_address ea','ea.id=ed.address_id')
+            ->where($map)
+            ->order('ed.id desc')
+            ->limit(30)
+            ->select();
+
+        $data = [];
+        foreach ($list as $k=>$v){
+//            $address = Db::name('energy_address')->where('id',$v['address_id'])->value('title');
+            $paramList = Db::name('energy_param')
+                ->field('content')
+                ->where('device_sn',$v['sn'])
+                ->where('org_id',$this->orgId)
+                ->where($where)
+                ->select();
+            $EPIF = $EPIJ = $EPIP = $EPIG = 0;
+            foreach ($paramList as $kk=>$vv){
+                $content = json_decode($vv['content'],true);
+                if(isset($content['EPIF'])){
+                    $EPIF += round($content['EPIF'],1);
+                    $EPIJ += round($content['EPIJ'],1);
+                    $EPIP += round($content['EPIP'],1);
+                    $EPIG += round($content['EPIG'],1);
+                }
+            }
+
+            $zong = $EPIF+$EPIJ+$EPIP+$EPIG;
+
+            $data[] =[
+//                'room'=>$v['room'],
+//                'address'=>$address,
+                'address'=>$v['address'],
+                'device'=>$v['title'],
+                'jian'=>round($EPIF,1),
+                'feng'=> round($EPIJ,1),
+                'ping'=>round($EPIP,1),
+                'gu'=>round($EPIG,1),
+                'count'=>round($zong,1),
+                'total_price'=>round($zong*0.5,1),
+            ];
+
+        }
+        $data = list_sort_by($data,'ping','desc');
+
+
+        $columns = [
+//            ["title" => "房间","key" => "room"],
+            ["title" => "地点","key" => "address"],
+            ["title" => "设备","key" => "device"],
+            ["title" => "尖用量(kWh)","key" => "jian"],
+            ["title" => "峰用量(kWh)","key" => "feng"],
+            ["title" => "平用量(kWh)","key" => "ping"],
+            ["title" => "谷用量(kWh)","key" => "gu"],
+            ["title" => "总用量(kWh)","key" => "count"],
+            ["title" => "总费用(元)","key" => "totalPrice"],
+        ];
+        $dt = [
+            'columns'=>$columns,
+            'list'=>$data
+        ];
+
+        HelpHander::success($dt);
+    }
+    //抄表明细表
+    public function meterReadingList(){
+        $page = input('page',1);
+        $size = input('size',6);
+        $date = input('date','');
+        $deviceName = input('deviceName');
+
+        if($deviceName !=''){
+            $map[] = ['title','like','%'.$deviceName.'%'];
+        }
+        $where = [];
+        if($date !=''){
+            $st = $date[0];
+            $et = $date[1];
+            $where[] = ['report_time','>=',date('Y-m-d H:i:s',strtotime($st))];
+            $where[] = ['report_time','<=',date('Y-m-d H:i:s',strtotime($et))];
+        }
+        $map[] = ['org_id','=',$this->orgId];
+        $map[] = ['del','=',0];
+        $map[] = ['cate','=',1];
+        $list =  Db::name('energy_device')
+            ->field('id,title,sn,address_id')
+            ->where($map)
+            ->order('id desc')
+            ->page($page,$size)
+            ->select();
+
+        foreach ($list as $k=>$v){
+            $list[$k]['address'] = Db::name('energy_address')->where('id',$v['address_id'])->value('title');
+
+            $sinfo = Db::name('energy_param')
+                ->where('device_sn',$v['sn'])
+                ->where($where)
+                ->where('org_id',$this->orgId)
+                ->where('report_time','<>','')
+                ->where('report_time','<>',null)
+                ->order('report_time asc')
+                ->find();
+
+            $einfo = Db::name('energy_param')
+                ->where('device_sn',$v['sn'])
+                ->where($where)
+                ->where('org_id',$this->orgId)
+                ->where('report_time','<>','')
+                ->where('report_time','<>',null)
+                ->order('report_time desc')
+                ->find();
+            $list[$k]['st'] = '';
+            $list[$k]['et'] = '';
+            $list[$k]['snum'] = 0;
+            $list[$k]['enum'] = 0;
+            $list[$k]['yl'] = 0;
+            $snum = $enum = 0;
+            if($sinfo){
+                $list[$k]['st'] = $sinfo['report_time']?date('Y-m-d H:i',strtotime($sinfo['report_time'])):'';
+                $list[$k]['snum'] = $snum = round($sinfo['degree'],1);
+            }
+
+            if($einfo){
+                $list[$k]['et'] = $einfo['report_time']?date('Y-m-d H:i',strtotime($einfo['report_time'])):'';
+                $list[$k]['enum']  = $enum = round($einfo['degree'],1);
+            }
+            $list[$k]['yl'] = round($enum-$snum,1);
+        }
+        $total = Db::name('energy_device')
+            ->where($map)
+            ->count();
+
+        $data = [
+            'total'=>$total,
+            'list'=>$list
+        ];
+
+        HelpHander::success($data);
+    }
+
+    public function meterReadingListExport(){
+        $ids = input('ids','');
+        $date = input('date','');
+        $deviceName = input('deviceName');
+
+        if($deviceName !=''){
+            $map[] = ['title','like','%'.$deviceName.'%'];
+        }
+        $where = [];
+        if($date !=''){
+            $st = $date[0];
+            $et = $date[1];
+            $where[] = ['report_time','>=',date('Y-m-d H:i:s',strtotime($st))];
+            $where[] = ['report_time','<=',date('Y-m-d H:i:s',strtotime($et))];
+        }
+        if($ids){
+            $map[] = ['id','in',explode(',',$ids)];
+        }
+        $map[] = ['org_id','=',$this->orgId];
+        $map[] = ['del','=',0];
+        $map[] = ['cate','=',1];
+        $list =  Db::name('energy_device')
+            ->field('id,title,sn,address_id')
+            ->where($map)
+            ->order('id desc')
+            ->select();
+
+        foreach ($list as $k=>$v){
+            $list[$k]['address'] = Db::name('energy_address')->where('id',$v['address_id'])->value('title');
+            $sinfo = Db::name('energy_param')
+                ->where('device_sn',$v['sn'])
+                ->where($where)
+                ->where('org_id',$this->orgId)
+                ->where('report_time','<>','')
+                ->where('report_time','<>',null)
+                ->order('report_time asc')
+                ->find();
+
+            $einfo = Db::name('energy_param')
+                ->where('device_sn',$v['sn'])
+                ->where($where)
+                ->where('org_id',$this->orgId)
+                ->where('report_time','<>','')
+                ->where('report_time','<>',null)
+                ->order('report_time desc')
+                ->find();
+            $list[$k]['st'] = '';
+            $list[$k]['et'] = '';
+            $list[$k]['snum'] = 0;
+            $list[$k]['enum'] = 0;
+            $list[$k]['yl'] = 0;
+            $snum = $enum = 0;
+            if($sinfo){
+                $list[$k]['st'] = $sinfo['report_time']?date('Y-m-d H:i',strtotime($sinfo['report_time'])):'';
+                $list[$k]['snum'] = $snum = round($sinfo['degree'],1);
+            }
+
+            if($einfo){
+                $list[$k]['et'] = $einfo['report_time']? date('Y-m-d H:i',strtotime($einfo['report_time'])):'';
+                $list[$k]['enum']  = $enum = round($einfo['degree'],1);
+            }
+            $list[$k]['yl'] = round($enum-$snum,1);
+        }
+
+        $columns = [
+            ["title" => "设备id","key" => "id"],
+            ["title" => "地点","key" => "address"],
+            ["title" => "设备名称","key" => "title"],
+            ["title" => "起始时间","key" => "st"],
+            ["title" => "终止时间","key" => "snum"],
+            ["title" => "起始读数","key" => "et"],
+            ["title" => "终止读数","key" => "enum"],
+            ["title" => "用量","key" => "yl"],
+        ];
+        $dt = [
+            'columns'=>$columns,
+            'list'=>$list
+        ];
+
+        HelpHander::success($dt);
+    }
+
+}

+ 26 - 0
application/api/controller/energy/Index.php

@@ -0,0 +1,26 @@
+<?php
+namespace app\api\controller\energy;
+
+use app\hander\HelpHander;
+use think\Controller;
+use think\Db;
+class Index extends Base
+{
+    public function userInfo(){
+
+        $info = Db::name('user')
+            ->field('id,real_name,head_image')
+            ->where('id',$this->userId)
+            ->where('del',0)
+            ->where('enable',1)
+            ->find();
+        if(!$info){
+            HelpHander::error('用户信息不存在');
+        }
+        $info['org_name'] = Db::name('org')->where('id',$this->orgId)->value('name');
+
+        HelpHander::success($info);
+    }
+
+
+}

+ 603 - 0
application/api/controller/energy/Warning.php

@@ -0,0 +1,603 @@
+<?php
+namespace app\api\controller\energy;
+
+use app\hander\HelpHander;
+use think\Controller;
+use think\Db;
+class Warning extends Base
+{
+    public function warningCount(){
+        $type = input('type','');
+
+        if($type == 1){
+            $map[] = ['eae.create_time','>=',date('Y-m-d').' 00:00:00'];
+            $map[] = ['eae.create_time','<=',date('Y-m-d').' 23:59:59'];
+        }elseif ($type == 2){
+            $map[] = ['eae.create_time','>=',date('Y-m').'-01 00:00:00'];
+            $map[] = ['eae.create_time','<=',date('Y-m').'-31 23:59:59'];
+        }elseif($type == 3){
+            $map[] = ['eae.create_time','>=',date('Y').'-01-01 00:00:00'];
+            $map[] = ['eae.create_time','<=',date('Y').'-12-31 23:59:59'];
+        }
+        $map[] = ['ea.org_id','=',$this->orgId];
+
+        $list = [
+            ['name'=>'严重警告','type'=>'高限报警'],
+            ['name'=>'一般警告','type'=>'低限报警'],
+        ];
+        $total = 0;
+        foreach ($list as $k=>$v){
+            $value = Db::name('energy_alarm_event')
+                ->alias('eae')
+                ->join('energy_alarm ea','ea.id=eae.alarm_id')
+                ->where('ea.alarm_type',$v['type'])
+                ->where($map)
+                ->count();
+
+            $total +=$value;
+            $list[$k]['value'] = $value;
+        }
+        $data = [
+            'total'=>$total,
+            'list'=>$list
+        ];
+
+        HelpHander::success($data);
+    }
+
+    public function typeList(){
+        $type = input('type','');
+
+        if($type == 1){
+            $map[] = ['eae.create_time','>=',date('Y-m-d').' 00:00:00'];
+            $map[] = ['eae.create_time','<=',date('Y-m-d').' 23:59:59'];
+        }elseif ($type == 2){
+            $map[] = ['eae.create_time','>=',date('Y-m').'-01 00:00:00'];
+            $map[] = ['eae.create_time','<=',date('Y-m').'-31 23:59:59'];
+        }elseif($type == 3){
+            $map[] = ['eae.create_time','>=',date('Y').'-01-01 00:00:00'];
+            $map[] = ['eae.create_time','<=',date('Y').'-12-31 23:59:59'];
+        }
+        $map[] = ['ea.org_id','=',$this->orgId];
+
+        $list = [
+            ['name'=>'严重警告','type'=>'高限报警'],
+            ['name'=>'一般警告','type'=>'低限报警'],
+        ];
+        $x = $y = [];
+        foreach ($list as $k=>$v){
+            $value = Db::name('energy_alarm_event')
+                ->alias('eae')
+                ->join('energy_alarm ea','ea.id=eae.alarm_id')
+                ->where('ea.alarm_type',$v['type'])
+                ->where($map)
+                ->count();
+            $x[] = $v['name'];
+            $y[] = $value;
+        }
+        HelpHander::success(['x'=>$x,'y'=>$y]);
+
+    }
+
+    public function timeTrend(){
+
+        $x = $y = $y1 = [];
+        $list = [];
+        for ($i=1;$i<=24;$i++){
+            $x[] = $i;
+            $t= $i-1;
+            if($i < 10){
+                $i = '0'.$i;
+            }
+            if($t < 10){
+                $t = '0'.$i;
+            }
+            $list[$i-1]['st'] = date('Y-m-d').' '.$t.'00:00';
+            $list[$i-1]['et'] = date('Y-m-d').' '.$i.'00:00';
+        }
+
+        foreach ($list as $k=>$v){
+            $jin = Db::name('energy_alarm_event')
+                ->alias('eae')
+                ->join('energy_alarm ea','ea.id=eae.alarm_id')
+                ->where('ea.org_id',$this->orgId)
+                ->where('eae.create_time','>=',$v['st'])
+                ->where('eae.create_time','<=',$v['et'])
+                ->count();
+            $y[] = $jin;
+
+            $zuo = Db::name('energy_alarm_event')
+                ->alias('eae')
+                ->join('energy_alarm ea','ea.id=eae.alarm_id')
+                ->where('ea.org_id',$this->orgId)
+                ->where('eae.create_time','>=',date('Y-m-d H:i:s',strtotime($v['st'])-86400))
+                ->where('eae.create_time','<=',date('Y-m-d H:i:s',strtotime($v['et'])-86400))
+                ->count();
+            $y1[] = $zuo;
+        }
+        $data =[
+            'x'=>$x,
+            'y'=>$y,
+            'y1'=>$y1
+        ];
+
+        HelpHander::success($data);
+    }
+
+    public function deviceRanking(){
+
+        $list = Db::name('energy_device')
+            ->field('id,title,sn')
+            ->where('org_id',$this->orgId)
+            ->where('del',0)
+            ->where('cate',5)
+            ->limit(6)
+            ->select();
+        $total = 0;
+        foreach ($list as $k=>$v){
+            $value = Db::name('energy_alarm_event')
+                ->alias('eae')
+                ->join('energy_alarm ea','ea.id=eae.alarm_id')
+                ->where('ea.device_sn',$v['sn'])
+                ->where('org_id',$this->orgId)
+                ->count();
+            $total +=$value;
+            $list[$k]['value'] = $value;
+        }
+        if($list){
+            foreach ($list as $k=>$v){
+                $list[$k]['bl'] = 0;
+                if($total > 0){
+                    $list[$k]['bl'] = round($v['value']/$total*100,0);
+                }
+            }
+        }
+        $newList =  list_sort_by($list,'value','desc');
+
+        $data = [
+            'top1'=>isset($newList[0])&&!empty($newList[0]) ? $newList[0]:'',
+            'top2'=>isset($newList[1])&&!empty($newList[1]) ? $newList[1]:'',
+            'top3'=>isset($newList[2])&&!empty($newList[2]) ? $newList[2]:'',
+            'top4'=>isset($newList[3])&&!empty($newList[3]) ? $newList[3]:'',
+            'top5'=>isset($newList[4])&&!empty($newList[4]) ? $newList[4]:'',
+            'top6'=>isset($newList[5])&&!empty($newList[5]) ? $newList[5]:'',
+        ];
+
+        HelpHander::success($data);
+    }
+
+    public function roomList(){
+
+        $list = Db::name('energy_room')
+            ->where('org_id',$this->orgId)
+            ->where('del',0)
+            ->limit(5)
+            ->select();
+        $x = $y = [];
+        foreach ($list as $k=>$v){
+            $y[] = Db::name('energy_alarm_event')
+                ->alias('eae')
+                ->join('energy_alarm ea','ea.id=eae.alarm_id')
+                ->join('energy_device ed','ed.sn=ea.device_sn')
+                ->where('ed.room_id',$v['id'])
+                ->where('ea.org_id',$this->orgId)
+                ->where('ed.del',0)
+                ->count();
+
+            $x[] = $v['title'];
+        }
+        HelpHander::success(['x'=>$x,'y'=>$y]);
+    }
+    //当前告警
+    public function warningInfoList(){
+        $num = Db::name('energy_alarm_event')
+            ->alias('eae')
+            ->join('energy_alarm ea','ea.id=eae.alarm_id')
+            ->where('ea.org_id',$this->orgId)
+            ->where('ea.alarm_type','高限报警')
+            ->where('eae.status',0)
+            ->count();
+
+        $num1 = Db::name('energy_alarm_event')
+            ->alias('eae')
+            ->join('energy_alarm ea','ea.id=eae.alarm_id')
+            ->where('ea.org_id',$this->orgId)
+            ->where('ea.alarm_type','低限报警')
+            ->where('eae.status',0)
+            ->count();
+
+        $count = $num + $num1;
+
+        $list  = Db::name('energy_alarm_event')
+            ->alias('eae')
+            ->field('ea.*,eae.create_time as waring_time')
+            ->join('energy_alarm ea','ea.id=eae.alarm_id')
+            ->where('ea.org_id',$this->orgId)
+            ->where('ea.alarm_type','in',['低限报警','高限报警'])
+            ->where('eae.status','=',0)
+            ->select();
+
+        foreach ($list as $k=>$v){
+            $device = Db::name('energy_device')
+                ->where('sn',$v['device_sn'])
+                ->find();
+            $room = '';
+            if($device){
+                $room = Db::name('energy_room')
+                    ->where('id',$device['room_id'])
+                    ->value('title');
+            }
+            $content = $v['point_label'].$v['alarm_type'];
+            $list[$k]['room'] = $room;
+            $list[$k]['device'] = $device ? $device['title']:'';
+            $list[$k]['infos'] = $content;
+        }
+
+        $data = [
+            'countinfo'=>[
+                'count'=>$count,
+                'num'=>$num,
+                'num1'=>$num1
+            ],
+            'list'=>$list
+        ];
+
+        HelpHander::success($data);
+
+    }
+    //事件记录
+    public function eventRecord(){
+        $page = input('page',1);
+        $size = input('size',10);
+        $date = input('date','');
+
+        $roomId = input('roomId','');
+        $cate = input('cate','');
+        $type = input('type','');
+        $deviceName = input('deviceName','');
+
+        if($date){
+            $st = $date[0];
+            $et = $date[1];
+            $map[] = ['alarm_time','>=',$st.' 00:00:00'];
+            $map[] = ['alarm_time','<=',$et.' 23:59:59'];
+        }
+        $map[] = ['org_id','=',$this->orgId];
+
+        if($roomId !=''){
+            $rsns = Db::name('energy_device')->where('room_id',$roomId)->column('sn');
+            $map[] = ['device_sn','in',$rsns];
+        }
+        if($cate !=''){
+            $rsns = Db::name('energy_device')->where('cate',$cate)->column('sn');
+            $map[] = ['device_sn','in',$rsns];
+        }
+
+        if($type !=''){
+            $map[] = ['alarm_type','=',$type];
+        }
+        if($deviceName !=''){
+            $rsns = Db::name('energy_device')->where('title','like','%'.$deviceName.'%')->column('sn');
+            $map[] = ['device_sn','in',$rsns];
+        }
+
+        $lists = Db::name('energy_alarm')
+            ->where($map)
+            ->order('id desc')
+            ->page($page,$size)
+            ->select();
+
+        foreach ($lists as $k=>$v){
+            $deviceInfo = Db::name('energy_device')
+                ->where('sn',$v['device_sn'])
+                ->find();
+            $cate = $room = '';
+            if($deviceInfo){
+                $cate = Db::name('energy_device_cate')
+                    ->where('id',$deviceInfo['cate'])
+                    ->value('title');
+                $room = Db::name('energy_room')
+                    ->where('id',$v['room_id'])
+                    ->value('title');
+            }
+            $content = $v['point_label'].$v['alarm_type'];
+            $lists[$k]['room'] = $room;
+            $lists[$k]['cate'] = $cate;
+            $lists[$k]['device'] = $deviceInfo ?$deviceInfo['title']:'';
+            $lists[$k]['content'] = $content;
+        }
+
+        $total = Db::name('energy_alarm')
+            ->where($map)
+            ->count();
+        $data = [
+            'total'=>$total,
+            'list'=>$lists
+        ];
+        HelpHander::success($data);
+    }
+
+    public function eventRecordExport(){
+        $ids = input('ids','');
+        $date = input('date','');
+        $roomId = input('roomId','');
+        $cate = input('cate','');
+        $type = input('type','');
+        $deviceName = input('deviceName','');
+
+        if($date){
+            $st = $date[0];
+            $et = $date[1];
+            $map[] = ['alarm_time','>=',$st.' 00:00:00'];
+            $map[] = ['alarm_time','<=',$et.' 23:59:59'];
+        }
+        if($ids){
+            $map[] = ['id','in',explode(',',$ids)];
+        }
+
+        $map[] = ['org_id','=',$this->orgId];
+
+        if($roomId !=''){
+            $rsns = Db::name('energy_device')->where('room_id',$roomId)->column('sn');
+            $map[] = ['device_sn','in',$rsns];
+        }
+        if($cate !=''){
+            $rsns = Db::name('energy_device')->where('cate',$cate)->column('sn');
+            $map[] = ['device_sn','in',$rsns];
+        }
+
+        if($type !=''){
+            $map[] = ['alarm_type','=',$type];
+        }
+        if($deviceName !=''){
+            $rsns = Db::name('energy_device')->where('title','like','%'.$deviceName.'%')->column('sn');
+            $map[] = ['device_sn','in',$rsns];
+        }
+
+        $lists = Db::name('energy_alarm')
+            ->where($map)
+            ->order('id desc')
+            ->select();
+
+        foreach ($lists as $k=>$v){
+            $deviceInfo = Db::name('energy_device')
+                ->where('sn',$v['device_sn'])
+                ->find();
+            $cate = $room = '';
+            if($deviceInfo){
+                $cate = Db::name('energy_device_cate')
+                    ->where('id',$deviceInfo['cate'])
+                    ->value('title');
+                $room = Db::name('energy_room')
+                    ->where('id',$v['room_id'])
+                    ->value('title');
+            }
+            $content = $v['point_label'].$v['alarm_type'];
+            $lists[$k]['room'] = $room;
+            $lists[$k]['cate'] = $cate;
+            $lists[$k]['device'] = $deviceInfo ?$deviceInfo['title']:'';
+            $lists[$k]['content'] = $content;
+        }
+
+        $columns = [
+            ["title" => "房间","key" => "room"],
+            ["title" => "设备名称","key" => "device"],
+            ["title" => "设备类型","key" => "cate"],
+            ["title" => "事件信息","key" => "content"],
+            ["title" => "发生时间","key" => "alarmTime"],
+        ];
+        $dt = [
+            'columns'=>$columns,
+            'list'=>$lists
+        ];
+        HelpHander::success($dt);
+    }
+
+
+    public function htoricalAlarms(){
+        $page = input('page',1);
+        $size = input('size',10);
+        $date = input('date','');
+
+        $roomId = input('roomId','');
+        $cate = input('cate','');
+        $type = input('type','');
+        $deviceName = input('deviceName','');
+
+        if($date){
+            $st = $date[0];
+            $et = $date[1];
+            $map[] = ['ea.alarm_time','>=',$st.' 00:00:00'];
+            $map[] = ['ea.alarm_time','<=',$et.' 23:59:59'];
+        }
+        $map[] = ['ea.org_id','=',$this->orgId];
+
+        if($roomId !=''){
+            $rsns = Db::name('energy_device')->where('room_id',$roomId)->column('sn');
+            $map[] = ['ea.device_sn','in',$rsns];
+        }
+        if($cate !=''){
+            $rsns = Db::name('energy_device')->where('cate',$cate)->column('sn');
+            $map[] = ['ea.device_sn','in',$rsns];
+        }
+
+        if($type !=''){
+            $map[] = ['ea.alarm_type','=',$type];
+        }
+        if($deviceName !=''){
+            $rsns = Db::name('energy_device')->where('title','like','%'.$deviceName.'%')->column('sn');
+            $map[] = ['ea.device_sn','in',$rsns];
+        }
+
+        $lists = Db::name('energy_alarm_event')
+            ->alias('eae')
+            ->field('ea.device_sn,ea.point_label,ea.alarm_type,ea.level,ea.alarm_time,eae.*')
+            ->join('energy_alarm ea','ea.id=eae.alarm_id')
+            ->where($map)
+            ->order('eae.id desc')
+            ->page($page,$size)
+            ->select();
+
+        foreach ($lists as $k=>$v){
+            $deviceInfo = Db::name('energy_device')
+                ->where('sn',$v['device_sn'])
+                ->find();
+            $cate = $room = '';
+            if($deviceInfo){
+                $cate = Db::name('energy_device_cate')
+                    ->where('id',$deviceInfo['cate'])
+                    ->value('title');
+                $room = Db::name('energy_room')
+                    ->where('id',$v['room_id'])
+                    ->value('title');
+            }
+            $content = $v['point_label'].$v['alarm_type'];
+            $lists[$k]['room'] = $room;
+            $lists[$k]['cate'] = $cate;
+            $lists[$k]['device'] = $deviceInfo ?$deviceInfo['title']:'';
+            $lists[$k]['content'] = $content;
+            $lists[$k]['deal_user_name'] = Db::name('user')->where('id',$v['deal_user'])->value('real_name');
+            $lists[$k]['is_deal_text'] = $v['is_deal'] == 1 ? '是':'否';
+            $lists[$k]['is_finish_text'] = $v['is_finish'] == 1 ? '是':'否';
+            $lists[$k]['xytime'] = round($v['xytime']/60,1).'min';
+            $lists[$k]['hftime'] = round($v['hftime']/60,1).'min';
+        }
+
+        $total = Db::name('energy_alarm_event')
+            ->alias('eae')
+            ->join('energy_alarm ea','ea.id=eae.alarm_id')
+            ->where($map)
+            ->count();
+        $data = [
+            'total'=>$total,
+            'list'=>$lists
+        ];
+        HelpHander::success($data);
+    }
+    public function htoricalAlarmsExport(){
+        $page = input('page',1);
+        $size = input('size',10);
+        $ids = input('ids','');
+
+        $date = input('date','');
+        $roomId = input('roomId','');
+        $cate = input('cate','');
+        $type = input('type','');
+        $deviceName = input('deviceName','');
+
+        if($ids){
+            $map[] = ['eae.id','in',explode(',',$ids)];
+        }
+
+        if($date){
+            $st = $date[0];
+            $et = $date[1];
+            $map[] = ['ea.alarm_time','>=',$st.' 00:00:00'];
+            $map[] = ['ea.alarm_time','<=',$et.' 23:59:59'];
+        }
+        $map[] = ['ea.org_id','=',$this->orgId];
+
+        if($roomId !=''){
+            $rsns = Db::name('energy_device')->where('room_id',$roomId)->column('sn');
+            $map[] = ['ea.device_sn','in',$rsns];
+        }
+        if($cate !=''){
+            $rsns = Db::name('energy_device')->where('cate',$cate)->column('sn');
+            $map[] = ['ea.device_sn','in',$rsns];
+        }
+
+        if($type !=''){
+            $map[] = ['ea.alarm_type','=',$type];
+        }
+        if($deviceName !=''){
+            $rsns = Db::name('energy_device')->where('title','like','%'.$deviceName.'%')->column('sn');
+            $map[] = ['ea.device_sn','in',$rsns];
+        }
+
+        $lists = Db::name('energy_alarm_event')
+            ->alias('eae')
+            ->field('ea.device_sn,ea.point_label,ea.alarm_type,ea.level,ea.alarm_time,eae.*')
+            ->join('energy_alarm ea','ea.id=eae.alarm_id')
+            ->where($map)
+            ->order('eae.id desc')
+            ->page($page,$size)
+            ->select();
+
+        foreach ($lists as $k=>$v){
+            $deviceInfo = Db::name('energy_device')
+                ->where('sn',$v['device_sn'])
+                ->find();
+            $cate = $room = '';
+            if($deviceInfo){
+                $cate = Db::name('energy_device_cate')
+                    ->where('id',$deviceInfo['cate'])
+                    ->value('title');
+                $room = Db::name('energy_room')
+                    ->where('id',$v['room_id'])
+                    ->value('title');
+            }
+            $content = $v['point_label'].$v['alarm_type'];
+            $lists[$k]['room'] = $room;
+            $lists[$k]['cate'] = $cate;
+            $lists[$k]['device'] = $deviceInfo ?$deviceInfo['title']:'';
+            $lists[$k]['content'] = $content;
+            $lists[$k]['deal_user_name'] = Db::name('user')->where('id',$v['deal_user'])->value('real_name');
+            $lists[$k]['is_deal_text'] = $v['is_deal'] == 1 ? '是':'否';
+            $lists[$k]['is_finish_text'] = $v['is_finish'] == 1 ? '是':'否';
+            $lists[$k]['xytime'] = round($v['xytime']/60,1).'min';
+            $lists[$k]['hftime'] = round($v['hftime']/60,1).'min';
+        }
+
+        $columns = [
+            ["title" => "房间","key" => "room"],
+            ["title" => "设备名称","key" => "device"],
+            ["title" => "设备类型","key" => "cate"],
+            ["title" => "告警信息","key" => "pointLabel"],
+            ["title" => "告警等级","key" => "alarmType"],
+            ["title" => "告警时间","key" => "alarmTime"],
+            ["title" => "处理时间","key" => "dealTime"],
+            ["title" => "告警解除时间","key" => "finishTime"],
+            ["title" => "处理人","key" => "dealUserName"],
+            ["title" => "响应时长","key" => "xytime"],
+            ["title" => "恢复时长","key" => "hftime"],
+            ["title" => "及时处理","key" => "isDealText"],
+            ["title" => "及时恢复","key" => "isFinishText"],
+            ["title" => "告警原因","key" => "reason"],
+        ];
+        $dt = [
+            'columns'=>$columns,
+            'list'=>$lists
+        ];
+        HelpHander::success($dt);
+
+    }
+
+
+
+
+
+
+
+    //房间列表
+    public function roomDataList(){
+        $list = Db::name('energy_room')
+            ->where('del',0)
+            ->where('org_id',$this->orgId)
+            ->select();
+        HelpHander::success($list);
+    }
+    //设备列表
+    public function deviceDataList(){
+        $list = Db::name('energy_device')
+            ->where('del',0)
+            ->where('org_id',$this->orgId)
+            ->select();
+        HelpHander::success($list);
+    }
+    //设备类型
+    public function deviceCateDataList(){
+        $list = Db::name('energy_device_cate')
+            ->select();
+        HelpHander::success($list);
+    }
+}