123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- include_once(FCPATH . 'application/controllers/API_Controller.php');
- class Alarm extends API_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');
- }
-
- // 获取告警信息列表
- public function get(){
- $filter = array();
- $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));
- // 时间筛选
- $endDate = $this->input->post('endDate',true);
- $startDate = $this->input->post('startDate',true);
- $type = intval($this->input->post('type',true));
- $version = $this->session->userdata('version');
- if (!empty($version)) {
- $alarmtype = alarm_translate_ch($alarmtype);
- }
- $page = !isset($page) ? 1 : $page;
- $count = empty($count) ? 20 : $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'];
- }
- if(!empty($alarmtype)) $filter['alarmtype'] = $alarmtype;
- if(isset($endDate)) $filter['endDate'] = $endDate;
- 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);
- }else{
- $alarm = $this->Alarm_model->getList($filter, $role, $user_id, $page, $count);
- }
-
- $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);
- }
- }
- }
- $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);
- }
- 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(
- 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($filter, $data);
- if ($status == 1) {
- foreach ($ids as $v) {
- $alarmData = $this->Alarm_model->getOne($v,'A.lampid,A.alarmtype');
- 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');
- $companyid = $this->get_user_info('companyid');
- $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;
- // 信息字段
- $field = "L.id,
- N.id as networkid,
- P.id as projectid,
- N.networkname as network_name,
- P.projectname as project_name,
- L.number,
- cmd.patroltype,
- cmd.patrolinterval,
- cmd.updatetime";
- $fiter =array();
- $section = $this->input->post('section',true);
-
- if (!empty($section)) $fiter['section'] = $section;
- if (!empty($keyword)) $fiter['keyword'] = $keyword;
- if (isset($status)) $fiter['status'] = $status;
-
- if (empty($download)) {
- // 获取巡检信息列表
- if (isset($print) && !empty($print)) {
- $data = $this->Patrol_model->getList($role,$companyid,$projectid,$userid,$fiter,$field,$page,$count,1);
- }else{
- $data = $this->Patrol_model->getList($role,$companyid,$projectid,$userid,$fiter,$field,$page,$count);
- }
-
- // 获取巡检信息总数
- $total = $this->Patrol_model->getTotal($role,$companyid,$projectid,$userid,$fiter);
- json_result('0000',$this->response['0000'],array('patrol_list'=>$data,'total'=>ceil($total/$count)));
- }else{
- // 获取巡检信息列表
- $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','Network name','Lamp Number','Patrol order','Inspection interval time(min)','Parameter setting time'),
- );
- }
-
- $temp = array();
- $i = ($page-1)*$count + 1;
- foreach ($data as $k=>$v) {
- $temp[$k][] = $i;
- $temp[$k][] = $v['project_name'];
- $temp[$k][] = $v['network_name'];
- $temp[$k][] = $v['number'];
- if (empty($version)) {
- $temp[$k][] = $v['patroltype'] == 1 ? '开' : '关';
- }else{
- $temp[$k][] = $v['patroltype'] == 1 ? 'on' : 'off';
- }
-
- $temp[$k][] = $v['patrolinterval'];
- $temp[$k][] = $v['updatetime'];
- $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))));
- }
- }
|