DESKTOP-9JTA2JJ\HP vor 5 Jahren
Ursprung
Commit
ebb25ac86e
2 geänderte Dateien mit 93 neuen und 29 gelöschten Zeilen
  1. 78 19
      api/application/controllers/Lampcontrol.php
  2. 15 10
      api/application/controllers/Syslog.php

+ 78 - 19
api/application/controllers/Lampcontrol.php

@@ -37,8 +37,8 @@ class Lampcontrol extends Base_Controller {
         $pid_arr = $project_id;
         $timezone = $this->Project_model->get_timezone_by_projectid($project_id);
 
-        // $filter = array('L.projectid'=>$project_id);
         $filter = 'L.projectid = '.$project_id;
+        $countWhere = array('projectid = '.$project_id);
         $network_id = $this->input->post('network_id', true);
         $section = $this->input->post('section', true);
         $type = intval($this->input->post('type', true));
@@ -46,28 +46,32 @@ class Lampcontrol extends Base_Controller {
         if (!empty($type) && !empty($company)) {
             
             if ($type == 2) {
-                // $filter['L.manu'] = $company;
                 $filter .= ' AND L.manu = '.$company;
+                $countWhere[] = 'manu = '.$company;
             }elseif ($type == 3) {
-                // $filter['L.supplier'] = $company;
                 $filter .= ' AND L.supplier = '.$company;
+                $countWhere[] = 'supplier = '.$company;
             }elseif ($type == 4) {
-                // $filter['L.po'] = $company;
                 $filter .= ' AND L.po = '.$company;
+                $countWhere[] = 'po = '.$company;
             }else {
-                // $filter['L.upazilla'] = $company;
-                // $filter .= ' AND L.upazilla = '.$company;
                 $filter .= ' AND P.cityid = '.$company;
             }
         }
-        // if (!empty($section)) $filter['L.section'] = $section;
-        if (!empty($section)) $filter .= ' AND L.section = "'.$section.'"';
+        if (!empty($section)) {
+            $filter .= ' AND L.section = "'.$section.'"';
+            $countWhere[] = 'section = "'.$section.'"';
+        }
         $offline = $this->input->post('offline', true);
-        // if (!empty($offline)) $filter['L.netstatus'] = 0;
-        if (!empty($offline)) $filter .= ' AND L.netstatus = 0';
+        if (!empty($offline)) {
+            $filter .= ' AND L.netstatus = 0';
+            $countWhere[] = 'netstatus = 0';
+        }
         $online = $this->input->post('online', true);
-        // if (!empty($online)) $filter['L.netstatus'] = 1;
-        if (!empty($online)) $filter .= ' AND L.netstatus= 1';
+        if (!empty($online)) {
+            $filter .= ' AND L.netstatus= 1';
+            $countWhere[] = 'netstatus = 1';
+        }
 
         // 分页数据
         $page = intval($this->input->post('page',true));
@@ -77,8 +81,10 @@ class Lampcontrol extends Base_Controller {
         $offset = ($page - 1)*$count;
 
         $keyword = $this->input->post('keyword', true);
-        // if ($keyword !== '' && $keyword !== null) $filter['L.number|L.section|L.address'] = $keyword;
-        if ($keyword !== '' && $keyword !== null) $filter .= ' AND (L.number like "%'.$keyword.'%" OR L.section like "%'.$keyword.'%" OR L.address like "%'.$keyword.'%")';
+        if ($keyword !== '' && $keyword !== null) {
+            $filter .= ' AND (L.number like "%'.$keyword.'%" OR L.section like "%'.$keyword.'%" OR L.address like "%'.$keyword.'%")';
+            $countWhere[] = '(number like "%'.$keyword.'%" OR section like "%'.$keyword.'%" OR address like "%'.$keyword.'%")';
+        }
 
         $status = $this->input->post('status', true);
         if (!empty($status)) {
@@ -362,11 +368,24 @@ class Lampcontrol extends Base_Controller {
         }
         // unset($filter['page']);
         // unset($filter['count']);
-        $data['total_data']['install_num'] = $this->Lamp_model->get_count(array('projectid'=>$project_id));
-        $data['total_data']['light_num'] = $this->Lamp_model->get_count(array('projectid'=>$project_id,'netstatus'=>1,'status'=>1));
-        $data['total_data']['online_num'] = $this->Lamp_model->get_count(array('projectid'=>$project_id,'netstatus'=>1));
-
-        $data['total_data']['fault_count'] = $this->Lamp_model->get_fault_count(array('L.projectid'=>$project_id,'L.isfaulted'=>1,'AI.status'=>0), $role, '', $userid,$project_id);
+        $countWheret1 = implode(' AND ', $countWhere);
+        $data['total_data']['install_num'] = $this->Lamp_model->get_count($countWheret1);
+        $countWheret = $countWhere;
+        $countWheret[] = 'status = 1';
+        $countWheret[] = 'netstatus = 1';
+        $countWheret1 = implode(' AND ', $countWheret);
+        $data['total_data']['light_num'] = $this->Lamp_model->get_count($countWheret1);
+        $countWheret = $countWhere;
+        $countWheret[] = 'netstatus = 1';
+        $countWheret1 = implode(' AND ', $countWhere);
+        $data['total_data']['online_num'] = $this->Lamp_model->get_count($countWheret1);
+
+        $filter2 = $filter.' AND (AI.batstatus != 0 OR AI.panelstatus != 0 OR AI.lampstatus != 0 OR AI.tempstatus != 0)';
+        $join = array();
+        $join2[] = ['table'=>'(select lampid,max(updatetime) as maxTime from warning_info_log group by lampid) as WI','cond'=>'WI.lampid = L.id','type'=>'inner'];
+        $join2[] = ['table'=>'warning_info_log as AI','cond'=>'WI.lampid = AI.lampid AND WI.maxTime = AI.updatetime','type'=>'inner'];
+        $res = $this->Lamp_model->get_list_by_multi_join($filter2, 'count(*) total',null, null, $join2, "L.number ASC", NUll, 'L',true);
+        $data['total_data']['fault_count'] = $res['total'];
         $data['total_data']['light_rate'] = empty($data['total_data']['install_num']) ? '0' : round($data['total_data']['light_num']/$data['total_data']['install_num'],4)*100;
         $data['total_data']['light_rate'] .= '%';
         $data['total_data']['online_rate'] = empty($data['total_data']['install_num']) ? '0' : round($data['total_data']['online_num']/$data['total_data']['install_num'],4)*100;
@@ -1230,6 +1249,46 @@ class Lampcontrol extends Base_Controller {
         }
     }
 
+    // 新控制器更新蓄电池设置
+    public function modbus_set_battery(){
+        $data['username'] = $this->input->post('username',true);
+        $data['client_key'] = $this->input->post('client_key',true);
+        $data['token'] = $this->input->post('token',true);
+        $lamp_id = $this->input->post('lamp_id',true);
+        $data['clientid'] = $this->input->post('clientid',true);
+        $data['role'] = $this->input->post('role',true);
+        $data['version'] = $this->session->userdata('version');
+
+        
+        $data['battery_type']              = $this->input->post('battery_type',true);  //蓄电池类型
+        $data['system_voltage']                 = $this->input->post('system_voltage',true);  // 电池电压
+        $data['overvoltage']                  = $this->input->post('overvoltage',true);  // 超压电压
+        $data['char_limit_voltage']            = $this->input->post('char_limit_voltage',true);  // 充电限制电压
+        $data['equ_char_voltage']               = $this->input->post('equ_char_voltage',true); // 均衡充电电压
+        $data['increa_char_voltage']           = $this->input->post('increa_char_voltage',true);  // 提升充电电压
+        $data['float_char_voltage']    = $this->input->post('float_char_voltage',true);  // 浮充充电电压
+        $data['increa_char_return_voltage']               = $this->input->post('increa_char_return_voltage',true);  // 提升充电返回电压
+        $data['over_dischar_return_voltage']          = $this->input->post('over_dischar_return_voltage',true); // 过放返回电压
+        $data['over_dischar_voltage']           = $this->input->post('over_dischar_voltage',true);  // 过放电压
+        $data['equ_char_time']               = $this->input->post('equ_char_time',true) * 60;  // 均衡充电时间
+        $data['increa_char_time']               = $this->input->post('increa_char_time',true) * 60;  // 提升充电时间
+        $data['balan_char_interval']               = $this->input->post('balan_char_interval',true);  // 均衡充电间隔
+        $data['temper_compen_coeff']               = $this->input->post('temper_compen_coeff',true);  // 温度补偿系数
+        $data['char_upper_limit_temper']           = $this->input->post('char_upper_limit_temper',true);  // 上限温度
+        $data['char_lower_limit_temper']           = $this->input->post('char_lower_limit_temper',true);  // 下限温度
+        $data['light_voltage']         = $this->input->post('light_voltage',true);  // 光控电压
+        
+        $lampArr = explode(',', $lamp_id);
+        // $lampList = $this->Lamp_model->get_list_in('L.id', $lampArr, 'L.id,N.protocoltype', array());
+        $url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'].'/api/device/modbus_set_battery_asy';
+
+        foreach ($lampArr as $l) {
+            $data['lampid'] = $l;
+            doAsyncRequest($url,$data);
+        }
+        exit();
+    }
+
     // public function set_battery_asy(){
     //     $res = $this->battery_update();
     //     $clientid = $this->input->post('clientid',true);

+ 15 - 10
api/application/controllers/Syslog.php

@@ -19,33 +19,38 @@ class Syslog extends Base_Controller {
         $print = $this->input->post('print',true);
 
     	$filter = array();
-    	if (!empty($keyword)) $filter['keyword'] = $keyword;
-    	if (!empty($type)) $filter['optype'] = $type;
+    	if (!empty($keyword)) $filter['S.content|U.username|U.name|S.time'] = $keyword;
+    	if (!empty($type)) $filter['S.optype'] = $type;
         $filter['language'] = empty($language) ? 0 : 1;
         $download = $this->input->post('download',true);
 
-        if ($role == COMPANY_ADMIN) {
-            $filter['company'] = $this->get_user_info('company');
-        }elseif ($role == COMPANY_CUSTOMER) {
-            $filter['userid'] = $this->get_user_info('id');
-        }
+        if ($role != SYSTEM_ADMIN) $filter['U.company'] = $this->get_user_info('company');
 
     	$page = !isset($page) ? 1 : $page;
     	$count = empty($count) ? 20 : $count;
+        $limit = $count;
+        $offset = ($page - 1) * $count;
 
     	$field = "S.id,
     			  S.time,
     			  S.optype as type,
     			  S.userid,
-    			  U.username,
+                  U.username,
+    			  U.name as realname,
     			  S.content,
                   S.is_read";
 
     	if (empty($download)) {
             if (isset($print) && !empty($print)) {
-                $data = $this->Syslog_model->getList($filter,$page,$count,$field,1);
+                // $data = $this->Syslog_model->get_list_by_join($where=NULL, $fields='*',$limit=NULL, $offset=NULL, $join = NULL, $order=NULL, $group=NUll, $alias=NULL);
+                // $data = $this->Syslog_model->get_list_by_join($filter,$page,$count,$field,1);
+                var_dump('expression');
             }else{
-                $data = $this->Syslog_model->getList($filter,$page,$count,$field);
+                $join = array();
+                $join[] = ['table'=>'user as U','cond'=>'U.id = S.userid','type'=>'left'];
+                $data = $this->Syslog_model->get_list_by_join($filter, $field,$limit, $offset, $join, 'time DESC,id DESC', NUll, 'S');
+                // var_dump($this->db->last_query());die;
+                // $data = $this->Syslog_model->getList($filter,$page,$count,$field);
             }
             
             $data = empty($data) ? array() : $data;