ForeignHaiRoboticsService.php 3.6 KB

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