尚醫通day13【預約掛號】(內附源碼)

来源:https://www.cnblogs.com/deyo/archive/2023/06/18/17489022.html
-Advertisement-
Play Games

# 頁面預覽 ## 預約掛號 - 根據預約周期,展示可預約日期,根據有號、無號、約滿等狀態展示不同顏色,以示區分 - 可預約最後一個日期為即將放號日期 - 選擇一個日期展示當天可預約列表 ![image-20230227202834422](https://s2.loli.net/2023/06/1 ...


頁面預覽

預約掛號

  • 根據預約周期,展示可預約日期,根據有號、無號、約滿等狀態展示不同顏色,以示區分
  • 可預約最後一個日期為即將放號日期
  • 選擇一個日期展示當天可預約列表

image-20230227202834422

預約確認

image-20230227203321417

image-20230227203620732

image-20230226175848111

第01章-預約掛號

介面分析

(1)根據預約周期,展示可預約日期數據

(2)選擇日期展示當天可預約列表

1、獲取可預約日期介面

1.1、Controller

service-hosp微服務創建FrontScheduleController

package com.atguigu.syt.hosp.controller.front;

@Api(tags = "排班")
@RestController
@RequestMapping("/front/hosp/schedule")
public class FrontScheduleController {

    @Resource
    private ScheduleService scheduleService;

    @ApiOperation(value = "獲取可預約排班日期數據")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hoscode",value = "醫院編碼", required = true),
            @ApiImplicitParam(name = "depcode",value = "科室編碼", required = true)})
    @GetMapping("getBookingScheduleRule/{hoscode}/{depcode}")
    public Result<Map<String, Object>> getBookingSchedule(
            @PathVariable String hoscode,
            @PathVariable String depcode) {

        Map<String, Object> result = scheduleService.getBookingScheduleRule(hoscode, depcode);
        return Result.ok(result);
    }

}

1.2、輔助方法

在ScheduleServiceImpl中添加兩個輔助方法

/**
     * 根據日期對象和時間字元串獲取一個日期時間對象
     * @param dateTime
     * @param timeString
     * @return
     */
private DateTime getDateTime(DateTime dateTime, String timeString) {
    String dateTimeString = dateTime.toString("yyyy-MM-dd") + " " + timeString;
    return DateTimeFormat.forPattern("yyyy-MM-dd HH:mm").parseDateTime(dateTimeString);
}
/**
     * 根據預約規則獲取可預約日期列表
     */
private List<Date> getDateList(BookingRule bookingRule) {
    //預約周期
    int cycle = bookingRule.getCycle();
    //當天放號時間
    DateTime releaseTime = this.getDateTime(new DateTime(), bookingRule.getReleaseTime());
    //如果當天放號時間已過,則預約周期後一天顯示即將放號,周期加1
    if (releaseTime.isBeforeNow()) {
        cycle += 1;
    }
    //計算當前可顯示的預約日期,並且最後一天顯示即將放號倒計時
    List<Date> dateList = new ArrayList<>();
    for (int i = 0; i < cycle; i++) {
        //計算當前可顯示的預約日期
        DateTime curDateTime = new DateTime().plusDays(i);
        String dateString = curDateTime.toString("yyyy-MM-dd");
        dateList.add(new DateTime(dateString).toDate());
    }
    return dateList;
}

1.3、Service

介面:ScheduleService

/**
     * 根據醫院編碼和科室編碼查詢醫院排班日期列表
     * @param hoscode
     * @param depcode
     * @return
     */
Map<String, Object> getBookingScheduleRule(String hoscode, String depcode);

實現:ScheduleServiceImpl

@Resource
private HospitalRepository hospitalRepository;

