Home.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  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,G.id';
  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,G.id';
  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,G.id';
  204. $group = 'group by L.po';
  205. $where[] = 'L.po != 0';
  206. $where[] = 'L.po != ""';
  207. }else{
  208. $fields = 'G.english_name as company,G.id';
  209. $group = 'group by G.id';
  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,t1.id as cityid,t1.company from (select count(*) as total,'.$fields.' from lampinfo AS L left join project AS P on P.id = L.projectid left join global_location G on P.cityid = G.id '.$where1.' '.$group.') as t1 left join company as C on t1.company = C.id order by total DESC limit 10';
  216. // var_dump($query);
  217. $list = $this->db->query($query)->result_array();
  218. // var_dump($list);die;
  219. if (empty($list)) exit(json_result('0000',$this->response['0000'],array('list'=>array())));
  220. $temp = array();
  221. $allDev = array_sum(array_column($list, 'total'));
  222. foreach ($list as $key => $value) {
  223. $totalPer = empty($allDev) ? '0%' : round($value['total']/$allDev*100,2).'%';
  224. $temp2 = array('name'=>$value['name'],'total'=>$value['total'],'onlineCount'=>0,'offlineCount'=>0,'faultCount'=>0,'totalPer'=>$totalPer);
  225. if ($type == 5) {
  226. $temp2['name'] = $value['company'];
  227. $temp[$value['cityid']] = $temp2;
  228. }else{
  229. $temp[$value['id']] = $temp2;
  230. }
  231. }
  232. $companyArr = array_unique(array_column($list, 'id'));
  233. $cityArr = array_unique(array_column($list, 'cityid'));
  234. if ($type == 2) {
  235. $where[] = 'L.manu in ('.implode(',', $companyArr).')';
  236. }elseif ($type == 3) {
  237. $where[] = 'L.supplier in ('.implode(',', $companyArr).')';
  238. }elseif ($type == 4) {
  239. $where[] = 'L.po in ('.implode(',', $companyArr).')';
  240. }else{
  241. $where[] = 'P.cityid in ('.implode(',', $cityArr).')';
  242. }
  243. $where1 = $where;
  244. $where1[] = 'L.netstatus = 0';
  245. $where1 = 'where '.implode(' AND ', $where1);
  246. if ($type == 5) {
  247. $query = 'select t1.total,t1.id from (select count(*) as total,'.$fields.' from lampinfo AS L left join project AS P on P.id = L.projectid left join global_location G on P.cityid = G.id '.$where1.' '.$group.') as t1 order by total DESC limit 10';
  248. }else{
  249. $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 left join global_location G on P.cityid = G.id '.$where1.' '.$group.') as t1 left join company as C on t1.company = C.id order by total DESC limit 10';
  250. }
  251. $list = $this->db->query($query)->result_array();
  252. foreach ($list as $key => $value) {
  253. if (isset($temp[$value['id']])) $temp[$value['id']]['offlineCount'] = $value['total'];
  254. }
  255. $where1 = $where;
  256. $where1[] = 'L.netstatus = 1';
  257. $where1 = 'where '.implode(' AND ', $where1);
  258. if ($type == 5) {
  259. $query = 'select t1.total,t1.id from (select count(*) as total,'.$fields.' from lampinfo AS L left join project AS P on P.id = L.projectid left join global_location G on P.cityid = G.id '.$where1.' '.$group.') as t1 order by total DESC limit 10';
  260. }else{
  261. $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 left join global_location G on P.cityid = G.id '.$where1.' '.$group.') as t1 left join company as C on t1.company = C.id order by total DESC limit 10';
  262. }
  263. $list = $this->db->query($query)->result_array();
  264. foreach ($list as $key => $value) {
  265. if (isset($temp[$value['id']])) $temp[$value['id']]['onlineCount'] = $value['total'];
  266. }
  267. $where1 = $where;
  268. $where1[] = 'L.netstatus = 1';
  269. $where1[] = '(WI.batstatus != 0 OR WI.panelstatus != 0 OR WI.lampstatus != 0 OR WI.tempstatus != 0)';
  270. $where1 = 'where '.implode(' AND ', $where1);
  271. if ($type == 5) {
  272. $query = 'select t1.total,t1.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 left join global_location G on P.cityid = G.id '.$where1.' '.$group.') as t1 order by total DESC limit 10';
  273. }else{
  274. $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 left join global_location G on P.cityid = G.id '.$where1.' '.$group.') as t1 left join company as C on t1.company = C.id order by total DESC limit 10';
  275. }
  276. $list = $this->db->query($query)->result_array();
  277. foreach ($list as $key => $value) {
  278. if (isset($temp[$value['id']])) $temp[$value['id']]['faultCount'] = $value['total'];
  279. }
  280. $list = array_values($temp);
  281. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  282. }
  283. // 故障信息列表
  284. public function alarm_list(){
  285. $projectIdArr = $this->get_project_id();
  286. $role = $this->get_user_info('role');
  287. $where = array();
  288. if ($role != SYSTEM_ADMIN){
  289. $company = $this->get_user_info('company');
  290. $where[] = 'P.company = '.$company;
  291. }
  292. if (!empty($projectIdArr)) $where[] = 'P.id in ('.implode(',', $projectIdArr).')';
  293. $where[] = '(WI.batstatus != 0 OR WI.panelstatus != 0 OR WI.lampstatus != 0 OR WI.tempstatus != 0)';
  294. $where[] = 'L.netstatus = 1';
  295. $where1 = implode(' AND ', $where);
  296. $join = [
  297. ['table'=>'project as P','cond'=>'P.id = L.projectid','type'=>'inner']
  298. ];
  299. $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'];
  300. $join[] = ['table'=>'global_location as G1','cond'=>'G1.id = P.cityid','type'=>'inner'];
  301. $join[] = ['table'=>'global_location as G2','cond'=>'G2.id = G1.pid','type'=>'inner'];
  302. $join[] = ['table'=>'global_location as G3','cond'=>'G3.id = G2.pid','type'=>'inner'];
  303. $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');
  304. $batstatus = $this->config->item('batstatus');
  305. $panelstatus = $this->config->item('panelstatus');
  306. $lampstatus = $this->config->item('lampstatus');
  307. $tempstatus = $this->config->item('tempstatus');
  308. foreach ($list as $key => $value) {
  309. $location = $value['proName'].'/'.$value['cityName'].'/'.$value['areaName'];
  310. $location = empty($value['section']) ? $location : $location.'/'.$value['section'];
  311. $list[$key]['location'] = $location;
  312. $list[$key]['fault_time'] = set_timezone($value['updatetime'],$value['timezone']);
  313. $temp2 = array();
  314. if (isset($batstatus[$value['batstatus']])) $temp2[] = $batstatus[$value['batstatus']];
  315. if (isset($panelstatus[$value['panelstatus']])) $temp2[] = $panelstatus[$value['panelstatus']];
  316. if (isset($lampstatus[$value['lampstatus']])) $temp2[] = $lampstatus[$value['lampstatus']];
  317. if (isset($tempstatus[$value['tempstatus']])) $temp2[] = $tempstatus[$value['tempstatus']];
  318. $list[$key]['fault_type'] = implode(',', $temp2);
  319. unset($list[$key]['cityName']);
  320. unset($list[$key]['proName']);
  321. unset($list[$key]['areaName']);
  322. unset($list[$key]['section']);
  323. unset($list[$key]['timezone']);
  324. unset($list[$key]['updatetime']);
  325. }
  326. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  327. }
  328. // 字段管理
  329. public function fields(){
  330. $userid = $this->get_user_info('id');
  331. $data = $this->User_model->get_user_field($userid);
  332. if (empty($data) || empty($data['lampfield'])) {
  333. // $fieldstr = "number,lampstatus,updatetime,lighteness,address,lamppower,chargestage,battvoltage,overtimes,solarpower,isfaulted,status,section";
  334. $fieldstr = "number,lampstatus,updatetime,lighteness,address,lamppower,chargestage,battvoltage,overtimes,solarpower,isfaulted,status,section";
  335. }else{
  336. if ($data['lampfield'] == 'number,lampstatus,updatetime,lighteness,address,lamppower,chargestage,battvoltage,overtimes,solarpower,isfaulted,status') {
  337. $data['lampfield'] .= ',section';
  338. }
  339. $fieldstr = $data['lampfield'];
  340. }
  341. // 系统默认
  342. $def = array(
  343. array('name'=>'路灯编号','field'=>'L.number','fields1'=>'number','enname'=>'Lamp number'),
  344. array('name'=>'路段','field'=>'L.section','fields1'=>'section','enname'=>'Road'),
  345. // array('name'=>'路灯状态','field'=>'L.status as lampstatus,L.lighteness','fields1'=>'lampstatus','enname'=>'Lamp status'),
  346. array('name'=>'信号状态','field'=>'L.protocoltype,L.netstatus as status,L.rssi','fields1'=>'status','enname'=>'Network status'),
  347. // array('name'=>'信号状态','field'=>'L.protocoltype,L.netstatus as status,N.rssi,N.snr','fields1'=>'status','enname'=>'Network status'),
  348. array('name'=>'更新时间','field'=>'RI.updatetime','fields1'=>'updatetime','enname'=>'Update time'),
  349. array('name'=>'路灯亮度(%)','field'=>'L.lighteness','fields1'=>'lighteness','enname'=>'Brightness(%)'),
  350. array('name'=>'无线模块地址','field'=>'L.address','fields1'=>'address','enname'=>'Wireless module address'),
  351. array('name'=>'负载功率(W)','field'=>'RI.loadpower','fields1'=>'loadpower','enname'=>'LED power(W)'),
  352. array('name'=>'蓄电池电压(V)','field'=>'RI.batpower as battvoltage','fields1'=>'battvoltage','enname'=>'Battery voltage(V)'),
  353. array('name'=>'蓄电池总过放次数','field'=>'HI.overtimes','fields1'=>'overtimes','enname'=>'Over discharge times'),
  354. array('name'=>'太阳能板功率(W)','field'=>'RI.panelpower as solarpower','fields1'=>'solarpower','enname'=>'Solar panel power(W)'),
  355. array('name'=>'是否故障','field'=>'AI.batstatus,AI.panelstatus,AI.lampstatus,AI.tempstatus,AI.status as alarmStatus','fields1'=>'isfaulted','enname'=>'Fault'),
  356. );
  357. // $def = array(
  358. // array('name'=>'路灯编号','field'=>'L.number','fields1'=>'number','enname'=>'Lamp number'),
  359. // array('name'=>'路段','field'=>'L.section','fields1'=>'section','enname'=>'Road'),
  360. // array('name'=>'路灯状态','field'=>'L.status as lampstatus,L.lighteness','fields1'=>'lampstatus','enname'=>'Lamp status'),
  361. // array('name'=>'信号状态','field'=>'L.protocoltype,L.netstatus as status','fields1'=>'status','enname'=>'Network status'),
  362. // // array('name'=>'信号状态','field'=>'L.protocoltype,L.netstatus as status,N.rssi,N.snr','fields1'=>'status','enname'=>'Network status'),
  363. // array('name'=>'更新时间','field'=>'L.logtime as updatetime','fields1'=>'updatetime','enname'=>'Update time'),
  364. // array('name'=>'路灯亮度(%)','field'=>'L.lighteness','fields1'=>'lighteness','enname'=>'Brightness(%)'),
  365. // array('name'=>'无线模块地址','field'=>'L.address','fields1'=>'address','enname'=>'Wireless module address'),
  366. // array('name'=>'路灯功率(W)','field'=>'L.lamppower','fields1'=>'lamppower','enname'=>'Lamp power(W)'),
  367. // array('name'=>'蓄电池充电阶段','field'=>'L.chargestage','fields1'=>'chargestage','enname'=>'Charging stage'),
  368. // array('name'=>'蓄电池电压(V)','field'=>'L.battvoltage','fields1'=>'battvoltage','enname'=>'Battery voltage(V)'),
  369. // array('name'=>'蓄电池总过放次数','field'=>'L.overtimes','fields1'=>'overtimes','enname'=>'Over discharge times'),
  370. // array('name'=>'太阳能板功率(W)','field'=>'L.solarpower','fields1'=>'solarpower','enname'=>'Solar panel power(W)'),
  371. // array('name'=>'是否故障','field'=>'L.isfaulted','fields1'=>'isfaulted','enname'=>'Fault'),
  372. // );
  373. // 路灯信息
  374. $lampinfo = array(
  375. array('name'=>'当前策略','field'=>'L.policyid','fields1'=>'policyid','enname'=>'Current strategy'),
  376. array('name'=>'路灯id','field'=>'L.id','fields1'=>'id','enname'=>'Lamp ID'),
  377. // array('name'=>'网络名称','field'=>'N.networkname','fields1'=>'networkname','enname'=>'Network name'),
  378. array('name'=>'项目名称','field'=>'P.projectname','fields1'=>'projectname','enname'=>'Project name'),
  379. array('name'=>'经度','field'=>'L.longitude','fields1'=>'longitude','enname'=>'Longitude'),
  380. array('name'=>'纬度','field'=>'L.latitude','fields1'=>'latitude','enname'=>'Latitude'),
  381. // array('name'=>'sim卡号','field'=>'N.simid','fields1'=>'simid','enname'=>'SIM card number'),
  382. // array('name'=>'套餐剩余','field'=>'N.packageSurplus','fields1'=>'packageSurplus','enname'=>'Package surplus'),
  383. array('name'=>'路灯类型','field'=>'L.lamptype','fields1'=>'lamptype','enname'=>'Lamp type'),
  384. array('name'=>'太阳能板类型','field'=>'L.boardtype','fields1'=>'boardtype','enname'=>'Solar panel type'),
  385. // array('name'=>'太阳能板功率(W)','field'=>'L.boardpower','fields1'=>'boardpower','enname'=>'Solar panel power(W)'),
  386. // array('name'=>'蓄电池类型','field'=>'L.batterytype','fields1'=>'batterytype','enname'=>'Battery type'),
  387. array('name'=>'蓄电池AH数(ah)','field'=>'HI.totalchargeah as batteryah','fields1'=>'batteryah','enname'=>'Battery capacity(ah)'),
  388. // array('name'=>'负载功率(W)','field'=>'L.loadpower','fields1'=>'loadpower','enname'=>'Load power(W)'),
  389. // array('name'=>'蓄电池剩余电量','field'=>'L.electricleft','fields1'=>'electricleft','enname'=>'Remaining battery capacity(Ah)'),
  390. );
  391. // 路灯信息日志
  392. $lamp_info_log = array(
  393. array('name'=>'路灯电压(V)','field'=>'RI.loadvoltage as lampvoltage','fields1'=>'lampvoltage','enname'=>'Lamp voltage(V)'),
  394. array('name'=>'路灯电流(A)','field'=>'RI.loadcurrent as lampcurrent','fields1'=>'lampcurrent','enname'=>'Lamp current(A)'),
  395. // array('name'=>'灯头温度(℃)','field'=>'L.lamptemper as temper','fields1'=>'temper','enname'=>'Lamp temperature(℃)'),
  396. );
  397. $solar_info_log = array(
  398. array('name'=>'太阳能板电压(V)','field'=>'RI.panelvoltage as solarvoltage','fields1'=>'solarvoltage','enname'=>'Solar panel voltage(V)'),
  399. array('name'=>'太阳能板电流(A)','field'=>'RI.panelcurrent as solarcurrent','fields1'=>'solarcurrent','enname'=>'Solar panel current(A)')
  400. );
  401. // 蓄电池信息日志
  402. // $battery_info_log = array(
  403. // array('name'=>'蓄电池状态','field'=>'L.battstatus','fields1'=>'battstatus','enname'=>'Battery status'),
  404. // array('name'=>'蓄电池充电电流(A)','field'=>'L.chargecurrent','fields1'=>'chargecurrent','enname'=>'Charging current(A)'),
  405. // array('name'=>'蓄电池放电电流(A)','field'=>'L.discharcurrent','fields1'=>'discharcurrent','enname'=>'Discharging current(A)'),
  406. // array('name'=>'蓄电池充电功率(w)','field'=>'L.chargepower','fields1'=>'chargepower','enname'=>'Charging power(w)'),
  407. // array('name'=>'蓄电池放电功率(w)','field'=>'L.dischargepower','fields1'=>'dischargepower','enname'=>'Discharging power(w)'),
  408. // array('name'=>'蓄电池表面温度(℃)','field'=>'L.batttemper','fields1'=>'batttemper','enname'=>'Battery surface temperature(℃)'),
  409. // array('name'=>'蓄电池总电量','field'=>'L.electrictotal','fields1'=>'electrictotal','enname'=>'Total battery capacity(Ah)'),
  410. // array('name'=>'蓄电池电量SOC(%)','field'=>'L.electricSOC','fields1'=>'electricSOC','enname'=>'Battery SOC(%)'),
  411. // array('name'=>'当天最低电压(V)','field'=>'L.voltagedaymin','fields1'=>'voltagedaymin','enname'=>'Minimum voltage(V)'),
  412. // array('name'=>'当天最高电压(V)','field'=>'L.voltagedaymax','fields1'=>'voltagedaymax','enname'=>'Highest voltage(V)'),
  413. // array('name'=>'当天充电安时数(ah)','field'=>'L.daychargeah','fields1'=>'daychargeah','enname'=>'Charging AH(ah)'),
  414. // array('name'=>'当天放电安时数(ah)','field'=>'L.daydischarah','fields1'=>'daydischarah','enname'=>'Discharging AH(ah)'),
  415. // array('name'=>'当天充电最大功率(W)','field'=>'L.daychargemaxpow','fields1'=>'daychargemaxpow','enname'=>'Charging max-power(W)'),
  416. // array('name'=>'当天放电最大功率(W)','field'=>'L.daydischarmaxpow','fields1'=>'daydischarmaxpow','enname'=>'Discharging max-power(W)'),
  417. // array('name'=>'当天灯亮时间(hh:mm)','field'=>'L.daychargemincurrent','fields1'=>'daychargemincurrent','enname'=>'Turn-on duration'),
  418. // array('name'=>'当天充电最大电流(A)','field'=>'L.daycharmaxcurrent','fields1'=>'daycharmaxcurrent','enname'=>'Highest charging current(A)'),
  419. // array('name'=>'当天充电时间(hh:mm)','field'=>'L.daydischargemincurrent','fields1'=>'daydischargemincurrent','enname'=>'Charging duration'),
  420. // array('name'=>'当天放电最大电流(A)','field'=>'L.daydischarmaxcurrent','fields1'=>'daydischarmaxcurrent','enname'=>'Highest discharging current(A)'),
  421. // array('name'=>'当天蓄电池最低温度(℃)','field'=>'L.daybattmintemper','fields1'=>'daybattmintemper','enname'=>'Battery min-temperature(℃)'),
  422. // array('name'=>'当天蓄电池最高温度(℃)','field'=>'L.daybattmaxtemper','fields1'=>'daybattmaxtemper','enname'=>'Battery max-temperature(℃)'),
  423. // );
  424. $electric_info_log = array(
  425. array('name'=>'当天发电量(kWh)','field'=>'RI.chargeday as daygeneration','fields1'=>'daygeneration','enname'=>'Power generation(kWh)'),
  426. array('name'=>'当天用电量(kWh)','field'=>'RI.dischargeday as dayconsumption','fields1'=>'dayconsumption','enname'=>'Power consumption(kWh)'),
  427. array('name'=>'累计发电量(kWh)','field'=>'HI.totalchargeah as totalgeneration','fields1'=>'totalgeneration','enname'=>'Cumulative power generation(kWh)'),
  428. array('name'=>'累计用电量(kWh)','field'=>'HI.totaldischarah as totalconsumption','fields1'=>'totalconsumption','enname'=>'Cumulative power consumption(kWh)'),
  429. );
  430. // $system_info_log = array(
  431. // array('name'=>'系统电压(V)','field'=>'L.sysvoltage','fields1'=>'sysvoltage','enname'=>'System voltage(V)'),
  432. // array('name'=>'系统电流(A)','field'=>'L.syscurrent','fields1'=>'syscurrent','enname'=>'System current(A)'),
  433. // array('name'=>'控制器温度(℃)','field'=>'L.temper as controlTemper','fields1'=>'controlTemper','enname'=>'Controller temperature(℃)'),
  434. // );
  435. // 历史信息日志
  436. // $history_info_log = array(
  437. // array('name'=>'运行天数','field'=>'L.rundays','fields1'=>'rundays','enname'=>'Running duration'),
  438. // array('name'=>'蓄电池总充满次数','field'=>'L.fulltimes','fields1'=>'fulltimes','enname'=>'Full charge times'),
  439. // array('name'=>'蓄电池总充电安时数(ah)','field'=>'L.totalchargeah','fields1'=>'totalchargeah','enname'=>'Total charge AH(ah)'),
  440. // array('name'=>'蓄电池总放电安时数(ah)','field'=>'L.totaldischarah','fields1'=>'totaldischarah','enname'=>'Total discharge AH(ah)'),
  441. // );
  442. // $fields = array_merge($def,$lampinfo,$lamp_info_log,$solar_info_log,$battery_info_log,$electric_info_log,$system_info_log,$history_info_log);
  443. $fields = array_merge($def,$lampinfo,$lamp_info_log,$solar_info_log,$electric_info_log);
  444. // $fields = $def;
  445. $def = explode(',', $fieldstr);
  446. foreach ($fields as &$v) {
  447. if (in_array($v['fields1'], $def)) {
  448. $v['select'] = '1';
  449. }else{
  450. $v['select'] = '0';
  451. }
  452. }
  453. exit(json_result('0000',$this->response['0000'],array('list'=>$fields)));
  454. }
  455. // 路灯下拉列表
  456. public function lamp_list(){
  457. $networkid = intval($this->input->post('networkid',true));
  458. $projectid = intval($this->input->post('projectid',true));
  459. if (empty($networkid) && empty($projectid)) {
  460. exit(json_result('0405',$this->response['0405'],array()));
  461. }
  462. if (!empty($networkid)) {
  463. $data = $this->Lamp_model->get_list(array('networkid'=>$networkid), 'number,id');
  464. }else{
  465. $data = $this->Lamp_model->get_list(array('projectid'=>$projectid), 'number,id');
  466. }
  467. exit(json_result('0000',$this->response['0000'],$data));
  468. }
  469. // 获取单个路灯的经纬度
  470. public function get_lng_lat(){
  471. $lampid = $this->input->post('lampid',true);
  472. $projectid = $this->input->post('projectid',true);
  473. $section = $this->input->post('section',true);
  474. $lampData = array();
  475. if (!empty($lampid)) {
  476. $where = array('id'=>$lampid,'longitude !='=>0,'latitude !='=>0);
  477. if (!empty($section)) {
  478. $where['section'] = $section;
  479. }
  480. $lampData = $this->Lamp_model->get_one($where,'longitude,latitude');
  481. }
  482. if (!empty($projectid)) {
  483. $where = array('projectid'=>$projectid,'longitude !='=>0,'latitude !='=>0);
  484. if (!empty($section)) {
  485. $where['section'] = $section;
  486. }
  487. $lampData = $this->Lamp_model->get_one($where,'longitude,latitude');
  488. }
  489. if (empty($lampData)) {
  490. $lampData = array('longitude'=>0,'latitude'=>0);
  491. }
  492. exit(json_result('0000',$this->response['0000'],$lampData));
  493. }
  494. public function get_province(){
  495. // $countryId = intval($this->input->post('countryId',true));
  496. $role = $this->get_user_info('role');
  497. $where = array();
  498. if ($role != SYSTEM_ADMIN) {
  499. $company = $this->get_user_info('company');
  500. $where['company'] = $company;
  501. }
  502. $pro_list = $this->Project_model->get_list($where,'cityid');
  503. $cityArr = array_unique(array_column($pro_list, 'cityid'));
  504. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  505. $areaList = array();
  506. $cityList = array();
  507. $proList = array();
  508. foreach ($list as $key => $value) {
  509. if ($value['level'] == 2) {
  510. $proList[] = $value;
  511. }elseif ($value['level'] == 3) {
  512. $cityList[] = $value;
  513. }elseif ($value['level'] == 4) {
  514. $areaList[] = $value;
  515. }
  516. }
  517. if (!empty($areaList)) {
  518. $cityArr = array_unique(array_column($areaList, 'pid'));
  519. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  520. foreach ($list as $key => $value) {
  521. if ($value['level'] == 2) {
  522. $proList[] = $value;
  523. }elseif ($value['level'] == 3) {
  524. $cityList[] = $value;
  525. }
  526. }
  527. }
  528. if (!empty($cityList)) {
  529. $cityArr = array_unique(array_column($cityList, 'pid'));
  530. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  531. foreach ($list as $key => $value) {
  532. if ($value['level'] == 2) $proList[] = $value;
  533. }
  534. }
  535. if (empty($proList)) exit(json_result('0000',$this->response['0000'],array('list'=>array())));
  536. $cityArr = array_unique(array_column($proList, 'id'));
  537. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
  538. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  539. }
  540. public function get_city(){
  541. $proId = intval($this->input->post('proId',true));
  542. $role = $this->get_user_info('role');
  543. $where = array();
  544. if ($role != SYSTEM_ADMIN) {
  545. $company = $this->get_user_info('company');
  546. $where['company'] = $company;
  547. }
  548. $pro_list = $this->Project_model->get_list($where,'cityid');
  549. $cityArr = array_unique(array_column($pro_list, 'cityid'));
  550. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  551. $areaList = array();
  552. $cityList = array();
  553. foreach ($list as $key => $value) {
  554. if ($value['level'] == 3) {
  555. $cityList[] = $value;
  556. }elseif ($value['level'] == 4) {
  557. $areaList[] = $value;
  558. }
  559. }
  560. if (!empty($areaList)) {
  561. $cityArr = array_unique(array_column($areaList, 'pid'));
  562. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  563. foreach ($list as $key => $value) {
  564. if ($value['level'] == 3) $cityList[] = $value;
  565. }
  566. }
  567. if (empty($cityList)) exit(json_result('0000',$this->response['0000'],array('list'=>array())));
  568. $cityArr = array_unique(array_column($cityList, 'id'));
  569. $where = ['id'=>$cityArr];
  570. if (!empty($proId)) $where['pid'] = $proId;
  571. $list = $this->Global_location_model->get_list($where,'id,english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
  572. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  573. }
  574. // 告警状态下拉列表
  575. public function alarm_type_list(){
  576. $version = $this->session->userdata('version');
  577. $batstatus = $this->config->item('batstatus');
  578. $panelstatus = $this->config->item('panelstatus');
  579. $lampstatus = $this->config->item('lampstatus');
  580. $tempstatus = $this->config->item('tempstatus');
  581. $list = array();
  582. foreach ($batstatus as $key => $value) {
  583. $list[] = ['name'=>$value,'value'=>'1'.$key];
  584. }
  585. foreach ($panelstatus as $key => $value) {
  586. $list[] = ['name'=>$value,'value'=>'2'.$key];
  587. }
  588. foreach ($lampstatus as $key => $value) {
  589. $list[] = ['name'=>$value,'value'=>'3'.$key];
  590. }
  591. foreach ($tempstatus as $key => $value) {
  592. $list[] = ['name'=>$value,'value'=>'4'.$key];
  593. }
  594. exit(json_result('0000',$this->response['0000'],$list));
  595. }
  596. // 省级设备数量
  597. public function pro_dev_count(){
  598. $role = $this->get_user_info('role');
  599. $company = $this->get_user_info('company');
  600. $where = array();
  601. if ($role != SYSTEM_ADMIN) $where['P.company'] = $company;
  602. $join = array();
  603. $join[] = ['table'=>'global_location as G1','cond'=>'G1.id = P.cityid AND G1.level = 4','type'=>'inner'];
  604. $join[] = ['table'=>'global_location as G2','cond'=>'G2.id = G1.pid AND G2.level = 3','type'=>'inner'];
  605. $join[] = ['table'=>'global_location as G3','cond'=>'G3.id = G2.pid AND G3.level = 2','type'=>'inner'];
  606. $list = $this->Project_model->get_list_by_join($where, 'G3.id,G3.english_name as name,sum(P.lampcount) as lampcount',NULL, NULL, $join, NULL, 'G3.id', 'P');
  607. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  608. }
  609. // 市级设备数量
  610. public function city_dev_count(){
  611. $role = $this->get_user_info('role');
  612. $company = $this->get_user_info('company');
  613. $where = array();
  614. $proId = intval($this->input->post('proId',true));
  615. if (!empty($proId)) $where['G2.pid'] = $proId;
  616. if ($role != SYSTEM_ADMIN) $where['P.company'] = $company;
  617. $join = array();
  618. $join[] = ['table'=>'global_location as G1','cond'=>'G1.id = P.cityid','type'=>'left'];
  619. $join[] = ['table'=>'global_location as G2','cond'=>'G2.id = G1.pid','type'=>'left'];
  620. $list = $this->Project_model->get_list_by_join($where, 'G2.id,G2.english_name as name,sum(P.lampcount) as lampcount',NULL, NULL, $join, NULL, 'G2.id', 'P');
  621. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  622. }
  623. }