123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461 |
- <?php
- namespace App\Libraries\BIM\Glendale;
- use App\BO\BIMFileBO;
- use App\Libraries\BIM\Abstracts\BIMAbstract;
- use App\Libraries\BIM\BIMDriverEnum;
- use App\Models\BimFile;
- use App\Models\Enums\BimFileConvertStatus;
- use App\Models\Enums\BimFileModelType;
- use Illuminate\Http\UploadedFile;
- use Illuminate\Support\Arr;
- class Glendale extends BIMAbstract
- {
- //http://gisbimapi.glendale.top/#/serviceApi/BIM%E6%A8%A1%E5%9E%8B%E6%9C%8D%E5%8A%A1?id=%e6%ba%90%e6%96%87%e4%bb%b6%e7%9b%b8%e5%85%b3
- /**
- * 匹配Glendale的轻量化状态码
- * @param int $sourceStatus
- * @return int
- */
- public static function mapSourceStatus(int $sourceStatus): int
- {
- if ($sourceStatus == 100) {
- $convertStatus = BimFileConvertStatus::DONE->value;
- } elseif ($sourceStatus < 100 && $sourceStatus > 0) {
- $convertStatus = BimFileConvertStatus::CONVERTING->value;
- } else {
- $convertStatus = BimFileConvertStatus::IN_QUEUE->value;
- }
- return $convertStatus;
- }
- private function isPointCloudGISModel(string $ext): bool
- {
- return in_array($ext, ['las', 'laz', 'ply', 'xyz']);
- }
- private function isOSGBGISModel(string $gisType): bool
- {
- return $gisType == 'osgb';
- }
- private function replaceUrlToHttps(array $data = [], array $needReplaceFields = []): array
- {
- $stationUrl = config('bim.glendale.host');
- foreach ($needReplaceFields as $field) {
- if (isset($data[$field])) {
- $data[$field] = str_replace('http://159.75.168.101:18086', $stationUrl, $data[$field]);
- }
- }
- return $data;
- }
- /**
- * 构造query的input传参
- * @param \App\BO\BIMFileBO $bimFileBO
- * @param array $append
- * @return array
- */
- private function buildQueryParams(BimFileBO $bimFileBO, array $append = []): array
- {
- $defaultConfigJson = ExtensionModelConfig::getConfigOption($bimFileBO->extension);
- $configJson = array_merge($defaultConfigJson, $bimFileBO->configJson);
- $input = [
- 'name' => $bimFileBO->name,
- 'initiatingUser' => $bimFileBO->initiatingUser,
- 'uniqueCode' => $bimFileBO->uniqueCode,
- 'priority' => $bimFileBO->priority,
- 'isCAD' => $bimFileBO->isCAD,
- 'callbackInterfaceURL' => route('glendale.callback'),
- 'configJson' => $configJson,
- ];
- if (!empty($append)) {
- $input = array_merge($input, $append);
- }
- return [
- 'input' => json_encode($input)
- ];
- }
- /**
- * 指定url方式上传模型到引擎服务器
- * @param string $fileUrl
- * @param BimFileBO $bimFileBO
- * @return array
- */
- protected function uploadModelByUrl(BimFileBO $bimFileBO): array
- {
- $append = ['modelDownloadUrl' => $bimFileBO->modelDownloadUrl];
- return Client::getInstance()->post('/api/app/model/transcode-file', [
- 'query' => $this->buildQueryParams($bimFileBO, $append)
- ]);
- }
- /**
- * 文件流方式上传模型到引擎服务器
- * @param \Illuminate\Http\UploadedFile $file
- * @param BimFileBO $bimFileBO
- * @return array
- */
- protected function uploadModelByStream(UploadedFile $file, BimFileBO $bimFileBO): array
- {
- return Client::getInstance()->post('/api/app/model/upload-file', [
- 'query' => $this->buildQueryParams($bimFileBO),
- 'multipart' => [
- ['name' => 'file', 'contents' => fopen($file, 'r+'), 'filename' => $bimFileBO->name]
- ],
- ]);
- }
- /**
- * 文件流方式上传点云GIS模型
- * @param \Illuminate\Http\UploadedFile $file
- * @param BimFileBO $bimFileBO
- * @return array|null
- */
- protected function uploadPointCloudModelByStream(UploadedFile $file, BimFileBO $bimFileBO)
- {
- $srs = $bimFileBO->pointCloudConfigJson['srs'] ?? '';
- $longitude = $bimFileBO->pointCloudConfigJson['longitude'] ?? null;
- $latitude = $bimFileBO->pointCloudConfigJson['latitude'] ?? null;
- throw_validation_if(empty($srs) && (empty($longitude) || empty($latitude)), 'srs or longitude & latitude is required');
- return Client::getInstance()->post('/api/app/gismodel/PointCloudUploadFile', [
- 'query' => $this->buildQueryParams($bimFileBO, ['pointCloudConfigJson' => $bimFileBO->pointCloudConfigJson]),
- 'multipart' => [
- ['name' => 'file', 'contents' => fopen($file, 'r+'), 'filename' => $bimFileBO->name]
- ],
- ]);
- }
- /**
- * 指定url方式上传点云GIS模型
- * @param \App\BO\BIMFileBO $bimFileBO
- * @return array|null
- */
- protected function uploadPointCloudModelByUrl(BimFileBO $bimFileBO)
- {
- $srs = $bimFileBO->pointCloudConfigJson['srs'] ?? '';
- $longitude = $bimFileBO->pointCloudConfigJson['longitude'] ?? null;
- $latitude = $bimFileBO->pointCloudConfigJson['latitude'] ?? null;
- throw_validation_if(empty($srs) && (empty($longitude) || empty($latitude)), 'srs or longitude & latitude is required');
- $append = [
- 'modelDownloadUrl' => $bimFileBO->modelDownloadUrl,
- 'pointCloudConfigJson' => $bimFileBO->pointCloudConfigJson
- ];
- return Client::getInstance()->post('/api/app/gismodel/OsgbUploadFileByUrl', [
- 'query' => $this->buildQueryParams($bimFileBO, $append)
- ]);
- }
- /**
- * 文件流方式上传OSGB GIS模型
- * @param \Illuminate\Http\UploadedFile $file
- * @param \App\BO\BIMFileBO $bimFileBO
- * @return array|null
- */
- protected function uploadOSGBModelByStream(UploadedFile $file, BimFileBO $bimFileBO)
- {
- return Client::getInstance()->post('/api/app/gismodel/OsgbUploadFile', [
- 'query' => $this->buildQueryParams($bimFileBO),
- 'multipart' => [
- ['name' => 'file', 'contents' => fopen($file, 'r+'), 'filename' => $bimFileBO->name]
- ],
- ]);
- }
- /**
- * 指定url方式上传OSGB GIS模型
- * @param \App\BO\BIMFileBO $bimFileBO
- * @return array|null
- */
- protected function uploadOSGBModelByUrl(BimFileBO $bimFileBO)
- {
- $append = ['modelDownloadUrl' => $bimFileBO->modelDownloadUrl];
- return Client::getInstance()->post('/api/app/gismodel/OsgbUploadFileByUrl', [
- 'query' => $this->buildQueryParams($bimFileBO, $append)
- ]);
- }
- /**
- * 上传文件
- * @param mixed $file
- * @param \App\BO\BIMFileBO $bimFileBO
- * @return array
- */
- public function uploadFile(?UploadedFile $file, BimFileBO $bimFileBO): array
- {
- try {
- if (!empty($bimFileBO->modelDownloadUrl)) { //url方式
- if ($this->isPointCloudGISModel($bimFileBO->extension)) { //点云
- $result = $this->uploadPointCloudModelByUrl($bimFileBO);
- } elseif ($this->isOSGBGISModel(gisType: $bimFileBO->gisType)) { //OSGB
- $result = $this->uploadOSGBModelByUrl($bimFileBO);
- } else { //普通BIM
- $result = $this->uploadModelByUrl($bimFileBO);
- }
- } else { //文件流方式
- if ($this->isPointCloudGISModel($bimFileBO->extension)) {
- $result = $this->uploadPointCloudModelByStream($file, $bimFileBO);
- } elseif ($this->isOSGBGISModel($bimFileBO->gisType)) {
- $result = $this->uploadOSGBModelByStream($file, bimFileBO: $bimFileBO);
- } else {
- $result = $this->uploadModelByStream($file, $bimFileBO);
- }
- }
- return [
- 'bim_data_set_id' => $result['datas']['lightweightName'],
- 'bim_file_id' => $result['datas']['lightweightName'],
- 'convert_status' => BimFileConvertStatus::IN_QUEUE->value,
- 'bim_driver' => BIMDriverEnum::GLENDALE->value,
- 'model_type' => $bimFileBO->modelType,
- ];
- } catch (\Throwable $th) {
- return ['error' => $th->getMessage()];
- }
- }
- public function downloadSourceFile()
- {
- // TODO: Implement downloadSourceFile() method.
- }
- public function findConvertStatus(string $dataSetId): array
- {
- $result = Client::getInstance()->post('/api/app/model/query-model-info', [
- 'query' => [
- '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;
- };
- $status = match ($result['datas'][0]['status']) {
- 0, 1, 101 => BimFileConvertStatus::IN_QUEUE->value,
- 100 => BimFileConvertStatus::DONE->value,
- default => $getStatus($result['datas'][0]['status'])
- };
- return $this->convertStatusFormat($status, $result['datas'][0]['status']);
- }
- public function viewDataSetModel(array $dataSetIDS)
- {
- $result = Client::getInstance()->post('/api/app/model/query-model-info', [
- 'query' => [
- 'LightweightName' => $dataSetIDS[0]
- ]
- ]);
- return $result['datas'] ?? [];
- }
- /**
- * 获取某个模型信息
- * @param \App\Models\BimFile $bimFile
- * @return array
- */
- public function getModelDetail(BimFile $bimFile): array
- {
- $result = [];
- if (!$bimFile) {
- return $result;
- }
- if ($bimFile->model_type == BimFileModelType::GIS->value) {
- $result = Client::getInstance()->post('/api/app/gismodel/QueryModelInfo', [
- 'query' => [
- 'LightweightName' => $bimFile->bim_data_set_id
- ]
- ]);
- } else {
- $result = Client::getInstance()->post('/api/app/model/query-model-info', [
- 'query' => [
- 'LightweightName' => $bimFile->bim_data_set_id
- ]
- ]);
- }
- if (isset($result['datas'][0])) {
- $result = $result['datas'][0];
- }
- $result = $this->replaceUrlToHttps($result, ['modelAccessAddress', 'floorJsonURL']);
- return $result;
- }
- public function addToConvertQueue(string $dataSetId): array
- {
- return [];
- }
- /**
- * 获取模型多视图信息
- * @param string $lightweightName
- * @return array
- */
- public function getModel3DViews(string $lightweightName): array
- {
- $result = [];
- if (empty($lightweightName)) {
- return $result;
- }
- try {
- $res = Client::getInstance()->get('/api/app/model/model3DViews', [
- 'LightweightName' => $lightweightName
- ]);
- foreach ($res['datas'] as $data) {
- $result[] = $this->replaceUrlToHttps($data, ['accessAddress']);
- }
- } catch (\Throwable $th) {
- }
- return $result;
- }
- /**
- * 获取楼层节点下所有构件ID
- * @param string $lightweightName
- * @param string $glid
- * @return mixed
- */
- public function getFloorComponents(string $lightweightName, string $glid): array
- {
- $components = [];
- try {
- $res = Client::getInstance()->get('/api/app/model/GetModelTreeFeatureIdByPid', [
- 'LightweightName' => $lightweightName,
- 'Pid' => $glid,
- ]);
- $components = explode(',', $res['datas']);
- if (!$components || $res['datas'] == '') {
- $components = [];
- }
- } catch (\Throwable $th) {
- }
- 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) {
- if (!isset($attributesGroup[$conponentId]) || !isset($newAttributesGroup[$conponentId])) {
- continue;
- }
- $conponents = $attributesGroup[$conponentId];
- $newConponents = $newAttributesGroup[$conponentId];
- if (!$conponents || !$newConponents) {
- continue;
- }
- if ($conponents->count() != $newConponents->count()) {
- $updatedIds[] = $conponentId;
- continue;
- }
- $fields = ['id', 'externalId', 'propertyTypeName', 'propertySetName', 'propertySetName', 'value', 'groupname'];
- $arr1 = [];
- $arr2 = [];
- $a = $conponents->sortBy('id');
- $b = $newConponents->sortBy('id');
- foreach ($a as $key => $value) {
- $arr1[] = Arr::only($value, $fields);
- }
- foreach ($b as $key => $value) {
- $arr2[] = Arr::only($value, $fields);
- }
- if (!array_are_equal($arr1, $arr2)) {
- $updatedIds[] = $conponentId;
- }
- }
- return $updatedIds;
- }
- /**
- * 把引擎数据同步过来
- * @param string $lightweightName
- * @return array|null
- */
- public function syncDB(string $lightweightName): array|null
- {
- $mysqlConfig = config('database.connections.mysql');
- $result = Client::getInstance()->post('/api/app/model/syncdbtodatabase', [
- 'query' => [
- 'LightweightName' => $lightweightName,
- 'DatabaseCategory' => 2, //1:SqlServer 2:MySql 3:DM8
- 'Server' => $mysqlConfig['host'],
- 'Database' => $mysqlConfig['database'],
- 'Uid' => $mysqlConfig['username'],
- 'PassWord' => $mysqlConfig['password'],
- 'Port' => $mysqlConfig['port'],
- 'DatabaseEngine' => 1, //数据库引擎,只针对Mysql, 0为MyISAM,1为InnoDB(阿里云服务器中引擎需要配置为InnoDB),默认值为0
- 'CallBackUrl' => route('glendale.sync-callback'),
- ]
- ]);
- return $result;
- }
- }
|