|
@@ -16,6 +16,7 @@ class Alarm extends Base_Controller {
|
|
|
// 获取告警信息列表
|
|
|
public function get(){
|
|
|
$filter = array();
|
|
|
+ $where = array('1=1');
|
|
|
$role = $this->get_user_info('role');
|
|
|
$user_id = $this->get_user_info('id');
|
|
|
$lampid = $this->input->post('lampid',true);
|
|
@@ -47,14 +48,14 @@ class Alarm extends Base_Controller {
|
|
|
}
|
|
|
|
|
|
$page = !isset($page) ? 1 : $page;
|
|
|
- $count = empty($count) ? 20 : $count;
|
|
|
+ $limit = empty($count) ? 20 : $count;
|
|
|
+ $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($type >= 0) $filter['type'] = $type;
|
|
|
if(!isset($lampid) && isset($status) && $status >= 0) $filter['status'] = $status;
|
|
|
if ($type == 0) {
|
|
|
$filter['status'] = empty($filter['status']) ? 0 : $filter['status'];
|
|
@@ -64,81 +65,59 @@ class Alarm extends Base_Controller {
|
|
|
if(isset($startDate)) $filter['startDate'] = $startDate;
|
|
|
|
|
|
if (empty($download)) {
|
|
|
- if (isset($print) && !empty($print)) {
|
|
|
- $alarm = $this->Alarm_model->getList($filter, $role, $user_id, $page, $count,1);
|
|
|
+ if (empty($type)) {
|
|
|
+ $join = array();
|
|
|
+ $join[] = ['table'=>'(select lampid,max(updatetime) as maxTime from warning_info_log group by lampid) as WI','cond'=>'WI.lampid = AI.lampid AND WI.maxTime = AI.updatetime','type'=>'inner'];
|
|
|
+ $join[] = ['table'=>'lampinfo as L','cond'=>'L.id = AI.lampid','type'=>'inner'];
|
|
|
+ $join[] = ['table'=>'project as P','cond'=>'P.id = L.projectid','type'=>'inner'];
|
|
|
+ $join[] = ['table'=>'global_location as G','cond'=>'G.id = P.cityid','type'=>'inner'];
|
|
|
+ $where[] = '(AI.batstatus != 0 OR AI.panelstatus != 0 OR AI.lampstatus != 0 OR AI.tempstatus != 0)';
|
|
|
+ $where = implode(' AND ', $where);
|
|
|
+ $alarm = $this->Alarm_model->get_list_by_join($where, 'AI.batstatus,AI.panelstatus,AI.lampstatus,AI.tempstatus,AI.status,AI.updatetime,G.timezone,L.number,P.projectname as project,AI.id',$limit, $offset, $join, 'AI.updatetime DESC,id DESC', NUll, 'AI');
|
|
|
+ $total = $this->Alarm_model->get_list_by_multi_join($where, 'count(*) as total',null, null, $join, null, NUll, 'AI',true);
|
|
|
+ $total = $total['total'];
|
|
|
+ // $alarm = $this->Alarm_model->getList($filter, $role, $user_id, $page, $count,1);
|
|
|
}else{
|
|
|
- $alarm = $this->Alarm_model->getList($filter, $role, $user_id, $page, $count);
|
|
|
+ $join = array();
|
|
|
+ // $join[] = ['table'=>'(select lampid,max(updatetime) as maxTime from warning_info_log group by lampid) as WI','cond'=>'WI.lampid = AI.lampid AND WI.maxTime = AI.updatetime','type'=>'inner'];
|
|
|
+ $join[] = ['table'=>'lampinfo as L','cond'=>'L.id = AI.lampid','type'=>'inner'];
|
|
|
+ $join[] = ['table'=>'project as P','cond'=>'P.id = L.projectid','type'=>'inner'];
|
|
|
+ $join[] = ['table'=>'global_location as G','cond'=>'G.id = P.cityid','type'=>'inner'];
|
|
|
+ $where[] = '(AI.batstatus != 0 OR AI.panelstatus != 0 OR AI.lampstatus != 0 OR AI.tempstatus != 0)';
|
|
|
+ $where = implode(' AND ', $where);
|
|
|
+ $alarm = $this->Alarm_model->get_list_by_join($where, 'AI.batstatus,AI.panelstatus,AI.lampstatus,AI.tempstatus,AI.status,AI.updatetime,G.timezone,L.number,P.projectname as project,AI.id',$limit, $offset, $join, 'AI.updatetime DESC,id DESC', NUll, 'AI');
|
|
|
+ $total = $this->Alarm_model->get_list_by_multi_join($where, 'count(*) as total',null, null, $join, null, NUll, 'AI',true);
|
|
|
+ $total = $total['total'];
|
|
|
}
|
|
|
|
|
|
- $total = $this->Alarm_model->getDataCount($filter, $role, $user_id);
|
|
|
$alarm = empty($alarm) ? array() : $alarm;
|
|
|
|
|
|
- foreach($alarm as &$v){
|
|
|
- // if (empty($projectid)) {
|
|
|
- // $lampData = $this->Lamp_model->getOne($v['lampid'],'L.projectid');
|
|
|
- // $projectid = $lampData['projectid'];
|
|
|
- // }
|
|
|
- // $timezone = $this->Project_model->get_timezone_by_projectid($projectid);
|
|
|
- // if (!empty($v['updatetime'])) {
|
|
|
- // $v['updatetime'] = date_change($v['updatetime'],8,$timezone['value']);
|
|
|
- // }
|
|
|
-
|
|
|
- if (empty($version)) {
|
|
|
- $v['statusStr'] = empty($v['status']) && $v['isfaulted'] == 1 ? '未处理' : '已处理';
|
|
|
- $stralarmtype = trim($v['stralarmtype']);
|
|
|
- if (!empty($stralarmtype)) {
|
|
|
- $alarmArr = explode(',', $stralarmtype);
|
|
|
- $temp = array();
|
|
|
- foreach ($alarmArr as $a) {
|
|
|
- if ($a == '电池故障') {
|
|
|
- $a = '电池电压异常';
|
|
|
- }
|
|
|
- $temp[] = $a;
|
|
|
- }
|
|
|
- $v['stralarmtype'] = implode(',', $temp);
|
|
|
- }
|
|
|
- }else{
|
|
|
- $v['statusStr'] = empty($v['status']) && $v['isfaulted'] == 1 ? 'Untreated' : 'Already processed';
|
|
|
|
|
|
- $stralarmtype = trim($v['stralarmtype']);
|
|
|
- if (!empty($stralarmtype)) {
|
|
|
- $alarmArr = explode(',', $stralarmtype);
|
|
|
- $temp = array();
|
|
|
- foreach ($alarmArr as $a) {
|
|
|
- if ($a == '电池故障') {
|
|
|
- $a = '电池电压异常';
|
|
|
- }
|
|
|
- if ($v['lampprotocoltype'] == 1) {
|
|
|
- $temp[] = modbus_alarm_translate($a);
|
|
|
- }else{
|
|
|
- $temp[] = alarm_translate($a);
|
|
|
- }
|
|
|
- }
|
|
|
- $v['stralarmtype'] = implode('.', $temp);
|
|
|
- }
|
|
|
- }
|
|
|
+ $batstatus = $this->config->item('batstatus');
|
|
|
+ $panelstatus = $this->config->item('panelstatus');
|
|
|
+ $lampstatus = $this->config->item('lampstatus');
|
|
|
+ $tempstatus = $this->config->item('tempstatus');
|
|
|
+
|
|
|
+ foreach($alarm as &$value){
|
|
|
+
|
|
|
+ $temp2 = array();
|
|
|
+ if (isset($batstatus[$value['batstatus']])) $temp2[] = $batstatus[$value['batstatus']];
|
|
|
+ if (isset($panelstatus[$value['panelstatus']])) $temp2[] = $panelstatus[$value['panelstatus']];
|
|
|
+ if (isset($lampstatus[$value['lampstatus']])) $temp2[] = $lampstatus[$value['lampstatus']];
|
|
|
+ if (isset($tempstatus[$value['tempstatus']])) $temp2[] = $tempstatus[$value['tempstatus']];
|
|
|
+ $value['stralarmtype'] = implode(',', $temp2);
|
|
|
+ $value['updatetime'] = set_timezone($value['updatetime'],$value['timezone']);
|
|
|
}
|
|
|
$data = array('history_list'=>$alarm, 'total'=>ceil($total/$count));
|
|
|
if (empty($type)) {
|
|
|
$filter['status'] = 0;
|
|
|
- $data['fault'] = $this->Alarm_model->getDataCount($filter, $role, $user_id);
|
|
|
+ $filter['fault'] = 0;
|
|
|
+ // $data['fault'] = $this->Alarm_model->getDataCount($filter, $role, $user_id);
|
|
|
}
|
|
|
exit(json_result('0000', $this->response['0000'], array('list'=>$data)));
|
|
|
}else{
|
|
|
$alarm = $this->Alarm_model->getList($filter, $role, $user_id, ($page-1)*$count, 3000);
|
|
|
$alarm = empty($alarm) ? array() : $alarm;
|
|
|
- // if (!empty($projectid)) {
|
|
|
- // foreach($alarm as &$v){
|
|
|
- // if (empty($projectid)) {
|
|
|
- // $lampData = $this->Lamp_model->getOne($v['lampid'],'L.projectid');
|
|
|
- // $projectid = $lampData['projectid'];
|
|
|
- // }
|
|
|
- // $timezone = $this->Project_model->get_timezone_by_projectid($projectid);
|
|
|
- // if (!empty($v['updatetime'])) {
|
|
|
- // $v['updatetime'] = date_change($v['updatetime'],8,$timezone['value']);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
// 导出到Excel
|
|
|
if (empty($version)) {
|
|
|
$title = array(
|