ForeignHaiRoboticsService.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. namespace App\Services;
  3. use App\Exceptions\ErrorException;
  4. use App\Exceptions\PanicException;
  5. use App\MaterialBox;
  6. use App\StationTaskMaterialBox;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Http\Response;
  9. use Illuminate\Support\Facades\Http;
  10. use Ramsey\Collection\Collection;
  11. class ForeignHaiRoboticsService
  12. {
  13. /**
  14. * @param string $modeName '输送线入立架'|'立架出至输送线'|'移动立架内位置'|'缓存架入立架'|'立架出至缓存架'
  15. * @param string $fromLocation
  16. * @param string $toLocation
  17. * @param Collection $taskMaterialBoxes
  18. * @param string $groupId
  19. * @param int $priority
  20. * @param int $isSequenced
  21. */
  22. private function makeJson_move(
  23. Collection $taskMaterialBoxes,
  24. string $modeName,
  25. string $fromLocation='',
  26. string $toLocation='',
  27. $groupId=''
  28. , $priority=10
  29. , $isSequenced=1
  30. ){
  31. $timestampSuffix = microtime(true);
  32. $taskMode=(function()use($modeName){
  33. switch ($modeName){
  34. case '输送线入立架': return 1;
  35. case '立架出至输送线': return 2;
  36. case '移动立架内位置': return 3;
  37. case '缓存架入立架':
  38. case '立架出至缓存架': return 6;
  39. default: throw new \Exception('发至海柔的移料箱请求,模式不存在');
  40. }
  41. })();
  42. $bins=$taskMaterialBoxes->map(function (StationTaskMaterialBox $taskMaterialBox)use($timestampSuffix){
  43. return [
  44. "taskCode" =>"{$taskMaterialBox['id']}_{$taskMaterialBox['material_box_id']}_{$timestampSuffix}",
  45. "binCode" => $taskMaterialBox['materialBox']['code'],
  46. "fromLocCode" => $fromLocation??'',
  47. "toLocCode" => $toLocation??'',
  48. ];
  49. });
  50. $groupId .= $timestampSuffix;
  51. return [
  52. "taskMode" =>$taskMode,
  53. "bins"=>$bins,
  54. "groupCode"=>$groupId,
  55. "priority"=>$priority,
  56. "sequenceFlag"=>$isSequenced,
  57. ];
  58. }
  59. public function fetchGroupToProcessor($toLocation, Collection $taskMaterialBoxes, $groupIdPrefix=''): bool
  60. {
  61. $dataToPost=$this->makeJson_move(
  62. $taskMaterialBoxes,
  63. '立架出至输送线',
  64. '',
  65. $toLocation,
  66. $groupIdPrefix
  67. );
  68. $response = Http::post(config('api.haiq.storage.moveBin'),$dataToPost);
  69. $errMsg=(function()use($response){
  70. if($response->ok())return '';
  71. $errMsg = '错误: ';
  72. if (!$response){
  73. return $errMsg.'没有返回内容,检查连接或目标服务器';
  74. }
  75. switch (((string)$response["code"])[0]){
  76. case 5: $errMsg.='目标服务器代码错误,请联系对方';break;
  77. case 4: $errMsg.='权限不足以请求资源,请检查对方服务器规范';break;
  78. default: $errMsg.='出现未知请求错误';break;
  79. }
  80. $responseDetails=' code:'.$response["code"]
  81. .' header:'.$response->body()
  82. .' response:'.json_encode($response->headers());
  83. return $errMsg.$responseDetails;
  84. })();
  85. LogService::log(__METHOD__,__FUNCTION__,
  86. $errMsg??''
  87. .'请求:'.json_encode($dataToPost)
  88. .'调用堆栈:'.json_encode(array_slice(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS),0,3))
  89. );
  90. return $isSuccess=!$errMsg;
  91. }
  92. public function moveBin(){
  93. }
  94. public function markBinProcessed(){
  95. }
  96. public function taskUpdate(
  97. $groupCode,
  98. $taskCode,
  99. $updateEventType, //0:task_begin(取货)1:task_end(放货)
  100. $status, //0:任务成功1:任务失败
  101. $binCode,
  102. $robotId,
  103. $description
  104. ):bool{
  105. if($status==1){
  106. return $this->excepted();
  107. }
  108. switch ($updateEventType){
  109. case 0:
  110. case 1:
  111. }
  112. $this->markHasGet();
  113. }
  114. public function markHasPut(
  115. $groupCode,
  116. $taskCode,
  117. $updateEventType, //0:task_begin(取货)1:task_end(放货)
  118. $status, //0:任务成功1:任务失败
  119. $binCode,
  120. $robotId,
  121. $description
  122. ):bool{
  123. }
  124. public function markHasGet(
  125. $groupCode,
  126. $taskCode,
  127. $updateEventType, //0:task_begin(取货)1:task_end(放货)
  128. $status, //0:任务成功1:任务失败
  129. $binCode,
  130. $robotId,
  131. $description
  132. ):bool{
  133. }
  134. public function excepted():bool{
  135. }
  136. }