科室级别的更新项目

main
鹿和sa0ChunLuyu 6 days ago
parent 27d1f65f40
commit 0d1257c431

@ -192,8 +192,8 @@ public function SyncItemClass()
//同步检查项目(全量) + 返回当前科室相关统计 //同步检查项目(全量) + 返回当前科室相关统计
public function SyncCheckItem($userid) public function SyncCheckItem($userid)
{ {
// 1. 同步前快照:当前科室所有符合条件的项目 code // 1. 同步前快照:当前科室所有符合条件的项目 code + 关键字段摘要
$beforeCodes = $this->getDeptItemCodes($userid); $beforeSnapshot = $this->getDeptItemSnapshot($userid);
// 2. 调用 HIS 同步项目(全量) // 2. 调用 HIS 同步项目(全量)
request()->merge(['termClassId' => 155]); request()->merge(['termClassId' => 155]);
@ -201,21 +201,35 @@ public function SyncCheckItem($userid)
$hisController->UpdateCheckItem(); $hisController->UpdateCheckItem();
// 3. 同步后快照 // 3. 同步后快照
$afterCodes = $this->getDeptItemCodes($userid); $afterSnapshot = $this->getDeptItemSnapshot($userid);
// 4. 对比统计 // 4. 对比统计
$beforeCodes = array_keys($beforeSnapshot);
$afterCodes = array_keys($afterSnapshot);
$beforeSet = array_flip($beforeCodes); $beforeSet = array_flip($beforeCodes);
$afterSet = array_flip($afterCodes); $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) {
if ($beforeSnapshot[$code] !== $afterSnapshot[$code]) {
$updatedCount++;
}
}
return \Yz::Return(true, '同步完成', [ return \Yz::Return(true, '同步完成', [
'added' => count(array_diff_key($afterSet, $beforeSet)), 'added' => count($addedCodes),
'removed' => count(array_diff_key($beforeSet, $afterSet)), 'removed' => count($removedCodes),
'updated' => count(array_intersect_key($beforeSet, $afterSet)), 'updated' => $updatedCount,
]); ]);
} }
//获取当前科室所有符合条件的项目 code 列表 //获取当前科室所有符合条件的项目快照code => 字段摘要)
private function getDeptItemCodes($userid) private function getDeptItemSnapshot($userid)
{ {
$user = DB::table('users')->where('id', $userid)->first(); $user = DB::table('users')->where('id', $userid)->first();
if (!$user || !$user->department_id) return []; if (!$user || !$user->department_id) return [];
@ -231,7 +245,7 @@ private function getDeptItemCodes($userid)
if (empty($deptNumbers)) return []; if (empty($deptNumbers)) return [];
return DB::table('s_check_item') $items = DB::table('s_check_item')
->where('is_del', 0) ->where('is_del', 0)
->whereNotNull('sheetType')->where('sheetType', '!=', '') ->whereNotNull('sheetType')->where('sheetType', '!=', '')
->where(function($q) use ($deptNumbers) { ->where(function($q) use ($deptNumbers) {
@ -239,7 +253,19 @@ private function getDeptItemCodes($userid)
$q->orWhere('hisExecDepts', 'like', '%"' . $num . '"%'); $q->orWhere('hisExecDepts', 'like', '%"' . $num . '"%');
} }
}) })
->pluck('item_code') ->select('item_code', 'item_name', 'hisExecDepts', 'check_notice', 'sheetType', 'item_class_id')
->toArray(); ->get();
$snapshot = [];
foreach ($items as $item) {
$snapshot[$item->item_code] = md5(json_encode([
'item_name' => $item->item_name,
'hisExecDepts' => $item->hisExecDepts,
'check_notice' => $item->check_notice,
'sheetType' => $item->sheetType,
'item_class_id'=> $item->item_class_id,
]));
}
return $snapshot;
} }
} }

