# RevenueController.java

    package cloud.wconnect.rateshop.controller.revenue;

    import cloud.wconnect.commonlib.annotation.ApiId;
    import cloud.wconnect.commonlib.component.SessionContext;
    import cloud.wconnect.commonlib.cons.BaseConstant;
    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.CommonErrorI18nConstant;
    import cloud.wconnect.commonlib.exception.BadRequestException;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.pojo.dto.scheduler.JobParameterDTO;
    import cloud.wconnect.commonlib.redis.PropertyI18nRedisService;
    import cloud.wconnect.commonlib.service.UserInternalService;
    import cloud.wconnect.commonlib.util.DateTimeUtils;
    import cloud.wconnect.commonlib.util.I18nMessageUtils;
    import cloud.wconnect.commonlib.util.JsonUtils;
    import cloud.wconnect.rateshop.cons.revenue.ReveneuErrorCons;
    import cloud.wconnect.rateshop.cons.revenue.RevenueImportCons;
    import cloud.wconnect.rateshop.entity.rateshop.Hotel;
    import cloud.wconnect.rateshop.entity.rateshop.PropertyHotel;
    import cloud.wconnect.rateshop.entity.rateshop.Setting;
    import cloud.wconnect.rateshop.pojo.dto.rateshop.RateConfigDTO;
    import cloud.wconnect.rateshop.pojo.dto.revenue.*;
    import cloud.wconnect.rateshop.pojo.query.revenue.ExportRevenueQuery;
    import cloud.wconnect.rateshop.pojo.query.revenue.Next14DaysRateQuery;
    import cloud.wconnect.rateshop.pojo.query.revenue.RevenueDetailQuery;
    import cloud.wconnect.rateshop.service.rateshop.IHotelService;
    import cloud.wconnect.rateshop.service.rateshop.IPropertyHotelService;
    import cloud.wconnect.rateshop.service.rateshop.ISettingService;
    import cloud.wconnect.rateshop.service.revenue.*;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import com.google.common.collect.ImmutableMap;
    import com.google.common.collect.Lists;
    import com.google.common.collect.Sets;
    import jakarta.servlet.http.HttpServletResponse;
    import jakarta.validation.Valid;
    import lombok.extern.slf4j.Slf4j;
    import org.apache.commons.collections.CollectionUtils;
    import org.apache.commons.collections.MapUtils;
    import org.apache.commons.lang3.StringUtils;
    import org.jxls.transform.poi.JxlsPoiTemplateFillerBuilder;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.context.i18n.LocaleContextHolder;
    import org.springframework.core.io.ClassPathResource;
    import org.springframework.util.Assert;
    import org.springframework.web.bind.annotation.*;

    import java.io.IOException;
    import java.io.InputStream;
    import java.nio.charset.StandardCharsets;
    import java.time.LocalDate;
    import java.time.ZoneId;
    import java.time.ZonedDateTime;
    import java.util.*;
    import java.util.stream.Collectors;

    /**
     * <p>
     * Revenue
     * </p>
     *
     * @author yyt
     * @since 2023-10-26
     */
    @RestController
    @RequestMapping("/revenue")
    @Slf4j
    public class RevenueController {

        @Autowired
        private SessionContext sessionContext;
        @Autowired
        private IRevenueService revenueService;
        @Autowired
        private IHotelService hotelService;
        @Autowired
        private IPropertyHotelService propertyHotelService;
        @Autowired
        private ISettingService settingService;
        @Autowired
        @Qualifier("revenueHandlerCurrentDataServiceImpl")
        private IRevenueHandlerService revenueHandlerCurrentDataServiceImpl;
        @Autowired
        @Qualifier("revenueHandlerFutureDataServiceImpl")
        private IRevenueHandlerService revenueHandlerFutureDataServiceImpl;
        @Autowired
        private INext14DaysService next14DaysService;
        @Autowired
        private UserInternalService userInternalService;
        @Autowired
        private IRevenueImportService revenueImportService;
        @Autowired
        private IRevenueSchedulerJobService schedulerJobService;
        @Autowired
        private IRevenueMepsGroupConfigService revenueMepsGroupConfigService;
        @Autowired
        private PropertyI18nRedisService propertyI18nRedisService;
        @Autowired
        private ObjectMapper objectMapper;
        @Autowired
        private I18nMessageUtils i18nMessageUtils;

        /**
         * Revenue 详情
         *
         * @param date         选择日期
         * @param property     资产标识
         * @param datasourceId 去年同期的房价的查询条件：数据源ID
         * @param platformId   去年同期的房价的查询条件：平台ID
         * @return Revenue 详情
         * @author yyt
         * @date 2023/10/26
         */
        @ApiId(869)
        @GetMapping("/{date:\\d+}")
        public RevenueDTO detail(@PathVariable long date, String property, @RequestParam(required = false) Integer datasourceId,
                                 @RequestParam(required = false) Integer platformId) {
            PropertyDTO propertyDTO = propertyI18nRedisService.get(sessionContext.getPropertyId(property));
            String timezone = propertyDTO.getTimezone();
            long currentDate = DateTimeUtils.dateNowTimestamp(timezone);
            if (date <= currentDate) {
                return revenueHandlerCurrentDataServiceImpl.getDetail(propertyDTO, date, new RevenueDetailQuery(datasourceId, platformId));
            } else {
                return revenueHandlerFutureDataServiceImpl.getDetail(propertyDTO, date, new RevenueDetailQuery(datasourceId, platformId));
            }
        }

        /**
         * 保存 Revenue
         *
         * @param date       选择日期
         * @param property   资产标识
         * @param revenueDTO 输入内容
         * @return {}
         * @author yyt
         * @date 2023/10/27
         */
        @ApiId(870)
        @PostMapping("/{date:\\d+}")
        public Map save(@PathVariable long date, String property, @Valid @RequestBody RevenueDTO revenueDTO) {
            PropertyDTO propertyDTO = propertyI18nRedisService.get(sessionContext.getPropertyId(property));
            // 检查修改数据日期是否符合规则
            checkDate(propertyDTO, date, revenueDTO);

            long currentDate = DateTimeUtils.dateNowTimestamp(propertyDTO.getTimezone());
            if (date <= currentDate) {
                revenueHandlerCurrentDataServiceImpl.save(propertyDTO, date, revenueDTO, sessionContext.getLoginUserId());
            } else {
                revenueHandlerFutureDataServiceImpl.save(propertyDTO, date, revenueDTO, sessionContext.getLoginUserId());
            }

            return Collections.emptyMap();
        }

        /**
         * 检查修改数据日期是否符合规则
         *
         * @param propertyDTO 资产
         * @param targetDate  指定日期
         * @param revenueDTO  修改内容
         * @author yyt
         * @date 2023/10/28
         */
        private void checkDate(PropertyDTO propertyDTO, long targetDate, RevenueDTO revenueDTO) {
            String timezone = propertyDTO.getTimezone();
            // 检查 transientAndGroup 中的日期是否是 目标日期 ~ 未来14天之内
            List<TransientAndGroupDTO> transientAndGroup = revenueDTO.getTransientAndGroup();
            if (CollectionUtils.isNotEmpty(transientAndGroup)) {
                // 未来 14 天
                long endDate = DateTimeUtils.toZonedDateTime(targetDate, timezone).plusDays(13).toEpochSecond();
                Assert.isTrue(transientAndGroup.stream().noneMatch(item -> item.getTargetDate() < targetDate || item.getTargetDate() > endDate),
                        "the transientAndGroup param is error");
            }

            // 检查 transientAndGroupLy 中的日期是 目标日期去年同期 ~ 未来14天之内
            List<TransientAndGroupLyDTO> transientAndGroupLy = revenueDTO.getTransientAndGroupLy();
            if (CollectionUtils.isNotEmpty(transientAndGroupLy)) {
                ZonedDateTime zonedDateTime = DateTimeUtils.toZonedDateTime(targetDate, timezone);
                ZonedDateTime lastYearDate = DateTimeUtils.getSameDateLastYear(zonedDateTime.toLocalDate()).atStartOfDay(ZoneId.of(timezone));
                long lastYearNextDateSecond = lastYearDate.plusDays(13).toEpochSecond();
                long lastYearDateSecond = lastYearDate.toEpochSecond();
                Assert.isTrue(transientAndGroupLy.stream().noneMatch(item -> item.getTargetDate() < lastYearDateSecond
                                || item.getTargetDate() > lastYearNextDateSecond),
                        "the transientAndGroupLy param is error");
            }
        }

        /**
         * 1103 - 指定日期的目标酒店未来14天房价信息
         *
         * @param date     选择日期（格式：yyyy-MM-dd)
         * @param symbol   酒店标识
         * @param property 资产标识
         * @return 未来14天房价
         * @author yyt
         * @date 2024/3/25
         **/
        @ApiId(1103)
        @GetMapping("/{date}/hotel/{symbol}/room-rate/next14days")
        public List<Next14DaysRateDTO> listNext14DaysRate(@PathVariable String date, @PathVariable String symbol,
                                                          String tenant, String property, @Valid Next14DaysRateQuery next14DaysRateQuery) {
            PropertyDTO propertyDTO = propertyI18nRedisService.get(sessionContext.getPropertyId(property));
            checkDateFormat(propertyDTO, date);

            Hotel hotel = hotelService.checkHotel(symbol);
            propertyHotelService.checkAffiliation(hotel.getId(), propertyDTO.getId());

            //查询资产的setting
            Setting setting = settingService.getByPropertyId(propertyDTO.getId());

            //选择的日期
            long targetDate = DateTimeUtils.dateStrToEpochSecond(date, BaseConstant.DATE_FORMAT_YYYY_MM_DD, propertyDTO.getTimezone());

            List<Next14DaysRateDTO> next14DaysRateDTOS;
            //判断查询的日期是否未来日期
            if (targetDate > DateTimeUtils.dateNow(propertyDTO.getTimezone()).toEpochSecond()) {
                //查询未来日期数据时，获取最新的房价表数据（latest_rate_xxxx，latest_bar_rate_xxxx）
                next14DaysRateDTOS = next14DaysService.listFutureDateNext14DaysRate(date, hotel, propertyDTO, setting, next14DaysRateQuery);
            } else {
                //查询当前及历史日期数据时，获取带版本的未来14天房价数据（history_bar_rate_next_n_days、history_rate_next_n_days）
                next14DaysRateDTOS = next14DaysService.listHistoryDateNext14DaysRate(date, hotel, propertyDTO, setting, next14DaysRateQuery);
            }

            //收集用户ID集合
            HashSet<Integer> userIds = Sets.newHashSet();
            for (Next14DaysRateDTO next14DaysRateDTO : next14DaysRateDTOS) {
                userIds.addAll(next14DaysRateDTO.getRoomRate()
                        .stream().map(Next14DaysRatesDTO::getOperatorId).toList());
            }
            Map<Integer, String> userId2Name = userInternalService.getNameMapByIds(propertyDTO.getTenantId(), userIds);

            //设置用户姓名
            for (Next14DaysRateDTO next14DaysRateDTO : next14DaysRateDTOS) {
                List<Next14DaysRatesDTO> roomRates = next14DaysRateDTO.getRoomRate();
                roomRates.forEach(roomRate -> roomRate.setOperatorName(userId2Name.get(roomRate.getOperatorId())));
            }
            return next14DaysRateDTOS;
        }

        /**
         * 1104 - 指定日期的目标酒店未来14天信息
         *
         * @param date                         指定日期（YYYY-MM-DD)
         * @param property                     资产标识
         * @param updateHurdlerPointAndRateDTO 修改内容
         * @return {}
         * @author yyt
         * @date 2024/3/26
         **/
        @ApiId(1104)
        @PutMapping("/{date}/next14days")
        public Map updateNext14DaysRate(@PathVariable String date, String property,
                                        @Valid @RequestBody UpdateHurdlerPointAndRateDTO updateHurdlerPointAndRateDTO) {
            PropertyDTO propertyDTO = propertyI18nRedisService.get(sessionContext.getPropertyId(property));
            // 校验数据
            List<UpdateRateDTO> roomRates = updateHurdlerPointAndRateDTO.getRoomRate();
            if (CollectionUtils.isNotEmpty(roomRates)) {
                // 校验参数必传
                if (Objects.isNull(updateHurdlerPointAndRateDTO.getSyncOtherProperty())) {
                    throw new BadRequestException(CommonErrorI18nConstant.CANNOT_EMPTY,
                            i18nMessageUtils.getErrorParamMapNotNeedTranslate("syncOtherProperty"),
                            BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(), "the syncOtherProperty must not be null");
                }

                // 校验 酒店是否属于当前资产
                List<String> symbols = roomRates.stream().map(UpdateRateDTO::getHotelSymbol).distinct().toList();
                List<Hotel> hotels = hotelService.listEffectiveBySymbols(symbols);
                if (hotels.size() != symbols.size()) {
                    throw new BadRequestException(CommonErrorI18nConstant.DATA_NOT_EXIST,
                            i18nMessageUtils.getErrorParamMapNotNeedTranslate("symbol"),
                            BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(), "the symbol is not found");
                }
                List<PropertyHotel> propertyHotels = propertyHotelService.listByPropertyIdAndHotelIds(propertyDTO.getId(),
                        hotels.stream().map(Hotel::getId).toList());
                if (propertyHotels.size() != hotels.size()) {
                    throw new BadRequestException(ReveneuErrorCons.HOTEL_NOT_BELONG_TO_CURRENT_PROPERTY,
                            BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(), "the hotel is not belong the property");
                }

                // 校验平台是否属于当前资产
                List<Integer> platformIds = roomRates.stream().map(UpdateRateDTO::getPlatformId).filter(Objects::nonNull).toList();
                Setting setting = settingService.getByPropertyId(propertyDTO.getId());

                //资产配置的平台id集合
                List<RateConfigDTO> rateConfigDTOS = JsonUtils.convertStringToList(objectMapper, setting.getRateConfig(), RateConfigDTO.class);
                Set<Integer> settingPlatformIds = rateConfigDTOS.stream().map(RateConfigDTO::getPlatformIds).flatMap(Collection::stream).collect(Collectors.toSet());

                if (platformIds.stream().anyMatch(item -> !settingPlatformIds.contains(item))) {
                    throw new BadRequestException(CommonErrorI18nConstant.DATA_NOT_EXIST,
                            i18nMessageUtils.getErrorParamMapNotNeedTranslate("platformId"),
                            BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(), "the platformId is not found");
                }

                // 房价为null时把平台ID也设置为null
                roomRates.forEach(roomRate -> {
                    if (StringUtils.isEmpty(roomRate.getPrice())) {
                        roomRate.setPlatformId(null);
                    }
                });

                //校验是否重复
                Set<String> set = roomRates.stream().map(UpdateRateDTO::generateKey).collect(Collectors.toSet());
                if (set.size() != roomRates.size()) {
                    log.error("update rates :" + roomRates);
                    throw new BadRequestException(CommonErrorI18nConstant.DATA_CANNOT_REPEAT,
                            i18nMessageUtils.getErrorParamMapNotNeedTranslate("rate"),
                            BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(), "the rate cannot repeat");
                }
            }

            // 更新未来14天的数据
            LocalDate targetDate = DateTimeUtils.strToLocalDate(date, BaseConstant.DATE_FORMAT_YYYY_MM_DD);
            LocalDate currentDate = DateTimeUtils.dateNow(propertyDTO.getTimezone()).toLocalDate();
            if (targetDate.isAfter(currentDate)) {
                revenueHandlerFutureDataServiceImpl.updateNext14DaysData(propertyDTO, date, updateHurdlerPointAndRateDTO,
                        sessionContext.getLoginUserId(), sessionContext.getPropertyIds());
            } else {
                revenueHandlerCurrentDataServiceImpl.updateNext14DaysData(propertyDTO, date, updateHurdlerPointAndRateDTO,
                        sessionContext.getLoginUserId(), sessionContext.getPropertyIds());
            }

            return Collections.emptyMap();
        }

        /**
         * 检查日期格式
         *
         * @param propertyDTO 资产
         * @param date        日期
         * @author yyt
         * @date 2024/3/25
         **/
        private void checkDateFormat(PropertyDTO propertyDTO, String date) {
            try {
                DateTimeUtils.dateStrToEpochSecond(date, BaseConstant.DATE_FORMAT_YYYY_MM_DD, propertyDTO.getTimezone());
            } catch (Exception e) {
                throw new BadRequestException(CommonErrorI18nConstant.FORMAT_ERROR,
                        i18nMessageUtils.getErrorParamMapNotNeedTranslate("date"),
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(), "the date format error");
            }
        }

        /**
         * - 导出
         *
         * @param theDate            指定日期
         * @param property           资产标识
         * @param exportRevenueQuery 导出的Query
         * @param response           响应信息
         * @author yyt
         * @date 2024/3/27
         **/
        @ApiId(1108)
        @GetMapping("/{theDate:\\d+}/export")
        public void exportRevenue(@PathVariable long theDate, String property,
                                  @Valid ExportRevenueQuery exportRevenueQuery, HttpServletResponse response) {
            PropertyDTO propertyDTO = propertyI18nRedisService.get(sessionContext.getPropertyId(property));

            HashMap<String, Object> data = new HashMap<>();
            RevenueDTO revenueDTO = detail(theDate, property, exportRevenueQuery.getDatasourceIdBySameTimeLastYear(), exportRevenueQuery.getPlatformIdBySameTimeLastYear());

            Integer propertyId = propertyDTO.getId();

            String templateName;
            if (exportRevenueQuery.getType().equals(ExportRevenueQuery.TYPE_EXPORT_ALL)) {
                // 导出全部内容
                revenueService.packageDataToFile(propertyDTO, theDate, revenueDTO, data, exportRevenueQuery);
                templateName = "/tmpl-xls/dailyrevenue/revenue_tmpl_" + LocaleContextHolder.getLocale() + ".xlsx";
                if(revenueMepsGroupConfigService.hasConfig(propertyId)){
                    templateName = "/tmpl-xls/dailyrevenue/revenue_meps_group_tmpl_" + LocaleContextHolder.getLocale() + ".xlsx";
                }
            } else {
                // 只导出未来14天房价内容
                revenueService.packageNext14DaysRateToFile(propertyDTO, theDate, revenueDTO, data, exportRevenueQuery);
                templateName = "/tmpl-xls/dailyrevenue/revenue_next_14_days_rate_tmpl_" + LocaleContextHolder.getLocale() + ".xlsx";
                if(revenueMepsGroupConfigService.hasConfig(propertyId)){
                    templateName = "/tmpl-xls/dailyrevenue/revenue_meps_group_next_14_days_rate_tmpl_" + LocaleContextHolder.getLocale() + ".xlsx";
                }
            }

            try (InputStream inputStream = new ClassPathResource(templateName).getInputStream()) {
                String fileName = propertyDTO.getAbbr() + "_" + "revenue.xlsx";
                fileName = new String(fileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
                response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
                response.setHeader("Content-Disposition", String.join("", "attachment; filename=", fileName));
                JxlsPoiTemplateFillerBuilder.newInstance()
                        .withTemplate(inputStream)
                        .buildAndFill(data, response::getOutputStream);
            } catch (IOException e) {
                throw new BadRequestException(BaseErrorCodeEnum.SYSTEM_ERROR.getI18nCode(),
                        BaseErrorCodeEnum.SYSTEM_ERROR.getCode(), "Export file failed; exception:" + e);
            }
        }

        /**
         * 1177 - 获取报告所需数据区间
         *
         * @param report   报告
         * @param property 资产标识
         * @param tenant   租户标识
         * @param theDate  指定日期
         * @return 报告所需数据区间
         * @author yyt
         * @date 2024/5/23
         **/
        @ApiId(1177)
        @GetMapping("/report/{report}/data-date")
        public Map getReportDataDateRange(@PathVariable String report, String property, String tenant,
                                          @RequestParam(required = false) Long theDate) {
            PropertyDTO propertyDTO = propertyI18nRedisService.get(sessionContext.getPropertyId(property));
            String timezone = propertyDTO.getTimezone();

            List<Long> dates = Collections.emptyList();
            Map<String, Long> dateRange;
            switch (report) {
                case RevenueImportCons.HISTORY_FORECAST_NAME:
                    dates = revenueImportService.listImportHistoryAndForecastDateRange(theDate, timezone);
                    break;
                case RevenueImportCons.HISTORY_FORECAST_BUSINESS_BLOCK_NAME:
                    dates = revenueImportService.listImportHistoryAndForecastBusinessBlockDateRange(theDate, timezone);
                    break;
                case RevenueImportCons.RESERVATION_STATISTIC_NAME:
                    dates = revenueImportService.listImportReservationStatisticsDateRange(propertyDTO, theDate, timezone);
                    break;
                case RevenueImportCons.RESERVATION_FORECAST_NAME:
                    dates = revenueImportService.listImportReservationForecastDateRange(theDate, timezone);
                    break;
                case RevenueImportCons.RESERVATION_FORECAST_NEXT_MONTH_NAME:
                    dates = revenueImportService.listImportReservationForecastNextMonthDateRange(theDate, timezone);
                    break;
                case RevenueImportCons.HISTORY_FORECAST_NEXT_MONTH_NAME:
                    dates = revenueImportService.listImportHistoryAndForecastNextMonthDateRange(theDate, timezone);
                    break;
                case RevenueImportCons.RESERVATION_FORECAST_NEXT_14_DAYS_NAME:
                    dates = revenueImportService.listImportReservationForecastNext14DaysDateRange(theDate, timezone);
                    break;
                case RevenueImportCons.HISTORY_AND_FORECAST_YESTERDAY_AND_NEXT_NINETY_DAYS_NAME:
                    dateRange = schedulerJobService.getDateRange(propertyDTO,
                            RevenueImportCons.HISTORY_AND_FORECAST_YESTERDAY_AND_NEXT_NINETY_DAYS, theDate);
                    if (MapUtils.isNotEmpty(dateRange)) {
                        dates = Lists.newArrayList(dateRange.get(JobParameterDTO.START_DATE), dateRange.get(JobParameterDTO.END_DATE));
                    }
                    break;
                case RevenueImportCons.MARKET_CODE_NAME:
                    dateRange = schedulerJobService.getDateRange(propertyDTO, RevenueImportCons.MARKET_CODE, theDate);
                    if (MapUtils.isNotEmpty(dateRange)) {
                        dates = Lists.newArrayList(dateRange.get(JobParameterDTO.START_DATE), dateRange.get(JobParameterDTO.END_DATE));
                    }
                    break;
                case RevenueImportCons.HISTORY_FORECAST_THIS_MONTH_FUTURE_NAME:
                    dates = revenueImportService.listImportHistoryAndForecastThisMonthFutureDateRange(timezone);
                    break;
                case RevenueImportCons.HISTORY_FORECAST_NEXT_MONTH_FUTURE_NAME:
                    dates = revenueImportService.listImportHistoryAndForecastNextMonthFutureDateRange(timezone);
                    break;
                case RevenueImportCons.HISTORY_FORECAST_THIS_MONTH_AFTER_NEXT_FUTURE_NAME:
                    dates = revenueImportService.listImportHistoryAndForecastThisMonthAfterNextFutureDateRange(timezone);
                    break;
                case RevenueImportCons.RESERVATION_FORECAST_NEXT_90_DAYS_NAME:
                    dates = revenueImportService.listImportReservationForecastNext90DaysDateRange(timezone);
                    break;
                case RevenueImportCons.HISTORY_FORECAST_BUSINESS_BLOCK_NEXT_90_DAYS_NAME:
                    dates = revenueImportService.listImportHistoryAndForecastBusinessBlockNext90DaysDateRange(timezone);
                    break;
                case RevenueImportCons.MANAGER_FLASH_NAME:
                    dateRange = schedulerJobService.getDateRange(propertyDTO, RevenueImportCons.MANAGER_FLASH, theDate);
                    if (MapUtils.isNotEmpty(dateRange)) {
                        dates = Lists.newArrayList(dateRange.get(JobParameterDTO.START_DATE), dateRange.get(JobParameterDTO.END_DATE));
                    }
                    break;
                case RevenueImportCons.DETAILED_AVAILABILITY_NEXT_14_DAYS_NAME:
                    dates = revenueImportService.listImportDetailedAvailabilityNext14DaysDateRange(theDate, timezone);
                    break;
                case RevenueImportCons.GROUP_PICKUP_YESTERDAY_NAME:
                    dates = Lists.newArrayList(DateTimeUtils.toZonedDateTime(theDate, timezone).toEpochSecond(), DateTimeUtils.toZonedDateTime(theDate, timezone).toEpochSecond());
                    break;
                case RevenueImportCons.HISTORY_AND_FORECAST_FROM_THIRTY_DAYS_AGO_TO_YESTERDAY_NAME:
                    dateRange = schedulerJobService.getDateRange(propertyDTO, RevenueImportCons.HISTORY_AND_FORECAST_FROM_THIRTY_DAYS_AGO_TO_YESTERDAY, theDate);
                    if (MapUtils.isNotEmpty(dateRange)) {
                        dates = Lists.newArrayList(dateRange.get(JobParameterDTO.START_DATE), dateRange.get(JobParameterDTO.END_DATE));
                    }
                    break;
                case RevenueImportCons.RESERVATION_FORECAST_THIS_MONTH_NAME:
                    dateRange = schedulerJobService.getDateRange(propertyDTO, RevenueImportCons.RESERVATION_FORECAST_THIS_MONTH, theDate);
                    if (MapUtils.isNotEmpty(dateRange)) {
                        dates = Lists.newArrayList(dateRange.get(JobParameterDTO.START_DATE), dateRange.get(JobParameterDTO.END_DATE));
                    }
                    break;
                default:
                    throw new BadRequestException(CommonErrorI18nConstant.DATA_INVALID,
                            i18nMessageUtils.getErrorParamMapNotNeedTranslate("report"),
                            BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(),  "report is invalid.");
            }

            if (CollectionUtils.isEmpty(dates)) {
                return Collections.emptyMap();
            }

            return ImmutableMap.of(JobParameterDTO.START_DATE, dates.get(0), JobParameterDTO.END_DATE, dates.get(1));
        }

    }