ソースを参照

料箱调度优先级
料箱分布可视化

Zhouzhendong 4 年 前
コミット
d632bbad40

+ 0 - 78
app/Http/Controllers/StationController.php

@@ -9,15 +9,6 @@ use Illuminate\Http\Request;
 
 class StationController extends Controller
 {
-    /**
-     * Display a listing of the resource.
-     *
-     * @return void
-     */
-    public function index()
-    {
-
-    }
     public function monitorIndex()
     {
         $stations = Station::query()->with('stationType:name','parent:name')->whereHas('stationType',function($query){
@@ -27,34 +18,8 @@ class StationController extends Controller
         return view('station.monitor.index',compact('stations'));
     }
 
-    /**
-     * Show the form for creating a new resource.
-     *
-     * @return \Illuminate\Http\Response
-     */
-    public function create()
-    {
-        //
-    }
-
-    /**
-     * Store a newly created resource in storage.
-     *
-     * @param  \Illuminate\Http\Request  $request
-     * @return \Illuminate\Http\Response
-     */
-    public function store(Request $request)
-    {
-        //
-    }
-
-    public function show(Station $station)
-    {
-        //
-    }
     public function monitorShow(Station $station)
     {
-//        $stationTypeBinMonitor = StationTypeBinMonitor::query()->where("station_id",$station->id)->first();
         $station->loadMissing([
             "stationTasks_today.stationTaskCommodities.commodity.barcodes",
             "stationTasks_today.stationTaskCommodities.stationTaskMaterialBox",
@@ -71,50 +36,7 @@ class StationController extends Controller
             ]);
             $station->load("stationTypeBinMonitor");
         }
-//        dd(
-//            data_get($station['stationTasks_today'],'*.id')
-//            ,data_get($station['stationTasks_today'],'*.stationTaskBatches.*.batch.code')
-//            ,data_get($station['stationTasks_today'],'*.stationTaskBatches.*.id')
-//            ,data_get($station['stationTasks_today'],'*.stationTaskBatches.*.batch.id')
-//            ,data_get(data_get($station['stationTasks_today'],'*.stationTaskCommodities')[7],'*.id')
-//            ,data_get(data_get($station['stationTasks_today'],'*.stationTaskCommodities')[9],'*.id')
-//        );
-//        $station=$station->toJson();
         return view('station.monitor.show',compact('station'));
     }
 
-    /**
-     * Show the form for editing the specified resource.
-     *
-     * @param  \App\Station  $station
-     * @return \Illuminate\Http\Response
-     */
-    public function edit(Station $station)
-    {
-        //
-    }
-
-    /**
-     * Update the specified resource in storage.
-     *
-     * @param  \Illuminate\Http\Request  $request
-     * @param  \App\Station  $station
-     * @return \Illuminate\Http\Response
-     */
-    public function update(Request $request, Station $station)
-    {
-        //
-    }
-
-    /**
-     * Remove the specified resource from storage.
-     *
-     * @param  \App\Station  $station
-     * @return \Illuminate\Http\Response
-     */
-    public function destroy(Station $station)
-    {
-        //
-    }
-
 }

+ 1 - 4
app/Http/Controllers/TestController.php

@@ -149,10 +149,7 @@ class TestController extends Controller
     }
     public function test()
     {
-        DB::connection("mysql_haiRobotics")->table("ks_bin")->where("ks_bin_code","IDE0000563")->update([
-            "ks_bin_space_code" => null,"ks_bin_space_id"=>null,"orig_ks_bin_space_code"=>null,"orig_ks_bin_space_id"=>null,
-            "status"=>4,
-        ]);
+       return view("station.monitor.visual");
     }
     public function orderCreateBill()
     {

+ 6 - 22
app/Services/BatchService.php

@@ -75,28 +75,16 @@ class BatchService
             $this->instant($this->stationTaskCommodityService,'StationTaskCommodityService');
             $this->instant($this->stationTaskMaterialBoxService,'StationTaskMaterialBoxService');
 
-            $stationTaskBatches=null;
             $stationTasks=null;
-            app('LogService')->log('海柔','assignTasks2',json_encode($batches));
             $batches_shouldProcess = $this->stationRuleBatchService->getBatches_shouldProcess($batches); //按规则过滤需要的波次
             if($batches_shouldProcess->isEmpty()) return;
-//            $stationTaskMaterialBoxes_occupied = $this->stationTaskMaterialBoxService->getOccupied_byBatches($batches_shouldProcess); //过滤料箱被占用的波次
-//            app('LogService')->log('海柔','assignTasks2.5',json_encode($stationTaskMaterialBoxes_occupied));
-//            if($stationTaskMaterialBoxes_occupied->isNotEmpty()) {
-//                foreach ($batches_shouldProcess as $batch){
-//                    Cache::tags(['波次防重叠'.$batch['id']])->flush();
-//                }
-//                BatchTaskJob::dispatch($batches_shouldProcess)
-//                    ->delay(now()->addMinutes(1));    //因为料箱被占用了,所以将任务推迟1分钟后尝试
-//                return;
-//            }
+
             app('LogService')->log('海柔','assignTasks3',json_encode($batches_shouldProcess));
-            DB::transaction(function ()use($batches,&$stationTaskBatches,&$batches_shouldProcess,&$stationTasks){
+            DB::transaction(function ()use($batches,&$batches_shouldProcess,&$stationTasks){
                 $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); //注册商品任务
-                app('LogService')->log('海柔','assignTasks4',json_encode($batches_shouldProcess));
+                $this->stationTaskBatchService->createByBatches($batches_shouldProcess,$stationTasks); //注册波次任务
+                $this->stationTaskMaterialBoxService->createByBatches($batches_shouldProcess,$stationTasks); //注册料箱任务
+                $this->stationTaskCommodityService->createByBatches($batches_shouldProcess,$stationTasks); //注册商品任务
             });
             foreach ($stationTasks as &$stationTask){
                 $stationTask->loadMissing([
@@ -106,19 +94,15 @@ class BatchService
                     "stationTaskMaterialBoxes.materialBox",
                 ]);
             }
-            app('LogService')->log('海柔','assignTasks5',json_encode($stationTasks,true).json_encode($batches_shouldProcess));
             $jsonStationTasks=json_encode($stationTasks,true);
             broadcast(new BroadcastToStation(BroadcastToStation::ALL_STATION, $jsonStationTasks));
-            app('LogService')->log('海柔','assignTasks6',$jsonStationTasks.json_encode($batches_shouldProcess));
-//            $ran=$this->stationTaskBatchService->runMany($stationTaskBatches);//执行波次任务
         }catch(Exception $e){
-            app('LogService')->log('海柔','assignTasks7',json_encode($batches));
             $batchesJson='';
             foreach ($batches as $batch){
                 $batchesJson.=json_encode($batch);
                 Cache::tags(['波次防重叠'.$batch['id']])->flush();
             }
-            app('LogService')->log('海柔','assignTasks8',json_encode($batches));
+            app('LogService')->log('海柔','注册任务失败',$e->getMessage()." | ".json_encode($batches));
             throw new ErrorException('注册任务失败: '. $batchesJson . $e->getMessage().json_encode($e->getTrace()));
         }
     }

