尚医通day13【预约挂号】(内附源码)

打印 上一主题 下一主题

主题 1658|帖子 1658|积分 4974

页面预览

预约挂号


  • 根据预约周期,展示可预约日期,根据有号、无号、约满等状态展示不同颜色,以示区分
  • 可预约最后一个日期为即将放号日期
  • 选择一个日期展示当天可预约列表

预约确认




第01章-预约挂号

接口分析
(1)根据预约周期,展示可预约日期数据
(2)选择日期展示当天可预约列表
1、获取可预约日期接口

1.1、Controller

service-hosp微服务创建FrontScheduleController
  1. package com.atguigu.syt.hosp.controller.front;
  2. @Api(tags = "排班")
  3. @RestController
  4. @RequestMapping("/front/hosp/schedule")
  5. public class FrontScheduleController {
  6.     @Resource
  7.     private ScheduleService scheduleService;
  8.     @ApiOperation(value = "获取可预约排班日期数据")
  9.     @ApiImplicitParams({
  10.             @ApiImplicitParam(name = "hoscode",value = "医院编码", required = true),
  11.             @ApiImplicitParam(name = "depcode",value = "科室编码", required = true)})
  12.     @GetMapping("getBookingScheduleRule/{hoscode}/{depcode}")
  13.     public Result<Map<String, Object>> getBookingSchedule(
  14.             @PathVariable String hoscode,
  15.             @PathVariable String depcode) {
  16.         Map<String, Object> result = scheduleService.getBookingScheduleRule(hoscode, depcode);
  17.         return Result.ok(result);
  18.     }
  19. }
复制代码
1.2、辅助方法

在ScheduleServiceImpl中添加两个辅助方法
  1. /**
  2.      * 根据日期对象和时间字符串获取一个日期时间对象
  3.      * @param dateTime
  4.      * @param timeString
  5.      * @return
  6.      */
  7. private DateTime getDateTime(DateTime dateTime, String timeString) {
  8.     String dateTimeString = dateTime.toString("yyyy-MM-dd") + " " + timeString;
  9.     return DateTimeFormat.forPattern("yyyy-MM-dd HH:mm").parseDateTime(dateTimeString);
  10. }
复制代码
  1. /**
  2.      * 根据预约规则获取可预约日期列表
  3.      */
  4. private List<Date> getDateList(BookingRule bookingRule) {
  5.     //预约周期
  6.     int cycle = bookingRule.getCycle();
  7.     //当天放号时间
  8.     DateTime releaseTime = this.getDateTime(new DateTime(), bookingRule.getReleaseTime());
  9.     //如果当天放号时间已过,则预约周期后一天显示即将放号,周期加1
  10.     if (releaseTime.isBeforeNow()) {
  11.         cycle += 1;
  12.     }
  13.     //计算当前可显示的预约日期,并且最后一天显示即将放号倒计时
  14.     List<Date> dateList = new ArrayList<>();
  15.     for (int i = 0; i < cycle; i++) {
  16.         //计算当前可显示的预约日期
  17.         DateTime curDateTime = new DateTime().plusDays(i);
  18.         String dateString = curDateTime.toString("yyyy-MM-dd");
  19.         dateList.add(new DateTime(dateString).toDate());
  20.     }
  21.     return dateList;
  22. }
复制代码
1.3、Service

接口:ScheduleService
  1. /**
  2.      * 根据医院编码和科室编码查询医院排班日期列表
  3.      * @param hoscode
  4.      * @param depcode
  5.      * @return
  6.      */
  7. Map<String, Object> getBookingScheduleRule(String hoscode, String depcode);
复制代码
实现:ScheduleServiceImpl
  1. @Resource
  2. private HospitalRepository hospitalRepository;
  3. @Resource
  4. private DepartmentRepository departmentRepository;
