| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- namespace App\Services;
- use App\Batch;
- use App\OracleActAllocationDetails;
- use App\Order;
- use App\OrderCommodity;
- use App\Owner;
- use ErrorException;
- use Exception;
- use Illuminate\Support\Collection;
- use Illuminate\Support\Facades\Http;
- use App\Traits\ServiceAppAop;
- class BatchService
- {
- use ServiceAppAop;
- protected $modelClass=Batch::class;
- /** @var StationTaskBatchService $stationTaskBatchService */
- private $stationTaskBatchService;
- /** @var StationRuleBatchService $stationRuleBatchService */
- private $stationRuleBatchService;
- /** @var StationTaskMaterialBoxService $stationTaskMaterialBoxService */
- private $stationTaskMaterialBoxService;
- /** @var StationTaskCommodityService $stationTaskCommodityService */
- private $stationTaskCommodityService;
- /** @var StationTaskService $stationTaskService */
- private $stationTaskService;
- public function __construct(){
- $this->stationTaskBatchService=null;
- $this->stationRuleBatchService=null;
- $this->stationTaskMaterialBoxService=null;
- $this->stationTaskCommodityService=null;
- $this->stationTaskService=null;
- }
- public function get(array $params)
- {
- $query = Batch::query();
- foreach ($params as $column=>$param){
- if (is_array($param))$query->whereIn($column,$param);
- else $query->where($column,$param);
- }
- return $query->get();
- }
- public function updateWhereIn($key,$values,$updateKeyValues){
- Batch::query()->whereIn($key,$values)->update($updateKeyValues);
- }
- /**
- * 为波次附加任务,已附加的重复任务不影响
- * @param Collection $batches
- * @throws Exception
- */
- public function assignTasks(Collection $batches)
- {
- try{
- $this->instant($this->stationTaskBatchService,'StationTaskBatchService');
- $this->instant($this->stationRuleBatchService,'StationRuleBatchService');
- $this->instant($this->stationTaskService,'StationTaskService');
- $this->instant($this->stationTaskCommodityService,'StationTaskCommodityService');
- $this->instant($this->stationTaskMaterialBoxService,'StationTaskMaterialBoxService');
- $batches_shouldProcess = $this->stationRuleBatchService->getBatches_shouldProcess($batches); //按规则过滤需要的波次
- if($batches_shouldProcess->isEmpty()) return;
- $stationTasks = $this->stationTaskService->create($batches_shouldProcess->count()); //生成总任务
- $stationTaskBatches=$this->stationTaskBatchService->createByBatches($batches_shouldProcess,$stationTasks); //注册波次任务
- $stationTaskMaterialBoxes=$this->stationTaskMaterialBoxService->createByBatches($batches_shouldProcess,$stationTasks); //注册料箱任务
- $stationTaskCommodities=$this->stationTaskCommodityService->createByBatches($batches_shouldProcess,$stationTasks); //注册商品任务
- $ran=$this->stationTaskBatchService->runMany($stationTaskBatches);//执行波次任务
- LogService::log('batchservice',__FUNCTION__,'8'.$ran->toJson());
- }catch(Exception $e){
- throw new ErrorException('注册任务失败: '.json_encode($batches). $e->getMessage());
- }
- }
- // public function directTemp($batches){
- // $ownerName='';
- // $batches=$batches->map(function(Batch $batch)use($ownerName){
- // $owner=Owner::query()->where('name',$ownerName)->get();
- // if(!$owner) return false;
- // if($batch['owner_id']==$owner['id'])return $batch;
- // return false;
- // });
- // $bins=$batches->map(function (Batch $batch){
- // $batch->loadMissing('orders.orderCommodities');
- //
- // foreach ($batch['orders'] as $order){
- // foreach ($order['orderCommodities'] as $orderCommodity){
- // return [
- // "taskCode" =>'testTask'.microtime(),
- // "binCode" => $orderCommodity['location'],
- // "toLocCode" => 'BIN-OUT1',
- // ];
- // }
- // }
- // return null;
- // });
- //
- // $json= [
- // "taskMode" =>2,
- // "bins"=>$bins,
- // "groupCode"=>'testGroup'.microtime(),
- // "priority"=>10,
- // "sequenceFlag"=>1,
- // ];
- // $response = Http::post(config('api.haiq.storage.moveBin'),$json);
- // LogService::log(__CLASS__,__METHOD__,$response->json());
- // }
- public function getBatchByCodes($codes)
- {
- if(empty($codes))return collect();
- if(count($codes) == 0)return collect();
- return Batch::query()->whereIn('code',$codes)->get();
- }
- }
|