医生排班日期的正确插入

This commit is contained in:
HuangXinQuan
2026-02-05 16:00:56 +08:00
parent 74892ea80f
commit f69de5e78f
8 changed files with 161 additions and 6 deletions

View File

@@ -15,6 +15,8 @@ public interface IDoctorScheduleAppService {
R<?> addDoctorSchedule(DoctorSchedule doctorSchedule);
R<?> addDoctorScheduleWithDate(DoctorSchedule doctorSchedule, String scheduledDate);
R<?> updateDoctorSchedule(DoctorSchedule doctorSchedule);
R<?> removeDoctorSchedule(Integer doctorScheduleId);

View File

@@ -177,6 +177,66 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
}
}
@Override
public R<?> addDoctorScheduleWithDate(DoctorSchedule doctorSchedule, String scheduledDate) {
if (ObjectUtil.isEmpty(doctorSchedule)) {
return R.fail("医生排班不能为空");
}
if (doctorSchedule.getLimitNumber() == null || doctorSchedule.getLimitNumber() <= 0) {
return R.fail("限号数量必须大于0");
}
// 创建新对象排除id字段数据库id列是GENERATED ALWAYS由数据库自动生成
DoctorSchedule newSchedule = new DoctorSchedule();
newSchedule.setWeekday(doctorSchedule.getWeekday());
newSchedule.setTimePeriod(doctorSchedule.getTimePeriod());
newSchedule.setDoctor(doctorSchedule.getDoctor());
newSchedule.setClinic(doctorSchedule.getClinic());
newSchedule.setStartTime(doctorSchedule.getStartTime());
newSchedule.setEndTime(doctorSchedule.getEndTime());
newSchedule.setLimitNumber(doctorSchedule.getLimitNumber());
// call_sign_record 字段不能为null设置默认值为空字符串
newSchedule.setCallSignRecord(doctorSchedule.getCallSignRecord() != null ? doctorSchedule.getCallSignRecord() : "");
newSchedule.setRegisterItem(doctorSchedule.getRegisterItem() != null ? doctorSchedule.getRegisterItem() : "");
newSchedule.setRegisterFee(doctorSchedule.getRegisterFee() != null ? doctorSchedule.getRegisterFee() : 0);
newSchedule.setDiagnosisItem(doctorSchedule.getDiagnosisItem() != null ? doctorSchedule.getDiagnosisItem() : "");
newSchedule.setDiagnosisFee(doctorSchedule.getDiagnosisFee() != null ? doctorSchedule.getDiagnosisFee() : 0);
newSchedule.setIsOnline(doctorSchedule.getIsOnline() != null ? doctorSchedule.getIsOnline() : true);
newSchedule.setIsStopped(doctorSchedule.getIsStopped() != null ? doctorSchedule.getIsStopped() : false);
newSchedule.setStopReason(doctorSchedule.getStopReason() != null ? doctorSchedule.getStopReason() : "");
newSchedule.setDeptId(doctorSchedule.getDeptId());
newSchedule.setDoctorId(doctorSchedule.getDoctorId());
// 不设置id字段让数据库自动生成
// 使用自定义的insertWithoutId方法确保INSERT语句不包含id字段
int result = doctorScheduleMapper.insertWithoutId(newSchedule);
if (result > 0) {
// 创建号源池并传入正确的医生ID和具体日期
SchedulePool pool = createSchedulePoolWithDate(newSchedule, doctorSchedule.getDoctorId(), scheduledDate);
boolean poolSaved = schedulePoolService.save(pool);
if (poolSaved) {
// 创建号源槽
List<ScheduleSlot> slots = createScheduleSlots(pool.getId().intValue(), newSchedule.getLimitNumber(),
newSchedule.getStartTime(), newSchedule.getEndTime());
boolean slotsSaved = scheduleSlotService.saveBatch(slots);
if (slotsSaved) {
return R.ok(newSchedule);
} else {
throw new RuntimeException("创建号源槽失败");
}
}
else {
throw new RuntimeException("创建号源池失败");
}
} else {
return R.fail("保存排班信息失败");
}
}
@Override
public R<?> updateDoctorSchedule(DoctorSchedule doctorSchedule) {
if (ObjectUtil.isEmpty(doctorSchedule) || ObjectUtil.isEmpty(doctorSchedule.getId())) {
@@ -227,6 +287,59 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
return pool;
}
/**
* 创建号源池(使用具体日期)
*/
private SchedulePool createSchedulePoolWithDate(DoctorSchedule schedule, Long doctorId, String scheduledDateStr) {
SchedulePool pool = new SchedulePool();
// 生成唯一池编码
pool.setPoolCode("POOL_" + System.currentTimeMillis());
pool.setHospitalId(1L); // 默认医院ID实际项目中应从上下文获取
pool.setDoctorId(doctorId); // 使用正确的医生ID
pool.setDoctorName(schedule.getDoctor());
pool.setDeptId(schedule.getDeptId());
pool.setClinicRoom(schedule.getClinic());
// 使用传入的具体日期
if (scheduledDateStr != null && !scheduledDateStr.isEmpty()) {
try {
LocalDate scheduledDate = LocalDate.parse(scheduledDateStr);
pool.setScheduleDate(scheduledDate);
} catch (Exception e) {
// 如果解析失败,回退到原来的计算方式
pool.setScheduleDate(calculateScheduleDate(schedule.getWeekday()));
}
} else {
// 如果没有提供具体日期,使用原来的计算方式
pool.setScheduleDate(calculateScheduleDate(schedule.getWeekday()));
}
pool.setShift(schedule.getTimePeriod());
pool.setStartTime(schedule.getStartTime());
pool.setEndTime(schedule.getEndTime());
pool.setTotalQuota(schedule.getLimitNumber());
pool.setBookedNum(0);
pool.setLockedNum(0);
// 不设置available_num因为它是数据库生成列
// pool.setAvailableNum(0); // 初始为0稍后更新
pool.setRegType(schedule.getRegisterItem() != null ? schedule.getRegisterItem() : "普通");
pool.setFee(schedule.getRegisterFee() != null ? schedule.getRegisterFee() / 100.0 : 0.0); // 假设数据库中以分为单位存储
pool.setInsurancePrice(pool.getFee()); // 医保价格暂时与原价相同
// 暂时设置support_channel为空字符串避免JSON类型问题
pool.setSupportChannel("");
pool.setStatus(1); // 1表示可用
// 设置时间字段
java.util.Date now = new java.util.Date();
java.util.Date tomorrow = new java.util.Date(System.currentTimeMillis() + 24 * 60 * 60 * 1000); // 明天的时间
pool.setReleaseTime(now);
pool.setDeadlineTime(tomorrow); // 截止时间为明天
pool.setScheduleId(schedule.getId());
return pool;
}
/**
* 创建号源槽
*/

View File

@@ -51,6 +51,17 @@ public class DoctorScheduleController {
return doctorScheduleAppService.addDoctorSchedule(doctorSchedule);
}
/*
* 新增医生排班(带具体日期)
*
* */
@PostMapping("/add-with-date")
public R<?> addDoctorScheduleWithDate(@RequestBody DoctorSchedule doctorSchedule) {
// 从DoctorSchedule对象中获取scheduledDate字段
String scheduledDate = doctorSchedule.getScheduledDate();
return doctorScheduleAppService.addDoctorScheduleWithDate(doctorSchedule, scheduledDate);
}
/*
* 修改医生排班
*