复制代码
  1. @Override
  2. public Map<String, Object> getBookingScheduleRule(String hoscode, String depcode) {
  3.     //获取医院
  4.     Hospital hospital = hospitalRepository.findByHoscode(hoscode);
  5.     //获取预约规则
  6.     BookingRule bookingRule = hospital.getBookingRule();
  7.     //根据预约规则获取可预约日期列表
  8.     List<Date> dateList = this.getDateList(bookingRule);
  9.     //查询条件:根据医院编号、科室编号以及预约日期查询
  10.     Criteria criteria = Criteria.where("hoscode").is(hoscode).and("depcode").is(depcode).and("workDate").in(dateList);
  11.     //根据工作日workDate期进行分组
  12.     Aggregation agg = Aggregation.newAggregation(
  13.         //查询条件
  14.         Aggregation.match(criteria),
  15.         Aggregation
  16.         //按照日期分组 select workDate as workDate from schedule group by workDate
  17.         .group("workDate").first("workDate").as("workDate")
  18.         //剩余预约数
  19.         .sum("availableNumber").as("availableNumber")
  20.     );
  21.     //执行查询
  22.     AggregationResults<BookingScheduleRuleVo> aggResults = mongoTemplate.aggregate(agg, Schedule.class, BookingScheduleRuleVo.class);
  23.     //获取查询结果
  24.     List<BookingScheduleRuleVo> list = aggResults.getMappedResults();
  25.     //将list转换成Map,日期为key,BookingScheduleRuleVo对象为value
  26.     Map<Date, BookingScheduleRuleVo> scheduleVoMap = new HashMap<>();
  27.     if (!CollectionUtils.isEmpty(list)) {
  28.         scheduleVoMap = list.stream().collect(
  29.             Collectors.toMap(bookingScheduleRuleVo -> bookingScheduleRuleVo.getWorkDate(), bookingScheduleRuleVo -> bookingScheduleRuleVo)
  30.         );
  31.     }
  32.     //获取可预约排班规则
  33.     List<BookingScheduleRuleVo> bookingScheduleRuleVoList = new ArrayList<>();
  34.     int size = dateList.size();
  35.     for (int i = 0; i < size; i++) {
  36.         Date date = dateList.get(i);
  37.         BookingScheduleRuleVo bookingScheduleRuleVo = scheduleVoMap.get(date);
  38.         if (bookingScheduleRuleVo == null) { // 说明当天没有排班数据
  39.             bookingScheduleRuleVo = new BookingScheduleRuleVo();
  40.             bookingScheduleRuleVo.setWorkDate(date);
  41.             //科室剩余预约数  -1表示无号
  42.             bookingScheduleRuleVo.setAvailableNumber(-1);
  43.         }
  44.         bookingScheduleRuleVo.setWorkDateMd(date);
  45.         //计算当前预约日期为周几
  46.         String dayOfWeek = DateUtil.getDayOfWeek(new DateTime(date));
  47.         bookingScheduleRuleVo.setDayOfWeek(dayOfWeek);
  48.         if (i == size - 1) { //最后一条记录为即将放号
  49.             bookingScheduleRuleVo.setStatus(1);
  50.         } else {
  51.             bookingScheduleRuleVo.setStatus(0);
  52.         }
  53.         //设置预约状态: 0正常; 1即将放号; -1当天已停止挂号
  54.         if (i == 0) { //当天如果过了停挂时间, 则不能挂号
  55.             DateTime stopTime = this.getDateTime(new DateTime(), bookingRule.getStopTime());
  56.             if (stopTime.isBeforeNow()) {
  57.                 bookingScheduleRuleVo.setStatus(-1);//停止挂号
  58.             }
  59.         }
  60.         bookingScheduleRuleVoList.add(bookingScheduleRuleVo);
  61.     }
  62.     //医院基本信息
  63.     Map<String, String> info = new HashMap<>();
  64.     //医院名称
  65.     info.put("hosname", hospitalRepository.findByHoscode(hoscode).getHosname());
  66.     //科室
  67.     Department department = departmentRepository.findByHoscodeAndDepcode(hoscode, depcode);
  68.     //大科室名称
  69.     info.put("bigname", department.getBigname());
  70.     //科室名称
  71.     info.put("depname", department.getDepname());
  72.     //当前月份
  73.     info.put("workDateString", new DateTime().toString("yyyy年MM月"));
  74.     //放号时间
  75.     info.put("releaseTime", bookingRule.getReleaseTime());
  76.     Map<String, Object> result = new HashMap<>();
  77.     //可预约日期数据
  78.     result.put("bookingScheduleList", bookingScheduleRuleVoList);//排班日期列表
  79.     result.put("info", info);//医院基本信息
  80.     return result;
  81. }
复制代码
2、获取排班数据接口

2.1、Controller

在FrontScheduleController添加方法
  1. @ApiOperation("获取排班数据")
  2. @ApiImplicitParams({
  3.             @ApiImplicitParam(name = "hoscode",value = "医院编码", required = true),
  4.             @ApiImplicitParam(name = "depcode",value = "科室编码", required = true),
  5.             @ApiImplicitParam(name = "workDate",value = "排班日期", required = true)})
  6. @GetMapping("getScheduleList/{hoscode}/{depcode}/{workDate}")
  7. public Result<List<Schedule>> getScheduleList(
  8.     @PathVariable String hoscode,
  9.     @PathVariable String depcode,
  10.     @PathVariable String workDate) {
  11.     List<Schedule> scheduleList = scheduleService.getScheduleList(hoscode, depcode, workDate);
  12.     return Result.ok(scheduleList);
  13. }
复制代码
2.2、Service

之前已经实现的业务
注意:如果我们在MongoDB集合的实体中使用了ObjectId作为唯一标识,那么需要对数据进行如下转换,以便将字符串形式的id传到前端
  1. @Override
  2. public List<Schedule> getScheduleList(String hoscode, String depcode, String workDate) {
  3.     //注意:最后一个参数需要进行数据类型的转换
  4.     List<Schedule> scheduleList = scheduleRepository.findByHoscodeAndDepcodeAndWorkDate(
  5.             hoscode,
  6.             depcode,
  7.             new DateTime(workDate).toDate());//数据类型的转换
  8.     //id为ObjectId类型时需要进行转换
  9.     scheduleList.forEach(schedule -> {
  10.         schedule.getParam().put("id", schedule.getId().toString());
  11.     });
  12.     return scheduleList;
  13. }
