Browse Source

黑洞bim接口完善

moell 10 months ago
parent
commit
7197554c13

+ 61 - 12
app/Services/File/BIM/BlackHole/BlackHole.php

@@ -15,10 +15,24 @@ class BlackHole implements BIMContact
         $treeInfo = $this->getTreeById($projectId);
 
         $modelFile = $this->modelFileCreate($projectId, $treeInfo['subNodes'][0]['nodeId'], $file);
-        dump($modelFile);
 
-        //$this->modelFileCreate(config("bim.black_hole.project_id"), $file);
+        $uploadFormData = [
+            ['name' => 'FileId', 'contents' => $modelFile['fileId']],
+            ['name' => 'FileInfo', 'contents' => $file],
+            ['name' => 'FileDataId', 'contents' => $modelFile['fileDataId']],
+            ['name' => 'Key', 'contents' => uniqid()],
+            ['name' => 'BlobIndex', 'contents' => 0],
+        ];
 
+        $result = Client::getInstance()->post("/blackHole3D/project/modelFile/append", [
+            'multipart' => $uploadFormData,
+            'headers' => [
+                'fileUploadScheme' => 'Bim',
+                'fileUploadMode' => 'ResumableCreate'
+            ]
+        ]);
+
+        dump($result);
 
     }
 
@@ -27,12 +41,52 @@ class BlackHole implements BIMContact
 
     }
 
+    public function viewDataSetModel(array $dataSetIDS)
+    {
+        $result = Client::getInstance()->post("/blackHole3D/project/dataSet/viewDataSetModel", [
+            'dataSetIds' => $dataSetIDS
+        ]);
+
+        return $result['data'] ?? [];
+    }
+
+    public function findConvertStatus(string $dataSetId)
+    {
+        $result = Client::getInstance()->post("/blackHole3D/project/dataSet/getConvertStatus", [
+            'json' => [
+                'dataSetId' => $dataSetId
+            ]
+        ]);
+
+        return $result['data'] ?? [];
+    }
+
+    public function addToConvertQueue(string $dataSetId): array
+    {
+        $formData = [
+            'dataSetId' => $dataSetId,
+            'execConvertingCallback' => '',
+            'isBuildDbIndex' => true,
+            'isResetConverting' => true,
+            'paramFilter' => new \stdClass(),
+            'fileNames' => [],
+            'useDefaultConfig' => false,
+        ];
+
+        $result = Client::getInstance()->post("/blackHole3D/project/modelFile/addToConvertQueue", [
+            'json' => $formData
+        ]);
+
+        return $result['data'] ?? [];
+    }
+
+
     protected function modelFileCreate(string $projectId, string $nodeId, UploadedFile $file)
     {
         $formData = [
             'ProjId' => $projectId,
             'DataSetId' => $nodeId,
-            'FileName' => $file->getClientOriginalName(),
+            'FileName' => uniqid() . $file->getClientOriginalName(),
             'FileSize' => $file->getSize(),
             'FileType' => $file->getExtension() ? $file->getExtension() : pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION),
             'Scheme' => 'Bim',
@@ -41,7 +95,7 @@ class BlackHole implements BIMContact
             'UploadWay' => 0
         ];
 
-        $result = Client::getInstance()->request("POST", "/blackHole3D/project/modelFile/create", [
+        $result = Client::getInstance()->post("/blackHole3D/project/modelFile/create", [
             'form_params' => $formData,
             'headers' => [
                 'fileUploadScheme' => 'Bim',
@@ -54,7 +108,7 @@ class BlackHole implements BIMContact
 
     protected function getTreeById(string $projectId)
     {
-        $result = Client::getInstance()->request("POST", "/blackHole3D/project/modelTree/getTreeById", [
+        $result = Client::getInstance()->post("/blackHole3D/project/modelTree/getTreeById", [
             'json' => [
                 'projId' => $projectId
             ]
@@ -70,18 +124,13 @@ class BlackHole implements BIMContact
             $items[]['dataSetName'] = $node;
         }
 
-        $result = Client::getInstance()->request("POST", "/blackHole3D/project/modelTree/addLevelNodes", [
+        $result = Client::getInstance()->post("/blackHole3D/project/modelTree/addLevelNodes", [
             'json' => [
                 'parentId' => $parentId,
                 'dataSets' => $items
             ]
         ]);
 
-        dump([
-            'parentId' => $parentId,
-            'dataSets' => $items
-        ]);
-
-        dump($result);
+        return $result['data'] ?? [];
     }
 }

+ 22 - 5
app/Services/File/BIM/BlackHole/Client.php

@@ -36,20 +36,37 @@ class Client {
         return self::$instance;
     }
 
-    public function request(string $method, string $uri, array $option = []): ?array
+    public function request(string $method, string $uri, array $options = []): ?array
     {
-        return $this->parseResponse($this->client->request($method, $uri, $option));
+        return $this->parseResponse($this->client->request($method, $uri, $options));
+    }
+
+    public function post(string $uri, array $options = []) {
+        return $this->request("POST", $uri, $options);
     }
 
     protected function parseResponse(ResponseInterface $response): ?array
     {
         $body = json_decode((string)$response->getBody(), true);
-        dump((string)$response->getBody());
-        $isJson = json_last_error() == JSON_ERROR_NONE;
 
         return match ($response->getStatusCode()) {
-            200, 201, 204 => $isJson ? $body : null,
+            200, 201, 204 => $this->parseStatusSuccessResponse($body),
             default => throw new FailedException($body['message'] ?? $response->getReasonPhrase()),
         };
     }
+
+    protected function parseStatusSuccessResponse(array $body)
+    {
+        $isJson = json_last_error() == JSON_ERROR_NONE;
+
+        if (! $isJson) {
+            return [];
+        }
+
+        if (! $body['isSuccess']) {
+            throw new FailedException($body['errMsg']);
+        }
+
+        return $body;
+    }
 }

+ 6 - 0
app/Services/File/BIM/Contacts/BIMContact.php

@@ -9,4 +9,10 @@ interface BIMContact {
     public function uploadFile(UploadedFile $file, array $params = []);
 
     public function downloadSourceFile();
+
+    public function findConvertStatus(string $dataSetId);
+
+    public function viewDataSetModel(array $dataSetIDS);
+
+    public function addToConvertQueue(string $dataSetId): array;
 }

+ 1 - 1
config/bim.php

@@ -6,7 +6,7 @@ return [
     'extensions' => ['rvt', 'ifc', 'fbx', '3dxml', 'gim', 'igms', 'stp', 'gltf', '3dm', 'skp', 'glb', 'dgn', 'nwd', 'nwc'],
 
     'black_hole' => [
-        'host' => env("BLACK_HOLE_HOST", "http://106.52.199.205:9012/"),
+        'host' => env("BLACK_HOLE_HOST", "http://106.53.68.51:9012/"),
         'client_id' => env("BLACK_HOLE_CLIENT_ID"),
         'secret_key' => env("BLACK_HOLE_SECRET_KEY"),
         'user_id' => env("BLACK_HOLE_USER_ID"),