<?php

namespace App\Http\Controllers\API\Admin\YeWu;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Services\Admin\YeWu\DepartmentResourceService;
use Illuminate\Support\Facades\DB;
use function Symfony\Component\Translation\t;

class DepartmentResourceController extends Controller
{
    public function Save(Request $request)
    {
        $userid = $request->get('userid');//中间件产生的参数
        $info =request('info');
        $service = new DepartmentResourceService();
        return $service->Save($info,$userid);
    }
    public function GetList()
    {
        $page =request('page');
        $pageSize =request('pageSize');
        $searchInfo =request('searchInfo');
        $service = new DepartmentResourceService();
        return $service->GetList($searchInfo,$page,$pageSize);
    }
    public function GetEnableList(Request $request)
    {
        $userid = $request->get('userid');//中间件产生的参数
        $res_department_id=$request->get('department_id');
        $userInfo = DB::table('users')->where(['id' => $userid])->first();
        if(!isset($userInfo->department_id) and !isset($res_department_id)){
            return \Yz::echoError1('科室信息不存在');
        }
        if(isset($userInfo->department_id)) $department_id=$userInfo->department_id;
        if(isset($res_department_id))  $department_id=$res_department_id;
        $resource=DB::table('s_department_resources')->where(['department_id'=>$department_id,'department_resources_status'=>1,'is_del'=>0])->orderBy('id')->get();
        foreach($resource as $k=>$v){
            $v->time_range=json_decode($v->time_range,true);
        }
        if(count($resource)>0){
            return \Yz::Return(true, '操作成功',$resource);
        }else{
            return \Yz::echoError1('获取科室资源失败');
        }
    }
    public function Del()
    {
        $id =request('id');
        $service = new DepartmentResourceService();
        return $service->Del($id);
    }
    public function BindDevice()
    {
        $department_id =request('department_id');
        $resource_id =request('resource_id');
        $device_ids = request('device_ids');
        $service = new DepartmentResourceService();
        return $service->BindDevice($department_id,$resource_id,$device_ids);
    }
    //获取诊室关联的服务组（设备）
    public function GetBindDeviceList()
    {
        $resource_id =request('resource_id');
        $service = new DepartmentResourceService();
        return $service->GetBindDeviceList($resource_id);
    }
}
