|
|
@@ -2,47 +2,63 @@
|
|
|
|
|
|
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\StationType;
|
|
|
use App\Traits\ServiceAppAop;
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
+use Illuminate\Database\Eloquent\Builder;
|
|
|
+use Illuminate\Database\Eloquent\Collection;
|
|
|
|
|
|
-class CacheShelfService
|
|
|
+class CacheShelfService
|
|
|
{
|
|
|
use ServiceAppAop;
|
|
|
|
|
|
protected $modelClass = Station::class;
|
|
|
+
|
|
|
+ /** @var StationService $stationService */
|
|
|
+ private $stationService;
|
|
|
/** @var StationTaskMaterialBoxService $stationTaskMaterialBoxService */
|
|
|
private $stationTaskMaterialBoxService;
|
|
|
- /** @var StationCacheShelfGridService $stationCacheShelfGridService */
|
|
|
- private $stationCacheShelfGridService;
|
|
|
/** @var ForeignHaiRoboticsService $foreignHaiRoboticsService */
|
|
|
private $foreignHaiRoboticsService;
|
|
|
+ /** @var StationTaskService $stationTaskService */
|
|
|
+ private $stationTaskService;
|
|
|
+ /** @var StationTaskChildService $stationTaskChildService */
|
|
|
+ private $stationTaskChildService;
|
|
|
|
|
|
/**
|
|
|
- * 获取现有的缓存架任务
|
|
|
- * @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','pendingStationTask.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)->first();
|
|
|
try {
|
|
|
- $bool = $this->putBinToStore($station, $materialBox, $grid); // 推送任务
|
|
|
- if($bool)$this->stationCacheShelfGridService->lightOff($locCode, $PTLAction); // 灭灯广播
|
|
|
- return ['success' => $bool];
|
|
|
+ $bool = $this->putBinToStore($station); // 推送任务
|
|
|
+ if($bool){
|
|
|
+ LogService::log(__CLASS__,'lightOffTask','code' .' true'. $locCode.json_encode($station));
|
|
|
+ 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 +66,193 @@ 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');
|
|
|
+ $this->instant($this->stationService, 'StationService');
|
|
|
+ $this->instant($this->stationTaskService, 'StationTaskService');
|
|
|
+ $this->instant($this->stationTaskChildService, 'StationTaskChildService');
|
|
|
+
|
|
|
+ /** @var StationTaskMaterialBox $takeStationTaskMaterialBox */
|
|
|
+ $takeStationTaskMaterialBox = $station['pendingStationTask']['stationTaskMaterialBoxes']->first();
|
|
|
+
|
|
|
+ $formStation = $this->stationService->getStation_byType('立库');
|
|
|
+
|
|
|
+ // 创建入立库任务
|
|
|
+ $stationTask = $this->stationTaskService->create(1); // 生成站任务
|
|
|
+ $this->stationTaskService->registerStations($stationTask,[$formStation['id']]); // 注册站任务站
|
|
|
+ /** @var StationTaskMaterialBox $putStationTaskMaterialBox */
|
|
|
+ $putStationTaskMaterialBox = $this->stationTaskMaterialBoxService->create([
|
|
|
+ 'station_id' => $formStation['id'],
|
|
|
+ 'material_box_id' => $takeStationTaskMaterialBox['material_box_id'],
|
|
|
+ 'status' => '待处理',
|
|
|
+ ]);
|
|
|
+ $putStationTaskMaterialBox['station_task_id'] = $stationTask->first()['id'];
|
|
|
+ $putStationTaskMaterialBox['type'] = '放';
|
|
|
+ $putStationTaskMaterialBox->update();
|
|
|
+
|
|
|
+ $params = [[
|
|
|
+ 'station_task_id'=>$stationTask->first()['id'],
|
|
|
+ 'station_taskable_type'=>StationTaskMaterialBox::class,
|
|
|
+ 'station_taskable_id'=>$putStationTaskMaterialBox['id']
|
|
|
+ ]];
|
|
|
+
|
|
|
+ $this->stationTaskChildService->insert($params); // 任务任务注册
|
|
|
+ // 标记站任务为处理中
|
|
|
+ $this->stationTaskMaterialBoxService->set($takeStationTaskMaterialBox,[
|
|
|
+ 'status' => '处理中'
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 推立库任务
|
|
|
+ return $this->foreignHaiRoboticsService->putBinToStore_fromCacheShelf($putStationTaskMaterialBox,$station['code']);
|
|
|
+ }
|
|
|
|
|
|
- /** @var StationTaskMaterialBox $stationTaskMaterialBox */
|
|
|
- $stationTaskMaterialBox = $this->stationTaskMaterialBoxService->createByStationAndMaterialBox($station, $materialBox);
|
|
|
- $this->stationCacheShelfGridService->processGrid($grid, $station, $materialBox);
|
|
|
+ /**
|
|
|
+ * 创建站任务和料箱任务
|
|
|
+ * @param $stationCode
|
|
|
+ * @param $materialBoxCode
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function createStationTask($stationCode,$materialBoxCode): array
|
|
|
+ {
|
|
|
+ $this->instant($this->stationTaskService, 'StationTaskService');
|
|
|
+ $this->instant($this->stationTaskMaterialBoxService,'StationTaskMaterialBoxService');
|
|
|
+ $this->instant($this->stationTaskChildService,'StationTaskChildService');
|
|
|
|
|
|
- $station->setRelation('grids', $grid);
|
|
|
- $stationTaskMaterialBox->setRelation('station', $station);
|
|
|
- $stationTaskMaterialBox->setRelation('materialBox', $materialBox);
|
|
|
+ $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']]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $materialBox = MaterialBox::query()->firstOrCreate(['code' => $materialBoxCode]);
|
|
|
|
|
|
- return $this->foreignHaiRoboticsService->putBinToStore_fromCacheShelf($stationTaskMaterialBox);
|
|
|
+ if($station['pendingStationTask'] ?? false){
|
|
|
+ return ['success' => false,'message' => '当前已有未完成的站任务'];
|
|
|
+ }
|
|
|
+ $stationTask = $this->stationTaskService->create(1); // 生成站任务
|
|
|
+ $stationTaskMaterialBox = $this->stationTaskMaterialBoxService->createByStationAndMaterialBox($station,$materialBox); // 创建料箱任务
|
|
|
+ $this->stationTaskService->registerStations($stationTask,[$station['id']]); // 注册站任务站
|
|
|
+ $stationTaskMaterialBox['station_task_id'] = $stationTask->first()['id'];
|
|
|
+ $stationTaskMaterialBox->update();
|
|
|
+ $params = [[
|
|
|
+ 'station_task_id'=>$stationTask->first()['id'],
|
|
|
+ 'station_taskable_type'=>StationTaskMaterialBox::class,
|
|
|
+ 'station_taskable_id'=>$stationTaskMaterialBox['id']
|
|
|
+ ]];
|
|
|
+ $this->stationTaskChildService->insert($params); // 任务任务注册
|
|
|
+
|
|
|
+ $body = $this->_stationCacheLightOn($stationCode,$materialBoxCode);
|
|
|
+
|
|
|
+ if($body->code == 200)return ['success'=>true];
|
|
|
+ return ['success' => false,'message' => '机器人亮灯异常'];
|
|
|
}
|
|
|
|
|
|
-// /**
|
|
|
-// * 入库任务完成
|
|
|
-// * @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());
|
|
|
-// }
|
|
|
+ /**
|
|
|
+ * 控制格口亮灯
|
|
|
+ * @param $locCode
|
|
|
+ * @param string $title
|
|
|
+ * @param null $materialCode
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function _stationCacheLightOn($locCode,$materialCode = null,$title = 'title')
|
|
|
+ {
|
|
|
+ $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){
|
|
|
+ if(!$locCode)return null;
|
|
|
+ $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['parent_id'],$json));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据立库任务完成 缓存架任务 和 入立架任务
|
|
|
+ * @param StationTaskMaterialBox $putStationTaskMaterial
|
|
|
+ */
|
|
|
+ public function putStationTaskMaterialBoxProcess(StationTaskMaterialBox $putStationTaskMaterial)
|
|
|
+ {
|
|
|
+ $this->instant($this->stationTaskMaterialBoxService,'StationTaskMaterialBoxService');
|
|
|
+
|
|
|
+ $takeStationTaskMaterialBox = StationTaskMaterialBox::query()->with('station','stationTask')->where('material_box_id',$putStationTaskMaterial['material_box_id'])->whereIn('station_id',function($query){
|
|
|
+ $query->from('stations')->selectRaw('id')->whereIn('station_type_id',function($query){
|
|
|
+ $query->from('station_types')->selectRaw('id')->where('name','缓存架');
|
|
|
+ });
|
|
|
+ })->where('status','处理中')->first();
|
|
|
+
|
|
|
+ if(!$takeStationTaskMaterialBox)return ;
|
|
|
+ $this->stationTaskMaterialBoxService->set($takeStationTaskMaterialBox, [
|
|
|
+ 'status' => '完成'
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 缓存架任务
|
|
|
+ if($takeStationTaskMaterialBox->stationTask)$takeStationTaskMaterialBox->stationTask->update(['status' => '完成']);
|
|
|
+ // 入立架任务
|
|
|
+ if($putStationTaskMaterial->stationTask)$putStationTaskMaterial->stationTask->update(['status' => '完成']);
|
|
|
+
|
|
|
+ $this->_stationCacheLightOff($takeStationTaskMaterialBox->station->code ?? null);
|
|
|
+ $this->_stationCacheBroadCast($takeStationTaskMaterialBox->station->code,0);
|
|
|
+ }
|
|
|
}
|