# WMRevenueReservationStatisticsTask.java

    package cloud.wconnect.rateshop.businesstask.weeklymonthlyrevenue;

    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.NotifyDTO;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.pojo.dto.ThresholdDTO;
    import cloud.wconnect.commonlib.pojo.dto.scheduler.JobParameterDTO;
    import cloud.wconnect.commonlib.redis.PropertyI18nRedisService;
    import cloud.wconnect.commonlib.service.PropertyInternalService;
    import cloud.wconnect.commonlib.util.JsonUtils;
    import cloud.wconnect.rateshop.cons.BusinessEnum;
    import cloud.wconnect.rateshop.cons.EventSubjectEnum;
    import cloud.wconnect.rateshop.entity.weeklymonthlyrevenue.WeeklyMonthlyRevenueScheduler;
    import cloud.wconnect.rateshop.service.weeklymonthlyrevenue.IWeeklyMonthlySendNotifyService;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import lombok.extern.slf4j.Slf4j;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.scheduling.annotation.Async;
    import org.springframework.stereotype.Component;

    import jakarta.annotation.Resource;
    import java.util.List;
    import java.util.concurrent.TimeUnit;

    /**
     * 检查报告缺失：reservation-statistics
     *
     * @author zc
     * @date 2024/5/16
     */
    @Slf4j
    @Component
    public class WMRevenueReservationStatisticsTask {
        @Resource
        private IWeeklyMonthlySendNotifyService sendNotifyService;
        @Resource
        private CheckReportMissedService checkReportMissedService;
        @Resource
        private PropertyI18nRedisService propertyI18nRedisService;
        @Resource
        private PropertyInternalService propertyInternalService;
        @Resource
        private ObjectMapper objectMapper;
        @Value("${default.timezone}")
        private String defaultTimezone;

        private final static String BUSINESS = BusinessEnum.WEEKLY_MONTHLY_REVENUE.getBusiness();
        private final static String SUBJECT = EventSubjectEnum.RESERVATION_STATISTICS_YESTERDAY.getSubject();

        /**
         * 检查报告是否缺失
         *
         * <p>
         * 报告下发时间：每天上午 6:00:00
         * 检查报告缺失：每天上午 6:30:00
         * 阈值：23 小时
         * </P>
         *
         * @param schedulerJob 调度数据
         * @author zc
         * @date 2024/5/16
         */
        @Async
        public void dataMissingCheck(WeeklyMonthlyRevenueScheduler schedulerJob) {
            log.info("WMRevenueReservationStatisticsTask.dataMissingCheck start...");

            int propertyId = schedulerJob.getPropertyId();
            PropertyDTO propertyDTO = propertyI18nRedisService.get(propertyId);
            if (!propertyDTO.getStatus()) {
                return;
            }

            JobParameterDTO jobParameterDTO = JsonUtils.convertStringToObject(objectMapper,
                    schedulerJob.getParameters(), JobParameterDTO.class);

            // 获取资产配置的 PMS 报告名称
            String reportName = propertyInternalService.getPmsReportConfig(propertyId,
                    propertyDTO.getPmsType(), PmsReportEnum.RESERVATION_STATISTICS.getSymbol()).getReportName();
            // 获取通知配置
            NotifyDTO notifyDTO = sendNotifyService.getNotifyDTO(propertyDTO, reportName, schedulerJob.getCategory());

            // 获取资产配置的阈值
            ThresholdDTO thresholdDTO = new ThresholdDTO(jobParameterDTO.getThreshold(), TimeUnit.MINUTES, defaultTimezone);

            // 封装 CheckReportMissedDTO 对象
            CheckReportMissedDTO job = CheckReportMissedDTO.builder()
                    .business(BUSINESS)
                    .subject(SUBJECT)
                    .ruleClazzList(List.of(MissedRuleByThreshold.class))
                    .propertyDTO(propertyDTO)
                    .notifyDTO(notifyDTO)
                    .thresholdDTO(thresholdDTO)
                    .build();
            checkReportMissedService.doCheck(job);

            log.info("WMRevenueReservationStatisticsTask.dataMissingCheck end");
        }
    }