with('stationType:name','parent:name')->whereHas('stationType',function($query){ /** @var Builder $query */ $query->where('name','料箱监视器'); })->paginate(100); return view('station.monitor.index',compact('stations')); } public function monitorShow(Station $station) { $station->loadMissing([ "stationTasks_today.stationTaskCommodities.commodity.barcodes", "stationTasks_today.stationTaskCommodities.stationTaskMaterialBox", "stationTasks_today.stationTaskBatches.batch.owner", "stationTasks_today.stationTaskMaterialBoxes.materialBox", "stationTypeBinMonitor", ]); if (!$station['stationTypeBinMonitor']){ StationTypeBinMonitor::query()->create([ 'station_id' => $station['id'], 'bin_row_length' => 4, 'bin_column_length' => 5, 'bin_wall_amount' => 2, ]); $station->load("stationTypeBinMonitor"); } return view('station.monitor.show',compact('station')); } public function getVisual() { $arr = \request("arr"); $cacheKey = "loadBoxMonitor_".$arr[0][0]; if (Cache::tags("loadBoxMonitor")->has($cacheKey))$this->success(Cache::tags("loadBoxMonitor")->get($cacheKey)); $res = []; foreach ($arr as $item){ $query = DB::connection("mysql_haiRobotics")->table("ks_bin")->select("ks_bin_code"); foreach ($item as $value)$query->orWhere("ks_bin_space_code",'like',$value); $codes = []; $query->get()->each(function ($bin)use(&$codes){ $codes[] = "'".$bin->ks_bin_code."'"; }); if (!$codes){$res[] = 100;continue;} $len = count($codes); $codes = "(".implode(",",$codes).")"; $sql = <<selectOne(DB::raw($sql))->count; //$res[] = intval($count/$len*1000)/10; $res[] = [$len,$count]; } Cache::tags("loadBoxMonitor")->put($cacheKey,$res,1800); $this->success($res); } public function getDetail() { $arr = \request("arr"); $cacheKey = "loadBoxMonitorDetail_".$arr[0]; if (Cache::tags("loadBoxMonitor")->has($cacheKey))$this->success(Cache::tags("loadBoxMonitor")->get($cacheKey)); $ks = DB::connection("mysql_haiRobotics")->table("ks_bin")->select("ks_bin_code","ks_bin_space_code") ->whereIn("ks_bin_space_code",$arr)->get(); $res = []; $codes = []; foreach ($ks as $k){ $res[$k->ks_bin_code] = $k->ks_bin_space_code; $codes[] = $k->ks_bin_code; } $locations = []; DB::connection("oracle")->table("INV_LOT_LOC_ID")->selectRaw("locationid,SUM(qty) qty") ->where("traceid","*") ->whereIn("locationid",$codes)->groupByRaw("locationid")->get()->each(function ($inv)use(&$locations,&$res){ $locations[] = [ "location" => $res[$inv->locationid], "status" => $inv->qty>0, ]; unset($res[$inv->locationid]); }); if ($res)foreach ($res as $item)$locations[] = [ "location" => $item, "status" => false, ]; Cache::tags("loadBoxMonitor")->put($cacheKey,$locations,1800); $this->success($locations); } public function getBoxes() { $arr = \request("arr"); if (!$arr)$this->error("无可用箱"); $ks = DB::connection("mysql_haiRobotics")->table("ks_bin")->select("ks_bin_code") ->whereIn("ks_bin_space_code",$arr)->pluck("ks_bin_code")->toArray(); $this->success(implode(" ",$ks)); } }