Browse Source

Merge remote-tracking branch 'origin/dev' into dev

kevinlan@lpchku.com 5 months ago
parent
commit
bfd212c58c

+ 19 - 0
app/BO/BimFileBO.php

@@ -18,6 +18,7 @@ class BimFileBO
     public function __construct(
         string $extension,
         string $name,
+        string $modelType = '',
         int $priority = 205,
         string $modelDownloadUrl = ''
     ) {
@@ -27,6 +28,24 @@ class BimFileBO
         $this->uniqueCode = Uuid::uuid4();
         $this->priority = $priority;
         $this->modelDownloadUrl = $modelDownloadUrl;
+        $this->modelType = $modelType;
+        if (empty($this->modelType)) {
+            $this->modelType = $this->guessModelType();
+        }
+    }
+
+    private function guessModelType(): string
+    {
+        if ($this->isCAD) {
+            return 'cad';
+        }
+        if (in_array($this->extension, config('bim.extensions'))) {
+            return 'bim';
+        }
+        if (in_array($this->extension, config('bim.gis_extensions'))) {
+            return 'gis';
+        }
+        return '';
     }
 
     /**

+ 1 - 1
app/Http/Resources/API/FileByObjectResource.php

@@ -30,7 +30,7 @@ class FileByObjectResource extends JsonResource
         ];
 
         if ($this->is_bim == 1 && $this->bimFile && $this->bimFile->convert_status == BimFileConvertStatus::DONE->value) {
-            $data['model_view_url'] = 'todo';//@todo 跟前端重新对一下判断
+            $data['model_preview'] = true;
         }
 
         return $data;

+ 12 - 16
app/Libraries/BIM/Glendale/Glendale.php

@@ -148,7 +148,7 @@ class Glendale extends BIMAbstract
         } elseif ($this->isPointCloudGISModel($bimFileBO->extension)) { //点云GIS
             $result = $this->uploadPointCloudModelByStream($file, $bimFileBO);
         } elseif ($this->isOSGBGISModel($bimFileBO->modelType)) { // OSGB 模型
-            $result = $this->uploadOSGBModelByStream($file, $bimFileBO);
+            $result = $this->uploadOSGBModelByStream($file, bimFileBO: $bimFileBO);
         } else { //文件流方式上传
             $result = $this->uploadModelByStream($file, $bimFileBO);
         }
@@ -158,6 +158,7 @@ class Glendale extends BIMAbstract
             'bim_file_id' => $result['datas']['lightweightName'],
             'convert_status' => BimFileConvertStatus::IN_QUEUE->value,
             'bim_driver' => BIMDriverEnum::GLENDALE->value,
+            'model_type' => $bimFileBO->modelType,
         ];
     }
 
@@ -220,34 +221,29 @@ class Glendale extends BIMAbstract
                     'LightweightName' => $file->bimFile->bim_data_set_id
                 ]
             ]);
-            if (isset($result['datas'][0])) {
-                $result = $result['datas'][0];
-                $result['modelType'] = 'gis';
-            }
+
         } else {
             $result = Client::getInstance()->post('/api/app/model/query-model-info', [
                 'query' => [
                     'LightweightName' => $file->bimFile->bim_data_set_id
                 ]
             ]);
-            if (isset($result['datas'][0])) {
-                $result = $result['datas'][0];
-                if ($result['isCAD']) {
-                    $result['modelType'] = 'cad';
-                } else {
-                    $result['modelType'] = 'bim';
-                }
-            }
         }
 
+        if (isset($result['datas'][0])) {
+            $result = $result['datas'][0];
+        }
+
+        $stationUrl = config('bim.glendale.host');
         $result = Arr::only($result, ['modelAccessAddress', 'lightweightName', 'fileOwnership', 'floorJsonURL', 'fileType', 'initiatingUser', 'modelType', 'name']);
         if (isset($result['modelAccessAddress'])) {
-            $result['modelAccessAddress'] = str_replace('http://159.75.168.101:18086', 'https://gelan.autocde.com', $result['modelAccessAddress']);
+            $result['modelAccessAddress'] = str_replace('http://159.75.168.101:18086', $stationUrl, $result['modelAccessAddress']);
         }
-        
+
         // $result['baseUrl'] = config('bim.glendale.base_url');
-        $result['stationUrl'] = config('bim.glendale.host');
+        $result['stationUrl'] = $stationUrl;
         $result['stationToken'] = config('bim.glendale.token');
+        $result['modelType'] = $file->bimFile->model_type;
         return $result;
     }
 

+ 13 - 0
app/Models/BaseModel.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class BaseModel extends Model
+{
+    use HasFactory;
+
+    protected $guarded = [];
+}

+ 5 - 9
app/Models/BimFile.php

@@ -2,14 +2,10 @@
 
 namespace App\Models;
 
-use Illuminate\Database\Eloquent\Factories\HasFactory;
-use Illuminate\Database\Eloquent\Model;
-
-class BimFile extends Model
+class BimFile extends BaseModel
 {
-    use HasFactory;
-
-    protected $fillable = [
-        'file_id', 'bim_driver', 'bim_data_set_id', 'bim_file_id', 'convert_status', 'error', 'source_status',
-    ];
+    public function file()
+    {
+        return $this->hasOne(File::class, 'id', 'file_id')->withTrashed();
+    }
 }

+ 4 - 5
app/Services/File/Upload/FilesUploadTrait.php

@@ -36,7 +36,7 @@ trait FilesUploadTrait
 
         $filesSize = 0;
         foreach ($request->file("files") as $file) {
-            throw_validation_if(! $file->isValid(), "File upload failed.");
+            throw_validation_if(!$file->isValid(), "File upload failed.");
 
             $filesSize += $file->getSize();
         }
@@ -71,11 +71,10 @@ trait FilesUploadTrait
         $modelType = $request->input('model_type', '');
 
         if ($this->isBIM($extension) || $modelType == 'osgb' && $request->object_type == FileObjectType::CONTAINER->value) {
-            $bimFileBO = new BimFileBO($extension, $file->getClientOriginalName());
-            $bimFileBO->modelType = $modelType;
+            $bimFileBO = new BimFileBO($extension, $file->getClientOriginalName(), $modelType);
             // $bimFileBO->modelDownloadUrl = $modelDownloadUrl;
             $bimFileBO->setPointCloudConfigJson($request->input('pointCloudConfigJson', []));
-            
+
             $data['bim'] = BIMFactory::make()->uploadFile($file, $bimFileBO);
 
             $isBimFile = true;
@@ -103,7 +102,7 @@ trait FilesUploadTrait
         $uploadedFiles = [];
         foreach ($items as $item) {
             $fileInfo = $item['file'];
-            if ($fileInfo['object_id'] && $fileInfo['source'] == 1||$fileInfo['uuid'] && $fileInfo['source']== 1) {
+            if ($fileInfo['object_id'] && $fileInfo['source'] == 1 || $fileInfo['uuid'] && $fileInfo['source'] == 1) {
                 $version = File::query()
                     ->where('object_type', $fileInfo['object_type'])
                     ->where('object_id', $fileInfo['object_id'])

+ 1 - 1
config/bim.php

@@ -5,7 +5,7 @@ return [
 
     'gis_extensions' => ['las', 'ply', 'pnts', 'czml', 'kml', 'wms', 'geojson', 'shp', 'bgltf', 'glb', 'glbf', 'b3dm', 'osgb'],
 
-    'extensions' => ['rvt', 'ifc', 'fbx', '3dxml', 'gim', 'igms', 'stp', 'gltf', '3dm', 'skp', 'glb', 'dgn', 'nwd', 'nwc', 'dwg', 'rfa', 'stl', 'iges'],
+    'extensions' => ['rvt', 'ifc', 'fbx', '3dxml', 'gim', 'igms', 'stp', 'gltf', '3dm', 'skp', 'glb', 'dgn', 'nwd', 'nwc', 'dwg', 'rfa', 'stl', 'iges', 'glzip'],
 
     'black_hole' => [
         'host' => env("BLACK_HOLE_HOST", "http://175.178.242.215:9012/"),

+ 36 - 0
database/migrations/2024_09_27_133610_alert_bim_files_and_containers.php

@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::table('bim_files', function (Blueprint $table) {
+            $table->string("model_type")->after("bim_driver")->comment('cad gis bim');
+            $table->json("extra")->after("source_status")->comment('其他模型信息');
+        });
+        Schema::table('containers', function (Blueprint $table) {
+            $table->string("type")->after("name")->comment('容器类型');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::table('bim_files', function (Blueprint $table) {
+            $table->dropColumn("model_type");
+            $table->dropColumn("extra");
+        });
+        Schema::table('containers', function (Blueprint $table) {
+            $table->dropColumn("type");
+        });
+    }
+};

+ 31 - 0
database/seeders/BimModelTypeSeeder.php

@@ -0,0 +1,31 @@
+<?php
+
+namespace Database\Seeders;
+
+use App\BO\BimFileBO;
+use App\Models\BimFile;
+use Illuminate\Database\Console\Seeds\WithoutModelEvents;
+use Illuminate\Database\Seeder;
+
+class BimModelTypeSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     */
+    public function run(): void
+    {
+        BimFile::query()->where('model_type', '')->chunkById(50, function ($bimFiles) {
+            foreach ($bimFiles as $bimFile) {
+                $file = $bimFile->file;
+                if ($file) {
+                    $bimFileBO = new BimFileBO($file->extension, $file->title);
+                    $bimFile->model_type = $bimFileBO->modelType;
+                    $bimFile->timestamps = false;
+                    $bimFile->save();
+
+                    echo $bimFile->id . ' model_type is ' . $bimFileBO->modelType . PHP_EOL;
+                }
+            }
+        });
+    }
+}