主頁 > 後端開發 > 尚醫通day13【預約掛號】(內附原始碼)

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

2023-06-19 07:36:36 後端開發

頁面預覽

預約掛號

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

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 = "https://www.cnblogs.com/deyo/archive/2023/06/18/獲取可預約排班日期資料")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hoscode",value = "https://www.cnblogs.com/deyo/archive/2023/06/18/醫院編碼", required = true),
            @ApiImplicitParam(name = "depcode",value = "https://www.cnblogs.com/deyo/archive/2023/06/18/科室編碼", 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 = "https://www.cnblogs.com/deyo/archive/2023/06/18/醫院編碼", required = true),
            @ApiImplicitParam(name = "depcode",value = "https://www.cnblogs.com/deyo/archive/2023/06/18/科室編碼", required = true),
            @ApiImplicitParam(name = "workDate",value = "https://www.cnblogs.com/deyo/archive/2023/06/18/排班日期", 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 = 'https://www.cnblogs.com/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 = 'https://www.cnblogs.com/user'
        },
      })
      return
    }
    window.location.href =
      'https://www.cnblogs.com/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 = "https://www.cnblogs.com/deyo/archive/2023/06/18/排班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

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/555490.html

標籤:其他

上一篇:并行計算——緒論

下一篇:返回列表

