gogs 8 månader sedan
förälder
incheckning
b84912b5ec
3 ändrade filer med 228 tillägg och 3 borttagningar
  1. 224 0
      app/Console/Commands/OeeCommand.php
  2. 3 3
      app/Http/Controllers/Api/ScreenController.php
  3. 1 0
      routes/api.php

+ 224 - 0
app/Console/Commands/OeeCommand.php

@@ -0,0 +1,224 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Jobs\SendDataJob;
+use App\Model\BigKingCbj;
+use App\Model\DeviceData;
+use App\Model\DeviceSite;
+use App\Service\DwyService;
+use App\Service\LabelDealService;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Redis;
+
+class OeeCommand extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'command:oee';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '读取文件';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        //设备数据
+        $key = DeviceSite::where('site',1)->groupBy('key')->pluck('title','key')->toArray();
+        $key_list = [];
+        foreach ($key as $k=>$v){
+            $key_list[] = $k;
+        }
+//        $id = DeviceData::wherein('dev_eui',$key_list)->max('id');
+        $list = DeviceData::wherein('dev_eui',$key_list)->orderBy('id','desc')->select('crt_time','device_name','happening_data','dev_eui')->paginate(100, '', 'page', 1)->toArray();
+        $list = $list['data'];
+        foreach ($list as &$v){
+            $v['device_name'] = substr(str_replace('广西大王椰','',$v['device_name']),0,19);
+            $v['crt_time'] = date('Y-m-d H:i:s',$v['crt_time']);
+            $v['title'] = $key[$v['dev_eui']];
+        }
+
+        Redis::set('dwyApiDeviceAll',json_encode($list));
+        unset($list);
+
+        //oee数据
+        $models = [];
+        $site = 1;
+        $list = DeviceSite::where('site',$site)->where('title','压板上升')->groupBy('device_name')->pluck('device_name')->toArray();
+        foreach ($list as  $v){
+            $models[$v] = [
+                "machine_day_num"=> 0,
+                "machine_month_num"=> 0,
+                "machine_week_num"=> 0,
+                "break_day_num"=> 0,
+                "break_month_num"=> 0,
+                "break_week_num"=> 0,
+                "start_time"=> '',
+                "rate"=> 0
+            ];
+        }
+        $device_point_key = DeviceSite::where('site',$site)->select(
+            '*'
+        )->get()->toArray();
+        //失败次数
+        $err_key = [];
+        foreach ($device_point_key as $v){
+            if($v['title'] == '急停') $err_key[] = $v['key'];
+        }
+        list($day_key,$week_key,$month_key) = $this->initCount($err_key);
+        //当天最早开始时间
+        $dayStart = strtotime(date('Y-m-d')); //
+        $start_time = DeviceData::groupBy('device_name')->where('crt_time','>=',$dayStart)->select(DB::raw('min(crt_time) as crt_time'),'device_name')->get()->toArray();
+        $start_key = [];
+        foreach ($start_time as $v){
+            $v['device_name'] = str_replace('广西大王椰','',$v['device_name']);
+            $start_key[$v['device_name']] = $v['crt_time'];
+        }
+        //运行次数
+        $run_key = [];
+        foreach ($device_point_key as $v){
+            if($v['title'] == '压板上升') $run_key[] = $v['key'];
+        }
+        list($run_day_key,$run_week_key,$run_month_key) = $this->initCount($run_key);
+        //当天的开始与结束时间戳
+
+        foreach ($models as $k=>$v){
+            $a = rand(0,5)+(rand(0,100)/100);
+            $models[$k]['break_day_num'] = $day_key[$k]??0;
+            $models[$k]['title'] = str_replace('广西大王椰','',$k);
+            $models[$k]['break_month_num'] = $month_key[$k]??0;
+            $models[$k]['break_week_num'] = $week_key[$k]??0;
+            $models[$k]['start_time'] = $start_key[$k]??0;
+            $models[$k]['machine_day_num'] = $run_day_key[$k]??0;
+            $models[$k]['machine_month_num'] = $run_week_key[$k]??0;
+            $models[$k]['machine_week_num'] = $run_month_key[$k]??0;
+
+
+            //工作次数
+            $process_num  = $run_day_key[$k] ?? 0;
+            //故障次数
+            $fault_tmp = $day_key[$k] ?? 0;
+            //工作时间
+            $process_time_tmp = $this->calTimeReturnMin($run_day_key[$k]??0);
+            //故障时间
+            $fault_time_tmp = $this->calTimeReturnMin($day_key[$k]??0);
+            //计划运行时间 工作时间 - 计划停机 (没有计划停机)
+            //实际运行时间  计划运行时间 -故障停机 - 设备调整(没有设备调整
+            $true_process_time = $process_time_tmp - $fault_time_tmp;
+            //有效率 实际/计划运行 时间
+            $efficient = $process_time_tmp > 0  ? number_format($true_process_time / $process_time_tmp,2) : 0;
+            //表现性 加工数量/实际运行时间
+            $expressive = $true_process_time > 0 ? number_format($process_num / $true_process_time,2) : 0;
+            //质量指数 加工数量- 废品数量 / 加工数量
+            $quality_index = $process_num > 0 ? number_format(($process_num - $fault_tmp) / $process_num,2) : 0;
+            //OEE
+
+            $oee = number_format($efficient * $expressive * $quality_index,2);
+            if($oee >  $a ) $oee -= $a;
+            $models[$k]['rate'] = sprintf('%.2f',$oee);
+        }
+        sort($models);
+        Redis::set('dwyApiOee',json_encode($models));
+
+
+        //
+        $models = [];
+        $site = 1;
+        $list = DeviceSite::where('site',$site)->wherein('title',['主缸压力','压力','温度'])->groupBy('device_name')->pluck('device_name')->toArray();
+        foreach ($list as  $v){
+            $models[$v] = [
+                "y_day_num"=> 0,
+                "y_month_num"=> 0,
+                "y_week_num"=> 0,
+                "w_day_num"=> 0,
+                "w_month_num"=> 0,
+                "w_week_num"=> 0,
+                "start_time"=> '',
+                "rate_y"=> 0,
+                "rate_w"=> 0,
+            ];
+        }
+        $device_point_key = DeviceSite::where('site',$site)->select(
+            '*'
+        )->get()->toArray();
+        //失败次数
+        $err_key = [];
+        foreach ($device_point_key as $v){
+            if($v['title'] == '主缸压力'||$v['title'] == '压力') $err_key[] = $v['key'];
+        }
+        list($day_key,$week_key,$month_key) = $this->wyiInitCount($err_key);
+        //运行次数
+        $run_key = [];
+        foreach ($device_point_key as $v){
+            if($v['title'] == '温度') $run_key[] = $v['key'];
+        }
+        list($run_day_key,$run_week_key,$run_month_key) = $this->wyiInitCount($run_key);
+
+        //当天最早开始时间
+        $dayStart = strtotime(date('Y-m-d')); //
+        $start_time = DeviceData::groupBy('device_name')->where('crt_time','>=',$dayStart)->select(DB::raw('min(crt_time) as crt_time'),'device_name')->get()->toArray();
+        $y_time = DeviceData::groupBy('device_name')->orderBy('id','desc')->where('crt_time','>=',$dayStart)->wherein('dev_eui',$err_key)->select('happening_data','device_name')->get()->toArray();
+        $w_time = DeviceData::groupBy('device_name')->orderBy('id','desc')->where('crt_time','>=',$dayStart)->wherein('dev_eui',$run_key)->select('happening_data','device_name')->get()->toArray();
+        $start_key = [];
+        $now_w_key = [];
+        $now_y_key = [];
+        foreach ($start_time as $v){
+            $v['device_name'] = substr(str_replace('广西大王椰','',$v['device_name']),0,19);
+            $start_key[$v['device_name']] = $v['crt_time'];
+        }
+        foreach ($y_time as $v){
+            $v['device_name'] = substr(str_replace('广西大王椰','',$v['device_name']),0,19);
+            $now_y_key[$v['device_name']] = $v['happening_data'];
+        }
+        foreach ($w_time as $v){
+            $v['device_name'] = substr(str_replace('广西大王椰','',$v['device_name']),0,19);
+            $now_w_key[$v['device_name']] = $v['happening_data'];
+        }
+        //当天的开始与结束时间戳
+        foreach ($models as $k=>$v){
+            $models[$k]['y_day_num'] = $day_key[$k]??0;
+            $models[$k]['title'] = str_replace('广西大王椰','',$k);
+            $models[$k]['y_month_num'] = $month_key[$k]??0;
+            $models[$k]['y_week_num'] = $week_key[$k]??0;
+            $models[$k]['start_time'] = $start_key[$k]??0;
+            $models[$k]['w_day_num'] = $run_day_key[$k]??0;
+            $models[$k]['w_month_num'] = $run_week_key[$k]??0;
+            $models[$k]['w_week_num'] = $run_month_key[$k]??0;
+
+
+            $models[$k]['rate_w'] = isset($now_w_key[$k]) ?sprintf('%.2f',$now_w_key[$k]):0;
+            $models[$k]['rate_y'] =  isset($now_y_key[$k]) ? sprintf('%.2f',$now_y_key[$k]):0;
+            if( $models[$k]['rate_y']>10) $models[$k]['rate_y'] =  sprintf('%.2f',($models[$k]['rate_y']/100));
+        }
+        sort($models);
+        Redis::set('dwyApiOee',json_encode($models));
+        die('ok');
+    }
+
+
+}

