|
|
|
@ -434,6 +434,21 @@ public function GetOptimalPlan($type, $regnum, $entrustids, $episodeid, $appoint
|
|
|
|
$endDate = new DateTime();
|
|
|
|
$endDate = new DateTime();
|
|
|
|
$endDate->modify('+' . $dateRange . ' day');
|
|
|
|
$endDate->modify('+' . $dateRange . ' day');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 批量查询每个检查项目的 use_seats
|
|
|
|
|
|
|
|
$entrustIds = array_column($items, 'entrust_id');
|
|
|
|
|
|
|
|
$useSeatsMap = [];
|
|
|
|
|
|
|
|
if (!empty($entrustIds)) {
|
|
|
|
|
|
|
|
$useSeatsMap = DB::table('s_list')
|
|
|
|
|
|
|
|
->join('s_check_item', 's_list.entrust', '=', 's_check_item.item_name')
|
|
|
|
|
|
|
|
->whereIn('s_list.entrust_id', $entrustIds)
|
|
|
|
|
|
|
|
->pluck('s_check_item.use_seats', 's_list.entrust_id')
|
|
|
|
|
|
|
|
->toArray();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($items as &$item) {
|
|
|
|
|
|
|
|
$item['use_seats'] = $useSeatsMap[$item['entrust_id']] ?? 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
unset($item);
|
|
|
|
|
|
|
|
|
|
|
|
if ($type === 'full_day') {
|
|
|
|
if ($type === 'full_day') {
|
|
|
|
return $this->doFullDayAssign($startDate, $endDate, $regnum, $entrustids, $episodeid, $appointment_type, $items, $scope, $userDeptId, $occupied_plan_ids);
|
|
|
|
return $this->doFullDayAssign($startDate, $endDate, $regnum, $entrustids, $episodeid, $appointment_type, $items, $scope, $userDeptId, $occupied_plan_ids);
|
|
|
|
} elseif ($type === 'same_day_slot') {
|
|
|
|
} elseif ($type === 'same_day_slot') {
|
|
|
|
@ -496,10 +511,11 @@ private function doOptimalTimeAssign($startDate, $endDate, $regnum, $entrustids,
|
|
|
|
$assigned = false;
|
|
|
|
$assigned = false;
|
|
|
|
foreach ($availablePlans as $plan) {
|
|
|
|
foreach ($availablePlans as $plan) {
|
|
|
|
$planId = $plan->id;
|
|
|
|
$planId = $plan->id;
|
|
|
|
|
|
|
|
$useSeats = $item['use_seats'] ?? 1;
|
|
|
|
$remaining = ($plan->count ?? 0) - ($plan->used_count ?? 0);
|
|
|
|
$remaining = ($plan->count ?? 0) - ($plan->used_count ?? 0);
|
|
|
|
$used = $usedCapacity[$planId] ?? 0;
|
|
|
|
$used = $usedCapacity[$planId] ?? 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (($remaining - $used) <= 0) continue;
|
|
|
|
if (($remaining - $used) < $useSeats) continue;
|
|
|
|
|
|
|
|
|
|
|
|
// 冲突检查:同一科室组内,不同排班时间不能重叠
|
|
|
|
// 冲突检查:同一科室组内,不同排班时间不能重叠
|
|
|
|
if ($this->isTimeConflict($assignedPlans, $plan)) continue;
|
|
|
|
if ($this->isTimeConflict($assignedPlans, $plan)) continue;
|
|
|
|
@ -514,7 +530,7 @@ private function doOptimalTimeAssign($startDate, $endDate, $regnum, $entrustids,
|
|
|
|
'begin_time' => $plan->begin_time,
|
|
|
|
'begin_time' => $plan->begin_time,
|
|
|
|
'end_time' => $plan->end_time
|
|
|
|
'end_time' => $plan->end_time
|
|
|
|
];
|
|
|
|
];
|
|
|
|
$usedCapacity[$planId] = ($usedCapacity[$planId] ?? 0) + 1;
|
|
|
|
$usedCapacity[$planId] = ($usedCapacity[$planId] ?? 0) + $useSeats;
|
|
|
|
$assignedPlans[] = [
|
|
|
|
$assignedPlans[] = [
|
|
|
|
'resource_name' => $plan->department_resources_name,
|
|
|
|
'resource_name' => $plan->department_resources_name,
|
|
|
|
'begin_time' => $plan->begin_time,
|
|
|
|
'begin_time' => $plan->begin_time,
|
|
|
|
@ -587,10 +603,11 @@ private function doFullDayAssign($startDate, $endDate, $regnum, $entrustids, $ep
|
|
|
|
$assigned = false;
|
|
|
|
$assigned = false;
|
|
|
|
foreach ($availablePlans as $plan) {
|
|
|
|
foreach ($availablePlans as $plan) {
|
|
|
|
$planId = $plan->id;
|
|
|
|
$planId = $plan->id;
|
|
|
|
|
|
|
|
$useSeats = $item['use_seats'] ?? 1;
|
|
|
|
$remaining = ($plan->count ?? 0) - ($plan->used_count ?? 0);
|
|
|
|
$remaining = ($plan->count ?? 0) - ($plan->used_count ?? 0);
|
|
|
|
$used = $usedCapacity[$planId] ?? 0;
|
|
|
|
$used = $usedCapacity[$planId] ?? 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (($remaining - $used) <= 0) continue;
|
|
|
|
if (($remaining - $used) < $useSeats) continue;
|
|
|
|
|
|
|
|
|
|
|
|
// 冲突检查:同一科室组内,不同排班时间不能重叠
|
|
|
|
// 冲突检查:同一科室组内,不同排班时间不能重叠
|
|
|
|
if ($this->isTimeConflict($assignedPlans, $plan)) continue;
|
|
|
|
if ($this->isTimeConflict($assignedPlans, $plan)) continue;
|
|
|
|
@ -603,7 +620,7 @@ private function doFullDayAssign($startDate, $endDate, $regnum, $entrustids, $ep
|
|
|
|
'begin_time' => $plan->begin_time,
|
|
|
|
'begin_time' => $plan->begin_time,
|
|
|
|
'end_time' => $plan->end_time
|
|
|
|
'end_time' => $plan->end_time
|
|
|
|
];
|
|
|
|
];
|
|
|
|
$usedCapacity[$planId] = ($usedCapacity[$planId] ?? 0) + 1;
|
|
|
|
$usedCapacity[$planId] = ($usedCapacity[$planId] ?? 0) + $useSeats;
|
|
|
|
$assignedPlans[] = [
|
|
|
|
$assignedPlans[] = [
|
|
|
|
'resource_name' => $plan->department_resources_name,
|
|
|
|
'resource_name' => $plan->department_resources_name,
|
|
|
|
'begin_time' => $plan->begin_time,
|
|
|
|
'begin_time' => $plan->begin_time,
|
|
|
|
@ -705,10 +722,11 @@ private function doSameDaySlotAssign($startDate, $endDate, $regnum, $entrustids,
|
|
|
|
$assigned = false;
|
|
|
|
$assigned = false;
|
|
|
|
foreach ($availablePlans as $plan) {
|
|
|
|
foreach ($availablePlans as $plan) {
|
|
|
|
$planId = $plan->id;
|
|
|
|
$planId = $plan->id;
|
|
|
|
|
|
|
|
$useSeats = $item['use_seats'] ?? 1;
|
|
|
|
$remaining = ($plan->count ?? 0) - ($plan->used_count ?? 0);
|
|
|
|
$remaining = ($plan->count ?? 0) - ($plan->used_count ?? 0);
|
|
|
|
$used = $usedCapacity[$planId] ?? 0;
|
|
|
|
$used = $usedCapacity[$planId] ?? 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (($remaining - $used) <= 0) continue;
|
|
|
|
if (($remaining - $used) < $useSeats) continue;
|
|
|
|
|
|
|
|
|
|
|
|
// 冲突检查:同一科室组内,不同排班时间不能重叠
|
|
|
|
// 冲突检查:同一科室组内,不同排班时间不能重叠
|
|
|
|
if ($this->isTimeConflict($assignedPlans, $plan)) continue;
|
|
|
|
if ($this->isTimeConflict($assignedPlans, $plan)) continue;
|
|
|
|
@ -721,7 +739,7 @@ private function doSameDaySlotAssign($startDate, $endDate, $regnum, $entrustids,
|
|
|
|
'begin_time' => $plan->begin_time,
|
|
|
|
'begin_time' => $plan->begin_time,
|
|
|
|
'end_time' => $plan->end_time
|
|
|
|
'end_time' => $plan->end_time
|
|
|
|
];
|
|
|
|
];
|
|
|
|
$usedCapacity[$planId] = ($usedCapacity[$planId] ?? 0) + 1;
|
|
|
|
$usedCapacity[$planId] = ($usedCapacity[$planId] ?? 0) + $useSeats;
|
|
|
|
$assignedPlans[] = [
|
|
|
|
$assignedPlans[] = [
|
|
|
|
'resource_name' => $plan->department_resources_name,
|
|
|
|
'resource_name' => $plan->department_resources_name,
|
|
|
|
'begin_time' => $plan->begin_time,
|
|
|
|
'begin_time' => $plan->begin_time,
|
|
|
|
|