소스 검색

超节损计算优化

unknown 1 주 전
부모
커밋
20cf665085
2개의 변경된 파일62개의 추가작업 그리고 1개의 파일을 삭제
  1. 6 1
      application/job/OrderLossQueueWorker.php
  2. 56 0
      application/job/OrderSuperLossJob.php

+ 6 - 1
application/job/OrderLossQueueWorker.php

@@ -102,8 +102,13 @@ class OrderLossQueueWorker
             ->where('印件及工序', $task['yjno'])
             ->delete();
 
-        Db::name('工单_质量考核汇总')
+        $insertSql = Db::name('工单_质量考核汇总')
+            ->fetchSql(true)
             ->insertAll($result);
+        $insertRes = Db::query($insertSql);
+        if ($insertRes === false) {
+            throw new \RuntimeException("超节损队列插入失败: {$task['gdbh']}-{$task['yjno']}");
+        }
     }
 
     private function updateProgress($batchId)

+ 56 - 0
application/job/OrderSuperLossJob.php

@@ -0,0 +1,56 @@
+<?php
+
+namespace app\job;
+
+use app\api\controller\OrderSuperLoss;
+use think\Db;
+use think\Log;
+
+class OrderSuperLossJob
+{
+    /**
+     * 队列消费入口(ThinkPHP queue fire)
+     * @param $job
+     * @param array $data
+     */
+    public function fire($job, $data)
+    {
+        try {
+            if (empty($data['gdbh']) || empty($data['yjno'])) {
+                Log::error('超节损队列参数缺失: ' . json_encode($data, JSON_UNESCAPED_UNICODE));
+                $job->delete();
+                return;
+            }
+
+            $api = new OrderSuperLoss();
+            $result = $api->OneOrderSuperLoss($data['gdbh'], $data['yjno']);
+
+            if (empty($result) || !is_array($result)) {
+                Log::warning('超节损队列无可写入数据: ' . $data['gdbh'] . '-' . $data['yjno']);
+                $job->delete();
+                return;
+            }
+
+            Db::name('工单_质量考核汇总')
+                ->where('Gy0_gdbh', $data['gdbh'])
+                ->where('印件及工序', $data['yjno'])
+                ->delete();
+
+            $insertSql = Db::name('工单_质量考核汇总')
+                ->fetchSql(true)
+                ->insertAll($result);
+            $insertRes = Db::query($insertSql);
+            if ($insertRes === false) {
+                throw new \RuntimeException('超节损队列写入失败');
+            }
+            $job->delete();
+        } catch (\Throwable $e) {
+            Log::error('超节损队列执行失败: ' . $e->getMessage() . '; data=' . json_encode($data, JSON_UNESCAPED_UNICODE));
+            if ($job->attempts() >= 3) {
+                $job->delete();
+            } else {
+                $job->release(10);
+            }
+        }
+    }
+}