当前位置:网站首页>Day116.尚医通:预约挂号详情 ※
Day116.尚医通:预约挂号详情 ※
2022-08-02 01:11:00 【焰火青年·】
一、预约挂号详情 ※
1、需求分析
(1) 根据page、limit、hoscode、depcode,带分页带条件查询信息
(2) 根据hoscode、depcode、workDate 查询排班明细数据
(3) 根据医院预约周期展现号源信息(失效)
(4) 如果当天已过开始挂号时间,预约周期+1
(5) 如果没有医生出诊的日期(放假),也需要展示出来
(6) 根据开始、停止挂号时间,判断状态
2、接口分析
1. 带分页带条件统计号源信息
*参数:page、limit、hoscode、depcode
*返回值:map
2. 查询排班明细数据
*参数: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.根据预约规则,分页信息,查询可预约日期的集合分页对象 (不受数据库影响,Ipage<Date>苞米豆)
//3.参考后台接口实现聚合查询 (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,"医院信息有误");
}
BookingRule bookingRule = hospital.getBookingRule();
//2、根据预约规则,分页信息,查询可预约日期的集合分页对象 (不受数据库影响,Ipage<Date>苞米豆)
IPage<Date> iPage = this.getDateListPage(page,limit,bookingRule);
List<Date> datePageList = iPage.getRecords();
//3、参考后台接口实现聚合查询 (List<BookingScheduleRuleVo>),获取可预约日期科室剩余预约数
//3.1准备筛选条件
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.4转化查询结果的类型,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,取出每一天日期
Date date = datePageList.get(i);
//4.2 根据日期,查询scheduleVoMap,获取排班聚合的记录信息
BookingScheduleRuleVo bookingScheduleRuleVo = scheduleVoMap.get(date);
//4.3 排班聚合的记录是空的,需要初始化
if(bookingScheduleRuleVo==null){
bookingScheduleRuleVo = new BookingScheduleRuleVo();
bookingScheduleRuleVo.setDocCount(0);//当前预约数
bookingScheduleRuleVo.setAvailableNumber(-1);//
}
//4.4 设置排班日期
bookingScheduleRuleVo.setWorkDate(date);
bookingScheduleRuleVo.setWorkDateMd(date);
//4.5 根据日期换算周几
String dayOfWeek = this.getDayOfWeek(new DateTime(date));
bookingScheduleRuleVo.setDayOfWeek(dayOfWeek);
//4.6 根据时间进行状态判断 (状态 0:正常 1:即将放号 -1:当天已停止挂号)
//最后一页,最后一条记录,状态为即将放号
if(i==let-1 && page==iPage.getPages()){
bookingScheduleRuleVo.setStatus(1);
}else{
bookingScheduleRuleVo.setStatus(0);
}
//第一页,第一条记录,如果已过停止挂号时间,状态为-1,当天停止挂号
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 :根据预约规则,分页信息,查询可预约日期的集合分页对象
private IPage<Date> getDateListPage(
Integer page, Integer limit, BookingRule bookingRule) {
//1.从预约规则中获取开始挂号的时间(当前系统日期+开始时间)
DateTime releaseDateTime =
this.getDateTime(new Date(),bookingRule.getReleaseTime());
// 2.从预约规则中获取周期,判断周期是否需要+1 如果当天放号时间已过,则预约周期后一天为即将放号时间,周期加1
Integer cycle = bookingRule.getCycle();
if(releaseDateTime.isBeforeNow()) cycle +=1;
//3.根据周期推算出可以挂号的日期,存入集合(list)
List<Date> dateList = new ArrayList<>();
for (int i = 0; i < cycle; i++) {
//当前日期向后i天
DateTime plusDays = new DateTime().plusDays(i);
String plusDaysString = plusDays.toString("yyyy-MM-dd");
dateList.add(new DateTime(plusDaysString).toDate());
}
//4.准备分页参数 日期分页,由于预约周期不一样,页面一排最多显示7天数据,多了就要分页显示
int start = (page-1)*limit;
int end = (page-1)*limit+limit;
if(end>dateList.size()) end = dateList.size();
//5.根据分页参数,获取分页后日期集合
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;
}
更新排班数据,测试:

边栏推荐
- 管理基础知识11
- 简单工厂模式
- 【软件工程之美 - 专栏笔记】34 | 账号密码泄露成灾,应该怎样预防?
- Mapped Statements collection does not contain value for的解决方法
- Entry name ‘org/apache/commons/codec/language/bm/gen_approx_greeklatin.txt’ collided
- ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your
- Navicat data shows incomplete resolution
- 6-24漏洞利用-vnc密码破解
- 网络请求技术--跨域
- input禁止输入
猜你喜欢

html+css+php+mysql实现注册+登录+修改密码(附完整代码)

feign异常传递的两种方式 fallbackfactory和全局处理 获取服务端自定义异常

flex布局中使用flex-wrap实现换行

from origin ‘null‘ has been blocked by CORS policy Cross origin requests are only supported for

Two ways to pass feign exceptions: fallbackfactory and global processing Get server-side custom exceptions

DCM 中间件家族迎来新成员

一本适合职场新人的好书

Redis cluster mode

dbeaver连接MySQL数据库及错误Connection refusedconnect处理

Maxwell 一款简单易上手的实时抓取Mysql数据的软件
随机推荐
Can't connect to MySQL server on 'localhost3306' (10061) Simple and clear solution
Entry name ‘org/apache/commons/codec/language/bm/gen_approx_greeklatin.txt’ collided
R语言使用cph函数和rcs函数构建限制性立方样条cox回归模型、使用anova函数进行方差分析通过p值确认指定连续变量和风险值HR之间是否存在非线性关系
滴滴秋招提前批正式开始,现在投递免笔试
牛顿定理和相关推论
ERROR 1819 (HY000) Your password does not satisfy the current policy requirements
Mapped Statements collection does not contain value for的解决方法
go mode tidy出现报错go warning “all“ matched no packages
华为5年女测试工程师离职:多么痛的领悟...
Reflex WMS中阶系列6:对一个装货重复run pick会有什么后果?
HSDC和独立生成树相关
datax与datax-web安装部署
飞桨开源社区季度报告来啦,你想知道的都在这里
管理基础知识9
ELK日志分析系统
三本毕业的我被腾讯拒绝了十四次,最终成功入职阿里
GO开发环境配置
Redis cluster mode
C语言:打印整数二进制的奇数位和偶数位
Interview: Briefly describe a project you are involved in