cqp 3 недель назад
Родитель
Сommit
a74369b351
3 измененных файлов с 4 добавлено и 54 удалено
  1. 1 50
      app/Jobs/ManDeviceJobHc.php
  2. 1 1
      app/Jobs/ManDeviceJobJLWM.php
  3. 2 3
      app/Jobs/ManDeviceJobLf.php

+ 1 - 50
app/Jobs/ManDeviceJobHc.php

@@ -78,55 +78,6 @@ class ManDeviceJobHc implements ShouldQueue
         }
     }
 
-    /**
-     * Execute the job.
-     *
-     * @return void
-     */
-//    public function handle()
-//    {
-//        try {
-//            if (empty($this->data['data'])) return;
-//
-//            $deviceId = $this->data['data']['deviceId'];
-//            $dataPoints = $this->data['data']['dataPoints'] ?? [];
-//
-//            if ($this->data['type'] == "dataPoint") {
-//                $redisKey = 'buffer:hengchang_data';
-//                $batchSize = 500;
-//
-//                // 1. 整理数据并推入 Redis 列表
-//                $records = [];
-//                foreach ($dataPoints as $value) {
-//                    if (empty($value['value'])) continue;
-//
-//                    $records[] = json_encode([
-//                        'machine_code' => $deviceId . $value['dataPointId'],
-//                        'param_value'   => floatval($value['value']),
-//                        'time'    => $this->getNowDay()
-//                    ]);
-//                }
-//
-//                if (!empty($records)) {
-//                    // 批量推入 Redis
-//                    \Illuminate\Support\Facades\Redis::rpush($redisKey, ...$records);
-//                }
-//
-//                // 2. 检查 Redis 里的总条数
-//                $currentCount = \Illuminate\Support\Facades\Redis::llen($redisKey);
-//
-//                // 3. 达到 500 条,执行批量发送
-//
-//                if ($currentCount >= $batchSize) {
-//                    $this->processBatchSend($redisKey, $batchSize);
-//                }
-//            }
-//        } catch (\Exception $exception) {
-//            Log::channel('apiLog')->info('hc开始位置', ["param" => $exception->getMessage()]);
-//            $this->delete();
-//        }
-//    }
-
     /**
      * 批量处理发送逻辑
      */
@@ -139,7 +90,7 @@ class ManDeviceJobHc implements ShouldQueue
             }
         });
 
-        $batchData = array_map(fn($item) => json_decode($item, true), array_filter($rawRecords));
+        $batchData = array_values(array_map(fn($item) => json_decode($item, true), array_filter($rawRecords)));
 
         if (empty($batchData)) return;
 

+ 1 - 1
app/Jobs/ManDeviceJobJLWM.php

@@ -95,7 +95,7 @@ class ManDeviceJobJLWM implements ShouldQueue
             }
         });
 
-        $batchData = array_map(fn($item) => json_decode($item, true), array_filter($rawRecords));
+        $batchData = array_values(array_map(fn($item) => json_decode($item, true), array_filter($rawRecords)));
 
         if (empty($batchData)) return;
 

+ 2 - 3
app/Jobs/ManDeviceJobLf.php

@@ -73,9 +73,8 @@ class ManDeviceJobLf implements ShouldQueue
 
                 // 3. 达到 500 条,执行批量发送
 
-                $this->processBatchSend($redisKey, $batchSize);
                 if ($currentCount >= $batchSize) {
-
+                    $this->processBatchSend($redisKey, $batchSize);
                 }
             }
         } catch (\Exception $exception) {
@@ -96,7 +95,7 @@ class ManDeviceJobLf implements ShouldQueue
             }
         });
 
-        $batchData = array_map(fn($item) => json_decode($item, true), array_filter($rawRecords));
+        $batchData = array_values(array_map(fn($item) => json_decode($item, true), array_filter($rawRecords)));
 
         if (empty($batchData)) return;