148 lines
3.5 KiB
Markdown
148 lines
3.5 KiB
Markdown
# 医生排班管理 - 数据源更新说明
|
||
|
||
## 更新内容
|
||
|
||
医生数据已更新为从系统管理员表获取,不再使用独立的医生表。
|
||
|
||
## 数据来源
|
||
|
||
### 医生数据
|
||
- **表名**: `zyt_admin`
|
||
- **筛选条件**: `role_id = 1`(医生角色)
|
||
- **字段映射**:
|
||
- `id` → 医生ID
|
||
- `name` 或 `account` → 医生姓名
|
||
|
||
### 排班数据
|
||
- **表名**: `la_doctor_roster`
|
||
- **关联字段**: `doctor_id` 对应 `zyt_admin.id`
|
||
|
||
## 数据库表结构
|
||
|
||
只需要一张排班表:
|
||
|
||
```sql
|
||
CREATE TABLE `la_doctor_roster` (
|
||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||
`doctor_id` int(11) NOT NULL COMMENT '医生ID(对应 zyt_admin.id)',
|
||
`date` date NOT NULL COMMENT '日期',
|
||
`period` varchar(20) NOT NULL COMMENT '时段 morning/afternoon',
|
||
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '1-出诊 2-停诊 3-休息 4-请假',
|
||
`quota` int(11) DEFAULT '0' COMMENT '号源数',
|
||
`max_patients` int(11) DEFAULT '0' COMMENT '最大接诊数',
|
||
`booked_count` int(11) DEFAULT '0' COMMENT '已预约数',
|
||
`remark` varchar(500) DEFAULT '',
|
||
`create_time` int(11) NOT NULL,
|
||
`update_time` int(11) NOT NULL,
|
||
`delete_time` int(11) DEFAULT NULL,
|
||
PRIMARY KEY (`id`),
|
||
UNIQUE KEY `uk_doctor_date_period` (`doctor_id`,`date`,`period`,`delete_time`)
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||
```
|
||
|
||
## API 调用
|
||
|
||
### 获取医生列表
|
||
|
||
```typescript
|
||
import { adminLists } from '@/api/perms/admin'
|
||
|
||
// 获取所有医生(role_id=1)
|
||
const res = await adminLists({
|
||
page_no: 1,
|
||
page_size: 1000,
|
||
role_id: 1
|
||
})
|
||
```
|
||
|
||
### 获取排班数据
|
||
|
||
```typescript
|
||
import { rosterLists } from '@/api/doctor'
|
||
|
||
const res = await rosterLists({
|
||
start_date: '2024-03-04',
|
||
end_date: '2024-03-10'
|
||
})
|
||
```
|
||
|
||
### 保存排班
|
||
|
||
```typescript
|
||
import { rosterSave } from '@/api/doctor'
|
||
|
||
await rosterSave({
|
||
id: 1, // 可选,有则更新,无则新增
|
||
doctor_id: 1,
|
||
date: '2024-03-04',
|
||
period: 'morning',
|
||
status: 1,
|
||
quota: 20
|
||
})
|
||
```
|
||
|
||
## 前端实现
|
||
|
||
### 加载医生列表
|
||
|
||
```typescript
|
||
const loadDoctors = async () => {
|
||
const res = await adminLists({
|
||
page_no: 1,
|
||
page_size: 1000,
|
||
role_id: 1
|
||
})
|
||
|
||
// 转换为表格数据
|
||
tableData.value = (res?.lists || []).map((doctor: any) => ({
|
||
doctorId: doctor.id,
|
||
doctorName: doctor.name || doctor.account,
|
||
rosters: {}
|
||
}))
|
||
}
|
||
```
|
||
|
||
### 加载排班数据
|
||
|
||
```typescript
|
||
const loadRosterData = async () => {
|
||
const res = await rosterLists({
|
||
start_date: currentWeekStart.value.format('YYYY-MM-DD'),
|
||
end_date: currentWeekStart.value.add(6, 'day').format('YYYY-MM-DD')
|
||
})
|
||
|
||
// 填充排班数据到医生行
|
||
const rosters = res?.lists || []
|
||
tableData.value.forEach(doctor => {
|
||
doctor.rosters = {}
|
||
rosters.forEach((roster: any) => {
|
||
if (roster.doctor_id === doctor.doctorId) {
|
||
const key = `${roster.date}_${roster.period}`
|
||
doctor.rosters[key] = {
|
||
id: roster.id,
|
||
status: roster.status,
|
||
quota: roster.quota
|
||
}
|
||
}
|
||
})
|
||
})
|
||
}
|
||
```
|
||
|
||
## 注意事项
|
||
|
||
1. 确保 `zyt_admin` 表中有 `role_id=1` 的用户(医生)
|
||
2. 排班表的 `doctor_id` 必须对应 `zyt_admin` 表中存在的医生ID
|
||
3. 删除排班时使用软删除(设置 `delete_time`)
|
||
4. 同一医生同一天同一时段只能有一条排班记录(通过唯一索引保证)
|
||
|
||
## 后端接口要求
|
||
|
||
后端需要实现以下接口:
|
||
|
||
1. `GET /doctor.roster/lists` - 获取排班列表
|
||
2. `POST /doctor.roster/save` - 保存排班(新增或更新)
|
||
3. `POST /doctor.roster/delete` - 删除排班
|
||
|
||
详细接口文档请参考 `DOCTOR_ROSTER.md`。
|