# FdProcedureCheckTask.java

    package cloud.wconnect.workperformance.businesstask.fdprocedurecheck;

    import cloud.wconnect.commonlib.pojo.dto.NotifyDTO;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.redis.PropertyI18nRedisService;
    import cloud.wconnect.commonlib.service.NotifyInternalService;
    import cloud.wconnect.workperformance.cons.fdprocedurecheck.FdProcedureCheckHandledResultEnum;
    import cloud.wconnect.workperformance.entity.fdprocedurecheck.FdProcedureCheck;
    import cloud.wconnect.workperformance.entity.fdprocedurecheck.FdProcedureCheckScheduler;
    import cloud.wconnect.workperformance.service.fdprocedurecheck.IFdProcedureCheckSendNotifyService;
    import cloud.wconnect.workperformance.service.fdprocedurecheck.IFdProcedureCheckService;
    import jakarta.annotation.Resource;
    import lombok.extern.slf4j.Slf4j;
    import org.apache.commons.collections.CollectionUtils;
    import org.springframework.scheduling.annotation.Async;
    import org.springframework.stereotype.Component;

    import java.util.List;
    import java.util.Objects;

    /**
     * FD Procedure Check Task
     *
     * @author zc
     * @date 2023/10/17
     */
    @Slf4j
    @Component
    public class FdProcedureCheckTask {
        @Resource
        private IFdProcedureCheckService fdProcedureCheckService;
        @Resource
        private IFdProcedureCheckSendNotifyService sendNotifyService;
        @Resource
        private PropertyI18nRedisService propertyI18nRedisService;
        @Resource
        private NotifyInternalService notifyInternalService;

        /**
         * 检查数据是否按时处理
         *
         * <p>
         * 每天的 10:00:00 检查数据是否按时处理，
         * 若未按时处理，则发送邮件通知、记录异常日志
         * </p>
         *
         * @param schedulerJob 调度数据
         * @author zc
         * @date 2024/3/16
         */
        @Async
        public void autoNotify(FdProcedureCheckScheduler schedulerJob) {
            log.info("FdProcedureCheckTask.autoNotify start...");

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

            int status = FdProcedureCheckHandledResultEnum.PENDING.getStatus();
            // 判断是否有要处理的数据
            List<FdProcedureCheck> procedureCheckList = fdProcedureCheckService.listLimitByStatus(propertyId, status, 10);
            if (CollectionUtils.isEmpty(procedureCheckList)) {
                log.info("FdProcedureCheckTask.autoNotify end... procedureCheckList is empty");
                return;
            }
            // 获取待处理的数据总数
            long total = fdProcedureCheckService.getTotalByStatus(propertyId, status);

            // 获取邮件配置
            NotifyDTO notifyDTO = sendNotifyService.getNotifyDTO(propertyDTO, schedulerJob.getCategory(), procedureCheckList, total);
            if (Objects.isNull(notifyDTO)) {
                log.info("FdProcedureCheckTask.autoNotify end... notifyDTO is null");
                return;
            }

            // 发送通知
            notifyInternalService.sendNotify(notifyDTO);

            log.info("FdProcedureCheckTask.autoNotify end...");
        }
    }