当前位置:网站首页>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;
}
更新排班数据,测试:
边栏推荐
- go mode tidy出现报错go warning “all“ matched no packages
- 创新项目实战之智能跟随机器人原理与代码实现
- ofstream,ifstream,fstream读写文件
- hutool工具-----JSON工具-JSONUtil
- MySQL——增删查改操作
- C语言:打印整数二进制的奇数位和偶数位
- Kubernetes — Calico
- 当关注「互联网+」模式的时候,通常仅仅只是在关注「互联网+」模式本身
- For effective automated testing, these software testing tools must be collected!!!
- Moonbeam与Project Galaxy集成,为社区带来全新的用户体验
猜你喜欢
Two ways to pass feign exceptions: fallbackfactory and global processing Get server-side custom exceptions
go版本升级
信息化和数字化的本质区别是什么?
Day11 Shell scripting basics
Can‘t connect to MySQL server on ‘localhost3306‘ (10061) 简洁明了的解决方法
3个月测试员自述:4个影响我职业生涯的重要技能
喜报 | AR 开启纺织产业新模式,ALVA Systems 再获殊荣!
Flask gets post request parameters
NFT到底有哪些实际用途?
电子制造仓储条码管理系统解决方案
随机推荐
Image fusion based on weighted 】 and pyramid image fusion with matlab code
datax与datax-web安装部署
iframe使用
Anti-oversold and high concurrent deduction scheme for e-commerce inventory system
Redis和MySQL数据一致性问题,有没有好的解决方案?
管理基础知识18
C语言实验八 字符数组程序设计
hash table
Kubernetes — Calico
mapbox使用教程
IDEA版Postman插件Restful Fast Request,细节到位,功能好用
管理基础知识17
管理基础知识15
6-25漏洞利用-irc后门利用
创新项目实战之智能跟随机器人原理与代码实现
Newton's theorem and related corollaries
JDBC PreparedStatement 的命名参数实现
ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘解决方法
Day.js 常用方法
ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your