IndexController.class.php.bak.2021-12-14 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. //报警主机报警总数
  27. $alarm_host_count=M()->query("select count(*) as alarm_host_count from sp_hj2017 where time >='".$end_time."' and device_code in(".$device_list.")");
  28. //消防水系统报警总数
  29. $fire_water_count=M()->query("select count(*) as fire_water_count from sp_sj2017 where time >='".$end_time."' and device_code in(".$device_list.")");
  30. //电气火灾报警总数
  31. $electrical_fire_count=M()->query("select count(*) as electrical_fire_count from sp_ef2017 where time >='".$end_time."' and device_code in(".$device_list.")");
  32. //视频监测报警总数
  33. $video_monitoring_count=M()->query("select count(*) as video_monitoring_count from sp_video2017 where time >='".$end_time."' and device_code in(".$device_list.")");
  34. //井盖
  35. $manhole_cover_count=M()->query("select count(*) as manhole_cover_count from sp_iw2017 where time >='".$end_time."' and device_code in(".$device_list.")");
  36. //门禁
  37. $door_count=M()->query("select count(*) as door_count from sp_door2020 where time >='".$end_time."' and device_code in(".$device_list.")");
  38. //可燃气体
  39. $gas_count=M()->query("select count(*) as gas_count from sp_gas2020 where time >='".$end_time."' and device_code in(".$device_list.")");
  40. //地磁
  41. $geomagnetism_count=M()->query("select count(*) as geomagnetism_count from sp_dc2020 where time >='".$end_time."' and device_code in(".$device_list.")");
  42. //RTU
  43. $rtu_count=M()->query("select count(*) as rtu_count from sp_rtu2017 where time >='".$end_time."' and device_code in(".$device_list.")");
  44. //电梯
  45. $elevator_count=M()->query("select count(*) as elevator_count from sp_lifter2017 where time >='".$end_time."' and device_code in(".$device_list.")");
  46. //其他类型一个月报警总数
  47. $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']
  48. +(int)$elevator_count[0]['elevator_count'];
  49. //报警信息统计结束
  50. //数据等级统计开始
  51. //告警总数
  52. $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']
  53. + (int)$alarm_host_count[0]['alarm_host_count'];
  54. //真实告警
  55. $real_alarm_count=M()->query("select count(*) as real_alarm_count from sp_hj2017 where time >='".$end_time."' and device_code in(".$device_list.") and data2='火警'");
  56. //隐患告警
  57. $hidden_danger_count=(int)$alarm_count-(int)$real_alarm_count[0]['real_alarm_count'];
  58. //事件告警
  59. $event_count=0;
  60. //数据等级统计结束
  61. //设备运行状态开始
  62. //离线
  63. $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.") ");
  64. $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."' ");
  65. $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'];
  66. //故障
  67. $fault_device_count=0;
  68. //预警
  69. $early_warning_device_count=0;
  70. //其他
  71. $other_device_count=0;
  72. //正常
  73. $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.") ");
  74. $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."' ");
  75. $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'];;
  76. //设备运行状态结束
  77. $data[0]['owner_name']=$this->owner_name;
  78. $data[0]['statisticalPeriod']=$statisticalPeriod;
  79. $data[0]['alarm_host_count'] = (int)$alarm_host_count[0]['alarm_host_count'];
  80. $data[0]['fire_water_count'] = (int)$fire_water_count[0]['fire_water_count'];
  81. $data[0]['electrical_fire_count'] = (int)$electrical_fire_count[0]['electrical_fire_count'];
  82. $data[0]['video_monitoring_count'] = (int)$video_monitoring_count[0]['video_monitoring_count'];
  83. $data[0]['other_count'] = $other_count;
  84. $data[0]['alarm_count'] = $alarm_count;
  85. $data[0]['real_alarm_count'] = (int)$real_alarm_count[0]['real_alarm_count'];
  86. $data[0]['hidden_danger_count'] = $hidden_danger_count;
  87. $data[0]['event_count'] = $event_count;
  88. $data[0]['off_line_device_count'] = $off_line_device_count;
  89. $data[0]['fault_device_count'] = $fault_device_count;
  90. $data[0]['early_warning_device_count'] = $early_warning_device_count;
  91. $data[0]['normal_device_count'] = $normal_device_count;
  92. $data[0]['other_device_count'] = $other_device_count;
  93. $data[0]['company_code'] = $company_code;
  94. $res['msg'] = '操作成功';
  95. $res['flag'] = true;
  96. $res['data'] = $data;
  97. echo json_encode($res);
  98. }
  99. public function getCompanyList(){
  100. $Date=I();
  101. if (!empty($_SESSION['phone'])) {
  102. $phone = $_SESSION['phone'];
  103. }else{
  104. $res['msg'] = '操作失败,缓存中参数缺失';
  105. $res['flag'] = 3002;
  106. echo json_encode($res);
  107. exit();
  108. }
  109. $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");
  110. $res['msg'] = '操作成功';
  111. $res['flag'] = true;
  112. $res['data'] = $company;
  113. echo json_encode($res);
  114. }
  115. public function getFunctionalModuleStatistics(){
  116. $Date=I();
  117. $phone=$Date['phone'];
  118. $company_code = $Date['company_code'];
  119. if (!empty($_SESSION['phone'])) {
  120. $phone = $_SESSION['phone'];
  121. }
  122. if (!empty($company_code)){
  123. $device_list = $this->getDeviceCode($company_code);
  124. }else{
  125. $company_code1=M()->query("select owner_code from sp_owner_phone WHERE phone='".$phone."' GROUP BY owner_code limit 1");
  126. $company_code=$company_code1[0]['owner_code'];
  127. $device_list = $this->getDeviceCode($company_code);
  128. }
  129. //报警主机未处理数量统计
  130. $alarm_host_count=M()->query("select count(*) as alarm_host_count from sp_hj2017 where clzt=0 and device_code in(".$device_list.")");
  131. //消防水未处理数量统计
  132. $fire_water_count=M()->query("select count(*) as fire_water_count from sp_sj2017 where clzt=0 and device_code in(".$device_list.")");
  133. //电气火灾未处理数量统计
  134. $electrical_fire_count=M()->query("select count(*) as electrical_fire_count from sp_ef2017 where clzt=0 and device_code in(".$device_list.")");
  135. //视频监测未处理数量统计
  136. $video_monitoring_count=M()->query("select count(*) as video_monitoring_count from sp_video2017 where clzt=0 and device_code in(".$device_list.")");
  137. //井盖未处理数量统计
  138. $manhole_cover_count=M()->query("select count(*) as manhole_cover_count from sp_iw2017 where clzt=0 and device_code in(".$device_list.")");
  139. //门禁未处理数量统计
  140. $door_count=M()->query("select count(*) as door_count from sp_door2020 where clzt=0 and device_code in(".$device_list.")");
  141. //可燃气体未处理数量统计
  142. $gas_count=M()->query("select count(*) as gas_count from sp_gas2020 where clzt=0 and device_code in(".$device_list.")");
  143. //地磁未处理数量统计
  144. $geomagnetism_count=M()->query("select count(*) as geomagnetism_count from sp_dc2020 where clzt=0 and device_code in(".$device_list.")");
  145. //RTU未处理数量统计
  146. $rtu_count=M()->query("select count(*) as rtu_count from sp_rtu2017 where clzt=0 and device_code in(".$device_list.")");
  147. //电梯未处理数量统计
  148. $elevator_count=M()->query("select count(*) as elevator_count from sp_lifter2017 where clzt=0 and device_code in(".$device_list.")");
  149. //综合告警统计
  150. $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[0]['rtu_count']
  151. +(int)$elevator_count[0]['elevator_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']
  152. + (int)$alarm_host_count[0]['alarm_host_count'];
  153. //人员督察单
  154. $personnel_inspection_list = query_187_ytapi("select count(*) as personnel_inspection_list_count from person_data where clzt='0' and company_code='" . $company_code."'");
  155. //电子督察单
  156. $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."'");
  157. //消防支队督察单未处理数量统计
  158. $fire_brigade_inspector_count=$personnel_inspection_list[0]['personnel_inspection_list_count']+$electronic_inspection_sheet[0]['electronic_inspection_sheet_count'];
  159. $data[0]['comprehensive_alarm_count']=$comprehensive_alarm_count;
  160. $data[0]['fire_brigade_inspector_count']=$fire_brigade_inspector_count;
  161. $res['msg'] = '操作成功';
  162. $res['flag'] = true;
  163. $res['data'] = $data;
  164. echo json_encode($res);
  165. }
  166. }