# RevenueReservationForecastNext90DaysTask.java

    package cloud.wconnect.rateshop.businesstask.revenue;

    import cloud.wconnect.commonlib.businesstask.CheckReportMissedService;
    import cloud.wconnect.commonlib.businesstask.rule.MissedRuleByThreshold;
    import cloud.wconnect.commonlib.pojo.dto.CheckReportMissedDTO;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    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.entity.revenue.RevenueSchedulerJob;
    import cloud.wconnect.rateshop.service.revenue.IRevenueImportService;
    import lombok.extern.slf4j.Slf4j;
    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.List;

    /**
     * Task: Reservation Forecast Next 90 Days
     *
     * @author yyt
     * 2024/5/24
     */
    @Slf4j
    @Service
    public class RevenueReservationForecastNext90DaysTask {

        @Autowired
        private PropertyI18nRedisService propertyI18nRedisService;
        @Autowired
        private CheckReportMissedService checkReportMissedService;
        @Autowired
        private PackageNotifyDTOUtil packageNotifyDTOUtil;
        @Autowired
        private IRevenueImportService revenueImportService;

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

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

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

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

            //报告缺失日期
            List<Long> dates = revenueImportService.listImportReservationForecastNext90DaysDateRange(propertyDTO.getTimezone());
            String missDate = packageNotifyDTOUtil.getDateRangeStr(propertyDTO, dates.get(0), dates.get(1));

            CheckReportMissedDTO check = CheckReportMissedDTO.builder()
                    .subject(SUBJECT)
                    .business(BUSINESS)
                    .propertyDTO(propertyDTO)
                    .ruleClazzList(Collections.singletonList(MissedRuleByThreshold.class))
                    .notifyDTO(packageNotifyDTOUtil.getNotifyDTO(propertyDTO, missDate, "Reservation Forecast Next 90 Days", schedulerJob.getCategory()))
                    .thresholdDTO(packageNotifyDTOUtil.getThresholdDTO(schedulerJob))
                    .build();
            checkReportMissedService.doCheck(check);

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

    }