@Resource
private DepartmentRepository departmentRepository;
@Override
public Map<String, Object> getBookingScheduleRule(String hoscode, String depcode) {
    //獲取醫院
    Hospital hospital = hospitalRepository.findByHoscode(hoscode);
    //獲取預約規則
    BookingRule bookingRule = hospital.getBookingRule();
    //根據預約規則獲取可預約日期列表
    List<Date> dateList = this.getDateList(bookingRule);
    //查詢條件:根據醫院編號、科室編號以及預約日期查詢
    Criteria criteria = Criteria.where("hoscode").is(hoscode).and("depcode").is(depcode).and("workDate").in(dateList);
    //根據工作日workDate期進行分組
    Aggregation agg = Aggregation.newAggregation(
        //查詢條件
        Aggregation.match(criteria),
        Aggregation
        //按照日期分組 select workDate as workDate from schedule group by workDate
        .group("workDate").first("workDate").as("workDate")
        //剩餘預約數
        .sum("availableNumber").as("availableNumber")
    );
    //執行查詢
    AggregationResults<BookingScheduleRuleVo> aggResults = mongoTemplate.aggregate(agg, Schedule.class, BookingScheduleRuleVo.class);
    //獲取查詢結果
    List<BookingScheduleRuleVo> list = aggResults.getMappedResults();
    //將list轉換成Map,日期為key,BookingScheduleRuleVo對象為value
    Map<Date, BookingScheduleRuleVo> scheduleVoMap = new HashMap<>();
    if (!CollectionUtils.isEmpty(list)) {
        scheduleVoMap = list.stream().collect(
            Collectors.toMap(bookingScheduleRuleVo -> bookingScheduleRuleVo.getWorkDate(), bookingScheduleRuleVo -> bookingScheduleRuleVo)
        );
    }
    //獲取可預約排班規則
    List<BookingScheduleRuleVo> bookingScheduleRuleVoList = new ArrayList<>();
    int size = dateList.size();
    for (int i = 0; i < size; i++) {
        Date date = dateList.get(i);
        BookingScheduleRuleVo bookingScheduleRuleVo = scheduleVoMap.get(date);
        if (bookingScheduleRuleVo == null) { // 說明當天沒有排班數據
            bookingScheduleRuleVo = new BookingScheduleRuleVo();
            bookingScheduleRuleVo.setWorkDate(date);
            //科室剩餘預約數  -1表示無號
            bookingScheduleRuleVo.setAvailableNumber(-1);
        }
        bookingScheduleRuleVo.setWorkDateMd(date);
        //計算當前預約日期為周幾
        String dayOfWeek = DateUtil.getDayOfWeek(new DateTime(date));
        bookingScheduleRuleVo.setDayOfWeek(dayOfWeek);
        if (i == size - 1) { //最後一條記錄為即將放號
            bookingScheduleRuleVo.setStatus(1);
        } else {
            bookingScheduleRuleVo.setStatus(0);
        }

        //設置預約狀態: 0正常; 1即將放號; -1當天已停止掛號
        if (i == 0) { //當天如果過了停掛時間, 則不能掛號
            DateTime stopTime = this.getDateTime(new DateTime(), bookingRule.getStopTime());
            if (stopTime.isBeforeNow()) {
                bookingScheduleRuleVo.setStatus(-1);//停止掛號
            }
        }
        bookingScheduleRuleVoList.add(bookingScheduleRuleVo);
    }
    //醫院基本信息
    Map<String, String> info = new HashMap<>();
    //醫院名稱
    info.put("hosname", hospitalRepository.findByHoscode(hoscode).getHosname());
    //科室
    Department department = departmentRepository.findByHoscodeAndDepcode(hoscode, depcode);
    //大科室名稱
    info.put("bigname", department.getBigname());
    //科室名稱
    info.put("depname", department.getDepname());
    //當前月份
    info.put("workDateString", new DateTime().toString("yyyy年MM月"));
    //放號時間
    info.put("releaseTime", bookingRule.getReleaseTime());
    Map<String, Object> result = new HashMap<>();
    //可預約日期數據
    result.put("bookingScheduleList", bookingScheduleRuleVoList);//排班日期列表
    result.put("info", info);//醫院基本信息
    return result;
}

2、獲取排班數據介面

2.1、Controller

在FrontScheduleController添加方法

