|
|
@@ -2,13 +2,16 @@
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
+use App\Events\BroadcastToStation;
|
|
|
use App\Exceptions\ErrorException;
|
|
|
use App\MaterialBox;
|
|
|
use App\Station;
|
|
|
-use App\StationCacheShelfGrid;
|
|
|
use App\StationTaskMaterialBox;
|
|
|
+use App\StationType;
|
|
|
use App\Traits\ServiceAppAop;
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
+use Illuminate\Database\Eloquent\Builder;
|
|
|
+use Illuminate\Database\Eloquent\Collection;
|
|
|
|
|
|
class CacheShelfService
|
|
|
{
|
|
|
@@ -21,28 +24,40 @@ class CacheShelfService
|
|
|
private $stationCacheShelfGridService;
|
|
|
/** @var ForeignHaiRoboticsService $foreignHaiRoboticsService */
|
|
|
private $foreignHaiRoboticsService;
|
|
|
+ /** @var StationTaskService $stationTaskService */
|
|
|
+ private $stationTaskService;
|
|
|
|
|
|
/**
|
|
|
- * 获取现有的缓存架任务
|
|
|
- * @param Station $station
|
|
|
+ * 获取缓存架上子货架当前任务
|
|
|
+ * @param $id
|
|
|
+ * @return Builder[]|Collection
|
|
|
*/
|
|
|
- public function getTasks(Station $station)
|
|
|
+ public function getChildStation($id)
|
|
|
{
|
|
|
- $grids = StationCacheShelfGrid::query()->with('materialBox')->where('station_id', $station['id'])->where('status', 1)->orderBy('grid_id')->get();
|
|
|
- $station->setRelation('grids', $grids);
|
|
|
+ return Station::query()->where('parent_id',$id)->with('parent','currentStationTask.stationTaskMaterialBoxes.materialBox')->get();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 拍灯触任务
|
|
|
+ * @param $locCode
|
|
|
+ * @param $PTLAction
|
|
|
+ * @return array|bool[]
|
|
|
+ */
|
|
|
public function lightOffTask($locCode, $PTLAction): array
|
|
|
{
|
|
|
$this->instant($this->stationCacheShelfGridService, 'StationCacheShelfGridService');
|
|
|
- list($stationCode, $gridId, $row, $col) = StationCacheShelfGrid::getGridByCode($locCode);
|
|
|
- $station = Station::query()->where('code', $stationCode)->first();
|
|
|
- $grid = StationCacheShelfGrid::query()->where('station_id', $station['id'])->where('grid_id', $gridId)->first();
|
|
|
- $materialBox = MaterialBox::query()->where('id', $grid['material_box_id'])->first();
|
|
|
+
|
|
|
+ $station = Station::query()->where('code', $locCode)->with('parent','currentStationTask.stationTaskMaterialBoxes.materialBox')->first();
|
|
|
try {
|
|
|
- $bool = $this->putBinToStore($station, $materialBox, $grid); // 推送任务
|
|
|
- if($bool)$this->stationCacheShelfGridService->lightOff($locCode, $PTLAction); // 灭灯广播
|
|
|
- return ['success' => $bool];
|
|
|
+ $bool = $this->putBinToStore($station); // 推送任务
|
|
|
+ if($bool){
|
|
|
+ $this->_stationCacheBroadCast($locCode,$PTLAction); // 灭灯广播
|
|
|
+ $this->_stationCacheLightOff($locCode);
|
|
|
+ return ['success' => true];
|
|
|
+ }else{
|
|
|
+ return ['success' => false,'errMsg' => '机器人推送失败'];
|
|
|
+ }
|
|
|
} catch (ErrorException $e) {
|
|
|
LogService::log(__FUNCTION__,'缓存架推送任务失败',json_encode($e->getMessage()));
|
|
|
return ['success' => false,'errMsg' => $e->getMessage()];
|
|
|
@@ -50,59 +65,120 @@ class CacheShelfService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 推任务
|
|
|
+ * 推任务至海柔机器人
|
|
|
* @param $station
|
|
|
- * @param $materialBox
|
|
|
- * @param $grid
|
|
|
* @return bool
|
|
|
* @throws ErrorException
|
|
|
*/
|
|
|
- public function putBinToStore($station, $materialBox, $grid): bool
|
|
|
+ public function putBinToStore($station): bool
|
|
|
{
|
|
|
$this->instant($this->stationTaskMaterialBoxService, 'StationTaskMaterialBoxService');
|
|
|
$this->instant($this->stationCacheShelfGridService, 'StationCacheShelfGridService');
|
|
|
$this->instant($this->foreignHaiRoboticsService, 'ForeignHaiRoboticsService');
|
|
|
|
|
|
/** @var StationTaskMaterialBox $stationTaskMaterialBox */
|
|
|
- $stationTaskMaterialBox = $this->stationTaskMaterialBoxService->createByStationMaterialBox($station, $materialBox);
|
|
|
- $this->stationCacheShelfGridService->processGrid($grid, $station, $materialBox);
|
|
|
+ $stationTaskMaterialBox = $station['currentStationTask']['stationTaskMaterialBoxes'];
|
|
|
+ return $this->foreignHaiRoboticsService->putBinToStore_fromCacheShelf($stationTaskMaterialBox);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建站任务和料箱任务
|
|
|
+ * @param $stationCode
|
|
|
+ * @param $materialBoxCode
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function createStationTask($stationCode,$materialBoxCode): array
|
|
|
+ {
|
|
|
+ $this->instant($this->stationTaskService, 'StationTaskService');
|
|
|
+ $this->instant($this->stationTaskMaterialBoxService,'stationTaskMaterialBoxService');
|
|
|
|
|
|
- $station->setRelation('grids', $grid);
|
|
|
- $stationTaskMaterialBox->setRelation('station', $station);
|
|
|
- $stationTaskMaterialBox->setRelation('materialBox', $materialBox);
|
|
|
+// $station = Station::query()->with('currentPendingTask.stationTaskMaterialBoxes.materialBox')->firstOrCreate(['code' => $stationCode]);
|
|
|
+ $station = Station::query()->where('code' , $stationCode)->first();
|
|
|
+ if(!$station){
|
|
|
+ $arr = [];
|
|
|
+ preg_match('/^HAI([\w]+)/',$stationCode,$arr);
|
|
|
+ $parentCode = $arr[1] ?? '';
|
|
|
+ $stationType = StationType::query()->where('name','缓存架')->first();
|
|
|
+ $parentStation = Station::query()->firstOrCreate(['code'=>$parentCode],['station_type_id'=>$stationType['id']]);
|
|
|
+ $station = Station::query()->firstOrCreate(['code' => $stationCode,'parent_id'=>$parentStation['id']],['name'=>$stationCode,'station_type_id' => $stationType['id']]);
|
|
|
+ }
|
|
|
|
|
|
- return $this->foreignHaiRoboticsService->putBinToStore_fromCacheShelf($stationTaskMaterialBox);
|
|
|
+ $materialBox = MaterialBox::query()->firstOrCreate(['code' => $materialBoxCode]);
|
|
|
+ if($station['currentPendingTask']['stationTaskMaterialBoxes']['materialBox'] ?? false){
|
|
|
+ return ['success' => false,'message' => '当前已有未完成的站任务'];
|
|
|
+ }
|
|
|
+ $stationTask = $this->stationTaskService->create(1); // 生成站任务
|
|
|
+ $this->stationTaskMaterialBoxService->createByStationMaterialBox($station,$materialBox); // 创建料箱任务
|
|
|
+ $this->stationTaskService->registerStations($stationTask,[$station['id']]); // 注册站任务站
|
|
|
+ return['success'=>true];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 控制格口亮灯
|
|
|
+ * @param $locCode
|
|
|
+ * @param string $title
|
|
|
+ * @param null $materialCode
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function _stationCacheLightOn($locCode,$title = 'title',$materialCode = null)
|
|
|
+ {
|
|
|
+ $params = [
|
|
|
+ "areaCode" => "1004",
|
|
|
+ 'locCode' => $locCode,
|
|
|
+ 'PTLAction' => 1,
|
|
|
+ 'PTLSettings' => [
|
|
|
+ 'color'=> 1,
|
|
|
+ 'frequency' =>1
|
|
|
+ ],
|
|
|
+ "displayInfo" => [
|
|
|
+ "detail01" => $materialCode,
|
|
|
+ "detail02" => "detail02",
|
|
|
+ "detail03" => "detail03",
|
|
|
+ "qrCode" => "qrCode",
|
|
|
+ "qty00" => "11",
|
|
|
+ "qty01" => 1,
|
|
|
+ "qty02" => 2,
|
|
|
+ "title" => $title,
|
|
|
+ "uomDesc01" => "uo",
|
|
|
+ "uomDesc02" => "uo"
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ $response = Http::post(config('api.haiq.storage.light'), $params);
|
|
|
+ return json_decode($response->body());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 控制格口灭灯
|
|
|
+ * @param $locCode
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function _stationCacheLightOff($locCode){
|
|
|
+ $params = [
|
|
|
+ "areaCode" => "1004",
|
|
|
+ 'locCode' => $locCode,
|
|
|
+ 'PTLAction' => 0,
|
|
|
+ ];
|
|
|
+ $response = Http::post(config('api.haiq.storage.light'), $params);
|
|
|
+ return json_decode($response->body());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 广播 通知货物被取走
|
|
|
+ * @param $locCode
|
|
|
+ * @param $PTLAction
|
|
|
+ */
|
|
|
+ public function _stationCacheBroadCast($locCode,$PTLAction)
|
|
|
+ {
|
|
|
+ if($PTLAction == 0){
|
|
|
+ $station = Station::query()->with('parent')->where('code',$locCode)->first();
|
|
|
+ $json = json_encode( [
|
|
|
+ 'station_id' => $station['parent']['id'],
|
|
|
+ 'code' => $station['parent']['code'],
|
|
|
+ 'gird_id' => $station['id'],
|
|
|
+ 'grid_code' => $station['code'],
|
|
|
+ ]);
|
|
|
+ broadcast(new BroadcastToStation($station['id'],$json));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-// /**
|
|
|
-// * 入库任务完成
|
|
|
-// * @param $params
|
|
|
-// */
|
|
|
-// public function putBinToStoreFinish($params)
|
|
|
-// {
|
|
|
-// $this->instant($this->stationTaskMaterialBoxService,'StationTaskMaterialBoxService');
|
|
|
-//
|
|
|
-// $locCode = $params['locCode'];
|
|
|
-//
|
|
|
-// list($stationCode, $gridId) = StationCacheShelfGrid::getGridByCode($locCode);
|
|
|
-// $station = Station::query()->where('code', $stationCode)->first();
|
|
|
-//
|
|
|
-// $stationCacheShelfGrid = StationCacheShelfGrid::query()->with('materialBox')->where('station_id', $station)->where('grid_id', $gridId)->first();
|
|
|
-// $stationCacheShelfGrid->update(['status' => '0', 'material_box_id' => null]);
|
|
|
-//
|
|
|
-// $StationTaskMaterialBox = StationTaskMaterialBox::query()->where('station_id', $station['id'])->where('material_box_id', $stationCacheShelfGrid['$stationCacheShelfGrid'])->first();
|
|
|
-// $this->stationTaskMaterialBoxService->set($StationTaskMaterialBox, ['status' => '已完成']);
|
|
|
-// }
|
|
|
-
|
|
|
-// /**
|
|
|
-// * 取消格口任务
|
|
|
-// * @param Station $station
|
|
|
-// * @param array $girds
|
|
|
-// */
|
|
|
-// public function cancelTask(Station $station, array $girds = [])
|
|
|
-// {
|
|
|
-// $gridQuery = StationCacheShelfGrid::query()->where('station_id', $station['id']);
|
|
|
-// if (count($girds) > 0) $gridQuery->whereIn('grid_id', $girds);
|
|
|
-// $this->stationCacheShelfGridService->cancelTask($gridQuery->get());
|
|
|
-// }
|
|
|
}
|