Browse Source

模型对比

waymen 4 months ago
parent
commit
e3d1aadb3f

+ 5 - 1
app/Http/Controllers/API/BimController.php

@@ -28,8 +28,12 @@ class BimController extends Controller
         $newComponents = $glendale->getFloorComponents($inputArr['new_bim_file_id'], $inputArr['new_glid']);
 
         $data['create'] = array_values(array_diff($newComponents, $components));
-        $data['update'] = array_values(array_intersect($components, $newComponents));
+        $sameComponentIds = array_values(array_intersect($components, $newComponents));
         $data['delete'] = array_values(array_diff($components, $newComponents));
+
+        $attributes = $glendale->getAttributes($inputArr['bim_file_id'], $sameComponentIds);
+        $newAttributes = $glendale->getAttributes($inputArr['new_bim_file_id'], $sameComponentIds);
+        $data['update'] = $glendale->getUpdatedComponentIds($sameComponentIds, $attributes, $newAttributes);
         $data['componets'] = $components;
         $data['new_componets'] = $newComponents;
 

+ 6 - 7
app/Http/Controllers/API/FileController.php

@@ -300,7 +300,7 @@ class FileController extends Controller
     public function models(Request $request)
     {
         $inputArr = $this->validate($request, [
-            'model_type' => 'in:bim,gis',
+            'model_type' => 'array',
             'container_id' => 'int',
             'library_id' => 'int',
             'asset_id' => 'int',
@@ -312,13 +312,12 @@ class FileController extends Controller
         $assetId = (int) ($inputArr['asset_id'] ?? 0);
         $projectId = (int) ($inputArr['project_id'] ?? 0);
         $folderId = (int) ($inputArr['folder_id'] ?? 0);
-        $modelType = $inputArr['model_type'] ?? 'bim';
         $pageSize = (int) $request->get('page_size', 10);
-
-        match ($modelType) {
-            'gis' => $modelTypeArr = [BimFileModelType::GIS->value],
-            default => $modelTypeArr = [BimFileModelType::BIM->value, BimFileModelType::CAD->value],
-        };
+        $modelTypeArr = $inputArr['model_type'] ?? [];
+        
+        if (empty($modelTypeArr)) {
+            $modelTypeArr = [BimFileModelType::BIM->value, BimFileModelType::CAD->value];
+        }
 
         $files = File::query()
             ->where('is_bim', 1)

+ 52 - 1
app/Libraries/BIM/Glendale/Glendale.php

@@ -9,7 +9,6 @@ use App\Models\BimFile;
 use App\Models\Enums\BimFileConvertStatus;
 use App\Models\Enums\BimFileModelType;
 use Illuminate\Http\UploadedFile;
-use Illuminate\Support\Facades\Log;
 
 class Glendale extends BIMAbstract
 {
@@ -370,6 +369,58 @@ class Glendale extends BIMAbstract
         return $components;
     }
 
+    public function getAttributes(string $lightweightName, array $attributeIds)
+    {
+        try {
+            $res = Client::getInstance()->get('api/app/model/property-data-by-externalid', [
+                'LightweightName' => $lightweightName,
+                'ExternalId' => implode(',', $attributeIds),
+            ]);
+        } catch (\Throwable $th) {
+            return [];
+        }
+
+        return $res['datas'] ?? [];
+    }
+
+
+    /**
+     * 获取有修改过的构件ID数组
+     * @param array $conponentIds
+     * @param array $attributes
+     * @param array $newAttributes
+     * @return array
+     */
+    public function getUpdatedComponentIds(array $conponentIds, array $attributes, array $newAttributes): array
+    {
+        $updatedIds = [];
+        $attributes = collect($attributes);
+        $newAttributes = collect($newAttributes);
+        $attributesGroup = $attributes->groupBy('externalId');
+        $newAttributesGroup = $newAttributes->groupBy('externalId');
+
+        foreach ($conponentIds as $conponentId) {
+            $conponents = $attributesGroup[$conponentId];
+            $newConponents = $newAttributesGroup[$conponentId];
+            if (!$conponents || !$newConponents) {
+                continue;
+            }
+
+            if ($conponents->count() != $newConponents->count()) {
+                $updatedIds[] = $conponentId;
+                continue;
+            }
+            
+            $a = array_values($conponents->sortBy('id')->toArray());
+            $b = array_values($newConponents->sortBy('id')->toArray());
+
+            if (!array_are_equal($a, $b, ['id', 'externalId', 'propertyTypeName', 'propertySetName', 'propertySetName', 'value', 'groupname'])) {
+                $updatedIds[] = $conponentId;
+            }
+        }
+        return $updatedIds;
+    }
+
     /**
      * 把引擎数据同步过来
      * @param string $lightweightName

+ 27 - 1
app/helpers.php

@@ -128,7 +128,7 @@ if (!function_exists('date_time_str')) {
         if ($timestamp == 0) {
             $timestamp = time();
         }
-        
+
         return date('Y-m-d H:i:s', $timestamp);
     }
 }
@@ -164,4 +164,30 @@ if (!function_exists('make_display_id')) {
     }
 }
 
+if (!function_exists('array_are_equal')) {
+    function array_are_equal(array $array1, array $array2, array $keys = []): bool
+    {
+        if (array_keys($array1) !== array_keys($array2)) {
+            return false;
+        }
 
+        foreach ($array1 as $key => $value) {
+            if (!empty($keys) && !in_array($key, $keys)) {
+                continue;
+            }
+            // 如果当前元素是数组,则递归比较
+            if (is_array($value)) {
+                if (!array_are_equal($value, $array2[$key])) {
+                    return false;
+                }
+            } else {
+                if ($value != $array2[$key]) {
+                    dd($value.'|'.$array2[$key]);
+                    return false;
+                }
+            }
+        }
+
+        return true;
+    }
+}