【发布时间】:2018-09-24 15:22:03
【问题描述】:
我正在为移动应用程序开发一个spring boot MVC REST API,该系统是诊所的病人预约,我正在寻找显示医生可用时间问题的最佳解决方案。
问题定义:系统应允许用户从日历中选择诊所、医生和具体日期(年/月/日),系统将显示所选日期的可用时间,预约时间为30从早上 7 点到下午 6 点。
更多说明: 该系统由许多诊所组成,医生属于这些诊所,每个医生都有固定的时间供用户预订。这些时间分为每个半小时约会的日期。用户不能同时预约同一个医生。
示例: 患者 Joey 在 2018 年 5 月 21 日 3:30 预约了医生 x , 另一位患者 Jack 已打开应用程序进行预约 他选择医生 x 并选择与 joey 相同的日期(2018 年 5 月 21 日) 系统将显示从早上 7 点到下午 6 点(7 :00 和 7:30)的可用时间, 8:00 , 8:30 ......) 不包括 3:30 。
尝试的解决方案: 1) 在数据库中填写每年的可用时间并用标志标记时间。 2)当客户询问可用时间时,系统会遍历医生的所有预约并找到这些时间。 3)制作一个包含时间和日期的静态列表,当用户询问可用时间时,迭代约会并从列表中删除属于约会的时间。 4)制作数据库日历。 5)让管理页面的用户从管理页面手动填写时间。 我尝试了所有这些可能的解决方案,但我没有发现它们非常有效,我正在寻找更好的解决方案。
代码示例: 控制器部分:
@RequestMapping(method = RequestMethod.GET , value = "/availabletimes")
public ResponseEntity<ResponseUtil> getAvailableTimes(@RequestParam String date){
try {
return new ResponseEntity<ResponseUtil> (new ResponseUtil(200, Constants.SUCCESS_STATUS, "Cancelled", service.getAvailableTimes(date)),HttpStatus.OK);
}catch (BackendException e) {
return new ResponseEntity<ResponseUtil> (new ResponseUtil(403, Constants.FAILED_STATUS, e.getMessage(), null),HttpStatus.FORBIDDEN);
}
}
服务实现:
@Override
public List<String> getAvailableTimes(String date) {
List<String> availableTimes = findAvailableTimes(date);
if(availableTimes == null || availableTimes.isEmpty())
throw new BackendException("No times available for the given date");
return availableTimes;
}
private List<String> findAvailableTimes(String date){
//TODO write the logic for findding the available times
return null;
}
存储库:
public interface AppointmentRepo extends IRepository<Appointment, Long> {
List<Appointment> findByCustomer(Customer customer);
}
实体:
@Entity
public class Appointment extends BaseEntity {
/**
*
*/
private static final long serialVersionUID = 1L;
private Date appoitmentDate;
// Relations
@ManyToOne(fetch = FetchType.LAZY)
private Doctor doctor;
@ManyToOne(fetch = FetchType.LAZY)
private Clinic clinic;
@ManyToOne(fetch = FetchType.LAZY)
private Customer customer;
@ManyToOne(fetch = FetchType.LAZY)
private Follower follower;
@ManyToOne(fetch = FetchType.LAZY)
private AppointmentStatus appointmentStatus;
@OneToOne(fetch = FetchType.LAZY)
private Report report;
// Setters and Getters
public Doctor getDoctor() {
return doctor;
}
public void setDoctor(Doctor doctor) {
this.doctor = doctor;
}
public Clinic getClinic() {
return clinic;
}
public void setClinic(Clinic clinic) {
this.clinic = clinic;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public Follower getFollower() {
return follower;
}
public void setFollower(Follower follower) {
this.follower = follower;
}
public Date getAppoitmentDate() {
return appoitmentDate;
}
public void setAppoitmentDate(Date appoitmentDate) {
this.appoitmentDate = appoitmentDate;
}
public AppointmentStatus getAppointmentStatus() {
return appointmentStatus;
}
public void setAppointmentStatus(AppointmentStatus appointmentStatus) {
this.appointmentStatus = appointmentStatus;
}
public Report getReport() {
return report;
}
public void setReport(Report report) {
this.report = report;
}
}
【问题讨论】:
-
抱歉,这个问题太宽泛了。
-
我无法理解列出的五个解决方案中的任何一个。而且,效率在什么意义上?您需要一个大表、几个索引和一个 SQL 查询,因此它必须很快,除非您使用 TB 级数据运行它。
-
if(availableTimes == null || availableTimes.isEmpty()) throw new BackendException("No times available for the given date");这感觉不对。 1.永远不要让你的方法不必要地返回null。 2. 一个空列表就是这样:一个空列表。没有错误。
标签: java mysql performance spring-mvc spring-boot