CameraStatusHistory 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Enum\ApiEnum;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Support\Facades\DB;
  6. class LogEmailSend extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'camera:statushistory';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '摄像头统计历史数据';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. $this->cameraStatusHistory();
  37. }
  38. //摄像头统计历史数据
  39. public function cameraStatusHistory()
  40. {
  41. $result['status'] = true;
  42. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  43. //宁煤集团
  44. $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
  45. $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();//所有区域
  46. $mine_ningmei = [];//宁煤集团所有区域
  47. foreach($mine_all as $k=>$v){
  48. if(explode('|',$v->degree)[0] == $ningmei[0]->id){
  49. $mine_ningmei[] = $v->id;
  50. }
  51. }
  52. //宁煤在离线数量
  53. $data[0]['title'] = '宁煤公司';
  54. $data[0]['mine_code'] = $ningmei[0]->slug;
  55. $data[0]['total'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('deleted_at',null)->count();
  56. $data[0]['total_online'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('camera_status',1)->where('deleted_at',null)->count();
  57. $data[0]['total_offline'] = $data[0]['total'] - $data[0]['total_online'];
  58. $data[0]['rate'] = round($data[0]['total_online'] / $data[0]['total'] * 100,2);
  59. //宁煤下各矿在离线数量
  60. $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->where('deleted_at',null)->get();
  61. foreach($mine_list as $k => $v){
  62. $mine_use = [];//宁煤下每个矿所有区域
  63. foreach($mine_all as $key=>$value){
  64. if(count(explode('|',$value->degree)) > 1){
  65. if(explode('|',$value->degree)[0] == $ningmei[0]->id && explode('|',$value->degree)[1] == $v->id){
  66. $mine_use[] = $value->id;
  67. }
  68. }
  69. }
  70. $total = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('deleted_at',null)->count();
  71. $total_online = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('camera_status',1)->where('deleted_at',null)->count();
  72. if($total == 0){
  73. $rate = "0";
  74. }else{
  75. $rate = round($total_online / $total * 100,2);
  76. }
  77. if($v->slug == 'NingXiaMeiYeTeShuZuoYeJianKongShiPin'){
  78. $res['title'] = $v->title;
  79. $res['mine_code'] = $v->slug."_jituan";
  80. $res['total'] = $total;
  81. $res['total_online'] = $total_online;
  82. $res['total_offline'] = $total - $total_online;
  83. $res['rate'] = $rate;
  84. }else{
  85. array_push($data,[
  86. 'title'=>$v->title,
  87. 'mine_code'=>$v->slug."_jituan",
  88. 'total'=>$total,
  89. 'total_online'=>$total_online,
  90. 'total_offline'=>$total - $total_online,
  91. 'rate'=>$rate
  92. ]);
  93. }
  94. }
  95. if(isset($res)){
  96. array_push($data,[
  97. 'title'=>$res['title'],
  98. 'mine_code'=>$res['mine_code'],
  99. 'total'=>$res['total'],
  100. 'total_online'=>$res['total_online'],
  101. 'total_offline'=>$res['total_offline'],
  102. 'rate'=>$res['rate']
  103. ]);
  104. }
  105. $timestamp = strtotime(date('Y-m-d H:i:s'));
  106. $hour = date('G', $timestamp);
  107. $minute = date('i', $timestamp);
  108. $month = date('n', $timestamp);
  109. $day = date('j', $timestamp);
  110. if($minute == '00'){
  111. $minute = '';
  112. }
  113. if ($hour < 12) {
  114. $time = $month."月".$day."号上午".$hour."时".$minute;
  115. } elseif ($hour >= 12 && $hour < 18) {
  116. $time = $month."月".$day."号下午".$hour."时".$minute;
  117. } else {
  118. $time = $month."月".$day."号晚上".$hour."时".$minute;
  119. }
  120. $unit_max_name = '';
  121. $unit_max_rate = 0;
  122. $unit_min_name = '';
  123. $unit_min_rate = 100;
  124. $mzy_max_name = '';
  125. $mzy_max_rate = 0;
  126. $mzy_min_name = '';
  127. $mzy_min_rate = 100;
  128. $other_max_name = '';
  129. $other_max_rate = 0;
  130. $other_min_name = '';
  131. $other_min_rate = 100;
  132. if(count($data)>0){
  133. for($i=0;$i<count($data);$i++){
  134. if (strpos($data[$i]['title'], '煤矿') !== false) {
  135. if($data[$i]['rate'] > $unit_max_rate){
  136. $unit_max_rate = $data[$i]['rate'];
  137. }
  138. if($data[$i]['rate'] < $unit_min_rate){
  139. $unit_min_rate = $data[$i]['rate'];
  140. }
  141. }elseif(strpos($data[$i]['title'], '煤制油') !== false){
  142. if($data[$i]['rate'] > $mzy_max_rate){
  143. $mzy_max_rate = $data[$i]['rate'];
  144. }
  145. if($data[$i]['rate'] < $mzy_min_rate){
  146. $mzy_min_rate = $data[$i]['rate'];
  147. }
  148. }else{
  149. if($data[$i]['rate'] > $other_max_rate){
  150. $other_max_rate = $data[$i]['rate'];
  151. }
  152. if($data[$i]['rate'] < $other_min_rate){
  153. $other_min_rate = $data[$i]['rate'];
  154. }
  155. }
  156. }
  157. for($i=0;$i<count($data);$i++){
  158. if (strpos($data[$i]['title'], '煤矿') !== false) {
  159. if($data[$i]['rate'] == $unit_max_rate){
  160. $unit_max_name = $unit_max_name.'、'.$data[$i]['title'];
  161. }
  162. if($data[$i]['rate'] == $unit_min_rate){
  163. $unit_min_name = $unit_max_name.'、'.$data[$i]['title'];
  164. }
  165. }elseif(strpos($data[$i]['title'], '煤制油') !== false){
  166. if($data[$i]['rate'] == $mzy_max_rate){
  167. $mzy_max_name = $mzy_max_name.'、'.$data[$i]['title'];
  168. }
  169. if($data[$i]['rate'] == $mzy_min_rate){
  170. $mzy_min_name = $mzy_max_name.'、'.$data[$i]['title'];
  171. }
  172. }else{
  173. if($data[$i]['rate'] == $other_max_rate){
  174. $other_max_name = $other_max_name.'、'.$data[$i]['title'];
  175. }
  176. if($data[$i]['rate'] == $other_min_rate){
  177. $other_min_name = $other_max_name.'、'.$data[$i]['title'];
  178. }
  179. }
  180. }
  181. }
  182. $unit_max_name = mb_substr($unit_max_name, 1);
  183. $unit_min_name = mb_substr($unit_min_name, 1);
  184. $mzy_max_name = mb_substr($mzy_max_name, 1);
  185. $mzy_min_name = mb_substr($mzy_min_name, 1);
  186. $other_max_name = mb_substr($other_max_name, 1);
  187. $other_min_name = mb_substr($other_min_name, 1);
  188. $result['data'] = '本周公司视频摄像头在线数'.$data[0]['total_online'].'个,'.'在线率为'.$data[0]['rate'].'%('.$time
  189. .'统计)。其中:①煤炭生产建设单位在线率排名第一的单位是'.$unit_max_name.',在线率达到'.$unit_max_rate
  190. .'%;排名末位的单位是'.$unit_min_name.',在线率达到'.$unit_min_rate
  191. .'%。②煤制油化工单位在线率排名第一的单位是'.$mzy_max_name.',在线率达到'.$mzy_max_rate.'%;排名末位的单位是'
  192. .$mzy_min_name.',在线率达到'.$mzy_min_rate.'%。③其他单位在线率排名第一的单位是'.$other_max_name
  193. .',在线率达到'.$other_max_rate.'%;排名末位的单位是'.$other_min_name.',在线率达到'.$other_min_rate.'%。';
  194. DB::table('camera_status_history')->insert(['content'=>$result['data']]);
  195. }
  196. }