同步人员信息

main
鹿和sa0ChunLuyu 6 days ago
parent b55c117b19
commit f00a44923d

@ -59,6 +59,121 @@ public function GetUserList(){
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 医生直接跳转过来,查看开单记录
public function AutoLogin(){
$usercode = request('usercode');

@ -185,6 +185,7 @@
Route::post('admin/HisGetDepartmentList','App\Http\Controllers\API\His\DepartmentController@GetDepartmentList');//获取his科室列表
Route::post('admin/SyncDepartmentFromData','App\Http\Controllers\API\His\DepartmentController@SyncDepartmentFromData');//根据入参数据同步科室
Route::post('admin/HisGetUserList','App\Http\Controllers\API\His\UserController@GetUserList');//获取his用户列表
Route::post('admin/DeptSyncUser','App\Http\Controllers\API\His\UserController@SyncUser');//从HIS同步人员
Route::post('admin/SyncDrugList','App\Http\Controllers\API\His\DrugController@SyncDrugList');//同步药品列表
Route::post('admin/SyncUndrugList','App\Http\Controllers\API\His\DrugController@SyncUndrugList');//同步非药品列表
Route::post('admin/HisAutoLogin','App\Http\Controllers\API\His\UserController@AutoLogin' );

@ -51,6 +51,10 @@ export const SaveSystemUserInfo = (data = {}) => {
export const GetSystemUserDetail = (data = {}) => {
return axios({ url: import.meta.env.VITE_APP_API + 'v1/admin/GetSystemUserDetail', data: data })
}
//从HIS同步人员
export const DeptSyncUser = (data = {}) => {
return axios({ url: import.meta.env.VITE_APP_API + 'v1/admin/DeptSyncUser', data: data })
}
//admin后台修改密码
export const adminChangePwd = (data = {}) => {
return axios({ url: import.meta.env.VITE_APP_API + 'v1/admin/adminChangePwd', data: data })

@ -15,6 +15,7 @@
<el-button @click="GetUserList()" style="margin-left: 10px;">查询</el-button>
<el-button type="primary" @click="add()" style="margin-left: 10px;">新建用户</el-button>
<el-button type="warning" @click="openSyncDialog" style="margin-left: 10px;">从HIS同步人员</el-button>
</el-row>
</div>
@ -108,6 +109,45 @@
</span>
</template>
</el-dialog>
<el-dialog v-model="syncDialogVisible" title="从HIS同步人员" width="480px" :close-on-click-modal="false">
<template v-if="!syncDone">
<div v-if="syncLoading" style="text-align: center; padding: 12px 0; color: #303133; font-size: 15px; font-weight: 500;">
<el-icon class="is-loading" style="vertical-align: middle; margin-right: 4px;">
<Loading />
</el-icon>
{{ syncLoadingText }}
</div>
<el-steps :active="syncStep" align-center finish-status="success" style="margin-top: 10px;">
<el-step title="同步人员" />
</el-steps>
<el-progress :percentage="syncPercent" :stroke-width="14" style="margin-top: 24px;" />
</template>
<template v-else>
<el-result icon="success" title="同步完成">
<template #extra>
<div style="display: flex; justify-content: space-around; padding: 12px 0;">
<div style="text-align: center; flex: 1;">
<div style="font-size: 28px; font-weight: 700; color: #409eff;">{{ syncResult.added }}</div>
<div style="color: #999; font-size: 13px;">新增</div>
</div>
<div style="width: 1px; background: #e8e8e8; margin: 0 12px;"></div>
<div style="text-align: center; flex: 1;">
<div style="font-size: 28px; font-weight: 700; color: #e6a23c;">{{ syncResult.removed }}</div>
<div style="color: #999; font-size: 13px;">移除</div>
</div>
<div style="width: 1px; background: #e8e8e8; margin: 0 12px;"></div>
<div style="text-align: center; flex: 1;">
<div style="font-size: 28px; font-weight: 700; color: #67c23a;">{{ syncResult.updated }}</div>
<div style="color: #999; font-size: 13px;">更新</div>
</div>
</div>
</template>
</el-result>
</template>
<template #footer>
<el-button v-if="syncDone" type="primary" @click="syncDialogVisible = false; GetUserList()"></el-button>
</template>
</el-dialog>
</div>
</template>
@ -125,11 +165,13 @@
getAdminUserList,
SaveSystemUserInfo,
GetSystemUserDetail,
resetPwd
resetPwd,
DeptSyncUser
} from '@/api/api.js'
import {
Edit,
Refresh
Refresh,
Loading
} from '@element-plus/icons-vue'
import {
@ -267,6 +309,16 @@
);
let resetPwdDialogShow = ref(false);
let Password = ref('');
//
let syncDialogVisible = ref(false)
let syncStep = ref(0)
let syncPercent = ref(0)
let syncDone = ref(false)
let syncLoading = ref(false)
let syncLoadingText = ref('')
let syncResult = ref({ added: 0, removed: 0, updated: 0 })
const resetPwdClick = () => {
resetPwdDialogShow.value = true
}
@ -294,6 +346,33 @@
}
})
}
//
const openSyncDialog = async () => {
syncDialogVisible.value = true
syncStep.value = 0
syncPercent.value = 0
syncDone.value = false
syncLoading.value = false
syncResult.value = { added: 0, removed: 0, updated: 0 }
syncLoadingText.value = '正在同步人员...'
syncLoading.value = true
const res = await DeptSyncUser()
syncLoading.value = false
if (!res.status) {
ElMessage.error('同步人员失败:' + (res.msg || '未知错误'))
syncDialogVisible.value = false
return
}
syncResult.value = res.data
syncStep.value = 1
syncPercent.value = 100
syncDone.value = true
}
onMounted(() => {
})

Loading…
Cancel
Save