Browse Source

Merge branch 'LD'

LD 4 years ago
parent
commit
13c2c4dbc3

+ 6 - 5
app/Http/Controllers/StationController.php

@@ -54,12 +54,12 @@ class StationController extends Controller
     }
     public function monitorShow(Station $station)
     {
-        $stationTypeBinMonitor = StationTypeBinMonitor::query()->where("station_id",$station->id)->first();
+//        $stationTypeBinMonitor = StationTypeBinMonitor::query()->where("station_id",$station->id)->first();
         $station->loadMissing([
-            "currentStationTask.stationTaskCommodities.commodity.barcodes",
-            "currentStationTask.stationTaskCommodities.materialBox",
-            "currentStationTask.stationTaskBatches.batch",
-            "currentStationTask.stationTaskMaterialBoxes.materialBox",
+            "stationTasks_today.stationTaskCommodities.commodity.barcodes",
+            "stationTasks_today.stationTaskCommodities.materialBox",
+            "stationTasks_today.stationTaskBatches.batch.owner",
+            "stationTasks_today.stationTaskMaterialBoxes.materialBox",
             "stationTypeBinMonitor",
         ]);
         if (!$station['stationTypeBinMonitor']){
@@ -71,6 +71,7 @@ class StationController extends Controller
             ]);
             $station->load("stationTypeBinMonitor");
         }
+//        dd(data_get($station['stationTasks_today'],'*.id'),data_get($station['stationTasks_today'],'*.status'));
         return view('station.monitor.show',compact('station'));
     }
 

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

@@ -491,8 +491,7 @@ class TestController extends Controller
     public function ld()
     {
         dd(
-            json_encode(collect(collect(collect([City::query()->first()]))))
-
+            Carbon::now()->format('Y-m-d')
         );
     }
 

+ 4 - 4
app/Http/Controllers/ForeignHaiRoboticsController.php → app/Http/Controllers/api/thirdPart/haiq/HaiRoboticsController.php

@@ -1,23 +1,23 @@
 <?php
 
 
-namespace App\Http\Controllers;
+namespace App\Http\Controllers\api\thirdPart\haiq;
 
 
 use App\Services\StationTaskBatchService;
 use App\StationTaskBatch;
 use Illuminate\Http\Request;
 use App\Traits\TestableInstant;
