wangqifan 5 年之前
父節點
當前提交
3991c546e5
共有 1 個文件被更改,包括 24 次插入40 次删除
  1. 24 40
      src/main/java/com/izouma/zhumj/service/RoomRateService.java

+ 24 - 40
src/main/java/com/izouma/zhumj/service/RoomRateService.java

@@ -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));
         }
     }
 }