# RevenueMarketSegmentSummaryYesterdayTask.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.pojo.dto.scheduler.JobParameterDTO;
    import cloud.wconnect.commonlib.redis.PropertyI18nRedisService;
    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: Market Segment Summary Yesterday
     *
     * @author yyt
     * 2026/3/4
     */
    @Slf4j
    @Service
    public class RevenueMarketSegmentSummaryYesterdayTask {

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

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

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

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

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

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

            CheckReportMissedDTO check = CheckReportMissedDTO.builder()
                    .subject(SUBJECT)
                    .business(BUSINESS)
                    .propertyDTO(propertyDTO)
                    .ruleClazzList(Collections.singletonList(MissedRuleByThreshold.class))
                    .notifyDTO(packageNotifyDTOUtil.getNotifyDTO(propertyDTO, missDate, "Market Segment Summary Yesterday", schedulerJob.getCategory()))
                    .thresholdDTO(packageNotifyDTOUtil.getThresholdDTO(schedulerJob))
                    .build();
            checkReportMissedService.doCheck(check);

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

    }