|
@@ -46,11 +46,15 @@ class CacheShelfTaskJob implements ShouldQueue
|
|
|
switch ($this->key){
|
|
switch ($this->key){
|
|
|
case "CACHE_SHELF_AVAILABLE"://缓存架释放呼叫
|
|
case "CACHE_SHELF_AVAILABLE"://缓存架释放呼叫
|
|
|
//等待一定时间来合并同类请求至此
|
|
//等待一定时间来合并同类请求至此
|
|
|
- $available = Cache::get($this->key,function (){return [];});
|
|
|
|
|
- if ($this->count!==count($available))return;
|
|
|
|
|
|
|
+ $available = Cache::get($this->key,0);
|
|
|
|
|
+ if ($this->count!==$available)return;
|
|
|
|
|
+ Cache::forget($this->key); //无论是否开始分发 都清除本次缓存架的计数器
|
|
|
|
|
+ //获取可用缓存架
|
|
|
|
|
+ $stations = app("StationService")->getCacheShelf(true);
|
|
|
|
|
+ if ($stations->count()==0)break;
|
|
|
//检查事务 尝试分发任务 改变下方序列来控制分发顺序 逐级分发 一次成功就终止
|
|
//检查事务 尝试分发任务 改变下方序列来控制分发顺序 逐级分发 一次成功就终止
|
|
|
- if ($this->dispatchOutTask($available,$service))break; //首先尝试向出库事务分发 分发成功跳出
|
|
|
|
|
- if ($this->dispatchInTask($available,$service))break; //尝试向入库事务分发
|
|
|
|
|
|
|
+ if ($this->dispatchOutTask($stations,$service))break; //首先尝试向出库事务分发 分发成功跳出
|
|
|
|
|
+ if ($this->dispatchInTask($stations,$service))break; //尝试向入库事务分发
|
|
|
break;
|
|
break;
|
|
|
default://入库呼叫
|
|
default://入库呼叫
|
|
|
if (!Cache::has($this->key))return;
|
|
if (!Cache::has($this->key))return;
|
|
@@ -61,10 +65,10 @@ class CacheShelfTaskJob implements ShouldQueue
|
|
|
$controlSuccess = $service->controlHaiRobot($dataToPost,$task,'缓存架入立架');
|
|
$controlSuccess = $service->controlHaiRobot($dataToPost,$task,'缓存架入立架');
|
|
|
$tIds = [];
|
|
$tIds = [];
|
|
|
$task->each(function ($t)use(&$tIds){$tIds[] = $t->id;});
|
|
$task->each(function ($t)use(&$tIds){$tIds[] = $t->id;});
|
|
|
- StationTaskMaterialBox::query()->where("id",$tIds)
|
|
|
|
|
|
|
+ StationTaskMaterialBox::query()->whereIn("id",$tIds)
|
|
|
->where("status","待处理")->update(['status' => $controlSuccess ? '处理中' : '异常']);
|
|
->where("status","待处理")->update(['status' => $controlSuccess ? '处理中' : '异常']);
|
|
|
Cache::forget($this->key);
|
|
Cache::forget($this->key);
|
|
|
- if ($controlSuccess)$this->materialBoxMappingCacheShelf($task,$location);
|
|
|
|
|
|
|
+ //if ($controlSuccess)$this->materialBoxMappingCacheShelf($task,$location);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -88,11 +92,11 @@ class CacheShelfTaskJob implements ShouldQueue
|
|
|
/**
|
|
/**
|
|
|
* 分发出库任务
|
|
* 分发出库任务
|
|
|
*
|
|
*
|
|
|
- * @param array $available
|
|
|
|
|
|
|
+ * @param $stations
|
|
|
* @param $service
|
|
* @param $service
|
|
|
* @return bool
|
|
* @return bool
|
|
|
*/
|
|
*/
|
|
|
- private function dispatchOutTask(array $available, $service):bool
|
|
|
|
|
|
|
+ private function dispatchOutTask(&$stations,$service):bool
|
|
|
{
|
|
{
|
|
|
DB::beginTransaction();
|
|
DB::beginTransaction();
|
|
|
try {
|
|
try {
|
|
@@ -101,14 +105,14 @@ class CacheShelfTaskJob implements ShouldQueue
|
|
|
$query->where("status","待处理");
|
|
$query->where("status","待处理");
|
|
|
})->where("status",3)->lockForUpdate()
|
|
})->where("status",3)->lockForUpdate()
|
|
|
->where("mark",2)->groupBy("task_id")->get(); //检索等待的队列事务来获取对应任务
|
|
->where("mark",2)->groupBy("task_id")->get(); //检索等待的队列事务来获取对应任务
|
|
|
- if ($this->dispatchTask($tasks,$available,$service,function ($obj,$stationId,$time,&$updateTransaction){
|
|
|
|
|
|
|
+ if ($this->dispatchTask($tasks,$stations,$service,function ($obj,$stationId,$time,&$updateTransaction){
|
|
|
if ($obj->ids!=$obj->id){
|
|
if ($obj->ids!=$obj->id){
|
|
|
$ids = explode(",",$obj->ids);
|
|
$ids = explode(",",$obj->ids);
|
|
|
foreach ($ids as $id)$updateTransaction[] = ["id"=>$id,"to_station_id"=>$stationId,"status"=>0,"updated_at"=>$time];
|
|
foreach ($ids as $id)$updateTransaction[] = ["id"=>$id,"to_station_id"=>$stationId,"status"=>0,"updated_at"=>$time];
|
|
|
}else $updateTransaction[] = ["id"=>$obj->id,"to_station_id"=>$stationId,"status"=>0,"updated_at"=>$time];
|
|
}else $updateTransaction[] = ["id"=>$obj->id,"to_station_id"=>$stationId,"status"=>0,"updated_at"=>$time];
|
|
|
},function ($service,$toLocation,$task,$prefix){
|
|
},function ($service,$toLocation,$task,$prefix){
|
|
|
return $service->fetchGroup_multiLocation($toLocation,$task,$prefix,'立架出至缓存架',20);
|
|
return $service->fetchGroup_multiLocation($toLocation,$task,$prefix,'立架出至缓存架',20);
|
|
|
- },"to_station_id")){DB::commit();return true;}
|
|
|
|
|
|
|
+ },"to_station_id")){DB::commit();return $stations->count()==0;} //缓存架用完 跳出,否则接着分发
|
|
|
DB::rollBack();
|
|
DB::rollBack();
|
|
|
}catch (\Exception $e){
|
|
}catch (\Exception $e){
|
|
|
DB::rollBack();
|
|
DB::rollBack();
|
|
@@ -120,11 +124,11 @@ class CacheShelfTaskJob implements ShouldQueue
|
|
|
/**
|
|
/**
|
|
|
* 分发入库任务
|
|
* 分发入库任务
|
|
|
*
|
|
*
|
|
|
- * @param array $available
|
|
|
|
|
|
|
+ * @param $stations
|
|
|
* @param $service
|
|
* @param $service
|
|
|
* @return bool
|
|
* @return bool
|
|
|
*/
|
|
*/
|
|
|
- private function dispatchInTask(array $available, $service):bool
|
|
|
|
|
|
|
+ private function dispatchInTask(&$stations,$service):bool
|
|
|
{
|
|
{
|
|
|
DB::beginTransaction();
|
|
DB::beginTransaction();
|
|
|
try {
|
|
try {
|
|
@@ -133,11 +137,14 @@ class CacheShelfTaskJob implements ShouldQueue
|
|
|
$query->where("status","待处理");
|
|
$query->where("status","待处理");
|
|
|
})->where("status",3)->lockForUpdate()
|
|
})->where("status",3)->lockForUpdate()
|
|
|
->where("mark",1)->get(); //检索等待的队列事务来获取对应任务
|
|
->where("mark",1)->get(); //检索等待的队列事务来获取对应任务
|
|
|
- if ($this->dispatchTask($tasks,$available,$service,function ($obj,$stationId,$time,&$updateTransaction){
|
|
|
|
|
|
|
+ if (!$tasks->count())return false;
|
|
|
|
|
+ if ($this->dispatchTask($tasks,$stations,$service,function ($obj,$stationId,$time,&$updateTransaction){
|
|
|
$updateTransaction[] = ["id"=>$obj->id,"fm_station_id"=>$stationId,"status"=>0,"updated_at"=>$time];
|
|
$updateTransaction[] = ["id"=>$obj->id,"fm_station_id"=>$stationId,"status"=>0,"updated_at"=>$time];
|
|
|
},function ($service,$toLocation,$task,$prefix){
|
|
},function ($service,$toLocation,$task,$prefix){
|
|
|
return $service->fetchGroup_multiLocation($toLocation,$task,'','立架出至缓存架');
|
|
return $service->fetchGroup_multiLocation($toLocation,$task,'','立架出至缓存架');
|
|
|
- },"fm_station_id")){DB::commit();return true;}
|
|
|
|
|
|
|
+ },"fm_station_id")){
|
|
|
|
|
+ DB::commit();return $stations->count()==0; //缓存架用完 跳出,否则接着分发
|
|
|
|
|
+ }
|
|
|
DB::rollBack();
|
|
DB::rollBack();
|
|
|
}catch (\Exception $e){
|
|
}catch (\Exception $e){
|
|
|
DB::rollBack();
|
|
DB::rollBack();
|
|
@@ -146,31 +153,32 @@ class CacheShelfTaskJob implements ShouldQueue
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private function dispatchTask(\Illuminate\Database\Eloquent\Collection $tasks, array $available, $service,
|
|
|
|
|
|
|
+ private function dispatchTask(\Illuminate\Database\Eloquent\Collection $tasks,&$stations, $service,
|
|
|
\Closure $update, \Closure $execute, string $stationName):bool
|
|
\Closure $update, \Closure $execute, string $stationName):bool
|
|
|
{
|
|
{
|
|
|
- if (!$tasks->count())return false;
|
|
|
|
|
- if ($tasks->count()>count($available))$tasks = $tasks->slice(0,count($available));//事务过多切割部分处理
|
|
|
|
|
|
|
+ $locations = $stations;
|
|
|
|
|
+ if ($tasks->count()>$locations->count())$tasks = $tasks->slice(0,$locations->count());//事务过多切割部分处理
|
|
|
|
|
+ if ($tasks->count()<$locations->count()){
|
|
|
|
|
+ $stations = $stations->slice($tasks->count());
|
|
|
|
|
+ $stations = $stations->values($stations);
|
|
|
|
|
+ }
|
|
|
$toLocation = collect();
|
|
$toLocation = collect();
|
|
|
$task = collect();
|
|
$task = collect();
|
|
|
- $availableTemp = array_keys($available);
|
|
|
|
|
- $map = app("StationService")->getStationMapping($availableTemp);//获取库位映射信息
|
|
|
|
|
$updateTask = [["id","station_id","updated_at"]];
|
|
$updateTask = [["id","station_id","updated_at"]];
|
|
|
$updateTransaction = [["id",$stationName,"status","updated_at"]];
|
|
$updateTransaction = [["id",$stationName,"status","updated_at"]];
|
|
|
$time = date("Y-m-d H:i:s");
|
|
$time = date("Y-m-d H:i:s");
|
|
|
|
|
+ $map = [];
|
|
|
foreach ($tasks as $index=>$obj){
|
|
foreach ($tasks as $index=>$obj){
|
|
|
- $loc = $availableTemp[$index];
|
|
|
|
|
- $toLocation->push($loc);
|
|
|
|
|
- $obj->task->station_id = $map[$loc];
|
|
|
|
|
|
|
+ $toLocation->push($stations[$index]->code);
|
|
|
|
|
+ $map[$stations[$index]->code] = $stations[$index]->id;
|
|
|
|
|
+ $obj->task->station_id = $stations[$index]->id;
|
|
|
$task->push($obj->task);
|
|
$task->push($obj->task);
|
|
|
- unset($available[$loc]);
|
|
|
|
|
- $updateTask[] = ["id"=>$obj->task->id,"station_id"=>$map[$loc],"updated_at"=>$time];
|
|
|
|
|
- $update($obj,$map[$loc],$time,$updateTransaction);
|
|
|
|
|
|
|
+ $updateTask[] = ["id"=>$obj->task->id,"station_id"=>$stations[$index]->id,"updated_at"=>$time];
|
|
|
|
|
+ $update($obj,$stations[$index]->id,$time,$updateTransaction);
|
|
|
}
|
|
}
|
|
|
app("BatchUpdateService")->batchUpdate("station_task_material_boxes",$updateTask);
|
|
app("BatchUpdateService")->batchUpdate("station_task_material_boxes",$updateTask);
|
|
|
app("BatchUpdateService")->batchUpdate("task_transactions",$updateTransaction);
|
|
app("BatchUpdateService")->batchUpdate("task_transactions",$updateTransaction);
|
|
|
if ($execute($service,$toLocation,$task,$tasks[0]->station_task_batch_id)){
|
|
if ($execute($service,$toLocation,$task,$tasks[0]->station_task_batch_id)){
|
|
|
- Cache::forever($this->key,$available);
|
|
|
|
|
foreach ($toLocation as $value){
|
|
foreach ($toLocation as $value){
|
|
|
app("CacheShelfService")->lightUp($value,'3','0',["title"=>"机器人取箱中,禁止操作"]);
|
|
app("CacheShelfService")->lightUp($value,'3','0',["title"=>"机器人取箱中,禁止操作"]);
|
|
|
Cache::forever("CACHE_SHELF_OCCUPANCY_{$map[$value]}",true);
|
|
Cache::forever("CACHE_SHELF_OCCUPANCY_{$map[$value]}",true);
|