|
|
|
@ -59,6 +59,121 @@ public function GetUserList(){
|
|
|
|
return \Yz::JsonError("调用His接口失败");
|
|
|
|
return \Yz::JsonError("调用His接口失败");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//从HIS同步人员 + 返回统计
|
|
|
|
|
|
|
|
public function SyncUser()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 1. 同步前快照
|
|
|
|
|
|
|
|
$beforeSnapshot = $this->getUserSnapshot();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 调用 HIS 接口
|
|
|
|
|
|
|
|
$His = new HisController();
|
|
|
|
|
|
|
|
$res = $His::Get('查询人员列表', []);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($res['code'] != 200) {
|
|
|
|
|
|
|
|
return \Yz::JsonError('调用His接口失败');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$hisData = $res['data'];
|
|
|
|
|
|
|
|
$receivedCodes = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($hisData as $item) {
|
|
|
|
|
|
|
|
$emplCode = $item['emplCode'];
|
|
|
|
|
|
|
|
if ($emplCode == 'admin') continue;
|
|
|
|
|
|
|
|
$receivedCodes[] = $emplCode;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$user = DB::table('users')->where('cas_code', $emplCode)->first();
|
|
|
|
|
|
|
|
$dept = DB::table('s_department')->where('department_number', $item['deptCode'])->first();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$group = null;
|
|
|
|
|
|
|
|
if ($item['posiCode'] == '300A') {
|
|
|
|
|
|
|
|
$group = 6;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (in_array($item['emplType'], ['N', 'T'])) {
|
|
|
|
|
|
|
|
$group = 3;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($item['emplType'] == 'D') {
|
|
|
|
|
|
|
|
$group = 7;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!$user) {
|
|
|
|
|
|
|
|
DB::table('users')->insert([
|
|
|
|
|
|
|
|
'cas_code' => $emplCode,
|
|
|
|
|
|
|
|
'cn_name' => $item['emplName'],
|
|
|
|
|
|
|
|
'username' => $emplCode,
|
|
|
|
|
|
|
|
'pwd' => '$2y$10$HlgBHem3knR9JGcPWWxfhuj/oQzGouQaWQ8BIDbSxliJ39G6pOj/K',
|
|
|
|
|
|
|
|
'department_id' => isset($dept->id) ? $dept->id : null,
|
|
|
|
|
|
|
|
'status' => 1,
|
|
|
|
|
|
|
|
'group' => $group,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$updateData = [
|
|
|
|
|
|
|
|
'cn_name' => $item['emplName'],
|
|
|
|
|
|
|
|
'department_id' => isset($dept->id) ? $dept->id : null,
|
|
|
|
|
|
|
|
'group' => $user->group_locked == 1 ? $user->group : $group,
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
// 如果之前是禁用状态,同步时恢复启用
|
|
|
|
|
|
|
|
if ($user->status == 0) {
|
|
|
|
|
|
|
|
$updateData['status'] = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
DB::table('users')->where('id', $user->id)->update($updateData);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 3. 处理移除:HIS未返回的人员标记 status=0
|
|
|
|
|
|
|
|
DB::table('users')
|
|
|
|
|
|
|
|
->where('status', 1)
|
|
|
|
|
|
|
|
->where('cas_code', '!=', 'admin')
|
|
|
|
|
|
|
|
->whereNotIn('cas_code', $receivedCodes)
|
|
|
|
|
|
|
|
->update(['status' => 0]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 4. 同步后快照
|
|
|
|
|
|
|
|
$afterSnapshot = $this->getUserSnapshot();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 5. 对比统计
|
|
|
|
|
|
|
|
$beforeCodes = array_keys($beforeSnapshot);
|
|
|
|
|
|
|
|
$afterCodes = array_keys($afterSnapshot);
|
|
|
|
|
|
|
|
$beforeSet = array_flip($beforeCodes);
|
|
|
|
|
|
|
|
$afterSet = array_flip($afterCodes);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$addedCodes = array_diff_key($afterSet, $beforeSet);
|
|
|
|
|
|
|
|
$removedCodes = array_diff_key($beforeSet, $afterSet);
|
|
|
|
|
|
|
|
$commonCodes = array_intersect_key($beforeSet, $afterSet);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$updatedCount = 0;
|
|
|
|
|
|
|
|
foreach ($commonCodes as $code => $v) {
|
|
|
|
|
|
|
|
$before = $beforeSnapshot[$code];
|
|
|
|
|
|
|
|
$after = $afterSnapshot[$code];
|
|
|
|
|
|
|
|
if ($before['name'] !== $after['name'] || $before['dept_id'] !== $after['dept_id']) {
|
|
|
|
|
|
|
|
$updatedCount++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return \Yz::Return(true, '同步完成', [
|
|
|
|
|
|
|
|
'added' => count($addedCodes),
|
|
|
|
|
|
|
|
'removed' => count($removedCodes),
|
|
|
|
|
|
|
|
'updated' => $updatedCount,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取所有 status=1 的人员快照
|
|
|
|
|
|
|
|
private function getUserSnapshot()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$items = DB::table('users')
|
|
|
|
|
|
|
|
->where('status', 1)
|
|
|
|
|
|
|
|
->select('cas_code', 'cn_name', 'department_id')
|
|
|
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$snapshot = [];
|
|
|
|
|
|
|
|
foreach ($items as $item) {
|
|
|
|
|
|
|
|
$snapshot[$item->cas_code] = [
|
|
|
|
|
|
|
|
'name' => $item->cn_name,
|
|
|
|
|
|
|
|
'dept_id' => $item->department_id,
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $snapshot;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//用于his 医生直接跳转过来,查看开单记录
|
|
|
|
//用于his 医生直接跳转过来,查看开单记录
|
|
|
|
public function AutoLogin(){
|
|
|
|
public function AutoLogin(){
|
|
|
|
$usercode = request('usercode');
|
|
|
|
$usercode = request('usercode');
|
|
|
|
|