Home.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. include_once(FCPATH . 'application/controllers/Base_Controller.php');
  3. class Home extends Base_Controller {
  4. public function __construct() {
  5. parent::__construct();
  6. $this->load->model('Lamp_model');
  7. $this->load->model('Project_model');
  8. $this->load->model('Global_location_model');
  9. }
  10. private function get_project_id(){
  11. $cityId = intval($this->input->post('cityId',true));
  12. $proId = intval($this->input->post('proId',true));
  13. $projectIdArr = array();
  14. $areaList = array();
  15. $cityList = array();
  16. $proList = array();
  17. if (!empty($proId)) {
  18. $proList[] = array('id'=>$proId,'level'=>1);
  19. $list = $this->Global_location_model->get_list(['pid'=>$proId],'id,level');
  20. foreach ($list as $key => $value) {
  21. if ($value['level'] == 3) {
  22. $cityList[] = $value;
  23. }elseif ($value['level'] == 4) {
  24. $areaList[] = $value;
  25. }
  26. }
  27. }
  28. if (!empty($cityId)) {
  29. $cityList[] = array('id'=>$cityId,'level'=>2);
  30. $list = $this->Global_location_model->get_list(['pid'=>$cityId],'id,level');
  31. foreach ($list as $key => $value) {
  32. if ($value['level'] == 4) $areaList[] = $value;
  33. }
  34. }
  35. $cityArr = array_unique(array_merge(array_column($proList, 'id'),array_column($cityList, 'id'),array_column($areaList, 'id')));
  36. if (!empty($cityArr)) {
  37. $res = $this->Project_model->get_list(['cityid'=>$cityArr],'id');
  38. $projectIdArr = array_unique(array_column($res, 'id'));
  39. }
  40. return $projectIdArr;
  41. }
  42. // 设备统计信息
  43. public function data(){
  44. $projectIdArr = $this->get_project_id();
  45. $data = array(
  46. 'day_new_count' => 0,
  47. 'day_faulty_count' => 0,
  48. 'total_light_count' => 0,
  49. 'light_up_count' => 0,
  50. 'online_count' => 0,
  51. 'faulty_count' => 0
  52. );
  53. $createTime = $this->get_user_info('createTime');
  54. $data['logCount'] = empty($createTime) ? 0 : ceil((time() - strtotime($createTime))/(3600 * 24));
  55. $date = date('Y-m-d H:i:s',strtotime(date('Y-m-d 00:00:00',time())) - 6*3600);
  56. $role = $this->get_user_info('role');
  57. if ($role == SYSTEM_ADMIN) {
  58. $data['total_light_count'] = $this->Lamp_model->get_count();
  59. $where = ['createtime >='=>$date];
  60. if (!empty($projectIdArr)) $where['projectid'] = $projectIdArr;
  61. $data['day_new_count'] = $this->Lamp_model->get_count($where);
  62. $where = ['netstatus'=>1,'status'=>1];
  63. if (!empty($projectIdArr)) $where['projectid'] = $projectIdArr;
  64. $data['light_up_count'] = $this->Lamp_model->get_count($where);
  65. $where = ['netstatus'=>1];
  66. if (!empty($projectIdArr)) $where['projectid'] = $projectIdArr;
  67. $data['online_count'] = $this->Lamp_model->get_count($where);
  68. // $where = ['netstatus'=>1,'devstatus !='=>0];
  69. // if (!empty($projectIdArr)) $where['projectid'] = $projectIdArr;
  70. // $data['faulty_count'] = $this->Lamp_model->get_count($where);
  71. // $where = ['netstatus'=>1,'logtime >='=>$date,'devstatus !='=>0];
  72. // if (!empty($projectIdArr)) $where['projectid'] = $projectIdArr;
  73. // $data['day_faulty_count'] = $this->Lamp_model->get_count($where);
  74. $where = ['L.netstatus ='=>1];
  75. if (!empty($projectIdArr)) $where['L.projectid'] = $projectIdArr;
  76. $where1 = [];
  77. foreach ($where as $key => $value) {
  78. if (is_array($value)) {
  79. $where1[] = $key.' in ('.implode(',', $value).')';
  80. }else{
  81. $where1[] = $key.' '.$value;
  82. }
  83. }
  84. $where1[] = '(WI.batstatus != 0 OR WI.panelstatus != 0 OR WI.lampstatus != 0 OR WI.tempstatus != 0)';
  85. $where1 = implode(' AND ', $where1);
  86. $join = [];
  87. $join[] = ['table'=>'(select w1.* from warning_info_log as w1 join (select lampid,max(updatetime) as maxTime from warning_info_log group by lampid) as w2 on w1.lampid = w2.lampid AND w1.updatetime = w2.maxTime) as WI','cond'=>'L.id = WI.lampid','type'=>'inner'];
  88. $total = $this->Lamp_model->get_list_by_multi_join($where1, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  89. $data['faulty_count'] = $total['total'];
  90. $where1 .= ' AND WI.updatetime >= "'.$date.'"';
  91. $total = $this->Lamp_model->get_list_by_multi_join($where1, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  92. $data['day_faulty_count'] = $total['total'];
  93. }else{
  94. $company = $this->get_user_info('company');
  95. $where = ['P.company ='=>$company];
  96. if (!empty($projectIdArr)) $where['P.id'] = $projectIdArr;
  97. $join = [
  98. ['table'=>'project as P','cond'=>'P.id = L.projectid','type'=>'inner']
  99. ];
  100. $total = $this->Lamp_model->get_list_by_multi_join($where, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  101. $data['total_light_count'] = $total['total'];
  102. $where['L.createtime >='] = $date;
  103. $total = $this->Lamp_model->get_list_by_multi_join($where, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  104. $data['day_new_count'] = $total['total'];
  105. unset($where['L.createtime >=']);
  106. $where['L.netstatus ='] = 1;
  107. $total = $this->Lamp_model->get_list_by_multi_join($where, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  108. $data['online_count'] = $total['total'];
  109. $where['L.status ='] = 1;
  110. $total = $this->Lamp_model->get_list_by_multi_join($where, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  111. $data['light_up_count'] = $total['total'];
  112. unset($where['L.status']);
  113. // $where['L.devstatus !='] = 0;
  114. $where1 = [];
  115. foreach ($where as $key => $value) {
  116. if (is_array($value)) {
  117. $where1[] = $key.' in ('.implode(',', $value).')';
  118. }else {
  119. $where1[] = $key.' '.$value;
  120. }
  121. }
  122. $where1[] = '(WI.batstatus != 0 OR WI.panelstatus != 0 OR WI.lampstatus != 0 OR WI.tempstatus != 0)';
  123. $where1 = implode(' AND ', $where1);
  124. $join[] = ['table'=>'(select w1.* from warning_info_log as w1 join (select lampid,max(updatetime) as maxTime from warning_info_log group by lampid) as w2 on w1.lampid = w2.lampid AND w1.updatetime = w2.maxTime) as WI','cond'=>'L.id = WI.lampid','type'=>'inner'];
  125. $total = $this->Lamp_model->get_list_by_multi_join($where1, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  126. $data['faulty_count'] = $total['total'];
  127. // $where['L.devstatus !='] = 0;
  128. $where1 .= ' AND WI.updatetime >= "'.$date.'"';
  129. $total = $this->Lamp_model->get_list_by_multi_join($where1, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  130. $data['day_faulty_count'] = $total['total'];
  131. }
  132. exit(json_result('0000',$this->response['0000'],$data));
  133. }
  134. // 发用电量统计信息
  135. public function sta_info(){
  136. $data = array(
  137. 'electricity' => 0,
  138. 'CO2_reduction' => 0,
  139. 'SO2_reduction' => 0,
  140. 'TCE_reduction' => 0
  141. );
  142. $type = intval($this->input->post('type',true));
  143. $projectIdArr = $this->get_project_id();
  144. $role = $this->get_user_info('role');
  145. $type = $this->input->post('type',true);
  146. $where = array();
  147. if ($role != SYSTEM_ADMIN){
  148. $company = $this->get_user_info('company');
  149. $where['P.company'] = $company;
  150. }
  151. if (!empty($projectIdArr)) $where['L.projectid'] = $projectIdArr;
  152. if ($type == 0) {
  153. $join = [];
  154. $join[] = ['table'=>'project as P','cond'=>'L.projectid = P.id','type'=>'left'];
  155. $join[] = ['table'=>'(select w1.* from realtime_info_log as w1 join (select lampid,max(updatetime) as maxTime from realtime_info_log group by lampid) as w2 on w1.lampid = w2.lampid AND w1.updatetime = w2.maxTime) as RI','cond'=>'L.id = RI.lampid','type'=>'inner'];
  156. $res = $this->Lamp_model->get_list_by_multi_join($where, 'sum(RI.dischargeday) as discharge,sum(RI.chargeday) as charge',NULL, NULL, $join, NULL, NUll, 'L', true);
  157. }elseif ($type == 1) {
  158. $join = [];
  159. $join[] = ['table'=>'project as P','cond'=>'L.projectid = P.id','type'=>'left'];
  160. $join[] = ['table'=>'(select w1.* from history_info_log as w1 join (select lampid,max(updatetime) as maxTime from history_info_log group by lampid) as w2 on w1.lampid = w2.lampid AND w1.updatetime = w2.maxTime) as RI','cond'=>'L.id = RI.lampid','type'=>'inner'];
  161. $res = $this->Lamp_model->get_list_by_multi_join($where, 'sum(RI.weekdischarg) as discharge,sum(RI.weekchargeah) as charge',NULL, NULL, $join, NULL, NUll, 'L', true);
  162. }elseif ($type == 2) {
  163. $join = [];
  164. $join[] = ['table'=>'project as P','cond'=>'L.projectid = P.id','type'=>'left'];
  165. $join[] = ['table'=>'(select w1.* from history_info_log as w1 join (select lampid,max(updatetime) as maxTime from history_info_log group by lampid) as w2 on w1.lampid = w2.lampid AND w1.updatetime = w2.maxTime) as RI','cond'=>'L.id = RI.lampid','type'=>'inner'];
  166. $res = $this->Lamp_model->get_list_by_multi_join($where, 'sum(RI.monthdischarge) as discharge,sum(RI.monthchargeah) as charge',NULL, NULL, $join, NULL, NUll, 'L', true);
  167. }else{
  168. $join = [];
  169. $join[] = ['table'=>'project as P','cond'=>'L.projectid = P.id','type'=>'left'];
  170. $join[] = ['table'=>'(select w1.* from history_info_log as w1 join (select lampid,max(updatetime) as maxTime from history_info_log group by lampid) as w2 on w1.lampid = w2.lampid AND w1.updatetime = w2.maxTime) as RI','cond'=>'L.id = RI.lampid','type'=>'inner'];
  171. $res = $this->Lamp_model->get_list_by_multi_join($where, 'sum(RI.totaldischarah) as discharge,sum(RI.totalchargeah) as charge',NULL, NULL, $join, NULL, NUll, 'L', true);
  172. }
  173. $data['electricity'] = $res['discharge'];
  174. $data['CO2_reduction'] = $res['discharge'];
  175. $data['SO2_reduction'] = $res['discharge'];
  176. $data['TCE_reduction'] = $res['discharge'];
  177. $data['CO2_reduction'] = round($res['charge']*0.977, 3);
  178. $data['SO2_reduction'] = round($res['charge']*0.977/2620*8.5*1000, 3);
  179. $data['TCE_reduction'] = round($res['charge']*0.977/2620*1000, 3);
  180. exit(json_result('0000',$this->response['0000'],$data));
  181. }
  182. // 设备统计列表
  183. public function dev_list(){
  184. $projectIdArr = $this->get_project_id();
  185. $role = $this->get_user_info('role');
  186. $type = $this->input->post('type',true);
  187. $where = array();
  188. if ($role != SYSTEM_ADMIN){
  189. $company = $this->get_user_info('company');
  190. $where[] = 'P.company = '.$company;
  191. }
  192. if ($type == 2) {
  193. $fields = 'L.manu as company';
  194. $group = 'group by L.manu';
  195. $where[] = 'L.manu != 0';
  196. $where[] = 'L.manu != ""';
  197. }elseif ($type == 3) {
  198. $fields = 'L.supplier as company';
  199. $group = 'group by L.supplier';
  200. $where[] = 'L.supplier != 0';
  201. $where[] = 'L.supplier != ""';
  202. }elseif ($type == 4) {
  203. $fields = 'L.po as company';
  204. $group = 'group by L.po';
  205. $where[] = 'L.po != 0';
  206. $where[] = 'L.po != ""';
  207. }else{
  208. $fields = 'L.upazilla as company';
  209. $group = 'group by L.upazilla';
  210. $where[] = 'L.upazilla != 0';
  211. $where[] = 'L.upazilla != ""';
  212. }
  213. if (!empty($projectIdArr)) $where[] = 'L.projectid in ('.implode(',', $projectIdArr).')';
  214. $where1 = empty($where) ? '' : 'where '.implode(' AND ', $where);
  215. $query = 'select t1.total,C.name,C.id from (select count(*) as total,'.$fields.' from lampinfo AS L left join project AS P on P.id = L.projectid '.$where1.' '.$group.') as t1 left join company as C on t1.company = C.id order by total DESC limit 10';
  216. $list = $this->db->query($query)->result_array();
  217. if (empty($list)) exit(json_result('0000',$this->response['0000'],array('list'=>array())));
  218. $temp = array();
  219. $allDev = array_sum(array_column($list, 'total'));
  220. foreach ($list as $key => $value) {
  221. $totalPer = empty($allDev) ? '0%' : round($value['total']/$allDev*100,2).'%';
  222. $temp2 = array('name'=>$value['name'],'total'=>$value['total'],'onlineCount'=>0,'offlineCount'=>0,'faultCount'=>0,'totalPer'=>$totalPer);
  223. $temp[$value['id']] = $temp2;
  224. }
  225. $companyArr = array_unique(array_column($list, 'id'));
  226. if ($type == 2) {
  227. $where[] = 'L.manu in ('.implode(',', $companyArr).')';
  228. }elseif ($type == 3) {
  229. $where[] = 'L.supplier in ('.implode(',', $companyArr).')';
  230. }elseif ($type == 4) {
  231. $where[] = 'L.po in ('.implode(',', $companyArr).')';
  232. }else{
  233. $where[] = 'L.upazilla in ('.implode(',', $companyArr).')';
  234. }
  235. $where1 = $where;
  236. $where1[] = 'L.netstatus = 0';
  237. $where1 = 'where '.implode(' AND ', $where1);
  238. $query = 'select t1.total,C.id from (select count(*) as total,'.$fields.' from lampinfo AS L left join project AS P on P.id = L.projectid '.$where1.' '.$group.') as t1 left join company as C on t1.company = C.id order by total DESC limit 10';
  239. $list = $this->db->query($query)->result_array();
  240. foreach ($list as $key => $value) {
  241. if (isset($temp[$value['id']])) $temp[$value['id']]['offlineCount'] = $value['total'];
  242. }
  243. $where1 = $where;
  244. $where1[] = 'L.netstatus = 1';
  245. $where1 = 'where '.implode(' AND ', $where1);
  246. $query = 'select t1.total,C.id from (select count(*) as total,'.$fields.' from lampinfo AS L left join project AS P on P.id = L.projectid '.$where1.' '.$group.') as t1 left join company as C on t1.company = C.id order by total DESC limit 10';
  247. $list = $this->db->query($query)->result_array();
  248. foreach ($list as $key => $value) {
  249. if (isset($temp[$value['id']])) $temp[$value['id']]['onlineCount'] = $value['total'];
  250. }
  251. $where1 = $where;
  252. $where1[] = 'L.netstatus = 1';
  253. $where1[] = '(WI.batstatus != 0 OR WI.panelstatus != 0 OR WI.lampstatus != 0 OR WI.tempstatus != 0)';
  254. $where1 = 'where '.implode(' AND ', $where1);
  255. $query = 'select t1.total,C.id from (select count(*) as total,'.$fields.' from lampinfo AS L join project AS P on P.id = L.projectid join (select w1.lampid,w1.batstatus,w1.panelstatus,w1.lampstatus,w1.tempstatus from warning_info_log as w1 join (select lampid,max(updatetime) as maxTime from warning_info_log group by lampid) as w2 on w1.updatetime = w2.maxTime AND w1.lampid = w2.lampid) as WI on WI.lampid = L.id '.$where1.' '.$group.') as t1 left join company as C on t1.company = C.id order by total DESC limit 10';
  256. $list = $this->db->query($query)->result_array();
  257. foreach ($list as $key => $value) {
  258. if (isset($temp[$value['id']])) $temp[$value['id']]['faultCount'] = $value['total'];
  259. }
  260. $list = array_values($temp);
  261. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  262. }
  263. // 故障信息列表
  264. public function alarm_list(){
  265. $projectIdArr = $this->get_project_id();
  266. $role = $this->get_user_info('role');
  267. $where = array();
  268. if ($role != SYSTEM_ADMIN){
  269. $company = $this->get_user_info('company');
  270. $where[] = 'P.company = '.$company;
  271. }
  272. if (!empty($projectIdArr)) $where[] = 'P.id in ('.implode(',', $projectIdArr).')';
  273. $where[] = '(WI.batstatus != 0 OR WI.panelstatus != 0 OR WI.lampstatus != 0 OR WI.tempstatus != 0)';
  274. $where[] = 'L.netstatus = 1';
  275. $where1 = implode(' AND ', $where);
  276. $join = [
  277. ['table'=>'project as P','cond'=>'P.id = L.projectid','type'=>'inner']
  278. ];
  279. $join[] = ['table'=>'(select w1.* from warning_info_log as w1 join (select lampid,max(updatetime) as maxTime from warning_info_log group by lampid) as w2 on w1.lampid = w2.lampid AND w1.updatetime = w2.maxTime) as WI','cond'=>'L.id = WI.lampid','type'=>'inner'];
  280. $join[] = ['table'=>'global_location as G1','cond'=>'G1.id = P.cityid','type'=>'inner'];
  281. $join[] = ['table'=>'global_location as G2','cond'=>'G2.id = G1.pid','type'=>'inner'];
  282. $join[] = ['table'=>'global_location as G3','cond'=>'G3.id = G2.pid','type'=>'inner'];
  283. $list = $this->Lamp_model->get_list_by_join($where1, 'P.projectname as project,WI.batstatus,WI.id,WI.panelstatus,WI.lampstatus,WI.tempstatus,P.cityid,L.address,L.section,G1.english_name as areaName,G2.english_name as cityName,G3.english_name as proName,WI.updatetime,G1.timezone',NULL, NULL, $join, NULL, NUll, 'L');
  284. $batstatus = $this->config->item('batstatus');
  285. $panelstatus = $this->config->item('panelstatus');
  286. $lampstatus = $this->config->item('lampstatus');
  287. $tempstatus = $this->config->item('tempstatus');
  288. foreach ($list as $key => $value) {
  289. $location = $value['proName'].'/'.$value['cityName'].'/'.$value['areaName'];
  290. $location = empty($value['section']) ? $location : $location.'/'.$value['section'];
  291. $list[$key]['location'] = $location;
  292. $list[$key]['fault_time'] = set_timezone($value['updatetime'],$value['timezone']);
  293. $temp2 = array();
  294. if (isset($batstatus[$value['batstatus']])) $temp2[] = $batstatus[$value['batstatus']];
  295. if (isset($panelstatus[$value['panelstatus']])) $temp2[] = $panelstatus[$value['panelstatus']];
  296. if (isset($lampstatus[$value['lampstatus']])) $temp2[] = $lampstatus[$value['lampstatus']];
  297. if (isset($tempstatus[$value['tempstatus']])) $temp2[] = $tempstatus[$value['tempstatus']];
  298. $list[$key]['fault_type'] = implode(',', $temp2);
  299. unset($list[$key]['cityName']);
  300. unset($list[$key]['proName']);
  301. unset($list[$key]['areaName']);
  302. unset($list[$key]['section']);
  303. unset($list[$key]['timezone']);
  304. unset($list[$key]['updatetime']);
  305. }
  306. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  307. }
  308. // 字段管理
  309. public function fields(){
  310. $userid = $this->get_user_info('id');
  311. $data = $this->User_model->get_user_field($userid);
  312. if (empty($data) || empty($data['lampfield'])) {
  313. // $fieldstr = "number,lampstatus,updatetime,lighteness,address,lamppower,chargestage,battvoltage,overtimes,solarpower,isfaulted,status,section";
  314. $fieldstr = "number,lampstatus,updatetime,lighteness,address,lamppower,chargestage,battvoltage,overtimes,solarpower,isfaulted,status,section";
  315. }else{
  316. if ($data['lampfield'] == 'number,lampstatus,updatetime,lighteness,address,lamppower,chargestage,battvoltage,overtimes,solarpower,isfaulted,status') {
  317. $data['lampfield'] .= ',section';
  318. }
  319. $fieldstr = $data['lampfield'];
  320. }
  321. // 系统默认
  322. $def = array(
  323. array('name'=>'路灯编号','field'=>'L.number','fields1'=>'number','enname'=>'Lamp number'),
  324. array('name'=>'路段','field'=>'L.section','fields1'=>'section','enname'=>'Road'),
  325. // array('name'=>'路灯状态','field'=>'L.status as lampstatus,L.lighteness','fields1'=>'lampstatus','enname'=>'Lamp status'),
  326. array('name'=>'信号状态','field'=>'L.protocoltype,L.netstatus as status,L.rssi','fields1'=>'status','enname'=>'Network status'),
  327. // array('name'=>'信号状态','field'=>'L.protocoltype,L.netstatus as status,N.rssi,N.snr','fields1'=>'status','enname'=>'Network status'),
  328. array('name'=>'更新时间','field'=>'RI.updatetime','fields1'=>'updatetime','enname'=>'Update time'),
  329. array('name'=>'路灯亮度(%)','field'=>'L.lighteness','fields1'=>'lighteness','enname'=>'Brightness(%)'),
  330. array('name'=>'无线模块地址','field'=>'L.address','fields1'=>'address','enname'=>'Wireless module address'),
  331. array('name'=>'负载功率(W)','field'=>'RI.loadpower','fields1'=>'loadpower','enname'=>'LED power(W)'),
  332. array('name'=>'蓄电池电压(V)','field'=>'RI.batpower as battvoltage','fields1'=>'battvoltage','enname'=>'Battery voltage(V)'),
  333. array('name'=>'蓄电池总过放次数','field'=>'HI.overtimes','fields1'=>'overtimes','enname'=>'Over discharge times'),
  334. array('name'=>'太阳能板功率(W)','field'=>'RI.panelpower as solarpower','fields1'=>'solarpower','enname'=>'Solar panel power(W)'),
  335. array('name'=>'是否故障','field'=>'AI.batstatus,AI.panelstatus,AI.lampstatus,AI.tempstatus,AI.status as alarmStatus','fields1'=>'isfaulted','enname'=>'Fault'),
  336. );
  337. // $def = array(
  338. // array('name'=>'路灯编号','field'=>'L.number','fields1'=>'number','enname'=>'Lamp number'),
  339. // array('name'=>'路段','field'=>'L.section','fields1'=>'section','enname'=>'Road'),
  340. // array('name'=>'路灯状态','field'=>'L.status as lampstatus,L.lighteness','fields1'=>'lampstatus','enname'=>'Lamp status'),
  341. // array('name'=>'信号状态','field'=>'L.protocoltype,L.netstatus as status','fields1'=>'status','enname'=>'Network status'),
  342. // // array('name'=>'信号状态','field'=>'L.protocoltype,L.netstatus as status,N.rssi,N.snr','fields1'=>'status','enname'=>'Network status'),
  343. // array('name'=>'更新时间','field'=>'L.logtime as updatetime','fields1'=>'updatetime','enname'=>'Update time'),
  344. // array('name'=>'路灯亮度(%)','field'=>'L.lighteness','fields1'=>'lighteness','enname'=>'Brightness(%)'),
  345. // array('name'=>'无线模块地址','field'=>'L.address','fields1'=>'address','enname'=>'Wireless module address'),
  346. // array('name'=>'路灯功率(W)','field'=>'L.lamppower','fields1'=>'lamppower','enname'=>'Lamp power(W)'),
  347. // array('name'=>'蓄电池充电阶段','field'=>'L.chargestage','fields1'=>'chargestage','enname'=>'Charging stage'),
  348. // array('name'=>'蓄电池电压(V)','field'=>'L.battvoltage','fields1'=>'battvoltage','enname'=>'Battery voltage(V)'),
  349. // array('name'=>'蓄电池总过放次数','field'=>'L.overtimes','fields1'=>'overtimes','enname'=>'Over discharge times'),
  350. // array('name'=>'太阳能板功率(W)','field'=>'L.solarpower','fields1'=>'solarpower','enname'=>'Solar panel power(W)'),
  351. // array('name'=>'是否故障','field'=>'L.isfaulted','fields1'=>'isfaulted','enname'=>'Fault'),
  352. // );
  353. // 路灯信息
  354. $lampinfo = array(
  355. array('name'=>'当前策略','field'=>'L.policyid','fields1'=>'policyid','enname'=>'Current strategy'),
  356. array('name'=>'路灯id','field'=>'L.id','fields1'=>'id','enname'=>'Lamp ID'),
  357. // array('name'=>'网络名称','field'=>'N.networkname','fields1'=>'networkname','enname'=>'Network name'),
  358. array('name'=>'项目名称','field'=>'P.projectname','fields1'=>'projectname','enname'=>'Project name'),
  359. array('name'=>'经度','field'=>'L.longitude','fields1'=>'longitude','enname'=>'Longitude'),
  360. array('name'=>'纬度','field'=>'L.latitude','fields1'=>'latitude','enname'=>'Latitude'),
  361. // array('name'=>'sim卡号','field'=>'N.simid','fields1'=>'simid','enname'=>'SIM card number'),
  362. // array('name'=>'套餐剩余','field'=>'N.packageSurplus','fields1'=>'packageSurplus','enname'=>'Package surplus'),
  363. array('name'=>'路灯类型','field'=>'L.lamptype','fields1'=>'lamptype','enname'=>'Lamp type'),
  364. array('name'=>'太阳能板类型','field'=>'L.boardtype','fields1'=>'boardtype','enname'=>'Solar panel type'),
  365. // array('name'=>'太阳能板功率(W)','field'=>'L.boardpower','fields1'=>'boardpower','enname'=>'Solar panel power(W)'),
  366. // array('name'=>'蓄电池类型','field'=>'L.batterytype','fields1'=>'batterytype','enname'=>'Battery type'),
  367. array('name'=>'蓄电池AH数(ah)','field'=>'HI.totalchargeah as batteryah','fields1'=>'batteryah','enname'=>'Battery capacity(ah)'),
  368. // array('name'=>'负载功率(W)','field'=>'L.loadpower','fields1'=>'loadpower','enname'=>'Load power(W)'),
  369. // array('name'=>'蓄电池剩余电量','field'=>'L.electricleft','fields1'=>'electricleft','enname'=>'Remaining battery capacity(Ah)'),
  370. );
  371. // 路灯信息日志
  372. $lamp_info_log = array(
  373. array('name'=>'路灯电压(V)','field'=>'RI.loadvoltage as lampvoltage','fields1'=>'lampvoltage','enname'=>'Lamp voltage(V)'),
  374. array('name'=>'路灯电流(A)','field'=>'RI.loadcurrent as lampcurrent','fields1'=>'lampcurrent','enname'=>'Lamp current(A)'),
  375. // array('name'=>'灯头温度(℃)','field'=>'L.lamptemper as temper','fields1'=>'temper','enname'=>'Lamp temperature(℃)'),
  376. );
  377. $solar_info_log = array(
  378. array('name'=>'太阳能板电压(V)','field'=>'RI.panelvoltage as solarvoltage','fields1'=>'solarvoltage','enname'=>'Solar panel voltage(V)'),
  379. array('name'=>'太阳能板电流(A)','field'=>'RI.panelcurrent as solarcurrent','fields1'=>'solarcurrent','enname'=>'Solar panel current(A)')
  380. );
  381. // 蓄电池信息日志
  382. // $battery_info_log = array(
  383. // array('name'=>'蓄电池状态','field'=>'L.battstatus','fields1'=>'battstatus','enname'=>'Battery status'),
  384. // array('name'=>'蓄电池充电电流(A)','field'=>'L.chargecurrent','fields1'=>'chargecurrent','enname'=>'Charging current(A)'),
  385. // array('name'=>'蓄电池放电电流(A)','field'=>'L.discharcurrent','fields1'=>'discharcurrent','enname'=>'Discharging current(A)'),
  386. // array('name'=>'蓄电池充电功率(w)','field'=>'L.chargepower','fields1'=>'chargepower','enname'=>'Charging power(w)'),
  387. // array('name'=>'蓄电池放电功率(w)','field'=>'L.dischargepower','fields1'=>'dischargepower','enname'=>'Discharging power(w)'),
  388. // array('name'=>'蓄电池表面温度(℃)','field'=>'L.batttemper','fields1'=>'batttemper','enname'=>'Battery surface temperature(℃)'),
  389. // array('name'=>'蓄电池总电量','field'=>'L.electrictotal','fields1'=>'electrictotal','enname'=>'Total battery capacity(Ah)'),
  390. // array('name'=>'蓄电池电量SOC(%)','field'=>'L.electricSOC','fields1'=>'electricSOC','enname'=>'Battery SOC(%)'),
  391. // array('name'=>'当天最低电压(V)','field'=>'L.voltagedaymin','fields1'=>'voltagedaymin','enname'=>'Minimum voltage(V)'),
  392. // array('name'=>'当天最高电压(V)','field'=>'L.voltagedaymax','fields1'=>'voltagedaymax','enname'=>'Highest voltage(V)'),
  393. // array('name'=>'当天充电安时数(ah)','field'=>'L.daychargeah','fields1'=>'daychargeah','enname'=>'Charging AH(ah)'),
  394. // array('name'=>'当天放电安时数(ah)','field'=>'L.daydischarah','fields1'=>'daydischarah','enname'=>'Discharging AH(ah)'),
  395. // array('name'=>'当天充电最大功率(W)','field'=>'L.daychargemaxpow','fields1'=>'daychargemaxpow','enname'=>'Charging max-power(W)'),
  396. // array('name'=>'当天放电最大功率(W)','field'=>'L.daydischarmaxpow','fields1'=>'daydischarmaxpow','enname'=>'Discharging max-power(W)'),
  397. // array('name'=>'当天灯亮时间(hh:mm)','field'=>'L.daychargemincurrent','fields1'=>'daychargemincurrent','enname'=>'Turn-on duration'),
  398. // array('name'=>'当天充电最大电流(A)','field'=>'L.daycharmaxcurrent','fields1'=>'daycharmaxcurrent','enname'=>'Highest charging current(A)'),
  399. // array('name'=>'当天充电时间(hh:mm)','field'=>'L.daydischargemincurrent','fields1'=>'daydischargemincurrent','enname'=>'Charging duration'),
  400. // array('name'=>'当天放电最大电流(A)','field'=>'L.daydischarmaxcurrent','fields1'=>'daydischarmaxcurrent','enname'=>'Highest discharging current(A)'),
  401. // array('name'=>'当天蓄电池最低温度(℃)','field'=>'L.daybattmintemper','fields1'=>'daybattmintemper','enname'=>'Battery min-temperature(℃)'),
  402. // array('name'=>'当天蓄电池最高温度(℃)','field'=>'L.daybattmaxtemper','fields1'=>'daybattmaxtemper','enname'=>'Battery max-temperature(℃)'),
  403. // );
  404. $electric_info_log = array(
  405. array('name'=>'当天发电量(kWh)','field'=>'RI.chargeday as daygeneration','fields1'=>'daygeneration','enname'=>'Power generation(kWh)'),
  406. array('name'=>'当天用电量(kWh)','field'=>'RI.dischargeday as dayconsumption','fields1'=>'dayconsumption','enname'=>'Power consumption(kWh)'),
  407. array('name'=>'累计发电量(kWh)','field'=>'HI.totalchargeah as totalgeneration','fields1'=>'totalgeneration','enname'=>'Cumulative power generation(kWh)'),
  408. array('name'=>'累计用电量(kWh)','field'=>'HI.totaldischarah as totalconsumption','fields1'=>'totalconsumption','enname'=>'Cumulative power consumption(kWh)'),
  409. );
  410. // $system_info_log = array(
  411. // array('name'=>'系统电压(V)','field'=>'L.sysvoltage','fields1'=>'sysvoltage','enname'=>'System voltage(V)'),
  412. // array('name'=>'系统电流(A)','field'=>'L.syscurrent','fields1'=>'syscurrent','enname'=>'System current(A)'),
  413. // array('name'=>'控制器温度(℃)','field'=>'L.temper as controlTemper','fields1'=>'controlTemper','enname'=>'Controller temperature(℃)'),
  414. // );
  415. // 历史信息日志
  416. // $history_info_log = array(
  417. // array('name'=>'运行天数','field'=>'L.rundays','fields1'=>'rundays','enname'=>'Running duration'),
  418. // array('name'=>'蓄电池总充满次数','field'=>'L.fulltimes','fields1'=>'fulltimes','enname'=>'Full charge times'),
  419. // array('name'=>'蓄电池总充电安时数(ah)','field'=>'L.totalchargeah','fields1'=>'totalchargeah','enname'=>'Total charge AH(ah)'),
  420. // array('name'=>'蓄电池总放电安时数(ah)','field'=>'L.totaldischarah','fields1'=>'totaldischarah','enname'=>'Total discharge AH(ah)'),
  421. // );
  422. // $fields = array_merge($def,$lampinfo,$lamp_info_log,$solar_info_log,$battery_info_log,$electric_info_log,$system_info_log,$history_info_log);
  423. $fields = array_merge($def,$lampinfo,$lamp_info_log,$solar_info_log,$electric_info_log);
  424. // $fields = $def;
  425. $def = explode(',', $fieldstr);
  426. foreach ($fields as &$v) {
  427. if (in_array($v['fields1'], $def)) {
  428. $v['select'] = '1';
  429. }else{
  430. $v['select'] = '0';
  431. }
  432. }
  433. exit(json_result('0000',$this->response['0000'],array('list'=>$fields)));
  434. }
  435. // 路灯下拉列表
  436. public function lamp_list(){
  437. $networkid = intval($this->input->post('networkid',true));
  438. $projectid = intval($this->input->post('projectid',true));
  439. if (empty($networkid) && empty($projectid)) {
  440. exit(json_result('0405',$this->response['0405'],array()));
  441. }
  442. if (!empty($networkid)) {
  443. $data = $this->Lamp_model->get_list(array('networkid'=>$networkid), 'number,id');
  444. }else{
  445. $data = $this->Lamp_model->get_list(array('projectid'=>$projectid), 'number,id');
  446. }
  447. exit(json_result('0000',$this->response['0000'],$data));
  448. }
  449. // 获取单个路灯的经纬度
  450. public function get_lng_lat(){
  451. $lampid = $this->input->post('lampid',true);
  452. $projectid = $this->input->post('projectid',true);
  453. $section = $this->input->post('section',true);
  454. $lampData = array();
  455. if (!empty($lampid)) {
  456. $where = array('id'=>$lampid,'longitude !='=>0,'latitude !='=>0);
  457. if (!empty($section)) {
  458. $where['section'] = $section;
  459. }
  460. $lampData = $this->Lamp_model->get_one($where,'longitude,latitude');
  461. }
  462. if (!empty($projectid)) {
  463. $where = array('projectid'=>$projectid,'longitude !='=>0,'latitude !='=>0);
  464. if (!empty($section)) {
  465. $where['section'] = $section;
  466. }
  467. $lampData = $this->Lamp_model->get_one($where,'longitude,latitude');
  468. }
  469. if (empty($lampData)) {
  470. $lampData = array('longitude'=>0,'latitude'=>0);
  471. }
  472. exit(json_result('0000',$this->response['0000'],$lampData));
  473. }
  474. public function get_province(){
  475. // $countryId = intval($this->input->post('countryId',true));
  476. $role = $this->get_user_info('role');
  477. $where = array();
  478. if ($role != SYSTEM_ADMIN) {
  479. $company = $this->get_user_info('company');
  480. $where['company'] = $company;
  481. }
  482. $pro_list = $this->Project_model->get_list($where,'cityid');
  483. $cityArr = array_unique(array_column($pro_list, 'cityid'));
  484. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  485. $areaList = array();
  486. $cityList = array();
  487. $proList = array();
  488. foreach ($list as $key => $value) {
  489. if ($value['level'] == 2) {
  490. $proList[] = $value;
  491. }elseif ($value['level'] == 3) {
  492. $cityList[] = $value;
  493. }elseif ($value['level'] == 4) {
  494. $areaList[] = $value;
  495. }
  496. }
  497. if (!empty($areaList)) {
  498. $cityArr = array_unique(array_column($areaList, 'pid'));
  499. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  500. foreach ($list as $key => $value) {
  501. if ($value['level'] == 2) {
  502. $proList[] = $value;
  503. }elseif ($value['level'] == 3) {
  504. $cityList[] = $value;
  505. }
  506. }
  507. }
  508. if (!empty($cityList)) {
  509. $cityArr = array_unique(array_column($cityList, 'pid'));
  510. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  511. foreach ($list as $key => $value) {
  512. if ($value['level'] == 2) $proList[] = $value;
  513. }
  514. }
  515. if (empty($proList)) exit(json_result('0000',$this->response['0000'],array('list'=>array())));
  516. $cityArr = array_unique(array_column($proList, 'id'));
  517. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
  518. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  519. }
  520. public function get_city(){
  521. $proId = intval($this->input->post('proId',true));
  522. $role = $this->get_user_info('role');
  523. $where = array();
  524. if ($role != SYSTEM_ADMIN) {
  525. $company = $this->get_user_info('company');
  526. $where['company'] = $company;
  527. }
  528. $pro_list = $this->Project_model->get_list($where,'cityid');
  529. $cityArr = array_unique(array_column($pro_list, 'cityid'));
  530. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  531. $areaList = array();
  532. $cityList = array();
  533. foreach ($list as $key => $value) {
  534. if ($value['level'] == 3) {
  535. $cityList[] = $value;
  536. }elseif ($value['level'] == 4) {
  537. $areaList[] = $value;
  538. }
  539. }
  540. if (!empty($areaList)) {
  541. $cityArr = array_unique(array_column($areaList, 'pid'));
  542. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  543. foreach ($list as $key => $value) {
  544. if ($value['level'] == 3) $cityList[] = $value;
  545. }
  546. }
  547. if (empty($cityList)) exit(json_result('0000',$this->response['0000'],array('list'=>array())));
  548. $cityArr = array_unique(array_column($cityList, 'id'));
  549. $where = ['id'=>$cityArr];
  550. if (!empty($proId)) $where['pid'] = $proId;
  551. $list = $this->Global_location_model->get_list($where,'id,english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
  552. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  553. }
  554. // 告警状态下拉列表
  555. public function alarm_type_list(){
  556. $version = $this->session->userdata('version');
  557. $batstatus = $this->config->item('batstatus');
  558. $panelstatus = $this->config->item('panelstatus');
  559. $lampstatus = $this->config->item('lampstatus');
  560. $tempstatus = $this->config->item('tempstatus');
  561. $list = array();
  562. foreach ($batstatus as $key => $value) {
  563. $list[] = ['name'=>$value,'value'=>'1'.$key];
  564. }
  565. foreach ($panelstatus as $key => $value) {
  566. $list[] = ['name'=>$value,'value'=>'2'.$key];
  567. }
  568. foreach ($lampstatus as $key => $value) {
  569. $list[] = ['name'=>$value,'value'=>'3'.$key];
  570. }
  571. foreach ($tempstatus as $key => $value) {
  572. $list[] = ['name'=>$value,'value'=>'4'.$key];
  573. }
  574. exit(json_result('0000',$this->response['0000'],$list));
  575. }
  576. }