Browse Source

no message

wzh 5 năm trước cách đây
mục cha
commit
9e99d7a00e
1 tập tin đã thay đổi với 33 bổ sung32 xóa
  1. 33 32
      api/application/controllers/Lampcontrol.php

+ 33 - 32
api/application/controllers/Lampcontrol.php

@@ -36,45 +36,35 @@ class Lampcontrol extends Base_Controller {
         $pid_arr = $project_id;
         $timezone = $this->Project_model->get_timezone_by_projectid($project_id);
 
-        $filter = array();
+        $filter = array('L.projectid'=>$project_id);
         $network_id = $this->input->post('network_id', true);
         $section = $this->input->post('section', true);
         // $type = intval($this->input->post('type', true));
-        if (!empty($network_id)) {
-            $filter['networkid'] = $network_id;
-        }
-        if (!empty($section)) {
-            $filter['section'] = $section;
-        }
+        if (!empty($network_id)) $filter['L.networkid'] = $network_id;
+        if (!empty($section)) $filter['L.section'] = $section;
         $offline = $this->input->post('offline', true);
-        if (!empty($offline)) {
-            $filter['offline'] = $offline;
-        }
+        if (!empty($offline)) $filter['N.status'] = 0;
         $online = $this->input->post('online', true);
-        if (!empty($online)) {
-            $filter['online'] = $online;
-        }
+        if (!empty($online)) $filter['N.status'] = 1;
 
         // 分页数据
-        $page = $this->input->post('page',true);
-        $count = $this->input->post('count',true);
-        $count = empty($count) ? 16 : $count;
+        $page = intval($this->input->post('page',true));
         $page = empty($page) ? 1 : $page;
-        $filter['count'] = $count;
-        $filter['page'] = $page;
+        $count = intval($this->input->post('count',true));
+        $limit = empty($count) ? 10 : $count;
+        $offset = ($page - 1)*$count;
+
         $keyword = $this->input->post('keyword', true);
-        if (!empty($keyword)) {
-            $filter['keyword'] = $keyword;
-        }
+        if ($keyword !== '' && $keyword !== null) $filter['L.number|L.section|L.address'] = $keyword;
 
         $status = $this->input->post('status', true);
         if (!empty($status)) {
-            $filter['status'] = $status;
+            $filter['L.isfaulted'] = $status;
+            $filter['AI.stralarmtype !='] = '';
+            $filter['AI.status'] = 0;
         }
         $alarmtype = $this->input->post('alarmtype', true);
-        if (!empty($alarmtype)) {
-            $filter['alarmtype'] = $alarmtype;
-        }
+        if ($alarmtype !== '' && $alarmtype !== null) $filter['AI.alarmtype'] = $alarmtype;
         // 记录用户选择的字段
         if (!empty($field1)) {
             $fieldData = array('userid'=>$userid,'lampfield'=>$field1);
@@ -89,7 +79,8 @@ class Lampcontrol extends Base_Controller {
             }else{
                 $fields .= ",L.updatetime";
             }
-            $data['lamps'] = !empty($pid_arr) ? $this->Lamp_model->get_list_in('L.projectid', $pid_arr, $fields, $filter, $lite) : array();
+            $join = array();
+            $data['lamps'] = $this->Lamp_model->get_list_by_join($filter, $fields,$limit, $offset, $join, "L.number ASC", NUll, 'L');
         } else {
             if(empty($fields) || empty($field1)){
                 $fields = 'L.id, L.number, IFNULL(L.status,0) as status, L.isfaulted, L.address, L.lamppower, L.electricSOC, L.battvoltage, L.chargestage, L.logtime as updatetime, L.updatetime as modifytime,L.overtimes,L.boardpower,L.lighteness as light,L.projectid,L.devstatus as online,N.networkname as network_name,N.type as net_type,P.projectname as project_name,L.section,L.protocoltype as lampProtocoltype,L.loadtype,P.timezone as timezoneid,M.iccid';
@@ -99,10 +90,18 @@ class Lampcontrol extends Base_Controller {
 
             $download = intval($this->input->post('download',true));
             if (!empty($download)) {
-                unset($filter['count']);
-                unset($filter['page']);
+                $limit = null;
+                $offset = null;
             }
-            $data['lamps'] = $this->Lamp_model->get_list_in('L.projectid', $pid_arr, $fields, $filter);
+
+            $join = array();
+
+            $join[] = ['table'=>'project as P', 'cond'=>'L.projectid = P.id', 'type'=>'left'];
+            $join[] = ['table'=>'network as N', 'cond'=>'L.networkid = N.id', 'type'=>'left'];
+            $join[] = ['table'=>'msisdn as M', 'cond'=>'N.simid = M.imsi', 'type'=>'left'];
+            $join[] = ['table'=>'(select t1.* from alarm_info_log t1, (select lampid, max(updatetime) as maxtime from alarm_info_log group by lampid) t2 where t1.lampid = t2.lampid and t1.updatetime = t2.maxtime) as AI', 'cond'=>'L.id = AI.lampid', 'type'=>'left'];
+            $data['lamps'] = $this->Lamp_model->get_list_by_join($filter, $fields,$limit, $offset, $join, "L.number ASC,N.networkname ASC", NUll, 'L');
+            // $data['lamps'] = $this->Lamp_model->get_list_in('L.projectid', $pid_arr, $fields, $filter);
             // var_dump(microtime());
             $indexArr = [2=>'16',3=>'32',4=>'48',5=>'64'];
             if (empty($version)) {
@@ -402,11 +401,13 @@ class Lampcontrol extends Base_Controller {
         }
         unset($filter['page']);
         unset($filter['count']);
-        $res = !empty($pid_arr) ? $this->Lamp_model->get_total('L.projectid', $pid_arr, 'L.id', $filter) : array();
+        $res = $this->Lamp_model->get_list_by_multi_join($filter, 'count(*) total',$limit, $offset, $join, "L.number ASC,N.networkname ASC", NUll, 'L',true);
+        // $res = !empty($pid_arr) ? $this->Lamp_model->get_total('L.projectid', $pid_arr, 'L.id', $filter) : array();
         $result = !empty($pid_arr) ? $this->Lamp_model->get_total('L.projectid', $pid_arr, 'L.id') : array();
-        $data['total'] = ceil($res/$count);
+        $result = $this->Lamp_model->get_count(['projectid'=>$pid_arr]);
+        $data['total'] = ceil($res['total']/$count);
         $data['count'] = $result;
-        $data['fault'] = $res;
+        $data['fault'] = $res['total'];
         exit(json_result('0000', $this->response['0000'], $data));
     }