+ 0 - 14
app/Services/ForeignHaiRoboticsService.php

@@ -409,20 +409,6 @@ class ForeignHaiRoboticsService
         return true;
     }
 
-//    public function markHasPut($taskCode,$binCode):bool{
-//        try{
-//            //标记料箱进入位置
-////            $taskMaterialBoxesService->markDone();//
-//        }catch (\Exception $e){
-//            switch ($e->getCode()){
-//                case 'taskBinNotMatch';
-//                case 'taskGetFailed';
-//            }
-//        }
-//
-//    }
-
-
     public function excepted($taskCode='',$binCode='', $msg=''):bool{
         try{
             throw new ErrorException(

+ 1 - 0
app/Services/OrderCommodityService.php

@@ -31,6 +31,7 @@ class OrderCommodityService
         }
     }
 
+    //暂时无意义,直到下个版本前仍未被引用则删除
     public function correctLocation_fromWMS($orderCommodities){
         $orderCommodities->loadMissing('order.batch');
         $details=OracleActAllocationDetails::query()

+ 18 - 42
app/Services/StationTaskBatchService.php

@@ -136,79 +136,55 @@ class StationTaskBatchService
     {
         LogService::log(__METHOD__,'runMany','波次任务分配6.1:'.json_encode($stationTaskBatches));
         $stationTaskBatches_failed = null;
-        ($execute =
-            function (
-                Collection $stationTaskBatches, &$stationTaskBatches_failed) {
-                LogService::log(__METHOD__,'runMany','波次任务分配6.2:'.json_encode($stationTaskBatches));
-                if ($stationTaskBatches->isEmpty()) return;
-                LogService::log(__METHOD__,'runMany','波次任务分配6.3:'.json_encode($stationTaskBatches));
+        ($execute = function(Collection $stationTaskBatches, &$stationTaskBatches_failed){
+                if ($stationTaskBatches->isEmpty()) return; //波次任务不存在 跳出
                 $stationTaskBatches_failed = collect();
-                LogService::log(__METHOD__,'runMany','波次任务分配6.4:'.json_encode($stationTaskBatches));
                 foreach ($stationTaskBatches as $stationTaskBatch) {
-                LogService::log(__METHOD__,'runMany','波次任务分配6.5:'.json_encode($stationTaskBatches));
-                    $failed = !$this->run($stationTaskBatch);
-                LogService::log(__METHOD__,'runMany','波次任务分配6.6:'.json_encode($stationTaskBatches));
-                    if ($failed) $stationTaskBatches_failed->push($stationTaskBatch);
+                    $failed = !$this->run($stationTaskBatch); //运行波次 获取执行结果
+                    if ($failed) $stationTaskBatches_failed->push($stationTaskBatch);//执行失败  记录失败波次
                 }
-            })($stationTaskBatches, $stationTaskBatches_failed);
+        })($stationTaskBatches, $stationTaskBatches_failed);
 
-        ($logAtFailings_andWait =
-            function ($stationTaskBatches_failed) {
-                LogService::log(__METHOD__,'runMany','波次任务分配6.7:'.json_encode($stationTaskBatches_failed));
+        (function ($stationTaskBatches_failed) {
                 if ($stationTaskBatches_failed->isEmpty()) return;
-                LogService::log(__METHOD__,'runMany','波次任务分配6.8:'.json_encode($stationTaskBatches_failed));
                 $retry_after_sec = config('task.batchTask.retry_after_sec');
                 LogService::log(__METHOD__, __FUNCTION__,
                     '任务波次没有执行完的,' . $retry_after_sec . '秒后准备重试:' . $stationTaskBatches_failed->toJson()
                     . '调用堆栈r:' . json_encode(array_slice(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), 0, 3))
                 );
-                LogService::log(__METHOD__,'runMany','波次任务分配6.9:'.json_encode($stationTaskBatches_failed));
                 sleep($retry_after_sec);
-                LogService::log(__METHOD__,'runMany','波次任务分配6.91:'.json_encode($stationTaskBatches_failed));
             })($stationTaskBatches_failed);
-                LogService::log(__METHOD__,'runMany','波次任务分配6.92:'.json_encode($stationTaskBatches));
-
-        $execute                    ($stationTaskBatches_failed, $stationTaskBatches_failed); //再次尝试
-                LogService::log(__METHOD__,'runMany','波次任务分配6.93:'.json_encode($stationTaskBatches));
-        $this->markManyExcepted  ($stationTaskBatches_failed);
-                LogService::log(__METHOD__,'runMany','波次任务分配6.94:'.json_encode($stationTaskBatches));
-        return                      $stationTaskBatches_failed;
+        $execute($stationTaskBatches_failed, $stationTaskBatches_failed); //再次尝试
+        $this->markManyExcepted($stationTaskBatches_failed);
+        return  $stationTaskBatches_failed;
     }
 
     function run(StationTaskBatch $stationTaskBatch): bool
     {
-        LogService::log(__METHOD__,'runMany','波次任务分配6.r1:'.json_encode($stationTaskBatch));
         $this->instant($this->foreignHaiRoboticsService,'ForeignHaiRoboticsService');
         $this->instant($this->stationService,'StationService');
         $stationTaskBatch->loadMissing(['station','stationTask.stationTaskMaterialBoxes']);
         LogService::log(__METHOD__,'runMany','波次任务分配6.r2:'.json_encode($stationTaskBatch));
-        $toLocation         = $this->stationService->getULineEntrance($stationTaskBatch['station'])['code'];
-        LogService::log(__METHOD__,'runMany','波次任务分配6.r3:'.json_encode($stationTaskBatch));
-        $groupPrefix        = $stationTaskBatch['id'];
+        $toLocation         = $this->stationService->getULineEntrance($stationTaskBatch['station'])['code'];//获取放线入口
+        $groupPrefix        = $stationTaskBatch['id'];//将波次任务ID当作组前缀
         $taskMaterialBoxes  = $stationTaskBatch['stationTask']['stationTaskMaterialBoxes'] ??
             (function () use ($stationTaskBatch) {
                 LogService::log(__METHOD__,'runMany','波次任务分配6.r4:'.json_encode($stationTaskBatch));
                 throw new Exception('找不到料箱:' . json_encode($stationTaskBatch));
-            })();
+            })();//存在任务返回任务 否则抛出无料箱异常
         try{
-            LogService::log(__METHOD__,'runMany','波次任务分配6.r5:'.json_encode($stationTaskBatch));
-            $isFetchedFromRobotics
-                = $this->foreignHaiRoboticsService->
-            fetchGroup($toLocation, $taskMaterialBoxes, $groupPrefix);
+            $isFetchedFromRobotics = $this->foreignHaiRoboticsService->
+                    fetchGroup($toLocation, $taskMaterialBoxes, $groupPrefix);//执行料箱任务
             LogService::log(__METHOD__,'runMany','波次任务分配6.r6:'.json_encode($stationTaskBatch));
         }catch(Exception $e){
             throw new ErrorException('$stationTaskBatch运行波次机器人任务失败,获取组失败: '.$stationTaskBatch->toJson() . $e->getMessage());
         }
-        LogService::log(__METHOD__,'runMany','波次任务分配6.r7:'.json_encode($stationTaskBatch));
-        ($markNewStatus
-            =function()use($isFetchedFromRobotics,$stationTaskBatch){
+        (function()use($isFetchedFromRobotics,$stationTaskBatch){
             $isFetchedFromRobotics?
-                $this->markProcessing($stationTaskBatch):
-                $this->markExcepted($stationTaskBatch);
-            LogService::log(__METHOD__,'runMany','波次任务分配6.r8:'.json_encode($stationTaskBatch));
+                $this->markProcessing($stationTaskBatch)://执行成功标记已处理
+                $this->markExcepted($stationTaskBatch);//执行失败标记失败
         })();
-        LogService::log(__METHOD__,'runMany','波次任务分配6.r9:'.json_encode($stationTaskBatch));
-        return $isFetchedFromRobotics;
+        return $isFetchedFromRobotics;//返回执行结果
     }
 
     function markProcessing($stationTaskBatch_orCollection)

+ 4 - 3
app/Services/StationTaskMaterialBoxService.php

@@ -109,13 +109,14 @@ class StationTaskMaterialBoxService
         $this->instant($this->orderCommodityService,'OrderCommodityService');
         $stationMaterialBoxes_toCreate=new Collection();
         $order_ids=data_get($batch['orders'],'*.id');
-        $orderCommodities=OrderCommodity::query()->with('orderBin')->whereIn('order_id',$order_ids)->get();
-        $orderCommodities=$this->orderCommodityService->correctLocation_fromWMS($orderCommodities);
+        $orderCommodities=OrderCommodity::query()->orderByRaw("commodity_id,amount")//同商品多条 数量最小优先
+            ->with('orderBin')->whereIn('order_id',$order_ids)->get();
+        //$orderCommodities=$this->orderCommodityService->correctLocation_fromWMS($orderCommodities);
         if($orderCommodities->isEmpty())return $stationMaterialBoxes_toCreate;
         $stationType=$this->stationTypeService->getForMaterialBox_onBatchProcess();
         $stationTaskBatch=$this->stationTaskBatchService->get(['batch_id'=>$batch['id']])->first();
         $materialBoxIds_used=[];
-        $orderCommodities=$orderCommodities->sortBy('commodity_id');//按商品排序后,出货可以同商品挨在一起
+        //$orderCommodities=$orderCommodities->sortBy('commodity_id');//按商品排序后,出货可以同商品挨在一起
         foreach ($orderCommodities as $orderCommodity){
             $station=$this->stationService->getStation_byType($stationType['name']);
             $materialBox=$this->materialBoxService->firstOrCreate(['code' => $orderCommodity['location']]);

+ 1 - 1
resources/views/order/index/delivering.blade.php

@@ -387,7 +387,7 @@
             methods:{
                 initData(){
                     this.orders.forEach((order)=>{
-                        if (order.c_contact.length>50 && order.c_contact.substring(0,3)==='~Ag')order.is_encryption = true;
+                        if (order.c_contact && order.c_contact.length>50 && order.c_contact.substring(0,3)==='~Ag')order.is_encryption = true;
                     });
                 },
                 getQueryVariable(variable){

+ 57 - 0
resources/views/station/monitor/visual.blade.php

@@ -0,0 +1,57 @@
+@extends('layouts.app')
+@section('title')料箱分布 - 监视器@endsection
+
+@section('content')
+    <div class="container-fluid d-none" id="container">
+        <div class="row bg-dark">
+            <div class="col-6 row mt-2 mb-2" v-for="(arr,i) in data">
+                <div class="offset-1 col-10 row">
+                    <div style="width: 12.5%" v-for="(val,j) in arr">
+                        <div class="progress mr-2" v-if="val===undefined">
+                            <div class="w-100 text-center d-inline-block"><i class="fa fa-spinner fa-pulse"></i></div>
+                        </div>
+                        <div class="progress mr-2" style="cursor: pointer" v-else>
+                            <div class="progress-bar bg-danger" :style="{width:(100-val)+'%'}">@{{(100-val)+'%'}}</div>
+                            <div class="progress-bar bg-success" :style="{width:val+'%'}">@{{ val+'%' }}</div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+@endsection
+
+@section('lastScript')
+    <script>
+        new Vue({
+            el:"#container",
+            data:{
+                rowSize:8, //单排大小:X列
+                columnSize:4,//单列大小 X竖
+                heightSize:10,//高度大小 X行
+                maxLoadSize:18,//最大加载大小 X排
+                data:[],//数据池
+                prefix:"HAI",
+            },
+            mounted() {
+                let data = [];
+                for (let i=this.maxLoadSize;i>0;i--){
+                    let arr = [];
+                    for (let j=0;j<this.rowSize;j++){
+                        arr.push(undefined);
+                    }
+                    data.push(arr);
+                    loadData
+                }
+                this.data = data;
+                $("#container").removeClass("d-none");
+            },
+            methods:{
+                loadData(row){
+                    let size = this.rowSize*this.columnSize;
+                    if (row%2!==0)size *= 2;
+                },
+            }
+        });
+    </script>
+@endsection