ajun 5 vuotta sitten
vanhempi
commit
c2f1f25733

+ 85 - 0
app/Http/Controllers/StationCacheShelfGridController.php

@@ -0,0 +1,85 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\StationCacheShelfGrid;
+use Illuminate\Http\Request;
+
+class StationCacheShelfGridController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index()
+    {
+        //
+    }
+
+    /**
+     * 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)
+    {
+        //
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  \App\StationCacheShelfGrid  $stationCacheShelfGrid
+     * @return \Illuminate\Http\Response
+     */
+    public function show(StationCacheShelfGrid $stationCacheShelfGrid)
+    {
+        //
+    }
+
+    /**
+     * Show the form for editing the specified resource.
+     *
+     * @param  \App\StationCacheShelfGrid  $stationCacheShelfGrid
+     * @return \Illuminate\Http\Response
+     */
+    public function edit(StationCacheShelfGrid $stationCacheShelfGrid)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \App\StationCacheShelfGrid  $stationCacheShelfGrid
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, StationCacheShelfGrid $stationCacheShelfGrid)
+    {
+        //
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\StationCacheShelfGrid  $stationCacheShelfGrid
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(StationCacheShelfGrid $stationCacheShelfGrid)
+    {
+        //
+    }
+}

+ 3 - 1
app/Providers/AppServiceProvider.php

@@ -101,6 +101,7 @@ use App\Services\UserWorkgroupService;
 use App\Services\DeliveryAppointment;
 use App\Services\DischargeTaskService;
 use App\Services\DeliveryAppointmentService;
+use App\Services\StationCacheShelfGridService;
 use Illuminate\Queue\Events\JobFailed;
 use Illuminate\Support\Facades\Queue;
 use Illuminate\Support\Facades\Schema;
@@ -156,6 +157,7 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('BatchService',BatchService::class);
         app()->singleton('BatchUpdateService', BatchUpdateService::class);
         app()->singleton('CacheService',CacheService::class);
+        app()->singleton('CacheShelfService',CacheShelfService::class);
         app()->singleton('CheckActiveMenuService',CheckActiveMenuService::class);
         app()->singleton('CommodityBarcodeService',CommodityBarcodeService::class);
         app()->singleton('CommodityService', CommodityService::class);
@@ -227,6 +229,7 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('RejectedBillService',RejectedBillService::class);
         app()->singleton('RejectedService',RejectedService::class);
         app()->singleton('ShopService',ShopService::class);
+        app()->singleton('StationCacheShelfGridService',StationCacheShelfGridService::class);
         app()->singleton('StationRuleBatchService',StationRuleBatchService::class);
         app()->singleton('StationService',StationService::class);
         app()->singleton('StationTaskBatchService',StationTaskBatchService::class);
@@ -249,7 +252,6 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('WarehouseService',WarehouseService::class);
         app()->singleton('WaybillFinancialService',WaybillFinancialService::class);
         app()->singleton('WeighExceptedService',WeighExceptedService::class);
-        app()->singleton('CacheShelfService',CacheShelfService::class);
     }
 
 

+ 52 - 25
app/Services/CacheShelfService.php

@@ -2,8 +2,11 @@
 
 namespace App\Services;
 
+use App\Exceptions\ErrorException;
 use App\MaterialBox;
 use App\Station;
+use App\StationCacheShelfGrid;
+use App\StationTaskMaterialBox;
 use App\Traits\ServiceAppAop;
 use Illuminate\Support\Facades\Http;
 
@@ -18,13 +21,17 @@ class CacheShelfService
      * @param MaterialBox $materialBox
      * @param $pointX
      * @param $pointY
