cqp 2 tuần trước cách đây
mục cha
commit
27a0158eb5
1 tập tin đã thay đổi với 46 bổ sung1 xóa
  1. 46 1
      app/Service/ReportFormsService.php

+ 46 - 1
app/Service/ReportFormsService.php

@@ -44,7 +44,7 @@ class ReportFormsService extends Service
      * @param $data
      * @return array
      */
-    public function deviceStatisticsReportOEEChart($data){
+    public function deviceStatisticsReportOEEChart1($data){
         if(empty($data['time'][0]) || empty($data['time'][1])) return [false, '时间必须选择!'];
         $site = $data['header'][2];
 
@@ -89,6 +89,51 @@ class ReportFormsService extends Service
         return [true, $return];
     }
 
+    public function deviceStatisticsReportOEEChart($data){
+        if(empty($data['time'][0]) || empty($data['time'][1])) return [false, '时间必须选择!'];
+        $site = $data['header'][2];
+
+        $day = $this->returnDays($data['time'], false);
+        if($day > 10) return [false, '查询时间仅支持范围区间在10天内'];
+
+        $device = SystemL::$device[$site];
+        $return = [];
+        $todayStart = strtotime(date('Y-m-d'));
+
+        foreach ($device as $key => $value){
+            $list = [];
+            for ($i = $data['time'][0]; $i <= $data['time'][1]; $i += 86400){
+                $currentDate = date("Y-m-d", $i);
+                $tmp['time'] = $currentDate;
+
+                if ($i > $todayStart) {
+                    $tmp['num'] = null;
+                } else {
+                    // --- 核心逻辑开始 ---
+                    // 使用 设备+日期 锁定种子
+                    mt_srand(crc32($key . $currentDate));
+
+                    // 模拟 15% 的概率设备不工作 (你可以调整这个 85)
+                    if (mt_rand(1, 100) > 85) {
+                        $tmp['num'] = 0; // 或者设为 null,取决于你前端图表想怎么展示
+                    } else {
+                        $tmp['num'] = $this->getRandomFloat(35);
+                    }
+                    // --- 核心逻辑结束 ---
+                }
+                $list[] = $tmp;
+            }
+
+            mt_srand(); // 重置种子
+            $return[] = [
+                "title" => $key,
+                "list" => $list
+            ];
+        }
+
+        return [true, $return];
+    }
+
     function getRandomFloat($min = 40, $max = 43) {
         // 生成一个在[0, 100)范围内的随机整数(乘以100是为了扩大范围,便于计算)
         $randomInt = mt_rand(0, 99);