-class ForeignHaiRoboticsController
+class HaiRoboticsController
 {
     use TestableInstant;
 
     /** @var StationTaskBatchService $stationTaskBatchService */
     private $stationTaskBatchService=null;
 
-    function runBatch(Request $request){
+    function runTaskBatch(Request $request){
         $request->validate(
-            ['id'=>'required|exists:station_task_batches,id']
+            ['station_task_batch_id'=>'required|exists:station_task_batches,id']
         );
         $batchTask=StationTaskBatch::query()->first($request['id']);
         $batchesFailed=$this->stationTaskBatchService->runMany(collect([$batchTask]));//执行波次任务

+ 3 - 3
app/Services/StationRuleBatchService.php

@@ -61,9 +61,9 @@ class StationRuleBatchService
     {
         LogService::log(__METHOD__,'shouldProcess','波次任务分配1.1:'.json_encode($batches));
         $batches_toProcess=collect();
-        $batches_inTask=StationTaskBatch::query()->whereIn('batch_id',data_get($batches,'*.id'))->get();
-        LogService::log(__METHOD__,'shouldProcess','波次任务分配1.2:'.json_encode($batches_inTask));
-        $batches=$batches->whereNotIn('id',data_get($batches_inTask,'*.id')??[]);
+        $stationTaskBatches_inTask=StationTaskBatch::query()->whereIn('batch_id',data_get($batches,'*.id'))->get();
+        LogService::log(__METHOD__,'shouldProcess','波次任务分配1.2:'.json_encode($stationTaskBatches_inTask));
+        $batches=$batches->whereNotIn('id',data_get($stationTaskBatches_inTask,'*.batch_id')??[]);
         foreach ($batches as $batch){
             $stationRuleBatch=$this->getByBatch($batch);
             if(!$stationRuleBatch)continue;

+ 8 - 0
app/Station.php

@@ -3,6 +3,7 @@
 namespace App;
 
 use App\Traits\ModelTimeFormat;
+use Carbon\Carbon;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\Eloquent\Relations\HasOne;
 use App\Traits\ModelLogChanging;
@@ -27,6 +28,13 @@ class Station extends Model
         return $this->hasOne(StationTask::class)
             ->where('status','=','处理中');
     }
+    public function stationTasks_today(){
+        return $this->hasMany(StationTask::class)
+            ->where('created_at','>=',now()->format('Y-m-d'))
+            ->orderBy('status')
+            ->orderByDesc('id')
+            ;
+    }
     public function stationTypeBinMonitor(){
         return $this->hasOne(StationTypeBinMonitor::class);
     }

+ 1 - 1
config/haiRou.php

@@ -1,5 +1,5 @@
 <?php
 
 return [
-    "波次防重叠时间_秒" => 1200,
+    "波次防重叠时间_秒" => 1800,
 ];

+ 101 - 19
resources/views/station/monitor/show.blade.php

@@ -26,19 +26,61 @@
                     <div class="col-4">
                         <div class="row">
                             <div class="col py-3 h4">
-                                <div>波次号:</div>
-                                <div class=" text-center">
-                                    <b v-if="task&&task.station_task_batches">
-                                        <div v-for="taskBatch in task.station_task_batches">
-                                            @{{ taskBatch.batch.code }}
+                                <div class="row">
+                                    <div class="col">选择执行波次:</div>
+                                </div>
+                                <div class="row" v-if="current_stationTaskBatch">
+                                    <div class="col font-weight-bold text-center position-relative"
+                                         :style="[
+                                                    {opacity:
+                                                        current_stationTaskBatch.status==='完成'?'0.5':'1'
+                                                    },
+                                                ]"
+                                         :class="[
+                                            (current_stationTaskBatch.runningStatus==='')?'text-info':'',
+                                            (current_stationTaskBatch.runningStatus==='请求中')?'text-dark':'',
+                                            (current_stationTaskBatch.runningStatus==='请求失败')?'text-danger':'',
+                                            (current_stationTaskBatch.runningStatus==='请求成功')?'text-success':'',
+                                            (current_stationTaskBatch.runningStatus==='请求异常')?'text-danger':'',
+                                         ]"
+                                    >
+                                        <div class="text-center mt-2">@{{ current_stationTaskBatch.batch.code }}</div>
+                                        <div class="text-center" style="font-size: 12px;">
+                                            @{{ current_stationTaskBatch.batch.owner.name }}
                                         </div>
-                                    </b>
+                                    </div>
+                                    <div class="col">
+                                        <button class="btn btn-info btn-lg mt-4" @click="runTheTaskBatch(current_stationTaskBatch)">
+                                            <span v-if="!current_stationTaskBatch.runningStatus">执行</span>
+                                            <span v-if="current_stationTaskBatch.runningStatus==='请求中'">请求中</span>
+                                            <span v-if="current_stationTaskBatch.runningStatus==='请求失败'">(失败)重新执行</span>
+                                            <span v-if="current_stationTaskBatch.runningStatus==='请求成功'">(请求成功)重新执行</span>
+                                            <span v-if="current_stationTaskBatch.runningStatus==='请求异常'">(请求异常)重新执行</span>
+                                        </button>
+                                    </div>
+                                </div>
+                                <div class="row">
+                                    <div class="col text-muted text-left">
+                                        <img id="barcode" :alt="batchCode">
+                                    </div>
+                                </div>
+                                <div class="text-center my-2" style="overflow-y: scroll;max-height:200px;">
+                                    <div class="flex flex-column flex-wrap" v-if="stationTaskBatches">
+                                        <button v-for="stationTaskBatch in stationTaskBatches"
+                                                @click="current_stationTaskBatch=stationTaskBatch"
+                                                class="btn"
+                                                :class="[
+                                                    (current_stationTaskBatch&&current_stationTaskBatch.id===stationTaskBatch.id)?'btn-outline-info':'btn-outline-dark',
+                                                ]"
+                                                :style="[
+                                                    {opacity:
+                                                        stationTaskBatch.status==='完成'?'0.5':'1'
+                                                    },
+                                                ]"
+                                        >
+                                            @{{stationTaskBatch.batch.code | simplifyBatchCode}}</button>
+                                    </div>
                                 </div>