+     * @return string
+     * @throws ErrorException
      */
     public function pushTask(Station $station,MaterialBox $materialBox,$pointX, $pointY)
     {
-        $locCode = 'HAI'.$station['code'].'-0'.$pointX.'-0'.$pointY;
-        $data = [
-            ''
-        ];
+        /** 推送任务 */
+        if($this->putBinToStore($station,$materialBox)){
+            /** 亮灯 */
+            return $this->lightOn($station,$pointX, $pointY);
+        }
+        else return false;
     }
 
     /**
@@ -33,43 +40,63 @@ class CacheShelfService
      */
     public function getTasks(Station $station)
     {
-
+        $grids = StationCacheShelfGrid::query()->with('materialBox:code')->where('station_id',$station['id'])->where('status',2)->orderBy('grid_id')->get();
+        $station->setRelation('grids',$grids);
     }
 
-    /** 缓存架  【亮灯】
-     * @param $post
+    /**
+     * 缓存架  【亮灯】
+     * @param Station $station
+     * @param $pointX
+     * @param $pointY
      * @return string
      */
-    public function lightOn($post): string
+    public function lightOn(Station $station,$pointX,$pointY): string
     {
-        $response = Http::post(config('api.haiq.storage.light'),$post);
+        $locCode = 'HAI'.$station['code'].'-0'.$pointX.'-0'.$pointY;
+        $params = [
+            "areaCode"=> "1004",
+            "PTLAction"=> 1, //1是开,0是关
+            "PTLSettings"=> [
+                "color"=> 1,
+                "frequency"=> 1
+            ],
+            "displayInfo"=> [
+                "detail01"=> "detail01",
+                "detail02"=> "detail02",
+                "detail03"=> "detail03",
+                "qrCode"=> "qrCode",
+                "qty00"=> "11",
+                "qty01"=> 1,
+                "qty02"=> 2,
+                "title"=> "title",
+                "uomDesc01"=> "uo",
+                "uomDesc02"=> "uo"
+            ],
+            "locCode"=> $locCode//灯条口,B1\B2=设备编号,中间号码代表从右往左数的列,右边号码时从下往上数
+        ];
+        $response = Http::post(config('api.haiq.storage.light'),$params);
         return $response->body();
     }
 
     /**
      * 推送到海柔的任务
+     * @param Station $station
+     * @param MaterialBox $materialBox
+     * @return bool
+     * @throws ErrorException
      */
-    public function putBinToStore()
+    public function putBinToStore(Station $station,MaterialBox $materialBox): bool
     {
+        $stationTaskMaterialBox = new StationTaskMaterialBox();
+        $stationTaskMaterialBox->setRelation('station',$station);
+        $stationTaskMaterialBox->setRelation('materialBox',$materialBox);
+
         /** @var ForeignHaiRoboticsService $foreignHaiRoboticsService */
         $foreignHaiRoboticsService = app(ForeignHaiRoboticsService::class);
-        $foreignHaiRoboticsService->putBinToStore_fromCacheShelf();
+        return $foreignHaiRoboticsService->putBinToStore_fromCacheShelf($stationTaskMaterialBox);
     }
 
 
-    public function relocate($post){
-        $response = Http::post(config('api.haiq.storage.moveBin'),$post);
-        if (!$response->ok()){
-            return ['success'=>false,"data"=>$response->body()];
-        }
-        if (($response["code"] ?? false) && $response["code"] != 200){
-            return ['success'=>false,"data"=>$response["errMsg"]];
-        }
-        if (($response["status"] ?? false) && $response["status"] == 500){
-            return ['success'=>false,"data"=>$response["msg"]];
-        }
-        app('LogService')->log(__METHOD__,"haiq-料箱出库成功","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
-        return ["success"=>true];
-    }
 
 }

+ 7 - 3
app/Services/ForeignHaiRoboticsService.php

@@ -231,7 +231,11 @@ class ForeignHaiRoboticsService
         return $controlSuccess;
     }
 
