瀏覽代碼

波次编辑中

LD 5 年之前
父節點
當前提交
acfd2ef59a

+ 3 - 23
app/Http/Controllers/TestController.php

@@ -51,6 +51,7 @@ use App\Services\OwnerService;
 use App\Services\ShopService;
 use App\Services\StoreService;
 use App\Services\WarehouseService;
+use App\StationTaskBatch;
 use App\StoreCheckingReceiveItem;
 use App\User;
 use App\Warehouse;
@@ -219,29 +220,8 @@ class TestController extends Controller
 
     function t1(Request $request)
     {
-        {
-            $username = config('database.connections.oracle.username');
-            $password = config('database.connections.oracle.password');
-            $host = config('database.connections.oracle.host');
-            $service_name = config('database.connections.oracle.service_name');
-            $conn = oci_connect($username, $password, $host . '/' . $service_name); //连接oracle数据库
-            $IN_WarehouseID = '';
-            $IN_TraceID = '';
-            $IN_WavenNo = '';
-            $IN_UserID = '';
-            $IN_Language = '';
-            $OUT_Return_Code = '';
-            $sql_sp = "begin SPCUS_EDI_WCS001(:IN_WarehouseID,:IN_Process_Action_C,:IN_Process_By_C,
-        :IN_WaveNO_C,:IN_OrderNO_C,:IN_OrderLineNO_C,:IN_AllocationDetailsID,:IN_Language,:IN_UserID,:OUT_Return_Code); end;";
-            $stmt = oci_parse($conn, $sql_sp);
-            oci_bind_by_name($stmt, ':IN_Warehouse', $IN_WarehouseID);
-            oci_bind_by_name($stmt, ':IN_TraceID', $IN_TraceID);
-            oci_bind_by_name($stmt, ':IN_WavenNo', $IN_WavenNo);
-            oci_bind_by_name($stmt, ':IN_Language', $IN_Language);
-            oci_bind_by_name($stmt, ':IN_UserID', $IN_UserID);
-            oci_bind_by_name($stmt, ':OUT_Return_Code', $OUT_Return_Code);
-            return oci_execute($stmt);
-        }
+        $obj=StationTaskBatch::query()->firstOrCreate(['batch_id'=>1,'station_id'=>1,'station_task_batch_type_id'=>1,'status'=>'未处理']);
+        dd(get_class($obj));
     }
     function packageT(Request $request)
     {

+ 15 - 5
app/Services/BatchService.php

@@ -13,10 +13,16 @@ Class BatchService
     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)
@@ -49,15 +55,19 @@ Class BatchService
     {
         $this->stationTaskBatchService=app('StationTaskBatchService');
         $this->stationRuleBatchService=app('StationRuleBatchService');
+        $this->stationTaskService=app('StationTaskService');
+        $this->stationTaskCommodityService=app('StationTaskCommodityService');
+        $this->stationTaskMaterialBoxService=app('StationTaskMaterialBoxService');
 
         $batches_canProcess = $this->stationRuleBatchService->getBatches_canProcess($batches); //按规则过滤需要的波次
         if($batches_canProcess->isEmpty()) return;
 
-        $stationTaskBatches=$this->stationTaskBatchService->createByBatches($batches); //注册波次任务
-        //注册商品任务
-        //注册料箱任务
-        //注册总任务
-        //执行总任务
+        $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)

+ 17 - 7
app/Services/StationTaskBatchService.php

@@ -7,6 +7,7 @@ namespace App\Services;
 use App\Batch;
 use App\Log;
 use App\Station;
+use App\StationTask;
 use App\StationTaskBatch;
 use App\StationTaskBatchType;
 use Exception;
@@ -23,46 +24,55 @@ class StationTaskBatchService
     private $batchService;
     /** @var StationTypeService $stationTypeService */
     private $stationTypeService;
+    /** @var StationTaskService $stationTaskService */
+    private $stationTaskService;
     public function __construct(){
         $this->stationService=null;
         $this->stationTypeService=null;
         $this->stationTaskBatchTypeService=null;
         $this->batchService=null;
+        $this->stationTaskService=null;
     }
 
     /**
      * @param $batches Batch[]
+     * @param Collection $stationTasks_toAttach
      * @return Collection
      * @throws Exception
      */
