| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace App\Http\Controllers;
- use App\Components\AsyncResponse;
- use App\Station;
- use App\StationTypeBinMonitor;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\DB;
- class StationController extends Controller
- {
- use AsyncResponse;
- public function monitorIndex()
- {
- $stations = Station::query()->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 = <<<SQL
- SELECT COUNT(*) count FROM (SELECT SUM(QTY) qty FROM INV_LOT_LOC_ID WHERE
- TRACEID = '*' AND LOCATIONID IN {$codes} GROUP BY LOCATIONID) inv WHERE INV.qty!=0
- SQL;
- $count = DB::connection("oracle")->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));
- }
- }
|