复制代码
3、前端整合

3.1、预约挂号页面跳转

修改/pages/hospital/_hoscode.vue组件的schedule方法
添加模块引用:
  1. import cookie from 'js-cookie'
  2. import userInfoApi from '~/api/userInfo'
复制代码
methods中添加如下方法:
  1. schedule(depcode) {
  2.   //window.location.href = '/hospital/schedule?hoscode=' + this.$route.params.hoscode + "&depcode="+ depcode
  3.   // 登录判断
  4.   let token = cookie.get('refreshToken')
  5.   if (!token) {
  6.     this.$alert('请先进行用户登录', { type: 'warning' })
  7.     return
  8.   }
  9.   //判断认证
  10.   userInfoApi.getUserInfo().then((response) => {
  11.     let authStatus = response.data.authStatus
  12.     // 状态为2认证通过
  13.     if (authStatus != 2) {
  14.       this.$alert('请先进行用户认证', {
  15.         type: 'warning',
  16.         callback: () => {
  17.           window.location.href = '/user'
  18.         },
  19.       })
  20.       return
  21.     }
  22.     window.location.href =
  23.       '/hospital/schedule?hoscode=' +
  24.       this.$route.params.hoscode +
  25.       '&depcode=' +
  26.       depcode
  27.   })
  28. }
复制代码
3.2、api

在api/hosp.js添加方法
  1. //获取可预约排班日期列表
  2. getBookingScheduleRule(hoscode, depcode) {
  3.   return request({
  4.     url: `/front/hosp/schedule/getBookingScheduleRule/${hoscode}/${depcode}`,
  5.     method: 'get'
  6.   })
  7. },
  8. //获取排班数据
  9. getScheduleList(hoscode, depcode, workDate) {
  10.   return request({
  11.     url: `/front/hosp/schedule/getScheduleList/${hoscode}/${depcode}/${workDate}`,
  12.     method: 'get'
  13.   })
  14. },
复制代码
3.3、页面渲染

/pages/hospital/schedule.vue
第02章-预约确认

1、后端接口

1.1、Controller

在FrontScheduleController中添加方法
  1. @ApiOperation("获取预约详情")
  2. @ApiImplicitParam(name = "id",value = "排班id", required = true)
  3. @GetMapping("getScheduleDetail/{id}")
  4. public Result<Schedule> getScheduleDetail(@PathVariable String id) {
  5.     Schedule schedule = scheduleService.getDetailById(id);
  6.     return Result.ok(schedule);
  7. }
复制代码
1.2、Service

接口:ScheduleService
  1. /**
  2.      * 排班记录详情
  3.      * @param id
  4.      * @return
  5.      */
  6. Schedule getDetailById(String id);
复制代码
实现:ScheduleServiceImpl
  1. @Override
  2. public Schedule getDetailById(String id) {
  3.     Schedule schedule = scheduleRepository.findById(new ObjectId(id)).get();
  4.     return this.packSchedule(schedule);
  5. }
复制代码
辅助方法
  1. /**
  2.      * 封装医院名称,科室名称和周几
  3.      * @param schedule
  4.      * @return
  5.      */
  6. private Schedule packSchedule(Schedule schedule) {
  7.     //医院名称
  8.     String hosname = hospitalRepository.findByHoscode(schedule.getHoscode()).getHosname();
  9.     //科室名称
  10.     String depname = departmentRepository.findByHoscodeAndDepcode(schedule.getHoscode(),schedule.getDepcode()).getDepname();
  11.     //周几
  12.     String dayOfWeek = DateUtil.getDayOfWeek(new DateTime(schedule.getWorkDate()));
  13.    
  14.     Integer workTime = schedule.getWorkTime();
  15.     String workTimeString = workTime.intValue() == 0 ? "上午" : "下午";
  16.    
  17.     schedule.getParam().put("hosname",hosname);
  18.     schedule.getParam().put("depname",depname);
  19.     schedule.getParam().put("dayOfWeek",dayOfWeek);
  20.     schedule.getParam().put("workTimeString", workTimeString);
  21.    
  22.           //id为ObjectId类型时需要进行转换
  23.     schedule.getParam().put("id",schedule.getId().toString());
  24.     return schedule;
  25. }
复制代码
2、前端整合

2.1、api

在api/hosp.js添加方法
  1. //获取预约详情
  2. getScheduleDetail(id) {
  3.     return request({
  4.         url: `/front/hosp/schedule/getScheduleDetail/${id}`,
  5.         method: 'get'
  6.     })
  7. }
复制代码
2.2、页面渲染

pages/hospital/booking.vue
源码:https://gitee.com/dengyaojava/guigu-syt-parent

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

九天猎人

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表