# RevenueReservationForecastThisMonthTask.java

    package cloud.wconnect.rateshop.businesstask.revenue;

    import cloud.wconnect.commonlib.businesstask.CheckReportMissedService;
    import cloud.wconnect.commonlib.businesstask.rule.MissedRuleByThreshold;
    import cloud.wconnect.commonlib.cons.PmsReportEnum;
    import cloud.wconnect.commonlib.pojo.dto.CheckReportMissedDTO;
    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.PropertyInternalService;
    import cloud.wconnect.rateshop.cons.BusinessEnum;
    import cloud.wconnect.rateshop.cons.EventSubjectEnum;
    import cloud.wconnect.rateshop.cons.revenue.RevenueImportCons;
    import cloud.wconnect.rateshop.entity.revenue.RevenueSchedulerJob;
    import cloud.wconnect.rateshop.service.revenue.IRevenueSchedulerJobService;
    import lombok.extern.slf4j.Slf4j;
    import org.apache.commons.collections.MapUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.scheduling.annotation.Async;
    import org.springframework.stereotype.Service;

    import java.util.Collections;
    import java.util.Map;

    /**
     * Task: Reservation Forecast This Month
     *
     * @author yyt
     * 2026/2/26
     */
    @Slf4j
    @Service
    public class RevenueReservationForecastThisMonthTask {

        @Autowired
        private PropertyI18nRedisService propertyI18nRedisService;
        @Autowired
        private PropertyInternalService propertyInternalService;
        @Autowired
        private CheckReportMissedService checkReportMissedService;
        @Autowired
        private PackageNotifyDTOUtil packageNotifyDTOUtil;
        @Autowired
        private IRevenueSchedulerJobService schedulerJobService;

        private static final String SUBJECT = EventSubjectEnum.RESERVATION_FORECAST_THIS_MONTH.getSubject();

        private static final String BUSINESS = BusinessEnum.REVENUE.getBusiness();

        /**
         * 检查报告缺失
         *
         * @param schedulerJob 定时任务
         * @author yyt
         * @date 2026/2/26
         */
        @Async
        public void checkReportMissing(RevenueSchedulerJob schedulerJob) {
            log.info("RevenueReservationForecastThisMonthTask.checkReportMissing start...");

            PropertyDTO propertyDTO = propertyI18nRedisService.get(schedulerJob.getPropertyId());
            if (!propertyDTO.getStatus()) {
                log.warn("RevenueReservationForecastThisMonthTask.checkReportMissing end... the property is closed, no processing required");
                return;
            }

            //报告缺失日期
            Map<String, Long> dateRange = schedulerJobService.getDateRange(propertyDTO, RevenueImportCons.RESERVATION_FORECAST_THIS_MONTH);
            if (MapUtils.isEmpty(dateRange)) {
                log.warn("RevenueReservationForecastThisMonthTask.checkReportMissing end... no date range");
                return;
            }
            String missDate = packageNotifyDTOUtil.getDateRangeStr(propertyDTO, dateRange.get(JobParameterDTO.START_DATE), dateRange.get(JobParameterDTO.END_DATE));

            // 获取资产配置的 PMS 报告名称
            String reportName = propertyInternalService.getPmsReportConfig(propertyDTO.getId(),
                    propertyDTO.getPmsType(), PmsReportEnum.RESERVATION_FORECAST.getSymbol()).getReportName() + " this month";
            CheckReportMissedDTO check = CheckReportMissedDTO.builder()
                    .subject(SUBJECT)
                    .business(BUSINESS)
                    .propertyDTO(propertyDTO)
                    .ruleClazzList(Collections.singletonList(MissedRuleByThreshold.class))
                    .notifyDTO(packageNotifyDTOUtil.getNotifyDTO(propertyDTO, missDate, reportName, schedulerJob.getCategory()))
                    .thresholdDTO(packageNotifyDTOUtil.getThresholdDTO(schedulerJob))
                    .build();
            checkReportMissedService.doCheck(check);

            log.info("RevenueReservationForecastThisMonthTask.checkReportMissing end...");
        }

    }