|
|
@@ -62,46 +62,27 @@ public class RoomRateService {
|
|
|
List<RoomRate> roomRateList = new ArrayList<>();
|
|
|
for (CheckinInfo checkinInfo : checkinInfoList) {
|
|
|
BigDecimal dayRate;
|
|
|
- LocalDate firstDay = date.with(TemporalAdjusters.firstDayOfMonth());
|
|
|
- LocalDate lastDay = date.with(TemporalAdjusters.lastDayOfMonth());
|
|
|
- if (lastDay.compareTo(date) == 0 && checkinInfo.getMonthRate() != null) {
|
|
|
- List<Long> checkinInfos = new ArrayList<>();
|
|
|
- checkinInfos.add(checkinInfo.getId());
|
|
|
- BigDecimal monthTotal = roomRateRepo.findAllByCheckinIdInAndDateBetween(checkinInfos, firstDay, lastDay)
|
|
|
- .stream().map(RoomRate::getDayRate).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
|
|
|
- dayRate = checkinInfo.getMonthRate().subtract(monthTotal);
|
|
|
- RoomRate roomRate = RoomRate.builder()
|
|
|
- .checkinId(checkinInfo.getId())
|
|
|
- .checkInType(checkinInfo.getCheckInType())
|
|
|
- .storeId(checkinInfo.getStoreId())
|
|
|
- .monthRate(checkinInfo.getMonthRate())
|
|
|
- .dayPrice(checkinInfo.getDayRate())
|
|
|
- .dayRate(dayRate)
|
|
|
- .date(date)
|
|
|
- .build();
|
|
|
- roomRateList.add(roomRate);
|
|
|
+ if (checkinInfo.getMonthRate() != null) {
|
|
|
+ YearMonth yearMonthObject = YearMonth.of(date.getYear(), date.getMonth());
|
|
|
+ int daysInMonth = yearMonthObject.lengthOfMonth();
|
|
|
+ dayRate = checkinInfo.getMonthRate()
|
|
|
+ .divide(BigDecimal.valueOf(daysInMonth), 2, RoundingMode.HALF_UP);
|
|
|
} else {
|
|
|
- if (checkinInfo.getMonthRate() != null) {
|
|
|
- YearMonth yearMonthObject = YearMonth.of(date.getYear(), date.getMonth());
|
|
|
- int daysInMonth = yearMonthObject.lengthOfMonth();
|
|
|
- dayRate = checkinInfo.getMonthRate()
|
|
|
- .divide(BigDecimal.valueOf(daysInMonth), 2, RoundingMode.HALF_UP);
|
|
|
- } else {
|
|
|
- dayRate = checkinInfo.getDayRate();
|
|
|
- }
|
|
|
- RoomRate roomRate = RoomRate.builder()
|
|
|
- .checkinId(checkinInfo.getId())
|
|
|
- .checkInType(checkinInfo.getCheckInType())
|
|
|
- .storeId(checkinInfo.getStoreId())
|
|
|
- .monthRate(checkinInfo.getMonthRate())
|
|
|
- .dayPrice(checkinInfo.getDayRate())
|
|
|
- .dayRate(dayRate)
|
|
|
- .date(date)
|
|
|
- .build();
|
|
|
- roomRateList.add(roomRate);
|
|
|
+ dayRate = checkinInfo.getDayRate();
|
|
|
}
|
|
|
+ RoomRate roomRate = RoomRate.builder()
|
|
|
+ .checkinId(checkinInfo.getId())
|
|
|
+ .checkInType(checkinInfo.getCheckInType())
|
|
|
+ .storeId(checkinInfo.getStoreId())
|
|
|
+ .monthRate(checkinInfo.getMonthRate())
|
|
|
+ .dayPrice(checkinInfo.getDayRate())
|
|
|
+ .dayRate(dayRate)
|
|
|
+ .date(date)
|
|
|
+ .build();
|
|
|
+ roomRateList.add(roomRate);
|
|
|
}
|
|
|
- List<RoomRate> extraRoomRates = roomRateRepo.findByStoreIdAndDateBetweenAndExtraFeeTrue(storeId, date, date);
|
|
|
+ List<RoomRate> extraRoomRates = roomRateRepo
|
|
|
+ .findByStoreIdAndDateBetweenAndExtraFeeTrue(storeId, date, date);
|
|
|
if (extraRoomRates.size() > 0) {
|
|
|
List<Long> checkInIds = extraRoomRates.stream()
|
|
|
.map(RoomRate::getCheckinId)
|
|
|
@@ -159,7 +140,8 @@ public class RoomRateService {
|
|
|
//对统计得到的map进行处理
|
|
|
money.forEach((contractId, amount) -> {
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
- ContractBill contractBill = Optional.ofNullable(contractBillRepo.findFirstByContractIdAndStartTimeBeforeAndEndTimeAfter(contractId, now, now))
|
|
|
+ ContractBill contractBill = Optional.ofNullable(contractBillRepo
|
|
|
+ .findFirstByContractIdAndStartTimeBeforeAndEndTimeAfter(contractId, now, now))
|
|
|
.orElse(
|
|
|
contractBillRepo.findDistinctFirstByContractId(contractId)
|
|
|
);
|
|
|
@@ -262,9 +244,11 @@ public class RoomRateService {
|
|
|
|
|
|
public List<RoomRateReport> findByDateAndStoreId(LocalDate start, LocalDate end, Long storeId, Integer type) {
|
|
|
if (type == 0) {
|
|
|
- return getRoomRateReports(roomRateRepo.findByStoreIdAndDateBetweenAndCheckInTypeNot(storeId, start, end, CheckInType.INDIVIDUAL));
|
|
|
+ return getRoomRateReports(roomRateRepo
|
|
|
+ .findByStoreIdAndDateBetweenAndCheckInTypeNot(storeId, start, end, CheckInType.INDIVIDUAL));
|
|
|
} else {
|
|
|
- return getRoomRateReports(roomRateRepo.findByStoreIdAndDateBetweenAndCheckInType(storeId, start, end, CheckInType.INDIVIDUAL));
|
|
|
+ return getRoomRateReports(roomRateRepo
|
|
|
+ .findByStoreIdAndDateBetweenAndCheckInType(storeId, start, end, CheckInType.INDIVIDUAL));
|
|
|
}
|
|
|
}
|
|
|
}
|