cqpCow 2 年之前
父节点
当前提交
61dfeb285c
共有 1 个文件被更改,包括 19 次插入10 次删除
  1. 19 10
      app/Service/FyySqlServerService.php

+ 19 - 10
app/Service/FyySqlServerService.php

@@ -190,16 +190,25 @@ class FyySqlServerService extends Service
         $result = $msg;
 
         //查询附带的一些信息(比较少)
-        $product_no = array_column($result,'product_no');
-        $messageOne = $this->db->table('Inventory as a')
-            ->join('ComputationUnit as b',function($join){
-                $join->on('a.cGroupCode','=','b.cGroupCode')
-                    ->on('a.cComUnitCode','=','b.cComUnitCode');
-            }, null,null,'left')
-            ->whereIn('a.cInvCode',$product_no)
-            ->select('a.cInvCode as product_no','a.cInvName as product_title','a.cInvStd as product_size','b.cComUnitName as product_unit')
-            ->get()->toArray();
-        $messageMap = array_column($messageOne,null,'product_no');
+        $product_no = array_filter(array_column($result,'product_no'));
+        $chunkSize = 1000; // 每个子集的大小
+        $chunks = array_chunk($product_no, $chunkSize); // 将原始数组拆分成多个较小的子数组
+
+        $results = []; // 存储查询结果的数组
+        foreach ($chunks as $chunk) {
+            $tmp = $this->db->table('Inventory as a')
+                ->join('ComputationUnit as b', function ($join) {
+                    $join->on('a.cGroupCode', '=', 'b.cGroupCode')
+                        ->on('a.cComUnitCode', '=', 'b.cComUnitCode');
+                }, null, null, 'left')
+                ->whereIn('a.cInvCode', $chunk)
+                ->select('a.cInvCode as product_no', 'a.cInvName as product_title', 'a.cInvStd as product_size', 'b.cComUnitName as product_unit')
+                ->get()
+                ->toArray();
+            $results = array_merge($results, $tmp); // 将每个子集的结果合并到总结果数组中
+        }
+        $messageMap = array_column($results,null,'product_no');
+        unset($results);
 
         //现存量查询开始 ---组织查询条件
         $args = '';