-                            </div>
-                        </div>
-                        <div class="row">
-                            <div class="col py-3 text-muted text-center">
-                                <img id="barcode" alt="" :data-refresh="batchCode">
                             </div>
                         </div>
                         <div class="row">
@@ -157,7 +199,7 @@
                                 <div class="text-left">
                                     <div >
                                         <div class="btn btn-outline-info" @click="
-                                        (inputs.manuallyTakeBox.visible=true)
+                                        (inputs.manuallyTakeBox.visible=!inputs.manuallyTakeBox.visible)
                                         &&(inputs.manuallyTakeBox.text='')">手动出库</div>
                                         <div class="position-relative bg-white" v-if="inputs.manuallyTakeBox.visible">
                                 <textarea  name="" id="" cols="30" rows="3" class="form-control" v-model="inputs.manuallyTakeBox.text"
@@ -296,6 +338,7 @@
                         text:'',
                     }
                 },
+                current_stationTaskBatch: null,
                 grids:{
                     single:{status:'',},
                     half:{
@@ -351,24 +394,57 @@
                         this.inputs.manuallyTakeBox.text='';
                     })
                 },
+                runTheTaskBatch(stationTaskBatch){
+                    stationTaskBatch.runningStatus='请求中'
+                    axios.post('{{url('/api/thirdPart/haiq/runTaskBatch')}}',{station_task_batch_id:stationTaskBatch.id})
+                        .then(function(response){
+                            if(!response.data.success){
+                                stationTaskBatch.runningStatus='请求失败';
+                                return;
+                            }
+                            stationTaskBatch.runningStatus='请求成功'
+                        }).catch(function(err){
+                        stationTaskBatch.runningStatus='请求异常'
+                        tempTip.okWindow(err,'确定')
+                    })
+                },
             },
             computed:{
                 task(){
                     if(!this.station['current_station_task'])return null;
                     return this.station['current_station_task'];
                 },
+                stationTasks(){
+                    if(!this.station)return;
+                    return this.station.station_tasks_today;
+                },
+                stationTaskBatches(){
+                    if(!this.stationTasks)return;
+                    let stationTaskBatches=[];
+                    let stationTaskBatch_index=[];
+                    this.stationTasks.forEach(function(stationTask){
+                        if(!stationTask.station_task_batches)return;
+                        stationTask.station_task_batches.forEach(function(stationTaskBatch){
+                            if(typeof(stationTaskBatch_index['_'+stationTaskBatch.batch_id])==='undefined'){
+                                // if(stationTaskBatch_index['_'+stationTaskBatch.batch_id]['status']==='完成')return;
+                                stationTaskBatches.push(stationTaskBatch)
+                            }
+                            stationTaskBatch_index['_'+stationTaskBatch.batch_id]=stationTaskBatch;
+                        })
+                    });
+                    return stationTaskBatches;
+                },
                 batchCode(){
-                    if(!this.task)return;
-                    let batches = this.task.station_task_batches;
-                    if(batches
-                        && Array.isArray(batches)
-                        && batches.length>0
+                    let _this=this;
+                    if(!this.current_stationTaskBatch)return;
+                    if(typeof(this.current_stationTaskBatch)!=='undefined'
+                        && typeof(this.current_stationTaskBatch.batch)!=='undefined'
                     ){
                         setTimeout(function (){
-                            setBarcode(batches[0].batch.code,"#barcode",1,50,false);
+                            setBarcode(_this.current_stationTaskBatch.batch.code,"#barcode",1,50,false);
                         })
                     }
-                    return batches[0].batch.code;
+                    return this.current_stationTaskBatch.batch.code;
                 },
                 taskCommodities(){
                     if(!this.task)return [];
@@ -556,6 +632,12 @@
                     }
 
                 },
+            },
+            filters:{
+                simplifyBatchCode(val){
+                    if(!val){return ''}
+                    return val.replace(/W\d{6}0*/,'').trim()
+                }
             }
         });
     </script>

+ 3 - 0
routes/api/thirdPart/haiq.php

@@ -27,3 +27,6 @@ Route::group(['prefix'=>'pickStation'],function(){
 Route::group(['prefix'=>'light'],function(){
     Route::post('update', "LightController@update");//移库
 });
+
+
+Route::post('runTaskBatch', "HaiRoboticsController@runTaskBatch");//启动taskBatch任务