BatchService.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App\Services;
  3. use App\Batch;
  4. use App\OracleActAllocationDetails;
  5. use App\Order;
  6. use App\OrderCommodity;
  7. use App\Owner;
  8. use ErrorException;
  9. use Exception;
  10. use Illuminate\Support\Collection;
  11. use Illuminate\Support\Facades\Http;
  12. use App\Traits\ServiceAppAop;
  13. class BatchService
  14. {
  15. use ServiceAppAop;
  16. protected $modelClass=Batch::class;
  17. /** @var StationTaskBatchService $stationTaskBatchService */
  18. private $stationTaskBatchService;
  19. /** @var StationRuleBatchService $stationRuleBatchService */
  20. private $stationRuleBatchService;
  21. /** @var StationTaskMaterialBoxService $stationTaskMaterialBoxService */
  22. private $stationTaskMaterialBoxService;
  23. /** @var StationTaskCommodityService $stationTaskCommodityService */
  24. private $stationTaskCommodityService;
  25. /** @var StationTaskService $stationTaskService */
  26. private $stationTaskService;
  27. public function __construct(){
  28. $this->stationTaskBatchService=null;
  29. $this->stationRuleBatchService=null;
  30. $this->stationTaskMaterialBoxService=null;
  31. $this->stationTaskCommodityService=null;
  32. $this->stationTaskService=null;
  33. }
  34. public function get(array $params)
  35. {
  36. $query = Batch::query();
  37. foreach ($params as $column=>$param){
  38. if (is_array($param))$query->whereIn($column,$param);
  39. else $query->where($column,$param);
  40. }
  41. return $query->get();
  42. }
  43. public function updateWhereIn($key,$values,$updateKeyValues){
  44. Batch::query()->whereIn($key,$values)->update($updateKeyValues);
  45. }
  46. /**
  47. * 为波次附加任务,已附加的重复任务不影响
  48. * @param Collection $batches
  49. * @throws Exception
  50. */
  51. public function assignTasks(Collection $batches)
  52. {
  53. try{
  54. $this->instant($this->stationTaskBatchService,'StationTaskBatchService');
  55. $this->instant($this->stationRuleBatchService,'StationRuleBatchService');
  56. $this->instant($this->stationTaskService,'StationTaskService');
  57. $this->instant($this->stationTaskCommodityService,'StationTaskCommodityService');
  58. $this->instant($this->stationTaskMaterialBoxService,'StationTaskMaterialBoxService');
  59. $batches_shouldProcess = $this->stationRuleBatchService->getBatches_shouldProcess($batches); //按规则过滤需要的波次
  60. if($batches_shouldProcess->isEmpty()) return;
  61. $stationTasks = $this->stationTaskService->create($batches_shouldProcess->count()); //生成总任务
  62. $stationTaskBatches=$this->stationTaskBatchService->createByBatches($batches_shouldProcess,$stationTasks); //注册波次任务
  63. $stationTaskMaterialBoxes=$this->stationTaskMaterialBoxService->createByBatches($batches_shouldProcess,$stationTasks); //注册料箱任务
  64. $stationTaskCommodities=$this->stationTaskCommodityService->createByBatches($batches_shouldProcess,$stationTasks); //注册商品任务
  65. $ran=$this->stationTaskBatchService->runMany($stationTaskBatches);//执行波次任务
  66. LogService::log('batchservice',__FUNCTION__,'8'.$ran->toJson());
  67. }catch(Exception $e){
  68. throw new ErrorException('注册任务失败: '.json_encode($batches). $e->getMessage());
  69. }
  70. }
  71. public function getBatchByCodes($codes)
  72. {
  73. if(empty($codes))return collect();
  74. if(count($codes) == 0)return collect();
  75. return Batch::query()->whereIn('code',$codes)->get();
  76. }
  77. }