diff --git a/Laravel/app/Services/Admin/YeWu/PlanListService.php b/Laravel/app/Services/Admin/YeWu/PlanListService.php index fadc444..5883dd3 100644 --- a/Laravel/app/Services/Admin/YeWu/PlanListService.php +++ b/Laravel/app/Services/Admin/YeWu/PlanListService.php @@ -366,20 +366,15 @@ public function GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_typ $pp = []; $nowtime = date('Y-m-d H:i:s'); - // 查询该患者已有共享项目在各排班下的 max + // 查询该患者已有共享项目在各排班下的 max(直接读 s_list 快照) $existingSharedAtPlan = []; if (!empty($regnum)) { $existingSharedItems = DB::table('s_list') - ->join('s_check_item', 's_list.entrust_code', '=', 's_check_item.item_code') - ->leftJoin('s_dept_check_item', function($j) { - $j->on('s_dept_check_item.check_item_id', '=', 's_check_item.id') - ->on('s_dept_check_item.department_id', '=', 's_list.department_id'); - }) ->where('s_list.reg_num', $regnum) ->where('s_list.list_status', 1) ->where('s_list.roster_id', '>', 0) - ->where(DB::raw('COALESCE(s_dept_check_item.is_share_slot, s_check_item.is_share_slot, 0)'), 1) - ->select('s_list.roster_id', DB::raw('COALESCE(s_dept_check_item.use_seats, s_check_item.use_seats, 1) as use_seats')) + ->where('s_list.is_share_slot', 1) + ->select('s_list.roster_id', 's_list.use_seats') ->get(); foreach ($existingSharedItems as $esi) { $pid = $esi->roster_id; @@ -669,20 +664,15 @@ public function GetOptimalPlan($type, $regnum, $entrustids, $episodeid, $appoint } } - // 查询该患者已有共享项目在各排班下的 max + // 查询该患者已有共享项目在各排班下的 max(直接读 s_list 快照) $existingSharedAtPlan = []; $existingSharedItems = DB::table('s_list') - ->join('s_check_item', 's_list.entrust_code', '=', 's_check_item.item_code') - ->leftJoin('s_dept_check_item', function($j) { - $j->on('s_dept_check_item.check_item_id', '=', 's_check_item.id') - ->on('s_dept_check_item.department_id', '=', 's_list.department_id'); - }) ->where('s_list.reg_num', $regnum) ->where('s_list.list_status', 1) ->where('s_list.is_nullify', 0) ->where('s_list.roster_id', '>', 0) - ->where(DB::raw('COALESCE(s_dept_check_item.is_share_slot, s_check_item.is_share_slot, 0)'), 1) - ->select('s_list.roster_id', DB::raw('COALESCE(s_dept_check_item.use_seats, s_check_item.use_seats, 1) as use_seats')) + ->where('s_list.is_share_slot', 1) + ->select('s_list.roster_id', 's_list.use_seats') ->get(); foreach ($existingSharedItems as $esi) { $pid = $esi->roster_id; @@ -1278,16 +1268,11 @@ public function YuYue($planid, $appointment_type, $mainlistids, $do_type,$is_eme $regNum = $oldMainInfos[0]->reg_num ?? null; if (!empty($shareSlotIds) && $regNum) { $existingSharedItems = DB::table('s_list') - ->join('s_check_item', 's_list.entrust_code', '=', 's_check_item.item_code') - ->leftJoin('s_dept_check_item', function($j) { - $j->on('s_dept_check_item.check_item_id', '=', 's_check_item.id') - ->on('s_dept_check_item.department_id', '=', 's_list.department_id'); - }) ->where('s_list.reg_num', $regNum) ->where('s_list.roster_id', $planid) ->where('s_list.list_status', 1) - ->where(DB::raw('COALESCE(s_dept_check_item.is_share_slot, s_check_item.is_share_slot, 0)'), 1) - ->select(DB::raw('COALESCE(s_dept_check_item.use_seats, s_check_item.use_seats, 1) as use_seats')) + ->where('s_list.is_share_slot', 1) + ->select('s_list.use_seats') ->get(); if ($existingSharedItems->isNotEmpty()) { $existingSharedMax = $existingSharedItems->max('use_seats'); @@ -1484,14 +1469,9 @@ public function YuYue($planid, $appointment_type, $mainlistids, $do_type,$is_eme throw new \Exception('号源总数不足,总容量' . $totalCountChannel . ',已用' . $totalUsedChannel); } - // 校验②:从s_list实际记录校验(实际记录维度) + // 校验②:从s_list实际记录校验(实际记录维度,直接读 s_list 快照) // 复用correctUsedCount的分组算法:按患者分组,共享取max,非共享累加 $activeItems = DB::table('s_list') - ->leftJoin('s_check_item', 's_list.entrust_code', '=', 's_check_item.item_code') - ->leftJoin('s_dept_check_item', function($j) { - $j->on('s_dept_check_item.check_item_id', '=', 's_check_item.id') - ->on('s_dept_check_item.department_id', '=', 's_list.department_id'); - }) ->where('s_list.roster_id', $planid) ->whereIn('s_list.list_status', [1, 2, 3]) ->where('s_list.is_nullify', 0) @@ -1501,8 +1481,8 @@ public function YuYue($planid, $appointment_type, $mainlistids, $do_type,$is_eme $q->whereNotIn('s_list.id', $mainlistids); }) ->select('s_list.*', - DB::raw('COALESCE(s_dept_check_item.use_seats, s_check_item.use_seats, 1) as use_seats'), - DB::raw('COALESCE(s_dept_check_item.is_share_slot, s_check_item.is_share_slot, 0) as is_share_slot')) + DB::raw('s_list.use_seats as use_seats'), + DB::raw('s_list.is_share_slot as is_share_slot')) ->get(); $grouped = []; foreach ($activeItems as $item) { @@ -1977,19 +1957,14 @@ public function correctUsedCount($rosterId) ->where('roster_detail_id', $rosterId) ->update(['used_count' => 0, 'version' => DB::raw('version + 1')]); - // 获取该排班上所有活跃项目及其配置 + // 获取该排班上所有活跃项目(直接读 s_list 快照的占位与共享标记) $activeItems = DB::table('s_list') - ->leftJoin('s_check_item', 's_list.entrust_code', '=', 's_check_item.item_code') - ->leftJoin('s_dept_check_item', function($j) { - $j->on('s_dept_check_item.check_item_id', '=', 's_check_item.id') - ->on('s_dept_check_item.department_id', '=', 's_list.department_id'); - }) ->where('s_list.roster_id', $rosterId) ->whereIn('s_list.list_status', [1, 2, 3]) ->where('s_list.is_nullify', 0) ->select('s_list.*', - DB::raw('COALESCE(s_dept_check_item.use_seats, s_check_item.use_seats, 1) as use_seats'), - DB::raw('COALESCE(s_dept_check_item.is_share_slot, s_check_item.is_share_slot, 0) as is_share_slot')) + DB::raw('s_list.use_seats as use_seats'), + DB::raw('s_list.is_share_slot as is_share_slot')) ->get(); // 计算总占位:按人隔离,共享取 max,非共享累加 @@ -2094,19 +2069,14 @@ public function calculateUsedCount($rosterId, $correct = 0) ) ->get(); - // 获取该排班上所有活跃项目及其配置 + // 获取该排班上所有活跃项目(直接读 s_list 快照的占位与共享标记) $activeItems = DB::table('s_list') - ->leftJoin('s_check_item', 's_list.entrust_code', '=', 's_check_item.item_code') - ->leftJoin('s_dept_check_item', function($j) { - $j->on('s_dept_check_item.check_item_id', '=', 's_check_item.id') - ->on('s_dept_check_item.department_id', '=', 's_list.department_id'); - }) ->where('s_list.roster_id', $rosterId) ->whereIn('s_list.list_status', [1, 2, 3]) ->where('s_list.is_nullify', 0) ->select('s_list.*', - DB::raw('COALESCE(s_dept_check_item.use_seats, s_check_item.use_seats, 1) as use_seats'), - DB::raw('COALESCE(s_dept_check_item.is_share_slot, s_check_item.is_share_slot, 0) as is_share_slot')) + DB::raw('s_list.use_seats as use_seats'), + DB::raw('s_list.is_share_slot as is_share_slot')) ->get(); // 按患者分组计算占位 @@ -3282,16 +3252,11 @@ public function PreCheckYuYue($groups, $appointment_type, $do_type, $is_emergenc $regNum = $oldMainInfos[0]->reg_num ?? null; if (!empty($shareSlotIds) && $regNum) { $existingSharedItems = DB::table('s_list') - ->join('s_check_item', 's_list.entrust_code', '=', 's_check_item.item_code') - ->leftJoin('s_dept_check_item', function($j) { - $j->on('s_dept_check_item.check_item_id', '=', 's_check_item.id') - ->on('s_dept_check_item.department_id', '=', 's_list.department_id'); - }) ->where('s_list.reg_num', $regNum) ->where('s_list.roster_id', $planid) ->where('s_list.list_status', 1) - ->where(DB::raw('COALESCE(s_dept_check_item.is_share_slot, s_check_item.is_share_slot, 0)'), 1) - ->select(DB::raw('COALESCE(s_dept_check_item.use_seats, s_check_item.use_seats, 1) as use_seats')) + ->where('s_list.is_share_slot', 1) + ->select('s_list.use_seats') ->get(); if ($existingSharedItems->isNotEmpty()) { $existingSharedMax = $existingSharedItems->max('use_seats');