<?php

namespace App\Http\Controllers\API\His;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class DepartmentController extends Controller
{
    //获取科室列表
    public function GetDepartmentList(){
        $His = new HisController();
        $data=[];
        $res = $His::Get("查询科室列表", $data);
        $up_count=0;
        if ($res['code'] == 200) {
            $res_data = $res['data'];
            foreach ($res_data as $data_k => $data_v) {
                $dpt=DB::table("s_department")->where(['department_number'=>$data_v['deptCode']])->first();
                if(!$dpt){
                    $u=DB::table("s_department")->insert([
                        'department_number' => $data_v['deptCode'],
                        'department_name' => $data_v['deptName'],
                        'department_status' => 1,
                        'is_del' => 0,
                    ]);
                }else{
                    $u=DB::table("s_department")->where(['department_number'=>$data_v['deptCode']])->update([
                        'department_name' => $data_v['deptName'],
                    ]);
                }
                if($u){
                    $up_count++;
                }
            }
            return \Yz::JsonReturn(true,"调用His接口完成，更新".$up_count."条数据",['up_count'=>$up_count]);
        }
        return \Yz::JsonError("调用His接口失败");
    }
}