@ -283,6 +283,12 @@
</el-dialog> </el-dialog>
<el-dialog v-model="syncDialogVisible" title="同步项目" width="480px" :close-on-click-modal="false"> <el-dialog v-model="syncDialogVisible" title="同步项目" width="480px" :close-on-click-modal="false">
<template v-if="!syncDone"> <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-steps :active="syncStep" align-center finish-status="success" style="margin-top: 10px;">
<el-step title="同步分类" /> <el-step title="同步分类" />
<el-step title="同步项目" /> <el-step title="同步项目" />
@ -293,15 +299,17 @@
<el-result icon="success" title="同步完成"> <el-result icon="success" title="同步完成">
<template #extra> <template #extra>
<div style="display: flex; justify-content: space-around; padding: 12px 0;"> <div style="display: flex; justify-content: space-around; padding: 12px 0;">
<div style="text-align: center;"> <div style="text-align: center; flex: 1;">
<div style="font-size: 28px; font-weight: 700; color: #409eff;">{{ syncResult.added }}</div> <div style="font-size: 28px; font-weight: 700; color: #409eff;">{{ syncResult.added }}</div>
<div style="color: #999; font-size: 13px;">新增项目</div> <div style="color: #999; font-size: 13px;">新增项目</div>
</div> </div>
<div style="text-align: center;"> <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="font-size: 28px; font-weight: 700; color: #e6a23c;">{{ syncResult.removed }}</div>
<div style="color: #999; font-size: 13px;">移除项目</div> <div style="color: #999; font-size: 13px;">移除项目</div>
</div> </div>
<div style="text-align: center;"> <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="font-size: 28px; font-weight: 700; color: #67c23a;">{{ syncResult.updated }}</div>
<div style="color: #999; font-size: 13px;">更新项目</div> <div style="color: #999; font-size: 13px;">更新项目</div>
</div> </div>
@ -345,7 +353,8 @@
ElMessageBox ElMessageBox
} from 'element-plus' } from 'element-plus'
import { import {
ArrowRight ArrowRight,
Loading
} from '@element-plus/icons-vue' } from '@element-plus/icons-vue'
let loading = ref(false); let loading = ref(false);
@ -461,6 +470,8 @@
let syncStep = ref(0) let syncStep = ref(0)
let syncPercent = ref(0) let syncPercent = ref(0)
let syncDone = ref(false) let syncDone = ref(false)
let syncLoading = ref(false)
let syncLoadingText = ref('')
let syncResult = ref({ added: 0, removed: 0, updated: 0 }) let syncResult = ref({ added: 0, removed: 0, updated: 0 })
// //
@ -528,10 +539,14 @@
syncStep.value = 0 syncStep.value = 0
syncPercent.value = 0 syncPercent.value = 0
syncDone.value = false syncDone.value = false
syncLoading.value = false
syncResult.value = { added: 0, removed: 0, updated: 0 } syncResult.value = { added: 0, removed: 0, updated: 0 }
// 1 // 1
syncLoadingText.value = '正在同步分类...'
syncLoading.value = true
const classRes = await DeptSyncItemClass() const classRes = await DeptSyncItemClass()
syncLoading.value = false
if (!classRes.status) { if (!classRes.status) {
ElMessage.error('同步分类失败:' + (classRes.msg || '未知错误')) ElMessage.error('同步分类失败:' + (classRes.msg || '未知错误'))
syncDialogVisible.value = false syncDialogVisible.value = false
@ -541,7 +556,10 @@
syncPercent.value = 50 syncPercent.value = 50
// 2 // 2
syncLoadingText.value = '正在同步项目...'
syncLoading.value = true
const itemRes = await DeptSyncCheckItem() const itemRes = await DeptSyncCheckItem()
syncLoading.value = false
if (!itemRes.status) { if (!itemRes.status) {
ElMessage.error('同步项目失败:' + (itemRes.msg || '未知错误')) ElMessage.error('同步项目失败:' + (itemRes.msg || '未知错误'))
syncDialogVisible.value = false syncDialogVisible.value = false

Loading…
Cancel
Save