当前位置:网站首页>Day116. Shangyitong: Details of appointment registration ※
Day116. Shangyitong: Details of appointment registration ※
2022-08-02 01:41:00 【Firework Youth·】
一、预约挂号详情 ※
1、需求分析
(1) 根据page、limit、hoscode、depcode,Query information with pagination and conditions
(2) 根据hoscode、depcode、workDate Query the schedule details data
(3) Display the number source information according to the hospital appointment cycle(失效)
(4) If the registration time has passed on the day,预约周期+1
(5) If there is no doctor visit date(放假),也需要展示出来
(6) 根据开始、Stop registration time,判断状态
2、接口分析
1. With pagination and conditional statistics number source information
*参数:page、limit、hoscode、depcode
*返回值:map
2. Query the schedule details data
*参数:hoscode、depcode、workDate
*返回值:list
3、实现controller
HospitalApiController下新增方法
@ApiOperation(value = "获取可预约排班数据")
@GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
public R getBookingSchedule(
@PathVariable Integer page,
@PathVariable Integer limit,
@PathVariable String hoscode,
@PathVariable String depcode) {
Map<String, Object> map = scheduleService.getBookingSchedule(page, limit, hoscode, depcode);
return R.ok().data(map);
}
@ApiOperation(value = "获取排班数据")
@GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
public R findScheduleList(
@PathVariable String hoscode,
@PathVariable String depcode,
@PathVariable String workDate) {
//方法复用
List<Schedule> scheduleList = scheduleService.getScheduleDetail(hoscode,depcode,workDate);
return R.ok().data("scheduleList",scheduleList);
}4、实现Service
//获取可预约排班数据
@Override
public Map<String, Object> getBookingSchedule(
Integer page, Integer limit, String hoscode, String depcode) {
//1.根据hoscode 查询医院信息,获取预约规则
//2.According to the reservation rules,分页信息,Query the collection pagination object of available dates (Not affected by the database,Ipage<Date>苞米豆)
//3.Refer to the background interface to implement aggregate query (List<BookingScheduleRuleVo>)
//4.合并 步骤2和步骤3的数据
//5.封装数据并返回
return null;
} //获取可预约排班数据
@Override
public Map<String, Object> getBookingSchedule(
Integer page, Integer limit, String hoscode, String depcode) {
Map<String, Object> result = new HashMap<>();
//1、根据hoscode 查询医院信息,获取预约规则
Hospital hospital = hospitalService.getHospital(hoscode);
if(hospital==null){
throw new YyghException(20001,"The hospital information is incorrect");
}
BookingRule bookingRule = hospital.getBookingRule();
//2、According to the reservation rules,分页信息,Query the collection pagination object of available dates (Not affected by the database,Ipage<Date>苞米豆)
IPage<Date> iPage = this.getDateListPage(page,limit,bookingRule);
List<Date> datePageList = iPage.getRecords();
//3、Refer to the background interface to implement aggregate query (List<BookingScheduleRuleVo>),获取可预约日期科室剩余预约数
//3.1Prepare filters
Criteria criteria = Criteria
.where("hoscode").is(hoscode)
.and("depcode").is(depcode)
.and("workDate").in(datePageList);
//3.2创建聚合查询对象
Aggregation agg = Aggregation.newAggregation(
//3.2.1设置查询条件
Aggregation.match(criteria),
//3.2.2设置聚合参数 + 聚合查询字段 (分组)
Aggregation.group("workDate")
.first("workDate").as("workDate")
.count().as("docCount")
.sum("reservedNumber").as("reservedNumber")
.sum("availableNumber").as("availableNumber")
);
//3.3执行聚合查询List<BookingScheduleRuleVo>
AggregationResults<BookingScheduleRuleVo> aggregate =
mongoTemplate.aggregate(agg, Schedule.class, BookingScheduleRuleVo.class);
List<BookingScheduleRuleVo> scheduleVoList =
aggregate.getMappedResults();
//3.4The type of conversion query result,List=>Map k:workDate v:BookingScheduleRuleVo
Map<Date,BookingScheduleRuleVo> scheduleVoMap = new HashMap<>();
if(!CollectionUtils.isEmpty(scheduleVoList)){
scheduleVoMap = scheduleVoList.stream().collect(Collectors.toMap(
BookingScheduleRuleVo::getWorkDate,
BookingScheduleRuleVo->BookingScheduleRuleVo
));
}
//4、合并 步骤2(datePageList)和步骤3(scheduleVoMap)的数据
List<BookingScheduleRuleVo> bookingScheduleRuleVoList = new ArrayList<>();
for (int i = 0, let = datePageList.size(); i < let; i++) {
//4.1 遍历 datePageList,Take out the date of each day
Date date = datePageList.get(i);
//4.2 根据日期,查询scheduleVoMap,Get the record information of shift aggregation
BookingScheduleRuleVo bookingScheduleRuleVo = scheduleVoMap.get(date);
//4.3 The records of the shift aggregation are empty,需要初始化
if(bookingScheduleRuleVo==null){
bookingScheduleRuleVo = new BookingScheduleRuleVo();
bookingScheduleRuleVo.setDocCount(0);//Current number of appointments
bookingScheduleRuleVo.setAvailableNumber(-1);//
}
//4.4 Set shift dates
bookingScheduleRuleVo.setWorkDate(date);
bookingScheduleRuleVo.setWorkDateMd(date);
//4.5 Convert the day of the week based on the date
String dayOfWeek = this.getDayOfWeek(new DateTime(date));
bookingScheduleRuleVo.setDayOfWeek(dayOfWeek);
//4.6 Status judgment based on time (状态 0:正常 1:即将放号 -1:当天已停止挂号)
//最后一页,最后一条记录,The status is about to be released
if(i==let-1 && page==iPage.getPages()){
bookingScheduleRuleVo.setStatus(1);
}else{
bookingScheduleRuleVo.setStatus(0);
}
//第一页,第一条记录,If the stop registration time has passed,状态为-1,Registration will be closed on the day
if(i==0&&page==1){
DateTime stopDateTime = this.getDateTime(new Date(), bookingRule.getStopTime());
if(stopDateTime.isBeforeNow()){
bookingScheduleRuleVo.setStatus(-1);
}
}
bookingScheduleRuleVoList.add(bookingScheduleRuleVo);
}
//5、封装数据并返回
//可预约日期规则数据
result.put("bookingScheduleList", bookingScheduleRuleVoList);
result.put("total", iPage.getTotal());
//其他基础数据
Map<String, String> baseMap = new HashMap<>();
//医院名称
baseMap.put("hosname", hospitalService.getHospName(hoscode));
//科室
Department department =departmentService.getDepartment(hoscode, depcode);
//大科室名称
baseMap.put("bigname", department.getBigname());
//科室名称
baseMap.put("depname", department.getDepname());
//月
baseMap.put("workDateString", new DateTime().toString("yyyy年MM月"));
//放号时间
baseMap.put("releaseTime", bookingRule.getReleaseTime());
//停号时间
baseMap.put("stopTime", bookingRule.getStopTime());
result.put("baseMap", baseMap);
return result;
} //分支2 :According to the reservation rules,分页信息,Query the collection pagination object of available dates
private IPage<Date> getDateListPage(
Integer page, Integer limit, BookingRule bookingRule) {
//1.Get the registration start time from the appointment rule(当前系统日期+开始时间)
DateTime releaseDateTime =
this.getDateTime(new Date(),bookingRule.getReleaseTime());
// 2.Get the period from the appointment rule,Determine if the cycle is needed+1 如果当天放号时间已过,则预约周期后一天为即将放号时间,周期加1
Integer cycle = bookingRule.getCycle();
if(releaseDateTime.isBeforeNow()) cycle +=1;
//3.Calculate the date of registration according to the cycle,存入集合(list)
List<Date> dateList = new ArrayList<>();
for (int i = 0; i < cycle; i++) {
//The current date is backwardsi天
DateTime plusDays = new DateTime().plusDays(i);
String plusDaysString = plusDays.toString("yyyy-MM-dd");
dateList.add(new DateTime(plusDaysString).toDate());
}
//4.Prepare pagination parameters 日期分页,由于预约周期不一样,页面一排最多显示7天数据,多了就要分页显示
int start = (page-1)*limit;
int end = (page-1)*limit+limit;
if(end>dateList.size()) end = dateList.size();
//5.根据分页参数,Get a collection of paginated dates
List<Date> datePageList = new ArrayList<>();
for (int i = start; i < end; i++) {
datePageList.add(dateList.get(i));
}
//6.封装数据到IPage对象,返回
IPage<Date> iPage = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(page,limit,dateList.size());
iPage.setRecords(datePageList);
return iPage;
}
//日期+开始时间
private DateTime getDateTime(Date date, String timeString) {
String dateTimeString = new DateTime(date)
.toString("yyyy-MM-dd") + " "+ timeString;
DateTime dateTime = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm").parseDateTime(dateTimeString);
return dateTime;
}
Update shift data,测试:

