|
|
<?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接口失败");
|
|
|
}
|
|
|
//根据入参数据同步科室(不调用HIS接口)
|
|
|
public function SyncDepartmentFromData()
|
|
|
{
|
|
|
$data = request('data');
|
|
|
$password = request('password');
|
|
|
|
|
|
//调试输出
|
|
|
\Log::debug('SyncDepartmentFromData 入参', [
|
|
|
'password' => $password,
|
|
|
'data_type' => gettype($data),
|
|
|
'data' => $data
|
|
|
]);
|
|
|
|
|
|
//校验password
|
|
|
if ($password !== '324F883D-D501-40AD-8740-98536606906D') {
|
|
|
return \Yz::JsonError('密钥验证失败,password: '.$password);
|
|
|
}
|
|
|
|
|
|
if (empty($data) || !is_array($data)) {
|
|
|
return \Yz::JsonError('数据不能为空,data类型: '.gettype($data));
|
|
|
}
|
|
|
|
|
|
$up_count = 0;
|
|
|
foreach ($data as $i => $item) {
|
|
|
//调试输出每条数据
|
|
|
\Log::debug('SyncDepartmentFromData 处理第'.$i.'条', ['item' => $item]);
|
|
|
|
|
|
if (!isset($item['deptCode']) || !isset($item['deptName'])) {
|
|
|
\Log::error('SyncDepartmentFromData 字段缺失', ['index' => $i, 'item' => $item]);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
$dpt = DB::table('s_department')
|
|
|
->where('department_number', $item['deptCode'])
|
|
|
->first();
|
|
|
|
|
|
if (!$dpt) {
|
|
|
DB::table('s_department')->insert([
|
|
|
'department_number' => $item['deptCode'],
|
|
|
'department_name' => $item['deptName'],
|
|
|
'department_status' => 1,
|
|
|
'is_del' => 0,
|
|
|
]);
|
|
|
$up_count++;
|
|
|
} else {
|
|
|
DB::table('s_department')
|
|
|
->where('department_number', $item['deptCode'])
|
|
|
->update(['department_name' => $item['deptName']]);
|
|
|
$up_count++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return \Yz::JsonReturn(true, "同步完成,更新{$up_count}条数据", ['up_count' => $up_count]);
|
|
|
}
|
|
|
}
|