|
|
@@ -10,14 +10,28 @@ use App\MaterialBox;
|
|
|
use App\StationTaskMaterialBox;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Http\Response;
|
|
|
+use Illuminate\Support\Collection;
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
-use Ramsey\Collection\Collection;
|
|
|
use App\Traits\ServiceAppAop;
|
|
|
|
|
|
|
|
|
class ForeignHaiRoboticsService
|
|
|
{
|
|
|
use ServiceAppAop;
|
|
|
+
|
|
|
+ /** @var $stationTaskMaterialBoxService StationTaskMaterialBoxService */
|
|
|
+ private $stationTaskMaterialBoxService;
|
|
|
+ /** @var $materialBoxService MaterialBoxService */
|
|
|
+ private $materialBoxService;
|
|
|
+ /** @var $stationService StationService */
|
|
|
+ private $stationService;
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ $this->stationTaskMaterialBoxService=null;
|
|
|
+ $this->materialBoxService=null;
|
|
|
+ $this->stationService=null;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param string $modeName '输送线入立架'|'立架出至输送线'|'移动立架内位置'|'缓存架入立架'|'立架出至缓存架'
|
|
|
* @param string $fromLocation
|
|
|
@@ -26,6 +40,7 @@ class ForeignHaiRoboticsService
|
|
|
* @param string $groupId
|
|
|
* @param int $priority
|
|
|
* @param int $isSequenced
|
|
|
+ * @return array
|
|
|
*/
|
|
|
private function makeJson_move(
|
|
|
Collection $taskMaterialBoxes,
|
|
|
@@ -35,7 +50,8 @@ class ForeignHaiRoboticsService
|
|
|
$groupId=''
|
|
|
, $priority=10
|
|
|
, $isSequenced=1
|
|
|
- ){
|
|
|
+ ): array
|
|
|
+ {
|
|
|
$timestampSuffix = microtime(true);
|
|
|
$taskMode=(function()use($modeName){
|
|
|
switch ($modeName){
|
|
|
@@ -47,113 +63,197 @@ class ForeignHaiRoboticsService
|
|
|
default: throw new \Exception('发至海柔的移料箱请求,模式不存在');
|
|
|
}
|
|
|
})();
|
|
|
- $bins=$taskMaterialBoxes->map(function (StationTaskMaterialBox $taskMaterialBox)use($timestampSuffix){
|
|
|
+ $bins=$taskMaterialBoxes->map(function (StationTaskMaterialBox $taskMaterialBox)use($timestampSuffix,$fromLocation,$toLocation){
|
|
|
return [
|
|
|
- "taskCode" =>"{$taskMaterialBox['id']}_{$taskMaterialBox['material_box_id']}_{$timestampSuffix}",
|
|
|
+ "taskCode" =>$taskMaterialBox['id'],
|
|
|
"binCode" => $taskMaterialBox['materialBox']['code'],
|
|
|
"fromLocCode" => $fromLocation??'',
|
|
|
"toLocCode" => $toLocation??'',
|
|
|
];
|
|
|
});
|
|
|
- $groupId .= $timestampSuffix;
|
|
|
return [
|
|
|
"taskMode" =>$taskMode,
|
|
|
"bins"=>$bins,
|
|
|
- "groupCode"=>$groupId,
|
|
|
+ "groupCode"=>$groupId.$timestampSuffix,
|
|
|
"priority"=>$priority,
|
|
|
"sequenceFlag"=>$isSequenced,
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- public function fetchGroupToProcessor($toLocation, Collection $taskMaterialBoxes, $groupIdPrefix=''): bool
|
|
|
+ public function fetchGroup($toLocation, Collection $taskMaterialBoxes, $groupIdPrefix=''): bool
|
|
|
{
|
|
|
$dataToPost=$this->makeJson_move(
|
|
|
$taskMaterialBoxes,
|
|
|
'立架出至输送线',
|
|
|
'',
|
|
|
- $toLocation,
|
|
|
+ $toLocation??'',
|
|
|
$groupIdPrefix
|
|
|
);
|
|
|
- $response = Http::post(config('api.haiq.storage.moveBin'),$dataToPost);
|
|
|
- $errMsg=(function()use($response){
|
|
|
- if($response->ok())return '';
|
|
|
- $errMsg = '错误: ';
|
|
|
- if (!$response){
|
|
|
- return $errMsg.'没有返回内容,检查连接或目标服务器';
|
|
|
- }
|
|
|
- switch (((string)$response["code"])[0]){
|
|
|
- case 5: $errMsg.='目标服务器代码错误,请联系对方';break;
|
|
|
- case 4: $errMsg.='权限不足以请求资源,请检查对方服务器规范';break;
|
|
|
- default: $errMsg.='出现未知请求错误';break;
|
|
|
- }
|
|
|
- $responseDetails=' code:'.$response["code"]
|
|
|
- .' header:'.$response->body()
|
|
|
- .' response:'.json_encode($response->headers());
|
|
|
- return $errMsg.$responseDetails;
|
|
|
- })();
|
|
|
-
|
|
|
- LogService::log(__METHOD__,__FUNCTION__,
|
|
|
- $errMsg??''
|
|
|
- .'请求:'.json_encode($dataToPost)
|
|
|
- .'调用堆栈:'.json_encode(array_slice(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS),0,3))
|
|
|
- );
|
|
|
- return $isSuccess=!$errMsg;
|
|
|
+ return $this->controlHaiRobot($dataToPost);
|
|
|
}
|
|
|
|
|
|
public function moveBin(){
|
|
|
|
|
|
}
|
|
|
|
|
|
- public function markBinProcessed(){
|
|
|
+ public function markBinProcessed(
|
|
|
+ $workStation,
|
|
|
+ $binCode,
|
|
|
+ $success,
|
|
|
+ $created_at,
|
|
|
+ $exception,
|
|
|
+ $is_in_plan
|
|
|
+ ): bool
|
|
|
+ {
|
|
|
+ try{
|
|
|
+ if($failed
|
|
|
+ =!$success)
|
|
|
+ throw new ErrorException('海柔任务失败:'.$exception);
|
|
|
+ if($NotInPlan
|
|
|
+ =!$is_in_plan)
|
|
|
+ throw new ErrorException('海柔认为是计划外的料箱:'.$exception);
|
|
|
|
|
|
+ $materialBox=
|
|
|
+ $this->materialBoxService->get(['code'=>$binCode]);
|
|
|
+ if($stationTaskMaterialBox
|
|
|
+ =(function()use($materialBox){
|
|
|
+ return $stationTaskMaterialBox=
|
|
|
+ $this->stationTaskMaterialBoxService
|
|
|
+ ->get([
|
|
|
+ 'material_box_id'=>$materialBox['id'],
|
|
|
+ 'status'=>'处理中',
|
|
|
+ ])->first();
|
|
|
+ })()){
|
|
|
+ throw new ErrorException('该料箱没有安排在处理队列中');
|
|
|
+ }
|
|
|
+ $this->putBinToStore($stationTaskMaterialBox)
|
|
|
+ ?true
|
|
|
+ :(function(){throw new ErrorException('呼叫机器人回收U型线料箱失败');})();
|
|
|
+ $this->stationTaskMaterialBoxService
|
|
|
+ ->markProcessed($stationTaskMaterialBox);
|
|
|
+ return true;
|
|
|
+ }catch (\Exception $e){
|
|
|
+ $this->stationTaskMaterialBoxService
|
|
|
+ ->excepted($stationTaskMaterialBox??$materialBox??null);
|
|
|
+ return $e->getMessage();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function putBinToStore(StationTaskMaterialBox $stationTaskMaterialBox): bool
|
|
|
+ {
|
|
|
+ $this->instant($this->stationService,'StationService');
|
|
|
+ $dataToPost=$this->makeJson_move(
|
|
|
+ collect($stationTaskMaterialBox),
|
|
|
+ '缓存架入立架',
|
|
|
+ $this->stationService->getULineExit($stationTaskMaterialBox['station'])['name']??'',
|
|
|
+ '',
|
|
|
+ $stationTaskMaterialBox['stationTaskBatch']['id']
|
|
|
+ );
|
|
|
+ return $this->controlHaiRobot($dataToPost);
|
|
|
}
|
|
|
+
|
|
|
public function taskUpdate(
|
|
|
- $groupCode,
|
|
|
+// $groupCode,
|
|
|
$taskCode,
|
|
|
$updateEventType, //0:task_begin(取货)1:task_end(放货)
|
|
|
$status, //0:任务成功1:任务失败
|
|
|
- $binCode,
|
|
|
- $robotId,
|
|
|
- $description
|
|
|
+ $binCode
|
|
|
):bool{
|
|
|
- if($status==1){
|
|
|
- return $this->excepted();
|
|
|
- }
|
|
|
- switch ($updateEventType){
|
|
|
- case 0:
|
|
|
- case 1:
|
|
|
+ try{
|
|
|
+ if(($failed
|
|
|
+ =$status)==1){
|
|
|
+ throw new ErrorException('海柔任务失败');
|
|
|
+ }
|
|
|
+ if($boxNotMatch=
|
|
|
+ !$stationTaskMaterialBox
|
|
|
+ =(function()use($taskCode,$binCode){
|
|
|
+ $stationTaskMaterialBox=StationTaskMaterialBox::query()->find($id=$taskCode);
|
|
|
+ if($stationTaskMaterialBox['code']==$binCode)return $stationTaskMaterialBox;
|
|
|
+ return null;
|
|
|
+ })()){
|
|
|
+ throw new ErrorException('发回的料箱和任务号(ID)不匹配');
|
|
|
+ }
|
|
|
+ ($标记已放置在库外=
|
|
|
+ function()use($updateEventType,$stationTaskMaterialBox){
|
|
|
+ if(($isPut
|
|
|
+ =$updateEventType)==1){
|
|
|
+ $this->stationTaskMaterialBoxService->markHasPut($stationTaskMaterialBox);
|
|
|
+ }
|
|
|
+ })();
|
|
|
+ ($标记已入立架=
|
|
|
+ function()use($updateEventType,$stationTaskMaterialBox){
|
|
|
+ if(($isGet
|
|
|
+ =$updateEventType)==0){
|
|
|
+ $this->stationTaskMaterialBoxService->markTaken($stationTaskMaterialBox);
|
|
|
+ }
|
|
|
+ })();
|
|
|
+ }catch (\Exception $e){
|
|
|
+ $this->excepted($taskCode, $binCode, $e->getMessage());
|
|
|
+ return false;
|
|
|
}
|
|
|
- $this->markHasGet();
|
|
|
-
|
|
|
+ return true;
|
|
|
}
|
|
|
- public function markHasPut(
|
|
|
- $groupCode,
|
|
|
- $taskCode,
|
|
|
- $updateEventType, //0:task_begin(取货)1:task_end(放货)
|
|
|
- $status, //0:任务成功1:任务失败
|
|
|
- $binCode,
|
|
|
- $robotId,
|
|
|
- $description
|
|
|
- ):bool{
|
|
|
-
|
|
|
|
|
|
- }
|
|
|
- public function markHasGet(
|
|
|
- $groupCode,
|
|
|
- $taskCode,
|
|
|
- $updateEventType, //0:task_begin(取货)1:task_end(放货)
|
|
|
- $status, //0:任务成功1:任务失败
|
|
|
- $binCode,
|
|
|
- $robotId,
|
|
|
- $description
|
|
|
- ):bool{
|
|
|
+// public function markHasPut($taskCode,$binCode):bool{
|
|
|
+// try{
|
|
|
+// //标记料箱进入位置
|
|
|
+//// $taskMaterialBoxesService->markDone();//
|
|
|
+// }catch (\Exception $e){
|
|
|
+// switch ($e->getCode()){
|
|
|
+// case 'taskBinNotMatch';
|
|
|
+// case 'taskGetFailed';
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
|
|
|
|
|
|
+ public function excepted($taskCode='',$binCode='', $msg=''):bool{
|
|
|
+ try{
|
|
|
+ throw new ErrorException(
|
|
|
+ "taskCode任务号:$taskCode , binCode箱号:$binCode 海柔运行报错: $msg"
|
|
|
+ );
|
|
|
+ }catch (\Exception $e){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param array $dataToPost
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function controlHaiRobot(array $dataToPost): bool
|
|
|
+ {
|
|
|
+ $response = Http::post(config('api.haiq.storage.moveBin'), $dataToPost);
|
|
|
+ $errMsg = (function () use ($response) {
|
|
|
+ if ($response->ok()) return '';
|
|
|
+ $errMsg = '错误: ';
|
|
|
+ if (!$response) {
|
|
|
+ return $errMsg . '没有返回内容,检查连接或目标服务器';
|
|
|
+ }
|
|
|
+ switch (((string)$response["code"])[0]) {
|
|
|
+ case 5:
|
|
|
+ $errMsg .= '目标服务器代码错误,请联系对方';
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ $errMsg .= '权限不足以请求资源,请检查对方服务器规范';
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ $errMsg .= '出现未知请求错误';
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ $responseDetails = ' code:' . $response["code"]
|
|
|
+ . ' header:' . $response->body()
|
|
|
+ . ' response:' . json_encode($response->headers());
|
|
|
+ return $errMsg . $responseDetails;
|
|
|
+ })();
|
|
|
|
|
|
- public function excepted():bool{
|
|
|
-
|
|
|
+ LogService::log(__METHOD__, __FUNCTION__,
|
|
|
+ $errMsg ?? ''
|
|
|
+ . '请求:' . json_encode($dataToPost)
|
|
|
+ . '调用堆栈:' . json_encode(array_slice(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), 0, 3))
|
|
|
+ );
|
|
|
+ return $isSuccess = !$errMsg;
|
|
|
}
|
|
|
|
|
|
}
|