1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| public Map<String, Object> getBookingScheduleRule(int page, int limit, String hoscode, String depcode) { Map<String,Object> result = new HashMap<>(); Hospital hospital = hospitalService.getByHoscode(hoscode); if(hospital == null) { throw new YyghException(ResultCodeEnum.DATA_ERROR); } BookingRule bookingRule = hospital.getBookingRule();
IPage iPage = this.getListDate(page,limit,bookingRule); List<Date> dateList = iPage.getRecords();
Criteria criteria = Criteria.where("hoscode").is(hoscode).and("depcode").is(depcode) .and("workDate").in(dateList);
Aggregation agg = Aggregation.newAggregation( Aggregation.match(criteria), Aggregation.group("workDate").first("workDate").as("workDate") .count().as("docCount") .sum("availableNumber").as("availableNumber") .sum("reservedNumber").as("reservedNumber") ); AggregationResults<BookingScheduleRuleVo> aggregateResult = mongoTemplate.aggregate(agg, Schedule.class, BookingScheduleRuleVo.class); List<BookingScheduleRuleVo> scheduleVoList = aggregateResult.getMappedResults();
Map<Date, BookingScheduleRuleVo> scheduleVoMap = new HashMap<>(); if(!CollectionUtils.isEmpty(scheduleVoList)) { scheduleVoMap = scheduleVoList.stream(). collect(Collectors.toMap(BookingScheduleRuleVo::getWorkDate, BookingScheduleRuleVo -> BookingScheduleRuleVo)); }
List<BookingScheduleRuleVo> bookingScheduleRuleVoList = new ArrayList<>(); for(int i=0,len=dateList.size();i<len;i++) { Date date = dateList.get(i); BookingScheduleRuleVo bookingScheduleRuleVo = scheduleVoMap.get(date); if(bookingScheduleRuleVo == null) { bookingScheduleRuleVo = new BookingScheduleRuleVo(); bookingScheduleRuleVo.setDocCount(0); bookingScheduleRuleVo.setAvailableNumber(-1); } bookingScheduleRuleVo.setWorkDate(date); bookingScheduleRuleVo.setWorkDateMd(date); String dayOfWeek = this.getDayOfWeek(new DateTime(date)); bookingScheduleRuleVo.setDayOfWeek(dayOfWeek);
if(i == len-1 && page == iPage.getPages()) { bookingScheduleRuleVo.setStatus(1); } else { bookingScheduleRuleVo.setStatus(0); } if(i == 0 && page == 1) { DateTime stopTime = this.getDateTime(new Date(), bookingRule.getStopTime()); if(stopTime.isBeforeNow()) { bookingScheduleRuleVo.setStatus(-1); } } bookingScheduleRuleVoList.add(bookingScheduleRuleVo); }
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; }
|