|
|
@@ -7,9 +7,11 @@ use App\Exceptions\ErrorException;
|
|
|
use App\MaterialBox;
|
|
|
use App\Station;
|
|
|
use App\StationTask;
|
|
|
+use App\StationTaskChild;
|
|
|
use App\StationTaskChildren;
|
|
|
use App\StationTaskMaterialBox;
|
|
|
use App\StationType;
|
|
|
+use App\Storage;
|
|
|
use App\Traits\ServiceAppAop;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
@@ -40,7 +42,7 @@ class CacheShelfService
|
|
|
*/
|
|
|
public function getChildStation($id)
|
|
|
{
|
|
|
- return Station::query()->where('parent_id',$id)->with('parent','pendingStationTask.stationTaskMaterialBoxes.materialBox')->get();
|
|
|
+ return Station::query()->where('parent_id', $id)->with('storage.materialBox')->get();
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -49,134 +51,95 @@ class CacheShelfService
|
|
|
* @param $locCode
|
|
|
* @param $PTLAction
|
|
|
* @return array|bool[]
|
|
|
+ * @throws \Exception
|
|
|
*/
|
|
|
public function lightOffTask($locCode, $PTLAction): array
|
|
|
{
|
|
|
- $station = Station::query()->with('pendingStationTask.stationTaskMaterialBoxes.materialBox')->where('code', $locCode)->first();
|
|
|
+ $station = Station::query()->with('storage.materialBox')->where('code', $locCode)->first();
|
|
|
try {
|
|
|
$bool = $this->putBinToStore($station); // 推送任务
|
|
|
- if($bool){
|
|
|
- LogService::log(__CLASS__,'lightOffTask','code' .' true'. $locCode.json_encode($station));
|
|
|
+ if ($bool) {
|
|
|
+ LogService::log(__CLASS__, 'lightOffTask', 'code' . ' true' . $locCode . json_encode($station));
|
|
|
return ['success' => true];
|
|
|
- }else{
|
|
|
- return ['success' => false,'errMsg' => '机器人推送失败'];
|
|
|
+ } else {
|
|
|
+ return ['success' => false, 'errMsg' => '机器人推送失败'];
|
|
|
}
|
|
|
} catch (ErrorException $e) {
|
|
|
- LogService::log(__FUNCTION__,'缓存架推送任务失败',json_encode($e->getMessage()));
|
|
|
- return ['success' => false,'errMsg' => $e->getMessage()];
|
|
|
+ LogService::log(__FUNCTION__, '缓存架推送任务失败', json_encode($e->getMessage()));
|
|
|
+ return ['success' => false, 'errMsg' => $e->getMessage()];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 推任务至海柔机器人
|
|
|
* @param $station
|
|
|
- * @return bool
|
|
|
+ * @return array
|
|
|
* @throws ErrorException
|
|
|
+ * @throws \Exception
|
|
|
*/
|
|
|
- public function putBinToStore($station): bool
|
|
|
+ public function putBinToStore($station): array
|
|
|
{
|
|
|
- $this->instant($this->stationTaskMaterialBoxService, 'StationTaskMaterialBoxService');
|
|
|
$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('立库');
|
|
|
+ /** @var MaterialBox $materialbox */
|
|
|
+ $materialBox = $station->storage->materialbox;
|
|
|
+
|
|
|
+ $formStation = $this->stationService->getStation_byType('立库'); // 立库
|
|
|
+
|
|
|
+ $stationTask = StationTask::query()->create(['station_id' => $formStation['id'], 'status' => '待处理']); // 生成任务
|
|
|
|
|
|
- // 查询是否有待处理的入库任务
|
|
|
- $putStationTaskMaterialBox = StationTaskMaterialBox::query()->where([
|
|
|
+ /** @var StationTaskMaterialBox $stationTaskMaterialBox */
|
|
|
+ $stationTaskMaterialBox = StationTaskMaterialBox::query()->create([
|
|
|
'station_id' => $formStation['id'],
|
|
|
- 'material_box_id' => $takeStationTaskMaterialBox['material_box_id'],
|
|
|
+ 'material_box_id' => $materialBox['id'],
|
|
|
'status' => '待处理',
|
|
|
- ])->first();
|
|
|
-
|
|
|
- // 创建入立库任务
|
|
|
- if(!$putStationTaskMaterialBox){
|
|
|
- $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']
|
|
|
- ]];
|
|
|
+ 'station_task_id' => $stationTask['id'],
|
|
|
+ 'type' => '放',
|
|
|
+ ]);
|
|
|
|
|
|
- $this->stationTaskChildService->insert($params); // 任务任务注册
|
|
|
- }
|
|
|
+ StationTaskChildren::query()->create([
|
|
|
+ 'station_task_id' => $stationTask['id'],
|
|
|
+ 'station_taskable_type' => StationTaskMaterialBox::class,
|
|
|
+ 'station_taskable_id' => $stationTaskMaterialBox['id']
|
|
|
+ ]);
|
|
|
|
|
|
- // 推立库任务
|
|
|
- $isSuccess = $this->foreignHaiRoboticsService->putBinToStore_fromCacheShelf($putStationTaskMaterialBox,$station['code']);
|
|
|
- if($isSuccess) $this->stationTaskMaterialBoxService->set($takeStationTaskMaterialBox,['status' => '处理中']); // 任务推送成功 标记站任务为处理中
|
|
|
- else {
|
|
|
- $materialBoxCode = $station['pendingStationTask']['stationTaskMaterialBoxes']->first()->code ?? '';
|
|
|
- $this->_stationCacheBroadCast($station->code,0,'error');
|
|
|
- $this->_stationCacheLightOn($station->code,$materialBoxCode,'拍灯重试任务');
|
|
|
- }
|
|
|
- return $isSuccess;
|
|
|
+ $bool = $this->foreignHaiRoboticsService->putBinToStore_fromCacheShelf($stationTaskMaterialBox, $station['code']);
|
|
|
+ return $bool ? ['success' => true] : ['success' => false];
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 创建站任务和料箱任务
|
|
|
+ * 缓存架和料箱的绑定
|
|
|
* @param $stationCode
|
|
|
* @param $materialBoxCode
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function createStationTask($stationCode,$materialBoxCode): array
|
|
|
+ public function bindMaterialBox($stationCode, $materialBoxCode): array
|
|
|
{
|
|
|
- $this->instant($this->stationTaskService, 'StationTaskService');
|
|
|
- $this->instant($this->stationTaskMaterialBoxService,'StationTaskMaterialBoxService');
|
|
|
- $this->instant($this->stationTaskChildService,'StationTaskChildService');
|
|
|
+ $station = Station::query()->with('storage')->where('code', $stationCode)->first();
|
|
|
|
|
|
- $station = Station::query()->where('code' , $stationCode)->first();
|
|
|
- if(!$station){
|
|
|
+ if (!$station) {
|
|
|
$arr = [];
|
|
|
- preg_match('/^HAI([\w]+)/',$stationCode,$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']]);
|
|
|
+ $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]);
|
|
|
|
|
|
- $station->load('pendingStationTask.stationTaskMaterialBoxes.materialBox');
|
|
|
- if($station->pendingStationTask){
|
|
|
- if($station['pendingStationTask']['stationTaskMaterialBoxes']->first()->materialBox->code == $materialBoxCode){
|
|
|
- $response = $this->_stationCacheLightOn($stationCode,$materialBoxCode,'任务重试');
|
|
|
- if($response->code) return ['success'=>true,'message' => '任务重试'];
|
|
|
- return ['success'=>true,'message' => '任务重试失败'];
|
|
|
- }
|
|
|
- return ['success' => false,'message' => '当前已有进行重的任务'];
|
|
|
- }
|
|
|
+ $storage = $station->storage ?? Storage::query()->firstOrCreate(['station_id' => $station['id']]);
|
|
|
|
|
|
- $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' => '机器人亮灯异常'];
|
|
|
+ $result = $this->_stationCacheLightOn($station['code'],$materialBoxCode);
|
|
|
+ if($result['code'] == 200){
|
|
|
+ $storage->update(['material_box_id' => $materialBox['id'],'status' => 1]);
|
|
|
+ return ['success' => true];
|
|
|
+ }
|
|
|
+ return ['success' => false,'message' => $result['errMsg']];
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 控制格口亮灯
|
|
|
* @param $locCode
|
|
|
@@ -185,13 +148,13 @@ class CacheShelfService
|
|
|
* @param string $color
|
|
|
* @return mixed
|
|
|
*/
|
|
|
- public function _stationCacheLightOn($locCode,$materialCode = null,$title = 'title' ,string $color = '1')
|
|
|
+ public function _stationCacheLightOn($locCode, $materialCode = null, $title = 'title', string $color = '1')
|
|
|
{
|
|
|
$params = [
|
|
|
"areaCode" => "1004",
|
|
|
'locCode' => $locCode,
|
|
|
'PTLAction' => 1,
|
|
|
- 'PTLSettings' => ['color'=> $color, 'frequency' =>1],
|
|
|
+ 'PTLSettings' => ['color' => $color, 'frequency' => 1],
|
|
|
"displayInfo" => [
|
|
|
"detail01" => $materialCode,
|
|
|
"detail02" => "detail02",
|
|
|
@@ -214,8 +177,9 @@ class CacheShelfService
|
|
|
* @param $locCode
|
|
|
* @return mixed
|
|
|
*/
|
|
|
- public function _stationCacheLightOff($locCode){
|
|
|
- if(!$locCode)return null;
|
|
|
+ public function _stationCacheLightOff($locCode)
|
|
|
+ {
|
|
|
+ if (!$locCode) return null;
|
|
|
$params = [
|
|
|
"areaCode" => "1004",
|
|
|
'locCode' => $locCode,
|
|
|
@@ -231,84 +195,62 @@ class CacheShelfService
|
|
|
* @param $PTLAction
|
|
|
* @param string $type
|
|
|
*/
|
|
|
- public function _stationCacheBroadCast($locCode, $PTLAction,string $type = 'success')
|
|
|
+ public function _stationCacheBroadCast($locCode, $PTLAction, string $type = 'success')
|
|
|
{
|
|
|
- if($PTLAction == 0){
|
|
|
- $station = Station::query()->with('parent')->where('code',$locCode)->first();
|
|
|
+ if (!$locCode) return;
|
|
|
+ if ($PTLAction == 0) {
|
|
|
+ $station = Station::query()->with('parent')->where('code', $locCode)->first();
|
|
|
|
|
|
- $json = json_encode( [
|
|
|
+ $json = json_encode([
|
|
|
'station_id' => $station['parent']['id'],
|
|
|
- 'code' => $station['parent']['code'],
|
|
|
+ 'code' => $station['parent']['code'],
|
|
|
'gird_id' => $station['id'],
|
|
|
'grid_code' => $station['code'],
|
|
|
- 'type' => $type
|
|
|
+ 'type' => $type,
|
|
|
+ 'status' => 0
|
|
|
]);
|
|
|
- broadcast(new BroadcastToStation($station['parent_id'],$json));
|
|
|
+ broadcast(new BroadcastToStation($station['parent_id'], $json));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 根据立库任务完成 缓存架任务 和 入立架任务
|
|
|
- * @param StationTaskMaterialBox $putStationTaskMaterial
|
|
|
+ * 根据立库任务完成对storage进行修改
|
|
|
+ * @param StationTaskMaterialBox $stationTaskMaterial
|
|
|
*/
|
|
|
- public function putStationTaskMaterialBoxProcess(StationTaskMaterialBox $putStationTaskMaterial)
|
|
|
+ public function putStationTaskMaterialBoxProcess(StationTaskMaterialBox $stationTaskMaterial)
|
|
|
{
|
|
|
- $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' => '完成'
|
|
|
- ]);
|
|
|
+ $this->instant($this->stationTaskMaterialBoxService, 'StationTaskMaterialBoxService');
|
|
|
|
|
|
- // 缓存架任务
|
|
|
- if($takeStationTaskMaterialBox->stationTask)$takeStationTaskMaterialBox->stationTask->update(['status' => '完成']);
|
|
|
- // 入立架任务
|
|
|
- if($putStationTaskMaterial->stationTask)$putStationTaskMaterial->stationTask->update(['status' => '完成']);
|
|
|
+ $storage = Storage::query()->where('material_box_id', $stationTaskMaterial['material_box_id'])->where('status',1)->first();
|
|
|
+ if($storage)$storage->update(['status' => 0, 'material_box_id' => null]);
|
|
|
|
|
|
- $this->_stationCacheLightOff($takeStationTaskMaterialBox->station->code ?? null); //海柔格口灭灯
|
|
|
- $this->_stationCacheBroadCast($takeStationTaskMaterialBox->station->code, 0); //通知缓存架任务完成
|
|
|
+ $this->_stationCacheLightOff($stationTaskMaterial->station->code ?? null); //海柔格口灭灯
|
|
|
+ $this->_stationCacheBroadCast($stationTaskMaterial->station->code ?? null, 0); //通知缓存架任务完成
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 取消任务
|
|
|
* @param $stationCode
|
|
|
* @return array
|
|
|
+ * @throws \Exception
|
|
|
*/
|
|
|
public function clearTask($stationCode): array
|
|
|
{
|
|
|
- $station = Station::query()->with(['currentStationTask.stationTaskMaterialBoxes.materialBox',
|
|
|
- 'pendingStationTask.stationTaskMaterialBoxes.materialBox'])
|
|
|
- ->where('code',$stationCode)->first();
|
|
|
+ $station = Station::query()->with('storage')->where('code', $stationCode)->first();
|
|
|
|
|
|
- if($station->currentStationTask)return ['success' => false,'message' => '当前任务正在执行','data'=>$stationCode];
|
|
|
- if($station->pendingStationTask->stationTaskMaterialBoxes->count() == 0){
|
|
|
- $station->pendingStationTask->delete();
|
|
|
- return ['success' => true];
|
|
|
- }
|
|
|
-
|
|
|
- $taskStationTaskMaterialBox = $station->pendingStationTask->stationTaskMaterialBoxes->first() ?? null;
|
|
|
- $stationTaskMaterialBoxes = StationTaskMaterialBox::query()->with('stationTask')
|
|
|
- ->where('material_box_id',$taskStationTaskMaterialBox['material_box_id'])
|
|
|
- ->where('station_id','!=',$station->pendingStationTask['id'])
|
|
|
- ->get();
|
|
|
+ if (!$station) return ['success' => false, 'message' => '传入参数异常,找不到对应的缓存架记录'];
|
|
|
|
|
|
- foreach ($stationTaskMaterialBoxes as $stationTaskMaterialBox) {
|
|
|
- if($stationTaskMaterialBox->stationTask){
|
|
|
- StationTaskChildren::query()->where([
|
|
|
- 'station_task_id' => $stationTaskMaterialBox->stationTask['id'],
|
|
|
- 'station_taskable_type'=>StationTaskMaterialBox::class,
|
|
|
- 'station_taskable_id'=>$stationTaskMaterialBox['id']])->delete();
|
|
|
-
|
|
|
- $stationTaskMaterialBox->stationTask->delete();
|
|
|
+ $stationTaskMaterialBox = StationTaskMaterialBox::query()->where('material_box_id',$station['storage']['material_box_id'])->first();
|
|
|
+ if($stationTaskMaterialBox ){
|
|
|
+ if($stationTaskMaterialBox->status == '处理中')
|
|
|
+ return ['success' => false, 'message' => '当前缓存架任务正在处理中'];
|
|
|
+ else{
|
|
|
+ $stationTaskMaterialBox->delete();
|
|
|
}
|
|
|
- $stationTaskMaterialBox->delete();
|
|
|
}
|
|
|
+
|
|
|
+ $station->storage->update(['status' => 0,'material_box_id' => null]);
|
|
|
+
|
|
|
return ['success' => true];
|
|
|
}
|
|
|
}
|