IndexController.class.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. class IndexController extends ComController
  5. {
  6. //首页统计图数据
  7. public function getHomePageData(){
  8. $Date=I();
  9. $phone=$Date['phone'];
  10. $company_code = $Date['company_code'];
  11. if (!empty($_SESSION['phone'])) {
  12. $phone = $_SESSION['phone'];
  13. }
  14. if (!empty($company_code)){
  15. $device_list = $this->getDeviceCode($company_code);
  16. }else{
  17. $company_code1=M()->query("select owner_code from sp_owner_phone WHERE phone='".$phone."' GROUP BY owner_code limit 1");
  18. $company_code=$company_code1[0]['owner_code'];
  19. $device_list = $this->getDeviceCode($company_code);
  20. }
  21. $end_time = date("Y-m-d");
  22. $start_time = date("Y-m-d", strtotime("-1 months", strtotime($end_time)));
  23. //时间段
  24. $statisticalPeriod = $start_time . '~' . $end_time;
  25. //报警信息统计开始
  26. if (!empty($device_list)){
  27. //报警主机报警总数
  28. $alarm_host_count=M()->query("select count(*) as alarm_host_count from sp_hj2017 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.")");
  29. //消防水系统报警总数
  30. $fire_water_count=M()->query("select count(*) as fire_water_count from sp_sj2017 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.")");
  31. //电气火灾报警总数
  32. $electrical_fire_count=M()->query("select count(*) as electrical_fire_count from sp_ef2017 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.")");
  33. //视频监测报警总数
  34. $video_monitoring_count=M()->query("select count(*) as video_monitoring_count from sp_video2017 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.")");
  35. //井盖
  36. $manhole_cover_count=M()->query("select count(*) as manhole_cover_count from sp_iw2017 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.")");
  37. //门禁
  38. $door_count=M()->query("select count(*) as door_count from sp_door2020 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.")");
  39. //可燃气体
  40. $gas_count=M()->query("select count(*) as gas_count from sp_gas2020 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.")");
  41. //地磁
  42. $geomagnetism_count=M()->query("select count(*) as geomagnetism_count from sp_dc2020 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.")");
  43. //RTU
  44. $rtu_count=M()->query("select count(*) as rtu_count from sp_rtu2017 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.")");
  45. //电梯
  46. $elevator_count=M()->query("select count(*) as elevator_count from sp_lifter2017 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.")");
  47. //正常
  48. $normal_fire_water_device_count=M()->query("select count(*) as normal_fire_water_device_count from sp_v_device_status where device_status='在线' and device_id in(".$device_list.") ");
  49. //离线
  50. $off_linefire_water_device_count=M()->query("select count(*) as off_linefire_water_device_count from sp_v_device_status where device_status='离线' and device_id in(".$device_list.") ");
  51. //真实告警
  52. $real_alarm_count=M()->query("select count(*) as real_alarm_count from sp_hj2017 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.") and data2='火警'");
  53. }
  54. //其他类型一个月报警总数
  55. $other_count=(int)$manhole_cover_count[0]['manhole_cover_count']+(int)$door_count[0]['door_count']+(int)$gas_count[0]['gas_count']+(int)$geomagnetism_count[0]['geomagnetism_count']+(int)$rtu_count[0]['rtu_count']
  56. +(int)$elevator_count[0]['elevator_count'];
  57. //报警信息统计结束
  58. //数据等级统计开始
  59. //告警总数
  60. $alarm_count=(int)$other_count+(int)$video_monitoring_count[0]['video_monitoring_count']+(int)$electrical_fire_count[0]['electrical_fire_count']+(int)$fire_water_count[0]['fire_water_count']
  61. + (int)$alarm_host_count[0]['alarm_host_count'];
  62. //隐患告警
  63. $hidden_danger_count=(int)$alarm_count-(int)$real_alarm_count[0]['real_alarm_count'];
  64. //事件告警
  65. $event_count=0;
  66. //数据等级统计结束
  67. //设备运行状态开始
  68. //离线
  69. $off_linealarm_host_device_count=M()->query("SELECT COUNT(*) as off_linealarm_host_device_count FROM sp_devices_status AS a JOIN sp_owner AS b ON a.deviceid=b.owner_code WHERE b.dwtype=1 AND a.true_status in(75,300) AND b.company='".$company_code."' ");
  70. $off_line_device_count=(int)$off_linefire_water_device_count[0]['off_linefire_water_device_count']+(int)$off_linealarm_host_device_count[0]['off_linealarm_host_device_count'];
  71. //故障
  72. $fault_device_count=0;
  73. //预警
  74. $early_warning_device_count=0;
  75. //其他
  76. $other_device_count=0;
  77. //正常
  78. $normal_alarm_host_device_count=M()->query("SELECT COUNT(*) as normal_alarm_host_device_count FROM sp_devices_status AS a JOIN sp_owner AS b ON a.deviceid=b.owner_code WHERE b.dwtype=1 AND a.true_status='0' AND b.company='".$company_code."' ");
  79. $normal_device_count=(int)$normal_fire_water_device_count[0]['normal_fire_water_device_count']+(int)$normal_alarm_host_device_count[0]['normal_alarm_host_device_count'];;
  80. //设备运行状态结束
  81. $data[0]['owner_name']=$this->owner_name;
  82. $data[0]['statisticalPeriod']=$statisticalPeriod;
  83. $data[0]['alarm_host_count'] = (int)$alarm_host_count[0]['alarm_host_count'];
  84. $data[0]['fire_water_count'] = (int)$fire_water_count[0]['fire_water_count'];
  85. $data[0]['electrical_fire_count'] = (int)$electrical_fire_count[0]['electrical_fire_count'];
  86. $data[0]['video_monitoring_count'] = (int)$video_monitoring_count[0]['video_monitoring_count'];
  87. $data[0]['other_count'] = $other_count;
  88. $data[0]['alarm_count'] = $alarm_count;
  89. $data[0]['real_alarm_count'] = (int)$real_alarm_count[0]['real_alarm_count'];
  90. $data[0]['hidden_danger_count'] = $hidden_danger_count;
  91. $data[0]['event_count'] = $event_count;
  92. $data[0]['off_line_device_count'] = $off_line_device_count;
  93. $data[0]['fault_device_count'] = $fault_device_count;
  94. $data[0]['early_warning_device_count'] = $early_warning_device_count;
  95. $data[0]['normal_device_count'] = $normal_device_count;
  96. $data[0]['other_device_count'] = $other_device_count;
  97. $data[0]['company_code'] = $company_code;
  98. $res['msg'] = '操作成功';
  99. $res['flag'] = true;
  100. $res['data'] = $data;
  101. echo json_encode($res);
  102. }
  103. public function getCompanyList(){
  104. $Date=I();
  105. if (!empty($_SESSION['phone'])) {
  106. $phone = $_SESSION['phone'];
  107. }else{
  108. $res['msg'] = '操作失败,缓存中参数缺失';
  109. $res['flag'] = 3002;
  110. echo json_encode($res);
  111. exit();
  112. }
  113. $company=M()->query("select a.owner_code,b.owner_name from sp_owner_phone as a join sp_owner_company as b on a.owner_code=b.owner_id where a.phone='".$phone."' GROUP BY owner_code");
  114. $res['msg'] = '操作成功';
  115. $res['flag'] = true;
  116. $res['data'] = $company;
  117. echo json_encode($res);
  118. }
  119. public function getFunctionalModuleStatistics(){
  120. $Date=I();
  121. $phone=$Date['phone'];
  122. $company_code = $Date['company_code'];
  123. if (!empty($_SESSION['phone'])) {
  124. $phone = $_SESSION['phone'];
  125. }
  126. $where2['company_code'] = $company_code;
  127. if (!empty($company_code)){
  128. $device_list = $this->getDeviceCode($company_code);
  129. }else{
  130. $company_code1=M()->query("select owner_code from sp_owner_phone WHERE phone='".$phone."' GROUP BY owner_code limit 1");
  131. $company_code=$company_code1[0]['owner_code'];
  132. $device_list = $this->getDeviceCode($company_code);
  133. }
  134. $data_statistics = M('company_sync')->where($where2)->find();
  135. if(!empty($data_statistics)){
  136. //报警主机未处理数量统计
  137. $alarm_host_count = $data_statistics['device_01_alarm']-$data_statistics['device_01_alarm_confirm']+$data_statistics['device_01_out']-$data_statistics['device_01_out_confirm'];
  138. //消防水未处理数量统计
  139. $fire_water_count=$data_statistics['device_02_alarm']+$data_statistics['device_00_alarm']-($data_statistics['device_02_alarm_confirm']+$data_statistics['device_00_alarm_confirm'])
  140. +$data_statistics['device_00_out']-$data_statistics['device_00_out_confirm']+$data_statistics['device_02_out']-$data_statistics['device_02_out_confirm'];
  141. //RTU未处理数量统计
  142. $rtu_count=$data_statistics['device_06_alarm'] - $data_statistics['device_06_alarm_confirm']+$data_statistics['device_06_out']-$data_statistics['device_06_out_confirm'];
  143. //电气火灾未处理数量统计
  144. $electrical_fire_count= $data_statistics['device_07_alarm'] - $data_statistics['device_07_alarm_confirm']+$data_statistics['device_07_out']-$data_statistics['device_07_out_confirm'];
  145. //视频监测未处理数量统计
  146. $video_monitoring_count=$data_statistics['device_16_alarm'] - $data_statistics['device_16_alarm_confirm']+$data_statistics['device_16_out']-$data_statistics['device_16_out_confirm'];
  147. }else{
  148. $alarm_host_count = 0;
  149. $fire_water_count = 0;
  150. $rtu_count = 0;
  151. $electrical_fire_count = 0;
  152. $video_monitoring_count = 0;
  153. }
  154. if (!empty($device_list)){
  155. // //报警主机未处理数量统计
  156. // $alarm_host_count=M()->query("select count(*) as alarm_host_count from sp_hj2017 where clzt=0 and device_code in(".$device_list.")");
  157. //消防水未处理数量统计
  158. // $fire_water_count=M()->query("select count(*) as fire_water_count from sp_sj2017 where clzt=0 and device_code in(".$device_list.")");
  159. //电气火灾未处理数量统计
  160. // $electrical_fire_count=M()->query("select count(*) as electrical_fire_count from sp_ef2017 where clzt=0 and device_code in(".$device_list.")");
  161. //视频监测未处理数量统计
  162. // $video_monitoring_count=M()->query("select count(*) as video_monitoring_count from sp_video2017 where clzt=0 and device_code in(".$device_list.")");
  163. //井盖未处理数量统计
  164. $manhole_cover_count=M()->query("select count(*) as manhole_cover_count from sp_iw2017 where clzt=0 and device_code in(".$device_list.")");
  165. //门禁未处理数量统计
  166. $door_count=M()->query("select count(*) as door_count from sp_door2020 where clzt=0 and device_code in(".$device_list.")");
  167. //可燃气体未处理数量统计
  168. $gas_count=M()->query("select count(*) as gas_count from sp_gas2020 where clzt=0 and device_code in(".$device_list.")");
  169. //地磁未处理数量统计
  170. $geomagnetism_count=M()->query("select count(*) as geomagnetism_count from sp_dc2020 where clzt=0 and device_code in(".$device_list.")");
  171. //RTU未处理数量统计
  172. // $rtu_count=M()->query("select count(*) as rtu_count from sp_rtu2017 where clzt=0 and device_code in(".$device_list.")");
  173. //电梯未处理数量统计
  174. $elevator_count=M()->query("select count(*) as elevator_count from sp_lifter2017 where clzt=0 and device_code in(".$device_list.")");
  175. }
  176. //综合告警统计
  177. $comprehensive_alarm_count=(int)$manhole_cover_count[0]['manhole_cover_count']+(int)$door_count[0]['door_count']+(int)$gas_count[0]['gas_count']+(int)$geomagnetism_count[0]['geomagnetism_count']+(int)$rtu_count
  178. +(int)$elevator_count[0]['elevator_count']+(int)$video_monitoring_count+(int)$electrical_fire_count+(int)$fire_water_count
  179. + (int)$alarm_host_count;
  180. //人员督察单
  181. $personnel_inspection_list = query_187_ytapi("select count(*) as personnel_inspection_list_count from person_data where clzt='0' and company_code='" . $company_code."'");
  182. //电子督察单
  183. $electronic_inspection_sheet = query_187_ytapi("select count(*) as electronic_inspection_sheet_count from jingan_analysis_data where status=0 and clzt='0' and content != '设备离线' and company_code='" . $company_code."'");
  184. //消防支队督察单未处理数量统计
  185. $fire_brigade_inspector_count=$personnel_inspection_list[0]['personnel_inspection_list_count']+$electronic_inspection_sheet[0]['electronic_inspection_sheet_count'];
  186. $data[0]['comprehensive_alarm_count']=$comprehensive_alarm_count;
  187. $data[0]['fire_brigade_inspector_count']=$fire_brigade_inspector_count;
  188. $res['msg'] = '操作成功';
  189. $res['flag'] = true;
  190. $res['data'] = $data;
  191. echo json_encode($res);
  192. }
  193. }