|
|
@@ -7,9 +7,11 @@ use App\Exceptions\ErrorException;
|
|
|
use App\MaterialBox;
|
|
|
use App\Station;
|
|
|
use App\StationTask;
|
|
|
+use App\StationTaskChildren;
|
|
|
use App\StationTaskMaterialBox;
|
|
|
use App\StationType;
|
|
|
use App\Traits\ServiceAppAop;
|
|
|
+use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
@@ -50,7 +52,7 @@ class CacheShelfService
|
|
|
*/
|
|
|
public function lightOffTask($locCode, $PTLAction): array
|
|
|
{
|
|
|
- $station = Station::query()->where('code', $locCode)->first();
|
|
|
+ $station = Station::query()->with('pendingStationTask.stationTaskMaterialBoxes.materialBox')->where('code', $locCode)->first();
|
|
|
try {
|
|
|
$bool = $this->putBinToStore($station); // 推送任务
|
|
|
if($bool){
|
|
|
@@ -81,36 +83,47 @@ class CacheShelfService
|
|
|
|
|
|
/** @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([
|
|
|
+ // 查询是否有待处理的入库任务
|
|
|
+ $putStationTaskMaterialBox = StationTaskMaterialBox::query()->where([
|
|
|
'station_id' => $formStation['id'],
|
|
|
'material_box_id' => $takeStationTaskMaterialBox['material_box_id'],
|
|
|
'status' => '待处理',
|
|
|
- ]);
|
|
|
- $putStationTaskMaterialBox['station_task_id'] = $stationTask->first()['id'];
|
|
|
- $putStationTaskMaterialBox['type'] = '放';
|
|
|
- $putStationTaskMaterialBox->update();
|
|
|
+ ])->first();
|
|
|
|
|
|
- $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' => '处理中'
|
|
|
- ]);
|
|
|
+ // 创建入立库任务
|
|
|
+ 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']
|
|
|
+ ]];
|
|
|
+
|
|
|
+ $this->stationTaskChildService->insert($params); // 任务任务注册
|
|
|
+ }
|
|
|
|
|
|
// 推立库任务
|
|
|
- return $this->foreignHaiRoboticsService->putBinToStore_fromCacheShelf($putStationTaskMaterialBox,$station['code']);
|
|
|
+ $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;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -137,12 +150,19 @@ class CacheShelfService
|
|
|
|
|
|
$materialBox = MaterialBox::query()->firstOrCreate(['code' => $materialBoxCode]);
|
|
|
|
|
|
- if($station['pendingStationTask'] ?? false){
|
|
|
- return ['success' => false,'message' => '当前已有未完成的站任务'];
|
|
|
+ $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' => '当前已有进行重的任务'];
|
|
|
}
|
|
|
- $stationTask = $this->stationTaskService->create(1); // 生成站任务
|
|
|
+
|
|
|
+ $stationTask = $this->stationTaskService->create(1); // 生成站任务
|
|
|
$stationTaskMaterialBox = $this->stationTaskMaterialBoxService->createByStationAndMaterialBox($station,$materialBox); // 创建料箱任务
|
|
|
- $this->stationTaskService->registerStations($stationTask,[$station['id']]); // 注册站任务站
|
|
|
+ $this->stationTaskService->registerStations($stationTask,[$station['id']]); // 注册站任务站
|
|
|
$stationTaskMaterialBox['station_task_id'] = $stationTask->first()['id'];
|
|
|
$stationTaskMaterialBox->update();
|
|
|
$params = [[
|
|
|
@@ -153,7 +173,6 @@ class CacheShelfService
|
|
|
$this->stationTaskChildService->insert($params); // 任务任务注册
|
|
|
|
|
|
$body = $this->_stationCacheLightOn($stationCode,$materialBoxCode);
|
|
|
-
|
|
|
if($body->code == 200)return ['success'=>true];
|
|
|
return ['success' => false,'message' => '机器人亮灯异常'];
|
|
|
}
|
|
|
@@ -161,20 +180,18 @@ class CacheShelfService
|
|
|
/**
|
|
|
* 控制格口亮灯
|
|
|
* @param $locCode
|
|
|
- * @param string $title
|
|
|
* @param null $materialCode
|
|
|
+ * @param string $title
|
|
|
+ * @param string $color
|
|
|
* @return mixed
|
|
|
*/
|
|
|
- public function _stationCacheLightOn($locCode,$materialCode = null,$title = 'title')
|
|
|
+ public function _stationCacheLightOn($locCode,$materialCode = null,$title = 'title' ,string $color = '1')
|
|
|
{
|
|
|
$params = [
|
|
|
"areaCode" => "1004",
|
|
|
'locCode' => $locCode,
|
|
|
'PTLAction' => 1,
|
|
|
- 'PTLSettings' => [
|
|
|
- 'color'=> 1,
|
|
|
- 'frequency' =>1
|
|
|
- ],
|
|
|
+ 'PTLSettings' => ['color'=> $color, 'frequency' =>1],
|
|
|
"displayInfo" => [
|
|
|
"detail01" => $materialCode,
|
|
|
"detail02" => "detail02",
|
|
|
@@ -188,8 +205,9 @@ class CacheShelfService
|
|
|
"uomDesc02" => "uo"
|
|
|
],
|
|
|
];
|
|
|
- $response = Http::post(config('api.haiq.storage.light'), $params);
|
|
|
- return json_decode($response->body());
|
|
|
+ return new MaterialBox(['code' => 200]);
|
|
|
+// $response = Http::post(config('api.haiq.storage.light'), $params);
|
|
|
+// return json_decode($response->body());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -209,11 +227,12 @@ class CacheShelfService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 广播 通知货物被取走
|
|
|
+ * 广播 type success成功 error 异常
|
|
|
* @param $locCode
|
|
|
* @param $PTLAction
|
|
|
+ * @param string $type
|
|
|
*/
|
|
|
- public function _stationCacheBroadCast($locCode,$PTLAction)
|
|
|
+ public function _stationCacheBroadCast($locCode, $PTLAction,string $type = 'success')
|
|
|
{
|
|
|
if($PTLAction == 0){
|
|
|
$station = Station::query()->with('parent')->where('code',$locCode)->first();
|
|
|
@@ -223,6 +242,7 @@ class CacheShelfService
|
|
|
'code' => $station['parent']['code'],
|
|
|
'gird_id' => $station['id'],
|
|
|
'grid_code' => $station['code'],
|
|
|
+ 'type' => $type
|
|
|
]);
|
|
|
broadcast(new BroadcastToStation($station['parent_id'],$json));
|
|
|
}
|
|
|
@@ -252,7 +272,44 @@ class CacheShelfService
|
|
|
// 入立架任务
|
|
|
if($putStationTaskMaterial->stationTask)$putStationTaskMaterial->stationTask->update(['status' => '完成']);
|
|
|
|
|
|
- $this->_stationCacheLightOff($takeStationTaskMaterialBox->station->code ?? null);
|
|
|
- $this->_stationCacheBroadCast($takeStationTaskMaterialBox->station->code,0);
|
|
|
+ $this->_stationCacheLightOff($takeStationTaskMaterialBox->station->code ?? null); //海柔格口灭灯
|
|
|
+ $this->_stationCacheBroadCast($takeStationTaskMaterialBox->station->code, 0); //通知缓存架任务完成
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 取消任务
|
|
|
+ * @param $stationCode
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function clearTask($stationCode): array
|
|
|
+ {
|
|
|
+ $station = Station::query()->with(['currentStationTask.stationTaskMaterialBoxes.materialBox',
|
|
|
+ 'pendingStationTask.stationTaskMaterialBoxes.materialBox'])
|
|
|
+ ->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();
|
|
|
+
|
|
|
+ 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->delete();
|
|
|
+ }
|
|
|
+ return ['success' => true];
|
|
|
}
|
|
|
}
|