-     function createByBatches(array $batches): Collection
+     function createByBatches(array $batches, Collection $stationTasks_toAttach): Collection
     {
         $this->stationService=app('StationService');
         $this->stationTypeService=app('StationTypeService');
         $this->stationTaskBatchTypeService=app('StationTaskBatchTypeService');
         $this->batchService=app('BatchService');
 
-        $stationMissionBatches_toCreate=new Collection();
+        $stationTaskBatches_toCreate=new Collection();
         $id_stationTaskBatchType=$this->stationTaskBatchTypeService->firstByWhere('name','U型线分捡');
 
-        $batches_handled=[];
+        $batches_handled=collect();
         foreach ($batches as $batch){
             if ($batch['status']=='未处理'){
                 $stationType=$this->stationTypeService->getByBatch($batch);
                 $station=$this->stationService->getStation_byType($stationType['name']);
-                $stationMissionBatches_toCreate->push([
+                $stationTaskBatches_toCreate->push([
                     'batch_id'=>$batch['id'],
                     'station_id'=>$station['id'],
                     'station_task_batch_type_id'=> $id_stationTaskBatchType,
                     'status'=>'待处理'
                 ]);
-                $batches_handled[]=$batch;
+                $batches_handled->push($batch);
             }
         }
         $this->batchService->updateWhereIn('id',data_get($batches_handled,'*.id'),['status'=>'处理中']);
-        $this->insert($stationMissionBatches_toCreate->toArray());
+        $this->insert($stationTaskBatches_toCreate->toArray());
+        $this->stationTaskService->registerSubTasks($stationTasks_toAttach,
+            $stationTaskBatches_toCreate->map(function ($stationMissionBatch){
+                return [$stationMissionBatch];
+            })
+        );
 
-        return $stationMissionBatches_toCreate;
+        return $stationTaskBatches_toCreate;
     }
 
     public function insert(array $stationMissionBatches): bool

+ 32 - 0
app/Services/StationTaskChildService.php

@@ -0,0 +1,32 @@
+<?php
+
+
+namespace App\Services;
+
+
+use App\StationTaskBatch;
+use App\StationTaskChild;
+use Illuminate\Support\Facades\Cache;
+
+class StationTaskChildService
+{
+
+    function get(array $whereParams){
+        ksort($whereParams);
+        return Cache::remember('stationTaskChild_'.md5(json_encode($whereParams)), config('cache.expirations.oftenChange'), function ()use($whereParams) {
+            $query = StationTaskChild::query();
+            foreach ($whereParams as $column => $value){
+                if (is_array($value))$query->whereIn($column,$value);
+                else $query->where($column,$value);
+            }
+            return $query->get();
+        });
+    }
+    public function insert(array $stationMissionBatches): bool
+    {
+        $inserted = StationTaskChild::query()->insert($stationMissionBatches);
+        LogService::log(__METHOD__,__FUNCTION__,json_encode($stationMissionBatches).
+            '||'.json_encode(array_slice(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS),0,3)));
+        return $inserted;
+    }
+}

+ 45 - 0
app/Services/StationTaskCommodityService.php

@@ -8,8 +8,53 @@ use Illuminate\Support\Collection;
 
 class StationTaskCommodityService
 {
+    /** @var StationService $stationService */
+    private $stationService;
+    /** @var StationTaskBatchTypeService $stationTaskBatchTypeService */
+    private $stationTaskBatchTypeService;
+    /** @var BatchService $batchService */
+    private $batchService;
+    /** @var StationTypeService $stationTypeService */
+    private $stationTypeService;
+    /** @var StationTaskService $stationTaskService */
+    private $stationTaskService;
+    /** @var StationTaskMaterialBoxService $stationTaskMaterialBoxService */
+    private $stationTaskMaterialBoxService;
+    public function __construct(){
+        $this->stationService=null;
+        $this->stationTypeService=null;
+        $this->stationTaskBatchTypeService=null;
+        $this->batchService=null;
+        $this->stationTaskService=null;
+        $this->stationTaskMaterialBoxService=null;
+    }
+    function get(array $whereParams){
+        ksort($whereParams);
+        return Cache::remember('stationTaskChild_'.md5(json_encode($whereParams)), config('cache.expirations.oftenChange'), function ()use($whereParams) {
+            $query = StationTaskCommodity::query();
+            foreach ($whereParams as $column => $value){
+                if (is_array($value))$query->whereIn($column,$value);
+                else $query->where($column,$value);
+            }
+            return $query->get();
+        });
+    }
     function createByBatches(array $batches): Collection
     {
+        $stationTaskCommodity_toCreate=new Collection();
+        $batches_handled=collect();
 
+        foreach ($batches as $batch){
+            $stationType=$this->stationTypeService->getByBatch($batch);
+            $station=$this->stationService->getStation_byType($stationType['name']);
+//            $materialBox=$this->stationTaskMaterialBoxService->get(['code'=>]);
+//            $stationTaskCommodity_toCreate->push([
+//                'station_id'=>$station['id'],
+//                'station_id'=>$station['id'],
+//                'status'=>'待处理'
+//            ]);
+            $batches_handled->push($batch);
+        }
+        $this->batchService->updateWhereIn('id',data_get($batches_handled,'*.id'),['status'=>'处理中']);
     }
 }

+ 67 - 0
app/Services/StationTaskService.php

@@ -0,0 +1,67 @@
+<?php
+
+
+namespace App\Services;
+
+
+use App\StationTask;
+use App\StationTaskBatch;
+use App\StationTaskChild;
+use App\StationTaskCommodity;
+use App\StationTaskMaterialBox;
+use Illuminate\Support\Collection;
+
+class StationTaskService
+{
+    /** @var StationTaskChildService $stationTaskChildService  */
+    private $stationTaskChildService;
+    public function __construct()
+    {
+        $this->stationTaskChildService=null;
+    }
+
+    function create(int $amountToCreate):Collection
+    {
+
+        $stationTasks=collect();
+        for ($i=0;$i<$amountToCreate;$i++){
+            $stationTasks->push(StationTask::query()->create(['status'=>'待处理']));
+        }
+        return $stationTasks;
+    }
+
+    /**
+     * 丙个列表一一对应,每个task注册一组子任务: [task,task...],[[subTask,subTask],[subTask,subTask]....]
+     * @param Collection $tasks
+     * @param Collection $subTaskLists 二维数组,第一维是对应注册的任务
+     * @return array
+     */
+    function registerSubTasks(Collection $tasks, Collection $subTaskLists): array
+    {
+        $this->stationTaskChildService=app('StationTaskChildService');
+        $taskChildren_toInsert=collect();
+        foreach ($subTaskLists as $i=>$subTaskList){
+            foreach ($subTaskList as $subTask){
+                $tableName=(function()use($subTask){
+                    switch (get_class($subTask)){
+                        case StationTaskBatch::class: return 'station_task_batches';
+                        case StationTaskCommodity::class: return 'station_task_commodities';
+                        case StationTaskMaterialBox::class: return 'station_task_material_boxes';
+                        default:
+                            throw new \Exception('任务类型没有定义相应的模型类');
+                    }
+                })();
+                $paramToInsert = [
+                    'station_task_id' => $tasks[$i]['id'],
+                    'station_task_table_type' => $tableName,
+                    'station_task_table_id' => $subTask['id'],
+                ];
+                $taskChild=$this->stationTaskChildService->get($paramToInsert)->frist();
+                if(!$taskChild)
+                    $taskChildren_toInsert->push($paramToInsert);
+            }
+        }
+        $this->stationTaskChildService->insert($taskChildren_toInsert->toArray());
+    }
+
+}

+ 1 - 1
app/StationTaskBatch.php

@@ -6,5 +6,5 @@ use Illuminate\Database\Eloquent\Model;
 
 class StationTaskBatch extends Model
 {
-    protected $fillable=['batch_id','station_id','station_mission_batch_type_id','status'];
+    protected $fillable=['batch_id','station_id','station_task_batch_type_id','status'];
 }

+ 10 - 0
app/StationTaskChild.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+class StationTaskChild extends Model
+{
+    protected $fillable= ['station_task_id','station_task_table_type','station_task_table_id'];
+}

+ 3 - 1
resources/views/inventory/stockInventory/blindReceive.blade.php

@@ -154,7 +154,9 @@
                                 <td>@{{ goods.produce_date }}</td>
                                 <td>@{{ goods.valid_date }}</td>
                                 <td>@{{ goods.batch_number }}</td>
-                                <td><button class="btn btn-outline-danger btn-sm" @click="removeGoods($event,goods.barcode)">删</button></td>
+                                <td>
+                                    <button class="btn btn-outline-danger btn-sm" @click="removeGoods($event,goods.barcode)">删</button>
+                                </td>
                             </tr>
                         </table>
                         <hr>

+ 3 - 1
resources/views/inventory/stockInventory/inventoryMission.blade.php

@@ -193,7 +193,9 @@
                                     <td>@{{ goods.produce_date }}</td>
                                     <td>@{{ goods.valid_date }}</td>
                                     <td>@{{ goods.batch_number }}</td>
-                                    <td><button class="btn btn-outline-danger btn-sm" @click="removeGoods($event,goods.barcode)">删</button></td>
+                                    <td>
+                                        <button class="btn btn-outline-danger btn-sm" @click="removeGoods($event,goods.barcode)">删</button>
+                                    </td>
                                 </tr>
                             </table>
                             <hr>

+ 3 - 1
resources/views/store/blindReceive/index.blade.php

@@ -105,7 +105,9 @@
                                 <td>@{{ goods.valid_date }}</td>
                                 <td>@{{ goods.batch_number }}</td>
                                 <td>@{{ goods.unique_code }}</td>
-                                <td><button class="btn btn-outline-danger btn-sm" @click="removeGoods($event,goods.barcode)">删</button></td>
+                                <td>
+                                    <button class="btn btn-outline-danger btn-sm" @click="removeGoods($event,goods.barcode)">删</button>
+                                </td>
                             </tr>
                         </table>
                         <hr>

+ 3 - 1
resources/views/store/checkingReceive/show.blade.php

@@ -125,7 +125,9 @@
                     <td>@{{ storeCheckingReceiveItem.invalid_at }}</td>
                     <td>@{{ storeCheckingReceiveItem.batch_code }}</td>
                     <td>@{{ storeCheckingReceiveItem.unique_code }}</td>
-                    <td>@can('入库管理-盘收一体-盘收-编辑')<button @click="destroyItem(storeCheckingReceiveItem,i)" class="btn btn-sm btn-outline-danger">删除</button>@endcan</td>
+                    <td>
+{{--                        @can('入库管理-盘收一体-盘收-编辑')<button @click="destroyItem(storeCheckingReceiveItem,i)" class="btn btn-sm btn-outline-danger">删除</button>@endcan--}}
+                    </td>
                 </tr>
             </table>
         </div>