DESKTOP-9JTA2JJ\HP 5 лет назад
Родитель
Сommit
541ff88b0b

+ 7 - 6
api/application/controllers/Alarm.php

@@ -52,13 +52,14 @@ class Alarm extends Base_Controller {
 		$offset = ($page - 1)*$count;
 		$section = $this->input->post('section',true);
 
-		if (!empty($section)) $filter['section'] = $section;
-		if (!empty($lampid)) $filter['lampid'] = $lampid;
-		if (!empty($keyword)) $filter['keyword'] = $keyword;
-		if (!empty($projectid)) $filter['projectid'] = $projectid;
-		if(!isset($lampid) && isset($status) && $status >= 0) $filter['status'] = $status;
+		if (!empty($section)) $where[] = 'L.section = "'.$section.'"';
+		if (!empty($lampid)) $where[] = 'L.id = '.$lampid;
+		if (!empty($keyword)) $where[] = 'L.number like "%'.$keyword.'%"';
+		if (!empty($projectid)) $where[] = 'L.projectid = '.$projectid;
+		if(!isset($lampid) && isset($status) && $status >= 0) $where[] = 'AI.status = '.$status;
 		if ($type == 0) {
-			$filter['status'] = empty($filter['status']) ? 0 : $filter['status'];
+			$status = empty($filter['status']) ? 0 : $filter['status'];
+			$where[] = 'AI.status = '.$status;
 		}
 		if(!empty($alarmtype)) $filter['alarmtype'] = $alarmtype;
 		if(isset($endDate)) $filter['endDate'] = $endDate;

+ 8 - 0
api/application/controllers/Base_Controller.php

@@ -236,4 +236,12 @@ class Base_Controller extends CI_Controller {
         }
         $this->Syslog_model->add($data);
     }
+
+    // 下发指令
+    protected function send_cmd($funcode,$address,$data,$manucode='0000000000',$version='0100'){
+        $sendData = $funcode.$version.'01'.$manucode.$data;
+        $sendData .= crc16(pack('H*',$sendData));
+
+        return lampMqttCmd('/IDCOL/CmdInput/'.$address,'/IDCOL/CmdOutput/'.$address,pack('H*',$sendData));
+    }
 }

+ 12 - 3
api/application/controllers/Lampcontrol.php

@@ -2127,7 +2127,7 @@ class Lampcontrol extends Base_Controller {
         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->RealtimeInfoLog_model->get_list(['lampid'=>$lamp_id,'updatetime >='=>$beginDate,'updatetime <='=>$endDate], 'loadvoltage as lampvoltage,loadcurrent as lampcurrent,loadpower as lamppower,updatetime,loadWorkTimeDay as daychargemincurrent',$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);
@@ -2141,8 +2141,16 @@ class Lampcontrol extends Base_Controller {
             $fields = 'batvoltage as battvoltage,updatetime,DayOverDisChgTimes as overtimes';
             $res = $this->RealtimeInfoLog_model->get_list($where, $fields,$count, ($page-1)*$count, 'updatetime desc,id desc');
         }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);
+
+            $join = [
+                // ['table'=>'history_info_log as HI','cond'=>'HI.lampid = RI.lampid and HI.updatetime = RI.updatetime','type'=>'inner'],
+            ];
+            $where = ['lampid'=>$lamp_id,'updatetime >='=>$beginDate,'updatetime <='=>$endDate];
+            $total = $this->RealtimeInfoLog_model->get_count($where,'count(*) as total');
+            $fields = 'panelvoltage as solarvoltage,updatetime,panelcurrent as solarcurrent,panelpower as solarpower';
+            $res = $this->RealtimeInfoLog_model->get_list($where, $fields,$count, ($page-1)*$count, 'updatetime desc,id desc');
+            // $total = $this->Lamp_model->getCountForInfoLog($lamp_id, $table,$beginDate,$endDate);
+            // $res = $this->Lamp_model->getListForInfoLog($lamp_id, $table, ($page-1)*$count, $count,$beginDate,$endDate);
         }
         
 
