ForeignHaiRoboticsService.php 4.7 KB

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