diff --git a/Laravel/app/Services/Admin/YeWu/DeptCheckItemService.php b/Laravel/app/Services/Admin/YeWu/DeptCheckItemService.php index e2a0f81..7598654 100644 --- a/Laravel/app/Services/Admin/YeWu/DeptCheckItemService.php +++ b/Laravel/app/Services/Admin/YeWu/DeptCheckItemService.php @@ -192,8 +192,8 @@ public function SyncItemClass() //同步检查项目(全量) + 返回当前科室相关统计 public function SyncCheckItem($userid) { - // 1. 同步前快照:当前科室所有符合条件的项目 code - $beforeCodes = $this->getDeptItemCodes($userid); + // 1. 同步前快照:当前科室所有符合条件的项目 code + 关键字段摘要 + $beforeSnapshot = $this->getDeptItemSnapshot($userid); // 2. 调用 HIS 同步项目(全量) request()->merge(['termClassId' => 155]); @@ -201,21 +201,35 @@ public function SyncCheckItem($userid) $hisController->UpdateCheckItem(); // 3. 同步后快照 - $afterCodes = $this->getDeptItemCodes($userid); + $afterSnapshot = $this->getDeptItemSnapshot($userid); // 4. 对比统计 + $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) { + if ($beforeSnapshot[$code] !== $afterSnapshot[$code]) { + $updatedCount++; + } + } + return \Yz::Return(true, '同步完成', [ - 'added' => count(array_diff_key($afterSet, $beforeSet)), - 'removed' => count(array_diff_key($beforeSet, $afterSet)), - 'updated' => count(array_intersect_key($beforeSet, $afterSet)), + 'added' => count($addedCodes), + 'removed' => count($removedCodes), + 'updated' => $updatedCount, ]); } - //获取当前科室所有符合条件的项目 code 列表 - private function getDeptItemCodes($userid) + //获取当前科室所有符合条件的项目快照(code => 字段摘要) + private function getDeptItemSnapshot($userid) { $user = DB::table('users')->where('id', $userid)->first(); if (!$user || !$user->department_id) return []; @@ -231,7 +245,7 @@ private function getDeptItemCodes($userid) if (empty($deptNumbers)) return []; - return DB::table('s_check_item') + $items = DB::table('s_check_item') ->where('is_del', 0) ->whereNotNull('sheetType')->where('sheetType', '!=', '') ->where(function($q) use ($deptNumbers) { @@ -239,7 +253,19 @@ private function getDeptItemCodes($userid) $q->orWhere('hisExecDepts', 'like', '%"' . $num . '"%'); } }) - ->pluck('item_code') - ->toArray(); + ->select('item_code', 'item_name', 'hisExecDepts', 'check_notice', 'sheetType', 'item_class_id') + ->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; } } \ No newline at end of file diff --git a/YiJi-admin/src/views/YeWu/DeptCheckItemConfig.vue b/YiJi-admin/src/views/YeWu/DeptCheckItemConfig.vue index fdf0198..dfa48ba 100644 --- a/YiJi-admin/src/views/YeWu/DeptCheckItemConfig.vue +++ b/YiJi-admin/src/views/YeWu/DeptCheckItemConfig.vue @@ -283,6 +283,12 @@