# GmwrDraftDataProcessTask.java

    package cloud.wconnect.workperformance.businesstask.gmwr;

    import cloud.wconnect.commonlib.cons.BaseConstant;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.redis.PropertyI18nRedisService;
    import cloud.wconnect.commonlib.util.DateTimeUtils;
    import cloud.wconnect.workperformance.cons.gmwr.GmwrStatusEnum;
    import cloud.wconnect.workperformance.entity.gmwr.GmwrScheduler;
    import cloud.wconnect.workperformance.entity.gmwr.GmwrWeeks;
    import cloud.wconnect.workperformance.service.gmwr.IGmwrSendNotifyService;
    import cloud.wconnect.workperformance.service.gmwr.IGmwrWeeksService;
    import cloud.wconnect.workperformance.service.hotelkpi.internal.IHotelKpiInternalService;
    import jakarta.annotation.Resource;
    import lombok.extern.slf4j.Slf4j;
    import org.springframework.scheduling.annotation.Async;
    import org.springframework.stereotype.Component;

    import java.time.DayOfWeek;
    import java.time.LocalDate;
    import java.time.ZoneId;
    import java.time.temporal.TemporalAdjusters;
    import java.util.Objects;

    /**
     * @author zc
     * @date 2025/01/24
     */
    @Slf4j
    @Component
    public class GmwrDraftDataProcessTask {
        @Resource
        private IGmwrSendNotifyService sendNotification;
        @Resource
        private IGmwrWeeksService weeksService;
        @Resource
        private IHotelKpiInternalService hotelKpiInternalService;
        @Resource
        private PropertyI18nRedisService propertyI18nRedisService;

        /**
         * 发送 Draft Notification
         *
         * <p>每周[x]的某时刻执行，通知上一周期的 Draft 状态数据，不重复通知</p>
         *
         * @author zc
         * @date 2025/1/24
         */
        @Async
        public void sendDraftNotification(GmwrScheduler schedulerJob) {
            log.info("GmwrDraftDataProcessTask.sendDraftNotification start...");

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

            // 获取周起始日
            DayOfWeek dayOfWeek = hotelKpiInternalService.getWeekStartDay(propertyId);
            // 获取上周期的周起始日
            LocalDate lastWeekStartDate = LocalDate.now(ZoneId.of(propertyDTO.getTimezone()))
                    .with(TemporalAdjusters.previousOrSame(dayOfWeek)).minusDays(7);
            long weekStartDate = Long.parseLong(DateTimeUtils.localDateToStr(lastWeekStartDate, BaseConstant.DATE_FORMAT_YYYYMMDD));
            // 获取上一周期的 Draft 状态数据
            GmwrWeeks gmwrWeeks = weeksService.getByDateAndStatus(propertyDTO.getId(), weekStartDate, GmwrStatusEnum.DRAFT.getStatus());
            if (Objects.isNull(gmwrWeeks)) {
                log.warn("GmwrDraftDataProcessTask.sendDraftNotification end... The data of the previous period is not obtained");
                return;
            }
            // 发送通知处理 Draft 状态的周报数据
            sendNotification.sendNotificationForDraft(propertyDTO, gmwrWeeks);

            log.info("GmwrDraftDataProcessTask.sendDraftNotification end...");
        }
    }