getLoginUserInfoByToken($token); // 获取当前项目中所有控制柜 $sql = prepare("select id from device where project_id = ?i and status = 1",array($user_basic['project_id'])); $data_device_array = get_data($sql); // for ($i=0; $i < count($data_device_array); $i++) { // $device_id = $data_device_array[$i]['id']; // $sql_1 = prepare("select (main_sewage_pump_count+standby_sewage_pump_count+main_rain_pump_count) as pump_count,(gate_up_count+gate_down_count) as gate_count from data where device_id = ?i order by id desc limit 1",array($device_id)); // $total_pump_count += get_line($sql_1)['pump_count']; // $total_gate_count += get_line($sql_1)['gate_count']; // } $sql_pump_count = prepare("select count(*) from event where event like ?s and device_id in (select id from device where project_id = ?i and status = 1)",array('%泵%',$user_basic['project_id'])); $total_pump_count = get_var($sql_pump_count) == null ? 0 : get_var($sql_pump_count); $sql_gate_count = prepare("select count(*) from event where event like ?s and device_id in (select id from device where project_id = ?i and status = 1)",array('%闸门%',$user_basic['project_id'])); $total_gate_count = get_var($sql_gate_count) == null ? 0 : get_var($sql_gate_count); // 获取场站数量 $sql_1 = prepare("select count(*) from device where project_id = ?i and status = 1",array($user_basic['project_id'])); $terminal_count = get_var($sql_1); $result = array('total_pump_count'=>$total_pump_count,'total_gate_count'=>$total_gate_count,'terminal_count'=>$terminal_count); return self::send_result($result); } // 获取总览内容中闸门总次数以及本月闸门次数 public function getOverviewGateActionInfo() { $token = $_GET['token']; // 获取登录人员基本信息 $user_basic = $this -> getLoginUserInfoByToken($token); // 获取当前项目中所有控制柜 $sql = prepare("select id from device where project_id = ?i",array($user_basic['project_id'])); $data_device_array = get_data($sql); // $month_start_table = "data_".date("Ym",time())."01"; // for ($i=0; $i < count($data_device_array); $i++) { // $device_id = $data_device_array[$i]['id']; // // 获取总的闸门次数 // $sql_1 = prepare("select (gate_up_count+gate_down_count) as gate_count from data where device_id = ?i order by id desc limit 1",array($device_id)); // $total_gate_count += get_var($sql_1); // // 获取本月之前的闸门次数 // $sql_2 = prepare("select (gate_up_count+gate_down_count) as gate_count from ".$month_start_table." where device_id = ?i order by id desc limit 1",array($device_id)); // $last_gate_count += get_var($sql_2); // } $start_time = date("Y-m",time())."-01 00:00:00"; $end_time = date("Y-m-d H:i:s",time()); // 获取总的闸门次数 $sql_gate_count = prepare("select count(*) from event where event like ?s and device_id in (select id from device where project_id = ?i and status = 1)",array('%闸门%',$user_basic['project_id'])); $total_gate_count = get_var($sql_gate_count) == null ? 0 : get_var($sql_gate_count); // 获取本月之前的闸门次数 $sql_current_gate_count = prepare("select count(*) from event where event like ?s and device_id in (select id from device where project_id = ?i and status = 1) and event_time >= ?s and event_time <= ?s",array('%闸门%',$user_basic['project_id'],$start_time,$end_time)); $current_gate_count = get_var($sql_current_gate_count) == null ? 0 : get_var($sql_current_gate_count); $result = array("total_gate_count"=>$total_gate_count,'current_gate_count'=>$current_gate_count); return self::send_result($result); } // 获取总览内容中水泵总次数以及本月水泵次数 public function getOverviewPumpActionInfo() { $token = $_GET['token']; // 获取登录人员基本信息 $user_basic = $this -> getLoginUserInfoByToken($token); // 获取当前项目中所有控制柜 $sql = prepare("select id from device where project_id = ?i",array($user_basic['project_id'])); $data_device_array = get_data($sql); // $month_start_table = "data_".date("Ym",time())."01"; // for ($i=0; $i < count($data_device_array); $i++) { // $device_id = $data_device_array[$i]['id']; // // 获取总的水泵次数 // $sql_1 = prepare("select (main_sewage_pump_count+standby_sewage_pump_count+main_rain_pump_count) as pump_count from data where device_id = ?i order by id desc limit 1",array($device_id)); // $total_pump_count += get_var($sql_1); // // 获取本月之前的水泵次数 // $sql_2 = prepare("select (main_sewage_pump_count+standby_sewage_pump_count+main_rain_pump_count) as pump_count from ".$month_start_table." where device_id = ?i order by id desc limit 1",array($device_id)); // $last_pump_count += get_var($sql_2); // } // // 本月闸门次数 // $current_pump_count = $total_pump_count - $last_pump_count; $start_time = date("Y-m",time())."-01 00:00:00"; $end_time = date("Y-m-d H:i:s",time()); // 获取总的闸门次数 $sql_pump_count = prepare("select count(*) from event where event like ?s and device_id in (select id from device where project_id = ?i and status = 1)",array('%泵%',$user_basic['project_id'])); $total_pump_count = get_var($sql_pump_count) == null ? 0 : get_var($sql_pump_count); // 获取本月之前的闸门次数 $sql_current_pump_count = prepare("select count(*) from event where event like ?s and device_id in (select id from device where project_id = ?i and status = 1) and event_time >= ?s and event_time <= ?s",array('%泵%',$user_basic['project_id'],$start_time,$end_time)); $current_pump_count = get_var($sql_current_pump_count) == null ? 0 : get_var($sql_current_pump_count); $result = array("total_pump_count"=>$total_pump_count,'current_pump_count'=>$current_pump_count); return self::send_result($result); } // 闸门调控统计 public function getOverviewGateLine() { $token = $_GET['token']; $type = $_GET['type'] == '' ? $type = 'month' : $type = $_GET['type']; // 获取登录人员基本信息 $user_basic = $this -> getLoginUserInfoByToken($token); // 获取当前项目中所有控制柜 $sql = prepare("select id from device where project_id = ?i",array($user_basic['project_id'])); $data_device_array = get_data($sql); $current_time = date("Y-m-d",time()); switch ($type) { case 'month': // 时间处理 $satrt_query_time = date("Y-m-d",time()-14*24*60*60).' 00:00:00'; $end_query_time = date("Y-m-d H:i:s",time()); $month_time_array = $this -> getDateFromtime($satrt_query_time,$end_query_time); for ($i=0; $i < count($month_time_array); $i++) { // 每天开始时间 和 结束时间 // echo $month_time_array[$i]; // if($month_time_array[$i] == $current_time) // { // $every_day_start_time_table = "data_".date("Ymd",strtotime($month_time_array[$i])-24*60*60); // $every_day_end_time_table = "data"; // } // else // { // $every_day_start_time_table = "data_".date("Ymd",strtotime($month_time_array[$i])-24*60*60); // $every_day_end_time_table = "data_".date("Ymd",strtotime($month_time_array[$i])); // } $start_time = $month_time_array[$i]." 00:00:00"; $end_time = $month_time_array[$i]." 23:59:59"; $gate_count_1 = $gate_count_2 = 0; // 计算每天闸门调控的次数 for ($j=0; $j < count($data_device_array); $j++) { $device_id = $data_device_array[$j]['id']; $sql_current_gate_count = prepare("select count(*) from event where event like ?s and device_id =?i and event_time >= ?s and event_time <= ?s",array('%闸门%',$device_id,$start_time,$end_time)); $gate_count_1 += get_var($sql_current_gate_count) == null ? 0 : get_var($sql_current_gate_count); // $sql_1 = prepare("select (gate_up_count+gate_down_count) as gate_count from ".$every_day_start_time_table." where device_id = ?i order by id desc limit 1",array($device_id)); // $gate_count_1 += get_var($sql_1) == null ? 0 : get_var($sql_1); // // 获取本月之前的闸门次数 // $sql_2 = prepare("select (gate_up_count+gate_down_count) as gate_count from ".$every_day_end_time_table." where device_id = ?i order by id desc limit 1",array($device_id)); } $result['count'][$i] = $gate_count_1; $result['time'][$i] = date("d",strtotime($month_time_array[$i])); } break; case 'year': // 时间处理 $year_time_array = $this -> getYearMonthTime(); for ($i=0; $i < count($year_time_array); $i++) { // 每月开始时间 和 结束时间 $every_month_start_time = $year_time_array[$i].'-01 00:00:00'; $every_month_end_time = $year_time_array[$i].'-31 23:59:59'; // echo $every_month_start_time.'-------'.$every_month_end_time."======================\r\n"; $gate_count_1 = $gate_count_2 = 0; // 计算每天闸门调控的次数 for ($j=0; $j < count($data_device_array); $j++) { $device_id = $data_device_array[$j]['id']; $sql_current_gate_count = prepare("select count(*) from event where event like ?s and device_id =?i and event_time >= ?s and event_time <= ?s",array('%闸门%',$device_id,$every_month_start_time,$every_month_end_time)); $gate_count_1 += get_var($sql_current_gate_count) == null ? 0 : get_var($sql_current_gate_count); // $sql_1 = prepare("select (gate_up_count+gate_down_count) as gate_count from data where device_id = ?i and `current_time` getLoginUserInfoByToken($token); // 获取当前项目中所有控制柜 $sql = prepare("select id from device where project_id = ?i",array($user_basic['project_id'])); $data_device_array = get_data($sql); $current_time = date("Y-m-d",time()); switch ($type) { case 'month': // 时间处理 $satrt_query_time = date("Y-m-d",time()-14*24*60*60).' 00:00:00'; $end_query_time = date("Y-m-d H:i:s",time()); $month_time_array = $this -> getDateFromtime($satrt_query_time,$end_query_time); for ($i=0; $i < count($month_time_array); $i++) { // 每天开始时间 和 结束时间 // echo $month_time_array[$i]; // if($month_time_array[$i] == $current_time) // { // $every_day_start_time_table = "data_".date("Ymd",strtotime($month_time_array[$i])-24*60*60); // $every_day_end_time_table = "data"; // } // else // { // $every_day_start_time_table = "data_".date("Ymd",strtotime($month_time_array[$i])-24*60*60); // $every_day_end_time_table = "data_".date("Ymd",strtotime($month_time_array[$i])); // } $start_time = $month_time_array[$i]." 00:00:00"; $end_time = $month_time_array[$i]." 23:59:59"; $pump_count_1 = $pump_count_2 = 0; // 计算每天闸门调控的次数 for ($j=0; $j < count($data_device_array); $j++) { $device_id = $data_device_array[$j]['id']; $sql_current_pump_count = prepare("select count(*) from event where event like ?s and device_id =?i and event_time >= ?s and event_time <= ?s",array('%泵%',$device_id,$start_time,$end_time)); $pump_count_1 += get_var($sql_current_pump_count) == null ? 0 : get_var($sql_current_pump_count); // $sql_1 = prepare("select (main_sewage_pump_count+standby_sewage_pump_count+main_rain_pump_count) as pump_count from ".$every_day_start_time_table." where device_id = ?i order by id desc limit 1",array($device_id)); // $pump_count_1 += get_var($sql_1) == null ? 0 : get_var($sql_1); // // 获取本月之前的闸门次数 // $sql_2 = prepare("select (main_sewage_pump_count+standby_sewage_pump_count+main_rain_pump_count) as pump_count from ".$every_day_end_time_table." where device_id = ?i order by id desc limit 1",array($device_id)); // $pump_count_2 += get_var($sql_2) == null ? 0 : get_var($sql_2); } $result['count'][$i] = $pump_count_1; $result['time'][$i] = date("d",strtotime($month_time_array[$i])); } break; case 'year': // 时间处理 $year_time_array = $this -> getYearMonthTime(); for ($i=0; $i < count($year_time_array); $i++) { // 每月开始时间 和 结束时间 $every_month_start_time = $year_time_array[$i].'-01 00:00:00'; $every_month_end_time = $year_time_array[$i].'-31 23:59:59'; // echo $every_month_start_time.'-------'.$every_month_end_time."======================\r\n"; $pump_count_1 = $pump_count_2 = 0; // 计算每天闸门调控的次数 for ($j=0; $j < count($data_device_array); $j++) { $device_id = $data_device_array[$j]['id']; $sql_current_pump_count = prepare("select count(*) from event where event like ?s and device_id =?i and event_time >= ?s and event_time <= ?s",array('%泵%',$device_id,$every_month_start_time,$every_month_end_time)); $pump_count_1 += get_var($sql_current_pump_count) == null ? 0 : get_var($sql_current_pump_count); // $sql_1 = prepare("select (main_sewage_pump_count+standby_sewage_pump_count+main_rain_pump_count) as pump_count from data where device_id = ?i and `current_time`