@ApiOperation("獲取排班數據")
@ApiImplicitParams({
            @ApiImplicitParam(name = "hoscode",value = "醫院編碼", required = true),
            @ApiImplicitParam(name = "depcode",value = "科室編碼", required = true),
            @ApiImplicitParam(name = "workDate",value = "排班日期", required = true)})
@GetMapping("getScheduleList/{hoscode}/{depcode}/{workDate}")
public Result<List<Schedule>> getScheduleList(
    @PathVariable String hoscode,
    @PathVariable String depcode,
    @PathVariable String workDate) {
    List<Schedule> scheduleList = scheduleService.getScheduleList(hoscode, depcode, workDate);
    return Result.ok(scheduleList);
}

2.2、Service

之前已經實現的業務

註意:如果我們在MongoDB集合的實體中使用了ObjectId作為唯一標識,那麼需要對數據進行如下轉換,以便將字元串形式的id傳到前端

@Override
public List<Schedule> getScheduleList(String hoscode, String depcode, String workDate) {

    //註意:最後一個參數需要進行數據類型的轉換
    List<Schedule> scheduleList = scheduleRepository.findByHoscodeAndDepcodeAndWorkDate(
            hoscode,
            depcode,
            new DateTime(workDate).toDate());//數據類型的轉換

    //id為ObjectId類型時需要進行轉換
    scheduleList.forEach(schedule -> {
        schedule.getParam().put("id", schedule.getId().toString());
    });

    return scheduleList;
}

3、前端整合

3.1、預約掛號頁面跳轉

修改/pages/hospital/_hoscode.vue組件的schedule方法

添加模塊引用:

import cookie from 'js-cookie'
import userInfoApi from '~/api/userInfo'

methods中添加如下方法:

schedule(depcode) {
  //window.location.href = '/hospital/schedule?hoscode=' + this.$route.params.hoscode + "&depcode="+ depcode
  // 登錄判斷
  let token = cookie.get('refreshToken')
  if (!token) {
    this.$alert('請先進行用戶登錄', { type: 'warning' })
    return
  }
  //判斷認證
  userInfoApi.getUserInfo().then((response) => {
    let authStatus = response.data.authStatus
    // 狀態為2認證通過
    if (authStatus != 2) {
      this.$alert('請先進行用戶認證', {
        type: 'warning',
        callback: () => {
          window.location.href = '/user'
        },
      })
      return
    }
    window.location.href =
      '/hospital/schedule?hoscode=' +
      this.$route.params.hoscode +
      '&depcode=' +
      depcode
  })
}

3.2、api

在api/hosp.js添加方法

//獲取可預約排班日期列表
getBookingScheduleRule(hoscode, depcode) {
  return request({
    url: `/front/hosp/schedule/getBookingScheduleRule/${hoscode}/${depcode}`,
    method: 'get'
  })
},

//獲取排班數據
getScheduleList(hoscode, depcode, workDate) {
  return request({
    url: `/front/hosp/schedule/getScheduleList/${hoscode}/${depcode}/${workDate}`,
    method: 'get'
  })
},

3.3、頁面渲染

/pages/hospital/schedule.vue

第02章-預約確認

1、後端介面

1.1、Controller

在FrontScheduleController中添加方法

@ApiOperation("獲取預約詳情")
@ApiImplicitParam(name = "id",value = "排班id", required = true)
@GetMapping("getScheduleDetail/{id}")
public Result<Schedule> getScheduleDetail(@PathVariable String id) {
    Schedule schedule = scheduleService.getDetailById(id);
    return Result.ok(schedule);
}

1.2、Service

介面:ScheduleService

/**
     * 排班記錄詳情
     * @param id
     * @return
     */
Schedule getDetailById(String id);

實現:ScheduleServiceImpl

@Override
public Schedule getDetailById(String id) {
    Schedule schedule = scheduleRepository.findById(new ObjectId(id)).get();
    return this.packSchedule(schedule);
}

輔助方法

/**
     * 封裝醫院名稱,科室名稱和周幾
     * @param schedule
     * @return
     */
