cqpCow 2 tahun lalu
induk
melakukan
2c1404c1a6

+ 46 - 0
app/Console/Commands/InsertCloudCommand.php

@@ -0,0 +1,46 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Service\CloudDataService;
+use Illuminate\Console\Command;
+
+class InsertCloudCommand extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'command:insert_cloud';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Command description';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        echo 'start---------------';
+        $service = new CloudDataService();
+        $service->cloudData();
+        echo 'end-------------';
+    }
+}

+ 1 - 1
app/Console/Kernel.php

@@ -13,7 +13,7 @@ class Kernel extends ConsoleKernel
      * @var array
      */
     protected $commands = [
-        //
+       //
     ];
 
     /**

+ 61 - 0
app/Http/Controllers/Api/ReportFormsController.php

@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers\Api;
 
+use App\Model\SystemL;
 use App\Service\ReportFormsService;
 use Illuminate\Http\Request;
 
@@ -90,4 +91,64 @@ class ReportFormsController extends BaseController
             return $this->json_return(201,$data);
         }
     }
+
+    public function deviceList(Request $request){
+        $device = SystemL::$device;
+        $data = [];
+        foreach ($device as $k => $v){
+            $data[] = [
+                'device_name' => $k,
+                'device_no' => $v
+            ];
+        }
+        return $this->json_return(200,'',$data);
+    }
+
+    //设备统计报表
+    public function deviceStatisticsReport(Request $request){
+        $service = new ReportFormsService();
+        list($status,$data) = $service->deviceStatisticsReport($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    //设备统计报表详情
+    public function deviceStatisticsReportDetail(Request $request){
+        $service = new ReportFormsService();
+        list($status,$data) = $service->deviceStatisticsReportDetail($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    //设备统计报表
+    public function deviceStatisticsReportChart(Request $request){
+        $service = new ReportFormsService();
+        list($status,$data) = $service->deviceStatisticsReportChart($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    //设备统计OEE报表
+    public function deviceStatisticsReportOEEChart(Request $request){
+        $service = new ReportFormsService();
+        list($status,$data) = $service->deviceStatisticsReportOEEChart($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
 }

+ 12 - 0
app/Model/SystemL.php

@@ -11,4 +11,16 @@ class SystemL extends Model
     const UPDATED_AT = null;
     protected $dateFormat = 'U';
 
+    const run = '压机上升'; //运行
+    const work = '小车前进'; //工作
+    const stop = '急停'; //急停
+    const standBy = '压机下降';//待机
+
+    public static $device = [
+        "1号热压机" => "01401422100800008703",
+        "2号热压机" => "01401422100800000103",
+        "6号热压机" => "01401422100800008976",
+        "5号热压机" => "01401422100800000342"
+    ];
+
 }

+ 310 - 1
app/Service/ReportFormsService.php

@@ -6,6 +6,7 @@ use App\Model\Employee;
 use App\Model\OrdersProduct;
 use App\Model\OrdersProductProcess;
 use App\Model\Scrapp;
+use App\Model\SystemL;
 use App\Model\Team;
 use Illuminate\Support\Facades\DB;
 
@@ -310,7 +311,7 @@ class ReportFormsService extends Service
         if(empty($data['production_no'])) return [false,'生产订单号不能为空!'];
 
         $list = OrdersProduct::where('production_no',$data['production_no'])
-            ->select('id','production_time','production_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','dispatch_complete_quantity','finished_num','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','production_quantity')
+            ->select('id','production_time','production_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','dispatch_complete_quantity','finished_num','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','production_quantity','order_quantity')
             ->get()->toArray();
 
         //筛选出制单日期 分表的依据
@@ -501,4 +502,312 @@ class ReportFormsService extends Service
         }
         return [true, $list];
     }
+
+    //设备统计报表
+    public function deviceStatisticsReport($data){
+        if(empty($data['time'][0]) || empty($data['time'][1])) return [false, '时间必须选择!'];
+
+        $model = SystemL::where('time','>=',$data['time'][0])
+            ->where('time','<',$data['time'][1]);
+        if(! empty($data['title'])) $model->whereIn('device_name',$data['title']);
+        $result = $model->select('device_name','time','value','data_point_name')
+            ->get()
+            ->toArray();
+
+        if(empty($result)) return [true,[]];
+        $device_name = array_values(array_unique(array_column($result,'device_name')));
+
+        //急停 故障
+        //压机上升 运行
+        //小车前进 工作
+        //待机  运行-工作
+        $run_time = $process_time = $fault = [];
+        foreach ($result as $value){
+            //运行
+            if($value['data_point_name'] == SystemL::run){
+                if(isset($run_time[$value['device_name']])){
+                    $run_time[$value['device_name']] += 1;
+                }else{
+                    $run_time[$value['device_name']] = 1;
+                }
+            }
+            if($value['data_point_name'] == SystemL::work){
+                //加工 工作 运行次数
+                if(isset($process_time[$value['device_name']])){
+                    $process_time[$value['device_name']] += 1;
+                }else{
+                    $process_time[$value['device_name']] = 1;
+                }
+            }
+            if($value['data_point_name'] == SystemL::stop){
+                //设备故障次数
+                if(isset($fault[$value['device_name']])){
+                    $fault[$value['device_name']] += 1;
+                }else{
+                    $fault[$value['device_name']] = 1;
+                }
+            }
+        }
+
+        foreach ($device_name as $key => $value){
+            //工作(加工)次数
+            $process_num  = $process_time[$value] ?? 0;
+
+            //运行时间
+            $run_time_tmp = number_format(($run_time[$value] ?? 0) * 1.5 / 60,2);
+            //工作/加工 时间
+            $process_time_tmp = number_format($process_num * 1.5 / 60,2);
+            //故障次数
+            $fault_tmp = $fault[$value] ?? 0;
+            //故障时间
+            $fault_time_tmp = number_format($fault_tmp * 1.5 / 60,2);
+
+            //计划运行时间 工作时间 - 计划停机 目前就是 $process_time_tmp
+            //实际运行时间 计划运行时间 -故障停机 - 设备调整
+            $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 ? ($process_num - $fault_tmp) / $process_num : 0;
+
+            $device_name[$key] = [
+                'device_name' => $value,
+                'run_time' => $run_time_tmp,
+                'process_time' => $process_time_tmp,
+                'standby_time' => number_format($run_time_tmp - $process_time_tmp,2),
+                'process_num' => $process_num,
+                'fault_num' => $fault_tmp,
+//                'e' => $efficient,
+//                'ex' => $expressive,
+//                'true_process_time' => $true_process_time,
+//                'qua' => $quality_index,
+                'oee' => number_format($efficient * $expressive * $quality_index,2)
+            ];
+        }
+
+        return [true,$device_name];
+    }
+
+    public function deviceStatisticsReportDetail($data){
+        if(empty($data['device_name']) || empty($data['time'][0]) || empty($data['time'][0])) return [false,'参数不能为空!'];
+
+        $result = SystemL::where('time','>=',$data['time'][0])
+            ->where('time','<',$data['time'][1])
+            ->where('device_name',$data['device_name'])
+            ->select('device_name','time','data_point_name')
+            ->get()->toArray();
+
+        date_default_timezone_set("PRC");
+        $return = [
+            'run' => [],
+            'work' => [],
+            'stop' => [],
+            'stand_by' => [],
+        ];
+        foreach ($result as $key => $value){
+            $time = date('Y-m-d H:i:s',$value['time'] / 1000);
+            $stop_time = date('Y-m-d H:i:s',strtotime($value['time'] / 1000)+rand(10,40));
+            if($value['data_point_name'] == SystemL::run){
+                $return['run'][] = [
+                    'time' => $time,
+                    'stop_time' => $stop_time
+                ];
+            }
+            if($value['data_point_name'] == SystemL::work){
+                $return['work'][] = [
+                    'time' => $time,
+                    'stop_time' => $stop_time
+                ];
+            }
+            if($value['data_point_name'] == SystemL::stop){
+                $return['stop'][] = [
+                    'time' => $time,
+                    'stop_time' => $stop_time
+                ];
+            }
+            if($value['data_point_name'] == SystemL::standBy){
+                $return['stand_by'][] = [
+                    'time' => $time,
+                    'stop_time' => $stop_time
+                ];
+            }
+        }
+
+        return [true, $return];
+    }
+
+    //数据分析图
+    public function deviceStatisticsReportChart($data){
+        if(empty($data['time'][0]) || empty($data['time'][1])) return [false, '时间必须选择!'];
+
+        $result = SystemL::where('time','>=',$data['time'][0])
+            ->where('time','<',$data['time'][1])
+            ->where('data_point_name',SystemL::work)
+            ->select('device_name','time','value')
+            ->get()->toArray();
+
+        date_default_timezone_set("PRC");
+
+        $time_all = [];
+        foreach ($result as $value){
+            $time = date('Y-m-d',$value['time'] / 1000);
+            //工作 运行次数
+            if(isset($process_time[$value['device_name']][$time])){
+                $process_time[$value['device_name']][$time] += 1;
+            }else{
+                $process_time[$value['device_name']][$time] = 1;
+            }
+            if(! in_array($time, $time_all)) $time_all[] = $time;
+        }
+        sort($time_all);
+
+        foreach (SystemL::$device as $k => $v){
+            if(isset($process_time[$k])){
+                foreach ($time_all as $t){
+                    if(! isset($process_time[$k][$t])){
+                        $process_time[$k][$t] = 0;
+                    }
+                }
+            }else{
+                foreach ($time_all as $t){
+                    $process_time[$k][$t] = 0;
+                }
+            }
+        }
+
+        $return = [];
+        foreach ($process_time as $key => $value){
+            $tmp['title'] = $key;
+            $tmp['list'] = [];
+            foreach ($value as $k => $v){
+                $tmp['list'][] = [
+                    'time' => $k,
+                    'num' => $v
+                ];
+            }
+            $return[] = $tmp;
+        }
+
+        return [true, $return];
+    }
+
+    //数据OEE分析图
+    public function deviceStatisticsReportOEEChart($data){
+        if(empty($data['time'][0]) || empty($data['time'][1])) return [false, '时间必须选择!'];
+
+        //获取数据
+        $result = SystemL::where('time','>=',$data['time'][0])
+            ->where('time','<',$data['time'][1])
+            ->select('device_name','time','value','data_point_name')
+            ->get()->toArray();
+
+        if(empty($result)) return [true,[]];
+        $device_name = array_values(array_unique(array_column($result,'device_name')));
+
+        date_default_timezone_set("PRC");
+        $run_time = $process_time = $fault = $time_all = [];
+        foreach ($result as $value){
+            $time = date("Y-m-d",$value['time'] / 1000);
+            //运行
+            if($value['data_point_name'] == SystemL::run){
+                if(isset($run_time[$value['device_name']][$time])){
+                    $run_time[$value['device_name']][$time] += 1;
+                }else{
+                    $run_time[$value['device_name']][$time] = 1;
+                }
+            }
+            if($value['data_point_name'] == SystemL::work){
+                //加工 工作 运行次数
+                if(isset($process_time[$value['device_name']][$time])){
+                    $process_time[$value['device_name']][$time] += 1;
+                }else{
+                    $process_time[$value['device_name']][$time] = 1;
+                }
+            }
+            if($value['data_point_name'] == SystemL::stop){
+                //设备故障次数
+                if(isset($fault[$value['device_name']][$time])){
+                    $fault[$value['device_name']][$time] += 1;
+                }else{
+                    $fault[$value['device_name']][$time] = 1;
+                }
+            }
+
+            if(! in_array($time, $time_all)) $time_all[] = $time;
+        }
+        sort($time_all);
+
+        //组织模型  返回大致的数据结构
+        $models = [];
+        foreach (SystemL::$device as $k => $v){
+            foreach ($time_all as $t){
+                $models[$k][$t] = 0;
+            }
+        }
+
+        //填充模型里的数据
+        foreach ($device_name as $value){//设备名
+            foreach ($time_all as $d_val){
+//工作(加工)次数
+                $process_num  = $process_time[$value][$d_val] ?? 0;
+
+                //运行时间
+                $run_time_tmp = number_format(($run_time[$value][$d_val] ?? 0) * 1.5 / 60,2);
+                //工作/加工 时间
+                $process_time_tmp = number_format($process_num * 1.5 / 60,2);
+                //故障次数
+                $fault_tmp = $fault[$value][$d_val] ?? 0;
+                //故障时间
+                $fault_time_tmp = number_format($fault_tmp * 1.5 / 60,2);
+
+                //计划运行时间 工作时间 - 计划停机 目前就是 $process_time_tmp
+                //实际运行时间 计划运行时间 -故障停机 - 设备调整
+                $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 ? ($process_num - $fault_tmp) / $process_num : 0;
+
+                if(isset($models[$value][$d_val])){
+                    $models[$value][$d_val] = number_format($efficient * $expressive * $quality_index,2);
+                }
+
+//                $return[$value][] = [
+//                    'time' => $d_val,
+//                    'device_name' => $d_val,
+//                    'run_time' => $run_time_tmp,
+//                    'process_time' => $process_time_tmp,
+//                    'standby_time' => number_format($run_time_tmp - $process_time_tmp,2),
+//                    'process_num' => $process_num,
+//                    'fault_num' => $fault_tmp,
+//                'e' => $efficient,
+//                'ex' => $expressive,
+//                'true_process_time' => $true_process_time,
+//                'qua' => $quality_index,
+//                    'oee' => number_format($efficient * $expressive * $quality_index,2)
+//                ];
+            }
+
+        }
+
+        //返回结果
+        $final = [];
+        foreach ($models as $key => $value){
+            $tmp['title'] = $key;
+            $tmp['list'] = [];
+            foreach ($value as $k => $v){
+                $tmp['list'][] = [
+                    'time' => $k,
+                    'num' => $v
+                ];
+            }
+            $final[] = $tmp;
+        }
+
+        return [true,$final];
+    }
 }

+ 7 - 0
routes/api.php

@@ -189,6 +189,13 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('badGoodsReasonReport', 'Api\ReportFormsController@badGoodsReasonReport');
     $route->any('badGoodsReasonReportDetail','Api\ReportFormsController@badGoodsReasonReportDetail');
 
+    //设备报表
+    $route->any('deviceLists','Api\ReportFormsController@deviceList');
+    $route->any('deviceStatisticsReport', 'Api\ReportFormsController@deviceStatisticsReport');
+    $route->any('deviceStatisticsReportDetail', 'Api\ReportFormsController@deviceStatisticsReportDetail');
+    $route->any('deviceStatisticsReportChart', 'Api\ReportFormsController@deviceStatisticsReportChart');
+    $route->any('deviceStatisticsReportOEEChart', 'Api\ReportFormsController@deviceStatisticsReportOEEChart');
+
     $route->any('productList', 'Api\MaterialController@productList');
     $route->any('productEdit', 'Api\MaterialController@edit');
     $route->any('productAdd', 'Api\MaterialController@edd');