@@ -2152,6 +2160,7 @@ class Lampcontrol extends Base_Controller {
             
             $arr = [2=>'16',3=>'32',4=>'48',5=>'64'];
             foreach ($res as &$v) {
+                if (isset($v['daychargemincurrent'])) $v['daychargemincurrent'] = intval($v['daychargemincurrent']);
                 // $v['updatetime'] = date_change($v["updatetime"],8,$timezone['value']);
                 $v['updatetime'] = set_timezone($v["updatetime"],$timezone['value']);
                 if ($lampData['protocoltype'] == 1 && $table == 'battery_info_log') {

+ 36 - 65
api/application/controllers/Project.php

@@ -725,79 +725,50 @@ class Project extends Base_Controller {
     }
 
     // 巡检设置
-    public function patrol() {
+    public function patrol(){
+        $username = $this->input->post('username',true);
+        $role = $this->input->post('role',true);
+        $client_key = $this->input->post('client_key',true);
+        $token = $this->input->post('token',true);
+        $clientid = $this->input->post('clientid',true);
+        $version = $this->session->userdata('version');
 
-        $role = $this->get_user_info('role');
-        // if ($role == COMPANY_CUSTOMER) {
-        //     exit(json_result('0011', $this->response['0011'], array()));
+        $lampid = intval($this->input->post('lampid', true));
+        $interval = $this->input->post('interval',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/project/patrol_asy';
+        
+        // foreach ($lampArr as $l) {
+            doAsyncRequest($url,['clientid'=>$clientid,'lampid'=>$lampid,'interval'=>$interval,'username'=>$username,'client_key'=>$client_key,'token'=>$token,'version'=>$version,'role'=>$role]);
         // }
+        
+        exit();
+    }
+    public function patrol_asy() {
 
-        $type = $this->input->post('type', true);
-        $value = $this->input->post('value', true);
-        $switch = $this->input->post('switch',true);
+        $lampid = intval($this->input->post('lampid', true));
         $interval = $this->input->post('interval',true);
 
-        if(!in_array($type, array('project','network','lamp')) || empty($interval) || empty($value)) {
-            exit(json_result('0005', $this->response['0005'], array()));
-        }
+        if (empty($lampid)) exit(json_result('0007',$this->response['0007']));
 
-        $nowtime                = time();
-        $data['patroltype']     = intval($switch);
-        $data['patrolinterval'] = intval($interval);
-        $data['updatetime']     = date("Y-m-d H:i:s", $nowtime);
-        $data['nextquerytime']  = date("Y-m-d H:i:s", time());
-        if ($type == 'project') {
-            $idArr = $this->Lamp_model->getLampIds(array('project'=>$value));
-        }elseif ($type == 'network') {
-            $idArr = $this->Lamp_model->getLampIds(array('network'=>$value));
-        }else{
+        $lampData = $this->Lamp_model->get_one(['id'=>$lampid],'address');
+        $address = substr($lampData['address'], 2);
 
-            $id = $value;
-            $ret = $this->Patrol_model->getOne($id);
-            if(empty($ret)){
-                $data['id'] = $id;
-                $this->Patrol_model->insert($data);
-            } else {
-                $this->Patrol_model->update(array('id'=>$id), $data);
-            }
-            $res = $this->Lamp_model->getOne($id,'N.protocoltype,L.address,L.protocoltype as lampprotocoltype');
-            if ($res['protocoltype'] == 4) {
-                $sendData = '000101A501';;
-                $sendData .= bitSubStr(base_convert(intval($interval/5), 10, 16));
-                lampMqttCmd('/lamp/WriteIn/'.$res['address'],'/lamp/WriteOut/'.$res['address'],pack('H*', $sendData),0);
-            }else{
-                if (isset($res['protocoltype']) && $res['protocoltype'] != 0) {
-                    $cmd = '{"cmd_type":"set_patrol_cmd","cmd_id":'.$id.',"broadcast":0}';
-                    $cmdret = send_cmd($cmd,1,0,$res['protocoltype']);
-                    // if (empty($cmdret)) exit(json_result('0016',$this->response['0016'], array('number'=>$lampData['number'])));
-                    // if($cmdret === false){
-                    //     exit(json_result('0008', $this->response['0008']));
-                    // } else {
-                    //     $res = json_decode($cmdret, true);
-                    // }
-
-                    // if (isset($res['result']) && $res['result'] == true) {
-                    //     exit(json_result('0000', $this->response['0000']));
-                    // } else {
-                    //     $version = $this->session->userdata('version');
-                    //     if (empty($version)) {
-                    //         $res['msg'] = empty($res['msg']) ? '未知错误' : transfer_error_tips($res['msg']);
-                    //         exit(json_result('0010', $res['msg']));
-                    //     }else{
-                    //         $res['msg'] = empty($res['msg']) ? 'Unknown error' : $res['msg'];
-                    //         exit(json_result('other', $res['msg']));
-                    //     }
-                    // }
-                }
-            }
-            
-        }
-        
-        if (!empty($idArr)) {
-            foreach ($idArr as $id) {
-                $this->do_setting($id, $data);
-            }
+        $sendData = '000A';
+        $interval = base_convert($interval, 10, 16);
+        $sendData .= substr('0000'.$interval, -4);
+
+        $res = $this->send_cmd('16',$address,$senddata);
+        if (empty($res)) {
+            exit(json_result('0016',$this->response['0016']));
+        }else{
+            $res = unpack('H*', $res['msg'])[1];
+            if (substr($res, 18,2) != '01') exit(json_result('0010',$this->response['0010']));
         }
+
         exit(json_result('0000', $this->response['0000'], array()));
     }