-    /** 缓存架入立架 料箱 任务 */
+    /** 缓存架入立架 料箱 任务
+     * @param StationTaskMaterialBox|null $stationTaskMaterialBox
+     * @return bool
+     * @throws ErrorException
+     */
     public function putBinToStore_fromCacheShelf(?StationTaskMaterialBox $stationTaskMaterialBox): bool
     {
         LogService::log('海柔请求','putBinToStore_fromCacheShelf1', '');
@@ -242,7 +246,7 @@ class ForeignHaiRoboticsService
         // 立架
         $formLocation =  $this->stationService->getULineExit($stationTaskMaterialBox['station']);
 
-        /** 创建料箱移动任务 */
+        /** 创建料箱 从缓存架 到 立架任务 */
         $dataToPost=$this->makeJson_move(
             collect([$stationTaskMaterialBox]),
             '缓存架入立架',
@@ -253,7 +257,7 @@ class ForeignHaiRoboticsService
 
         LogService::log('海柔请求','putBinToStore_fromCacheShelf3', json_encode($dataToPost));
 
-        /** 控制海柔机器人 */
+        /** 控制海柔机器人执行任务 */
         $controlSuccess = $this->controlHaiRobot($dataToPost);
         if($controlSuccess){
             $this->instant($this->stationTaskMaterialBoxService,'StationTaskMaterialBoxService');

+ 13 - 0
app/Services/StationCacheShelfGridService.php

@@ -0,0 +1,13 @@
+<?php 
+
+namespace App\Services;
+
+use App\Traits\ServiceAppAop;
+use App\StationCacheShelfGrid;
+
+class StationCacheShelfGridService
+{
+    use ServiceAppAop;
+    protected $modelClass=StationCacheShelfGrid::class;
+
+}

+ 6 - 1
app/Station.php

@@ -3,7 +3,7 @@
 namespace App;
 
 use Illuminate\Database\Eloquent\Model;
-
+use Illuminate\Database\Eloquent\Relations\HasMany;
 use App\Traits\ModelLogChanging;
 
 class Station extends Model
@@ -28,4 +28,9 @@ class Station extends Model
     public function stationTypeBinMonitor(){
         return $this->hasOne(StationTypeBinMonitor::class);
     }
+
+    public function grids(): HasMany
+    {
+        return $this->hasMany(StationCacheShelfGrid::class);
+    }
 }

+ 32 - 0
app/StationCacheShelfGrid.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+use App\Traits\ModelLogChanging;
+
+class StationCacheShelfGrid extends Model
+{
+    use ModelLogChanging;
+
+    protected $fillable = ['station_id','material_box_id','grid_id','status'];
+
+    public static $status = [
+        '0' => '无',
+        '1' => '待处理',
+        '2' => '完成',
+        '3' => '异常'
+    ];
+
+    public function station(): BelongsTo
+    {
+        return $this->belongsTo(Station::class);
+    }
+
+    public function materialBox(): BelongsTo
+    {
+        return $this->belongsTo(MaterialBox::class);
+    }
+
+}

+ 12 - 0
database/factories/StationCacheShelfGridFactory.php

@@ -0,0 +1,12 @@
+<?php
+
+/** @var \Illuminate\Database\Eloquent\Factory $factory */
+
+use App\StationCacheShelfGrid;
+use Faker\Generator as Faker;
+
+$factory->define(StationCacheShelfGrid::class, function (Faker $faker) {
+    return [
+        //
+    ];
+});

+ 31 - 0
database/migrations/2021_04_15_132002_create_station_cache_shelf_grids_table.php

@@ -0,0 +1,31 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateStationCacheShelfGridsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('station_cache_shelf_grids', function (Blueprint $table) {
+            $table->id();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('station_cache_shelf_grids');
+    }
+}

+ 16 - 0
database/seeds/StationCacheShelfGridSeeder.php

@@ -0,0 +1,16 @@
+<?php
+
+use Illuminate\Database\Seeder;
+
+class StationCacheShelfGridSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     *
+     * @return void
+     */
+    public function run()
+    {
+        //
+    }
+}

+ 4 - 3
resources/views/station/cachingShelf/list/_fillBox.blade.php

@@ -19,9 +19,10 @@
                     <template v-if="currentStation.data ">
                         <div class="row mt-1 mb-1" v-for="(rows,rowI) in currentStation.data">
                             <template v-if="rows.length !== 0">
-                                <div class="col" v-for="(item,colI) in rows" :y="item.col" :x="item.row">
-                                    <textarea class="form-control"
-                                              @keyup.enter="pushBoxToStation(item.col,item.row,$event)"
+                                <div class="col" v-for="(item,colI) in rows" :y="item.row" :x="item.col">
+                                    <textarea class="form-control font-weight-bold"
+                                              style="font-size: 35px"
+                                              @keyup.enter="pushBoxToStation(item.row,item.col,$event)"
                                               :value="item.code"
                                               :placeholder="item.index"
                                               :class="item.code? 'border-success ':''"

+ 3 - 0
resources/views/station/cachingShelf/list/_table.blade.php

@@ -37,6 +37,9 @@
                 <td>
                     @{{ station.parent ? station.parent.name  : ''}}
                 </td>
+                <td>
+                    @{{ station.parent ? station.parent.id  : ''}}
+                </td>
                 <td>
                     @{{ station.created_at }}
                 </td>

+ 64 - 51
resources/views/station/cachingShelf/list/index.blade.php

@@ -7,7 +7,7 @@
         @component('station.menu')@endcomponent
         @component('station.cachingShelf.menu')@endcomponent
     </div>
-    <div class="container-fluid" id="list">
+    <div class="container-fluid d-none" id="list">
         @include('station.cachingShelf.list._table')
         @include('station.cachingShelf.list._fillBox')
     </div>
@@ -21,31 +21,32 @@
                 stations: {!! $stations->toJson() !!}['data'],
                 selectTr: null,
                 materialBoxCode: null,  // 料箱编码
-                currentStation: {       // 当前Station
-                    id:null,            // Station->id
-                    data: [[], [], []], // 任务
+
+                currentStation: {        // 当前Station
+                    id: null,            // Station->id
+                    data: [[], [], []],  // 格口
                 },
                 boxClass: 'modal-sm',
-            },
-            created() {
 
+                broadcastName: null,
+                channelName: ".App\\Events\\BroadcastToStation",
             },
             mounted() {
                 this.initCacheShelfBox();
                 this.initModalBox();
-                /** 灭灯  */
+                $('#list').removeClass('d-none');
             },
             methods: {
                 /** 1初始化缓存架格口 */
-                initCacheShelfBox(){
+                initCacheShelfBox() {
                     this.currentStation.data.forEach(function (item, index, self) {
                         let boxRow = new Array(3);
                         for (let i = 0; i < boxRow.length; i++) {
-                            boxRow[i] ={
-                                x:index,
-                                y:i,
-                                col: 2 - index + 1,
-                                row:  2 - i + 1,
+                            boxRow[i] = {
+                                x: index,
+                                y: i,
+                                row: 2 - index + 1,
+                                col: 2 - i + 1,
                                 code: null,
                                 index: index * 3 + i + 1
                             };
@@ -61,17 +62,30 @@
                     if (window.screen.width >= 1200) this.boxClass = 'modal-xl';
                 },
                 /** 展示modal */
-                showFeedBox() {
+                showFeedBox(station) {
+                    this.currentStation.id = station['id'];
+                    this.broadcastName = "{{config('database.redis.options.prefix')}}" + 'station-' + station['id'];
+                    this.initCacheGrid();
                     $('#box').modal('show');
                 },
-                /** 获取缓存货架上的任务 */
-                getStation(id) {
-                    let url = '{{url('apiLocal/station/cachingShelf')}}' + '/' + id;
+                /** 初始化格口 */
+                initCacheGrid() {
+                    let url = '';
                     window.tempTip.setIndex(1099);
                     window.tempTip.setDuration(3000);
-
                     window.axios.get(url).then(res => {
                         if (res.data.data) {
+                            if (!isArray(res.data.data)) return;
+                            if (res.data.data.length === 0) return;
+                            for (let i = 0; i < res.data.data.length; i++) {
+                                let grid = res.data.data[i];
+                                let gridIndex = grid['id'];
+                                let row = gridIndex / 3;
+                                let col = gridIndex % 3;
+                                let code = grid['materialBox'] ? grid['materialBox']['code'] : null;
+                                this.$set(this.currentStation.data[row][col], 'code', code);
+                            }
+                            this.$forceUpdate();
                             return;
                         }
                         window.tempTip.show('获取缓存货架信息失败');
@@ -80,44 +94,37 @@
                     });
                 },
                 /** 扫码 2、填写九宫格 */
-                // 自动排号和自动发送
-                pushBoxToStation(x=null,y=null,$e = null) {
+                pushBoxToStation(x = null, y = null, $e = null) {
+                    // 自动排号和自动发送
                     // 选排
-                    if(x!==null && y!==null){
+                    if (x !== null && y !== null) {
                         let code = $($e.target).val();
-                        this.$set(this.currentStation.data[x][y],'code',code);
+                        this.$set(this.currentStation.data[x][y], 'code', code);
                         this.$forceUpdate();
                         return;
                     }
-
                     // 自动排号
                     let arr = [];
-                    this.currentStation.data.forEach(function(items){
-                        items.forEach(function (item){
-                            if(item['code'] === null){arr.push(item);}
+                    this.currentStation.data.forEach(function (items) {
+                        items.forEach(function (item) {
+                            if (item['code'] === null) {
+                                arr.push(item);
+                            }
                         });
                     })
                     x = arr[0]['x'];
                     y = arr[0]['y'];
-                    this.$set(this.currentStation.data[x][y],'code',this.materialBoxCode);
+                    this.$set(this.currentStation.data[x][y], 'code', this.materialBoxCode);
                     this.$forceUpdate();
                 },
-                /** 手动输入到指定格口 */
-                pullBoxToStation(x,y){
-                    if(this.currentStation.data[x][y]['code']!=null){
-                        this.$set(this.currentStation.data[x][y],'code',null);
-                        this.$forceUpdate();
-                    }
-                },
                 /** 扫码 3、上传等排灯 */
                 pushTask(data) {
                     let url = '';
-                    window.axios.post(url).then(res=>{
+                    window.axios.post(url).then(res => {
                         alert(res.data.success)
-                        if(res.data.success){
-
+                        if (res.data.success) {
                         }
-                    }).catch(err=>{
+                    }).catch(err => {
                         alert(err)
                     });
                 },
@@ -132,17 +139,13 @@
                     this.materialBoxCode = null;
                 },
                 /** 清空格口号 */
-                clearCurrentStation(){
-                    this.currentStation.data.forEach(function (item,index,items){
-                        items[index].forEach(function (item,index,self){
-                            self[index]['code']=null;
+                clearCurrentStation() {
+                    this.currentStation.data.forEach(function (item, index, items) {
+                        items[index].forEach(function (item, index, self) {
+                            self[index]['code'] = null;
                         })
                     });
                     this.$forceUpdate();
-                },
-                /** 料箱排序 */
-                sortMaterialBox() {
-
                 },
                 /** 亮灯 */
                 lightOn() {
@@ -152,20 +155,30 @@
                 lightOff() {
 
                 },
-                checkMaterialBoxCodeExist(code){
+                checkMaterialBoxCodeExist(code) {
                     let bool = false;
                     for (let x = 0; x < this.currentStation.data.length; x++) {
-                        if(!isArray(this.currentStation.data[x]) ){
+                        if (!isArray(this.currentStation.data[x])) {
                             continue;
                         }
-                        if(this.currentStation.data[x].length > 0){
+                        if (this.currentStation.data[x].length > 0) {
                             for (let y = 0; y < this.currentStation.data[y].length; y++) {
-                                if(this.currentStation.data[x][y]['code']===code)return true;
+                                if (this.currentStation.data[x][y]['code'] === code) return true;
                             }
                         }
                     }
                     return bool;
-                }
+                },
+                /** 监听 【灭灯】 */
+                _listenBroadcast() {
+                    initEcho();
+                    window.Echo.channel(this.broadcastName).listen(this.channelName, (msg) => {
+                        let json = JSON.parse(msg.json);
+                        if (!json || json.length === 0) return;
+                        this.station['current_station_task'] = json;
+                        console.log((new Date()).toTimeString(), json);
+                    });
+                },
             }
         })
     </script>