边栏推荐
- Markdown (CSDN) MD编辑器(四)- 漂亮表格(表格背景色、跨行、跨列)
- Flink_CDC construction and simple use
- "Introduction to Natural Language Processing Practice" Question Answering Robot Based on Knowledge Graph
- Anti-oversold and high concurrent deduction scheme for e-commerce inventory system
- 【ORB_SLAM2】SetPose、UpdatePoseMatrices
- flowable工作流所有业务概念
- DCM 中间件家族迎来新成员
- Local storage in Kubernetes
- 电商库存系统的防超卖和高并发扣减方案
- R语言使用table1包绘制(生成)三线表、使用单变量分列构建三线表、编写自定义三线表结构(将因子变量细粒度化重新构建三线图)、自定义修改描述性统计参数输出自定义统计量
猜你喜欢
随机推荐
feign异常传递的两种方式 fallbackfactory和全局处理 获取服务端自定义异常
Local storage in Kubernetes
dbeaver连接MySQL数据库及错误Connection refusedconnect处理
Markdown (CSDN) MD编辑器(四)- 漂亮表格(表格背景色、跨行、跨列)
Entry name ‘org/apache/commons/codec/language/bm/gen_approx_greeklatin.txt’ collided
flv.js解析与使用
Maxwell 一款简单易上手的实时抓取Mysql数据的软件
FlinkSQL CDC实现同步oracle数据到mysql
html+css+php+mysql实现注册+登录+修改密码(附完整代码)
YGG Guild Development Plan Season 1 Summary
60种特征工程操作:使用自定义聚合函数【收藏】
C语言实验九 函数(一)
成都openGauss用户组招募啦!
华为5年女测试工程师离职:多么痛的领悟...
【图像融合】基于加权和金字塔实现图像融合附matlab代码
typescript31-any类型
飞桨开源社区季度报告来啦,你想知道的都在这里
Newton's theorem and related corollaries
typescript34-class的基本使用
信息收集之cms指纹识别









