| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace App\Services;
- use App\Batch;
- use Exception;
- use App\Traits\ServiceAppAop;
- Class BatchService
- {
- use ServiceAppAop;
- /** @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 insert(array $insert): bool
- {
- $result = Batch::query()->insert($insert);
- // if($result)$this->assignTasks($insert);
- return $result;
- }
- public function updateWhereIn($key,$values,$updateKeyValues){
- Batch::query()->whereIn($key,$values)->update($updateKeyValues);
- }
- /**
- * 为波次附加任务,已附加的重复任务不影响
- * @param Batch[] $batches
- * @throws Exception
- */
- public function assignTasks(array $batches)
- {
- $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_canProcess = $this->stationRuleBatchService->getBatches_canProcess($batches); //按规则过滤需要的波次
- if($batches_canProcess->isEmpty()) return;
- $stationTasks = $this->stationTaskService->create($batches_canProcess->count()); //生成总任务
- $stationTaskBatches=$this->stationTaskBatchService->createByBatches($batches_canProcess,$stationTasks); //注册波次任务
- $this->stationTaskCommodityService->createByBatches($batches_canProcess,$stationTasks); //注册商品任务
- $this->stationTaskMaterialBoxService->createByBatches($batches_canProcess,$stationTasks); //注册料箱任务
- $this->stationTaskBatchService->runMany($stationTaskBatches);//执行波次任务
- }
- public function getBatchByCodes($codes)
- {
- if(empty($codes))return collect();
- if(count($codes) == 0)return collect();
- return Batch::query()->whereIn('code',$codes)->get();
- }
- }
|