Browse Source

响应看板数据时,将task合并到其对应的需求中

langshiyeye 11 months ago
parent
commit
b49abacae0
1 changed files with 15 additions and 8 deletions
  1. 15 8
      app/Services/Project/ProjectKanbanService.php

+ 15 - 8
app/Services/Project/ProjectKanbanService.php

@@ -41,14 +41,14 @@ class ProjectKanbanService
         }
 
         return [
-            'group_data' => $this->getKanbanGroupData($groupIds, $group),
+            'group_data' => $this->getKanbanGroupData($groupIds, $group,$items),
             'group' => $group,
-            'tasks' => $items,
+//            'tasks' => $items,
             'status_items' => $statusItems,
         ];
     }
 
-    protected function getKanbanGroupData(array $ids, string $group)
+    protected function getKanbanGroupData(array $ids, string $group,$items)
     {
         $orderBy = match ($group) {
             "requirement_asc" => ['id', 'asc'],
@@ -58,13 +58,20 @@ class ProjectKanbanService
             default => null
         };
 
+        $collection = Requirement::query()->whereIn("id", $ids)
+            ->when($orderBy, fn($query) => $query->orderBy(...$orderBy))
+            ->get([
+                'id', 'title', 'priority', 'status'
+            ]);
+
+        $collection->each(function ($item, $key)use ($collection,$items) {
+
+            $collection[$key]=(object)array_merge($collection[$key]->toarray(),$items[$collection[$key]->id]);
+        });
+
         return match ($group) {
             "assign", "finished_by" => UserProfileResource::collection(User::query()->whereIn("id", $ids)->get()),
-            default => Requirement::query()->whereIn("id", $ids)
-                ->when($orderBy, fn($query) => $query->orderBy(...$orderBy))
-                ->get([
-                    'id', 'title', 'priority', 'status'
-                ]),
+            default => $collection,
         };
     }
 }