Ver código fonte

临时福洋洋的拿过来直接用

gogs 5 meses atrás
pai
commit
a7638a671c

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

@@ -0,0 +1,35 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+use App\Model\SystemL;
+use App\Service\ReportFormsService;
+use Illuminate\Http\Request;
+
+class ReportFormsController extends BaseController
+{
+
+    //设备统计报表
+    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);
+        }
+    }
+}

+ 31 - 0
app/Model/SystemL.php

@@ -0,0 +1,31 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class SystemL extends Model
+{
+    protected $table = "system_L"; //指定表
+    const CREATED_AT = null;
+    const UPDATED_AT = null;
+    protected $dateFormat = 'U';
+
+    const run = '压机上升'; //  运行时间/次数
+    const work = '小车前进'; // 工作时间/次数  不用了
+    const stop = '急停'; // 故障时间/次数
+    const standBy = '压机下降';// 待机时间/次数
+
+    public static $device = [
+        "2号热压机" => "01401422102400001960",
+        "UV生产线" => "01401422100800000103",
+        "6号热压机" => "01401422100800008976",
+        "5号热压机" => "01401422100800000342"
+    ];
+
+    public static $device_point_id_1 = [
+        self::run => '15262427',
+        self::stop => '15262429',
+        self::standBy => '15262428',
+    ];
+}

+ 223 - 0
app/Service/ReportFormsService.php

@@ -0,0 +1,223 @@
+<?php
+
+namespace App\Service;
+
+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;
+
+/**
+ * 设备相关设置报表
+ * Class ReportFormsService
+ * @package App\Service
+ */
+class ReportFormsService extends Service
+{
+
+
+    /**
+     * 数据分析图
+     * @param $data
+     * @return array
+     */
+    public function deviceStatisticsReportChart($data){
+        if(empty($data['time'][0]) || empty($data['time'][1])) return [false, '时间必须选择!'];
+
+        $day = $this->returnDays($data['time'], false);
+        if($day > 31) return [false, '查询时间仅支持范围区间在31天内'];
+
+        $process_time = [];
+
+        $result = SystemL::where('time','>=',$data['time'][0])
+            ->where('time','<',$data['time'][1])
+            ->where('data_point_name',SystemL::standBy)
+            ->select('device_name','time','value')
+            ->get()->toArray();
+
+        //所有的时间
+        $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分析图
+     * @param $data
+     * @return array
+     */
+    public function deviceStatisticsReportOEEChart($data){
+        if(empty($data['time'][0]) || empty($data['time'][1])) return [false, '时间必须选择!'];
+
+        $day = $this->returnDays($data['time'], false);
+        if($day > 31) return [false, '查询时间仅支持范围区间在31天内'];
+
+        //获取数据
+        $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')));
+
+
+        $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 || $value['data_point_name'] == SystemL::standBy){
+                //运行次数
+                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::standBy){
+                //工作次数
+                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){
+                //运行次数
+                $run_num = $run_time[$value][$d_val] ?? 0;
+                //工作次数
+                $process_num  = $process_time[$value][$d_val] ?? 0;
+                //故障次数
+                $fault_tmp = $fault[$value][$d_val] ?? 0;
+
+                //运行时间
+                $run_time_tmp = $this->calTimeReturnMin($run_num);
+                //工作时间
+                $process_time_tmp = $this->calTimeReturnMin($process_num);
+                //故障时间
+                $fault_time_tmp = $this->calTimeReturnMin($fault_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 ? number_format(($process_num - $fault_tmp) / $process_num,2) : 0;
+                //OEE
+                $oee = number_format($efficient * $expressive * $quality_index,2);
+                //模型里赋值
+                if(isset($models[$value][$d_val])){
+                    $models[$value][$d_val] = $oee;
+                }
+            }
+        }
+
+        //返回结果
+        $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];
+    }
+
+    /**
+     * 用于计算时间
+     * @param $minute
+     * @return string
+     */
+    public function calTimeReturnMin($minute){
+        return number_format($minute * 1.5 / 60,2);
+    }
+
+    function returnDays($time = [], $is_mirco_time = true){
+
+        // 示例时间戳
+        $timestamp1 = $time[0];
+        $timestamp2 = $time[1];
+
+        // 计算时间差
+        $difference = abs($timestamp2 - $timestamp1);
+
+        // 将时间差转换为天数
+        $days = floor($difference / (60 * 60 * 24));
+        if($is_mirco_time) $days = $days / 1000;
+
+        return $days;
+    }
+}

+ 3 - 0
routes/api.php

@@ -32,6 +32,9 @@ Route::any('testdwyget','Api\TestController@testdwyget');
 Route::any('testdwyput','Api\TestController@testdwyput');
 Route::any('getFileData','Api\ImportController@getFileData');
 
+Route::any('deviceStatisticsReportChart', 'Api\ReportFormsController@deviceStatisticsReportChart');
+Route::any('deviceStatisticsReportOEEChart', 'Api\ReportFormsController@deviceStatisticsReportOEEChart');
+
 Route::group(['middleware'=> ['CheckJRFIDLogin']],function ($route){
     //站点获取登录后
     $route->any('getSiteByLogin', 'Api\JRFIDController@getSite2');