# RevenueDailySummaryGroupPickupTask.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.internationalization.InternationalizationDateTimeDTO;
    import cloud.wconnect.commonlib.pojo.dto.scheduler.JobParameterDTO;
    import cloud.wconnect.commonlib.redis.PropertyI18nRedisService;
    import cloud.wconnect.commonlib.util.InternationalizationUtils;
    import cloud.wconnect.commonlib.util.JobParameterUtils;
    import cloud.wconnect.commonlib.util.JsonUtils;
    import cloud.wconnect.rateshop.cons.BusinessEnum;
    import cloud.wconnect.rateshop.cons.EventSubjectEnum;
    import cloud.wconnect.rateshop.entity.revenue.RevenueSchedulerJob;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import lombok.extern.slf4j.Slf4j;
    import org.apache.commons.lang3.StringUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.scheduling.annotation.Async;
    import org.springframework.stereotype.Component;

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

    /**
     * 检测 group pickup 报告缺失的定时任务
     *
     * @author yyt
     * @date 2025/6/25
     */
    @Slf4j
    @Component
    public class RevenueDailySummaryGroupPickupTask {

        @Autowired
        private PropertyI18nRedisService propertyI18nRedisService;
        @Autowired
        private CheckReportMissedService checkReportMissedService;
        @Autowired
        private PackageNotifyDTOUtil packageNotifyDTOUtil;
        @Autowired
        private ObjectMapper objectMapper;
        private static final String SUBJECT = EventSubjectEnum.GROUP_PICKUP_YESTERDAY.getSubject();
        private static final String BUSINESS = BusinessEnum.REVENUE.getBusiness();

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

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

            //报告缺失日期
            InternationalizationDateTimeDTO dateTime = propertyDTO.getInternationalization().getDateTime();
            String missDate = "";
            String parameters = schedulerJob.getParameters();
            if (StringUtils.isNotBlank(parameters) && !parameters.equals("{}")) {
                JobParameterDTO jobParameterDTO = JsonUtils.convertStringToObject(objectMapper, parameters, JobParameterDTO.class);
                Map<String, Long> dataRange = JobParameterUtils.parseDateRange(jobParameterDTO.getDateRange(), jobParameterDTO.getDateRangeUnit(), propertyDTO.getTimezone(), null);
                String startDate = InternationalizationUtils.formatDateTime(dataRange.get(JobParameterDTO.START_DATE),
                        dateTime.getLongDate(), StringUtils.EMPTY, propertyDTO.getTimezone(), propertyDTO.getLanguage());
                String endDate = InternationalizationUtils.formatDateTime(dataRange.get(JobParameterDTO.END_DATE),
                        dateTime.getLongDate(), StringUtils.EMPTY, propertyDTO.getTimezone(), propertyDTO.getLanguage());
                missDate = startDate + " ~ " + endDate;
            }

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

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

    }