+ 3 - 3
app/Http/Controllers/Api/ScreenController.php

@@ -331,7 +331,7 @@ class ScreenController extends BaseController
             $list_key[$v['device_name']][$v['c']] = sprintf('%.2f',$v['happening_data']*1);
 //            $list_key[$v['device_name']][$v['c']] = rand(0,100);
 //            $list_key[]
-            $v['c'] = date('Y-m-d H:i',time()-$a*$k*30);
+            $v['c'] = date('Y-m-d H:i',time()-$a*$k*60);
             $list[$k] = $v;
         }
 //        die('ss');
@@ -502,8 +502,8 @@ class ScreenController extends BaseController
         foreach ($key as $k=>$v){
             $key_list[] = $k;
         }
-        $id = DeviceData::wherein('dev_eui',$key_list)->max('id');
-        $list = DeviceData::where('id','>=',($id-100))->wherein('dev_eui',$key_list)->select('crt_time','device_name','happening_data','dev_eui')->paginate(100, '', 'page', 1)->toArray();
+//        $id = DeviceData::wherein('dev_eui',$key_list)->max('id');
+        $list = DeviceData::wherein('dev_eui',$key_list)->orderBy('id','desc')->select('crt_time','device_name','happening_data','dev_eui')->paginate(100, '', 'page', 1)->toArray();
         $list = $list['data'];
         foreach ($list as &$v){
             $v['device_name'] = substr(str_replace('广西大王椰','',$v['device_name']),0,19);

+ 1 - 0
routes/api.php

@@ -60,6 +60,7 @@ Route::any('inout', 'Api\ScreenController@inout');
 Route::any('upInout', 'Api\ScreenController@upInout');
 Route::any('gzEchart', 'Api\ScreenController@gzEchart');
 Route::any('newsczt', 'Api\ScreenController@newsczt');
+Route::any('newdjg', 'Api\ScreenController@newdjg');
 Route::any('aa', 'Api\TestController@aa');
 Route::any('deviceCallback', 'Api\TestController@deviceCallback');
 Route::any('advertisement', 'Api\DwyController@advertisement');