当前位置:网站首页>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,测试:
边栏推荐
猜你喜欢
随机推荐
电商库存系统的防超卖和高并发扣减方案
Test Cases: Four-Step Test Design Approach
typescript38-class的构造函数实例方法继承(implement)
《自然语言处理实战入门》 基于知识图谱的问答机器人
"Introduction to Natural Language Processing Practice" Question Answering Robot Based on Knowledge Graph
H5页面调用微信授权获取code
字节给我狠狠上了一课:危机来的时候你连准备时间都没有...
Kubernetes — 核心资源对象 — Controller
Anti-oversold and high concurrent deduction scheme for e-commerce inventory system
typescript31-any类型
Newton's theorem and related corollaries
Can‘t connect to MySQL server on ‘localhost3306‘ (10061) 简洁明了的解决方法
Go 1.18 的那些事——工作区、模糊测试、泛型
Local storage in Kubernetes
fastjson详解
C语言实验十 函数(二)
Maxwell 一款简单易上手的实时抓取Mysql数据的软件
去经营企业吧
成都openGauss用户组招募啦!
喜报 | AR 开启纺织产业新模式,ALVA Systems 再获殊荣!