wzh 5 tahun lalu
induk
melakukan
40725919ad

+ 72 - 40
api/application/controllers/Lampcontrol.php

@@ -21,6 +21,7 @@ class Lampcontrol extends Base_Controller {
         $this->load->model('Modbus_load_model');
         $this->load->model('Modbus_battery_model');
         $this->load->model('Global_location_model');
+        $this->load->model('RealtimeInfoLog_model');
     }
 
     // 灯控列表
@@ -3302,26 +3303,36 @@ class Lampcontrol extends Base_Controller {
         $datatype = $this->input->post('datatype',true);
         $page = intval($this->input->post('page',true));
         $count = intval($this->input->post('count',true));
+
+        $count = empty($count) ? 16 : $count;
         if (empty($lamp_id)) {
             exit(json_result('0400', $this->response['0400'], array()));
         }
         $date = $this->input->post('date',true);
         $beginDate = '';
         $endDate = '';
+
+        // 按时区修改时间
+        $lampData = $this->Lamp_model->get_one(['id'=>$lamp_id],'projectid,protocoltype');
+        $timezone = $this->Project_model->get_timezone_by_projectid($lampData['projectid']);
+
         if (!empty($date)) {
             $dateArr = explode('/', $date);
-            $beginDate = $dateArr[0];
-            $endDate = $dateArr[1];
+            $beginDate = date('Y-m-d H:i:s',strtotime($dateArr[0]) - 8*3600 + $timezone['value']*3600);
+            $endDate = date('Y-m-d H:i:s',strtotime($dateArr[1]) - 8*3600 + $timezone['value']*3600);
+            // $beginDate = $dateArr[0];
+            // $endDate = $dateArr[1];
             if (strtotime($endDate) - strtotime($beginDate) > 31*24*3600) {
                 exit(json_result('0418',$this->response['0418']));
             }
+        }else{
+            $beginDate = date('Y-m-d H:i:s',strtotime(date('Y-m-d 00:00:00',time())) - 8*3600 + $timezone['value']*3600);
+            $endDate = date('Y-m-d H:i:s',strtotime(date('Y-m-d 23:59:59',time())) - 8*3600 + $timezone['value']*3600);
         }
         if($page < 1){
             $page = 1;
         }
-        // 按时区修改时间
-        $lampData = $this->Lamp_model->getOne($lamp_id,'L.projectid,L.protocoltype');
-        $timezone = $this->Project_model->get_timezone_by_projectid($lampData['projectid']);
+        
 
         $download = intval($this->input->post('download'));
         if (!empty($download)) {
@@ -3479,8 +3490,29 @@ class Lampcontrol extends Base_Controller {
         }
         // $table_map = array('system_info_log','lamp_info_log','solar_info_log','battery_info_log','electric_info_log','history_info_log');
         $table = !empty($datatype) ? $datatype : 'system_info_log';
-        $total = $this->Lamp_model->getCountForInfoLog($lamp_id, $table,$beginDate,$endDate);
-        $res = $this->Lamp_model->getListForInfoLog($lamp_id, $table, ($page-1)*$count, $count,$beginDate,$endDate);
+        if ($table == 'lamp_info_log') {
+            $table = 'realtime_info_log';
+            $total = $this->RealtimeInfoLog_model->get_count(['lampid'=>$lamp_id,'updatetime >='=>$beginDate,'updatetime <='=>$endDate]);
+            $res = $this->RealtimeInfoLog_model->get_list(['lampid'=>$lamp_id,'updatetime >='=>$beginDate,'updatetime <='=>$endDate], 'loadvoltage as lampvoltage,loadcurrent as lampcurrent,loadpower as lamppower,updatetime',$count, ($page-1)*$count, 'updatetime desc,id desc', NUll);
+            // $res = $this->Lamp_model->getListForInfoLog($lamp_id, $table, ($page-1)*$count, $count,$beginDate,$endDate);
+        }elseif ($table == 'system_info_log') {
+            $total = $this->Lamp_model->getCountForInfoLog($lamp_id, $table,$beginDate,$endDate);
+            $res = $this->Lamp_model->getListForInfoLog($lamp_id, $table, ($page-1)*$count, $count,$beginDate,$endDate);
+        }elseif ($table == 'battery_info_log') {
+            $join = [
+                ['table'=>'history_info_log as HI','cond'=>'HI.lampid = RI.lampid and HI.updatetime = RI.updatetime','type'=>'inner'],
+            ];
+            $where = ['HI.lampid'=>$lamp_id,'HI.updatetime >='=>$beginDate,'HI.updatetime <='=>$endDate];
+            $total = $this->RealtimeInfoLog_model->get_list_by_multi_join($where,'count(*) as total',NULL, NULL, $join, NULL, NUll, 'RI', true);
+            $total = $total['total'];
+
+            $fields = 'RI.batvoltage as battvoltage,RI.updatetime,HI.overtimes';
+            $res = $this->RealtimeInfoLog_model->get_list_by_join($where, $fields,$count, ($page-1)*$count, $join, 'RI.updatetime desc,RI.id desc', NUll, 'RI');
+        }else{
+            $total = $this->Lamp_model->getCountForInfoLog($lamp_id, $table,$beginDate,$endDate);
+            $res = $this->Lamp_model->getListForInfoLog($lamp_id, $table, ($page-1)*$count, $count,$beginDate,$endDate);
+        }
+        
 
         if(!$res){
             exit(json_result('0000', $this->response['0006'], array()));
@@ -3965,7 +3997,7 @@ class Lampcontrol extends Base_Controller {
 
         $data = ['patrolinterval'=>$lampData['patrolinterval']];
         if ($type == 0) {  // 路灯
-            $sql = 'select LI.lampvoltage,LI.lampcurrent,LI.lamppower,LI.lighteness,LI.updatetime,BI.daychargemincurrent from lamp_info_log as LI LEFT JOIN battery_info_log as BI on BI.lampid = LI.lampid AND LI.updatetime = BI.updatetime where LI.lampid = '.$lampId.' and LI.updatetime >= "'.$beginDate.'" and LI.updatetime <= "'.$endDate.'"';
+            $sql = 'select LI.loadvoltage as lampvoltage,LI.loadcurrent as lampcurrent,LI.loadpower as lamppower,LI.updatetime from realtime_info_log as LI where LI.lampid = '.$lampId.' and LI.updatetime >= "'.$beginDate.'" and LI.updatetime <= "'.$endDate.'"';
 
             $list = $this->db->query($sql)->result_array();
             $temp = [];
@@ -3973,18 +4005,18 @@ class Lampcontrol extends Base_Controller {
                 $temp['lampvoltage'][] = $value['lampvoltage'];
                 $temp['lampcurrent'][] = $value['lampcurrent'];
                 $temp['lamppower'][] = $value['lamppower'];
-                $temp['lighteness'][] = $value['lighteness'];
+                // $temp['lighteness'][] = $value['lighteness'];
                 $temp['updatetime'][] = date_change($value['updatetime'],8,$timezone);
                 if (!isset($data['maxcurrent'])) {
                     $data['maxcurrent'] = $value['lampcurrent'];
                 }else{
                     $data['maxcurrent'] = $value['lampcurrent'] > $data['maxcurrent'] ? $value['lampcurrent'] : $data['maxcurrent'];
                 }
-                if (!isset($data['maxdaychargemincurrent'])) {
-                    $data['maxdaychargemincurrent'] = $value['daychargemincurrent'];
-                }else{
-                    $data['maxdaychargemincurrent'] = $value['daychargemincurrent'] > $data['maxdaychargemincurrent'] ? $value['daychargemincurrent'] : $data['maxdaychargemincurrent'];
-                }
+                // if (!isset($data['maxdaychargemincurrent'])) {
+                //     $data['maxdaychargemincurrent'] = $value['daychargemincurrent'];
+                // }else{
+                //     $data['maxdaychargemincurrent'] = $value['daychargemincurrent'] > $data['maxdaychargemincurrent'] ? $value['daychargemincurrent'] : $data['maxdaychargemincurrent'];
+                // }
                 if (!isset($data['mincurrent'])) {
                     $data['mincurrent'] = $value['lampcurrent'];
                 }else{
@@ -4010,37 +4042,37 @@ class Lampcontrol extends Base_Controller {
                 }else{
                     $data['minpower'] = $value['lamppower'] < $data['minpower'] ? $value['lamppower'] : $data['minpower'];
                 }
-                if (!isset($data['maxlighteness'])) {
-                    $data['maxlighteness'] = $value['lighteness'];
-                }else{
-                    $data['maxlighteness'] = $value['lighteness'] > $data['maxlighteness'] ? $value['lighteness'] : $data['maxlighteness'];
-                }
-                if (!isset($data['minlighteness'])) {
-                    $data['minlighteness'] = $value['lighteness'];
-                }else{
-                    $data['minlighteness'] = $value['lighteness'] < $data['minlighteness'] ? $value['lighteness'] : $data['minlighteness'];
-                }
-                if (isset($data['maxdaychargemincurrent'])) {
-                    $h = floor($data['maxdaychargemincurrent'] / 3600);
-                    $h = $h < 10 ? '0'.$h : $h;
-                    $m = floor($data['maxdaychargemincurrent'] / 3600 % 60);
-                    $m = $m < 10 ? '0'.$m : $m;
-                    $data['maxdaychargemincurrent'] = $h.':'.$m;
-                }
+                // if (!isset($data['maxlighteness'])) {
+                //     $data['maxlighteness'] = $value['lighteness'];
+                // }else{
+                //     $data['maxlighteness'] = $value['lighteness'] > $data['maxlighteness'] ? $value['lighteness'] : $data['maxlighteness'];
+                // }
+                // if (!isset($data['minlighteness'])) {
+                //     $data['minlighteness'] = $value['lighteness'];
+                // }else{
+                //     $data['minlighteness'] = $value['lighteness'] < $data['minlighteness'] ? $value['lighteness'] : $data['minlighteness'];
+                // }
+                // if (isset($data['maxdaychargemincurrent'])) {
+                //     $h = floor($data['maxdaychargemincurrent'] / 3600);
+                //     $h = $h < 10 ? '0'.$h : $h;
+                //     $m = floor($data['maxdaychargemincurrent'] / 3600 % 60);
+                //     $m = $m < 10 ? '0'.$m : $m;
+                //     $data['maxdaychargemincurrent'] = $h.':'.$m;
+                // }
             }
             $list = $temp;
         }elseif ($type == 1) { // 蓄电池
-            $sql = 'select battvoltage,chargecurrent,discharcurrent,batttemper,chargepower,dischargepower,updatetime from battery_info_log where lampid = '.$lampId.' and updatetime >= "'.$beginDate.'" and updatetime <= "'.$endDate.'"';
+            $sql = 'select batvoltage as battvoltage,batcurrent as chargecurrent,chgtemper as batttemper,batpower as chargepower,updatetime from realtime_info_log where lampid = '.$lampId.' and updatetime >= "'.$beginDate.'" and updatetime <= "'.$endDate.'"';
             $list = $this->db->query($sql)->result_array();
             $temp = [];
             foreach ($list as $value) {
                 $temp['battvoltage'][] = $value['battvoltage'];
                 $temp['updatetime'][] = date_change($value['updatetime'],8,$timezone);
                 
-                $batterycurrent = $value['chargecurrent'] > 0 ? $value['chargecurrent'] : 0 - $value['discharcurrent'];
+                $batterycurrent = $value['chargecurrent'];
                 $temp['batterycurrent'][] = $batterycurrent;
                 
-                $batterypower = $value['chargepower'] > 0 ? $value['chargepower'] : 0 - $value['dischargepower'];
+                $batterypower = $value['chargepower'];
                 $temp['batterypower'][] = $batterypower;
                 if (!isset($data['maxcurrent'])) {
                     $data['maxcurrent'] = $batterycurrent;
@@ -4086,7 +4118,7 @@ class Lampcontrol extends Base_Controller {
             }
             $list = $temp;
         }elseif ($type == 2) {  // 太阳能板
-            $sql = 'select SI.solarvoltage,SI.solarcurrent,SI.solarpower,SI.updatetime,BI.daydischargemincurrent from solar_info_log as SI LEFT JOIN battery_info_log as BI on BI.lampid = SI.lampid AND SI.updatetime = BI.updatetime where SI.lampid = '.$lampId.' and SI.updatetime >= "'.$beginDate.'" and SI.updatetime <= "'.$endDate.'"';
+            $sql = 'select SI.panelvoltage as solarvoltage,SI.panelcurrent as solarcurrent,SI.panelpower as solarpower,SI.updatetime from realtime_info_log as SI where SI.lampid = '.$lampId.' and SI.updatetime >= "'.$beginDate.'" and SI.updatetime <= "'.$endDate.'"';
             $list = $this->db->query($sql)->result_array();
             $temp = [];
             foreach ($list as $value) {
@@ -4109,11 +4141,11 @@ class Lampcontrol extends Base_Controller {
                 }else{
                     $data['maxvoltage'] = $value['solarvoltage'] > $data['maxvoltage'] ? $value['solarvoltage'] : $data['maxvoltage'];
                 }
-                if (!isset($data['maxdaydischargemincurrent'])) {
-                    $data['maxdaydischargemincurrent'] = $value['daydischargemincurrent'];
-                }else{
-                    $data['maxdaydischargemincurrent'] = $value['daydischargemincurrent'] > $data['maxdaydischargemincurrent'] ? $value['daydischargemincurrent'] : $data['maxdaydischargemincurrent'];
-                }
+                // if (!isset($data['maxdaydischargemincurrent'])) {
+                //     $data['maxdaydischargemincurrent'] = $value['daydischargemincurrent'];
+                // }else{
+                //     $data['maxdaydischargemincurrent'] = $value['daydischargemincurrent'] > $data['maxdaydischargemincurrent'] ? $value['daydischargemincurrent'] : $data['maxdaydischargemincurrent'];
+                // }
                 if (!isset($data['minvoltage'])) {
                     $data['minvoltage'] = $value['solarvoltage'];
                 }else{

+ 8 - 0
api/application/models/RealtimeInfoLog_model.php

@@ -0,0 +1,8 @@
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+
+include_once(FCPATH . 'application/models/Base_model.php');
+class RealtimeInfoLog_model extends Base_Model {
+
+    protected $table = 'realtime_info_log';
+    
+}