private Schedule packSchedule(Schedule schedule) {
    //醫院名稱
    String hosname = hospitalRepository.findByHoscode(schedule.getHoscode()).getHosname();
    //科室名稱
    String depname = departmentRepository.findByHoscodeAndDepcode(schedule.getHoscode(),schedule.getDepcode()).getDepname();
    //周幾
    String dayOfWeek = DateUtil.getDayOfWeek(new DateTime(schedule.getWorkDate()));
    
    Integer workTime = schedule.getWorkTime();
    String workTimeString = workTime.intValue() == 0 ? "上午" : "下午";
    
    schedule.getParam().put("hosname",hosname);
    schedule.getParam().put("depname",depname);
    schedule.getParam().put("dayOfWeek",dayOfWeek);
    schedule.getParam().put("workTimeString", workTimeString);
    
  	//id為ObjectId類型時需要進行轉換
    schedule.getParam().put("id",schedule.getId().toString());
    return schedule;
}

2、前端整合

2.1、api

在api/hosp.js添加方法

//獲取預約詳情
getScheduleDetail(id) {
    return request({
        url: `/front/hosp/schedule/getScheduleDetail/${id}`,
        method: 'get'
    })
}

2.2、頁面渲染

pages/hospital/booking.vue

源碼:https://gitee.com/dengyaojava/guigu-syt-parent

本文來自博客園,作者:自律即自由-,轉載請註明原文鏈接:https://www.cnblogs.com/deyo/p/17489022.html


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • # Java 變數與基本數據類型 # 1. 變數是保存特定數據類型的值。變數必須先聲明,後使用。變數表示記憶體中的一個存儲區域。變數在同一個域中不可出現相同的變數名。 ## # 2. 程式中 + 號的作用 > ## 如果兩邊都是數值,進行加法運算 > > ## 如果左右一邊有一方位字元串,則做拼接字元 ...
  • > 我們之前對Redis的學習都是在命令行視窗,那麼如何使用Java來對Redis進行操作呢?對於Java連接Redis的開發工具有很多,這裡先介紹通過Jedis實現對Redis的各種操作。(前提是你的redis已經配置了遠程訪問) ## 1.創建一個maven工程,並且添加以下依賴 ~~~xml ...
  • 利用Python調用外部系統命令的方法可以提高編碼效率。調用外部系統命令完成後可以通過獲取命令執行返回結果碼、命令執行的輸出結果進行進一步的處理。本文主要描述Python常見的調用外部系統命令的方法,包括os.system()、os.popen()、subprocess.Popen()等。 本文分析 ...
  • pymongo模塊是python操作mongo數據的第三方模塊,記錄一下常用到的簡單用法。 **首先需要連接資料庫:** - MongoClient():該方法第一個參數是資料庫所在地址,第二個參數是資料庫所在的埠號 - authenticate():該方法第一個參數是資料庫的賬號,第二個參數是數 ...
  • # Go 語言之 Viper 的使用 ## Viper 介紹 [Viper](https://github.com/spf13/viper): ### 安裝 ```bash go get github.com/spf13/viper ``` ### Viper 是什麼? Viper 是一個針對 Go ...
  • 以WebMvcAutoConfiguration自動配置的原理為例,SpringBoot內部對大量的第三方庫或Spring內部庫進行了預設配置,這些配置是否生效,取決於我們是否引入了對應庫所需的依賴,如果有那麼預設配置就會生效。如果引入springboot-starter-web那麼對應的web配置 ...
  • `NumPy`(Numerical Python)是一個`Python`庫,主要用於高效地處理多維數組和矩陣計算。它是科學計算領域中使用最廣泛的一個庫。 在`NumPy`中,**數組**是最核心的概念,用於存儲和操作數據。 `NumPy`數組是一種多維數組對象,可以存儲相同類型的元素,它支持高效的數 ...
  • 一、簡介 官網: https://spring.io/projects/spring-framework#overview 官方下載工具: https://repo.spring.io/release/org/springframework/spring/ github下載: https://git ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...