BlackHole.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Services\File\BIM\BlackHole;
  3. use App\Services\File\BIM\Contacts\BIMContact;
  4. use Illuminate\Http\UploadedFile;
  5. class BlackHole implements BIMContact
  6. {
  7. public function uploadFile(UploadedFile $file, array $params = [])
  8. {
  9. //$this->addLeafNodes(['Node1', 'Node2'], config("bim.black_hole.project_id"));
  10. $projectId = config("bim.black_hole.project_id");
  11. $treeInfo = $this->getTreeById($projectId);
  12. $modelFile = $this->modelFileCreate($projectId, $treeInfo['subNodes'][0]['nodeId'], $file);
  13. dump($modelFile);
  14. //$this->modelFileCreate(config("bim.black_hole.project_id"), $file);
  15. }
  16. public function downloadSourceFile()
  17. {
  18. }
  19. protected function modelFileCreate(string $projectId, string $nodeId, UploadedFile $file)
  20. {
  21. $formData = [
  22. 'ProjId' => $projectId,
  23. 'DataSetId' => $nodeId,
  24. 'FileName' => $file->getClientOriginalName(),
  25. 'FileSize' => $file->getSize(),
  26. 'FileType' => $file->getExtension() ? $file->getExtension() : pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION),
  27. 'Scheme' => 'Bim',
  28. 'BlobCount' => 1,
  29. 'BlobSize' => $file->getSize(),
  30. 'UploadWay' => 0
  31. ];
  32. $result = Client::getInstance()->request("POST", "/blackHole3D/project/modelFile/create", [
  33. 'form_params' => $formData,
  34. 'headers' => [
  35. 'fileUploadScheme' => 'Bim',
  36. 'fileUploadMode' => 'ResumableCreate'
  37. ]
  38. ]);
  39. return $result['data'] ?? [];
  40. }
  41. protected function getTreeById(string $projectId)
  42. {
  43. $result = Client::getInstance()->request("POST", "/blackHole3D/project/modelTree/getTreeById", [
  44. 'json' => [
  45. 'projId' => $projectId
  46. ]
  47. ]);
  48. return $result['data'] ?? [];
  49. }
  50. protected function addLeafNodes(array $nodes, string $parentId = "")
  51. {
  52. $items = [];
  53. foreach ($nodes as $node) {
  54. $items[]['dataSetName'] = $node;
  55. }
  56. $result = Client::getInstance()->request("POST", "/blackHole3D/project/modelTree/addLevelNodes", [
  57. 'json' => [
  58. 'parentId' => $parentId,
  59. 'dataSets' => $items
  60. ]
  61. ]);
  62. dump([
  63. 'parentId' => $parentId,
  64. 'dataSets' => $items
  65. ]);
  66. dump($result);
  67. }
  68. }