BatchService.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Services;
  3. use App\Batch;
  4. use Exception;
  5. Class BatchService
  6. {
  7. /** @var StationTaskBatchService $stationTaskBatchService */
  8. private $stationTaskBatchService;
  9. /** @var StationRuleBatchService $stationRuleBatchService */
  10. private $stationRuleBatchService;
  11. /** @var StationTaskMaterialBoxService $stationTaskMaterialBoxService */
  12. private $stationTaskMaterialBoxService;
  13. public function __construct(){
  14. $this->stationTaskBatchService=null;
  15. $this->stationRuleBatchService=null;
  16. $this->stationTaskMaterialBoxService=null;
  17. }
  18. public function get(array $params)
  19. {~
  20. $query = Batch::query();
  21. foreach ($params as $column=>$param){
  22. if (is_array($param))$query->whereIn($column,$param);
  23. else $query->where($column,$param);
  24. }
  25. return $query->get();
  26. }
  27. public function insert(array $insert)
  28. {
  29. $result = Batch::query()->insert($insert);
  30. if($result)$this->assignTasks($insert);
  31. return $result;
  32. }
  33. public function updateWhereIn($key,$values,$updateKeyValues){
  34. Batch::query()->whereIn($key,$values)->update($updateKeyValues);
  35. }
  36. /**
  37. * 为波次附加任务,已附加的重复任务不影响
  38. * @param Batch[] $batches
  39. * @throws Exception
  40. */
  41. public function assignTasks(array $batches)
  42. {
  43. $this->stationTaskBatchService=app('StationTaskBatchService');
  44. $this->stationRuleBatchService=app('StationRuleBatchService');
  45. $batches_canProcess = $this->stationRuleBatchService->getBatches_canProcess($batches); //按规则过滤需要的波次
  46. if($batches_canProcess->isEmpty()) return;
  47. $stationTaskBatches=$this->stationTaskBatchService->createByBatches($batches); //注册波次任务
  48. //注册商品任务
  49. //注册料箱任务
  50. //注册总任务
  51. }
  52. }