moell 10 mēneši atpakaļ
vecāks
revīzija
ff01a87cb0

+ 6 - 0
app/Services/File/BIM/Glendale/Client.php

@@ -44,6 +44,12 @@ class Client {
         return $this->request("POST", $uri, $options);
     }
 
+    public function get(string $uri, array $params = []) {
+        return $this->request("POST", $uri, [
+            'query_params' => $params
+        ]);
+    }
+
     protected function parseResponse(ResponseInterface $response): ?array
     {
         $body = json_decode((string)$response->getBody(), true);

+ 50 - 0
app/Services/File/BIM/Glendale/ExtensionModelConfig.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace App\Services\File\BIM\Glendale;
+
+class ExtensionModelConfig
+{
+    public static function getConfigOption(string $extension): array
+    {
+        return match ($extension) {
+            "rvt" => [
+                "style" => 1,
+                "zGrid" => 0,
+                "drawing" => 0,
+                "accuracy" => 5,
+                "vertexNormal" => 1,
+                "locationType" => 3,
+                "type" => 4,
+                "draco" => 1,
+                "isInstance" => 1,
+                "faceNumLimit" => 300000,
+                "materialType" => 1
+            ],
+            'dwg', 'dwf', 'dws', 'dwt' => [
+                "style" => 0,
+                "zGrid" => 0,
+                "drawing" => 0,
+                "accuracy" => 5,
+                "vertexNormal" => 0,
+                "unitRatio" => 0.001,
+                "type" => 2,
+                "isInstance" => 0,
+                "draco" => 0,
+                "engineType" => 1,
+                "combineTexture" => 0
+            ],
+            default => [
+                "style" => 0,
+                "zGrid" => 0,
+                "drawing" => 0,
+                "accuracy" => 5,
+                "vertexNormal" => 1,
+                "type" => 4,
+                "draco" => 1,
+                "isInstance" => 1,
+                "faceNumLimit" => 300000,
+                "materialType" => 1
+            ]
+        };
+    }
+}

+ 64 - 3
app/Services/File/BIM/Glendale/Glendale.php

@@ -2,15 +2,48 @@
 
 namespace App\Services\File\BIM\Glendale;
 
+use App\Models\Enums\BimFileConvertStatus;
 use App\Services\File\BIM\Contacts\BIMContact;
 use Illuminate\Http\UploadedFile;
+use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\Storage;
+use Ramsey\Uuid\Uuid;
 
 class Glendale implements BIMContact
 {
 
     public function uploadFile(UploadedFile $file, array $params = [])
     {
-        // TODO: Implement uploadFile() method.
+        /*dump([
+            'name' => $file->getClientOriginalName(),
+            'initiatingUser' => Auth::user()->name,
+            'uniqueCode' => Uuid::uuid4(),
+            'priority' => 205,
+            'isCAD' => $params['is_cad'],
+            'modelDownloadUrl' => Storage::url($params['pathname'])
+        ]);*/
+
+        $uploadFormData = [
+            ['name' => 'file', 'contents' =>  fopen($file, 'r')]
+        ];
+
+        $result = Client::getInstance()->post('/api/app/model/transcode-file', [
+            'query_params' => [
+                'input' => json_encode([
+                    'name' => $file->getClientOriginalName(),
+                    'initiatingUser' => Auth::user()->name,
+                    'uniqueCode' => Uuid::uuid4(),
+                    'priority' => 205,
+                    'isCAD' => $params['is_cad'],
+                    'modelDownloadUrl' => $params['pathname'],
+                    "configJson" => ExtensionModelConfig::getConfigOption($params['extension']),
+                ])
+            ],
+            //'multipart' => $uploadFormData,
+        ]);
+
+        dump($result);
+
     }
 
     public function downloadSourceFile()
@@ -20,12 +53,40 @@ class Glendale implements BIMContact
 
     public function findConvertStatus(string $dataSetId)
     {
-        // TODO: Implement findConvertStatus() method.
+        $result = Client::getInstance()->post('/api/app/model/query-model-info', [
+            'query_params' => [
+                'LightweightName' => $dataSetId
+            ]
+        ]);
+
+        $getStatus = function($status) {
+            if ($status >= 1 && $status <= 99) {
+                return BimFileConvertStatus::CONVERTING->value;
+            }
+
+            if ($status <= 0) {
+                return BimFileConvertStatus::FAILED_TO_ADD_QUEUE->value;
+            }
+
+            return BimFileConvertStatus::IN_QUEUE->value;
+        };
+
+        return match ($result['data']['status']) {
+            0, 1, 101 => BimFileConvertStatus::IN_QUEUE->value,
+            100 => BimFileConvertStatus::DONE->value,
+            default => $getStatus($result['data']['status'])
+        };
     }
 
     public function viewDataSetModel(array $dataSetIDS)
     {
-        // TODO: Implement viewDataSetModel() method.
+        $result = Client::getInstance()->get('/api/app/model/model-SourceFileurl', [
+            'LightweightName' => $dataSetIDS[0]
+        ]);
+
+        return [
+            'datas' => $result['datas']
+        ];
     }
 
     public function addToConvertQueue(string $dataSetId): array

+ 8 - 3
app/Services/File/Upload/FilesUploadTrait.php

@@ -43,20 +43,25 @@ trait FilesUploadTrait
 
     protected function uploadFile(Request $request, UploadedFile $file): array
     {
+        $extension = $file->extension() ? $file->extension() : pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
+
         $pathname = $file->storeAs(
             sprintf("c%s/%s/%s", Auth::user()->company_id, $request->get("object_type"), date("Ymd")),
-            sprintf("%s.%s", md5(uniqid()), $file->extension())
+            sprintf("%s.%s", md5(uniqid()), $extension)
         );
 
         $data = [
             'bim' => [],
         ];
 
-        $extension = $file->extension() ? $file->extension() : pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
         $isBimFile = 0;
         if (in_array($extension, config("bim.extensions")) && $request->object_type == FileObjectType::CONTAINER->value) {
             $isBimFile = true;
-            $data['bim'] = BIMFactory::make()->uploadFile($file);
+            $data['bim'] = BIMFactory::make()->uploadFile($file, [
+                'pathname' => $pathname,
+                'extension' => $extension,
+                'is_cad' => in_array($extension, ['dwg', 'dwf', 'dws', 'dwt']),
+            ]);
         }
 
         throw_validation_if(! $pathname, "File upload failed.");