標籤雲
其他(161225) Python(38240) JavaScript(25505) Java(18246) C(15237) 區塊鏈(8271) C#(7972) AI(7469) 爪哇(7425) MySQL(7256) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5875) 数组(5741) R(5409) Linux(5347) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4603) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2436) ASP.NET(2404) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) .NET技术(1984) HtmlCss(1968) 功能(1967) Web開發(1951) C++(1941) python-3.x(1918) 弹簧靴(1913) xml(1889) PostgreSQL(1881) .NETCore(1863) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【C++】Microsoft C++、C 和匯編程式檔案

    ......

    uj5u.com 2020-09-10 00:57:23 more
  • 例外宣告

    相比于斷言適用于排除邏輯上不可能存在的狀態,例外通常是用于邏輯上可能發生的錯誤。 例外宣告 Item 1:當函式不可能拋出例外或不能接受拋出例外時,使用noexcept 理由 如果不打算拋出例外的話,程式就會認為無法處理這種錯誤,并且應當盡早終止,如此可以有效地阻止例外的傳播與擴散。 示例 //不可 ......

    uj5u.com 2020-09-10 00:57:27 more
  • Codeforces 1400E Clear the Multiset(貪心 + 分治)

    鏈接:https://codeforces.com/problemset/problem/1400/E 來源:Codeforces 思路:給你一個陣列,現在你可以進行兩種操作,操作1:將一段沒有 0 的區間進行減一的操作,操作2:將 i 位置上的元素歸零。最終問:將這個陣列的全部元素歸零后操作的最少 ......

    uj5u.com 2020-09-10 00:57:30 more
  • UVA11610 【Reverse Prime】

    本人看到此題沒有翻譯,就附帶了一個自己的翻譯版本 思考 這一題,它的第一個要求是找出所有 $7$ 位反向質數及其質因數的個數。 我們應該需要質數篩篩選1~$10^{7}$的所有數,這里就不慢慢介紹了。但是,重讀題,我們突然發現反向質數都是 $7$ 位,而將它反過來后的數字卻是 $6$ 位數,這就說明 ......

    uj5u.com 2020-09-10 00:57:36 more
  • 統計區間素數數量

    1 #pragma GCC optimize(2) 2 #include <bits/stdc++.h> 3 using namespace std; 4 bool isprime[1000000010]; 5 vector<int> prime; 6 inline int getlist(int ......

    uj5u.com 2020-09-10 00:57:47 more
  • C/C++編程筆記:C++中的 const 變數詳解,教你正確認識const用法

    1、C中的const 1、區域const變數存放在堆疊區中,會分配記憶體(也就是說可以通過地址間接修改變數的值)。測驗代碼如下: 運行結果: 2、全域const變數存放在只讀資料段(不能通過地址修改,會發生寫入錯誤), 默認為外部聯編,可以給其他源檔案使用(需要用extern關鍵字修飾) 運行結果: ......

    uj5u.com 2020-09-10 00:58:04 more
  • 【C++犯錯記錄】VS2019 MFC添加資源不懂如何修改資源宏ID

    1. 首先在資源視圖中,添加資源 2. 點擊新添加的資源,復制自動生成的ID 3. 在解決方案資源管理器中找到Resource.h檔案,編輯,使用整個專案搜索和替換的方式快速替換 宏宣告 4. Ctrl+Shift+F 全域搜索,點擊查找全部,然后逐個替換 5. 為什么使用搜索替換而不使用屬性視窗直 ......

    uj5u.com 2020-09-10 00:59:11 more
  • 【C++犯錯記錄】VS2019 MFC不懂的批量添加資源

    1. 打開資源頭檔案Resource.h,在其中預先定義好宏 ID(不清楚其實ID值應該設定多少,可以先新建一個相同的資源項,再在這個資源的ID值的基礎上遞增即可) 2. 在資源視圖中選中專案資源,按F7編輯資源檔案,按 ID 型別 相對路徑的形式添加 資源。(別忘了先把檔案拷貝到專案中的res檔案 ......

    uj5u.com 2020-09-10 01:00:19 more
  • C/C++編程筆記:關于C++的參考型別,專供新手入門使用

    今天要講的是C++中我最喜歡的一個用法——參考,也叫別名。 參考就是給一個變數名取一個變數名,方便我們間接地使用這個變數。我們可以給一個變數創建N個參考,這N + 1個變數共享了同一塊記憶體區域。(參考型別的變數會占用記憶體空間,占用的記憶體空間的大小和指標型別的大小是相同的。雖然參考是一個物件的別名,但 ......

    uj5u.com 2020-09-10 01:00:22 more
  • 【C/C++編程筆記】從頭開始學習C ++:初學者完整指南

    眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......

    uj5u.com 2020-09-10 01:00:41 more
最新发布
  • 尚醫通day13【預約掛號】(內附原始碼)

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

    uj5u.com 2023-06-19 07:36:36 more
  • 并行計算——緒論

    # 一、緒論 ## 1.1 基本概念 1. 加速比:表示加速效果。單個處理器運行花費時間 / P個處理器運行花費時間;$S=\frac{T(1)}{T(p)}$ 2. 效率:$E = \frac{S}{p} = \frac{T(1)}{T(p)\times p}$ 3. 開銷:$C=T(p)\tim ......

    uj5u.com 2023-06-19 07:31:09 more
  • 集合體系結構

    集合體系結構 List系列集合:添加的元素有序,可重復,有索引 Collection:是單列集合的祖宗介面,它的功能是全部單列集合都可以繼承使用的 set系列集合:添加的元素無序,不重復,無索引 方法名說明 public boolean add(E e) 把給定的物件添加到當前集合中 public ......

    uj5u.com 2023-06-18 08:13:56 more
  • 集合體系結構

    集合體系結構 List系列集合:添加的元素有序,可重復,有索引 Collection:是單列集合的祖宗介面,它的功能是全部單列集合都可以繼承使用的 set系列集合:添加的元素無序,不重復,無索引 方法名說明 public boolean add(E e) 把給定的物件添加到當前集合中 public ......

    uj5u.com 2023-06-18 08:12:55 more
  • rust 使用第三方庫構建mini命令列工具

    這是上一篇 [rust 學習 - 構建 mini 命令列工具](https://www.cnblogs.com/dreamHot/p/17467837.html)的續作,擴展增加一些 crate 庫。這些基礎庫在以后的編程作業中會常用到,他們作為基架存在于專案中,解決專案中的某個問題。 專案示例還是 ......

    uj5u.com 2023-06-18 07:49:48 more
  • [ARM 匯編]進階篇—例外處理與中斷—2.4.2 ARM處理器的例外向量

    #### 例外向量表簡介 在ARM架構中,例外向量表是一組固定位置的記憶體地址,它們包含了處理器在遇到例外時需要跳轉到的處理程式的入口地址。每個例外型別都有一個對應的向量地址。當例外發生時,處理器會自動跳轉到對應的向量地址,并開始執行例外處理程式。 #### 例外向量表的位置 ARM處理器的例外向量表 ......

    uj5u.com 2023-06-18 07:49:41 more
  • 基于回歸分析的波士頓房價分析

    #基于回歸分析的波士頓房價分析 專案實作步驟: 1.專案結構 2.處理資料 3.處理繪圖 4.對資料進行分析 5.結果展示 一.專案結構 ![image](https://img2023.cnblogs.com/blog/3047082/202306/3047082-2023061722315431 ......

    uj5u.com 2023-06-18 07:49:28 more
  • 通過模仿學會Python爬蟲(一):零基礎上手

    好家伙,爬蟲來了 爬蟲,這玩意,不會怎么辦, 誒,先抄一份作業回來 1.別人的爬蟲 Python爬蟲史上超詳細講解(零基礎入門,老年人都看的懂)_ChenBinBini的博客-CSDN博客 # -*- codeing = utf-8 -*- from bs4 import BeautifulSoup ......

    uj5u.com 2023-06-18 07:49:10 more
  • 09. centos使用docker方式安裝mysql

    ## 一、創建宿主機物理路徑 新建/mydata/mysql/data、log和conf三個檔案夾 ```bash mkdir -p /mnt/mysql/log mkdir -p /mnt/mysql/data mkdir -p /mnt/mysql/config ``` 或者 ```bash m ......

    uj5u.com 2023-06-18 07:49:00 more
  • C++面試八股文:聊一聊指標?

    某日二師兄參加XXX科技公司的C++工程師開發崗位第17面: > 面試官:聊一聊指標? > > 二師兄:好的。 > > 面試官:你覺得指標本質上是什么? > > 二師兄:這要從記憶體地址開始說起了。如果有一塊容量是1G的記憶體,假設它的地址是從`0x00000000` 到`0x3fffffff`,每一個 ......

    uj5u.com 2023-06-18 07:48:54 more