ajun 5 лет назад
Родитель
Сommit
4f79e94419

+ 12 - 6
app/Http/Controllers/CacheShelfController.php

@@ -40,15 +40,21 @@ class CacheShelfController extends Controller
     }
 
     /**
-     * 往缓存架上放料箱
+     * 亮灯
      * @param Request $request
      */
-    public function pushTaskApi(Request $request)
+    public function lightOnApi(Request $request)
+    {
+
+
+    }
+
+    /**
+     * 推送任务至海柔机器人
+     * @param Request $request
+     */
+    public function pushHaiQTask(Request $request)
     {
-        /** @var Station  $station */
-        $station = Station::query()->where('id', $request['id'])->first();
-        /** @var MaterialBox $materialBox */
-        $materialBox = MaterialBox::query()->firstOrCreate(['code' => $request['code'],['code'=>$request['code']]]);
 
 
     }

+ 13 - 29
app/Services/CacheShelfService.php

@@ -2,12 +2,10 @@
 
 namespace App\Services;
 
-use App\Events\BroadcastToStation;
 use App\Exceptions\ErrorException;
 use App\MaterialBox;
 use App\Station;
 use App\StationCacheShelfGrid;
-use App\StationTask;
 use App\StationTaskMaterialBox;
 use App\Traits\ServiceAppAop;
 use Illuminate\Support\Facades\Http;
@@ -17,29 +15,6 @@ class CacheShelfService
     use ServiceAppAop;
     protected $modelClass=Station::class;
 
-    /**
-     * 缓存架上架料箱
-     * @param Station $station
-     * @param MaterialBox $materialBox
-     * @param $pointX
-     * @param $pointY
-     * @return string
-     * @throws ErrorException
-     */
-    public function pushTask(Station $station,MaterialBox $materialBox,$pointX, $pointY)
-    {
-        $grid = (3-$pointX)*3 + (3-$pointX);
-        $params = ['station'=>$station['id'],'grid_id'=>$grid];
-        $stationCacheShelfGrid = StationCacheShelfGrid::query()->firstOrCreate($params,$params);
-        $stationCacheShelfGrid->update(['material_box_id' => $materialBox['id'],'status'=> 0]);
-        /** 推送任务至海柔机器人 */
-        if($this->putBinToStore($station,$materialBox)){
-            $stationCacheShelfGrid->update(['material_box_id' => $materialBox['id'],'status'=> 1]);
-            /** 亮灯 */
-            return $this->lightOn($station,$pointX, $pointY);
-        }
-        else return false;
-    }
 
     /**
      * 获取缓存架任务
@@ -58,7 +33,7 @@ class CacheShelfService
      * @param $pointY
      * @return string
      */
-    public function lightOn(Station $station,$pointX,$pointY): string
+    public function lightOnApi(Station $station,$pointX,$pointY): string
     {
         $locCode = 'HAI'.$station['code'].'-0'.$pointX.'-0'.$pointY;
         $params = [
@@ -88,15 +63,24 @@ class CacheShelfService
     }
 
     /**
-     * 推送到海柔的任务
+     * 推送到海柔机器人的任务
      * @param Station $station
      * @param MaterialBox $materialBox
+     * @param StationCacheShelfGrid $grid
      * @return bool
      * @throws ErrorException
      */
-    public function putBinToStore(Station $station,MaterialBox $materialBox): bool
+    public function putBinToStore(Station $station,MaterialBox $materialBox,StationCacheShelfGrid $grid): bool
     {
-        $stationTaskMaterialBox = new StationTaskMaterialBox();
+        // 生成任务
+        /** @var StationTaskMaterialBox $stationTaskMaterialBox */
+        $stationTaskMaterialBox = StationTaskMaterialBox::query()->create([
+            'station_id' => $station['id'],
+            'material_box_id' => $materialBox['id'],
+            'status' => '待处理'
+        ]);
+
+        $station->setRelation('grids',$grid);
         $stationTaskMaterialBox->setRelation('station',$station);
         $stationTaskMaterialBox->setRelation('materialBox',$materialBox);
 

+ 6 - 3
app/Services/ForeignHaiRoboticsService.php

@@ -6,6 +6,7 @@ namespace App\Services;
 
 use App\Exceptions\ErrorException;
 use App\MaterialBox;
+use App\StationCacheShelfGrid;
 use App\StationTaskMaterialBox;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Http;
@@ -244,13 +245,15 @@ class ForeignHaiRoboticsService
         $this->instant($this->stationService,'StationService');
 
         // 立架
-        $formLocation =  $this->stationService->getULineExit($stationTaskMaterialBox['station']);
+//        $formLocation =  $this->stationService->getULineExit($stationTaskMaterialBox['station']);
+
+        $formLocation = StationCacheShelfGrid::getLocation($stationTaskMaterialBox['station'],$stationTaskMaterialBox['station']['grids']->first());
 
         /** 创建料箱 从缓存架 到 立架任务 */
         $dataToPost=$this->makeJson_move(
             collect([$stationTaskMaterialBox]),
             '缓存架入立架',
-            'BIN-IN1',//TODO:这里应该是动态取得,参考出立架getULineExit()方法,不然不能从站获得对应的出口,而且要改Station的child为children
+            $formLocation,//TODO:这里应该是动态取得,参考出立架getULineExit()方法,不然不能从站获得对应的出口,而且要改Station的child为children
             '',
             $stationTaskMaterialBox['stationTaskBatch']['id']
         );
@@ -264,7 +267,7 @@ class ForeignHaiRoboticsService
             $this->stationTaskMaterialBoxService->set($stationTaskMaterialBox,[
                 'id' => $stationTaskMaterialBox['id'],
                 'status' => $stationTaskMaterialBox['status']='处理中',
-                'station_id' => 4,
+                'station_id' => $stationTaskMaterialBox['station']['id']?? '',
             ]);
         }
         return $controlSuccess;

+ 9 - 2
app/StationCacheShelfGrid.php

@@ -15,8 +15,6 @@ class StationCacheShelfGrid extends Model
     public static $status = [
         '0' => '无',
         '1' => '待处理',
-        '2' => '完成',
-        '3' => '异常'
     ];
 
     public function station(): BelongsTo
@@ -29,4 +27,13 @@ class StationCacheShelfGrid extends Model
         return $this->belongsTo(MaterialBox::class);
     }
 
+    public static function getLocation(Station $station,StationCacheShelfGrid $grid)
+    {
+
+        $code = $station['code'];
+        $grid_id = $grid['grid_id'];
+        $row = 2- ($grid_id / 3) +1;
+        $col = 2- ($grid_id % 3) +1;
+        return 'HAI'.$code.'-0'.$row.'-0'.$col;
+    }
 }