123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514 |
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- include_once(FCPATH . 'application/controllers/Base_Controller.php');
- class Alarm extends Base_Controller {
-
- public function __construct() {
- parent::__construct();
- $this->load->model('Alarm_model');
- $this->load->model('Project_model');
- $this->load->model('Network_model');
- $this->load->model('Lamp_model');
- $this->load->model('Patrol_model');
- $this->load->model('Repair_model');
- $this->load->model('AlarmSendUserInfo_model');
- }
-
- // 获取告警信息列表
- 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);
- $page = intval($this->input->post('page',true));
- $count = intval($this->input->post('count',true));
- $print = $this->input->post('print',true);
- // 告警状态筛选
- $status = $this->input->post('status',true);
- // 关键字搜索
- $keyword = $this->input->post('keyword',true);
- $projectid = $this->input->post('projectid',true);
- // 是否导出
- $download = $this->input->post('download',true);
- // 告警类型筛选
- $alarmtype = trim($this->input->post('alarmtype',true));
- // var_dump($alarmtype);
- // 时间筛选
- $endDate = $this->input->post('endDate',true);
- $startDate = $this->input->post('startDate',true);
- $type = intval($this->input->post('type',true));
- $version = $this->version;
- // var_dump($version);
- // if (!empty($version)) {
- // $alarmtype = alarm_translate($alarmtype);
- // }
- $page = empty($page) ? 1 : $page;
- $count = empty($count) ? 20 : $count;
- $limit = $count;
- $offset = ($page - 1)*$count;
- $section = $this->input->post('section',true);
- 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) {
- $status = empty($filter['status']) ? 0 : $filter['status'];
- $where[] = 'AI.status = '.$status;
- }
- // if(!empty($alarmtype)) $filter['alarmtype'] = $alarmtype;
- if(!empty($alarmtype) && is_numeric($alarmtype)) {
- $t_ty = substr($alarmtype, 0,1);
- $t_ty2 = substr($alarmtype, 1,1);
- if ($t_ty == 1) {
- $t_1 = 'batstatus';
- }elseif ($t_ty == 2) {
- $t_1 = 'panelstatus';
- }elseif ($t_ty == 2) {
- $t_1 = 'lampstatus';
- }else {
- $t_1 = 'tempstatus';
- }
- $where[] = 'AI.'.$t_1.' = '.$t_ty2;
- }
- // var_dump($alarmtype);
- // if(isset($endDate)) $filter['endDate'] = $endDate;
- if(isset($endDate) && !empty($endDate)) $where[] = 'AI.updatetime <= "'.$endDate.'"';
- if(isset($startDate) && !empty($startDate)) $where[] = 'AI.updatetime >= "'.$startDate.'"';
- // if(isset($startDate)) $filter['startDate'] = $startDate;
- if (empty($download)) {
- 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{
- $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 = empty($alarm) ? array() : $alarm;
- $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;
- $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;
- // 导出到Excel
- if (empty($version)) {
- $title = array(
- array('编号','项目名称','报警路灯','报警事件','是否已处理','更新时间'),
- );
- }else{ // 英文导出
- $title = array(
- array('Number','Project name','Alarm lamp','Alarm event','Has it been processed','Update time'),
- );
- }
-
- $temp = array();
- $i = ($page-1)*$count + 1;
- foreach ($alarm as $k=>$v) {
- $temp[$k][] = $i;
- $temp[$k][] = $v['project'];
- $temp[$k][] = $v['number'];
-
- if (empty($version)) {
- $stralarmtype = trim($v['stralarmtype']);
- if (!empty($stralarmtype)) {
- $alarmArr = explode(',', $stralarmtype);
- $temp1 = array();
- foreach ($alarmArr as $a) {
- if ($a == '电池故障') {
- $a = '电池电压异常';
- }
- $temp1[] = $a;
- }
- $v['stralarmtype'] = implode(',', $temp1);
- }
- $temp[$k][] = $v['stralarmtype'];
- $temp[$k][] = empty($v['status']) ? '未处理' : '已处理';
- }else{
- $stralarmtype = trim($v['stralarmtype']);
- if (!empty($stralarmtype)) {
- $alarmArr = explode(',', $stralarmtype);
- $arr = array();
- foreach ($alarmArr as $a) {
- if ($a == '电池故障') {
- $a = '电池电压异常';
- }
- $arr[] = alarm_translate($a);
- }
- // var_dump($temp);
- $temp[$k][] = empty($arr) ? '' : implode('.', $arr);
- }else{
- $temp[$k][] = '';
- }
- $temp[$k][] = empty($v['status']) ? 'Untreated' : 'Already processed';
- }
- $temp[$k][] = $v['updatetime'];
- $i ++;
- }
- $data = array_merge($title,$temp);
- $path = push_excel($data,'alarmExcel_'.date('Ymd'));
- exit(json_result('0000',$this->response['0000'],array('path'=>$path)));
- }
-
- }
-
- // 查看故障详情
- public function detail(){
- $id = $this->input->post('id',true);
- if (empty($id)) {
- exit(json_result('0604', $this->response['0604'], array()));
- }
- $data = $this->Alarm_model->getOne($id);
- exit(json_result('0000', $this->response['0000'], $data));
- }
-
- // 更改故障状态
- public function set(){
- $role = $this->get_user_info('role');
- // if ($role == COMPANY_CUSTOMER) {
- // exit(json_result('0011', $this->response['0011'], array()));
- // }
-
- $ids = $this->input->post("ids",true);
- if (empty($ids)) {
- exit(json_result('0604', $this->response['0604'], array()));
- }
- $status = $this->input->post("status",true);
- $ids = explode(",", $ids);
- $filter = array('id' => $ids);
- $data = array('status' => intval($status));
- $res = $this->Alarm_model->update($data,$filter);
- // if ($status == 1) {
- // foreach ($ids as $v) {
- // $alarmData = $this->Alarm_model->get_one(['id'=>$v],'lampid');
- // if ($status == 0) {
- // $this->Lamp_model->update(array('id'=>$alarData['lampid']),array('isfaulted'=>1));
- // }else{
- // $this->Lamp_model->update(array('id'=>$alarData['lampid']),array('isfaulted'=>0));
- // }
- // $this->Alarm_model->update(array('lampid'=>$alarmData['lampid'],'status'=>0),array('status'=>1));
- // }
- // }
- if ($res) {
- exit(json_result('0000', $this->response['0000'], array()));
- } else {
- exit(json_result('0009', $this->response['0009'], array()));
- }
- }
-
- // 删除故障信息
- public function del(){
- $role = $this->get_user_info('role');
- // if ($role == COMPANY_CUSTOMER) {
- // exit(json_result('0011', $this->response['0011'], array()));
- // }
- $ids = $this->input->post("ids",true);
- $lamp_ids = $this->input->post('lamp_ids', true);
- if (empty($ids) && empty($lamp_ids)) {
- exit(json_result('0603', $this->response['0603'], array()));
- }
- if (!empty($ids)) {
- $ids = explode(",", $ids);
- $res = $this->Alarm_model->delBatch($ids);
- } else {
- $lamp_ids = explode(",", $lamp_ids);
- $res = $this->Alarm_model->delBatch($lamp_ids, 'lampid');
- $this->Lamp_model->markNormal($lamp_ids);
- $dataArr = $this->Lamp_model->getBatch($lamp_ids);
- foreach ($dataArr as $data) {
- $this->Network_model->minus_fault_count($data['networkid']);
- $this->Project_model->minus_fault_count($data['projectid']);
- }
- }
- if ($res) {
- exit(json_result('0000', $this->response['0000'], array()));
- } else {
- exit(json_result('0005', $this->response['0005'], array()));
- }
- }
- // 巡检信息列表
- public function patrol_list(){
- $role = $this->get_user_info('role');
- $userid = $this->get_user_info('id');
- $company = $this->get_user_info('company');
- $projectid = $this->input->post('projectid',true);
- $page = $this->input->post('page',true);
- $count = $this->input->post('count',true);
- $keyword = $this->input->post('keyword',true);
- $download = $this->input->post('download',true);
- $status = $this->input->post('status',true);
- $print = $this->input->post('print',true);
- $page = !isset($page) ? 1 : $page;
- $count = empty($count) ? 20 : $count;
- $limit = $count;
- $offset = ($page - 1)*$count;
- // 信息字段
- $field = "L.id,
- P.id as projectid,
- P.projectname as project_name,
- L.number,
- L.patrolinterval";
- $where =array();
- $section = $this->input->post('section',true);
- $projectid = intval($this->input->post('projectid',true));
-
- if (!empty($section)) $where['L.section'] = $section;
- if (!empty($projectid)) $where['L.projectid'] = $projectid;
- if (!empty($keyword)) $where['L.number|'] = $keyword;
- if ($role != SYSTEM_ADMIN) $where['P.company'] = $company;
-
- $join = [];
- $join[] = ['table'=>'project as P','cond'=>'P.id = L.projectid','type'=>'left'];
- if (empty($download)) {
-
- // 获取巡检信息列表
- if (isset($print) && !empty($print)) {
- // $data = $this->Patrol_model->getList($role,$companyid,$projectid,$userid,$fiter,$field,$page,$count,1);
- $data = $this->Lamp_model->get_list_by_join($where, $field,$limit, $offset, $join, 'L.number ASC,L.id DESC', NUll, 'L');
- }else{
- $data = $this->Lamp_model->get_list_by_join($where, $field,$limit, $offset, $join, 'L.number ASC,L.id DESC', NUll, 'L');
- }
-
- // 获取巡检信息总数
- $total = $this->Lamp_model->get_list_by_multi_join($where, 'count(*) as total', null, null, $join, 'L.number ASC,L.id DESC', NUll, 'L',true);
- $total = $total['total'];
- json_result('0000',$this->response['0000'],array('patrol_list'=>$data,'total'=>ceil($total/$count)));
- }else{
- // 获取巡检信息列表
- $data = $this->Lamp_model->get_list_by_join($where, $field,3000, 0, $join, 'L.number ASC,id DESC', NUll, 'L');
- // $data = $this->Patrol_model->getList($role,$companyid,$projectid,$userid,$fiter,$field,($page-1)*$count,3000);
- $version = $this->session->userdata('version');
- if (empty($version)) {
- $title = array(
- array('编号','项目名称','路灯编号','巡检间隔时间(min)'),
- );
- }else{
- $title = array(
- array('Number','Project name','Lamp Number','Inspection interval time(min)'),
- );
- }
-
- $temp = array();
- $i = ($page-1)*$count + 1;
- foreach ($data as $k=>$v) {
- $temp[$k][] = $i;
- $temp[$k][] = $v['project_name'];
- $temp[$k][] = $v['number'];
- $temp[$k][] = $v['patrolinterval'];
- $i ++;
- }
- $res = array_merge($title,$temp);
- $path = push_excel($res,'patrolExcel_'.date('Ymd'));
- exit(json_result('0000',$this->response['0000'],array('path'=>$path)));
- }
-
- }
- // 单个路灯维修信息
- public function repair_info(){
- $alarmid = $this->input->post('alarmid');
- if (empty($alarmid)) {
- exit(json_result('0007',$this->response['0007'],array()));
- }
- $page = $this->input->post('page',true);
- $count = $this->input->post('count',true);
- $page = empty($page) ? 1 : $page;
- $count = empty($count) ? 1 : $count;
- $alarmData = $this->Alarm_model->getOne($alarmid,'A.lampid,A.alarmtype');
- $field = 'RI.repair_hitch,RI.repair_path,RI.repair_solution,RI.repair_time,RU.name';
- $repair_list = $this->Repair_model->get_repair_info_list(array('RI.lampid'=>$alarmData['lampid'],'page'=>$page,'count'=>$count),$field);
- $total = $this->Repair_model->get_repair_total(array('RI.lampid'=>$alarmData['lampid']));
- if (empty($repair_list)) {
- exit(json_result('0616',$this->response['0616'],array()));
- }
- exit(json_result('0000',$this->response['0000'],array('list'=>$repair_list,'total'=>ceil($total/$count))));
- }
- // 添加编辑推送人员
- public function save_alarm_send_user(){
- $id = intval($this->input->post('id',true));
- $userId = $this->get_user_info('id');
- $name = $this->input->post('name',true);
- $email = $this->input->post('email',true);
- $phone = $this->input->post('phone',true);
- $project = $this->input->post('project',true);
- $project = $project === null ? '' : $project;
- if ($phone === '' || $phone === null) exit(json_result('0607',$this->response['0607']));
- if ($email === '' || $email === null) exit(json_result('0618',$this->response['0618']));
- $config = array();
- // $config[] = array(
- // 'field' => 'phone',
- // 'label' => 'Phone',
- // 'rules' => 'required|numeric|exact_length[11]',
- // 'errors' => array(
- // 'numeric' => '0406',
- // 'exact_length' => '0406',
- // )
- // );
-
- $config[] = array(
- 'field' => 'email',
- 'label' => 'Email',
- 'rules' => 'required|valid_email',
- 'errors' => array(
- 'valid_email' => '0719',
- )
- );
- $this->load->library('form_validation');
- $this->form_validation->set_rules($config);
- if ($this->form_validation->run() == FALSE){
- $errors = $this->form_validation->error_array();
- exit(json_result(current($errors),$this->response[current($errors)]));
- }
- if (empty($id)) {
- if ($this->AlarmSendUserInfo_model->getDataCount(['email'=>$email])) exit(json_result('0722',$this->response['0722']));
- if ($this->AlarmSendUserInfo_model->getDataCount(['phone'=>$phone])) exit(json_result('0721',$this->response['0721']));
- if ($this->AlarmSendUserInfo_model->getDataCount(['name'=>$name,'userId'=>$userId])) exit(json_result('0619',$this->response['0619']));
- $data = array('name'=>$name,'email'=>$email,'phone'=>$phone,'project'=>$project,'userId'=>$userId);
- $data['createTime'] = date('Y-m-d H:i:s',time());
- $this->AlarmSendUserInfo_model->add($data);
- }else{
- if ($this->AlarmSendUserInfo_model->getDataCount(['email'=>$email],$id)) exit(json_result('0722',$this->response['0722']));
- if ($this->AlarmSendUserInfo_model->getDataCount(['phone'=>$phone],$id)) exit(json_result('0721',$this->response['0721']));
- if ($this->AlarmSendUserInfo_model->getDataCount(['name'=>$name,'userId'=>$userId],$id)) exit(json_result('0619',$this->response['0619']));
- $data = array('name'=>$name,'email'=>$email,'phone'=>$phone,'project'=>$project,'userId'=>$userId);
- $this->AlarmSendUserInfo_model->update($data,['id'=>$id]);
- }
- exit(json_result('0000',$this->response['0000']));
- }
- // 推送人员列表
- public function alarm_send_user_list(){
- $userId = $this->get_user_info('id');
- $where = ['userId'=>$userId];
- $page = intval($this->input->post('page'));
- $count = intval($this->input->post('count'));
- $page = empty($page) ? 1 : $page;
- $limit = empty($count) ? 10 : $count;
- $offset = ($page - 1) * $limit;
- $keyword = $this->input->post('keyword',true);
- if ($keyword === '' || $keyword === null) $where['name|'] = $keyword;
- $list = $this->AlarmSendUserInfo_model->get_list($where, 'id,name,email,project,phone,is_send',$limit, $offset, 'convert(name using gbk) asc,id desc', NUll);
- $total = $this->AlarmSendUserInfo_model->get_count($where);
- exit(json_result('0000',$this->response['0000'],['list'=>$list,'total'=>$total]));
- }
- // 删除推送人员
- public function del_alarm_send_user(){
- $id = $this->input->post('id',true);
- if ($id === '' || $id === null) exit(json_result('0007',$this->response['0007']));
- $idArr = explode(',', $id);
- foreach ($idArr as $id) {
- $this->AlarmSendUserInfo_model->delete(['id'=>$id]);
- }
- exit(json_result('0000',$this->response['0000']));
- }
- // 是否开启推送
- public function set_alarm_send_user_status(){
- $id = intval($this->input->post('id',true));
- $status = intval($this->input->post('status',true));
- if (empty($id)) exit(json_result('0007',$this->response['0007']));
- $is_send = empty($status) ? 0 : 1;
- $this->AlarmSendUserInfo_model->update(['is_send'=>$is_send],['id'=>$id]);
- exit(json_result('0000',$this->response['0000']));
- }
-
- }
|