diff --git a/Laravel/app/Http/Controllers/API/Admin/YeWu/PlanListController.php b/Laravel/app/Http/Controllers/API/Admin/YeWu/PlanListController.php index 59d9f41..68b17ae 100644 --- a/Laravel/app/Http/Controllers/API/Admin/YeWu/PlanListController.php +++ b/Laravel/app/Http/Controllers/API/Admin/YeWu/PlanListController.php @@ -200,9 +200,17 @@ public function GetEnablePlan() $episodeid = request('episodeid'); $appointment_type = request('appointment_type'); //预约类型 $appointment_date = request('date'); //预约日期 + $scope = request('scope', 'all'); + $do_user = request('do_user', 0); + + $userDeptId = 0; + if ($do_user) { + $user = DB::table('users')->find($do_user); + $userDeptId = $user->department_id ?? 0; + } $service = new PlanListService(); - return $service->GetEnablePlan($regnum, $entrustid, $episodeid, $appointment_type, $appointment_date); + return $service->GetEnablePlan($regnum, $entrustid, $episodeid, $appointment_type, $appointment_date, $scope, $userDeptId); } //最优时间/单天全检 分配 diff --git a/Laravel/app/Http/Controllers/API/Admin/YeWu/WorkMainController.php b/Laravel/app/Http/Controllers/API/Admin/YeWu/WorkMainController.php index 2cfa400..e4e551f 100644 --- a/Laravel/app/Http/Controllers/API/Admin/YeWu/WorkMainController.php +++ b/Laravel/app/Http/Controllers/API/Admin/YeWu/WorkMainController.php @@ -223,6 +223,95 @@ public function GetList(Request $request) return \Yz::Return(true,'查询完成',['list'=>$list,'count'=>$count]); } + //管理员主工作列表(支持科室切换) + public function GetListByDept(Request $request) + { + $searchInfo = request('searchInfo'); + $page = request('page'); + $pageSize = request('pageSize'); + $department_id = request('department_id'); // 0 或空表示全部科室 + + $list = DB::table('s_list') + ->leftJoin('s_period', 's_list.reservation_time', '=', 's_period.id') + ->leftJoin('s_department_resources', 's_list.reservation_sources', '=', 's_department_resources.id') + ->select('s_list.*', 's_period.period_begin_time', 's_period.period_end_time', 's_department_resources.department_resources_name') + ->where(['s_list.is_del' => 0, 's_list.is_nullify' => 0]); + + // 选中具体科室时,按科室编号过滤 + if (!empty($department_id)) { + $deptNumbers = DB::table('s_department') + ->where('is_del', 0) + ->where(function ($q) use ($department_id) { + $q->where('id', $department_id) + ->orWhere('pid', $department_id); + }) + ->pluck('department_number'); + + $list = $list->where(function ($q) use ($deptNumbers) { + $q->whereIn('RISRAcceptDeptCode', $deptNumbers) + ->orWhereIn('reservation_department_code', $deptNumbers); + }); + } + + // 搜索条件(与 GetList 保持一致) + $dateType = $searchInfo['dateType'] ?? 'reservation_date'; + if ($searchInfo['dateRange'] != null and count($searchInfo['dateRange']) == 2) { + if ($dateType === 'both') { + $list = $list->where(function ($q) use ($searchInfo) { + $q->whereBetween('s_list.entrust_date', $searchInfo['dateRange']) + ->orWhereBetween('s_list.reservation_date', $searchInfo['dateRange']); + }); + } elseif ($dateType === 'entrust_date') { + $list = $list->whereBetween('s_list.entrust_date', $searchInfo['dateRange']); + } else { + $list = $list->whereBetween('s_list.reservation_date', $searchInfo['dateRange']); + } + } + if (isset($searchInfo['list_status'])) { + $list = $list->where('s_list.list_status', $searchInfo['list_status']); + } + if (isset($searchInfo['patient_type'])) { + $list = $list->where('s_list.patient_type', $searchInfo['patient_type']); + } + if (!empty($searchInfo['resources'])) { + $list = $list->whereIn('s_list.reservation_sources', $searchInfo['resources']); + } + if (isset($searchInfo['services_group'])) { + $list = $list->whereRaw("FIND_IN_SET(?, s_list.services_group)", [$searchInfo['services_group']]); + } + if (isset($searchInfo['reg_num'])) { + $list = $list->where('s_list.reg_num', $searchInfo['reg_num']); + } + if (isset($searchInfo['user_name'])) { + $list = $list->where('s_list.user_name', 'like', '%' . $searchInfo['user_name'] . '%'); + } + if (isset($searchInfo['doctor'])) { + $list = $list->where('s_list.docotr', 'like', '%' . $searchInfo['doctor'] . '%'); + } + if (isset($searchInfo['apply_department'])) { + $list = $list->where('s_list.reservation_department', 'like', '%' . $searchInfo['apply_department'] . '%'); + } + + $count = $list; + $count = $count->count(); + $list = $list->orderBy('id', 'desc')->limit($pageSize)->skip(($page - 1) * $pageSize) + ->take($pageSize)->get(); + + // 匹配设备(服务组) + $devices = DB::table('s_devices')->get(); + foreach ($list as $key => $value) { + $list[$key]->age = \Tools::calculateAgeText($value->user_brithday); + $list[$key]->devices = []; + $array_device_id = explode(",", $value->services_group); + foreach ($devices as $k => $v) { + if (in_array($v->id, $array_device_id)) { + $list[$key]->devices[] = $v; + } + } + } + return \Yz::Return(true, '查询完成', ['list' => $list, 'count' => $count]); + } + //获取医嘱变更日志 public function GetLoglist() { diff --git a/Laravel/app/Services/Admin/YeWu/PlanListService.php b/Laravel/app/Services/Admin/YeWu/PlanListService.php index e576c66..e1b28c2 100644 --- a/Laravel/app/Services/Admin/YeWu/PlanListService.php +++ b/Laravel/app/Services/Admin/YeWu/PlanListService.php @@ -65,12 +65,14 @@ public function GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_typ } $commonDevice = []; //多个检查项目共同的设备id + $first = true; foreach ($allDevice as $set) { - if (count($commonDevice) == 0) { - // 如果$intersection为空,直接将第一个子数组的元素放入 + if ($first) { + // 首次迭代:直接取第一个项目的设备 $commonDevice = $set; + $first = false; } else { - // 使用array_intersect()函数求当前子数组与已有交集的交集 + // 后续迭代:取交集,交集为空则保持空,不再重置 $commonDevice = array_intersect($commonDevice, $set); } } @@ -319,7 +321,7 @@ public function GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_typ $grouped[$name]['plans'][] = $plan; // 累计全天总剩余 - $remaining = ($plan->count ?? 0) - ($plan->used_count ?? 0) - ($plan->locked_count ?? 0); + $remaining = ($plan->count ?? 0) - ($plan->used_count ?? 0); $grouped[$name]['remaining'] += max($remaining, 0); // 判断是否未过期,收集最早开始时间及该时段剩余 @@ -439,60 +441,89 @@ public function GetOptimalPlan($type, $regnum, $entrustids, $episodeid, $appoint } } - // 最优时间分配:逐个 item 找最早可用号源,可跨天 + // 最优时间分配:按科室分组,逐个 item 找最早可用号源,可跨天 private function doOptimalTimeAssign($startDate, $endDate, $regnum, $entrustids, $episodeid, $appointment_type, $items, $scope, $userDeptId) { + // 按科室分组 + $deptGroups = $this->groupItemsByDept($items); + if (empty($deptGroups)) { + return \Yz::Return(true, '获取成功', []); + } + $result = []; - $usedCapacity = []; - $assignedPlans = []; // 已分配的时间段 [{resource_name, begin, end}] $currentDate = clone $startDate; - $remainingItems = $items; + // 每组待分配的 items + $remainingGroups = []; + foreach ($deptGroups as $deptCode => $group) { + $remainingGroups[$deptCode] = [ + 'entrustids' => $group['entrustids'], + 'items' => $group['items'] + ]; + } - while ($currentDate <= $endDate && !empty($remainingItems)) { + while ($currentDate <= $endDate && !empty($remainingGroups)) { $nowdate = $currentDate->format('Y-m-d'); - $availablePlans = $this->getAvailablePlansForDate($regnum, $entrustids, $episodeid, $appointment_type, $nowdate, $scope, $userDeptId); + $newRemainingGroups = []; - if (empty($availablePlans)) { - $currentDate->modify('+1 day'); - continue; - } + foreach ($remainingGroups as $deptCode => $group) { + $groupEntrustids = $group['entrustids']; + $groupItems = $group['items']; - $newRemaining = []; - foreach ($remainingItems as $item) { - $assigned = false; - foreach ($availablePlans as $plan) { - $planId = $plan->id; - $remaining = ($plan->count ?? 0) - ($plan->used_count ?? 0) - ($plan->locked_count ?? 0); - $used = $usedCapacity[$planId] ?? 0; + $availablePlans = $this->getAvailablePlansForDate($regnum, $groupEntrustids, $episodeid, $appointment_type, $nowdate, $scope, $userDeptId); - if (($remaining - $used) <= 0) continue; + if (empty($availablePlans)) { + // 当天该科室无号源,整组留到下一轮 + $newRemainingGroups[$deptCode] = $group; + continue; + } - // 冲突检查:不同排班且时间段重叠 - if ($this->isTimeConflict($assignedPlans, $plan)) continue; + $usedCapacity = []; + $assignedPlans = []; + $remainingItems = []; + + foreach ($groupItems as $item) { + $assigned = false; + foreach ($availablePlans as $plan) { + $planId = $plan->id; + $remaining = ($plan->count ?? 0) - ($plan->used_count ?? 0); + $used = $usedCapacity[$planId] ?? 0; + + if (($remaining - $used) <= 0) continue; + + // 冲突检查:同一科室组内,不同排班时间不能重叠 + if ($this->isTimeConflict($assignedPlans, $plan)) continue; + + $result[] = [ + 'id' => $item['id'], + 'plan_id' => $planId, + 'department_resources_name' => $plan->department_resources_name, + 'date' => $plan->date, + 'begin_time' => $plan->begin_time, + 'end_time' => $plan->end_time + ]; + $usedCapacity[$planId] = ($usedCapacity[$planId] ?? 0) + 1; + $assignedPlans[] = [ + 'resource_name' => $plan->department_resources_name, + 'begin_time' => $plan->begin_time, + 'end_time' => $plan->end_time + ]; + $assigned = true; + break; + } + if (!$assigned) { + $remainingItems[] = $item; + } + } - // 分配 - $result[] = [ - 'id' => $item['id'], - 'plan_id' => $planId, - 'department_resources_name' => $plan->department_resources_name, - 'date' => $plan->date, - 'begin_time' => $plan->begin_time, - 'end_time' => $plan->end_time - ]; - $usedCapacity[$planId] = ($usedCapacity[$planId] ?? 0) + 1; - $assignedPlans[] = [ - 'resource_name' => $plan->department_resources_name, - 'begin_time' => $plan->begin_time, - 'end_time' => $plan->end_time + if (!empty($remainingItems)) { + $newRemainingGroups[$deptCode] = [ + 'entrustids' => $groupEntrustids, + 'items' => $remainingItems ]; - $assigned = true; - break; - } - if (!$assigned) { - $newRemaining[] = $item; } } - $remainingItems = $newRemaining; + + $remainingGroups = $newRemainingGroups; $currentDate->modify('+1 day'); } @@ -502,55 +533,64 @@ private function doOptimalTimeAssign($startDate, $endDate, $regnum, $entrustids, // 单天全检分配:所有 item 必须在同一天完成 private function doFullDayAssign($startDate, $endDate, $regnum, $entrustids, $episodeid, $appointment_type, $items, $scope, $userDeptId) { + // 按科室分组 + $deptGroups = $this->groupItemsByDept($items); + if (empty($deptGroups)) { + return \Yz::Return(true, '获取成功', []); + } + $currentDate = clone $startDate; while ($currentDate <= $endDate) { $nowdate = $currentDate->format('Y-m-d'); - $availablePlans = $this->getAvailablePlansForDate($regnum, $entrustids, $episodeid, $appointment_type, $nowdate, $scope, $userDeptId); - - if (empty($availablePlans)) { - $currentDate->modify('+1 day'); - continue; - } - - $result = []; - $usedCapacity = []; - $assignedPlans = []; $allAssigned = true; + $result = []; - foreach ($items as $item) { - $assigned = false; - foreach ($availablePlans as $plan) { - $planId = $plan->id; - $remaining = ($plan->count ?? 0) - ($plan->used_count ?? 0) - ($plan->locked_count ?? 0); - $used = $usedCapacity[$planId] ?? 0; - - if (($remaining - $used) <= 0) continue; - - // 冲突检查:不同排班且时间段重叠 - if ($this->isTimeConflict($assignedPlans, $plan)) continue; - - $result[] = [ - 'id' => $item['id'], - 'plan_id' => $planId, - 'department_resources_name' => $plan->department_resources_name, - 'date' => $plan->date, - 'begin_time' => $plan->begin_time, - 'end_time' => $plan->end_time - ]; - $usedCapacity[$planId] = ($usedCapacity[$planId] ?? 0) + 1; - $assignedPlans[] = [ - 'resource_name' => $plan->department_resources_name, - 'begin_time' => $plan->begin_time, - 'end_time' => $plan->end_time - ]; - $assigned = true; - break; - } - if (!$assigned) { + foreach ($deptGroups as $deptCode => $group) { + $availablePlans = $this->getAvailablePlansForDate($regnum, $group['entrustids'], $episodeid, $appointment_type, $nowdate, $scope, $userDeptId); + + if (empty($availablePlans)) { $allAssigned = false; break; } + + $usedCapacity = []; + $assignedPlans = []; + + foreach ($group['items'] as $item) { + $assigned = false; + foreach ($availablePlans as $plan) { + $planId = $plan->id; + $remaining = ($plan->count ?? 0) - ($plan->used_count ?? 0); + $used = $usedCapacity[$planId] ?? 0; + + if (($remaining - $used) <= 0) continue; + + // 冲突检查:同一科室组内,不同排班时间不能重叠 + if ($this->isTimeConflict($assignedPlans, $plan)) continue; + + $result[] = [ + 'id' => $item['id'], + 'plan_id' => $planId, + 'department_resources_name' => $plan->department_resources_name, + 'date' => $plan->date, + 'begin_time' => $plan->begin_time, + 'end_time' => $plan->end_time + ]; + $usedCapacity[$planId] = ($usedCapacity[$planId] ?? 0) + 1; + $assignedPlans[] = [ + 'resource_name' => $plan->department_resources_name, + 'begin_time' => $plan->begin_time, + 'end_time' => $plan->end_time + ]; + $assigned = true; + break; + } + if (!$assigned) { + $allAssigned = false; + break 2; + } + } } if ($allAssigned) { @@ -612,6 +652,33 @@ private function isTimeConflict($assignedPlans, $plan) return false; } + // 按科室分组 items:相同 RISRAcceptDeptCode 的归为一组 + private function groupItemsByDept($items) + { + $groups = []; + foreach ($items as $item) { + $entrustId = $item['entrust_id'] ?? null; + if (!$entrustId) continue; + + $list = DB::table('s_list') + ->where(['entrust_id' => $entrustId, 'is_nullify' => 0]) + ->first(); + if (!$list) continue; + + $deptCode = $list->RISRAcceptDeptCode ?: 'unknown'; + + if (!isset($groups[$deptCode])) { + $groups[$deptCode] = [ + 'entrustids' => [], + 'items' => [] + ]; + } + $groups[$deptCode]['entrustids'][] = $entrustId; + $groups[$deptCode]['items'][] = $item; + } + return $groups; + } + //开始预约占用名额 public function YuYue($planid, $appointment_type, $mainlistids, $do_type,$is_emergency=0,$do_user=null) { diff --git a/Laravel/routes/api.php b/Laravel/routes/api.php index fbc22e5..c4a80b2 100644 --- a/Laravel/routes/api.php +++ b/Laravel/routes/api.php @@ -123,6 +123,7 @@ Route::post('admin/PlanListDel','App\Http\Controllers\API\Admin\YeWu\PlanListController@Del');//删除计划详情 Route::post('admin/SaveLockedCount','App\Http\Controllers\API\Admin\YeWu\PlanListController@SaveLockedCount');//保存占位数量 Route::post('admin/GetMainList','App\Http\Controllers\API\Admin\YeWu\WorkMainController@GetList');//获取主表列表 + Route::post('admin/GetMainListByDept','App\Http\Controllers\API\Admin\YeWu\WorkMainController@GetListByDept');//管理员获取主表列表(支持科室切换) Route::post('admin/GetLoglist','App\Http\Controllers\API\Admin\YeWu\WorkMainController@GetLoglist');//获取日志 Route::post('admin/CancelYuYue','App\Http\Controllers\API\Admin\YeWu\PlanListController@CancelYuYue');//取消预约 Route::post('admin/SetHuChi','App\Http\Controllers\API\Admin\YeWu\CheckItemController@SetHuChi');//设置互斥 diff --git a/YiJi-admin/src/api/api.js b/YiJi-admin/src/api/api.js index fcbcc1e..3b386e0 100644 --- a/YiJi-admin/src/api/api.js +++ b/YiJi-admin/src/api/api.js @@ -371,6 +371,10 @@ export const PlanDetailPlanListDelAdmin = (data = {}) => { export const GetMainList = (data = {}) => { return axios({ url: import.meta.env.VITE_APP_API + 'v1/admin/GetMainList', data: data }) } +//admin获取主表列表(支持科室切换) +export const GetMainListByDept = (data = {}) => { + return axios({ url: import.meta.env.VITE_APP_API + 'v1/admin/GetMainListByDept', data: data }) +} //模糊搜索科室 export const SearchDepartment = (data = {}) => { return axios({ url: import.meta.env.VITE_APP_API + 'v1/admin/SearchDepartment', data: data }) diff --git a/YiJi-admin/src/components/Yewu/YuYue202506.vue b/YiJi-admin/src/components/Yewu/YuYue202506.vue index 7e0c5e3..2471713 100644 --- a/YiJi-admin/src/components/Yewu/YuYue202506.vue +++ b/YiJi-admin/src/components/Yewu/YuYue202506.vue @@ -23,9 +23,9 @@ 正常 - +